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