Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/device.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/clk.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/interrupt.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/delay.h> |
| 22 | #include <linux/io.h> |
| 23 | #include <linux/ioport.h> |
| 24 | #include <linux/uaccess.h> |
| 25 | #include <linux/debugfs.h> |
| 26 | #include <linux/seq_file.h> |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 27 | #include <linux/pm_runtime.h> |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame^] | 28 | #include <linux/of.h> |
| 29 | #include <linux/dma-mapping.h> |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 30 | |
| 31 | #include <linux/usb.h> |
| 32 | #include <linux/usb/otg.h> |
| 33 | #include <linux/usb/ulpi.h> |
| 34 | #include <linux/usb/gadget.h> |
| 35 | #include <linux/usb/hcd.h> |
| 36 | #include <linux/usb/msm_hsusb.h> |
| 37 | #include <linux/usb/msm_hsusb_hw.h> |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 38 | #include <linux/regulator/consumer.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 39 | #include <linux/mfd/pm8xxx/pm8921-charger.h> |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 40 | |
| 41 | #include <mach/clk.h> |
| 42 | |
| 43 | #define MSM_USB_BASE (motg->regs) |
| 44 | #define DRIVER_NAME "msm_otg" |
| 45 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 46 | #define ID_TIMER_FREQ (jiffies + msecs_to_jiffies(2000)) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 47 | #define ULPI_IO_TIMEOUT_USEC (10 * 1000) |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 48 | |
| 49 | #define USB_PHY_3P3_VOL_MIN 3050000 /* uV */ |
| 50 | #define USB_PHY_3P3_VOL_MAX 3300000 /* uV */ |
| 51 | #define USB_PHY_3P3_HPM_LOAD 50000 /* uA */ |
| 52 | #define USB_PHY_3P3_LPM_LOAD 4000 /* uA */ |
| 53 | |
| 54 | #define USB_PHY_1P8_VOL_MIN 1800000 /* uV */ |
| 55 | #define USB_PHY_1P8_VOL_MAX 1800000 /* uV */ |
| 56 | #define USB_PHY_1P8_HPM_LOAD 50000 /* uA */ |
| 57 | #define USB_PHY_1P8_LPM_LOAD 4000 /* uA */ |
| 58 | |
Vamsi Krishna | 132b276 | 2011-11-11 16:09:20 -0800 | [diff] [blame] | 59 | #define USB_PHY_VDD_DIG_VOL_MIN 1045000 /* uV */ |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 60 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
| 61 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 62 | static struct msm_otg *the_msm_otg; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 63 | static bool debug_aca_enabled; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 65 | static struct regulator *hsusb_3p3; |
| 66 | static struct regulator *hsusb_1p8; |
| 67 | static struct regulator *hsusb_vddcx; |
| 68 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 69 | static inline bool aca_enabled(void) |
| 70 | { |
| 71 | #ifdef CONFIG_USB_MSM_ACA |
| 72 | return true; |
| 73 | #else |
| 74 | return debug_aca_enabled; |
| 75 | #endif |
| 76 | } |
| 77 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 78 | static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init) |
| 79 | { |
| 80 | int ret = 0; |
| 81 | |
| 82 | if (init) { |
| 83 | hsusb_vddcx = regulator_get(motg->otg.dev, "HSUSB_VDDCX"); |
| 84 | if (IS_ERR(hsusb_vddcx)) { |
| 85 | dev_err(motg->otg.dev, "unable to get hsusb vddcx\n"); |
| 86 | return PTR_ERR(hsusb_vddcx); |
| 87 | } |
| 88 | |
| 89 | ret = regulator_set_voltage(hsusb_vddcx, |
| 90 | USB_PHY_VDD_DIG_VOL_MIN, |
| 91 | USB_PHY_VDD_DIG_VOL_MAX); |
| 92 | if (ret) { |
| 93 | dev_err(motg->otg.dev, "unable to set the voltage " |
| 94 | "for hsusb vddcx\n"); |
| 95 | regulator_put(hsusb_vddcx); |
| 96 | return ret; |
| 97 | } |
| 98 | |
| 99 | ret = regulator_enable(hsusb_vddcx); |
| 100 | if (ret) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 101 | regulator_set_voltage(hsusb_vddcx, 0, |
| 102 | USB_PHY_VDD_DIG_VOL_MIN); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 103 | regulator_put(hsusb_vddcx); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 104 | dev_err(motg->otg.dev, "unable to enable the hsusb vddcx\n"); |
| 105 | return ret; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 106 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 107 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 108 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 109 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 110 | ret = regulator_disable(hsusb_vddcx); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 111 | if (ret) { |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 112 | dev_err(motg->otg.dev, "unable to disable hsusb vddcx\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 113 | return ret; |
| 114 | } |
| 115 | |
| 116 | ret = regulator_set_voltage(hsusb_vddcx, 0, |
| 117 | USB_PHY_VDD_DIG_VOL_MIN); |
| 118 | if (ret) { |
| 119 | dev_err(motg->otg.dev, "unable to set the voltage" |
| 120 | "for hsusb vddcx\n"); |
| 121 | return ret; |
| 122 | } |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 123 | |
| 124 | regulator_put(hsusb_vddcx); |
| 125 | } |
| 126 | |
| 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | static int msm_hsusb_ldo_init(struct msm_otg *motg, int init) |
| 131 | { |
| 132 | int rc = 0; |
| 133 | |
| 134 | if (init) { |
| 135 | hsusb_3p3 = regulator_get(motg->otg.dev, "HSUSB_3p3"); |
| 136 | if (IS_ERR(hsusb_3p3)) { |
| 137 | dev_err(motg->otg.dev, "unable to get hsusb 3p3\n"); |
| 138 | return PTR_ERR(hsusb_3p3); |
| 139 | } |
| 140 | |
| 141 | rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN, |
| 142 | USB_PHY_3P3_VOL_MAX); |
| 143 | if (rc) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 144 | dev_err(motg->otg.dev, "unable to set voltage level for" |
| 145 | "hsusb 3p3\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 146 | goto put_3p3; |
| 147 | } |
| 148 | hsusb_1p8 = regulator_get(motg->otg.dev, "HSUSB_1p8"); |
| 149 | if (IS_ERR(hsusb_1p8)) { |
| 150 | dev_err(motg->otg.dev, "unable to get hsusb 1p8\n"); |
| 151 | rc = PTR_ERR(hsusb_1p8); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 152 | goto put_3p3_lpm; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 153 | } |
| 154 | rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN, |
| 155 | USB_PHY_1P8_VOL_MAX); |
| 156 | if (rc) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 157 | dev_err(motg->otg.dev, "unable to set voltage level for" |
| 158 | "hsusb 1p8\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 159 | goto put_1p8; |
| 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 165 | put_1p8: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 166 | regulator_set_voltage(hsusb_1p8, 0, USB_PHY_1P8_VOL_MAX); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 167 | regulator_put(hsusb_1p8); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 168 | put_3p3_lpm: |
| 169 | regulator_set_voltage(hsusb_3p3, 0, USB_PHY_3P3_VOL_MAX); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 170 | put_3p3: |
| 171 | regulator_put(hsusb_3p3); |
| 172 | return rc; |
| 173 | } |
| 174 | |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 175 | #ifdef CONFIG_PM_SLEEP |
| 176 | #define USB_PHY_SUSP_DIG_VOL 500000 |
| 177 | static int msm_hsusb_config_vddcx(int high) |
| 178 | { |
| 179 | int max_vol = USB_PHY_VDD_DIG_VOL_MAX; |
| 180 | int min_vol; |
| 181 | int ret; |
| 182 | |
| 183 | if (high) |
| 184 | min_vol = USB_PHY_VDD_DIG_VOL_MIN; |
| 185 | else |
| 186 | min_vol = USB_PHY_SUSP_DIG_VOL; |
| 187 | |
| 188 | ret = regulator_set_voltage(hsusb_vddcx, min_vol, max_vol); |
| 189 | if (ret) { |
| 190 | pr_err("%s: unable to set the voltage for regulator " |
| 191 | "HSUSB_VDDCX\n", __func__); |
| 192 | return ret; |
| 193 | } |
| 194 | |
| 195 | pr_debug("%s: min_vol:%d max_vol:%d\n", __func__, min_vol, max_vol); |
| 196 | |
| 197 | return ret; |
| 198 | } |
Hemant Kumar | 8e7bd07 | 2011-08-01 14:14:24 -0700 | [diff] [blame] | 199 | #else |
| 200 | static int msm_hsusb_config_vddcx(int high) |
| 201 | { |
| 202 | return 0; |
| 203 | } |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 204 | #endif |
| 205 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 206 | static int msm_hsusb_ldo_enable(struct msm_otg *motg, int on) |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 207 | { |
| 208 | int ret = 0; |
| 209 | |
Pavankumar Kondeti | 68964c9 | 2011-10-27 14:58:56 +0530 | [diff] [blame] | 210 | if (IS_ERR(hsusb_1p8)) { |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 211 | pr_err("%s: HSUSB_1p8 is not initialized\n", __func__); |
| 212 | return -ENODEV; |
| 213 | } |
| 214 | |
Pavankumar Kondeti | 68964c9 | 2011-10-27 14:58:56 +0530 | [diff] [blame] | 215 | if (IS_ERR(hsusb_3p3)) { |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 216 | pr_err("%s: HSUSB_3p3 is not initialized\n", __func__); |
| 217 | return -ENODEV; |
| 218 | } |
| 219 | |
| 220 | if (on) { |
| 221 | ret = regulator_set_optimum_mode(hsusb_1p8, |
| 222 | USB_PHY_1P8_HPM_LOAD); |
| 223 | if (ret < 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 224 | pr_err("%s: Unable to set HPM of the regulator:" |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 225 | "HSUSB_1p8\n", __func__); |
| 226 | return ret; |
| 227 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 228 | |
| 229 | ret = regulator_enable(hsusb_1p8); |
| 230 | if (ret) { |
| 231 | dev_err(motg->otg.dev, "%s: unable to enable the hsusb 1p8\n", |
| 232 | __func__); |
| 233 | regulator_set_optimum_mode(hsusb_1p8, 0); |
| 234 | return ret; |
| 235 | } |
| 236 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 237 | ret = regulator_set_optimum_mode(hsusb_3p3, |
| 238 | USB_PHY_3P3_HPM_LOAD); |
| 239 | if (ret < 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 240 | pr_err("%s: Unable to set HPM of the regulator:" |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 241 | "HSUSB_3p3\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 242 | regulator_set_optimum_mode(hsusb_1p8, 0); |
| 243 | regulator_disable(hsusb_1p8); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 244 | return ret; |
| 245 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 246 | |
| 247 | ret = regulator_enable(hsusb_3p3); |
| 248 | if (ret) { |
| 249 | dev_err(motg->otg.dev, "%s: unable to enable the hsusb 3p3\n", |
| 250 | __func__); |
| 251 | regulator_set_optimum_mode(hsusb_3p3, 0); |
| 252 | regulator_set_optimum_mode(hsusb_1p8, 0); |
| 253 | regulator_disable(hsusb_1p8); |
| 254 | return ret; |
| 255 | } |
| 256 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 257 | } else { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 258 | ret = regulator_disable(hsusb_1p8); |
| 259 | if (ret) { |
| 260 | dev_err(motg->otg.dev, "%s: unable to disable the hsusb 1p8\n", |
| 261 | __func__); |
| 262 | return ret; |
| 263 | } |
| 264 | |
| 265 | ret = regulator_set_optimum_mode(hsusb_1p8, 0); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 266 | if (ret < 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 267 | pr_err("%s: Unable to set LPM of the regulator:" |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 268 | "HSUSB_1p8\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 269 | |
| 270 | ret = regulator_disable(hsusb_3p3); |
| 271 | if (ret) { |
| 272 | dev_err(motg->otg.dev, "%s: unable to disable the hsusb 3p3\n", |
| 273 | __func__); |
| 274 | return ret; |
| 275 | } |
| 276 | ret = regulator_set_optimum_mode(hsusb_3p3, 0); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 277 | if (ret < 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 278 | pr_err("%s: Unable to set LPM of the regulator:" |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 279 | "HSUSB_3p3\n", __func__); |
| 280 | } |
| 281 | |
| 282 | pr_debug("reg (%s)\n", on ? "HPM" : "LPM"); |
| 283 | return ret < 0 ? ret : 0; |
| 284 | } |
| 285 | |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 286 | static void msm_hsusb_mhl_switch_enable(struct msm_otg *motg, bool on) |
| 287 | { |
| 288 | static struct regulator *mhl_analog_switch; |
| 289 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 290 | |
| 291 | if (!pdata->mhl_enable) |
| 292 | return; |
| 293 | |
| 294 | if (on) { |
| 295 | mhl_analog_switch = regulator_get(motg->otg.dev, |
| 296 | "mhl_ext_3p3v"); |
| 297 | if (IS_ERR(mhl_analog_switch)) { |
| 298 | pr_err("Unable to get mhl_analog_switch\n"); |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | if (regulator_enable(mhl_analog_switch)) { |
| 303 | pr_err("unable to enable mhl_analog_switch\n"); |
| 304 | goto put_analog_switch; |
| 305 | } |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | regulator_disable(mhl_analog_switch); |
| 310 | put_analog_switch: |
| 311 | regulator_put(mhl_analog_switch); |
| 312 | } |
| 313 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 314 | static int ulpi_read(struct otg_transceiver *otg, u32 reg) |
| 315 | { |
| 316 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); |
| 317 | int cnt = 0; |
| 318 | |
| 319 | /* initiate read operation */ |
| 320 | writel(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg), |
| 321 | USB_ULPI_VIEWPORT); |
| 322 | |
| 323 | /* wait for completion */ |
| 324 | while (cnt < ULPI_IO_TIMEOUT_USEC) { |
| 325 | if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN)) |
| 326 | break; |
| 327 | udelay(1); |
| 328 | cnt++; |
| 329 | } |
| 330 | |
| 331 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { |
| 332 | dev_err(otg->dev, "ulpi_read: timeout %08x\n", |
| 333 | readl(USB_ULPI_VIEWPORT)); |
| 334 | return -ETIMEDOUT; |
| 335 | } |
| 336 | return ULPI_DATA_READ(readl(USB_ULPI_VIEWPORT)); |
| 337 | } |
| 338 | |
| 339 | static int ulpi_write(struct otg_transceiver *otg, u32 val, u32 reg) |
| 340 | { |
| 341 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); |
| 342 | int cnt = 0; |
| 343 | |
| 344 | /* initiate write operation */ |
| 345 | writel(ULPI_RUN | ULPI_WRITE | |
| 346 | ULPI_ADDR(reg) | ULPI_DATA(val), |
| 347 | USB_ULPI_VIEWPORT); |
| 348 | |
| 349 | /* wait for completion */ |
| 350 | while (cnt < ULPI_IO_TIMEOUT_USEC) { |
| 351 | if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN)) |
| 352 | break; |
| 353 | udelay(1); |
| 354 | cnt++; |
| 355 | } |
| 356 | |
| 357 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { |
| 358 | dev_err(otg->dev, "ulpi_write: timeout\n"); |
| 359 | return -ETIMEDOUT; |
| 360 | } |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static struct otg_io_access_ops msm_otg_io_ops = { |
| 365 | .read = ulpi_read, |
| 366 | .write = ulpi_write, |
| 367 | }; |
| 368 | |
| 369 | static void ulpi_init(struct msm_otg *motg) |
| 370 | { |
| 371 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 372 | int *seq = pdata->phy_init_seq; |
| 373 | |
| 374 | if (!seq) |
| 375 | return; |
| 376 | |
| 377 | while (seq[0] >= 0) { |
| 378 | dev_vdbg(motg->otg.dev, "ulpi: write 0x%02x to 0x%02x\n", |
| 379 | seq[0], seq[1]); |
| 380 | ulpi_write(&motg->otg, seq[0], seq[1]); |
| 381 | seq += 2; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) |
| 386 | { |
| 387 | int ret; |
| 388 | |
| 389 | if (assert) { |
| 390 | ret = clk_reset(motg->clk, CLK_RESET_ASSERT); |
| 391 | if (ret) |
| 392 | dev_err(motg->otg.dev, "usb hs_clk assert failed\n"); |
| 393 | } else { |
| 394 | ret = clk_reset(motg->clk, CLK_RESET_DEASSERT); |
| 395 | if (ret) |
| 396 | dev_err(motg->otg.dev, "usb hs_clk deassert failed\n"); |
| 397 | } |
| 398 | return ret; |
| 399 | } |
| 400 | |
| 401 | static int msm_otg_phy_clk_reset(struct msm_otg *motg) |
| 402 | { |
| 403 | int ret; |
| 404 | |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 405 | if (IS_ERR(motg->phy_reset_clk)) |
| 406 | return 0; |
| 407 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 408 | ret = clk_reset(motg->phy_reset_clk, CLK_RESET_ASSERT); |
| 409 | if (ret) { |
| 410 | dev_err(motg->otg.dev, "usb phy clk assert failed\n"); |
| 411 | return ret; |
| 412 | } |
| 413 | usleep_range(10000, 12000); |
| 414 | ret = clk_reset(motg->phy_reset_clk, CLK_RESET_DEASSERT); |
| 415 | if (ret) |
| 416 | dev_err(motg->otg.dev, "usb phy clk deassert failed\n"); |
| 417 | return ret; |
| 418 | } |
| 419 | |
| 420 | static int msm_otg_phy_reset(struct msm_otg *motg) |
| 421 | { |
| 422 | u32 val; |
| 423 | int ret; |
| 424 | int retries; |
| 425 | |
| 426 | ret = msm_otg_link_clk_reset(motg, 1); |
| 427 | if (ret) |
| 428 | return ret; |
| 429 | ret = msm_otg_phy_clk_reset(motg); |
| 430 | if (ret) |
| 431 | return ret; |
| 432 | ret = msm_otg_link_clk_reset(motg, 0); |
| 433 | if (ret) |
| 434 | return ret; |
| 435 | |
| 436 | val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK; |
| 437 | writel(val | PORTSC_PTS_ULPI, USB_PORTSC); |
| 438 | |
| 439 | for (retries = 3; retries > 0; retries--) { |
| 440 | ret = ulpi_write(&motg->otg, ULPI_FUNC_CTRL_SUSPENDM, |
| 441 | ULPI_CLR(ULPI_FUNC_CTRL)); |
| 442 | if (!ret) |
| 443 | break; |
| 444 | ret = msm_otg_phy_clk_reset(motg); |
| 445 | if (ret) |
| 446 | return ret; |
| 447 | } |
| 448 | if (!retries) |
| 449 | return -ETIMEDOUT; |
| 450 | |
| 451 | /* This reset calibrates the phy, if the above write succeeded */ |
| 452 | ret = msm_otg_phy_clk_reset(motg); |
| 453 | if (ret) |
| 454 | return ret; |
| 455 | |
| 456 | for (retries = 3; retries > 0; retries--) { |
| 457 | ret = ulpi_read(&motg->otg, ULPI_DEBUG); |
| 458 | if (ret != -ETIMEDOUT) |
| 459 | break; |
| 460 | ret = msm_otg_phy_clk_reset(motg); |
| 461 | if (ret) |
| 462 | return ret; |
| 463 | } |
| 464 | if (!retries) |
| 465 | return -ETIMEDOUT; |
| 466 | |
| 467 | dev_info(motg->otg.dev, "phy_reset: success\n"); |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 472 | static int msm_otg_link_reset(struct msm_otg *motg) |
| 473 | { |
| 474 | int cnt = 0; |
| 475 | |
| 476 | writel_relaxed(USBCMD_RESET, USB_USBCMD); |
| 477 | while (cnt < LINK_RESET_TIMEOUT_USEC) { |
| 478 | if (!(readl_relaxed(USB_USBCMD) & USBCMD_RESET)) |
| 479 | break; |
| 480 | udelay(1); |
| 481 | cnt++; |
| 482 | } |
| 483 | if (cnt >= LINK_RESET_TIMEOUT_USEC) |
| 484 | return -ETIMEDOUT; |
| 485 | |
| 486 | /* select ULPI phy */ |
| 487 | writel_relaxed(0x80000000, USB_PORTSC); |
| 488 | writel_relaxed(0x0, USB_AHBBURST); |
| 489 | writel_relaxed(0x00, USB_AHBMODE); |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 494 | static int msm_otg_reset(struct otg_transceiver *otg) |
| 495 | { |
| 496 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); |
| 497 | struct msm_otg_platform_data *pdata = motg->pdata; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 498 | int ret; |
| 499 | u32 val = 0; |
| 500 | u32 ulpi_val = 0; |
| 501 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 502 | clk_enable(motg->clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 503 | ret = msm_otg_phy_reset(motg); |
| 504 | if (ret) { |
| 505 | dev_err(otg->dev, "phy_reset failed\n"); |
| 506 | return ret; |
| 507 | } |
| 508 | |
| 509 | ulpi_init(motg); |
| 510 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 511 | ret = msm_otg_link_reset(motg); |
| 512 | if (ret) { |
| 513 | dev_err(otg->dev, "link reset failed\n"); |
| 514 | return ret; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 515 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 516 | msleep(100); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 517 | /* Ensure that RESET operation is completed before turning off clock */ |
| 518 | mb(); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 519 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 520 | clk_disable(motg->clk); |
| 521 | |
| 522 | val = readl_relaxed(USB_OTGSC); |
| 523 | if (pdata->mode == USB_OTG) { |
| 524 | ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID; |
| 525 | val |= OTGSC_IDIE | OTGSC_BSVIE; |
| 526 | } else if (pdata->mode == USB_PERIPHERAL) { |
| 527 | ulpi_val = ULPI_INT_SESS_VALID; |
| 528 | val |= OTGSC_BSVIE; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 529 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 530 | writel_relaxed(val, USB_OTGSC); |
| 531 | ulpi_write(otg, ulpi_val, ULPI_USB_INT_EN_RISE); |
| 532 | ulpi_write(otg, ulpi_val, ULPI_USB_INT_EN_FALL); |
| 533 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 534 | return 0; |
| 535 | } |
| 536 | |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 537 | static int msm_otg_set_suspend(struct otg_transceiver *otg, int suspend) |
| 538 | { |
| 539 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); |
| 540 | |
| 541 | /* |
| 542 | * Allow bus suspend only for host mode. Device mode bus suspend |
| 543 | * is not implemented yet. |
| 544 | */ |
| 545 | if (!test_bit(ID, &motg->inputs) || test_bit(ID_A, &motg->inputs)) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 546 | /* |
| 547 | * ID_GND --> ID_A transition can not be detected in LPM. |
| 548 | * Disallow host bus suspend when ACA is enabled. |
| 549 | */ |
| 550 | if (suspend && !aca_enabled()) |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 551 | pm_runtime_put(otg->dev); |
| 552 | else |
| 553 | pm_runtime_resume(otg->dev); |
| 554 | } |
| 555 | |
| 556 | return 0; |
| 557 | } |
| 558 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 559 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 560 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) |
| 561 | |
| 562 | #ifdef CONFIG_PM_SLEEP |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 563 | static int msm_otg_suspend(struct msm_otg *motg) |
| 564 | { |
| 565 | struct otg_transceiver *otg = &motg->otg; |
| 566 | struct usb_bus *bus = otg->host; |
| 567 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 568 | int cnt = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 569 | bool session_active; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 570 | |
| 571 | if (atomic_read(&motg->in_lpm)) |
| 572 | return 0; |
| 573 | |
| 574 | disable_irq(motg->irq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 575 | session_active = (otg->host && !test_bit(ID, &motg->inputs)) || |
| 576 | test_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 577 | /* |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 578 | * Chipidea 45-nm PHY suspend sequence: |
| 579 | * |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 580 | * Interrupt Latch Register auto-clear feature is not present |
| 581 | * in all PHY versions. Latch register is clear on read type. |
| 582 | * Clear latch register to avoid spurious wakeup from |
| 583 | * low power mode (LPM). |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 584 | * |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 585 | * PHY comparators are disabled when PHY enters into low power |
| 586 | * mode (LPM). Keep PHY comparators ON in LPM only when we expect |
| 587 | * VBUS/Id notifications from USB PHY. Otherwise turn off USB |
| 588 | * PHY comparators. This save significant amount of power. |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 589 | * |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 590 | * PLL is not turned off when PHY enters into low power mode (LPM). |
| 591 | * Disable PLL for maximum power savings. |
| 592 | */ |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 593 | |
| 594 | if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) { |
| 595 | ulpi_read(otg, 0x14); |
| 596 | if (pdata->otg_control == OTG_PHY_CONTROL) |
| 597 | ulpi_write(otg, 0x01, 0x30); |
| 598 | ulpi_write(otg, 0x08, 0x09); |
| 599 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 600 | |
| 601 | /* |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 602 | * Turn off the OTG comparators, if depends on PMIC for |
| 603 | * VBUS and ID notifications. |
| 604 | */ |
| 605 | if ((motg->caps & ALLOW_PHY_COMP_DISABLE) && !session_active) { |
| 606 | ulpi_write(otg, OTG_COMP_DISABLE, |
| 607 | ULPI_SET(ULPI_PWR_CLK_MNG_REG)); |
| 608 | motg->lpm_flags |= PHY_OTG_COMP_DISABLED; |
| 609 | } |
| 610 | |
| 611 | /* |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 612 | * PHY may take some time or even fail to enter into low power |
| 613 | * mode (LPM). Hence poll for 500 msec and reset the PHY and link |
| 614 | * in failure case. |
| 615 | */ |
| 616 | writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC); |
| 617 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 618 | if (readl(USB_PORTSC) & PORTSC_PHCD) |
| 619 | break; |
| 620 | udelay(1); |
| 621 | cnt++; |
| 622 | } |
| 623 | |
| 624 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) { |
| 625 | dev_err(otg->dev, "Unable to suspend PHY\n"); |
| 626 | msm_otg_reset(otg); |
| 627 | enable_irq(motg->irq); |
| 628 | return -ETIMEDOUT; |
| 629 | } |
| 630 | |
| 631 | /* |
| 632 | * PHY has capability to generate interrupt asynchronously in low |
| 633 | * power mode (LPM). This interrupt is level triggered. So USB IRQ |
| 634 | * line must be disabled till async interrupt enable bit is cleared |
| 635 | * in USBCMD register. Assert STP (ULPI interface STOP signal) to |
| 636 | * block data communication from PHY. |
| 637 | */ |
| 638 | writel(readl(USB_USBCMD) | ASYNC_INTR_CTRL | ULPI_STP_CTRL, USB_USBCMD); |
| 639 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 640 | if (motg->caps & ALLOW_PHY_RETENTION && !session_active) { |
| 641 | writel_relaxed(readl_relaxed(USB_PHY_CTRL) & ~PHY_RETEN, |
| 642 | USB_PHY_CTRL); |
| 643 | motg->lpm_flags |= PHY_RETENTIONED; |
| 644 | } |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 645 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 646 | /* Ensure that above operation is completed before turning off clocks */ |
| 647 | mb(); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 648 | clk_disable(motg->pclk); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 649 | if (motg->core_clk) |
| 650 | clk_disable(motg->core_clk); |
| 651 | |
Amit Blay | 137575f | 2011-11-06 15:20:54 +0200 | [diff] [blame] | 652 | if (!IS_ERR(motg->system_clk)) |
| 653 | clk_disable(motg->system_clk); |
| 654 | |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 655 | if (!IS_ERR(motg->pclk_src)) |
| 656 | clk_disable(motg->pclk_src); |
| 657 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 658 | if (motg->caps & ALLOW_PHY_POWER_COLLAPSE && !session_active) { |
| 659 | msm_hsusb_ldo_enable(motg, 0); |
| 660 | motg->lpm_flags |= PHY_PWR_COLLAPSED; |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 661 | } |
| 662 | |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 663 | if (motg->lpm_flags & PHY_RETENTIONED) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 664 | msm_hsusb_config_vddcx(0); |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 665 | msm_hsusb_mhl_switch_enable(motg, 0); |
| 666 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 667 | |
| 668 | if (device_may_wakeup(otg->dev)) { |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 669 | enable_irq_wake(motg->irq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 670 | if (motg->pdata->pmic_id_irq) |
| 671 | enable_irq_wake(motg->pdata->pmic_id_irq); |
| 672 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 673 | if (bus) |
| 674 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags); |
| 675 | |
| 676 | atomic_set(&motg->in_lpm, 1); |
| 677 | enable_irq(motg->irq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 678 | wake_unlock(&motg->wlock); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 679 | |
| 680 | dev_info(otg->dev, "USB in low power mode\n"); |
| 681 | |
| 682 | return 0; |
| 683 | } |
| 684 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 685 | static int msm_otg_resume(struct msm_otg *motg) |
| 686 | { |
| 687 | struct otg_transceiver *otg = &motg->otg; |
| 688 | struct usb_bus *bus = otg->host; |
| 689 | int cnt = 0; |
| 690 | unsigned temp; |
| 691 | |
| 692 | if (!atomic_read(&motg->in_lpm)) |
| 693 | return 0; |
| 694 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 695 | wake_lock(&motg->wlock); |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 696 | if (!IS_ERR(motg->pclk_src)) |
| 697 | clk_enable(motg->pclk_src); |
| 698 | |
Amit Blay | 137575f | 2011-11-06 15:20:54 +0200 | [diff] [blame] | 699 | if (!IS_ERR(motg->system_clk)) |
| 700 | clk_enable(motg->system_clk); |
| 701 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 702 | clk_enable(motg->pclk); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 703 | if (motg->core_clk) |
| 704 | clk_enable(motg->core_clk); |
| 705 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 706 | if (motg->lpm_flags & PHY_PWR_COLLAPSED) { |
| 707 | msm_hsusb_ldo_enable(motg, 1); |
| 708 | motg->lpm_flags &= ~PHY_PWR_COLLAPSED; |
| 709 | } |
| 710 | |
| 711 | if (motg->lpm_flags & PHY_RETENTIONED) { |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 712 | msm_hsusb_mhl_switch_enable(motg, 1); |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 713 | msm_hsusb_config_vddcx(1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 714 | writel_relaxed(readl_relaxed(USB_PHY_CTRL) | PHY_RETEN, |
| 715 | USB_PHY_CTRL); |
| 716 | motg->lpm_flags &= ~PHY_RETENTIONED; |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 717 | } |
| 718 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 719 | temp = readl(USB_USBCMD); |
| 720 | temp &= ~ASYNC_INTR_CTRL; |
| 721 | temp &= ~ULPI_STP_CTRL; |
| 722 | writel(temp, USB_USBCMD); |
| 723 | |
| 724 | /* |
| 725 | * PHY comes out of low power mode (LPM) in case of wakeup |
| 726 | * from asynchronous interrupt. |
| 727 | */ |
| 728 | if (!(readl(USB_PORTSC) & PORTSC_PHCD)) |
| 729 | goto skip_phy_resume; |
| 730 | |
| 731 | writel(readl(USB_PORTSC) & ~PORTSC_PHCD, USB_PORTSC); |
| 732 | while (cnt < PHY_RESUME_TIMEOUT_USEC) { |
| 733 | if (!(readl(USB_PORTSC) & PORTSC_PHCD)) |
| 734 | break; |
| 735 | udelay(1); |
| 736 | cnt++; |
| 737 | } |
| 738 | |
| 739 | if (cnt >= PHY_RESUME_TIMEOUT_USEC) { |
| 740 | /* |
| 741 | * This is a fatal error. Reset the link and |
| 742 | * PHY. USB state can not be restored. Re-insertion |
| 743 | * of USB cable is the only way to get USB working. |
| 744 | */ |
| 745 | dev_err(otg->dev, "Unable to resume USB." |
| 746 | "Re-plugin the cable\n"); |
| 747 | msm_otg_reset(otg); |
| 748 | } |
| 749 | |
| 750 | skip_phy_resume: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 751 | /* Turn on the OTG comparators on resume */ |
| 752 | if (motg->lpm_flags & PHY_OTG_COMP_DISABLED) { |
| 753 | ulpi_write(otg, OTG_COMP_DISABLE, |
| 754 | ULPI_CLR(ULPI_PWR_CLK_MNG_REG)); |
| 755 | motg->lpm_flags &= ~PHY_OTG_COMP_DISABLED; |
| 756 | } |
| 757 | if (device_may_wakeup(otg->dev)) { |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 758 | disable_irq_wake(motg->irq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 759 | if (motg->pdata->pmic_id_irq) |
| 760 | disable_irq_wake(motg->pdata->pmic_id_irq); |
| 761 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 762 | if (bus) |
| 763 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags); |
| 764 | |
Pavankumar Kondeti | 2ce2c3a | 2011-05-02 11:56:33 +0530 | [diff] [blame] | 765 | atomic_set(&motg->in_lpm, 0); |
| 766 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 767 | if (aca_enabled() && !irq_read_line(motg->pdata->pmic_id_irq)) { |
| 768 | clear_bit(ID, &motg->inputs); |
| 769 | schedule_work(&motg->sm_work); |
| 770 | } |
| 771 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 772 | if (motg->async_int) { |
| 773 | motg->async_int = 0; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 774 | enable_irq(motg->irq); |
| 775 | } |
| 776 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 777 | dev_info(otg->dev, "USB exited from low power mode\n"); |
| 778 | |
| 779 | return 0; |
| 780 | } |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 781 | #endif |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 782 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 783 | static void msm_otg_notify_charger(struct msm_otg *motg, unsigned mA) |
| 784 | { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 785 | if ((motg->chg_type == USB_ACA_DOCK_CHARGER || |
| 786 | motg->chg_type == USB_ACA_A_CHARGER || |
| 787 | motg->chg_type == USB_ACA_B_CHARGER || |
| 788 | motg->chg_type == USB_ACA_C_CHARGER) && |
| 789 | mA > IDEV_ACA_CHG_LIMIT) |
| 790 | mA = IDEV_ACA_CHG_LIMIT; |
| 791 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 792 | if (motg->cur_power == mA) |
| 793 | return; |
| 794 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 795 | dev_info(motg->otg.dev, "Avail curr from USB = %u\n", mA); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 796 | pm8921_charger_vbus_draw(mA); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 797 | motg->cur_power = mA; |
| 798 | } |
| 799 | |
| 800 | static int msm_otg_set_power(struct otg_transceiver *otg, unsigned mA) |
| 801 | { |
| 802 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); |
| 803 | |
| 804 | /* |
| 805 | * Gadget driver uses set_power method to notify about the |
| 806 | * available current based on suspend/configured states. |
| 807 | * |
| 808 | * IDEV_CHG can be drawn irrespective of suspend/un-configured |
| 809 | * states when CDP/ACA is connected. |
| 810 | */ |
| 811 | if (motg->chg_type == USB_SDP_CHARGER) |
| 812 | msm_otg_notify_charger(motg, mA); |
| 813 | |
| 814 | return 0; |
| 815 | } |
| 816 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 817 | static void msm_otg_start_host(struct otg_transceiver *otg, int on) |
| 818 | { |
| 819 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); |
| 820 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 821 | struct usb_hcd *hcd; |
| 822 | |
| 823 | if (!otg->host) |
| 824 | return; |
| 825 | |
| 826 | hcd = bus_to_hcd(otg->host); |
| 827 | |
| 828 | if (on) { |
| 829 | dev_dbg(otg->dev, "host on\n"); |
| 830 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 831 | /* |
| 832 | * Some boards have a switch cotrolled by gpio |
| 833 | * to enable/disable internal HUB. Enable internal |
| 834 | * HUB before kicking the host. |
| 835 | */ |
| 836 | if (pdata->setup_gpio) |
| 837 | pdata->setup_gpio(OTG_STATE_A_HOST); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 838 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 839 | } else { |
| 840 | dev_dbg(otg->dev, "host off\n"); |
| 841 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 842 | usb_remove_hcd(hcd); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 843 | /* HCD core reset all bits of PORTSC. select ULPI phy */ |
| 844 | writel_relaxed(0x80000000, USB_PORTSC); |
| 845 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 846 | if (pdata->setup_gpio) |
| 847 | pdata->setup_gpio(OTG_STATE_UNDEFINED); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 848 | } |
| 849 | } |
| 850 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 851 | static int msm_otg_usbdev_notify(struct notifier_block *self, |
| 852 | unsigned long action, void *priv) |
| 853 | { |
| 854 | struct msm_otg *motg = container_of(self, struct msm_otg, usbdev_nb); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 855 | struct usb_device *udev = priv; |
| 856 | |
| 857 | if (!aca_enabled()) |
| 858 | goto out; |
| 859 | |
| 860 | if (action == USB_BUS_ADD || action == USB_BUS_REMOVE) |
| 861 | goto out; |
| 862 | |
| 863 | if (udev->bus != motg->otg.host) |
| 864 | goto out; |
| 865 | /* |
| 866 | * Interested in devices connected directly to the root hub. |
| 867 | * ACA dock can supply IDEV_CHG irrespective devices connected |
| 868 | * on the accessory port. |
| 869 | */ |
| 870 | if (!udev->parent || udev->parent->parent || |
| 871 | motg->chg_type == USB_ACA_DOCK_CHARGER) |
| 872 | goto out; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 873 | |
| 874 | switch (action) { |
| 875 | case USB_DEVICE_ADD: |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 876 | usb_disable_autosuspend(udev); |
| 877 | /* fall through */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 878 | case USB_DEVICE_CONFIG: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 879 | if (udev->actconfig) |
| 880 | motg->mA_port = udev->actconfig->desc.bMaxPower * 2; |
| 881 | else |
| 882 | motg->mA_port = IUNIT; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 883 | break; |
| 884 | case USB_DEVICE_REMOVE: |
| 885 | motg->mA_port = IUNIT; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 886 | break; |
| 887 | default: |
| 888 | break; |
| 889 | } |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 890 | if (test_bit(ID_A, &motg->inputs)) |
| 891 | msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX - |
| 892 | motg->mA_port); |
| 893 | out: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 894 | return NOTIFY_OK; |
| 895 | } |
| 896 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 897 | static int msm_otg_set_host(struct otg_transceiver *otg, struct usb_bus *host) |
| 898 | { |
| 899 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); |
| 900 | struct usb_hcd *hcd; |
| 901 | |
| 902 | /* |
| 903 | * Fail host registration if this board can support |
| 904 | * only peripheral configuration. |
| 905 | */ |
| 906 | if (motg->pdata->mode == USB_PERIPHERAL) { |
| 907 | dev_info(otg->dev, "Host mode is not supported\n"); |
| 908 | return -ENODEV; |
| 909 | } |
| 910 | |
| 911 | if (!host) { |
| 912 | if (otg->state == OTG_STATE_A_HOST) { |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 913 | pm_runtime_get_sync(otg->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 914 | usb_unregister_notify(&motg->usbdev_nb); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 915 | msm_otg_start_host(otg, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 916 | if (motg->pdata->vbus_power) |
| 917 | motg->pdata->vbus_power(0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 918 | otg->host = NULL; |
| 919 | otg->state = OTG_STATE_UNDEFINED; |
| 920 | schedule_work(&motg->sm_work); |
| 921 | } else { |
| 922 | otg->host = NULL; |
| 923 | } |
| 924 | |
| 925 | return 0; |
| 926 | } |
| 927 | |
| 928 | hcd = bus_to_hcd(host); |
| 929 | hcd->power_budget = motg->pdata->power_budget; |
| 930 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 931 | motg->usbdev_nb.notifier_call = msm_otg_usbdev_notify; |
| 932 | usb_register_notify(&motg->usbdev_nb); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 933 | otg->host = host; |
| 934 | dev_dbg(otg->dev, "host driver registered w/ tranceiver\n"); |
| 935 | |
| 936 | /* |
| 937 | * Kick the state machine work, if peripheral is not supported |
| 938 | * or peripheral is already registered with us. |
| 939 | */ |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 940 | if (motg->pdata->mode == USB_HOST || otg->gadget) { |
| 941 | pm_runtime_get_sync(otg->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 942 | schedule_work(&motg->sm_work); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 943 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 944 | |
| 945 | return 0; |
| 946 | } |
| 947 | |
| 948 | static void msm_otg_start_peripheral(struct otg_transceiver *otg, int on) |
| 949 | { |
| 950 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); |
| 951 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 952 | |
| 953 | if (!otg->gadget) |
| 954 | return; |
| 955 | |
| 956 | if (on) { |
| 957 | dev_dbg(otg->dev, "gadget on\n"); |
| 958 | /* |
| 959 | * Some boards have a switch cotrolled by gpio |
| 960 | * to enable/disable internal HUB. Disable internal |
| 961 | * HUB before kicking the gadget. |
| 962 | */ |
| 963 | if (pdata->setup_gpio) |
| 964 | pdata->setup_gpio(OTG_STATE_B_PERIPHERAL); |
| 965 | usb_gadget_vbus_connect(otg->gadget); |
| 966 | } else { |
| 967 | dev_dbg(otg->dev, "gadget off\n"); |
| 968 | usb_gadget_vbus_disconnect(otg->gadget); |
| 969 | if (pdata->setup_gpio) |
| 970 | pdata->setup_gpio(OTG_STATE_UNDEFINED); |
| 971 | } |
| 972 | |
| 973 | } |
| 974 | |
| 975 | static int msm_otg_set_peripheral(struct otg_transceiver *otg, |
| 976 | struct usb_gadget *gadget) |
| 977 | { |
| 978 | struct msm_otg *motg = container_of(otg, struct msm_otg, otg); |
| 979 | |
| 980 | /* |
| 981 | * Fail peripheral registration if this board can support |
| 982 | * only host configuration. |
| 983 | */ |
| 984 | if (motg->pdata->mode == USB_HOST) { |
| 985 | dev_info(otg->dev, "Peripheral mode is not supported\n"); |
| 986 | return -ENODEV; |
| 987 | } |
| 988 | |
| 989 | if (!gadget) { |
| 990 | if (otg->state == OTG_STATE_B_PERIPHERAL) { |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 991 | pm_runtime_get_sync(otg->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 992 | msm_otg_start_peripheral(otg, 0); |
| 993 | otg->gadget = NULL; |
| 994 | otg->state = OTG_STATE_UNDEFINED; |
| 995 | schedule_work(&motg->sm_work); |
| 996 | } else { |
| 997 | otg->gadget = NULL; |
| 998 | } |
| 999 | |
| 1000 | return 0; |
| 1001 | } |
| 1002 | otg->gadget = gadget; |
| 1003 | dev_dbg(otg->dev, "peripheral driver registered w/ tranceiver\n"); |
| 1004 | |
| 1005 | /* |
| 1006 | * Kick the state machine work, if host is not supported |
| 1007 | * or host is already registered with us. |
| 1008 | */ |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1009 | if (motg->pdata->mode == USB_PERIPHERAL || otg->host) { |
| 1010 | pm_runtime_get_sync(otg->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1011 | schedule_work(&motg->sm_work); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1012 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1013 | |
| 1014 | return 0; |
| 1015 | } |
| 1016 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1017 | static bool msm_chg_aca_detect(struct msm_otg *motg) |
| 1018 | { |
| 1019 | struct otg_transceiver *otg = &motg->otg; |
| 1020 | u32 int_sts; |
| 1021 | bool ret = false; |
| 1022 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1023 | if (!aca_enabled()) |
| 1024 | goto out; |
| 1025 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1026 | if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) |
| 1027 | goto out; |
| 1028 | |
| 1029 | int_sts = ulpi_read(otg, 0x87); |
| 1030 | switch (int_sts & 0x1C) { |
| 1031 | case 0x08: |
| 1032 | if (!test_and_set_bit(ID_A, &motg->inputs)) { |
| 1033 | dev_dbg(otg->dev, "ID_A\n"); |
| 1034 | motg->chg_type = USB_ACA_A_CHARGER; |
| 1035 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1036 | clear_bit(ID_B, &motg->inputs); |
| 1037 | clear_bit(ID_C, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1038 | set_bit(ID, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1039 | ret = true; |
| 1040 | } |
| 1041 | break; |
| 1042 | case 0x0C: |
| 1043 | if (!test_and_set_bit(ID_B, &motg->inputs)) { |
| 1044 | dev_dbg(otg->dev, "ID_B\n"); |
| 1045 | motg->chg_type = USB_ACA_B_CHARGER; |
| 1046 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1047 | clear_bit(ID_A, &motg->inputs); |
| 1048 | clear_bit(ID_C, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1049 | set_bit(ID, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1050 | ret = true; |
| 1051 | } |
| 1052 | break; |
| 1053 | case 0x10: |
| 1054 | if (!test_and_set_bit(ID_C, &motg->inputs)) { |
| 1055 | dev_dbg(otg->dev, "ID_C\n"); |
| 1056 | motg->chg_type = USB_ACA_C_CHARGER; |
| 1057 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1058 | clear_bit(ID_A, &motg->inputs); |
| 1059 | clear_bit(ID_B, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1060 | set_bit(ID, &motg->inputs); |
| 1061 | ret = true; |
| 1062 | } |
| 1063 | break; |
| 1064 | case 0x04: |
| 1065 | if (test_and_clear_bit(ID, &motg->inputs)) { |
| 1066 | dev_dbg(otg->dev, "ID_GND\n"); |
| 1067 | motg->chg_type = USB_INVALID_CHARGER; |
| 1068 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1069 | clear_bit(ID_A, &motg->inputs); |
| 1070 | clear_bit(ID_B, &motg->inputs); |
| 1071 | clear_bit(ID_C, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1072 | ret = true; |
| 1073 | } |
| 1074 | break; |
| 1075 | default: |
| 1076 | ret = test_and_clear_bit(ID_A, &motg->inputs) | |
| 1077 | test_and_clear_bit(ID_B, &motg->inputs) | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1078 | test_and_clear_bit(ID_C, &motg->inputs) | |
| 1079 | !test_and_set_bit(ID, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1080 | if (ret) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1081 | dev_dbg(otg->dev, "ID A/B/C/GND is no more\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1082 | motg->chg_type = USB_INVALID_CHARGER; |
| 1083 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1084 | } |
| 1085 | } |
| 1086 | out: |
| 1087 | return ret; |
| 1088 | } |
| 1089 | |
| 1090 | static void msm_chg_enable_aca_det(struct msm_otg *motg) |
| 1091 | { |
| 1092 | struct otg_transceiver *otg = &motg->otg; |
| 1093 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1094 | if (!aca_enabled()) |
| 1095 | return; |
| 1096 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1097 | switch (motg->pdata->phy_type) { |
| 1098 | case SNPS_28NM_INTEGRATED_PHY: |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1099 | /* Disable ID_GND in link and PHY */ |
| 1100 | writel_relaxed(readl_relaxed(USB_OTGSC) & ~(OTGSC_IDPU | |
| 1101 | OTGSC_IDIE), USB_OTGSC); |
| 1102 | ulpi_write(otg, 0x01, 0x0C); |
| 1103 | ulpi_write(otg, 0x10, 0x0F); |
| 1104 | ulpi_write(otg, 0x10, 0x12); |
| 1105 | /* Enable ACA ID detection */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1106 | ulpi_write(otg, 0x20, 0x85); |
| 1107 | break; |
| 1108 | default: |
| 1109 | break; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | static void msm_chg_enable_aca_intr(struct msm_otg *motg) |
| 1114 | { |
| 1115 | struct otg_transceiver *otg = &motg->otg; |
| 1116 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1117 | if (!aca_enabled()) |
| 1118 | return; |
| 1119 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1120 | switch (motg->pdata->phy_type) { |
| 1121 | case SNPS_28NM_INTEGRATED_PHY: |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1122 | /* Enable ACA Detection interrupt (on any RID change) */ |
| 1123 | ulpi_write(otg, 0x01, 0x94); |
| 1124 | break; |
| 1125 | default: |
| 1126 | break; |
| 1127 | } |
| 1128 | } |
| 1129 | |
| 1130 | static void msm_chg_disable_aca_intr(struct msm_otg *motg) |
| 1131 | { |
| 1132 | struct otg_transceiver *otg = &motg->otg; |
| 1133 | |
| 1134 | if (!aca_enabled()) |
| 1135 | return; |
| 1136 | |
| 1137 | switch (motg->pdata->phy_type) { |
| 1138 | case SNPS_28NM_INTEGRATED_PHY: |
| 1139 | ulpi_write(otg, 0x01, 0x95); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1140 | break; |
| 1141 | default: |
| 1142 | break; |
| 1143 | } |
| 1144 | } |
| 1145 | |
| 1146 | static bool msm_chg_check_aca_intr(struct msm_otg *motg) |
| 1147 | { |
| 1148 | struct otg_transceiver *otg = &motg->otg; |
| 1149 | bool ret = false; |
| 1150 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1151 | if (!aca_enabled()) |
| 1152 | return ret; |
| 1153 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1154 | switch (motg->pdata->phy_type) { |
| 1155 | case SNPS_28NM_INTEGRATED_PHY: |
| 1156 | if (ulpi_read(otg, 0x91) & 1) { |
| 1157 | dev_dbg(otg->dev, "RID change\n"); |
| 1158 | ulpi_write(otg, 0x01, 0x92); |
| 1159 | ret = msm_chg_aca_detect(motg); |
| 1160 | } |
| 1161 | default: |
| 1162 | break; |
| 1163 | } |
| 1164 | return ret; |
| 1165 | } |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1166 | |
| 1167 | static void msm_otg_id_timer_func(unsigned long data) |
| 1168 | { |
| 1169 | struct msm_otg *motg = (struct msm_otg *) data; |
| 1170 | |
| 1171 | if (!aca_enabled()) |
| 1172 | return; |
| 1173 | |
| 1174 | if (atomic_read(&motg->in_lpm)) { |
| 1175 | dev_dbg(motg->otg.dev, "timer: in lpm\n"); |
| 1176 | return; |
| 1177 | } |
| 1178 | |
| 1179 | if (msm_chg_check_aca_intr(motg)) { |
| 1180 | dev_dbg(motg->otg.dev, "timer: aca work\n"); |
| 1181 | schedule_work(&motg->sm_work); |
| 1182 | } |
| 1183 | |
| 1184 | if (!test_bit(ID, &motg->inputs) || test_bit(ID_A, &motg->inputs)) |
| 1185 | mod_timer(&motg->id_timer, ID_TIMER_FREQ); |
| 1186 | } |
| 1187 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1188 | static bool msm_chg_check_secondary_det(struct msm_otg *motg) |
| 1189 | { |
| 1190 | struct otg_transceiver *otg = &motg->otg; |
| 1191 | u32 chg_det; |
| 1192 | bool ret = false; |
| 1193 | |
| 1194 | switch (motg->pdata->phy_type) { |
| 1195 | case CI_45NM_INTEGRATED_PHY: |
| 1196 | chg_det = ulpi_read(otg, 0x34); |
| 1197 | ret = chg_det & (1 << 4); |
| 1198 | break; |
| 1199 | case SNPS_28NM_INTEGRATED_PHY: |
| 1200 | chg_det = ulpi_read(otg, 0x87); |
| 1201 | ret = chg_det & 1; |
| 1202 | break; |
| 1203 | default: |
| 1204 | break; |
| 1205 | } |
| 1206 | return ret; |
| 1207 | } |
| 1208 | |
| 1209 | static void msm_chg_enable_secondary_det(struct msm_otg *motg) |
| 1210 | { |
| 1211 | struct otg_transceiver *otg = &motg->otg; |
| 1212 | u32 chg_det; |
| 1213 | |
| 1214 | switch (motg->pdata->phy_type) { |
| 1215 | case CI_45NM_INTEGRATED_PHY: |
| 1216 | chg_det = ulpi_read(otg, 0x34); |
| 1217 | /* Turn off charger block */ |
| 1218 | chg_det |= ~(1 << 1); |
| 1219 | ulpi_write(otg, chg_det, 0x34); |
| 1220 | udelay(20); |
| 1221 | /* control chg block via ULPI */ |
| 1222 | chg_det &= ~(1 << 3); |
| 1223 | ulpi_write(otg, chg_det, 0x34); |
| 1224 | /* put it in host mode for enabling D- source */ |
| 1225 | chg_det &= ~(1 << 2); |
| 1226 | ulpi_write(otg, chg_det, 0x34); |
| 1227 | /* Turn on chg detect block */ |
| 1228 | chg_det &= ~(1 << 1); |
| 1229 | ulpi_write(otg, chg_det, 0x34); |
| 1230 | udelay(20); |
| 1231 | /* enable chg detection */ |
| 1232 | chg_det &= ~(1 << 0); |
| 1233 | ulpi_write(otg, chg_det, 0x34); |
| 1234 | break; |
| 1235 | case SNPS_28NM_INTEGRATED_PHY: |
| 1236 | /* |
| 1237 | * Configure DM as current source, DP as current sink |
| 1238 | * and enable battery charging comparators. |
| 1239 | */ |
| 1240 | ulpi_write(otg, 0x8, 0x85); |
| 1241 | ulpi_write(otg, 0x2, 0x85); |
| 1242 | ulpi_write(otg, 0x1, 0x85); |
| 1243 | break; |
| 1244 | default: |
| 1245 | break; |
| 1246 | } |
| 1247 | } |
| 1248 | |
| 1249 | static bool msm_chg_check_primary_det(struct msm_otg *motg) |
| 1250 | { |
| 1251 | struct otg_transceiver *otg = &motg->otg; |
| 1252 | u32 chg_det; |
| 1253 | bool ret = false; |
| 1254 | |
| 1255 | switch (motg->pdata->phy_type) { |
| 1256 | case CI_45NM_INTEGRATED_PHY: |
| 1257 | chg_det = ulpi_read(otg, 0x34); |
| 1258 | ret = chg_det & (1 << 4); |
| 1259 | break; |
| 1260 | case SNPS_28NM_INTEGRATED_PHY: |
| 1261 | chg_det = ulpi_read(otg, 0x87); |
| 1262 | ret = chg_det & 1; |
| 1263 | break; |
| 1264 | default: |
| 1265 | break; |
| 1266 | } |
| 1267 | return ret; |
| 1268 | } |
| 1269 | |
| 1270 | static void msm_chg_enable_primary_det(struct msm_otg *motg) |
| 1271 | { |
| 1272 | struct otg_transceiver *otg = &motg->otg; |
| 1273 | u32 chg_det; |
| 1274 | |
| 1275 | switch (motg->pdata->phy_type) { |
| 1276 | case CI_45NM_INTEGRATED_PHY: |
| 1277 | chg_det = ulpi_read(otg, 0x34); |
| 1278 | /* enable chg detection */ |
| 1279 | chg_det &= ~(1 << 0); |
| 1280 | ulpi_write(otg, chg_det, 0x34); |
| 1281 | break; |
| 1282 | case SNPS_28NM_INTEGRATED_PHY: |
| 1283 | /* |
| 1284 | * Configure DP as current source, DM as current sink |
| 1285 | * and enable battery charging comparators. |
| 1286 | */ |
| 1287 | ulpi_write(otg, 0x2, 0x85); |
| 1288 | ulpi_write(otg, 0x1, 0x85); |
| 1289 | break; |
| 1290 | default: |
| 1291 | break; |
| 1292 | } |
| 1293 | } |
| 1294 | |
| 1295 | static bool msm_chg_check_dcd(struct msm_otg *motg) |
| 1296 | { |
| 1297 | struct otg_transceiver *otg = &motg->otg; |
| 1298 | u32 line_state; |
| 1299 | bool ret = false; |
| 1300 | |
| 1301 | switch (motg->pdata->phy_type) { |
| 1302 | case CI_45NM_INTEGRATED_PHY: |
| 1303 | line_state = ulpi_read(otg, 0x15); |
| 1304 | ret = !(line_state & 1); |
| 1305 | break; |
| 1306 | case SNPS_28NM_INTEGRATED_PHY: |
| 1307 | line_state = ulpi_read(otg, 0x87); |
| 1308 | ret = line_state & 2; |
| 1309 | break; |
| 1310 | default: |
| 1311 | break; |
| 1312 | } |
| 1313 | return ret; |
| 1314 | } |
| 1315 | |
| 1316 | static void msm_chg_disable_dcd(struct msm_otg *motg) |
| 1317 | { |
| 1318 | struct otg_transceiver *otg = &motg->otg; |
| 1319 | u32 chg_det; |
| 1320 | |
| 1321 | switch (motg->pdata->phy_type) { |
| 1322 | case CI_45NM_INTEGRATED_PHY: |
| 1323 | chg_det = ulpi_read(otg, 0x34); |
| 1324 | chg_det &= ~(1 << 5); |
| 1325 | ulpi_write(otg, chg_det, 0x34); |
| 1326 | break; |
| 1327 | case SNPS_28NM_INTEGRATED_PHY: |
| 1328 | ulpi_write(otg, 0x10, 0x86); |
| 1329 | break; |
| 1330 | default: |
| 1331 | break; |
| 1332 | } |
| 1333 | } |
| 1334 | |
| 1335 | static void msm_chg_enable_dcd(struct msm_otg *motg) |
| 1336 | { |
| 1337 | struct otg_transceiver *otg = &motg->otg; |
| 1338 | u32 chg_det; |
| 1339 | |
| 1340 | switch (motg->pdata->phy_type) { |
| 1341 | case CI_45NM_INTEGRATED_PHY: |
| 1342 | chg_det = ulpi_read(otg, 0x34); |
| 1343 | /* Turn on D+ current source */ |
| 1344 | chg_det |= (1 << 5); |
| 1345 | ulpi_write(otg, chg_det, 0x34); |
| 1346 | break; |
| 1347 | case SNPS_28NM_INTEGRATED_PHY: |
| 1348 | /* Data contact detection enable */ |
| 1349 | ulpi_write(otg, 0x10, 0x85); |
| 1350 | break; |
| 1351 | default: |
| 1352 | break; |
| 1353 | } |
| 1354 | } |
| 1355 | |
| 1356 | static void msm_chg_block_on(struct msm_otg *motg) |
| 1357 | { |
| 1358 | struct otg_transceiver *otg = &motg->otg; |
| 1359 | u32 func_ctrl, chg_det; |
| 1360 | |
| 1361 | /* put the controller in non-driving mode */ |
| 1362 | func_ctrl = ulpi_read(otg, ULPI_FUNC_CTRL); |
| 1363 | func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
| 1364 | func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; |
| 1365 | ulpi_write(otg, func_ctrl, ULPI_FUNC_CTRL); |
| 1366 | |
| 1367 | switch (motg->pdata->phy_type) { |
| 1368 | case CI_45NM_INTEGRATED_PHY: |
| 1369 | chg_det = ulpi_read(otg, 0x34); |
| 1370 | /* control chg block via ULPI */ |
| 1371 | chg_det &= ~(1 << 3); |
| 1372 | ulpi_write(otg, chg_det, 0x34); |
| 1373 | /* Turn on chg detect block */ |
| 1374 | chg_det &= ~(1 << 1); |
| 1375 | ulpi_write(otg, chg_det, 0x34); |
| 1376 | udelay(20); |
| 1377 | break; |
| 1378 | case SNPS_28NM_INTEGRATED_PHY: |
| 1379 | /* Clear charger detecting control bits */ |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1380 | ulpi_write(otg, 0x1F, 0x86); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1381 | /* Clear alt interrupt latch and enable bits */ |
| 1382 | ulpi_write(otg, 0x1F, 0x92); |
| 1383 | ulpi_write(otg, 0x1F, 0x95); |
| 1384 | udelay(100); |
| 1385 | break; |
| 1386 | default: |
| 1387 | break; |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | static void msm_chg_block_off(struct msm_otg *motg) |
| 1392 | { |
| 1393 | struct otg_transceiver *otg = &motg->otg; |
| 1394 | u32 func_ctrl, chg_det; |
| 1395 | |
| 1396 | switch (motg->pdata->phy_type) { |
| 1397 | case CI_45NM_INTEGRATED_PHY: |
| 1398 | chg_det = ulpi_read(otg, 0x34); |
| 1399 | /* Turn off charger block */ |
| 1400 | chg_det |= ~(1 << 1); |
| 1401 | ulpi_write(otg, chg_det, 0x34); |
| 1402 | break; |
| 1403 | case SNPS_28NM_INTEGRATED_PHY: |
| 1404 | /* Clear charger detecting control bits */ |
| 1405 | ulpi_write(otg, 0x3F, 0x86); |
| 1406 | /* Clear alt interrupt latch and enable bits */ |
| 1407 | ulpi_write(otg, 0x1F, 0x92); |
| 1408 | ulpi_write(otg, 0x1F, 0x95); |
| 1409 | break; |
| 1410 | default: |
| 1411 | break; |
| 1412 | } |
| 1413 | |
| 1414 | /* put the controller in normal mode */ |
| 1415 | func_ctrl = ulpi_read(otg, ULPI_FUNC_CTRL); |
| 1416 | func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
| 1417 | func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NORMAL; |
| 1418 | ulpi_write(otg, func_ctrl, ULPI_FUNC_CTRL); |
| 1419 | } |
| 1420 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 1421 | static const char *chg_to_string(enum usb_chg_type chg_type) |
| 1422 | { |
| 1423 | switch (chg_type) { |
| 1424 | case USB_SDP_CHARGER: return "USB_SDP_CHARGER"; |
| 1425 | case USB_DCP_CHARGER: return "USB_DCP_CHARGER"; |
| 1426 | case USB_CDP_CHARGER: return "USB_CDP_CHARGER"; |
| 1427 | case USB_ACA_A_CHARGER: return "USB_ACA_A_CHARGER"; |
| 1428 | case USB_ACA_B_CHARGER: return "USB_ACA_B_CHARGER"; |
| 1429 | case USB_ACA_C_CHARGER: return "USB_ACA_C_CHARGER"; |
| 1430 | case USB_ACA_DOCK_CHARGER: return "USB_ACA_DOCK_CHARGER"; |
| 1431 | default: return "INVALID_CHARGER"; |
| 1432 | } |
| 1433 | } |
| 1434 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1435 | #define MSM_CHG_DCD_POLL_TIME (100 * HZ/1000) /* 100 msec */ |
| 1436 | #define MSM_CHG_DCD_MAX_RETRIES 6 /* Tdcd_tmout = 6 * 100 msec */ |
| 1437 | #define MSM_CHG_PRIMARY_DET_TIME (40 * HZ/1000) /* TVDPSRC_ON */ |
| 1438 | #define MSM_CHG_SECONDARY_DET_TIME (40 * HZ/1000) /* TVDMSRC_ON */ |
| 1439 | static void msm_chg_detect_work(struct work_struct *w) |
| 1440 | { |
| 1441 | struct msm_otg *motg = container_of(w, struct msm_otg, chg_work.work); |
| 1442 | struct otg_transceiver *otg = &motg->otg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1443 | bool is_dcd, tmout, vout, is_aca; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1444 | unsigned long delay; |
| 1445 | |
| 1446 | dev_dbg(otg->dev, "chg detection work\n"); |
| 1447 | switch (motg->chg_state) { |
| 1448 | case USB_CHG_STATE_UNDEFINED: |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1449 | msm_chg_block_on(motg); |
| 1450 | msm_chg_enable_dcd(motg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1451 | msm_chg_enable_aca_det(motg); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1452 | motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; |
| 1453 | motg->dcd_retries = 0; |
| 1454 | delay = MSM_CHG_DCD_POLL_TIME; |
| 1455 | break; |
| 1456 | case USB_CHG_STATE_WAIT_FOR_DCD: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1457 | is_aca = msm_chg_aca_detect(motg); |
| 1458 | if (is_aca) { |
| 1459 | /* |
| 1460 | * ID_A can be ACA dock too. continue |
| 1461 | * primary detection after DCD. |
| 1462 | */ |
| 1463 | if (test_bit(ID_A, &motg->inputs)) { |
| 1464 | motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; |
| 1465 | } else { |
| 1466 | delay = 0; |
| 1467 | break; |
| 1468 | } |
| 1469 | } |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1470 | is_dcd = msm_chg_check_dcd(motg); |
| 1471 | tmout = ++motg->dcd_retries == MSM_CHG_DCD_MAX_RETRIES; |
| 1472 | if (is_dcd || tmout) { |
| 1473 | msm_chg_disable_dcd(motg); |
| 1474 | msm_chg_enable_primary_det(motg); |
| 1475 | delay = MSM_CHG_PRIMARY_DET_TIME; |
| 1476 | motg->chg_state = USB_CHG_STATE_DCD_DONE; |
| 1477 | } else { |
| 1478 | delay = MSM_CHG_DCD_POLL_TIME; |
| 1479 | } |
| 1480 | break; |
| 1481 | case USB_CHG_STATE_DCD_DONE: |
| 1482 | vout = msm_chg_check_primary_det(motg); |
| 1483 | if (vout) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1484 | if (test_bit(ID_A, &motg->inputs)) { |
| 1485 | motg->chg_type = USB_ACA_DOCK_CHARGER; |
| 1486 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1487 | delay = 0; |
| 1488 | break; |
| 1489 | } |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1490 | msm_chg_enable_secondary_det(motg); |
| 1491 | delay = MSM_CHG_SECONDARY_DET_TIME; |
| 1492 | motg->chg_state = USB_CHG_STATE_PRIMARY_DONE; |
| 1493 | } else { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1494 | if (test_bit(ID_A, &motg->inputs)) { |
| 1495 | motg->chg_type = USB_ACA_A_CHARGER; |
| 1496 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1497 | delay = 0; |
| 1498 | break; |
| 1499 | } |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1500 | motg->chg_type = USB_SDP_CHARGER; |
| 1501 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1502 | delay = 0; |
| 1503 | } |
| 1504 | break; |
| 1505 | case USB_CHG_STATE_PRIMARY_DONE: |
| 1506 | vout = msm_chg_check_secondary_det(motg); |
| 1507 | if (vout) |
| 1508 | motg->chg_type = USB_DCP_CHARGER; |
| 1509 | else |
| 1510 | motg->chg_type = USB_CDP_CHARGER; |
| 1511 | motg->chg_state = USB_CHG_STATE_SECONDARY_DONE; |
| 1512 | /* fall through */ |
| 1513 | case USB_CHG_STATE_SECONDARY_DONE: |
| 1514 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1515 | case USB_CHG_STATE_DETECTED: |
| 1516 | msm_chg_block_off(motg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1517 | msm_chg_enable_aca_det(motg); |
| 1518 | msm_chg_enable_aca_intr(motg); |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 1519 | dev_dbg(otg->dev, "chg_type = %s\n", |
| 1520 | chg_to_string(motg->chg_type)); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1521 | schedule_work(&motg->sm_work); |
| 1522 | return; |
| 1523 | default: |
| 1524 | return; |
| 1525 | } |
| 1526 | |
| 1527 | schedule_delayed_work(&motg->chg_work, delay); |
| 1528 | } |
| 1529 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1530 | /* |
| 1531 | * We support OTG, Peripheral only and Host only configurations. In case |
| 1532 | * of OTG, mode switch (host-->peripheral/peripheral-->host) can happen |
| 1533 | * via Id pin status or user request (debugfs). Id/BSV interrupts are not |
| 1534 | * enabled when switch is controlled by user and default mode is supplied |
| 1535 | * by board file, which can be changed by userspace later. |
| 1536 | */ |
| 1537 | static void msm_otg_init_sm(struct msm_otg *motg) |
| 1538 | { |
| 1539 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 1540 | u32 otgsc = readl(USB_OTGSC); |
| 1541 | |
| 1542 | switch (pdata->mode) { |
| 1543 | case USB_OTG: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1544 | if (pdata->otg_control == OTG_USER_CONTROL) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1545 | if (pdata->default_mode == USB_HOST) { |
| 1546 | clear_bit(ID, &motg->inputs); |
| 1547 | } else if (pdata->default_mode == USB_PERIPHERAL) { |
| 1548 | set_bit(ID, &motg->inputs); |
| 1549 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1550 | } else { |
| 1551 | set_bit(ID, &motg->inputs); |
| 1552 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 1553 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1554 | } else { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1555 | if (aca_enabled()) { |
| 1556 | if (irq_read_line(motg->pdata->pmic_id_irq)) |
| 1557 | set_bit(ID, &motg->inputs); |
| 1558 | else |
| 1559 | clear_bit(ID, &motg->inputs); |
| 1560 | |
| 1561 | } else { |
| 1562 | if (otgsc & OTGSC_ID) |
| 1563 | set_bit(ID, &motg->inputs); |
| 1564 | else |
| 1565 | clear_bit(ID, &motg->inputs); |
| 1566 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1567 | |
| 1568 | if (otgsc & OTGSC_BSV) |
| 1569 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1570 | else |
| 1571 | clear_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1572 | } |
| 1573 | break; |
| 1574 | case USB_HOST: |
| 1575 | clear_bit(ID, &motg->inputs); |
| 1576 | break; |
| 1577 | case USB_PERIPHERAL: |
| 1578 | set_bit(ID, &motg->inputs); |
| 1579 | if (otgsc & OTGSC_BSV) |
| 1580 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1581 | else |
| 1582 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 1583 | break; |
| 1584 | default: |
| 1585 | break; |
| 1586 | } |
| 1587 | } |
| 1588 | |
| 1589 | static void msm_otg_sm_work(struct work_struct *w) |
| 1590 | { |
| 1591 | struct msm_otg *motg = container_of(w, struct msm_otg, sm_work); |
| 1592 | struct otg_transceiver *otg = &motg->otg; |
| 1593 | |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 1594 | pm_runtime_resume(otg->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1595 | switch (otg->state) { |
| 1596 | case OTG_STATE_UNDEFINED: |
| 1597 | dev_dbg(otg->dev, "OTG_STATE_UNDEFINED state\n"); |
| 1598 | msm_otg_reset(otg); |
| 1599 | msm_otg_init_sm(motg); |
| 1600 | otg->state = OTG_STATE_B_IDLE; |
| 1601 | /* FALL THROUGH */ |
| 1602 | case OTG_STATE_B_IDLE: |
| 1603 | dev_dbg(otg->dev, "OTG_STATE_B_IDLE state\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1604 | if ((!test_bit(ID, &motg->inputs) || |
| 1605 | test_bit(ID_A, &motg->inputs)) && otg->host) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1606 | if (motg->chg_type == USB_ACA_DOCK_CHARGER) |
| 1607 | msm_otg_notify_charger(motg, |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1608 | IDEV_ACA_CHG_MAX); |
| 1609 | else if (test_bit(ID_A, &motg->inputs)) |
| 1610 | msm_otg_notify_charger(motg, |
| 1611 | IDEV_ACA_CHG_MAX - IUNIT); |
| 1612 | else if (motg->pdata->vbus_power) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1613 | motg->pdata->vbus_power(1); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1614 | msm_otg_start_host(otg, 1); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1615 | /* |
| 1616 | * Link can not generate PHY_ALT interrupt |
| 1617 | * in host mode when no device is attached |
| 1618 | * to the port. It is also observed PHY_ALT |
| 1619 | * interrupt missing upon Micro-A cable disconnect. |
| 1620 | * Hence disable PHY_ALT interrupt and perform |
| 1621 | * polling to detect RID change. |
| 1622 | */ |
| 1623 | msm_chg_enable_aca_det(motg); |
| 1624 | msm_chg_disable_aca_intr(motg); |
| 1625 | mod_timer(&motg->id_timer, ID_TIMER_FREQ); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1626 | otg->state = OTG_STATE_A_HOST; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1627 | } else if (test_bit(B_SESS_VLD, &motg->inputs)) { |
| 1628 | switch (motg->chg_state) { |
| 1629 | case USB_CHG_STATE_UNDEFINED: |
| 1630 | msm_chg_detect_work(&motg->chg_work.work); |
| 1631 | break; |
| 1632 | case USB_CHG_STATE_DETECTED: |
| 1633 | switch (motg->chg_type) { |
| 1634 | case USB_DCP_CHARGER: |
| 1635 | msm_otg_notify_charger(motg, |
| 1636 | IDEV_CHG_MAX); |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 1637 | pm_runtime_put_noidle(otg->dev); |
| 1638 | pm_runtime_suspend(otg->dev); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1639 | break; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1640 | case USB_ACA_B_CHARGER: |
| 1641 | msm_otg_notify_charger(motg, |
| 1642 | IDEV_ACA_CHG_MAX); |
| 1643 | /* |
| 1644 | * (ID_B --> ID_C) PHY_ALT interrupt can |
| 1645 | * not be detected in LPM. |
| 1646 | */ |
| 1647 | break; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1648 | case USB_CDP_CHARGER: |
| 1649 | msm_otg_notify_charger(motg, |
| 1650 | IDEV_CHG_MAX); |
| 1651 | msm_otg_start_peripheral(otg, 1); |
| 1652 | otg->state = OTG_STATE_B_PERIPHERAL; |
| 1653 | break; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1654 | case USB_ACA_C_CHARGER: |
| 1655 | msm_otg_notify_charger(motg, |
| 1656 | IDEV_ACA_CHG_MAX); |
| 1657 | msm_otg_start_peripheral(otg, 1); |
| 1658 | otg->state = OTG_STATE_B_PERIPHERAL; |
| 1659 | break; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1660 | case USB_SDP_CHARGER: |
| 1661 | msm_otg_notify_charger(motg, IUNIT); |
| 1662 | msm_otg_start_peripheral(otg, 1); |
| 1663 | otg->state = OTG_STATE_B_PERIPHERAL; |
| 1664 | break; |
| 1665 | default: |
| 1666 | break; |
| 1667 | } |
| 1668 | break; |
| 1669 | default: |
| 1670 | break; |
| 1671 | } |
| 1672 | } else { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1673 | cancel_delayed_work_sync(&motg->chg_work); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1674 | msm_otg_notify_charger(motg, 0); |
| 1675 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1676 | motg->chg_type = USB_INVALID_CHARGER; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1677 | msm_otg_reset(otg); |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 1678 | pm_runtime_put_noidle(otg->dev); |
| 1679 | pm_runtime_suspend(otg->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1680 | } |
| 1681 | break; |
| 1682 | case OTG_STATE_B_PERIPHERAL: |
| 1683 | dev_dbg(otg->dev, "OTG_STATE_B_PERIPHERAL state\n"); |
| 1684 | if (!test_bit(B_SESS_VLD, &motg->inputs) || |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1685 | !test_bit(ID, &motg->inputs) || |
| 1686 | !test_bit(ID_C, &motg->inputs)) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1687 | msm_otg_start_peripheral(otg, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1688 | otg->state = OTG_STATE_B_IDLE; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1689 | schedule_work(w); |
| 1690 | } else if (test_bit(ID_C, &motg->inputs)) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1691 | msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1692 | } |
| 1693 | break; |
| 1694 | case OTG_STATE_A_HOST: |
| 1695 | dev_dbg(otg->dev, "OTG_STATE_A_HOST state\n"); |
| 1696 | if (test_bit(ID, &motg->inputs) && |
| 1697 | !test_bit(ID_A, &motg->inputs)) { |
| 1698 | msm_otg_start_host(otg, 0); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1699 | if (motg->pdata->vbus_power) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1700 | motg->pdata->vbus_power(0); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1701 | msleep(100); /* TA_WAIT_VFALL */ |
| 1702 | } |
| 1703 | /* |
| 1704 | * Exit point of host mode. |
| 1705 | * |
| 1706 | * 1. Micro-A cable disconnect: Just schedule |
| 1707 | * the work. PHY is reset in B_IDLE and LPM |
| 1708 | * is allowed. |
| 1709 | * 2. ID_GND --> ID_B: No need to reset the PHY. |
| 1710 | * HCD core clears all PORTSC bits and initializes |
| 1711 | * the controller to host mode in remove_hcd. |
| 1712 | * Restore PORTSC transceiver select bits (ULPI) |
| 1713 | * and reset the controller to change MODE bits. |
| 1714 | * PHY_ALT interrupt can not occur in host mode. |
| 1715 | */ |
| 1716 | del_timer_sync(&motg->id_timer); |
| 1717 | if (motg->chg_state != USB_CHG_STATE_UNDEFINED) { |
| 1718 | msm_otg_link_reset(motg); |
| 1719 | msm_chg_enable_aca_intr(motg); |
| 1720 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1721 | otg->state = OTG_STATE_B_IDLE; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1722 | schedule_work(w); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1723 | } else if (test_bit(ID_A, &motg->inputs)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1724 | if (motg->pdata->vbus_power) |
| 1725 | motg->pdata->vbus_power(0); |
| 1726 | msm_otg_notify_charger(motg, |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1727 | IDEV_ACA_CHG_MAX - motg->mA_port); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1728 | } else if (!test_bit(ID, &motg->inputs)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1729 | msm_otg_notify_charger(motg, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1730 | if (motg->pdata->vbus_power) |
| 1731 | motg->pdata->vbus_power(1); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1732 | } |
| 1733 | break; |
| 1734 | default: |
| 1735 | break; |
| 1736 | } |
| 1737 | } |
| 1738 | |
| 1739 | static irqreturn_t msm_otg_irq(int irq, void *data) |
| 1740 | { |
| 1741 | struct msm_otg *motg = data; |
| 1742 | struct otg_transceiver *otg = &motg->otg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1743 | u32 otgsc = 0, usbsts; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1744 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1745 | if (atomic_read(&motg->in_lpm)) { |
| 1746 | disable_irq_nosync(irq); |
| 1747 | motg->async_int = 1; |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 1748 | pm_request_resume(otg->dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1749 | return IRQ_HANDLED; |
| 1750 | } |
| 1751 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1752 | usbsts = readl(USB_USBSTS); |
| 1753 | if ((usbsts & PHY_ALT_INT)) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1754 | dev_dbg(otg->dev, "PHY_ALT interrupt\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1755 | writel(PHY_ALT_INT, USB_USBSTS); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1756 | if (msm_chg_check_aca_intr(motg)) { |
| 1757 | dev_dbg(otg->dev, "ACA work from IRQ\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1758 | schedule_work(&motg->sm_work); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1759 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1760 | return IRQ_HANDLED; |
| 1761 | } |
| 1762 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1763 | otgsc = readl(USB_OTGSC); |
| 1764 | if (!(otgsc & (OTGSC_IDIS | OTGSC_BSVIS))) |
| 1765 | return IRQ_NONE; |
| 1766 | |
| 1767 | if ((otgsc & OTGSC_IDIS) && (otgsc & OTGSC_IDIE)) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1768 | if (otgsc & OTGSC_ID) { |
| 1769 | dev_dbg(otg->dev, "ID set\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1770 | set_bit(ID, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1771 | } else { |
| 1772 | dev_dbg(otg->dev, "ID clear\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1773 | clear_bit(ID, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1774 | msm_chg_enable_aca_det(motg); |
| 1775 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1776 | schedule_work(&motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1777 | } else if ((otgsc & OTGSC_BSVIS) && (otgsc & OTGSC_BSVIE)) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1778 | if (otgsc & OTGSC_BSV) { |
| 1779 | dev_dbg(otg->dev, "BSV set\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1780 | set_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1781 | } else { |
| 1782 | dev_dbg(otg->dev, "BSV clear\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1783 | clear_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1784 | msm_chg_check_aca_intr(motg); |
| 1785 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1786 | schedule_work(&motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1787 | } |
| 1788 | |
| 1789 | writel(otgsc, USB_OTGSC); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1790 | return IRQ_HANDLED; |
| 1791 | } |
| 1792 | |
| 1793 | static void msm_otg_set_vbus_state(int online) |
| 1794 | { |
| 1795 | struct msm_otg *motg = the_msm_otg; |
| 1796 | |
| 1797 | /* We depend on PMIC for only VBUS ON interrupt */ |
| 1798 | if (!atomic_read(&motg->in_lpm) || !online) |
| 1799 | return; |
| 1800 | |
| 1801 | /* |
| 1802 | * Let interrupt handler take care of resuming |
| 1803 | * the hardware. |
| 1804 | */ |
| 1805 | msm_otg_irq(motg->irq, (void *) motg); |
| 1806 | } |
| 1807 | |
| 1808 | static irqreturn_t msm_pmic_id_irq(int irq, void *data) |
| 1809 | { |
| 1810 | struct msm_otg *motg = data; |
| 1811 | |
| 1812 | if (atomic_read(&motg->in_lpm) && !motg->async_int) |
| 1813 | msm_otg_irq(motg->irq, motg); |
| 1814 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1815 | return IRQ_HANDLED; |
| 1816 | } |
| 1817 | |
| 1818 | static int msm_otg_mode_show(struct seq_file *s, void *unused) |
| 1819 | { |
| 1820 | struct msm_otg *motg = s->private; |
| 1821 | struct otg_transceiver *otg = &motg->otg; |
| 1822 | |
| 1823 | switch (otg->state) { |
| 1824 | case OTG_STATE_A_HOST: |
| 1825 | seq_printf(s, "host\n"); |
| 1826 | break; |
| 1827 | case OTG_STATE_B_PERIPHERAL: |
| 1828 | seq_printf(s, "peripheral\n"); |
| 1829 | break; |
| 1830 | default: |
| 1831 | seq_printf(s, "none\n"); |
| 1832 | break; |
| 1833 | } |
| 1834 | |
| 1835 | return 0; |
| 1836 | } |
| 1837 | |
| 1838 | static int msm_otg_mode_open(struct inode *inode, struct file *file) |
| 1839 | { |
| 1840 | return single_open(file, msm_otg_mode_show, inode->i_private); |
| 1841 | } |
| 1842 | |
| 1843 | static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, |
| 1844 | size_t count, loff_t *ppos) |
| 1845 | { |
Pavankumar Kondeti | e2904ee | 2011-02-15 09:42:35 +0530 | [diff] [blame] | 1846 | struct seq_file *s = file->private_data; |
| 1847 | struct msm_otg *motg = s->private; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1848 | char buf[16]; |
| 1849 | struct otg_transceiver *otg = &motg->otg; |
| 1850 | int status = count; |
| 1851 | enum usb_mode_type req_mode; |
| 1852 | |
| 1853 | memset(buf, 0x00, sizeof(buf)); |
| 1854 | |
| 1855 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) { |
| 1856 | status = -EFAULT; |
| 1857 | goto out; |
| 1858 | } |
| 1859 | |
| 1860 | if (!strncmp(buf, "host", 4)) { |
| 1861 | req_mode = USB_HOST; |
| 1862 | } else if (!strncmp(buf, "peripheral", 10)) { |
| 1863 | req_mode = USB_PERIPHERAL; |
| 1864 | } else if (!strncmp(buf, "none", 4)) { |
| 1865 | req_mode = USB_NONE; |
| 1866 | } else { |
| 1867 | status = -EINVAL; |
| 1868 | goto out; |
| 1869 | } |
| 1870 | |
| 1871 | switch (req_mode) { |
| 1872 | case USB_NONE: |
| 1873 | switch (otg->state) { |
| 1874 | case OTG_STATE_A_HOST: |
| 1875 | case OTG_STATE_B_PERIPHERAL: |
| 1876 | set_bit(ID, &motg->inputs); |
| 1877 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 1878 | break; |
| 1879 | default: |
| 1880 | goto out; |
| 1881 | } |
| 1882 | break; |
| 1883 | case USB_PERIPHERAL: |
| 1884 | switch (otg->state) { |
| 1885 | case OTG_STATE_B_IDLE: |
| 1886 | case OTG_STATE_A_HOST: |
| 1887 | set_bit(ID, &motg->inputs); |
| 1888 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1889 | break; |
| 1890 | default: |
| 1891 | goto out; |
| 1892 | } |
| 1893 | break; |
| 1894 | case USB_HOST: |
| 1895 | switch (otg->state) { |
| 1896 | case OTG_STATE_B_IDLE: |
| 1897 | case OTG_STATE_B_PERIPHERAL: |
| 1898 | clear_bit(ID, &motg->inputs); |
| 1899 | break; |
| 1900 | default: |
| 1901 | goto out; |
| 1902 | } |
| 1903 | break; |
| 1904 | default: |
| 1905 | goto out; |
| 1906 | } |
| 1907 | |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 1908 | pm_runtime_resume(otg->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1909 | schedule_work(&motg->sm_work); |
| 1910 | out: |
| 1911 | return status; |
| 1912 | } |
| 1913 | |
| 1914 | const struct file_operations msm_otg_mode_fops = { |
| 1915 | .open = msm_otg_mode_open, |
| 1916 | .read = seq_read, |
| 1917 | .write = msm_otg_mode_write, |
| 1918 | .llseek = seq_lseek, |
| 1919 | .release = single_release, |
| 1920 | }; |
| 1921 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 1922 | static int msm_otg_show_chg_type(struct seq_file *s, void *unused) |
| 1923 | { |
| 1924 | struct msm_otg *motg = s->private; |
| 1925 | |
| 1926 | seq_printf(s, chg_to_string(motg->chg_type)); |
| 1927 | return 0; |
| 1928 | } |
| 1929 | |
| 1930 | static int msm_otg_chg_open(struct inode *inode, struct file *file) |
| 1931 | { |
| 1932 | return single_open(file, msm_otg_show_chg_type, inode->i_private); |
| 1933 | } |
| 1934 | |
| 1935 | const struct file_operations msm_otg_chg_fops = { |
| 1936 | .open = msm_otg_chg_open, |
| 1937 | .read = seq_read, |
| 1938 | .llseek = seq_lseek, |
| 1939 | .release = single_release, |
| 1940 | }; |
| 1941 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1942 | static int msm_otg_aca_show(struct seq_file *s, void *unused) |
| 1943 | { |
| 1944 | if (debug_aca_enabled) |
| 1945 | seq_printf(s, "enabled\n"); |
| 1946 | else |
| 1947 | seq_printf(s, "disabled\n"); |
| 1948 | |
| 1949 | return 0; |
| 1950 | } |
| 1951 | |
| 1952 | static int msm_otg_aca_open(struct inode *inode, struct file *file) |
| 1953 | { |
| 1954 | return single_open(file, msm_otg_aca_show, inode->i_private); |
| 1955 | } |
| 1956 | |
| 1957 | static ssize_t msm_otg_aca_write(struct file *file, const char __user *ubuf, |
| 1958 | size_t count, loff_t *ppos) |
| 1959 | { |
| 1960 | char buf[8]; |
| 1961 | |
| 1962 | memset(buf, 0x00, sizeof(buf)); |
| 1963 | |
| 1964 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 1965 | return -EFAULT; |
| 1966 | |
| 1967 | if (!strncmp(buf, "enable", 6)) |
| 1968 | debug_aca_enabled = true; |
| 1969 | else |
| 1970 | debug_aca_enabled = false; |
| 1971 | |
| 1972 | return count; |
| 1973 | } |
| 1974 | |
| 1975 | const struct file_operations msm_otg_aca_fops = { |
| 1976 | .open = msm_otg_aca_open, |
| 1977 | .read = seq_read, |
| 1978 | .write = msm_otg_aca_write, |
| 1979 | .llseek = seq_lseek, |
| 1980 | .release = single_release, |
| 1981 | }; |
| 1982 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1983 | static struct dentry *msm_otg_dbg_root; |
| 1984 | static struct dentry *msm_otg_dbg_mode; |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 1985 | static struct dentry *msm_otg_chg_type; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1986 | static struct dentry *msm_otg_dbg_aca; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1987 | |
| 1988 | static int msm_otg_debugfs_init(struct msm_otg *motg) |
| 1989 | { |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 1990 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1991 | msm_otg_dbg_root = debugfs_create_dir("msm_otg", NULL); |
| 1992 | |
| 1993 | if (!msm_otg_dbg_root || IS_ERR(msm_otg_dbg_root)) |
| 1994 | return -ENODEV; |
| 1995 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 1996 | if (motg->pdata->mode == USB_OTG && |
| 1997 | motg->pdata->otg_control == OTG_USER_CONTROL) { |
| 1998 | |
| 1999 | msm_otg_dbg_mode = debugfs_create_file("mode", S_IRUGO | |
| 2000 | S_IWUSR, msm_otg_dbg_root, motg, |
| 2001 | &msm_otg_mode_fops); |
| 2002 | |
| 2003 | if (!msm_otg_dbg_mode) { |
| 2004 | debugfs_remove(msm_otg_dbg_root); |
| 2005 | msm_otg_dbg_root = NULL; |
| 2006 | return -ENODEV; |
| 2007 | } |
| 2008 | } |
| 2009 | |
| 2010 | msm_otg_chg_type = debugfs_create_file("chg_type", S_IRUGO, |
| 2011 | msm_otg_dbg_root, motg, |
| 2012 | &msm_otg_chg_fops); |
| 2013 | |
| 2014 | if (!msm_otg_chg_type) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2015 | debugfs_remove_recursive(msm_otg_dbg_root); |
| 2016 | return -ENODEV; |
| 2017 | } |
| 2018 | |
| 2019 | msm_otg_dbg_aca = debugfs_create_file("aca", S_IRUGO | S_IWUSR, |
| 2020 | msm_otg_dbg_root, motg, |
| 2021 | &msm_otg_aca_fops); |
| 2022 | |
| 2023 | if (!msm_otg_dbg_aca) { |
| 2024 | debugfs_remove_recursive(msm_otg_dbg_root); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2025 | return -ENODEV; |
| 2026 | } |
| 2027 | |
| 2028 | return 0; |
| 2029 | } |
| 2030 | |
| 2031 | static void msm_otg_debugfs_cleanup(void) |
| 2032 | { |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 2033 | debugfs_remove_recursive(msm_otg_dbg_root); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2034 | } |
| 2035 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame^] | 2036 | static u64 msm_otg_dma_mask = DMA_BIT_MASK(64); |
| 2037 | static struct platform_device *msm_otg_add_pdev( |
| 2038 | struct platform_device *ofdev, const char *name) |
| 2039 | { |
| 2040 | struct platform_device *pdev; |
| 2041 | const struct resource *res = ofdev->resource; |
| 2042 | unsigned int num = ofdev->num_resources; |
| 2043 | int retval; |
| 2044 | |
| 2045 | pdev = platform_device_alloc(name, -1); |
| 2046 | if (!pdev) { |
| 2047 | retval = -ENOMEM; |
| 2048 | goto error; |
| 2049 | } |
| 2050 | |
| 2051 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 2052 | pdev->dev.dma_mask = &msm_otg_dma_mask; |
| 2053 | |
| 2054 | if (num) { |
| 2055 | retval = platform_device_add_resources(pdev, res, num); |
| 2056 | if (retval) |
| 2057 | goto error; |
| 2058 | } |
| 2059 | |
| 2060 | retval = platform_device_add(pdev); |
| 2061 | if (retval) |
| 2062 | goto error; |
| 2063 | |
| 2064 | return pdev; |
| 2065 | |
| 2066 | error: |
| 2067 | platform_device_put(pdev); |
| 2068 | return ERR_PTR(retval); |
| 2069 | } |
| 2070 | |
| 2071 | static int msm_otg_setup_devices(struct platform_device *ofdev, |
| 2072 | enum usb_mode_type mode, bool init) |
| 2073 | { |
| 2074 | const char *gadget_name = "msm_hsusb"; |
| 2075 | const char *host_name = "msm_hsusb_host"; |
| 2076 | static struct platform_device *gadget_pdev; |
| 2077 | static struct platform_device *host_pdev; |
| 2078 | int retval = 0; |
| 2079 | |
| 2080 | if (!init) { |
| 2081 | if (gadget_pdev) |
| 2082 | platform_device_unregister(gadget_pdev); |
| 2083 | if (host_pdev) |
| 2084 | platform_device_unregister(host_pdev); |
| 2085 | return 0; |
| 2086 | } |
| 2087 | |
| 2088 | switch (mode) { |
| 2089 | case USB_OTG: |
| 2090 | /* fall through */ |
| 2091 | case USB_PERIPHERAL: |
| 2092 | gadget_pdev = msm_otg_add_pdev(ofdev, gadget_name); |
| 2093 | if (IS_ERR(gadget_pdev)) { |
| 2094 | retval = PTR_ERR(gadget_pdev); |
| 2095 | break; |
| 2096 | } |
| 2097 | if (mode == USB_PERIPHERAL) |
| 2098 | break; |
| 2099 | /* fall through */ |
| 2100 | case USB_HOST: |
| 2101 | host_pdev = msm_otg_add_pdev(ofdev, host_name); |
| 2102 | if (IS_ERR(host_pdev)) { |
| 2103 | retval = PTR_ERR(host_pdev); |
| 2104 | if (mode == USB_OTG) |
| 2105 | platform_device_unregister(gadget_pdev); |
| 2106 | } |
| 2107 | break; |
| 2108 | default: |
| 2109 | break; |
| 2110 | } |
| 2111 | |
| 2112 | return retval; |
| 2113 | } |
| 2114 | |
| 2115 | struct msm_otg_platform_data *msm_otg_dt_to_pdata(struct platform_device *pdev) |
| 2116 | { |
| 2117 | struct device_node *node = pdev->dev.of_node; |
| 2118 | struct msm_otg_platform_data *pdata; |
| 2119 | int len = 0; |
| 2120 | |
| 2121 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 2122 | if (!pdata) { |
| 2123 | pr_err("unable to allocate platform data\n"); |
| 2124 | return NULL; |
| 2125 | } |
| 2126 | of_get_property(node, "qcom,hsusb-otg-phy-init-seq", &len); |
| 2127 | if (len) { |
| 2128 | pdata->phy_init_seq = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); |
| 2129 | if (!pdata->phy_init_seq) |
| 2130 | return NULL; |
| 2131 | of_property_read_u32_array(node, "qcom,hsusb-otg-phy-init-seq", |
| 2132 | pdata->phy_init_seq, |
| 2133 | len/sizeof(*pdata->phy_init_seq)); |
| 2134 | } |
| 2135 | of_property_read_u32(node, "qcom,hsusb-otg-power-budget", |
| 2136 | &pdata->power_budget); |
| 2137 | of_property_read_u32(node, "qcom,hsusb-otg-mode", |
| 2138 | &pdata->mode); |
| 2139 | of_property_read_u32(node, "qcom,hsusb-otg-otg-control", |
| 2140 | &pdata->otg_control); |
| 2141 | of_property_read_u32(node, "qcom,hsusb-otg-default-mode", |
| 2142 | &pdata->default_mode); |
| 2143 | of_property_read_u32(node, "qcom,hsusb-otg-phy-type", |
| 2144 | &pdata->phy_type); |
| 2145 | of_property_read_u32(node, "qcom,hsusb-otg-pmic-id-irq", |
| 2146 | &pdata->pmic_id_irq); |
| 2147 | of_property_read_string(node, "qcom,hsusb-otg-pclk-src-name", |
| 2148 | &pdata->pclk_src_name); |
| 2149 | return pdata; |
| 2150 | } |
| 2151 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2152 | static int __init msm_otg_probe(struct platform_device *pdev) |
| 2153 | { |
| 2154 | int ret = 0; |
| 2155 | struct resource *res; |
| 2156 | struct msm_otg *motg; |
| 2157 | struct otg_transceiver *otg; |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame^] | 2158 | struct msm_otg_platform_data *pdata; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2159 | |
| 2160 | dev_info(&pdev->dev, "msm_otg probe\n"); |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame^] | 2161 | |
| 2162 | if (pdev->dev.of_node) { |
| 2163 | dev_dbg(&pdev->dev, "device tree enabled\n"); |
| 2164 | pdata = msm_otg_dt_to_pdata(pdev); |
| 2165 | if (!pdata) |
| 2166 | return -ENOMEM; |
| 2167 | ret = msm_otg_setup_devices(pdev, pdata->mode, true); |
| 2168 | if (ret) { |
| 2169 | dev_err(&pdev->dev, "devices setup failed\n"); |
| 2170 | return ret; |
| 2171 | } |
| 2172 | } else if (!pdev->dev.platform_data) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2173 | dev_err(&pdev->dev, "No platform data given. Bailing out\n"); |
| 2174 | return -ENODEV; |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame^] | 2175 | } else { |
| 2176 | pdata = pdev->dev.platform_data; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2177 | } |
| 2178 | |
| 2179 | motg = kzalloc(sizeof(struct msm_otg), GFP_KERNEL); |
| 2180 | if (!motg) { |
| 2181 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); |
| 2182 | return -ENOMEM; |
| 2183 | } |
| 2184 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2185 | the_msm_otg = motg; |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame^] | 2186 | motg->pdata = pdata; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2187 | otg = &motg->otg; |
| 2188 | otg->dev = &pdev->dev; |
| 2189 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2190 | /* |
| 2191 | * ACA ID_GND threshold range is overlapped with OTG ID_FLOAT. Hence |
| 2192 | * PHY treat ACA ID_GND as float and no interrupt is generated. But |
| 2193 | * PMIC can detect ACA ID_GND and generate an interrupt. |
| 2194 | */ |
| 2195 | if (aca_enabled() && motg->pdata->otg_control != OTG_PMIC_CONTROL) { |
| 2196 | dev_err(&pdev->dev, "ACA can not be enabled without PMIC\n"); |
| 2197 | ret = -EINVAL; |
| 2198 | goto free_motg; |
| 2199 | } |
| 2200 | |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 2201 | /* Some targets don't support PHY clock. */ |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2202 | motg->phy_reset_clk = clk_get(&pdev->dev, "usb_phy_clk"); |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 2203 | if (IS_ERR(motg->phy_reset_clk)) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2204 | dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2205 | |
| 2206 | motg->clk = clk_get(&pdev->dev, "usb_hs_clk"); |
| 2207 | if (IS_ERR(motg->clk)) { |
| 2208 | dev_err(&pdev->dev, "failed to get usb_hs_clk\n"); |
| 2209 | ret = PTR_ERR(motg->clk); |
| 2210 | goto put_phy_reset_clk; |
| 2211 | } |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 2212 | clk_set_rate(motg->clk, 60000000); |
| 2213 | |
| 2214 | /* |
| 2215 | * If USB Core is running its protocol engine based on CORE CLK, |
| 2216 | * CORE CLK must be running at >55Mhz for correct HSUSB |
| 2217 | * operation and USB core cannot tolerate frequency changes on |
| 2218 | * CORE CLK. For such USB cores, vote for maximum clk frequency |
| 2219 | * on pclk source |
| 2220 | */ |
| 2221 | if (motg->pdata->pclk_src_name) { |
| 2222 | motg->pclk_src = clk_get(&pdev->dev, |
| 2223 | motg->pdata->pclk_src_name); |
| 2224 | if (IS_ERR(motg->pclk_src)) |
| 2225 | goto put_clk; |
| 2226 | clk_set_rate(motg->pclk_src, INT_MAX); |
| 2227 | clk_enable(motg->pclk_src); |
| 2228 | } else |
| 2229 | motg->pclk_src = ERR_PTR(-ENOENT); |
| 2230 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2231 | motg->pclk = clk_get(&pdev->dev, "usb_hs_pclk"); |
| 2232 | if (IS_ERR(motg->pclk)) { |
| 2233 | dev_err(&pdev->dev, "failed to get usb_hs_pclk\n"); |
| 2234 | ret = PTR_ERR(motg->pclk); |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 2235 | goto put_pclk_src; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2236 | } |
| 2237 | |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 2238 | motg->system_clk = clk_get(&pdev->dev, "usb_hs_system_clk"); |
| 2239 | if (!IS_ERR(motg->system_clk)) |
| 2240 | clk_enable(motg->system_clk); |
| 2241 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2242 | /* |
| 2243 | * USB core clock is not present on all MSM chips. This |
| 2244 | * clock is introduced to remove the dependency on AXI |
| 2245 | * bus frequency. |
| 2246 | */ |
| 2247 | motg->core_clk = clk_get(&pdev->dev, "usb_hs_core_clk"); |
| 2248 | if (IS_ERR(motg->core_clk)) |
| 2249 | motg->core_clk = NULL; |
| 2250 | |
| 2251 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 2252 | if (!res) { |
| 2253 | dev_err(&pdev->dev, "failed to get platform resource mem\n"); |
| 2254 | ret = -ENODEV; |
| 2255 | goto put_core_clk; |
| 2256 | } |
| 2257 | |
| 2258 | motg->regs = ioremap(res->start, resource_size(res)); |
| 2259 | if (!motg->regs) { |
| 2260 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 2261 | ret = -ENOMEM; |
| 2262 | goto put_core_clk; |
| 2263 | } |
| 2264 | dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs); |
| 2265 | |
| 2266 | motg->irq = platform_get_irq(pdev, 0); |
| 2267 | if (!motg->irq) { |
| 2268 | dev_err(&pdev->dev, "platform_get_irq failed\n"); |
| 2269 | ret = -ENODEV; |
| 2270 | goto free_regs; |
| 2271 | } |
| 2272 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2273 | clk_enable(motg->pclk); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 2274 | |
| 2275 | ret = msm_hsusb_init_vddcx(motg, 1); |
| 2276 | if (ret) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2277 | dev_err(&pdev->dev, "hsusb vddcx init failed\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 2278 | goto free_regs; |
| 2279 | } |
| 2280 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2281 | ret = msm_hsusb_config_vddcx(1); |
| 2282 | if (ret) { |
| 2283 | dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); |
| 2284 | goto free_init_vddcx; |
| 2285 | } |
| 2286 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 2287 | ret = msm_hsusb_ldo_init(motg, 1); |
| 2288 | if (ret) { |
| 2289 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2290 | goto free_init_vddcx; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 2291 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2292 | |
| 2293 | ret = msm_hsusb_ldo_enable(motg, 1); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 2294 | if (ret) { |
| 2295 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2296 | goto free_ldo_init; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 2297 | } |
| 2298 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2299 | if (motg->core_clk) |
| 2300 | clk_enable(motg->core_clk); |
| 2301 | |
| 2302 | writel(0, USB_USBINTR); |
| 2303 | writel(0, USB_OTGSC); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2304 | /* Ensure that above STOREs are completed before enabling interrupts */ |
| 2305 | mb(); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2306 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2307 | wake_lock_init(&motg->wlock, WAKE_LOCK_SUSPEND, "msm_otg"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2308 | INIT_WORK(&motg->sm_work, msm_otg_sm_work); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2309 | INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2310 | setup_timer(&motg->id_timer, msm_otg_id_timer_func, |
| 2311 | (unsigned long) motg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2312 | ret = request_irq(motg->irq, msm_otg_irq, IRQF_SHARED, |
| 2313 | "msm_otg", motg); |
| 2314 | if (ret) { |
| 2315 | dev_err(&pdev->dev, "request irq failed\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2316 | goto destroy_wlock; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2317 | } |
| 2318 | |
| 2319 | otg->init = msm_otg_reset; |
| 2320 | otg->set_host = msm_otg_set_host; |
| 2321 | otg->set_peripheral = msm_otg_set_peripheral; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2322 | otg->set_power = msm_otg_set_power; |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 2323 | otg->set_suspend = msm_otg_set_suspend; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2324 | |
| 2325 | otg->io_ops = &msm_otg_io_ops; |
| 2326 | |
| 2327 | ret = otg_set_transceiver(&motg->otg); |
| 2328 | if (ret) { |
| 2329 | dev_err(&pdev->dev, "otg_set_transceiver failed\n"); |
| 2330 | goto free_irq; |
| 2331 | } |
| 2332 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2333 | if (motg->pdata->otg_control == OTG_PMIC_CONTROL) { |
| 2334 | if (motg->pdata->pmic_id_irq) { |
| 2335 | ret = request_irq(motg->pdata->pmic_id_irq, |
| 2336 | msm_pmic_id_irq, |
| 2337 | IRQF_TRIGGER_RISING | |
| 2338 | IRQF_TRIGGER_FALLING, |
| 2339 | "msm_otg", motg); |
| 2340 | if (ret) { |
| 2341 | dev_err(&pdev->dev, "request irq failed for PMIC ID\n"); |
| 2342 | goto remove_otg; |
| 2343 | } |
| 2344 | } else { |
| 2345 | ret = -ENODEV; |
| 2346 | dev_err(&pdev->dev, "PMIC IRQ for ID notifications doesn't exist\n"); |
| 2347 | goto remove_otg; |
| 2348 | } |
| 2349 | } |
| 2350 | |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 2351 | msm_hsusb_mhl_switch_enable(motg, 1); |
| 2352 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2353 | platform_set_drvdata(pdev, motg); |
| 2354 | device_init_wakeup(&pdev->dev, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2355 | motg->mA_port = IUNIT; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2356 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 2357 | ret = msm_otg_debugfs_init(motg); |
| 2358 | if (ret) |
| 2359 | dev_dbg(&pdev->dev, "mode debugfs file is" |
| 2360 | "not available\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2361 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2362 | if (motg->pdata->otg_control == OTG_PMIC_CONTROL) |
| 2363 | pm8921_charger_register_vbus_sn(&msm_otg_set_vbus_state); |
| 2364 | |
| 2365 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && |
| 2366 | motg->pdata->otg_control == OTG_PMIC_CONTROL && |
| 2367 | motg->pdata->pmic_id_irq) |
| 2368 | motg->caps = ALLOW_PHY_POWER_COLLAPSE | |
| 2369 | ALLOW_PHY_RETENTION | |
| 2370 | ALLOW_PHY_COMP_DISABLE; |
| 2371 | |
| 2372 | wake_lock(&motg->wlock); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2373 | pm_runtime_set_active(&pdev->dev); |
| 2374 | pm_runtime_enable(&pdev->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2375 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2376 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2377 | |
| 2378 | remove_otg: |
| 2379 | otg_set_transceiver(NULL); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2380 | free_irq: |
| 2381 | free_irq(motg->irq, motg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2382 | destroy_wlock: |
| 2383 | wake_lock_destroy(&motg->wlock); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2384 | clk_disable(motg->pclk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2385 | msm_hsusb_ldo_enable(motg, 0); |
| 2386 | free_ldo_init: |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 2387 | msm_hsusb_ldo_init(motg, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2388 | free_init_vddcx: |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 2389 | msm_hsusb_init_vddcx(motg, 0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2390 | free_regs: |
| 2391 | iounmap(motg->regs); |
| 2392 | put_core_clk: |
| 2393 | if (motg->core_clk) |
| 2394 | clk_put(motg->core_clk); |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 2395 | |
| 2396 | if (!IS_ERR(motg->system_clk)) { |
| 2397 | clk_disable(motg->system_clk); |
| 2398 | clk_put(motg->system_clk); |
| 2399 | } |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 2400 | put_pclk_src: |
| 2401 | if (!IS_ERR(motg->pclk_src)) { |
| 2402 | clk_disable(motg->pclk_src); |
| 2403 | clk_put(motg->pclk_src); |
| 2404 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2405 | put_clk: |
| 2406 | clk_put(motg->clk); |
| 2407 | put_phy_reset_clk: |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 2408 | if (!IS_ERR(motg->phy_reset_clk)) |
| 2409 | clk_put(motg->phy_reset_clk); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2410 | free_motg: |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2411 | kfree(motg); |
| 2412 | return ret; |
| 2413 | } |
| 2414 | |
| 2415 | static int __devexit msm_otg_remove(struct platform_device *pdev) |
| 2416 | { |
| 2417 | struct msm_otg *motg = platform_get_drvdata(pdev); |
| 2418 | struct otg_transceiver *otg = &motg->otg; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2419 | int cnt = 0; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2420 | |
| 2421 | if (otg->host || otg->gadget) |
| 2422 | return -EBUSY; |
| 2423 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame^] | 2424 | if (pdev->dev.of_node) |
| 2425 | msm_otg_setup_devices(pdev, motg->pdata->mode, false); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2426 | if (motg->pdata->otg_control == OTG_PMIC_CONTROL) |
| 2427 | pm8921_charger_unregister_vbus_sn(0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2428 | msm_otg_debugfs_cleanup(); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2429 | cancel_delayed_work_sync(&motg->chg_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2430 | cancel_work_sync(&motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2431 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 2432 | pm_runtime_resume(&pdev->dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2433 | |
| 2434 | device_init_wakeup(&pdev->dev, 0); |
| 2435 | pm_runtime_disable(&pdev->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2436 | wake_lock_destroy(&motg->wlock); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2437 | |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 2438 | msm_hsusb_mhl_switch_enable(motg, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2439 | if (motg->pdata->pmic_id_irq) |
| 2440 | free_irq(motg->pdata->pmic_id_irq, motg); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2441 | otg_set_transceiver(NULL); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2442 | free_irq(motg->irq, motg); |
| 2443 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2444 | /* |
| 2445 | * Put PHY in low power mode. |
| 2446 | */ |
| 2447 | ulpi_read(otg, 0x14); |
| 2448 | ulpi_write(otg, 0x08, 0x09); |
| 2449 | |
| 2450 | writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC); |
| 2451 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 2452 | if (readl(USB_PORTSC) & PORTSC_PHCD) |
| 2453 | break; |
| 2454 | udelay(1); |
| 2455 | cnt++; |
| 2456 | } |
| 2457 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) |
| 2458 | dev_err(otg->dev, "Unable to suspend PHY\n"); |
| 2459 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2460 | clk_disable(motg->pclk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2461 | if (motg->core_clk) |
| 2462 | clk_disable(motg->core_clk); |
Amit Blay | 137575f | 2011-11-06 15:20:54 +0200 | [diff] [blame] | 2463 | if (!IS_ERR(motg->system_clk)) |
| 2464 | clk_disable(motg->system_clk); |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 2465 | if (!IS_ERR(motg->pclk_src)) { |
| 2466 | clk_disable(motg->pclk_src); |
| 2467 | clk_put(motg->pclk_src); |
| 2468 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2469 | msm_hsusb_ldo_enable(motg, 0); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 2470 | msm_hsusb_ldo_init(motg, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2471 | msm_hsusb_init_vddcx(motg, 0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2472 | |
| 2473 | iounmap(motg->regs); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2474 | pm_runtime_set_suspended(&pdev->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2475 | |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 2476 | if (!IS_ERR(motg->phy_reset_clk)) |
| 2477 | clk_put(motg->phy_reset_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2478 | clk_put(motg->pclk); |
| 2479 | clk_put(motg->clk); |
| 2480 | if (motg->core_clk) |
| 2481 | clk_put(motg->core_clk); |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 2482 | if (!IS_ERR(motg->system_clk)) |
| 2483 | clk_put(motg->system_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2484 | |
| 2485 | kfree(motg); |
| 2486 | |
| 2487 | return 0; |
| 2488 | } |
| 2489 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2490 | #ifdef CONFIG_PM_RUNTIME |
| 2491 | static int msm_otg_runtime_idle(struct device *dev) |
| 2492 | { |
| 2493 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 2494 | struct otg_transceiver *otg = &motg->otg; |
| 2495 | |
| 2496 | dev_dbg(dev, "OTG runtime idle\n"); |
| 2497 | |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 2498 | if (otg->state == OTG_STATE_UNDEFINED) |
| 2499 | return -EAGAIN; |
| 2500 | else |
| 2501 | return 0; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | static int msm_otg_runtime_suspend(struct device *dev) |
| 2505 | { |
| 2506 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 2507 | |
| 2508 | dev_dbg(dev, "OTG runtime suspend\n"); |
| 2509 | return msm_otg_suspend(motg); |
| 2510 | } |
| 2511 | |
| 2512 | static int msm_otg_runtime_resume(struct device *dev) |
| 2513 | { |
| 2514 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 2515 | |
| 2516 | dev_dbg(dev, "OTG runtime resume\n"); |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 2517 | pm_runtime_get_noresume(dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2518 | return msm_otg_resume(motg); |
| 2519 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2520 | #endif |
| 2521 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 2522 | #ifdef CONFIG_PM_SLEEP |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2523 | static int msm_otg_pm_suspend(struct device *dev) |
| 2524 | { |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 2525 | int ret; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2526 | |
| 2527 | dev_dbg(dev, "OTG PM suspend\n"); |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 2528 | |
| 2529 | #ifdef CONFIG_PM_RUNTIME |
| 2530 | ret = pm_runtime_suspend(dev); |
| 2531 | if (ret > 0) |
| 2532 | ret = 0; |
| 2533 | #else |
| 2534 | ret = msm_otg_suspend(dev_get_drvdata(dev)); |
| 2535 | #endif |
| 2536 | return ret; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2537 | } |
| 2538 | |
| 2539 | static int msm_otg_pm_resume(struct device *dev) |
| 2540 | { |
| 2541 | struct msm_otg *motg = dev_get_drvdata(dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2542 | |
| 2543 | dev_dbg(dev, "OTG PM resume\n"); |
| 2544 | |
Manu Gautam | f284c05 | 2011-09-08 16:52:48 +0530 | [diff] [blame] | 2545 | #ifdef CONFIG_PM_RUNTIME |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2546 | /* |
Manu Gautam | f284c05 | 2011-09-08 16:52:48 +0530 | [diff] [blame] | 2547 | * Do not resume hardware as part of system resume, |
| 2548 | * rather, wait for the ASYNC INT from the h/w |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2549 | */ |
Gregory Bean | ebd8ca2 | 2011-10-11 12:02:35 -0700 | [diff] [blame] | 2550 | return 0; |
Manu Gautam | f284c05 | 2011-09-08 16:52:48 +0530 | [diff] [blame] | 2551 | #endif |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2552 | |
Manu Gautam | f284c05 | 2011-09-08 16:52:48 +0530 | [diff] [blame] | 2553 | return msm_otg_resume(motg); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2554 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2555 | #endif |
| 2556 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 2557 | #ifdef CONFIG_PM |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2558 | static const struct dev_pm_ops msm_otg_dev_pm_ops = { |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 2559 | SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume) |
| 2560 | SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume, |
| 2561 | msm_otg_runtime_idle) |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2562 | }; |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 2563 | #endif |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2564 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame^] | 2565 | static struct of_device_id msm_otg_dt_match[] = { |
| 2566 | { .compatible = "qcom,hsusb-otg", |
| 2567 | }, |
| 2568 | {} |
| 2569 | }; |
| 2570 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2571 | static struct platform_driver msm_otg_driver = { |
| 2572 | .remove = __devexit_p(msm_otg_remove), |
| 2573 | .driver = { |
| 2574 | .name = DRIVER_NAME, |
| 2575 | .owner = THIS_MODULE, |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 2576 | #ifdef CONFIG_PM |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2577 | .pm = &msm_otg_dev_pm_ops, |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 2578 | #endif |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame^] | 2579 | .of_match_table = msm_otg_dt_match, |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2580 | }, |
| 2581 | }; |
| 2582 | |
| 2583 | static int __init msm_otg_init(void) |
| 2584 | { |
| 2585 | return platform_driver_probe(&msm_otg_driver, msm_otg_probe); |
| 2586 | } |
| 2587 | |
| 2588 | static void __exit msm_otg_exit(void) |
| 2589 | { |
| 2590 | platform_driver_unregister(&msm_otg_driver); |
| 2591 | } |
| 2592 | |
| 2593 | module_init(msm_otg_init); |
| 2594 | module_exit(msm_otg_exit); |
| 2595 | |
| 2596 | MODULE_LICENSE("GPL v2"); |
| 2597 | MODULE_DESCRIPTION("MSM USB transceiver driver"); |