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> |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 6 | * Copyright 2014 Hans de Goede <hdegoede@redhat.com> |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 7 | * |
| 8 | * Derived from the ohci-ssb driver |
| 9 | * Copyright 2007 Michael Buesch <m@bues.ch> |
| 10 | * |
| 11 | * Derived from the EHCI-PCI driver |
| 12 | * Copyright (c) 2000-2004 by David Brownell |
| 13 | * |
| 14 | * Derived from the ohci-pci driver |
| 15 | * Copyright 1999 Roman Weissgaerber |
| 16 | * Copyright 2000-2002 David Brownell |
| 17 | * Copyright 1999 Linus Torvalds |
| 18 | * Copyright 1999 Gregory P. Smith |
| 19 | * |
| 20 | * Licensed under the GNU/GPL. See COPYING for details. |
| 21 | */ |
Jeremy Linton | 776c15d | 2015-08-19 16:36:32 -0500 | [diff] [blame] | 22 | #include <linux/acpi.h> |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 23 | #include <linux/clk.h> |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 24 | #include <linux/dma-mapping.h> |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 25 | #include <linux/err.h> |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 26 | #include <linux/kernel.h> |
Alan Stern | d1bb67a | 2012-11-02 10:13:24 -0400 | [diff] [blame] | 27 | #include <linux/hrtimer.h> |
| 28 | #include <linux/io.h> |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 29 | #include <linux/module.h> |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 30 | #include <linux/of.h> |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 31 | #include <linux/phy/phy.h> |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 32 | #include <linux/platform_device.h> |
Boris BREZILLON | 2d87bbd | 2014-05-13 17:44:19 +0200 | [diff] [blame] | 33 | #include <linux/reset.h> |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 34 | #include <linux/usb.h> |
| 35 | #include <linux/usb/hcd.h> |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 36 | #include <linux/usb/ehci_pdriver.h> |
Yoshihiro Shimoda | d4d7512 | 2017-02-21 19:59:48 +0900 | [diff] [blame] | 37 | #include <linux/usb/of.h> |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 38 | |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 39 | #include "ehci.h" |
| 40 | |
| 41 | #define DRIVER_DESC "EHCI generic platform driver" |
Icenowy Zheng | 73577d6 | 2016-08-12 11:06:22 +0800 | [diff] [blame] | 42 | #define EHCI_MAX_CLKS 4 |
Masahiro Yamada | 1e4b434 | 2016-10-17 20:11:59 +0900 | [diff] [blame] | 43 | #define EHCI_MAX_RSTS 4 |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 44 | #define hcd_to_ehci_priv(h) ((struct ehci_platform_priv *)hcd_to_ehci(h)->priv) |
| 45 | |
| 46 | struct ehci_platform_priv { |
| 47 | struct clk *clks[EHCI_MAX_CLKS]; |
Jiancheng Xue | d0e08b0 | 2016-05-12 09:41:37 +0800 | [diff] [blame] | 48 | struct reset_control *rsts[EHCI_MAX_RSTS]; |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 49 | struct phy **phys; |
| 50 | int num_phys; |
Alban Bedel | b4629a7 | 2015-08-04 10:59:17 +0200 | [diff] [blame] | 51 | bool reset_on_resume; |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 52 | }; |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 53 | |
| 54 | static const char hcd_name[] = "ehci-platform"; |
| 55 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 56 | static int ehci_platform_reset(struct usb_hcd *hcd) |
| 57 | { |
| 58 | struct platform_device *pdev = to_platform_device(hcd->self.controller); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 59 | struct usb_ehci_pdata *pdata = dev_get_platdata(&pdev->dev); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 60 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 61 | int retval; |
| 62 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 63 | ehci->has_synopsys_hc_bug = pdata->has_synopsys_hc_bug; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 64 | |
Sergei Shtylyov | 743fcce | 2013-06-02 01:33:56 +0400 | [diff] [blame] | 65 | if (pdata->pre_setup) { |
| 66 | retval = pdata->pre_setup(hcd); |
| 67 | if (retval < 0) |
| 68 | return retval; |
| 69 | } |
| 70 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 71 | ehci->caps = hcd->regs + pdata->caps_offset; |
| 72 | retval = ehci_setup(hcd); |
| 73 | if (retval) |
| 74 | return retval; |
| 75 | |
Florian Fainelli | 4534874 | 2012-10-08 15:11:21 +0200 | [diff] [blame] | 76 | if (pdata->no_io_watchdog) |
| 77 | ehci->need_io_watchdog = 0; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 78 | return 0; |
| 79 | } |
| 80 | |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 81 | static int ehci_platform_power_on(struct platform_device *dev) |
| 82 | { |
| 83 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
| 84 | struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 85 | int clk, ret, phy_num; |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 86 | |
| 87 | for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++) { |
| 88 | ret = clk_prepare_enable(priv->clks[clk]); |
| 89 | if (ret) |
| 90 | goto err_disable_clks; |
| 91 | } |
| 92 | |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 93 | for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { |
Arun Ramamurthy | 216e299 | 2015-04-22 16:04:12 -0700 | [diff] [blame] | 94 | ret = phy_init(priv->phys[phy_num]); |
| 95 | if (ret) |
| 96 | goto err_exit_phy; |
| 97 | ret = phy_power_on(priv->phys[phy_num]); |
| 98 | if (ret) { |
| 99 | phy_exit(priv->phys[phy_num]); |
| 100 | goto err_exit_phy; |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 101 | } |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | return 0; |
| 105 | |
| 106 | err_exit_phy: |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 107 | while (--phy_num >= 0) { |
Arun Ramamurthy | 216e299 | 2015-04-22 16:04:12 -0700 | [diff] [blame] | 108 | phy_power_off(priv->phys[phy_num]); |
| 109 | phy_exit(priv->phys[phy_num]); |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 110 | } |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 111 | err_disable_clks: |
| 112 | while (--clk >= 0) |
| 113 | clk_disable_unprepare(priv->clks[clk]); |
| 114 | |
| 115 | return ret; |
| 116 | } |
| 117 | |
| 118 | static void ehci_platform_power_off(struct platform_device *dev) |
| 119 | { |
| 120 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
| 121 | struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 122 | int clk, phy_num; |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 123 | |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 124 | for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { |
Arun Ramamurthy | 216e299 | 2015-04-22 16:04:12 -0700 | [diff] [blame] | 125 | phy_power_off(priv->phys[phy_num]); |
| 126 | phy_exit(priv->phys[phy_num]); |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | for (clk = EHCI_MAX_CLKS - 1; clk >= 0; clk--) |
| 130 | if (priv->clks[clk]) |
| 131 | clk_disable_unprepare(priv->clks[clk]); |
| 132 | } |
| 133 | |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 134 | static struct hc_driver __read_mostly ehci_platform_hc_driver; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 135 | |
Andi Kleen | 62d08a1 | 2013-04-22 09:44:56 -0700 | [diff] [blame] | 136 | static const struct ehci_driver_overrides platform_overrides __initconst = { |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 137 | .reset = ehci_platform_reset, |
| 138 | .extra_priv_size = sizeof(struct ehci_platform_priv), |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 139 | }; |
| 140 | |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 141 | static struct usb_ehci_pdata ehci_platform_defaults = { |
| 142 | .power_on = ehci_platform_power_on, |
| 143 | .power_suspend = ehci_platform_power_off, |
| 144 | .power_off = ehci_platform_power_off, |
| 145 | }; |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 146 | |
Bill Pemberton | 41ac7b3 | 2012-11-19 13:21:48 -0500 | [diff] [blame] | 147 | static int ehci_platform_probe(struct platform_device *dev) |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 148 | { |
| 149 | struct usb_hcd *hcd; |
| 150 | struct resource *res_mem; |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 151 | struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev); |
| 152 | struct ehci_platform_priv *priv; |
Hans de Goede | ad3db5d | 2014-02-07 16:36:43 +0100 | [diff] [blame] | 153 | struct ehci_hcd *ehci; |
Jiancheng Xue | d0e08b0 | 2016-05-12 09:41:37 +0800 | [diff] [blame] | 154 | int err, irq, phy_num, clk = 0, rst; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 155 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 156 | if (usb_disabled()) |
| 157 | return -ENODEV; |
| 158 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 159 | /* |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 160 | * Use reasonable defaults so platforms don't have to provide these |
| 161 | * with DT probing on ARM. |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 162 | */ |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 163 | if (!pdata) |
| 164 | pdata = &ehci_platform_defaults; |
Russell King | e1fd734 | 2013-06-27 12:36:37 +0100 | [diff] [blame] | 165 | |
Andreas Herrmann | c99e76c | 2015-01-12 16:05:52 +0100 | [diff] [blame] | 166 | err = dma_coerce_mask_and_coherent(&dev->dev, |
| 167 | pdata->dma_mask_64 ? DMA_BIT_MASK(64) : DMA_BIT_MASK(32)); |
Jeremy Linton | 17f69b5 | 2015-08-19 16:36:31 -0500 | [diff] [blame] | 168 | if (err) { |
| 169 | dev_err(&dev->dev, "Error: DMA mask configuration failed\n"); |
Russell King | 22d9d8e | 2013-06-10 16:28:49 +0100 | [diff] [blame] | 170 | return err; |
Jeremy Linton | 17f69b5 | 2015-08-19 16:36:31 -0500 | [diff] [blame] | 171 | } |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 172 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 173 | irq = platform_get_irq(dev, 0); |
| 174 | if (irq < 0) { |
Florian Fainelli | 2350cb0 | 2012-10-08 15:11:41 +0200 | [diff] [blame] | 175 | dev_err(&dev->dev, "no irq provided"); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 176 | return irq; |
| 177 | } |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 178 | |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 179 | hcd = usb_create_hcd(&ehci_platform_hc_driver, &dev->dev, |
| 180 | dev_name(&dev->dev)); |
| 181 | if (!hcd) |
| 182 | return -ENOMEM; |
| 183 | |
| 184 | platform_set_drvdata(dev, hcd); |
| 185 | dev->dev.platform_data = pdata; |
| 186 | priv = hcd_to_ehci_priv(hcd); |
Hans de Goede | ad3db5d | 2014-02-07 16:36:43 +0100 | [diff] [blame] | 187 | ehci = hcd_to_ehci(hcd); |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 188 | |
| 189 | if (pdata == &ehci_platform_defaults && dev->dev.of_node) { |
Hans de Goede | ad3db5d | 2014-02-07 16:36:43 +0100 | [diff] [blame] | 190 | if (of_property_read_bool(dev->dev.of_node, "big-endian-regs")) |
| 191 | ehci->big_endian_mmio = 1; |
| 192 | |
| 193 | if (of_property_read_bool(dev->dev.of_node, "big-endian-desc")) |
| 194 | ehci->big_endian_desc = 1; |
| 195 | |
| 196 | if (of_property_read_bool(dev->dev.of_node, "big-endian")) |
| 197 | ehci->big_endian_mmio = ehci->big_endian_desc = 1; |
| 198 | |
Wu Liang feng | 314b41b | 2014-12-24 18:22:19 +0800 | [diff] [blame] | 199 | if (of_property_read_bool(dev->dev.of_node, |
| 200 | "needs-reset-on-resume")) |
Alban Bedel | b4629a7 | 2015-08-04 10:59:17 +0200 | [diff] [blame] | 201 | priv->reset_on_resume = true; |
Wu Liang feng | 314b41b | 2014-12-24 18:22:19 +0800 | [diff] [blame] | 202 | |
Joachim Eastwood | 40f2f2a | 2015-05-16 17:17:40 +0200 | [diff] [blame] | 203 | if (of_property_read_bool(dev->dev.of_node, |
| 204 | "has-transaction-translator")) |
Alban Bedel | b4629a7 | 2015-08-04 10:59:17 +0200 | [diff] [blame] | 205 | hcd->has_tt = 1; |
Joachim Eastwood | 40f2f2a | 2015-05-16 17:17:40 +0200 | [diff] [blame] | 206 | |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 207 | priv->num_phys = of_count_phandle_with_args(dev->dev.of_node, |
| 208 | "phys", "#phy-cells"); |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 209 | |
Arun Ramamurthy | 216e299 | 2015-04-22 16:04:12 -0700 | [diff] [blame] | 210 | if (priv->num_phys > 0) { |
| 211 | priv->phys = devm_kcalloc(&dev->dev, priv->num_phys, |
| 212 | sizeof(struct phy *), GFP_KERNEL); |
| 213 | if (!priv->phys) |
| 214 | return -ENOMEM; |
| 215 | } else |
| 216 | priv->num_phys = 0; |
Arun Ramamurthy | 7e7a0e6 | 2015-01-19 16:05:29 -0800 | [diff] [blame] | 217 | |
| 218 | for (phy_num = 0; phy_num < priv->num_phys; phy_num++) { |
Arun Ramamurthy | 216e299 | 2015-04-22 16:04:12 -0700 | [diff] [blame] | 219 | priv->phys[phy_num] = devm_of_phy_get_by_index( |
| 220 | &dev->dev, dev->dev.of_node, phy_num); |
| 221 | if (IS_ERR(priv->phys[phy_num])) { |
| 222 | err = PTR_ERR(priv->phys[phy_num]); |
| 223 | goto err_put_hcd; |
Yoshihiro Shimoda | 42a58c9 | 2017-03-13 15:25:23 +0900 | [diff] [blame] | 224 | } else if (!hcd->phy) { |
| 225 | /* Avoiding phy_get() in usb_add_hcd() */ |
| 226 | hcd->phy = priv->phys[phy_num]; |
Arun Ramamurthy | 216e299 | 2015-04-22 16:04:12 -0700 | [diff] [blame] | 227 | } |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | for (clk = 0; clk < EHCI_MAX_CLKS; clk++) { |
| 231 | priv->clks[clk] = of_clk_get(dev->dev.of_node, clk); |
| 232 | if (IS_ERR(priv->clks[clk])) { |
| 233 | err = PTR_ERR(priv->clks[clk]); |
| 234 | if (err == -EPROBE_DEFER) |
| 235 | goto err_put_clks; |
| 236 | priv->clks[clk] = NULL; |
| 237 | break; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
Jiancheng Xue | d0e08b0 | 2016-05-12 09:41:37 +0800 | [diff] [blame] | 242 | for (rst = 0; rst < EHCI_MAX_RSTS; rst++) { |
Hans de Goede | 76d15c8 | 2016-06-08 18:54:40 +0200 | [diff] [blame] | 243 | priv->rsts[rst] = devm_reset_control_get_shared_by_index( |
| 244 | &dev->dev, rst); |
Jiancheng Xue | d0e08b0 | 2016-05-12 09:41:37 +0800 | [diff] [blame] | 245 | if (IS_ERR(priv->rsts[rst])) { |
| 246 | err = PTR_ERR(priv->rsts[rst]); |
| 247 | if (err == -EPROBE_DEFER) |
| 248 | goto err_reset; |
| 249 | priv->rsts[rst] = NULL; |
| 250 | break; |
| 251 | } |
| 252 | |
| 253 | err = reset_control_deassert(priv->rsts[rst]); |
Hans de Goede | 76d15c8 | 2016-06-08 18:54:40 +0200 | [diff] [blame] | 254 | if (err) |
Jiancheng Xue | d0e08b0 | 2016-05-12 09:41:37 +0800 | [diff] [blame] | 255 | goto err_reset; |
Boris BREZILLON | 2d87bbd | 2014-05-13 17:44:19 +0200 | [diff] [blame] | 256 | } |
| 257 | |
Alan Stern | 843d5e0 | 2014-02-11 11:26:10 -0500 | [diff] [blame] | 258 | if (pdata->big_endian_desc) |
| 259 | ehci->big_endian_desc = 1; |
| 260 | if (pdata->big_endian_mmio) |
| 261 | ehci->big_endian_mmio = 1; |
Alban Bedel | b4629a7 | 2015-08-04 10:59:17 +0200 | [diff] [blame] | 262 | if (pdata->has_tt) |
| 263 | hcd->has_tt = 1; |
| 264 | if (pdata->reset_on_resume) |
| 265 | priv->reset_on_resume = true; |
Alan Stern | 843d5e0 | 2014-02-11 11:26:10 -0500 | [diff] [blame] | 266 | |
| 267 | #ifndef CONFIG_USB_EHCI_BIG_ENDIAN_MMIO |
| 268 | if (ehci->big_endian_mmio) { |
| 269 | dev_err(&dev->dev, |
| 270 | "Error: CONFIG_USB_EHCI_BIG_ENDIAN_MMIO not set\n"); |
| 271 | err = -EINVAL; |
Boris BREZILLON | 2d87bbd | 2014-05-13 17:44:19 +0200 | [diff] [blame] | 272 | goto err_reset; |
Alan Stern | 843d5e0 | 2014-02-11 11:26:10 -0500 | [diff] [blame] | 273 | } |
| 274 | #endif |
| 275 | #ifndef CONFIG_USB_EHCI_BIG_ENDIAN_DESC |
| 276 | if (ehci->big_endian_desc) { |
| 277 | dev_err(&dev->dev, |
| 278 | "Error: CONFIG_USB_EHCI_BIG_ENDIAN_DESC not set\n"); |
| 279 | err = -EINVAL; |
Boris BREZILLON | 2d87bbd | 2014-05-13 17:44:19 +0200 | [diff] [blame] | 280 | goto err_reset; |
Alan Stern | 843d5e0 | 2014-02-11 11:26:10 -0500 | [diff] [blame] | 281 | } |
| 282 | #endif |
| 283 | |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 284 | if (pdata->power_on) { |
| 285 | err = pdata->power_on(dev); |
| 286 | if (err < 0) |
Boris BREZILLON | 2d87bbd | 2014-05-13 17:44:19 +0200 | [diff] [blame] | 287 | goto err_reset; |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 288 | } |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 289 | |
Varka Bhadram | 2062ff4 | 2014-11-04 07:51:25 +0530 | [diff] [blame] | 290 | res_mem = platform_get_resource(dev, IORESOURCE_MEM, 0); |
Thierry Reding | 148e113 | 2013-01-21 11:09:22 +0100 | [diff] [blame] | 291 | hcd->regs = devm_ioremap_resource(&dev->dev, res_mem); |
| 292 | if (IS_ERR(hcd->regs)) { |
| 293 | err = PTR_ERR(hcd->regs); |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 294 | goto err_power; |
Julia Lawall | ec03ad8 | 2012-08-14 08:47:38 +0200 | [diff] [blame] | 295 | } |
Varka Bhadram | 2062ff4 | 2014-11-04 07:51:25 +0530 | [diff] [blame] | 296 | hcd->rsrc_start = res_mem->start; |
| 297 | hcd->rsrc_len = resource_size(res_mem); |
| 298 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 299 | err = usb_add_hcd(hcd, irq, IRQF_SHARED); |
| 300 | if (err) |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 301 | goto err_power; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 302 | |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 303 | device_wakeup_enable(hcd->self.controller); |
Yoshihiro Shimoda | d4d7512 | 2017-02-21 19:59:48 +0900 | [diff] [blame] | 304 | device_enable_async_suspend(hcd->self.controller); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 305 | platform_set_drvdata(dev, hcd); |
| 306 | |
| 307 | return err; |
| 308 | |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 309 | err_power: |
| 310 | if (pdata->power_off) |
| 311 | pdata->power_off(dev); |
Boris BREZILLON | 2d87bbd | 2014-05-13 17:44:19 +0200 | [diff] [blame] | 312 | err_reset: |
Hans de Goede | 76d15c8 | 2016-06-08 18:54:40 +0200 | [diff] [blame] | 313 | while (--rst >= 0) |
Jiancheng Xue | d0e08b0 | 2016-05-12 09:41:37 +0800 | [diff] [blame] | 314 | reset_control_assert(priv->rsts[rst]); |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 315 | err_put_clks: |
| 316 | while (--clk >= 0) |
| 317 | clk_put(priv->clks[clk]); |
| 318 | err_put_hcd: |
| 319 | if (pdata == &ehci_platform_defaults) |
| 320 | dev->dev.platform_data = NULL; |
| 321 | |
| 322 | usb_put_hcd(hcd); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 323 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 324 | return err; |
| 325 | } |
| 326 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 327 | static int ehci_platform_remove(struct platform_device *dev) |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 328 | { |
| 329 | struct usb_hcd *hcd = platform_get_drvdata(dev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 330 | struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev); |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 331 | struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); |
Jiancheng Xue | d0e08b0 | 2016-05-12 09:41:37 +0800 | [diff] [blame] | 332 | int clk, rst; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 333 | |
| 334 | usb_remove_hcd(hcd); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 335 | |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 336 | if (pdata->power_off) |
| 337 | pdata->power_off(dev); |
| 338 | |
Hans de Goede | 76d15c8 | 2016-06-08 18:54:40 +0200 | [diff] [blame] | 339 | for (rst = 0; rst < EHCI_MAX_RSTS && priv->rsts[rst]; rst++) |
Jiancheng Xue | d0e08b0 | 2016-05-12 09:41:37 +0800 | [diff] [blame] | 340 | reset_control_assert(priv->rsts[rst]); |
Boris BREZILLON | 2d87bbd | 2014-05-13 17:44:19 +0200 | [diff] [blame] | 341 | |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 342 | for (clk = 0; clk < EHCI_MAX_CLKS && priv->clks[clk]; clk++) |
| 343 | clk_put(priv->clks[clk]); |
| 344 | |
| 345 | usb_put_hcd(hcd); |
| 346 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 347 | if (pdata == &ehci_platform_defaults) |
| 348 | dev->dev.platform_data = NULL; |
| 349 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 350 | return 0; |
| 351 | } |
| 352 | |
Wonhong Kwon | 5e4ccd9 | 2014-10-24 13:45:47 +0900 | [diff] [blame] | 353 | #ifdef CONFIG_PM_SLEEP |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 354 | static int ehci_platform_suspend(struct device *dev) |
| 355 | { |
| 356 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 357 | struct usb_ehci_pdata *pdata = dev_get_platdata(dev); |
Geliang Tang | 20db551 | 2015-12-23 21:26:52 +0800 | [diff] [blame] | 358 | struct platform_device *pdev = to_platform_device(dev); |
Alan Stern | c5cf921 | 2012-06-28 11:19:02 -0400 | [diff] [blame] | 359 | bool do_wakeup = device_may_wakeup(dev); |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 360 | int ret; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 361 | |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 362 | ret = ehci_suspend(hcd, do_wakeup); |
Vivek Gautam | e155b5b | 2014-04-10 15:58:02 +0530 | [diff] [blame] | 363 | if (ret) |
| 364 | return ret; |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 365 | |
| 366 | if (pdata->power_suspend) |
| 367 | pdata->power_suspend(pdev); |
| 368 | |
| 369 | return ret; |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static int ehci_platform_resume(struct device *dev) |
| 373 | { |
| 374 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
Jingoo Han | d4f09e2 | 2013-07-30 19:59:40 +0900 | [diff] [blame] | 375 | struct usb_ehci_pdata *pdata = dev_get_platdata(dev); |
Geliang Tang | 20db551 | 2015-12-23 21:26:52 +0800 | [diff] [blame] | 376 | struct platform_device *pdev = to_platform_device(dev); |
Alban Bedel | b4629a7 | 2015-08-04 10:59:17 +0200 | [diff] [blame] | 377 | struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd); |
Yoshihiro Shimoda | d4d7512 | 2017-02-21 19:59:48 +0900 | [diff] [blame] | 378 | struct device *companion_dev; |
Kuninori Morimoto | 04216be | 2012-08-06 18:08:39 -0700 | [diff] [blame] | 379 | |
| 380 | if (pdata->power_on) { |
| 381 | int err = pdata->power_on(pdev); |
| 382 | if (err < 0) |
| 383 | return err; |
| 384 | } |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 385 | |
Yoshihiro Shimoda | d4d7512 | 2017-02-21 19:59:48 +0900 | [diff] [blame] | 386 | companion_dev = usb_of_get_companion_dev(hcd->self.controller); |
| 387 | if (companion_dev) |
| 388 | device_pm_wait_for_dev(hcd->self.controller, companion_dev); |
| 389 | |
Alban Bedel | b4629a7 | 2015-08-04 10:59:17 +0200 | [diff] [blame] | 390 | ehci_resume(hcd, priv->reset_on_resume); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 391 | return 0; |
| 392 | } |
Wonhong Kwon | 5e4ccd9 | 2014-10-24 13:45:47 +0900 | [diff] [blame] | 393 | #endif /* CONFIG_PM_SLEEP */ |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 394 | |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 395 | static const struct of_device_id vt8500_ehci_ids[] = { |
| 396 | { .compatible = "via,vt8500-ehci", }, |
| 397 | { .compatible = "wm,prizm-ehci", }, |
Hans de Goede | 915974c | 2014-02-11 17:35:29 +0100 | [diff] [blame] | 398 | { .compatible = "generic-ehci", }, |
Andreas Herrmann | a95cfa6 | 2015-01-06 13:48:56 +0100 | [diff] [blame] | 399 | { .compatible = "cavium,octeon-6335-ehci", }, |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 400 | {} |
| 401 | }; |
Hans de Goede | a4aeb21 | 2014-02-07 16:36:41 +0100 | [diff] [blame] | 402 | MODULE_DEVICE_TABLE(of, vt8500_ehci_ids); |
Arnd Bergmann | f3bc64d | 2013-03-27 21:44:22 +0000 | [diff] [blame] | 403 | |
Jeremy Linton | 776c15d | 2015-08-19 16:36:32 -0500 | [diff] [blame] | 404 | static const struct acpi_device_id ehci_acpi_match[] = { |
| 405 | { "PNP0D20", 0 }, /* EHCI controller without debug */ |
| 406 | { } |
| 407 | }; |
| 408 | MODULE_DEVICE_TABLE(acpi, ehci_acpi_match); |
| 409 | |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 410 | static const struct platform_device_id ehci_platform_table[] = { |
| 411 | { "ehci-platform", 0 }, |
| 412 | { } |
| 413 | }; |
| 414 | MODULE_DEVICE_TABLE(platform, ehci_platform_table); |
| 415 | |
Wonhong Kwon | 5e4ccd9 | 2014-10-24 13:45:47 +0900 | [diff] [blame] | 416 | static SIMPLE_DEV_PM_OPS(ehci_platform_pm_ops, ehci_platform_suspend, |
| 417 | ehci_platform_resume); |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 418 | |
| 419 | static struct platform_driver ehci_platform_driver = { |
| 420 | .id_table = ehci_platform_table, |
| 421 | .probe = ehci_platform_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 422 | .remove = ehci_platform_remove, |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 423 | .shutdown = usb_hcd_platform_shutdown, |
| 424 | .driver = { |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 425 | .name = "ehci-platform", |
| 426 | .pm = &ehci_platform_pm_ops, |
Sachin Kamat | ae5e5f7 | 2013-05-21 17:17:16 +0530 | [diff] [blame] | 427 | .of_match_table = vt8500_ehci_ids, |
Jeremy Linton | 776c15d | 2015-08-19 16:36:32 -0500 | [diff] [blame] | 428 | .acpi_match_table = ACPI_PTR(ehci_acpi_match), |
Hauke Mehrtens | 7a7a4a59 | 2012-03-13 01:04:48 +0100 | [diff] [blame] | 429 | } |
| 430 | }; |
Alan Stern | 99f9193 | 2012-11-01 11:13:08 -0400 | [diff] [blame] | 431 | |
| 432 | static int __init ehci_platform_init(void) |
| 433 | { |
| 434 | if (usb_disabled()) |
| 435 | return -ENODEV; |
| 436 | |
| 437 | pr_info("%s: " DRIVER_DESC "\n", hcd_name); |
| 438 | |
| 439 | ehci_init_driver(&ehci_platform_hc_driver, &platform_overrides); |
| 440 | return platform_driver_register(&ehci_platform_driver); |
| 441 | } |
| 442 | module_init(ehci_platform_init); |
| 443 | |
| 444 | static void __exit ehci_platform_cleanup(void) |
| 445 | { |
| 446 | platform_driver_unregister(&ehci_platform_driver); |
| 447 | } |
| 448 | module_exit(ehci_platform_cleanup); |
| 449 | |
| 450 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 451 | MODULE_AUTHOR("Hauke Mehrtens"); |
| 452 | MODULE_AUTHOR("Alan Stern"); |
| 453 | MODULE_LICENSE("GPL"); |