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