Root/target/linux/cns21xx/patches-3.7/103-cns21xx-usb-ohci-support.patch

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

Archive Download this file



interactive