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); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 42 | struct usb_ehci_pdata *pdata = dev_get_platdata(&pdev->dev); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 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 | |
Sergei Shtylyov | 743fcce | 2013-06-02 01:33:56 +0400 | [diff] [blame] | 51 | if (pdata->pre_setup) { |
| 52 | retval = pdata->pre_setup(hcd); |
| 53 | if (retval < 0) |
| 54 | return retval; |
| 55 | } |
| 56 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 57 | ehci->caps = hcd->regs + pdata->caps_offset; |
| 58 | retval = ehci_setup(hcd); |
| 59 | if (retval) |
| 60 | return retval; |
| 61 | |
Florian Fainelli | 4534874 | 2012-10-08 15:11:21 +0200 | [diff] [blame] | 62 | if (pdata->no_io_watchdog) |
| 63 | ehci->need_io_watchdog = 0; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 67 | static struct hc_driver __read_mostly ehci_platform_hc_driver; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 68 | |
Andi Kleen | 62d08a1 | 2013-04-22 09:44:56 -0700 | [diff] [blame] | 69 | static const struct ehci_driver_overrides platform_overrides __initconst = { |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 70 | .reset = ehci_platform_reset, |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 71 | }; |
| 72 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 73 | static struct usb_ehci_pdata ehci_platform_defaults; |
| 74 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 75 | static int ehci_platform_probe(struct platform_device *dev) |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 76 | { |
| 77 | struct usb_hcd *hcd; |
| 78 | struct resource *res_mem; |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 79 | struct usb_ehci_pdata *pdata; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 80 | int irq; |
Russell King | 22d9d8e | 2013-06-10 16:28:49 +0100 | [diff] [blame] | 81 | int err; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 82 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 83 | if (usb_disabled()) |
| 84 | return -ENODEV; |
| 85 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 86 | /* |
| 87 | * use reasonable defaults so platforms don't have to provide these. |
| 88 | * with DT probing on ARM, none of these are set. |
| 89 | */ |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 90 | if (!dev_get_platdata(&dev->dev)) |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 91 | dev->dev.platform_data = &ehci_platform_defaults; |
Russell King | e1fd734 | 2013-06-27 12:36:37 +0100 | [diff] [blame^] | 92 | |
| 93 | err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32)); |
Russell King | 22d9d8e | 2013-06-10 16:28:49 +0100 | [diff] [blame] | 94 | if (err) |
| 95 | return err; |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 96 | |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 97 | pdata = dev_get_platdata(&dev->dev); |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 98 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 99 | irq = platform_get_irq(dev, 0); |
| 100 | if (irq < 0) { |
Florian Fainelli | 2350cb0 | 2012-10-08 15:11:41 +0200 | [diff] [blame] | 101 | dev_err(&dev->dev, "no irq provided"); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 102 | return irq; |
| 103 | } |
| 104 | res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 105 | if (!res_mem) { |
Florian Fainelli | 5c9b2b2 | 2012-10-08 15:11:43 +0200 | [diff] [blame] | 106 | dev_err(&dev->dev, "no memory resource provided"); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 107 | return -ENXIO; |
| 108 | } |
| 109 | |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 110 | if (pdata->power_on) { |
| 111 | err = pdata->power_on(dev); |
| 112 | if (err < 0) |
| 113 | return err; |
| 114 | } |
| 115 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 116 | hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev, |
| 117 | dev_name(&dev->dev)); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 118 | if (!hcd) { |
| 119 | err = -ENOMEM; |
| 120 | goto err_power; |
| 121 | } |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 122 | |
| 123 | hcd->rsrc_start = res_mem->start; |
| 124 | hcd->rsrc_len = resource_size(res_mem); |
| 125 | |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 126 | hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); |
| 127 | if (IS_ERR(hcd->regs)) { |
| 128 | err = PTR_ERR(hcd->regs); |
Florian Fainelli | 61ff274 | 2012-10-08 15:11:45 +0200 | [diff] [blame] | 129 | goto err_put_hcd; |
Julia Lawall | ec03ad8 | 2012-08-14 08:47:38 +0200 | [diff] [blame] | 130 | } |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 131 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 132 | if (err) |
Florian Fainelli | 61ff274 | 2012-10-08 15:11:45 +0200 | [diff] [blame] | 133 | goto err_put_hcd; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 134 | |
| 135 | platform_set_drvdata(dev, hcd); |
| 136 | |
| 137 | return err; |
| 138 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 139 | err_put_hcd: |
| 140 | usb_put_hcd(hcd); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 141 | err_power: |
| 142 | if (pdata->power_off) |
| 143 | pdata->power_off(dev); |
| 144 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 145 | return err; |
| 146 | } |
| 147 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 148 | static int ehci_platform_remove(struct platform_device *dev) |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 149 | { |
| 150 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 151 | struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 152 | |
| 153 | usb_remove_hcd(hcd); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 154 | usb_put_hcd(hcd); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 155 | |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 156 | if (pdata->power_off) |
| 157 | pdata->power_off(dev); |
| 158 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 159 | if (pdata == &ehci_platform_defaults) |
| 160 | dev->dev.platform_data = NULL; |
| 161 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 162 | return 0; |
| 163 | } |
| 164 | |
| 165 | #ifdef CONFIG_PM |
| 166 | |
| 167 | static int ehci_platform_suspend(struct device *dev) |
| 168 | { |
| 169 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 170 | struct usb_ehci_pdata *pdata = dev_get_platdata(dev); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 171 | struct platform_device *pdev = |
| 172 | container_of(dev, struct platform_device, dev); |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 173 | bool do_wakeup = device_may_wakeup(dev); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 174 | int ret; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 175 | |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 176 | ret = ehci_suspend(hcd, do_wakeup); |
| 177 | |
| 178 | if (pdata->power_suspend) |
| 179 | pdata->power_suspend(pdev); |
| 180 | |
| 181 | return ret; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | static int ehci_platform_resume(struct device *dev) |
| 185 | { |
| 186 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 187 | struct usb_ehci_pdata *pdata = dev_get_platdata(dev); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 188 | struct platform_device *pdev = |
| 189 | container_of(dev, struct platform_device, dev); |
| 190 | |
| 191 | if (pdata->power_on) { |
| 192 | int err = pdata->power_on(pdev); |
| 193 | if (err < 0) |
| 194 | return err; |
| 195 | } |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 196 | |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 197 | ehci_resume(hcd, false); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | #else /* !CONFIG_PM */ |
| 202 | #define ehci_platform_suspend NULL |
| 203 | #define ehci_platform_resume NULL |
| 204 | #endif /* CONFIG_PM */ |
| 205 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 206 | static const struct of_device_id vt8500_ehci_ids[] = { |
| 207 | { .compatible = "via,vt8500-ehci", }, |
| 208 | { .compatible = "wm,prizm-ehci", }, |
| 209 | {} |
| 210 | }; |
| 211 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 212 | static const struct platform_device_id ehci_platform_table[] = { |
| 213 | { "ehci-platform", 0 }, |
| 214 | { } |
| 215 | }; |
| 216 | MODULE_DEVICE_TABLE(platform, ehci_platform_table); |
| 217 | |
| 218 | static const struct dev_pm_ops ehci_platform_pm_ops = { |
| 219 | .suspend = ehci_platform_suspend, |
| 220 | .resume = ehci_platform_resume, |
| 221 | }; |
| 222 | |
| 223 | static struct platform_driver ehci_platform_driver = { |
| 224 | .id_table = ehci_platform_table, |
| 225 | .probe = ehci_platform_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 226 | .remove = ehci_platform_remove, |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 227 | .shutdown = usb_hcd_platform_shutdown, |
| 228 | .driver = { |
| 229 | .owner = THIS_MODULE, |
| 230 | .name = "ehci-platform", |
| 231 | .pm = &ehci_platform_pm_ops, |
Sachin Kamat | ae5e5f7 | 2013-05-21 17:17:16 +0530 | [diff] [blame] | 232 | .of_match_table = vt8500_ehci_ids, |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 233 | } |
| 234 | }; |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 235 | |
| 236 | static int __init ehci_platform_init(void) |
| 237 | { |
| 238 | if (usb_disabled()) |
| 239 | return -ENODEV; |
| 240 | |
| 241 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 242 | |
| 243 | ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides); |
| 244 | return platform_driver_register(&ehci_platform_driver); |
| 245 | } |
| 246 | module_init(ehci_platform_init); |
| 247 | |
| 248 | static void __exit ehci_platform_cleanup(void) |
| 249 | { |
| 250 | platform_driver_unregister(&ehci_platform_driver); |
| 251 | } |
| 252 | module_exit(ehci_platform_cleanup); |
| 253 | |
| 254 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 255 | MODULE_AUTHOR("Hauke Mehrtens"); |
| 256 | MODULE_AUTHOR("Alan Stern"); |
| 257 | MODULE_LICENSE("GPL"); |