Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Generic platform ehci driver |
| 3 | * |
| 4 | * Copyright 2007 Steven Brown <sbrown@cortland.com> |
| 5 | * Copyright 2010-2012 Hauke Mehrtens <hauke@hauke-m.de> |
| 6 | * |
| 7 | * Derived from the ohci-ssb driver |
| 8 | * Copyright 2007 Michael Buesch <m@bues.ch> |
| 9 | * |
| 10 | * Derived from the EHCI-PCI driver |
| 11 | * Copyright (c) 2000-2004 by David Brownell |
| 12 | * |
| 13 | * Derived from the ohci-pci driver |
| 14 | * Copyright 1999 Roman Weissgaerber |
| 15 | * Copyright 2000-2002 David Brownell |
| 16 | * Copyright 1999 Linus Torvalds |
| 17 | * Copyright 1999 Gregory P. Smith |
| 18 | * |
| 19 | * Licensed under the GNU/GPL. See COPYING for details. |
| 20 | */ |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame^] | 21 | #include <linux/dma-mapping.h> |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 22 | #include <linux/err.h> |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 23 | #include <linux/kernel.h> |
Alan Stern | d1bb67a | 2012-11-02 10:13:24 -0400 | [diff] [blame] | 24 | #include <linux/hrtimer.h> |
| 25 | #include <linux/io.h> |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 26 | #include <linux/module.h> |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame^] | 27 | #include <linux/of.h> |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 28 | #include <linux/platform_device.h> |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 29 | #include <linux/usb.h> |
| 30 | #include <linux/usb/hcd.h> |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 31 | #include <linux/usb/ehci_pdriver.h> |
| 32 | |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 33 | #include "ehci.h" |
| 34 | |
| 35 | #define DRIVER_DESC "EHCI generic platform driver" |
| 36 | |
| 37 | static const char hcd_name[] = "ehci-platform"; |
| 38 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 39 | static int ehci_platform_reset(struct usb_hcd *hcd) |
| 40 | { |
| 41 | struct platform_device *pdev = to_platform_device(hcd->self.controller); |
| 42 | struct usb_ehci_pdata *pdata = pdev->dev.platform_data; |
| 43 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 44 | int retval; |
| 45 | |
| 46 | hcd->has_tt = pdata->has_tt; |
| 47 | ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug; |
| 48 | ehci->big_endian_desc = pdata->big_endian_desc; |
| 49 | ehci->big_endian_mmio = pdata->big_endian_mmio; |
| 50 | |
| 51 | ehci->caps = hcd->regs + pdata->caps_offset; |
| 52 | retval = ehci_setup(hcd); |
| 53 | if (retval) |
| 54 | return retval; |
| 55 | |
Florian Fainelli | 4534874 | 2012-10-08 15:11:21 +0200 | [diff] [blame] | 56 | if (pdata->no_io_watchdog) |
| 57 | ehci->need_io_watchdog = 0; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 58 | return 0; |
| 59 | } |
| 60 | |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 61 | static struct hc_driver __read_mostly ehci_platform_hc_driver; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 62 | |
Alan Stern | 1b36810 | 2012-11-07 16:12:47 -0500 | [diff] [blame] | 63 | static const struct ehci_driver_overrides platform_overrides __initdata = { |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 64 | .reset = ehci_platform_reset, |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame^] | 67 | static struct usb_ehci_pdata ehci_platform_defaults; |
| 68 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 69 | static int ehci_platform_probe(struct platform_device *dev) |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 70 | { |
| 71 | struct usb_hcd *hcd; |
| 72 | struct resource *res_mem; |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame^] | 73 | struct usb_ehci_pdata *pdata; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 74 | int irq; |
| 75 | int err = -ENOMEM; |
| 76 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 77 | if (usb_disabled()) |
| 78 | return -ENODEV; |
| 79 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame^] | 80 | /* |
| 81 | * use reasonable defaults so platforms don't have to provide these. |
| 82 | * with DT probing on ARM, none of these are set. |
| 83 | */ |
| 84 | if (!dev->dev.platform_data) |
| 85 | dev->dev.platform_data = &ehci_platform_defaults; |
| 86 | if (!dev->dev.dma_mask) |
| 87 | dev->dev.dma_mask = &dev->dev.coherent_dma_mask; |
| 88 | if (!dev->dev.coherent_dma_mask) |
| 89 | dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 90 | |
| 91 | pdata = dev->dev.platform_data; |
| 92 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 93 | irq = platform_get_irq(dev, 0); |
| 94 | if (irq < 0) { |
Florian Fainelli | 2350cb0 | 2012-10-08 15:11:41 +0200 | [diff] [blame] | 95 | dev_err(&dev->dev, "no irq provided"); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 96 | return irq; |
| 97 | } |
| 98 | res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 99 | if (!res_mem) { |
Florian Fainelli | 5c9b2b2 | 2012-10-08 15:11:43 +0200 | [diff] [blame] | 100 | dev_err(&dev->dev, "no memory resource provided"); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 101 | return -ENXIO; |
| 102 | } |
| 103 | |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 104 | if (pdata->power_on) { |
| 105 | err = pdata->power_on(dev); |
| 106 | if (err < 0) |
| 107 | return err; |
| 108 | } |
| 109 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 110 | hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev, |
| 111 | dev_name(&dev->dev)); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 112 | if (!hcd) { |
| 113 | err = -ENOMEM; |
| 114 | goto err_power; |
| 115 | } |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 116 | |
| 117 | hcd->rsrc_start = res_mem->start; |
| 118 | hcd->rsrc_len = resource_size(res_mem); |
| 119 | |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 120 | hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); |
| 121 | if (IS_ERR(hcd->regs)) { |
| 122 | err = PTR_ERR(hcd->regs); |
Florian Fainelli | 61ff274 | 2012-10-08 15:11:45 +0200 | [diff] [blame] | 123 | goto err_put_hcd; |
Julia Lawall | ec03ad8 | 2012-08-14 08:47:38 +0200 | [diff] [blame] | 124 | } |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 125 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 126 | if (err) |
Florian Fainelli | 61ff274 | 2012-10-08 15:11:45 +0200 | [diff] [blame] | 127 | goto err_put_hcd; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 128 | |
| 129 | platform_set_drvdata(dev, hcd); |
| 130 | |
| 131 | return err; |
| 132 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 133 | err_put_hcd: |
| 134 | usb_put_hcd(hcd); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 135 | err_power: |
| 136 | if (pdata->power_off) |
| 137 | pdata->power_off(dev); |
| 138 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 139 | return err; |
| 140 | } |
| 141 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 142 | static int ehci_platform_remove(struct platform_device *dev) |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 143 | { |
| 144 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 145 | struct usb_ehci_pdata *pdata = dev->dev.platform_data; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 146 | |
| 147 | usb_remove_hcd(hcd); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 148 | usb_put_hcd(hcd); |
| 149 | platform_set_drvdata(dev, NULL); |
| 150 | |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 151 | if (pdata->power_off) |
| 152 | pdata->power_off(dev); |
| 153 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame^] | 154 | if (pdata == &ehci_platform_defaults) |
| 155 | dev->dev.platform_data = NULL; |
| 156 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | #ifdef CONFIG_PM |
| 161 | |
| 162 | static int ehci_platform_suspend(struct device *dev) |
| 163 | { |
| 164 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 165 | struct usb_ehci_pdata *pdata = dev->platform_data; |
| 166 | struct platform_device *pdev = |
| 167 | container_of(dev, struct platform_device, dev); |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 168 | bool do_wakeup = device_may_wakeup(dev); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 169 | int ret; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 170 | |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 171 | ret = ehci_suspend(hcd, do_wakeup); |
| 172 | |
| 173 | if (pdata->power_suspend) |
| 174 | pdata->power_suspend(pdev); |
| 175 | |
| 176 | return ret; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | static int ehci_platform_resume(struct device *dev) |
| 180 | { |
| 181 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 182 | struct usb_ehci_pdata *pdata = dev->platform_data; |
| 183 | struct platform_device *pdev = |
| 184 | container_of(dev, struct platform_device, dev); |
| 185 | |
| 186 | if (pdata->power_on) { |
| 187 | int err = pdata->power_on(pdev); |
| 188 | if (err < 0) |
| 189 | return err; |
| 190 | } |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 191 | |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 192 | ehci_resume(hcd, false); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 193 | return 0; |
| 194 | } |
| 195 | |
| 196 | #else /* !CONFIG_PM */ |
| 197 | #define ehci_platform_suspend NULL |
| 198 | #define ehci_platform_resume NULL |
| 199 | #endif /* CONFIG_PM */ |
| 200 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame^] | 201 | static const struct of_device_id vt8500_ehci_ids[] = { |
| 202 | { .compatible = "via,vt8500-ehci", }, |
| 203 | { .compatible = "wm,prizm-ehci", }, |
| 204 | {} |
| 205 | }; |
| 206 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 207 | static const struct platform_device_id ehci_platform_table[] = { |
| 208 | { "ehci-platform", 0 }, |
| 209 | { } |
| 210 | }; |
| 211 | MODULE_DEVICE_TABLE(platform, ehci_platform_table); |
| 212 | |
| 213 | static const struct dev_pm_ops ehci_platform_pm_ops = { |
| 214 | .suspend = ehci_platform_suspend, |
| 215 | .resume = ehci_platform_resume, |
| 216 | }; |
| 217 | |
| 218 | static struct platform_driver ehci_platform_driver = { |
| 219 | .id_table = ehci_platform_table, |
| 220 | .probe = ehci_platform_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 221 | .remove = ehci_platform_remove, |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 222 | .shutdown = usb_hcd_platform_shutdown, |
| 223 | .driver = { |
| 224 | .owner = THIS_MODULE, |
| 225 | .name = "ehci-platform", |
| 226 | .pm = &ehci_platform_pm_ops, |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame^] | 227 | .of_match_table = of_match_ptr(vt8500_ehci_ids), |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 228 | } |
| 229 | }; |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 230 | |
| 231 | static int __init ehci_platform_init(void) |
| 232 | { |
| 233 | if (usb_disabled()) |
| 234 | return -ENODEV; |
| 235 | |
| 236 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 237 | |
| 238 | ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides); |
| 239 | return platform_driver_register(&ehci_platform_driver); |
| 240 | } |
| 241 | module_init(ehci_platform_init); |
| 242 | |
| 243 | static void __exit ehci_platform_cleanup(void) |
| 244 | { |
| 245 | platform_driver_unregister(&ehci_platform_driver); |
| 246 | } |
| 247 | module_exit(ehci_platform_cleanup); |
| 248 | |
| 249 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 250 | MODULE_AUTHOR("Hauke Mehrtens"); |
| 251 | MODULE_AUTHOR("Alan Stern"); |
| 252 | MODULE_LICENSE("GPL"); |