Greg Kroah-Hartman | 5fd54ac | 2017-11-03 11:28:30 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Generic platform ohci driver |
| 4 | * |
| 5 | * Copyright 2007 Michael Buesch <m@bues.ch> |
| 6 | * Copyright 2011-2012 Hauke Mehrtens <hauke@hauke-m.de> |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 7 | * Copyright 2014 Hans de Goede <hdegoede@redhat.com> |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 8 | * |
| 9 | * Derived from the OCHI-SSB driver |
| 10 | * Derived from the OHCI-PCI driver |
| 11 | * Copyright 1999 Roman Weissgaerber |
| 12 | * Copyright 2000-2002 David Brownell |
| 13 | * Copyright 1999 Linus Torvalds |
| 14 | * Copyright 1999 Gregory P. Smith |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 15 | */ |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 16 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 17 | #include <linux/clk.h> |
| 18 | #include <linux/dma-mapping.h> |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 19 | #include <linux/hrtimer.h> |
| 20 | #include <linux/io.h> |
| 21 | #include <linux/kernel.h> |
| 22 | #include <linux/module.h> |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 23 | #include <linux/err.h> |
Martin Blumenstingl | 1255dfd | 2018-03-03 22:43:08 +0100 | [diff] [blame] | 24 | #include <linux/of.h> |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 25 | #include <linux/platform_device.h> |
Tony Lindgren | 0aa0b93 | 2017-05-25 09:13:31 -0700 | [diff] [blame] | 26 | #include <linux/pm_runtime.h> |
Maxime Ripard | 4615f3b | 2014-05-13 17:44:20 +0200 | [diff] [blame] | 27 | #include <linux/reset.h> |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 28 | #include <linux/usb/ohci_pdriver.h> |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 29 | #include <linux/usb.h> |
| 30 | #include <linux/usb/hcd.h> |
| 31 | |
| 32 | #include "ohci.h" |
| 33 | |
| 34 | #define DRIVER_DESC "OHCI generic platform driver" |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 35 | #define OHCI_MAX_CLKS 3 |
| 36 | #define hcd_to_ohci_priv(h) ((struct ohci_platform_priv *)hcd_to_ohci(h)->priv) |
| 37 | |
| 38 | struct ohci_platform_priv { |
| 39 | struct clk *clks[OHCI_MAX_CLKS]; |
Masahiro Yamada | 20a7f3a | 2017-11-02 01:01:59 +0900 | [diff] [blame] | 40 | struct reset_control *resets; |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 41 | }; |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 42 | |
| 43 | static const char hcd_name[] = "ohci-platform"; |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 44 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 45 | static int ohci_platform_power_on(struct platform_device *dev) |
| 46 | { |
| 47 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
| 48 | struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd); |
Martin Blumenstingl | 1255dfd | 2018-03-03 22:43:08 +0100 | [diff] [blame] | 49 | int clk, ret; |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 50 | |
| 51 | for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) { |
| 52 | ret = clk_prepare_enable(priv->clks[clk]); |
| 53 | if (ret) |
| 54 | goto err_disable_clks; |
| 55 | } |
| 56 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 57 | return 0; |
| 58 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 59 | err_disable_clks: |
| 60 | while (--clk >= 0) |
| 61 | clk_disable_unprepare(priv->clks[clk]); |
| 62 | |
| 63 | return ret; |
| 64 | } |
| 65 | |
| 66 | static void ohci_platform_power_off(struct platform_device *dev) |
| 67 | { |
| 68 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
| 69 | struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd); |
Martin Blumenstingl | 1255dfd | 2018-03-03 22:43:08 +0100 | [diff] [blame] | 70 | int clk; |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 71 | |
| 72 | for (clk = OHCI_MAX_CLKS - 1; clk >= 0; clk--) |
| 73 | if (priv->clks[clk]) |
| 74 | clk_disable_unprepare(priv->clks[clk]); |
| 75 | } |
| 76 | |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 77 | static struct hc_driver __read_mostly ohci_platform_hc_driver; |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 78 | |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 79 | static const struct ohci_driver_overrides platform_overrides __initconst = { |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 80 | .product_desc = "Generic Platform OHCI controller", |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 81 | .extra_priv_size = sizeof(struct ohci_platform_priv), |
| 82 | }; |
| 83 | |
| 84 | static struct usb_ohci_pdata ohci_platform_defaults = { |
| 85 | .power_on = ohci_platform_power_on, |
| 86 | .power_suspend = ohci_platform_power_off, |
| 87 | .power_off = ohci_platform_power_off, |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 88 | }; |
| 89 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 90 | static int ohci_platform_probe(struct platform_device *dev) |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 91 | { |
| 92 | struct usb_hcd *hcd; |
| 93 | struct resource *res_mem; |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 94 | struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev); |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 95 | struct ohci_platform_priv *priv; |
Hans de Goede | b103441 | 2014-02-07 16:36:42 +0100 | [diff] [blame] | 96 | struct ohci_hcd *ohci; |
Martin Blumenstingl | 1255dfd | 2018-03-03 22:43:08 +0100 | [diff] [blame] | 97 | int err, irq, clk = 0; |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 98 | |
| 99 | if (usb_disabled()) |
| 100 | return -ENODEV; |
| 101 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 102 | /* |
| 103 | * Use reasonable defaults so platforms don't have to provide these |
| 104 | * with DT probing on ARM. |
| 105 | */ |
| 106 | if (!pdata) |
| 107 | pdata = &ohci_platform_defaults; |
| 108 | |
| 109 | err = dma_coerce_mask_and_coherent(&dev->dev, DMA_BIT_MASK(32)); |
| 110 | if (err) |
| 111 | return err; |
| 112 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 113 | irq = platform_get_irq(dev, 0); |
| 114 | if (irq < 0) { |
Florian Fainelli | 976baf6 | 2012-10-08 15:11:42 +0200 | [diff] [blame] | 115 | dev_err(&dev->dev, "no irq provided"); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 116 | return irq; |
| 117 | } |
| 118 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 119 | hcd = usb_create_hcd(&ohci_platform_hc_driver, &dev->dev, |
| 120 | dev_name(&dev->dev)); |
| 121 | if (!hcd) |
| 122 | return -ENOMEM; |
| 123 | |
| 124 | platform_set_drvdata(dev, hcd); |
| 125 | dev->dev.platform_data = pdata; |
| 126 | priv = hcd_to_ohci_priv(hcd); |
Hans de Goede | b103441 | 2014-02-07 16:36:42 +0100 | [diff] [blame] | 127 | ohci = hcd_to_ohci(hcd); |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 128 | |
| 129 | if (pdata == &ohci_platform_defaults && dev->dev.of_node) { |
Hans de Goede | b103441 | 2014-02-07 16:36:42 +0100 | [diff] [blame] | 130 | if (of_property_read_bool(dev->dev.of_node, "big-endian-regs")) |
| 131 | ohci->flags |= OHCI_QUIRK_BE_MMIO; |
| 132 | |
| 133 | if (of_property_read_bool(dev->dev.of_node, "big-endian-desc")) |
| 134 | ohci->flags |= OHCI_QUIRK_BE_DESC; |
| 135 | |
| 136 | if (of_property_read_bool(dev->dev.of_node, "big-endian")) |
| 137 | ohci->flags |= OHCI_QUIRK_BE_MMIO | OHCI_QUIRK_BE_DESC; |
| 138 | |
Kevin Cernekee | c4b8692 | 2014-10-11 11:10:48 -0700 | [diff] [blame] | 139 | if (of_property_read_bool(dev->dev.of_node, "no-big-frame-no")) |
| 140 | ohci->flags |= OHCI_QUIRK_FRAME_NO; |
| 141 | |
Tony Lindgren | 2545d85 | 2017-05-25 09:13:32 -0700 | [diff] [blame] | 142 | if (of_property_read_bool(dev->dev.of_node, |
| 143 | "remote-wakeup-connected")) |
| 144 | ohci->hc_control = OHCI_CTRL_RWC; |
| 145 | |
Kevin Cernekee | c4b8692 | 2014-10-11 11:10:48 -0700 | [diff] [blame] | 146 | of_property_read_u32(dev->dev.of_node, "num-ports", |
| 147 | &ohci->num_ports); |
| 148 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 149 | for (clk = 0; clk < OHCI_MAX_CLKS; clk++) { |
| 150 | priv->clks[clk] = of_clk_get(dev->dev.of_node, clk); |
| 151 | if (IS_ERR(priv->clks[clk])) { |
| 152 | err = PTR_ERR(priv->clks[clk]); |
| 153 | if (err == -EPROBE_DEFER) |
| 154 | goto err_put_clks; |
| 155 | priv->clks[clk] = NULL; |
| 156 | break; |
| 157 | } |
| 158 | } |
Masahiro Yamada | 20a7f3a | 2017-11-02 01:01:59 +0900 | [diff] [blame] | 159 | |
| 160 | priv->resets = devm_reset_control_array_get_optional_shared( |
| 161 | &dev->dev); |
| 162 | if (IS_ERR(priv->resets)) { |
| 163 | err = PTR_ERR(priv->resets); |
| 164 | goto err_put_clks; |
Hans de Goede | 62d9694 | 2016-06-02 17:14:06 +0200 | [diff] [blame] | 165 | } |
Masahiro Yamada | 20a7f3a | 2017-11-02 01:01:59 +0900 | [diff] [blame] | 166 | |
| 167 | err = reset_control_deassert(priv->resets); |
| 168 | if (err) |
| 169 | goto err_put_clks; |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 170 | } |
| 171 | |
Alan Stern | adff529 | 2014-02-11 11:26:00 -0500 | [diff] [blame] | 172 | if (pdata->big_endian_desc) |
| 173 | ohci->flags |= OHCI_QUIRK_BE_DESC; |
| 174 | if (pdata->big_endian_mmio) |
| 175 | ohci->flags |= OHCI_QUIRK_BE_MMIO; |
Kevin Cernekee | 46f2194 | 2014-10-11 11:10:49 -0700 | [diff] [blame] | 176 | if (pdata->no_big_frame_no) |
| 177 | ohci->flags |= OHCI_QUIRK_FRAME_NO; |
| 178 | if (pdata->num_ports) |
| 179 | ohci->num_ports = pdata->num_ports; |
Alan Stern | adff529 | 2014-02-11 11:26:00 -0500 | [diff] [blame] | 180 | |
| 181 | #ifndef CONFIG_USB_OHCI_BIG_ENDIAN_MMIO |
| 182 | if (ohci->flags & OHCI_QUIRK_BE_MMIO) { |
| 183 | dev_err(&dev->dev, |
| 184 | "Error: CONFIG_USB_OHCI_BIG_ENDIAN_MMIO not set\n"); |
| 185 | err = -EINVAL; |
Maxime Ripard | 4615f3b | 2014-05-13 17:44:20 +0200 | [diff] [blame] | 186 | goto err_reset; |
Alan Stern | adff529 | 2014-02-11 11:26:00 -0500 | [diff] [blame] | 187 | } |
| 188 | #endif |
| 189 | #ifndef CONFIG_USB_OHCI_BIG_ENDIAN_DESC |
| 190 | if (ohci->flags & OHCI_QUIRK_BE_DESC) { |
| 191 | dev_err(&dev->dev, |
| 192 | "Error: CONFIG_USB_OHCI_BIG_ENDIAN_DESC not set\n"); |
| 193 | err = -EINVAL; |
Maxime Ripard | 4615f3b | 2014-05-13 17:44:20 +0200 | [diff] [blame] | 194 | goto err_reset; |
Alan Stern | adff529 | 2014-02-11 11:26:00 -0500 | [diff] [blame] | 195 | } |
| 196 | #endif |
| 197 | |
Tony Lindgren | 0aa0b93 | 2017-05-25 09:13:31 -0700 | [diff] [blame] | 198 | pm_runtime_set_active(&dev->dev); |
| 199 | pm_runtime_enable(&dev->dev); |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 200 | if (pdata->power_on) { |
| 201 | err = pdata->power_on(dev); |
| 202 | if (err < 0) |
Maxime Ripard | 4615f3b | 2014-05-13 17:44:20 +0200 | [diff] [blame] | 203 | goto err_reset; |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 204 | } |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 205 | |
Varka Bhadram | 7b51929 | 2014-11-04 07:51:16 +0530 | [diff] [blame] | 206 | res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 207 | hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); |
| 208 | if (IS_ERR(hcd->regs)) { |
| 209 | err = PTR_ERR(hcd->regs); |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 210 | goto err_power; |
Julia Lawall | aece389 | 2012-08-14 08:47:37 +0200 | [diff] [blame] | 211 | } |
Varka Bhadram | 7b51929 | 2014-11-04 07:51:16 +0530 | [diff] [blame] | 212 | hcd->rsrc_start = res_mem->start; |
| 213 | hcd->rsrc_len = resource_size(res_mem); |
| 214 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 215 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 216 | if (err) |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 217 | goto err_power; |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 218 | |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 219 | device_wakeup_enable(hcd->self.controller); |
| 220 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 221 | platform_set_drvdata(dev, hcd); |
| 222 | |
| 223 | return err; |
| 224 | |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 225 | err_power: |
| 226 | if (pdata->power_off) |
| 227 | pdata->power_off(dev); |
Maxime Ripard | 4615f3b | 2014-05-13 17:44:20 +0200 | [diff] [blame] | 228 | err_reset: |
Tony Lindgren | 0aa0b93 | 2017-05-25 09:13:31 -0700 | [diff] [blame] | 229 | pm_runtime_disable(&dev->dev); |
Masahiro Yamada | 20a7f3a | 2017-11-02 01:01:59 +0900 | [diff] [blame] | 230 | reset_control_assert(priv->resets); |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 231 | err_put_clks: |
| 232 | while (--clk >= 0) |
| 233 | clk_put(priv->clks[clk]); |
Martin Blumenstingl | 1255dfd | 2018-03-03 22:43:08 +0100 | [diff] [blame] | 234 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 235 | if (pdata == &ohci_platform_defaults) |
| 236 | dev->dev.platform_data = NULL; |
| 237 | |
| 238 | usb_put_hcd(hcd); |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 239 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 240 | return err; |
| 241 | } |
| 242 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 243 | static int ohci_platform_remove(struct platform_device *dev) |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 244 | { |
| 245 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 246 | struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev); |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 247 | struct ohci_platform_priv *priv = hcd_to_ohci_priv(hcd); |
Masahiro Yamada | 20a7f3a | 2017-11-02 01:01:59 +0900 | [diff] [blame] | 248 | int clk; |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 249 | |
Tony Lindgren | 0aa0b93 | 2017-05-25 09:13:31 -0700 | [diff] [blame] | 250 | pm_runtime_get_sync(&dev->dev); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 251 | usb_remove_hcd(hcd); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 252 | |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 253 | if (pdata->power_off) |
| 254 | pdata->power_off(dev); |
| 255 | |
Masahiro Yamada | 20a7f3a | 2017-11-02 01:01:59 +0900 | [diff] [blame] | 256 | reset_control_assert(priv->resets); |
Maxime Ripard | 4615f3b | 2014-05-13 17:44:20 +0200 | [diff] [blame] | 257 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 258 | for (clk = 0; clk < OHCI_MAX_CLKS && priv->clks[clk]; clk++) |
| 259 | clk_put(priv->clks[clk]); |
| 260 | |
| 261 | usb_put_hcd(hcd); |
| 262 | |
Tony Lindgren | 0aa0b93 | 2017-05-25 09:13:31 -0700 | [diff] [blame] | 263 | pm_runtime_put_sync(&dev->dev); |
| 264 | pm_runtime_disable(&dev->dev); |
| 265 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 266 | if (pdata == &ohci_platform_defaults) |
| 267 | dev->dev.platform_data = NULL; |
| 268 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 269 | return 0; |
| 270 | } |
| 271 | |
Wonhong Kwon | 5e4ccd9 | 2014-10-24 13:45:47 +0900 | [diff] [blame] | 272 | #ifdef CONFIG_PM_SLEEP |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 273 | static int ohci_platform_suspend(struct device *dev) |
| 274 | { |
Manjunath Goudar | 39dbd7d | 2013-10-04 09:58:14 +0530 | [diff] [blame] | 275 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 276 | struct usb_ohci_pdata *pdata = dev->platform_data; |
Geliang Tang | 20db551 | 2015-12-23 21:26:52 +0800 | [diff] [blame] | 277 | struct platform_device *pdev = to_platform_device(dev); |
Manjunath Goudar | 39dbd7d | 2013-10-04 09:58:14 +0530 | [diff] [blame] | 278 | bool do_wakeup = device_may_wakeup(dev); |
| 279 | int ret; |
| 280 | |
| 281 | ret = ohci_suspend(hcd, do_wakeup); |
| 282 | if (ret) |
| 283 | return ret; |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 284 | |
| 285 | if (pdata->power_suspend) |
| 286 | pdata->power_suspend(pdev); |
| 287 | |
Manjunath Goudar | 39dbd7d | 2013-10-04 09:58:14 +0530 | [diff] [blame] | 288 | return ret; |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | static int ohci_platform_resume(struct device *dev) |
| 292 | { |
| 293 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 294 | struct usb_ohci_pdata *pdata = dev_get_platdata(dev); |
Geliang Tang | 20db551 | 2015-12-23 21:26:52 +0800 | [diff] [blame] | 295 | struct platform_device *pdev = to_platform_device(dev); |
Kuninori Morimoto | e4d37ae | 2012-08-06 18:09:10 -0700 | [diff] [blame] | 296 | |
| 297 | if (pdata->power_on) { |
| 298 | int err = pdata->power_on(pdev); |
| 299 | if (err < 0) |
| 300 | return err; |
| 301 | } |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 302 | |
Florian Fainelli | cfa49b4 | 2012-10-08 15:11:29 +0200 | [diff] [blame] | 303 | ohci_resume(hcd, false); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 304 | return 0; |
| 305 | } |
Wonhong Kwon | 5e4ccd9 | 2014-10-24 13:45:47 +0900 | [diff] [blame] | 306 | #endif /* CONFIG_PM_SLEEP */ |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 307 | |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 308 | static const struct of_device_id ohci_platform_ids[] = { |
Hans de Goede | ce149c3 | 2014-02-11 17:35:28 +0100 | [diff] [blame] | 309 | { .compatible = "generic-ohci", }, |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 310 | { .compatible = "cavium,octeon-6335-ohci", }, |
Tony Lindgren | 2545d85 | 2017-05-25 09:13:32 -0700 | [diff] [blame] | 311 | { .compatible = "ti,ohci-omap3", }, |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 312 | { } |
| 313 | }; |
| 314 | MODULE_DEVICE_TABLE(of, ohci_platform_ids); |
| 315 | |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 316 | static const struct platform_device_id ohci_platform_table[] = { |
| 317 | { "ohci-platform", 0 }, |
| 318 | { } |
| 319 | }; |
| 320 | MODULE_DEVICE_TABLE(platform, ohci_platform_table); |
| 321 | |
Wonhong Kwon | 5e4ccd9 | 2014-10-24 13:45:47 +0900 | [diff] [blame] | 322 | static SIMPLE_DEV_PM_OPS(ohci_platform_pm_ops, ohci_platform_suspend, |
| 323 | ohci_platform_resume); |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 324 | |
| 325 | static struct platform_driver ohci_platform_driver = { |
| 326 | .id_table = ohci_platform_table, |
| 327 | .probe = ohci_platform_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 328 | .remove = ohci_platform_remove, |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 329 | .shutdown = usb_hcd_platform_shutdown, |
| 330 | .driver = { |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 331 | .name = "ohci-platform", |
| 332 | .pm = &ohci_platform_pm_ops, |
Hans de Goede | ca52a17 | 2014-02-07 16:36:40 +0100 | [diff] [blame] | 333 | .of_match_table = ohci_platform_ids, |
Hauke Mehrtens | fa3364b | 2012-03-13 01:04:47 +0100 | [diff] [blame] | 334 | } |
| 335 | }; |
Manjunath Goudar | 928fb68 | 2013-06-03 20:46:08 +0530 | [diff] [blame] | 336 | |
| 337 | static int __init ohci_platform_init(void) |
| 338 | { |
| 339 | if (usb_disabled()) |
| 340 | return -ENODEV; |
| 341 | |
| 342 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 343 | |
| 344 | ohci_init_driver(&ohci_platform_hc_driver, &platform_overrides); |
| 345 | return platform_driver_register(&ohci_platform_driver); |
| 346 | } |
| 347 | module_init(ohci_platform_init); |
| 348 | |
| 349 | static void __exit ohci_platform_cleanup(void) |
| 350 | { |
| 351 | platform_driver_unregister(&ohci_platform_driver); |
| 352 | } |
| 353 | module_exit(ohci_platform_cleanup); |
| 354 | |
| 355 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 356 | MODULE_AUTHOR("Hauke Mehrtens"); |
| 357 | MODULE_AUTHOR("Alan Stern"); |
| 358 | MODULE_LICENSE("GPL"); |