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