ar71xx: ethernet: cache skb->len in the tx function to avoid accessing it again in...
[openwrt.git] / target / linux / cns21xx / patches-3.8 / 103-cns21xx-usb-ohci-support.patch
1 --- a/drivers/usb/host/ohci-hcd.c
2 +++ b/drivers/usb/host/ohci-hcd.c
3 @@ -691,6 +691,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 @@ -1186,6 +1189,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 PLATFORM_DRIVER                ohci_cns21xx_driver
20 +#endif
21 +
22  #ifdef CONFIG_USB_OHCI_HCD_PLATFORM
23  #include "ohci-platform.c"
24  #define OHCI_PLATFORM_DRIVER           ohci_platform_driver
25 --- /dev/null
26 +++ b/drivers/usb/host/ohci-cns21xx.c
27 @@ -0,0 +1,178 @@
28 +/*
29 + *  Copyright (c) 2008 Cavium Networks
30 + *  Copyright (c) 2010-2012 Gabor Juhos <juhosg@openwrt.org>
31 + *
32 + *  This file is free software; you can redistribute it and/or modify
33 + *  it under the terms of the GNU General Public License, Version 2, as
34 + *  published by the Free Software Foundation.
35 + */
36 +
37 +#include <linux/platform_device.h>
38 +
39 +#include <mach/cns21xx.h>
40 +
41 +#define DRIVER_NAME    "cns21xx-ohci"
42 +
43 +static int cns21xx_ohci_start(struct usb_hcd *hcd)
44 +{
45 +       struct ohci_hcd *ohci = hcd_to_ohci(hcd);
46 +       int ret;
47 +
48 +       ret = ohci_init(ohci);
49 +       if (ret)
50 +               return ret;
51 +
52 +       ret = ohci_run(ohci);
53 +       if (ret) {
54 +               ohci_err(ohci, "can't start %s",
55 +                        ohci_to_hcd(ohci)->self.bus_name);
56 +               goto err;
57 +       }
58 +
59 +       return 0;
60 +
61 +err:
62 +       ohci_stop(hcd);
63 +       return ret;
64 +}
65 +
66 +static const struct hc_driver ohci_cns21xx_hc_driver = {
67 +       .description            = hcd_name,
68 +       .product_desc           = "cns21xx-ohci",
69 +       .hcd_priv_size          = sizeof(struct ohci_hcd),
70 +
71 +       /*
72 +        * generic hardware linkage
73 +        */
74 +       .irq                    = ohci_irq,
75 +       .flags                  = HCD_USB11 | HCD_MEMORY,
76 +
77 +       /*
78 +        * basic lifecycle operations
79 +        */
80 +       .start                  = cns21xx_ohci_start,
81 +       .stop                   = ohci_stop,
82 +       .shutdown               = ohci_shutdown,
83 +
84 +       /*
85 +        * managing i/o requests and associated device resources
86 +        */
87 +       .urb_enqueue            = ohci_urb_enqueue,
88 +       .urb_dequeue            = ohci_urb_dequeue,
89 +       .endpoint_disable       = ohci_endpoint_disable,
90 +
91 +       /*
92 +        * scheduling support
93 +        */
94 +       .get_frame_number       = ohci_get_frame,
95 +
96 +       /*
97 +        * root hub support
98 +        */
99 +       .hub_status_data        = ohci_hub_status_data,
100 +       .hub_control            = ohci_hub_control,
101 +       .start_port_reset       = ohci_start_port_reset,
102 +};
103 +
104 +static void cns21xx_ohci_init_hc(void)
105 +{
106 +       void __iomem *base = (void __iomem *) CNS21XX_OHCI_CONFIG_BASE_VIRT;
107 +
108 +       __raw_writel(0x146, base + 0x04);
109 +       __raw_writel(0x200, base + 0x44);
110 +       msleep(100);
111 +}
112 +
113 +static int ohci_cns21xx_probe(struct platform_device *pdev)
114 +{
115 +       struct usb_hcd *hcd;
116 +       struct resource *res;
117 +       struct ohci_hcd *ohci;
118 +       int irq;
119 +       int ret;
120 +
121 +       if (usb_disabled())
122 +               return -ENODEV;
123 +
124 +       res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
125 +       if (!res) {
126 +               dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
127 +                       dev_name(&pdev->dev));
128 +               return -ENODEV;
129 +       }
130 +       irq = res->start;
131 +
132 +       hcd = usb_create_hcd(&ohci_cns21xx_hc_driver, &pdev->dev,
133 +                            dev_name(&pdev->dev));
134 +       if (!hcd)
135 +               return -ENOMEM;
136 +
137 +       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
138 +       if (!res) {
139 +               dev_dbg(&pdev->dev, "no base address specified for %s\n",
140 +                       dev_name(&pdev->dev));
141 +               ret = -ENODEV;
142 +               goto err_put_hcd;
143 +       }
144 +       hcd->rsrc_start = res->start;
145 +       hcd->rsrc_len   = res->end - res->start + 1;
146 +
147 +       if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
148 +               dev_dbg(&pdev->dev, "controller already in use\n");
149 +               ret = -EBUSY;
150 +               goto err_put_hcd;
151 +       }
152 +
153 +       hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
154 +       if (!hcd->regs) {
155 +               dev_dbg(&pdev->dev, "error mapping memory\n");
156 +               ret = -EFAULT;
157 +               goto err_release_region;
158 +       }
159 +
160 +       cns21xx_ohci_init_hc();
161 +
162 +       ohci = hcd_to_ohci(hcd);
163 +       ohci->flags |= OHCI_QUIRK_INIT_FMINTERVAL;
164 +       ohci_hcd_init(ohci);
165 +
166 +       ret = usb_add_hcd(hcd, irq,  IRQF_DISABLED);
167 +       if (ret)
168 +               goto err_unmap;
169 +
170 +       platform_set_drvdata(pdev, hcd);
171 +       return 0;
172 +
173 +err_unmap:
174 +       iounmap(hcd->regs);
175 +err_release_region:
176 +       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
177 +err_put_hcd:
178 +       usb_put_hcd(hcd);
179 +       return ret;
180 +}
181 +
182 +static int ohci_cns21xx_remove(struct platform_device *pdev)
183 +{
184 +       struct usb_hcd *hcd = platform_get_drvdata(pdev);
185 +
186 +       usb_remove_hcd(hcd);
187 +       iounmap(hcd->regs);
188 +       release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
189 +       usb_put_hcd(hcd);
190 +       platform_set_drvdata(pdev, NULL);
191 +
192 +       return 0;
193 +}
194 +
195 +static struct platform_driver ohci_cns21xx_driver = {
196 +       .probe          = ohci_cns21xx_probe,
197 +       .remove         = ohci_cns21xx_remove,
198 +       .shutdown       = usb_hcd_platform_shutdown,
199 +       .driver         = {
200 +               .owner  = THIS_MODULE,
201 +               .name   = DRIVER_NAME,
202 +       },
203 +};
204 +
205 +MODULE_ALIAS("platform:" DRIVER_NAME);
206 --- a/drivers/usb/host/ohci.h
207 +++ b/drivers/usb/host/ohci.h
208 @@ -405,6 +405,7 @@ struct ohci_hcd {
209  #define        OHCI_QUIRK_HUB_POWER    0x100                   /* distrust firmware power/oc setup */
210  #define        OHCI_QUIRK_AMD_PLL      0x200                   /* AMD PLL quirk*/
211  #define        OHCI_QUIRK_AMD_PREFETCH 0x400                   /* pre-fetch for ISO transfer */
212 +#define        OHCI_QUIRK_INIT_FMINTERVAL 0x1000               /* fminterval must be initialized */
213         // there are also chip quirks/bugs in init logic
214  
215         struct work_struct      nec_work;       /* Worker for NEC quirk */
216 --- a/arch/arm/Kconfig
217 +++ b/arch/arm/Kconfig
218 @@ -381,6 +381,7 @@ config ARCH_CNS21XX
219         select PLAT_FA_GPIO
220         select ARCH_REQUIRE_GPIOLIB
221         select ARM_L1_CACHE_SHIFT_4
222 +       select USB_ARCH_HAS_OHCI
223         help
224           Support for Cavium Networks CNS21xx family.
225