Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Generic platform ohci driver |
| 3 | * |
| 4 | * Copyright 2007 Michael Buesch <m@bues.ch> |
| 5 | * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de> |
| 6 | * |
| 7 | * Derived from the OCHI-SSB driver |
| 8 | * Derived from the OHCI-PCI driver |
| 9 | * Copyright 1999 Roman Weissgaerber |
| 10 | * Copyright 2000-2002 David Brownell |
| 11 | * Copyright 1999 Linus Torvalds |
| 12 | * Copyright 1999 Gregory P. Smith |
| 13 | * |
| 14 | * Licensed under the GNU/GPL. See COPYING for details. |
| 15 | */ |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 16 | |
| 17 | #include <linux/hrtimer.h> |
| 18 | #include <linux/io.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/module.h> |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 21 | #include <linux/err.h> |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/usb/ohci_pdriver.h> |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 24 | #include <linux/usb.h> |
| 25 | #include <linux/usb/hcd.h> |
| 26 | |
| 27 | #include "ohci.h" |
| 28 | |
| 29 | #define DRIVER_DESC "OHCI generic platform driver" |
| 30 | |
| 31 | static const char hcd_name[] = "ohci-platform"; |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 32 | |
| 33 | static int ohci_platform_reset(struct usb_hcd *hcd) |
| 34 | { |
| 35 | struct platform_device *pdev = to_platform_device(hcd->self.controller); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 36 | struct usb_ohci_pdata *pdata = dev_get_platdata(&pdev->dev); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 37 | struct ohci_hcd *ohci = hcd_to_ohci(hcd); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 38 | |
| 39 | if (pdata->big_endian_desc) |
| 40 | ohci->flags |= OHCI_QUIRK_BE_DESC; |
| 41 | if (pdata->big_endian_mmio) |
| 42 | ohci->flags |= OHCI_QUIRK_BE_MMIO; |
| 43 | if (pdata->no_big_frame_no) |
| 44 | ohci->flags |= OHCI_QUIRK_FRAME_NO; |
Florian Fainelli | 2b16e39 | 2012-10-08 15:11:26 +0200 | [diff] [blame] | 45 | if (pdata->num_ports) |
| 46 | ohci->num_ports = pdata->num_ports; |
| 47 | |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 48 | return ohci_setup(hcd); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 49 | } |
| 50 | |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 51 | static struct hc_driver __read_mostly ohci_platform_hc_driver; |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 52 | |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 53 | static const struct ohci_driver_overrides platform_overrides __initconst = { |
| 54 | .product_desc = "Generic Platform OHCI controller", |
| 55 | .reset = ohci_platform_reset, |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 56 | }; |
| 57 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 58 | static int ohci_platform_probe(struct platform_device *dev) |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 59 | { |
| 60 | struct usb_hcd *hcd; |
| 61 | struct resource *res_mem; |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 62 | struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 63 | int irq; |
| 64 | int err = -ENOMEM; |
| 65 | |
Kuninori Morimoto | b6dd245 | 2012-08-06 18:07:30 -0700 | [diff] [blame] | 66 | if (!pdata) { |
| 67 | WARN_ON(1); |
| 68 | return -ENODEV; |
| 69 | } |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 70 | |
| 71 | if (usb_disabled()) |
| 72 | return -ENODEV; |
| 73 | |
| 74 | irq = platform_get_irq(dev, 0); |
| 75 | if (irq < 0) { |
Florian Fainelli | 976baf6e | 2012-10-08 15:11:42 +0200 | [diff] [blame] | 76 | dev_err(&dev->dev, "no irq provided"); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 77 | return irq; |
| 78 | } |
| 79 | |
| 80 | res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 81 | if (!res_mem) { |
Florian Fainelli | ac0e3c0 | 2012-10-08 15:11:44 +0200 | [diff] [blame] | 82 | dev_err(&dev->dev, "no memory resource provided"); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 83 | return -ENXIO; |
| 84 | } |
| 85 | |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 86 | if (pdata->power_on) { |
| 87 | err = pdata->power_on(dev); |
| 88 | if (err < 0) |
| 89 | return err; |
| 90 | } |
| 91 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 92 | hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev, |
| 93 | dev_name(&dev->dev)); |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 94 | if (!hcd) { |
| 95 | err = -ENOMEM; |
| 96 | goto err_power; |
| 97 | } |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 98 | |
| 99 | hcd->rsrc_start = res_mem->start; |
| 100 | hcd->rsrc_len = resource_size(res_mem); |
| 101 | |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 102 | hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); |
| 103 | if (IS_ERR(hcd->regs)) { |
| 104 | err = PTR_ERR(hcd->regs); |
Florian Fainelli | be7ac70 | 2012-10-08 15:11:46 +0200 | [diff] [blame] | 105 | goto err_put_hcd; |
Julia Lawall | aece389 | 2012-08-14 08:47:37 +0200 | [diff] [blame] | 106 | } |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 107 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 108 | if (err) |
Florian Fainelli | be7ac70 | 2012-10-08 15:11:46 +0200 | [diff] [blame] | 109 | goto err_put_hcd; |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 110 | |
| 111 | platform_set_drvdata(dev, hcd); |
| 112 | |
| 113 | return err; |
| 114 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 115 | err_put_hcd: |
| 116 | usb_put_hcd(hcd); |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 117 | err_power: |
| 118 | if (pdata->power_off) |
| 119 | pdata->power_off(dev); |
| 120 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 121 | return err; |
| 122 | } |
| 123 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 124 | static int ohci_platform_remove(struct platform_device *dev) |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 125 | { |
| 126 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 127 | struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 128 | |
| 129 | usb_remove_hcd(hcd); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 130 | usb_put_hcd(hcd); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 131 | |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 132 | if (pdata->power_off) |
| 133 | pdata->power_off(dev); |
| 134 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 135 | return 0; |
| 136 | } |
| 137 | |
| 138 | #ifdef CONFIG_PM |
| 139 | |
| 140 | static int ohci_platform_suspend(struct device *dev) |
| 141 | { |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 142 | struct usb_ohci_pdata *pdata = dev_get_platdata(dev); |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 143 | struct platform_device *pdev = |
| 144 | container_of(dev, struct platform_device, dev); |
| 145 | |
| 146 | if (pdata->power_suspend) |
| 147 | pdata->power_suspend(pdev); |
| 148 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 149 | return 0; |
| 150 | } |
| 151 | |
| 152 | static int ohci_platform_resume(struct device *dev) |
| 153 | { |
| 154 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 155 | struct usb_ohci_pdata *pdata = dev_get_platdata(dev); |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 156 | struct platform_device *pdev = |
| 157 | container_of(dev, struct platform_device, dev); |
| 158 | |
| 159 | if (pdata->power_on) { |
| 160 | int err = pdata->power_on(pdev); |
| 161 | if (err < 0) |
| 162 | return err; |
| 163 | } |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 164 | |
Florian Fainelli | cfa49b4 | 2012-10-08 15:11:29 +0200 | [diff] [blame] | 165 | ohci_resume(hcd, false); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | #else /* !CONFIG_PM */ |
| 170 | #define ohci_platform_suspend NULL |
| 171 | #define ohci_platform_resume NULL |
| 172 | #endif /* CONFIG_PM */ |
| 173 | |
| 174 | static const struct platform_device_id ohci_platform_table[] = { |
| 175 | { "ohci-platform", 0 }, |
| 176 | { } |
| 177 | }; |
| 178 | MODULE_DEVICE_TABLE(platform, ohci_platform_table); |
| 179 | |
| 180 | static const struct dev_pm_ops ohci_platform_pm_ops = { |
| 181 | .suspend = ohci_platform_suspend, |
| 182 | .resume = ohci_platform_resume, |
| 183 | }; |
| 184 | |
| 185 | static struct platform_driver ohci_platform_driver = { |
| 186 | .id_table = ohci_platform_table, |
| 187 | .probe = ohci_platform_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 188 | .remove = ohci_platform_remove, |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 189 | .shutdown = usb_hcd_platform_shutdown, |
| 190 | .driver = { |
| 191 | .owner = THIS_MODULE, |
| 192 | .name = "ohci-platform", |
| 193 | .pm = &ohci_platform_pm_ops, |
| 194 | } |
| 195 | }; |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 196 | |
| 197 | static int __init ohci_platform_init(void) |
| 198 | { |
| 199 | if (usb_disabled()) |
| 200 | return -ENODEV; |
| 201 | |
| 202 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 203 | |
| 204 | ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides); |
| 205 | return platform_driver_register(&ohci_platform_driver); |
| 206 | } |
| 207 | module_init(ohci_platform_init); |
| 208 | |
| 209 | static void __exit ohci_platform_cleanup(void) |
| 210 | { |
| 211 | platform_driver_unregister(&ohci_platform_driver); |
| 212 | } |
| 213 | module_exit(ohci_platform_cleanup); |
| 214 | |
| 215 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 216 | MODULE_AUTHOR("Hauke Mehrtens"); |
| 217 | MODULE_AUTHOR("Alan Stern"); |
| 218 | MODULE_LICENSE("GPL"); |