Root/target/linux/brcm47xx/patches-3.0/0031-USB-EHCI-Add-a-generic-platform-device-driver.patch

1From aa05e0048cec25719921291e8749674b8cc66fc0 Mon Sep 17 00:00:00 2001
2From: Hauke Mehrtens <hauke@hauke-m.de>
3Date: Sat, 26 Nov 2011 21:28:56 +0100
4Subject: [PATCH 18/21] USB: EHCI: Add a generic platform device driver
5
6This adds a generic driver for platform devices. It works like the PCI
7driver and is based on it. This is for devices which do not have an own
8bus but their EHCI controller works like a PCI controller. It will be
9used for the Broadcom bcma and ssb USB EHCI controller.
10
11Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
12---
13 drivers/usb/host/Kconfig | 10 ++
14 drivers/usb/host/ehci-hcd.c | 5 +
15 drivers/usb/host/ehci-platform.c | 211 ++++++++++++++++++++++++++++++++++++++
16 3 files changed, 226 insertions(+), 0 deletions(-)
17 create mode 100644 drivers/usb/host/ehci-platform.c
18
19--- a/drivers/usb/host/Kconfig
20+++ b/drivers/usb/host/Kconfig
21@@ -388,6 +388,16 @@ config USB_OHCI_HCD_PLATFORM
22 
23       If unsure, say N.
24 
25+config USB_EHCI_HCD_PLATFORM
26+ bool "Generic EHCI driver for a platform device"
27+ depends on USB_EHCI_HCD && EXPERIMENTAL
28+ default n
29+ ---help---
30+ Adds an EHCI 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/ehci-hcd.c
39+++ b/drivers/usb/host/ehci-hcd.c
40@@ -1312,6 +1312,11 @@ MODULE_LICENSE ("GPL");
41 #define PLATFORM_DRIVER ehci_grlib_driver
42 #endif
43 
44+#ifdef CONFIG_USB_EHCI_HCD_PLATFORM
45+#include "ehci-platform.c"
46+#define PLATFORM_DRIVER ehci_platform_driver
47+#endif
48+
49 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
50     !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
51     !defined(XILINX_OF_PLATFORM_DRIVER)
52--- /dev/null
53+++ b/drivers/usb/host/ehci-platform.c
54@@ -0,0 +1,211 @@
55+/*
56+ * Generic platform ehci driver
57+ *
58+ * Copyright 2007 Steven Brown <sbrown@cortland.com>
59+ * Copyright 2010-2011 Hauke Mehrtens <hauke@hauke-m.de>
60+ *
61+ * Derived from the ohci-ssb driver
62+ * Copyright 2007 Michael Buesch <mb@bu3sch.de>
63+ *
64+ * Derived from the EHCI-PCI driver
65+ * Copyright (c) 2000-2004 by David Brownell
66+ *
67+ * Derived from the ohci-pci driver
68+ * Copyright 1999 Roman Weissgaerber
69+ * Copyright 2000-2002 David Brownell
70+ * Copyright 1999 Linus Torvalds
71+ * Copyright 1999 Gregory P. Smith
72+ *
73+ * Licensed under the GNU/GPL. See COPYING for details.
74+ */
75+#include <linux/platform_device.h>
76+
77+static int ehci_platform_reset(struct usb_hcd *hcd)
78+{
79+ struct ehci_hcd *ehci = hcd_to_ehci(hcd);
80+ int retval;
81+
82+ ehci->caps = hcd->regs;
83+ ehci->regs = hcd->regs +
84+ HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
85+
86+ dbg_hcs_params(ehci, "reset");
87+ dbg_hcc_params(ehci, "reset");
88+
89+ /* cache this readonly data; minimize chip reads */
90+ ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
91+
92+ retval = ehci_halt(ehci);
93+ if (retval)
94+ return retval;
95+
96+ /* data structure init */
97+ retval = ehci_init(hcd);
98+ if (retval)
99+ return retval;
100+
101+ ehci_reset(ehci);
102+
103+ ehci_port_power(ehci, 1);
104+
105+ return retval;
106+}
107+
108+static const struct hc_driver ehci_platform_hc_driver = {
109+ .description = "platform-usb-ehci",
110+ .product_desc = "Generic Platform EHCI Controller",
111+ .hcd_priv_size = sizeof(struct ehci_hcd),
112+
113+ .irq = ehci_irq,
114+ .flags = HCD_MEMORY | HCD_USB2,
115+
116+ .reset = ehci_platform_reset,
117+ .start = ehci_run,
118+ .stop = ehci_stop,
119+ .shutdown = ehci_shutdown,
120+
121+ .urb_enqueue = ehci_urb_enqueue,
122+ .urb_dequeue = ehci_urb_dequeue,
123+ .endpoint_disable = ehci_endpoint_disable,
124+ .endpoint_reset = ehci_endpoint_reset,
125+
126+ .get_frame_number = ehci_get_frame,
127+
128+ .hub_status_data = ehci_hub_status_data,
129+ .hub_control = ehci_hub_control,
130+#if defined(CONFIG_PM)
131+ .bus_suspend = ehci_bus_suspend,
132+ .bus_resume = ehci_bus_resume,
133+#endif
134+ .relinquish_port = ehci_relinquish_port,
135+ .port_handed_over = ehci_port_handed_over,
136+
137+ .update_device = ehci_update_device,
138+
139+ .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
140+};
141+
142+static int ehci_platform_attach(struct platform_device *dev)
143+{
144+ struct usb_hcd *hcd;
145+ struct resource *res_irq, *res_mem;
146+ int err = -ENOMEM;
147+
148+ hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
149+ dev_name(&dev->dev));
150+ if (!hcd)
151+ goto err_return;
152+
153+ res_irq = platform_get_resource(dev, IORESOURCE_IRQ, 0);
154+ if (!res_irq) {
155+ err = -ENXIO;
156+ goto err_return;
157+ }
158+ res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
159+ if (!res_mem) {
160+ err = -ENXIO;
161+ goto err_return;
162+ }
163+ hcd->rsrc_start = res_mem->start;
164+ hcd->rsrc_len = res_mem->end - res_mem->start + 1;
165+
166+ /*
167+ * start & size modified per sbutils.c
168+ */
169+ hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
170+ if (!hcd->regs)
171+ goto err_put_hcd;
172+ err = usb_add_hcd(hcd, res_irq->start, IRQF_SHARED);
173+ if (err)
174+ goto err_iounmap;
175+
176+ platform_set_drvdata(dev, hcd);
177+
178+ return err;
179+
180+err_iounmap:
181+ iounmap(hcd->regs);
182+err_put_hcd:
183+ usb_put_hcd(hcd);
184+err_return:
185+ return err;
186+}
187+
188+static int ehci_platform_probe(struct platform_device *dev)
189+{
190+ int err;
191+
192+ if (usb_disabled())
193+ return -ENODEV;
194+
195+ err = ehci_platform_attach(dev);
196+
197+ return err;
198+}
199+
200+static int ehci_platform_remove(struct platform_device *dev)
201+{
202+ struct usb_hcd *hcd;
203+
204+ hcd = platform_get_drvdata(dev);
205+ if (!hcd)
206+ return -ENODEV;
207+
208+ usb_remove_hcd(hcd);
209+ iounmap(hcd->regs);
210+ release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
211+ usb_put_hcd(hcd);
212+
213+ return 0;
214+}
215+
216+static void ehci_platform_shutdown(struct platform_device *dev)
217+{
218+ struct usb_hcd *hcd;
219+
220+ hcd = platform_get_drvdata(dev);
221+ if (!hcd)
222+ return;
223+
224+ if (hcd->driver->shutdown)
225+ hcd->driver->shutdown(hcd);
226+}
227+
228+#ifdef CONFIG_PM
229+
230+static int ehci_platform_suspend(struct platform_device *dev,
231+ pm_message_t state)
232+{
233+ return 0;
234+}
235+
236+static int ehci_platform_resume(struct platform_device *dev)
237+{
238+ struct usb_hcd *hcd = platform_get_drvdata(dev);
239+
240+ ehci_finish_controller_resume(hcd);
241+ return 0;
242+}
243+
244+#else /* !CONFIG_PM */
245+#define ehci_platform_suspend NULL
246+#define ehci_platform_resume NULL
247+#endif /* CONFIG_PM */
248+
249+static const struct platform_device_id ehci_platform_table[] = {
250+ { "ehci-platform", 0 },
251+ { }
252+};
253+MODULE_DEVICE_TABLE(platform, ehci_platform_table);
254+
255+static struct platform_driver ehci_platform_driver = {
256+ .id_table = ehci_platform_table,
257+ .probe = ehci_platform_probe,
258+ .remove = ehci_platform_remove,
259+ .shutdown = ehci_platform_shutdown,
260+ .suspend = ehci_platform_suspend,
261+ .resume = ehci_platform_resume,
262+ .driver = {
263+ .name = "ehci-platform",
264+ }
265+};
266

Archive Download this file



interactive