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