kernel: update 3.10 to 3.10.17
[openwrt.git] / target / linux / cns21xx / patches-3.10 / 103-cns21xx-usb-ohci-support.patch
1 --- a/drivers/usb/host/ohci-hcd.c
2 +++ b/drivers/usb/host/ohci-hcd.c
3 @@ -697,6 +697,9 @@ retry:
4  
5         periodic_reinit (ohci);
6  
7 +       if (ohci->flags & OHCI_QUIRK_INIT_FMINTERVAL)
8 +               ohci_writel (ohci, ohci->fminterval, &ohci->regs->fminterval);
9 +
10         /* some OHCI implementations are finicky about how they init.
11          * bogus values here mean not even enumeration could work.
12          */
13 @@ -1191,6 +1194,11 @@ MODULE_LICENSE ("GPL");
14  #define PLATFORM_DRIVER                ohci_hcd_tilegx_driver
15  #endif
16  
17 +#ifdef CONFIG_ARCH_CNS21XX
18 +#include "ohci-cns21xx.c"
19 +#define CNS21XX_PLATFORM_DRIVER                ohci_cns21xx_driver
20 +#endif
21 +
22  #ifdef CONFIG_USB_OHCI_HCD_PLATFORM
23  #include "ohci-platform.c"
24  #define PLATFORM_DRIVER                ohci_platform_driver
25 @@ -1211,7 +1219,8 @@ MODULE_LICENSE ("GPL");
26         !defined(AT91_PLATFORM_DRIVER) && \
27         !defined(NXP_PLATFORM_DRIVER) && \
28         !defined(DAVINCI_PLATFORM_DRIVER) && \
29 -       !defined(SPEAR_PLATFORM_DRIVER)
30 +       !defined(SPEAR_PLATFORM_DRIVER) && \
31 +       !defined(CNS21XX_PLATFORM_DRIVER)
32  #error "missing bus glue for ohci-hcd"
33  #endif
34  
35 @@ -1331,9 +1340,19 @@ static int __init ohci_hcd_mod_init(void
36                 goto error_spear;
37  #endif
38  
39 +#ifdef CNS21XX_PLATFORM_DRIVER
40 +       retval = platform_driver_register(&CNS21XX_PLATFORM_DRIVER);
41 +       if (retval < 0)
42 +               goto error_cns21xx;
43 +#endif
44 +
45         return retval;
46  
47         /* Error path */
48 +#ifdef CNS21XX_PLATFORM_DRIVER
49 +       platform_driver_unregister(&CNS21XX_PLATFORM_DRIVER);
50 + error_cns21xx:
51 +#endif
52  #ifdef SPEAR_PLATFORM_DRIVER
53         platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
54   error_spear:
55 @@ -1411,6 +1430,9 @@ module_init(ohci_hcd_mod_init);
56  
57  static void __exit ohci_hcd_mod_exit(void)
58  {
59 +#ifdef CNS21XX_PLATFORM_DRIVER
60 +       platform_driver_unregister(&CNS21XX_PLATFORM_DRIVER);
61 +#endif
62  #ifdef SPEAR_PLATFORM_DRIVER
63         platform_driver_unregister(&SPEAR_PLATFORM_DRIVER);
64  #endif
65 --- /dev/null
66 +++ b/drivers/usb/host/ohci-cns21xx.c
67 @@ -0,0 +1,178 @@
68 +/*
69 + *  Copyright (c) 2008 Cavium Networks
70 + *  Copyright (c) 2010-2012 Gabor Juhos <juhosg@openwrt.org>
71 + *
72 + *  This file is free software; you can redistribute it and/or modify
73 + *  it under the terms of the GNU General Public License, Version 2, as
74 + *  published by the Free Software Foundation.
75 + */
76 +
77 +#include <linux/platform_device.h>
78 +
79 +#include <mach/cns21xx.h>
80 +
81 +#define DRIVER_NAME    "cns21xx-ohci"
82 +
83 +static int cns21xx_ohci_start(struct usb_hcd *hcd)
84 +{
85 +       struct ohci_hcd *ohci = hcd_to_ohci(hcd);
86 +       int ret;
87 +
88 +       ret = ohci_init(ohci);
89 +       if (ret)
90 +               return ret;
91 +
92 +       ret = ohci_run(ohci);
93 +       if (ret) {
94 +               ohci_err(ohci, "can't start %s",
95 +                        ohci_to_hcd(ohci)->self.bus_name);
96 +               goto err;
97 +       }
98 +
99 +       return 0;
100 +
101 +err:
102 +       ohci_stop(hcd);
103 +       return ret;
104 +}
105 +
106 +static const struct hc_driver ohci_cns21xx_hc_driver = {
107 +       .description            = hcd_name,
108 +       .product_desc           = "cns21xx-ohci",
109 +       .hcd_priv_size          = sizeof(struct ohci_hcd),
110 +
111 +       /*
112 +        * generic hardware linkage
113 +        */
114 +       .irq                    = ohci_irq,
115 +       .flags                  = HCD_USB11 | HCD_MEMORY,
116 +
117 +       /*
118 +        * basic lifecycle operations
119 +        */
120 +       .start                  = cns21xx_ohci_start,
121 +       .stop                   = ohci_stop,
122 +       .shutdown               = ohci_shutdown,
123 +
124 +       /*
125 +        * managing i/o requests and associated device resources
126 +        */
127 +       .urb_enqueue            = ohci_urb_enqueue,
128 +       .urb_dequeue            = ohci_urb_dequeue,
129 +       .endpoint_disable       = ohci_endpoint_disable,
130 +
131 +       /*
132 +        * scheduling support
133 +        */
134 +       .get_frame_number       = ohci_get_frame,
135 +
136 +       /*
137 +        * root hub support
138 +        */
139 +       .hub_status_data        = ohci_hub_status_data,
140 +       .hub_control            = ohci_hub_control,
141 +       .start_port_reset       = ohci_start_port_reset,
142 +};
143 +
144 +static void cns21xx_ohci_init_hc(void)
145 +{
146 +       void __iomem *base = (void __iomem *) CNS21XX_OHCI_CONFIG_BASE_VIRT;
147 +
148 +       __raw_writel(0x146, base + 0x04);
149 +       __raw_writel(0x200, base + 0x44);
150 +       msleep(100);
151 +}
152 +
153 +static int ohci_cns21xx_probe(struct platform_device *pdev)
154 +{
155 +       struct usb_hcd *hcd;
156 +       struct resource *res;
157 +       struct ohci_hcd *ohci;
158 +       int irq;
159 +       int ret;
160 +
161 +       if (usb_disabled())
162 +               return -ENODEV;
163 +
164 +       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
165 +       if (!res) {
166 +               dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
167 +                       dev_name(&pdev->dev));
168 +               return -ENODEV;
169 +       }
170 +       irq = res->start;
171 +
172 +       hcd = usb_create_hcd(&ohci_cns21xx_hc_driver, &pdev->dev,
173 +                            dev_name(&pdev->dev));
174 +       if (!hcd)
175 +               return -ENOMEM;
176 +
177 +       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
178 +       if (!res) {
179 +               dev_dbg(&pdev->dev, "no base address specified for %s\n",
180 +                       dev_name(&pdev->dev));
181 +               ret = -ENODEV;
182 +               goto err_put_hcd;
183 +       }
184 +       hcd->rsrc_start = res->start;
185 +       hcd->rsrc_len   = res->end - res->start + 1;
186 +
187 +       if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
188 +               dev_dbg(&pdev->dev, "controller already in use\n");
189 +               ret = -EBUSY;
190 +               goto err_put_hcd;
191 +       }
192 +
193 +       hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
194 +       if (!hcd->regs) {
195 +               dev_dbg(&pdev->dev, "error mapping memory\n");
196 +               ret = -EFAULT;
197 +               goto err_release_region;
198 +       }
199 +
200 +       cns21xx_ohci_init_hc();
201 +
202 +       ohci = hcd_to_ohci(hcd);
203 +       ohci->flags |= OHCI_QUIRK_INIT_FMINTERVAL;
204 +       ohci_hcd_init(ohci);
205 +
206 +       ret = usb_add_hcd(hcd, irq,  IRQF_DISABLED);
207 +       if (ret)
208 +               goto err_unmap;
209 +
210 +       platform_set_drvdata(pdev, hcd);
211 +       return 0;
212 +
213 +err_unmap:
214 +       iounmap(hcd->regs);
215 +err_release_region:
216 +       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
217 +err_put_hcd:
218 +       usb_put_hcd(hcd);
219 +       return ret;
220 +}
221 +
222 +static int ohci_cns21xx_remove(struct platform_device *pdev)
223 +{
224 +       struct usb_hcd *hcd = platform_get_drvdata(pdev);
225 +
226 +       usb_remove_hcd(hcd);
227 +       iounmap(hcd->regs);
228 +       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
229 +       usb_put_hcd(hcd);
230 +       platform_set_drvdata(pdev, NULL);
231 +
232 +       return 0;
233 +}
234 +
235 +static struct platform_driver ohci_cns21xx_driver = {
236 +       .probe          = ohci_cns21xx_probe,
237 +       .remove         = ohci_cns21xx_remove,
238 +       .shutdown       = usb_hcd_platform_shutdown,
239 +       .driver         = {
240 +               .owner  = THIS_MODULE,
241 +               .name   = DRIVER_NAME,
242 +       },
243 +};
244 +
245 +MODULE_ALIAS("platform:" DRIVER_NAME);
246 --- a/drivers/usb/host/ohci.h
247 +++ b/drivers/usb/host/ohci.h
248 @@ -405,6 +405,7 @@ struct ohci_hcd {
249  #define        OHCI_QUIRK_HUB_POWER    0x100                   /* distrust firmware power/oc setup */
250  #define        OHCI_QUIRK_AMD_PLL      0x200                   /* AMD PLL quirk*/
251  #define        OHCI_QUIRK_AMD_PREFETCH 0x400                   /* pre-fetch for ISO transfer */
252 +#define        OHCI_QUIRK_INIT_FMINTERVAL 0x1000               /* fminterval must be initialized */
253         // there are also chip quirks/bugs in init logic
254  
255         struct work_struct      nec_work;       /* Worker for NEC quirk */
256 --- a/arch/arm/Kconfig
257 +++ b/arch/arm/Kconfig
258 @@ -374,6 +374,7 @@ config ARCH_CNS21XX
259         select PLAT_FA_GPIO
260         select ARCH_REQUIRE_GPIOLIB
261         select ARM_L1_CACHE_SHIFT_4
262 +       select USB_ARCH_HAS_OHCI
263         help
264           Support for Cavium Networks CNS21xx family.
265