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