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