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