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