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