Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2009-2011, 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 | * |
| 12 | * You should have received a copy of the GNU General Public License |
| 13 | * along with this program; if not, write to the Free Software |
| 14 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 15 | * 02110-1301, USA. |
| 16 | * |
| 17 | */ |
| 18 | |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/device.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/clk.h> |
| 23 | #include <linux/slab.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/err.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/io.h> |
| 28 | #include <linux/ioport.h> |
| 29 | #include <linux/uaccess.h> |
| 30 | #include <linux/debugfs.h> |
| 31 | #include <linux/seq_file.h> |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 32 | #include <linux/pm_runtime.h> |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 33 | #include <linux/of.h> |
| 34 | #include <linux/of_device.h> |
Ivan T. Ivanov | a273454 | 2014-04-28 16:34:16 +0300 | [diff] [blame] | 35 | #include <linux/reset.h> |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 36 | |
| 37 | #include <linux/usb.h> |
| 38 | #include <linux/usb/otg.h> |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 39 | #include <linux/usb/of.h> |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 40 | #include <linux/usb/ulpi.h> |
| 41 | #include <linux/usb/gadget.h> |
| 42 | #include <linux/usb/hcd.h> |
| 43 | #include <linux/usb/msm_hsusb.h> |
| 44 | #include <linux/usb/msm_hsusb_hw.h> |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 45 | #include <linux/regulator/consumer.h> |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 46 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 47 | #define MSM_USB_BASE (motg->regs) |
| 48 | #define DRIVER_NAME "msm_otg" |
| 49 | |
| 50 | #define ULPI_IO_TIMEOUT_USEC (10 * 1000) |
Ivan T. Ivanov | d69c6f5 | 2014-04-28 16:34:18 +0300 | [diff] [blame] | 51 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 52 | |
| 53 | #define USB_PHY_3P3_VOL_MIN 3050000 /* uV */ |
| 54 | #define USB_PHY_3P3_VOL_MAX 3300000 /* uV */ |
| 55 | #define USB_PHY_3P3_HPM_LOAD 50000 /* uA */ |
| 56 | #define USB_PHY_3P3_LPM_LOAD 4000 /* uA */ |
| 57 | |
| 58 | #define USB_PHY_1P8_VOL_MIN 1800000 /* uV */ |
| 59 | #define USB_PHY_1P8_VOL_MAX 1800000 /* uV */ |
| 60 | #define USB_PHY_1P8_HPM_LOAD 50000 /* uA */ |
| 61 | #define USB_PHY_1P8_LPM_LOAD 4000 /* uA */ |
| 62 | |
| 63 | #define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */ |
| 64 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
| 65 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 66 | static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init) |
| 67 | { |
| 68 | int ret = 0; |
| 69 | |
| 70 | if (init) { |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 71 | ret = regulator_set_voltage(motg->vddcx, |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 72 | USB_PHY_VDD_DIG_VOL_MIN, |
| 73 | USB_PHY_VDD_DIG_VOL_MAX); |
| 74 | if (ret) { |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 75 | dev_err(motg->phy.dev, "Cannot set vddcx voltage\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 76 | return ret; |
| 77 | } |
| 78 | |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 79 | ret = regulator_enable(motg->vddcx); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 80 | if (ret) |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 81 | dev_err(motg->phy.dev, "unable to enable hsusb vddcx\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 82 | } else { |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 83 | ret = regulator_set_voltage(motg->vddcx, 0, |
Mark Brown | 7b521fc | 2011-05-15 09:55:57 -0700 | [diff] [blame] | 84 | USB_PHY_VDD_DIG_VOL_MAX); |
Mark Brown | e99c430 | 2011-05-15 09:55:58 -0700 | [diff] [blame] | 85 | if (ret) |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 86 | dev_err(motg->phy.dev, "Cannot set vddcx voltage\n"); |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 87 | ret = regulator_disable(motg->vddcx); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 88 | if (ret) |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 89 | dev_err(motg->phy.dev, "unable to disable hsusb vddcx\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | return ret; |
| 93 | } |
| 94 | |
| 95 | static int msm_hsusb_ldo_init(struct msm_otg *motg, int init) |
| 96 | { |
| 97 | int rc = 0; |
| 98 | |
| 99 | if (init) { |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 100 | rc = regulator_set_voltage(motg->v3p3, USB_PHY_3P3_VOL_MIN, |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 101 | USB_PHY_3P3_VOL_MAX); |
| 102 | if (rc) { |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 103 | dev_err(motg->phy.dev, "Cannot set v3p3 voltage\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 104 | goto exit; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 105 | } |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 106 | rc = regulator_enable(motg->v3p3); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 107 | if (rc) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 108 | dev_err(motg->phy.dev, "unable to enable the hsusb 3p3\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 109 | goto exit; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 110 | } |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 111 | rc = regulator_set_voltage(motg->v1p8, USB_PHY_1P8_VOL_MIN, |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 112 | USB_PHY_1P8_VOL_MAX); |
| 113 | if (rc) { |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 114 | dev_err(motg->phy.dev, "Cannot set v1p8 voltage\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 115 | goto disable_3p3; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 116 | } |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 117 | rc = regulator_enable(motg->v1p8); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 118 | if (rc) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 119 | dev_err(motg->phy.dev, "unable to enable the hsusb 1p8\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 120 | goto disable_3p3; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 126 | regulator_disable(motg->v1p8); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 127 | disable_3p3: |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 128 | regulator_disable(motg->v3p3); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 129 | exit: |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 130 | return rc; |
| 131 | } |
| 132 | |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 133 | static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, int on) |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 134 | { |
| 135 | int ret = 0; |
| 136 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 137 | if (on) { |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 138 | ret = regulator_set_optimum_mode(motg->v1p8, |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 139 | USB_PHY_1P8_HPM_LOAD); |
| 140 | if (ret < 0) { |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 141 | pr_err("Could not set HPM for v1p8\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 142 | return ret; |
| 143 | } |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 144 | ret = regulator_set_optimum_mode(motg->v3p3, |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 145 | USB_PHY_3P3_HPM_LOAD); |
| 146 | if (ret < 0) { |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 147 | pr_err("Could not set HPM for v3p3\n"); |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 148 | regulator_set_optimum_mode(motg->v1p8, |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 149 | USB_PHY_1P8_LPM_LOAD); |
| 150 | return ret; |
| 151 | } |
| 152 | } else { |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 153 | ret = regulator_set_optimum_mode(motg->v1p8, |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 154 | USB_PHY_1P8_LPM_LOAD); |
| 155 | if (ret < 0) |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 156 | pr_err("Could not set LPM for v1p8\n"); |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 157 | ret = regulator_set_optimum_mode(motg->v3p3, |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 158 | USB_PHY_3P3_LPM_LOAD); |
| 159 | if (ret < 0) |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 160 | pr_err("Could not set LPM for v3p3\n"); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | pr_debug("reg (%s)\n", on ? "HPM" : "LPM"); |
| 164 | return ret < 0 ? ret : 0; |
| 165 | } |
| 166 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 167 | static int ulpi_read(struct usb_phy *phy, u32 reg) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 168 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 169 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 170 | int cnt = 0; |
| 171 | |
| 172 | /* initiate read operation */ |
| 173 | writel(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg), |
| 174 | USB_ULPI_VIEWPORT); |
| 175 | |
| 176 | /* wait for completion */ |
| 177 | while (cnt < ULPI_IO_TIMEOUT_USEC) { |
| 178 | if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN)) |
| 179 | break; |
| 180 | udelay(1); |
| 181 | cnt++; |
| 182 | } |
| 183 | |
| 184 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 185 | dev_err(phy->dev, "ulpi_read: timeout %08x\n", |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 186 | readl(USB_ULPI_VIEWPORT)); |
| 187 | return -ETIMEDOUT; |
| 188 | } |
| 189 | return ULPI_DATA_READ(readl(USB_ULPI_VIEWPORT)); |
| 190 | } |
| 191 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 192 | static int ulpi_write(struct usb_phy *phy, u32 val, u32 reg) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 193 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 194 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 195 | int cnt = 0; |
| 196 | |
| 197 | /* initiate write operation */ |
| 198 | writel(ULPI_RUN | ULPI_WRITE | |
| 199 | ULPI_ADDR(reg) | ULPI_DATA(val), |
| 200 | USB_ULPI_VIEWPORT); |
| 201 | |
| 202 | /* wait for completion */ |
| 203 | while (cnt < ULPI_IO_TIMEOUT_USEC) { |
| 204 | if (!(readl(USB_ULPI_VIEWPORT) & ULPI_RUN)) |
| 205 | break; |
| 206 | udelay(1); |
| 207 | cnt++; |
| 208 | } |
| 209 | |
| 210 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 211 | dev_err(phy->dev, "ulpi_write: timeout\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 212 | return -ETIMEDOUT; |
| 213 | } |
| 214 | return 0; |
| 215 | } |
| 216 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 217 | static struct usb_phy_io_ops msm_otg_io_ops = { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 218 | .read = ulpi_read, |
| 219 | .write = ulpi_write, |
| 220 | }; |
| 221 | |
| 222 | static void ulpi_init(struct msm_otg *motg) |
| 223 | { |
| 224 | struct msm_otg_platform_data *pdata = motg->pdata; |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 225 | int *seq = pdata->phy_init_seq, idx; |
| 226 | u32 addr = ULPI_EXT_VENDOR_SPECIFIC; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 227 | |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 228 | for (idx = 0; idx < pdata->phy_init_sz; idx++) { |
| 229 | if (seq[idx] == -1) |
| 230 | continue; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 231 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 232 | dev_vdbg(motg->phy.dev, "ulpi: write 0x%02x to 0x%02x\n", |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 233 | seq[idx], addr + idx); |
| 234 | ulpi_write(&motg->phy, seq[idx], addr + idx); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | |
Ivan T. Ivanov | 349907c | 2014-04-28 16:34:21 +0300 | [diff] [blame^] | 238 | static int msm_phy_notify_disconnect(struct usb_phy *phy, |
| 239 | enum usb_device_speed speed) |
| 240 | { |
| 241 | int val; |
| 242 | |
| 243 | /* |
| 244 | * Put the transceiver in non-driving mode. Otherwise host |
| 245 | * may not detect soft-disconnection. |
| 246 | */ |
| 247 | val = ulpi_read(phy, ULPI_FUNC_CTRL); |
| 248 | val &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
| 249 | val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; |
| 250 | ulpi_write(phy, val, ULPI_FUNC_CTRL); |
| 251 | |
| 252 | return 0; |
| 253 | } |
| 254 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 255 | static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert) |
| 256 | { |
Ivan T. Ivanov | a273454 | 2014-04-28 16:34:16 +0300 | [diff] [blame] | 257 | int ret; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 258 | |
Ivan T. Ivanov | a273454 | 2014-04-28 16:34:16 +0300 | [diff] [blame] | 259 | if (motg->pdata->link_clk_reset) |
| 260 | ret = motg->pdata->link_clk_reset(motg->clk, assert); |
| 261 | else if (assert) |
| 262 | ret = reset_control_assert(motg->link_rst); |
| 263 | else |
| 264 | ret = reset_control_deassert(motg->link_rst); |
Ivan T. Ivanov | 5146d77 | 2013-12-30 13:15:27 -0800 | [diff] [blame] | 265 | |
Ivan T. Ivanov | 5146d77 | 2013-12-30 13:15:27 -0800 | [diff] [blame] | 266 | if (ret) |
| 267 | dev_err(motg->phy.dev, "usb link clk reset %s failed\n", |
| 268 | assert ? "assert" : "deassert"); |
| 269 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 270 | return ret; |
| 271 | } |
| 272 | |
| 273 | static int msm_otg_phy_clk_reset(struct msm_otg *motg) |
| 274 | { |
Ivan T. Ivanov | a273454 | 2014-04-28 16:34:16 +0300 | [diff] [blame] | 275 | int ret; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 276 | |
Ivan T. Ivanov | a273454 | 2014-04-28 16:34:16 +0300 | [diff] [blame] | 277 | if (motg->pdata->phy_clk_reset) |
| 278 | ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk); |
| 279 | else |
| 280 | ret = reset_control_reset(motg->phy_rst); |
Ivan T. Ivanov | 5146d77 | 2013-12-30 13:15:27 -0800 | [diff] [blame] | 281 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 282 | if (ret) |
Ivan T. Ivanov | 5146d77 | 2013-12-30 13:15:27 -0800 | [diff] [blame] | 283 | dev_err(motg->phy.dev, "usb phy clk reset failed\n"); |
| 284 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 285 | return ret; |
| 286 | } |
| 287 | |
Ivan T. Ivanov | d69c6f5 | 2014-04-28 16:34:18 +0300 | [diff] [blame] | 288 | static int msm_link_reset(struct msm_otg *motg) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 289 | { |
| 290 | u32 val; |
| 291 | int ret; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 292 | |
| 293 | ret = msm_otg_link_clk_reset(motg, 1); |
| 294 | if (ret) |
| 295 | return ret; |
Ivan T. Ivanov | d69c6f5 | 2014-04-28 16:34:18 +0300 | [diff] [blame] | 296 | |
| 297 | /* wait for 1ms delay as suggested in HPG. */ |
| 298 | usleep_range(1000, 1200); |
| 299 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 300 | ret = msm_otg_link_clk_reset(motg, 0); |
| 301 | if (ret) |
| 302 | return ret; |
| 303 | |
Ivan T. Ivanov | cfa3ff5 | 2014-04-28 16:34:17 +0300 | [diff] [blame] | 304 | if (motg->phy_number) |
| 305 | writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2); |
| 306 | |
Tim Bird | 9f27984b | 2014-04-28 16:34:19 +0300 | [diff] [blame] | 307 | /* put transceiver in serial mode as part of reset */ |
Ivan T. Ivanov | d69c6f5 | 2014-04-28 16:34:18 +0300 | [diff] [blame] | 308 | val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK; |
Tim Bird | 9f27984b | 2014-04-28 16:34:19 +0300 | [diff] [blame] | 309 | writel(val | PORTSC_PTS_SERIAL, USB_PORTSC); |
Ivan T. Ivanov | d69c6f5 | 2014-04-28 16:34:18 +0300 | [diff] [blame] | 310 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 311 | return 0; |
| 312 | } |
| 313 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 314 | static int msm_otg_reset(struct usb_phy *phy) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 315 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 316 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 317 | int cnt = 0; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 318 | |
| 319 | writel(USBCMD_RESET, USB_USBCMD); |
| 320 | while (cnt < LINK_RESET_TIMEOUT_USEC) { |
| 321 | if (!(readl(USB_USBCMD) & USBCMD_RESET)) |
| 322 | break; |
| 323 | udelay(1); |
| 324 | cnt++; |
| 325 | } |
| 326 | if (cnt >= LINK_RESET_TIMEOUT_USEC) |
| 327 | return -ETIMEDOUT; |
| 328 | |
Tim Bird | 9f27984b | 2014-04-28 16:34:19 +0300 | [diff] [blame] | 329 | /* select ULPI phy and clear other status/control bits in PORTSC */ |
| 330 | writel(PORTSC_PTS_ULPI, USB_PORTSC); |
| 331 | |
Ivan T. Ivanov | d69c6f5 | 2014-04-28 16:34:18 +0300 | [diff] [blame] | 332 | writel(0x0, USB_AHBBURST); |
| 333 | writel(0x08, USB_AHBMODE); |
| 334 | |
| 335 | if (motg->phy_number) |
| 336 | writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2); |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static void msm_phy_reset(struct msm_otg *motg) |
| 341 | { |
| 342 | void __iomem *addr; |
| 343 | |
| 344 | if (motg->pdata->phy_type != SNPS_28NM_INTEGRATED_PHY) { |
| 345 | msm_otg_phy_clk_reset(motg); |
| 346 | return; |
| 347 | } |
| 348 | |
| 349 | addr = USB_PHY_CTRL; |
| 350 | if (motg->phy_number) |
| 351 | addr = USB_PHY_CTRL2; |
| 352 | |
| 353 | /* Assert USB PHY_POR */ |
| 354 | writel(readl(addr) | PHY_POR_ASSERT, addr); |
| 355 | |
| 356 | /* |
| 357 | * wait for minimum 10 microseconds as suggested in HPG. |
| 358 | * Use a slightly larger value since the exact value didn't |
| 359 | * work 100% of the time. |
| 360 | */ |
| 361 | udelay(12); |
| 362 | |
| 363 | /* Deassert USB PHY_POR */ |
| 364 | writel(readl(addr) & ~PHY_POR_ASSERT, addr); |
| 365 | } |
| 366 | |
| 367 | static int msm_usb_reset(struct usb_phy *phy) |
| 368 | { |
| 369 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
| 370 | int ret; |
| 371 | |
| 372 | if (!IS_ERR(motg->core_clk)) |
| 373 | clk_prepare_enable(motg->core_clk); |
| 374 | |
| 375 | ret = msm_link_reset(motg); |
| 376 | if (ret) { |
| 377 | dev_err(phy->dev, "phy_reset failed\n"); |
| 378 | return ret; |
| 379 | } |
| 380 | |
| 381 | ret = msm_otg_reset(&motg->phy); |
| 382 | if (ret) { |
| 383 | dev_err(phy->dev, "link reset failed\n"); |
| 384 | return ret; |
| 385 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 386 | |
| 387 | msleep(100); |
| 388 | |
Ivan T. Ivanov | d69c6f5 | 2014-04-28 16:34:18 +0300 | [diff] [blame] | 389 | /* Reset USB PHY after performing USB Link RESET */ |
| 390 | msm_phy_reset(motg); |
| 391 | |
| 392 | if (!IS_ERR(motg->core_clk)) |
| 393 | clk_disable_unprepare(motg->core_clk); |
| 394 | |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | static int msm_phy_init(struct usb_phy *phy) |
| 399 | { |
| 400 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
| 401 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 402 | u32 val, ulpi_val = 0; |
| 403 | |
| 404 | /* Program USB PHY Override registers. */ |
| 405 | ulpi_init(motg); |
| 406 | |
| 407 | /* |
| 408 | * It is recommended in HPG to reset USB PHY after programming |
| 409 | * USB PHY Override registers. |
| 410 | */ |
| 411 | msm_phy_reset(motg); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 412 | |
| 413 | if (pdata->otg_control == OTG_PHY_CONTROL) { |
| 414 | val = readl(USB_OTGSC); |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 415 | if (pdata->mode == USB_DR_MODE_OTG) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 416 | ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID; |
| 417 | val |= OTGSC_IDIE | OTGSC_BSVIE; |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 418 | } else if (pdata->mode == USB_DR_MODE_PERIPHERAL) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 419 | ulpi_val = ULPI_INT_SESS_VALID; |
| 420 | val |= OTGSC_BSVIE; |
| 421 | } |
| 422 | writel(val, USB_OTGSC); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 423 | ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_RISE); |
| 424 | ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_FALL); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 425 | } |
| 426 | |
Ivan T. Ivanov | cfa3ff5 | 2014-04-28 16:34:17 +0300 | [diff] [blame] | 427 | if (motg->phy_number) |
| 428 | writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2); |
| 429 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 430 | return 0; |
| 431 | } |
| 432 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 433 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 434 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) |
| 435 | |
Josh Cartwright | e7d613d | 2014-02-18 10:36:29 -0600 | [diff] [blame] | 436 | #ifdef CONFIG_PM |
| 437 | |
| 438 | #define USB_PHY_SUSP_DIG_VOL 500000 |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 439 | static int msm_hsusb_config_vddcx(struct msm_otg *motg, int high) |
Josh Cartwright | e7d613d | 2014-02-18 10:36:29 -0600 | [diff] [blame] | 440 | { |
| 441 | int max_vol = USB_PHY_VDD_DIG_VOL_MAX; |
| 442 | int min_vol; |
| 443 | int ret; |
| 444 | |
| 445 | if (high) |
| 446 | min_vol = USB_PHY_VDD_DIG_VOL_MIN; |
| 447 | else |
| 448 | min_vol = USB_PHY_SUSP_DIG_VOL; |
| 449 | |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 450 | ret = regulator_set_voltage(motg->vddcx, min_vol, max_vol); |
Josh Cartwright | e7d613d | 2014-02-18 10:36:29 -0600 | [diff] [blame] | 451 | if (ret) { |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 452 | pr_err("Cannot set vddcx voltage\n"); |
Josh Cartwright | e7d613d | 2014-02-18 10:36:29 -0600 | [diff] [blame] | 453 | return ret; |
| 454 | } |
| 455 | |
| 456 | pr_debug("%s: min_vol:%d max_vol:%d\n", __func__, min_vol, max_vol); |
| 457 | |
| 458 | return ret; |
| 459 | } |
| 460 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 461 | static int msm_otg_suspend(struct msm_otg *motg) |
| 462 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 463 | struct usb_phy *phy = &motg->phy; |
| 464 | struct usb_bus *bus = phy->otg->host; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 465 | struct msm_otg_platform_data *pdata = motg->pdata; |
Ivan T. Ivanov | cfa3ff5 | 2014-04-28 16:34:17 +0300 | [diff] [blame] | 466 | void __iomem *addr; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 467 | int cnt = 0; |
| 468 | |
| 469 | if (atomic_read(&motg->in_lpm)) |
| 470 | return 0; |
| 471 | |
| 472 | disable_irq(motg->irq); |
| 473 | /* |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 474 | * Chipidea 45-nm PHY suspend sequence: |
| 475 | * |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 476 | * Interrupt Latch Register auto-clear feature is not present |
| 477 | * in all PHY versions. Latch register is clear on read type. |
| 478 | * Clear latch register to avoid spurious wakeup from |
| 479 | * low power mode (LPM). |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 480 | * |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 481 | * PHY comparators are disabled when PHY enters into low power |
| 482 | * mode (LPM). Keep PHY comparators ON in LPM only when we expect |
| 483 | * VBUS/Id notifications from USB PHY. Otherwise turn off USB |
| 484 | * PHY comparators. This save significant amount of power. |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 485 | * |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 486 | * PLL is not turned off when PHY enters into low power mode (LPM). |
| 487 | * Disable PLL for maximum power savings. |
| 488 | */ |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 489 | |
| 490 | if (motg->pdata->phy_type == CI_45NM_INTEGRATED_PHY) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 491 | ulpi_read(phy, 0x14); |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 492 | if (pdata->otg_control == OTG_PHY_CONTROL) |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 493 | ulpi_write(phy, 0x01, 0x30); |
| 494 | ulpi_write(phy, 0x08, 0x09); |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 495 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 496 | |
| 497 | /* |
| 498 | * PHY may take some time or even fail to enter into low power |
| 499 | * mode (LPM). Hence poll for 500 msec and reset the PHY and link |
| 500 | * in failure case. |
| 501 | */ |
| 502 | writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC); |
| 503 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 504 | if (readl(USB_PORTSC) & PORTSC_PHCD) |
| 505 | break; |
| 506 | udelay(1); |
| 507 | cnt++; |
| 508 | } |
| 509 | |
| 510 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 511 | dev_err(phy->dev, "Unable to suspend PHY\n"); |
| 512 | msm_otg_reset(phy); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 513 | enable_irq(motg->irq); |
| 514 | return -ETIMEDOUT; |
| 515 | } |
| 516 | |
| 517 | /* |
| 518 | * PHY has capability to generate interrupt asynchronously in low |
| 519 | * power mode (LPM). This interrupt is level triggered. So USB IRQ |
| 520 | * line must be disabled till async interrupt enable bit is cleared |
| 521 | * in USBCMD register. Assert STP (ULPI interface STOP signal) to |
| 522 | * block data communication from PHY. |
| 523 | */ |
| 524 | writel(readl(USB_USBCMD) | ASYNC_INTR_CTRL | ULPI_STP_CTRL, USB_USBCMD); |
| 525 | |
Ivan T. Ivanov | cfa3ff5 | 2014-04-28 16:34:17 +0300 | [diff] [blame] | 526 | addr = USB_PHY_CTRL; |
| 527 | if (motg->phy_number) |
| 528 | addr = USB_PHY_CTRL2; |
| 529 | |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 530 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && |
| 531 | motg->pdata->otg_control == OTG_PMIC_CONTROL) |
Ivan T. Ivanov | cfa3ff5 | 2014-04-28 16:34:17 +0300 | [diff] [blame] | 532 | writel(readl(addr) | PHY_RETEN, addr); |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 533 | |
Stephen Boyd | b99a8f6 | 2013-06-17 10:43:10 -0700 | [diff] [blame] | 534 | clk_disable_unprepare(motg->pclk); |
| 535 | clk_disable_unprepare(motg->clk); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 536 | if (!IS_ERR(motg->core_clk)) |
Stephen Boyd | b99a8f6 | 2013-06-17 10:43:10 -0700 | [diff] [blame] | 537 | clk_disable_unprepare(motg->core_clk); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 538 | |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 539 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && |
| 540 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 541 | msm_hsusb_ldo_set_mode(motg, 0); |
| 542 | msm_hsusb_config_vddcx(motg, 0); |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 543 | } |
| 544 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 545 | if (device_may_wakeup(phy->dev)) |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 546 | enable_irq_wake(motg->irq); |
| 547 | if (bus) |
| 548 | clear_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags); |
| 549 | |
| 550 | atomic_set(&motg->in_lpm, 1); |
| 551 | enable_irq(motg->irq); |
| 552 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 553 | dev_info(phy->dev, "USB in low power mode\n"); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 558 | static int msm_otg_resume(struct msm_otg *motg) |
| 559 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 560 | struct usb_phy *phy = &motg->phy; |
| 561 | struct usb_bus *bus = phy->otg->host; |
Ivan T. Ivanov | cfa3ff5 | 2014-04-28 16:34:17 +0300 | [diff] [blame] | 562 | void __iomem *addr; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 563 | int cnt = 0; |
| 564 | unsigned temp; |
| 565 | |
| 566 | if (!atomic_read(&motg->in_lpm)) |
| 567 | return 0; |
| 568 | |
Stephen Boyd | b99a8f6 | 2013-06-17 10:43:10 -0700 | [diff] [blame] | 569 | clk_prepare_enable(motg->pclk); |
| 570 | clk_prepare_enable(motg->clk); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 571 | if (!IS_ERR(motg->core_clk)) |
Stephen Boyd | b99a8f6 | 2013-06-17 10:43:10 -0700 | [diff] [blame] | 572 | clk_prepare_enable(motg->core_clk); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 573 | |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 574 | if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY && |
| 575 | motg->pdata->otg_control == OTG_PMIC_CONTROL) { |
Ivan T. Ivanov | cfa3ff5 | 2014-04-28 16:34:17 +0300 | [diff] [blame] | 576 | |
| 577 | addr = USB_PHY_CTRL; |
| 578 | if (motg->phy_number) |
| 579 | addr = USB_PHY_CTRL2; |
| 580 | |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 581 | msm_hsusb_ldo_set_mode(motg, 1); |
| 582 | msm_hsusb_config_vddcx(motg, 1); |
Ivan T. Ivanov | cfa3ff5 | 2014-04-28 16:34:17 +0300 | [diff] [blame] | 583 | writel(readl(addr) & ~PHY_RETEN, addr); |
Pavankumar Kondeti | 04aebcb | 2011-05-04 10:19:49 +0530 | [diff] [blame] | 584 | } |
| 585 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 586 | temp = readl(USB_USBCMD); |
| 587 | temp &= ~ASYNC_INTR_CTRL; |
| 588 | temp &= ~ULPI_STP_CTRL; |
| 589 | writel(temp, USB_USBCMD); |
| 590 | |
| 591 | /* |
| 592 | * PHY comes out of low power mode (LPM) in case of wakeup |
| 593 | * from asynchronous interrupt. |
| 594 | */ |
| 595 | if (!(readl(USB_PORTSC) & PORTSC_PHCD)) |
| 596 | goto skip_phy_resume; |
| 597 | |
| 598 | writel(readl(USB_PORTSC) & ~PORTSC_PHCD, USB_PORTSC); |
| 599 | while (cnt < PHY_RESUME_TIMEOUT_USEC) { |
| 600 | if (!(readl(USB_PORTSC) & PORTSC_PHCD)) |
| 601 | break; |
| 602 | udelay(1); |
| 603 | cnt++; |
| 604 | } |
| 605 | |
| 606 | if (cnt >= PHY_RESUME_TIMEOUT_USEC) { |
| 607 | /* |
| 608 | * This is a fatal error. Reset the link and |
| 609 | * PHY. USB state can not be restored. Re-insertion |
| 610 | * of USB cable is the only way to get USB working. |
| 611 | */ |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 612 | dev_err(phy->dev, "Unable to resume USB. Re-plugin the cable\n"); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 613 | msm_otg_reset(phy); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 614 | } |
| 615 | |
| 616 | skip_phy_resume: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 617 | if (device_may_wakeup(phy->dev)) |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 618 | disable_irq_wake(motg->irq); |
| 619 | if (bus) |
| 620 | set_bit(HCD_FLAG_HW_ACCESSIBLE, &(bus_to_hcd(bus))->flags); |
| 621 | |
Pavankumar Kondeti | 2ce2c3a | 2011-05-02 11:56:33 +0530 | [diff] [blame] | 622 | atomic_set(&motg->in_lpm, 0); |
| 623 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 624 | if (motg->async_int) { |
| 625 | motg->async_int = 0; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 626 | pm_runtime_put(phy->dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 627 | enable_irq(motg->irq); |
| 628 | } |
| 629 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 630 | dev_info(phy->dev, "USB exited from low power mode\n"); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 631 | |
| 632 | return 0; |
| 633 | } |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 634 | #endif |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 635 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 636 | static void msm_otg_notify_charger(struct msm_otg *motg, unsigned mA) |
| 637 | { |
| 638 | if (motg->cur_power == mA) |
| 639 | return; |
| 640 | |
| 641 | /* TODO: Notify PMIC about available current */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 642 | dev_info(motg->phy.dev, "Avail curr from USB = %u\n", mA); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 643 | motg->cur_power = mA; |
| 644 | } |
| 645 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 646 | static int msm_otg_set_power(struct usb_phy *phy, unsigned mA) |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 647 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 648 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 649 | |
| 650 | /* |
| 651 | * Gadget driver uses set_power method to notify about the |
| 652 | * available current based on suspend/configured states. |
| 653 | * |
| 654 | * IDEV_CHG can be drawn irrespective of suspend/un-configured |
| 655 | * states when CDP/ACA is connected. |
| 656 | */ |
| 657 | if (motg->chg_type == USB_SDP_CHARGER) |
| 658 | msm_otg_notify_charger(motg, mA); |
| 659 | |
| 660 | return 0; |
| 661 | } |
| 662 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 663 | static void msm_otg_start_host(struct usb_phy *phy, int on) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 664 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 665 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 666 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 667 | struct usb_hcd *hcd; |
| 668 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 669 | if (!phy->otg->host) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 670 | return; |
| 671 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 672 | hcd = bus_to_hcd(phy->otg->host); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 673 | |
| 674 | if (on) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 675 | dev_dbg(phy->dev, "host on\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 676 | |
| 677 | if (pdata->vbus_power) |
| 678 | pdata->vbus_power(1); |
| 679 | /* |
| 680 | * Some boards have a switch cotrolled by gpio |
| 681 | * to enable/disable internal HUB. Enable internal |
| 682 | * HUB before kicking the host. |
| 683 | */ |
| 684 | if (pdata->setup_gpio) |
| 685 | pdata->setup_gpio(OTG_STATE_A_HOST); |
| 686 | #ifdef CONFIG_USB |
| 687 | usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
Peter Chen | 3c9740a | 2013-11-05 10:46:02 +0800 | [diff] [blame] | 688 | device_wakeup_enable(hcd->self.controller); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 689 | #endif |
| 690 | } else { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 691 | dev_dbg(phy->dev, "host off\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 692 | |
| 693 | #ifdef CONFIG_USB |
| 694 | usb_remove_hcd(hcd); |
| 695 | #endif |
| 696 | if (pdata->setup_gpio) |
| 697 | pdata->setup_gpio(OTG_STATE_UNDEFINED); |
| 698 | if (pdata->vbus_power) |
| 699 | pdata->vbus_power(0); |
| 700 | } |
| 701 | } |
| 702 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 703 | 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] | 704 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 705 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 706 | struct usb_hcd *hcd; |
| 707 | |
| 708 | /* |
| 709 | * Fail host registration if this board can support |
| 710 | * only peripheral configuration. |
| 711 | */ |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 712 | if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 713 | dev_info(otg->phy->dev, "Host mode is not supported\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 714 | return -ENODEV; |
| 715 | } |
| 716 | |
| 717 | if (!host) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 718 | if (otg->phy->state == OTG_STATE_A_HOST) { |
| 719 | pm_runtime_get_sync(otg->phy->dev); |
| 720 | msm_otg_start_host(otg->phy, 0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 721 | otg->host = NULL; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 722 | otg->phy->state = OTG_STATE_UNDEFINED; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 723 | schedule_work(&motg->sm_work); |
| 724 | } else { |
| 725 | otg->host = NULL; |
| 726 | } |
| 727 | |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | hcd = bus_to_hcd(host); |
| 732 | hcd->power_budget = motg->pdata->power_budget; |
| 733 | |
| 734 | otg->host = host; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 735 | dev_dbg(otg->phy->dev, "host driver registered w/ tranceiver\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 736 | |
| 737 | /* |
| 738 | * Kick the state machine work, if peripheral is not supported |
| 739 | * or peripheral is already registered with us. |
| 740 | */ |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 741 | if (motg->pdata->mode == USB_DR_MODE_HOST || otg->gadget) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 742 | pm_runtime_get_sync(otg->phy->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 743 | schedule_work(&motg->sm_work); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 744 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 745 | |
| 746 | return 0; |
| 747 | } |
| 748 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 749 | static void msm_otg_start_peripheral(struct usb_phy *phy, int on) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 750 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 751 | struct msm_otg *motg = container_of(phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 752 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 753 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 754 | if (!phy->otg->gadget) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 755 | return; |
| 756 | |
| 757 | if (on) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 758 | dev_dbg(phy->dev, "gadget on\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 759 | /* |
| 760 | * Some boards have a switch cotrolled by gpio |
| 761 | * to enable/disable internal HUB. Disable internal |
| 762 | * HUB before kicking the gadget. |
| 763 | */ |
| 764 | if (pdata->setup_gpio) |
| 765 | pdata->setup_gpio(OTG_STATE_B_PERIPHERAL); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 766 | usb_gadget_vbus_connect(phy->otg->gadget); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 767 | } else { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 768 | dev_dbg(phy->dev, "gadget off\n"); |
| 769 | usb_gadget_vbus_disconnect(phy->otg->gadget); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 770 | if (pdata->setup_gpio) |
| 771 | pdata->setup_gpio(OTG_STATE_UNDEFINED); |
| 772 | } |
| 773 | |
| 774 | } |
| 775 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 776 | static int msm_otg_set_peripheral(struct usb_otg *otg, |
| 777 | struct usb_gadget *gadget) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 778 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 779 | struct msm_otg *motg = container_of(otg->phy, struct msm_otg, phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 780 | |
| 781 | /* |
| 782 | * Fail peripheral registration if this board can support |
| 783 | * only host configuration. |
| 784 | */ |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 785 | if (motg->pdata->mode == USB_DR_MODE_HOST) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 786 | dev_info(otg->phy->dev, "Peripheral mode is not supported\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 787 | return -ENODEV; |
| 788 | } |
| 789 | |
| 790 | if (!gadget) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 791 | if (otg->phy->state == OTG_STATE_B_PERIPHERAL) { |
| 792 | pm_runtime_get_sync(otg->phy->dev); |
| 793 | msm_otg_start_peripheral(otg->phy, 0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 794 | otg->gadget = NULL; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 795 | otg->phy->state = OTG_STATE_UNDEFINED; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 796 | schedule_work(&motg->sm_work); |
| 797 | } else { |
| 798 | otg->gadget = NULL; |
| 799 | } |
| 800 | |
| 801 | return 0; |
| 802 | } |
| 803 | otg->gadget = gadget; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 804 | dev_dbg(otg->phy->dev, "peripheral driver registered w/ tranceiver\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 805 | |
| 806 | /* |
| 807 | * Kick the state machine work, if host is not supported |
| 808 | * or host is already registered with us. |
| 809 | */ |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 810 | if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL || otg->host) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 811 | pm_runtime_get_sync(otg->phy->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 812 | schedule_work(&motg->sm_work); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 813 | } |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 814 | |
| 815 | return 0; |
| 816 | } |
| 817 | |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 818 | static bool msm_chg_check_secondary_det(struct msm_otg *motg) |
| 819 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 820 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 821 | u32 chg_det; |
| 822 | bool ret = false; |
| 823 | |
| 824 | switch (motg->pdata->phy_type) { |
| 825 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 826 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 827 | ret = chg_det & (1 << 4); |
| 828 | break; |
| 829 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 830 | chg_det = ulpi_read(phy, 0x87); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 831 | ret = chg_det & 1; |
| 832 | break; |
| 833 | default: |
| 834 | break; |
| 835 | } |
| 836 | return ret; |
| 837 | } |
| 838 | |
| 839 | static void msm_chg_enable_secondary_det(struct msm_otg *motg) |
| 840 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 841 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 842 | u32 chg_det; |
| 843 | |
| 844 | switch (motg->pdata->phy_type) { |
| 845 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 846 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 847 | /* Turn off charger block */ |
| 848 | chg_det |= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 849 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 850 | udelay(20); |
| 851 | /* control chg block via ULPI */ |
| 852 | chg_det &= ~(1 << 3); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 853 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 854 | /* put it in host mode for enabling D- source */ |
| 855 | chg_det &= ~(1 << 2); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 856 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 857 | /* Turn on chg detect block */ |
| 858 | chg_det &= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 859 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 860 | udelay(20); |
| 861 | /* enable chg detection */ |
| 862 | chg_det &= ~(1 << 0); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 863 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 864 | break; |
| 865 | case SNPS_28NM_INTEGRATED_PHY: |
| 866 | /* |
| 867 | * Configure DM as current source, DP as current sink |
| 868 | * and enable battery charging comparators. |
| 869 | */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 870 | ulpi_write(phy, 0x8, 0x85); |
| 871 | ulpi_write(phy, 0x2, 0x85); |
| 872 | ulpi_write(phy, 0x1, 0x85); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 873 | break; |
| 874 | default: |
| 875 | break; |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | static bool msm_chg_check_primary_det(struct msm_otg *motg) |
| 880 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 881 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 882 | u32 chg_det; |
| 883 | bool ret = false; |
| 884 | |
| 885 | switch (motg->pdata->phy_type) { |
| 886 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 887 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 888 | ret = chg_det & (1 << 4); |
| 889 | break; |
| 890 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 891 | chg_det = ulpi_read(phy, 0x87); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 892 | ret = chg_det & 1; |
| 893 | break; |
| 894 | default: |
| 895 | break; |
| 896 | } |
| 897 | return ret; |
| 898 | } |
| 899 | |
| 900 | static void msm_chg_enable_primary_det(struct msm_otg *motg) |
| 901 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 902 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 903 | u32 chg_det; |
| 904 | |
| 905 | switch (motg->pdata->phy_type) { |
| 906 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 907 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 908 | /* enable chg detection */ |
| 909 | chg_det &= ~(1 << 0); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 910 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 911 | break; |
| 912 | case SNPS_28NM_INTEGRATED_PHY: |
| 913 | /* |
| 914 | * Configure DP as current source, DM as current sink |
| 915 | * and enable battery charging comparators. |
| 916 | */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 917 | ulpi_write(phy, 0x2, 0x85); |
| 918 | ulpi_write(phy, 0x1, 0x85); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 919 | break; |
| 920 | default: |
| 921 | break; |
| 922 | } |
| 923 | } |
| 924 | |
| 925 | static bool msm_chg_check_dcd(struct msm_otg *motg) |
| 926 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 927 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 928 | u32 line_state; |
| 929 | bool ret = false; |
| 930 | |
| 931 | switch (motg->pdata->phy_type) { |
| 932 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 933 | line_state = ulpi_read(phy, 0x15); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 934 | ret = !(line_state & 1); |
| 935 | break; |
| 936 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 937 | line_state = ulpi_read(phy, 0x87); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 938 | ret = line_state & 2; |
| 939 | break; |
| 940 | default: |
| 941 | break; |
| 942 | } |
| 943 | return ret; |
| 944 | } |
| 945 | |
| 946 | static void msm_chg_disable_dcd(struct msm_otg *motg) |
| 947 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 948 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 949 | u32 chg_det; |
| 950 | |
| 951 | switch (motg->pdata->phy_type) { |
| 952 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 953 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 954 | chg_det &= ~(1 << 5); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 955 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 956 | break; |
| 957 | case SNPS_28NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 958 | ulpi_write(phy, 0x10, 0x86); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 959 | break; |
| 960 | default: |
| 961 | break; |
| 962 | } |
| 963 | } |
| 964 | |
| 965 | static void msm_chg_enable_dcd(struct msm_otg *motg) |
| 966 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 967 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 968 | u32 chg_det; |
| 969 | |
| 970 | switch (motg->pdata->phy_type) { |
| 971 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 972 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 973 | /* Turn on D+ current source */ |
| 974 | chg_det |= (1 << 5); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 975 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 976 | break; |
| 977 | case SNPS_28NM_INTEGRATED_PHY: |
| 978 | /* Data contact detection enable */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 979 | ulpi_write(phy, 0x10, 0x85); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 980 | break; |
| 981 | default: |
| 982 | break; |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | static void msm_chg_block_on(struct msm_otg *motg) |
| 987 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 988 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 989 | u32 func_ctrl, chg_det; |
| 990 | |
| 991 | /* put the controller in non-driving mode */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 992 | func_ctrl = ulpi_read(phy, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 993 | func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
| 994 | func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 995 | ulpi_write(phy, func_ctrl, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 996 | |
| 997 | switch (motg->pdata->phy_type) { |
| 998 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 999 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1000 | /* control chg block via ULPI */ |
| 1001 | chg_det &= ~(1 << 3); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1002 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1003 | /* Turn on chg detect block */ |
| 1004 | chg_det &= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1005 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1006 | udelay(20); |
| 1007 | break; |
| 1008 | case SNPS_28NM_INTEGRATED_PHY: |
| 1009 | /* Clear charger detecting control bits */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1010 | ulpi_write(phy, 0x3F, 0x86); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1011 | /* Clear alt interrupt latch and enable bits */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1012 | ulpi_write(phy, 0x1F, 0x92); |
| 1013 | ulpi_write(phy, 0x1F, 0x95); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1014 | udelay(100); |
| 1015 | break; |
| 1016 | default: |
| 1017 | break; |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | static void msm_chg_block_off(struct msm_otg *motg) |
| 1022 | { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1023 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1024 | u32 func_ctrl, chg_det; |
| 1025 | |
| 1026 | switch (motg->pdata->phy_type) { |
| 1027 | case CI_45NM_INTEGRATED_PHY: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1028 | chg_det = ulpi_read(phy, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1029 | /* Turn off charger block */ |
| 1030 | chg_det |= ~(1 << 1); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1031 | ulpi_write(phy, chg_det, 0x34); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1032 | break; |
| 1033 | case SNPS_28NM_INTEGRATED_PHY: |
| 1034 | /* Clear charger detecting control bits */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1035 | ulpi_write(phy, 0x3F, 0x86); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1036 | /* Clear alt interrupt latch and enable bits */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1037 | ulpi_write(phy, 0x1F, 0x92); |
| 1038 | ulpi_write(phy, 0x1F, 0x95); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1039 | break; |
| 1040 | default: |
| 1041 | break; |
| 1042 | } |
| 1043 | |
| 1044 | /* put the controller in normal mode */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1045 | func_ctrl = ulpi_read(phy, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1046 | func_ctrl &= ~ULPI_FUNC_CTRL_OPMODE_MASK; |
| 1047 | func_ctrl |= ULPI_FUNC_CTRL_OPMODE_NORMAL; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1048 | ulpi_write(phy, func_ctrl, ULPI_FUNC_CTRL); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | #define MSM_CHG_DCD_POLL_TIME (100 * HZ/1000) /* 100 msec */ |
| 1052 | #define MSM_CHG_DCD_MAX_RETRIES 6 /* Tdcd_tmout = 6 * 100 msec */ |
| 1053 | #define MSM_CHG_PRIMARY_DET_TIME (40 * HZ/1000) /* TVDPSRC_ON */ |
| 1054 | #define MSM_CHG_SECONDARY_DET_TIME (40 * HZ/1000) /* TVDMSRC_ON */ |
| 1055 | static void msm_chg_detect_work(struct work_struct *w) |
| 1056 | { |
| 1057 | 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] | 1058 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1059 | bool is_dcd, tmout, vout; |
| 1060 | unsigned long delay; |
| 1061 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1062 | dev_dbg(phy->dev, "chg detection work\n"); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1063 | switch (motg->chg_state) { |
| 1064 | case USB_CHG_STATE_UNDEFINED: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1065 | pm_runtime_get_sync(phy->dev); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1066 | msm_chg_block_on(motg); |
| 1067 | msm_chg_enable_dcd(motg); |
| 1068 | motg->chg_state = USB_CHG_STATE_WAIT_FOR_DCD; |
| 1069 | motg->dcd_retries = 0; |
| 1070 | delay = MSM_CHG_DCD_POLL_TIME; |
| 1071 | break; |
| 1072 | case USB_CHG_STATE_WAIT_FOR_DCD: |
| 1073 | is_dcd = msm_chg_check_dcd(motg); |
| 1074 | tmout = ++motg->dcd_retries == MSM_CHG_DCD_MAX_RETRIES; |
| 1075 | if (is_dcd || tmout) { |
| 1076 | msm_chg_disable_dcd(motg); |
| 1077 | msm_chg_enable_primary_det(motg); |
| 1078 | delay = MSM_CHG_PRIMARY_DET_TIME; |
| 1079 | motg->chg_state = USB_CHG_STATE_DCD_DONE; |
| 1080 | } else { |
| 1081 | delay = MSM_CHG_DCD_POLL_TIME; |
| 1082 | } |
| 1083 | break; |
| 1084 | case USB_CHG_STATE_DCD_DONE: |
| 1085 | vout = msm_chg_check_primary_det(motg); |
| 1086 | if (vout) { |
| 1087 | msm_chg_enable_secondary_det(motg); |
| 1088 | delay = MSM_CHG_SECONDARY_DET_TIME; |
| 1089 | motg->chg_state = USB_CHG_STATE_PRIMARY_DONE; |
| 1090 | } else { |
| 1091 | motg->chg_type = USB_SDP_CHARGER; |
| 1092 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1093 | delay = 0; |
| 1094 | } |
| 1095 | break; |
| 1096 | case USB_CHG_STATE_PRIMARY_DONE: |
| 1097 | vout = msm_chg_check_secondary_det(motg); |
| 1098 | if (vout) |
| 1099 | motg->chg_type = USB_DCP_CHARGER; |
| 1100 | else |
| 1101 | motg->chg_type = USB_CDP_CHARGER; |
| 1102 | motg->chg_state = USB_CHG_STATE_SECONDARY_DONE; |
| 1103 | /* fall through */ |
| 1104 | case USB_CHG_STATE_SECONDARY_DONE: |
| 1105 | motg->chg_state = USB_CHG_STATE_DETECTED; |
| 1106 | case USB_CHG_STATE_DETECTED: |
| 1107 | msm_chg_block_off(motg); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1108 | dev_dbg(phy->dev, "charger = %d\n", motg->chg_type); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1109 | schedule_work(&motg->sm_work); |
| 1110 | return; |
| 1111 | default: |
| 1112 | return; |
| 1113 | } |
| 1114 | |
| 1115 | schedule_delayed_work(&motg->chg_work, delay); |
| 1116 | } |
| 1117 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1118 | /* |
| 1119 | * We support OTG, Peripheral only and Host only configurations. In case |
| 1120 | * of OTG, mode switch (host-->peripheral/peripheral-->host) can happen |
| 1121 | * via Id pin status or user request (debugfs). Id/BSV interrupts are not |
| 1122 | * enabled when switch is controlled by user and default mode is supplied |
| 1123 | * by board file, which can be changed by userspace later. |
| 1124 | */ |
| 1125 | static void msm_otg_init_sm(struct msm_otg *motg) |
| 1126 | { |
| 1127 | struct msm_otg_platform_data *pdata = motg->pdata; |
| 1128 | u32 otgsc = readl(USB_OTGSC); |
| 1129 | |
| 1130 | switch (pdata->mode) { |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1131 | case USB_DR_MODE_OTG: |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1132 | if (pdata->otg_control == OTG_PHY_CONTROL) { |
| 1133 | if (otgsc & OTGSC_ID) |
| 1134 | set_bit(ID, &motg->inputs); |
| 1135 | else |
| 1136 | clear_bit(ID, &motg->inputs); |
| 1137 | |
| 1138 | if (otgsc & OTGSC_BSV) |
| 1139 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1140 | else |
| 1141 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 1142 | } else if (pdata->otg_control == OTG_USER_CONTROL) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1143 | set_bit(ID, &motg->inputs); |
| 1144 | clear_bit(B_SESS_VLD, &motg->inputs); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1145 | } |
| 1146 | break; |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1147 | case USB_DR_MODE_HOST: |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1148 | clear_bit(ID, &motg->inputs); |
| 1149 | break; |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1150 | case USB_DR_MODE_PERIPHERAL: |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1151 | set_bit(ID, &motg->inputs); |
| 1152 | if (otgsc & OTGSC_BSV) |
| 1153 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1154 | else |
| 1155 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 1156 | break; |
| 1157 | default: |
| 1158 | break; |
| 1159 | } |
| 1160 | } |
| 1161 | |
| 1162 | static void msm_otg_sm_work(struct work_struct *w) |
| 1163 | { |
| 1164 | struct msm_otg *motg = container_of(w, struct msm_otg, sm_work); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1165 | struct usb_otg *otg = motg->phy.otg; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1166 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1167 | switch (otg->phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1168 | case OTG_STATE_UNDEFINED: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1169 | dev_dbg(otg->phy->dev, "OTG_STATE_UNDEFINED state\n"); |
| 1170 | msm_otg_reset(otg->phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1171 | msm_otg_init_sm(motg); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1172 | otg->phy->state = OTG_STATE_B_IDLE; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1173 | /* FALL THROUGH */ |
| 1174 | case OTG_STATE_B_IDLE: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1175 | dev_dbg(otg->phy->dev, "OTG_STATE_B_IDLE state\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1176 | if (!test_bit(ID, &motg->inputs) && otg->host) { |
| 1177 | /* disable BSV bit */ |
| 1178 | writel(readl(USB_OTGSC) & ~OTGSC_BSVIE, USB_OTGSC); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1179 | msm_otg_start_host(otg->phy, 1); |
| 1180 | otg->phy->state = OTG_STATE_A_HOST; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1181 | } else if (test_bit(B_SESS_VLD, &motg->inputs)) { |
| 1182 | switch (motg->chg_state) { |
| 1183 | case USB_CHG_STATE_UNDEFINED: |
| 1184 | msm_chg_detect_work(&motg->chg_work.work); |
| 1185 | break; |
| 1186 | case USB_CHG_STATE_DETECTED: |
| 1187 | switch (motg->chg_type) { |
| 1188 | case USB_DCP_CHARGER: |
| 1189 | msm_otg_notify_charger(motg, |
| 1190 | IDEV_CHG_MAX); |
| 1191 | break; |
| 1192 | case USB_CDP_CHARGER: |
| 1193 | msm_otg_notify_charger(motg, |
| 1194 | IDEV_CHG_MAX); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1195 | msm_otg_start_peripheral(otg->phy, 1); |
| 1196 | otg->phy->state |
| 1197 | = OTG_STATE_B_PERIPHERAL; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1198 | break; |
| 1199 | case USB_SDP_CHARGER: |
| 1200 | msm_otg_notify_charger(motg, IUNIT); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1201 | msm_otg_start_peripheral(otg->phy, 1); |
| 1202 | otg->phy->state |
| 1203 | = OTG_STATE_B_PERIPHERAL; |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1204 | break; |
| 1205 | default: |
| 1206 | break; |
| 1207 | } |
| 1208 | break; |
| 1209 | default: |
| 1210 | break; |
| 1211 | } |
| 1212 | } else { |
| 1213 | /* |
| 1214 | * If charger detection work is pending, decrement |
| 1215 | * the pm usage counter to balance with the one that |
| 1216 | * is incremented in charger detection work. |
| 1217 | */ |
| 1218 | if (cancel_delayed_work_sync(&motg->chg_work)) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1219 | pm_runtime_put_sync(otg->phy->dev); |
| 1220 | msm_otg_reset(otg->phy); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1221 | } |
| 1222 | msm_otg_notify_charger(motg, 0); |
| 1223 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1224 | motg->chg_type = USB_INVALID_CHARGER; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1225 | } |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1226 | pm_runtime_put_sync(otg->phy->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1227 | break; |
| 1228 | case OTG_STATE_B_PERIPHERAL: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1229 | dev_dbg(otg->phy->dev, "OTG_STATE_B_PERIPHERAL state\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1230 | if (!test_bit(B_SESS_VLD, &motg->inputs) || |
| 1231 | !test_bit(ID, &motg->inputs)) { |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1232 | msm_otg_notify_charger(motg, 0); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1233 | msm_otg_start_peripheral(otg->phy, 0); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1234 | motg->chg_state = USB_CHG_STATE_UNDEFINED; |
| 1235 | motg->chg_type = USB_INVALID_CHARGER; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1236 | otg->phy->state = OTG_STATE_B_IDLE; |
| 1237 | msm_otg_reset(otg->phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1238 | schedule_work(w); |
| 1239 | } |
| 1240 | break; |
| 1241 | case OTG_STATE_A_HOST: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1242 | dev_dbg(otg->phy->dev, "OTG_STATE_A_HOST state\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1243 | if (test_bit(ID, &motg->inputs)) { |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1244 | msm_otg_start_host(otg->phy, 0); |
| 1245 | otg->phy->state = OTG_STATE_B_IDLE; |
| 1246 | msm_otg_reset(otg->phy); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1247 | schedule_work(w); |
| 1248 | } |
| 1249 | break; |
| 1250 | default: |
| 1251 | break; |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | static irqreturn_t msm_otg_irq(int irq, void *data) |
| 1256 | { |
| 1257 | struct msm_otg *motg = data; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1258 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1259 | u32 otgsc = 0; |
| 1260 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1261 | if (atomic_read(&motg->in_lpm)) { |
| 1262 | disable_irq_nosync(irq); |
| 1263 | motg->async_int = 1; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1264 | pm_runtime_get(phy->dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1265 | return IRQ_HANDLED; |
| 1266 | } |
| 1267 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1268 | otgsc = readl(USB_OTGSC); |
| 1269 | if (!(otgsc & (OTGSC_IDIS | OTGSC_BSVIS))) |
| 1270 | return IRQ_NONE; |
| 1271 | |
| 1272 | if ((otgsc & OTGSC_IDIS) && (otgsc & OTGSC_IDIE)) { |
| 1273 | if (otgsc & OTGSC_ID) |
| 1274 | set_bit(ID, &motg->inputs); |
| 1275 | else |
| 1276 | clear_bit(ID, &motg->inputs); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1277 | dev_dbg(phy->dev, "ID set/clear\n"); |
| 1278 | pm_runtime_get_noresume(phy->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1279 | } else if ((otgsc & OTGSC_BSVIS) && (otgsc & OTGSC_BSVIE)) { |
| 1280 | if (otgsc & OTGSC_BSV) |
| 1281 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1282 | else |
| 1283 | clear_bit(B_SESS_VLD, &motg->inputs); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1284 | dev_dbg(phy->dev, "BSV set/clear\n"); |
| 1285 | pm_runtime_get_noresume(phy->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | writel(otgsc, USB_OTGSC); |
| 1289 | schedule_work(&motg->sm_work); |
| 1290 | return IRQ_HANDLED; |
| 1291 | } |
| 1292 | |
| 1293 | static int msm_otg_mode_show(struct seq_file *s, void *unused) |
| 1294 | { |
| 1295 | struct msm_otg *motg = s->private; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1296 | struct usb_otg *otg = motg->phy.otg; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1297 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1298 | switch (otg->phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1299 | case OTG_STATE_A_HOST: |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 1300 | seq_puts(s, "host\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1301 | break; |
| 1302 | case OTG_STATE_B_PERIPHERAL: |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 1303 | seq_puts(s, "peripheral\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1304 | break; |
| 1305 | default: |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 1306 | seq_puts(s, "none\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1307 | break; |
| 1308 | } |
| 1309 | |
| 1310 | return 0; |
| 1311 | } |
| 1312 | |
| 1313 | static int msm_otg_mode_open(struct inode *inode, struct file *file) |
| 1314 | { |
| 1315 | return single_open(file, msm_otg_mode_show, inode->i_private); |
| 1316 | } |
| 1317 | |
| 1318 | static ssize_t msm_otg_mode_write(struct file *file, const char __user *ubuf, |
| 1319 | size_t count, loff_t *ppos) |
| 1320 | { |
Pavankumar Kondeti | e2904ee | 2011-02-15 09:42:35 +0530 | [diff] [blame] | 1321 | struct seq_file *s = file->private_data; |
| 1322 | struct msm_otg *motg = s->private; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1323 | char buf[16]; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1324 | struct usb_otg *otg = motg->phy.otg; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1325 | int status = count; |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1326 | enum usb_dr_mode req_mode; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1327 | |
| 1328 | memset(buf, 0x00, sizeof(buf)); |
| 1329 | |
| 1330 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) { |
| 1331 | status = -EFAULT; |
| 1332 | goto out; |
| 1333 | } |
| 1334 | |
| 1335 | if (!strncmp(buf, "host", 4)) { |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1336 | req_mode = USB_DR_MODE_HOST; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1337 | } else if (!strncmp(buf, "peripheral", 10)) { |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1338 | req_mode = USB_DR_MODE_PERIPHERAL; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1339 | } else if (!strncmp(buf, "none", 4)) { |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1340 | req_mode = USB_DR_MODE_UNKNOWN; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1341 | } else { |
| 1342 | status = -EINVAL; |
| 1343 | goto out; |
| 1344 | } |
| 1345 | |
| 1346 | switch (req_mode) { |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1347 | case USB_DR_MODE_UNKNOWN: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1348 | switch (otg->phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1349 | case OTG_STATE_A_HOST: |
| 1350 | case OTG_STATE_B_PERIPHERAL: |
| 1351 | set_bit(ID, &motg->inputs); |
| 1352 | clear_bit(B_SESS_VLD, &motg->inputs); |
| 1353 | break; |
| 1354 | default: |
| 1355 | goto out; |
| 1356 | } |
| 1357 | break; |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1358 | case USB_DR_MODE_PERIPHERAL: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1359 | switch (otg->phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1360 | case OTG_STATE_B_IDLE: |
| 1361 | case OTG_STATE_A_HOST: |
| 1362 | set_bit(ID, &motg->inputs); |
| 1363 | set_bit(B_SESS_VLD, &motg->inputs); |
| 1364 | break; |
| 1365 | default: |
| 1366 | goto out; |
| 1367 | } |
| 1368 | break; |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1369 | case USB_DR_MODE_HOST: |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1370 | switch (otg->phy->state) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1371 | case OTG_STATE_B_IDLE: |
| 1372 | case OTG_STATE_B_PERIPHERAL: |
| 1373 | clear_bit(ID, &motg->inputs); |
| 1374 | break; |
| 1375 | default: |
| 1376 | goto out; |
| 1377 | } |
| 1378 | break; |
| 1379 | default: |
| 1380 | goto out; |
| 1381 | } |
| 1382 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1383 | pm_runtime_get_sync(otg->phy->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1384 | schedule_work(&motg->sm_work); |
| 1385 | out: |
| 1386 | return status; |
| 1387 | } |
| 1388 | |
| 1389 | const struct file_operations msm_otg_mode_fops = { |
| 1390 | .open = msm_otg_mode_open, |
| 1391 | .read = seq_read, |
| 1392 | .write = msm_otg_mode_write, |
| 1393 | .llseek = seq_lseek, |
| 1394 | .release = single_release, |
| 1395 | }; |
| 1396 | |
| 1397 | static struct dentry *msm_otg_dbg_root; |
| 1398 | static struct dentry *msm_otg_dbg_mode; |
| 1399 | |
| 1400 | static int msm_otg_debugfs_init(struct msm_otg *motg) |
| 1401 | { |
| 1402 | msm_otg_dbg_root = debugfs_create_dir("msm_otg", NULL); |
| 1403 | |
| 1404 | if (!msm_otg_dbg_root || IS_ERR(msm_otg_dbg_root)) |
| 1405 | return -ENODEV; |
| 1406 | |
| 1407 | msm_otg_dbg_mode = debugfs_create_file("mode", S_IRUGO | S_IWUSR, |
| 1408 | msm_otg_dbg_root, motg, &msm_otg_mode_fops); |
| 1409 | if (!msm_otg_dbg_mode) { |
| 1410 | debugfs_remove(msm_otg_dbg_root); |
| 1411 | msm_otg_dbg_root = NULL; |
| 1412 | return -ENODEV; |
| 1413 | } |
| 1414 | |
| 1415 | return 0; |
| 1416 | } |
| 1417 | |
| 1418 | static void msm_otg_debugfs_cleanup(void) |
| 1419 | { |
| 1420 | debugfs_remove(msm_otg_dbg_mode); |
| 1421 | debugfs_remove(msm_otg_dbg_root); |
| 1422 | } |
| 1423 | |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1424 | static struct of_device_id msm_otg_dt_match[] = { |
| 1425 | { |
| 1426 | .compatible = "qcom,usb-otg-ci", |
| 1427 | .data = (void *) CI_45NM_INTEGRATED_PHY |
| 1428 | }, |
| 1429 | { |
| 1430 | .compatible = "qcom,usb-otg-snps", |
| 1431 | .data = (void *) SNPS_28NM_INTEGRATED_PHY |
| 1432 | }, |
| 1433 | { } |
| 1434 | }; |
| 1435 | MODULE_DEVICE_TABLE(of, msm_otg_dt_match); |
| 1436 | |
| 1437 | static int msm_otg_read_dt(struct platform_device *pdev, struct msm_otg *motg) |
| 1438 | { |
| 1439 | struct msm_otg_platform_data *pdata; |
| 1440 | const struct of_device_id *id; |
| 1441 | struct device_node *node = pdev->dev.of_node; |
| 1442 | struct property *prop; |
| 1443 | int len, ret, words; |
| 1444 | u32 val; |
| 1445 | |
| 1446 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 1447 | if (!pdata) |
| 1448 | return -ENOMEM; |
| 1449 | |
| 1450 | motg->pdata = pdata; |
| 1451 | |
| 1452 | id = of_match_device(msm_otg_dt_match, &pdev->dev); |
| 1453 | pdata->phy_type = (int) id->data; |
| 1454 | |
Ivan T. Ivanov | a273454 | 2014-04-28 16:34:16 +0300 | [diff] [blame] | 1455 | motg->link_rst = devm_reset_control_get(&pdev->dev, "link"); |
| 1456 | if (IS_ERR(motg->link_rst)) |
| 1457 | return PTR_ERR(motg->link_rst); |
| 1458 | |
| 1459 | motg->phy_rst = devm_reset_control_get(&pdev->dev, "phy"); |
| 1460 | if (IS_ERR(motg->phy_rst)) |
| 1461 | return PTR_ERR(motg->phy_rst); |
| 1462 | |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1463 | pdata->mode = of_usb_get_dr_mode(node); |
| 1464 | if (pdata->mode == USB_DR_MODE_UNKNOWN) |
| 1465 | pdata->mode = USB_DR_MODE_OTG; |
| 1466 | |
| 1467 | pdata->otg_control = OTG_PHY_CONTROL; |
| 1468 | if (!of_property_read_u32(node, "qcom,otg-control", &val)) |
| 1469 | if (val == OTG_PMIC_CONTROL) |
| 1470 | pdata->otg_control = val; |
| 1471 | |
Ivan T. Ivanov | cfa3ff5 | 2014-04-28 16:34:17 +0300 | [diff] [blame] | 1472 | if (!of_property_read_u32(node, "qcom,phy-num", &val) && val < 2) |
| 1473 | motg->phy_number = val; |
| 1474 | |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1475 | prop = of_find_property(node, "qcom,phy-init-sequence", &len); |
| 1476 | if (!prop || !len) |
| 1477 | return 0; |
| 1478 | |
| 1479 | words = len / sizeof(u32); |
| 1480 | |
| 1481 | if (words >= ULPI_EXT_VENDOR_SPECIFIC) { |
| 1482 | dev_warn(&pdev->dev, "Too big PHY init sequence %d\n", words); |
| 1483 | return 0; |
| 1484 | } |
| 1485 | |
| 1486 | pdata->phy_init_seq = devm_kzalloc(&pdev->dev, len, GFP_KERNEL); |
| 1487 | if (!pdata->phy_init_seq) { |
| 1488 | dev_warn(&pdev->dev, "No space for PHY init sequence\n"); |
| 1489 | return 0; |
| 1490 | } |
| 1491 | |
| 1492 | ret = of_property_read_u32_array(node, "qcom,phy-init-sequence", |
| 1493 | pdata->phy_init_seq, words); |
| 1494 | if (!ret) |
| 1495 | pdata->phy_init_sz = words; |
| 1496 | |
| 1497 | return 0; |
| 1498 | } |
| 1499 | |
Ivan T. Ivanov | 06a6ec4 | 2014-04-28 16:34:07 +0300 | [diff] [blame] | 1500 | static int msm_otg_probe(struct platform_device *pdev) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1501 | { |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1502 | struct regulator_bulk_data regs[3]; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1503 | int ret = 0; |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1504 | struct device_node *np = pdev->dev.of_node; |
| 1505 | struct msm_otg_platform_data *pdata; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1506 | struct resource *res; |
| 1507 | struct msm_otg *motg; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1508 | struct usb_phy *phy; |
Tim Bird | 30bf866 | 2014-04-28 16:34:20 +0300 | [diff] [blame] | 1509 | void __iomem *phy_select; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1510 | |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1511 | motg = devm_kzalloc(&pdev->dev, sizeof(struct msm_otg), GFP_KERNEL); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1512 | if (!motg) { |
| 1513 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); |
| 1514 | return -ENOMEM; |
| 1515 | } |
| 1516 | |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1517 | pdata = dev_get_platdata(&pdev->dev); |
| 1518 | if (!pdata) { |
| 1519 | if (!np) |
| 1520 | return -ENXIO; |
| 1521 | ret = msm_otg_read_dt(pdev, motg); |
| 1522 | if (ret) |
| 1523 | return ret; |
| 1524 | } |
| 1525 | |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1526 | motg->phy.otg = devm_kzalloc(&pdev->dev, sizeof(struct usb_otg), |
| 1527 | GFP_KERNEL); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1528 | if (!motg->phy.otg) { |
| 1529 | dev_err(&pdev->dev, "unable to allocate msm_otg\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1530 | return -ENOMEM; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1531 | } |
| 1532 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1533 | phy = &motg->phy; |
| 1534 | phy->dev = &pdev->dev; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1535 | |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1536 | motg->phy_reset_clk = devm_clk_get(&pdev->dev, |
| 1537 | np ? "phy" : "usb_phy_clk"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1538 | if (IS_ERR(motg->phy_reset_clk)) { |
| 1539 | dev_err(&pdev->dev, "failed to get usb_phy_clk\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1540 | return PTR_ERR(motg->phy_reset_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1541 | } |
| 1542 | |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1543 | motg->clk = devm_clk_get(&pdev->dev, np ? "core" : "usb_hs_clk"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1544 | if (IS_ERR(motg->clk)) { |
| 1545 | dev_err(&pdev->dev, "failed to get usb_hs_clk\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1546 | return PTR_ERR(motg->clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1547 | } |
Anji jonnala | 0f73cac8 | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 1548 | |
| 1549 | /* |
| 1550 | * If USB Core is running its protocol engine based on CORE CLK, |
| 1551 | * CORE CLK must be running at >55Mhz for correct HSUSB |
| 1552 | * operation and USB core cannot tolerate frequency changes on |
Ivan T. Ivanov | ff0e4a6 | 2014-04-28 16:34:12 +0300 | [diff] [blame] | 1553 | * CORE CLK. |
Anji jonnala | 0f73cac8 | 2011-05-04 10:19:46 +0530 | [diff] [blame] | 1554 | */ |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1555 | motg->pclk = devm_clk_get(&pdev->dev, np ? "iface" : "usb_hs_pclk"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1556 | if (IS_ERR(motg->pclk)) { |
| 1557 | dev_err(&pdev->dev, "failed to get usb_hs_pclk\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1558 | return PTR_ERR(motg->pclk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | /* |
| 1562 | * USB core clock is not present on all MSM chips. This |
| 1563 | * clock is introduced to remove the dependency on AXI |
| 1564 | * bus frequency. |
| 1565 | */ |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1566 | motg->core_clk = devm_clk_get(&pdev->dev, |
| 1567 | np ? "alt_core" : "usb_hs_core_clk"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1568 | |
| 1569 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1570 | motg->regs = devm_ioremap(&pdev->dev, res->start, resource_size(res)); |
| 1571 | if (IS_ERR(motg->regs)) |
| 1572 | return PTR_ERR(motg->regs); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1573 | |
Tim Bird | 30bf866 | 2014-04-28 16:34:20 +0300 | [diff] [blame] | 1574 | /* |
| 1575 | * NOTE: The PHYs can be multiplexed between the chipidea controller |
| 1576 | * and the dwc3 controller, using a single bit. It is important that |
| 1577 | * the dwc3 driver does not set this bit in an incompatible way. |
| 1578 | */ |
| 1579 | if (motg->phy_number) { |
| 1580 | phy_select = devm_ioremap_nocache(&pdev->dev, USB2_PHY_SEL, 4); |
| 1581 | if (IS_ERR(phy_select)) |
| 1582 | return PTR_ERR(phy_select); |
| 1583 | /* Enable second PHY with the OTG port */ |
| 1584 | writel_relaxed(0x1, phy_select); |
| 1585 | } |
| 1586 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1587 | dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs); |
| 1588 | |
| 1589 | motg->irq = platform_get_irq(pdev, 0); |
Ivan T. Ivanov | f60c114 | 2014-04-28 16:34:14 +0300 | [diff] [blame] | 1590 | if (motg->irq < 0) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1591 | dev_err(&pdev->dev, "platform_get_irq failed\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1592 | return motg->irq; |
| 1593 | } |
| 1594 | |
Ivan T. Ivanov | f5ef237 | 2014-04-28 16:34:13 +0300 | [diff] [blame] | 1595 | regs[0].supply = "vddcx"; |
| 1596 | regs[1].supply = "v3p3"; |
| 1597 | regs[2].supply = "v1p8"; |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1598 | |
| 1599 | ret = devm_regulator_bulk_get(motg->phy.dev, ARRAY_SIZE(regs), regs); |
| 1600 | if (ret) |
| 1601 | return ret; |
| 1602 | |
| 1603 | motg->vddcx = regs[0].consumer; |
| 1604 | motg->v3p3 = regs[1].consumer; |
| 1605 | motg->v1p8 = regs[2].consumer; |
| 1606 | |
| 1607 | clk_set_rate(motg->clk, 60000000); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1608 | |
Stephen Boyd | b99a8f6 | 2013-06-17 10:43:10 -0700 | [diff] [blame] | 1609 | clk_prepare_enable(motg->clk); |
| 1610 | clk_prepare_enable(motg->pclk); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 1611 | |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1612 | if (!IS_ERR(motg->core_clk)) |
| 1613 | clk_prepare_enable(motg->core_clk); |
| 1614 | |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 1615 | ret = msm_hsusb_init_vddcx(motg, 1); |
| 1616 | if (ret) { |
| 1617 | dev_err(&pdev->dev, "hsusb vddcx configuration failed\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1618 | goto disable_clks; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | ret = msm_hsusb_ldo_init(motg, 1); |
| 1622 | if (ret) { |
| 1623 | dev_err(&pdev->dev, "hsusb vreg configuration failed\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1624 | goto disable_vddcx; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 1625 | } |
Ivan T. Ivanov | 37cfdaf | 2014-04-28 16:34:06 +0300 | [diff] [blame] | 1626 | ret = msm_hsusb_ldo_set_mode(motg, 1); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 1627 | if (ret) { |
| 1628 | dev_err(&pdev->dev, "hsusb vreg enable failed\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1629 | goto disable_ldo; |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 1630 | } |
| 1631 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1632 | writel(0, USB_USBINTR); |
| 1633 | writel(0, USB_OTGSC); |
| 1634 | |
| 1635 | INIT_WORK(&motg->sm_work, msm_otg_sm_work); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1636 | INIT_DELAYED_WORK(&motg->chg_work, msm_chg_detect_work); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1637 | ret = devm_request_irq(&pdev->dev, motg->irq, msm_otg_irq, IRQF_SHARED, |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1638 | "msm_otg", motg); |
| 1639 | if (ret) { |
| 1640 | dev_err(&pdev->dev, "request irq failed\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1641 | goto disable_ldo; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1642 | } |
| 1643 | |
Ivan T. Ivanov | d69c6f5 | 2014-04-28 16:34:18 +0300 | [diff] [blame] | 1644 | phy->init = msm_phy_init; |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1645 | phy->set_power = msm_otg_set_power; |
Ivan T. Ivanov | 349907c | 2014-04-28 16:34:21 +0300 | [diff] [blame^] | 1646 | phy->notify_disconnect = msm_phy_notify_disconnect; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1647 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1648 | phy->io_ops = &msm_otg_io_ops; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1649 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1650 | phy->otg->phy = &motg->phy; |
| 1651 | phy->otg->set_host = msm_otg_set_host; |
| 1652 | phy->otg->set_peripheral = msm_otg_set_peripheral; |
| 1653 | |
Ivan T. Ivanov | d69c6f5 | 2014-04-28 16:34:18 +0300 | [diff] [blame] | 1654 | msm_usb_reset(phy); |
| 1655 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 1656 | ret = usb_add_phy(&motg->phy, USB_PHY_TYPE_USB2); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1657 | if (ret) { |
Kishon Vijay Abraham I | 721002e | 2012-06-22 17:02:45 +0530 | [diff] [blame] | 1658 | dev_err(&pdev->dev, "usb_add_phy failed\n"); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1659 | goto disable_ldo; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | platform_set_drvdata(pdev, motg); |
| 1663 | device_init_wakeup(&pdev->dev, 1); |
| 1664 | |
Ivan T. Ivanov | 971232c | 2014-04-28 16:34:11 +0300 | [diff] [blame] | 1665 | if (motg->pdata->mode == USB_DR_MODE_OTG && |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1666 | motg->pdata->otg_control == OTG_USER_CONTROL) { |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1667 | ret = msm_otg_debugfs_init(motg); |
| 1668 | if (ret) |
Ivan T. Ivanov | 3aca0fa | 2014-04-28 16:34:10 +0300 | [diff] [blame] | 1669 | dev_dbg(&pdev->dev, "Can not create mode change file\n"); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1670 | } |
| 1671 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1672 | pm_runtime_set_active(&pdev->dev); |
| 1673 | pm_runtime_enable(&pdev->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1674 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1675 | return 0; |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1676 | |
| 1677 | disable_ldo: |
| 1678 | msm_hsusb_ldo_init(motg, 0); |
| 1679 | disable_vddcx: |
| 1680 | msm_hsusb_init_vddcx(motg, 0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1681 | disable_clks: |
Stephen Boyd | b99a8f6 | 2013-06-17 10:43:10 -0700 | [diff] [blame] | 1682 | clk_disable_unprepare(motg->pclk); |
| 1683 | clk_disable_unprepare(motg->clk); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1684 | if (!IS_ERR(motg->core_clk)) |
| 1685 | clk_disable_unprepare(motg->core_clk); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1686 | return ret; |
| 1687 | } |
| 1688 | |
Bill Pemberton | fb4e98a | 2012-11-19 13:26:20 -0500 | [diff] [blame] | 1689 | static int msm_otg_remove(struct platform_device *pdev) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1690 | { |
| 1691 | struct msm_otg *motg = platform_get_drvdata(pdev); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1692 | struct usb_phy *phy = &motg->phy; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1693 | int cnt = 0; |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1694 | |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1695 | if (phy->otg->host || phy->otg->gadget) |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1696 | return -EBUSY; |
| 1697 | |
| 1698 | msm_otg_debugfs_cleanup(); |
Pavankumar Kondeti | d860852 | 2011-05-04 10:19:47 +0530 | [diff] [blame] | 1699 | cancel_delayed_work_sync(&motg->chg_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1700 | cancel_work_sync(&motg->sm_work); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1701 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 1702 | pm_runtime_resume(&pdev->dev); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1703 | |
| 1704 | device_init_wakeup(&pdev->dev, 0); |
| 1705 | pm_runtime_disable(&pdev->dev); |
| 1706 | |
Kishon Vijay Abraham I | 662dca5 | 2012-06-22 17:02:46 +0530 | [diff] [blame] | 1707 | usb_remove_phy(phy); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1708 | disable_irq(motg->irq); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1709 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1710 | /* |
| 1711 | * Put PHY in low power mode. |
| 1712 | */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1713 | ulpi_read(phy, 0x14); |
| 1714 | ulpi_write(phy, 0x08, 0x09); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1715 | |
| 1716 | writel(readl(USB_PORTSC) | PORTSC_PHCD, USB_PORTSC); |
| 1717 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 1718 | if (readl(USB_PORTSC) & PORTSC_PHCD) |
| 1719 | break; |
| 1720 | udelay(1); |
| 1721 | cnt++; |
| 1722 | } |
| 1723 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1724 | dev_err(phy->dev, "Unable to suspend PHY\n"); |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1725 | |
Stephen Boyd | b99a8f6 | 2013-06-17 10:43:10 -0700 | [diff] [blame] | 1726 | clk_disable_unprepare(motg->pclk); |
| 1727 | clk_disable_unprepare(motg->clk); |
Ivan T. Ivanov | 6b99c68e | 2014-04-28 16:34:08 +0300 | [diff] [blame] | 1728 | if (!IS_ERR(motg->core_clk)) |
Stephen Boyd | b99a8f6 | 2013-06-17 10:43:10 -0700 | [diff] [blame] | 1729 | clk_disable_unprepare(motg->core_clk); |
Anji jonnala | 11aa5c4 | 2011-05-04 10:19:48 +0530 | [diff] [blame] | 1730 | msm_hsusb_ldo_init(motg, 0); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1731 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1732 | pm_runtime_set_suspended(&pdev->dev); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1733 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1734 | return 0; |
| 1735 | } |
| 1736 | |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1737 | #ifdef CONFIG_PM_RUNTIME |
| 1738 | static int msm_otg_runtime_idle(struct device *dev) |
| 1739 | { |
| 1740 | struct msm_otg *motg = dev_get_drvdata(dev); |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1741 | struct usb_otg *otg = motg->phy.otg; |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1742 | |
| 1743 | dev_dbg(dev, "OTG runtime idle\n"); |
| 1744 | |
| 1745 | /* |
| 1746 | * It is observed some times that a spurious interrupt |
| 1747 | * comes when PHY is put into LPM immediately after PHY reset. |
| 1748 | * This 1 sec delay also prevents entering into LPM immediately |
| 1749 | * after asynchronous interrupt. |
| 1750 | */ |
Heikki Krogerus | 1d4c929 | 2012-02-13 13:24:09 +0200 | [diff] [blame] | 1751 | if (otg->phy->state != OTG_STATE_UNDEFINED) |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1752 | pm_schedule_suspend(dev, 1000); |
| 1753 | |
| 1754 | return -EAGAIN; |
| 1755 | } |
| 1756 | |
| 1757 | static int msm_otg_runtime_suspend(struct device *dev) |
| 1758 | { |
| 1759 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 1760 | |
| 1761 | dev_dbg(dev, "OTG runtime suspend\n"); |
| 1762 | return msm_otg_suspend(motg); |
| 1763 | } |
| 1764 | |
| 1765 | static int msm_otg_runtime_resume(struct device *dev) |
| 1766 | { |
| 1767 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 1768 | |
| 1769 | dev_dbg(dev, "OTG runtime resume\n"); |
| 1770 | return msm_otg_resume(motg); |
| 1771 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1772 | #endif |
| 1773 | |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 1774 | #ifdef CONFIG_PM_SLEEP |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1775 | static int msm_otg_pm_suspend(struct device *dev) |
| 1776 | { |
| 1777 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 1778 | |
| 1779 | dev_dbg(dev, "OTG PM suspend\n"); |
| 1780 | return msm_otg_suspend(motg); |
| 1781 | } |
| 1782 | |
| 1783 | static int msm_otg_pm_resume(struct device *dev) |
| 1784 | { |
| 1785 | struct msm_otg *motg = dev_get_drvdata(dev); |
| 1786 | int ret; |
| 1787 | |
| 1788 | dev_dbg(dev, "OTG PM resume\n"); |
| 1789 | |
| 1790 | ret = msm_otg_resume(motg); |
| 1791 | if (ret) |
| 1792 | return ret; |
| 1793 | |
| 1794 | /* |
| 1795 | * Runtime PM Documentation recommends bringing the |
| 1796 | * device to full powered state upon resume. |
| 1797 | */ |
| 1798 | pm_runtime_disable(dev); |
| 1799 | pm_runtime_set_active(dev); |
| 1800 | pm_runtime_enable(dev); |
| 1801 | |
| 1802 | return 0; |
| 1803 | } |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1804 | #endif |
| 1805 | |
| 1806 | static const struct dev_pm_ops msm_otg_dev_pm_ops = { |
Pavankumar Kondeti | 7018773 | 2011-02-15 09:42:34 +0530 | [diff] [blame] | 1807 | SET_SYSTEM_SLEEP_PM_OPS(msm_otg_pm_suspend, msm_otg_pm_resume) |
| 1808 | SET_RUNTIME_PM_OPS(msm_otg_runtime_suspend, msm_otg_runtime_resume, |
| 1809 | msm_otg_runtime_idle) |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1810 | }; |
| 1811 | |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1812 | static struct platform_driver msm_otg_driver = { |
Ivan T. Ivanov | 06a6ec4 | 2014-04-28 16:34:07 +0300 | [diff] [blame] | 1813 | .probe = msm_otg_probe, |
Bill Pemberton | 7690417 | 2012-11-19 13:21:08 -0500 | [diff] [blame] | 1814 | .remove = msm_otg_remove, |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1815 | .driver = { |
| 1816 | .name = DRIVER_NAME, |
| 1817 | .owner = THIS_MODULE, |
Pavankumar Kondeti | 87c0104 | 2010-12-07 17:53:58 +0530 | [diff] [blame] | 1818 | .pm = &msm_otg_dev_pm_ops, |
Ivan T. Ivanov | 8364f9a | 2014-04-28 16:34:15 +0300 | [diff] [blame] | 1819 | .of_match_table = msm_otg_dt_match, |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1820 | }, |
| 1821 | }; |
| 1822 | |
Ivan T. Ivanov | 06a6ec4 | 2014-04-28 16:34:07 +0300 | [diff] [blame] | 1823 | module_platform_driver(msm_otg_driver); |
Pavankumar Kondeti | e0c201f | 2010-12-07 17:53:55 +0530 | [diff] [blame] | 1824 | |
| 1825 | MODULE_LICENSE("GPL v2"); |
| 1826 | MODULE_DESCRIPTION("MSM USB transceiver driver"); |