generic: disintegrate UAPI from include/linux/switch.h
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.3 / 081-USB-OHCI-Add-a-generic-platform-device-driver.patch
1 --- a/drivers/usb/host/Kconfig
2 +++ b/drivers/usb/host/Kconfig
3 @@ -393,6 +393,16 @@ config USB_CNS3XXX_OHCI
4 Enable support for the CNS3XXX SOC's on-chip OHCI controller.
5 It is needed for low-speed USB 1.0 device support.
6
7 +config USB_OHCI_HCD_PLATFORM
8 + bool "Generic OHCI driver for a platform device"
9 + depends on USB_OHCI_HCD && EXPERIMENTAL
10 + default n
11 + ---help---
12 + Adds an OHCI host driver for a generic platform device, which
13 + provieds a memory space and an irq.
14 +
15 + If unsure, say N.
16 +
17 config USB_OHCI_BIG_ENDIAN_DESC
18 bool
19 depends on USB_OHCI_HCD
20 --- a/drivers/usb/host/ohci-hcd.c
21 +++ b/drivers/usb/host/ohci-hcd.c
22 @@ -1121,6 +1121,11 @@ MODULE_LICENSE ("GPL");
23 #define PLATFORM_DRIVER ohci_xls_driver
24 #endif
25
26 +#ifdef CONFIG_USB_OHCI_HCD_PLATFORM
27 +#include "ohci-platform.c"
28 +#define PLATFORM_DRIVER ohci_platform_driver
29 +#endif
30 +
31 #if !defined(PCI_DRIVER) && \
32 !defined(PLATFORM_DRIVER) && \
33 !defined(OMAP1_PLATFORM_DRIVER) && \
34 --- /dev/null
35 +++ b/drivers/usb/host/ohci-platform.c
36 @@ -0,0 +1,194 @@
37 +/*
38 + * Generic platform ohci driver
39 + *
40 + * Copyright 2007 Michael Buesch <m@bues.ch>
41 + * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de>
42 + *
43 + * Derived from the OCHI-SSB driver
44 + * Derived from the OHCI-PCI driver
45 + * Copyright 1999 Roman Weissgaerber
46 + * Copyright 2000-2002 David Brownell
47 + * Copyright 1999 Linus Torvalds
48 + * Copyright 1999 Gregory P. Smith
49 + *
50 + * Licensed under the GNU/GPL. See COPYING for details.
51 + */
52 +#include <linux/platform_device.h>
53 +#include <linux/usb/ohci_pdriver.h>
54 +
55 +static int ohci_platform_reset(struct usb_hcd *hcd)
56 +{
57 + struct platform_device *pdev = to_platform_device(hcd->self.controller);
58 + struct usb_ohci_pdata *pdata = pdev->dev.platform_data;
59 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
60 + int err;
61 +
62 + if (pdata->big_endian_desc)
63 + ohci->flags |= OHCI_QUIRK_BE_DESC;
64 + if (pdata->big_endian_mmio)
65 + ohci->flags |= OHCI_QUIRK_BE_MMIO;
66 + if (pdata->no_big_frame_no)
67 + ohci->flags |= OHCI_QUIRK_FRAME_NO;
68 +
69 + ohci_hcd_init(ohci);
70 + err = ohci_init(ohci);
71 +
72 + return err;
73 +}
74 +
75 +static int ohci_platform_start(struct usb_hcd *hcd)
76 +{
77 + struct ohci_hcd *ohci = hcd_to_ohci(hcd);
78 + int err;
79 +
80 + err = ohci_run(ohci);
81 + if (err < 0) {
82 + ohci_err(ohci, "can't start\n");
83 + ohci_stop(hcd);
84 + }
85 +
86 + return err;
87 +}
88 +
89 +static const struct hc_driver ohci_platform_hc_driver = {
90 + .description = hcd_name,
91 + .product_desc = "Generic Platform OHCI Controller",
92 + .hcd_priv_size = sizeof(struct ohci_hcd),
93 +
94 + .irq = ohci_irq,
95 + .flags = HCD_MEMORY | HCD_USB11,
96 +
97 + .reset = ohci_platform_reset,
98 + .start = ohci_platform_start,
99 + .stop = ohci_stop,
100 + .shutdown = ohci_shutdown,
101 +
102 + .urb_enqueue = ohci_urb_enqueue,
103 + .urb_dequeue = ohci_urb_dequeue,
104 + .endpoint_disable = ohci_endpoint_disable,
105 +
106 + .get_frame_number = ohci_get_frame,
107 +
108 + .hub_status_data = ohci_hub_status_data,
109 + .hub_control = ohci_hub_control,
110 +#ifdef CONFIG_PM
111 + .bus_suspend = ohci_bus_suspend,
112 + .bus_resume = ohci_bus_resume,
113 +#endif
114 +
115 + .start_port_reset = ohci_start_port_reset,
116 +};
117 +
118 +static int __devinit ohci_platform_probe(struct platform_device *dev)
119 +{
120 + struct usb_hcd *hcd;
121 + struct resource *res_mem;
122 + int irq;
123 + int err = -ENOMEM;
124 +
125 + BUG_ON(!dev->dev.platform_data);
126 +
127 + if (usb_disabled())
128 + return -ENODEV;
129 +
130 + irq = platform_get_irq(dev, 0);
131 + if (irq < 0) {
132 + pr_err("no irq provieded");
133 + return irq;
134 + }
135 +
136 + res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
137 + if (!res_mem) {
138 + pr_err("no memory recourse provieded");
139 + return -ENXIO;
140 + }
141 +
142 + hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev,
143 + dev_name(&dev->dev));
144 + if (!hcd)
145 + return -ENOMEM;
146 +
147 + hcd->rsrc_start = res_mem->start;
148 + hcd->rsrc_len = resource_size(res_mem);
149 +
150 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
151 + pr_err("controller already in use");
152 + err = -EBUSY;
153 + goto err_put_hcd;
154 + }
155 +
156 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
157 + if (!hcd->regs)
158 + goto err_release_region;
159 + err = usb_add_hcd(hcd, irq, IRQF_SHARED);
160 + if (err)
161 + goto err_iounmap;
162 +
163 + platform_set_drvdata(dev, hcd);
164 +
165 + return err;
166 +
167 +err_iounmap:
168 + iounmap(hcd->regs);
169 +err_release_region:
170 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
171 +err_put_hcd:
172 + usb_put_hcd(hcd);
173 + return err;
174 +}
175 +
176 +static int __devexit ohci_platform_remove(struct platform_device *dev)
177 +{
178 + struct usb_hcd *hcd = platform_get_drvdata(dev);
179 +
180 + usb_remove_hcd(hcd);
181 + iounmap(hcd->regs);
182 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
183 + usb_put_hcd(hcd);
184 + platform_set_drvdata(dev, NULL);
185 +
186 + return 0;
187 +}
188 +
189 +#ifdef CONFIG_PM
190 +
191 +static int ohci_platform_suspend(struct device *dev)
192 +{
193 + return 0;
194 +}
195 +
196 +static int ohci_platform_resume(struct device *dev)
197 +{
198 + struct usb_hcd *hcd = dev_get_drvdata(dev);
199 +
200 + ohci_finish_controller_resume(hcd);
201 + return 0;
202 +}
203 +
204 +#else /* !CONFIG_PM */
205 +#define ohci_platform_suspend NULL
206 +#define ohci_platform_resume NULL
207 +#endif /* CONFIG_PM */
208 +
209 +static const struct platform_device_id ohci_platform_table[] = {
210 + { "ohci-platform", 0 },
211 + { }
212 +};
213 +MODULE_DEVICE_TABLE(platform, ohci_platform_table);
214 +
215 +static const struct dev_pm_ops ohci_platform_pm_ops = {
216 + .suspend = ohci_platform_suspend,
217 + .resume = ohci_platform_resume,
218 +};
219 +
220 +static struct platform_driver ohci_platform_driver = {
221 + .id_table = ohci_platform_table,
222 + .probe = ohci_platform_probe,
223 + .remove = __devexit_p(ohci_platform_remove),
224 + .shutdown = usb_hcd_platform_shutdown,
225 + .driver = {
226 + .owner = THIS_MODULE,
227 + .name = "ohci-platform",
228 + .pm = &ohci_platform_pm_ops,
229 + }
230 +};
231 --- /dev/null
232 +++ b/include/linux/usb/ohci_pdriver.h
233 @@ -0,0 +1,38 @@
234 +/*
235 + * Copyright (C) 2012 Hauke Mehrtens <hauke@hauke-m.de>
236 + *
237 + * This program is free software; you can redistribute it and/or modify it
238 + * under the terms of the GNU General Public License as published by the
239 + * Free Software Foundation; either version 2 of the License, or (at your
240 + * option) any later version.
241 + *
242 + * This program is distributed in the hope that it will be useful, but
243 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
244 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
245 + * for more details.
246 + *
247 + * You should have received a copy of the GNU General Public License
248 + * along with this program; if not, write to the Free Software Foundation,
249 + * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
250 + */
251 +
252 +#ifndef __USB_CORE_OHCI_PDRIVER_H
253 +#define __USB_CORE_OHCI_PDRIVER_H
254 +
255 +/**
256 + * struct usb_ohci_pdata - platform_data for generic ohci driver
257 + *
258 + * @big_endian_desc: BE descriptors
259 + * @big_endian_mmio: BE registers
260 + * @no_big_frame_no: no big endian frame_no shift
261 + *
262 + * These are general configuration options for the OHCI controller. All of
263 + * these options are activating more or less workarounds for some hardware.
264 + */
265 +struct usb_ohci_pdata {
266 + unsigned big_endian_desc:1;
267 + unsigned big_endian_mmio:1;
268 + unsigned no_big_frame_no:1;
269 +};
270 +
271 +#endif /* __USB_CORE_OHCI_PDRIVER_H */