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