| 1 | From 1be00523336ac484c52681f838dfb8a76e8531cd Mon Sep 17 00:00:00 2001 |
| 2 | From: Hauke Mehrtens <hauke@hauke-m.de> |
| 3 | Date: Sat, 26 Nov 2011 21:28:56 +0100 |
| 4 | Subject: [PATCH 182/186] USB: EHCI: Add a generic platform device driver |
| 5 | |
| 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. |
| 10 | |
| 11 | Signed-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 | 199 ++++++++++++++++++++++++++++++++++++++ |
| 16 | 3 files changed, 214 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 | @@ -1329,6 +1329,11 @@ MODULE_LICENSE ("GPL"); |
| 41 | #define PLATFORM_DRIVER ehci_xls_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,199 @@ |
| 55 | +/* |
| 56 | + * Generic platform ehci driver |
| 57 | + * |
| 58 | + * Copyright 2007 Steven Brown <sbrown@cortland.com> |
| 59 | + * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de> |
| 60 | + * |
| 61 | + * Derived from the ohci-ssb driver |
| 62 | + * Copyright 2007 Michael Buesch <m@bues.ch> |
| 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 | +#include <linux/usb/hci_driver.h> |
| 77 | + |
| 78 | +static int ehci_platform_reset(struct usb_hcd *hcd) |
| 79 | +{ |
| 80 | + struct platform_device *pdev = to_platform_device(hcd->self.controller); |
| 81 | + struct usb_hci_pdata *pdata = pdev->dev.platform_data; |
| 82 | + struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 83 | + int caps_offset = 0; |
| 84 | + int flags = 0; |
| 85 | + int retval; |
| 86 | + |
| 87 | + if (pdata) { |
| 88 | + caps_offset = pdata->caps_offset; |
| 89 | + flags = pdata->flags; |
| 90 | + } |
| 91 | + |
| 92 | + if (flags & USB_HCI_PDATA_HAS_TT_SET) |
| 93 | + hcd->has_tt = pdata->has_tt; |
| 94 | + |
| 95 | + ehci->caps = hcd->regs + caps_offset; |
| 96 | + retval = ehci_setup(hcd); |
| 97 | + if (retval) |
| 98 | + return retval; |
| 99 | + |
| 100 | + if (flags & USB_HCI_PDATA_PORT_POWER_SET) |
| 101 | + ehci_port_power(ehci, pdata->power_set_is_on); |
| 102 | + |
| 103 | + return 0; |
| 104 | +} |
| 105 | + |
| 106 | +static const struct hc_driver ehci_platform_hc_driver = { |
| 107 | + .description = hcd_name, |
| 108 | + .product_desc = "Generic Platform EHCI Controller", |
| 109 | + .hcd_priv_size = sizeof(struct ehci_hcd), |
| 110 | + |
| 111 | + .irq = ehci_irq, |
| 112 | + .flags = HCD_MEMORY | HCD_USB2, |
| 113 | + |
| 114 | + .reset = ehci_platform_reset, |
| 115 | + .start = ehci_run, |
| 116 | + .stop = ehci_stop, |
| 117 | + .shutdown = ehci_shutdown, |
| 118 | + |
| 119 | + .urb_enqueue = ehci_urb_enqueue, |
| 120 | + .urb_dequeue = ehci_urb_dequeue, |
| 121 | + .endpoint_disable = ehci_endpoint_disable, |
| 122 | + .endpoint_reset = ehci_endpoint_reset, |
| 123 | + |
| 124 | + .get_frame_number = ehci_get_frame, |
| 125 | + |
| 126 | + .hub_status_data = ehci_hub_status_data, |
| 127 | + .hub_control = ehci_hub_control, |
| 128 | +#if defined(CONFIG_PM) |
| 129 | + .bus_suspend = ehci_bus_suspend, |
| 130 | + .bus_resume = ehci_bus_resume, |
| 131 | +#endif |
| 132 | + .relinquish_port = ehci_relinquish_port, |
| 133 | + .port_handed_over = ehci_port_handed_over, |
| 134 | + |
| 135 | + .update_device = ehci_update_device, |
| 136 | + |
| 137 | + .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 138 | +}; |
| 139 | + |
| 140 | +static int __devinit ehci_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 | + if (usb_disabled()) |
| 148 | + return -ENODEV; |
| 149 | + |
| 150 | + irq = platform_get_irq(dev, 0); |
| 151 | + if (irq < 0) { |
| 152 | + pr_err("no irq provieded"); |
| 153 | + return irq; |
| 154 | + } |
| 155 | + res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 156 | + if (!res_mem) { |
| 157 | + pr_err("no memory recourse provieded"); |
| 158 | + return -ENXIO; |
| 159 | + } |
| 160 | + |
| 161 | + hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev, |
| 162 | + dev_name(&dev->dev)); |
| 163 | + if (!hcd) |
| 164 | + return -ENOMEM; |
| 165 | + |
| 166 | + hcd->rsrc_start = res_mem->start; |
| 167 | + hcd->rsrc_len = resource_size(res_mem); |
| 168 | + |
| 169 | + if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { |
| 170 | + pr_err("controller already in use"); |
| 171 | + err = -EBUSY; |
| 172 | + goto err_put_hcd; |
| 173 | + } |
| 174 | + |
| 175 | + hcd->regs = ioremap_nocache(hcd->rsrc_start, hcd->rsrc_len); |
| 176 | + if (!hcd->regs) |
| 177 | + goto err_release_region; |
| 178 | + err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 179 | + if (err) |
| 180 | + goto err_iounmap; |
| 181 | + |
| 182 | + platform_set_drvdata(dev, hcd); |
| 183 | + |
| 184 | + return err; |
| 185 | + |
| 186 | +err_iounmap: |
| 187 | + iounmap(hcd->regs); |
| 188 | +err_release_region: |
| 189 | + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 190 | +err_put_hcd: |
| 191 | + usb_put_hcd(hcd); |
| 192 | + return err; |
| 193 | +} |
| 194 | + |
| 195 | +static int __devexit ehci_platform_remove(struct platform_device *dev) |
| 196 | +{ |
| 197 | + struct usb_hcd *hcd = platform_get_drvdata(dev); |
| 198 | + |
| 199 | + usb_remove_hcd(hcd); |
| 200 | + iounmap(hcd->regs); |
| 201 | + release_mem_region(hcd->rsrc_start, hcd->rsrc_len); |
| 202 | + usb_put_hcd(hcd); |
| 203 | + platform_set_drvdata(dev, NULL); |
| 204 | + |
| 205 | + return 0; |
| 206 | +} |
| 207 | + |
| 208 | +#ifdef CONFIG_PM |
| 209 | + |
| 210 | +static int ehci_platform_suspend(struct device *dev) |
| 211 | +{ |
| 212 | + struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 213 | + bool wakeup = device_may_wakeup(dev); |
| 214 | + |
| 215 | + ehci_prepare_ports_for_controller_suspend(hcd_to_ehci(hcd), wakeup); |
| 216 | + return 0; |
| 217 | +} |
| 218 | + |
| 219 | +static int ehci_platform_resume(struct device *dev) |
| 220 | +{ |
| 221 | + struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 222 | + |
| 223 | + ehci_prepare_ports_for_controller_resume(hcd_to_ehci(hcd)); |
| 224 | + return 0; |
| 225 | +} |
| 226 | + |
| 227 | +#else /* !CONFIG_PM */ |
| 228 | +#define ehci_platform_suspend NULL |
| 229 | +#define ehci_platform_resume NULL |
| 230 | +#endif /* CONFIG_PM */ |
| 231 | + |
| 232 | +static const struct platform_device_id ehci_platform_table[] = { |
| 233 | + { "ehci-platform", 0 }, |
| 234 | + { } |
| 235 | +}; |
| 236 | +MODULE_DEVICE_TABLE(platform, ehci_platform_table); |
| 237 | + |
| 238 | +static const struct dev_pm_ops ehci_platform_pm_ops = { |
| 239 | + .suspend = ehci_platform_suspend, |
| 240 | + .resume = ehci_platform_resume, |
| 241 | +}; |
| 242 | + |
| 243 | +static struct platform_driver ehci_platform_driver = { |
| 244 | + .id_table = ehci_platform_table, |
| 245 | + .probe = ehci_platform_probe, |
| 246 | + .remove = __devexit_p(ehci_platform_remove), |
| 247 | + .shutdown = usb_hcd_platform_shutdown, |
| 248 | + .driver = { |
| 249 | + .owner = THIS_MODULE, |
| 250 | + .name = "ehci-platform", |
| 251 | + .pm = &ehci_platform_pm_ops, |
| 252 | + } |
| 253 | +}; |
| 254 | |