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