Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1 | /* ehci-msm2.c - HSUSB Host Controller Driver Implementation |
| 2 | * |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 3 | * Copyright (c) 2008-2013, The Linux Foundation. All rights reserved. |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 4 | * |
| 5 | * Partly derived from ehci-fsl.c and ehci-hcd.c |
| 6 | * Copyright (c) 2000-2004 by David Brownell |
| 7 | * Copyright (c) 2005 MontaVista Software |
| 8 | * |
| 9 | * All source code in this file is licensed under the following license except |
| 10 | * where indicated. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License version 2 as published |
| 14 | * by the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 19 | * |
| 20 | * See the GNU General Public License for more details. |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, you can find it at http://www.fsf.org |
| 23 | */ |
| 24 | |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/clk.h> |
| 27 | #include <linux/err.h> |
| 28 | #include <linux/wakelock.h> |
| 29 | #include <linux/pm_runtime.h> |
| 30 | #include <linux/regulator/consumer.h> |
| 31 | |
| 32 | #include <linux/usb/ulpi.h> |
| 33 | #include <linux/usb/msm_hsusb_hw.h> |
| 34 | #include <linux/usb/msm_hsusb.h> |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 35 | #include <linux/of.h> |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 36 | #include <mach/clk.h> |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 37 | #include <mach/msm_xo.h> |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 38 | #include <mach/msm_iomap.h> |
| 39 | |
| 40 | #define MSM_USB_BASE (hcd->regs) |
| 41 | |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 42 | #define PDEV_NAME_LEN 20 |
| 43 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 44 | struct msm_hcd { |
| 45 | struct ehci_hcd ehci; |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 46 | spinlock_t wakeup_lock; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 47 | struct device *dev; |
Vijayavardhan Vennapusa | 16fcaf9 | 2013-03-04 10:24:21 +0530 | [diff] [blame] | 48 | struct clk *xo_clk; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 49 | struct clk *iface_clk; |
| 50 | struct clk *core_clk; |
| 51 | struct clk *alt_core_clk; |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 52 | struct clk *phy_sleep_clk; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 53 | struct regulator *hsusb_vddcx; |
| 54 | struct regulator *hsusb_3p3; |
| 55 | struct regulator *hsusb_1p8; |
| 56 | struct regulator *vbus; |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 57 | struct msm_xo_voter *xo_handle; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 58 | bool async_int; |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 59 | bool vbus_on; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 60 | atomic_t in_lpm; |
Vijayavardhan Vennapusa | 4fa1369 | 2012-08-02 14:35:03 +0530 | [diff] [blame] | 61 | int pmic_gpio_dp_irq; |
| 62 | bool pmic_gpio_dp_irq_enabled; |
| 63 | uint32_t pmic_gpio_int_cnt; |
| 64 | atomic_t pm_usage_cnt; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 65 | struct wake_lock wlock; |
Chiranjeevi Velempati | ce16958 | 2012-08-25 14:15:41 +0530 | [diff] [blame] | 66 | struct work_struct phy_susp_fail_work; |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 67 | int async_irq; |
| 68 | bool async_irq_enabled; |
| 69 | uint32_t async_int_cnt; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | static inline struct msm_hcd *hcd_to_mhcd(struct usb_hcd *hcd) |
| 73 | { |
| 74 | return (struct msm_hcd *) (hcd->hcd_priv); |
| 75 | } |
| 76 | |
| 77 | static inline struct usb_hcd *mhcd_to_hcd(struct msm_hcd *mhcd) |
| 78 | { |
| 79 | return container_of((void *) mhcd, struct usb_hcd, hcd_priv); |
| 80 | } |
| 81 | |
| 82 | #define HSUSB_PHY_3P3_VOL_MIN 3050000 /* uV */ |
| 83 | #define HSUSB_PHY_3P3_VOL_MAX 3300000 /* uV */ |
| 84 | #define HSUSB_PHY_3P3_HPM_LOAD 50000 /* uA */ |
| 85 | |
| 86 | #define HSUSB_PHY_1P8_VOL_MIN 1800000 /* uV */ |
| 87 | #define HSUSB_PHY_1P8_VOL_MAX 1800000 /* uV */ |
| 88 | #define HSUSB_PHY_1P8_HPM_LOAD 50000 /* uA */ |
| 89 | |
| 90 | #define HSUSB_PHY_VDD_DIG_VOL_MIN 1045000 /* uV */ |
| 91 | #define HSUSB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
| 92 | #define HSUSB_PHY_VDD_DIG_LOAD 49360 /* uA */ |
| 93 | |
| 94 | static int msm_ehci_init_vddcx(struct msm_hcd *mhcd, int init) |
| 95 | { |
| 96 | int ret = 0; |
| 97 | |
| 98 | if (!init) |
| 99 | goto disable_reg; |
| 100 | |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame] | 101 | mhcd->hsusb_vddcx = devm_regulator_get(mhcd->dev, "HSUSB_VDDCX"); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 102 | if (IS_ERR(mhcd->hsusb_vddcx)) { |
| 103 | dev_err(mhcd->dev, "unable to get ehci vddcx\n"); |
| 104 | return PTR_ERR(mhcd->hsusb_vddcx); |
| 105 | } |
| 106 | |
| 107 | ret = regulator_set_voltage(mhcd->hsusb_vddcx, |
| 108 | HSUSB_PHY_VDD_DIG_VOL_MIN, |
| 109 | HSUSB_PHY_VDD_DIG_VOL_MAX); |
| 110 | if (ret) { |
| 111 | dev_err(mhcd->dev, "unable to set the voltage" |
| 112 | "for ehci vddcx\n"); |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame] | 113 | return ret; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | ret = regulator_set_optimum_mode(mhcd->hsusb_vddcx, |
| 117 | HSUSB_PHY_VDD_DIG_LOAD); |
| 118 | if (ret < 0) { |
| 119 | dev_err(mhcd->dev, "%s: Unable to set optimum mode of the" |
| 120 | " regulator: VDDCX\n", __func__); |
| 121 | goto reg_optimum_mode_err; |
| 122 | } |
| 123 | |
| 124 | ret = regulator_enable(mhcd->hsusb_vddcx); |
| 125 | if (ret) { |
| 126 | dev_err(mhcd->dev, "unable to enable ehci vddcx\n"); |
| 127 | goto reg_enable_err; |
| 128 | } |
| 129 | |
| 130 | return 0; |
| 131 | |
| 132 | disable_reg: |
| 133 | regulator_disable(mhcd->hsusb_vddcx); |
| 134 | reg_enable_err: |
| 135 | regulator_set_optimum_mode(mhcd->hsusb_vddcx, 0); |
| 136 | reg_optimum_mode_err: |
| 137 | regulator_set_voltage(mhcd->hsusb_vddcx, 0, |
| 138 | HSUSB_PHY_VDD_DIG_VOL_MIN); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 139 | return ret; |
| 140 | |
| 141 | } |
| 142 | |
| 143 | static int msm_ehci_ldo_init(struct msm_hcd *mhcd, int init) |
| 144 | { |
| 145 | int rc = 0; |
| 146 | |
| 147 | if (!init) |
| 148 | goto put_1p8; |
| 149 | |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame] | 150 | mhcd->hsusb_3p3 = devm_regulator_get(mhcd->dev, "HSUSB_3p3"); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 151 | if (IS_ERR(mhcd->hsusb_3p3)) { |
| 152 | dev_err(mhcd->dev, "unable to get hsusb 3p3\n"); |
| 153 | return PTR_ERR(mhcd->hsusb_3p3); |
| 154 | } |
| 155 | |
| 156 | rc = regulator_set_voltage(mhcd->hsusb_3p3, |
| 157 | HSUSB_PHY_3P3_VOL_MIN, HSUSB_PHY_3P3_VOL_MAX); |
| 158 | if (rc) { |
| 159 | dev_err(mhcd->dev, "unable to set voltage level for" |
| 160 | "hsusb 3p3\n"); |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame] | 161 | return rc; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 162 | } |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame] | 163 | mhcd->hsusb_1p8 = devm_regulator_get(mhcd->dev, "HSUSB_1p8"); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 164 | if (IS_ERR(mhcd->hsusb_1p8)) { |
| 165 | dev_err(mhcd->dev, "unable to get hsusb 1p8\n"); |
| 166 | rc = PTR_ERR(mhcd->hsusb_1p8); |
| 167 | goto put_3p3_lpm; |
| 168 | } |
| 169 | rc = regulator_set_voltage(mhcd->hsusb_1p8, |
| 170 | HSUSB_PHY_1P8_VOL_MIN, HSUSB_PHY_1P8_VOL_MAX); |
| 171 | if (rc) { |
| 172 | dev_err(mhcd->dev, "unable to set voltage level for" |
| 173 | "hsusb 1p8\n"); |
| 174 | goto put_1p8; |
| 175 | } |
| 176 | |
| 177 | return 0; |
| 178 | |
| 179 | put_1p8: |
| 180 | regulator_set_voltage(mhcd->hsusb_1p8, 0, HSUSB_PHY_1P8_VOL_MAX); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 181 | put_3p3_lpm: |
| 182 | regulator_set_voltage(mhcd->hsusb_3p3, 0, HSUSB_PHY_3P3_VOL_MAX); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 183 | |
| 184 | return rc; |
| 185 | } |
| 186 | |
| 187 | #ifdef CONFIG_PM_SLEEP |
Hemant Kumar | 441356be | 2012-02-13 16:12:49 -0800 | [diff] [blame] | 188 | #define HSUSB_PHY_SUSP_DIG_VOL_P50 500000 |
| 189 | #define HSUSB_PHY_SUSP_DIG_VOL_P75 750000 |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 190 | static int msm_ehci_config_vddcx(struct msm_hcd *mhcd, int high) |
| 191 | { |
Hemant Kumar | 441356be | 2012-02-13 16:12:49 -0800 | [diff] [blame] | 192 | struct msm_usb_host_platform_data *pdata; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 193 | int max_vol = HSUSB_PHY_VDD_DIG_VOL_MAX; |
| 194 | int min_vol; |
| 195 | int ret; |
| 196 | |
Hemant Kumar | 441356be | 2012-02-13 16:12:49 -0800 | [diff] [blame] | 197 | pdata = mhcd->dev->platform_data; |
| 198 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 199 | if (high) |
| 200 | min_vol = HSUSB_PHY_VDD_DIG_VOL_MIN; |
Hemant Kumar | 441356be | 2012-02-13 16:12:49 -0800 | [diff] [blame] | 201 | else if (pdata && pdata->dock_connect_irq && |
| 202 | !irq_read_line(pdata->dock_connect_irq)) |
| 203 | min_vol = HSUSB_PHY_SUSP_DIG_VOL_P75; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 204 | else |
Hemant Kumar | 441356be | 2012-02-13 16:12:49 -0800 | [diff] [blame] | 205 | min_vol = HSUSB_PHY_SUSP_DIG_VOL_P50; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 206 | |
| 207 | ret = regulator_set_voltage(mhcd->hsusb_vddcx, min_vol, max_vol); |
| 208 | if (ret) { |
| 209 | dev_err(mhcd->dev, "%s: unable to set the voltage of regulator" |
| 210 | " HSUSB_VDDCX\n", __func__); |
| 211 | return ret; |
| 212 | } |
| 213 | |
| 214 | dev_dbg(mhcd->dev, "%s: min_vol:%d max_vol:%d\n", __func__, min_vol, |
| 215 | max_vol); |
| 216 | |
| 217 | return ret; |
| 218 | } |
| 219 | #else |
| 220 | static int msm_ehci_config_vddcx(struct msm_hcd *mhcd, int high) |
| 221 | { |
| 222 | return 0; |
| 223 | } |
| 224 | #endif |
| 225 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 226 | static void msm_ehci_vbus_power(struct msm_hcd *mhcd, bool on) |
| 227 | { |
| 228 | int ret; |
| 229 | |
| 230 | if (!mhcd->vbus) { |
| 231 | pr_err("vbus is NULL."); |
| 232 | return; |
| 233 | } |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 234 | |
| 235 | if (mhcd->vbus_on == on) |
| 236 | return; |
| 237 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 238 | if (on) { |
| 239 | ret = regulator_enable(mhcd->vbus); |
| 240 | if (ret) { |
| 241 | pr_err("unable to enable vbus\n"); |
| 242 | return; |
| 243 | } |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 244 | mhcd->vbus_on = true; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 245 | } else { |
| 246 | ret = regulator_disable(mhcd->vbus); |
| 247 | if (ret) { |
| 248 | pr_err("unable to disable vbus\n"); |
| 249 | return; |
| 250 | } |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 251 | mhcd->vbus_on = false; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 255 | static irqreturn_t msm_ehci_dock_connect_irq(int irq, void *data) |
| 256 | { |
| 257 | const struct msm_usb_host_platform_data *pdata; |
| 258 | struct msm_hcd *mhcd = data; |
| 259 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 260 | |
| 261 | pdata = mhcd->dev->platform_data; |
| 262 | |
| 263 | if (atomic_read(&mhcd->in_lpm)) |
| 264 | usb_hcd_resume_root_hub(hcd); |
| 265 | |
| 266 | if (irq_read_line(pdata->dock_connect_irq)) { |
| 267 | dev_dbg(mhcd->dev, "%s:Dock removed disable vbus\n", __func__); |
| 268 | msm_ehci_vbus_power(mhcd, 0); |
| 269 | } else { |
| 270 | dev_dbg(mhcd->dev, "%s:Dock connected enable vbus\n", __func__); |
| 271 | msm_ehci_vbus_power(mhcd, 1); |
| 272 | } |
| 273 | |
| 274 | return IRQ_HANDLED; |
| 275 | } |
| 276 | |
| 277 | static int msm_ehci_init_vbus(struct msm_hcd *mhcd, int init) |
| 278 | { |
| 279 | int rc = 0; |
| 280 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 281 | const struct msm_usb_host_platform_data *pdata; |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 282 | int ret = 0; |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 283 | |
| 284 | pdata = mhcd->dev->platform_data; |
| 285 | |
| 286 | if (!init) { |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 287 | if (pdata && pdata->dock_connect_irq) |
| 288 | free_irq(pdata->dock_connect_irq, mhcd); |
| 289 | return rc; |
| 290 | } |
| 291 | |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame] | 292 | mhcd->vbus = devm_regulator_get(mhcd->dev, "vbus"); |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 293 | ret = PTR_ERR(mhcd->vbus); |
| 294 | if (ret == -EPROBE_DEFER) { |
| 295 | pr_debug("failed to get vbus handle, defer probe\n"); |
| 296 | return ret; |
| 297 | } else if (IS_ERR(mhcd->vbus)) { |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 298 | pr_err("Unable to get vbus\n"); |
| 299 | return -ENODEV; |
| 300 | } |
| 301 | |
| 302 | if (pdata) { |
| 303 | hcd->power_budget = pdata->power_budget; |
| 304 | |
| 305 | if (pdata->dock_connect_irq) { |
| 306 | rc = request_threaded_irq(pdata->dock_connect_irq, NULL, |
| 307 | msm_ehci_dock_connect_irq, |
| 308 | IRQF_TRIGGER_FALLING | |
| 309 | IRQF_TRIGGER_RISING | |
| 310 | IRQF_ONESHOT, "msm_ehci_host", mhcd); |
| 311 | if (!rc) |
| 312 | enable_irq_wake(pdata->dock_connect_irq); |
| 313 | } |
| 314 | } |
| 315 | return rc; |
| 316 | } |
| 317 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 318 | static int msm_ehci_ldo_enable(struct msm_hcd *mhcd, int on) |
| 319 | { |
| 320 | int ret = 0; |
| 321 | |
| 322 | if (IS_ERR(mhcd->hsusb_1p8)) { |
| 323 | dev_err(mhcd->dev, "%s: HSUSB_1p8 is not initialized\n", |
| 324 | __func__); |
| 325 | return -ENODEV; |
| 326 | } |
| 327 | |
| 328 | if (IS_ERR(mhcd->hsusb_3p3)) { |
| 329 | dev_err(mhcd->dev, "%s: HSUSB_3p3 is not initialized\n", |
| 330 | __func__); |
| 331 | return -ENODEV; |
| 332 | } |
| 333 | |
| 334 | if (on) { |
| 335 | ret = regulator_set_optimum_mode(mhcd->hsusb_1p8, |
| 336 | HSUSB_PHY_1P8_HPM_LOAD); |
| 337 | if (ret < 0) { |
| 338 | dev_err(mhcd->dev, "%s: Unable to set HPM of the" |
| 339 | " regulator: HSUSB_1p8\n", __func__); |
| 340 | return ret; |
| 341 | } |
| 342 | |
| 343 | ret = regulator_enable(mhcd->hsusb_1p8); |
| 344 | if (ret) { |
| 345 | dev_err(mhcd->dev, "%s: unable to enable the hsusb" |
| 346 | " 1p8\n", __func__); |
| 347 | regulator_set_optimum_mode(mhcd->hsusb_1p8, 0); |
| 348 | return ret; |
| 349 | } |
| 350 | |
| 351 | ret = regulator_set_optimum_mode(mhcd->hsusb_3p3, |
| 352 | HSUSB_PHY_3P3_HPM_LOAD); |
| 353 | if (ret < 0) { |
| 354 | dev_err(mhcd->dev, "%s: Unable to set HPM of the " |
| 355 | "regulator: HSUSB_3p3\n", __func__); |
| 356 | regulator_set_optimum_mode(mhcd->hsusb_1p8, 0); |
| 357 | regulator_disable(mhcd->hsusb_1p8); |
| 358 | return ret; |
| 359 | } |
| 360 | |
| 361 | ret = regulator_enable(mhcd->hsusb_3p3); |
| 362 | if (ret) { |
| 363 | dev_err(mhcd->dev, "%s: unable to enable the " |
| 364 | "hsusb 3p3\n", __func__); |
| 365 | regulator_set_optimum_mode(mhcd->hsusb_3p3, 0); |
| 366 | regulator_set_optimum_mode(mhcd->hsusb_1p8, 0); |
| 367 | regulator_disable(mhcd->hsusb_1p8); |
| 368 | return ret; |
| 369 | } |
| 370 | |
| 371 | } else { |
| 372 | ret = regulator_disable(mhcd->hsusb_1p8); |
| 373 | if (ret) { |
| 374 | dev_err(mhcd->dev, "%s: unable to disable the " |
| 375 | "hsusb 1p8\n", __func__); |
| 376 | return ret; |
| 377 | } |
| 378 | |
| 379 | ret = regulator_set_optimum_mode(mhcd->hsusb_1p8, 0); |
| 380 | if (ret < 0) |
| 381 | dev_err(mhcd->dev, "%s: Unable to set LPM of the " |
| 382 | "regulator: HSUSB_1p8\n", __func__); |
| 383 | |
| 384 | ret = regulator_disable(mhcd->hsusb_3p3); |
| 385 | if (ret) { |
| 386 | dev_err(mhcd->dev, "%s: unable to disable the " |
| 387 | "hsusb 3p3\n", __func__); |
| 388 | return ret; |
| 389 | } |
| 390 | ret = regulator_set_optimum_mode(mhcd->hsusb_3p3, 0); |
| 391 | if (ret < 0) |
| 392 | dev_err(mhcd->dev, "%s: Unable to set LPM of the " |
| 393 | "regulator: HSUSB_3p3\n", __func__); |
| 394 | } |
| 395 | |
| 396 | dev_dbg(mhcd->dev, "reg (%s)\n", on ? "HPM" : "LPM"); |
| 397 | |
| 398 | return ret < 0 ? ret : 0; |
| 399 | } |
| 400 | |
| 401 | |
| 402 | #define ULPI_IO_TIMEOUT_USECS (10 * 1000) |
| 403 | static int msm_ulpi_read(struct msm_hcd *mhcd, u32 reg) |
| 404 | { |
| 405 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 406 | unsigned long timeout; |
| 407 | |
| 408 | /* initiate read operation */ |
| 409 | writel_relaxed(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg), |
| 410 | USB_ULPI_VIEWPORT); |
| 411 | |
| 412 | /* wait for completion */ |
| 413 | timeout = jiffies + usecs_to_jiffies(ULPI_IO_TIMEOUT_USECS); |
| 414 | while (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN) { |
| 415 | if (time_after(jiffies, timeout)) { |
| 416 | dev_err(mhcd->dev, "msm_ulpi_read: timeout %08x\n", |
| 417 | readl_relaxed(USB_ULPI_VIEWPORT)); |
| 418 | return -ETIMEDOUT; |
| 419 | } |
| 420 | udelay(1); |
| 421 | } |
| 422 | |
| 423 | return ULPI_DATA_READ(readl_relaxed(USB_ULPI_VIEWPORT)); |
| 424 | } |
| 425 | |
| 426 | |
| 427 | static int msm_ulpi_write(struct msm_hcd *mhcd, u32 val, u32 reg) |
| 428 | { |
| 429 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 430 | unsigned long timeout; |
| 431 | |
| 432 | /* initiate write operation */ |
| 433 | writel_relaxed(ULPI_RUN | ULPI_WRITE | |
| 434 | ULPI_ADDR(reg) | ULPI_DATA(val), |
| 435 | USB_ULPI_VIEWPORT); |
| 436 | |
| 437 | /* wait for completion */ |
| 438 | timeout = jiffies + usecs_to_jiffies(ULPI_IO_TIMEOUT_USECS); |
| 439 | while (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN) { |
| 440 | if (time_after(jiffies, timeout)) { |
| 441 | dev_err(mhcd->dev, "msm_ulpi_write: timeout\n"); |
| 442 | return -ETIMEDOUT; |
| 443 | } |
| 444 | udelay(1); |
| 445 | } |
| 446 | |
| 447 | return 0; |
| 448 | } |
| 449 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 450 | /** |
| 451 | * Do hard reset to USB hardware block using one of reset methodology based |
| 452 | * on availablity of alt_core_clk. There are two kinds of hardware resets. |
| 453 | * 1. Conventional synchronous reset where clocks to blocks to be ON while |
| 454 | * issuing the reset. 2. Asynchronous reset which requires clocks to be OFF. |
| 455 | */ |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 456 | static int msm_ehci_link_clk_reset(struct msm_hcd *mhcd, bool assert) |
| 457 | { |
| 458 | int ret; |
| 459 | |
| 460 | if (assert) { |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 461 | if (!IS_ERR(mhcd->alt_core_clk)) { |
| 462 | ret = clk_reset(mhcd->alt_core_clk, CLK_RESET_ASSERT); |
| 463 | } else { |
| 464 | /* Using asynchronous block reset to the hardware */ |
| 465 | clk_disable(mhcd->iface_clk); |
| 466 | clk_disable(mhcd->core_clk); |
| 467 | ret = clk_reset(mhcd->core_clk, CLK_RESET_ASSERT); |
| 468 | } |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 469 | if (ret) |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 470 | dev_err(mhcd->dev, "usb clk assert failed\n"); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 471 | } else { |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 472 | if (!IS_ERR(mhcd->alt_core_clk)) { |
| 473 | ret = clk_reset(mhcd->alt_core_clk, CLK_RESET_DEASSERT); |
| 474 | } else { |
| 475 | ret = clk_reset(mhcd->core_clk, CLK_RESET_DEASSERT); |
| 476 | ndelay(200); |
| 477 | clk_enable(mhcd->core_clk); |
| 478 | clk_enable(mhcd->iface_clk); |
| 479 | } |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 480 | if (ret) |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 481 | dev_err(mhcd->dev, "usb clk deassert failed\n"); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | return ret; |
| 485 | } |
| 486 | |
| 487 | static int msm_ehci_phy_reset(struct msm_hcd *mhcd) |
| 488 | { |
| 489 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 490 | struct msm_usb_host_platform_data *pdata; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 491 | u32 val; |
| 492 | int ret; |
| 493 | int retries; |
| 494 | |
| 495 | ret = msm_ehci_link_clk_reset(mhcd, 1); |
| 496 | if (ret) |
| 497 | return ret; |
| 498 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 499 | usleep_range(10, 12); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 500 | |
| 501 | ret = msm_ehci_link_clk_reset(mhcd, 0); |
| 502 | if (ret) |
| 503 | return ret; |
| 504 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 505 | pdata = mhcd->dev->platform_data; |
| 506 | if (pdata && pdata->use_sec_phy) |
| 507 | /* select secondary phy if offset is set for USB operation */ |
| 508 | writel_relaxed(readl_relaxed(USB_PHY_CTRL2) | (1<<16), |
| 509 | USB_PHY_CTRL2); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 510 | val = readl_relaxed(USB_PORTSC) & ~PORTSC_PTS_MASK; |
| 511 | writel_relaxed(val | PORTSC_PTS_ULPI, USB_PORTSC); |
| 512 | |
| 513 | for (retries = 3; retries > 0; retries--) { |
| 514 | ret = msm_ulpi_write(mhcd, ULPI_FUNC_CTRL_SUSPENDM, |
| 515 | ULPI_CLR(ULPI_FUNC_CTRL)); |
| 516 | if (!ret) |
| 517 | break; |
| 518 | } |
| 519 | if (!retries) |
| 520 | return -ETIMEDOUT; |
| 521 | |
| 522 | /* Wakeup the PHY with a reg-access for calibration */ |
| 523 | for (retries = 3; retries > 0; retries--) { |
| 524 | ret = msm_ulpi_read(mhcd, ULPI_DEBUG); |
| 525 | if (ret != -ETIMEDOUT) |
| 526 | break; |
| 527 | } |
| 528 | if (!retries) |
| 529 | return -ETIMEDOUT; |
| 530 | |
| 531 | dev_info(mhcd->dev, "phy_reset: success\n"); |
| 532 | |
| 533 | return 0; |
| 534 | } |
| 535 | |
| 536 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) |
| 537 | static int msm_hsusb_reset(struct msm_hcd *mhcd) |
| 538 | { |
| 539 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 540 | struct msm_usb_host_platform_data *pdata; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 541 | unsigned long timeout; |
| 542 | int ret; |
| 543 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 544 | if (!IS_ERR(mhcd->alt_core_clk)) |
| 545 | clk_prepare_enable(mhcd->alt_core_clk); |
| 546 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 547 | ret = msm_ehci_phy_reset(mhcd); |
| 548 | if (ret) { |
| 549 | dev_err(mhcd->dev, "phy_reset failed\n"); |
| 550 | return ret; |
| 551 | } |
| 552 | |
| 553 | writel_relaxed(USBCMD_RESET, USB_USBCMD); |
| 554 | |
| 555 | timeout = jiffies + usecs_to_jiffies(LINK_RESET_TIMEOUT_USEC); |
| 556 | while (readl_relaxed(USB_USBCMD) & USBCMD_RESET) { |
| 557 | if (time_after(jiffies, timeout)) |
| 558 | return -ETIMEDOUT; |
| 559 | udelay(1); |
| 560 | } |
| 561 | |
| 562 | /* select ULPI phy */ |
| 563 | writel_relaxed(0x80000000, USB_PORTSC); |
| 564 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 565 | pdata = mhcd->dev->platform_data; |
| 566 | if (pdata && pdata->use_sec_phy) |
| 567 | writel_relaxed(readl_relaxed(USB_PHY_CTRL2) | (1<<16), |
| 568 | USB_PHY_CTRL2); |
| 569 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 570 | msleep(100); |
| 571 | |
| 572 | writel_relaxed(0x0, USB_AHBBURST); |
Vijayavardhan Vennapusa | 5f32d7a | 2012-03-14 16:30:26 +0530 | [diff] [blame] | 573 | writel_relaxed(0x08, USB_AHBMODE); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 574 | |
| 575 | /* Ensure that RESET operation is completed before turning off clock */ |
| 576 | mb(); |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 577 | |
| 578 | if (!IS_ERR(mhcd->alt_core_clk)) |
| 579 | clk_disable_unprepare(mhcd->alt_core_clk); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 580 | |
| 581 | /*rising edge interrupts with Dp rise and fall enabled*/ |
| 582 | msm_ulpi_write(mhcd, ULPI_INT_DP, ULPI_USB_INT_EN_RISE); |
| 583 | msm_ulpi_write(mhcd, ULPI_INT_DP, ULPI_USB_INT_EN_FALL); |
| 584 | |
| 585 | /*Clear the PHY interrupts by reading the PHY interrupt latch register*/ |
| 586 | msm_ulpi_read(mhcd, ULPI_USB_INT_LATCH); |
| 587 | |
| 588 | return 0; |
| 589 | } |
| 590 | |
Chiranjeevi Velempati | ce16958 | 2012-08-25 14:15:41 +0530 | [diff] [blame] | 591 | static void msm_ehci_phy_susp_fail_work(struct work_struct *w) |
| 592 | { |
| 593 | struct msm_hcd *mhcd = container_of(w, struct msm_hcd, |
| 594 | phy_susp_fail_work); |
| 595 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 596 | |
| 597 | msm_ehci_vbus_power(mhcd, 0); |
| 598 | usb_remove_hcd(hcd); |
| 599 | msm_hsusb_reset(mhcd); |
| 600 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
| 601 | msm_ehci_vbus_power(mhcd, 1); |
| 602 | } |
| 603 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 604 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) |
| 605 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) |
| 606 | |
| 607 | #ifdef CONFIG_PM_SLEEP |
| 608 | static int msm_ehci_suspend(struct msm_hcd *mhcd) |
| 609 | { |
| 610 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 611 | unsigned long timeout; |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 612 | int ret; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 613 | u32 portsc; |
| 614 | |
| 615 | if (atomic_read(&mhcd->in_lpm)) { |
| 616 | dev_dbg(mhcd->dev, "%s called in lpm\n", __func__); |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | disable_irq(hcd->irq); |
| 621 | |
| 622 | /* Set the PHCD bit, only if it is not set by the controller. |
| 623 | * PHY may take some time or even fail to enter into low power |
| 624 | * mode (LPM). Hence poll for 500 msec and reset the PHY and link |
| 625 | * in failure case. |
| 626 | */ |
| 627 | portsc = readl_relaxed(USB_PORTSC); |
| 628 | if (!(portsc & PORTSC_PHCD)) { |
| 629 | writel_relaxed(portsc | PORTSC_PHCD, |
| 630 | USB_PORTSC); |
| 631 | |
| 632 | timeout = jiffies + usecs_to_jiffies(PHY_SUSPEND_TIMEOUT_USEC); |
| 633 | while (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD)) { |
| 634 | if (time_after(jiffies, timeout)) { |
| 635 | dev_err(mhcd->dev, "Unable to suspend PHY\n"); |
Chiranjeevi Velempati | ce16958 | 2012-08-25 14:15:41 +0530 | [diff] [blame] | 636 | schedule_work(&mhcd->phy_susp_fail_work); |
| 637 | return -ETIMEDOUT; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 638 | } |
| 639 | udelay(1); |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | /* |
| 644 | * PHY has capability to generate interrupt asynchronously in low |
| 645 | * power mode (LPM). This interrupt is level triggered. So USB IRQ |
| 646 | * line must be disabled till async interrupt enable bit is cleared |
| 647 | * in USBCMD register. Assert STP (ULPI interface STOP signal) to |
| 648 | * block data communication from PHY. |
| 649 | */ |
| 650 | writel_relaxed(readl_relaxed(USB_USBCMD) | ASYNC_INTR_CTRL | |
| 651 | ULPI_STP_CTRL, USB_USBCMD); |
| 652 | |
| 653 | /* |
| 654 | * Ensure that hardware is put in low power mode before |
| 655 | * clocks are turned OFF and VDD is allowed to minimize. |
| 656 | */ |
| 657 | mb(); |
| 658 | |
| 659 | clk_disable_unprepare(mhcd->iface_clk); |
| 660 | clk_disable_unprepare(mhcd->core_clk); |
| 661 | |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 662 | /* usb phy does not require TCXO clock, hence vote for TCXO disable */ |
Vijayavardhan Vennapusa | 16fcaf9 | 2013-03-04 10:24:21 +0530 | [diff] [blame] | 663 | if (!IS_ERR(mhcd->xo_clk)) { |
| 664 | clk_disable_unprepare(mhcd->xo_clk); |
| 665 | } else { |
| 666 | ret = msm_xo_mode_vote(mhcd->xo_handle, MSM_XO_MODE_OFF); |
| 667 | if (ret) |
| 668 | dev_err(mhcd->dev, "%s failed to devote for TCXO %d\n", |
| 669 | __func__, ret); |
| 670 | } |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 671 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 672 | msm_ehci_config_vddcx(mhcd, 0); |
| 673 | |
| 674 | atomic_set(&mhcd->in_lpm, 1); |
| 675 | enable_irq(hcd->irq); |
Vijayavardhan Vennapusa | 4fa1369 | 2012-08-02 14:35:03 +0530 | [diff] [blame] | 676 | if (mhcd->pmic_gpio_dp_irq) { |
| 677 | mhcd->pmic_gpio_dp_irq_enabled = 1; |
| 678 | enable_irq_wake(mhcd->pmic_gpio_dp_irq); |
| 679 | enable_irq(mhcd->pmic_gpio_dp_irq); |
| 680 | } |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 681 | if (mhcd->async_irq) { |
| 682 | mhcd->async_irq_enabled = 1; |
| 683 | enable_irq_wake(mhcd->async_irq); |
| 684 | enable_irq(mhcd->async_irq); |
| 685 | } |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 686 | wake_unlock(&mhcd->wlock); |
| 687 | |
| 688 | dev_info(mhcd->dev, "EHCI USB in low power mode\n"); |
| 689 | |
| 690 | return 0; |
| 691 | } |
| 692 | |
| 693 | static int msm_ehci_resume(struct msm_hcd *mhcd) |
| 694 | { |
| 695 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 696 | unsigned long timeout; |
| 697 | unsigned temp; |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 698 | int ret; |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 699 | unsigned long flags; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 700 | |
| 701 | if (!atomic_read(&mhcd->in_lpm)) { |
| 702 | dev_dbg(mhcd->dev, "%s called in !in_lpm\n", __func__); |
| 703 | return 0; |
| 704 | } |
| 705 | |
Vijayavardhan Vennapusa | 4fa1369 | 2012-08-02 14:35:03 +0530 | [diff] [blame] | 706 | if (mhcd->pmic_gpio_dp_irq_enabled) { |
| 707 | disable_irq_wake(mhcd->pmic_gpio_dp_irq); |
| 708 | disable_irq_nosync(mhcd->pmic_gpio_dp_irq); |
| 709 | mhcd->pmic_gpio_dp_irq_enabled = 0; |
| 710 | } |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 711 | spin_lock_irqsave(&mhcd->wakeup_lock, flags); |
| 712 | if (mhcd->async_irq_enabled) { |
| 713 | disable_irq_wake(mhcd->async_irq); |
| 714 | disable_irq_nosync(mhcd->async_irq); |
| 715 | mhcd->async_irq_enabled = 0; |
| 716 | } |
| 717 | spin_unlock_irqrestore(&mhcd->wakeup_lock, flags); |
| 718 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 719 | wake_lock(&mhcd->wlock); |
| 720 | |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 721 | /* Vote for TCXO when waking up the phy */ |
Vijayavardhan Vennapusa | 16fcaf9 | 2013-03-04 10:24:21 +0530 | [diff] [blame] | 722 | if (!IS_ERR(mhcd->xo_clk)) { |
| 723 | clk_prepare_enable(mhcd->xo_clk); |
| 724 | } else { |
| 725 | ret = msm_xo_mode_vote(mhcd->xo_handle, MSM_XO_MODE_ON); |
| 726 | if (ret) |
| 727 | dev_err(mhcd->dev, "%s failed to vote for TCXO D0 %d\n", |
| 728 | __func__, ret); |
| 729 | } |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 730 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 731 | clk_prepare_enable(mhcd->core_clk); |
| 732 | clk_prepare_enable(mhcd->iface_clk); |
| 733 | |
| 734 | msm_ehci_config_vddcx(mhcd, 1); |
| 735 | |
| 736 | temp = readl_relaxed(USB_USBCMD); |
| 737 | temp &= ~ASYNC_INTR_CTRL; |
| 738 | temp &= ~ULPI_STP_CTRL; |
| 739 | writel_relaxed(temp, USB_USBCMD); |
| 740 | |
| 741 | if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD)) |
| 742 | goto skip_phy_resume; |
| 743 | |
| 744 | temp = readl_relaxed(USB_PORTSC) & ~PORTSC_PHCD; |
| 745 | writel_relaxed(temp, USB_PORTSC); |
| 746 | |
| 747 | timeout = jiffies + usecs_to_jiffies(PHY_RESUME_TIMEOUT_USEC); |
| 748 | while ((readl_relaxed(USB_PORTSC) & PORTSC_PHCD) || |
| 749 | !(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_SYNC_STATE)) { |
| 750 | if (time_after(jiffies, timeout)) { |
| 751 | /*This is a fatal error. Reset the link and PHY*/ |
| 752 | dev_err(mhcd->dev, "Unable to resume USB. Resetting the h/w\n"); |
| 753 | msm_hsusb_reset(mhcd); |
| 754 | break; |
| 755 | } |
| 756 | udelay(1); |
| 757 | } |
| 758 | |
| 759 | skip_phy_resume: |
| 760 | |
Chiranjeevi Velempati | 35d46ab | 2012-07-18 20:36:53 +0530 | [diff] [blame] | 761 | usb_hcd_resume_root_hub(hcd); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 762 | atomic_set(&mhcd->in_lpm, 0); |
| 763 | |
| 764 | if (mhcd->async_int) { |
| 765 | mhcd->async_int = false; |
| 766 | pm_runtime_put_noidle(mhcd->dev); |
| 767 | enable_irq(hcd->irq); |
| 768 | } |
| 769 | |
Vijayavardhan Vennapusa | 4fa1369 | 2012-08-02 14:35:03 +0530 | [diff] [blame] | 770 | if (atomic_read(&mhcd->pm_usage_cnt)) { |
| 771 | atomic_set(&mhcd->pm_usage_cnt, 0); |
| 772 | pm_runtime_put_noidle(mhcd->dev); |
| 773 | } |
| 774 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 775 | dev_info(mhcd->dev, "EHCI USB exited from low power mode\n"); |
| 776 | |
| 777 | return 0; |
| 778 | } |
| 779 | #endif |
| 780 | |
| 781 | static irqreturn_t msm_ehci_irq(struct usb_hcd *hcd) |
| 782 | { |
| 783 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 784 | |
| 785 | if (atomic_read(&mhcd->in_lpm)) { |
| 786 | disable_irq_nosync(hcd->irq); |
| 787 | mhcd->async_int = true; |
| 788 | pm_runtime_get(mhcd->dev); |
| 789 | return IRQ_HANDLED; |
| 790 | } |
| 791 | |
| 792 | return ehci_irq(hcd); |
| 793 | } |
| 794 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 795 | static irqreturn_t msm_async_irq(int irq, void *data) |
| 796 | { |
| 797 | struct msm_hcd *mhcd = data; |
| 798 | int ret; |
| 799 | |
| 800 | mhcd->async_int_cnt++; |
| 801 | dev_dbg(mhcd->dev, "%s: hsusb host remote wakeup interrupt cnt: %u\n", |
| 802 | __func__, mhcd->async_int_cnt); |
| 803 | |
| 804 | wake_lock(&mhcd->wlock); |
| 805 | |
| 806 | spin_lock(&mhcd->wakeup_lock); |
| 807 | if (mhcd->async_irq_enabled) { |
| 808 | mhcd->async_irq_enabled = 0; |
| 809 | disable_irq_wake(irq); |
| 810 | disable_irq_nosync(irq); |
| 811 | } |
| 812 | spin_unlock(&mhcd->wakeup_lock); |
| 813 | |
| 814 | if (!atomic_read(&mhcd->pm_usage_cnt)) { |
| 815 | ret = pm_runtime_get(mhcd->dev); |
| 816 | if ((ret == 1) || (ret == -EINPROGRESS)) |
| 817 | pm_runtime_put_noidle(mhcd->dev); |
| 818 | else |
| 819 | atomic_set(&mhcd->pm_usage_cnt, 1); |
| 820 | } |
| 821 | |
| 822 | return IRQ_HANDLED; |
| 823 | } |
| 824 | |
Vijayavardhan Vennapusa | 4fa1369 | 2012-08-02 14:35:03 +0530 | [diff] [blame] | 825 | static irqreturn_t msm_ehci_host_wakeup_irq(int irq, void *data) |
| 826 | { |
| 827 | |
| 828 | struct msm_hcd *mhcd = data; |
| 829 | |
| 830 | mhcd->pmic_gpio_int_cnt++; |
| 831 | dev_dbg(mhcd->dev, "%s: hsusb host remote wakeup interrupt cnt: %u\n", |
| 832 | __func__, mhcd->pmic_gpio_int_cnt); |
| 833 | |
| 834 | |
| 835 | wake_lock(&mhcd->wlock); |
| 836 | |
| 837 | if (mhcd->pmic_gpio_dp_irq_enabled) { |
| 838 | mhcd->pmic_gpio_dp_irq_enabled = 0; |
| 839 | disable_irq_wake(irq); |
| 840 | disable_irq_nosync(irq); |
| 841 | } |
| 842 | |
| 843 | if (!atomic_read(&mhcd->pm_usage_cnt)) { |
| 844 | atomic_set(&mhcd->pm_usage_cnt, 1); |
| 845 | pm_runtime_get(mhcd->dev); |
| 846 | } |
| 847 | |
| 848 | return IRQ_HANDLED; |
| 849 | } |
| 850 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 851 | static int msm_ehci_reset(struct usb_hcd *hcd) |
| 852 | { |
| 853 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 854 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 855 | struct msm_usb_host_platform_data *pdata; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 856 | int retval; |
| 857 | |
| 858 | ehci->caps = USB_CAPLENGTH; |
| 859 | ehci->regs = USB_CAPLENGTH + |
| 860 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
| 861 | dbg_hcs_params(ehci, "reset"); |
| 862 | dbg_hcc_params(ehci, "reset"); |
| 863 | |
| 864 | /* cache the data to minimize the chip reads*/ |
| 865 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
| 866 | |
| 867 | hcd->has_tt = 1; |
| 868 | ehci->sbrn = HCD_USB2; |
| 869 | |
| 870 | retval = ehci_halt(ehci); |
| 871 | if (retval) |
| 872 | return retval; |
| 873 | |
| 874 | /* data structure init */ |
| 875 | retval = ehci_init(hcd); |
| 876 | if (retval) |
| 877 | return retval; |
| 878 | |
| 879 | retval = ehci_reset(ehci); |
| 880 | if (retval) |
| 881 | return retval; |
| 882 | |
| 883 | /* bursts of unspecified length. */ |
| 884 | writel_relaxed(0, USB_AHBBURST); |
| 885 | /* Use the AHB transactor */ |
Vijayavardhan Vennapusa | 5f32d7a | 2012-03-14 16:30:26 +0530 | [diff] [blame] | 886 | writel_relaxed(0x08, USB_AHBMODE); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 887 | /* Disable streaming mode and select host mode */ |
| 888 | writel_relaxed(0x13, USB_USBMODE); |
| 889 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 890 | pdata = mhcd->dev->platform_data; |
| 891 | if (pdata && pdata->use_sec_phy) |
| 892 | writel_relaxed(readl_relaxed(USB_PHY_CTRL2) | (1<<16), |
| 893 | USB_PHY_CTRL2); |
| 894 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 895 | ehci_port_power(ehci, 1); |
| 896 | return 0; |
| 897 | } |
| 898 | |
| 899 | static struct hc_driver msm_hc2_driver = { |
| 900 | .description = hcd_name, |
| 901 | .product_desc = "Qualcomm EHCI Host Controller", |
| 902 | .hcd_priv_size = sizeof(struct msm_hcd), |
| 903 | |
| 904 | /* |
| 905 | * generic hardware linkage |
| 906 | */ |
| 907 | .irq = msm_ehci_irq, |
| 908 | .flags = HCD_USB2 | HCD_MEMORY, |
| 909 | |
| 910 | .reset = msm_ehci_reset, |
| 911 | .start = ehci_run, |
| 912 | |
| 913 | .stop = ehci_stop, |
| 914 | .shutdown = ehci_shutdown, |
| 915 | |
| 916 | /* |
| 917 | * managing i/o requests and associated device resources |
| 918 | */ |
| 919 | .urb_enqueue = ehci_urb_enqueue, |
| 920 | .urb_dequeue = ehci_urb_dequeue, |
| 921 | .endpoint_disable = ehci_endpoint_disable, |
| 922 | .endpoint_reset = ehci_endpoint_reset, |
| 923 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 924 | |
| 925 | /* |
| 926 | * scheduling support |
| 927 | */ |
| 928 | .get_frame_number = ehci_get_frame, |
| 929 | |
| 930 | /* |
| 931 | * root hub support |
| 932 | */ |
| 933 | .hub_status_data = ehci_hub_status_data, |
| 934 | .hub_control = ehci_hub_control, |
| 935 | .relinquish_port = ehci_relinquish_port, |
| 936 | .port_handed_over = ehci_port_handed_over, |
| 937 | |
| 938 | /* |
| 939 | * PM support |
| 940 | */ |
| 941 | .bus_suspend = ehci_bus_suspend, |
| 942 | .bus_resume = ehci_bus_resume, |
| 943 | }; |
| 944 | |
| 945 | static int msm_ehci_init_clocks(struct msm_hcd *mhcd, u32 init) |
| 946 | { |
| 947 | int ret = 0; |
| 948 | |
| 949 | if (!init) |
| 950 | goto put_clocks; |
| 951 | |
| 952 | /* 60MHz alt_core_clk is for LINK to be used during PHY RESET */ |
| 953 | mhcd->alt_core_clk = clk_get(mhcd->dev, "alt_core_clk"); |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 954 | if (IS_ERR(mhcd->alt_core_clk)) |
| 955 | dev_dbg(mhcd->dev, "failed to get alt_core_clk\n"); |
| 956 | else |
| 957 | clk_set_rate(mhcd->alt_core_clk, 60000000); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 958 | |
| 959 | /* iface_clk is required for data transfers */ |
| 960 | mhcd->iface_clk = clk_get(mhcd->dev, "iface_clk"); |
| 961 | if (IS_ERR(mhcd->iface_clk)) { |
| 962 | dev_err(mhcd->dev, "failed to get iface_clk\n"); |
| 963 | ret = PTR_ERR(mhcd->iface_clk); |
| 964 | goto put_alt_core_clk; |
| 965 | } |
| 966 | |
| 967 | /* Link's protocol engine is based on pclk which must |
| 968 | * be running >55Mhz and frequency should also not change. |
| 969 | * Hence, vote for maximum clk frequency on its source |
| 970 | */ |
| 971 | mhcd->core_clk = clk_get(mhcd->dev, "core_clk"); |
| 972 | if (IS_ERR(mhcd->core_clk)) { |
| 973 | dev_err(mhcd->dev, "failed to get core_clk\n"); |
| 974 | ret = PTR_ERR(mhcd->core_clk); |
| 975 | goto put_iface_clk; |
| 976 | } |
| 977 | clk_set_rate(mhcd->core_clk, INT_MAX); |
| 978 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 979 | mhcd->phy_sleep_clk = clk_get(mhcd->dev, "sleep_clk"); |
| 980 | if (IS_ERR(mhcd->phy_sleep_clk)) |
| 981 | dev_dbg(mhcd->dev, "failed to get sleep_clk\n"); |
| 982 | else |
| 983 | clk_prepare_enable(mhcd->phy_sleep_clk); |
| 984 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 985 | clk_prepare_enable(mhcd->core_clk); |
| 986 | clk_prepare_enable(mhcd->iface_clk); |
| 987 | |
| 988 | return 0; |
| 989 | |
| 990 | put_clocks: |
Jack Pham | 35fba31 | 2013-01-21 19:19:21 -0800 | [diff] [blame] | 991 | if (!atomic_read(&mhcd->in_lpm)) { |
| 992 | clk_disable_unprepare(mhcd->iface_clk); |
| 993 | clk_disable_unprepare(mhcd->core_clk); |
| 994 | } |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 995 | clk_put(mhcd->core_clk); |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 996 | if (!IS_ERR(mhcd->phy_sleep_clk)) { |
| 997 | clk_disable_unprepare(mhcd->phy_sleep_clk); |
| 998 | clk_put(mhcd->phy_sleep_clk); |
| 999 | } |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1000 | put_iface_clk: |
| 1001 | clk_put(mhcd->iface_clk); |
| 1002 | put_alt_core_clk: |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 1003 | if (!IS_ERR(mhcd->alt_core_clk)) |
| 1004 | clk_put(mhcd->alt_core_clk); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1005 | |
| 1006 | return ret; |
| 1007 | } |
| 1008 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 1009 | struct msm_usb_host_platform_data *ehci_msm2_dt_to_pdata( |
| 1010 | struct platform_device *pdev) |
| 1011 | { |
| 1012 | struct device_node *node = pdev->dev.of_node; |
| 1013 | struct msm_usb_host_platform_data *pdata; |
| 1014 | |
| 1015 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 1016 | if (!pdata) { |
| 1017 | dev_err(&pdev->dev, "unable to allocate platform data\n"); |
| 1018 | return NULL; |
| 1019 | } |
| 1020 | |
| 1021 | pdata->use_sec_phy = of_property_read_bool(node, |
| 1022 | "qcom,usb2-enable-hsphy2"); |
| 1023 | of_property_read_u32(node, "qcom,usb2-power-budget", |
| 1024 | &pdata->power_budget); |
| 1025 | return pdata; |
| 1026 | } |
| 1027 | |
| 1028 | static u64 ehci_msm_dma_mask = DMA_BIT_MASK(64); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1029 | static int __devinit ehci_msm2_probe(struct platform_device *pdev) |
| 1030 | { |
| 1031 | struct usb_hcd *hcd; |
| 1032 | struct resource *res; |
| 1033 | struct msm_hcd *mhcd; |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 1034 | const struct msm_usb_host_platform_data *pdata; |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 1035 | char pdev_name[PDEV_NAME_LEN]; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1036 | int ret; |
| 1037 | |
| 1038 | dev_dbg(&pdev->dev, "ehci_msm2 probe\n"); |
| 1039 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 1040 | if (pdev->dev.of_node) { |
| 1041 | dev_dbg(&pdev->dev, "device tree enabled\n"); |
| 1042 | pdev->dev.platform_data = ehci_msm2_dt_to_pdata(pdev); |
| 1043 | } |
| 1044 | |
| 1045 | if (!pdev->dev.platform_data) |
| 1046 | dev_dbg(&pdev->dev, "No platform data given\n"); |
| 1047 | |
| 1048 | if (!pdev->dev.dma_mask) |
| 1049 | pdev->dev.dma_mask = &ehci_msm_dma_mask; |
| 1050 | if (!pdev->dev.coherent_dma_mask) |
| 1051 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 1052 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1053 | hcd = usb_create_hcd(&msm_hc2_driver, &pdev->dev, |
| 1054 | dev_name(&pdev->dev)); |
| 1055 | if (!hcd) { |
| 1056 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
| 1057 | return -ENOMEM; |
| 1058 | } |
| 1059 | |
| 1060 | hcd->irq = platform_get_irq(pdev, 0); |
| 1061 | if (hcd->irq < 0) { |
| 1062 | dev_err(&pdev->dev, "Unable to get IRQ resource\n"); |
| 1063 | ret = hcd->irq; |
| 1064 | goto put_hcd; |
| 1065 | } |
| 1066 | |
| 1067 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1068 | if (!res) { |
| 1069 | dev_err(&pdev->dev, "Unable to get memory resource\n"); |
| 1070 | ret = -ENODEV; |
| 1071 | goto put_hcd; |
| 1072 | } |
| 1073 | |
| 1074 | hcd->rsrc_start = res->start; |
| 1075 | hcd->rsrc_len = resource_size(res); |
| 1076 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 1077 | if (!hcd->regs) { |
| 1078 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 1079 | ret = -ENOMEM; |
| 1080 | goto put_hcd; |
| 1081 | } |
| 1082 | |
| 1083 | mhcd = hcd_to_mhcd(hcd); |
| 1084 | mhcd->dev = &pdev->dev; |
| 1085 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 1086 | spin_lock_init(&mhcd->wakeup_lock); |
| 1087 | |
| 1088 | mhcd->async_irq = platform_get_irq_byname(pdev, "async_irq"); |
| 1089 | if (mhcd->async_irq < 0) { |
| 1090 | dev_dbg(&pdev->dev, "platform_get_irq for async_int failed\n"); |
| 1091 | mhcd->async_irq = 0; |
| 1092 | } else { |
| 1093 | ret = request_irq(mhcd->async_irq, msm_async_irq, |
| 1094 | IRQF_TRIGGER_RISING, "msm_ehci_host", mhcd); |
| 1095 | if (ret) { |
| 1096 | dev_err(&pdev->dev, "request irq failed (ASYNC INT)\n"); |
| 1097 | goto unmap; |
| 1098 | } |
| 1099 | disable_irq(mhcd->async_irq); |
| 1100 | } |
| 1101 | |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 1102 | snprintf(pdev_name, PDEV_NAME_LEN, "%s.%d", pdev->name, pdev->id); |
Vijayavardhan Vennapusa | 16fcaf9 | 2013-03-04 10:24:21 +0530 | [diff] [blame] | 1103 | mhcd->xo_clk = clk_get(&pdev->dev, "xo"); |
| 1104 | if (!IS_ERR(mhcd->xo_clk)) { |
| 1105 | ret = clk_prepare_enable(mhcd->xo_clk); |
| 1106 | } else { |
| 1107 | mhcd->xo_handle = msm_xo_get(MSM_XO_TCXO_D0, pdev_name); |
| 1108 | if (IS_ERR(mhcd->xo_handle)) { |
| 1109 | dev_err(&pdev->dev, "%s fail to get handle for X0 D0\n", |
| 1110 | __func__); |
| 1111 | ret = PTR_ERR(mhcd->xo_handle); |
| 1112 | goto free_async_irq; |
| 1113 | } else { |
| 1114 | ret = msm_xo_mode_vote(mhcd->xo_handle, MSM_XO_MODE_ON); |
| 1115 | } |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 1116 | } |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 1117 | if (ret) { |
Vijayavardhan Vennapusa | 16fcaf9 | 2013-03-04 10:24:21 +0530 | [diff] [blame] | 1118 | dev_err(&pdev->dev, "%s failed to vote for TCXO %d\n", |
| 1119 | __func__, ret); |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 1120 | goto free_xo_handle; |
| 1121 | } |
| 1122 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1123 | ret = msm_ehci_init_clocks(mhcd, 1); |
| 1124 | if (ret) { |
| 1125 | dev_err(&pdev->dev, "unable to initialize clocks\n"); |
| 1126 | ret = -ENODEV; |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 1127 | goto devote_xo_handle; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1128 | } |
| 1129 | |
| 1130 | ret = msm_ehci_init_vddcx(mhcd, 1); |
| 1131 | if (ret) { |
| 1132 | dev_err(&pdev->dev, "unable to initialize VDDCX\n"); |
| 1133 | ret = -ENODEV; |
| 1134 | goto deinit_clocks; |
| 1135 | } |
| 1136 | |
| 1137 | ret = msm_ehci_config_vddcx(mhcd, 1); |
| 1138 | if (ret) { |
| 1139 | dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); |
| 1140 | goto deinit_vddcx; |
| 1141 | } |
| 1142 | |
| 1143 | ret = msm_ehci_ldo_init(mhcd, 1); |
| 1144 | if (ret) { |
| 1145 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); |
| 1146 | goto deinit_vddcx; |
| 1147 | } |
| 1148 | |
| 1149 | ret = msm_ehci_ldo_enable(mhcd, 1); |
| 1150 | if (ret) { |
| 1151 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); |
| 1152 | goto deinit_ldo; |
| 1153 | } |
| 1154 | |
| 1155 | ret = msm_ehci_init_vbus(mhcd, 1); |
| 1156 | if (ret) { |
| 1157 | dev_err(&pdev->dev, "unable to get vbus\n"); |
| 1158 | goto disable_ldo; |
| 1159 | } |
| 1160 | |
| 1161 | ret = msm_hsusb_reset(mhcd); |
| 1162 | if (ret) { |
| 1163 | dev_err(&pdev->dev, "hsusb PHY initialization failed\n"); |
| 1164 | goto vbus_deinit; |
| 1165 | } |
| 1166 | |
| 1167 | ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
| 1168 | if (ret) { |
| 1169 | dev_err(&pdev->dev, "unable to register HCD\n"); |
| 1170 | goto vbus_deinit; |
| 1171 | } |
| 1172 | |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 1173 | pdata = mhcd->dev->platform_data; |
| 1174 | if (pdata && (!pdata->dock_connect_irq || |
| 1175 | !irq_read_line(pdata->dock_connect_irq))) |
| 1176 | msm_ehci_vbus_power(mhcd, 1); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1177 | |
| 1178 | device_init_wakeup(&pdev->dev, 1); |
| 1179 | wake_lock_init(&mhcd->wlock, WAKE_LOCK_SUSPEND, dev_name(&pdev->dev)); |
| 1180 | wake_lock(&mhcd->wlock); |
Chiranjeevi Velempati | ce16958 | 2012-08-25 14:15:41 +0530 | [diff] [blame] | 1181 | INIT_WORK(&mhcd->phy_susp_fail_work, msm_ehci_phy_susp_fail_work); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1182 | /* |
| 1183 | * This pdev->dev is assigned parent of root-hub by USB core, |
| 1184 | * hence, runtime framework automatically calls this driver's |
| 1185 | * runtime APIs based on root-hub's state. |
| 1186 | */ |
Vijayavardhan Vennapusa | 4fa1369 | 2012-08-02 14:35:03 +0530 | [diff] [blame] | 1187 | /* configure pmic_gpio_irq for D+ change */ |
| 1188 | if (pdata && pdata->pmic_gpio_dp_irq) |
| 1189 | mhcd->pmic_gpio_dp_irq = pdata->pmic_gpio_dp_irq; |
| 1190 | if (mhcd->pmic_gpio_dp_irq) { |
| 1191 | ret = request_threaded_irq(mhcd->pmic_gpio_dp_irq, NULL, |
| 1192 | msm_ehci_host_wakeup_irq, |
| 1193 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, |
| 1194 | "msm_ehci_host_wakeup", mhcd); |
| 1195 | if (!ret) { |
| 1196 | disable_irq_nosync(mhcd->pmic_gpio_dp_irq); |
| 1197 | } else { |
| 1198 | dev_err(&pdev->dev, "request_irq(%d) failed: %d\n", |
| 1199 | mhcd->pmic_gpio_dp_irq, ret); |
| 1200 | mhcd->pmic_gpio_dp_irq = 0; |
| 1201 | } |
| 1202 | } |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1203 | pm_runtime_set_active(&pdev->dev); |
| 1204 | pm_runtime_enable(&pdev->dev); |
| 1205 | |
| 1206 | return 0; |
| 1207 | |
| 1208 | vbus_deinit: |
| 1209 | msm_ehci_init_vbus(mhcd, 0); |
| 1210 | disable_ldo: |
| 1211 | msm_ehci_ldo_enable(mhcd, 0); |
| 1212 | deinit_ldo: |
| 1213 | msm_ehci_ldo_init(mhcd, 0); |
| 1214 | deinit_vddcx: |
| 1215 | msm_ehci_init_vddcx(mhcd, 0); |
| 1216 | deinit_clocks: |
| 1217 | msm_ehci_init_clocks(mhcd, 0); |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 1218 | devote_xo_handle: |
Vijayavardhan Vennapusa | 16fcaf9 | 2013-03-04 10:24:21 +0530 | [diff] [blame] | 1219 | if (!IS_ERR(mhcd->xo_clk)) |
| 1220 | clk_disable_unprepare(mhcd->xo_clk); |
| 1221 | else |
| 1222 | msm_xo_mode_vote(mhcd->xo_handle, MSM_XO_MODE_OFF); |
Hemant Kumar | 8c0f2a8 | 2012-05-03 19:17:26 -0700 | [diff] [blame] | 1223 | free_xo_handle: |
Vijayavardhan Vennapusa | 16fcaf9 | 2013-03-04 10:24:21 +0530 | [diff] [blame] | 1224 | if (!IS_ERR(mhcd->xo_clk)) |
| 1225 | clk_put(mhcd->xo_clk); |
| 1226 | else |
| 1227 | msm_xo_put(mhcd->xo_handle); |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 1228 | free_async_irq: |
| 1229 | if (mhcd->async_irq) |
| 1230 | free_irq(mhcd->async_irq, mhcd); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1231 | unmap: |
| 1232 | iounmap(hcd->regs); |
| 1233 | put_hcd: |
| 1234 | usb_put_hcd(hcd); |
| 1235 | |
| 1236 | return ret; |
| 1237 | } |
| 1238 | |
| 1239 | static int __devexit ehci_msm2_remove(struct platform_device *pdev) |
| 1240 | { |
| 1241 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 1242 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 1243 | |
Vijayavardhan Vennapusa | 4fa1369 | 2012-08-02 14:35:03 +0530 | [diff] [blame] | 1244 | if (mhcd->pmic_gpio_dp_irq) { |
| 1245 | if (mhcd->pmic_gpio_dp_irq_enabled) |
| 1246 | disable_irq_wake(mhcd->pmic_gpio_dp_irq); |
| 1247 | free_irq(mhcd->pmic_gpio_dp_irq, mhcd); |
| 1248 | } |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 1249 | if (mhcd->async_irq) { |
| 1250 | if (mhcd->async_irq_enabled) |
| 1251 | disable_irq_wake(mhcd->async_irq); |
| 1252 | free_irq(mhcd->async_irq, mhcd); |
| 1253 | } |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1254 | device_init_wakeup(&pdev->dev, 0); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1255 | pm_runtime_set_suspended(&pdev->dev); |
| 1256 | |
| 1257 | usb_remove_hcd(hcd); |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 1258 | |
Vijayavardhan Vennapusa | 16fcaf9 | 2013-03-04 10:24:21 +0530 | [diff] [blame] | 1259 | if (!IS_ERR(mhcd->xo_clk)) { |
| 1260 | clk_disable_unprepare(mhcd->xo_clk); |
| 1261 | clk_put(mhcd->xo_clk); |
| 1262 | } else { |
| 1263 | msm_xo_put(mhcd->xo_handle); |
| 1264 | } |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1265 | msm_ehci_vbus_power(mhcd, 0); |
| 1266 | msm_ehci_init_vbus(mhcd, 0); |
| 1267 | msm_ehci_ldo_enable(mhcd, 0); |
| 1268 | msm_ehci_ldo_init(mhcd, 0); |
| 1269 | msm_ehci_init_vddcx(mhcd, 0); |
| 1270 | |
| 1271 | msm_ehci_init_clocks(mhcd, 0); |
| 1272 | wake_lock_destroy(&mhcd->wlock); |
| 1273 | iounmap(hcd->regs); |
| 1274 | usb_put_hcd(hcd); |
| 1275 | |
| 1276 | return 0; |
| 1277 | } |
| 1278 | |
| 1279 | #ifdef CONFIG_PM_SLEEP |
| 1280 | static int ehci_msm2_pm_suspend(struct device *dev) |
| 1281 | { |
| 1282 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1283 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 1284 | |
| 1285 | dev_dbg(dev, "ehci-msm2 PM suspend\n"); |
| 1286 | |
| 1287 | if (device_may_wakeup(dev)) |
| 1288 | enable_irq_wake(hcd->irq); |
| 1289 | |
| 1290 | return msm_ehci_suspend(mhcd); |
| 1291 | |
| 1292 | } |
| 1293 | |
| 1294 | static int ehci_msm2_pm_resume(struct device *dev) |
| 1295 | { |
| 1296 | int ret; |
| 1297 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1298 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 1299 | |
| 1300 | dev_dbg(dev, "ehci-msm2 PM resume\n"); |
| 1301 | |
| 1302 | if (device_may_wakeup(dev)) |
| 1303 | disable_irq_wake(hcd->irq); |
| 1304 | |
| 1305 | ret = msm_ehci_resume(mhcd); |
| 1306 | if (ret) |
| 1307 | return ret; |
| 1308 | |
| 1309 | /* Bring the device to full powered state upon system resume */ |
| 1310 | pm_runtime_disable(dev); |
| 1311 | pm_runtime_set_active(dev); |
| 1312 | pm_runtime_enable(dev); |
| 1313 | |
| 1314 | return 0; |
| 1315 | } |
| 1316 | #endif |
| 1317 | |
| 1318 | #ifdef CONFIG_PM_RUNTIME |
| 1319 | static int ehci_msm2_runtime_idle(struct device *dev) |
| 1320 | { |
| 1321 | dev_dbg(dev, "EHCI runtime idle\n"); |
| 1322 | |
| 1323 | return 0; |
| 1324 | } |
| 1325 | |
| 1326 | static int ehci_msm2_runtime_suspend(struct device *dev) |
| 1327 | { |
| 1328 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1329 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 1330 | |
| 1331 | dev_dbg(dev, "EHCI runtime suspend\n"); |
| 1332 | return msm_ehci_suspend(mhcd); |
| 1333 | } |
| 1334 | |
| 1335 | static int ehci_msm2_runtime_resume(struct device *dev) |
| 1336 | { |
| 1337 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1338 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 1339 | |
| 1340 | dev_dbg(dev, "EHCI runtime resume\n"); |
| 1341 | return msm_ehci_resume(mhcd); |
| 1342 | } |
| 1343 | #endif |
| 1344 | |
| 1345 | #ifdef CONFIG_PM |
| 1346 | static const struct dev_pm_ops ehci_msm2_dev_pm_ops = { |
| 1347 | SET_SYSTEM_SLEEP_PM_OPS(ehci_msm2_pm_suspend, ehci_msm2_pm_resume) |
| 1348 | SET_RUNTIME_PM_OPS(ehci_msm2_runtime_suspend, ehci_msm2_runtime_resume, |
| 1349 | ehci_msm2_runtime_idle) |
| 1350 | }; |
| 1351 | #endif |
| 1352 | |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 1353 | static const struct of_device_id ehci_msm2_dt_match[] = { |
| 1354 | { .compatible = "qcom,ehci-host", |
| 1355 | }, |
| 1356 | {} |
| 1357 | }; |
| 1358 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1359 | static struct platform_driver ehci_msm2_driver = { |
| 1360 | .probe = ehci_msm2_probe, |
| 1361 | .remove = __devexit_p(ehci_msm2_remove), |
| 1362 | .driver = { |
| 1363 | .name = "msm_ehci_host", |
| 1364 | #ifdef CONFIG_PM |
| 1365 | .pm = &ehci_msm2_dev_pm_ops, |
| 1366 | #endif |
Vijayavardhan Vennapusa | 1f5da0b | 2013-01-08 20:03:57 +0530 | [diff] [blame] | 1367 | .of_match_table = ehci_msm2_dt_match, |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1368 | }, |
| 1369 | }; |