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