generic: 6.1, 6.6: replace Airoha EN8811H PHY driver with upstream
[openwrt/openwrt.git] / target / linux / gemini / patches-6.1 / 0017-usb-fotg210-Acquire-memory-resource-in-core.patch
1 From fa735ad1afeb5791d5562617b9bbed74574d3e81 Mon Sep 17 00:00:00 2001
2 From: Linus Walleij <linus.walleij@linaro.org>
3 Date: Wed, 18 Jan 2023 08:09:17 +0100
4 Subject: [PATCH 17/29] usb: fotg210: Acquire memory resource in core
5
6 The subdrivers are obtaining and mapping the memory resource
7 separately. Create a common state container for the shared
8 resources and start populating this by acquiring the IO
9 memory resource and remap it and pass this to the subdrivers
10 for host and peripheral.
11
12 Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
13 Link: https://lore.kernel.org/r/20230103-gemini-fotg210-usb-v2-3-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 @@ -33,9 +33,10 @@
19 #define GEMINI_MISC_USB0_MINI_B BIT(29)
20 #define GEMINI_MISC_USB1_MINI_B BIT(30)
21
22 -static int fotg210_gemini_init(struct device *dev, struct resource *res,
23 +static int fotg210_gemini_init(struct fotg210 *fotg, struct resource *res,
24 enum usb_dr_mode mode)
25 {
26 + struct device *dev = fotg->dev;
27 struct device_node *np = dev->of_node;
28 struct regmap *map;
29 bool wakeup;
30 @@ -47,6 +48,7 @@ static int fotg210_gemini_init(struct de
31 dev_err(dev, "no syscon\n");
32 return PTR_ERR(map);
33 }
34 + fotg->map = map;
35 wakeup = of_property_read_bool(np, "wakeup-source");
36
37 /*
38 @@ -55,6 +57,7 @@ static int fotg210_gemini_init(struct de
39 */
40 mask = 0;
41 if (res->start == 0x69000000) {
42 + fotg->port = GEMINI_PORT_1;
43 mask = GEMINI_MISC_USB1_VBUS_ON | GEMINI_MISC_USB1_MINI_B |
44 GEMINI_MISC_USB1_WAKEUP;
45 if (mode == USB_DR_MODE_HOST)
46 @@ -64,6 +67,7 @@ static int fotg210_gemini_init(struct de
47 if (wakeup)
48 val |= GEMINI_MISC_USB1_WAKEUP;
49 } else {
50 + fotg->port = GEMINI_PORT_0;
51 mask = GEMINI_MISC_USB0_VBUS_ON | GEMINI_MISC_USB0_MINI_B |
52 GEMINI_MISC_USB0_WAKEUP;
53 if (mode == USB_DR_MODE_HOST)
54 @@ -89,23 +93,34 @@ static int fotg210_probe(struct platform
55 {
56 struct device *dev = &pdev->dev;
57 enum usb_dr_mode mode;
58 + struct fotg210 *fotg;
59 int ret;
60
61 + fotg = devm_kzalloc(dev, sizeof(*fotg), GFP_KERNEL);
62 + if (!fotg)
63 + return -ENOMEM;
64 + fotg->dev = dev;
65 +
66 + fotg->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
67 + if (!fotg->res)
68 + return -ENODEV;
69 +
70 + fotg->base = devm_ioremap_resource(dev, fotg->res);
71 + if (!fotg->base)
72 + return -ENOMEM;
73 +
74 mode = usb_get_dr_mode(dev);
75
76 if (of_device_is_compatible(dev->of_node, "cortina,gemini-usb")) {
77 - struct resource *res;
78 -
79 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
80 - ret = fotg210_gemini_init(dev, res, mode);
81 + ret = fotg210_gemini_init(fotg, fotg->res, mode);
82 if (ret)
83 return ret;
84 }
85
86 if (mode == USB_DR_MODE_PERIPHERAL)
87 - ret = fotg210_udc_probe(pdev);
88 + ret = fotg210_udc_probe(pdev, fotg);
89 else
90 - ret = fotg210_hcd_probe(pdev);
91 + ret = fotg210_hcd_probe(pdev, fotg);
92
93 return ret;
94 }
95 --- a/drivers/usb/fotg210/fotg210-hcd.c
96 +++ b/drivers/usb/fotg210/fotg210-hcd.c
97 @@ -5557,11 +5557,10 @@ static void fotg210_init(struct fotg210_
98 * then invokes the start() method for the HCD associated with it
99 * through the hotplug entry's driver_data.
100 */
101 -int fotg210_hcd_probe(struct platform_device *pdev)
102 +int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg)
103 {
104 struct device *dev = &pdev->dev;
105 struct usb_hcd *hcd;
106 - struct resource *res;
107 int irq;
108 int retval;
109 struct fotg210_hcd *fotg210;
110 @@ -5585,18 +5584,14 @@ int fotg210_hcd_probe(struct platform_de
111
112 hcd->has_tt = 1;
113
114 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
115 - hcd->regs = devm_ioremap_resource(&pdev->dev, res);
116 - if (IS_ERR(hcd->regs)) {
117 - retval = PTR_ERR(hcd->regs);
118 - goto failed_put_hcd;
119 - }
120 + hcd->regs = fotg->base;
121
122 - hcd->rsrc_start = res->start;
123 - hcd->rsrc_len = resource_size(res);
124 + hcd->rsrc_start = fotg->res->start;
125 + hcd->rsrc_len = resource_size(fotg->res);
126
127 fotg210 = hcd_to_fotg210(hcd);
128
129 + fotg210->fotg = fotg;
130 fotg210->caps = hcd->regs;
131
132 /* It's OK not to supply this clock */
133 --- a/drivers/usb/fotg210/fotg210-hcd.h
134 +++ b/drivers/usb/fotg210/fotg210-hcd.h
135 @@ -182,6 +182,7 @@ struct fotg210_hcd { /* one per contro
136 # define INCR(x) do {} while (0)
137 #endif
138
139 + struct fotg210 *fotg; /* Overarching FOTG210 device */
140 /* silicon clock */
141 struct clk *pclk;
142 };
143 --- a/drivers/usb/fotg210/fotg210-udc.c
144 +++ b/drivers/usb/fotg210/fotg210-udc.c
145 @@ -1155,21 +1155,14 @@ int fotg210_udc_remove(struct platform_d
146 return 0;
147 }
148
149 -int fotg210_udc_probe(struct platform_device *pdev)
150 +int fotg210_udc_probe(struct platform_device *pdev, struct fotg210 *fotg)
151 {
152 - struct resource *res;
153 struct fotg210_udc *fotg210 = NULL;
154 struct device *dev = &pdev->dev;
155 int irq;
156 int ret = 0;
157 int i;
158
159 - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
160 - if (!res) {
161 - pr_err("platform_get_resource error.\n");
162 - return -ENODEV;
163 - }
164 -
165 irq = platform_get_irq(pdev, 0);
166 if (irq < 0) {
167 pr_err("could not get irq\n");
168 @@ -1182,6 +1175,7 @@ int fotg210_udc_probe(struct platform_de
169 return -ENOMEM;
170
171 fotg210->dev = dev;
172 + fotg210->fotg = fotg;
173
174 /* It's OK not to supply this clock */
175 fotg210->pclk = devm_clk_get(dev, "PCLK");
176 @@ -1222,11 +1216,7 @@ int fotg210_udc_probe(struct platform_de
177 goto err_alloc;
178 }
179
180 - fotg210->reg = ioremap(res->start, resource_size(res));
181 - if (fotg210->reg == NULL) {
182 - dev_err(dev, "ioremap error\n");
183 - goto err_alloc;
184 - }
185 + fotg210->reg = fotg->base;
186
187 spin_lock_init(&fotg210->lock);
188
189 --- a/drivers/usb/fotg210/fotg210-udc.h
190 +++ b/drivers/usb/fotg210/fotg210-udc.h
191 @@ -236,6 +236,7 @@ struct fotg210_udc {
192 unsigned long irq_trigger;
193
194 struct device *dev;
195 + struct fotg210 *fotg;
196 struct usb_phy *phy;
197 struct usb_gadget gadget;
198 struct usb_gadget_driver *driver;
199 --- a/drivers/usb/fotg210/fotg210.h
200 +++ b/drivers/usb/fotg210/fotg210.h
201 @@ -2,13 +2,28 @@
202 #ifndef __FOTG210_H
203 #define __FOTG210_H
204
205 +enum gemini_port {
206 + GEMINI_PORT_NONE = 0,
207 + GEMINI_PORT_0,
208 + GEMINI_PORT_1,
209 +};
210 +
211 +struct fotg210 {
212 + struct device *dev;
213 + struct resource *res;
214 + void __iomem *base;
215 + struct regmap *map;
216 + enum gemini_port port;
217 +};
218 +
219 #ifdef CONFIG_USB_FOTG210_HCD
220 -int fotg210_hcd_probe(struct platform_device *pdev);
221 +int fotg210_hcd_probe(struct platform_device *pdev, struct fotg210 *fotg);
222 int fotg210_hcd_remove(struct platform_device *pdev);
223 int fotg210_hcd_init(void);
224 void fotg210_hcd_cleanup(void);
225 #else
226 -static inline int fotg210_hcd_probe(struct platform_device *pdev)
227 +static inline int fotg210_hcd_probe(struct platform_device *pdev,
228 + struct fotg210 *fotg)
229 {
230 return 0;
231 }
232 @@ -26,10 +41,11 @@ static inline void fotg210_hcd_cleanup(v
233 #endif
234
235 #ifdef CONFIG_USB_FOTG210_UDC
236 -int fotg210_udc_probe(struct platform_device *pdev);
237 +int fotg210_udc_probe(struct platform_device *pdev, struct fotg210 *fotg);
238 int fotg210_udc_remove(struct platform_device *pdev);
239 #else
240 -static inline int fotg210_udc_probe(struct platform_device *pdev)
241 +static inline int fotg210_udc_probe(struct platform_device *pdev,
242 + struct fotg210 *fotg)
243 {
244 return 0;
245 }