1 From 4fa3face95f1ca2e396dd59324a6c6ef01df24cc Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Tue, 13 Mar 2012 01:04:48 +0100
4 Subject: [PATCH 02/47] USB: EHCI: Add a generic platform device driver
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 EHCI controller works like a PCI controller. It will be
9 used for the Broadcom bcma and ssb USB EHCI controller.
11 Acked-by: Alan Stern <stern@rowland.harvard.edu>
12 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
13 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
15 drivers/usb/host/Kconfig | 10 ++
16 drivers/usb/host/ehci-hcd.c | 5 +
17 drivers/usb/host/ehci-platform.c | 198 ++++++++++++++++++++++++++++++++++++++
18 include/linux/usb/ehci_pdriver.h | 46 +++++++++
19 4 files changed, 259 insertions(+), 0 deletions(-)
20 create mode 100644 drivers/usb/host/ehci-platform.c
21 create mode 100644 include/linux/usb/ehci_pdriver.h
23 --- a/drivers/usb/host/Kconfig
24 +++ b/drivers/usb/host/Kconfig
25 @@ -403,6 +403,16 @@ config USB_OHCI_HCD_PLATFORM
29 +config USB_EHCI_HCD_PLATFORM
30 + bool "Generic EHCI driver for a platform device"
31 + depends on USB_EHCI_HCD && EXPERIMENTAL
34 + Adds an EHCI host driver for a generic platform device, which
35 + provieds a memory space and an irq.
39 config USB_OHCI_BIG_ENDIAN_DESC
41 depends on USB_OHCI_HCD
42 --- a/drivers/usb/host/ehci-hcd.c
43 +++ b/drivers/usb/host/ehci-hcd.c
44 @@ -1381,6 +1381,11 @@ MODULE_LICENSE ("GPL");
45 #define PLATFORM_DRIVER ehci_mv_driver
48 +#ifdef CONFIG_USB_EHCI_HCD_PLATFORM
49 +#include "ehci-platform.c"
50 +#define PLATFORM_DRIVER ehci_platform_driver
53 #if !defined(PCI_DRIVER) && !defined(PLATFORM_DRIVER) && \
54 !defined(PS3_SYSTEM_BUS_DRIVER) && !defined(OF_PLATFORM_DRIVER) && \
55 !defined(XILINX_OF_PLATFORM_DRIVER)
57 +++ b/drivers/usb/host/ehci-platform.c
60 + * Generic platform ehci driver
62 + * Copyright 2007 Steven Brown <sbrown@cortland.com>
63 + * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
65 + * Derived from the ohci-ssb driver
66 + * Copyright 2007 Michael Buesch <m@bues.ch>
68 + * Derived from the EHCI-PCI driver
69 + * Copyright (c) 2000-2004 by David Brownell
71 + * Derived from the ohci-pci driver
72 + * Copyright 1999 Roman Weissgaerber
73 + * Copyright 2000-2002 David Brownell
74 + * Copyright 1999 Linus Torvalds
75 + * Copyright 1999 Gregory P. Smith
77 + * Licensed under the GNU/GPL. See COPYING for details.
79 +#include <linux/platform_device.h>
80 +#include <linux/usb/ehci_pdriver.h>
82 +static int ehci_platform_reset(struct usb_hcd *hcd)
84 + struct platform_device *pdev = to_platform_device(hcd->self.controller);
85 + struct usb_ehci_pdata *pdata = pdev->dev.platform_data;
86 + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
89 + hcd->has_tt = pdata->has_tt;
90 + ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug;
91 + ehci->big_endian_desc = pdata->big_endian_desc;
92 + ehci->big_endian_mmio = pdata->big_endian_mmio;
94 + ehci->caps = hcd->regs + pdata->caps_offset;
95 + retval = ehci_setup(hcd);
99 + if (pdata->port_power_on)
100 + ehci_port_power(ehci, 1);
101 + if (pdata->port_power_off)
102 + ehci_port_power(ehci, 0);
107 +static const struct hc_driver ehci_platform_hc_driver = {
108 + .description = hcd_name,
109 + .product_desc = "Generic Platform EHCI Controller",
110 + .hcd_priv_size = sizeof(struct ehci_hcd),
113 + .flags = HCD_MEMORY | HCD_USB2,
115 + .reset = ehci_platform_reset,
118 + .shutdown = ehci_shutdown,
120 + .urb_enqueue = ehci_urb_enqueue,
121 + .urb_dequeue = ehci_urb_dequeue,
122 + .endpoint_disable = ehci_endpoint_disable,
123 + .endpoint_reset = ehci_endpoint_reset,
125 + .get_frame_number = ehci_get_frame,
127 + .hub_status_data = ehci_hub_status_data,
128 + .hub_control = ehci_hub_control,
129 +#if defined(CONFIG_PM)
130 + .bus_suspend = ehci_bus_suspend,
131 + .bus_resume = ehci_bus_resume,
133 + .relinquish_port = ehci_relinquish_port,
134 + .port_handed_over = ehci_port_handed_over,
136 + .update_device = ehci_update_device,
138 + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
141 +static int __devinit ehci_platform_probe(struct platform_device *dev)
143 + struct usb_hcd *hcd;
144 + struct resource *res_mem;
148 + BUG_ON(!dev->dev.platform_data);
150 + if (usb_disabled())
153 + irq = platform_get_irq(dev, 0);
155 + pr_err("no irq provieded");
158 + res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0);
160 + pr_err("no memory recourse provieded");
164 + hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev,
165 + dev_name(&dev->dev));
169 + hcd->rsrc_start = res_mem->start;
170 + hcd->rsrc_len = resource_size(res_mem);
172 + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) {
173 + pr_err("controller already in use");
178 + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len);
180 + goto err_release_region;
181 + err = usb_add_hcd(hcd, irq, IRQF_SHARED);
185 + platform_set_drvdata(dev, hcd);
190 + iounmap(hcd->regs);
192 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
198 +static int __devexit ehci_platform_remove(struct platform_device *dev)
200 + struct usb_hcd *hcd = platform_get_drvdata(dev);
202 + usb_remove_hcd(hcd);
203 + iounmap(hcd->regs);
204 + release_mem_region(hcd->rsrc_start, hcd->rsrc_len);
206 + platform_set_drvdata(dev, NULL);
213 +static int ehci_platform_suspend(struct device *dev)
215 + struct usb_hcd *hcd = dev_get_drvdata(dev);
216 + bool wakeup = device_may_wakeup(dev);
218 + ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), wakeup);
222 +static int ehci_platform_resume(struct device *dev)
224 + struct usb_hcd *hcd = dev_get_drvdata(dev);
226 + ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd));
230 +#else /* !CONFIG_PM */
231 +#define ehci_platform_suspend NULL
232 +#define ehci_platform_resume NULL
233 +#endif /* CONFIG_PM */
235 +static const struct platform_device_id ehci_platform_table[] = {
236 + { "ehci-platform", 0 },
239 +MODULE_DEVICE_TABLE(platform, ehci_platform_table);
241 +static const struct dev_pm_ops ehci_platform_pm_ops = {
242 + .suspend = ehci_platform_suspend,
243 + .resume = ehci_platform_resume,
246 +static struct platform_driver ehci_platform_driver = {
247 + .id_table = ehci_platform_table,
248 + .probe = ehci_platform_probe,
249 + .remove = __devexit_p(ehci_platform_remove),
250 + .shutdown = usb_hcd_platform_shutdown,
252 + .owner = THIS_MODULE,
253 + .name = "ehci-platform",
254 + .pm = &ehci_platform_pm_ops,
258 +++ b/include/linux/usb/ehci_pdriver.h
261 + * Copyright (C) 2012 Hauke Mehrtens <hauke@hauke-m.de>
263 + * This program is free software; you can redistribute it and/or modify it
264 + * under the terms of the GNU General Public License as published by the
265 + * Free Software Foundation; either version 2 of the License, or (at your
266 + * option) any later version.
268 + * This program is distributed in the hope that it will be useful, but
269 + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
270 + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
271 + * for more details.
273 + * You should have received a copy of the GNU General Public License
274 + * along with this program; if not, write to the Free Software Foundation,
275 + * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
278 +#ifndef __USB_CORE_EHCI_PDRIVER_H
279 +#define __USB_CORE_EHCI_PDRIVER_H
282 + * struct usb_ehci_pdata - platform_data for generic ehci driver
284 + * @caps_offset: offset of the EHCI Capability Registers to the start of
285 + * the io memory region provided to the driver.
286 + * @has_tt: set to 1 if TT is integrated in root hub.
287 + * @port_power_on: set to 1 if the controller needs a power up after
289 + * @port_power_off: set to 1 if the controller needs to be powered down
290 + * after initialization.
292 + * These are general configuration options for the EHCI controller. All of
293 + * these options are activating more or less workarounds for some hardware.
295 +struct usb_ehci_pdata {
298 + unsigned has_synopsys_hc_bug:1;
299 + unsigned big_endian_desc:1;
300 + unsigned big_endian_mmio:1;
301 + unsigned port_power_on:1;
302 + unsigned port_power_off:1;
305 +#endif /* __USB_CORE_EHCI_PDRIVER_H */