Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 1 | /* ehci-msm2.c - HSUSB Host Controller Driver Implementation |
| 2 | * |
| 3 | * Copyright (c) 2008-2012, Code Aurora Forum. All rights reserved. |
| 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> |
| 35 | #include <mach/clk.h> |
| 36 | #include <mach/msm_iomap.h> |
| 37 | |
| 38 | #define MSM_USB_BASE (hcd->regs) |
| 39 | |
| 40 | struct msm_hcd { |
| 41 | struct ehci_hcd ehci; |
| 42 | struct device *dev; |
| 43 | struct clk *iface_clk; |
| 44 | struct clk *core_clk; |
| 45 | struct clk *alt_core_clk; |
| 46 | struct regulator *hsusb_vddcx; |
| 47 | struct regulator *hsusb_3p3; |
| 48 | struct regulator *hsusb_1p8; |
| 49 | struct regulator *vbus; |
| 50 | bool async_int; |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 51 | bool vbus_on; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 52 | atomic_t in_lpm; |
| 53 | struct wake_lock wlock; |
| 54 | }; |
| 55 | |
| 56 | static inline struct msm_hcd *hcd_to_mhcd(struct usb_hcd *hcd) |
| 57 | { |
| 58 | return (struct msm_hcd *) (hcd->hcd_priv); |
| 59 | } |
| 60 | |
| 61 | static inline struct usb_hcd *mhcd_to_hcd(struct msm_hcd *mhcd) |
| 62 | { |
| 63 | return container_of((void *) mhcd, struct usb_hcd, hcd_priv); |
| 64 | } |
| 65 | |
| 66 | #define HSUSB_PHY_3P3_VOL_MIN 3050000 /* uV */ |
| 67 | #define HSUSB_PHY_3P3_VOL_MAX 3300000 /* uV */ |
| 68 | #define HSUSB_PHY_3P3_HPM_LOAD 50000 /* uA */ |
| 69 | |
| 70 | #define HSUSB_PHY_1P8_VOL_MIN 1800000 /* uV */ |
| 71 | #define HSUSB_PHY_1P8_VOL_MAX 1800000 /* uV */ |
| 72 | #define HSUSB_PHY_1P8_HPM_LOAD 50000 /* uA */ |
| 73 | |
| 74 | #define HSUSB_PHY_VDD_DIG_VOL_MIN 1045000 /* uV */ |
| 75 | #define HSUSB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
| 76 | #define HSUSB_PHY_VDD_DIG_LOAD 49360 /* uA */ |
| 77 | |
| 78 | static int msm_ehci_init_vddcx(struct msm_hcd *mhcd, int init) |
| 79 | { |
| 80 | int ret = 0; |
| 81 | |
| 82 | if (!init) |
| 83 | goto disable_reg; |
| 84 | |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame^] | 85 | mhcd->hsusb_vddcx = devm_regulator_get(mhcd->dev, "HSUSB_VDDCX"); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 86 | if (IS_ERR(mhcd->hsusb_vddcx)) { |
| 87 | dev_err(mhcd->dev, "unable to get ehci vddcx\n"); |
| 88 | return PTR_ERR(mhcd->hsusb_vddcx); |
| 89 | } |
| 90 | |
| 91 | ret = regulator_set_voltage(mhcd->hsusb_vddcx, |
| 92 | HSUSB_PHY_VDD_DIG_VOL_MIN, |
| 93 | HSUSB_PHY_VDD_DIG_VOL_MAX); |
| 94 | if (ret) { |
| 95 | dev_err(mhcd->dev, "unable to set the voltage" |
| 96 | "for ehci vddcx\n"); |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame^] | 97 | return ret; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | ret = regulator_set_optimum_mode(mhcd->hsusb_vddcx, |
| 101 | HSUSB_PHY_VDD_DIG_LOAD); |
| 102 | if (ret < 0) { |
| 103 | dev_err(mhcd->dev, "%s: Unable to set optimum mode of the" |
| 104 | " regulator: VDDCX\n", __func__); |
| 105 | goto reg_optimum_mode_err; |
| 106 | } |
| 107 | |
| 108 | ret = regulator_enable(mhcd->hsusb_vddcx); |
| 109 | if (ret) { |
| 110 | dev_err(mhcd->dev, "unable to enable ehci vddcx\n"); |
| 111 | goto reg_enable_err; |
| 112 | } |
| 113 | |
| 114 | return 0; |
| 115 | |
| 116 | disable_reg: |
| 117 | regulator_disable(mhcd->hsusb_vddcx); |
| 118 | reg_enable_err: |
| 119 | regulator_set_optimum_mode(mhcd->hsusb_vddcx, 0); |
| 120 | reg_optimum_mode_err: |
| 121 | regulator_set_voltage(mhcd->hsusb_vddcx, 0, |
| 122 | HSUSB_PHY_VDD_DIG_VOL_MIN); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 123 | return ret; |
| 124 | |
| 125 | } |
| 126 | |
| 127 | static int msm_ehci_ldo_init(struct msm_hcd *mhcd, int init) |
| 128 | { |
| 129 | int rc = 0; |
| 130 | |
| 131 | if (!init) |
| 132 | goto put_1p8; |
| 133 | |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame^] | 134 | mhcd->hsusb_3p3 = devm_regulator_get(mhcd->dev, "HSUSB_3p3"); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 135 | if (IS_ERR(mhcd->hsusb_3p3)) { |
| 136 | dev_err(mhcd->dev, "unable to get hsusb 3p3\n"); |
| 137 | return PTR_ERR(mhcd->hsusb_3p3); |
| 138 | } |
| 139 | |
| 140 | rc = regulator_set_voltage(mhcd->hsusb_3p3, |
| 141 | HSUSB_PHY_3P3_VOL_MIN, HSUSB_PHY_3P3_VOL_MAX); |
| 142 | if (rc) { |
| 143 | dev_err(mhcd->dev, "unable to set voltage level for" |
| 144 | "hsusb 3p3\n"); |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame^] | 145 | return rc; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 146 | } |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame^] | 147 | mhcd->hsusb_1p8 = devm_regulator_get(mhcd->dev, "HSUSB_1p8"); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 148 | if (IS_ERR(mhcd->hsusb_1p8)) { |
| 149 | dev_err(mhcd->dev, "unable to get hsusb 1p8\n"); |
| 150 | rc = PTR_ERR(mhcd->hsusb_1p8); |
| 151 | goto put_3p3_lpm; |
| 152 | } |
| 153 | rc = regulator_set_voltage(mhcd->hsusb_1p8, |
| 154 | HSUSB_PHY_1P8_VOL_MIN, HSUSB_PHY_1P8_VOL_MAX); |
| 155 | if (rc) { |
| 156 | dev_err(mhcd->dev, "unable to set voltage level for" |
| 157 | "hsusb 1p8\n"); |
| 158 | goto put_1p8; |
| 159 | } |
| 160 | |
| 161 | return 0; |
| 162 | |
| 163 | put_1p8: |
| 164 | regulator_set_voltage(mhcd->hsusb_1p8, 0, HSUSB_PHY_1P8_VOL_MAX); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 165 | put_3p3_lpm: |
| 166 | regulator_set_voltage(mhcd->hsusb_3p3, 0, HSUSB_PHY_3P3_VOL_MAX); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 167 | |
| 168 | return rc; |
| 169 | } |
| 170 | |
| 171 | #ifdef CONFIG_PM_SLEEP |
Hemant Kumar | 441356be | 2012-02-13 16:12:49 -0800 | [diff] [blame] | 172 | #define HSUSB_PHY_SUSP_DIG_VOL_P50 500000 |
| 173 | #define HSUSB_PHY_SUSP_DIG_VOL_P75 750000 |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 174 | static int msm_ehci_config_vddcx(struct msm_hcd *mhcd, int high) |
| 175 | { |
Hemant Kumar | 441356be | 2012-02-13 16:12:49 -0800 | [diff] [blame] | 176 | struct msm_usb_host_platform_data *pdata; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 177 | int max_vol = HSUSB_PHY_VDD_DIG_VOL_MAX; |
| 178 | int min_vol; |
| 179 | int ret; |
| 180 | |
Hemant Kumar | 441356be | 2012-02-13 16:12:49 -0800 | [diff] [blame] | 181 | pdata = mhcd->dev->platform_data; |
| 182 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 183 | if (high) |
| 184 | min_vol = HSUSB_PHY_VDD_DIG_VOL_MIN; |
Hemant Kumar | 441356be | 2012-02-13 16:12:49 -0800 | [diff] [blame] | 185 | else if (pdata && pdata->dock_connect_irq && |
| 186 | !irq_read_line(pdata->dock_connect_irq)) |
| 187 | min_vol = HSUSB_PHY_SUSP_DIG_VOL_P75; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 188 | else |
Hemant Kumar | 441356be | 2012-02-13 16:12:49 -0800 | [diff] [blame] | 189 | min_vol = HSUSB_PHY_SUSP_DIG_VOL_P50; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 190 | |
| 191 | ret = regulator_set_voltage(mhcd->hsusb_vddcx, min_vol, max_vol); |
| 192 | if (ret) { |
| 193 | dev_err(mhcd->dev, "%s: unable to set the voltage of regulator" |
| 194 | " HSUSB_VDDCX\n", __func__); |
| 195 | return ret; |
| 196 | } |
| 197 | |
| 198 | dev_dbg(mhcd->dev, "%s: min_vol:%d max_vol:%d\n", __func__, min_vol, |
| 199 | max_vol); |
| 200 | |
| 201 | return ret; |
| 202 | } |
| 203 | #else |
| 204 | static int msm_ehci_config_vddcx(struct msm_hcd *mhcd, int high) |
| 205 | { |
| 206 | return 0; |
| 207 | } |
| 208 | #endif |
| 209 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 210 | static void msm_ehci_vbus_power(struct msm_hcd *mhcd, bool on) |
| 211 | { |
| 212 | int ret; |
| 213 | |
| 214 | if (!mhcd->vbus) { |
| 215 | pr_err("vbus is NULL."); |
| 216 | return; |
| 217 | } |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 218 | |
| 219 | if (mhcd->vbus_on == on) |
| 220 | return; |
| 221 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 222 | if (on) { |
| 223 | ret = regulator_enable(mhcd->vbus); |
| 224 | if (ret) { |
| 225 | pr_err("unable to enable vbus\n"); |
| 226 | return; |
| 227 | } |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 228 | mhcd->vbus_on = true; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 229 | } else { |
| 230 | ret = regulator_disable(mhcd->vbus); |
| 231 | if (ret) { |
| 232 | pr_err("unable to disable vbus\n"); |
| 233 | return; |
| 234 | } |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 235 | mhcd->vbus_on = false; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 239 | static irqreturn_t msm_ehci_dock_connect_irq(int irq, void *data) |
| 240 | { |
| 241 | const struct msm_usb_host_platform_data *pdata; |
| 242 | struct msm_hcd *mhcd = data; |
| 243 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 244 | |
| 245 | pdata = mhcd->dev->platform_data; |
| 246 | |
| 247 | if (atomic_read(&mhcd->in_lpm)) |
| 248 | usb_hcd_resume_root_hub(hcd); |
| 249 | |
| 250 | if (irq_read_line(pdata->dock_connect_irq)) { |
| 251 | dev_dbg(mhcd->dev, "%s:Dock removed disable vbus\n", __func__); |
| 252 | msm_ehci_vbus_power(mhcd, 0); |
| 253 | } else { |
| 254 | dev_dbg(mhcd->dev, "%s:Dock connected enable vbus\n", __func__); |
| 255 | msm_ehci_vbus_power(mhcd, 1); |
| 256 | } |
| 257 | |
| 258 | return IRQ_HANDLED; |
| 259 | } |
| 260 | |
| 261 | static int msm_ehci_init_vbus(struct msm_hcd *mhcd, int init) |
| 262 | { |
| 263 | int rc = 0; |
| 264 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 265 | const struct msm_usb_host_platform_data *pdata; |
| 266 | |
| 267 | pdata = mhcd->dev->platform_data; |
| 268 | |
| 269 | if (!init) { |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 270 | if (pdata && pdata->dock_connect_irq) |
| 271 | free_irq(pdata->dock_connect_irq, mhcd); |
| 272 | return rc; |
| 273 | } |
| 274 | |
Mayank Rana | 2f416c2 | 2012-03-24 05:23:25 +0530 | [diff] [blame^] | 275 | mhcd->vbus = devm_regulator_get(mhcd->dev, "vbus"); |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 276 | if (IS_ERR(mhcd->vbus)) { |
| 277 | pr_err("Unable to get vbus\n"); |
| 278 | return -ENODEV; |
| 279 | } |
| 280 | |
| 281 | if (pdata) { |
| 282 | hcd->power_budget = pdata->power_budget; |
| 283 | |
| 284 | if (pdata->dock_connect_irq) { |
| 285 | rc = request_threaded_irq(pdata->dock_connect_irq, NULL, |
| 286 | msm_ehci_dock_connect_irq, |
| 287 | IRQF_TRIGGER_FALLING | |
| 288 | IRQF_TRIGGER_RISING | |
| 289 | IRQF_ONESHOT, "msm_ehci_host", mhcd); |
| 290 | if (!rc) |
| 291 | enable_irq_wake(pdata->dock_connect_irq); |
| 292 | } |
| 293 | } |
| 294 | return rc; |
| 295 | } |
| 296 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 297 | static int msm_ehci_ldo_enable(struct msm_hcd *mhcd, int on) |
| 298 | { |
| 299 | int ret = 0; |
| 300 | |
| 301 | if (IS_ERR(mhcd->hsusb_1p8)) { |
| 302 | dev_err(mhcd->dev, "%s: HSUSB_1p8 is not initialized\n", |
| 303 | __func__); |
| 304 | return -ENODEV; |
| 305 | } |
| 306 | |
| 307 | if (IS_ERR(mhcd->hsusb_3p3)) { |
| 308 | dev_err(mhcd->dev, "%s: HSUSB_3p3 is not initialized\n", |
| 309 | __func__); |
| 310 | return -ENODEV; |
| 311 | } |
| 312 | |
| 313 | if (on) { |
| 314 | ret = regulator_set_optimum_mode(mhcd->hsusb_1p8, |
| 315 | HSUSB_PHY_1P8_HPM_LOAD); |
| 316 | if (ret < 0) { |
| 317 | dev_err(mhcd->dev, "%s: Unable to set HPM of the" |
| 318 | " regulator: HSUSB_1p8\n", __func__); |
| 319 | return ret; |
| 320 | } |
| 321 | |
| 322 | ret = regulator_enable(mhcd->hsusb_1p8); |
| 323 | if (ret) { |
| 324 | dev_err(mhcd->dev, "%s: unable to enable the hsusb" |
| 325 | " 1p8\n", __func__); |
| 326 | regulator_set_optimum_mode(mhcd->hsusb_1p8, 0); |
| 327 | return ret; |
| 328 | } |
| 329 | |
| 330 | ret = regulator_set_optimum_mode(mhcd->hsusb_3p3, |
| 331 | HSUSB_PHY_3P3_HPM_LOAD); |
| 332 | if (ret < 0) { |
| 333 | dev_err(mhcd->dev, "%s: Unable to set HPM of the " |
| 334 | "regulator: HSUSB_3p3\n", __func__); |
| 335 | regulator_set_optimum_mode(mhcd->hsusb_1p8, 0); |
| 336 | regulator_disable(mhcd->hsusb_1p8); |
| 337 | return ret; |
| 338 | } |
| 339 | |
| 340 | ret = regulator_enable(mhcd->hsusb_3p3); |
| 341 | if (ret) { |
| 342 | dev_err(mhcd->dev, "%s: unable to enable the " |
| 343 | "hsusb 3p3\n", __func__); |
| 344 | regulator_set_optimum_mode(mhcd->hsusb_3p3, 0); |
| 345 | regulator_set_optimum_mode(mhcd->hsusb_1p8, 0); |
| 346 | regulator_disable(mhcd->hsusb_1p8); |
| 347 | return ret; |
| 348 | } |
| 349 | |
| 350 | } else { |
| 351 | ret = regulator_disable(mhcd->hsusb_1p8); |
| 352 | if (ret) { |
| 353 | dev_err(mhcd->dev, "%s: unable to disable the " |
| 354 | "hsusb 1p8\n", __func__); |
| 355 | return ret; |
| 356 | } |
| 357 | |
| 358 | ret = regulator_set_optimum_mode(mhcd->hsusb_1p8, 0); |
| 359 | if (ret < 0) |
| 360 | dev_err(mhcd->dev, "%s: Unable to set LPM of the " |
| 361 | "regulator: HSUSB_1p8\n", __func__); |
| 362 | |
| 363 | ret = regulator_disable(mhcd->hsusb_3p3); |
| 364 | if (ret) { |
| 365 | dev_err(mhcd->dev, "%s: unable to disable the " |
| 366 | "hsusb 3p3\n", __func__); |
| 367 | return ret; |
| 368 | } |
| 369 | ret = regulator_set_optimum_mode(mhcd->hsusb_3p3, 0); |
| 370 | if (ret < 0) |
| 371 | dev_err(mhcd->dev, "%s: Unable to set LPM of the " |
| 372 | "regulator: HSUSB_3p3\n", __func__); |
| 373 | } |
| 374 | |
| 375 | dev_dbg(mhcd->dev, "reg (%s)\n", on ? "HPM" : "LPM"); |
| 376 | |
| 377 | return ret < 0 ? ret : 0; |
| 378 | } |
| 379 | |
| 380 | |
| 381 | #define ULPI_IO_TIMEOUT_USECS (10 * 1000) |
| 382 | static int msm_ulpi_read(struct msm_hcd *mhcd, u32 reg) |
| 383 | { |
| 384 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 385 | unsigned long timeout; |
| 386 | |
| 387 | /* initiate read operation */ |
| 388 | writel_relaxed(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg), |
| 389 | USB_ULPI_VIEWPORT); |
| 390 | |
| 391 | /* wait for completion */ |
| 392 | timeout = jiffies + usecs_to_jiffies(ULPI_IO_TIMEOUT_USECS); |
| 393 | while (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN) { |
| 394 | if (time_after(jiffies, timeout)) { |
| 395 | dev_err(mhcd->dev, "msm_ulpi_read: timeout %08x\n", |
| 396 | readl_relaxed(USB_ULPI_VIEWPORT)); |
| 397 | return -ETIMEDOUT; |
| 398 | } |
| 399 | udelay(1); |
| 400 | } |
| 401 | |
| 402 | return ULPI_DATA_READ(readl_relaxed(USB_ULPI_VIEWPORT)); |
| 403 | } |
| 404 | |
| 405 | |
| 406 | static int msm_ulpi_write(struct msm_hcd *mhcd, u32 val, u32 reg) |
| 407 | { |
| 408 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 409 | unsigned long timeout; |
| 410 | |
| 411 | /* initiate write operation */ |
| 412 | writel_relaxed(ULPI_RUN | ULPI_WRITE | |
| 413 | ULPI_ADDR(reg) | ULPI_DATA(val), |
| 414 | USB_ULPI_VIEWPORT); |
| 415 | |
| 416 | /* wait for completion */ |
| 417 | timeout = jiffies + usecs_to_jiffies(ULPI_IO_TIMEOUT_USECS); |
| 418 | while (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN) { |
| 419 | if (time_after(jiffies, timeout)) { |
| 420 | dev_err(mhcd->dev, "msm_ulpi_write: timeout\n"); |
| 421 | return -ETIMEDOUT; |
| 422 | } |
| 423 | udelay(1); |
| 424 | } |
| 425 | |
| 426 | return 0; |
| 427 | } |
| 428 | |
| 429 | static int msm_ehci_link_clk_reset(struct msm_hcd *mhcd, bool assert) |
| 430 | { |
| 431 | int ret; |
| 432 | |
| 433 | if (assert) { |
| 434 | ret = clk_reset(mhcd->alt_core_clk, CLK_RESET_ASSERT); |
| 435 | if (ret) |
| 436 | dev_err(mhcd->dev, "usb alt_core_clk assert failed\n"); |
| 437 | } else { |
| 438 | ret = clk_reset(mhcd->alt_core_clk, CLK_RESET_DEASSERT); |
| 439 | if (ret) |
| 440 | dev_err(mhcd->dev, "usb alt_core_clk deassert failed\n"); |
| 441 | } |
| 442 | |
| 443 | return ret; |
| 444 | } |
| 445 | |
| 446 | static int msm_ehci_phy_reset(struct msm_hcd *mhcd) |
| 447 | { |
| 448 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 449 | u32 val; |
| 450 | int ret; |
| 451 | int retries; |
| 452 | |
| 453 | ret = msm_ehci_link_clk_reset(mhcd, 1); |
| 454 | if (ret) |
| 455 | return ret; |
| 456 | |
| 457 | udelay(1); |
| 458 | |
| 459 | ret = msm_ehci_link_clk_reset(mhcd, 0); |
| 460 | if (ret) |
| 461 | return ret; |
| 462 | |
| 463 | val = readl_relaxed(USB_PORTSC) & ~PORTSC_PTS_MASK; |
| 464 | writel_relaxed(val | PORTSC_PTS_ULPI, USB_PORTSC); |
| 465 | |
| 466 | for (retries = 3; retries > 0; retries--) { |
| 467 | ret = msm_ulpi_write(mhcd, ULPI_FUNC_CTRL_SUSPENDM, |
| 468 | ULPI_CLR(ULPI_FUNC_CTRL)); |
| 469 | if (!ret) |
| 470 | break; |
| 471 | } |
| 472 | if (!retries) |
| 473 | return -ETIMEDOUT; |
| 474 | |
| 475 | /* Wakeup the PHY with a reg-access for calibration */ |
| 476 | for (retries = 3; retries > 0; retries--) { |
| 477 | ret = msm_ulpi_read(mhcd, ULPI_DEBUG); |
| 478 | if (ret != -ETIMEDOUT) |
| 479 | break; |
| 480 | } |
| 481 | if (!retries) |
| 482 | return -ETIMEDOUT; |
| 483 | |
| 484 | dev_info(mhcd->dev, "phy_reset: success\n"); |
| 485 | |
| 486 | return 0; |
| 487 | } |
| 488 | |
| 489 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) |
| 490 | static int msm_hsusb_reset(struct msm_hcd *mhcd) |
| 491 | { |
| 492 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 493 | unsigned long timeout; |
| 494 | int ret; |
| 495 | |
| 496 | clk_prepare_enable(mhcd->alt_core_clk); |
| 497 | ret = msm_ehci_phy_reset(mhcd); |
| 498 | if (ret) { |
| 499 | dev_err(mhcd->dev, "phy_reset failed\n"); |
| 500 | return ret; |
| 501 | } |
| 502 | |
| 503 | writel_relaxed(USBCMD_RESET, USB_USBCMD); |
| 504 | |
| 505 | timeout = jiffies + usecs_to_jiffies(LINK_RESET_TIMEOUT_USEC); |
| 506 | while (readl_relaxed(USB_USBCMD) & USBCMD_RESET) { |
| 507 | if (time_after(jiffies, timeout)) |
| 508 | return -ETIMEDOUT; |
| 509 | udelay(1); |
| 510 | } |
| 511 | |
| 512 | /* select ULPI phy */ |
| 513 | writel_relaxed(0x80000000, USB_PORTSC); |
| 514 | |
| 515 | msleep(100); |
| 516 | |
| 517 | writel_relaxed(0x0, USB_AHBBURST); |
| 518 | writel_relaxed(0x00, USB_AHBMODE); |
| 519 | |
| 520 | /* Ensure that RESET operation is completed before turning off clock */ |
| 521 | mb(); |
| 522 | clk_disable_unprepare(mhcd->alt_core_clk); |
| 523 | |
| 524 | /*rising edge interrupts with Dp rise and fall enabled*/ |
| 525 | msm_ulpi_write(mhcd, ULPI_INT_DP, ULPI_USB_INT_EN_RISE); |
| 526 | msm_ulpi_write(mhcd, ULPI_INT_DP, ULPI_USB_INT_EN_FALL); |
| 527 | |
| 528 | /*Clear the PHY interrupts by reading the PHY interrupt latch register*/ |
| 529 | msm_ulpi_read(mhcd, ULPI_USB_INT_LATCH); |
| 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) |
| 535 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) |
| 536 | |
| 537 | #ifdef CONFIG_PM_SLEEP |
| 538 | static int msm_ehci_suspend(struct msm_hcd *mhcd) |
| 539 | { |
| 540 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 541 | unsigned long timeout; |
| 542 | u32 portsc; |
| 543 | |
| 544 | if (atomic_read(&mhcd->in_lpm)) { |
| 545 | dev_dbg(mhcd->dev, "%s called in lpm\n", __func__); |
| 546 | return 0; |
| 547 | } |
| 548 | |
| 549 | disable_irq(hcd->irq); |
| 550 | |
| 551 | /* Set the PHCD bit, only if it is not set by the controller. |
| 552 | * PHY may take some time or even fail to enter into low power |
| 553 | * mode (LPM). Hence poll for 500 msec and reset the PHY and link |
| 554 | * in failure case. |
| 555 | */ |
| 556 | portsc = readl_relaxed(USB_PORTSC); |
| 557 | if (!(portsc & PORTSC_PHCD)) { |
| 558 | writel_relaxed(portsc | PORTSC_PHCD, |
| 559 | USB_PORTSC); |
| 560 | |
| 561 | timeout = jiffies + usecs_to_jiffies(PHY_SUSPEND_TIMEOUT_USEC); |
| 562 | while (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD)) { |
| 563 | if (time_after(jiffies, timeout)) { |
| 564 | dev_err(mhcd->dev, "Unable to suspend PHY\n"); |
| 565 | msm_hsusb_reset(mhcd); |
| 566 | break; |
| 567 | } |
| 568 | udelay(1); |
| 569 | } |
| 570 | } |
| 571 | |
| 572 | /* |
| 573 | * PHY has capability to generate interrupt asynchronously in low |
| 574 | * power mode (LPM). This interrupt is level triggered. So USB IRQ |
| 575 | * line must be disabled till async interrupt enable bit is cleared |
| 576 | * in USBCMD register. Assert STP (ULPI interface STOP signal) to |
| 577 | * block data communication from PHY. |
| 578 | */ |
| 579 | writel_relaxed(readl_relaxed(USB_USBCMD) | ASYNC_INTR_CTRL | |
| 580 | ULPI_STP_CTRL, USB_USBCMD); |
| 581 | |
| 582 | /* |
| 583 | * Ensure that hardware is put in low power mode before |
| 584 | * clocks are turned OFF and VDD is allowed to minimize. |
| 585 | */ |
| 586 | mb(); |
| 587 | |
| 588 | clk_disable_unprepare(mhcd->iface_clk); |
| 589 | clk_disable_unprepare(mhcd->core_clk); |
| 590 | |
| 591 | msm_ehci_config_vddcx(mhcd, 0); |
| 592 | |
| 593 | atomic_set(&mhcd->in_lpm, 1); |
| 594 | enable_irq(hcd->irq); |
| 595 | wake_unlock(&mhcd->wlock); |
| 596 | |
| 597 | dev_info(mhcd->dev, "EHCI USB in low power mode\n"); |
| 598 | |
| 599 | return 0; |
| 600 | } |
| 601 | |
| 602 | static int msm_ehci_resume(struct msm_hcd *mhcd) |
| 603 | { |
| 604 | struct usb_hcd *hcd = mhcd_to_hcd(mhcd); |
| 605 | unsigned long timeout; |
| 606 | unsigned temp; |
| 607 | |
| 608 | if (!atomic_read(&mhcd->in_lpm)) { |
| 609 | dev_dbg(mhcd->dev, "%s called in !in_lpm\n", __func__); |
| 610 | return 0; |
| 611 | } |
| 612 | |
| 613 | wake_lock(&mhcd->wlock); |
| 614 | |
| 615 | clk_prepare_enable(mhcd->core_clk); |
| 616 | clk_prepare_enable(mhcd->iface_clk); |
| 617 | |
| 618 | msm_ehci_config_vddcx(mhcd, 1); |
| 619 | |
| 620 | temp = readl_relaxed(USB_USBCMD); |
| 621 | temp &= ~ASYNC_INTR_CTRL; |
| 622 | temp &= ~ULPI_STP_CTRL; |
| 623 | writel_relaxed(temp, USB_USBCMD); |
| 624 | |
| 625 | if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD)) |
| 626 | goto skip_phy_resume; |
| 627 | |
| 628 | temp = readl_relaxed(USB_PORTSC) & ~PORTSC_PHCD; |
| 629 | writel_relaxed(temp, USB_PORTSC); |
| 630 | |
| 631 | timeout = jiffies + usecs_to_jiffies(PHY_RESUME_TIMEOUT_USEC); |
| 632 | while ((readl_relaxed(USB_PORTSC) & PORTSC_PHCD) || |
| 633 | !(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_SYNC_STATE)) { |
| 634 | if (time_after(jiffies, timeout)) { |
| 635 | /*This is a fatal error. Reset the link and PHY*/ |
| 636 | dev_err(mhcd->dev, "Unable to resume USB. Resetting the h/w\n"); |
| 637 | msm_hsusb_reset(mhcd); |
| 638 | break; |
| 639 | } |
| 640 | udelay(1); |
| 641 | } |
| 642 | |
| 643 | skip_phy_resume: |
| 644 | |
| 645 | atomic_set(&mhcd->in_lpm, 0); |
| 646 | |
| 647 | if (mhcd->async_int) { |
| 648 | mhcd->async_int = false; |
| 649 | pm_runtime_put_noidle(mhcd->dev); |
| 650 | enable_irq(hcd->irq); |
| 651 | } |
| 652 | |
| 653 | dev_info(mhcd->dev, "EHCI USB exited from low power mode\n"); |
| 654 | |
| 655 | return 0; |
| 656 | } |
| 657 | #endif |
| 658 | |
| 659 | static irqreturn_t msm_ehci_irq(struct usb_hcd *hcd) |
| 660 | { |
| 661 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 662 | |
| 663 | if (atomic_read(&mhcd->in_lpm)) { |
| 664 | disable_irq_nosync(hcd->irq); |
| 665 | mhcd->async_int = true; |
| 666 | pm_runtime_get(mhcd->dev); |
| 667 | return IRQ_HANDLED; |
| 668 | } |
| 669 | |
| 670 | return ehci_irq(hcd); |
| 671 | } |
| 672 | |
| 673 | static int msm_ehci_reset(struct usb_hcd *hcd) |
| 674 | { |
| 675 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 676 | int retval; |
| 677 | |
| 678 | ehci->caps = USB_CAPLENGTH; |
| 679 | ehci->regs = USB_CAPLENGTH + |
| 680 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
| 681 | dbg_hcs_params(ehci, "reset"); |
| 682 | dbg_hcc_params(ehci, "reset"); |
| 683 | |
| 684 | /* cache the data to minimize the chip reads*/ |
| 685 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
| 686 | |
| 687 | hcd->has_tt = 1; |
| 688 | ehci->sbrn = HCD_USB2; |
| 689 | |
| 690 | retval = ehci_halt(ehci); |
| 691 | if (retval) |
| 692 | return retval; |
| 693 | |
| 694 | /* data structure init */ |
| 695 | retval = ehci_init(hcd); |
| 696 | if (retval) |
| 697 | return retval; |
| 698 | |
| 699 | retval = ehci_reset(ehci); |
| 700 | if (retval) |
| 701 | return retval; |
| 702 | |
| 703 | /* bursts of unspecified length. */ |
| 704 | writel_relaxed(0, USB_AHBBURST); |
| 705 | /* Use the AHB transactor */ |
| 706 | writel_relaxed(0, USB_AHBMODE); |
| 707 | /* Disable streaming mode and select host mode */ |
| 708 | writel_relaxed(0x13, USB_USBMODE); |
| 709 | |
| 710 | ehci_port_power(ehci, 1); |
| 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | static struct hc_driver msm_hc2_driver = { |
| 715 | .description = hcd_name, |
| 716 | .product_desc = "Qualcomm EHCI Host Controller", |
| 717 | .hcd_priv_size = sizeof(struct msm_hcd), |
| 718 | |
| 719 | /* |
| 720 | * generic hardware linkage |
| 721 | */ |
| 722 | .irq = msm_ehci_irq, |
| 723 | .flags = HCD_USB2 | HCD_MEMORY, |
| 724 | |
| 725 | .reset = msm_ehci_reset, |
| 726 | .start = ehci_run, |
| 727 | |
| 728 | .stop = ehci_stop, |
| 729 | .shutdown = ehci_shutdown, |
| 730 | |
| 731 | /* |
| 732 | * managing i/o requests and associated device resources |
| 733 | */ |
| 734 | .urb_enqueue = ehci_urb_enqueue, |
| 735 | .urb_dequeue = ehci_urb_dequeue, |
| 736 | .endpoint_disable = ehci_endpoint_disable, |
| 737 | .endpoint_reset = ehci_endpoint_reset, |
| 738 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 739 | |
| 740 | /* |
| 741 | * scheduling support |
| 742 | */ |
| 743 | .get_frame_number = ehci_get_frame, |
| 744 | |
| 745 | /* |
| 746 | * root hub support |
| 747 | */ |
| 748 | .hub_status_data = ehci_hub_status_data, |
| 749 | .hub_control = ehci_hub_control, |
| 750 | .relinquish_port = ehci_relinquish_port, |
| 751 | .port_handed_over = ehci_port_handed_over, |
| 752 | |
| 753 | /* |
| 754 | * PM support |
| 755 | */ |
| 756 | .bus_suspend = ehci_bus_suspend, |
| 757 | .bus_resume = ehci_bus_resume, |
| 758 | }; |
| 759 | |
| 760 | static int msm_ehci_init_clocks(struct msm_hcd *mhcd, u32 init) |
| 761 | { |
| 762 | int ret = 0; |
| 763 | |
| 764 | if (!init) |
| 765 | goto put_clocks; |
| 766 | |
| 767 | /* 60MHz alt_core_clk is for LINK to be used during PHY RESET */ |
| 768 | mhcd->alt_core_clk = clk_get(mhcd->dev, "alt_core_clk"); |
| 769 | if (IS_ERR(mhcd->alt_core_clk)) { |
| 770 | dev_err(mhcd->dev, "failed to get alt_core_clk\n"); |
| 771 | ret = PTR_ERR(mhcd->alt_core_clk); |
| 772 | return ret; |
| 773 | } |
| 774 | clk_set_rate(mhcd->alt_core_clk, 60000000); |
| 775 | |
| 776 | /* iface_clk is required for data transfers */ |
| 777 | mhcd->iface_clk = clk_get(mhcd->dev, "iface_clk"); |
| 778 | if (IS_ERR(mhcd->iface_clk)) { |
| 779 | dev_err(mhcd->dev, "failed to get iface_clk\n"); |
| 780 | ret = PTR_ERR(mhcd->iface_clk); |
| 781 | goto put_alt_core_clk; |
| 782 | } |
| 783 | |
| 784 | /* Link's protocol engine is based on pclk which must |
| 785 | * be running >55Mhz and frequency should also not change. |
| 786 | * Hence, vote for maximum clk frequency on its source |
| 787 | */ |
| 788 | mhcd->core_clk = clk_get(mhcd->dev, "core_clk"); |
| 789 | if (IS_ERR(mhcd->core_clk)) { |
| 790 | dev_err(mhcd->dev, "failed to get core_clk\n"); |
| 791 | ret = PTR_ERR(mhcd->core_clk); |
| 792 | goto put_iface_clk; |
| 793 | } |
| 794 | clk_set_rate(mhcd->core_clk, INT_MAX); |
| 795 | |
| 796 | clk_prepare_enable(mhcd->core_clk); |
| 797 | clk_prepare_enable(mhcd->iface_clk); |
| 798 | |
| 799 | return 0; |
| 800 | |
| 801 | put_clocks: |
| 802 | clk_disable_unprepare(mhcd->iface_clk); |
| 803 | clk_disable_unprepare(mhcd->core_clk); |
| 804 | clk_put(mhcd->core_clk); |
| 805 | put_iface_clk: |
| 806 | clk_put(mhcd->iface_clk); |
| 807 | put_alt_core_clk: |
| 808 | clk_put(mhcd->alt_core_clk); |
| 809 | |
| 810 | return ret; |
| 811 | } |
| 812 | |
| 813 | static int __devinit ehci_msm2_probe(struct platform_device *pdev) |
| 814 | { |
| 815 | struct usb_hcd *hcd; |
| 816 | struct resource *res; |
| 817 | struct msm_hcd *mhcd; |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 818 | const struct msm_usb_host_platform_data *pdata; |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 819 | int ret; |
| 820 | |
| 821 | dev_dbg(&pdev->dev, "ehci_msm2 probe\n"); |
| 822 | |
| 823 | hcd = usb_create_hcd(&msm_hc2_driver, &pdev->dev, |
| 824 | dev_name(&pdev->dev)); |
| 825 | if (!hcd) { |
| 826 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
| 827 | return -ENOMEM; |
| 828 | } |
| 829 | |
| 830 | hcd->irq = platform_get_irq(pdev, 0); |
| 831 | if (hcd->irq < 0) { |
| 832 | dev_err(&pdev->dev, "Unable to get IRQ resource\n"); |
| 833 | ret = hcd->irq; |
| 834 | goto put_hcd; |
| 835 | } |
| 836 | |
| 837 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 838 | if (!res) { |
| 839 | dev_err(&pdev->dev, "Unable to get memory resource\n"); |
| 840 | ret = -ENODEV; |
| 841 | goto put_hcd; |
| 842 | } |
| 843 | |
| 844 | hcd->rsrc_start = res->start; |
| 845 | hcd->rsrc_len = resource_size(res); |
| 846 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 847 | if (!hcd->regs) { |
| 848 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 849 | ret = -ENOMEM; |
| 850 | goto put_hcd; |
| 851 | } |
| 852 | |
| 853 | mhcd = hcd_to_mhcd(hcd); |
| 854 | mhcd->dev = &pdev->dev; |
| 855 | |
| 856 | ret = msm_ehci_init_clocks(mhcd, 1); |
| 857 | if (ret) { |
| 858 | dev_err(&pdev->dev, "unable to initialize clocks\n"); |
| 859 | ret = -ENODEV; |
| 860 | goto unmap; |
| 861 | } |
| 862 | |
| 863 | ret = msm_ehci_init_vddcx(mhcd, 1); |
| 864 | if (ret) { |
| 865 | dev_err(&pdev->dev, "unable to initialize VDDCX\n"); |
| 866 | ret = -ENODEV; |
| 867 | goto deinit_clocks; |
| 868 | } |
| 869 | |
| 870 | ret = msm_ehci_config_vddcx(mhcd, 1); |
| 871 | if (ret) { |
| 872 | dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); |
| 873 | goto deinit_vddcx; |
| 874 | } |
| 875 | |
| 876 | ret = msm_ehci_ldo_init(mhcd, 1); |
| 877 | if (ret) { |
| 878 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); |
| 879 | goto deinit_vddcx; |
| 880 | } |
| 881 | |
| 882 | ret = msm_ehci_ldo_enable(mhcd, 1); |
| 883 | if (ret) { |
| 884 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); |
| 885 | goto deinit_ldo; |
| 886 | } |
| 887 | |
| 888 | ret = msm_ehci_init_vbus(mhcd, 1); |
| 889 | if (ret) { |
| 890 | dev_err(&pdev->dev, "unable to get vbus\n"); |
| 891 | goto disable_ldo; |
| 892 | } |
| 893 | |
| 894 | ret = msm_hsusb_reset(mhcd); |
| 895 | if (ret) { |
| 896 | dev_err(&pdev->dev, "hsusb PHY initialization failed\n"); |
| 897 | goto vbus_deinit; |
| 898 | } |
| 899 | |
| 900 | ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
| 901 | if (ret) { |
| 902 | dev_err(&pdev->dev, "unable to register HCD\n"); |
| 903 | goto vbus_deinit; |
| 904 | } |
| 905 | |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 906 | pdata = mhcd->dev->platform_data; |
| 907 | if (pdata && (!pdata->dock_connect_irq || |
| 908 | !irq_read_line(pdata->dock_connect_irq))) |
| 909 | msm_ehci_vbus_power(mhcd, 1); |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 910 | |
| 911 | device_init_wakeup(&pdev->dev, 1); |
| 912 | wake_lock_init(&mhcd->wlock, WAKE_LOCK_SUSPEND, dev_name(&pdev->dev)); |
| 913 | wake_lock(&mhcd->wlock); |
| 914 | /* |
| 915 | * This pdev->dev is assigned parent of root-hub by USB core, |
| 916 | * hence, runtime framework automatically calls this driver's |
| 917 | * runtime APIs based on root-hub's state. |
| 918 | */ |
| 919 | pm_runtime_set_active(&pdev->dev); |
| 920 | pm_runtime_enable(&pdev->dev); |
| 921 | |
| 922 | return 0; |
| 923 | |
| 924 | vbus_deinit: |
| 925 | msm_ehci_init_vbus(mhcd, 0); |
| 926 | disable_ldo: |
| 927 | msm_ehci_ldo_enable(mhcd, 0); |
| 928 | deinit_ldo: |
| 929 | msm_ehci_ldo_init(mhcd, 0); |
| 930 | deinit_vddcx: |
| 931 | msm_ehci_init_vddcx(mhcd, 0); |
| 932 | deinit_clocks: |
| 933 | msm_ehci_init_clocks(mhcd, 0); |
| 934 | unmap: |
| 935 | iounmap(hcd->regs); |
| 936 | put_hcd: |
| 937 | usb_put_hcd(hcd); |
| 938 | |
| 939 | return ret; |
| 940 | } |
| 941 | |
| 942 | static int __devexit ehci_msm2_remove(struct platform_device *pdev) |
| 943 | { |
| 944 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 945 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 946 | |
| 947 | device_init_wakeup(&pdev->dev, 0); |
| 948 | pm_runtime_disable(&pdev->dev); |
| 949 | pm_runtime_set_suspended(&pdev->dev); |
| 950 | |
| 951 | usb_remove_hcd(hcd); |
Hemant Kumar | 5692535 | 2012-02-13 16:59:52 -0800 | [diff] [blame] | 952 | |
Manu Gautam | 91223e0 | 2011-11-08 15:27:22 +0530 | [diff] [blame] | 953 | msm_ehci_vbus_power(mhcd, 0); |
| 954 | msm_ehci_init_vbus(mhcd, 0); |
| 955 | msm_ehci_ldo_enable(mhcd, 0); |
| 956 | msm_ehci_ldo_init(mhcd, 0); |
| 957 | msm_ehci_init_vddcx(mhcd, 0); |
| 958 | |
| 959 | msm_ehci_init_clocks(mhcd, 0); |
| 960 | wake_lock_destroy(&mhcd->wlock); |
| 961 | iounmap(hcd->regs); |
| 962 | usb_put_hcd(hcd); |
| 963 | |
| 964 | return 0; |
| 965 | } |
| 966 | |
| 967 | #ifdef CONFIG_PM_SLEEP |
| 968 | static int ehci_msm2_pm_suspend(struct device *dev) |
| 969 | { |
| 970 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 971 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 972 | |
| 973 | dev_dbg(dev, "ehci-msm2 PM suspend\n"); |
| 974 | |
| 975 | if (device_may_wakeup(dev)) |
| 976 | enable_irq_wake(hcd->irq); |
| 977 | |
| 978 | return msm_ehci_suspend(mhcd); |
| 979 | |
| 980 | } |
| 981 | |
| 982 | static int ehci_msm2_pm_resume(struct device *dev) |
| 983 | { |
| 984 | int ret; |
| 985 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 986 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 987 | |
| 988 | dev_dbg(dev, "ehci-msm2 PM resume\n"); |
| 989 | |
| 990 | if (device_may_wakeup(dev)) |
| 991 | disable_irq_wake(hcd->irq); |
| 992 | |
| 993 | ret = msm_ehci_resume(mhcd); |
| 994 | if (ret) |
| 995 | return ret; |
| 996 | |
| 997 | /* Bring the device to full powered state upon system resume */ |
| 998 | pm_runtime_disable(dev); |
| 999 | pm_runtime_set_active(dev); |
| 1000 | pm_runtime_enable(dev); |
| 1001 | |
| 1002 | return 0; |
| 1003 | } |
| 1004 | #endif |
| 1005 | |
| 1006 | #ifdef CONFIG_PM_RUNTIME |
| 1007 | static int ehci_msm2_runtime_idle(struct device *dev) |
| 1008 | { |
| 1009 | dev_dbg(dev, "EHCI runtime idle\n"); |
| 1010 | |
| 1011 | return 0; |
| 1012 | } |
| 1013 | |
| 1014 | static int ehci_msm2_runtime_suspend(struct device *dev) |
| 1015 | { |
| 1016 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1017 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 1018 | |
| 1019 | dev_dbg(dev, "EHCI runtime suspend\n"); |
| 1020 | return msm_ehci_suspend(mhcd); |
| 1021 | } |
| 1022 | |
| 1023 | static int ehci_msm2_runtime_resume(struct device *dev) |
| 1024 | { |
| 1025 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1026 | struct msm_hcd *mhcd = hcd_to_mhcd(hcd); |
| 1027 | |
| 1028 | dev_dbg(dev, "EHCI runtime resume\n"); |
| 1029 | return msm_ehci_resume(mhcd); |
| 1030 | } |
| 1031 | #endif |
| 1032 | |
| 1033 | #ifdef CONFIG_PM |
| 1034 | static const struct dev_pm_ops ehci_msm2_dev_pm_ops = { |
| 1035 | SET_SYSTEM_SLEEP_PM_OPS(ehci_msm2_pm_suspend, ehci_msm2_pm_resume) |
| 1036 | SET_RUNTIME_PM_OPS(ehci_msm2_runtime_suspend, ehci_msm2_runtime_resume, |
| 1037 | ehci_msm2_runtime_idle) |
| 1038 | }; |
| 1039 | #endif |
| 1040 | |
| 1041 | static struct platform_driver ehci_msm2_driver = { |
| 1042 | .probe = ehci_msm2_probe, |
| 1043 | .remove = __devexit_p(ehci_msm2_remove), |
| 1044 | .driver = { |
| 1045 | .name = "msm_ehci_host", |
| 1046 | #ifdef CONFIG_PM |
| 1047 | .pm = &ehci_msm2_dev_pm_ops, |
| 1048 | #endif |
| 1049 | }, |
| 1050 | }; |