2fb19288884c2874c388d971ec5b6783347886c1
[openwrt/staging/chunkeey.git] / target / linux / sunxi / patches-3.14 / 195-1-ohci-plat-changes.patch
1 From 49ff47db168655cac5213cf5dd1844b08fb9823c Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Sun, 5 Jan 2014 14:42:39 +0100
4 Subject: [PATCH] ohci-platform: Add support for devicetree instantiation
5
6 Add support for ohci-platform instantiation from devicetree, including
7 optionally getting clks and a phy from devicetree, and enabling / disabling
8 those on power_on / off.
9
10 This should allow using ohci-platform from devicetree in various cases.
11 Specifically after this commit it can be used for the ohci controller found
12 on Allwinner sunxi SoCs.
13
14 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
15 Acked-by: Alan Stern <stern@rowland.harvard.edu>
16 ---
17 Documentation/devicetree/bindings/usb/usb-ohci.txt | 22 +++
18 drivers/usb/host/ohci-platform.c | 162 ++++++++++++++++++---
19 2 files changed, 162 insertions(+), 22 deletions(-)
20 create mode 100644 Documentation/devicetree/bindings/usb/usb-ohci.txt
21
22 diff --git a/Documentation/devicetree/bindings/usb/usb-ohci.txt b/Documentation/devicetree/bindings/usb/usb-ohci.txt
23 new file mode 100644
24 index 0000000..6ba38d9
25 --- /dev/null
26 +++ b/Documentation/devicetree/bindings/usb/usb-ohci.txt
27 @@ -0,0 +1,22 @@
28 +USB OHCI controllers
29 +
30 +Required properties:
31 +- compatible : "usb-ohci"
32 +- reg : ohci controller register range (address and length)
33 +- interrupts : ohci controller interrupt
34 +
35 +Optional properties:
36 +- clocks : a list of phandle + clock specifier pairs
37 +- phys : phandle + phy specifier pair
38 +- phy-names : "usb"
39 +
40 +Example:
41 +
42 + ohci0: usb@01c14400 {
43 + compatible = "allwinner,sun4i-a10-ohci", "usb-ohci";
44 + reg = <0x01c14400 0x100>;
45 + interrupts = <64>;
46 + clocks = <&usb_clk 6>, <&ahb_gates 2>;
47 + phys = <&usbphy 1>;
48 + phy-names = "usb";
49 + };
50 diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
51 index 68f674c..49304dd 100644
52 --- a/drivers/usb/host/ohci-platform.c
53 +++ b/drivers/usb/host/ohci-platform.c
54 @@ -3,6 +3,7 @@
55 *
56 * Copyright 2007 Michael Buesch <m@bues.ch>
57 * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
58 + * Copyright 2014 Hans de Goede <hdegoede@redhat.com>
59 *
60 * Derived from the OCHI-SSB driver
61 * Derived from the OHCI-PCI driver
62 @@ -14,11 +15,14 @@
63 * Licensed under the GNU/GPL. See COPYING for details.
64 */
65
66 +#include <linux/clk.h>
67 +#include <linux/dma-mapping.h>
68 #include <linux/hrtimer.h>
69 #include <linux/io.h>
70 #include <linux/kernel.h>
71 #include <linux/module.h>
72 #include <linux/err.h>
73 +#include <linux/phy/phy.h>
74 #include <linux/platform_device.h>
75 #include <linux/usb/ohci_pdriver.h>
76 #include <linux/usb.h>
77 @@ -27,6 +31,13 @@
78 #include "ohci.h"
79
80 #define DRIVER_DESC "OHCI generic platform driver"
81 +#define OHCI_MAX_CLKS 3
82 +#define hcd_to_ohci_priv(h) ((struct ohci_platform_priv *)hcd_to_ohci(h)->priv)
83 +
84 +struct ohci_platform_priv {
85 + struct clk *clks[OHCI_MAX_CLKS];
86 + struct phy *phy;
87 +};
88
89 static const char hcd_name[] = "ohci-platform";
90
91 @@ -48,11 +59,67 @@ static int ohci_platform_reset(struct usb_hcd *hcd)
92 return ohci_setup(hcd);
93 }
94
95 +static int ohci_platform_power_on(struct platform_device *dev)
96 +{
97 + struct usb_hcd *hcd = platform_get_drvdata(dev);
98 + struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
99 + int clk, ret;
100 +
101 + for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) {
102 + ret = clk_prepare_enable(priv->clks[clk]);
103 + if (ret)
104 + goto err_disable_clks;
105 + }
106 +
107 + if (priv->phy) {
108 + ret = phy_init(priv->phy);
109 + if (ret)
110 + goto err_disable_clks;
111 +
112 + ret = phy_power_on(priv->phy);
113 + if (ret)
114 + goto err_exit_phy;
115 + }
116 +
117 + return 0;
118 +
119 +err_exit_phy:
120 + phy_exit(priv->phy);
121 +err_disable_clks:
122 + while (--clk >= 0)
123 + clk_disable_unprepare(priv->clks[clk]);
124 +
125 + return ret;
126 +}
127 +
128 +static void ohci_platform_power_off(struct platform_device *dev)
129 +{
130 + struct usb_hcd *hcd = platform_get_drvdata(dev);
131 + struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
132 + int clk;
133 +
134 + if (priv->phy) {
135 + phy_power_off(priv->phy);
136 + phy_exit(priv->phy);
137 + }
138 +
139 + for (clk = OHCI_MAX_CLKS - 1; clk >= 0; clk--)
140 + if (priv->clks[clk])
141 + clk_disable_unprepare(priv->clks[clk]);
142 +}
143 +
144 static struct hc_driver __read_mostly ohci_platform_hc_driver;
145
146 static const struct ohci_driver_overrides platform_overrides __initconst = {
147 - .product_desc = "Generic Platform OHCI controller",
148 - .reset = ohci_platform_reset,
149 + .product_desc = "Generic Platform OHCI controller",
150 + .reset = ohci_platform_reset,
151 + .extra_priv_size = sizeof(struct ohci_platform_priv),
152 +};
153 +
154 +static struct usb_ohci_pdata ohci_platform_defaults = {
155 + .power_on = ohci_platform_power_on,
156 + .power_suspend = ohci_platform_power_off,
157 + .power_off = ohci_platform_power_off,
158 };
159
160 static int ohci_platform_probe(struct platform_device *dev)
161 @@ -60,17 +127,23 @@ static int ohci_platform_probe(struct platform_device *dev)
162 struct usb_hcd *hcd;
163 struct resource *res_mem;
164 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
165 - int irq;
166 - int err = -ENOMEM;
167 -
168 - if (!pdata) {
169 - WARN_ON(1);
170 - return -ENODEV;
171 - }
172 + struct ohci_platform_priv *priv;
173 + int err, irq, clk = 0;
174
175 if (usb_disabled())
176 return -ENODEV;
177
178 + /*
179 + * Use reasonable defaults so platforms don't have to provide these
180 + * with DT probing on ARM.
181 + */
182 + if (!pdata)
183 + pdata = &ohci_platform_defaults;
184 +
185 + err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32));
186 + if (err)
187 + return err;
188 +
189 irq = platform_get_irq(dev, 0);
190 if (irq < 0) {
191 dev_err(&dev->dev, "no irq provided");
192 @@ -83,17 +156,40 @@ static int ohci_platform_probe(struct platform_device *dev)
193 return -ENXIO;
194 }
195
196 + hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
197 + dev_name(&dev->dev));
198 + if (!hcd)
199 + return -ENOMEM;
200 +
201 + platform_set_drvdata(dev, hcd);
202 + dev->dev.platform_data = pdata;
203 + priv = hcd_to_ohci_priv(hcd);
204 +
205 + if (pdata == &ohci_platform_defaults && dev->dev.of_node) {
206 + priv->phy = devm_phy_get(&dev->dev, "usb");
207 + if (IS_ERR(priv->phy)) {
208 + err = PTR_ERR(priv->phy);
209 + if (err == -EPROBE_DEFER)
210 + goto err_put_hcd;
211 + priv->phy = NULL;
212 + }
213 +
214 + for (clk = 0; clk < OHCI_MAX_CLKS; clk++) {
215 + priv->clks[clk] = of_clk_get(dev->dev.of_node, clk);
216 + if (IS_ERR(priv->clks[clk])) {
217 + err = PTR_ERR(priv->clks[clk]);
218 + if (err == -EPROBE_DEFER)
219 + goto err_put_clks;
220 + priv->clks[clk] = NULL;
221 + break;
222 + }
223 + }
224 + }
225 +
226 if (pdata->power_on) {
227 err = pdata->power_on(dev);
228 if (err < 0)
229 - return err;
230 - }
231 -
232 - hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
233 - dev_name(&dev->dev));
234 - if (!hcd) {
235 - err = -ENOMEM;
236 - goto err_power;
237 + goto err_put_clks;
238 }
239
240 hcd->rsrc_start = res_mem->start;
241 @@ -102,11 +198,11 @@ static int ohci_platform_probe(struct platform_device *dev)
242 hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
243 if (IS_ERR(hcd->regs)) {
244 err = PTR_ERR(hcd->regs);
245 - goto err_put_hcd;
246 + goto err_power;
247 }
248 err = usb_add_hcd(hcd, irq, IRQF_SHARED);
249 if (err)
250 - goto err_put_hcd;
251 + goto err_power;
252
253 device_wakeup_enable(hcd->self.controller);
254
255 @@ -114,11 +210,17 @@ static int ohci_platform_probe(struct platform_device *dev)
256
257 return err;
258
259 -err_put_hcd:
260 - usb_put_hcd(hcd);
261 err_power:
262 if (pdata->power_off)
263 pdata->power_off(dev);
264 +err_put_clks:
265 + while (--clk >= 0)
266 + clk_put(priv->clks[clk]);
267 +err_put_hcd:
268 + if (pdata == &ohci_platform_defaults)
269 + dev->dev.platform_data = NULL;
270 +
271 + usb_put_hcd(hcd);
272
273 return err;
274 }
275 @@ -127,13 +229,22 @@ static int ohci_platform_remove(struct platform_device *dev)
276 {
277 struct usb_hcd *hcd = platform_get_drvdata(dev);
278 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
279 + struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd);
280 + int clk;
281
282 usb_remove_hcd(hcd);
283 - usb_put_hcd(hcd);
284
285 if (pdata->power_off)
286 pdata->power_off(dev);
287
288 + for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++)
289 + clk_put(priv->clks[clk]);
290 +
291 + usb_put_hcd(hcd);
292 +
293 + if (pdata == &ohci_platform_defaults)
294 + dev->dev.platform_data = NULL;
295 +
296 return 0;
297 }
298
299 @@ -180,6 +291,12 @@ static int ohci_platform_resume(struct device *dev)
300 #define ohci_platform_resume NULL
301 #endif /* CONFIG_PM */
302
303 +static const struct of_device_id ohci_platform_ids[] = {
304 + { .compatible = "usb-ohci", },
305 + { }
306 +};
307 +MODULE_DEVICE_TABLE(of, ohci_platform_ids);
308 +
309 static const struct platform_device_id ohci_platform_table[] = {
310 { "ohci-platform", 0 },
311 { }
312 @@ -200,6 +317,7 @@ static struct platform_driver ohci_platform_driver = {
313 .owner = THIS_MODULE,
314 .name = "ohci-platform",
315 .pm = &ohci_platform_pm_ops,
316 + .of_match_table = ohci_platform_ids,
317 }
318 };
319
320 --
321 2.0.3
322
323 From 8c4b97ea8b66e0fc8bdf648675e6889ce48c5ea7 Mon Sep 17 00:00:00 2001
324 From: Hans de Goede <hdegoede@redhat.com>
325 Date: Tue, 21 Jan 2014 16:05:47 +0100
326 Subject: [PATCH] ohci-platform: Add support for controllers with big-endian
327 regs / descriptors
328
329 Note this commit uses the same devicetree booleans for this as the ones
330 already existing in the usb-ehci bindings, see:
331 Documentation/devicetree/bindings/usb/usb-ehci.txt
332
333 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
334 ---
335 Documentation/devicetree/bindings/usb/usb-ohci.txt | 3 +++
336 drivers/usb/host/ohci-platform.c | 27 ++++++++++++++++++++++
337 2 files changed, 30 insertions(+)
338
339 diff --git a/Documentation/devicetree/bindings/usb/usb-ohci.txt b/Documentation/devicetree/bindings/usb/usb-ohci.txt
340 index 6ba38d9..6933b0c 100644
341 --- a/Documentation/devicetree/bindings/usb/usb-ohci.txt
342 +++ b/Documentation/devicetree/bindings/usb/usb-ohci.txt
343 @@ -6,6 +6,9 @@ Required properties:
344 - interrupts : ohci controller interrupt
345
346 Optional properties:
347 +- big-endian-regs : boolean, set this for hcds with big-endian registers
348 +- big-endian-desc : boolean, set this for hcds with big-endian descriptors
349 +- big-endian : boolean, for hcds with big-endian-regs + big-endian-desc
350 - clocks : a list of phandle + clock specifier pairs
351 - phys : phandle + phy specifier pair
352 - phy-names : "usb"
353 diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
354 index 49304dd..e2c28fd 100644
355 --- a/drivers/usb/host/ohci-platform.c
356 +++ b/drivers/usb/host/ohci-platform.c
357 @@ -128,6 +128,7 @@ static int ohci_platform_probe(struct platform_device *dev)
358 struct resource *res_mem;
359 struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
360 struct ohci_platform_priv *priv;
361 + struct ohci_hcd *ohci;
362 int err, irq, clk = 0;
363
364 if (usb_disabled())
365 @@ -164,8 +165,34 @@ static int ohci_platform_probe(struct platform_device *dev)
366 platform_set_drvdata(dev, hcd);
367 dev->dev.platform_data = pdata;
368 priv = hcd_to_ohci_priv(hcd);
369 + ohci = hcd_to_ohci(hcd);
370
371 if (pdata == &ohci_platform_defaults && dev->dev.of_node) {
372 + if (of_property_read_bool(dev->dev.of_node, "big-endian-regs"))
373 + ohci->flags |= OHCI_QUIRK_BE_MMIO;
374 +
375 + if (of_property_read_bool(dev->dev.of_node, "big-endian-desc"))
376 + ohci->flags |= OHCI_QUIRK_BE_DESC;
377 +
378 + if (of_property_read_bool(dev->dev.of_node, "big-endian"))
379 + ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC;
380 +
381 +#ifndef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO
382 + if (ohci->flags & OHCI_QUIRK_BE_MMIO) {
383 + dev_err(&dev->dev,
384 + "Error big-endian-regs not compiled in\n");
385 + err = -EINVAL;
386 + goto err_put_hcd;
387 + }
388 +#endif
389 +#ifndef CONFIG_USB_OHCI_BIG_ENDIAN_DESC
390 + if (ohci->flags & OHCI_QUIRK_BE_DESC) {
391 + dev_err(&dev->dev,
392 + "Error big-endian-desc not compiled in\n");
393 + err = -EINVAL;
394 + goto err_put_hcd;
395 + }
396 +#endif
397 priv->phy = devm_phy_get(&dev->dev, "usb");
398 if (IS_ERR(priv->phy)) {
399 err = PTR_ERR(priv->phy);
400 --
401 2.0.3
402
403 From ddf77eb2ec72a3676dabe17baf6e3b32ce0542e5 Mon Sep 17 00:00:00 2001
404 From: Hans de Goede <hdegoede@redhat.com>
405 Date: Tue, 11 Feb 2014 11:27:29 +0100
406 Subject: [PATCH] ohci-platform: Change compatible string from usb-ohci to
407 generic-ohci
408
409 The initial versions of the devicetree enablement patches for ohci-platform
410 used "ohci-platform" as compatible string. However this was disliked by various
411 reviewers because the platform bus is a Linux invention and devicetree is
412 supposed to be OS agnostic. After much discussion I gave up and went with
413 the generic usb-ohci as requested.
414
415 In retro-spect I should have chosen something different, the dts files for many
416 existing boards already claim to be compatible with "usb-ohci", ie they have:
417
418 compatible = "ti,ohci-omap3", "usb-ohci";
419
420 In theory this should not be a problem since the "ti,ohci-omap3" entry takes
421 presedence, but in practice using a conflicting compatible string is an issue,
422 because it makes which driver gets used depend on driver registration order.
423
424 This patch changes the compatible string claimed by ohci-platform to
425 "generic-ohci", avoiding the driver registration / module loading ordering
426 problems.
427
428 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
429 ---
430 Documentation/devicetree/bindings/usb/usb-ohci.txt | 4 ++--
431 drivers/usb/host/ohci-platform.c | 2 +-
432 2 files changed, 3 insertions(+), 3 deletions(-)
433
434 diff --git a/Documentation/devicetree/bindings/usb/usb-ohci.txt b/Documentation/devicetree/bindings/usb/usb-ohci.txt
435 index 6933b0c..45f67d9 100644
436 --- a/Documentation/devicetree/bindings/usb/usb-ohci.txt
437 +++ b/Documentation/devicetree/bindings/usb/usb-ohci.txt
438 @@ -1,7 +1,7 @@
439 USB OHCI controllers
440
441 Required properties:
442 -- compatible : "usb-ohci"
443 +- compatible : "generic-ohci"
444 - reg : ohci controller register range (address and length)
445 - interrupts : ohci controller interrupt
446
447 @@ -16,7 +16,7 @@ Optional properties:
448 Example:
449
450 ohci0: usb@01c14400 {
451 - compatible = "allwinner,sun4i-a10-ohci", "usb-ohci";
452 + compatible = "allwinner,sun4i-a10-ohci", "generic-ohci";
453 reg = <0x01c14400 0x100>;
454 interrupts = <64>;
455 clocks = <&usb_clk 6>, <&ahb_gates 2>;
456 diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
457 index e2c28fd..b6ca0b2 100644
458 --- a/drivers/usb/host/ohci-platform.c
459 +++ b/drivers/usb/host/ohci-platform.c
460 @@ -319,7 +319,7 @@ static int ohci_platform_resume(struct device *dev)
461 #endif /* CONFIG_PM */
462
463 static const struct of_device_id ohci_platform_ids[] = {
464 - { .compatible = "usb-ohci", },
465 + { .compatible = "generic-ohci", },
466 { }
467 };
468 MODULE_DEVICE_TABLE(of, ohci_platform_ids);
469 --
470 2.0.3
471