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