brcm47xx: update usb driver for brcm47xx.
[openwrt/svn-archive/archive.git] / target / linux / brcm47xx / patches-3.2 / 181-USB-OHCI-Add-a-generic-platform-device-driver.patch
1 From 2232a2ab6015496fecdfad68a9d6794312a9b2f2 Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 26 Nov 2011 21:20:54 +0100
4 Subject: [PATCH 181/186] USB: OHCI: Add a generic platform device driver
5
6 This adds a generic driver for platform devices. It works like the PCI
7 driver and is based on it. This is for devices which do not have an own
8 bus but their OHCI controller works like a PCI controller. It will be
9 used for the Broadcom bcma and ssb USB OHCI controller.
10
11 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
12 ---
13 drivers/usb/host/Kconfig | 10 ++
14 drivers/usb/host/ohci-hcd.c | 5 +
15 drivers/usb/host/ohci-platform.c | 183 ++++++++++++++++++++++++++++++++++++++
16 3 files changed, 198 insertions(+), 0 deletions(-)
17 create mode 100644 drivers/usb/host/ohci-platform.c
18
19 --- a/drivers/usb/host/Kconfig
20 +++ b/drivers/usb/host/Kconfig
21 @@ -378,6 +378,16 @@ config USB_CNS3XXX_OHCI
22 Enable support for the CNS3XXX SOC's on-chip OHCI controller.
23 It is needed for low-speed USB 1.0 device support.
24
25 +config USB_OHCI_HCD_PLATFORM
26 + bool "OHCI driver for a platform device"
27 + depends on USB_OHCI_HCD && EXPERIMENTAL
28 + default n
29 + ---help---
30 + Adds an OHCI host driver for a generic platform device, which
31 + provieds a memory space and an irq.
32 +
33 + If unsure, say N.
34 +
35 config USB_OHCI_BIG_ENDIAN_DESC
36 bool
37 depends on USB_OHCI_HCD
38 --- a/drivers/usb/host/ohci-hcd.c
39 +++ b/drivers/usb/host/ohci-hcd.c
40 @@ -1116,6 +1116,11 @@ MODULE_LICENSE ("GPL");
41 #define PLATFORM_DRIVER ohci_xls_driver
42 #endif
43
44 +#ifdef CONFIG_USB_OHCI_HCD_PLATFORM
45 +#include "ohci-platform.c"
46 +#define PLATFORM_DRIVER ohci_platform_driver
47 +#endif
48 +
49 #if !defined(PCI_DRIVER) && \
50 !defined(PLATFORM_DRIVER) && \
51 !defined(OMAP1_PLATFORM_DRIVER) && \
52 --- /dev/null
53 +++ b/drivers/usb/host/ohci-platform.c
54 @@ -0,0 +1,183 @@
55 +/*
56 + * Generic platform ohci driver
57 + *
58 + * Copyright 2007 Michael Buesch <m@bues.ch>
59 + * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
60 + *
61 + * Derived from the OCHI-SSB driver
62 + * Derived from the OHCI-PCI driver
63 + * Copyright 1999 Roman Weissgaerber
64 + * Copyright 2000-2002 David Brownell
65 + * Copyright 1999 Linus Torvalds
66 + * Copyright 1999 Gregory P. Smith
67 + *
68 + * Licensed under the GNU/GPL. See COPYING for details.
69 + */
70 +#include <linux/platform_device.h>
71 +#include <linux/usb/hci_driver.h>
72 +
73 +static int ohci_platform_reset(struct usb_hcd *hcd)
74 +{
75 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
76 + int err;
77 +
78 + ohci_hcd_init(ohci);
79 + err = ohci_init(ohci);
80 +
81 + return err;
82 +}
83 +
84 +static int ohci_platform_start(struct usb_hcd *hcd)
85 +{
86 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
87 + int err;
88 +
89 + err = ohci_run(ohci);
90 + if (err < 0) {
91 + ohci_err(ohci, "can't start\n");
92 + ohci_stop(hcd);
93 + }
94 +
95 + return err;
96 +}
97 +
98 +static const struct hc_driver ohci_platform_hc_driver = {
99 + .description = hcd_name,
100 + .product_desc = "Generic Platform OHCI Controller",
101 + .hcd_priv_size = sizeof(struct ohci_hcd),
102 +
103 + .irq = ohci_irq,
104 + .flags = HCD_MEMORY | HCD_USB11,
105 +
106 + .reset = ohci_platform_reset,
107 + .start = ohci_platform_start,
108 + .stop = ohci_stop,
109 + .shutdown = ohci_shutdown,
110 +
111 + .urb_enqueue = ohci_urb_enqueue,
112 + .urb_dequeue = ohci_urb_dequeue,
113 + .endpoint_disable = ohci_endpoint_disable,
114 +
115 + .get_frame_number = ohci_get_frame,
116 +
117 + .hub_status_data = ohci_hub_status_data,
118 + .hub_control = ohci_hub_control,
119 +#ifdef CONFIG_PM
120 + .bus_suspend = ohci_bus_suspend,
121 + .bus_resume = ohci_bus_resume,
122 +#endif
123 +
124 + .start_port_reset = ohci_start_port_reset,
125 +};
126 +
127 +static int __devinit ohci_platform_probe(struct platform_device *dev)
128 +{
129 + struct usb_hcd *hcd;
130 + struct resource *res_mem;
131 + int irq;
132 + int err = -ENOMEM;
133 +
134 + if (usb_disabled())
135 + return -ENODEV;
136 +
137 + irq = platform_get_irq(dev, 0);
138 + if (irq < 0) {
139 + pr_err("no irq provieded");
140 + return irq;
141 + }
142 +
143 + res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
144 + if (!res_mem) {
145 + pr_err("no memory recourse provieded");
146 + return -ENXIO;
147 + }
148 +
149 + hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
150 + dev_name(&dev->dev));
151 + if (!hcd)
152 + return -ENOMEM;
153 +
154 + hcd->rsrc_start = res_mem->start;
155 + hcd->rsrc_len = resource_size(res_mem);
156 +
157 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
158 + pr_err("controller already in use");
159 + err = -EBUSY;
160 + goto err_put_hcd;
161 + }
162 +
163 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
164 + if (!hcd->regs)
165 + goto err_release_region;
166 + err = usb_add_hcd(hcd, irq, IRQF_SHARED);
167 + if (err)
168 + goto err_iounmap;
169 +
170 + platform_set_drvdata(dev, hcd);
171 +
172 + return err;
173 +
174 +err_iounmap:
175 + iounmap(hcd->regs);
176 +err_release_region:
177 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
178 +err_put_hcd:
179 + usb_put_hcd(hcd);
180 + return err;
181 +}
182 +
183 +static int __devexit ohci_platform_remove(struct platform_device *dev)
184 +{
185 + struct usb_hcd *hcd = platform_get_drvdata(dev);
186 +
187 + usb_remove_hcd(hcd);
188 + iounmap(hcd->regs);
189 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
190 + usb_put_hcd(hcd);
191 + platform_set_drvdata(dev, NULL);
192 +
193 + return 0;
194 +}
195 +
196 +#ifdef CONFIG_PM
197 +
198 +static int ohci_platform_suspend(struct device *dev)
199 +{
200 + return 0;
201 +}
202 +
203 +static int ohci_platform_resume(struct device *dev)
204 +{
205 + struct usb_hcd *hcd = dev_get_drvdata(dev);
206 +
207 + ohci_finish_controller_resume(hcd);
208 + return 0;
209 +}
210 +
211 +#else /* !CONFIG_PM */
212 +#define ohci_platform_suspend NULL
213 +#define ohci_platform_resume NULL
214 +#endif /* CONFIG_PM */
215 +
216 +static const struct platform_device_id ohci_platform_table[] = {
217 + { "ohci-platform", 0 },
218 + { }
219 +};
220 +MODULE_DEVICE_TABLE(platform, ohci_platform_table);
221 +
222 +static const struct dev_pm_ops ohci_platform_pm_ops = {
223 + .suspend = ohci_platform_suspend,
224 + .resume = ohci_platform_resume,
225 +};
226 +
227 +static struct platform_driver ohci_platform_driver = {
228 + .id_table = ohci_platform_table,
229 + .probe = ohci_platform_probe,
230 + .remove = __devexit_p(ohci_platform_remove),
231 + .shutdown = usb_hcd_platform_shutdown,
232 + .driver = {
233 + .owner = THIS_MODULE,
234 + .name = "ohci-platform",
235 + .pm = &ohci_platform_pm_ops,
236 + }
237 +};