Pavankumar Kondeti | ebb4a2d | 2013-01-04 12:28:10 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2009-2013, Linux Foundation. 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> |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 36 | #include <linux/usb/quirks.h> |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 37 | #include <linux/usb/msm_hsusb.h> |
| 38 | #include <linux/usb/msm_hsusb_hw.h> |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 39 | #include <linux/regulator/consumer.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 40 | #include <linux/mfd/pm8xxx/pm8921-charger.h> |
Pavankumar Kondeti | 446f454 | 2012-02-01 13:57:13 +0530 | [diff] [blame] | 41 | #include <linux/mfd/pm8xxx/misc.h> |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 42 | #include <linux/mhl_8334.h> |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 43 | |
Manu Gautam | 0ddbd92 | 2012-09-21 17:17:38 +0530 | [diff] [blame] | 44 | #include <mach/scm.h> |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 45 | #include <mach/clk.h> |
Jack Pham | 87f202f | 2012-08-06 00:24:22 -0700 | [diff] [blame] | 46 | #include <mach/mpm.h> |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 47 | #include <mach/msm_xo.h> |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 48 | #include <mach/msm_bus.h> |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 49 | #include <mach/rpm-regulator.h> |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 50 | |
| 51 | #define MSM_USB_BASE (motg->regs) |
| 52 | #define DRIVER_NAME "msm_otg" |
| 53 | |
Chiranjeevi Velempati | 489a27c | 2012-03-29 09:47:17 +0530 | [diff] [blame] | 54 | #define ID_TIMER_FREQ (jiffies + msecs_to_jiffies(500)) |
Pavankumar Kondeti | 458d879 | 2012-09-28 14:45:18 +0530 | [diff] [blame] | 55 | #define CHG_RECHECK_DELAY (jiffies + msecs_to_jiffies(2000)) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 56 | #define ULPI_IO_TIMEOUT_USEC (10 * 1000) |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 57 | #define USB_PHY_3P3_VOL_MIN 3050000 /* uV */ |
| 58 | #define USB_PHY_3P3_VOL_MAX 3300000 /* uV */ |
| 59 | #define USB_PHY_3P3_HPM_LOAD 50000 /* uA */ |
| 60 | #define USB_PHY_3P3_LPM_LOAD 4000 /* uA */ |
| 61 | |
| 62 | #define USB_PHY_1P8_VOL_MIN 1800000 /* uV */ |
| 63 | #define USB_PHY_1P8_VOL_MAX 1800000 /* uV */ |
| 64 | #define USB_PHY_1P8_HPM_LOAD 50000 /* uA */ |
| 65 | #define USB_PHY_1P8_LPM_LOAD 4000 /* uA */ |
| 66 | |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 67 | #define USB_PHY_VDD_DIG_VOL_NONE 0 /*uV */ |
Vamsi Krishna | 132b276 | 2011-11-11 16:09:20 -0800 | [diff] [blame] | 68 | #define USB_PHY_VDD_DIG_VOL_MIN 1045000 /* uV */ |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 69 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
| 70 | |
Amit Blay | d0fe07b | 2012-09-05 16:42:09 +0300 | [diff] [blame] | 71 | #define USB_SUSPEND_DELAY_TIME (500 * HZ/1000) /* 500 msec */ |
| 72 | |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 73 | enum msm_otg_phy_reg_mode { |
| 74 | USB_PHY_REG_OFF, |
| 75 | USB_PHY_REG_ON, |
| 76 | USB_PHY_REG_LPM_ON, |
| 77 | USB_PHY_REG_LPM_OFF, |
| 78 | }; |
| 79 | |
Mayank Rana | 443f9e4 | 2012-09-21 18:32:39 +0530 | [diff] [blame] | 80 | static char *override_phy_init; |
| 81 | module_param(override_phy_init, charp, S_IRUGO|S_IWUSR); |
| 82 | MODULE_PARM_DESC(override_phy_init, |
| 83 | "Override HSUSB PHY Init Settings"); |
| 84 | |
Amit Blay | d6f3828 | 2012-10-29 13:13:46 +0200 | [diff] [blame] | 85 | unsigned int lpm_disconnect_thresh = 1000; |
| 86 | module_param(lpm_disconnect_thresh , uint, S_IRUGO | S_IWUSR); |
| 87 | MODULE_PARM_DESC(lpm_disconnect_thresh, |
| 88 | "Delay before entering LPM on USB disconnect"); |
| 89 | |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 90 | static DECLARE_COMPLETION(pmic_vbus_init); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 91 | static struct msm_otg *the_msm_otg; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 92 | static bool debug_aca_enabled; |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 93 | static bool debug_bus_voting_enabled; |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 94 | static bool mhl_det_in_progress; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 95 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 96 | static struct regulator *hsusb_3p3; |
| 97 | static struct regulator *hsusb_1p8; |
| 98 | static struct regulator *hsusb_vddcx; |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 99 | static struct regulator *vbus_otg; |
Pavankumar Kondeti | 56dc742 | 2012-07-02 12:45:19 +0530 | [diff] [blame] | 100 | static struct regulator *mhl_usb_hs_switch; |
Vijayavardhan Vennapusa | 05c437c | 2012-05-25 16:20:46 +0530 | [diff] [blame] | 101 | static struct power_supply *psy; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 102 | |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 103 | static bool aca_id_turned_on; |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 104 | static bool legacy_power_supply; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 105 | static inline bool aca_enabled(void) |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 106 | { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 107 | #ifdef CONFIG_USB_MSM_ACA |
| 108 | return true; |
| 109 | #else |
| 110 | return debug_aca_enabled; |
| 111 | #endif |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 112 | } |
| 113 | |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 114 | static const int vdd_val[VDD_TYPE_MAX][VDD_VAL_MAX] = { |
| 115 | { /* VDD_CX CORNER Voting */ |
| 116 | [VDD_NONE] = RPM_VREG_CORNER_NONE, |
| 117 | [VDD_MIN] = RPM_VREG_CORNER_NOMINAL, |
| 118 | [VDD_MAX] = RPM_VREG_CORNER_HIGH, |
| 119 | }, |
| 120 | { /* VDD_CX Voltage Voting */ |
| 121 | [VDD_NONE] = USB_PHY_VDD_DIG_VOL_NONE, |
| 122 | [VDD_MIN] = USB_PHY_VDD_DIG_VOL_MIN, |
| 123 | [VDD_MAX] = USB_PHY_VDD_DIG_VOL_MAX, |
| 124 | }, |
| 125 | }; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 126 | |
| 127 | static int msm_hsusb_ldo_init(struct msm_otg *motg, int init) |
| 128 | { |
| 129 | int rc = 0; |
| 130 | |
| 131 | if (init) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 132 | hsusb_3p3 = devm_regulator_get(motg->phy.dev, "HSUSB_3p3"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 133 | if (IS_ERR(hsusb_3p3)) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 134 | dev_err(motg->phy.dev, "unable to get hsusb 3p3\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 135 | return PTR_ERR(hsusb_3p3); |
| 136 | } |
| 137 | |
| 138 | rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN, |
| 139 | USB_PHY_3P3_VOL_MAX); |
| 140 | if (rc) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 141 | dev_err(motg->phy.dev, "unable to set voltage level for" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 142 | "hsusb 3p3\n"); |
Mayank Rana | 9e9a2ac | 2012-03-24 04:05:28 +0530 | [diff] [blame] | 143 | return rc; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 144 | } |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 145 | hsusb_1p8 = devm_regulator_get(motg->phy.dev, "HSUSB_1p8"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 146 | if (IS_ERR(hsusb_1p8)) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 147 | dev_err(motg->phy.dev, "unable to get hsusb 1p8\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 148 | rc = PTR_ERR(hsusb_1p8); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 149 | goto put_3p3_lpm; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 150 | } |
| 151 | rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN, |
| 152 | USB_PHY_1P8_VOL_MAX); |
| 153 | if (rc) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 154 | dev_err(motg->phy.dev, "unable to set voltage level for" |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 155 | "hsusb 1p8\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 156 | goto put_1p8; |
| 157 | } |
| 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 162 | put_1p8: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 163 | regulator_set_voltage(hsusb_1p8, 0, USB_PHY_1P8_VOL_MAX); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 164 | put_3p3_lpm: |
| 165 | regulator_set_voltage(hsusb_3p3, 0, USB_PHY_3P3_VOL_MAX); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 166 | return rc; |
| 167 | } |
| 168 | |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 169 | static int msm_hsusb_config_vddcx(int high) |
| 170 | { |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 171 | struct msm_otg *motg = the_msm_otg; |
| 172 | enum usb_vdd_type vdd_type = motg->vdd_type; |
| 173 | int max_vol = vdd_val[vdd_type][VDD_MAX]; |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 174 | int min_vol; |
| 175 | int ret; |
| 176 | |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 177 | min_vol = vdd_val[vdd_type][!!high]; |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 178 | ret = regulator_set_voltage(hsusb_vddcx, min_vol, max_vol); |
| 179 | if (ret) { |
| 180 | pr_err("%s: unable to set the voltage for regulator " |
| 181 | "HSUSB_VDDCX\n", __func__); |
| 182 | return ret; |
| 183 | } |
| 184 | |
| 185 | pr_debug("%s: min_vol:%d max_vol:%d\n", __func__, min_vol, max_vol); |
| 186 | |
| 187 | return ret; |
| 188 | } |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 189 | |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 190 | static int msm_hsusb_ldo_enable(struct msm_otg *motg, |
| 191 | enum msm_otg_phy_reg_mode mode) |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 192 | { |
| 193 | int ret = 0; |
| 194 | |
Pavankumar Kondeti | 68964c9 | 2011-10-27 14:58:56 +0530 | [diff] [blame] | 195 | if (IS_ERR(hsusb_1p8)) { |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 196 | pr_err("%s: HSUSB_1p8 is not initialized\n", __func__); |
| 197 | return -ENODEV; |
| 198 | } |
| 199 | |
Pavankumar Kondeti | 68964c9 | 2011-10-27 14:58:56 +0530 | [diff] [blame] | 200 | if (IS_ERR(hsusb_3p3)) { |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 201 | pr_err("%s: HSUSB_3p3 is not initialized\n", __func__); |
| 202 | return -ENODEV; |
| 203 | } |
| 204 | |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 205 | switch (mode) { |
| 206 | case USB_PHY_REG_ON: |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 207 | ret = regulator_set_optimum_mode(hsusb_1p8, |
| 208 | USB_PHY_1P8_HPM_LOAD); |
| 209 | if (ret < 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 210 | pr_err("%s: Unable to set HPM of the regulator:" |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 211 | "HSUSB_1p8\n", __func__); |
| 212 | return ret; |
| 213 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 214 | |
| 215 | ret = regulator_enable(hsusb_1p8); |
| 216 | if (ret) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 217 | dev_err(motg->phy.dev, "%s: unable to enable the hsusb 1p8\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 218 | __func__); |
| 219 | regulator_set_optimum_mode(hsusb_1p8, 0); |
| 220 | return ret; |
| 221 | } |
| 222 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 223 | ret = regulator_set_optimum_mode(hsusb_3p3, |
| 224 | USB_PHY_3P3_HPM_LOAD); |
| 225 | if (ret < 0) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 226 | pr_err("%s: Unable to set HPM of the regulator:" |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 227 | "HSUSB_3p3\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 228 | regulator_set_optimum_mode(hsusb_1p8, 0); |
| 229 | regulator_disable(hsusb_1p8); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 230 | return ret; |
| 231 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 232 | |
| 233 | ret = regulator_enable(hsusb_3p3); |
| 234 | if (ret) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 235 | dev_err(motg->phy.dev, "%s: unable to enable the hsusb 3p3\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 236 | __func__); |
| 237 | regulator_set_optimum_mode(hsusb_3p3, 0); |
| 238 | regulator_set_optimum_mode(hsusb_1p8, 0); |
| 239 | regulator_disable(hsusb_1p8); |
| 240 | return ret; |
| 241 | } |
| 242 | |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 243 | break; |
| 244 | |
| 245 | case USB_PHY_REG_OFF: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 246 | ret = regulator_disable(hsusb_1p8); |
| 247 | if (ret) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 248 | dev_err(motg->phy.dev, "%s: unable to disable the hsusb 1p8\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 249 | __func__); |
| 250 | return ret; |
| 251 | } |
| 252 | |
| 253 | ret = regulator_set_optimum_mode(hsusb_1p8, 0); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 254 | if (ret < 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 255 | pr_err("%s: Unable to set LPM of the regulator:" |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 256 | "HSUSB_1p8\n", __func__); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 257 | |
| 258 | ret = regulator_disable(hsusb_3p3); |
| 259 | if (ret) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 260 | dev_err(motg->phy.dev, "%s: unable to disable the hsusb 3p3\n", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 261 | __func__); |
| 262 | return ret; |
| 263 | } |
| 264 | ret = regulator_set_optimum_mode(hsusb_3p3, 0); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 265 | if (ret < 0) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 266 | pr_err("%s: Unable to set LPM of the regulator:" |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 267 | "HSUSB_3p3\n", __func__); |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 268 | |
| 269 | break; |
| 270 | |
| 271 | case USB_PHY_REG_LPM_ON: |
| 272 | ret = regulator_set_optimum_mode(hsusb_1p8, |
| 273 | USB_PHY_1P8_LPM_LOAD); |
| 274 | if (ret < 0) { |
| 275 | pr_err("%s: Unable to set LPM of the regulator: HSUSB_1p8\n", |
| 276 | __func__); |
| 277 | return ret; |
| 278 | } |
| 279 | |
| 280 | ret = regulator_set_optimum_mode(hsusb_3p3, |
| 281 | USB_PHY_3P3_LPM_LOAD); |
| 282 | if (ret < 0) { |
| 283 | pr_err("%s: Unable to set LPM of the regulator: HSUSB_3p3\n", |
| 284 | __func__); |
| 285 | regulator_set_optimum_mode(hsusb_1p8, USB_PHY_REG_ON); |
| 286 | return ret; |
| 287 | } |
| 288 | |
| 289 | break; |
| 290 | |
| 291 | case USB_PHY_REG_LPM_OFF: |
| 292 | ret = regulator_set_optimum_mode(hsusb_1p8, |
| 293 | USB_PHY_1P8_HPM_LOAD); |
| 294 | if (ret < 0) { |
| 295 | pr_err("%s: Unable to set HPM of the regulator: HSUSB_1p8\n", |
| 296 | __func__); |
| 297 | return ret; |
| 298 | } |
| 299 | |
| 300 | ret = regulator_set_optimum_mode(hsusb_3p3, |
| 301 | USB_PHY_3P3_HPM_LOAD); |
| 302 | if (ret < 0) { |
| 303 | pr_err("%s: Unable to set HPM of the regulator: HSUSB_3p3\n", |
| 304 | __func__); |
| 305 | regulator_set_optimum_mode(hsusb_1p8, USB_PHY_REG_ON); |
| 306 | return ret; |
| 307 | } |
| 308 | |
| 309 | break; |
| 310 | |
| 311 | default: |
| 312 | pr_err("%s: Unsupported mode (%d).", __func__, mode); |
| 313 | return -ENOTSUPP; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 314 | } |
| 315 | |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 316 | pr_debug("%s: USB reg mode (%d) (OFF/HPM/LPM)\n", __func__, mode); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 317 | return ret < 0 ? ret : 0; |
| 318 | } |
| 319 | |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 320 | static void msm_hsusb_mhl_switch_enable(struct msm_otg *motg, bool on) |
| 321 | { |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 322 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 323 | |
| 324 | if (!pdata->mhl_enable) |
| 325 | return; |
| 326 | |
Pavankumar Kondeti | 56dc742 | 2012-07-02 12:45:19 +0530 | [diff] [blame] | 327 | if (!mhl_usb_hs_switch) { |
| 328 | pr_err("%s: mhl_usb_hs_switch is NULL.\n", __func__); |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 329 | return; |
| 330 | } |
| 331 | |
Mayank Rana | 9e9a2ac | 2012-03-24 04:05:28 +0530 | [diff] [blame] | 332 | if (on) { |
Pavankumar Kondeti | 56dc742 | 2012-07-02 12:45:19 +0530 | [diff] [blame] | 333 | if (regulator_enable(mhl_usb_hs_switch)) |
| 334 | pr_err("unable to enable mhl_usb_hs_switch\n"); |
Mayank Rana | 9e9a2ac | 2012-03-24 04:05:28 +0530 | [diff] [blame] | 335 | } else { |
Pavankumar Kondeti | 56dc742 | 2012-07-02 12:45:19 +0530 | [diff] [blame] | 336 | regulator_disable(mhl_usb_hs_switch); |
Mayank Rana | 9e9a2ac | 2012-03-24 04:05:28 +0530 | [diff] [blame] | 337 | } |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 338 | } |
| 339 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 340 | static int ulpi_read(struct usb_phy *phy, u32 reg) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 341 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 342 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 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) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 358 | dev_err(phy->dev, "ulpi_read: timeout %08x\n", |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 359 | readl(USB_ULPI_VIEWPORT)); |
| 360 | return -ETIMEDOUT; |
| 361 | } |
| 362 | return ULPI_DATA_READ(readl(USB_ULPI_VIEWPORT)); |
| 363 | } |
| 364 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 365 | static int ulpi_write(struct usb_phy *phy, u32 val, u32 reg) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 366 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 367 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 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) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 384 | dev_err(phy->dev, "ulpi_write: timeout\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 385 | return -ETIMEDOUT; |
| 386 | } |
| 387 | return 0; |
| 388 | } |
| 389 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 390 | static struct usb_phy_io_ops msm_otg_io_ops = { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 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; |
Mayank Rana | 443f9e4 | 2012-09-21 18:32:39 +0530 | [diff] [blame] | 398 | int aseq[10]; |
| 399 | int *seq = NULL; |
| 400 | |
| 401 | if (override_phy_init) { |
| 402 | pr_debug("%s(): HUSB PHY Init:%s\n", __func__, |
| 403 | override_phy_init); |
| 404 | get_options(override_phy_init, ARRAY_SIZE(aseq), aseq); |
| 405 | seq = &aseq[1]; |
| 406 | } else { |
| 407 | seq = pdata->phy_init_seq; |
| 408 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 409 | |
| 410 | if (!seq) |
| 411 | return; |
| 412 | |
| 413 | while (seq[0] >= 0) { |
Mayank Rana | 443f9e4 | 2012-09-21 18:32:39 +0530 | [diff] [blame] | 414 | if (override_phy_init) |
| 415 | pr_debug("ulpi: write 0x%02x to 0x%02x\n", |
| 416 | seq[0], seq[1]); |
| 417 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 418 | dev_vdbg(motg->phy.dev, "ulpi: write 0x%02x to 0x%02x\n", |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 419 | seq[0], seq[1]); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 420 | ulpi_write(&motg->phy, seq[0], seq[1]); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 421 | seq += 2; |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) |
| 426 | { |
| 427 | int ret; |
| 428 | |
| 429 | if (assert) { |
Manu Gautam | 5025ff1 | 2012-07-20 10:56:50 +0530 | [diff] [blame] | 430 | if (!IS_ERR(motg->clk)) { |
| 431 | ret = clk_reset(motg->clk, CLK_RESET_ASSERT); |
| 432 | } else { |
| 433 | /* Using asynchronous block reset to the hardware */ |
| 434 | dev_dbg(motg->phy.dev, "block_reset ASSERT\n"); |
| 435 | clk_disable_unprepare(motg->pclk); |
| 436 | clk_disable_unprepare(motg->core_clk); |
| 437 | ret = clk_reset(motg->core_clk, CLK_RESET_ASSERT); |
| 438 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 439 | if (ret) |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 440 | dev_err(motg->phy.dev, "usb hs_clk assert failed\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 441 | } else { |
Manu Gautam | 5025ff1 | 2012-07-20 10:56:50 +0530 | [diff] [blame] | 442 | if (!IS_ERR(motg->clk)) { |
| 443 | ret = clk_reset(motg->clk, CLK_RESET_DEASSERT); |
| 444 | } else { |
| 445 | dev_dbg(motg->phy.dev, "block_reset DEASSERT\n"); |
| 446 | ret = clk_reset(motg->core_clk, CLK_RESET_DEASSERT); |
| 447 | ndelay(200); |
| 448 | clk_prepare_enable(motg->core_clk); |
| 449 | clk_prepare_enable(motg->pclk); |
| 450 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 451 | if (ret) |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 452 | dev_err(motg->phy.dev, "usb hs_clk deassert failed\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 453 | } |
| 454 | return ret; |
| 455 | } |
| 456 | |
| 457 | static int msm_otg_phy_clk_reset(struct msm_otg *motg) |
| 458 | { |
| 459 | int ret; |
| 460 | |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 461 | if (IS_ERR(motg->phy_reset_clk)) |
| 462 | return 0; |
| 463 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 464 | ret = clk_reset(motg->phy_reset_clk, CLK_RESET_ASSERT); |
| 465 | if (ret) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 466 | dev_err(motg->phy.dev, "usb phy clk assert failed\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 467 | return ret; |
| 468 | } |
| 469 | usleep_range(10000, 12000); |
| 470 | ret = clk_reset(motg->phy_reset_clk, CLK_RESET_DEASSERT); |
| 471 | if (ret) |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 472 | dev_err(motg->phy.dev, "usb phy clk deassert failed\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 473 | return ret; |
| 474 | } |
| 475 | |
| 476 | static int msm_otg_phy_reset(struct msm_otg *motg) |
| 477 | { |
| 478 | u32 val; |
| 479 | int ret; |
| 480 | int retries; |
| 481 | |
| 482 | ret = msm_otg_link_clk_reset(motg, 1); |
| 483 | if (ret) |
| 484 | return ret; |
| 485 | ret = msm_otg_phy_clk_reset(motg); |
| 486 | if (ret) |
| 487 | return ret; |
Amit Blay | 58dc2bc | 2013-01-24 12:28:03 +0200 | [diff] [blame^] | 488 | |
| 489 | /* |
| 490 | * 10 usec delay is required according to spec. Using larger value |
| 491 | * since the exact value proved to not work 100% of the time. |
| 492 | */ |
Bar Weiner | e7129cb | 2012-11-28 08:44:14 +0200 | [diff] [blame] | 493 | if (IS_ERR(motg->phy_reset_clk)) |
Amit Blay | 58dc2bc | 2013-01-24 12:28:03 +0200 | [diff] [blame^] | 494 | usleep_range(100, 120); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 495 | ret = msm_otg_link_clk_reset(motg, 0); |
| 496 | if (ret) |
| 497 | return ret; |
| 498 | |
| 499 | val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK; |
| 500 | writel(val | PORTSC_PTS_ULPI, USB_PORTSC); |
| 501 | |
| 502 | for (retries = 3; retries > 0; retries--) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 503 | ret = ulpi_write(&motg->phy, ULPI_FUNC_CTRL_SUSPENDM, |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 504 | ULPI_CLR(ULPI_FUNC_CTRL)); |
| 505 | if (!ret) |
| 506 | break; |
| 507 | ret = msm_otg_phy_clk_reset(motg); |
| 508 | if (ret) |
| 509 | return ret; |
| 510 | } |
| 511 | if (!retries) |
| 512 | return -ETIMEDOUT; |
| 513 | |
| 514 | /* This reset calibrates the phy, if the above write succeeded */ |
| 515 | ret = msm_otg_phy_clk_reset(motg); |
| 516 | if (ret) |
| 517 | return ret; |
| 518 | |
| 519 | for (retries = 3; retries > 0; retries--) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 520 | ret = ulpi_read(&motg->phy, ULPI_DEBUG); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 521 | if (ret != -ETIMEDOUT) |
| 522 | break; |
| 523 | ret = msm_otg_phy_clk_reset(motg); |
| 524 | if (ret) |
| 525 | return ret; |
| 526 | } |
| 527 | if (!retries) |
| 528 | return -ETIMEDOUT; |
| 529 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 530 | dev_info(motg->phy.dev, "phy_reset: success\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 531 | return 0; |
| 532 | } |
| 533 | |
| 534 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 535 | static int msm_otg_link_reset(struct msm_otg *motg) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 536 | { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 537 | int cnt = 0; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 538 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 539 | writel_relaxed(USBCMD_RESET, USB_USBCMD); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 540 | while (cnt < LINK_RESET_TIMEOUT_USEC) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 541 | if (!(readl_relaxed(USB_USBCMD) & USBCMD_RESET)) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 542 | break; |
| 543 | udelay(1); |
| 544 | cnt++; |
| 545 | } |
| 546 | if (cnt >= LINK_RESET_TIMEOUT_USEC) |
| 547 | return -ETIMEDOUT; |
| 548 | |
| 549 | /* select ULPI phy */ |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 550 | writel_relaxed(0x80000000, USB_PORTSC); |
| 551 | writel_relaxed(0x0, USB_AHBBURST); |
Vijayavardhan Vennapusa | 5f32d7a | 2012-03-14 16:30:26 +0530 | [diff] [blame] | 552 | writel_relaxed(0x08, USB_AHBMODE); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 553 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 554 | return 0; |
| 555 | } |
| 556 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 557 | static int msm_otg_reset(struct usb_phy *phy) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 558 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 559 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 560 | struct msm_otg_platform_data *pdata = motg->pdata; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 561 | int ret; |
| 562 | u32 val = 0; |
| 563 | u32 ulpi_val = 0; |
| 564 | |
Ofir Cohen | 4da266f | 2012-01-03 10:19:29 +0200 | [diff] [blame] | 565 | /* |
| 566 | * USB PHY and Link reset also reset the USB BAM. |
| 567 | * Thus perform reset operation only once to avoid |
| 568 | * USB BAM reset on other cases e.g. USB cable disconnections. |
| 569 | */ |
| 570 | if (pdata->disable_reset_on_disconnect) { |
| 571 | if (motg->reset_counter) |
| 572 | return 0; |
| 573 | else |
| 574 | motg->reset_counter++; |
| 575 | } |
| 576 | |
Pavankumar Kondeti | 923262e | 2012-04-20 15:34:24 +0530 | [diff] [blame] | 577 | if (!IS_ERR(motg->clk)) |
| 578 | clk_prepare_enable(motg->clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 579 | ret = msm_otg_phy_reset(motg); |
| 580 | if (ret) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 581 | dev_err(phy->dev, "phy_reset failed\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 582 | return ret; |
| 583 | } |
| 584 | |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 585 | aca_id_turned_on = false; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 586 | ret = msm_otg_link_reset(motg); |
| 587 | if (ret) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 588 | dev_err(phy->dev, "link reset failed\n"); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 589 | return ret; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 590 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 591 | msleep(100); |
| 592 | |
Anji jonnala | a8b8d73 | 2011-12-06 10:03:24 +0530 | [diff] [blame] | 593 | ulpi_init(motg); |
| 594 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 595 | /* Ensure that RESET operation is completed before turning off clock */ |
| 596 | mb(); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 597 | |
Pavankumar Kondeti | 923262e | 2012-04-20 15:34:24 +0530 | [diff] [blame] | 598 | if (!IS_ERR(motg->clk)) |
| 599 | clk_disable_unprepare(motg->clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 600 | |
| 601 | if (pdata->otg_control == OTG_PHY_CONTROL) { |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 602 | val = readl_relaxed(USB_OTGSC); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 603 | if (pdata->mode == USB_OTG) { |
| 604 | ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID; |
| 605 | val |= OTGSC_IDIE | OTGSC_BSVIE; |
| 606 | } else if (pdata->mode == USB_PERIPHERAL) { |
| 607 | ulpi_val = ULPI_INT_SESS_VALID; |
| 608 | val |= OTGSC_BSVIE; |
| 609 | } |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 610 | writel_relaxed(val, USB_OTGSC); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 611 | ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_RISE); |
| 612 | ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_FALL); |
Pavankumar Kondeti | 446f454 | 2012-02-01 13:57:13 +0530 | [diff] [blame] | 613 | } else if (pdata->otg_control == OTG_PMIC_CONTROL) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 614 | ulpi_write(phy, OTG_COMP_DISABLE, |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 615 | ULPI_SET(ULPI_PWR_CLK_MNG_REG)); |
Pavankumar Kondeti | 446f454 | 2012-02-01 13:57:13 +0530 | [diff] [blame] | 616 | /* Enable PMIC pull-up */ |
| 617 | pm8xxx_usb_id_pullup(1); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | return 0; |
| 621 | } |
| 622 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 623 | static const char *timer_string(int bit) |
| 624 | { |
| 625 | switch (bit) { |
| 626 | case A_WAIT_VRISE: return "a_wait_vrise"; |
| 627 | case A_WAIT_VFALL: return "a_wait_vfall"; |
| 628 | case B_SRP_FAIL: return "b_srp_fail"; |
| 629 | case A_WAIT_BCON: return "a_wait_bcon"; |
| 630 | case A_AIDL_BDIS: return "a_aidl_bdis"; |
| 631 | case A_BIDL_ADIS: return "a_bidl_adis"; |
| 632 | case B_ASE0_BRST: return "b_ase0_brst"; |
| 633 | case A_TST_MAINT: return "a_tst_maint"; |
| 634 | case B_TST_SRP: return "b_tst_srp"; |
| 635 | case B_TST_CONFIG: return "b_tst_config"; |
| 636 | default: return "UNDEFINED"; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | static enum hrtimer_restart msm_otg_timer_func(struct hrtimer *hrtimer) |
| 641 | { |
| 642 | struct msm_otg *motg = container_of(hrtimer, struct msm_otg, timer); |
| 643 | |
| 644 | switch (motg->active_tmout) { |
| 645 | case A_WAIT_VRISE: |
| 646 | /* TODO: use vbus_vld interrupt */ |
| 647 | set_bit(A_VBUS_VLD, &motg->inputs); |
| 648 | break; |
| 649 | case A_TST_MAINT: |
| 650 | /* OTG PET: End session after TA_TST_MAINT */ |
| 651 | set_bit(A_BUS_DROP, &motg->inputs); |
| 652 | break; |
| 653 | case B_TST_SRP: |
| 654 | /* |
| 655 | * OTG PET: Initiate SRP after TB_TST_SRP of |
| 656 | * previous session end. |
| 657 | */ |
| 658 | set_bit(B_BUS_REQ, &motg->inputs); |
| 659 | break; |
| 660 | case B_TST_CONFIG: |
| 661 | clear_bit(A_CONN, &motg->inputs); |
| 662 | break; |
| 663 | default: |
| 664 | set_bit(motg->active_tmout, &motg->tmouts); |
| 665 | } |
| 666 | |
| 667 | pr_debug("expired %s timer\n", timer_string(motg->active_tmout)); |
| 668 | queue_work(system_nrt_wq, &motg->sm_work); |
| 669 | return HRTIMER_NORESTART; |
| 670 | } |
| 671 | |
| 672 | static void msm_otg_del_timer(struct msm_otg *motg) |
| 673 | { |
| 674 | int bit = motg->active_tmout; |
| 675 | |
| 676 | pr_debug("deleting %s timer. remaining %lld msec\n", timer_string(bit), |
| 677 | div_s64(ktime_to_us(hrtimer_get_remaining( |
| 678 | &motg->timer)), 1000)); |
| 679 | hrtimer_cancel(&motg->timer); |
| 680 | clear_bit(bit, &motg->tmouts); |
| 681 | } |
| 682 | |
| 683 | static void msm_otg_start_timer(struct msm_otg *motg, int time, int bit) |
| 684 | { |
| 685 | clear_bit(bit, &motg->tmouts); |
| 686 | motg->active_tmout = bit; |
| 687 | pr_debug("starting %s timer\n", timer_string(bit)); |
| 688 | hrtimer_start(&motg->timer, |
| 689 | ktime_set(time / 1000, (time % 1000) * 1000000), |
| 690 | HRTIMER_MODE_REL); |
| 691 | } |
| 692 | |
| 693 | static void msm_otg_init_timer(struct msm_otg *motg) |
| 694 | { |
| 695 | hrtimer_init(&motg->timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); |
| 696 | motg->timer.function = msm_otg_timer_func; |
| 697 | } |
| 698 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 699 | static int msm_otg_start_hnp(struct usb_otg *otg) |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 700 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 701 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 702 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 703 | if (otg->phy->state != OTG_STATE_A_HOST) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 704 | pr_err("HNP can not be initiated in %s state\n", |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 705 | otg_state_string(otg->phy->state)); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 706 | return -EINVAL; |
| 707 | } |
| 708 | |
| 709 | pr_debug("A-Host: HNP initiated\n"); |
| 710 | clear_bit(A_BUS_REQ, &motg->inputs); |
| 711 | queue_work(system_nrt_wq, &motg->sm_work); |
| 712 | return 0; |
| 713 | } |
| 714 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 715 | static int msm_otg_start_srp(struct usb_otg *otg) |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 716 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 717 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 718 | u32 val; |
| 719 | int ret = 0; |
| 720 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 721 | if (otg->phy->state != OTG_STATE_B_IDLE) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 722 | pr_err("SRP can not be initiated in %s state\n", |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 723 | otg_state_string(otg->phy->state)); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 724 | ret = -EINVAL; |
| 725 | goto out; |
| 726 | } |
| 727 | |
| 728 | if ((jiffies - motg->b_last_se0_sess) < msecs_to_jiffies(TB_SRP_INIT)) { |
| 729 | pr_debug("initial conditions of SRP are not met. Try again" |
| 730 | "after some time\n"); |
| 731 | ret = -EAGAIN; |
| 732 | goto out; |
| 733 | } |
| 734 | |
| 735 | pr_debug("B-Device SRP started\n"); |
| 736 | |
| 737 | /* |
| 738 | * PHY won't pull D+ high unless it detects Vbus valid. |
| 739 | * Since by definition, SRP is only done when Vbus is not valid, |
| 740 | * software work-around needs to be used to spoof the PHY into |
| 741 | * thinking it is valid. This can be done using the VBUSVLDEXTSEL and |
| 742 | * VBUSVLDEXT register bits. |
| 743 | */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 744 | ulpi_write(otg->phy, 0x03, 0x97); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 745 | /* |
| 746 | * Harware auto assist data pulsing: Data pulse is given |
| 747 | * for 7msec; wait for vbus |
| 748 | */ |
| 749 | val = readl_relaxed(USB_OTGSC); |
| 750 | writel_relaxed((val & ~OTGSC_INTSTS_MASK) | OTGSC_HADP, USB_OTGSC); |
| 751 | |
| 752 | /* VBUS plusing is obsoleted in OTG 2.0 supplement */ |
| 753 | out: |
| 754 | return ret; |
| 755 | } |
| 756 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 757 | static void msm_otg_host_hnp_enable(struct usb_otg *otg, bool enable) |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 758 | { |
| 759 | struct usb_hcd *hcd = bus_to_hcd(otg->host); |
| 760 | struct usb_device *rhub = otg->host->root_hub; |
| 761 | |
| 762 | if (enable) { |
| 763 | pm_runtime_disable(&rhub->dev); |
| 764 | rhub->state = USB_STATE_NOTATTACHED; |
| 765 | hcd->driver->bus_suspend(hcd); |
| 766 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags); |
| 767 | } else { |
| 768 | usb_remove_hcd(hcd); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 769 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 770 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
| 771 | } |
| 772 | } |
| 773 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 774 | static int msm_otg_set_suspend(struct usb_phy *phy, int suspend) |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 775 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 776 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 777 | |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 778 | if (aca_enabled()) |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 779 | return 0; |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 780 | |
Pavankumar Kondeti | e618bf8 | 2012-11-28 21:12:44 +0530 | [diff] [blame] | 781 | /* |
| 782 | * UDC and HCD call usb_phy_set_suspend() to enter/exit LPM |
| 783 | * during bus suspend/resume. Update the relevant state |
| 784 | * machine inputs and trigger LPM entry/exit. Checking |
| 785 | * in_lpm flag would avoid unnecessary work scheduling. |
| 786 | */ |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 787 | if (suspend) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 788 | switch (phy->state) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 789 | case OTG_STATE_A_WAIT_BCON: |
| 790 | if (TA_WAIT_BCON > 0) |
| 791 | break; |
| 792 | /* fall through */ |
| 793 | case OTG_STATE_A_HOST: |
| 794 | pr_debug("host bus suspend\n"); |
| 795 | clear_bit(A_BUS_REQ, &motg->inputs); |
Pavankumar Kondeti | e618bf8 | 2012-11-28 21:12:44 +0530 | [diff] [blame] | 796 | if (!atomic_read(&motg->in_lpm)) |
| 797 | queue_work(system_nrt_wq, &motg->sm_work); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 798 | break; |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 799 | case OTG_STATE_B_PERIPHERAL: |
| 800 | pr_debug("peripheral bus suspend\n"); |
| 801 | if (!(motg->caps & ALLOW_LPM_ON_DEV_SUSPEND)) |
| 802 | break; |
| 803 | set_bit(A_BUS_SUSPEND, &motg->inputs); |
Pavankumar Kondeti | e618bf8 | 2012-11-28 21:12:44 +0530 | [diff] [blame] | 804 | if (!atomic_read(&motg->in_lpm)) |
| 805 | queue_delayed_work(system_nrt_wq, |
| 806 | &motg->suspend_work, |
| 807 | USB_SUSPEND_DELAY_TIME); |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 808 | break; |
| 809 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 810 | default: |
| 811 | break; |
| 812 | } |
| 813 | } else { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 814 | switch (phy->state) { |
Pavankumar Kondeti | e618bf8 | 2012-11-28 21:12:44 +0530 | [diff] [blame] | 815 | case OTG_STATE_A_WAIT_BCON: |
| 816 | /* Remote wakeup or resume */ |
| 817 | set_bit(A_BUS_REQ, &motg->inputs); |
| 818 | /* ensure hardware is not in low power mode */ |
| 819 | if (atomic_read(&motg->in_lpm)) |
| 820 | pm_runtime_resume(phy->dev); |
| 821 | break; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 822 | case OTG_STATE_A_SUSPEND: |
| 823 | /* Remote wakeup or resume */ |
| 824 | set_bit(A_BUS_REQ, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 825 | phy->state = OTG_STATE_A_HOST; |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 826 | |
| 827 | /* ensure hardware is not in low power mode */ |
Pavankumar Kondeti | e618bf8 | 2012-11-28 21:12:44 +0530 | [diff] [blame] | 828 | if (atomic_read(&motg->in_lpm)) |
| 829 | pm_runtime_resume(phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 830 | break; |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 831 | case OTG_STATE_B_PERIPHERAL: |
| 832 | pr_debug("peripheral bus resume\n"); |
| 833 | if (!(motg->caps & ALLOW_LPM_ON_DEV_SUSPEND)) |
| 834 | break; |
| 835 | clear_bit(A_BUS_SUSPEND, &motg->inputs); |
Pavankumar Kondeti | e618bf8 | 2012-11-28 21:12:44 +0530 | [diff] [blame] | 836 | if (atomic_read(&motg->in_lpm)) |
| 837 | queue_work(system_nrt_wq, &motg->sm_work); |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 838 | break; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 839 | default: |
| 840 | break; |
| 841 | } |
| 842 | } |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 843 | return 0; |
| 844 | } |
| 845 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 846 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 847 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) |
| 848 | |
| 849 | #ifdef CONFIG_PM_SLEEP |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 850 | static int msm_otg_suspend(struct msm_otg *motg) |
| 851 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 852 | struct usb_phy *phy = &motg->phy; |
| 853 | struct usb_bus *bus = phy->otg->host; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 854 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 855 | int cnt = 0; |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 856 | bool host_bus_suspend, device_bus_suspend, dcp; |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 857 | u32 phy_ctrl_val = 0, cmd_val; |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 858 | unsigned ret; |
Rajkumar Raghupathy | 242565d | 2011-12-13 12:10:59 +0530 | [diff] [blame] | 859 | u32 portsc; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 860 | |
| 861 | if (atomic_read(&motg->in_lpm)) |
| 862 | return 0; |
| 863 | |
| 864 | disable_irq(motg->irq); |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 865 | host_bus_suspend = !test_bit(MHL, &motg->inputs) && phy->otg->host && |
| 866 | !test_bit(ID, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 867 | device_bus_suspend = phy->otg->gadget && test_bit(ID, &motg->inputs) && |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 868 | test_bit(A_BUS_SUSPEND, &motg->inputs) && |
| 869 | motg->caps & ALLOW_LPM_ON_DEV_SUSPEND; |
Pavankumar Kondeti | 283146f | 2012-01-12 12:51:19 +0530 | [diff] [blame] | 870 | dcp = motg->chg_type == USB_DCP_CHARGER; |
Jack Pham | 502bea3 | 2012-08-13 15:34:20 -0700 | [diff] [blame] | 871 | |
Pavankumar Kondeti | cfe0539 | 2012-10-22 13:21:19 +0530 | [diff] [blame] | 872 | /* |
| 873 | * Abort suspend when, |
| 874 | * 1. charging detection in progress due to cable plug-in |
| 875 | * 2. host mode activation in progress due to Micro-A cable insertion |
| 876 | */ |
| 877 | |
| 878 | if ((test_bit(B_SESS_VLD, &motg->inputs) && !device_bus_suspend && |
| 879 | !dcp) || test_bit(A_BUS_REQ, &motg->inputs)) { |
Jack Pham | 502bea3 | 2012-08-13 15:34:20 -0700 | [diff] [blame] | 880 | enable_irq(motg->irq); |
| 881 | return -EBUSY; |
| 882 | } |
| 883 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 884 | /* |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 885 | * Chipidea 45-nm PHY suspend sequence: |
| 886 | * |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 887 | * Interrupt Latch Register auto-clear feature is not present |
| 888 | * in all PHY versions. Latch register is clear on read type. |
| 889 | * Clear latch register to avoid spurious wakeup from |
| 890 | * low power mode (LPM). |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 891 | * |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 892 | * PHY comparators are disabled when PHY enters into low power |
| 893 | * mode (LPM). Keep PHY comparators ON in LPM only when we expect |
| 894 | * VBUS/Id notifications from USB PHY. Otherwise turn off USB |
| 895 | * PHY comparators. This save significant amount of power. |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 896 | * |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 897 | * PLL is not turned off when PHY enters into low power mode (LPM). |
| 898 | * Disable PLL for maximum power savings. |
| 899 | */ |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 900 | |
| 901 | if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 902 | ulpi_read(phy, 0x14); |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 903 | if (pdata->otg_control == OTG_PHY_CONTROL) |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 904 | ulpi_write(phy, 0x01, 0x30); |
| 905 | ulpi_write(phy, 0x08, 0x09); |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 906 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 907 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 908 | |
Rajkumar Raghupathy | 242565d | 2011-12-13 12:10:59 +0530 | [diff] [blame] | 909 | /* 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] | 910 | * PHY may take some time or even fail to enter into low power |
| 911 | * mode (LPM). Hence poll for 500 msec and reset the PHY and link |
| 912 | * in failure case. |
| 913 | */ |
Rajkumar Raghupathy | 242565d | 2011-12-13 12:10:59 +0530 | [diff] [blame] | 914 | portsc = readl_relaxed(USB_PORTSC); |
| 915 | if (!(portsc & PORTSC_PHCD)) { |
| 916 | writel_relaxed(portsc | PORTSC_PHCD, |
| 917 | USB_PORTSC); |
| 918 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 919 | if (readl_relaxed(USB_PORTSC) & PORTSC_PHCD) |
| 920 | break; |
| 921 | udelay(1); |
| 922 | cnt++; |
| 923 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 927 | dev_err(phy->dev, "Unable to suspend PHY\n"); |
| 928 | msm_otg_reset(phy); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 929 | enable_irq(motg->irq); |
| 930 | return -ETIMEDOUT; |
| 931 | } |
| 932 | |
| 933 | /* |
| 934 | * PHY has capability to generate interrupt asynchronously in low |
| 935 | * power mode (LPM). This interrupt is level triggered. So USB IRQ |
| 936 | * line must be disabled till async interrupt enable bit is cleared |
| 937 | * in USBCMD register. Assert STP (ULPI interface STOP signal) to |
| 938 | * block data communication from PHY. |
Pavankumar Kondeti | 6be675f | 2012-04-16 13:29:24 +0530 | [diff] [blame] | 939 | * |
| 940 | * PHY retention mode is disallowed while entering to LPM with wall |
| 941 | * charger connected. But PHY is put into suspend mode. Hence |
| 942 | * enable asynchronous interrupt to detect charger disconnection when |
| 943 | * PMIC notifications are unavailable. |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 944 | */ |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 945 | cmd_val = readl_relaxed(USB_USBCMD); |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 946 | if (host_bus_suspend || device_bus_suspend || |
| 947 | (motg->pdata->otg_control == OTG_PHY_CONTROL && dcp)) |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 948 | cmd_val |= ASYNC_INTR_CTRL | ULPI_STP_CTRL; |
| 949 | else |
| 950 | cmd_val |= ULPI_STP_CTRL; |
| 951 | writel_relaxed(cmd_val, USB_USBCMD); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 952 | |
Pavankumar Kondeti | 283146f | 2012-01-12 12:51:19 +0530 | [diff] [blame] | 953 | /* |
| 954 | * BC1.2 spec mandates PD to enable VDP_SRC when charging from DCP. |
| 955 | * PHY retention and collapse can not happen with VDP_SRC enabled. |
| 956 | */ |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 957 | if (motg->caps & ALLOW_PHY_RETENTION && !host_bus_suspend && |
| 958 | !device_bus_suspend && !dcp) { |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 959 | phy_ctrl_val = readl_relaxed(USB_PHY_CTRL); |
Vijayavardhan Vennapusa | 9ab6f97 | 2012-10-11 19:18:55 +0530 | [diff] [blame] | 960 | if (motg->pdata->otg_control == OTG_PHY_CONTROL) { |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 961 | /* Enable PHY HV interrupts to wake MPM/Link */ |
Vijayavardhan Vennapusa | 9ab6f97 | 2012-10-11 19:18:55 +0530 | [diff] [blame] | 962 | if ((motg->pdata->mode == USB_OTG) || |
| 963 | (motg->pdata->mode == USB_HOST)) |
| 964 | phy_ctrl_val |= (PHY_IDHV_INTEN | |
| 965 | PHY_OTGSESSVLDHV_INTEN); |
| 966 | else |
| 967 | phy_ctrl_val |= PHY_OTGSESSVLDHV_INTEN; |
| 968 | } |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 969 | |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 970 | writel_relaxed(phy_ctrl_val & ~PHY_RETEN, USB_PHY_CTRL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 971 | motg->lpm_flags |= PHY_RETENTIONED; |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 972 | } |
| 973 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 974 | /* Ensure that above operation is completed before turning off clocks */ |
| 975 | mb(); |
Ido Shayevitz | c5c0f57 | 2012-07-31 13:58:45 +0300 | [diff] [blame] | 976 | /* Consider clocks on workaround flag only in case of bus suspend */ |
| 977 | if (!(phy->state == OTG_STATE_B_PERIPHERAL && |
| 978 | test_bit(A_BUS_SUSPEND, &motg->inputs)) || |
| 979 | !motg->pdata->core_clk_always_on_workaround) { |
Amit Blay | 9b6e58b | 2012-06-18 13:12:49 +0300 | [diff] [blame] | 980 | clk_disable_unprepare(motg->pclk); |
| 981 | clk_disable_unprepare(motg->core_clk); |
Ido Shayevitz | c5c0f57 | 2012-07-31 13:58:45 +0300 | [diff] [blame] | 982 | motg->lpm_flags |= CLOCKS_DOWN; |
Amit Blay | 9b6e58b | 2012-06-18 13:12:49 +0300 | [diff] [blame] | 983 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 984 | |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 985 | /* usb phy no more require TCXO clock, hence vote for TCXO disable */ |
Vijayavardhan Vennapusa | bbdd608 | 2012-06-06 14:14:25 +0530 | [diff] [blame] | 986 | if (!host_bus_suspend) { |
| 987 | ret = msm_xo_mode_vote(motg->xo_handle, MSM_XO_MODE_OFF); |
| 988 | if (ret) |
Steve Muckle | 75c34ca | 2012-06-12 14:27:40 -0700 | [diff] [blame] | 989 | dev_err(phy->dev, "%s failed to devote for " |
Vijayavardhan Vennapusa | bbdd608 | 2012-06-06 14:14:25 +0530 | [diff] [blame] | 990 | "TCXO D0 buffer%d\n", __func__, ret); |
| 991 | else |
| 992 | motg->lpm_flags |= XO_SHUTDOWN; |
| 993 | } |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 994 | |
Pavankumar Kondeti | 283146f | 2012-01-12 12:51:19 +0530 | [diff] [blame] | 995 | if (motg->caps & ALLOW_PHY_POWER_COLLAPSE && |
| 996 | !host_bus_suspend && !dcp) { |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 997 | msm_hsusb_ldo_enable(motg, USB_PHY_REG_OFF); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 998 | motg->lpm_flags |= PHY_PWR_COLLAPSED; |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 999 | } else if (motg->caps & ALLOW_PHY_REGULATORS_LPM && |
| 1000 | !host_bus_suspend && !device_bus_suspend && !dcp) { |
| 1001 | msm_hsusb_ldo_enable(motg, USB_PHY_REG_LPM_ON); |
| 1002 | motg->lpm_flags |= PHY_REGULATORS_LPM; |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 1003 | } |
| 1004 | |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 1005 | if (motg->lpm_flags & PHY_RETENTIONED) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1006 | msm_hsusb_config_vddcx(0); |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 1007 | msm_hsusb_mhl_switch_enable(motg, 0); |
| 1008 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1009 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1010 | if (device_may_wakeup(phy->dev)) { |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1011 | enable_irq_wake(motg->irq); |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 1012 | if (motg->async_irq) |
| 1013 | enable_irq_wake(motg->async_irq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1014 | if (motg->pdata->pmic_id_irq) |
| 1015 | enable_irq_wake(motg->pdata->pmic_id_irq); |
Jack Pham | 87f202f | 2012-08-06 00:24:22 -0700 | [diff] [blame] | 1016 | if (pdata->otg_control == OTG_PHY_CONTROL && |
| 1017 | pdata->mpm_otgsessvld_int) |
| 1018 | msm_mpm_set_pin_wake(pdata->mpm_otgsessvld_int, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1019 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1020 | if (bus) |
| 1021 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags); |
| 1022 | |
| 1023 | atomic_set(&motg->in_lpm, 1); |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 1024 | /* Enable ASYNC IRQ (if present) during LPM */ |
| 1025 | if (motg->async_irq) |
| 1026 | enable_irq(motg->async_irq); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1027 | enable_irq(motg->irq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1028 | wake_unlock(&motg->wlock); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1029 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1030 | dev_info(phy->dev, "USB in low power mode\n"); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1035 | static int msm_otg_resume(struct msm_otg *motg) |
| 1036 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1037 | struct usb_phy *phy = &motg->phy; |
| 1038 | struct usb_bus *bus = phy->otg->host; |
Jack Pham | 87f202f | 2012-08-06 00:24:22 -0700 | [diff] [blame] | 1039 | struct msm_otg_platform_data *pdata = motg->pdata; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1040 | int cnt = 0; |
| 1041 | unsigned temp; |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 1042 | u32 phy_ctrl_val = 0; |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 1043 | unsigned ret; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1044 | |
| 1045 | if (!atomic_read(&motg->in_lpm)) |
| 1046 | return 0; |
| 1047 | |
Jack Pham | 8978b89 | 2012-10-17 16:31:39 -0700 | [diff] [blame] | 1048 | disable_irq(motg->irq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1049 | wake_lock(&motg->wlock); |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 1050 | |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 1051 | /* Vote for TCXO when waking up the phy */ |
Vijayavardhan Vennapusa | bbdd608 | 2012-06-06 14:14:25 +0530 | [diff] [blame] | 1052 | if (motg->lpm_flags & XO_SHUTDOWN) { |
| 1053 | ret = msm_xo_mode_vote(motg->xo_handle, MSM_XO_MODE_ON); |
| 1054 | if (ret) |
Steve Muckle | 75c34ca | 2012-06-12 14:27:40 -0700 | [diff] [blame] | 1055 | dev_err(phy->dev, "%s failed to vote for " |
Vijayavardhan Vennapusa | bbdd608 | 2012-06-06 14:14:25 +0530 | [diff] [blame] | 1056 | "TCXO D0 buffer%d\n", __func__, ret); |
| 1057 | motg->lpm_flags &= ~XO_SHUTDOWN; |
| 1058 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1059 | |
Ido Shayevitz | c5c0f57 | 2012-07-31 13:58:45 +0300 | [diff] [blame] | 1060 | if (motg->lpm_flags & CLOCKS_DOWN) { |
Amit Blay | 9b6e58b | 2012-06-18 13:12:49 +0300 | [diff] [blame] | 1061 | clk_prepare_enable(motg->core_clk); |
| 1062 | clk_prepare_enable(motg->pclk); |
Ido Shayevitz | c5c0f57 | 2012-07-31 13:58:45 +0300 | [diff] [blame] | 1063 | motg->lpm_flags &= ~CLOCKS_DOWN; |
Amit Blay | 9b6e58b | 2012-06-18 13:12:49 +0300 | [diff] [blame] | 1064 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1065 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1066 | if (motg->lpm_flags & PHY_PWR_COLLAPSED) { |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 1067 | msm_hsusb_ldo_enable(motg, USB_PHY_REG_ON); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1068 | motg->lpm_flags &= ~PHY_PWR_COLLAPSED; |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 1069 | } else if (motg->lpm_flags & PHY_REGULATORS_LPM) { |
| 1070 | msm_hsusb_ldo_enable(motg, USB_PHY_REG_LPM_OFF); |
| 1071 | motg->lpm_flags &= ~PHY_REGULATORS_LPM; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | if (motg->lpm_flags & PHY_RETENTIONED) { |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 1075 | msm_hsusb_mhl_switch_enable(motg, 1); |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 1076 | msm_hsusb_config_vddcx(1); |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 1077 | phy_ctrl_val = readl_relaxed(USB_PHY_CTRL); |
| 1078 | phy_ctrl_val |= PHY_RETEN; |
| 1079 | if (motg->pdata->otg_control == OTG_PHY_CONTROL) |
| 1080 | /* Disable PHY HV interrupts */ |
| 1081 | phy_ctrl_val &= |
| 1082 | ~(PHY_IDHV_INTEN | PHY_OTGSESSVLDHV_INTEN); |
| 1083 | writel_relaxed(phy_ctrl_val, USB_PHY_CTRL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1084 | motg->lpm_flags &= ~PHY_RETENTIONED; |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 1085 | } |
| 1086 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1087 | temp = readl(USB_USBCMD); |
| 1088 | temp &= ~ASYNC_INTR_CTRL; |
| 1089 | temp &= ~ULPI_STP_CTRL; |
| 1090 | writel(temp, USB_USBCMD); |
| 1091 | |
| 1092 | /* |
| 1093 | * PHY comes out of low power mode (LPM) in case of wakeup |
| 1094 | * from asynchronous interrupt. |
| 1095 | */ |
| 1096 | if (!(readl(USB_PORTSC) & PORTSC_PHCD)) |
| 1097 | goto skip_phy_resume; |
| 1098 | |
| 1099 | writel(readl(USB_PORTSC) & ~PORTSC_PHCD, USB_PORTSC); |
| 1100 | while (cnt < PHY_RESUME_TIMEOUT_USEC) { |
| 1101 | if (!(readl(USB_PORTSC) & PORTSC_PHCD)) |
| 1102 | break; |
| 1103 | udelay(1); |
| 1104 | cnt++; |
| 1105 | } |
| 1106 | |
| 1107 | if (cnt >= PHY_RESUME_TIMEOUT_USEC) { |
| 1108 | /* |
| 1109 | * This is a fatal error. Reset the link and |
| 1110 | * PHY. USB state can not be restored. Re-insertion |
| 1111 | * of USB cable is the only way to get USB working. |
| 1112 | */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1113 | dev_err(phy->dev, "Unable to resume USB." |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1114 | "Re-plugin the cable\n"); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1115 | msm_otg_reset(phy); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | skip_phy_resume: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1119 | if (device_may_wakeup(phy->dev)) { |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1120 | disable_irq_wake(motg->irq); |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 1121 | if (motg->async_irq) |
| 1122 | disable_irq_wake(motg->async_irq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1123 | if (motg->pdata->pmic_id_irq) |
| 1124 | disable_irq_wake(motg->pdata->pmic_id_irq); |
Jack Pham | 87f202f | 2012-08-06 00:24:22 -0700 | [diff] [blame] | 1125 | if (pdata->otg_control == OTG_PHY_CONTROL && |
| 1126 | pdata->mpm_otgsessvld_int) |
| 1127 | msm_mpm_set_pin_wake(pdata->mpm_otgsessvld_int, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1128 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1129 | if (bus) |
| 1130 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags); |
| 1131 | |
Pavankumar Kondeti | 2ce2c3a | 2011-05-02 11:56:33 +0530 | [diff] [blame] | 1132 | atomic_set(&motg->in_lpm, 0); |
| 1133 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1134 | if (motg->async_int) { |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 1135 | /* Match the disable_irq call from ISR */ |
| 1136 | enable_irq(motg->async_int); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1137 | motg->async_int = 0; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1138 | } |
Jack Pham | 8978b89 | 2012-10-17 16:31:39 -0700 | [diff] [blame] | 1139 | enable_irq(motg->irq); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1140 | |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 1141 | /* If ASYNC IRQ is present then keep it enabled only during LPM */ |
| 1142 | if (motg->async_irq) |
| 1143 | disable_irq(motg->async_irq); |
| 1144 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1145 | dev_info(phy->dev, "USB exited from low power mode\n"); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1146 | |
| 1147 | return 0; |
| 1148 | } |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 1149 | #endif |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1150 | |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1151 | static void msm_otg_notify_host_mode(struct msm_otg *motg, bool host_mode) |
Abhijeet Dharmapurikar | 5e96aaa | 2012-06-26 11:21:03 -0700 | [diff] [blame] | 1152 | { |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1153 | if (!psy) { |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1154 | pr_err("No USB power supply registered!\n"); |
| 1155 | return; |
| 1156 | } |
Sridhar Parasuram | 3c67a41 | 2012-09-26 09:36:22 -0700 | [diff] [blame] | 1157 | |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1158 | if (legacy_power_supply) { |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1159 | /* legacy support */ |
Pavankumar Kondeti | 811cab3 | 2012-11-09 20:51:36 +0530 | [diff] [blame] | 1160 | if (host_mode) { |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1161 | power_supply_set_scope(psy, POWER_SUPPLY_SCOPE_SYSTEM); |
Pavankumar Kondeti | 811cab3 | 2012-11-09 20:51:36 +0530 | [diff] [blame] | 1162 | } else { |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1163 | power_supply_set_scope(psy, POWER_SUPPLY_SCOPE_DEVICE); |
Pavankumar Kondeti | 811cab3 | 2012-11-09 20:51:36 +0530 | [diff] [blame] | 1164 | /* |
| 1165 | * VBUS comparator is disabled by PMIC charging driver |
| 1166 | * when SYSTEM scope is selected. For ID_GND->ID_A |
| 1167 | * transition, give 50 msec delay so that PMIC charger |
| 1168 | * driver detect the VBUS and ready for accepting |
| 1169 | * charging current value from USB. |
| 1170 | */ |
| 1171 | if (test_bit(ID_A, &motg->inputs)) |
| 1172 | msleep(50); |
| 1173 | } |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1174 | } else { |
| 1175 | motg->host_mode = host_mode; |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1176 | power_supply_changed(psy); |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1177 | } |
Abhijeet Dharmapurikar | 5e96aaa | 2012-06-26 11:21:03 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
David Keitel | 081a3e2 | 2012-04-18 12:37:07 -0700 | [diff] [blame] | 1180 | static int msm_otg_notify_chg_type(struct msm_otg *motg) |
| 1181 | { |
| 1182 | static int charger_type; |
David Keitel | ba8f832 | 2012-06-01 17:14:10 -0700 | [diff] [blame] | 1183 | |
David Keitel | 081a3e2 | 2012-04-18 12:37:07 -0700 | [diff] [blame] | 1184 | /* |
| 1185 | * TODO |
| 1186 | * Unify OTG driver charger types and power supply charger types |
| 1187 | */ |
| 1188 | if (charger_type == motg->chg_type) |
| 1189 | return 0; |
| 1190 | |
| 1191 | if (motg->chg_type == USB_SDP_CHARGER) |
| 1192 | charger_type = POWER_SUPPLY_TYPE_USB; |
| 1193 | else if (motg->chg_type == USB_CDP_CHARGER) |
| 1194 | charger_type = POWER_SUPPLY_TYPE_USB_CDP; |
Pavankumar Kondeti | 9ec21d3 | 2012-05-07 15:50:23 +0530 | [diff] [blame] | 1195 | else if (motg->chg_type == USB_DCP_CHARGER || |
| 1196 | motg->chg_type == USB_PROPRIETARY_CHARGER) |
David Keitel | 081a3e2 | 2012-04-18 12:37:07 -0700 | [diff] [blame] | 1197 | charger_type = POWER_SUPPLY_TYPE_USB_DCP; |
| 1198 | else if ((motg->chg_type == USB_ACA_DOCK_CHARGER || |
| 1199 | motg->chg_type == USB_ACA_A_CHARGER || |
| 1200 | motg->chg_type == USB_ACA_B_CHARGER || |
| 1201 | motg->chg_type == USB_ACA_C_CHARGER)) |
| 1202 | charger_type = POWER_SUPPLY_TYPE_USB_ACA; |
| 1203 | else |
Anirudh Ghayal | 685a6a5 | 2013-01-08 18:28:55 +0530 | [diff] [blame] | 1204 | charger_type = POWER_SUPPLY_TYPE_UNKNOWN; |
David Keitel | 081a3e2 | 2012-04-18 12:37:07 -0700 | [diff] [blame] | 1205 | |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1206 | if (!psy) { |
David Keitel | ba8f832 | 2012-06-01 17:14:10 -0700 | [diff] [blame] | 1207 | pr_err("No USB power supply registered!\n"); |
| 1208 | return -EINVAL; |
| 1209 | } |
| 1210 | |
| 1211 | pr_debug("setting usb power supply type %d\n", charger_type); |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1212 | power_supply_set_supply_type(psy, charger_type); |
David Keitel | ba8f832 | 2012-06-01 17:14:10 -0700 | [diff] [blame] | 1213 | return 0; |
David Keitel | 081a3e2 | 2012-04-18 12:37:07 -0700 | [diff] [blame] | 1214 | } |
| 1215 | |
Amit Blay | 0f7edf7 | 2012-01-15 10:11:27 +0200 | [diff] [blame] | 1216 | static int msm_otg_notify_power_supply(struct msm_otg *motg, unsigned mA) |
| 1217 | { |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1218 | if (!psy) { |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1219 | dev_dbg(motg->phy.dev, "no usb power supply registered\n"); |
| 1220 | goto psy_error; |
David Keitel | f5c5d60 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1221 | } |
| 1222 | |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1223 | if (motg->cur_power == 0 && mA > 2) { |
| 1224 | /* Enable charging */ |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1225 | if (power_supply_set_online(psy, true)) |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1226 | goto psy_error; |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1227 | if (power_supply_set_current_limit(psy, 1000*mA)) |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1228 | goto psy_error; |
| 1229 | } else if (motg->cur_power > 0 && (mA == 0 || mA == 2)) { |
| 1230 | /* Disable charging */ |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1231 | if (power_supply_set_online(psy, false)) |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1232 | goto psy_error; |
| 1233 | /* Set max current limit */ |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1234 | if (power_supply_set_current_limit(psy, 0)) |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1235 | goto psy_error; |
| 1236 | } |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 1237 | power_supply_changed(psy); |
Amit Blay | 0f7edf7 | 2012-01-15 10:11:27 +0200 | [diff] [blame] | 1238 | return 0; |
| 1239 | |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 1240 | psy_error: |
| 1241 | dev_dbg(motg->phy.dev, "power supply error when setting property\n"); |
Amit Blay | 0f7edf7 | 2012-01-15 10:11:27 +0200 | [diff] [blame] | 1242 | return -ENXIO; |
| 1243 | } |
| 1244 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1245 | static void msm_otg_notify_charger(struct msm_otg *motg, unsigned mA) |
| 1246 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1247 | struct usb_gadget *g = motg->phy.otg->gadget; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1248 | |
| 1249 | if (g && g->is_a_peripheral) |
| 1250 | return; |
| 1251 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1252 | if ((motg->chg_type == USB_ACA_DOCK_CHARGER || |
| 1253 | motg->chg_type == USB_ACA_A_CHARGER || |
| 1254 | motg->chg_type == USB_ACA_B_CHARGER || |
| 1255 | motg->chg_type == USB_ACA_C_CHARGER) && |
| 1256 | mA > IDEV_ACA_CHG_LIMIT) |
| 1257 | mA = IDEV_ACA_CHG_LIMIT; |
| 1258 | |
David Keitel | 081a3e2 | 2012-04-18 12:37:07 -0700 | [diff] [blame] | 1259 | if (msm_otg_notify_chg_type(motg)) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1260 | dev_err(motg->phy.dev, |
David Keitel | 081a3e2 | 2012-04-18 12:37:07 -0700 | [diff] [blame] | 1261 | "Failed notifying %d charger type to PMIC\n", |
| 1262 | motg->chg_type); |
| 1263 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1264 | if (motg->cur_power == mA) |
| 1265 | return; |
| 1266 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1267 | dev_info(motg->phy.dev, "Avail curr from USB = %u\n", mA); |
Amit Blay | 0f7edf7 | 2012-01-15 10:11:27 +0200 | [diff] [blame] | 1268 | |
| 1269 | /* |
| 1270 | * Use Power Supply API if supported, otherwise fallback |
| 1271 | * to legacy pm8921 API. |
| 1272 | */ |
| 1273 | if (msm_otg_notify_power_supply(motg, mA)) |
| 1274 | pm8921_charger_vbus_draw(mA); |
| 1275 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1276 | motg->cur_power = mA; |
| 1277 | } |
| 1278 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1279 | static int msm_otg_set_power(struct usb_phy *phy, unsigned mA) |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1280 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1281 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1282 | |
| 1283 | /* |
| 1284 | * Gadget driver uses set_power method to notify about the |
| 1285 | * available current based on suspend/configured states. |
| 1286 | * |
| 1287 | * IDEV_CHG can be drawn irrespective of suspend/un-configured |
| 1288 | * states when CDP/ACA is connected. |
| 1289 | */ |
| 1290 | if (motg->chg_type == USB_SDP_CHARGER) |
| 1291 | msm_otg_notify_charger(motg, mA); |
| 1292 | |
| 1293 | return 0; |
| 1294 | } |
| 1295 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1296 | static void msm_otg_start_host(struct usb_otg *otg, int on) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1297 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1298 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1299 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 1300 | struct usb_hcd *hcd; |
| 1301 | |
| 1302 | if (!otg->host) |
| 1303 | return; |
| 1304 | |
| 1305 | hcd = bus_to_hcd(otg->host); |
| 1306 | |
| 1307 | if (on) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1308 | dev_dbg(otg->phy->dev, "host on\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1309 | |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 1310 | if (pdata->otg_control == OTG_PHY_CONTROL) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1311 | ulpi_write(otg->phy, OTG_COMP_DISABLE, |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 1312 | ULPI_SET(ULPI_PWR_CLK_MNG_REG)); |
| 1313 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1314 | /* |
| 1315 | * Some boards have a switch cotrolled by gpio |
| 1316 | * to enable/disable internal HUB. Enable internal |
| 1317 | * HUB before kicking the host. |
| 1318 | */ |
| 1319 | if (pdata->setup_gpio) |
| 1320 | pdata->setup_gpio(OTG_STATE_A_HOST); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1321 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1322 | } else { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1323 | dev_dbg(otg->phy->dev, "host off\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1324 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1325 | usb_remove_hcd(hcd); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1326 | /* HCD core reset all bits of PORTSC. select ULPI phy */ |
| 1327 | writel_relaxed(0x80000000, USB_PORTSC); |
| 1328 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1329 | if (pdata->setup_gpio) |
| 1330 | pdata->setup_gpio(OTG_STATE_UNDEFINED); |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 1331 | |
| 1332 | if (pdata->otg_control == OTG_PHY_CONTROL) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1333 | ulpi_write(otg->phy, OTG_COMP_DISABLE, |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 1334 | ULPI_CLR(ULPI_PWR_CLK_MNG_REG)); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1335 | } |
| 1336 | } |
| 1337 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1338 | static int msm_otg_usbdev_notify(struct notifier_block *self, |
| 1339 | unsigned long action, void *priv) |
| 1340 | { |
| 1341 | struct msm_otg *motg = container_of(self, struct msm_otg, usbdev_nb); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1342 | struct usb_otg *otg = motg->phy.otg; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1343 | struct usb_device *udev = priv; |
| 1344 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1345 | if (action == USB_BUS_ADD || action == USB_BUS_REMOVE) |
| 1346 | goto out; |
| 1347 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1348 | if (udev->bus != otg->host) |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1349 | goto out; |
| 1350 | /* |
| 1351 | * Interested in devices connected directly to the root hub. |
| 1352 | * ACA dock can supply IDEV_CHG irrespective devices connected |
| 1353 | * on the accessory port. |
| 1354 | */ |
| 1355 | if (!udev->parent || udev->parent->parent || |
| 1356 | motg->chg_type == USB_ACA_DOCK_CHARGER) |
| 1357 | goto out; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1358 | |
| 1359 | switch (action) { |
| 1360 | case USB_DEVICE_ADD: |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1361 | if (aca_enabled()) |
| 1362 | usb_disable_autosuspend(udev); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1363 | if (otg->phy->state == OTG_STATE_A_WAIT_BCON) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1364 | pr_debug("B_CONN set\n"); |
| 1365 | set_bit(B_CONN, &motg->inputs); |
| 1366 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1367 | otg->phy->state = OTG_STATE_A_HOST; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1368 | /* |
| 1369 | * OTG PET: A-device must end session within |
| 1370 | * 10 sec after PET enumeration. |
| 1371 | */ |
| 1372 | if (udev->quirks & USB_QUIRK_OTG_PET) |
| 1373 | msm_otg_start_timer(motg, TA_TST_MAINT, |
| 1374 | A_TST_MAINT); |
| 1375 | } |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1376 | /* fall through */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1377 | case USB_DEVICE_CONFIG: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1378 | if (udev->actconfig) |
| 1379 | motg->mA_port = udev->actconfig->desc.bMaxPower * 2; |
| 1380 | else |
| 1381 | motg->mA_port = IUNIT; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1382 | if (otg->phy->state == OTG_STATE_B_HOST) |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1383 | msm_otg_del_timer(motg); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1384 | break; |
| 1385 | case USB_DEVICE_REMOVE: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1386 | if ((otg->phy->state == OTG_STATE_A_HOST) || |
| 1387 | (otg->phy->state == OTG_STATE_A_SUSPEND)) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1388 | pr_debug("B_CONN clear\n"); |
| 1389 | clear_bit(B_CONN, &motg->inputs); |
| 1390 | /* |
| 1391 | * OTG PET: A-device must end session after |
| 1392 | * PET disconnection if it is enumerated |
| 1393 | * with bcdDevice[0] = 1. USB core sets |
| 1394 | * bus->otg_vbus_off for us. clear it here. |
| 1395 | */ |
| 1396 | if (udev->bus->otg_vbus_off) { |
| 1397 | udev->bus->otg_vbus_off = 0; |
| 1398 | set_bit(A_BUS_DROP, &motg->inputs); |
| 1399 | } |
| 1400 | queue_work(system_nrt_wq, &motg->sm_work); |
| 1401 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1402 | default: |
| 1403 | break; |
| 1404 | } |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1405 | if (test_bit(ID_A, &motg->inputs)) |
| 1406 | msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX - |
| 1407 | motg->mA_port); |
| 1408 | out: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1409 | return NOTIFY_OK; |
| 1410 | } |
| 1411 | |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1412 | static void msm_hsusb_vbus_power(struct msm_otg *motg, bool on) |
| 1413 | { |
| 1414 | int ret; |
| 1415 | static bool vbus_is_on; |
| 1416 | |
| 1417 | if (vbus_is_on == on) |
| 1418 | return; |
| 1419 | |
| 1420 | if (motg->pdata->vbus_power) { |
Mayank Rana | 91f597e | 2012-01-20 10:12:06 +0530 | [diff] [blame] | 1421 | ret = motg->pdata->vbus_power(on); |
| 1422 | if (!ret) |
| 1423 | vbus_is_on = on; |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1424 | return; |
| 1425 | } |
| 1426 | |
| 1427 | if (!vbus_otg) { |
| 1428 | pr_err("vbus_otg is NULL."); |
| 1429 | return; |
| 1430 | } |
| 1431 | |
Abhijeet Dharmapurikar | be05488 | 2012-01-03 20:27:07 -0800 | [diff] [blame] | 1432 | /* |
| 1433 | * if entering host mode tell the charger to not draw any current |
Abhijeet Dharmapurikar | 6d94121 | 2012-03-05 10:30:56 -0800 | [diff] [blame] | 1434 | * from usb before turning on the boost. |
| 1435 | * if exiting host mode disable the boost before enabling to draw |
| 1436 | * current from the source. |
Abhijeet Dharmapurikar | be05488 | 2012-01-03 20:27:07 -0800 | [diff] [blame] | 1437 | */ |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1438 | if (on) { |
Abhijeet Dharmapurikar | 5e96aaa | 2012-06-26 11:21:03 -0700 | [diff] [blame] | 1439 | msm_otg_notify_host_mode(motg, on); |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1440 | ret = regulator_enable(vbus_otg); |
| 1441 | if (ret) { |
| 1442 | pr_err("unable to enable vbus_otg\n"); |
| 1443 | return; |
| 1444 | } |
| 1445 | vbus_is_on = true; |
| 1446 | } else { |
| 1447 | ret = regulator_disable(vbus_otg); |
| 1448 | if (ret) { |
| 1449 | pr_err("unable to disable vbus_otg\n"); |
| 1450 | return; |
| 1451 | } |
Abhijeet Dharmapurikar | 5e96aaa | 2012-06-26 11:21:03 -0700 | [diff] [blame] | 1452 | msm_otg_notify_host_mode(motg, on); |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1453 | vbus_is_on = false; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1457 | static int msm_otg_set_host(struct usb_otg *otg, struct usb_bus *host) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1458 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1459 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1460 | struct usb_hcd *hcd; |
| 1461 | |
| 1462 | /* |
| 1463 | * Fail host registration if this board can support |
| 1464 | * only peripheral configuration. |
| 1465 | */ |
| 1466 | if (motg->pdata->mode == USB_PERIPHERAL) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1467 | dev_info(otg->phy->dev, "Host mode is not supported\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1468 | return -ENODEV; |
| 1469 | } |
| 1470 | |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1471 | if (!motg->pdata->vbus_power && host) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1472 | vbus_otg = devm_regulator_get(motg->phy.dev, "vbus_otg"); |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1473 | if (IS_ERR(vbus_otg)) { |
| 1474 | pr_err("Unable to get vbus_otg\n"); |
| 1475 | return -ENODEV; |
| 1476 | } |
| 1477 | } |
| 1478 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1479 | if (!host) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1480 | if (otg->phy->state == OTG_STATE_A_HOST) { |
| 1481 | pm_runtime_get_sync(otg->phy->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1482 | usb_unregister_notify(&motg->usbdev_nb); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1483 | msm_otg_start_host(otg, 0); |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1484 | msm_hsusb_vbus_power(motg, 0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1485 | otg->host = NULL; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1486 | otg->phy->state = OTG_STATE_UNDEFINED; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1487 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1488 | } else { |
| 1489 | otg->host = NULL; |
| 1490 | } |
| 1491 | |
| 1492 | return 0; |
| 1493 | } |
| 1494 | |
| 1495 | hcd = bus_to_hcd(host); |
| 1496 | hcd->power_budget = motg->pdata->power_budget; |
| 1497 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1498 | #ifdef CONFIG_USB_OTG |
| 1499 | host->otg_port = 1; |
| 1500 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1501 | motg->usbdev_nb.notifier_call = msm_otg_usbdev_notify; |
| 1502 | usb_register_notify(&motg->usbdev_nb); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1503 | otg->host = host; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1504 | dev_dbg(otg->phy->dev, "host driver registered w/ tranceiver\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1505 | |
| 1506 | /* |
| 1507 | * Kick the state machine work, if peripheral is not supported |
| 1508 | * or peripheral is already registered with us. |
| 1509 | */ |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1510 | if (motg->pdata->mode == USB_HOST || otg->gadget) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1511 | pm_runtime_get_sync(otg->phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1512 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1513 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1514 | |
| 1515 | return 0; |
| 1516 | } |
| 1517 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1518 | static void msm_otg_start_peripheral(struct usb_otg *otg, int on) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1519 | { |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1520 | int ret; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1521 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1522 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 1523 | |
| 1524 | if (!otg->gadget) |
| 1525 | return; |
| 1526 | |
| 1527 | if (on) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1528 | dev_dbg(otg->phy->dev, "gadget on\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1529 | /* |
| 1530 | * Some boards have a switch cotrolled by gpio |
| 1531 | * to enable/disable internal HUB. Disable internal |
| 1532 | * HUB before kicking the gadget. |
| 1533 | */ |
| 1534 | if (pdata->setup_gpio) |
| 1535 | pdata->setup_gpio(OTG_STATE_B_PERIPHERAL); |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 1536 | |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1537 | /* Configure BUS performance parameters for MAX bandwidth */ |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 1538 | if (motg->bus_perf_client && debug_bus_voting_enabled) { |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1539 | ret = msm_bus_scale_client_update_request( |
| 1540 | motg->bus_perf_client, 1); |
| 1541 | if (ret) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1542 | dev_err(motg->phy.dev, "%s: Failed to vote for " |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1543 | "bus bandwidth %d\n", __func__, ret); |
| 1544 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1545 | usb_gadget_vbus_connect(otg->gadget); |
| 1546 | } else { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1547 | dev_dbg(otg->phy->dev, "gadget off\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1548 | usb_gadget_vbus_disconnect(otg->gadget); |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1549 | /* Configure BUS performance parameters to default */ |
| 1550 | if (motg->bus_perf_client) { |
| 1551 | ret = msm_bus_scale_client_update_request( |
| 1552 | motg->bus_perf_client, 0); |
| 1553 | if (ret) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1554 | dev_err(motg->phy.dev, "%s: Failed to devote " |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1555 | "for bus bw %d\n", __func__, ret); |
| 1556 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1557 | if (pdata->setup_gpio) |
| 1558 | pdata->setup_gpio(OTG_STATE_UNDEFINED); |
| 1559 | } |
| 1560 | |
| 1561 | } |
| 1562 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1563 | static int msm_otg_set_peripheral(struct usb_otg *otg, |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1564 | struct usb_gadget *gadget) |
| 1565 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1566 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1567 | |
| 1568 | /* |
| 1569 | * Fail peripheral registration if this board can support |
| 1570 | * only host configuration. |
| 1571 | */ |
| 1572 | if (motg->pdata->mode == USB_HOST) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1573 | dev_info(otg->phy->dev, "Peripheral mode is not supported\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1574 | return -ENODEV; |
| 1575 | } |
| 1576 | |
| 1577 | if (!gadget) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1578 | if (otg->phy->state == OTG_STATE_B_PERIPHERAL) { |
| 1579 | pm_runtime_get_sync(otg->phy->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1580 | msm_otg_start_peripheral(otg, 0); |
| 1581 | otg->gadget = NULL; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1582 | otg->phy->state = OTG_STATE_UNDEFINED; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1583 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1584 | } else { |
| 1585 | otg->gadget = NULL; |
| 1586 | } |
| 1587 | |
| 1588 | return 0; |
| 1589 | } |
| 1590 | otg->gadget = gadget; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1591 | dev_dbg(otg->phy->dev, "peripheral driver registered w/ tranceiver\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1592 | |
| 1593 | /* |
| 1594 | * Kick the state machine work, if host is not supported |
| 1595 | * or host is already registered with us. |
| 1596 | */ |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1597 | if (motg->pdata->mode == USB_PERIPHERAL || otg->host) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1598 | pm_runtime_get_sync(otg->phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1599 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1600 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1601 | |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
Pavankumar Kondeti | becab5b | 2012-11-06 16:45:10 +0530 | [diff] [blame] | 1605 | static bool msm_otg_read_pmic_id_state(struct msm_otg *motg) |
| 1606 | { |
| 1607 | unsigned long flags; |
| 1608 | int id; |
| 1609 | |
| 1610 | if (!motg->pdata->pmic_id_irq) |
| 1611 | return -ENODEV; |
| 1612 | |
| 1613 | local_irq_save(flags); |
| 1614 | id = irq_read_line(motg->pdata->pmic_id_irq); |
| 1615 | local_irq_restore(flags); |
| 1616 | |
| 1617 | /* |
| 1618 | * If we can not read ID line state for some reason, treat |
| 1619 | * it as float. This would prevent MHL discovery and kicking |
| 1620 | * host mode unnecessarily. |
| 1621 | */ |
| 1622 | return !!id; |
| 1623 | } |
| 1624 | |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 1625 | static int msm_otg_mhl_register_callback(struct msm_otg *motg, |
| 1626 | void (*callback)(int on)) |
| 1627 | { |
| 1628 | struct usb_phy *phy = &motg->phy; |
| 1629 | int ret; |
| 1630 | |
Manoj Rao | a7bddd1 | 2012-08-27 20:36:45 -0700 | [diff] [blame] | 1631 | if (!motg->pdata->mhl_enable) { |
| 1632 | dev_dbg(phy->dev, "MHL feature not enabled\n"); |
| 1633 | return -ENODEV; |
| 1634 | } |
| 1635 | |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 1636 | if (motg->pdata->otg_control != OTG_PMIC_CONTROL || |
| 1637 | !motg->pdata->pmic_id_irq) { |
| 1638 | dev_dbg(phy->dev, "MHL can not be supported without PMIC Id\n"); |
| 1639 | return -ENODEV; |
| 1640 | } |
| 1641 | |
| 1642 | if (!motg->pdata->mhl_dev_name) { |
| 1643 | dev_dbg(phy->dev, "MHL device name does not exist.\n"); |
| 1644 | return -ENODEV; |
| 1645 | } |
| 1646 | |
| 1647 | if (callback) |
| 1648 | ret = mhl_register_callback(motg->pdata->mhl_dev_name, |
| 1649 | callback); |
| 1650 | else |
| 1651 | ret = mhl_unregister_callback(motg->pdata->mhl_dev_name); |
| 1652 | |
| 1653 | if (ret) |
| 1654 | dev_dbg(phy->dev, "mhl_register_callback(%s) return error=%d\n", |
| 1655 | motg->pdata->mhl_dev_name, ret); |
| 1656 | else |
| 1657 | motg->mhl_enabled = true; |
| 1658 | |
| 1659 | return ret; |
| 1660 | } |
| 1661 | |
| 1662 | static void msm_otg_mhl_notify_online(int on) |
| 1663 | { |
| 1664 | struct msm_otg *motg = the_msm_otg; |
| 1665 | struct usb_phy *phy = &motg->phy; |
| 1666 | bool queue = false; |
| 1667 | |
| 1668 | dev_dbg(phy->dev, "notify MHL %s%s\n", on ? "" : "dis", "connected"); |
| 1669 | |
| 1670 | if (on) { |
| 1671 | set_bit(MHL, &motg->inputs); |
| 1672 | } else { |
| 1673 | clear_bit(MHL, &motg->inputs); |
| 1674 | queue = true; |
| 1675 | } |
| 1676 | |
| 1677 | if (queue && phy->state != OTG_STATE_UNDEFINED) |
| 1678 | schedule_work(&motg->sm_work); |
| 1679 | } |
| 1680 | |
| 1681 | static bool msm_otg_is_mhl(struct msm_otg *motg) |
| 1682 | { |
| 1683 | struct usb_phy *phy = &motg->phy; |
| 1684 | int is_mhl, ret; |
| 1685 | |
| 1686 | ret = mhl_device_discovery(motg->pdata->mhl_dev_name, &is_mhl); |
| 1687 | if (ret || is_mhl != MHL_DISCOVERY_RESULT_MHL) { |
| 1688 | /* |
| 1689 | * MHL driver calls our callback saying that MHL connected |
| 1690 | * if RID_GND is detected. But at later part of discovery |
| 1691 | * it may figure out MHL is not connected and returns |
| 1692 | * false. Hence clear MHL input here. |
| 1693 | */ |
| 1694 | clear_bit(MHL, &motg->inputs); |
| 1695 | dev_dbg(phy->dev, "MHL device not found\n"); |
| 1696 | return false; |
| 1697 | } |
| 1698 | |
| 1699 | set_bit(MHL, &motg->inputs); |
| 1700 | dev_dbg(phy->dev, "MHL device found\n"); |
| 1701 | return true; |
| 1702 | } |
| 1703 | |
| 1704 | static bool msm_chg_mhl_detect(struct msm_otg *motg) |
| 1705 | { |
| 1706 | bool ret, id; |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 1707 | |
| 1708 | if (!motg->mhl_enabled) |
| 1709 | return false; |
| 1710 | |
Pavankumar Kondeti | becab5b | 2012-11-06 16:45:10 +0530 | [diff] [blame] | 1711 | id = msm_otg_read_pmic_id_state(motg); |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 1712 | |
| 1713 | if (id) |
| 1714 | return false; |
| 1715 | |
| 1716 | mhl_det_in_progress = true; |
| 1717 | ret = msm_otg_is_mhl(motg); |
| 1718 | mhl_det_in_progress = false; |
| 1719 | |
| 1720 | return ret; |
| 1721 | } |
| 1722 | |
Pavankumar Kondeti | 458d879 | 2012-09-28 14:45:18 +0530 | [diff] [blame] | 1723 | static void msm_otg_chg_check_timer_func(unsigned long data) |
| 1724 | { |
| 1725 | struct msm_otg *motg = (struct msm_otg *) data; |
| 1726 | struct usb_otg *otg = motg->phy.otg; |
| 1727 | |
| 1728 | if (atomic_read(&motg->in_lpm) || |
| 1729 | !test_bit(B_SESS_VLD, &motg->inputs) || |
| 1730 | otg->phy->state != OTG_STATE_B_PERIPHERAL || |
| 1731 | otg->gadget->speed != USB_SPEED_UNKNOWN) { |
| 1732 | dev_dbg(otg->phy->dev, "Nothing to do in chg_check_timer\n"); |
| 1733 | return; |
| 1734 | } |
| 1735 | |
| 1736 | if ((readl_relaxed(USB_PORTSC) & PORTSC_LS) == PORTSC_LS) { |
| 1737 | dev_dbg(otg->phy->dev, "DCP is detected as SDP\n"); |
| 1738 | set_bit(B_FALSE_SDP, &motg->inputs); |
| 1739 | queue_work(system_nrt_wq, &motg->sm_work); |
| 1740 | } |
| 1741 | } |
| 1742 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1743 | static bool msm_chg_aca_detect(struct msm_otg *motg) |
| 1744 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1745 | struct usb_phy *phy = &motg->phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1746 | u32 int_sts; |
| 1747 | bool ret = false; |
| 1748 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1749 | if (!aca_enabled()) |
| 1750 | goto out; |
| 1751 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1752 | if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) |
| 1753 | goto out; |
| 1754 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1755 | int_sts = ulpi_read(phy, 0x87); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1756 | switch (int_sts & 0x1C) { |
| 1757 | case 0x08: |
| 1758 | if (!test_and_set_bit(ID_A, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1759 | dev_dbg(phy->dev, "ID_A\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1760 | motg->chg_type = USB_ACA_A_CHARGER; |
| 1761 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1762 | clear_bit(ID_B, &motg->inputs); |
| 1763 | clear_bit(ID_C, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1764 | set_bit(ID, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1765 | ret = true; |
| 1766 | } |
| 1767 | break; |
| 1768 | case 0x0C: |
| 1769 | if (!test_and_set_bit(ID_B, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1770 | dev_dbg(phy->dev, "ID_B\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1771 | motg->chg_type = USB_ACA_B_CHARGER; |
| 1772 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1773 | clear_bit(ID_A, &motg->inputs); |
| 1774 | clear_bit(ID_C, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1775 | set_bit(ID, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1776 | ret = true; |
| 1777 | } |
| 1778 | break; |
| 1779 | case 0x10: |
| 1780 | if (!test_and_set_bit(ID_C, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1781 | dev_dbg(phy->dev, "ID_C\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1782 | motg->chg_type = USB_ACA_C_CHARGER; |
| 1783 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1784 | clear_bit(ID_A, &motg->inputs); |
| 1785 | clear_bit(ID_B, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1786 | set_bit(ID, &motg->inputs); |
| 1787 | ret = true; |
| 1788 | } |
| 1789 | break; |
| 1790 | case 0x04: |
| 1791 | if (test_and_clear_bit(ID, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1792 | dev_dbg(phy->dev, "ID_GND\n"); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1793 | motg->chg_type = USB_INVALID_CHARGER; |
| 1794 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1795 | clear_bit(ID_A, &motg->inputs); |
| 1796 | clear_bit(ID_B, &motg->inputs); |
| 1797 | clear_bit(ID_C, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1798 | ret = true; |
| 1799 | } |
| 1800 | break; |
| 1801 | default: |
| 1802 | ret = test_and_clear_bit(ID_A, &motg->inputs) | |
| 1803 | test_and_clear_bit(ID_B, &motg->inputs) | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1804 | test_and_clear_bit(ID_C, &motg->inputs) | |
| 1805 | !test_and_set_bit(ID, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1806 | if (ret) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1807 | dev_dbg(phy->dev, "ID A/B/C/GND is no more\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1808 | motg->chg_type = USB_INVALID_CHARGER; |
| 1809 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1810 | } |
| 1811 | } |
| 1812 | out: |
| 1813 | return ret; |
| 1814 | } |
| 1815 | |
| 1816 | static void msm_chg_enable_aca_det(struct msm_otg *motg) |
| 1817 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1818 | struct usb_phy *phy = &motg->phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1819 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1820 | if (!aca_enabled()) |
| 1821 | return; |
| 1822 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1823 | switch (motg->pdata->phy_type) { |
| 1824 | case SNPS_28NM_INTEGRATED_PHY: |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1825 | /* Disable ID_GND in link and PHY */ |
| 1826 | writel_relaxed(readl_relaxed(USB_OTGSC) & ~(OTGSC_IDPU | |
| 1827 | OTGSC_IDIE), USB_OTGSC); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1828 | ulpi_write(phy, 0x01, 0x0C); |
| 1829 | ulpi_write(phy, 0x10, 0x0F); |
| 1830 | ulpi_write(phy, 0x10, 0x12); |
Pavankumar Kondeti | 446f454 | 2012-02-01 13:57:13 +0530 | [diff] [blame] | 1831 | /* Disable PMIC ID pull-up */ |
| 1832 | pm8xxx_usb_id_pullup(0); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1833 | /* Enable ACA ID detection */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1834 | ulpi_write(phy, 0x20, 0x85); |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 1835 | aca_id_turned_on = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1836 | break; |
| 1837 | default: |
| 1838 | break; |
| 1839 | } |
| 1840 | } |
| 1841 | |
| 1842 | static void msm_chg_enable_aca_intr(struct msm_otg *motg) |
| 1843 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1844 | struct usb_phy *phy = &motg->phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1845 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1846 | if (!aca_enabled()) |
| 1847 | return; |
| 1848 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1849 | switch (motg->pdata->phy_type) { |
| 1850 | case SNPS_28NM_INTEGRATED_PHY: |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1851 | /* Enable ACA Detection interrupt (on any RID change) */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1852 | ulpi_write(phy, 0x01, 0x94); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1853 | break; |
| 1854 | default: |
| 1855 | break; |
| 1856 | } |
| 1857 | } |
| 1858 | |
| 1859 | static void msm_chg_disable_aca_intr(struct msm_otg *motg) |
| 1860 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1861 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1862 | |
| 1863 | if (!aca_enabled()) |
| 1864 | return; |
| 1865 | |
| 1866 | switch (motg->pdata->phy_type) { |
| 1867 | case SNPS_28NM_INTEGRATED_PHY: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1868 | ulpi_write(phy, 0x01, 0x95); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1869 | break; |
| 1870 | default: |
| 1871 | break; |
| 1872 | } |
| 1873 | } |
| 1874 | |
| 1875 | static bool msm_chg_check_aca_intr(struct msm_otg *motg) |
| 1876 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1877 | struct usb_phy *phy = &motg->phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1878 | bool ret = false; |
| 1879 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1880 | if (!aca_enabled()) |
| 1881 | return ret; |
| 1882 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1883 | switch (motg->pdata->phy_type) { |
| 1884 | case SNPS_28NM_INTEGRATED_PHY: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1885 | if (ulpi_read(phy, 0x91) & 1) { |
| 1886 | dev_dbg(phy->dev, "RID change\n"); |
| 1887 | ulpi_write(phy, 0x01, 0x92); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1888 | ret = msm_chg_aca_detect(motg); |
| 1889 | } |
| 1890 | default: |
| 1891 | break; |
| 1892 | } |
| 1893 | return ret; |
| 1894 | } |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1895 | |
| 1896 | static void msm_otg_id_timer_func(unsigned long data) |
| 1897 | { |
| 1898 | struct msm_otg *motg = (struct msm_otg *) data; |
| 1899 | |
| 1900 | if (!aca_enabled()) |
| 1901 | return; |
| 1902 | |
| 1903 | if (atomic_read(&motg->in_lpm)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1904 | dev_dbg(motg->phy.dev, "timer: in lpm\n"); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1905 | return; |
| 1906 | } |
| 1907 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1908 | if (motg->phy.state == OTG_STATE_A_SUSPEND) |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1909 | goto out; |
| 1910 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1911 | if (msm_chg_check_aca_intr(motg)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1912 | dev_dbg(motg->phy.dev, "timer: aca work\n"); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1913 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1914 | } |
| 1915 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1916 | out: |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1917 | if (!test_bit(ID, &motg->inputs) || test_bit(ID_A, &motg->inputs)) |
| 1918 | mod_timer(&motg->id_timer, ID_TIMER_FREQ); |
| 1919 | } |
| 1920 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1921 | static bool msm_chg_check_secondary_det(struct msm_otg *motg) |
| 1922 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1923 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1924 | u32 chg_det; |
| 1925 | bool ret = false; |
| 1926 | |
| 1927 | switch (motg->pdata->phy_type) { |
| 1928 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1929 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1930 | ret = chg_det & (1 << 4); |
| 1931 | break; |
| 1932 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1933 | chg_det = ulpi_read(phy, 0x87); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1934 | ret = chg_det & 1; |
| 1935 | break; |
| 1936 | default: |
| 1937 | break; |
| 1938 | } |
| 1939 | return ret; |
| 1940 | } |
| 1941 | |
| 1942 | static void msm_chg_enable_secondary_det(struct msm_otg *motg) |
| 1943 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1944 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1945 | u32 chg_det; |
| 1946 | |
| 1947 | switch (motg->pdata->phy_type) { |
| 1948 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1949 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1950 | /* Turn off charger block */ |
| 1951 | chg_det |= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1952 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1953 | udelay(20); |
| 1954 | /* control chg block via ULPI */ |
| 1955 | chg_det &= ~(1 << 3); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1956 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1957 | /* put it in host mode for enabling D- source */ |
| 1958 | chg_det &= ~(1 << 2); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1959 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1960 | /* Turn on chg detect block */ |
| 1961 | chg_det &= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1962 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1963 | udelay(20); |
| 1964 | /* enable chg detection */ |
| 1965 | chg_det &= ~(1 << 0); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1966 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1967 | break; |
| 1968 | case SNPS_28NM_INTEGRATED_PHY: |
| 1969 | /* |
| 1970 | * Configure DM as current source, DP as current sink |
| 1971 | * and enable battery charging comparators. |
| 1972 | */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1973 | ulpi_write(phy, 0x8, 0x85); |
| 1974 | ulpi_write(phy, 0x2, 0x85); |
| 1975 | ulpi_write(phy, 0x1, 0x85); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1976 | break; |
| 1977 | default: |
| 1978 | break; |
| 1979 | } |
| 1980 | } |
| 1981 | |
| 1982 | static bool msm_chg_check_primary_det(struct msm_otg *motg) |
| 1983 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1984 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1985 | u32 chg_det; |
| 1986 | bool ret = false; |
| 1987 | |
| 1988 | switch (motg->pdata->phy_type) { |
| 1989 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1990 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1991 | ret = chg_det & (1 << 4); |
| 1992 | break; |
| 1993 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1994 | chg_det = ulpi_read(phy, 0x87); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1995 | ret = chg_det & 1; |
Pavankumar Kondeti | 9ec21d3 | 2012-05-07 15:50:23 +0530 | [diff] [blame] | 1996 | /* Turn off VDP_SRC */ |
| 1997 | ulpi_write(phy, 0x3, 0x86); |
| 1998 | msleep(20); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1999 | break; |
| 2000 | default: |
| 2001 | break; |
| 2002 | } |
| 2003 | return ret; |
| 2004 | } |
| 2005 | |
| 2006 | static void msm_chg_enable_primary_det(struct msm_otg *motg) |
| 2007 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2008 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2009 | u32 chg_det; |
| 2010 | |
| 2011 | switch (motg->pdata->phy_type) { |
| 2012 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2013 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2014 | /* enable chg detection */ |
| 2015 | chg_det &= ~(1 << 0); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2016 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2017 | break; |
| 2018 | case SNPS_28NM_INTEGRATED_PHY: |
| 2019 | /* |
| 2020 | * Configure DP as current source, DM as current sink |
| 2021 | * and enable battery charging comparators. |
| 2022 | */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2023 | ulpi_write(phy, 0x2, 0x85); |
| 2024 | ulpi_write(phy, 0x1, 0x85); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2025 | break; |
| 2026 | default: |
| 2027 | break; |
| 2028 | } |
| 2029 | } |
| 2030 | |
| 2031 | static bool msm_chg_check_dcd(struct msm_otg *motg) |
| 2032 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2033 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2034 | u32 line_state; |
| 2035 | bool ret = false; |
| 2036 | |
| 2037 | switch (motg->pdata->phy_type) { |
| 2038 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2039 | line_state = ulpi_read(phy, 0x15); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2040 | ret = !(line_state & 1); |
| 2041 | break; |
| 2042 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2043 | line_state = ulpi_read(phy, 0x87); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2044 | ret = line_state & 2; |
| 2045 | break; |
| 2046 | default: |
| 2047 | break; |
| 2048 | } |
| 2049 | return ret; |
| 2050 | } |
| 2051 | |
| 2052 | static void msm_chg_disable_dcd(struct msm_otg *motg) |
| 2053 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2054 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2055 | u32 chg_det; |
| 2056 | |
| 2057 | switch (motg->pdata->phy_type) { |
| 2058 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2059 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2060 | chg_det &= ~(1 << 5); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2061 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2062 | break; |
| 2063 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2064 | ulpi_write(phy, 0x10, 0x86); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2065 | break; |
| 2066 | default: |
| 2067 | break; |
| 2068 | } |
| 2069 | } |
| 2070 | |
| 2071 | static void msm_chg_enable_dcd(struct msm_otg *motg) |
| 2072 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2073 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2074 | u32 chg_det; |
| 2075 | |
| 2076 | switch (motg->pdata->phy_type) { |
| 2077 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2078 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2079 | /* Turn on D+ current source */ |
| 2080 | chg_det |= (1 << 5); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2081 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2082 | break; |
| 2083 | case SNPS_28NM_INTEGRATED_PHY: |
| 2084 | /* Data contact detection enable */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2085 | ulpi_write(phy, 0x10, 0x85); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2086 | break; |
| 2087 | default: |
| 2088 | break; |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | static void msm_chg_block_on(struct msm_otg *motg) |
| 2093 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2094 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2095 | u32 func_ctrl, chg_det; |
| 2096 | |
| 2097 | /* put the controller in non-driving mode */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2098 | func_ctrl = ulpi_read(phy, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2099 | func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
| 2100 | func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2101 | ulpi_write(phy, func_ctrl, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2102 | |
| 2103 | switch (motg->pdata->phy_type) { |
| 2104 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2105 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2106 | /* control chg block via ULPI */ |
| 2107 | chg_det &= ~(1 << 3); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2108 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2109 | /* Turn on chg detect block */ |
| 2110 | chg_det &= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2111 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2112 | udelay(20); |
| 2113 | break; |
| 2114 | case SNPS_28NM_INTEGRATED_PHY: |
Pavankumar Kondeti | 768dcb8 | 2012-10-05 13:21:45 +0530 | [diff] [blame] | 2115 | /* disable DP and DM pull down resistors */ |
| 2116 | ulpi_write(phy, 0x6, 0xC); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2117 | /* Clear charger detecting control bits */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2118 | ulpi_write(phy, 0x1F, 0x86); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2119 | /* Clear alt interrupt latch and enable bits */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2120 | ulpi_write(phy, 0x1F, 0x92); |
| 2121 | ulpi_write(phy, 0x1F, 0x95); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2122 | udelay(100); |
| 2123 | break; |
| 2124 | default: |
| 2125 | break; |
| 2126 | } |
| 2127 | } |
| 2128 | |
| 2129 | static void msm_chg_block_off(struct msm_otg *motg) |
| 2130 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2131 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2132 | u32 func_ctrl, chg_det; |
| 2133 | |
| 2134 | switch (motg->pdata->phy_type) { |
| 2135 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2136 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2137 | /* Turn off charger block */ |
| 2138 | chg_det |= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2139 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2140 | break; |
| 2141 | case SNPS_28NM_INTEGRATED_PHY: |
| 2142 | /* Clear charger detecting control bits */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2143 | ulpi_write(phy, 0x3F, 0x86); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2144 | /* Clear alt interrupt latch and enable bits */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2145 | ulpi_write(phy, 0x1F, 0x92); |
| 2146 | ulpi_write(phy, 0x1F, 0x95); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2147 | break; |
| 2148 | default: |
| 2149 | break; |
| 2150 | } |
| 2151 | |
| 2152 | /* put the controller in normal mode */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2153 | func_ctrl = ulpi_read(phy, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2154 | func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
| 2155 | func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NORMAL; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2156 | ulpi_write(phy, func_ctrl, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2157 | } |
| 2158 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 2159 | static const char *chg_to_string(enum usb_chg_type chg_type) |
| 2160 | { |
| 2161 | switch (chg_type) { |
| 2162 | case USB_SDP_CHARGER: return "USB_SDP_CHARGER"; |
| 2163 | case USB_DCP_CHARGER: return "USB_DCP_CHARGER"; |
| 2164 | case USB_CDP_CHARGER: return "USB_CDP_CHARGER"; |
| 2165 | case USB_ACA_A_CHARGER: return "USB_ACA_A_CHARGER"; |
| 2166 | case USB_ACA_B_CHARGER: return "USB_ACA_B_CHARGER"; |
| 2167 | case USB_ACA_C_CHARGER: return "USB_ACA_C_CHARGER"; |
| 2168 | case USB_ACA_DOCK_CHARGER: return "USB_ACA_DOCK_CHARGER"; |
Pavankumar Kondeti | 9ec21d3 | 2012-05-07 15:50:23 +0530 | [diff] [blame] | 2169 | case USB_PROPRIETARY_CHARGER: return "USB_PROPRIETARY_CHARGER"; |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 2170 | default: return "INVALID_CHARGER"; |
| 2171 | } |
| 2172 | } |
| 2173 | |
Pavankumar Kondeti | ebb4a2d | 2013-01-04 12:28:10 +0530 | [diff] [blame] | 2174 | #define MSM_CHG_DCD_TIMEOUT (750 * HZ/1000) /* 750 msec */ |
| 2175 | #define MSM_CHG_DCD_POLL_TIME (50 * HZ/1000) /* 50 msec */ |
Pavankumar Kondeti | 283146f | 2012-01-12 12:51:19 +0530 | [diff] [blame] | 2176 | #define MSM_CHG_PRIMARY_DET_TIME (50 * HZ/1000) /* TVDPSRC_ON */ |
| 2177 | #define MSM_CHG_SECONDARY_DET_TIME (50 * HZ/1000) /* TVDMSRC_ON */ |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2178 | static void msm_chg_detect_work(struct work_struct *w) |
| 2179 | { |
| 2180 | struct msm_otg *motg = container_of(w, struct msm_otg, chg_work.work); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2181 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | 2d09e5f | 2012-01-16 08:56:57 +0530 | [diff] [blame] | 2182 | bool is_dcd = false, tmout, vout, is_aca; |
Pavankumar Kondeti | 9ec21d3 | 2012-05-07 15:50:23 +0530 | [diff] [blame] | 2183 | u32 line_state, dm_vlgc; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2184 | unsigned long delay; |
| 2185 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2186 | dev_dbg(phy->dev, "chg detection work\n"); |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 2187 | |
| 2188 | if (test_bit(MHL, &motg->inputs)) { |
| 2189 | dev_dbg(phy->dev, "detected MHL, escape chg detection work\n"); |
| 2190 | return; |
| 2191 | } |
| 2192 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2193 | switch (motg->chg_state) { |
| 2194 | case USB_CHG_STATE_UNDEFINED: |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2195 | msm_chg_block_on(motg); |
Pavankumar Kondeti | 768dcb8 | 2012-10-05 13:21:45 +0530 | [diff] [blame] | 2196 | msm_chg_enable_dcd(motg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2197 | msm_chg_enable_aca_det(motg); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2198 | motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; |
Pavankumar Kondeti | ebb4a2d | 2013-01-04 12:28:10 +0530 | [diff] [blame] | 2199 | motg->dcd_time = 0; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2200 | delay = MSM_CHG_DCD_POLL_TIME; |
| 2201 | break; |
| 2202 | case USB_CHG_STATE_WAIT_FOR_DCD: |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 2203 | if (msm_chg_mhl_detect(motg)) { |
| 2204 | msm_chg_block_off(motg); |
| 2205 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 2206 | motg->chg_type = USB_INVALID_CHARGER; |
| 2207 | queue_work(system_nrt_wq, &motg->sm_work); |
| 2208 | return; |
| 2209 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2210 | is_aca = msm_chg_aca_detect(motg); |
| 2211 | if (is_aca) { |
| 2212 | /* |
| 2213 | * ID_A can be ACA dock too. continue |
| 2214 | * primary detection after DCD. |
| 2215 | */ |
| 2216 | if (test_bit(ID_A, &motg->inputs)) { |
| 2217 | motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; |
| 2218 | } else { |
| 2219 | delay = 0; |
| 2220 | break; |
| 2221 | } |
| 2222 | } |
Pavankumar Kondeti | 768dcb8 | 2012-10-05 13:21:45 +0530 | [diff] [blame] | 2223 | is_dcd = msm_chg_check_dcd(motg); |
Pavankumar Kondeti | ebb4a2d | 2013-01-04 12:28:10 +0530 | [diff] [blame] | 2224 | motg->dcd_time += MSM_CHG_DCD_POLL_TIME; |
| 2225 | tmout = motg->dcd_time >= MSM_CHG_DCD_TIMEOUT; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2226 | if (is_dcd || tmout) { |
Pavankumar Kondeti | 768dcb8 | 2012-10-05 13:21:45 +0530 | [diff] [blame] | 2227 | msm_chg_disable_dcd(motg); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2228 | msm_chg_enable_primary_det(motg); |
| 2229 | delay = MSM_CHG_PRIMARY_DET_TIME; |
| 2230 | motg->chg_state = USB_CHG_STATE_DCD_DONE; |
| 2231 | } else { |
| 2232 | delay = MSM_CHG_DCD_POLL_TIME; |
| 2233 | } |
| 2234 | break; |
| 2235 | case USB_CHG_STATE_DCD_DONE: |
| 2236 | vout = msm_chg_check_primary_det(motg); |
Pavankumar Kondeti | 9ec21d3 | 2012-05-07 15:50:23 +0530 | [diff] [blame] | 2237 | line_state = readl_relaxed(USB_PORTSC) & PORTSC_LS; |
| 2238 | dm_vlgc = line_state & PORTSC_LS_DM; |
| 2239 | if (vout && !dm_vlgc) { /* VDAT_REF < DM < VLGC */ |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2240 | if (test_bit(ID_A, &motg->inputs)) { |
| 2241 | motg->chg_type = USB_ACA_DOCK_CHARGER; |
| 2242 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 2243 | delay = 0; |
| 2244 | break; |
| 2245 | } |
Pavankumar Kondeti | 9ec21d3 | 2012-05-07 15:50:23 +0530 | [diff] [blame] | 2246 | if (line_state) { /* DP > VLGC */ |
| 2247 | motg->chg_type = USB_PROPRIETARY_CHARGER; |
| 2248 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 2249 | delay = 0; |
| 2250 | } else { |
| 2251 | msm_chg_enable_secondary_det(motg); |
| 2252 | delay = MSM_CHG_SECONDARY_DET_TIME; |
| 2253 | motg->chg_state = USB_CHG_STATE_PRIMARY_DONE; |
| 2254 | } |
| 2255 | } else { /* DM < VDAT_REF || DM > VLGC */ |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2256 | if (test_bit(ID_A, &motg->inputs)) { |
| 2257 | motg->chg_type = USB_ACA_A_CHARGER; |
| 2258 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 2259 | delay = 0; |
| 2260 | break; |
| 2261 | } |
Pavankumar Kondeti | 9ec21d3 | 2012-05-07 15:50:23 +0530 | [diff] [blame] | 2262 | |
| 2263 | if (line_state) /* DP > VLGC or/and DM > VLGC */ |
| 2264 | motg->chg_type = USB_PROPRIETARY_CHARGER; |
| 2265 | else |
| 2266 | motg->chg_type = USB_SDP_CHARGER; |
| 2267 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2268 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 2269 | delay = 0; |
| 2270 | } |
| 2271 | break; |
| 2272 | case USB_CHG_STATE_PRIMARY_DONE: |
| 2273 | vout = msm_chg_check_secondary_det(motg); |
| 2274 | if (vout) |
| 2275 | motg->chg_type = USB_DCP_CHARGER; |
| 2276 | else |
| 2277 | motg->chg_type = USB_CDP_CHARGER; |
| 2278 | motg->chg_state = USB_CHG_STATE_SECONDARY_DONE; |
| 2279 | /* fall through */ |
| 2280 | case USB_CHG_STATE_SECONDARY_DONE: |
| 2281 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 2282 | case USB_CHG_STATE_DETECTED: |
Pavankumar Kondeti | d7b6d1a | 2013-01-11 15:38:09 +0530 | [diff] [blame] | 2283 | /* |
| 2284 | * Notify the charger type to power supply |
| 2285 | * owner as soon as we determine the charger. |
| 2286 | */ |
| 2287 | msm_otg_notify_chg_type(motg); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2288 | msm_chg_block_off(motg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2289 | msm_chg_enable_aca_det(motg); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2290 | /* |
| 2291 | * Spurious interrupt is seen after enabling ACA detection |
| 2292 | * due to which charger detection fails in case of PET. |
| 2293 | * Add delay of 100 microsec to avoid that. |
| 2294 | */ |
| 2295 | udelay(100); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2296 | msm_chg_enable_aca_intr(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2297 | dev_dbg(phy->dev, "chg_type = %s\n", |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 2298 | chg_to_string(motg->chg_type)); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2299 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2300 | return; |
| 2301 | default: |
| 2302 | return; |
| 2303 | } |
| 2304 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2305 | queue_delayed_work(system_nrt_wq, &motg->chg_work, delay); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2306 | } |
| 2307 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2308 | /* |
| 2309 | * We support OTG, Peripheral only and Host only configurations. In case |
| 2310 | * of OTG, mode switch (host-->peripheral/peripheral-->host) can happen |
| 2311 | * via Id pin status or user request (debugfs). Id/BSV interrupts are not |
| 2312 | * enabled when switch is controlled by user and default mode is supplied |
| 2313 | * by board file, which can be changed by userspace later. |
| 2314 | */ |
| 2315 | static void msm_otg_init_sm(struct msm_otg *motg) |
| 2316 | { |
| 2317 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 2318 | u32 otgsc = readl(USB_OTGSC); |
| 2319 | |
| 2320 | switch (pdata->mode) { |
| 2321 | case USB_OTG: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2322 | if (pdata->otg_control == OTG_USER_CONTROL) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2323 | if (pdata->default_mode == USB_HOST) { |
| 2324 | clear_bit(ID, &motg->inputs); |
| 2325 | } else if (pdata->default_mode == USB_PERIPHERAL) { |
| 2326 | set_bit(ID, &motg->inputs); |
| 2327 | set_bit(B_SESS_VLD, &motg->inputs); |
| 2328 | } else { |
| 2329 | set_bit(ID, &motg->inputs); |
| 2330 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 2331 | } |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2332 | } else if (pdata->otg_control == OTG_PHY_CONTROL) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2333 | if (otgsc & OTGSC_ID) { |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2334 | set_bit(ID, &motg->inputs); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2335 | } else { |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2336 | clear_bit(ID, &motg->inputs); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2337 | set_bit(A_BUS_REQ, &motg->inputs); |
| 2338 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2339 | if (otgsc & OTGSC_BSV) |
| 2340 | set_bit(B_SESS_VLD, &motg->inputs); |
| 2341 | else |
| 2342 | clear_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2343 | } else if (pdata->otg_control == OTG_PMIC_CONTROL) { |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 2344 | if (pdata->pmic_id_irq) { |
Pavankumar Kondeti | becab5b | 2012-11-06 16:45:10 +0530 | [diff] [blame] | 2345 | if (msm_otg_read_pmic_id_state(motg)) |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 2346 | set_bit(ID, &motg->inputs); |
| 2347 | else |
| 2348 | clear_bit(ID, &motg->inputs); |
| 2349 | } |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2350 | /* |
| 2351 | * VBUS initial state is reported after PMIC |
| 2352 | * driver initialization. Wait for it. |
| 2353 | */ |
| 2354 | wait_for_completion(&pmic_vbus_init); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2355 | } |
| 2356 | break; |
| 2357 | case USB_HOST: |
| 2358 | clear_bit(ID, &motg->inputs); |
| 2359 | break; |
| 2360 | case USB_PERIPHERAL: |
| 2361 | set_bit(ID, &motg->inputs); |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 2362 | if (pdata->otg_control == OTG_PHY_CONTROL) { |
| 2363 | if (otgsc & OTGSC_BSV) |
| 2364 | set_bit(B_SESS_VLD, &motg->inputs); |
| 2365 | else |
| 2366 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 2367 | } else if (pdata->otg_control == OTG_PMIC_CONTROL) { |
| 2368 | /* |
| 2369 | * VBUS initial state is reported after PMIC |
| 2370 | * driver initialization. Wait for it. |
| 2371 | */ |
| 2372 | wait_for_completion(&pmic_vbus_init); |
| 2373 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2374 | break; |
| 2375 | default: |
| 2376 | break; |
| 2377 | } |
| 2378 | } |
| 2379 | |
| 2380 | static void msm_otg_sm_work(struct work_struct *w) |
| 2381 | { |
| 2382 | struct msm_otg *motg = container_of(w, struct msm_otg, sm_work); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2383 | struct usb_otg *otg = motg->phy.otg; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2384 | bool work = 0, srp_reqd; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2385 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2386 | pm_runtime_resume(otg->phy->dev); |
| 2387 | pr_debug("%s work\n", otg_state_string(otg->phy->state)); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2388 | switch (otg->phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2389 | case OTG_STATE_UNDEFINED: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2390 | msm_otg_reset(otg->phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2391 | msm_otg_init_sm(motg); |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 2392 | if (!psy && legacy_power_supply) { |
| 2393 | psy = power_supply_get_by_name("usb"); |
| 2394 | |
| 2395 | if (!psy) |
| 2396 | pr_err("couldn't get usb power supply\n"); |
| 2397 | } |
| 2398 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2399 | otg->phy->state = OTG_STATE_B_IDLE; |
Pavankumar Kondeti | 8a379b4 | 2011-12-12 13:07:23 +0530 | [diff] [blame] | 2400 | if (!test_bit(B_SESS_VLD, &motg->inputs) && |
| 2401 | test_bit(ID, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2402 | pm_runtime_put_noidle(otg->phy->dev); |
| 2403 | pm_runtime_suspend(otg->phy->dev); |
Pavankumar Kondeti | 8a379b4 | 2011-12-12 13:07:23 +0530 | [diff] [blame] | 2404 | break; |
| 2405 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2406 | /* FALL THROUGH */ |
| 2407 | case OTG_STATE_B_IDLE: |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 2408 | if (test_bit(MHL, &motg->inputs)) { |
| 2409 | /* allow LPM */ |
| 2410 | pm_runtime_put_noidle(otg->phy->dev); |
| 2411 | pm_runtime_suspend(otg->phy->dev); |
| 2412 | } else if ((!test_bit(ID, &motg->inputs) || |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2413 | test_bit(ID_A, &motg->inputs)) && otg->host) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2414 | pr_debug("!id || id_A\n"); |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 2415 | if (msm_chg_mhl_detect(motg)) { |
| 2416 | work = 1; |
| 2417 | break; |
| 2418 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2419 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2420 | set_bit(A_BUS_REQ, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2421 | otg->phy->state = OTG_STATE_A_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2422 | work = 1; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2423 | } else if (test_bit(B_SESS_VLD, &motg->inputs)) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2424 | pr_debug("b_sess_vld\n"); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2425 | switch (motg->chg_state) { |
| 2426 | case USB_CHG_STATE_UNDEFINED: |
| 2427 | msm_chg_detect_work(&motg->chg_work.work); |
| 2428 | break; |
| 2429 | case USB_CHG_STATE_DETECTED: |
| 2430 | switch (motg->chg_type) { |
| 2431 | case USB_DCP_CHARGER: |
Pavankumar Kondeti | 283146f | 2012-01-12 12:51:19 +0530 | [diff] [blame] | 2432 | /* Enable VDP_SRC */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2433 | ulpi_write(otg->phy, 0x2, 0x85); |
Pavankumar Kondeti | 9ec21d3 | 2012-05-07 15:50:23 +0530 | [diff] [blame] | 2434 | /* fall through */ |
| 2435 | case USB_PROPRIETARY_CHARGER: |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2436 | msm_otg_notify_charger(motg, |
| 2437 | IDEV_CHG_MAX); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2438 | pm_runtime_put_noidle(otg->phy->dev); |
| 2439 | pm_runtime_suspend(otg->phy->dev); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2440 | break; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2441 | case USB_ACA_B_CHARGER: |
| 2442 | msm_otg_notify_charger(motg, |
| 2443 | IDEV_ACA_CHG_MAX); |
| 2444 | /* |
| 2445 | * (ID_B --> ID_C) PHY_ALT interrupt can |
| 2446 | * not be detected in LPM. |
| 2447 | */ |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2448 | break; |
| 2449 | case USB_CDP_CHARGER: |
| 2450 | msm_otg_notify_charger(motg, |
| 2451 | IDEV_CHG_MAX); |
| 2452 | msm_otg_start_peripheral(otg, 1); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2453 | otg->phy->state = |
| 2454 | OTG_STATE_B_PERIPHERAL; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2455 | break; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2456 | case USB_ACA_C_CHARGER: |
| 2457 | msm_otg_notify_charger(motg, |
| 2458 | IDEV_ACA_CHG_MAX); |
| 2459 | msm_otg_start_peripheral(otg, 1); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2460 | otg->phy->state = |
| 2461 | OTG_STATE_B_PERIPHERAL; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2462 | break; |
| 2463 | case USB_SDP_CHARGER: |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2464 | msm_otg_start_peripheral(otg, 1); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2465 | otg->phy->state = |
| 2466 | OTG_STATE_B_PERIPHERAL; |
Pavankumar Kondeti | 458d879 | 2012-09-28 14:45:18 +0530 | [diff] [blame] | 2467 | mod_timer(&motg->chg_check_timer, |
| 2468 | CHG_RECHECK_DELAY); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2469 | break; |
| 2470 | default: |
| 2471 | break; |
| 2472 | } |
| 2473 | break; |
| 2474 | default: |
| 2475 | break; |
| 2476 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2477 | } else if (test_bit(B_BUS_REQ, &motg->inputs)) { |
| 2478 | pr_debug("b_sess_end && b_bus_req\n"); |
| 2479 | if (msm_otg_start_srp(otg) < 0) { |
| 2480 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2481 | work = 1; |
| 2482 | break; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2483 | } |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2484 | otg->phy->state = OTG_STATE_B_SRP_INIT; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2485 | msm_otg_start_timer(motg, TB_SRP_FAIL, B_SRP_FAIL); |
| 2486 | break; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2487 | } else { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2488 | pr_debug("chg_work cancel"); |
Pavankumar Kondeti | 458d879 | 2012-09-28 14:45:18 +0530 | [diff] [blame] | 2489 | del_timer_sync(&motg->chg_check_timer); |
| 2490 | clear_bit(B_FALSE_SDP, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2491 | cancel_delayed_work_sync(&motg->chg_work); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2492 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 2493 | motg->chg_type = USB_INVALID_CHARGER; |
Rajkumar Raghupathy | 18fd713 | 2012-04-20 11:28:13 +0530 | [diff] [blame] | 2494 | msm_otg_notify_charger(motg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2495 | msm_otg_reset(otg->phy); |
Pavankumar Kondeti | becab5b | 2012-11-06 16:45:10 +0530 | [diff] [blame] | 2496 | /* |
| 2497 | * There is a small window where ID interrupt |
| 2498 | * is not monitored during ID detection circuit |
| 2499 | * switch from ACA to PMIC. Check ID state |
| 2500 | * before entering into low power mode. |
| 2501 | */ |
| 2502 | if (!msm_otg_read_pmic_id_state(motg)) { |
| 2503 | pr_debug("process missed ID intr\n"); |
| 2504 | clear_bit(ID, &motg->inputs); |
| 2505 | work = 1; |
| 2506 | break; |
| 2507 | } |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2508 | pm_runtime_put_noidle(otg->phy->dev); |
Amit Blay | d6f3828 | 2012-10-29 13:13:46 +0200 | [diff] [blame] | 2509 | /* |
| 2510 | * Only if autosuspend was enabled in probe, it will be |
| 2511 | * used here. Otherwise, no delay will be used. |
| 2512 | */ |
| 2513 | pm_runtime_mark_last_busy(otg->phy->dev); |
| 2514 | pm_runtime_autosuspend(otg->phy->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2515 | } |
| 2516 | break; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2517 | case OTG_STATE_B_SRP_INIT: |
| 2518 | if (!test_bit(ID, &motg->inputs) || |
| 2519 | test_bit(ID_A, &motg->inputs) || |
| 2520 | test_bit(ID_C, &motg->inputs) || |
| 2521 | (test_bit(B_SESS_VLD, &motg->inputs) && |
| 2522 | !test_bit(ID_B, &motg->inputs))) { |
| 2523 | pr_debug("!id || id_a/c || b_sess_vld+!id_b\n"); |
| 2524 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2525 | otg->phy->state = OTG_STATE_B_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2526 | /* |
| 2527 | * clear VBUSVLDEXTSEL and VBUSVLDEXT register |
| 2528 | * bits after SRP initiation. |
| 2529 | */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2530 | ulpi_write(otg->phy, 0x0, 0x98); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2531 | work = 1; |
| 2532 | } else if (test_bit(B_SRP_FAIL, &motg->tmouts)) { |
| 2533 | pr_debug("b_srp_fail\n"); |
| 2534 | pr_info("A-device did not respond to SRP\n"); |
| 2535 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2536 | clear_bit(B_SRP_FAIL, &motg->tmouts); |
| 2537 | otg_send_event(OTG_EVENT_NO_RESP_FOR_SRP); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2538 | ulpi_write(otg->phy, 0x0, 0x98); |
| 2539 | otg->phy->state = OTG_STATE_B_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2540 | motg->b_last_se0_sess = jiffies; |
| 2541 | work = 1; |
| 2542 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2543 | break; |
| 2544 | case OTG_STATE_B_PERIPHERAL: |
Pavankumar Kondeti | 458d879 | 2012-09-28 14:45:18 +0530 | [diff] [blame] | 2545 | if (test_bit(B_SESS_VLD, &motg->inputs) && |
| 2546 | test_bit(B_FALSE_SDP, &motg->inputs)) { |
| 2547 | pr_debug("B_FALSE_SDP\n"); |
| 2548 | msm_otg_start_peripheral(otg, 0); |
| 2549 | motg->chg_type = USB_DCP_CHARGER; |
| 2550 | clear_bit(B_FALSE_SDP, &motg->inputs); |
| 2551 | otg->phy->state = OTG_STATE_B_IDLE; |
| 2552 | work = 1; |
| 2553 | } else if (!test_bit(ID, &motg->inputs) || |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2554 | test_bit(ID_A, &motg->inputs) || |
| 2555 | test_bit(ID_B, &motg->inputs) || |
| 2556 | !test_bit(B_SESS_VLD, &motg->inputs)) { |
| 2557 | pr_debug("!id || id_a/b || !b_sess_vld\n"); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2558 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 2559 | motg->chg_type = USB_INVALID_CHARGER; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2560 | msm_otg_notify_charger(motg, 0); |
| 2561 | srp_reqd = otg->gadget->otg_srp_reqd; |
| 2562 | msm_otg_start_peripheral(otg, 0); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2563 | if (test_bit(ID_B, &motg->inputs)) |
| 2564 | clear_bit(ID_B, &motg->inputs); |
| 2565 | clear_bit(B_BUS_REQ, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2566 | otg->phy->state = OTG_STATE_B_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2567 | motg->b_last_se0_sess = jiffies; |
| 2568 | if (srp_reqd) |
| 2569 | msm_otg_start_timer(motg, |
| 2570 | TB_TST_SRP, B_TST_SRP); |
| 2571 | else |
| 2572 | work = 1; |
| 2573 | } else if (test_bit(B_BUS_REQ, &motg->inputs) && |
| 2574 | otg->gadget->b_hnp_enable && |
| 2575 | test_bit(A_BUS_SUSPEND, &motg->inputs)) { |
| 2576 | pr_debug("b_bus_req && b_hnp_en && a_bus_suspend\n"); |
| 2577 | msm_otg_start_timer(motg, TB_ASE0_BRST, B_ASE0_BRST); |
| 2578 | /* D+ pullup should not be disconnected within 4msec |
| 2579 | * after A device suspends the bus. Otherwise PET will |
| 2580 | * fail the compliance test. |
| 2581 | */ |
| 2582 | udelay(1000); |
| 2583 | msm_otg_start_peripheral(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2584 | otg->phy->state = OTG_STATE_B_WAIT_ACON; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2585 | /* |
| 2586 | * start HCD even before A-device enable |
| 2587 | * pull-up to meet HNP timings. |
| 2588 | */ |
| 2589 | otg->host->is_b_host = 1; |
| 2590 | msm_otg_start_host(otg, 1); |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 2591 | } else if (test_bit(A_BUS_SUSPEND, &motg->inputs) && |
| 2592 | test_bit(B_SESS_VLD, &motg->inputs)) { |
| 2593 | pr_debug("a_bus_suspend && b_sess_vld\n"); |
| 2594 | if (motg->caps & ALLOW_LPM_ON_DEV_SUSPEND) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2595 | pm_runtime_put_noidle(otg->phy->dev); |
| 2596 | pm_runtime_suspend(otg->phy->dev); |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 2597 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2598 | } else if (test_bit(ID_C, &motg->inputs)) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2599 | msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2600 | } |
| 2601 | break; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2602 | case OTG_STATE_B_WAIT_ACON: |
| 2603 | if (!test_bit(ID, &motg->inputs) || |
| 2604 | test_bit(ID_A, &motg->inputs) || |
| 2605 | test_bit(ID_B, &motg->inputs) || |
| 2606 | !test_bit(B_SESS_VLD, &motg->inputs)) { |
| 2607 | pr_debug("!id || id_a/b || !b_sess_vld\n"); |
| 2608 | msm_otg_del_timer(motg); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2609 | /* |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2610 | * A-device is physically disconnected during |
| 2611 | * HNP. Remove HCD. |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2612 | */ |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2613 | msm_otg_start_host(otg, 0); |
| 2614 | otg->host->is_b_host = 0; |
| 2615 | |
| 2616 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2617 | clear_bit(A_BUS_SUSPEND, &motg->inputs); |
| 2618 | motg->b_last_se0_sess = jiffies; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2619 | otg->phy->state = OTG_STATE_B_IDLE; |
| 2620 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2621 | work = 1; |
| 2622 | } else if (test_bit(A_CONN, &motg->inputs)) { |
| 2623 | pr_debug("a_conn\n"); |
| 2624 | clear_bit(A_BUS_SUSPEND, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2625 | otg->phy->state = OTG_STATE_B_HOST; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2626 | /* |
| 2627 | * PET disconnects D+ pullup after reset is generated |
| 2628 | * by B device in B_HOST role which is not detected by |
| 2629 | * B device. As workaorund , start timer of 300msec |
| 2630 | * and stop timer if A device is enumerated else clear |
| 2631 | * A_CONN. |
| 2632 | */ |
| 2633 | msm_otg_start_timer(motg, TB_TST_CONFIG, |
| 2634 | B_TST_CONFIG); |
| 2635 | } else if (test_bit(B_ASE0_BRST, &motg->tmouts)) { |
| 2636 | pr_debug("b_ase0_brst_tmout\n"); |
| 2637 | pr_info("B HNP fail:No response from A device\n"); |
| 2638 | msm_otg_start_host(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2639 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2640 | otg->host->is_b_host = 0; |
| 2641 | clear_bit(B_ASE0_BRST, &motg->tmouts); |
| 2642 | clear_bit(A_BUS_SUSPEND, &motg->inputs); |
| 2643 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2644 | otg_send_event(OTG_EVENT_HNP_FAILED); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2645 | otg->phy->state = OTG_STATE_B_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2646 | work = 1; |
| 2647 | } else if (test_bit(ID_C, &motg->inputs)) { |
| 2648 | msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX); |
| 2649 | } |
| 2650 | break; |
| 2651 | case OTG_STATE_B_HOST: |
| 2652 | if (!test_bit(B_BUS_REQ, &motg->inputs) || |
| 2653 | !test_bit(A_CONN, &motg->inputs) || |
| 2654 | !test_bit(B_SESS_VLD, &motg->inputs)) { |
| 2655 | pr_debug("!b_bus_req || !a_conn || !b_sess_vld\n"); |
| 2656 | clear_bit(A_CONN, &motg->inputs); |
| 2657 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2658 | msm_otg_start_host(otg, 0); |
| 2659 | otg->host->is_b_host = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2660 | otg->phy->state = OTG_STATE_B_IDLE; |
| 2661 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2662 | work = 1; |
| 2663 | } else if (test_bit(ID_C, &motg->inputs)) { |
| 2664 | msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX); |
| 2665 | } |
| 2666 | break; |
| 2667 | case OTG_STATE_A_IDLE: |
| 2668 | otg->default_a = 1; |
| 2669 | if (test_bit(ID, &motg->inputs) && |
| 2670 | !test_bit(ID_A, &motg->inputs)) { |
| 2671 | pr_debug("id && !id_a\n"); |
| 2672 | otg->default_a = 0; |
| 2673 | clear_bit(A_BUS_DROP, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2674 | otg->phy->state = OTG_STATE_B_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2675 | del_timer_sync(&motg->id_timer); |
| 2676 | msm_otg_link_reset(motg); |
| 2677 | msm_chg_enable_aca_intr(motg); |
| 2678 | msm_otg_notify_charger(motg, 0); |
| 2679 | work = 1; |
| 2680 | } else if (!test_bit(A_BUS_DROP, &motg->inputs) && |
| 2681 | (test_bit(A_SRP_DET, &motg->inputs) || |
| 2682 | test_bit(A_BUS_REQ, &motg->inputs))) { |
| 2683 | pr_debug("!a_bus_drop && (a_srp_det || a_bus_req)\n"); |
| 2684 | |
| 2685 | clear_bit(A_SRP_DET, &motg->inputs); |
| 2686 | /* Disable SRP detection */ |
| 2687 | writel_relaxed((readl_relaxed(USB_OTGSC) & |
| 2688 | ~OTGSC_INTSTS_MASK) & |
| 2689 | ~OTGSC_DPIE, USB_OTGSC); |
| 2690 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2691 | otg->phy->state = OTG_STATE_A_WAIT_VRISE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2692 | /* VBUS should not be supplied before end of SRP pulse |
| 2693 | * generated by PET, if not complaince test fail. |
| 2694 | */ |
| 2695 | usleep_range(10000, 12000); |
| 2696 | /* ACA: ID_A: Stop charging untill enumeration */ |
| 2697 | if (test_bit(ID_A, &motg->inputs)) |
| 2698 | msm_otg_notify_charger(motg, 0); |
| 2699 | else |
| 2700 | msm_hsusb_vbus_power(motg, 1); |
| 2701 | msm_otg_start_timer(motg, TA_WAIT_VRISE, A_WAIT_VRISE); |
| 2702 | } else { |
| 2703 | pr_debug("No session requested\n"); |
| 2704 | clear_bit(A_BUS_DROP, &motg->inputs); |
| 2705 | if (test_bit(ID_A, &motg->inputs)) { |
| 2706 | msm_otg_notify_charger(motg, |
| 2707 | IDEV_ACA_CHG_MAX); |
| 2708 | } else if (!test_bit(ID, &motg->inputs)) { |
| 2709 | msm_otg_notify_charger(motg, 0); |
| 2710 | /* |
| 2711 | * A-device is not providing power on VBUS. |
| 2712 | * Enable SRP detection. |
| 2713 | */ |
| 2714 | writel_relaxed(0x13, USB_USBMODE); |
| 2715 | writel_relaxed((readl_relaxed(USB_OTGSC) & |
| 2716 | ~OTGSC_INTSTS_MASK) | |
| 2717 | OTGSC_DPIE, USB_OTGSC); |
| 2718 | mb(); |
| 2719 | } |
| 2720 | } |
| 2721 | break; |
| 2722 | case OTG_STATE_A_WAIT_VRISE: |
| 2723 | if ((test_bit(ID, &motg->inputs) && |
| 2724 | !test_bit(ID_A, &motg->inputs)) || |
| 2725 | test_bit(A_BUS_DROP, &motg->inputs) || |
| 2726 | test_bit(A_WAIT_VRISE, &motg->tmouts)) { |
| 2727 | pr_debug("id || a_bus_drop || a_wait_vrise_tmout\n"); |
| 2728 | clear_bit(A_BUS_REQ, &motg->inputs); |
| 2729 | msm_otg_del_timer(motg); |
| 2730 | msm_hsusb_vbus_power(motg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2731 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2732 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2733 | } else if (test_bit(A_VBUS_VLD, &motg->inputs)) { |
| 2734 | pr_debug("a_vbus_vld\n"); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2735 | otg->phy->state = OTG_STATE_A_WAIT_BCON; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2736 | if (TA_WAIT_BCON > 0) |
| 2737 | msm_otg_start_timer(motg, TA_WAIT_BCON, |
| 2738 | A_WAIT_BCON); |
| 2739 | msm_otg_start_host(otg, 1); |
| 2740 | msm_chg_enable_aca_det(motg); |
| 2741 | msm_chg_disable_aca_intr(motg); |
Chiranjeevi Velempati | 489a27c | 2012-03-29 09:47:17 +0530 | [diff] [blame] | 2742 | mod_timer(&motg->id_timer, ID_TIMER_FREQ); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2743 | if (msm_chg_check_aca_intr(motg)) |
| 2744 | work = 1; |
| 2745 | } |
| 2746 | break; |
| 2747 | case OTG_STATE_A_WAIT_BCON: |
| 2748 | if ((test_bit(ID, &motg->inputs) && |
| 2749 | !test_bit(ID_A, &motg->inputs)) || |
| 2750 | test_bit(A_BUS_DROP, &motg->inputs) || |
| 2751 | test_bit(A_WAIT_BCON, &motg->tmouts)) { |
| 2752 | pr_debug("(id && id_a/b/c) || a_bus_drop ||" |
| 2753 | "a_wait_bcon_tmout\n"); |
| 2754 | if (test_bit(A_WAIT_BCON, &motg->tmouts)) { |
| 2755 | pr_info("Device No Response\n"); |
| 2756 | otg_send_event(OTG_EVENT_DEV_CONN_TMOUT); |
| 2757 | } |
| 2758 | msm_otg_del_timer(motg); |
| 2759 | clear_bit(A_BUS_REQ, &motg->inputs); |
| 2760 | clear_bit(B_CONN, &motg->inputs); |
| 2761 | msm_otg_start_host(otg, 0); |
| 2762 | /* |
| 2763 | * ACA: ID_A with NO accessory, just the A plug is |
| 2764 | * attached to ACA: Use IDCHG_MAX for charging |
| 2765 | */ |
| 2766 | if (test_bit(ID_A, &motg->inputs)) |
| 2767 | msm_otg_notify_charger(motg, IDEV_CHG_MIN); |
| 2768 | else |
| 2769 | msm_hsusb_vbus_power(motg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2770 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2771 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2772 | } else if (!test_bit(A_VBUS_VLD, &motg->inputs)) { |
| 2773 | pr_debug("!a_vbus_vld\n"); |
| 2774 | clear_bit(B_CONN, &motg->inputs); |
| 2775 | msm_otg_del_timer(motg); |
| 2776 | msm_otg_start_host(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2777 | otg->phy->state = OTG_STATE_A_VBUS_ERR; |
| 2778 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2779 | } else if (test_bit(ID_A, &motg->inputs)) { |
| 2780 | msm_hsusb_vbus_power(motg, 0); |
| 2781 | } else if (!test_bit(A_BUS_REQ, &motg->inputs)) { |
| 2782 | /* |
| 2783 | * If TA_WAIT_BCON is infinite, we don;t |
| 2784 | * turn off VBUS. Enter low power mode. |
| 2785 | */ |
| 2786 | if (TA_WAIT_BCON < 0) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2787 | pm_runtime_put_sync(otg->phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2788 | } else if (!test_bit(ID, &motg->inputs)) { |
| 2789 | msm_hsusb_vbus_power(motg, 1); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2790 | } |
| 2791 | break; |
| 2792 | case OTG_STATE_A_HOST: |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2793 | if ((test_bit(ID, &motg->inputs) && |
| 2794 | !test_bit(ID_A, &motg->inputs)) || |
| 2795 | test_bit(A_BUS_DROP, &motg->inputs)) { |
| 2796 | pr_debug("id_a/b/c || a_bus_drop\n"); |
| 2797 | clear_bit(B_CONN, &motg->inputs); |
| 2798 | clear_bit(A_BUS_REQ, &motg->inputs); |
| 2799 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2800 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2801 | msm_otg_start_host(otg, 0); |
| 2802 | if (!test_bit(ID_A, &motg->inputs)) |
| 2803 | msm_hsusb_vbus_power(motg, 0); |
| 2804 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2805 | } else if (!test_bit(A_VBUS_VLD, &motg->inputs)) { |
| 2806 | pr_debug("!a_vbus_vld\n"); |
| 2807 | clear_bit(B_CONN, &motg->inputs); |
| 2808 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2809 | otg->phy->state = OTG_STATE_A_VBUS_ERR; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2810 | msm_otg_start_host(otg, 0); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2811 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2812 | } else if (!test_bit(A_BUS_REQ, &motg->inputs)) { |
| 2813 | /* |
| 2814 | * a_bus_req is de-asserted when root hub is |
| 2815 | * suspended or HNP is in progress. |
| 2816 | */ |
| 2817 | pr_debug("!a_bus_req\n"); |
| 2818 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2819 | otg->phy->state = OTG_STATE_A_SUSPEND; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2820 | if (otg->host->b_hnp_enable) |
| 2821 | msm_otg_start_timer(motg, TA_AIDL_BDIS, |
| 2822 | A_AIDL_BDIS); |
| 2823 | else |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2824 | pm_runtime_put_sync(otg->phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2825 | } else if (!test_bit(B_CONN, &motg->inputs)) { |
| 2826 | pr_debug("!b_conn\n"); |
| 2827 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2828 | otg->phy->state = OTG_STATE_A_WAIT_BCON; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2829 | if (TA_WAIT_BCON > 0) |
| 2830 | msm_otg_start_timer(motg, TA_WAIT_BCON, |
| 2831 | A_WAIT_BCON); |
| 2832 | if (msm_chg_check_aca_intr(motg)) |
| 2833 | work = 1; |
| 2834 | } else if (test_bit(ID_A, &motg->inputs)) { |
| 2835 | msm_otg_del_timer(motg); |
| 2836 | msm_hsusb_vbus_power(motg, 0); |
| 2837 | if (motg->chg_type == USB_ACA_DOCK_CHARGER) |
| 2838 | msm_otg_notify_charger(motg, |
| 2839 | IDEV_ACA_CHG_MAX); |
| 2840 | else |
| 2841 | msm_otg_notify_charger(motg, |
| 2842 | IDEV_CHG_MIN - motg->mA_port); |
| 2843 | } else if (!test_bit(ID, &motg->inputs)) { |
| 2844 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 2845 | motg->chg_type = USB_INVALID_CHARGER; |
| 2846 | msm_otg_notify_charger(motg, 0); |
| 2847 | msm_hsusb_vbus_power(motg, 1); |
| 2848 | } |
| 2849 | break; |
| 2850 | case OTG_STATE_A_SUSPEND: |
| 2851 | if ((test_bit(ID, &motg->inputs) && |
| 2852 | !test_bit(ID_A, &motg->inputs)) || |
| 2853 | test_bit(A_BUS_DROP, &motg->inputs) || |
| 2854 | test_bit(A_AIDL_BDIS, &motg->tmouts)) { |
| 2855 | pr_debug("id_a/b/c || a_bus_drop ||" |
| 2856 | "a_aidl_bdis_tmout\n"); |
| 2857 | msm_otg_del_timer(motg); |
| 2858 | clear_bit(B_CONN, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2859 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2860 | msm_otg_start_host(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2861 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2862 | if (!test_bit(ID_A, &motg->inputs)) |
| 2863 | msm_hsusb_vbus_power(motg, 0); |
| 2864 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2865 | } else if (!test_bit(A_VBUS_VLD, &motg->inputs)) { |
| 2866 | pr_debug("!a_vbus_vld\n"); |
| 2867 | msm_otg_del_timer(motg); |
| 2868 | clear_bit(B_CONN, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2869 | otg->phy->state = OTG_STATE_A_VBUS_ERR; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2870 | msm_otg_start_host(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2871 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2872 | } else if (!test_bit(B_CONN, &motg->inputs) && |
| 2873 | otg->host->b_hnp_enable) { |
| 2874 | pr_debug("!b_conn && b_hnp_enable"); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2875 | otg->phy->state = OTG_STATE_A_PERIPHERAL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2876 | msm_otg_host_hnp_enable(otg, 1); |
| 2877 | otg->gadget->is_a_peripheral = 1; |
| 2878 | msm_otg_start_peripheral(otg, 1); |
| 2879 | } else if (!test_bit(B_CONN, &motg->inputs) && |
| 2880 | !otg->host->b_hnp_enable) { |
| 2881 | pr_debug("!b_conn && !b_hnp_enable"); |
| 2882 | /* |
| 2883 | * bus request is dropped during suspend. |
| 2884 | * acquire again for next device. |
| 2885 | */ |
| 2886 | set_bit(A_BUS_REQ, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2887 | otg->phy->state = OTG_STATE_A_WAIT_BCON; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2888 | if (TA_WAIT_BCON > 0) |
| 2889 | msm_otg_start_timer(motg, TA_WAIT_BCON, |
| 2890 | A_WAIT_BCON); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2891 | } else if (test_bit(ID_A, &motg->inputs)) { |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 2892 | msm_hsusb_vbus_power(motg, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2893 | msm_otg_notify_charger(motg, |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2894 | IDEV_CHG_MIN - motg->mA_port); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2895 | } else if (!test_bit(ID, &motg->inputs)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2896 | msm_otg_notify_charger(motg, 0); |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 2897 | msm_hsusb_vbus_power(motg, 1); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2898 | } |
| 2899 | break; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2900 | case OTG_STATE_A_PERIPHERAL: |
| 2901 | if ((test_bit(ID, &motg->inputs) && |
| 2902 | !test_bit(ID_A, &motg->inputs)) || |
| 2903 | test_bit(A_BUS_DROP, &motg->inputs)) { |
| 2904 | pr_debug("id _f/b/c || a_bus_drop\n"); |
| 2905 | /* Clear BIDL_ADIS timer */ |
| 2906 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2907 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2908 | msm_otg_start_peripheral(otg, 0); |
| 2909 | otg->gadget->is_a_peripheral = 0; |
| 2910 | msm_otg_start_host(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2911 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2912 | if (!test_bit(ID_A, &motg->inputs)) |
| 2913 | msm_hsusb_vbus_power(motg, 0); |
| 2914 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2915 | } else if (!test_bit(A_VBUS_VLD, &motg->inputs)) { |
| 2916 | pr_debug("!a_vbus_vld\n"); |
| 2917 | /* Clear BIDL_ADIS timer */ |
| 2918 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2919 | otg->phy->state = OTG_STATE_A_VBUS_ERR; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2920 | msm_otg_start_peripheral(otg, 0); |
| 2921 | otg->gadget->is_a_peripheral = 0; |
| 2922 | msm_otg_start_host(otg, 0); |
| 2923 | } else if (test_bit(A_BIDL_ADIS, &motg->tmouts)) { |
| 2924 | pr_debug("a_bidl_adis_tmout\n"); |
| 2925 | msm_otg_start_peripheral(otg, 0); |
| 2926 | otg->gadget->is_a_peripheral = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2927 | otg->phy->state = OTG_STATE_A_WAIT_BCON; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2928 | set_bit(A_BUS_REQ, &motg->inputs); |
| 2929 | msm_otg_host_hnp_enable(otg, 0); |
| 2930 | if (TA_WAIT_BCON > 0) |
| 2931 | msm_otg_start_timer(motg, TA_WAIT_BCON, |
| 2932 | A_WAIT_BCON); |
| 2933 | } else if (test_bit(ID_A, &motg->inputs)) { |
| 2934 | msm_hsusb_vbus_power(motg, 0); |
| 2935 | msm_otg_notify_charger(motg, |
| 2936 | IDEV_CHG_MIN - motg->mA_port); |
| 2937 | } else if (!test_bit(ID, &motg->inputs)) { |
| 2938 | msm_otg_notify_charger(motg, 0); |
| 2939 | msm_hsusb_vbus_power(motg, 1); |
| 2940 | } |
| 2941 | break; |
| 2942 | case OTG_STATE_A_WAIT_VFALL: |
| 2943 | if (test_bit(A_WAIT_VFALL, &motg->tmouts)) { |
| 2944 | clear_bit(A_VBUS_VLD, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2945 | otg->phy->state = OTG_STATE_A_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2946 | work = 1; |
| 2947 | } |
| 2948 | break; |
| 2949 | case OTG_STATE_A_VBUS_ERR: |
| 2950 | if ((test_bit(ID, &motg->inputs) && |
| 2951 | !test_bit(ID_A, &motg->inputs)) || |
| 2952 | test_bit(A_BUS_DROP, &motg->inputs) || |
| 2953 | test_bit(A_CLR_ERR, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2954 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2955 | if (!test_bit(ID_A, &motg->inputs)) |
| 2956 | msm_hsusb_vbus_power(motg, 0); |
| 2957 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2958 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 2959 | motg->chg_type = USB_INVALID_CHARGER; |
| 2960 | msm_otg_notify_charger(motg, 0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2961 | } |
| 2962 | break; |
| 2963 | default: |
| 2964 | break; |
| 2965 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2966 | if (work) |
| 2967 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2968 | } |
| 2969 | |
Amit Blay | d0fe07b | 2012-09-05 16:42:09 +0300 | [diff] [blame] | 2970 | static void msm_otg_suspend_work(struct work_struct *w) |
| 2971 | { |
| 2972 | struct msm_otg *motg = |
| 2973 | container_of(w, struct msm_otg, suspend_work.work); |
Pavankumar Kondeti | e618bf8 | 2012-11-28 21:12:44 +0530 | [diff] [blame] | 2974 | |
| 2975 | /* This work is only for device bus suspend */ |
| 2976 | if (test_bit(A_BUS_SUSPEND, &motg->inputs)) |
| 2977 | msm_otg_sm_work(&motg->sm_work); |
Amit Blay | d0fe07b | 2012-09-05 16:42:09 +0300 | [diff] [blame] | 2978 | } |
| 2979 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2980 | static irqreturn_t msm_otg_irq(int irq, void *data) |
| 2981 | { |
| 2982 | struct msm_otg *motg = data; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2983 | struct usb_otg *otg = motg->phy.otg; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2984 | u32 otgsc = 0, usbsts, pc; |
| 2985 | bool work = 0; |
| 2986 | irqreturn_t ret = IRQ_HANDLED; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2987 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2988 | if (atomic_read(&motg->in_lpm)) { |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 2989 | pr_debug("OTG IRQ: %d in LPM\n", irq); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2990 | disable_irq_nosync(irq); |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 2991 | motg->async_int = irq; |
Jack Pham | c7edb17 | 2012-08-13 15:32:39 -0700 | [diff] [blame] | 2992 | if (!atomic_read(&motg->pm_suspended)) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2993 | pm_request_resume(otg->phy->dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2994 | return IRQ_HANDLED; |
| 2995 | } |
| 2996 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2997 | usbsts = readl(USB_USBSTS); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2998 | otgsc = readl(USB_OTGSC); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2999 | |
| 3000 | if (!(otgsc & OTG_OTGSTS_MASK) && !(usbsts & OTG_USBSTS_MASK)) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3001 | return IRQ_NONE; |
| 3002 | |
| 3003 | if ((otgsc & OTGSC_IDIS) && (otgsc & OTGSC_IDIE)) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3004 | if (otgsc & OTGSC_ID) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3005 | pr_debug("Id set\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3006 | set_bit(ID, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3007 | } else { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3008 | pr_debug("Id clear\n"); |
| 3009 | /* |
| 3010 | * Assert a_bus_req to supply power on |
| 3011 | * VBUS when Micro/Mini-A cable is connected |
| 3012 | * with out user intervention. |
| 3013 | */ |
| 3014 | set_bit(A_BUS_REQ, &motg->inputs); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3015 | clear_bit(ID, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3016 | msm_chg_enable_aca_det(motg); |
| 3017 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3018 | writel_relaxed(otgsc, USB_OTGSC); |
| 3019 | work = 1; |
| 3020 | } else if (otgsc & OTGSC_DPIS) { |
| 3021 | pr_debug("DPIS detected\n"); |
| 3022 | writel_relaxed(otgsc, USB_OTGSC); |
| 3023 | set_bit(A_SRP_DET, &motg->inputs); |
| 3024 | set_bit(A_BUS_REQ, &motg->inputs); |
| 3025 | work = 1; |
| 3026 | } else if (otgsc & OTGSC_BSVIS) { |
| 3027 | writel_relaxed(otgsc, USB_OTGSC); |
| 3028 | /* |
| 3029 | * BSV interrupt comes when operating as an A-device |
| 3030 | * (VBUS on/off). |
| 3031 | * But, handle BSV when charger is removed from ACA in ID_A |
| 3032 | */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3033 | if ((otg->phy->state >= OTG_STATE_A_IDLE) && |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3034 | !test_bit(ID_A, &motg->inputs)) |
| 3035 | return IRQ_HANDLED; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3036 | if (otgsc & OTGSC_BSV) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3037 | pr_debug("BSV set\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3038 | set_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3039 | } else { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3040 | pr_debug("BSV clear\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3041 | clear_bit(B_SESS_VLD, &motg->inputs); |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 3042 | clear_bit(A_BUS_SUSPEND, &motg->inputs); |
| 3043 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3044 | msm_chg_check_aca_intr(motg); |
| 3045 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3046 | work = 1; |
| 3047 | } else if (usbsts & STS_PCI) { |
| 3048 | pc = readl_relaxed(USB_PORTSC); |
| 3049 | pr_debug("portsc = %x\n", pc); |
| 3050 | ret = IRQ_NONE; |
| 3051 | /* |
| 3052 | * HCD Acks PCI interrupt. We use this to switch |
| 3053 | * between different OTG states. |
| 3054 | */ |
| 3055 | work = 1; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3056 | switch (otg->phy->state) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3057 | case OTG_STATE_A_SUSPEND: |
| 3058 | if (otg->host->b_hnp_enable && (pc & PORTSC_CSC) && |
| 3059 | !(pc & PORTSC_CCS)) { |
| 3060 | pr_debug("B_CONN clear\n"); |
| 3061 | clear_bit(B_CONN, &motg->inputs); |
| 3062 | msm_otg_del_timer(motg); |
| 3063 | } |
| 3064 | break; |
| 3065 | case OTG_STATE_A_PERIPHERAL: |
| 3066 | /* |
| 3067 | * A-peripheral observed activity on bus. |
| 3068 | * clear A_BIDL_ADIS timer. |
| 3069 | */ |
| 3070 | msm_otg_del_timer(motg); |
| 3071 | work = 0; |
| 3072 | break; |
| 3073 | case OTG_STATE_B_WAIT_ACON: |
| 3074 | if ((pc & PORTSC_CSC) && (pc & PORTSC_CCS)) { |
| 3075 | pr_debug("A_CONN set\n"); |
| 3076 | set_bit(A_CONN, &motg->inputs); |
| 3077 | /* Clear ASE0_BRST timer */ |
| 3078 | msm_otg_del_timer(motg); |
| 3079 | } |
| 3080 | break; |
| 3081 | case OTG_STATE_B_HOST: |
| 3082 | if ((pc & PORTSC_CSC) && !(pc & PORTSC_CCS)) { |
| 3083 | pr_debug("A_CONN clear\n"); |
| 3084 | clear_bit(A_CONN, &motg->inputs); |
| 3085 | msm_otg_del_timer(motg); |
| 3086 | } |
| 3087 | break; |
| 3088 | case OTG_STATE_A_WAIT_BCON: |
| 3089 | if (TA_WAIT_BCON < 0) |
| 3090 | set_bit(A_BUS_REQ, &motg->inputs); |
| 3091 | default: |
| 3092 | work = 0; |
| 3093 | break; |
| 3094 | } |
| 3095 | } else if (usbsts & STS_URI) { |
| 3096 | ret = IRQ_NONE; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3097 | switch (otg->phy->state) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3098 | case OTG_STATE_A_PERIPHERAL: |
| 3099 | /* |
| 3100 | * A-peripheral observed activity on bus. |
| 3101 | * clear A_BIDL_ADIS timer. |
| 3102 | */ |
| 3103 | msm_otg_del_timer(motg); |
| 3104 | work = 0; |
| 3105 | break; |
| 3106 | default: |
| 3107 | work = 0; |
| 3108 | break; |
| 3109 | } |
| 3110 | } else if (usbsts & STS_SLI) { |
| 3111 | ret = IRQ_NONE; |
| 3112 | work = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3113 | switch (otg->phy->state) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3114 | case OTG_STATE_B_PERIPHERAL: |
| 3115 | if (otg->gadget->b_hnp_enable) { |
| 3116 | set_bit(A_BUS_SUSPEND, &motg->inputs); |
| 3117 | set_bit(B_BUS_REQ, &motg->inputs); |
| 3118 | work = 1; |
| 3119 | } |
| 3120 | break; |
| 3121 | case OTG_STATE_A_PERIPHERAL: |
| 3122 | msm_otg_start_timer(motg, TA_BIDL_ADIS, |
| 3123 | A_BIDL_ADIS); |
| 3124 | break; |
| 3125 | default: |
| 3126 | break; |
| 3127 | } |
| 3128 | } else if ((usbsts & PHY_ALT_INT)) { |
| 3129 | writel_relaxed(PHY_ALT_INT, USB_USBSTS); |
| 3130 | if (msm_chg_check_aca_intr(motg)) |
| 3131 | work = 1; |
| 3132 | ret = IRQ_HANDLED; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3133 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3134 | if (work) |
| 3135 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3136 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3137 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3138 | } |
| 3139 | |
| 3140 | static void msm_otg_set_vbus_state(int online) |
| 3141 | { |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 3142 | static bool init; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3143 | struct msm_otg *motg = the_msm_otg; |
Mayank Rana | baf31f4 | 2012-07-05 09:43:54 +0530 | [diff] [blame] | 3144 | |
Chiranjeevi Velempati | 2e1048b | 2012-11-08 09:54:33 +0530 | [diff] [blame] | 3145 | /* Ignore received BSV interrupts, if ID pin is GND */ |
Pavankumar Kondeti | bbaa46ff | 2012-12-09 20:21:02 +0530 | [diff] [blame] | 3146 | if (!test_bit(ID, &motg->inputs)) { |
| 3147 | /* |
| 3148 | * state machine work waits for initial VBUS |
| 3149 | * completion in UNDEFINED state. Process |
| 3150 | * the initial VBUS event in ID_GND state. |
| 3151 | */ |
| 3152 | if (init) |
| 3153 | return; |
| 3154 | goto complete; |
| 3155 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3156 | |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 3157 | if (online) { |
| 3158 | pr_debug("PMIC: BSV set\n"); |
| 3159 | set_bit(B_SESS_VLD, &motg->inputs); |
| 3160 | } else { |
| 3161 | pr_debug("PMIC: BSV clear\n"); |
| 3162 | clear_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3163 | } |
Pavankumar Kondeti | bbaa46ff | 2012-12-09 20:21:02 +0530 | [diff] [blame] | 3164 | complete: |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 3165 | if (!init) { |
| 3166 | init = true; |
| 3167 | complete(&pmic_vbus_init); |
| 3168 | pr_debug("PMIC: BSV init complete\n"); |
| 3169 | return; |
| 3170 | } |
| 3171 | |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 3172 | if (test_bit(MHL, &motg->inputs) || |
| 3173 | mhl_det_in_progress) { |
| 3174 | pr_debug("PMIC: BSV interrupt ignored in MHL\n"); |
| 3175 | return; |
| 3176 | } |
| 3177 | |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 3178 | if (atomic_read(&motg->pm_suspended)) |
| 3179 | motg->sm_work_pending = true; |
| 3180 | else |
| 3181 | queue_work(system_nrt_wq, &motg->sm_work); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3182 | } |
| 3183 | |
Vijayavardhan Vennapusa | 68d55cf | 2012-06-27 20:06:12 +0530 | [diff] [blame] | 3184 | static void msm_pmic_id_status_w(struct work_struct *w) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3185 | { |
Vijayavardhan Vennapusa | 68d55cf | 2012-06-27 20:06:12 +0530 | [diff] [blame] | 3186 | struct msm_otg *motg = container_of(w, struct msm_otg, |
| 3187 | pmic_id_status_work.work); |
| 3188 | int work = 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3189 | |
Pavankumar Kondeti | becab5b | 2012-11-06 16:45:10 +0530 | [diff] [blame] | 3190 | if (msm_otg_read_pmic_id_state(motg)) { |
Vijayavardhan Vennapusa | 68d55cf | 2012-06-27 20:06:12 +0530 | [diff] [blame] | 3191 | if (!test_and_set_bit(ID, &motg->inputs)) { |
| 3192 | pr_debug("PMIC: ID set\n"); |
| 3193 | work = 1; |
| 3194 | } |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 3195 | } else { |
Vijayavardhan Vennapusa | 68d55cf | 2012-06-27 20:06:12 +0530 | [diff] [blame] | 3196 | if (test_and_clear_bit(ID, &motg->inputs)) { |
| 3197 | pr_debug("PMIC: ID clear\n"); |
| 3198 | set_bit(A_BUS_REQ, &motg->inputs); |
| 3199 | work = 1; |
| 3200 | } |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 3201 | } |
| 3202 | |
Vijayavardhan Vennapusa | 68d55cf | 2012-06-27 20:06:12 +0530 | [diff] [blame] | 3203 | if (work && (motg->phy.state != OTG_STATE_UNDEFINED)) { |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 3204 | if (atomic_read(&motg->pm_suspended)) |
| 3205 | motg->sm_work_pending = true; |
| 3206 | else |
| 3207 | queue_work(system_nrt_wq, &motg->sm_work); |
| 3208 | } |
Vijayavardhan Vennapusa | 68d55cf | 2012-06-27 20:06:12 +0530 | [diff] [blame] | 3209 | |
| 3210 | } |
| 3211 | |
| 3212 | #define MSM_PMIC_ID_STATUS_DELAY 5 /* 5msec */ |
| 3213 | static irqreturn_t msm_pmic_id_irq(int irq, void *data) |
| 3214 | { |
| 3215 | struct msm_otg *motg = data; |
| 3216 | |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 3217 | if (test_bit(MHL, &motg->inputs) || |
| 3218 | mhl_det_in_progress) { |
| 3219 | pr_debug("PMIC: Id interrupt ignored in MHL\n"); |
| 3220 | return IRQ_HANDLED; |
| 3221 | } |
| 3222 | |
Vijayavardhan Vennapusa | 68d55cf | 2012-06-27 20:06:12 +0530 | [diff] [blame] | 3223 | if (!aca_id_turned_on) |
| 3224 | /*schedule delayed work for 5msec for ID line state to settle*/ |
| 3225 | queue_delayed_work(system_nrt_wq, &motg->pmic_id_status_work, |
| 3226 | msecs_to_jiffies(MSM_PMIC_ID_STATUS_DELAY)); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3227 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3228 | return IRQ_HANDLED; |
| 3229 | } |
| 3230 | |
| 3231 | static int msm_otg_mode_show(struct seq_file *s, void *unused) |
| 3232 | { |
| 3233 | struct msm_otg *motg = s->private; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3234 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3235 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3236 | switch (phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3237 | case OTG_STATE_A_HOST: |
| 3238 | seq_printf(s, "host\n"); |
| 3239 | break; |
| 3240 | case OTG_STATE_B_PERIPHERAL: |
| 3241 | seq_printf(s, "peripheral\n"); |
| 3242 | break; |
| 3243 | default: |
| 3244 | seq_printf(s, "none\n"); |
| 3245 | break; |
| 3246 | } |
| 3247 | |
| 3248 | return 0; |
| 3249 | } |
| 3250 | |
| 3251 | static int msm_otg_mode_open(struct inode *inode, struct file *file) |
| 3252 | { |
| 3253 | return single_open(file, msm_otg_mode_show, inode->i_private); |
| 3254 | } |
| 3255 | |
| 3256 | static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, |
| 3257 | size_t count, loff_t *ppos) |
| 3258 | { |
Pavankumar Kondeti | e2904ee | 2011-02-15 09:42:35 +0530 | [diff] [blame] | 3259 | struct seq_file *s = file->private_data; |
| 3260 | struct msm_otg *motg = s->private; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3261 | char buf[16]; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3262 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3263 | int status = count; |
| 3264 | enum usb_mode_type req_mode; |
| 3265 | |
| 3266 | memset(buf, 0x00, sizeof(buf)); |
| 3267 | |
| 3268 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) { |
| 3269 | status = -EFAULT; |
| 3270 | goto out; |
| 3271 | } |
| 3272 | |
| 3273 | if (!strncmp(buf, "host", 4)) { |
| 3274 | req_mode = USB_HOST; |
| 3275 | } else if (!strncmp(buf, "peripheral", 10)) { |
| 3276 | req_mode = USB_PERIPHERAL; |
| 3277 | } else if (!strncmp(buf, "none", 4)) { |
| 3278 | req_mode = USB_NONE; |
| 3279 | } else { |
| 3280 | status = -EINVAL; |
| 3281 | goto out; |
| 3282 | } |
| 3283 | |
| 3284 | switch (req_mode) { |
| 3285 | case USB_NONE: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3286 | switch (phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3287 | case OTG_STATE_A_HOST: |
| 3288 | case OTG_STATE_B_PERIPHERAL: |
| 3289 | set_bit(ID, &motg->inputs); |
| 3290 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 3291 | break; |
| 3292 | default: |
| 3293 | goto out; |
| 3294 | } |
| 3295 | break; |
| 3296 | case USB_PERIPHERAL: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3297 | switch (phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3298 | case OTG_STATE_B_IDLE: |
| 3299 | case OTG_STATE_A_HOST: |
| 3300 | set_bit(ID, &motg->inputs); |
| 3301 | set_bit(B_SESS_VLD, &motg->inputs); |
| 3302 | break; |
| 3303 | default: |
| 3304 | goto out; |
| 3305 | } |
| 3306 | break; |
| 3307 | case USB_HOST: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3308 | switch (phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3309 | case OTG_STATE_B_IDLE: |
| 3310 | case OTG_STATE_B_PERIPHERAL: |
| 3311 | clear_bit(ID, &motg->inputs); |
| 3312 | break; |
| 3313 | default: |
| 3314 | goto out; |
| 3315 | } |
| 3316 | break; |
| 3317 | default: |
| 3318 | goto out; |
| 3319 | } |
| 3320 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3321 | pm_runtime_resume(phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3322 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3323 | out: |
| 3324 | return status; |
| 3325 | } |
| 3326 | |
| 3327 | const struct file_operations msm_otg_mode_fops = { |
| 3328 | .open = msm_otg_mode_open, |
| 3329 | .read = seq_read, |
| 3330 | .write = msm_otg_mode_write, |
| 3331 | .llseek = seq_lseek, |
| 3332 | .release = single_release, |
| 3333 | }; |
| 3334 | |
Chiranjeevi Velempati | f9a1154 | 2012-03-28 18:18:34 +0530 | [diff] [blame] | 3335 | static int msm_otg_show_otg_state(struct seq_file *s, void *unused) |
| 3336 | { |
| 3337 | struct msm_otg *motg = s->private; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3338 | struct usb_phy *phy = &motg->phy; |
Chiranjeevi Velempati | f9a1154 | 2012-03-28 18:18:34 +0530 | [diff] [blame] | 3339 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3340 | seq_printf(s, "%s\n", otg_state_string(phy->state)); |
Chiranjeevi Velempati | f9a1154 | 2012-03-28 18:18:34 +0530 | [diff] [blame] | 3341 | return 0; |
| 3342 | } |
| 3343 | |
| 3344 | static int msm_otg_otg_state_open(struct inode *inode, struct file *file) |
| 3345 | { |
| 3346 | return single_open(file, msm_otg_show_otg_state, inode->i_private); |
| 3347 | } |
| 3348 | |
| 3349 | const struct file_operations msm_otg_state_fops = { |
| 3350 | .open = msm_otg_otg_state_open, |
| 3351 | .read = seq_read, |
| 3352 | .llseek = seq_lseek, |
| 3353 | .release = single_release, |
| 3354 | }; |
| 3355 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3356 | static int msm_otg_show_chg_type(struct seq_file *s, void *unused) |
| 3357 | { |
| 3358 | struct msm_otg *motg = s->private; |
| 3359 | |
Pavankumar Kondeti | 9ef69cb | 2011-12-12 14:18:22 +0530 | [diff] [blame] | 3360 | seq_printf(s, "%s\n", chg_to_string(motg->chg_type)); |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3361 | return 0; |
| 3362 | } |
| 3363 | |
| 3364 | static int msm_otg_chg_open(struct inode *inode, struct file *file) |
| 3365 | { |
| 3366 | return single_open(file, msm_otg_show_chg_type, inode->i_private); |
| 3367 | } |
| 3368 | |
| 3369 | const struct file_operations msm_otg_chg_fops = { |
| 3370 | .open = msm_otg_chg_open, |
| 3371 | .read = seq_read, |
| 3372 | .llseek = seq_lseek, |
| 3373 | .release = single_release, |
| 3374 | }; |
| 3375 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3376 | static int msm_otg_aca_show(struct seq_file *s, void *unused) |
| 3377 | { |
| 3378 | if (debug_aca_enabled) |
| 3379 | seq_printf(s, "enabled\n"); |
| 3380 | else |
| 3381 | seq_printf(s, "disabled\n"); |
| 3382 | |
| 3383 | return 0; |
| 3384 | } |
| 3385 | |
| 3386 | static int msm_otg_aca_open(struct inode *inode, struct file *file) |
| 3387 | { |
| 3388 | return single_open(file, msm_otg_aca_show, inode->i_private); |
| 3389 | } |
| 3390 | |
| 3391 | static ssize_t msm_otg_aca_write(struct file *file, const char __user *ubuf, |
| 3392 | size_t count, loff_t *ppos) |
| 3393 | { |
| 3394 | char buf[8]; |
| 3395 | |
| 3396 | memset(buf, 0x00, sizeof(buf)); |
| 3397 | |
| 3398 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 3399 | return -EFAULT; |
| 3400 | |
| 3401 | if (!strncmp(buf, "enable", 6)) |
| 3402 | debug_aca_enabled = true; |
| 3403 | else |
| 3404 | debug_aca_enabled = false; |
| 3405 | |
| 3406 | return count; |
| 3407 | } |
| 3408 | |
| 3409 | const struct file_operations msm_otg_aca_fops = { |
| 3410 | .open = msm_otg_aca_open, |
| 3411 | .read = seq_read, |
| 3412 | .write = msm_otg_aca_write, |
| 3413 | .llseek = seq_lseek, |
| 3414 | .release = single_release, |
| 3415 | }; |
| 3416 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3417 | static int msm_otg_bus_show(struct seq_file *s, void *unused) |
| 3418 | { |
| 3419 | if (debug_bus_voting_enabled) |
| 3420 | seq_printf(s, "enabled\n"); |
| 3421 | else |
| 3422 | seq_printf(s, "disabled\n"); |
| 3423 | |
| 3424 | return 0; |
| 3425 | } |
| 3426 | |
| 3427 | static int msm_otg_bus_open(struct inode *inode, struct file *file) |
| 3428 | { |
| 3429 | return single_open(file, msm_otg_bus_show, inode->i_private); |
| 3430 | } |
| 3431 | |
| 3432 | static ssize_t msm_otg_bus_write(struct file *file, const char __user *ubuf, |
| 3433 | size_t count, loff_t *ppos) |
| 3434 | { |
| 3435 | char buf[8]; |
| 3436 | int ret; |
| 3437 | struct seq_file *s = file->private_data; |
| 3438 | struct msm_otg *motg = s->private; |
| 3439 | |
| 3440 | memset(buf, 0x00, sizeof(buf)); |
| 3441 | |
| 3442 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 3443 | return -EFAULT; |
| 3444 | |
| 3445 | if (!strncmp(buf, "enable", 6)) { |
| 3446 | /* Do not vote here. Let OTG statemachine decide when to vote */ |
| 3447 | debug_bus_voting_enabled = true; |
| 3448 | } else { |
| 3449 | debug_bus_voting_enabled = false; |
| 3450 | if (motg->bus_perf_client) { |
| 3451 | ret = msm_bus_scale_client_update_request( |
| 3452 | motg->bus_perf_client, 0); |
| 3453 | if (ret) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3454 | dev_err(motg->phy.dev, "%s: Failed to devote " |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3455 | "for bus bw %d\n", __func__, ret); |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | return count; |
| 3460 | } |
| 3461 | |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 3462 | static int otg_power_get_property_usb(struct power_supply *psy, |
| 3463 | enum power_supply_property psp, |
| 3464 | union power_supply_propval *val) |
| 3465 | { |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 3466 | struct msm_otg *motg = container_of(psy, struct msm_otg, usb_psy); |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 3467 | switch (psp) { |
| 3468 | case POWER_SUPPLY_PROP_SCOPE: |
| 3469 | if (motg->host_mode) |
| 3470 | val->intval = POWER_SUPPLY_SCOPE_SYSTEM; |
| 3471 | else |
| 3472 | val->intval = POWER_SUPPLY_SCOPE_DEVICE; |
| 3473 | break; |
| 3474 | case POWER_SUPPLY_PROP_CURRENT_MAX: |
| 3475 | val->intval = motg->current_max; |
| 3476 | break; |
| 3477 | /* Reflect USB enumeration */ |
| 3478 | case POWER_SUPPLY_PROP_PRESENT: |
| 3479 | case POWER_SUPPLY_PROP_ONLINE: |
| 3480 | val->intval = motg->online; |
| 3481 | break; |
| 3482 | default: |
| 3483 | return -EINVAL; |
| 3484 | } |
| 3485 | return 0; |
| 3486 | } |
| 3487 | |
| 3488 | static int otg_power_set_property_usb(struct power_supply *psy, |
| 3489 | enum power_supply_property psp, |
| 3490 | const union power_supply_propval *val) |
| 3491 | { |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 3492 | struct msm_otg *motg = container_of(psy, struct msm_otg, usb_psy); |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 3493 | |
| 3494 | switch (psp) { |
| 3495 | /* Process PMIC notification in PRESENT prop */ |
| 3496 | case POWER_SUPPLY_PROP_PRESENT: |
| 3497 | msm_otg_set_vbus_state(val->intval); |
| 3498 | break; |
| 3499 | /* The ONLINE property reflects if usb has enumerated */ |
| 3500 | case POWER_SUPPLY_PROP_ONLINE: |
| 3501 | motg->online = val->intval; |
| 3502 | break; |
| 3503 | case POWER_SUPPLY_PROP_CURRENT_MAX: |
| 3504 | motg->current_max = val->intval; |
| 3505 | break; |
| 3506 | default: |
| 3507 | return -EINVAL; |
| 3508 | } |
| 3509 | |
| 3510 | power_supply_changed(&motg->usb_psy); |
| 3511 | return 0; |
| 3512 | } |
| 3513 | |
David Collins | d79acc5 | 2012-11-26 14:59:00 -0800 | [diff] [blame] | 3514 | static int otg_power_property_is_writeable_usb(struct power_supply *psy, |
| 3515 | enum power_supply_property psp) |
| 3516 | { |
| 3517 | switch (psp) { |
| 3518 | case POWER_SUPPLY_PROP_PRESENT: |
| 3519 | case POWER_SUPPLY_PROP_ONLINE: |
| 3520 | case POWER_SUPPLY_PROP_CURRENT_MAX: |
| 3521 | return 1; |
| 3522 | default: |
| 3523 | break; |
| 3524 | } |
| 3525 | |
| 3526 | return 0; |
| 3527 | } |
| 3528 | |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 3529 | static char *otg_pm_power_supplied_to[] = { |
| 3530 | "battery", |
| 3531 | }; |
| 3532 | |
| 3533 | static enum power_supply_property otg_pm_power_props_usb[] = { |
| 3534 | POWER_SUPPLY_PROP_PRESENT, |
| 3535 | POWER_SUPPLY_PROP_ONLINE, |
| 3536 | POWER_SUPPLY_PROP_CURRENT_MAX, |
| 3537 | POWER_SUPPLY_PROP_SCOPE, |
| 3538 | }; |
| 3539 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3540 | const struct file_operations msm_otg_bus_fops = { |
| 3541 | .open = msm_otg_bus_open, |
| 3542 | .read = seq_read, |
| 3543 | .write = msm_otg_bus_write, |
| 3544 | .llseek = seq_lseek, |
| 3545 | .release = single_release, |
| 3546 | }; |
| 3547 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3548 | static struct dentry *msm_otg_dbg_root; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3549 | |
| 3550 | static int msm_otg_debugfs_init(struct msm_otg *motg) |
| 3551 | { |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3552 | struct dentry *msm_otg_dentry; |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3553 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3554 | msm_otg_dbg_root = debugfs_create_dir("msm_otg", NULL); |
| 3555 | |
| 3556 | if (!msm_otg_dbg_root || IS_ERR(msm_otg_dbg_root)) |
| 3557 | return -ENODEV; |
| 3558 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3559 | if (motg->pdata->mode == USB_OTG && |
| 3560 | motg->pdata->otg_control == OTG_USER_CONTROL) { |
| 3561 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3562 | msm_otg_dentry = debugfs_create_file("mode", S_IRUGO | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3563 | S_IWUSR, msm_otg_dbg_root, motg, |
| 3564 | &msm_otg_mode_fops); |
| 3565 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3566 | if (!msm_otg_dentry) { |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3567 | debugfs_remove(msm_otg_dbg_root); |
| 3568 | msm_otg_dbg_root = NULL; |
| 3569 | return -ENODEV; |
| 3570 | } |
| 3571 | } |
| 3572 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3573 | msm_otg_dentry = debugfs_create_file("chg_type", S_IRUGO, |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3574 | msm_otg_dbg_root, motg, |
| 3575 | &msm_otg_chg_fops); |
| 3576 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3577 | if (!msm_otg_dentry) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3578 | debugfs_remove_recursive(msm_otg_dbg_root); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3579 | return -ENODEV; |
| 3580 | } |
| 3581 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3582 | msm_otg_dentry = debugfs_create_file("aca", S_IRUGO | S_IWUSR, |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3583 | msm_otg_dbg_root, motg, |
| 3584 | &msm_otg_aca_fops); |
| 3585 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3586 | if (!msm_otg_dentry) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3587 | debugfs_remove_recursive(msm_otg_dbg_root); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3588 | return -ENODEV; |
| 3589 | } |
| 3590 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3591 | msm_otg_dentry = debugfs_create_file("bus_voting", S_IRUGO | S_IWUSR, |
| 3592 | msm_otg_dbg_root, motg, |
| 3593 | &msm_otg_bus_fops); |
| 3594 | |
| 3595 | if (!msm_otg_dentry) { |
| 3596 | debugfs_remove_recursive(msm_otg_dbg_root); |
| 3597 | return -ENODEV; |
| 3598 | } |
Chiranjeevi Velempati | f9a1154 | 2012-03-28 18:18:34 +0530 | [diff] [blame] | 3599 | |
| 3600 | msm_otg_dentry = debugfs_create_file("otg_state", S_IRUGO, |
| 3601 | msm_otg_dbg_root, motg, &msm_otg_state_fops); |
| 3602 | |
| 3603 | if (!msm_otg_dentry) { |
| 3604 | debugfs_remove_recursive(msm_otg_dbg_root); |
| 3605 | return -ENODEV; |
| 3606 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3607 | return 0; |
| 3608 | } |
| 3609 | |
| 3610 | static void msm_otg_debugfs_cleanup(void) |
| 3611 | { |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3612 | debugfs_remove_recursive(msm_otg_dbg_root); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3613 | } |
| 3614 | |
Manu Gautam | 0ddbd92 | 2012-09-21 17:17:38 +0530 | [diff] [blame] | 3615 | #define MSM_OTG_CMD_ID 0x09 |
| 3616 | #define MSM_OTG_DEVICE_ID 0x04 |
| 3617 | #define MSM_OTG_VMID_IDX 0xFF |
| 3618 | #define MSM_OTG_MEM_TYPE 0x02 |
| 3619 | struct msm_otg_scm_cmd_buf { |
| 3620 | unsigned int device_id; |
| 3621 | unsigned int vmid_idx; |
| 3622 | unsigned int mem_type; |
| 3623 | } __attribute__ ((__packed__)); |
| 3624 | |
| 3625 | static void msm_otg_pnoc_errata_fix(struct msm_otg *motg) |
| 3626 | { |
| 3627 | int ret; |
| 3628 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 3629 | struct msm_otg_scm_cmd_buf cmd_buf; |
| 3630 | |
| 3631 | if (!pdata->pnoc_errata_fix) |
| 3632 | return; |
| 3633 | |
| 3634 | dev_dbg(motg->phy.dev, "applying fix for pnoc h/w issue\n"); |
| 3635 | |
| 3636 | cmd_buf.device_id = MSM_OTG_DEVICE_ID; |
| 3637 | cmd_buf.vmid_idx = MSM_OTG_VMID_IDX; |
| 3638 | cmd_buf.mem_type = MSM_OTG_MEM_TYPE; |
| 3639 | |
| 3640 | ret = scm_call(SCM_SVC_CP, MSM_OTG_CMD_ID, &cmd_buf, |
| 3641 | sizeof(cmd_buf), NULL, 0); |
| 3642 | |
| 3643 | if (ret) |
| 3644 | dev_err(motg->phy.dev, "scm command failed to update VMIDMT\n"); |
| 3645 | } |
| 3646 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3647 | static u64 msm_otg_dma_mask = DMA_BIT_MASK(64); |
| 3648 | static struct platform_device *msm_otg_add_pdev( |
| 3649 | struct platform_device *ofdev, const char *name) |
| 3650 | { |
| 3651 | struct platform_device *pdev; |
| 3652 | const struct resource *res = ofdev->resource; |
| 3653 | unsigned int num = ofdev->num_resources; |
| 3654 | int retval; |
| 3655 | |
| 3656 | pdev = platform_device_alloc(name, -1); |
| 3657 | if (!pdev) { |
| 3658 | retval = -ENOMEM; |
| 3659 | goto error; |
| 3660 | } |
| 3661 | |
| 3662 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 3663 | pdev->dev.dma_mask = &msm_otg_dma_mask; |
| 3664 | |
| 3665 | if (num) { |
| 3666 | retval = platform_device_add_resources(pdev, res, num); |
| 3667 | if (retval) |
| 3668 | goto error; |
| 3669 | } |
| 3670 | |
| 3671 | retval = platform_device_add(pdev); |
| 3672 | if (retval) |
| 3673 | goto error; |
| 3674 | |
| 3675 | return pdev; |
| 3676 | |
| 3677 | error: |
| 3678 | platform_device_put(pdev); |
| 3679 | return ERR_PTR(retval); |
| 3680 | } |
| 3681 | |
| 3682 | static int msm_otg_setup_devices(struct platform_device *ofdev, |
| 3683 | enum usb_mode_type mode, bool init) |
| 3684 | { |
| 3685 | const char *gadget_name = "msm_hsusb"; |
| 3686 | const char *host_name = "msm_hsusb_host"; |
| 3687 | static struct platform_device *gadget_pdev; |
| 3688 | static struct platform_device *host_pdev; |
| 3689 | int retval = 0; |
| 3690 | |
| 3691 | if (!init) { |
| 3692 | if (gadget_pdev) |
| 3693 | platform_device_unregister(gadget_pdev); |
| 3694 | if (host_pdev) |
| 3695 | platform_device_unregister(host_pdev); |
| 3696 | return 0; |
| 3697 | } |
| 3698 | |
| 3699 | switch (mode) { |
| 3700 | case USB_OTG: |
| 3701 | /* fall through */ |
| 3702 | case USB_PERIPHERAL: |
| 3703 | gadget_pdev = msm_otg_add_pdev(ofdev, gadget_name); |
| 3704 | if (IS_ERR(gadget_pdev)) { |
| 3705 | retval = PTR_ERR(gadget_pdev); |
| 3706 | break; |
| 3707 | } |
| 3708 | if (mode == USB_PERIPHERAL) |
| 3709 | break; |
| 3710 | /* fall through */ |
| 3711 | case USB_HOST: |
| 3712 | host_pdev = msm_otg_add_pdev(ofdev, host_name); |
| 3713 | if (IS_ERR(host_pdev)) { |
| 3714 | retval = PTR_ERR(host_pdev); |
| 3715 | if (mode == USB_OTG) |
| 3716 | platform_device_unregister(gadget_pdev); |
| 3717 | } |
| 3718 | break; |
| 3719 | default: |
| 3720 | break; |
| 3721 | } |
| 3722 | |
| 3723 | return retval; |
| 3724 | } |
| 3725 | |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 3726 | static int msm_otg_register_power_supply(struct platform_device *pdev, |
| 3727 | struct msm_otg *motg) |
| 3728 | { |
| 3729 | int ret; |
| 3730 | |
| 3731 | ret = power_supply_register(&pdev->dev, &motg->usb_psy); |
| 3732 | if (ret < 0) { |
| 3733 | dev_err(motg->phy.dev, |
| 3734 | "%s:power_supply_register usb failed\n", |
| 3735 | __func__); |
| 3736 | return ret; |
| 3737 | } |
| 3738 | |
| 3739 | legacy_power_supply = false; |
| 3740 | return 0; |
| 3741 | } |
| 3742 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3743 | struct msm_otg_platform_data *msm_otg_dt_to_pdata(struct platform_device *pdev) |
| 3744 | { |
| 3745 | struct device_node *node = pdev->dev.of_node; |
| 3746 | struct msm_otg_platform_data *pdata; |
| 3747 | int len = 0; |
| 3748 | |
| 3749 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 3750 | if (!pdata) { |
| 3751 | pr_err("unable to allocate platform data\n"); |
| 3752 | return NULL; |
| 3753 | } |
| 3754 | of_get_property(node, "qcom,hsusb-otg-phy-init-seq", &len); |
| 3755 | if (len) { |
| 3756 | pdata->phy_init_seq = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); |
| 3757 | if (!pdata->phy_init_seq) |
| 3758 | return NULL; |
| 3759 | of_property_read_u32_array(node, "qcom,hsusb-otg-phy-init-seq", |
| 3760 | pdata->phy_init_seq, |
| 3761 | len/sizeof(*pdata->phy_init_seq)); |
| 3762 | } |
| 3763 | of_property_read_u32(node, "qcom,hsusb-otg-power-budget", |
| 3764 | &pdata->power_budget); |
| 3765 | of_property_read_u32(node, "qcom,hsusb-otg-mode", |
| 3766 | &pdata->mode); |
| 3767 | of_property_read_u32(node, "qcom,hsusb-otg-otg-control", |
| 3768 | &pdata->otg_control); |
| 3769 | of_property_read_u32(node, "qcom,hsusb-otg-default-mode", |
| 3770 | &pdata->default_mode); |
| 3771 | of_property_read_u32(node, "qcom,hsusb-otg-phy-type", |
| 3772 | &pdata->phy_type); |
| 3773 | of_property_read_u32(node, "qcom,hsusb-otg-pmic-id-irq", |
| 3774 | &pdata->pmic_id_irq); |
Manu Gautam | bd53fba | 2012-07-31 16:13:06 +0530 | [diff] [blame] | 3775 | pdata->disable_reset_on_disconnect = of_property_read_bool(node, |
| 3776 | "qcom,hsusb-otg-disable-reset"); |
Manu Gautam | 0ddbd92 | 2012-09-21 17:17:38 +0530 | [diff] [blame] | 3777 | pdata->pnoc_errata_fix = of_property_read_bool(node, |
| 3778 | "qcom,hsusb-otg-pnoc-errata-fix"); |
Manu Gautam | bd53fba | 2012-07-31 16:13:06 +0530 | [diff] [blame] | 3779 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3780 | return pdata; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3781 | } |
| 3782 | |
| 3783 | static int __init msm_otg_probe(struct platform_device *pdev) |
| 3784 | { |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 3785 | int ret = 0; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3786 | struct resource *res; |
| 3787 | struct msm_otg *motg; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3788 | struct usb_phy *phy; |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3789 | struct msm_otg_platform_data *pdata; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3790 | |
| 3791 | dev_info(&pdev->dev, "msm_otg probe\n"); |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3792 | |
| 3793 | if (pdev->dev.of_node) { |
| 3794 | dev_dbg(&pdev->dev, "device tree enabled\n"); |
| 3795 | pdata = msm_otg_dt_to_pdata(pdev); |
| 3796 | if (!pdata) |
| 3797 | return -ENOMEM; |
Manu Gautam | 2e8ac10 | 2012-08-31 11:41:16 -0700 | [diff] [blame] | 3798 | |
| 3799 | pdata->bus_scale_table = msm_bus_cl_get_pdata(pdev); |
| 3800 | if (!pdata->bus_scale_table) |
| 3801 | dev_dbg(&pdev->dev, "bus scaling is disabled\n"); |
| 3802 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3803 | ret = msm_otg_setup_devices(pdev, pdata->mode, true); |
| 3804 | if (ret) { |
| 3805 | dev_err(&pdev->dev, "devices setup failed\n"); |
| 3806 | return ret; |
| 3807 | } |
| 3808 | } else if (!pdev->dev.platform_data) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3809 | dev_err(&pdev->dev, "No platform data given. Bailing out\n"); |
| 3810 | return -ENODEV; |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3811 | } else { |
| 3812 | pdata = pdev->dev.platform_data; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | motg = kzalloc(sizeof(struct msm_otg), GFP_KERNEL); |
| 3816 | if (!motg) { |
| 3817 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); |
| 3818 | return -ENOMEM; |
| 3819 | } |
| 3820 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3821 | motg->phy.otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); |
| 3822 | if (!motg->phy.otg) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3823 | dev_err(&pdev->dev, "unable to allocate usb_otg\n"); |
| 3824 | ret = -ENOMEM; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3825 | goto free_motg; |
| 3826 | } |
| 3827 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3828 | the_msm_otg = motg; |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3829 | motg->pdata = pdata; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3830 | phy = &motg->phy; |
| 3831 | phy->dev = &pdev->dev; |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 3832 | |
| 3833 | /* |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3834 | * ACA ID_GND threshold range is overlapped with OTG ID_FLOAT. Hence |
| 3835 | * PHY treat ACA ID_GND as float and no interrupt is generated. But |
| 3836 | * PMIC can detect ACA ID_GND and generate an interrupt. |
| 3837 | */ |
| 3838 | if (aca_enabled() && motg->pdata->otg_control != OTG_PMIC_CONTROL) { |
| 3839 | dev_err(&pdev->dev, "ACA can not be enabled without PMIC\n"); |
| 3840 | ret = -EINVAL; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3841 | goto free_otg; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3842 | } |
| 3843 | |
Ofir Cohen | 4da266f | 2012-01-03 10:19:29 +0200 | [diff] [blame] | 3844 | /* initialize reset counter */ |
| 3845 | motg->reset_counter = 0; |
| 3846 | |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 3847 | /* Some targets don't support PHY clock. */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3848 | motg->phy_reset_clk = clk_get(&pdev->dev, "phy_clk"); |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 3849 | if (IS_ERR(motg->phy_reset_clk)) |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3850 | dev_err(&pdev->dev, "failed to get phy_clk\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3851 | |
Pavankumar Kondeti | 923262e | 2012-04-20 15:34:24 +0530 | [diff] [blame] | 3852 | /* |
| 3853 | * Targets on which link uses asynchronous reset methodology, |
| 3854 | * free running clock is not required during the reset. |
| 3855 | */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3856 | motg->clk = clk_get(&pdev->dev, "alt_core_clk"); |
Pavankumar Kondeti | 923262e | 2012-04-20 15:34:24 +0530 | [diff] [blame] | 3857 | if (IS_ERR(motg->clk)) |
| 3858 | dev_dbg(&pdev->dev, "alt_core_clk is not present\n"); |
| 3859 | else |
| 3860 | clk_set_rate(motg->clk, 60000000); |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 3861 | |
| 3862 | /* |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3863 | * USB Core is running its protocol engine based on CORE CLK, |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 3864 | * CORE CLK must be running at >55Mhz for correct HSUSB |
| 3865 | * operation and USB core cannot tolerate frequency changes on |
| 3866 | * CORE CLK. For such USB cores, vote for maximum clk frequency |
| 3867 | * on pclk source |
| 3868 | */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3869 | motg->core_clk = clk_get(&pdev->dev, "core_clk"); |
| 3870 | if (IS_ERR(motg->core_clk)) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3871 | motg->core_clk = NULL; |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3872 | dev_err(&pdev->dev, "failed to get core_clk\n"); |
Pavankumar Kondeti | bc54133 | 2012-04-20 15:32:04 +0530 | [diff] [blame] | 3873 | ret = PTR_ERR(motg->core_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3874 | goto put_clk; |
| 3875 | } |
| 3876 | clk_set_rate(motg->core_clk, INT_MAX); |
| 3877 | |
| 3878 | motg->pclk = clk_get(&pdev->dev, "iface_clk"); |
| 3879 | if (IS_ERR(motg->pclk)) { |
| 3880 | dev_err(&pdev->dev, "failed to get iface_clk\n"); |
| 3881 | ret = PTR_ERR(motg->pclk); |
| 3882 | goto put_core_clk; |
| 3883 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3884 | |
| 3885 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 3886 | if (!res) { |
| 3887 | dev_err(&pdev->dev, "failed to get platform resource mem\n"); |
| 3888 | ret = -ENODEV; |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3889 | goto put_pclk; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3890 | } |
| 3891 | |
| 3892 | motg->regs = ioremap(res->start, resource_size(res)); |
| 3893 | if (!motg->regs) { |
| 3894 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 3895 | ret = -ENOMEM; |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3896 | goto put_pclk; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3897 | } |
| 3898 | dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs); |
| 3899 | |
| 3900 | motg->irq = platform_get_irq(pdev, 0); |
| 3901 | if (!motg->irq) { |
| 3902 | dev_err(&pdev->dev, "platform_get_irq failed\n"); |
| 3903 | ret = -ENODEV; |
| 3904 | goto free_regs; |
| 3905 | } |
| 3906 | |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 3907 | motg->async_irq = platform_get_irq_byname(pdev, "async_irq"); |
| 3908 | if (motg->async_irq < 0) { |
| 3909 | dev_dbg(&pdev->dev, "platform_get_irq for async_int failed\n"); |
| 3910 | motg->async_irq = 0; |
| 3911 | } |
| 3912 | |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 3913 | motg->xo_handle = msm_xo_get(MSM_XO_TCXO_D0, "usb"); |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 3914 | if (IS_ERR(motg->xo_handle)) { |
| 3915 | dev_err(&pdev->dev, "%s not able to get the handle " |
| 3916 | "to vote for TCXO D0 buffer\n", __func__); |
| 3917 | ret = PTR_ERR(motg->xo_handle); |
| 3918 | goto free_regs; |
| 3919 | } |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3920 | |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 3921 | ret = msm_xo_mode_vote(motg->xo_handle, MSM_XO_MODE_ON); |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 3922 | if (ret) { |
| 3923 | dev_err(&pdev->dev, "%s failed to vote for TCXO " |
| 3924 | "D0 buffer%d\n", __func__, ret); |
| 3925 | goto free_xo_handle; |
| 3926 | } |
| 3927 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 3928 | clk_prepare_enable(motg->pclk); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3929 | |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3930 | motg->vdd_type = VDDCX_CORNER; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3931 | hsusb_vddcx = devm_regulator_get(motg->phy.dev, "hsusb_vdd_dig"); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3932 | if (IS_ERR(hsusb_vddcx)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3933 | hsusb_vddcx = devm_regulator_get(motg->phy.dev, "HSUSB_VDDCX"); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3934 | if (IS_ERR(hsusb_vddcx)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3935 | dev_err(motg->phy.dev, "unable to get hsusb vddcx\n"); |
Hemant Kumar | 4181239 | 2012-07-13 15:26:20 -0700 | [diff] [blame] | 3936 | ret = PTR_ERR(hsusb_vddcx); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3937 | goto devote_xo_handle; |
| 3938 | } |
| 3939 | motg->vdd_type = VDDCX; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3940 | } |
| 3941 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3942 | ret = msm_hsusb_config_vddcx(1); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3943 | if (ret) { |
| 3944 | dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3945 | goto devote_xo_handle; |
| 3946 | } |
| 3947 | |
| 3948 | ret = regulator_enable(hsusb_vddcx); |
| 3949 | if (ret) { |
| 3950 | dev_err(&pdev->dev, "unable to enable the hsusb vddcx\n"); |
| 3951 | goto free_config_vddcx; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3952 | } |
| 3953 | |
| 3954 | ret = msm_hsusb_ldo_init(motg, 1); |
| 3955 | if (ret) { |
| 3956 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3957 | goto free_hsusb_vddcx; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3958 | } |
| 3959 | |
Mayank Rana | 9e9a2ac | 2012-03-24 04:05:28 +0530 | [diff] [blame] | 3960 | if (pdata->mhl_enable) { |
Pavankumar Kondeti | 56dc742 | 2012-07-02 12:45:19 +0530 | [diff] [blame] | 3961 | mhl_usb_hs_switch = devm_regulator_get(motg->phy.dev, |
| 3962 | "mhl_usb_hs_switch"); |
| 3963 | if (IS_ERR(mhl_usb_hs_switch)) { |
| 3964 | dev_err(&pdev->dev, "Unable to get mhl_usb_hs_switch\n"); |
Hemant Kumar | 4181239 | 2012-07-13 15:26:20 -0700 | [diff] [blame] | 3965 | ret = PTR_ERR(mhl_usb_hs_switch); |
Mayank Rana | 9e9a2ac | 2012-03-24 04:05:28 +0530 | [diff] [blame] | 3966 | goto free_ldo_init; |
| 3967 | } |
| 3968 | } |
| 3969 | |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 3970 | ret = msm_hsusb_ldo_enable(motg, USB_PHY_REG_ON); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3971 | if (ret) { |
| 3972 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3973 | goto free_ldo_init; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3974 | } |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 3975 | clk_prepare_enable(motg->core_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3976 | |
Manu Gautam | 0ddbd92 | 2012-09-21 17:17:38 +0530 | [diff] [blame] | 3977 | /* Check if USB mem_type change is needed to workaround PNOC hw issue */ |
| 3978 | msm_otg_pnoc_errata_fix(motg); |
| 3979 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3980 | writel(0, USB_USBINTR); |
| 3981 | writel(0, USB_OTGSC); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3982 | /* Ensure that above STOREs are completed before enabling interrupts */ |
| 3983 | mb(); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3984 | |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 3985 | ret = msm_otg_mhl_register_callback(motg, msm_otg_mhl_notify_online); |
| 3986 | if (ret) |
| 3987 | dev_dbg(&pdev->dev, "MHL can not be supported\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3988 | wake_lock_init(&motg->wlock, WAKE_LOCK_SUSPEND, "msm_otg"); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3989 | msm_otg_init_timer(motg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3990 | INIT_WORK(&motg->sm_work, msm_otg_sm_work); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 3991 | INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work); |
Vijayavardhan Vennapusa | 68d55cf | 2012-06-27 20:06:12 +0530 | [diff] [blame] | 3992 | INIT_DELAYED_WORK(&motg->pmic_id_status_work, msm_pmic_id_status_w); |
Amit Blay | d0fe07b | 2012-09-05 16:42:09 +0300 | [diff] [blame] | 3993 | INIT_DELAYED_WORK(&motg->suspend_work, msm_otg_suspend_work); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3994 | setup_timer(&motg->id_timer, msm_otg_id_timer_func, |
| 3995 | (unsigned long) motg); |
Pavankumar Kondeti | 458d879 | 2012-09-28 14:45:18 +0530 | [diff] [blame] | 3996 | setup_timer(&motg->chg_check_timer, msm_otg_chg_check_timer_func, |
| 3997 | (unsigned long) motg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3998 | ret = request_irq(motg->irq, msm_otg_irq, IRQF_SHARED, |
| 3999 | "msm_otg", motg); |
| 4000 | if (ret) { |
| 4001 | dev_err(&pdev->dev, "request irq failed\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4002 | goto destroy_wlock; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4003 | } |
| 4004 | |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 4005 | if (motg->async_irq) { |
Vijayavardhan Vennapusa | 9ab6f97 | 2012-10-11 19:18:55 +0530 | [diff] [blame] | 4006 | ret = request_irq(motg->async_irq, msm_otg_irq, |
| 4007 | IRQF_TRIGGER_RISING, "msm_otg", motg); |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 4008 | if (ret) { |
| 4009 | dev_err(&pdev->dev, "request irq failed (ASYNC INT)\n"); |
| 4010 | goto free_irq; |
| 4011 | } |
| 4012 | disable_irq(motg->async_irq); |
| 4013 | } |
| 4014 | |
Jack Pham | 87f202f | 2012-08-06 00:24:22 -0700 | [diff] [blame] | 4015 | if (pdata->otg_control == OTG_PHY_CONTROL && pdata->mpm_otgsessvld_int) |
| 4016 | msm_mpm_enable_pin(pdata->mpm_otgsessvld_int, 1); |
| 4017 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 4018 | phy->init = msm_otg_reset; |
| 4019 | phy->set_power = msm_otg_set_power; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4020 | phy->set_suspend = msm_otg_set_suspend; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4021 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 4022 | phy->io_ops = &msm_otg_io_ops; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4023 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 4024 | phy->otg->phy = &motg->phy; |
| 4025 | phy->otg->set_host = msm_otg_set_host; |
| 4026 | phy->otg->set_peripheral = msm_otg_set_peripheral; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4027 | phy->otg->start_hnp = msm_otg_start_hnp; |
| 4028 | phy->otg->start_srp = msm_otg_start_srp; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 4029 | |
| 4030 | ret = usb_set_transceiver(&motg->phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4031 | if (ret) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 4032 | dev_err(&pdev->dev, "usb_set_transceiver failed\n"); |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 4033 | goto free_async_irq; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4034 | } |
| 4035 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4036 | if (motg->pdata->mode == USB_OTG && |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 4037 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4038 | if (motg->pdata->pmic_id_irq) { |
| 4039 | ret = request_irq(motg->pdata->pmic_id_irq, |
| 4040 | msm_pmic_id_irq, |
| 4041 | IRQF_TRIGGER_RISING | |
| 4042 | IRQF_TRIGGER_FALLING, |
| 4043 | "msm_otg", motg); |
| 4044 | if (ret) { |
| 4045 | dev_err(&pdev->dev, "request irq failed for PMIC ID\n"); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4046 | goto remove_phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4047 | } |
| 4048 | } else { |
| 4049 | ret = -ENODEV; |
| 4050 | dev_err(&pdev->dev, "PMIC IRQ for ID notifications doesn't exist\n"); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4051 | goto remove_phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4052 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4053 | } |
| 4054 | |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 4055 | msm_hsusb_mhl_switch_enable(motg, 1); |
| 4056 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4057 | platform_set_drvdata(pdev, motg); |
| 4058 | device_init_wakeup(&pdev->dev, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4059 | motg->mA_port = IUNIT; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4060 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 4061 | ret = msm_otg_debugfs_init(motg); |
| 4062 | if (ret) |
| 4063 | dev_dbg(&pdev->dev, "mode debugfs file is" |
| 4064 | "not available\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4065 | |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 4066 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY) { |
| 4067 | if (motg->pdata->otg_control == OTG_PMIC_CONTROL && |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 4068 | (!(motg->pdata->mode == USB_OTG) || |
| 4069 | motg->pdata->pmic_id_irq)) |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 4070 | motg->caps = ALLOW_PHY_POWER_COLLAPSE | |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 4071 | ALLOW_PHY_RETENTION; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4072 | |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 4073 | if (motg->pdata->otg_control == OTG_PHY_CONTROL) |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 4074 | motg->caps = ALLOW_PHY_RETENTION | |
| 4075 | ALLOW_PHY_REGULATORS_LPM; |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 4076 | } |
| 4077 | |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 4078 | if (motg->pdata->enable_lpm_on_dev_suspend) |
| 4079 | motg->caps |= ALLOW_LPM_ON_DEV_SUSPEND; |
| 4080 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4081 | wake_lock(&motg->wlock); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4082 | pm_runtime_set_active(&pdev->dev); |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 4083 | pm_runtime_enable(&pdev->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4084 | |
Amit Blay | d6f3828 | 2012-10-29 13:13:46 +0200 | [diff] [blame] | 4085 | if (motg->pdata->delay_lpm_on_disconnect) { |
| 4086 | pm_runtime_set_autosuspend_delay(&pdev->dev, |
| 4087 | lpm_disconnect_thresh); |
| 4088 | pm_runtime_use_autosuspend(&pdev->dev); |
| 4089 | } |
| 4090 | |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 4091 | if (motg->pdata->bus_scale_table) { |
| 4092 | motg->bus_perf_client = |
| 4093 | msm_bus_scale_register_client(motg->pdata->bus_scale_table); |
| 4094 | if (!motg->bus_perf_client) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4095 | dev_err(motg->phy.dev, "%s: Failed to register BUS " |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 4096 | "scaling client!!\n", __func__); |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 4097 | else |
| 4098 | debug_bus_voting_enabled = true; |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 4099 | } |
| 4100 | |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 4101 | motg->usb_psy.name = "usb"; |
| 4102 | motg->usb_psy.type = POWER_SUPPLY_TYPE_USB; |
| 4103 | motg->usb_psy.supplied_to = otg_pm_power_supplied_to; |
| 4104 | motg->usb_psy.num_supplicants = ARRAY_SIZE(otg_pm_power_supplied_to); |
| 4105 | motg->usb_psy.properties = otg_pm_power_props_usb; |
| 4106 | motg->usb_psy.num_properties = ARRAY_SIZE(otg_pm_power_props_usb); |
| 4107 | motg->usb_psy.get_property = otg_power_get_property_usb; |
| 4108 | motg->usb_psy.set_property = otg_power_set_property_usb; |
David Collins | d79acc5 | 2012-11-26 14:59:00 -0800 | [diff] [blame] | 4109 | motg->usb_psy.property_is_writeable |
| 4110 | = otg_power_property_is_writeable_usb; |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 4111 | |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 4112 | if (!pm8921_charger_register_vbus_sn(NULL)) { |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 4113 | /* if pm8921 use legacy implementation */ |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 4114 | dev_dbg(motg->phy.dev, "%s: legacy support\n", __func__); |
| 4115 | legacy_power_supply = true; |
| 4116 | } else { |
| 4117 | /* otherwise register our own power supply */ |
| 4118 | if (!msm_otg_register_power_supply(pdev, motg)) |
| 4119 | psy = &motg->usb_psy; |
David Keitel | 272ce52 | 2012-08-17 16:25:24 -0700 | [diff] [blame] | 4120 | } |
| 4121 | |
Jack Pham | 0c69528 | 2012-10-19 18:13:03 -0700 | [diff] [blame] | 4122 | if (legacy_power_supply && pdata->otg_control == OTG_PMIC_CONTROL) |
| 4123 | pm8921_charger_register_vbus_sn(&msm_otg_set_vbus_state); |
| 4124 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4125 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4126 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4127 | remove_phy: |
| 4128 | usb_set_transceiver(NULL); |
Manu Gautam | f8c4564 | 2012-08-10 10:20:56 -0700 | [diff] [blame] | 4129 | free_async_irq: |
| 4130 | if (motg->async_irq) |
| 4131 | free_irq(motg->async_irq, motg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4132 | free_irq: |
| 4133 | free_irq(motg->irq, motg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4134 | destroy_wlock: |
| 4135 | wake_lock_destroy(&motg->wlock); |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 4136 | clk_disable_unprepare(motg->core_clk); |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 4137 | msm_hsusb_ldo_enable(motg, USB_PHY_REG_OFF); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4138 | free_ldo_init: |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 4139 | msm_hsusb_ldo_init(motg, 0); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 4140 | free_hsusb_vddcx: |
| 4141 | regulator_disable(hsusb_vddcx); |
| 4142 | free_config_vddcx: |
| 4143 | regulator_set_voltage(hsusb_vddcx, |
| 4144 | vdd_val[motg->vdd_type][VDD_NONE], |
| 4145 | vdd_val[motg->vdd_type][VDD_MAX]); |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 4146 | devote_xo_handle: |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 4147 | clk_disable_unprepare(motg->pclk); |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 4148 | msm_xo_mode_vote(motg->xo_handle, MSM_XO_MODE_OFF); |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 4149 | free_xo_handle: |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 4150 | msm_xo_put(motg->xo_handle); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4151 | free_regs: |
| 4152 | iounmap(motg->regs); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 4153 | put_pclk: |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4154 | clk_put(motg->pclk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4155 | put_core_clk: |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 4156 | clk_put(motg->core_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4157 | put_clk: |
Pavankumar Kondeti | 923262e | 2012-04-20 15:34:24 +0530 | [diff] [blame] | 4158 | if (!IS_ERR(motg->clk)) |
| 4159 | clk_put(motg->clk); |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 4160 | if (!IS_ERR(motg->phy_reset_clk)) |
| 4161 | clk_put(motg->phy_reset_clk); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4162 | free_otg: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 4163 | kfree(motg->phy.otg); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 4164 | free_motg: |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4165 | kfree(motg); |
| 4166 | return ret; |
| 4167 | } |
| 4168 | |
| 4169 | static int __devexit msm_otg_remove(struct platform_device *pdev) |
| 4170 | { |
| 4171 | struct msm_otg *motg = platform_get_drvdata(pdev); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4172 | struct usb_otg *otg = motg->phy.otg; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4173 | int cnt = 0; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4174 | |
| 4175 | if (otg->host || otg->gadget) |
| 4176 | return -EBUSY; |
| 4177 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 4178 | if (pdev->dev.of_node) |
| 4179 | msm_otg_setup_devices(pdev, motg->pdata->mode, false); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4180 | if (motg->pdata->otg_control == OTG_PMIC_CONTROL) |
| 4181 | pm8921_charger_unregister_vbus_sn(0); |
Pavankumar Kondeti | 2aec9f3 | 2012-06-13 09:06:03 +0530 | [diff] [blame] | 4182 | msm_otg_mhl_register_callback(motg, NULL); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4183 | msm_otg_debugfs_cleanup(); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 4184 | cancel_delayed_work_sync(&motg->chg_work); |
Vijayavardhan Vennapusa | 68d55cf | 2012-06-27 20:06:12 +0530 | [diff] [blame] | 4185 | cancel_delayed_work_sync(&motg->pmic_id_status_work); |
Amit Blay | d0fe07b | 2012-09-05 16:42:09 +0300 | [diff] [blame] | 4186 | cancel_delayed_work_sync(&motg->suspend_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4187 | cancel_work_sync(&motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4188 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 4189 | pm_runtime_resume(&pdev->dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4190 | |
| 4191 | device_init_wakeup(&pdev->dev, 0); |
| 4192 | pm_runtime_disable(&pdev->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4193 | wake_lock_destroy(&motg->wlock); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4194 | |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 4195 | msm_hsusb_mhl_switch_enable(motg, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 4196 | if (motg->pdata->pmic_id_irq) |
| 4197 | free_irq(motg->pdata->pmic_id_irq, motg); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 4198 | usb_set_transceiver(NULL); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4199 | free_irq(motg->irq, motg); |
| 4200 | |
Jack Pham | 87f202f | 2012-08-06 00:24:22 -0700 | [diff] [blame] | 4201 | if (motg->pdata->otg_control == OTG_PHY_CONTROL && |
| 4202 | motg->pdata->mpm_otgsessvld_int) |
| 4203 | msm_mpm_enable_pin(motg->pdata->mpm_otgsessvld_int, 0); |
| 4204 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4205 | /* |
| 4206 | * Put PHY in low power mode. |
| 4207 | */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4208 | ulpi_read(otg->phy, 0x14); |
| 4209 | ulpi_write(otg->phy, 0x08, 0x09); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4210 | |
| 4211 | writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC); |
| 4212 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 4213 | if (readl(USB_PORTSC) & PORTSC_PHCD) |
| 4214 | break; |
| 4215 | udelay(1); |
| 4216 | cnt++; |
| 4217 | } |
| 4218 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4219 | dev_err(otg->phy->dev, "Unable to suspend PHY\n"); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4220 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 4221 | clk_disable_unprepare(motg->pclk); |
| 4222 | clk_disable_unprepare(motg->core_clk); |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 4223 | msm_xo_put(motg->xo_handle); |
Amit Blay | 81801aa | 2012-09-19 12:08:12 +0200 | [diff] [blame] | 4224 | msm_hsusb_ldo_enable(motg, USB_PHY_REG_OFF); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 4225 | msm_hsusb_ldo_init(motg, 0); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 4226 | regulator_disable(hsusb_vddcx); |
| 4227 | regulator_set_voltage(hsusb_vddcx, |
| 4228 | vdd_val[motg->vdd_type][VDD_NONE], |
| 4229 | vdd_val[motg->vdd_type][VDD_MAX]); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4230 | |
| 4231 | iounmap(motg->regs); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4232 | pm_runtime_set_suspended(&pdev->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4233 | |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 4234 | if (!IS_ERR(motg->phy_reset_clk)) |
| 4235 | clk_put(motg->phy_reset_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4236 | clk_put(motg->pclk); |
Pavankumar Kondeti | 923262e | 2012-04-20 15:34:24 +0530 | [diff] [blame] | 4237 | if (!IS_ERR(motg->clk)) |
| 4238 | clk_put(motg->clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 4239 | clk_put(motg->core_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4240 | |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 4241 | if (motg->bus_perf_client) |
| 4242 | msm_bus_scale_unregister_client(motg->bus_perf_client); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4243 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 4244 | kfree(motg->phy.otg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4245 | kfree(motg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4246 | return 0; |
| 4247 | } |
| 4248 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4249 | #ifdef CONFIG_PM_RUNTIME |
| 4250 | static int msm_otg_runtime_idle(struct device *dev) |
| 4251 | { |
| 4252 | struct msm_otg *motg = dev_get_drvdata(dev); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4253 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4254 | |
| 4255 | dev_dbg(dev, "OTG runtime idle\n"); |
| 4256 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 4257 | if (phy->state == OTG_STATE_UNDEFINED) |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 4258 | return -EAGAIN; |
| 4259 | else |
| 4260 | return 0; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | static int msm_otg_runtime_suspend(struct device *dev) |
| 4264 | { |
| 4265 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 4266 | |
| 4267 | dev_dbg(dev, "OTG runtime suspend\n"); |
| 4268 | return msm_otg_suspend(motg); |
| 4269 | } |
| 4270 | |
| 4271 | static int msm_otg_runtime_resume(struct device *dev) |
| 4272 | { |
| 4273 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 4274 | |
| 4275 | dev_dbg(dev, "OTG runtime resume\n"); |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 4276 | pm_runtime_get_noresume(dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4277 | return msm_otg_resume(motg); |
| 4278 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4279 | #endif |
| 4280 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 4281 | #ifdef CONFIG_PM_SLEEP |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4282 | static int msm_otg_pm_suspend(struct device *dev) |
| 4283 | { |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 4284 | int ret = 0; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4285 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 4286 | |
| 4287 | dev_dbg(dev, "OTG PM suspend\n"); |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 4288 | |
| 4289 | atomic_set(&motg->pm_suspended, 1); |
| 4290 | ret = msm_otg_suspend(motg); |
| 4291 | if (ret) |
| 4292 | atomic_set(&motg->pm_suspended, 0); |
| 4293 | |
| 4294 | return ret; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4295 | } |
| 4296 | |
| 4297 | static int msm_otg_pm_resume(struct device *dev) |
| 4298 | { |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 4299 | int ret = 0; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4300 | struct msm_otg *motg = dev_get_drvdata(dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4301 | |
| 4302 | dev_dbg(dev, "OTG PM resume\n"); |
| 4303 | |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 4304 | atomic_set(&motg->pm_suspended, 0); |
Jack Pham | c7edb17 | 2012-08-13 15:32:39 -0700 | [diff] [blame] | 4305 | if (motg->async_int || motg->sm_work_pending) { |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 4306 | pm_runtime_get_noresume(dev); |
| 4307 | ret = msm_otg_resume(motg); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4308 | |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 4309 | /* Update runtime PM status */ |
| 4310 | pm_runtime_disable(dev); |
| 4311 | pm_runtime_set_active(dev); |
| 4312 | pm_runtime_enable(dev); |
| 4313 | |
Jack Pham | c7edb17 | 2012-08-13 15:32:39 -0700 | [diff] [blame] | 4314 | if (motg->sm_work_pending) { |
| 4315 | motg->sm_work_pending = false; |
| 4316 | queue_work(system_nrt_wq, &motg->sm_work); |
| 4317 | } |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 4318 | } |
| 4319 | |
| 4320 | return ret; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4321 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4322 | #endif |
| 4323 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 4324 | #ifdef CONFIG_PM |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4325 | static const struct dev_pm_ops msm_otg_dev_pm_ops = { |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 4326 | SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume) |
| 4327 | SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume, |
| 4328 | msm_otg_runtime_idle) |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4329 | }; |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 4330 | #endif |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4331 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 4332 | static struct of_device_id msm_otg_dt_match[] = { |
| 4333 | { .compatible = "qcom,hsusb-otg", |
| 4334 | }, |
| 4335 | {} |
| 4336 | }; |
| 4337 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4338 | static struct platform_driver msm_otg_driver = { |
| 4339 | .remove = __devexit_p(msm_otg_remove), |
| 4340 | .driver = { |
| 4341 | .name = DRIVER_NAME, |
| 4342 | .owner = THIS_MODULE, |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 4343 | #ifdef CONFIG_PM |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 4344 | .pm = &msm_otg_dev_pm_ops, |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 4345 | #endif |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 4346 | .of_match_table = msm_otg_dt_match, |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 4347 | }, |
| 4348 | }; |
| 4349 | |
| 4350 | static int __init msm_otg_init(void) |
| 4351 | { |
| 4352 | return platform_driver_probe(&msm_otg_driver, msm_otg_probe); |
| 4353 | } |
| 4354 | |
| 4355 | static void __exit msm_otg_exit(void) |
| 4356 | { |
| 4357 | platform_driver_unregister(&msm_otg_driver); |
| 4358 | } |
| 4359 | |
| 4360 | module_init(msm_otg_init); |
| 4361 | module_exit(msm_otg_exit); |
| 4362 | |
| 4363 | MODULE_LICENSE("GPL v2"); |
| 4364 | MODULE_DESCRIPTION("MSM USB transceiver driver"); |