generic: 6.1, 6.6: replace Airoha EN8811H PHY driver with upstream
[openwrt/openwrt.git] / target / linux / gemini / patches-6.1 / 0018-usb-fotg210-Move-clock-handling-to-core.patch
1 From fb8e1e8dbc47e7aff7624b47adaa0a84d2983802 Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Wed, 18 Jan 2023 08:09:18 +0100
4 Subject: [PATCH 18/29] usb: fotg210: Move clock handling to core
5
6 Grab the optional silicon block clock, prepare and enable it in
7 the core before proceeding to prepare the host or peripheral
8 driver. This saves duplicate code and also uses the simple
9 devm_clk_get_optional_enabled() to do everything we really
10 want to do.
11
12 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
13 Link: https://lore.kernel.org/r/20230103-gemini-fotg210-usb-v2-4-100388af9810@linaro.org
14 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
15 ---
16 --- a/drivers/usb/fotg210/fotg210-core.c
17 +++ b/drivers/usb/fotg210/fotg210-core.c
18 @@ -6,6 +6,7 @@
19 * driver.
20 */
21 #include <linux/bitops.h>
22 +#include <linux/clk.h>
23 #include <linux/device.h>
24 #include <linux/mfd/syscon.h>
25 #include <linux/module.h>
26 @@ -109,6 +110,10 @@ static int fotg210_probe(struct platform
27 if (!fotg->base)
28 return -ENOMEM;
29
30 + fotg->pclk = devm_clk_get_optional_enabled(dev, "PCLK");
31 + if (IS_ERR(fotg->pclk))
32 + return PTR_ERR(fotg->pclk);
33 +
34 mode = usb_get_dr_mode(dev);
35
36 if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
37 --- a/drivers/usb/fotg210/fotg210-hcd.c
38 +++ b/drivers/usb/fotg210/fotg210-hcd.c
39 @@ -33,7 +33,6 @@
40 #include <linux/platform_device.h>
41 #include <linux/io.h>
42 #include <linux/iopoll.h>
43 -#include <linux/clk.h>
44
45 #include <asm/byteorder.h>
46 #include <asm/irq.h>
47 @@ -5594,44 +5593,22 @@ int fotg210_hcd_probe(struct platform_de
48 fotg210->fotg = fotg;
49 fotg210->caps = hcd->regs;
50
51 - /* It's OK not to supply this clock */
52 - fotg210->pclk = clk_get(dev, "PCLK");
53 - if (!IS_ERR(fotg210->pclk)) {
54 - retval = clk_prepare_enable(fotg210->pclk);
55 - if (retval) {
56 - dev_err(dev, "failed to enable PCLK\n");
57 - goto failed_put_hcd;
58 - }
59 - } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
60 - /*
61 - * Percolate deferrals, for anything else,
62 - * just live without the clocking.
63 - */
64 - retval = PTR_ERR(fotg210->pclk);
65 - goto failed_dis_clk;
66 - }
67 -
68 retval = fotg210_setup(hcd);
69 if (retval)
70 - goto failed_dis_clk;
71 + goto failed_put_hcd;
72
73 fotg210_init(fotg210);
74
75 retval = usb_add_hcd(hcd, irq, IRQF_SHARED);
76 if (retval) {
77 dev_err(dev, "failed to add hcd with err %d\n", retval);
78 - goto failed_dis_clk;
79 + goto failed_put_hcd;
80 }
81 device_wakeup_enable(hcd->self.controller);
82 platform_set_drvdata(pdev, hcd);
83
84 return retval;
85
86 -failed_dis_clk:
87 - if (!IS_ERR(fotg210->pclk)) {
88 - clk_disable_unprepare(fotg210->pclk);
89 - clk_put(fotg210->pclk);
90 - }
91 failed_put_hcd:
92 usb_put_hcd(hcd);
93 fail_create_hcd:
94 @@ -5647,12 +5624,6 @@ fail_create_hcd:
95 int fotg210_hcd_remove(struct platform_device *pdev)
96 {
97 struct usb_hcd *hcd = platform_get_drvdata(pdev);
98 - struct fotg210_hcd *fotg210 = hcd_to_fotg210(hcd);
99 -
100 - if (!IS_ERR(fotg210->pclk)) {
101 - clk_disable_unprepare(fotg210->pclk);
102 - clk_put(fotg210->pclk);
103 - }
104
105 usb_remove_hcd(hcd);
106 usb_put_hcd(hcd);
107 --- a/drivers/usb/fotg210/fotg210-udc.c
108 +++ b/drivers/usb/fotg210/fotg210-udc.c
109 @@ -15,7 +15,6 @@
110 #include <linux/platform_device.h>
111 #include <linux/usb/ch9.h>
112 #include <linux/usb/gadget.h>
113 -#include <linux/clk.h>
114 #include <linux/usb/otg.h>
115 #include <linux/usb/phy.h>
116
117 @@ -1147,9 +1146,6 @@ int fotg210_udc_remove(struct platform_d
118 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
119 kfree(fotg210->ep[i]);
120
121 - if (!IS_ERR(fotg210->pclk))
122 - clk_disable_unprepare(fotg210->pclk);
123 -
124 kfree(fotg210);
125
126 return 0;
127 @@ -1177,34 +1173,17 @@ int fotg210_udc_probe(struct platform_de
128 fotg210->dev = dev;
129 fotg210->fotg = fotg;
130
131 - /* It's OK not to supply this clock */
132 - fotg210->pclk = devm_clk_get(dev, "PCLK");
133 - if (!IS_ERR(fotg210->pclk)) {
134 - ret = clk_prepare_enable(fotg210->pclk);
135 - if (ret) {
136 - dev_err(dev, "failed to enable PCLK\n");
137 - goto err;
138 - }
139 - } else if (PTR_ERR(fotg210->pclk) == -EPROBE_DEFER) {
140 - /*
141 - * Percolate deferrals, for anything else,
142 - * just live without the clocking.
143 - */
144 - ret = -EPROBE_DEFER;
145 - goto err;
146 - }
147 -
148 fotg210->phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
149 if (IS_ERR(fotg210->phy)) {
150 ret = PTR_ERR(fotg210->phy);
151 if (ret == -EPROBE_DEFER)
152 - goto err_pclk;
153 + goto err_free;
154 dev_info(dev, "no PHY found\n");
155 fotg210->phy = NULL;
156 } else {
157 ret = usb_phy_init(fotg210->phy);
158 if (ret)
159 - goto err_pclk;
160 + goto err_free;
161 dev_info(dev, "found and initialized PHY\n");
162 }
163
164 @@ -1303,11 +1282,8 @@ err_map:
165 err_alloc:
166 for (i = 0; i < FOTG210_MAX_NUM_EP; i++)
167 kfree(fotg210->ep[i]);
168 -err_pclk:
169 - if (!IS_ERR(fotg210->pclk))
170 - clk_disable_unprepare(fotg210->pclk);
171
172 -err:
173 +err_free:
174 kfree(fotg210);
175 return ret;
176 }
177 --- a/drivers/usb/fotg210/fotg210-udc.h
178 +++ b/drivers/usb/fotg210/fotg210-udc.h
179 @@ -231,7 +231,6 @@ struct fotg210_ep {
180 struct fotg210_udc {
181 spinlock_t lock; /* protect the struct */
182 void __iomem *reg;
183 - struct clk *pclk;
184
185 unsigned long irq_trigger;
186
187 --- a/drivers/usb/fotg210/fotg210.h
188 +++ b/drivers/usb/fotg210/fotg210.h
189 @@ -12,6 +12,7 @@ struct fotg210 {
190 struct device *dev;
191 struct resource *res;
192 void __iomem *base;
193 + struct clk *pclk;
194 struct regmap *map;
195 enum gemini_port port;
196 };