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; |
Mayank Rana | 9e9a2ac | 2012-03-24 04:05:28 +0530 | [diff] [blame] | 77 | static struct regulator *mhl_analog_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 | |
Mayank Rana | 9e9a2ac | 2012-03-24 04:05:28 +0530 | [diff] [blame] | 253 | if (!mhl_analog_switch) { |
| 254 | pr_err("%s: mhl_analog_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) { |
| 259 | if (regulator_enable(mhl_analog_switch)) |
| 260 | pr_err("unable to enable mhl_analog_switch\n"); |
| 261 | } else { |
| 262 | regulator_disable(mhl_analog_switch); |
| 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 | |
David Keitel | 081a3e2 | 2012-04-18 12:37:07 -0700 | [diff] [blame] | 975 | static int msm_otg_notify_chg_type(struct msm_otg *motg) |
| 976 | { |
| 977 | static int charger_type; |
| 978 | /* |
| 979 | * TODO |
| 980 | * Unify OTG driver charger types and power supply charger types |
| 981 | */ |
| 982 | if (charger_type == motg->chg_type) |
| 983 | return 0; |
| 984 | |
| 985 | if (motg->chg_type == USB_SDP_CHARGER) |
| 986 | charger_type = POWER_SUPPLY_TYPE_USB; |
| 987 | else if (motg->chg_type == USB_CDP_CHARGER) |
| 988 | charger_type = POWER_SUPPLY_TYPE_USB_CDP; |
| 989 | else if (motg->chg_type == USB_DCP_CHARGER) |
| 990 | charger_type = POWER_SUPPLY_TYPE_USB_DCP; |
| 991 | else if ((motg->chg_type == USB_ACA_DOCK_CHARGER || |
| 992 | motg->chg_type == USB_ACA_A_CHARGER || |
| 993 | motg->chg_type == USB_ACA_B_CHARGER || |
| 994 | motg->chg_type == USB_ACA_C_CHARGER)) |
| 995 | charger_type = POWER_SUPPLY_TYPE_USB_ACA; |
| 996 | else |
| 997 | charger_type = POWER_SUPPLY_TYPE_BATTERY; |
| 998 | |
| 999 | return pm8921_set_usb_power_supply_type(charger_type); |
| 1000 | } |
| 1001 | |
Amit Blay | 0f7edf7 | 2012-01-15 10:11:27 +0200 | [diff] [blame] | 1002 | static int msm_otg_notify_power_supply(struct msm_otg *motg, unsigned mA) |
| 1003 | { |
Amit Blay | 0f7edf7 | 2012-01-15 10:11:27 +0200 | [diff] [blame] | 1004 | |
Amit Blay | 0f7edf7 | 2012-01-15 10:11:27 +0200 | [diff] [blame] | 1005 | if (!psy) |
| 1006 | goto psy_not_supported; |
| 1007 | |
| 1008 | if (motg->cur_power == 0 && mA > 0) { |
| 1009 | /* Enable charging */ |
| 1010 | if (power_supply_set_online(psy, true)) |
| 1011 | goto psy_not_supported; |
| 1012 | } else if (motg->cur_power > 0 && mA == 0) { |
| 1013 | /* Disable charging */ |
| 1014 | if (power_supply_set_online(psy, false)) |
| 1015 | goto psy_not_supported; |
| 1016 | return 0; |
| 1017 | } |
| 1018 | /* Set max current limit */ |
| 1019 | if (power_supply_set_current_limit(psy, 1000*mA)) |
| 1020 | goto psy_not_supported; |
| 1021 | |
| 1022 | return 0; |
| 1023 | |
| 1024 | psy_not_supported: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1025 | 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] | 1026 | return -ENXIO; |
| 1027 | } |
| 1028 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1029 | static void msm_otg_notify_charger(struct msm_otg *motg, unsigned mA) |
| 1030 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1031 | struct usb_gadget *g = motg->phy.otg->gadget; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1032 | |
| 1033 | if (g && g->is_a_peripheral) |
| 1034 | return; |
| 1035 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1036 | if ((motg->chg_type == USB_ACA_DOCK_CHARGER || |
| 1037 | motg->chg_type == USB_ACA_A_CHARGER || |
| 1038 | motg->chg_type == USB_ACA_B_CHARGER || |
| 1039 | motg->chg_type == USB_ACA_C_CHARGER) && |
| 1040 | mA > IDEV_ACA_CHG_LIMIT) |
| 1041 | mA = IDEV_ACA_CHG_LIMIT; |
| 1042 | |
David Keitel | 081a3e2 | 2012-04-18 12:37:07 -0700 | [diff] [blame] | 1043 | if (msm_otg_notify_chg_type(motg)) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1044 | dev_err(motg->phy.dev, |
David Keitel | 081a3e2 | 2012-04-18 12:37:07 -0700 | [diff] [blame] | 1045 | "Failed notifying %d charger type to PMIC\n", |
| 1046 | motg->chg_type); |
| 1047 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1048 | if (motg->cur_power == mA) |
| 1049 | return; |
| 1050 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1051 | dev_info(motg->phy.dev, "Avail curr from USB = %u\n", mA); |
Amit Blay | 0f7edf7 | 2012-01-15 10:11:27 +0200 | [diff] [blame] | 1052 | |
| 1053 | /* |
| 1054 | * Use Power Supply API if supported, otherwise fallback |
| 1055 | * to legacy pm8921 API. |
| 1056 | */ |
| 1057 | if (msm_otg_notify_power_supply(motg, mA)) |
| 1058 | pm8921_charger_vbus_draw(mA); |
| 1059 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1060 | motg->cur_power = mA; |
| 1061 | } |
| 1062 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1063 | static int msm_otg_set_power(struct usb_phy *phy, unsigned mA) |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1064 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1065 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1066 | |
| 1067 | /* |
| 1068 | * Gadget driver uses set_power method to notify about the |
| 1069 | * available current based on suspend/configured states. |
| 1070 | * |
| 1071 | * IDEV_CHG can be drawn irrespective of suspend/un-configured |
| 1072 | * states when CDP/ACA is connected. |
| 1073 | */ |
| 1074 | if (motg->chg_type == USB_SDP_CHARGER) |
| 1075 | msm_otg_notify_charger(motg, mA); |
| 1076 | |
| 1077 | return 0; |
| 1078 | } |
| 1079 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1080 | static void msm_otg_start_host(struct usb_otg *otg, int on) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1081 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1082 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1083 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 1084 | struct usb_hcd *hcd; |
| 1085 | |
| 1086 | if (!otg->host) |
| 1087 | return; |
| 1088 | |
| 1089 | hcd = bus_to_hcd(otg->host); |
| 1090 | |
| 1091 | if (on) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1092 | dev_dbg(otg->phy->dev, "host on\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1093 | |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 1094 | if (pdata->otg_control == OTG_PHY_CONTROL) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1095 | ulpi_write(otg->phy, OTG_COMP_DISABLE, |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 1096 | ULPI_SET(ULPI_PWR_CLK_MNG_REG)); |
| 1097 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1098 | /* |
| 1099 | * Some boards have a switch cotrolled by gpio |
| 1100 | * to enable/disable internal HUB. Enable internal |
| 1101 | * HUB before kicking the host. |
| 1102 | */ |
| 1103 | if (pdata->setup_gpio) |
| 1104 | pdata->setup_gpio(OTG_STATE_A_HOST); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1105 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1106 | } else { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1107 | dev_dbg(otg->phy->dev, "host off\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1108 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1109 | usb_remove_hcd(hcd); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1110 | /* HCD core reset all bits of PORTSC. select ULPI phy */ |
| 1111 | writel_relaxed(0x80000000, USB_PORTSC); |
| 1112 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1113 | if (pdata->setup_gpio) |
| 1114 | pdata->setup_gpio(OTG_STATE_UNDEFINED); |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 1115 | |
| 1116 | if (pdata->otg_control == OTG_PHY_CONTROL) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1117 | ulpi_write(otg->phy, OTG_COMP_DISABLE, |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 1118 | ULPI_CLR(ULPI_PWR_CLK_MNG_REG)); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1119 | } |
| 1120 | } |
| 1121 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1122 | static int msm_otg_usbdev_notify(struct notifier_block *self, |
| 1123 | unsigned long action, void *priv) |
| 1124 | { |
| 1125 | struct msm_otg *motg = container_of(self, struct msm_otg, usbdev_nb); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1126 | struct usb_otg *otg = motg->phy.otg; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1127 | struct usb_device *udev = priv; |
| 1128 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1129 | if (action == USB_BUS_ADD || action == USB_BUS_REMOVE) |
| 1130 | goto out; |
| 1131 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1132 | if (udev->bus != otg->host) |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1133 | goto out; |
| 1134 | /* |
| 1135 | * Interested in devices connected directly to the root hub. |
| 1136 | * ACA dock can supply IDEV_CHG irrespective devices connected |
| 1137 | * on the accessory port. |
| 1138 | */ |
| 1139 | if (!udev->parent || udev->parent->parent || |
| 1140 | motg->chg_type == USB_ACA_DOCK_CHARGER) |
| 1141 | goto out; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1142 | |
| 1143 | switch (action) { |
| 1144 | case USB_DEVICE_ADD: |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1145 | if (aca_enabled()) |
| 1146 | usb_disable_autosuspend(udev); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1147 | if (otg->phy->state == OTG_STATE_A_WAIT_BCON) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1148 | pr_debug("B_CONN set\n"); |
| 1149 | set_bit(B_CONN, &motg->inputs); |
| 1150 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1151 | otg->phy->state = OTG_STATE_A_HOST; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1152 | /* |
| 1153 | * OTG PET: A-device must end session within |
| 1154 | * 10 sec after PET enumeration. |
| 1155 | */ |
| 1156 | if (udev->quirks & USB_QUIRK_OTG_PET) |
| 1157 | msm_otg_start_timer(motg, TA_TST_MAINT, |
| 1158 | A_TST_MAINT); |
| 1159 | } |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1160 | /* fall through */ |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1161 | case USB_DEVICE_CONFIG: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1162 | if (udev->actconfig) |
| 1163 | motg->mA_port = udev->actconfig->desc.bMaxPower * 2; |
| 1164 | else |
| 1165 | motg->mA_port = IUNIT; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1166 | if (otg->phy->state == OTG_STATE_B_HOST) |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1167 | msm_otg_del_timer(motg); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1168 | break; |
| 1169 | case USB_DEVICE_REMOVE: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1170 | if ((otg->phy->state == OTG_STATE_A_HOST) || |
| 1171 | (otg->phy->state == OTG_STATE_A_SUSPEND)) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1172 | pr_debug("B_CONN clear\n"); |
| 1173 | clear_bit(B_CONN, &motg->inputs); |
| 1174 | /* |
| 1175 | * OTG PET: A-device must end session after |
| 1176 | * PET disconnection if it is enumerated |
| 1177 | * with bcdDevice[0] = 1. USB core sets |
| 1178 | * bus->otg_vbus_off for us. clear it here. |
| 1179 | */ |
| 1180 | if (udev->bus->otg_vbus_off) { |
| 1181 | udev->bus->otg_vbus_off = 0; |
| 1182 | set_bit(A_BUS_DROP, &motg->inputs); |
| 1183 | } |
| 1184 | queue_work(system_nrt_wq, &motg->sm_work); |
| 1185 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1186 | default: |
| 1187 | break; |
| 1188 | } |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1189 | if (test_bit(ID_A, &motg->inputs)) |
| 1190 | msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX - |
| 1191 | motg->mA_port); |
| 1192 | out: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1193 | return NOTIFY_OK; |
| 1194 | } |
| 1195 | |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1196 | static void msm_hsusb_vbus_power(struct msm_otg *motg, bool on) |
| 1197 | { |
| 1198 | int ret; |
| 1199 | static bool vbus_is_on; |
| 1200 | |
| 1201 | if (vbus_is_on == on) |
| 1202 | return; |
| 1203 | |
| 1204 | if (motg->pdata->vbus_power) { |
Mayank Rana | 91f597e | 2012-01-20 10:12:06 +0530 | [diff] [blame] | 1205 | ret = motg->pdata->vbus_power(on); |
| 1206 | if (!ret) |
| 1207 | vbus_is_on = on; |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1208 | return; |
| 1209 | } |
| 1210 | |
| 1211 | if (!vbus_otg) { |
| 1212 | pr_err("vbus_otg is NULL."); |
| 1213 | return; |
| 1214 | } |
| 1215 | |
Abhijeet Dharmapurikar | be05488 | 2012-01-03 20:27:07 -0800 | [diff] [blame] | 1216 | /* |
| 1217 | * if entering host mode tell the charger to not draw any current |
Abhijeet Dharmapurikar | 6d94121 | 2012-03-05 10:30:56 -0800 | [diff] [blame] | 1218 | * from usb before turning on the boost. |
| 1219 | * if exiting host mode disable the boost before enabling to draw |
| 1220 | * current from the source. |
Abhijeet Dharmapurikar | be05488 | 2012-01-03 20:27:07 -0800 | [diff] [blame] | 1221 | */ |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1222 | if (on) { |
Abhijeet Dharmapurikar | 6d94121 | 2012-03-05 10:30:56 -0800 | [diff] [blame] | 1223 | pm8921_disable_source_current(on); |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1224 | ret = regulator_enable(vbus_otg); |
| 1225 | if (ret) { |
| 1226 | pr_err("unable to enable vbus_otg\n"); |
| 1227 | return; |
| 1228 | } |
| 1229 | vbus_is_on = true; |
| 1230 | } else { |
| 1231 | ret = regulator_disable(vbus_otg); |
| 1232 | if (ret) { |
| 1233 | pr_err("unable to disable vbus_otg\n"); |
| 1234 | return; |
| 1235 | } |
Abhijeet Dharmapurikar | 6d94121 | 2012-03-05 10:30:56 -0800 | [diff] [blame] | 1236 | pm8921_disable_source_current(on); |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1237 | vbus_is_on = false; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1241 | 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] | 1242 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1243 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1244 | struct usb_hcd *hcd; |
| 1245 | |
| 1246 | /* |
| 1247 | * Fail host registration if this board can support |
| 1248 | * only peripheral configuration. |
| 1249 | */ |
| 1250 | if (motg->pdata->mode == USB_PERIPHERAL) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1251 | dev_info(otg->phy->dev, "Host mode is not supported\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1252 | return -ENODEV; |
| 1253 | } |
| 1254 | |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1255 | if (!motg->pdata->vbus_power && host) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1256 | vbus_otg = devm_regulator_get(motg->phy.dev, "vbus_otg"); |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1257 | if (IS_ERR(vbus_otg)) { |
| 1258 | pr_err("Unable to get vbus_otg\n"); |
| 1259 | return -ENODEV; |
| 1260 | } |
| 1261 | } |
| 1262 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1263 | if (!host) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1264 | if (otg->phy->state == OTG_STATE_A_HOST) { |
| 1265 | pm_runtime_get_sync(otg->phy->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1266 | usb_unregister_notify(&motg->usbdev_nb); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1267 | msm_otg_start_host(otg, 0); |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 1268 | msm_hsusb_vbus_power(motg, 0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1269 | otg->host = NULL; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1270 | otg->phy->state = OTG_STATE_UNDEFINED; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1271 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1272 | } else { |
| 1273 | otg->host = NULL; |
| 1274 | } |
| 1275 | |
| 1276 | return 0; |
| 1277 | } |
| 1278 | |
| 1279 | hcd = bus_to_hcd(host); |
| 1280 | hcd->power_budget = motg->pdata->power_budget; |
| 1281 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1282 | #ifdef CONFIG_USB_OTG |
| 1283 | host->otg_port = 1; |
| 1284 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1285 | motg->usbdev_nb.notifier_call = msm_otg_usbdev_notify; |
| 1286 | usb_register_notify(&motg->usbdev_nb); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1287 | otg->host = host; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1288 | dev_dbg(otg->phy->dev, "host driver registered w/ tranceiver\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1289 | |
| 1290 | /* |
| 1291 | * Kick the state machine work, if peripheral is not supported |
| 1292 | * or peripheral is already registered with us. |
| 1293 | */ |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1294 | if (motg->pdata->mode == USB_HOST || otg->gadget) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1295 | pm_runtime_get_sync(otg->phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1296 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1297 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1298 | |
| 1299 | return 0; |
| 1300 | } |
| 1301 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1302 | static void msm_otg_start_peripheral(struct usb_otg *otg, int on) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1303 | { |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1304 | int ret; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1305 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1306 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 1307 | |
| 1308 | if (!otg->gadget) |
| 1309 | return; |
| 1310 | |
| 1311 | if (on) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1312 | dev_dbg(otg->phy->dev, "gadget on\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1313 | /* |
| 1314 | * Some boards have a switch cotrolled by gpio |
| 1315 | * to enable/disable internal HUB. Disable internal |
| 1316 | * HUB before kicking the gadget. |
| 1317 | */ |
| 1318 | if (pdata->setup_gpio) |
| 1319 | pdata->setup_gpio(OTG_STATE_B_PERIPHERAL); |
Ofir Cohen | 94213a7 | 2012-05-03 14:26:32 +0300 | [diff] [blame] | 1320 | |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1321 | /* Configure BUS performance parameters for MAX bandwidth */ |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 1322 | if (motg->bus_perf_client && debug_bus_voting_enabled) { |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1323 | ret = msm_bus_scale_client_update_request( |
| 1324 | motg->bus_perf_client, 1); |
| 1325 | if (ret) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1326 | dev_err(motg->phy.dev, "%s: Failed to vote for " |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1327 | "bus bandwidth %d\n", __func__, ret); |
| 1328 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1329 | usb_gadget_vbus_connect(otg->gadget); |
| 1330 | } else { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1331 | dev_dbg(otg->phy->dev, "gadget off\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1332 | usb_gadget_vbus_disconnect(otg->gadget); |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1333 | /* Configure BUS performance parameters to default */ |
| 1334 | if (motg->bus_perf_client) { |
| 1335 | ret = msm_bus_scale_client_update_request( |
| 1336 | motg->bus_perf_client, 0); |
| 1337 | if (ret) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1338 | dev_err(motg->phy.dev, "%s: Failed to devote " |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 1339 | "for bus bw %d\n", __func__, ret); |
| 1340 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1341 | if (pdata->setup_gpio) |
| 1342 | pdata->setup_gpio(OTG_STATE_UNDEFINED); |
| 1343 | } |
| 1344 | |
| 1345 | } |
| 1346 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1347 | static int msm_otg_set_peripheral(struct usb_otg *otg, |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1348 | struct usb_gadget *gadget) |
| 1349 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1350 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1351 | |
| 1352 | /* |
| 1353 | * Fail peripheral registration if this board can support |
| 1354 | * only host configuration. |
| 1355 | */ |
| 1356 | if (motg->pdata->mode == USB_HOST) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1357 | dev_info(otg->phy->dev, "Peripheral mode is not supported\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1358 | return -ENODEV; |
| 1359 | } |
| 1360 | |
| 1361 | if (!gadget) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1362 | if (otg->phy->state == OTG_STATE_B_PERIPHERAL) { |
| 1363 | pm_runtime_get_sync(otg->phy->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1364 | msm_otg_start_peripheral(otg, 0); |
| 1365 | otg->gadget = NULL; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1366 | otg->phy->state = OTG_STATE_UNDEFINED; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1367 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1368 | } else { |
| 1369 | otg->gadget = NULL; |
| 1370 | } |
| 1371 | |
| 1372 | return 0; |
| 1373 | } |
| 1374 | otg->gadget = gadget; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1375 | dev_dbg(otg->phy->dev, "peripheral driver registered w/ tranceiver\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1376 | |
| 1377 | /* |
| 1378 | * Kick the state machine work, if host is not supported |
| 1379 | * or host is already registered with us. |
| 1380 | */ |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1381 | if (motg->pdata->mode == USB_PERIPHERAL || otg->host) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1382 | pm_runtime_get_sync(otg->phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1383 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1384 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1385 | |
| 1386 | return 0; |
| 1387 | } |
| 1388 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1389 | static bool msm_chg_aca_detect(struct msm_otg *motg) |
| 1390 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1391 | struct usb_phy *phy = &motg->phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1392 | u32 int_sts; |
| 1393 | bool ret = false; |
| 1394 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1395 | if (!aca_enabled()) |
| 1396 | goto out; |
| 1397 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1398 | if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) |
| 1399 | goto out; |
| 1400 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1401 | int_sts = ulpi_read(phy, 0x87); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1402 | switch (int_sts & 0x1C) { |
| 1403 | case 0x08: |
| 1404 | if (!test_and_set_bit(ID_A, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1405 | dev_dbg(phy->dev, "ID_A\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1406 | motg->chg_type = USB_ACA_A_CHARGER; |
| 1407 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1408 | clear_bit(ID_B, &motg->inputs); |
| 1409 | clear_bit(ID_C, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1410 | set_bit(ID, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1411 | ret = true; |
| 1412 | } |
| 1413 | break; |
| 1414 | case 0x0C: |
| 1415 | if (!test_and_set_bit(ID_B, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1416 | dev_dbg(phy->dev, "ID_B\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1417 | motg->chg_type = USB_ACA_B_CHARGER; |
| 1418 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1419 | clear_bit(ID_A, &motg->inputs); |
| 1420 | clear_bit(ID_C, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1421 | set_bit(ID, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1422 | ret = true; |
| 1423 | } |
| 1424 | break; |
| 1425 | case 0x10: |
| 1426 | if (!test_and_set_bit(ID_C, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1427 | dev_dbg(phy->dev, "ID_C\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1428 | motg->chg_type = USB_ACA_C_CHARGER; |
| 1429 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1430 | clear_bit(ID_A, &motg->inputs); |
| 1431 | clear_bit(ID_B, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1432 | set_bit(ID, &motg->inputs); |
| 1433 | ret = true; |
| 1434 | } |
| 1435 | break; |
| 1436 | case 0x04: |
| 1437 | if (test_and_clear_bit(ID, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1438 | dev_dbg(phy->dev, "ID_GND\n"); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1439 | motg->chg_type = USB_INVALID_CHARGER; |
| 1440 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1441 | clear_bit(ID_A, &motg->inputs); |
| 1442 | clear_bit(ID_B, &motg->inputs); |
| 1443 | clear_bit(ID_C, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1444 | ret = true; |
| 1445 | } |
| 1446 | break; |
| 1447 | default: |
| 1448 | ret = test_and_clear_bit(ID_A, &motg->inputs) | |
| 1449 | test_and_clear_bit(ID_B, &motg->inputs) | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1450 | test_and_clear_bit(ID_C, &motg->inputs) | |
| 1451 | !test_and_set_bit(ID, &motg->inputs); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1452 | if (ret) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1453 | 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] | 1454 | motg->chg_type = USB_INVALID_CHARGER; |
| 1455 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1456 | } |
| 1457 | } |
| 1458 | out: |
| 1459 | return ret; |
| 1460 | } |
| 1461 | |
| 1462 | static void msm_chg_enable_aca_det(struct msm_otg *motg) |
| 1463 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1464 | struct usb_phy *phy = &motg->phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1465 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1466 | if (!aca_enabled()) |
| 1467 | return; |
| 1468 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1469 | switch (motg->pdata->phy_type) { |
| 1470 | case SNPS_28NM_INTEGRATED_PHY: |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1471 | /* Disable ID_GND in link and PHY */ |
| 1472 | writel_relaxed(readl_relaxed(USB_OTGSC) & ~(OTGSC_IDPU | |
| 1473 | OTGSC_IDIE), USB_OTGSC); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1474 | ulpi_write(phy, 0x01, 0x0C); |
| 1475 | ulpi_write(phy, 0x10, 0x0F); |
| 1476 | ulpi_write(phy, 0x10, 0x12); |
Pavankumar Kondeti | 446f454 | 2012-02-01 13:57:13 +0530 | [diff] [blame] | 1477 | /* Disable PMIC ID pull-up */ |
| 1478 | pm8xxx_usb_id_pullup(0); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1479 | /* Enable ACA ID detection */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1480 | ulpi_write(phy, 0x20, 0x85); |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 1481 | aca_id_turned_on = true; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1482 | break; |
| 1483 | default: |
| 1484 | break; |
| 1485 | } |
| 1486 | } |
| 1487 | |
| 1488 | static void msm_chg_enable_aca_intr(struct msm_otg *motg) |
| 1489 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1490 | struct usb_phy *phy = &motg->phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1491 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1492 | if (!aca_enabled()) |
| 1493 | return; |
| 1494 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1495 | switch (motg->pdata->phy_type) { |
| 1496 | case SNPS_28NM_INTEGRATED_PHY: |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1497 | /* Enable ACA Detection interrupt (on any RID change) */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1498 | ulpi_write(phy, 0x01, 0x94); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1499 | break; |
| 1500 | default: |
| 1501 | break; |
| 1502 | } |
| 1503 | } |
| 1504 | |
| 1505 | static void msm_chg_disable_aca_intr(struct msm_otg *motg) |
| 1506 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1507 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1508 | |
| 1509 | if (!aca_enabled()) |
| 1510 | return; |
| 1511 | |
| 1512 | switch (motg->pdata->phy_type) { |
| 1513 | case SNPS_28NM_INTEGRATED_PHY: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1514 | ulpi_write(phy, 0x01, 0x95); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1515 | break; |
| 1516 | default: |
| 1517 | break; |
| 1518 | } |
| 1519 | } |
| 1520 | |
| 1521 | static bool msm_chg_check_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; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1524 | bool ret = false; |
| 1525 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1526 | if (!aca_enabled()) |
| 1527 | return ret; |
| 1528 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1529 | switch (motg->pdata->phy_type) { |
| 1530 | case SNPS_28NM_INTEGRATED_PHY: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1531 | if (ulpi_read(phy, 0x91) & 1) { |
| 1532 | dev_dbg(phy->dev, "RID change\n"); |
| 1533 | ulpi_write(phy, 0x01, 0x92); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1534 | ret = msm_chg_aca_detect(motg); |
| 1535 | } |
| 1536 | default: |
| 1537 | break; |
| 1538 | } |
| 1539 | return ret; |
| 1540 | } |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1541 | |
| 1542 | static void msm_otg_id_timer_func(unsigned long data) |
| 1543 | { |
| 1544 | struct msm_otg *motg = (struct msm_otg *) data; |
| 1545 | |
| 1546 | if (!aca_enabled()) |
| 1547 | return; |
| 1548 | |
| 1549 | if (atomic_read(&motg->in_lpm)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1550 | dev_dbg(motg->phy.dev, "timer: in lpm\n"); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1551 | return; |
| 1552 | } |
| 1553 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1554 | if (motg->phy.state == OTG_STATE_A_SUSPEND) |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1555 | goto out; |
| 1556 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1557 | if (msm_chg_check_aca_intr(motg)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1558 | dev_dbg(motg->phy.dev, "timer: aca work\n"); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1559 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1560 | } |
| 1561 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1562 | out: |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1563 | if (!test_bit(ID, &motg->inputs) || test_bit(ID_A, &motg->inputs)) |
| 1564 | mod_timer(&motg->id_timer, ID_TIMER_FREQ); |
| 1565 | } |
| 1566 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1567 | static bool msm_chg_check_secondary_det(struct msm_otg *motg) |
| 1568 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1569 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1570 | u32 chg_det; |
| 1571 | bool ret = false; |
| 1572 | |
| 1573 | switch (motg->pdata->phy_type) { |
| 1574 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1575 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1576 | ret = chg_det & (1 << 4); |
| 1577 | break; |
| 1578 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1579 | chg_det = ulpi_read(phy, 0x87); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1580 | ret = chg_det & 1; |
| 1581 | break; |
| 1582 | default: |
| 1583 | break; |
| 1584 | } |
| 1585 | return ret; |
| 1586 | } |
| 1587 | |
| 1588 | static void msm_chg_enable_secondary_det(struct msm_otg *motg) |
| 1589 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1590 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1591 | u32 chg_det; |
| 1592 | |
| 1593 | switch (motg->pdata->phy_type) { |
| 1594 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1595 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1596 | /* Turn off charger block */ |
| 1597 | chg_det |= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1598 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1599 | udelay(20); |
| 1600 | /* control chg block via ULPI */ |
| 1601 | chg_det &= ~(1 << 3); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1602 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1603 | /* put it in host mode for enabling D- source */ |
| 1604 | chg_det &= ~(1 << 2); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1605 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1606 | /* Turn on chg detect block */ |
| 1607 | chg_det &= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1608 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1609 | udelay(20); |
| 1610 | /* enable chg detection */ |
| 1611 | chg_det &= ~(1 << 0); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1612 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1613 | break; |
| 1614 | case SNPS_28NM_INTEGRATED_PHY: |
Pavankumar Kondeti | 283146f | 2012-01-12 12:51:19 +0530 | [diff] [blame] | 1615 | /* Turn off VDP_SRC */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1616 | ulpi_write(phy, 0x3, 0x86); |
Pavankumar Kondeti | 283146f | 2012-01-12 12:51:19 +0530 | [diff] [blame] | 1617 | msleep(20); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1618 | /* |
| 1619 | * Configure DM as current source, DP as current sink |
| 1620 | * and enable battery charging comparators. |
| 1621 | */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1622 | ulpi_write(phy, 0x8, 0x85); |
| 1623 | ulpi_write(phy, 0x2, 0x85); |
| 1624 | ulpi_write(phy, 0x1, 0x85); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1625 | break; |
| 1626 | default: |
| 1627 | break; |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | static bool msm_chg_check_primary_det(struct msm_otg *motg) |
| 1632 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1633 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1634 | u32 chg_det; |
| 1635 | bool ret = false; |
| 1636 | |
| 1637 | switch (motg->pdata->phy_type) { |
| 1638 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1639 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1640 | ret = chg_det & (1 << 4); |
| 1641 | break; |
| 1642 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1643 | chg_det = ulpi_read(phy, 0x87); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1644 | ret = chg_det & 1; |
| 1645 | break; |
| 1646 | default: |
| 1647 | break; |
| 1648 | } |
| 1649 | return ret; |
| 1650 | } |
| 1651 | |
| 1652 | static void msm_chg_enable_primary_det(struct msm_otg *motg) |
| 1653 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1654 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1655 | u32 chg_det; |
| 1656 | |
| 1657 | switch (motg->pdata->phy_type) { |
| 1658 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1659 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1660 | /* enable chg detection */ |
| 1661 | chg_det &= ~(1 << 0); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1662 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1663 | break; |
| 1664 | case SNPS_28NM_INTEGRATED_PHY: |
| 1665 | /* |
| 1666 | * Configure DP as current source, DM as current sink |
| 1667 | * and enable battery charging comparators. |
| 1668 | */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1669 | ulpi_write(phy, 0x2, 0x85); |
| 1670 | ulpi_write(phy, 0x1, 0x85); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1671 | break; |
| 1672 | default: |
| 1673 | break; |
| 1674 | } |
| 1675 | } |
| 1676 | |
| 1677 | static bool msm_chg_check_dcd(struct msm_otg *motg) |
| 1678 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1679 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1680 | u32 line_state; |
| 1681 | bool ret = false; |
| 1682 | |
| 1683 | switch (motg->pdata->phy_type) { |
| 1684 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1685 | line_state = ulpi_read(phy, 0x15); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1686 | ret = !(line_state & 1); |
| 1687 | break; |
| 1688 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1689 | line_state = ulpi_read(phy, 0x87); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1690 | ret = line_state & 2; |
| 1691 | break; |
| 1692 | default: |
| 1693 | break; |
| 1694 | } |
| 1695 | return ret; |
| 1696 | } |
| 1697 | |
| 1698 | static void msm_chg_disable_dcd(struct msm_otg *motg) |
| 1699 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1700 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1701 | u32 chg_det; |
| 1702 | |
| 1703 | switch (motg->pdata->phy_type) { |
| 1704 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1705 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1706 | chg_det &= ~(1 << 5); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1707 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1708 | break; |
| 1709 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1710 | ulpi_write(phy, 0x10, 0x86); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1711 | break; |
| 1712 | default: |
| 1713 | break; |
| 1714 | } |
| 1715 | } |
| 1716 | |
| 1717 | static void msm_chg_enable_dcd(struct msm_otg *motg) |
| 1718 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1719 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1720 | u32 chg_det; |
| 1721 | |
| 1722 | switch (motg->pdata->phy_type) { |
| 1723 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1724 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1725 | /* Turn on D+ current source */ |
| 1726 | chg_det |= (1 << 5); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1727 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1728 | break; |
| 1729 | case SNPS_28NM_INTEGRATED_PHY: |
| 1730 | /* Data contact detection enable */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1731 | ulpi_write(phy, 0x10, 0x85); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1732 | break; |
| 1733 | default: |
| 1734 | break; |
| 1735 | } |
| 1736 | } |
| 1737 | |
| 1738 | static void msm_chg_block_on(struct msm_otg *motg) |
| 1739 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1740 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1741 | u32 func_ctrl, chg_det; |
| 1742 | |
| 1743 | /* put the controller in non-driving mode */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1744 | func_ctrl = ulpi_read(phy, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1745 | func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
| 1746 | func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1747 | ulpi_write(phy, func_ctrl, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1748 | |
| 1749 | switch (motg->pdata->phy_type) { |
| 1750 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1751 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1752 | /* control chg block via ULPI */ |
| 1753 | chg_det &= ~(1 << 3); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1754 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1755 | /* Turn on chg detect block */ |
| 1756 | chg_det &= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1757 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1758 | udelay(20); |
| 1759 | break; |
| 1760 | case SNPS_28NM_INTEGRATED_PHY: |
| 1761 | /* Clear charger detecting control bits */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1762 | ulpi_write(phy, 0x1F, 0x86); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1763 | /* Clear alt interrupt latch and enable bits */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1764 | ulpi_write(phy, 0x1F, 0x92); |
| 1765 | ulpi_write(phy, 0x1F, 0x95); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1766 | udelay(100); |
| 1767 | break; |
| 1768 | default: |
| 1769 | break; |
| 1770 | } |
| 1771 | } |
| 1772 | |
| 1773 | static void msm_chg_block_off(struct msm_otg *motg) |
| 1774 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1775 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1776 | u32 func_ctrl, chg_det; |
| 1777 | |
| 1778 | switch (motg->pdata->phy_type) { |
| 1779 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1780 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1781 | /* Turn off charger block */ |
| 1782 | chg_det |= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1783 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1784 | break; |
| 1785 | case SNPS_28NM_INTEGRATED_PHY: |
| 1786 | /* Clear charger detecting control bits */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1787 | ulpi_write(phy, 0x3F, 0x86); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1788 | /* Clear alt interrupt latch and enable bits */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1789 | ulpi_write(phy, 0x1F, 0x92); |
| 1790 | ulpi_write(phy, 0x1F, 0x95); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1791 | break; |
| 1792 | default: |
| 1793 | break; |
| 1794 | } |
| 1795 | |
| 1796 | /* put the controller in normal mode */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1797 | func_ctrl = ulpi_read(phy, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1798 | func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
| 1799 | func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NORMAL; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1800 | ulpi_write(phy, func_ctrl, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1801 | } |
| 1802 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 1803 | static const char *chg_to_string(enum usb_chg_type chg_type) |
| 1804 | { |
| 1805 | switch (chg_type) { |
| 1806 | case USB_SDP_CHARGER: return "USB_SDP_CHARGER"; |
| 1807 | case USB_DCP_CHARGER: return "USB_DCP_CHARGER"; |
| 1808 | case USB_CDP_CHARGER: return "USB_CDP_CHARGER"; |
| 1809 | case USB_ACA_A_CHARGER: return "USB_ACA_A_CHARGER"; |
| 1810 | case USB_ACA_B_CHARGER: return "USB_ACA_B_CHARGER"; |
| 1811 | case USB_ACA_C_CHARGER: return "USB_ACA_C_CHARGER"; |
| 1812 | case USB_ACA_DOCK_CHARGER: return "USB_ACA_DOCK_CHARGER"; |
| 1813 | default: return "INVALID_CHARGER"; |
| 1814 | } |
| 1815 | } |
| 1816 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1817 | #define MSM_CHG_DCD_POLL_TIME (100 * HZ/1000) /* 100 msec */ |
| 1818 | #define MSM_CHG_DCD_MAX_RETRIES 6 /* Tdcd_tmout = 6 * 100 msec */ |
Pavankumar Kondeti | 283146f | 2012-01-12 12:51:19 +0530 | [diff] [blame] | 1819 | #define MSM_CHG_PRIMARY_DET_TIME (50 * HZ/1000) /* TVDPSRC_ON */ |
| 1820 | #define MSM_CHG_SECONDARY_DET_TIME (50 * HZ/1000) /* TVDMSRC_ON */ |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1821 | static void msm_chg_detect_work(struct work_struct *w) |
| 1822 | { |
| 1823 | 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] | 1824 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | 2d09e5f | 2012-01-16 08:56:57 +0530 | [diff] [blame] | 1825 | bool is_dcd = false, tmout, vout, is_aca; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1826 | unsigned long delay; |
| 1827 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1828 | dev_dbg(phy->dev, "chg detection work\n"); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1829 | switch (motg->chg_state) { |
| 1830 | case USB_CHG_STATE_UNDEFINED: |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1831 | msm_chg_block_on(motg); |
Pavankumar Kondeti | 2d09e5f | 2012-01-16 08:56:57 +0530 | [diff] [blame] | 1832 | if (motg->pdata->enable_dcd) |
| 1833 | msm_chg_enable_dcd(motg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1834 | msm_chg_enable_aca_det(motg); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1835 | motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; |
| 1836 | motg->dcd_retries = 0; |
| 1837 | delay = MSM_CHG_DCD_POLL_TIME; |
| 1838 | break; |
| 1839 | case USB_CHG_STATE_WAIT_FOR_DCD: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1840 | is_aca = msm_chg_aca_detect(motg); |
| 1841 | if (is_aca) { |
| 1842 | /* |
| 1843 | * ID_A can be ACA dock too. continue |
| 1844 | * primary detection after DCD. |
| 1845 | */ |
| 1846 | if (test_bit(ID_A, &motg->inputs)) { |
| 1847 | motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; |
| 1848 | } else { |
| 1849 | delay = 0; |
| 1850 | break; |
| 1851 | } |
| 1852 | } |
Pavankumar Kondeti | 2d09e5f | 2012-01-16 08:56:57 +0530 | [diff] [blame] | 1853 | if (motg->pdata->enable_dcd) |
| 1854 | is_dcd = msm_chg_check_dcd(motg); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1855 | tmout = ++motg->dcd_retries == MSM_CHG_DCD_MAX_RETRIES; |
| 1856 | if (is_dcd || tmout) { |
Pavankumar Kondeti | 2d09e5f | 2012-01-16 08:56:57 +0530 | [diff] [blame] | 1857 | if (motg->pdata->enable_dcd) |
| 1858 | msm_chg_disable_dcd(motg); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1859 | msm_chg_enable_primary_det(motg); |
| 1860 | delay = MSM_CHG_PRIMARY_DET_TIME; |
| 1861 | motg->chg_state = USB_CHG_STATE_DCD_DONE; |
| 1862 | } else { |
| 1863 | delay = MSM_CHG_DCD_POLL_TIME; |
| 1864 | } |
| 1865 | break; |
| 1866 | case USB_CHG_STATE_DCD_DONE: |
| 1867 | vout = msm_chg_check_primary_det(motg); |
| 1868 | if (vout) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1869 | if (test_bit(ID_A, &motg->inputs)) { |
| 1870 | motg->chg_type = USB_ACA_DOCK_CHARGER; |
| 1871 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1872 | delay = 0; |
| 1873 | break; |
| 1874 | } |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1875 | msm_chg_enable_secondary_det(motg); |
| 1876 | delay = MSM_CHG_SECONDARY_DET_TIME; |
| 1877 | motg->chg_state = USB_CHG_STATE_PRIMARY_DONE; |
| 1878 | } else { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 1879 | if (test_bit(ID_A, &motg->inputs)) { |
| 1880 | motg->chg_type = USB_ACA_A_CHARGER; |
| 1881 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1882 | delay = 0; |
| 1883 | break; |
| 1884 | } |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1885 | motg->chg_type = USB_SDP_CHARGER; |
| 1886 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1887 | delay = 0; |
| 1888 | } |
| 1889 | break; |
| 1890 | case USB_CHG_STATE_PRIMARY_DONE: |
| 1891 | vout = msm_chg_check_secondary_det(motg); |
| 1892 | if (vout) |
| 1893 | motg->chg_type = USB_DCP_CHARGER; |
| 1894 | else |
| 1895 | motg->chg_type = USB_CDP_CHARGER; |
| 1896 | motg->chg_state = USB_CHG_STATE_SECONDARY_DONE; |
| 1897 | /* fall through */ |
| 1898 | case USB_CHG_STATE_SECONDARY_DONE: |
| 1899 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1900 | case USB_CHG_STATE_DETECTED: |
| 1901 | msm_chg_block_off(motg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1902 | msm_chg_enable_aca_det(motg); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1903 | /* |
| 1904 | * Spurious interrupt is seen after enabling ACA detection |
| 1905 | * due to which charger detection fails in case of PET. |
| 1906 | * Add delay of 100 microsec to avoid that. |
| 1907 | */ |
| 1908 | udelay(100); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1909 | msm_chg_enable_aca_intr(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 1910 | dev_dbg(phy->dev, "chg_type = %s\n", |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 1911 | chg_to_string(motg->chg_type)); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1912 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1913 | return; |
| 1914 | default: |
| 1915 | return; |
| 1916 | } |
| 1917 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1918 | queue_delayed_work(system_nrt_wq, &motg->chg_work, delay); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1919 | } |
| 1920 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1921 | /* |
| 1922 | * We support OTG, Peripheral only and Host only configurations. In case |
| 1923 | * of OTG, mode switch (host-->peripheral/peripheral-->host) can happen |
| 1924 | * via Id pin status or user request (debugfs). Id/BSV interrupts are not |
| 1925 | * enabled when switch is controlled by user and default mode is supplied |
| 1926 | * by board file, which can be changed by userspace later. |
| 1927 | */ |
| 1928 | static void msm_otg_init_sm(struct msm_otg *motg) |
| 1929 | { |
| 1930 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 1931 | u32 otgsc = readl(USB_OTGSC); |
| 1932 | |
| 1933 | switch (pdata->mode) { |
| 1934 | case USB_OTG: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1935 | if (pdata->otg_control == OTG_USER_CONTROL) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1936 | if (pdata->default_mode == USB_HOST) { |
| 1937 | clear_bit(ID, &motg->inputs); |
| 1938 | } else if (pdata->default_mode == USB_PERIPHERAL) { |
| 1939 | set_bit(ID, &motg->inputs); |
| 1940 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1941 | } else { |
| 1942 | set_bit(ID, &motg->inputs); |
| 1943 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 1944 | } |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 1945 | } else if (pdata->otg_control == OTG_PHY_CONTROL) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1946 | if (otgsc & OTGSC_ID) { |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 1947 | set_bit(ID, &motg->inputs); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1948 | } else { |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 1949 | clear_bit(ID, &motg->inputs); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 1950 | set_bit(A_BUS_REQ, &motg->inputs); |
| 1951 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1952 | if (otgsc & OTGSC_BSV) |
| 1953 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1954 | else |
| 1955 | clear_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 1956 | } else if (pdata->otg_control == OTG_PMIC_CONTROL) { |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 1957 | if (pdata->pmic_id_irq) { |
Stephen Boyd | 431771e | 2012-04-18 20:00:23 -0700 | [diff] [blame] | 1958 | unsigned long flags; |
| 1959 | local_irq_save(flags); |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 1960 | if (irq_read_line(pdata->pmic_id_irq)) |
| 1961 | set_bit(ID, &motg->inputs); |
| 1962 | else |
| 1963 | clear_bit(ID, &motg->inputs); |
Stephen Boyd | 431771e | 2012-04-18 20:00:23 -0700 | [diff] [blame] | 1964 | local_irq_restore(flags); |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 1965 | } |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 1966 | /* |
| 1967 | * VBUS initial state is reported after PMIC |
| 1968 | * driver initialization. Wait for it. |
| 1969 | */ |
| 1970 | wait_for_completion(&pmic_vbus_init); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1971 | } |
| 1972 | break; |
| 1973 | case USB_HOST: |
| 1974 | clear_bit(ID, &motg->inputs); |
| 1975 | break; |
| 1976 | case USB_PERIPHERAL: |
| 1977 | set_bit(ID, &motg->inputs); |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 1978 | if (pdata->otg_control == OTG_PHY_CONTROL) { |
| 1979 | if (otgsc & OTGSC_BSV) |
| 1980 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1981 | else |
| 1982 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 1983 | } else if (pdata->otg_control == OTG_PMIC_CONTROL) { |
| 1984 | /* |
| 1985 | * VBUS initial state is reported after PMIC |
| 1986 | * driver initialization. Wait for it. |
| 1987 | */ |
| 1988 | wait_for_completion(&pmic_vbus_init); |
| 1989 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1990 | break; |
| 1991 | default: |
| 1992 | break; |
| 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | static void msm_otg_sm_work(struct work_struct *w) |
| 1997 | { |
| 1998 | struct msm_otg *motg = container_of(w, struct msm_otg, sm_work); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1999 | struct usb_otg *otg = motg->phy.otg; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2000 | bool work = 0, srp_reqd; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2001 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2002 | pm_runtime_resume(otg->phy->dev); |
| 2003 | pr_debug("%s work\n", otg_state_string(otg->phy->state)); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2004 | switch (otg->phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2005 | case OTG_STATE_UNDEFINED: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2006 | msm_otg_reset(otg->phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2007 | msm_otg_init_sm(motg); |
Vijayavardhan Vennapusa | 05c437c | 2012-05-25 16:20:46 +0530 | [diff] [blame] | 2008 | psy = power_supply_get_by_name("usb"); |
| 2009 | if (!psy) |
| 2010 | pr_err("couldn't get usb power supply\n"); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2011 | otg->phy->state = OTG_STATE_B_IDLE; |
Pavankumar Kondeti | 8a379b4 | 2011-12-12 13:07:23 +0530 | [diff] [blame] | 2012 | if (!test_bit(B_SESS_VLD, &motg->inputs) && |
| 2013 | test_bit(ID, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2014 | pm_runtime_put_noidle(otg->phy->dev); |
| 2015 | pm_runtime_suspend(otg->phy->dev); |
Pavankumar Kondeti | 8a379b4 | 2011-12-12 13:07:23 +0530 | [diff] [blame] | 2016 | break; |
| 2017 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2018 | /* FALL THROUGH */ |
| 2019 | case OTG_STATE_B_IDLE: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2020 | if ((!test_bit(ID, &motg->inputs) || |
| 2021 | test_bit(ID_A, &motg->inputs)) && otg->host) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2022 | pr_debug("!id || id_A\n"); |
| 2023 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2024 | set_bit(A_BUS_REQ, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2025 | otg->phy->state = OTG_STATE_A_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2026 | work = 1; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2027 | } else if (test_bit(B_SESS_VLD, &motg->inputs)) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2028 | pr_debug("b_sess_vld\n"); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2029 | switch (motg->chg_state) { |
| 2030 | case USB_CHG_STATE_UNDEFINED: |
| 2031 | msm_chg_detect_work(&motg->chg_work.work); |
| 2032 | break; |
| 2033 | case USB_CHG_STATE_DETECTED: |
| 2034 | switch (motg->chg_type) { |
| 2035 | case USB_DCP_CHARGER: |
Pavankumar Kondeti | 283146f | 2012-01-12 12:51:19 +0530 | [diff] [blame] | 2036 | /* Enable VDP_SRC */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2037 | ulpi_write(otg->phy, 0x2, 0x85); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2038 | msm_otg_notify_charger(motg, |
| 2039 | IDEV_CHG_MAX); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2040 | pm_runtime_put_noidle(otg->phy->dev); |
| 2041 | pm_runtime_suspend(otg->phy->dev); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2042 | break; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2043 | case USB_ACA_B_CHARGER: |
| 2044 | msm_otg_notify_charger(motg, |
| 2045 | IDEV_ACA_CHG_MAX); |
| 2046 | /* |
| 2047 | * (ID_B --> ID_C) PHY_ALT interrupt can |
| 2048 | * not be detected in LPM. |
| 2049 | */ |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2050 | break; |
| 2051 | case USB_CDP_CHARGER: |
| 2052 | msm_otg_notify_charger(motg, |
| 2053 | IDEV_CHG_MAX); |
| 2054 | msm_otg_start_peripheral(otg, 1); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2055 | otg->phy->state = |
| 2056 | OTG_STATE_B_PERIPHERAL; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2057 | break; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2058 | case USB_ACA_C_CHARGER: |
| 2059 | msm_otg_notify_charger(motg, |
| 2060 | IDEV_ACA_CHG_MAX); |
| 2061 | msm_otg_start_peripheral(otg, 1); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2062 | otg->phy->state = |
| 2063 | OTG_STATE_B_PERIPHERAL; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2064 | break; |
| 2065 | case USB_SDP_CHARGER: |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2066 | msm_otg_start_peripheral(otg, 1); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2067 | otg->phy->state = |
| 2068 | OTG_STATE_B_PERIPHERAL; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2069 | break; |
| 2070 | default: |
| 2071 | break; |
| 2072 | } |
| 2073 | break; |
| 2074 | default: |
| 2075 | break; |
| 2076 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2077 | } else if (test_bit(B_BUS_REQ, &motg->inputs)) { |
| 2078 | pr_debug("b_sess_end && b_bus_req\n"); |
| 2079 | if (msm_otg_start_srp(otg) < 0) { |
| 2080 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2081 | work = 1; |
| 2082 | break; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2083 | } |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2084 | otg->phy->state = OTG_STATE_B_SRP_INIT; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2085 | msm_otg_start_timer(motg, TB_SRP_FAIL, B_SRP_FAIL); |
| 2086 | break; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2087 | } else { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2088 | pr_debug("chg_work cancel"); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2089 | cancel_delayed_work_sync(&motg->chg_work); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2090 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 2091 | motg->chg_type = USB_INVALID_CHARGER; |
Rajkumar Raghupathy | 18fd713 | 2012-04-20 11:28:13 +0530 | [diff] [blame] | 2092 | msm_otg_notify_charger(motg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2093 | msm_otg_reset(otg->phy); |
| 2094 | pm_runtime_put_noidle(otg->phy->dev); |
| 2095 | pm_runtime_suspend(otg->phy->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2096 | } |
| 2097 | break; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2098 | case OTG_STATE_B_SRP_INIT: |
| 2099 | if (!test_bit(ID, &motg->inputs) || |
| 2100 | test_bit(ID_A, &motg->inputs) || |
| 2101 | test_bit(ID_C, &motg->inputs) || |
| 2102 | (test_bit(B_SESS_VLD, &motg->inputs) && |
| 2103 | !test_bit(ID_B, &motg->inputs))) { |
| 2104 | pr_debug("!id || id_a/c || b_sess_vld+!id_b\n"); |
| 2105 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2106 | otg->phy->state = OTG_STATE_B_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2107 | /* |
| 2108 | * clear VBUSVLDEXTSEL and VBUSVLDEXT register |
| 2109 | * bits after SRP initiation. |
| 2110 | */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2111 | ulpi_write(otg->phy, 0x0, 0x98); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2112 | work = 1; |
| 2113 | } else if (test_bit(B_SRP_FAIL, &motg->tmouts)) { |
| 2114 | pr_debug("b_srp_fail\n"); |
| 2115 | pr_info("A-device did not respond to SRP\n"); |
| 2116 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2117 | clear_bit(B_SRP_FAIL, &motg->tmouts); |
| 2118 | otg_send_event(OTG_EVENT_NO_RESP_FOR_SRP); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2119 | ulpi_write(otg->phy, 0x0, 0x98); |
| 2120 | otg->phy->state = OTG_STATE_B_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2121 | motg->b_last_se0_sess = jiffies; |
| 2122 | work = 1; |
| 2123 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2124 | break; |
| 2125 | case OTG_STATE_B_PERIPHERAL: |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2126 | if (!test_bit(ID, &motg->inputs) || |
| 2127 | test_bit(ID_A, &motg->inputs) || |
| 2128 | test_bit(ID_B, &motg->inputs) || |
| 2129 | !test_bit(B_SESS_VLD, &motg->inputs)) { |
| 2130 | pr_debug("!id || id_a/b || !b_sess_vld\n"); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 2131 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 2132 | motg->chg_type = USB_INVALID_CHARGER; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2133 | msm_otg_notify_charger(motg, 0); |
| 2134 | srp_reqd = otg->gadget->otg_srp_reqd; |
| 2135 | msm_otg_start_peripheral(otg, 0); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2136 | if (test_bit(ID_B, &motg->inputs)) |
| 2137 | clear_bit(ID_B, &motg->inputs); |
| 2138 | clear_bit(B_BUS_REQ, &motg->inputs); |
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 | motg->b_last_se0_sess = jiffies; |
| 2141 | if (srp_reqd) |
| 2142 | msm_otg_start_timer(motg, |
| 2143 | TB_TST_SRP, B_TST_SRP); |
| 2144 | else |
| 2145 | work = 1; |
| 2146 | } else if (test_bit(B_BUS_REQ, &motg->inputs) && |
| 2147 | otg->gadget->b_hnp_enable && |
| 2148 | test_bit(A_BUS_SUSPEND, &motg->inputs)) { |
| 2149 | pr_debug("b_bus_req && b_hnp_en && a_bus_suspend\n"); |
| 2150 | msm_otg_start_timer(motg, TB_ASE0_BRST, B_ASE0_BRST); |
| 2151 | /* D+ pullup should not be disconnected within 4msec |
| 2152 | * after A device suspends the bus. Otherwise PET will |
| 2153 | * fail the compliance test. |
| 2154 | */ |
| 2155 | udelay(1000); |
| 2156 | msm_otg_start_peripheral(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2157 | otg->phy->state = OTG_STATE_B_WAIT_ACON; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2158 | /* |
| 2159 | * start HCD even before A-device enable |
| 2160 | * pull-up to meet HNP timings. |
| 2161 | */ |
| 2162 | otg->host->is_b_host = 1; |
| 2163 | msm_otg_start_host(otg, 1); |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 2164 | } else if (test_bit(A_BUS_SUSPEND, &motg->inputs) && |
| 2165 | test_bit(B_SESS_VLD, &motg->inputs)) { |
| 2166 | pr_debug("a_bus_suspend && b_sess_vld\n"); |
| 2167 | if (motg->caps & ALLOW_LPM_ON_DEV_SUSPEND) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2168 | pm_runtime_put_noidle(otg->phy->dev); |
| 2169 | pm_runtime_suspend(otg->phy->dev); |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 2170 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2171 | } else if (test_bit(ID_C, &motg->inputs)) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2172 | msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2173 | } |
| 2174 | break; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2175 | case OTG_STATE_B_WAIT_ACON: |
| 2176 | if (!test_bit(ID, &motg->inputs) || |
| 2177 | test_bit(ID_A, &motg->inputs) || |
| 2178 | test_bit(ID_B, &motg->inputs) || |
| 2179 | !test_bit(B_SESS_VLD, &motg->inputs)) { |
| 2180 | pr_debug("!id || id_a/b || !b_sess_vld\n"); |
| 2181 | msm_otg_del_timer(motg); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2182 | /* |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2183 | * A-device is physically disconnected during |
| 2184 | * HNP. Remove HCD. |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2185 | */ |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2186 | msm_otg_start_host(otg, 0); |
| 2187 | otg->host->is_b_host = 0; |
| 2188 | |
| 2189 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2190 | clear_bit(A_BUS_SUSPEND, &motg->inputs); |
| 2191 | motg->b_last_se0_sess = jiffies; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2192 | otg->phy->state = OTG_STATE_B_IDLE; |
| 2193 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2194 | work = 1; |
| 2195 | } else if (test_bit(A_CONN, &motg->inputs)) { |
| 2196 | pr_debug("a_conn\n"); |
| 2197 | clear_bit(A_BUS_SUSPEND, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2198 | otg->phy->state = OTG_STATE_B_HOST; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2199 | /* |
| 2200 | * PET disconnects D+ pullup after reset is generated |
| 2201 | * by B device in B_HOST role which is not detected by |
| 2202 | * B device. As workaorund , start timer of 300msec |
| 2203 | * and stop timer if A device is enumerated else clear |
| 2204 | * A_CONN. |
| 2205 | */ |
| 2206 | msm_otg_start_timer(motg, TB_TST_CONFIG, |
| 2207 | B_TST_CONFIG); |
| 2208 | } else if (test_bit(B_ASE0_BRST, &motg->tmouts)) { |
| 2209 | pr_debug("b_ase0_brst_tmout\n"); |
| 2210 | pr_info("B HNP fail:No response from A device\n"); |
| 2211 | msm_otg_start_host(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2212 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2213 | otg->host->is_b_host = 0; |
| 2214 | clear_bit(B_ASE0_BRST, &motg->tmouts); |
| 2215 | clear_bit(A_BUS_SUSPEND, &motg->inputs); |
| 2216 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2217 | otg_send_event(OTG_EVENT_HNP_FAILED); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2218 | otg->phy->state = OTG_STATE_B_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2219 | work = 1; |
| 2220 | } else if (test_bit(ID_C, &motg->inputs)) { |
| 2221 | msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX); |
| 2222 | } |
| 2223 | break; |
| 2224 | case OTG_STATE_B_HOST: |
| 2225 | if (!test_bit(B_BUS_REQ, &motg->inputs) || |
| 2226 | !test_bit(A_CONN, &motg->inputs) || |
| 2227 | !test_bit(B_SESS_VLD, &motg->inputs)) { |
| 2228 | pr_debug("!b_bus_req || !a_conn || !b_sess_vld\n"); |
| 2229 | clear_bit(A_CONN, &motg->inputs); |
| 2230 | clear_bit(B_BUS_REQ, &motg->inputs); |
| 2231 | msm_otg_start_host(otg, 0); |
| 2232 | otg->host->is_b_host = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2233 | otg->phy->state = OTG_STATE_B_IDLE; |
| 2234 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2235 | work = 1; |
| 2236 | } else if (test_bit(ID_C, &motg->inputs)) { |
| 2237 | msm_otg_notify_charger(motg, IDEV_ACA_CHG_MAX); |
| 2238 | } |
| 2239 | break; |
| 2240 | case OTG_STATE_A_IDLE: |
| 2241 | otg->default_a = 1; |
| 2242 | if (test_bit(ID, &motg->inputs) && |
| 2243 | !test_bit(ID_A, &motg->inputs)) { |
| 2244 | pr_debug("id && !id_a\n"); |
| 2245 | otg->default_a = 0; |
| 2246 | clear_bit(A_BUS_DROP, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2247 | otg->phy->state = OTG_STATE_B_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2248 | del_timer_sync(&motg->id_timer); |
| 2249 | msm_otg_link_reset(motg); |
| 2250 | msm_chg_enable_aca_intr(motg); |
| 2251 | msm_otg_notify_charger(motg, 0); |
| 2252 | work = 1; |
| 2253 | } else if (!test_bit(A_BUS_DROP, &motg->inputs) && |
| 2254 | (test_bit(A_SRP_DET, &motg->inputs) || |
| 2255 | test_bit(A_BUS_REQ, &motg->inputs))) { |
| 2256 | pr_debug("!a_bus_drop && (a_srp_det || a_bus_req)\n"); |
| 2257 | |
| 2258 | clear_bit(A_SRP_DET, &motg->inputs); |
| 2259 | /* Disable SRP detection */ |
| 2260 | writel_relaxed((readl_relaxed(USB_OTGSC) & |
| 2261 | ~OTGSC_INTSTS_MASK) & |
| 2262 | ~OTGSC_DPIE, USB_OTGSC); |
| 2263 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2264 | otg->phy->state = OTG_STATE_A_WAIT_VRISE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2265 | /* VBUS should not be supplied before end of SRP pulse |
| 2266 | * generated by PET, if not complaince test fail. |
| 2267 | */ |
| 2268 | usleep_range(10000, 12000); |
| 2269 | /* ACA: ID_A: Stop charging untill enumeration */ |
| 2270 | if (test_bit(ID_A, &motg->inputs)) |
| 2271 | msm_otg_notify_charger(motg, 0); |
| 2272 | else |
| 2273 | msm_hsusb_vbus_power(motg, 1); |
| 2274 | msm_otg_start_timer(motg, TA_WAIT_VRISE, A_WAIT_VRISE); |
| 2275 | } else { |
| 2276 | pr_debug("No session requested\n"); |
| 2277 | clear_bit(A_BUS_DROP, &motg->inputs); |
| 2278 | if (test_bit(ID_A, &motg->inputs)) { |
| 2279 | msm_otg_notify_charger(motg, |
| 2280 | IDEV_ACA_CHG_MAX); |
| 2281 | } else if (!test_bit(ID, &motg->inputs)) { |
| 2282 | msm_otg_notify_charger(motg, 0); |
| 2283 | /* |
| 2284 | * A-device is not providing power on VBUS. |
| 2285 | * Enable SRP detection. |
| 2286 | */ |
| 2287 | writel_relaxed(0x13, USB_USBMODE); |
| 2288 | writel_relaxed((readl_relaxed(USB_OTGSC) & |
| 2289 | ~OTGSC_INTSTS_MASK) | |
| 2290 | OTGSC_DPIE, USB_OTGSC); |
| 2291 | mb(); |
| 2292 | } |
| 2293 | } |
| 2294 | break; |
| 2295 | case OTG_STATE_A_WAIT_VRISE: |
| 2296 | if ((test_bit(ID, &motg->inputs) && |
| 2297 | !test_bit(ID_A, &motg->inputs)) || |
| 2298 | test_bit(A_BUS_DROP, &motg->inputs) || |
| 2299 | test_bit(A_WAIT_VRISE, &motg->tmouts)) { |
| 2300 | pr_debug("id || a_bus_drop || a_wait_vrise_tmout\n"); |
| 2301 | clear_bit(A_BUS_REQ, &motg->inputs); |
| 2302 | msm_otg_del_timer(motg); |
| 2303 | msm_hsusb_vbus_power(motg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2304 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2305 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2306 | } else if (test_bit(A_VBUS_VLD, &motg->inputs)) { |
| 2307 | pr_debug("a_vbus_vld\n"); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2308 | otg->phy->state = OTG_STATE_A_WAIT_BCON; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2309 | if (TA_WAIT_BCON > 0) |
| 2310 | msm_otg_start_timer(motg, TA_WAIT_BCON, |
| 2311 | A_WAIT_BCON); |
| 2312 | msm_otg_start_host(otg, 1); |
| 2313 | msm_chg_enable_aca_det(motg); |
| 2314 | msm_chg_disable_aca_intr(motg); |
Chiranjeevi Velempati | 489a27c | 2012-03-29 09:47:17 +0530 | [diff] [blame] | 2315 | mod_timer(&motg->id_timer, ID_TIMER_FREQ); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2316 | if (msm_chg_check_aca_intr(motg)) |
| 2317 | work = 1; |
| 2318 | } |
| 2319 | break; |
| 2320 | case OTG_STATE_A_WAIT_BCON: |
| 2321 | if ((test_bit(ID, &motg->inputs) && |
| 2322 | !test_bit(ID_A, &motg->inputs)) || |
| 2323 | test_bit(A_BUS_DROP, &motg->inputs) || |
| 2324 | test_bit(A_WAIT_BCON, &motg->tmouts)) { |
| 2325 | pr_debug("(id && id_a/b/c) || a_bus_drop ||" |
| 2326 | "a_wait_bcon_tmout\n"); |
| 2327 | if (test_bit(A_WAIT_BCON, &motg->tmouts)) { |
| 2328 | pr_info("Device No Response\n"); |
| 2329 | otg_send_event(OTG_EVENT_DEV_CONN_TMOUT); |
| 2330 | } |
| 2331 | msm_otg_del_timer(motg); |
| 2332 | clear_bit(A_BUS_REQ, &motg->inputs); |
| 2333 | clear_bit(B_CONN, &motg->inputs); |
| 2334 | msm_otg_start_host(otg, 0); |
| 2335 | /* |
| 2336 | * ACA: ID_A with NO accessory, just the A plug is |
| 2337 | * attached to ACA: Use IDCHG_MAX for charging |
| 2338 | */ |
| 2339 | if (test_bit(ID_A, &motg->inputs)) |
| 2340 | msm_otg_notify_charger(motg, IDEV_CHG_MIN); |
| 2341 | else |
| 2342 | msm_hsusb_vbus_power(motg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2343 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2344 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2345 | } else if (!test_bit(A_VBUS_VLD, &motg->inputs)) { |
| 2346 | pr_debug("!a_vbus_vld\n"); |
| 2347 | clear_bit(B_CONN, &motg->inputs); |
| 2348 | msm_otg_del_timer(motg); |
| 2349 | msm_otg_start_host(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2350 | otg->phy->state = OTG_STATE_A_VBUS_ERR; |
| 2351 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2352 | } else if (test_bit(ID_A, &motg->inputs)) { |
| 2353 | msm_hsusb_vbus_power(motg, 0); |
| 2354 | } else if (!test_bit(A_BUS_REQ, &motg->inputs)) { |
| 2355 | /* |
| 2356 | * If TA_WAIT_BCON is infinite, we don;t |
| 2357 | * turn off VBUS. Enter low power mode. |
| 2358 | */ |
| 2359 | if (TA_WAIT_BCON < 0) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2360 | pm_runtime_put_sync(otg->phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2361 | } else if (!test_bit(ID, &motg->inputs)) { |
| 2362 | msm_hsusb_vbus_power(motg, 1); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2363 | } |
| 2364 | break; |
| 2365 | case OTG_STATE_A_HOST: |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2366 | if ((test_bit(ID, &motg->inputs) && |
| 2367 | !test_bit(ID_A, &motg->inputs)) || |
| 2368 | test_bit(A_BUS_DROP, &motg->inputs)) { |
| 2369 | pr_debug("id_a/b/c || a_bus_drop\n"); |
| 2370 | clear_bit(B_CONN, &motg->inputs); |
| 2371 | clear_bit(A_BUS_REQ, &motg->inputs); |
| 2372 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2373 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2374 | msm_otg_start_host(otg, 0); |
| 2375 | if (!test_bit(ID_A, &motg->inputs)) |
| 2376 | msm_hsusb_vbus_power(motg, 0); |
| 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); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2382 | otg->phy->state = OTG_STATE_A_VBUS_ERR; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2383 | msm_otg_start_host(otg, 0); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 2384 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2385 | } else if (!test_bit(A_BUS_REQ, &motg->inputs)) { |
| 2386 | /* |
| 2387 | * a_bus_req is de-asserted when root hub is |
| 2388 | * suspended or HNP is in progress. |
| 2389 | */ |
| 2390 | pr_debug("!a_bus_req\n"); |
| 2391 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2392 | otg->phy->state = OTG_STATE_A_SUSPEND; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2393 | if (otg->host->b_hnp_enable) |
| 2394 | msm_otg_start_timer(motg, TA_AIDL_BDIS, |
| 2395 | A_AIDL_BDIS); |
| 2396 | else |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2397 | pm_runtime_put_sync(otg->phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2398 | } else if (!test_bit(B_CONN, &motg->inputs)) { |
| 2399 | pr_debug("!b_conn\n"); |
| 2400 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2401 | otg->phy->state = OTG_STATE_A_WAIT_BCON; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2402 | if (TA_WAIT_BCON > 0) |
| 2403 | msm_otg_start_timer(motg, TA_WAIT_BCON, |
| 2404 | A_WAIT_BCON); |
| 2405 | if (msm_chg_check_aca_intr(motg)) |
| 2406 | work = 1; |
| 2407 | } else if (test_bit(ID_A, &motg->inputs)) { |
| 2408 | msm_otg_del_timer(motg); |
| 2409 | msm_hsusb_vbus_power(motg, 0); |
| 2410 | if (motg->chg_type == USB_ACA_DOCK_CHARGER) |
| 2411 | msm_otg_notify_charger(motg, |
| 2412 | IDEV_ACA_CHG_MAX); |
| 2413 | else |
| 2414 | msm_otg_notify_charger(motg, |
| 2415 | IDEV_CHG_MIN - motg->mA_port); |
| 2416 | } else if (!test_bit(ID, &motg->inputs)) { |
| 2417 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 2418 | motg->chg_type = USB_INVALID_CHARGER; |
| 2419 | msm_otg_notify_charger(motg, 0); |
| 2420 | msm_hsusb_vbus_power(motg, 1); |
| 2421 | } |
| 2422 | break; |
| 2423 | case OTG_STATE_A_SUSPEND: |
| 2424 | if ((test_bit(ID, &motg->inputs) && |
| 2425 | !test_bit(ID_A, &motg->inputs)) || |
| 2426 | test_bit(A_BUS_DROP, &motg->inputs) || |
| 2427 | test_bit(A_AIDL_BDIS, &motg->tmouts)) { |
| 2428 | pr_debug("id_a/b/c || a_bus_drop ||" |
| 2429 | "a_aidl_bdis_tmout\n"); |
| 2430 | msm_otg_del_timer(motg); |
| 2431 | clear_bit(B_CONN, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2432 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2433 | msm_otg_start_host(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2434 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2435 | if (!test_bit(ID_A, &motg->inputs)) |
| 2436 | msm_hsusb_vbus_power(motg, 0); |
| 2437 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2438 | } else if (!test_bit(A_VBUS_VLD, &motg->inputs)) { |
| 2439 | pr_debug("!a_vbus_vld\n"); |
| 2440 | msm_otg_del_timer(motg); |
| 2441 | clear_bit(B_CONN, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2442 | otg->phy->state = OTG_STATE_A_VBUS_ERR; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2443 | msm_otg_start_host(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2444 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2445 | } else if (!test_bit(B_CONN, &motg->inputs) && |
| 2446 | otg->host->b_hnp_enable) { |
| 2447 | pr_debug("!b_conn && b_hnp_enable"); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2448 | otg->phy->state = OTG_STATE_A_PERIPHERAL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2449 | msm_otg_host_hnp_enable(otg, 1); |
| 2450 | otg->gadget->is_a_peripheral = 1; |
| 2451 | msm_otg_start_peripheral(otg, 1); |
| 2452 | } else if (!test_bit(B_CONN, &motg->inputs) && |
| 2453 | !otg->host->b_hnp_enable) { |
| 2454 | pr_debug("!b_conn && !b_hnp_enable"); |
| 2455 | /* |
| 2456 | * bus request is dropped during suspend. |
| 2457 | * acquire again for next device. |
| 2458 | */ |
| 2459 | set_bit(A_BUS_REQ, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2460 | otg->phy->state = OTG_STATE_A_WAIT_BCON; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2461 | if (TA_WAIT_BCON > 0) |
| 2462 | msm_otg_start_timer(motg, TA_WAIT_BCON, |
| 2463 | A_WAIT_BCON); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2464 | } else if (test_bit(ID_A, &motg->inputs)) { |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 2465 | msm_hsusb_vbus_power(motg, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2466 | msm_otg_notify_charger(motg, |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2467 | IDEV_CHG_MIN - motg->mA_port); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2468 | } else if (!test_bit(ID, &motg->inputs)) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2469 | msm_otg_notify_charger(motg, 0); |
Mayank Rana | e392688 | 2011-12-26 09:47:54 +0530 | [diff] [blame] | 2470 | msm_hsusb_vbus_power(motg, 1); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2471 | } |
| 2472 | break; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2473 | case OTG_STATE_A_PERIPHERAL: |
| 2474 | if ((test_bit(ID, &motg->inputs) && |
| 2475 | !test_bit(ID_A, &motg->inputs)) || |
| 2476 | test_bit(A_BUS_DROP, &motg->inputs)) { |
| 2477 | pr_debug("id _f/b/c || a_bus_drop\n"); |
| 2478 | /* Clear BIDL_ADIS timer */ |
| 2479 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2480 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2481 | msm_otg_start_peripheral(otg, 0); |
| 2482 | otg->gadget->is_a_peripheral = 0; |
| 2483 | msm_otg_start_host(otg, 0); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2484 | msm_otg_reset(otg->phy); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2485 | if (!test_bit(ID_A, &motg->inputs)) |
| 2486 | msm_hsusb_vbus_power(motg, 0); |
| 2487 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2488 | } else if (!test_bit(A_VBUS_VLD, &motg->inputs)) { |
| 2489 | pr_debug("!a_vbus_vld\n"); |
| 2490 | /* Clear BIDL_ADIS timer */ |
| 2491 | msm_otg_del_timer(motg); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2492 | otg->phy->state = OTG_STATE_A_VBUS_ERR; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2493 | msm_otg_start_peripheral(otg, 0); |
| 2494 | otg->gadget->is_a_peripheral = 0; |
| 2495 | msm_otg_start_host(otg, 0); |
| 2496 | } else if (test_bit(A_BIDL_ADIS, &motg->tmouts)) { |
| 2497 | pr_debug("a_bidl_adis_tmout\n"); |
| 2498 | msm_otg_start_peripheral(otg, 0); |
| 2499 | otg->gadget->is_a_peripheral = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2500 | otg->phy->state = OTG_STATE_A_WAIT_BCON; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2501 | set_bit(A_BUS_REQ, &motg->inputs); |
| 2502 | msm_otg_host_hnp_enable(otg, 0); |
| 2503 | if (TA_WAIT_BCON > 0) |
| 2504 | msm_otg_start_timer(motg, TA_WAIT_BCON, |
| 2505 | A_WAIT_BCON); |
| 2506 | } else if (test_bit(ID_A, &motg->inputs)) { |
| 2507 | msm_hsusb_vbus_power(motg, 0); |
| 2508 | msm_otg_notify_charger(motg, |
| 2509 | IDEV_CHG_MIN - motg->mA_port); |
| 2510 | } else if (!test_bit(ID, &motg->inputs)) { |
| 2511 | msm_otg_notify_charger(motg, 0); |
| 2512 | msm_hsusb_vbus_power(motg, 1); |
| 2513 | } |
| 2514 | break; |
| 2515 | case OTG_STATE_A_WAIT_VFALL: |
| 2516 | if (test_bit(A_WAIT_VFALL, &motg->tmouts)) { |
| 2517 | clear_bit(A_VBUS_VLD, &motg->inputs); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2518 | otg->phy->state = OTG_STATE_A_IDLE; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2519 | work = 1; |
| 2520 | } |
| 2521 | break; |
| 2522 | case OTG_STATE_A_VBUS_ERR: |
| 2523 | if ((test_bit(ID, &motg->inputs) && |
| 2524 | !test_bit(ID_A, &motg->inputs)) || |
| 2525 | test_bit(A_BUS_DROP, &motg->inputs) || |
| 2526 | test_bit(A_CLR_ERR, &motg->inputs)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2527 | otg->phy->state = OTG_STATE_A_WAIT_VFALL; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2528 | if (!test_bit(ID_A, &motg->inputs)) |
| 2529 | msm_hsusb_vbus_power(motg, 0); |
| 2530 | msm_otg_start_timer(motg, TA_WAIT_VFALL, A_WAIT_VFALL); |
| 2531 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 2532 | motg->chg_type = USB_INVALID_CHARGER; |
| 2533 | msm_otg_notify_charger(motg, 0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2534 | } |
| 2535 | break; |
| 2536 | default: |
| 2537 | break; |
| 2538 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2539 | if (work) |
| 2540 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | static irqreturn_t msm_otg_irq(int irq, void *data) |
| 2544 | { |
| 2545 | struct msm_otg *motg = data; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2546 | struct usb_otg *otg = motg->phy.otg; |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2547 | u32 otgsc = 0, usbsts, pc; |
| 2548 | bool work = 0; |
| 2549 | irqreturn_t ret = IRQ_HANDLED; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2550 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2551 | if (atomic_read(&motg->in_lpm)) { |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2552 | pr_debug("OTG IRQ: in LPM\n"); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2553 | disable_irq_nosync(irq); |
| 2554 | motg->async_int = 1; |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 2555 | if (atomic_read(&motg->pm_suspended)) |
| 2556 | motg->sm_work_pending = true; |
| 2557 | else |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2558 | pm_request_resume(otg->phy->dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 2559 | return IRQ_HANDLED; |
| 2560 | } |
| 2561 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2562 | usbsts = readl(USB_USBSTS); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2563 | otgsc = readl(USB_OTGSC); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2564 | |
| 2565 | if (!(otgsc & OTG_OTGSTS_MASK) && !(usbsts & OTG_USBSTS_MASK)) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2566 | return IRQ_NONE; |
| 2567 | |
| 2568 | if ((otgsc & OTGSC_IDIS) && (otgsc & OTGSC_IDIE)) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2569 | if (otgsc & OTGSC_ID) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2570 | pr_debug("Id set\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2571 | set_bit(ID, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2572 | } else { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2573 | pr_debug("Id clear\n"); |
| 2574 | /* |
| 2575 | * Assert a_bus_req to supply power on |
| 2576 | * VBUS when Micro/Mini-A cable is connected |
| 2577 | * with out user intervention. |
| 2578 | */ |
| 2579 | set_bit(A_BUS_REQ, &motg->inputs); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2580 | clear_bit(ID, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2581 | msm_chg_enable_aca_det(motg); |
| 2582 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2583 | writel_relaxed(otgsc, USB_OTGSC); |
| 2584 | work = 1; |
| 2585 | } else if (otgsc & OTGSC_DPIS) { |
| 2586 | pr_debug("DPIS detected\n"); |
| 2587 | writel_relaxed(otgsc, USB_OTGSC); |
| 2588 | set_bit(A_SRP_DET, &motg->inputs); |
| 2589 | set_bit(A_BUS_REQ, &motg->inputs); |
| 2590 | work = 1; |
| 2591 | } else if (otgsc & OTGSC_BSVIS) { |
| 2592 | writel_relaxed(otgsc, USB_OTGSC); |
| 2593 | /* |
| 2594 | * BSV interrupt comes when operating as an A-device |
| 2595 | * (VBUS on/off). |
| 2596 | * But, handle BSV when charger is removed from ACA in ID_A |
| 2597 | */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2598 | if ((otg->phy->state >= OTG_STATE_A_IDLE) && |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2599 | !test_bit(ID_A, &motg->inputs)) |
| 2600 | return IRQ_HANDLED; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2601 | if (otgsc & OTGSC_BSV) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2602 | pr_debug("BSV set\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2603 | set_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2604 | } else { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2605 | pr_debug("BSV clear\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2606 | clear_bit(B_SESS_VLD, &motg->inputs); |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 2607 | clear_bit(A_BUS_SUSPEND, &motg->inputs); |
| 2608 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2609 | msm_chg_check_aca_intr(motg); |
| 2610 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2611 | work = 1; |
| 2612 | } else if (usbsts & STS_PCI) { |
| 2613 | pc = readl_relaxed(USB_PORTSC); |
| 2614 | pr_debug("portsc = %x\n", pc); |
| 2615 | ret = IRQ_NONE; |
| 2616 | /* |
| 2617 | * HCD Acks PCI interrupt. We use this to switch |
| 2618 | * between different OTG states. |
| 2619 | */ |
| 2620 | work = 1; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2621 | switch (otg->phy->state) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2622 | case OTG_STATE_A_SUSPEND: |
| 2623 | if (otg->host->b_hnp_enable && (pc & PORTSC_CSC) && |
| 2624 | !(pc & PORTSC_CCS)) { |
| 2625 | pr_debug("B_CONN clear\n"); |
| 2626 | clear_bit(B_CONN, &motg->inputs); |
| 2627 | msm_otg_del_timer(motg); |
| 2628 | } |
| 2629 | break; |
| 2630 | case OTG_STATE_A_PERIPHERAL: |
| 2631 | /* |
| 2632 | * A-peripheral observed activity on bus. |
| 2633 | * clear A_BIDL_ADIS timer. |
| 2634 | */ |
| 2635 | msm_otg_del_timer(motg); |
| 2636 | work = 0; |
| 2637 | break; |
| 2638 | case OTG_STATE_B_WAIT_ACON: |
| 2639 | if ((pc & PORTSC_CSC) && (pc & PORTSC_CCS)) { |
| 2640 | pr_debug("A_CONN set\n"); |
| 2641 | set_bit(A_CONN, &motg->inputs); |
| 2642 | /* Clear ASE0_BRST timer */ |
| 2643 | msm_otg_del_timer(motg); |
| 2644 | } |
| 2645 | break; |
| 2646 | case OTG_STATE_B_HOST: |
| 2647 | if ((pc & PORTSC_CSC) && !(pc & PORTSC_CCS)) { |
| 2648 | pr_debug("A_CONN clear\n"); |
| 2649 | clear_bit(A_CONN, &motg->inputs); |
| 2650 | msm_otg_del_timer(motg); |
| 2651 | } |
| 2652 | break; |
| 2653 | case OTG_STATE_A_WAIT_BCON: |
| 2654 | if (TA_WAIT_BCON < 0) |
| 2655 | set_bit(A_BUS_REQ, &motg->inputs); |
| 2656 | default: |
| 2657 | work = 0; |
| 2658 | break; |
| 2659 | } |
| 2660 | } else if (usbsts & STS_URI) { |
| 2661 | ret = IRQ_NONE; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2662 | switch (otg->phy->state) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 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 | default: |
| 2672 | work = 0; |
| 2673 | break; |
| 2674 | } |
| 2675 | } else if (usbsts & STS_SLI) { |
| 2676 | ret = IRQ_NONE; |
| 2677 | work = 0; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2678 | switch (otg->phy->state) { |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2679 | case OTG_STATE_B_PERIPHERAL: |
| 2680 | if (otg->gadget->b_hnp_enable) { |
| 2681 | set_bit(A_BUS_SUSPEND, &motg->inputs); |
| 2682 | set_bit(B_BUS_REQ, &motg->inputs); |
| 2683 | work = 1; |
| 2684 | } |
| 2685 | break; |
| 2686 | case OTG_STATE_A_PERIPHERAL: |
| 2687 | msm_otg_start_timer(motg, TA_BIDL_ADIS, |
| 2688 | A_BIDL_ADIS); |
| 2689 | break; |
| 2690 | default: |
| 2691 | break; |
| 2692 | } |
| 2693 | } else if ((usbsts & PHY_ALT_INT)) { |
| 2694 | writel_relaxed(PHY_ALT_INT, USB_USBSTS); |
| 2695 | if (msm_chg_check_aca_intr(motg)) |
| 2696 | work = 1; |
| 2697 | ret = IRQ_HANDLED; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2698 | } |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2699 | if (work) |
| 2700 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2701 | |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2702 | return ret; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | static void msm_otg_set_vbus_state(int online) |
| 2706 | { |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2707 | static bool init; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2708 | struct msm_otg *motg = the_msm_otg; |
| 2709 | |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2710 | if (online) { |
| 2711 | pr_debug("PMIC: BSV set\n"); |
| 2712 | set_bit(B_SESS_VLD, &motg->inputs); |
| 2713 | } else { |
| 2714 | pr_debug("PMIC: BSV clear\n"); |
| 2715 | clear_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2716 | } |
| 2717 | |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2718 | if (!init) { |
| 2719 | init = true; |
| 2720 | complete(&pmic_vbus_init); |
| 2721 | pr_debug("PMIC: BSV init complete\n"); |
| 2722 | return; |
| 2723 | } |
| 2724 | |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 2725 | if (atomic_read(&motg->pm_suspended)) |
| 2726 | motg->sm_work_pending = true; |
| 2727 | else |
| 2728 | queue_work(system_nrt_wq, &motg->sm_work); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | static irqreturn_t msm_pmic_id_irq(int irq, void *data) |
| 2732 | { |
| 2733 | struct msm_otg *motg = data; |
| 2734 | |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2735 | if (aca_id_turned_on) |
| 2736 | return IRQ_HANDLED; |
| 2737 | |
| 2738 | if (irq_read_line(motg->pdata->pmic_id_irq)) { |
| 2739 | pr_debug("PMIC: ID set\n"); |
| 2740 | set_bit(ID, &motg->inputs); |
| 2741 | } else { |
| 2742 | pr_debug("PMIC: ID clear\n"); |
| 2743 | clear_bit(ID, &motg->inputs); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2744 | set_bit(A_BUS_REQ, &motg->inputs); |
Pavankumar Kondeti | 4960f31 | 2011-12-06 15:46:14 +0530 | [diff] [blame] | 2745 | } |
| 2746 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2747 | if (motg->phy.state != OTG_STATE_UNDEFINED) { |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 2748 | if (atomic_read(&motg->pm_suspended)) |
| 2749 | motg->sm_work_pending = true; |
| 2750 | else |
| 2751 | queue_work(system_nrt_wq, &motg->sm_work); |
| 2752 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2753 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2754 | return IRQ_HANDLED; |
| 2755 | } |
| 2756 | |
| 2757 | static int msm_otg_mode_show(struct seq_file *s, void *unused) |
| 2758 | { |
| 2759 | struct msm_otg *motg = s->private; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2760 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2761 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2762 | switch (phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2763 | case OTG_STATE_A_HOST: |
| 2764 | seq_printf(s, "host\n"); |
| 2765 | break; |
| 2766 | case OTG_STATE_B_PERIPHERAL: |
| 2767 | seq_printf(s, "peripheral\n"); |
| 2768 | break; |
| 2769 | default: |
| 2770 | seq_printf(s, "none\n"); |
| 2771 | break; |
| 2772 | } |
| 2773 | |
| 2774 | return 0; |
| 2775 | } |
| 2776 | |
| 2777 | static int msm_otg_mode_open(struct inode *inode, struct file *file) |
| 2778 | { |
| 2779 | return single_open(file, msm_otg_mode_show, inode->i_private); |
| 2780 | } |
| 2781 | |
| 2782 | static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, |
| 2783 | size_t count, loff_t *ppos) |
| 2784 | { |
Pavankumar Kondeti | e2904ee | 2011-02-15 09:42:35 +0530 | [diff] [blame] | 2785 | struct seq_file *s = file->private_data; |
| 2786 | struct msm_otg *motg = s->private; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2787 | char buf[16]; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2788 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2789 | int status = count; |
| 2790 | enum usb_mode_type req_mode; |
| 2791 | |
| 2792 | memset(buf, 0x00, sizeof(buf)); |
| 2793 | |
| 2794 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) { |
| 2795 | status = -EFAULT; |
| 2796 | goto out; |
| 2797 | } |
| 2798 | |
| 2799 | if (!strncmp(buf, "host", 4)) { |
| 2800 | req_mode = USB_HOST; |
| 2801 | } else if (!strncmp(buf, "peripheral", 10)) { |
| 2802 | req_mode = USB_PERIPHERAL; |
| 2803 | } else if (!strncmp(buf, "none", 4)) { |
| 2804 | req_mode = USB_NONE; |
| 2805 | } else { |
| 2806 | status = -EINVAL; |
| 2807 | goto out; |
| 2808 | } |
| 2809 | |
| 2810 | switch (req_mode) { |
| 2811 | case USB_NONE: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2812 | switch (phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2813 | case OTG_STATE_A_HOST: |
| 2814 | case OTG_STATE_B_PERIPHERAL: |
| 2815 | set_bit(ID, &motg->inputs); |
| 2816 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 2817 | break; |
| 2818 | default: |
| 2819 | goto out; |
| 2820 | } |
| 2821 | break; |
| 2822 | case USB_PERIPHERAL: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2823 | switch (phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2824 | case OTG_STATE_B_IDLE: |
| 2825 | case OTG_STATE_A_HOST: |
| 2826 | set_bit(ID, &motg->inputs); |
| 2827 | set_bit(B_SESS_VLD, &motg->inputs); |
| 2828 | break; |
| 2829 | default: |
| 2830 | goto out; |
| 2831 | } |
| 2832 | break; |
| 2833 | case USB_HOST: |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2834 | switch (phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2835 | case OTG_STATE_B_IDLE: |
| 2836 | case OTG_STATE_B_PERIPHERAL: |
| 2837 | clear_bit(ID, &motg->inputs); |
| 2838 | break; |
| 2839 | default: |
| 2840 | goto out; |
| 2841 | } |
| 2842 | break; |
| 2843 | default: |
| 2844 | goto out; |
| 2845 | } |
| 2846 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2847 | pm_runtime_resume(phy->dev); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 2848 | queue_work(system_nrt_wq, &motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2849 | out: |
| 2850 | return status; |
| 2851 | } |
| 2852 | |
| 2853 | const struct file_operations msm_otg_mode_fops = { |
| 2854 | .open = msm_otg_mode_open, |
| 2855 | .read = seq_read, |
| 2856 | .write = msm_otg_mode_write, |
| 2857 | .llseek = seq_lseek, |
| 2858 | .release = single_release, |
| 2859 | }; |
| 2860 | |
Chiranjeevi Velempati | f9a1154 | 2012-03-28 18:18:34 +0530 | [diff] [blame] | 2861 | static int msm_otg_show_otg_state(struct seq_file *s, void *unused) |
| 2862 | { |
| 2863 | struct msm_otg *motg = s->private; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2864 | struct usb_phy *phy = &motg->phy; |
Chiranjeevi Velempati | f9a1154 | 2012-03-28 18:18:34 +0530 | [diff] [blame] | 2865 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2866 | seq_printf(s, "%s\n", otg_state_string(phy->state)); |
Chiranjeevi Velempati | f9a1154 | 2012-03-28 18:18:34 +0530 | [diff] [blame] | 2867 | return 0; |
| 2868 | } |
| 2869 | |
| 2870 | static int msm_otg_otg_state_open(struct inode *inode, struct file *file) |
| 2871 | { |
| 2872 | return single_open(file, msm_otg_show_otg_state, inode->i_private); |
| 2873 | } |
| 2874 | |
| 2875 | const struct file_operations msm_otg_state_fops = { |
| 2876 | .open = msm_otg_otg_state_open, |
| 2877 | .read = seq_read, |
| 2878 | .llseek = seq_lseek, |
| 2879 | .release = single_release, |
| 2880 | }; |
| 2881 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 2882 | static int msm_otg_show_chg_type(struct seq_file *s, void *unused) |
| 2883 | { |
| 2884 | struct msm_otg *motg = s->private; |
| 2885 | |
Pavankumar Kondeti | 9ef69cb | 2011-12-12 14:18:22 +0530 | [diff] [blame] | 2886 | seq_printf(s, "%s\n", chg_to_string(motg->chg_type)); |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 2887 | return 0; |
| 2888 | } |
| 2889 | |
| 2890 | static int msm_otg_chg_open(struct inode *inode, struct file *file) |
| 2891 | { |
| 2892 | return single_open(file, msm_otg_show_chg_type, inode->i_private); |
| 2893 | } |
| 2894 | |
| 2895 | const struct file_operations msm_otg_chg_fops = { |
| 2896 | .open = msm_otg_chg_open, |
| 2897 | .read = seq_read, |
| 2898 | .llseek = seq_lseek, |
| 2899 | .release = single_release, |
| 2900 | }; |
| 2901 | |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 2902 | static int msm_otg_aca_show(struct seq_file *s, void *unused) |
| 2903 | { |
| 2904 | if (debug_aca_enabled) |
| 2905 | seq_printf(s, "enabled\n"); |
| 2906 | else |
| 2907 | seq_printf(s, "disabled\n"); |
| 2908 | |
| 2909 | return 0; |
| 2910 | } |
| 2911 | |
| 2912 | static int msm_otg_aca_open(struct inode *inode, struct file *file) |
| 2913 | { |
| 2914 | return single_open(file, msm_otg_aca_show, inode->i_private); |
| 2915 | } |
| 2916 | |
| 2917 | static ssize_t msm_otg_aca_write(struct file *file, const char __user *ubuf, |
| 2918 | size_t count, loff_t *ppos) |
| 2919 | { |
| 2920 | char buf[8]; |
| 2921 | |
| 2922 | memset(buf, 0x00, sizeof(buf)); |
| 2923 | |
| 2924 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 2925 | return -EFAULT; |
| 2926 | |
| 2927 | if (!strncmp(buf, "enable", 6)) |
| 2928 | debug_aca_enabled = true; |
| 2929 | else |
| 2930 | debug_aca_enabled = false; |
| 2931 | |
| 2932 | return count; |
| 2933 | } |
| 2934 | |
| 2935 | const struct file_operations msm_otg_aca_fops = { |
| 2936 | .open = msm_otg_aca_open, |
| 2937 | .read = seq_read, |
| 2938 | .write = msm_otg_aca_write, |
| 2939 | .llseek = seq_lseek, |
| 2940 | .release = single_release, |
| 2941 | }; |
| 2942 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 2943 | static int msm_otg_bus_show(struct seq_file *s, void *unused) |
| 2944 | { |
| 2945 | if (debug_bus_voting_enabled) |
| 2946 | seq_printf(s, "enabled\n"); |
| 2947 | else |
| 2948 | seq_printf(s, "disabled\n"); |
| 2949 | |
| 2950 | return 0; |
| 2951 | } |
| 2952 | |
| 2953 | static int msm_otg_bus_open(struct inode *inode, struct file *file) |
| 2954 | { |
| 2955 | return single_open(file, msm_otg_bus_show, inode->i_private); |
| 2956 | } |
| 2957 | |
| 2958 | static ssize_t msm_otg_bus_write(struct file *file, const char __user *ubuf, |
| 2959 | size_t count, loff_t *ppos) |
| 2960 | { |
| 2961 | char buf[8]; |
| 2962 | int ret; |
| 2963 | struct seq_file *s = file->private_data; |
| 2964 | struct msm_otg *motg = s->private; |
| 2965 | |
| 2966 | memset(buf, 0x00, sizeof(buf)); |
| 2967 | |
| 2968 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 2969 | return -EFAULT; |
| 2970 | |
| 2971 | if (!strncmp(buf, "enable", 6)) { |
| 2972 | /* Do not vote here. Let OTG statemachine decide when to vote */ |
| 2973 | debug_bus_voting_enabled = true; |
| 2974 | } else { |
| 2975 | debug_bus_voting_enabled = false; |
| 2976 | if (motg->bus_perf_client) { |
| 2977 | ret = msm_bus_scale_client_update_request( |
| 2978 | motg->bus_perf_client, 0); |
| 2979 | if (ret) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 2980 | dev_err(motg->phy.dev, "%s: Failed to devote " |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 2981 | "for bus bw %d\n", __func__, ret); |
| 2982 | } |
| 2983 | } |
| 2984 | |
| 2985 | return count; |
| 2986 | } |
| 2987 | |
| 2988 | const struct file_operations msm_otg_bus_fops = { |
| 2989 | .open = msm_otg_bus_open, |
| 2990 | .read = seq_read, |
| 2991 | .write = msm_otg_bus_write, |
| 2992 | .llseek = seq_lseek, |
| 2993 | .release = single_release, |
| 2994 | }; |
| 2995 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2996 | static struct dentry *msm_otg_dbg_root; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 2997 | |
| 2998 | static int msm_otg_debugfs_init(struct msm_otg *motg) |
| 2999 | { |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3000 | struct dentry *msm_otg_dentry; |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3001 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3002 | msm_otg_dbg_root = debugfs_create_dir("msm_otg", NULL); |
| 3003 | |
| 3004 | if (!msm_otg_dbg_root || IS_ERR(msm_otg_dbg_root)) |
| 3005 | return -ENODEV; |
| 3006 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3007 | if (motg->pdata->mode == USB_OTG && |
| 3008 | motg->pdata->otg_control == OTG_USER_CONTROL) { |
| 3009 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3010 | msm_otg_dentry = debugfs_create_file("mode", S_IRUGO | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3011 | S_IWUSR, msm_otg_dbg_root, motg, |
| 3012 | &msm_otg_mode_fops); |
| 3013 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3014 | if (!msm_otg_dentry) { |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3015 | debugfs_remove(msm_otg_dbg_root); |
| 3016 | msm_otg_dbg_root = NULL; |
| 3017 | return -ENODEV; |
| 3018 | } |
| 3019 | } |
| 3020 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3021 | msm_otg_dentry = debugfs_create_file("chg_type", S_IRUGO, |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3022 | msm_otg_dbg_root, motg, |
| 3023 | &msm_otg_chg_fops); |
| 3024 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3025 | if (!msm_otg_dentry) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3026 | debugfs_remove_recursive(msm_otg_dbg_root); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3027 | return -ENODEV; |
| 3028 | } |
| 3029 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3030 | msm_otg_dentry = debugfs_create_file("aca", S_IRUGO | S_IWUSR, |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3031 | msm_otg_dbg_root, motg, |
| 3032 | &msm_otg_aca_fops); |
| 3033 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3034 | if (!msm_otg_dentry) { |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3035 | debugfs_remove_recursive(msm_otg_dbg_root); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3036 | return -ENODEV; |
| 3037 | } |
| 3038 | |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3039 | msm_otg_dentry = debugfs_create_file("bus_voting", S_IRUGO | S_IWUSR, |
| 3040 | msm_otg_dbg_root, motg, |
| 3041 | &msm_otg_bus_fops); |
| 3042 | |
| 3043 | if (!msm_otg_dentry) { |
| 3044 | debugfs_remove_recursive(msm_otg_dbg_root); |
| 3045 | return -ENODEV; |
| 3046 | } |
Chiranjeevi Velempati | f9a1154 | 2012-03-28 18:18:34 +0530 | [diff] [blame] | 3047 | |
| 3048 | msm_otg_dentry = debugfs_create_file("otg_state", S_IRUGO, |
| 3049 | msm_otg_dbg_root, motg, &msm_otg_state_fops); |
| 3050 | |
| 3051 | if (!msm_otg_dentry) { |
| 3052 | debugfs_remove_recursive(msm_otg_dbg_root); |
| 3053 | return -ENODEV; |
| 3054 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3055 | return 0; |
| 3056 | } |
| 3057 | |
| 3058 | static void msm_otg_debugfs_cleanup(void) |
| 3059 | { |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3060 | debugfs_remove_recursive(msm_otg_dbg_root); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3061 | } |
| 3062 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3063 | static u64 msm_otg_dma_mask = DMA_BIT_MASK(64); |
| 3064 | static struct platform_device *msm_otg_add_pdev( |
| 3065 | struct platform_device *ofdev, const char *name) |
| 3066 | { |
| 3067 | struct platform_device *pdev; |
| 3068 | const struct resource *res = ofdev->resource; |
| 3069 | unsigned int num = ofdev->num_resources; |
| 3070 | int retval; |
| 3071 | |
| 3072 | pdev = platform_device_alloc(name, -1); |
| 3073 | if (!pdev) { |
| 3074 | retval = -ENOMEM; |
| 3075 | goto error; |
| 3076 | } |
| 3077 | |
| 3078 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 3079 | pdev->dev.dma_mask = &msm_otg_dma_mask; |
| 3080 | |
| 3081 | if (num) { |
| 3082 | retval = platform_device_add_resources(pdev, res, num); |
| 3083 | if (retval) |
| 3084 | goto error; |
| 3085 | } |
| 3086 | |
| 3087 | retval = platform_device_add(pdev); |
| 3088 | if (retval) |
| 3089 | goto error; |
| 3090 | |
| 3091 | return pdev; |
| 3092 | |
| 3093 | error: |
| 3094 | platform_device_put(pdev); |
| 3095 | return ERR_PTR(retval); |
| 3096 | } |
| 3097 | |
| 3098 | static int msm_otg_setup_devices(struct platform_device *ofdev, |
| 3099 | enum usb_mode_type mode, bool init) |
| 3100 | { |
| 3101 | const char *gadget_name = "msm_hsusb"; |
| 3102 | const char *host_name = "msm_hsusb_host"; |
| 3103 | static struct platform_device *gadget_pdev; |
| 3104 | static struct platform_device *host_pdev; |
| 3105 | int retval = 0; |
| 3106 | |
| 3107 | if (!init) { |
| 3108 | if (gadget_pdev) |
| 3109 | platform_device_unregister(gadget_pdev); |
| 3110 | if (host_pdev) |
| 3111 | platform_device_unregister(host_pdev); |
| 3112 | return 0; |
| 3113 | } |
| 3114 | |
| 3115 | switch (mode) { |
| 3116 | case USB_OTG: |
| 3117 | /* fall through */ |
| 3118 | case USB_PERIPHERAL: |
| 3119 | gadget_pdev = msm_otg_add_pdev(ofdev, gadget_name); |
| 3120 | if (IS_ERR(gadget_pdev)) { |
| 3121 | retval = PTR_ERR(gadget_pdev); |
| 3122 | break; |
| 3123 | } |
| 3124 | if (mode == USB_PERIPHERAL) |
| 3125 | break; |
| 3126 | /* fall through */ |
| 3127 | case USB_HOST: |
| 3128 | host_pdev = msm_otg_add_pdev(ofdev, host_name); |
| 3129 | if (IS_ERR(host_pdev)) { |
| 3130 | retval = PTR_ERR(host_pdev); |
| 3131 | if (mode == USB_OTG) |
| 3132 | platform_device_unregister(gadget_pdev); |
| 3133 | } |
| 3134 | break; |
| 3135 | default: |
| 3136 | break; |
| 3137 | } |
| 3138 | |
| 3139 | return retval; |
| 3140 | } |
| 3141 | |
| 3142 | struct msm_otg_platform_data *msm_otg_dt_to_pdata(struct platform_device *pdev) |
| 3143 | { |
| 3144 | struct device_node *node = pdev->dev.of_node; |
| 3145 | struct msm_otg_platform_data *pdata; |
| 3146 | int len = 0; |
| 3147 | |
| 3148 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 3149 | if (!pdata) { |
| 3150 | pr_err("unable to allocate platform data\n"); |
| 3151 | return NULL; |
| 3152 | } |
| 3153 | of_get_property(node, "qcom,hsusb-otg-phy-init-seq", &len); |
| 3154 | if (len) { |
| 3155 | pdata->phy_init_seq = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); |
| 3156 | if (!pdata->phy_init_seq) |
| 3157 | return NULL; |
| 3158 | of_property_read_u32_array(node, "qcom,hsusb-otg-phy-init-seq", |
| 3159 | pdata->phy_init_seq, |
| 3160 | len/sizeof(*pdata->phy_init_seq)); |
| 3161 | } |
| 3162 | of_property_read_u32(node, "qcom,hsusb-otg-power-budget", |
| 3163 | &pdata->power_budget); |
| 3164 | of_property_read_u32(node, "qcom,hsusb-otg-mode", |
| 3165 | &pdata->mode); |
| 3166 | of_property_read_u32(node, "qcom,hsusb-otg-otg-control", |
| 3167 | &pdata->otg_control); |
| 3168 | of_property_read_u32(node, "qcom,hsusb-otg-default-mode", |
| 3169 | &pdata->default_mode); |
| 3170 | of_property_read_u32(node, "qcom,hsusb-otg-phy-type", |
| 3171 | &pdata->phy_type); |
| 3172 | of_property_read_u32(node, "qcom,hsusb-otg-pmic-id-irq", |
| 3173 | &pdata->pmic_id_irq); |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3174 | return pdata; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3175 | } |
| 3176 | |
| 3177 | static int __init msm_otg_probe(struct platform_device *pdev) |
| 3178 | { |
| 3179 | int ret = 0; |
| 3180 | struct resource *res; |
| 3181 | struct msm_otg *motg; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3182 | struct usb_phy *phy; |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3183 | struct msm_otg_platform_data *pdata; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3184 | |
| 3185 | dev_info(&pdev->dev, "msm_otg probe\n"); |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3186 | |
| 3187 | if (pdev->dev.of_node) { |
| 3188 | dev_dbg(&pdev->dev, "device tree enabled\n"); |
| 3189 | pdata = msm_otg_dt_to_pdata(pdev); |
| 3190 | if (!pdata) |
| 3191 | return -ENOMEM; |
| 3192 | ret = msm_otg_setup_devices(pdev, pdata->mode, true); |
| 3193 | if (ret) { |
| 3194 | dev_err(&pdev->dev, "devices setup failed\n"); |
| 3195 | return ret; |
| 3196 | } |
| 3197 | } else if (!pdev->dev.platform_data) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3198 | dev_err(&pdev->dev, "No platform data given. Bailing out\n"); |
| 3199 | return -ENODEV; |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3200 | } else { |
| 3201 | pdata = pdev->dev.platform_data; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3202 | } |
| 3203 | |
| 3204 | motg = kzalloc(sizeof(struct msm_otg), GFP_KERNEL); |
| 3205 | if (!motg) { |
| 3206 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); |
| 3207 | return -ENOMEM; |
| 3208 | } |
| 3209 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3210 | motg->phy.otg = kzalloc(sizeof(struct usb_otg), GFP_KERNEL); |
| 3211 | if (!motg->phy.otg) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3212 | dev_err(&pdev->dev, "unable to allocate usb_otg\n"); |
| 3213 | ret = -ENOMEM; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3214 | goto free_motg; |
| 3215 | } |
| 3216 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3217 | the_msm_otg = motg; |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3218 | motg->pdata = pdata; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3219 | phy = &motg->phy; |
| 3220 | phy->dev = &pdev->dev; |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 3221 | |
| 3222 | /* |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3223 | * ACA ID_GND threshold range is overlapped with OTG ID_FLOAT. Hence |
| 3224 | * PHY treat ACA ID_GND as float and no interrupt is generated. But |
| 3225 | * PMIC can detect ACA ID_GND and generate an interrupt. |
| 3226 | */ |
| 3227 | if (aca_enabled() && motg->pdata->otg_control != OTG_PMIC_CONTROL) { |
| 3228 | dev_err(&pdev->dev, "ACA can not be enabled without PMIC\n"); |
| 3229 | ret = -EINVAL; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3230 | goto free_otg; |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3231 | } |
| 3232 | |
Ofir Cohen | 4da266f | 2012-01-03 10:19:29 +0200 | [diff] [blame] | 3233 | /* initialize reset counter */ |
| 3234 | motg->reset_counter = 0; |
| 3235 | |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 3236 | /* Some targets don't support PHY clock. */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3237 | motg->phy_reset_clk = clk_get(&pdev->dev, "phy_clk"); |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 3238 | if (IS_ERR(motg->phy_reset_clk)) |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3239 | dev_err(&pdev->dev, "failed to get phy_clk\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3240 | |
Pavankumar Kondeti | 923262e | 2012-04-20 15:34:24 +0530 | [diff] [blame] | 3241 | /* |
| 3242 | * Targets on which link uses asynchronous reset methodology, |
| 3243 | * free running clock is not required during the reset. |
| 3244 | */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3245 | motg->clk = clk_get(&pdev->dev, "alt_core_clk"); |
Pavankumar Kondeti | 923262e | 2012-04-20 15:34:24 +0530 | [diff] [blame] | 3246 | if (IS_ERR(motg->clk)) |
| 3247 | dev_dbg(&pdev->dev, "alt_core_clk is not present\n"); |
| 3248 | else |
| 3249 | clk_set_rate(motg->clk, 60000000); |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 3250 | |
| 3251 | /* |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3252 | * USB Core is running its protocol engine based on CORE CLK, |
Anji jonnala | 0f73cac | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 3253 | * CORE CLK must be running at >55Mhz for correct HSUSB |
| 3254 | * operation and USB core cannot tolerate frequency changes on |
| 3255 | * CORE CLK. For such USB cores, vote for maximum clk frequency |
| 3256 | * on pclk source |
| 3257 | */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3258 | motg->core_clk = clk_get(&pdev->dev, "core_clk"); |
| 3259 | if (IS_ERR(motg->core_clk)) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3260 | motg->core_clk = NULL; |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3261 | dev_err(&pdev->dev, "failed to get core_clk\n"); |
Pavankumar Kondeti | bc54133 | 2012-04-20 15:32:04 +0530 | [diff] [blame] | 3262 | ret = PTR_ERR(motg->core_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3263 | goto put_clk; |
| 3264 | } |
| 3265 | clk_set_rate(motg->core_clk, INT_MAX); |
| 3266 | |
| 3267 | motg->pclk = clk_get(&pdev->dev, "iface_clk"); |
| 3268 | if (IS_ERR(motg->pclk)) { |
| 3269 | dev_err(&pdev->dev, "failed to get iface_clk\n"); |
| 3270 | ret = PTR_ERR(motg->pclk); |
| 3271 | goto put_core_clk; |
| 3272 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3273 | |
| 3274 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 3275 | if (!res) { |
| 3276 | dev_err(&pdev->dev, "failed to get platform resource mem\n"); |
| 3277 | ret = -ENODEV; |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3278 | goto put_pclk; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3279 | } |
| 3280 | |
| 3281 | motg->regs = ioremap(res->start, resource_size(res)); |
| 3282 | if (!motg->regs) { |
| 3283 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 3284 | ret = -ENOMEM; |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3285 | goto put_pclk; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3286 | } |
| 3287 | dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs); |
| 3288 | |
| 3289 | motg->irq = platform_get_irq(pdev, 0); |
| 3290 | if (!motg->irq) { |
| 3291 | dev_err(&pdev->dev, "platform_get_irq failed\n"); |
| 3292 | ret = -ENODEV; |
| 3293 | goto free_regs; |
| 3294 | } |
| 3295 | |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 3296 | motg->xo_handle = msm_xo_get(MSM_XO_TCXO_D0, "usb"); |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 3297 | if (IS_ERR(motg->xo_handle)) { |
| 3298 | dev_err(&pdev->dev, "%s not able to get the handle " |
| 3299 | "to vote for TCXO D0 buffer\n", __func__); |
| 3300 | ret = PTR_ERR(motg->xo_handle); |
| 3301 | goto free_regs; |
| 3302 | } |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3303 | |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 3304 | ret = msm_xo_mode_vote(motg->xo_handle, MSM_XO_MODE_ON); |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 3305 | if (ret) { |
| 3306 | dev_err(&pdev->dev, "%s failed to vote for TCXO " |
| 3307 | "D0 buffer%d\n", __func__, ret); |
| 3308 | goto free_xo_handle; |
| 3309 | } |
| 3310 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 3311 | clk_prepare_enable(motg->pclk); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3312 | |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3313 | motg->vdd_type = VDDCX_CORNER; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3314 | hsusb_vddcx = devm_regulator_get(motg->phy.dev, "hsusb_vdd_dig"); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3315 | if (IS_ERR(hsusb_vddcx)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3316 | hsusb_vddcx = devm_regulator_get(motg->phy.dev, "HSUSB_VDDCX"); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3317 | if (IS_ERR(hsusb_vddcx)) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3318 | dev_err(motg->phy.dev, "unable to get hsusb vddcx\n"); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3319 | goto devote_xo_handle; |
| 3320 | } |
| 3321 | motg->vdd_type = VDDCX; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3322 | } |
| 3323 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3324 | ret = msm_hsusb_config_vddcx(1); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3325 | if (ret) { |
| 3326 | dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3327 | goto devote_xo_handle; |
| 3328 | } |
| 3329 | |
| 3330 | ret = regulator_enable(hsusb_vddcx); |
| 3331 | if (ret) { |
| 3332 | dev_err(&pdev->dev, "unable to enable the hsusb vddcx\n"); |
| 3333 | goto free_config_vddcx; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3334 | } |
| 3335 | |
| 3336 | ret = msm_hsusb_ldo_init(motg, 1); |
| 3337 | if (ret) { |
| 3338 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3339 | goto free_hsusb_vddcx; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3340 | } |
| 3341 | |
Mayank Rana | 9e9a2ac | 2012-03-24 04:05:28 +0530 | [diff] [blame] | 3342 | if (pdata->mhl_enable) { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3343 | mhl_analog_switch = devm_regulator_get(motg->phy.dev, |
Mayank Rana | 9e9a2ac | 2012-03-24 04:05:28 +0530 | [diff] [blame] | 3344 | "mhl_ext_3p3v"); |
| 3345 | if (IS_ERR(mhl_analog_switch)) { |
| 3346 | dev_err(&pdev->dev, "Unable to get mhl_analog_switch\n"); |
| 3347 | goto free_ldo_init; |
| 3348 | } |
| 3349 | } |
| 3350 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3351 | ret = msm_hsusb_ldo_enable(motg, 1); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3352 | if (ret) { |
| 3353 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3354 | goto free_ldo_init; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3355 | } |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 3356 | clk_prepare_enable(motg->core_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3357 | |
| 3358 | writel(0, USB_USBINTR); |
| 3359 | writel(0, USB_OTGSC); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3360 | /* Ensure that above STOREs are completed before enabling interrupts */ |
| 3361 | mb(); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3362 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3363 | wake_lock_init(&motg->wlock, WAKE_LOCK_SUSPEND, "msm_otg"); |
Vijayavardhan Vennapusa | a315203 | 2012-03-05 16:29:30 +0530 | [diff] [blame] | 3364 | msm_otg_init_timer(motg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3365 | INIT_WORK(&motg->sm_work, msm_otg_sm_work); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 3366 | INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3367 | setup_timer(&motg->id_timer, msm_otg_id_timer_func, |
| 3368 | (unsigned long) motg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3369 | ret = request_irq(motg->irq, msm_otg_irq, IRQF_SHARED, |
| 3370 | "msm_otg", motg); |
| 3371 | if (ret) { |
| 3372 | dev_err(&pdev->dev, "request irq failed\n"); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3373 | goto destroy_wlock; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3374 | } |
| 3375 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3376 | phy->init = msm_otg_reset; |
| 3377 | phy->set_power = msm_otg_set_power; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3378 | phy->set_suspend = msm_otg_set_suspend; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3379 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3380 | phy->io_ops = &msm_otg_io_ops; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3381 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3382 | phy->otg->phy = &motg->phy; |
| 3383 | phy->otg->set_host = msm_otg_set_host; |
| 3384 | phy->otg->set_peripheral = msm_otg_set_peripheral; |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3385 | phy->otg->start_hnp = msm_otg_start_hnp; |
| 3386 | phy->otg->start_srp = msm_otg_start_srp; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3387 | |
| 3388 | ret = usb_set_transceiver(&motg->phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3389 | if (ret) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3390 | dev_err(&pdev->dev, "usb_set_transceiver failed\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3391 | goto free_irq; |
| 3392 | } |
| 3393 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3394 | if (motg->pdata->mode == USB_OTG && |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 3395 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3396 | if (motg->pdata->pmic_id_irq) { |
| 3397 | ret = request_irq(motg->pdata->pmic_id_irq, |
| 3398 | msm_pmic_id_irq, |
| 3399 | IRQF_TRIGGER_RISING | |
| 3400 | IRQF_TRIGGER_FALLING, |
| 3401 | "msm_otg", motg); |
| 3402 | if (ret) { |
| 3403 | dev_err(&pdev->dev, "request irq failed for PMIC ID\n"); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3404 | goto remove_phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3405 | } |
| 3406 | } else { |
| 3407 | ret = -ENODEV; |
| 3408 | 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] | 3409 | goto remove_phy; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3410 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3411 | } |
| 3412 | |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 3413 | msm_hsusb_mhl_switch_enable(motg, 1); |
| 3414 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3415 | platform_set_drvdata(pdev, motg); |
| 3416 | device_init_wakeup(&pdev->dev, 1); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3417 | motg->mA_port = IUNIT; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3418 | |
Anji jonnala | d270e2d | 2011-08-09 11:28:32 +0530 | [diff] [blame] | 3419 | ret = msm_otg_debugfs_init(motg); |
| 3420 | if (ret) |
| 3421 | dev_dbg(&pdev->dev, "mode debugfs file is" |
| 3422 | "not available\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3423 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3424 | if (motg->pdata->otg_control == OTG_PMIC_CONTROL) |
| 3425 | pm8921_charger_register_vbus_sn(&msm_otg_set_vbus_state); |
| 3426 | |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 3427 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY) { |
| 3428 | if (motg->pdata->otg_control == OTG_PMIC_CONTROL && |
Pavankumar Kondeti | 0d81f31 | 2012-01-13 11:34:10 +0530 | [diff] [blame] | 3429 | (!(motg->pdata->mode == USB_OTG) || |
| 3430 | motg->pdata->pmic_id_irq)) |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 3431 | motg->caps = ALLOW_PHY_POWER_COLLAPSE | |
Vijayavardhan Vennapusa | 03171c7 | 2012-04-26 14:44:48 +0530 | [diff] [blame] | 3432 | ALLOW_PHY_RETENTION; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3433 | |
Amit Blay | 58b3147 | 2011-11-18 09:39:39 +0200 | [diff] [blame] | 3434 | if (motg->pdata->otg_control == OTG_PHY_CONTROL) |
| 3435 | motg->caps = ALLOW_PHY_RETENTION; |
| 3436 | } |
| 3437 | |
Amit Blay | 6fa647a | 2012-05-24 14:12:08 +0300 | [diff] [blame] | 3438 | if (motg->pdata->enable_lpm_on_dev_suspend) |
| 3439 | motg->caps |= ALLOW_LPM_ON_DEV_SUSPEND; |
| 3440 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3441 | wake_lock(&motg->wlock); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3442 | pm_runtime_set_active(&pdev->dev); |
| 3443 | pm_runtime_enable(&pdev->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3444 | |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 3445 | if (motg->pdata->bus_scale_table) { |
| 3446 | motg->bus_perf_client = |
| 3447 | msm_bus_scale_register_client(motg->pdata->bus_scale_table); |
| 3448 | if (!motg->bus_perf_client) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3449 | dev_err(motg->phy.dev, "%s: Failed to register BUS " |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 3450 | "scaling client!!\n", __func__); |
Manu Gautam | 8bdcc59 | 2012-03-06 11:26:06 +0530 | [diff] [blame] | 3451 | else |
| 3452 | debug_bus_voting_enabled = true; |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 3453 | } |
| 3454 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3455 | return 0; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3456 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3457 | remove_phy: |
| 3458 | usb_set_transceiver(NULL); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3459 | free_irq: |
| 3460 | free_irq(motg->irq, motg); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3461 | destroy_wlock: |
| 3462 | wake_lock_destroy(&motg->wlock); |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 3463 | clk_disable_unprepare(motg->core_clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3464 | msm_hsusb_ldo_enable(motg, 0); |
| 3465 | free_ldo_init: |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3466 | msm_hsusb_ldo_init(motg, 0); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3467 | free_hsusb_vddcx: |
| 3468 | regulator_disable(hsusb_vddcx); |
| 3469 | free_config_vddcx: |
| 3470 | regulator_set_voltage(hsusb_vddcx, |
| 3471 | vdd_val[motg->vdd_type][VDD_NONE], |
| 3472 | vdd_val[motg->vdd_type][VDD_MAX]); |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 3473 | devote_xo_handle: |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 3474 | clk_disable_unprepare(motg->pclk); |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 3475 | msm_xo_mode_vote(motg->xo_handle, MSM_XO_MODE_OFF); |
Anji jonnala | 7da3f26 | 2011-12-02 17:22:14 -0800 | [diff] [blame] | 3476 | free_xo_handle: |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 3477 | msm_xo_put(motg->xo_handle); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3478 | free_regs: |
| 3479 | iounmap(motg->regs); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3480 | put_pclk: |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3481 | clk_put(motg->pclk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3482 | put_core_clk: |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3483 | clk_put(motg->core_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3484 | put_clk: |
Pavankumar Kondeti | 923262e | 2012-04-20 15:34:24 +0530 | [diff] [blame] | 3485 | if (!IS_ERR(motg->clk)) |
| 3486 | clk_put(motg->clk); |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 3487 | if (!IS_ERR(motg->phy_reset_clk)) |
| 3488 | clk_put(motg->phy_reset_clk); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3489 | free_otg: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3490 | kfree(motg->phy.otg); |
Pavankumar Kondeti | aa449e1 | 2011-11-04 11:09:26 +0530 | [diff] [blame] | 3491 | free_motg: |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3492 | kfree(motg); |
| 3493 | return ret; |
| 3494 | } |
| 3495 | |
| 3496 | static int __devexit msm_otg_remove(struct platform_device *pdev) |
| 3497 | { |
| 3498 | struct msm_otg *motg = platform_get_drvdata(pdev); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3499 | struct usb_otg *otg = motg->phy.otg; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3500 | int cnt = 0; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3501 | |
| 3502 | if (otg->host || otg->gadget) |
| 3503 | return -EBUSY; |
| 3504 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3505 | if (pdev->dev.of_node) |
| 3506 | msm_otg_setup_devices(pdev, motg->pdata->mode, false); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3507 | if (motg->pdata->otg_control == OTG_PMIC_CONTROL) |
| 3508 | pm8921_charger_unregister_vbus_sn(0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3509 | msm_otg_debugfs_cleanup(); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 3510 | cancel_delayed_work_sync(&motg->chg_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3511 | cancel_work_sync(&motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3512 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 3513 | pm_runtime_resume(&pdev->dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3514 | |
| 3515 | device_init_wakeup(&pdev->dev, 0); |
| 3516 | pm_runtime_disable(&pdev->dev); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3517 | wake_lock_destroy(&motg->wlock); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3518 | |
Vijayavardhan Vennapusa | fc464f0 | 2011-11-04 21:54:00 +0530 | [diff] [blame] | 3519 | msm_hsusb_mhl_switch_enable(motg, 0); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3520 | if (motg->pdata->pmic_id_irq) |
| 3521 | free_irq(motg->pdata->pmic_id_irq, motg); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3522 | usb_set_transceiver(NULL); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3523 | free_irq(motg->irq, motg); |
| 3524 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3525 | /* |
| 3526 | * Put PHY in low power mode. |
| 3527 | */ |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3528 | ulpi_read(otg->phy, 0x14); |
| 3529 | ulpi_write(otg->phy, 0x08, 0x09); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3530 | |
| 3531 | writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC); |
| 3532 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 3533 | if (readl(USB_PORTSC) & PORTSC_PHCD) |
| 3534 | break; |
| 3535 | udelay(1); |
| 3536 | cnt++; |
| 3537 | } |
| 3538 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3539 | dev_err(otg->phy->dev, "Unable to suspend PHY\n"); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3540 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 3541 | clk_disable_unprepare(motg->pclk); |
| 3542 | clk_disable_unprepare(motg->core_clk); |
Stephen Boyd | 30ad10b | 2012-03-01 14:51:04 -0800 | [diff] [blame] | 3543 | msm_xo_put(motg->xo_handle); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3544 | msm_hsusb_ldo_enable(motg, 0); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 3545 | msm_hsusb_ldo_init(motg, 0); |
Mayank Rana | 248698c | 2012-04-19 00:03:16 +0530 | [diff] [blame] | 3546 | regulator_disable(hsusb_vddcx); |
| 3547 | regulator_set_voltage(hsusb_vddcx, |
| 3548 | vdd_val[motg->vdd_type][VDD_NONE], |
| 3549 | vdd_val[motg->vdd_type][VDD_MAX]); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3550 | |
| 3551 | iounmap(motg->regs); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3552 | pm_runtime_set_suspended(&pdev->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3553 | |
Amit Blay | 02eff13 | 2011-09-21 16:46:24 +0300 | [diff] [blame] | 3554 | if (!IS_ERR(motg->phy_reset_clk)) |
| 3555 | clk_put(motg->phy_reset_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3556 | clk_put(motg->pclk); |
Pavankumar Kondeti | 923262e | 2012-04-20 15:34:24 +0530 | [diff] [blame] | 3557 | if (!IS_ERR(motg->clk)) |
| 3558 | clk_put(motg->clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3559 | clk_put(motg->core_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3560 | |
Manu Gautam | cd82e9d | 2011-12-20 14:17:28 +0530 | [diff] [blame] | 3561 | if (motg->bus_perf_client) |
| 3562 | msm_bus_scale_unregister_client(motg->bus_perf_client); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3563 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 3564 | kfree(motg->phy.otg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3565 | kfree(motg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3566 | return 0; |
| 3567 | } |
| 3568 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3569 | #ifdef CONFIG_PM_RUNTIME |
| 3570 | static int msm_otg_runtime_idle(struct device *dev) |
| 3571 | { |
| 3572 | struct msm_otg *motg = dev_get_drvdata(dev); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3573 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3574 | |
| 3575 | dev_dbg(dev, "OTG runtime idle\n"); |
| 3576 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 3577 | if (phy->state == OTG_STATE_UNDEFINED) |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 3578 | return -EAGAIN; |
| 3579 | else |
| 3580 | return 0; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3581 | } |
| 3582 | |
| 3583 | static int msm_otg_runtime_suspend(struct device *dev) |
| 3584 | { |
| 3585 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 3586 | |
| 3587 | dev_dbg(dev, "OTG runtime suspend\n"); |
| 3588 | return msm_otg_suspend(motg); |
| 3589 | } |
| 3590 | |
| 3591 | static int msm_otg_runtime_resume(struct device *dev) |
| 3592 | { |
| 3593 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 3594 | |
| 3595 | dev_dbg(dev, "OTG runtime resume\n"); |
Pavankumar Kondeti | 8be99cf | 2011-08-04 10:48:08 +0530 | [diff] [blame] | 3596 | pm_runtime_get_noresume(dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3597 | return msm_otg_resume(motg); |
| 3598 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3599 | #endif |
| 3600 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 3601 | #ifdef CONFIG_PM_SLEEP |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3602 | static int msm_otg_pm_suspend(struct device *dev) |
| 3603 | { |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 3604 | int ret = 0; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3605 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 3606 | |
| 3607 | dev_dbg(dev, "OTG PM suspend\n"); |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 3608 | |
| 3609 | atomic_set(&motg->pm_suspended, 1); |
| 3610 | ret = msm_otg_suspend(motg); |
| 3611 | if (ret) |
| 3612 | atomic_set(&motg->pm_suspended, 0); |
| 3613 | |
| 3614 | return ret; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | static int msm_otg_pm_resume(struct device *dev) |
| 3618 | { |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 3619 | int ret = 0; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3620 | struct msm_otg *motg = dev_get_drvdata(dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3621 | |
| 3622 | dev_dbg(dev, "OTG PM resume\n"); |
| 3623 | |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 3624 | atomic_set(&motg->pm_suspended, 0); |
| 3625 | if (motg->sm_work_pending) { |
| 3626 | motg->sm_work_pending = false; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3627 | |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 3628 | pm_runtime_get_noresume(dev); |
| 3629 | ret = msm_otg_resume(motg); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3630 | |
Jack Pham | 5ca279b | 2012-05-14 18:42:54 -0700 | [diff] [blame] | 3631 | /* Update runtime PM status */ |
| 3632 | pm_runtime_disable(dev); |
| 3633 | pm_runtime_set_active(dev); |
| 3634 | pm_runtime_enable(dev); |
| 3635 | |
| 3636 | queue_work(system_nrt_wq, &motg->sm_work); |
| 3637 | } |
| 3638 | |
| 3639 | return ret; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3640 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3641 | #endif |
| 3642 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 3643 | #ifdef CONFIG_PM |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3644 | static const struct dev_pm_ops msm_otg_dev_pm_ops = { |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 3645 | SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume) |
| 3646 | SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume, |
| 3647 | msm_otg_runtime_idle) |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3648 | }; |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 3649 | #endif |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3650 | |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3651 | static struct of_device_id msm_otg_dt_match[] = { |
| 3652 | { .compatible = "qcom,hsusb-otg", |
| 3653 | }, |
| 3654 | {} |
| 3655 | }; |
| 3656 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3657 | static struct platform_driver msm_otg_driver = { |
| 3658 | .remove = __devexit_p(msm_otg_remove), |
| 3659 | .driver = { |
| 3660 | .name = DRIVER_NAME, |
| 3661 | .owner = THIS_MODULE, |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 3662 | #ifdef CONFIG_PM |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 3663 | .pm = &msm_otg_dev_pm_ops, |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 3664 | #endif |
Pavankumar Kondeti | eaea7fe | 2011-10-27 14:46:45 +0530 | [diff] [blame] | 3665 | .of_match_table = msm_otg_dt_match, |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 3666 | }, |
| 3667 | }; |
| 3668 | |
| 3669 | static int __init msm_otg_init(void) |
| 3670 | { |
| 3671 | return platform_driver_probe(&msm_otg_driver, msm_otg_probe); |
| 3672 | } |
| 3673 | |
| 3674 | static void __exit msm_otg_exit(void) |
| 3675 | { |
| 3676 | platform_driver_unregister(&msm_otg_driver); |
| 3677 | } |
| 3678 | |
| 3679 | module_init(msm_otg_init); |
| 3680 | module_exit(msm_otg_exit); |
| 3681 | |
| 3682 | MODULE_LICENSE("GPL v2"); |
| 3683 | MODULE_DESCRIPTION("MSM USB transceiver driver"); |