ar71xx: make AR8327 LEDs working on the DB120 board
[openwrt.git] / target / linux / ar71xx / patches-3.3 / 002-USB-use-generic-platform-driver-on-ath79.patch
1 From dbcbcdd001c5943adbb18db3b8f0dafc405559eb Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Tue, 13 Mar 2012 01:04:53 +0100
4 Subject: [PATCH 03/47] USB: use generic platform driver on ath79
5
6 The ath79 usb driver doesn't do anything special and is now converted
7 to the generic ehci and ohci driver.
8 This was tested on a TP-Link TL-WR1043ND (AR9132)
9
10 Acked-by: Gabor Juhos <juhosg@openwrt.org>
11 CC: Imre Kaloz <kaloz@openwrt.org>
12 CC: linux-mips@linux-mips.org
13 CC: Ralf Baechle <ralf@linux-mips.org>
14 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
15 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
16 ---
17  arch/mips/ath79/dev-usb.c     |   31 +++++-
18  drivers/usb/host/Kconfig      |   12 ++-
19  drivers/usb/host/ehci-ath79.c |  208 -----------------------------------------
20  drivers/usb/host/ehci-hcd.c   |    5 -
21  drivers/usb/host/ohci-ath79.c |  151 -----------------------------
22  drivers/usb/host/ohci-hcd.c   |    5 -
23  6 files changed, 35 insertions(+), 377 deletions(-)
24  delete mode 100644 drivers/usb/host/ehci-ath79.c
25  delete mode 100644 drivers/usb/host/ohci-ath79.c
26
27 --- a/arch/mips/ath79/dev-usb.c
28 +++ b/arch/mips/ath79/dev-usb.c
29 @@ -17,6 +17,8 @@
30  #include <linux/irq.h>
31  #include <linux/dma-mapping.h>
32  #include <linux/platform_device.h>
33 +#include <linux/usb/ehci_pdriver.h>
34 +#include <linux/usb/ohci_pdriver.h>
35  
36  #include <asm/mach-ath79/ath79.h>
37  #include <asm/mach-ath79/ar71xx_regs.h>
38 @@ -36,14 +38,19 @@ static struct resource ath79_ohci_resour
39  };
40  
41  static u64 ath79_ohci_dmamask = DMA_BIT_MASK(32);
42 +
43 +static struct usb_ohci_pdata ath79_ohci_pdata = {
44 +};
45 +
46  static struct platform_device ath79_ohci_device = {
47 -       .name           = "ath79-ohci",
48 +       .name           = "ohci-platform",
49         .id             = -1,
50         .resource       = ath79_ohci_resources,
51         .num_resources  = ARRAY_SIZE(ath79_ohci_resources),
52         .dev = {
53                 .dma_mask               = &ath79_ohci_dmamask,
54                 .coherent_dma_mask      = DMA_BIT_MASK(32),
55 +               .platform_data          = &ath79_ohci_pdata,
56         },
57  };
58  
59 @@ -60,8 +67,20 @@ static struct resource ath79_ehci_resour
60  };
61  
62  static u64 ath79_ehci_dmamask = DMA_BIT_MASK(32);
63 +
64 +static struct usb_ehci_pdata ath79_ehci_pdata_v1 = {
65 +       .has_synopsys_hc_bug    = 1,
66 +       .port_power_off         = 1,
67 +};
68 +
69 +static struct usb_ehci_pdata ath79_ehci_pdata_v2 = {
70 +       .caps_offset            = 0x100,
71 +       .has_tt                 = 1,
72 +       .port_power_off         = 1,
73 +};
74 +
75  static struct platform_device ath79_ehci_device = {
76 -       .name           = "ath79-ehci",
77 +       .name           = "ehci-platform",
78         .id             = -1,
79         .resource       = ath79_ehci_resources,
80         .num_resources  = ARRAY_SIZE(ath79_ehci_resources),
81 @@ -101,7 +120,7 @@ static void __init ath79_usb_setup(void)
82  
83         ath79_ehci_resources[0].start = AR71XX_EHCI_BASE;
84         ath79_ehci_resources[0].end = AR71XX_EHCI_BASE + AR71XX_EHCI_SIZE - 1;
85 -       ath79_ehci_device.name = "ar71xx-ehci";
86 +       ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v1;
87         platform_device_register(&ath79_ehci_device);
88  }
89  
90 @@ -142,7 +161,7 @@ static void __init ar724x_usb_setup(void
91  
92         ath79_ehci_resources[0].start = AR724X_EHCI_BASE;
93         ath79_ehci_resources[0].end = AR724X_EHCI_BASE + AR724X_EHCI_SIZE - 1;
94 -       ath79_ehci_device.name = "ar724x-ehci";
95 +       ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v2;
96         platform_device_register(&ath79_ehci_device);
97  }
98  
99 @@ -159,7 +178,7 @@ static void __init ar913x_usb_setup(void
100  
101         ath79_ehci_resources[0].start = AR913X_EHCI_BASE;
102         ath79_ehci_resources[0].end = AR913X_EHCI_BASE + AR913X_EHCI_SIZE - 1;
103 -       ath79_ehci_device.name = "ar913x-ehci";
104 +       ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v2;
105         platform_device_register(&ath79_ehci_device);
106  }
107  
108 @@ -176,7 +195,7 @@ static void __init ar933x_usb_setup(void
109  
110         ath79_ehci_resources[0].start = AR933X_EHCI_BASE;
111         ath79_ehci_resources[0].end = AR933X_EHCI_BASE + AR933X_EHCI_SIZE - 1;
112 -       ath79_ehci_device.name = "ar933x-ehci";
113 +       ath79_ehci_device.dev.platform_data = &ath79_ehci_pdata_v2;
114         platform_device_register(&ath79_ehci_device);
115  }
116  
117 --- a/drivers/usb/host/Kconfig
118 +++ b/drivers/usb/host/Kconfig
119 @@ -218,11 +218,15 @@ config USB_CNS3XXX_EHCI
120           support.
121  
122  config USB_EHCI_ATH79
123 -       bool "EHCI support for AR7XXX/AR9XXX SoCs"
124 +       bool "EHCI support for AR7XXX/AR9XXX SoCs (DEPRECATED)"
125         depends on USB_EHCI_HCD && (SOC_AR71XX || SOC_AR724X || SOC_AR913X || SOC_AR933X)
126         select USB_EHCI_ROOT_HUB_TT
127 +       select USB_EHCI_HCD_PLATFORM
128         default y
129         ---help---
130 +         This option is deprecated now and the driver was removed, use
131 +         USB_EHCI_HCD_PLATFORM instead.
132 +
133           Enables support for the built-in EHCI controller present
134           on the Atheros AR7XXX/AR9XXX SoCs.
135  
136 @@ -312,10 +316,14 @@ config USB_OHCI_HCD_OMAP3
137           OMAP3 and later chips.
138  
139  config USB_OHCI_ATH79
140 -       bool "USB OHCI support for the Atheros AR71XX/AR7240 SoCs"
141 +       bool "USB OHCI support for the Atheros AR71XX/AR7240 SoCs (DEPRECATED)"
142         depends on USB_OHCI_HCD && (SOC_AR71XX || SOC_AR724X)
143 +       select USB_OHCI_HCD_PLATFORM
144         default y
145         help
146 +         This option is deprecated now and the driver was removed, use
147 +         USB_OHCI_HCD_PLATFORM instead.
148 +
149           Enables support for the built-in OHCI controller present on the
150           Atheros AR71XX/AR7240 SoCs.
151  
152 --- a/drivers/usb/host/ehci-ath79.c
153 +++ /dev/null
154 @@ -1,208 +0,0 @@
155 -/*
156 - *  Bus Glue for Atheros AR7XXX/AR9XXX built-in EHCI controller.
157 - *
158 - *  Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
159 - *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
160 - *
161 - *  Parts of this file are based on Atheros' 2.6.15 BSP
162 - *     Copyright (C) 2007 Atheros Communications, Inc.
163 - *
164 - *  This program is free software; you can redistribute it and/or modify it
165 - *  under the terms of the GNU General Public License version 2 as published
166 - *  by the Free Software Foundation.
167 - */
168 -
169 -#include <linux/platform_device.h>
170 -
171 -enum {
172 -       EHCI_ATH79_IP_V1 = 0,
173 -       EHCI_ATH79_IP_V2,
174 -};
175 -
176 -static const struct platform_device_id ehci_ath79_id_table[] = {
177 -       {
178 -               .name           = "ar71xx-ehci",
179 -               .driver_data    = EHCI_ATH79_IP_V1,
180 -       },
181 -       {
182 -               .name           = "ar724x-ehci",
183 -               .driver_data    = EHCI_ATH79_IP_V2,
184 -       },
185 -       {
186 -               .name           = "ar913x-ehci",
187 -               .driver_data    = EHCI_ATH79_IP_V2,
188 -       },
189 -       {
190 -               .name           = "ar933x-ehci",
191 -               .driver_data    = EHCI_ATH79_IP_V2,
192 -       },
193 -       {
194 -               /* terminating entry */
195 -       },
196 -};
197 -
198 -MODULE_DEVICE_TABLE(platform, ehci_ath79_id_table);
199 -
200 -static int ehci_ath79_init(struct usb_hcd *hcd)
201 -{
202 -       struct ehci_hcd *ehci = hcd_to_ehci(hcd);
203 -       struct platform_device *pdev = to_platform_device(hcd->self.controller);
204 -       const struct platform_device_id *id;
205 -       int ret;
206 -
207 -       id = platform_get_device_id(pdev);
208 -       if (!id) {
209 -               dev_err(hcd->self.controller, "missing device id\n");
210 -               return -EINVAL;
211 -       }
212 -
213 -       switch (id->driver_data) {
214 -       case EHCI_ATH79_IP_V1:
215 -               ehci->has_synopsys_hc_bug = 1;
216 -
217 -               ehci->caps = hcd->regs;
218 -               ehci->regs = hcd->regs +
219 -                       HC_LENGTH(ehci,
220 -                                 ehci_readl(ehci, &ehci->caps->hc_capbase));
221 -               break;
222 -
223 -       case EHCI_ATH79_IP_V2:
224 -               hcd->has_tt = 1;
225 -
226 -               ehci->caps = hcd->regs + 0x100;
227 -               ehci->regs = hcd->regs + 0x100 +
228 -                       HC_LENGTH(ehci,
229 -                                 ehci_readl(ehci, &ehci->caps->hc_capbase));
230 -               break;
231 -
232 -       default:
233 -               BUG();
234 -       }
235 -
236 -       dbg_hcs_params(ehci, "reset");
237 -       dbg_hcc_params(ehci, "reset");
238 -       ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
239 -       ehci->sbrn = 0x20;
240 -
241 -       ehci_reset(ehci);
242 -
243 -       ret = ehci_init(hcd);
244 -       if (ret)
245 -               return ret;
246 -
247 -       ehci_port_power(ehci, 0);
248 -
249 -       return 0;
250 -}
251 -
252 -static const struct hc_driver ehci_ath79_hc_driver = {
253 -       .description            = hcd_name,
254 -       .product_desc           = "Atheros built-in EHCI controller",
255 -       .hcd_priv_size          = sizeof(struct ehci_hcd),
256 -       .irq                    = ehci_irq,
257 -       .flags                  = HCD_MEMORY | HCD_USB2,
258 -
259 -       .reset                  = ehci_ath79_init,
260 -       .start                  = ehci_run,
261 -       .stop                   = ehci_stop,
262 -       .shutdown               = ehci_shutdown,
263 -
264 -       .urb_enqueue            = ehci_urb_enqueue,
265 -       .urb_dequeue            = ehci_urb_dequeue,
266 -       .endpoint_disable       = ehci_endpoint_disable,
267 -       .endpoint_reset         = ehci_endpoint_reset,
268 -
269 -       .get_frame_number       = ehci_get_frame,
270 -
271 -       .hub_status_data        = ehci_hub_status_data,
272 -       .hub_control            = ehci_hub_control,
273 -
274 -       .relinquish_port        = ehci_relinquish_port,
275 -       .port_handed_over       = ehci_port_handed_over,
276 -
277 -       .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
278 -};
279 -
280 -static int ehci_ath79_probe(struct platform_device *pdev)
281 -{
282 -       struct usb_hcd *hcd;
283 -       struct resource *res;
284 -       int irq;
285 -       int ret;
286 -
287 -       if (usb_disabled())
288 -               return -ENODEV;
289 -
290 -       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
291 -       if (!res) {
292 -               dev_dbg(&pdev->dev, "no IRQ specified\n");
293 -               return -ENODEV;
294 -       }
295 -       irq = res->start;
296 -
297 -       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
298 -       if (!res) {
299 -               dev_dbg(&pdev->dev, "no base address specified\n");
300 -               return -ENODEV;
301 -       }
302 -
303 -       hcd = usb_create_hcd(&ehci_ath79_hc_driver, &pdev->dev,
304 -                            dev_name(&pdev->dev));
305 -       if (!hcd)
306 -               return -ENOMEM;
307 -
308 -       hcd->rsrc_start = res->start;
309 -       hcd->rsrc_len   = resource_size(res);
310 -
311 -       if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
312 -               dev_dbg(&pdev->dev, "controller already in use\n");
313 -               ret = -EBUSY;
314 -               goto err_put_hcd;
315 -       }
316 -
317 -       hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
318 -       if (!hcd->regs) {
319 -               dev_dbg(&pdev->dev, "error mapping memory\n");
320 -               ret = -EFAULT;
321 -               goto err_release_region;
322 -       }
323 -
324 -       ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
325 -       if (ret)
326 -               goto err_iounmap;
327 -
328 -       return 0;
329 -
330 -err_iounmap:
331 -       iounmap(hcd->regs);
332 -
333 -err_release_region:
334 -       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
335 -err_put_hcd:
336 -       usb_put_hcd(hcd);
337 -       return ret;
338 -}
339 -
340 -static int ehci_ath79_remove(struct platform_device *pdev)
341 -{
342 -       struct usb_hcd *hcd = platform_get_drvdata(pdev);
343 -
344 -       usb_remove_hcd(hcd);
345 -       iounmap(hcd->regs);
346 -       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
347 -       usb_put_hcd(hcd);
348 -
349 -       return 0;
350 -}
351 -
352 -static struct platform_driver ehci_ath79_driver = {
353 -       .probe          = ehci_ath79_probe,
354 -       .remove         = ehci_ath79_remove,
355 -       .id_table       = ehci_ath79_id_table,
356 -       .driver = {
357 -               .owner  = THIS_MODULE,
358 -               .name   = "ath79-ehci",
359 -       }
360 -};
361 -
362 -MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ath79-ehci");
363 --- a/drivers/usb/host/ehci-hcd.c
364 +++ b/drivers/usb/host/ehci-hcd.c
365 @@ -1356,11 +1356,6 @@ MODULE_LICENSE ("GPL");
366  #define PLATFORM_DRIVER                s5p_ehci_driver
367  #endif
368  
369 -#ifdef CONFIG_USB_EHCI_ATH79
370 -#include "ehci-ath79.c"
371 -#define PLATFORM_DRIVER                ehci_ath79_driver
372 -#endif
373 -
374  #ifdef CONFIG_SPARC_LEON
375  #include "ehci-grlib.c"
376  #define PLATFORM_DRIVER                ehci_grlib_driver
377 --- a/drivers/usb/host/ohci-ath79.c
378 +++ /dev/null
379 @@ -1,151 +0,0 @@
380 -/*
381 - *  OHCI HCD (Host Controller Driver) for USB.
382 - *
383 - *  Bus Glue for Atheros AR71XX/AR724X built-in OHCI controller.
384 - *
385 - *  Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
386 - *  Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
387 - *
388 - *  Parts of this file are based on Atheros' 2.6.15 BSP
389 - *     Copyright (C) 2007 Atheros Communications, Inc.
390 - *
391 - *  This program is free software; you can redistribute it and/or modify it
392 - *  under the terms of the GNU General Public License version 2 as published
393 - *  by the Free Software Foundation.
394 - */
395 -
396 -#include <linux/platform_device.h>
397 -
398 -static int __devinit ohci_ath79_start(struct usb_hcd *hcd)
399 -{
400 -       struct ohci_hcd *ohci = hcd_to_ohci(hcd);
401 -       int ret;
402 -
403 -       ret = ohci_init(ohci);
404 -       if (ret < 0)
405 -               return ret;
406 -
407 -       ret = ohci_run(ohci);
408 -       if (ret < 0)
409 -               goto err;
410 -
411 -       return 0;
412 -
413 -err:
414 -       ohci_stop(hcd);
415 -       return ret;
416 -}
417 -
418 -static const struct hc_driver ohci_ath79_hc_driver = {
419 -       .description            = hcd_name,
420 -       .product_desc           = "Atheros built-in OHCI controller",
421 -       .hcd_priv_size          = sizeof(struct ohci_hcd),
422 -
423 -       .irq                    = ohci_irq,
424 -       .flags                  = HCD_USB11 | HCD_MEMORY,
425 -
426 -       .start                  = ohci_ath79_start,
427 -       .stop                   = ohci_stop,
428 -       .shutdown               = ohci_shutdown,
429 -
430 -       .urb_enqueue            = ohci_urb_enqueue,
431 -       .urb_dequeue            = ohci_urb_dequeue,
432 -       .endpoint_disable       = ohci_endpoint_disable,
433 -
434 -       /*
435 -        * scheduling support
436 -        */
437 -       .get_frame_number       = ohci_get_frame,
438 -
439 -       /*
440 -        * root hub support
441 -        */
442 -       .hub_status_data        = ohci_hub_status_data,
443 -       .hub_control            = ohci_hub_control,
444 -       .start_port_reset       = ohci_start_port_reset,
445 -};
446 -
447 -static int ohci_ath79_probe(struct platform_device *pdev)
448 -{
449 -       struct usb_hcd *hcd;
450 -       struct resource *res;
451 -       int irq;
452 -       int ret;
453 -
454 -       if (usb_disabled())
455 -               return -ENODEV;
456 -
457 -       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
458 -       if (!res) {
459 -               dev_dbg(&pdev->dev, "no IRQ specified\n");
460 -               return -ENODEV;
461 -       }
462 -       irq = res->start;
463 -
464 -       hcd = usb_create_hcd(&ohci_ath79_hc_driver, &pdev->dev,
465 -                            dev_name(&pdev->dev));
466 -       if (!hcd)
467 -               return -ENOMEM;
468 -
469 -       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
470 -       if (!res) {
471 -               dev_dbg(&pdev->dev, "no base address specified\n");
472 -               ret = -ENODEV;
473 -               goto err_put_hcd;
474 -       }
475 -       hcd->rsrc_start = res->start;
476 -       hcd->rsrc_len = resource_size(res);
477 -
478 -       if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
479 -               dev_dbg(&pdev->dev, "controller already in use\n");
480 -               ret = -EBUSY;
481 -               goto err_put_hcd;
482 -       }
483 -
484 -       hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
485 -       if (!hcd->regs) {
486 -               dev_dbg(&pdev->dev, "error mapping memory\n");
487 -               ret = -EFAULT;
488 -               goto err_release_region;
489 -       }
490 -
491 -       ohci_hcd_init(hcd_to_ohci(hcd));
492 -
493 -       ret = usb_add_hcd(hcd, irq, 0);
494 -       if (ret)
495 -               goto err_stop_hcd;
496 -
497 -       return 0;
498 -
499 -err_stop_hcd:
500 -       iounmap(hcd->regs);
501 -err_release_region:
502 -       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
503 -err_put_hcd:
504 -       usb_put_hcd(hcd);
505 -       return ret;
506 -}
507 -
508 -static int ohci_ath79_remove(struct platform_device *pdev)
509 -{
510 -       struct usb_hcd *hcd = platform_get_drvdata(pdev);
511 -
512 -       usb_remove_hcd(hcd);
513 -       iounmap(hcd->regs);
514 -       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
515 -       usb_put_hcd(hcd);
516 -
517 -       return 0;
518 -}
519 -
520 -static struct platform_driver ohci_hcd_ath79_driver = {
521 -       .probe          = ohci_ath79_probe,
522 -       .remove         = ohci_ath79_remove,
523 -       .shutdown       = usb_hcd_platform_shutdown,
524 -       .driver         = {
525 -               .name   = "ath79-ohci",
526 -               .owner  = THIS_MODULE,
527 -       },
528 -};
529 -
530 -MODULE_ALIAS(PLATFORM_MODULE_PREFIX "ath79-ohci");
531 --- a/drivers/usb/host/ohci-hcd.c
532 +++ b/drivers/usb/host/ohci-hcd.c
533 @@ -1111,11 +1111,6 @@ MODULE_LICENSE ("GPL");
534  #define PLATFORM_DRIVER                ohci_hcd_cns3xxx_driver
535  #endif
536  
537 -#ifdef CONFIG_USB_OHCI_ATH79
538 -#include "ohci-ath79.c"
539 -#define PLATFORM_DRIVER                ohci_hcd_ath79_driver
540 -#endif
541 -
542  #ifdef CONFIG_CPU_XLR
543  #include "ohci-xls.c"
544  #define PLATFORM_DRIVER                ohci_xls_driver