Root/target/linux/ar71xx/patches-3.3/000-USB-OHCI-Add-a-generic-platform-device-driver.patch

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

Archive Download this file



interactive