forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/clk/renesas/rcar-usb2-clock-sel.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
23 * Renesas R-Car USB2.0 clock selector
34 *
....@@ -6,21 +7,19 @@
67 * Based on renesas-cpg-mssr.c
78 *
89 * Copyright (C) 2015 Glider bvba
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; version 2 of the License.
1310 */
1411
1512 #include <linux/clk.h>
1613 #include <linux/clk-provider.h>
1714 #include <linux/device.h>
1815 #include <linux/init.h>
16
+#include <linux/io.h>
1917 #include <linux/module.h>
2018 #include <linux/of_device.h>
2119 #include <linux/platform_device.h>
2220 #include <linux/pm.h>
2321 #include <linux/pm_runtime.h>
22
+#include <linux/reset.h>
2423 #include <linux/slab.h>
2524
2625 #define USB20_CLKSET0 0x00
....@@ -28,9 +27,16 @@
2827 #define CLKSET0_PRIVATE BIT(0)
2928 #define CLKSET0_EXTAL_ONLY (CLKSET0_INTCLK_EN | CLKSET0_PRIVATE)
3029
30
+static const struct clk_bulk_data rcar_usb2_clocks[] = {
31
+ { .id = "ehci_ohci", },
32
+ { .id = "hs-usb-if", },
33
+};
34
+
3135 struct usb2_clock_sel_priv {
3236 void __iomem *base;
3337 struct clk_hw hw;
38
+ struct clk_bulk_data clks[ARRAY_SIZE(rcar_usb2_clocks)];
39
+ struct reset_control *rsts;
3440 bool extal;
3541 bool xtal;
3642 };
....@@ -55,14 +61,32 @@
5561
5662 static int usb2_clock_sel_enable(struct clk_hw *hw)
5763 {
58
- usb2_clock_sel_enable_extal_only(to_priv(hw));
64
+ struct usb2_clock_sel_priv *priv = to_priv(hw);
65
+ int ret;
66
+
67
+ ret = reset_control_deassert(priv->rsts);
68
+ if (ret)
69
+ return ret;
70
+
71
+ ret = clk_bulk_prepare_enable(ARRAY_SIZE(priv->clks), priv->clks);
72
+ if (ret) {
73
+ reset_control_assert(priv->rsts);
74
+ return ret;
75
+ }
76
+
77
+ usb2_clock_sel_enable_extal_only(priv);
5978
6079 return 0;
6180 }
6281
6382 static void usb2_clock_sel_disable(struct clk_hw *hw)
6483 {
65
- usb2_clock_sel_disable_extal_only(to_priv(hw));
84
+ struct usb2_clock_sel_priv *priv = to_priv(hw);
85
+
86
+ usb2_clock_sel_disable_extal_only(priv);
87
+
88
+ clk_bulk_disable_unprepare(ARRAY_SIZE(priv->clks), priv->clks);
89
+ reset_control_assert(priv->rsts);
6690 }
6791
6892 /*
....@@ -104,10 +128,8 @@
104128 static int rcar_usb2_clock_sel_remove(struct platform_device *pdev)
105129 {
106130 struct device *dev = &pdev->dev;
107
- struct usb2_clock_sel_priv *priv = platform_get_drvdata(pdev);
108131
109132 of_clk_del_provider(dev->of_node);
110
- clk_hw_unregister(&priv->hw);
111133 pm_runtime_put(dev);
112134 pm_runtime_disable(dev);
113135
....@@ -119,21 +141,26 @@
119141 struct device *dev = &pdev->dev;
120142 struct device_node *np = dev->of_node;
121143 struct usb2_clock_sel_priv *priv;
122
- struct resource *res;
123144 struct clk *clk;
124
- struct clk_init_data init = {};
145
+ struct clk_init_data init;
146
+ int ret;
125147
126148 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
127149 if (!priv)
128150 return -ENOMEM;
129151
130
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
131
- priv->base = devm_ioremap_resource(dev, res);
152
+ priv->base = devm_platform_ioremap_resource(pdev, 0);
132153 if (IS_ERR(priv->base))
133154 return PTR_ERR(priv->base);
134155
135
- pm_runtime_enable(dev);
136
- pm_runtime_get_sync(dev);
156
+ memcpy(priv->clks, rcar_usb2_clocks, sizeof(priv->clks));
157
+ ret = devm_clk_bulk_get(dev, ARRAY_SIZE(priv->clks), priv->clks);
158
+ if (ret < 0)
159
+ return ret;
160
+
161
+ priv->rsts = devm_reset_control_array_get(dev, true, false);
162
+ if (IS_ERR(priv->rsts))
163
+ return PTR_ERR(priv->rsts);
137164
138165 clk = devm_clk_get(dev, "usb_extal");
139166 if (!IS_ERR(clk) && !clk_prepare_enable(clk)) {
....@@ -151,6 +178,8 @@
151178 return -ENOENT;
152179 }
153180
181
+ pm_runtime_enable(dev);
182
+ pm_runtime_get_sync(dev);
154183 platform_set_drvdata(pdev, priv);
155184 dev_set_drvdata(dev, priv);
156185
....@@ -161,11 +190,20 @@
161190 init.num_parents = 0;
162191 priv->hw.init = &init;
163192
164
- clk = clk_register(NULL, &priv->hw);
165
- if (IS_ERR(clk))
166
- return PTR_ERR(clk);
193
+ ret = devm_clk_hw_register(dev, &priv->hw);
194
+ if (ret)
195
+ goto pm_put;
167196
168
- return of_clk_add_hw_provider(np, of_clk_hw_simple_get, &priv->hw);
197
+ ret = of_clk_add_hw_provider(np, of_clk_hw_simple_get, &priv->hw);
198
+ if (ret)
199
+ goto pm_put;
200
+
201
+ return 0;
202
+
203
+pm_put:
204
+ pm_runtime_put(dev);
205
+ pm_runtime_disable(dev);
206
+ return ret;
169207 }
170208
171209 static const struct dev_pm_ops rcar_usb2_clock_sel_pm_ops = {