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