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