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