kernel: update linux 3.8 to 3.8.6
[openwrt/svn-archive/archive.git] / target / linux / cns21xx / patches-3.8 / 104-cns21xx-usb-ehci-support.patch
1 --- a/drivers/usb/host/ehci-hcd.c
2 +++ b/drivers/usb/host/ehci-hcd.c
3 @@ -1341,6 +1341,11 @@ MODULE_LICENSE ("GPL");
4 #define PLATFORM_DRIVER ehci_hcd_sead3_driver
5 #endif
6
7 +#ifdef CONFIG_ARCH_CNS21XX
8 +#include "ehci-cns21xx.c"
9 +#define PLATFORM_DRIVER ehci_cns21xx_driver
10 +#endif
11 +
12 #if !IS_ENABLED(CONFIG_USB_EHCI_PCI) && \
13 !IS_ENABLED(CONFIG_USB_EHCI_HCD_PLATFORM) && \
14 !IS_ENABLED(CONFIG_USB_CHIPIDEA_HOST) && \
15 --- /dev/null
16 +++ b/drivers/usb/host/ehci-cns21xx.c
17 @@ -0,0 +1,187 @@
18 +/*
19 + * Copyright (c) 2008 Cavium Networks
20 + * Copyright (c) 2010-2012 Gabor Juhos <juhosg@openwrt.org>
21 + *
22 + * This file is free software; you can redistribute it and/or modify
23 + * it under the terms of the GNU General Public License, Version 2, as
24 + * published by the Free Software Foundation.
25 + */
26 +
27 +#include <linux/platform_device.h>
28 +#include <linux/irq.h>
29 +
30 +#include <mach/cns21xx.h>
31 +
32 +#define DRIVER_NAME "cns21xx-ehci"
33 +
34 +static int cns21xx_ehci_reset(struct usb_hcd *hcd)
35 +{
36 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
37 + int ret;
38 +
39 + ret = ehci_halt(ehci);
40 + if (ret)
41 + return ret;
42 +
43 + ret = ehci_init(hcd);
44 + if (ret)
45 + return ret;
46 +
47 + ehci_reset(ehci);
48 +
49 + return 0;
50 +}
51 +
52 +static const struct hc_driver ehci_cns21xx_hc_driver = {
53 + .description = hcd_name,
54 + .product_desc = DRIVER_NAME,
55 + .hcd_priv_size = sizeof(struct ehci_hcd),
56 +
57 + /*
58 + * generic hardware linkage
59 + */
60 + .irq = ehci_irq,
61 + .flags = HCD_MEMORY | HCD_USB2,
62 +
63 + /*
64 + * basic lifecycle operations
65 + */
66 + .reset = cns21xx_ehci_reset,
67 + .start = ehci_run,
68 + .stop = ehci_stop,
69 + .shutdown = ehci_shutdown,
70 +
71 + /*
72 + * managing i/o requests and associated device resources
73 + */
74 + .urb_enqueue = ehci_urb_enqueue,
75 + .urb_dequeue = ehci_urb_dequeue,
76 + .endpoint_disable = ehci_endpoint_disable,
77 + .endpoint_reset = ehci_endpoint_reset,
78 +
79 + /*
80 + * scheduling support
81 + */
82 + .get_frame_number = ehci_get_frame,
83 +
84 + /*
85 + * root hub support
86 + */
87 + .hub_status_data = ehci_hub_status_data,
88 + .hub_control = ehci_hub_control,
89 + .relinquish_port = ehci_relinquish_port,
90 + .port_handed_over = ehci_port_handed_over,
91 +
92 + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
93 +};
94 +
95 +static void cns21xx_ehci_init_hc(void)
96 +{
97 + void __iomem *base = (void __iomem *) CNS21XX_EHCI_CONFIG_BASE_VIRT;
98 +
99 + __raw_writel(0x106, base + 0x04);
100 + __raw_writel((3 << 5) | 0x2000, base + 0x40);
101 + msleep(100);
102 +}
103 +
104 +static int ehci_cns21xx_probe(struct platform_device *pdev)
105 +{
106 + struct usb_hcd *hcd;
107 + struct ehci_hcd *ehci;
108 + struct resource *res;
109 + int irq;
110 + int ret;
111 +
112 + if (usb_disabled())
113 + return -ENODEV;
114 +
115 + res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
116 + if (!res) {
117 + dev_dbg(&pdev->dev, "no IRQ specified for %s\n",
118 + dev_name(&pdev->dev));
119 + return -ENODEV;
120 + }
121 + irq = res->start;
122 +
123 + hcd = usb_create_hcd(&ehci_cns21xx_hc_driver, &pdev->dev,
124 + dev_name(&pdev->dev));
125 + if (!hcd)
126 + return -ENOMEM;
127 +
128 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
129 + if (!res) {
130 + dev_dbg(&pdev->dev, "no base address specified for %s\n",
131 + dev_name(&pdev->dev));
132 + ret = -ENODEV;
133 + goto err_put_hcd;
134 + }
135 + hcd->rsrc_start = res->start;
136 + hcd->rsrc_len = res->end - res->start + 1;
137 +
138 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
139 + dev_dbg(&pdev->dev, "controller already in use\n");
140 + ret = -EBUSY;
141 + goto err_put_hcd;
142 + }
143 +
144 + hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
145 + if (!hcd->regs) {
146 + dev_dbg(&pdev->dev, "error mapping memory\n");
147 + ret = -EFAULT;
148 + goto err_release_region;
149 + }
150 +
151 + cns21xx_ehci_init_hc();
152 +
153 + ehci = hcd_to_ehci(hcd);
154 +
155 + ehci->caps = hcd->regs;
156 + ehci->regs = hcd->regs +
157 + HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
158 + dbg_hcs_params(ehci, "reset");
159 + dbg_hcc_params(ehci, "reset");
160 +
161 + /* cache this readonly data; minimize chip reads */
162 + ehci->hcs_params = readl(&ehci->caps->hcs_params);
163 + ehci->sbrn = 0x20;
164 +
165 + ret = usb_add_hcd(hcd, CNS21XX_IRQ_EHCI, IRQF_DISABLED);
166 + if (ret)
167 + goto err_unmap;
168 +
169 + platform_set_drvdata(pdev, hcd);
170 + return 0;
171 +
172 +err_unmap:
173 + iounmap(hcd->regs);
174 +err_release_region:
175 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
176 +err_put_hcd:
177 + usb_put_hcd(hcd);
178 + return ret;
179 +}
180 +
181 +static int ehci_cns21xx_remove(struct platform_device *pdev)
182 +{
183 + struct usb_hcd *hcd = platform_get_drvdata(pdev);
184 +
185 + usb_remove_hcd(hcd);
186 + iounmap(hcd->regs);
187 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
188 + usb_put_hcd(hcd);
189 + platform_set_drvdata(pdev, NULL);
190 +
191 + return 0;
192 +}
193 +
194 +static struct platform_driver ehci_cns21xx_driver = {
195 + .probe = ehci_cns21xx_probe,
196 + .remove = ehci_cns21xx_remove,
197 + .shutdown = usb_hcd_platform_shutdown,
198 + .driver = {
199 + .owner = THIS_MODULE,
200 + .name = DRIVER_NAME,
201 + },
202 +};
203 +
204 +MODULE_ALIAS("platform:" DRIVER_NAME);
205 --- a/arch/arm/Kconfig
206 +++ b/arch/arm/Kconfig
207 @@ -382,6 +382,7 @@ config ARCH_CNS21XX
208 select ARCH_REQUIRE_GPIOLIB
209 select ARM_L1_CACHE_SHIFT_4
210 select USB_ARCH_HAS_OHCI
211 + select USB_ARCH_HAS_EHCI
212 help
213 Support for Cavium Networks CNS21xx family.
214