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