generic: disintegrate UAPI from include/linux/switch.h
[openwrt/svn-archive/archive.git] / target / linux / generic / patches-3.3 / 082-USB-EHCI-Add-a-generic-platform-device-driver.patch
1 --- a/drivers/usb/host/Kconfig
2 +++ b/drivers/usb/host/Kconfig
3 @@ -403,6 +403,16 @@ config USB_OHCI_HCD_PLATFORM
4
5 If unsure, say N.
6
7 +config USB_EHCI_HCD_PLATFORM
8 + bool "Generic EHCI driver for a platform device"
9 + depends on USB_EHCI_HCD && EXPERIMENTAL
10 + default n
11 + ---help---
12 + Adds an EHCI 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/ehci-hcd.c
21 +++ b/drivers/usb/host/ehci-hcd.c
22 @@ -1381,6 +1381,11 @@ MODULE_LICENSE ("GPL");
23 #define PLATFORM_DRIVER ehci_mv_driver
24 #endif
25
26 +#ifdef CONFIG_USB_EHCI_HCD_PLATFORM
27 +#include "ehci-platform.c"
28 +#define PLATFORM_DRIVER ehci_platform_driver
29 +#endif
30 +
31 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
32 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
33 !defined(XILINX_OF_PLATFORM_DRIVER)
34 --- /dev/null
35 +++ b/drivers/usb/host/ehci-platform.c
36 @@ -0,0 +1,198 @@
37 +/*
38 + * Generic platform ehci driver
39 + *
40 + * Copyright 2007 Steven Brown <sbrown@cortland.com>
41 + * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
42 + *
43 + * Derived from the ohci-ssb driver
44 + * Copyright 2007 Michael Buesch <m@bues.ch>
45 + *
46 + * Derived from the EHCI-PCI driver
47 + * Copyright (c) 2000-2004 by David Brownell
48 + *
49 + * Derived from the ohci-pci driver
50 + * Copyright 1999 Roman Weissgaerber
51 + * Copyright 2000-2002 David Brownell
52 + * Copyright 1999 Linus Torvalds
53 + * Copyright 1999 Gregory P. Smith
54 + *
55 + * Licensed under the GNU/GPL. See COPYING for details.
56 + */
57 +#include <linux/platform_device.h>
58 +#include <linux/usb/ehci_pdriver.h>
59 +
60 +static int ehci_platform_reset(struct usb_hcd *hcd)
61 +{
62 + struct platform_device *pdev = to_platform_device(hcd->self.controller);
63 + struct usb_ehci_pdata *pdata = pdev->dev.platform_data;
64 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
65 + int retval;
66 +
67 + hcd->has_tt = pdata->has_tt;
68 + ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
69 + ehci->big_endian_desc = pdata->big_endian_desc;
70 + ehci->big_endian_mmio = pdata->big_endian_mmio;
71 +
72 + ehci->caps = hcd->regs + pdata->caps_offset;
73 + retval = ehci_setup(hcd);
74 + if (retval)
75 + return retval;
76 +
77 + if (pdata->port_power_on)
78 + ehci_port_power(ehci, 1);
79 + if (pdata->port_power_off)
80 + ehci_port_power(ehci, 0);
81 +
82 + return 0;
83 +}
84 +
85 +static const struct hc_driver ehci_platform_hc_driver = {
86 + .description = hcd_name,
87 + .product_desc = "Generic Platform EHCI Controller",
88 + .hcd_priv_size = sizeof(struct ehci_hcd),
89 +
90 + .irq = ehci_irq,
91 + .flags = HCD_MEMORY | HCD_USB2,
92 +
93 + .reset = ehci_platform_reset,
94 + .start = ehci_run,
95 + .stop = ehci_stop,
96 + .shutdown = ehci_shutdown,
97 +
98 + .urb_enqueue = ehci_urb_enqueue,
99 + .urb_dequeue = ehci_urb_dequeue,
100 + .endpoint_disable = ehci_endpoint_disable,
101 + .endpoint_reset = ehci_endpoint_reset,
102 +
103 + .get_frame_number = ehci_get_frame,
104 +
105 + .hub_status_data = ehci_hub_status_data,
106 + .hub_control = ehci_hub_control,
107 +#if defined(CONFIG_PM)
108 + .bus_suspend = ehci_bus_suspend,
109 + .bus_resume = ehci_bus_resume,
110 +#endif
111 + .relinquish_port = ehci_relinquish_port,
112 + .port_handed_over = ehci_port_handed_over,
113 +
114 + .update_device = ehci_update_device,
115 +
116 + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
117 +};
118 +
119 +static int __devinit ehci_platform_probe(struct platform_device *dev)
120 +{
121 + struct usb_hcd *hcd;
122 + struct resource *res_mem;
123 + int irq;
124 + int err = -ENOMEM;
125 +
126 + BUG_ON(!dev->dev.platform_data);
127 +
128 + if (usb_disabled())
129 + return -ENODEV;
130 +
131 + irq = platform_get_irq(dev, 0);
132 + if (irq < 0) {
133 + pr_err("no irq provieded");
134 + return irq;
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(&ehci_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 ehci_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 ehci_platform_suspend(struct device *dev)
192 +{
193 + struct usb_hcd *hcd = dev_get_drvdata(dev);
194 + bool wakeup = device_may_wakeup(dev);
195 +
196 + ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), wakeup);
197 + return 0;
198 +}
199 +
200 +static int ehci_platform_resume(struct device *dev)
201 +{
202 + struct usb_hcd *hcd = dev_get_drvdata(dev);
203 +
204 + ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
205 + return 0;
206 +}
207 +
208 +#else /* !CONFIG_PM */
209 +#define ehci_platform_suspend NULL
210 +#define ehci_platform_resume NULL
211 +#endif /* CONFIG_PM */
212 +
213 +static const struct platform_device_id ehci_platform_table[] = {
214 + { "ehci-platform", 0 },
215 + { }
216 +};
217 +MODULE_DEVICE_TABLE(platform, ehci_platform_table);
218 +
219 +static const struct dev_pm_ops ehci_platform_pm_ops = {
220 + .suspend = ehci_platform_suspend,
221 + .resume = ehci_platform_resume,
222 +};
223 +
224 +static struct platform_driver ehci_platform_driver = {
225 + .id_table = ehci_platform_table,
226 + .probe = ehci_platform_probe,
227 + .remove = __devexit_p(ehci_platform_remove),
228 + .shutdown = usb_hcd_platform_shutdown,
229 + .driver = {
230 + .owner = THIS_MODULE,
231 + .name = "ehci-platform",
232 + .pm = &ehci_platform_pm_ops,
233 + }
234 +};
235 --- /dev/null
236 +++ b/include/linux/usb/ehci_pdriver.h
237 @@ -0,0 +1,46 @@
238 +/*
239 + * Copyright (C) 2012 Hauke Mehrtens <hauke@hauke-m.de>
240 + *
241 + * This program is free software; you can redistribute it and/or modify it
242 + * under the terms of the GNU General Public License as published by the
243 + * Free Software Foundation; either version 2 of the License, or (at your
244 + * option) any later version.
245 + *
246 + * This program is distributed in the hope that it will be useful, but
247 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
248 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
249 + * for more details.
250 + *
251 + * You should have received a copy of the GNU General Public License
252 + * along with this program; if not, write to the Free Software Foundation,
253 + * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
254 + */
255 +
256 +#ifndef __USB_CORE_EHCI_PDRIVER_H
257 +#define __USB_CORE_EHCI_PDRIVER_H
258 +
259 +/**
260 + * struct usb_ehci_pdata - platform_data for generic ehci driver
261 + *
262 + * @caps_offset: offset of the EHCI Capability Registers to the start of
263 + * the io memory region provided to the driver.
264 + * @has_tt: set to 1 if TT is integrated in root hub.
265 + * @port_power_on: set to 1 if the controller needs a power up after
266 + * initialization.
267 + * @port_power_off: set to 1 if the controller needs to be powered down
268 + * after initialization.
269 + *
270 + * These are general configuration options for the EHCI controller. All of
271 + * these options are activating more or less workarounds for some hardware.
272 + */
273 +struct usb_ehci_pdata {
274 + int caps_offset;
275 + unsigned has_tt:1;
276 + unsigned has_synopsys_hc_bug:1;
277 + unsigned big_endian_desc:1;
278 + unsigned big_endian_mmio:1;
279 + unsigned port_power_on:1;
280 + unsigned port_power_off:1;
281 +};
282 +
283 +#endif /* __USB_CORE_EHCI_PDRIVER_H */