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