Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1 | /* ehci-msm-hsic.c - HSUSB Host Controller Driver Implementation |
| 2 | * |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 3 | * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 4 | * |
| 5 | * Partly derived from ehci-fsl.c and ehci-hcd.c |
| 6 | * Copyright (c) 2000-2004 by David Brownell |
| 7 | * Copyright (c) 2005 MontaVista Software |
| 8 | * |
| 9 | * All source code in this file is licensed under the following license except |
| 10 | * where indicated. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify it |
| 13 | * under the terms of the GNU General Public License version 2 as published |
| 14 | * by the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 19 | * |
| 20 | * See the GNU General Public License for more details. |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, you can find it at http://www.fsf.org |
| 23 | */ |
| 24 | |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/clk.h> |
| 27 | #include <linux/err.h> |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 28 | #include <linux/debugfs.h> |
| 29 | #include <linux/seq_file.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 30 | #include <linux/wakelock.h> |
| 31 | #include <linux/pm_runtime.h> |
| 32 | #include <linux/regulator/consumer.h> |
| 33 | |
| 34 | #include <linux/usb/msm_hsusb_hw.h> |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 35 | #include <linux/usb/msm_hsusb.h> |
| 36 | #include <linux/gpio.h> |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 37 | #include <linux/spinlock.h> |
| 38 | |
| 39 | #include <mach/msm_bus.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 40 | #include <mach/clk.h> |
| 41 | #include <mach/msm_iomap.h> |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 42 | #include <mach/msm_xo.h> |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 43 | #include <linux/spinlock.h> |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 44 | #include <linux/cpu.h> |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 45 | #include <mach/rpm-regulator.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 46 | |
| 47 | #define MSM_USB_BASE (hcd->regs) |
| 48 | |
| 49 | struct msm_hsic_hcd { |
| 50 | struct ehci_hcd ehci; |
| 51 | struct device *dev; |
| 52 | struct clk *ahb_clk; |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 53 | struct clk *core_clk; |
| 54 | struct clk *alt_core_clk; |
| 55 | struct clk *phy_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 56 | struct clk *cal_clk; |
| 57 | struct regulator *hsic_vddcx; |
| 58 | bool async_int; |
| 59 | atomic_t in_lpm; |
| 60 | struct wake_lock wlock; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 61 | int peripheral_status_irq; |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 62 | int wakeup_irq; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 63 | int wakeup_gpio; |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 64 | bool wakeup_irq_enabled; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 65 | atomic_t pm_usage_cnt; |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 66 | uint32_t bus_perf_client; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 67 | uint32_t wakeup_int_cnt; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 68 | enum usb_vdd_type vdd_type; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 69 | }; |
| 70 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 71 | static bool debug_bus_voting_enabled = true; |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 72 | |
| 73 | static unsigned int enable_dbg_log = 1; |
| 74 | module_param(enable_dbg_log, uint, S_IRUGO | S_IWUSR); |
| 75 | /*by default log ep0 and efs sync ep*/ |
| 76 | static unsigned int ep_addr_rxdbg_mask = 9; |
| 77 | module_param(ep_addr_rxdbg_mask, uint, S_IRUGO | S_IWUSR); |
| 78 | static unsigned int ep_addr_txdbg_mask = 9; |
| 79 | module_param(ep_addr_txdbg_mask, uint, S_IRUGO | S_IWUSR); |
| 80 | |
| 81 | /* Maximum debug message length */ |
| 82 | #define DBG_MSG_LEN 100UL |
| 83 | |
| 84 | /* Maximum number of messages */ |
| 85 | #define DBG_MAX_MSG 256UL |
| 86 | |
| 87 | #define TIME_BUF_LEN 20 |
| 88 | |
| 89 | enum event_type { |
| 90 | EVENT_UNDEF = -1, |
| 91 | URB_SUBMIT, |
| 92 | URB_COMPLETE, |
| 93 | EVENT_NONE, |
| 94 | }; |
| 95 | |
| 96 | #define EVENT_STR_LEN 5 |
| 97 | |
| 98 | static char *event_to_str(enum event_type e) |
| 99 | { |
| 100 | switch (e) { |
| 101 | case URB_SUBMIT: |
| 102 | return "S"; |
| 103 | case URB_COMPLETE: |
| 104 | return "C"; |
| 105 | case EVENT_NONE: |
| 106 | return "NONE"; |
| 107 | default: |
| 108 | return "UNDEF"; |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | static enum event_type str_to_event(const char *name) |
| 113 | { |
| 114 | if (!strncasecmp("S", name, EVENT_STR_LEN)) |
| 115 | return URB_SUBMIT; |
| 116 | if (!strncasecmp("C", name, EVENT_STR_LEN)) |
| 117 | return URB_COMPLETE; |
| 118 | if (!strncasecmp("", name, EVENT_STR_LEN)) |
| 119 | return EVENT_NONE; |
| 120 | |
| 121 | return EVENT_UNDEF; |
| 122 | } |
| 123 | |
| 124 | /*log ep0 activity*/ |
| 125 | static struct { |
| 126 | char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */ |
| 127 | unsigned idx; /* index */ |
| 128 | rwlock_t lck; /* lock */ |
| 129 | } dbg_hsic_ctrl = { |
| 130 | .idx = 0, |
| 131 | .lck = __RW_LOCK_UNLOCKED(lck) |
| 132 | }; |
| 133 | |
| 134 | static struct { |
| 135 | char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */ |
| 136 | unsigned idx; /* index */ |
| 137 | rwlock_t lck; /* lock */ |
| 138 | } dbg_hsic_data = { |
| 139 | .idx = 0, |
| 140 | .lck = __RW_LOCK_UNLOCKED(lck) |
| 141 | }; |
| 142 | |
| 143 | /** |
| 144 | * dbg_inc: increments debug event index |
| 145 | * @idx: buffer index |
| 146 | */ |
| 147 | static void dbg_inc(unsigned *idx) |
| 148 | { |
| 149 | *idx = (*idx + 1) & (DBG_MAX_MSG-1); |
| 150 | } |
| 151 | |
| 152 | /*get_timestamp - returns time of day in us */ |
| 153 | static char *get_timestamp(char *tbuf) |
| 154 | { |
| 155 | unsigned long long t; |
| 156 | unsigned long nanosec_rem; |
| 157 | |
| 158 | t = cpu_clock(smp_processor_id()); |
| 159 | nanosec_rem = do_div(t, 1000000000)/1000; |
| 160 | scnprintf(tbuf, TIME_BUF_LEN, "[%5lu.%06lu] ", (unsigned long)t, |
| 161 | nanosec_rem); |
| 162 | return tbuf; |
| 163 | } |
| 164 | |
| 165 | static int allow_dbg_log(int ep_addr) |
| 166 | { |
| 167 | int dir, num; |
| 168 | |
| 169 | dir = ep_addr & USB_DIR_IN ? USB_DIR_IN : USB_DIR_OUT; |
| 170 | num = ep_addr & ~USB_DIR_IN; |
| 171 | num = 1 << num; |
| 172 | |
| 173 | if ((dir == USB_DIR_IN) && (num & ep_addr_rxdbg_mask)) |
| 174 | return 1; |
| 175 | if ((dir == USB_DIR_OUT) && (num & ep_addr_txdbg_mask)) |
| 176 | return 1; |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | static void dbg_log_event(struct urb *urb, char * event, unsigned extra) |
| 182 | { |
| 183 | unsigned long flags; |
| 184 | int ep_addr; |
| 185 | char tbuf[TIME_BUF_LEN]; |
| 186 | |
| 187 | if (!enable_dbg_log) |
| 188 | return; |
| 189 | |
| 190 | if (!urb) { |
| 191 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 192 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], DBG_MSG_LEN, |
| 193 | "%s: %s : %u\n", get_timestamp(tbuf), event, extra); |
| 194 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 195 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 196 | return; |
| 197 | } |
| 198 | |
| 199 | ep_addr = urb->ep->desc.bEndpointAddress; |
| 200 | if (!allow_dbg_log(ep_addr)) |
| 201 | return; |
| 202 | |
| 203 | if ((ep_addr & 0x0f) == 0x0) { |
| 204 | /*submit event*/ |
| 205 | if (!str_to_event(event)) { |
| 206 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 207 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], |
| 208 | DBG_MSG_LEN, "%s: [%s : %p]:[%s] " |
| 209 | "%02x %02x %04x %04x %04x %u %d\n", |
| 210 | get_timestamp(tbuf), event, urb, |
| 211 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 212 | urb->setup_packet[0], urb->setup_packet[1], |
| 213 | (urb->setup_packet[3] << 8) | |
| 214 | urb->setup_packet[2], |
| 215 | (urb->setup_packet[5] << 8) | |
| 216 | urb->setup_packet[4], |
| 217 | (urb->setup_packet[7] << 8) | |
| 218 | urb->setup_packet[6], |
| 219 | urb->transfer_buffer_length, urb->status); |
| 220 | |
| 221 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 222 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 223 | } else { |
| 224 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 225 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], |
| 226 | DBG_MSG_LEN, "%s: [%s : %p]:[%s] %u %d\n", |
| 227 | get_timestamp(tbuf), event, urb, |
| 228 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 229 | urb->actual_length, extra); |
| 230 | |
| 231 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 232 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 233 | } |
| 234 | } else { |
| 235 | write_lock_irqsave(&dbg_hsic_data.lck, flags); |
| 236 | scnprintf(dbg_hsic_data.buf[dbg_hsic_data.idx], DBG_MSG_LEN, |
| 237 | "%s: [%s : %p]:ep%d[%s] %u %d\n", |
| 238 | get_timestamp(tbuf), event, urb, ep_addr & 0x0f, |
| 239 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 240 | str_to_event(event) ? urb->actual_length : |
| 241 | urb->transfer_buffer_length, |
| 242 | str_to_event(event) ? extra : urb->status); |
| 243 | |
| 244 | dbg_inc(&dbg_hsic_data.idx); |
| 245 | write_unlock_irqrestore(&dbg_hsic_data.lck, flags); |
| 246 | } |
| 247 | } |
| 248 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 249 | static inline struct msm_hsic_hcd *hcd_to_hsic(struct usb_hcd *hcd) |
| 250 | { |
| 251 | return (struct msm_hsic_hcd *) (hcd->hcd_priv); |
| 252 | } |
| 253 | |
| 254 | static inline struct usb_hcd *hsic_to_hcd(struct msm_hsic_hcd *mehci) |
| 255 | { |
| 256 | return container_of((void *) mehci, struct usb_hcd, hcd_priv); |
| 257 | } |
| 258 | |
| 259 | #define ULPI_IO_TIMEOUT_USEC (10 * 1000) |
| 260 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 261 | #define USB_PHY_VDD_DIG_VOL_NONE 0 /*uV */ |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 262 | #define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */ |
| 263 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 264 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 265 | #define HSIC_DBG1_REG 0x38 |
| 266 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 267 | static const int vdd_val[VDD_TYPE_MAX][VDD_VAL_MAX] = { |
| 268 | { /* VDD_CX CORNER Voting */ |
| 269 | [VDD_NONE] = RPM_VREG_CORNER_NONE, |
| 270 | [VDD_MIN] = RPM_VREG_CORNER_NOMINAL, |
| 271 | [VDD_MAX] = RPM_VREG_CORNER_HIGH, |
| 272 | }, |
| 273 | { /* VDD_CX Voltage Voting */ |
| 274 | [VDD_NONE] = USB_PHY_VDD_DIG_VOL_NONE, |
| 275 | [VDD_MIN] = USB_PHY_VDD_DIG_VOL_MIN, |
| 276 | [VDD_MAX] = USB_PHY_VDD_DIG_VOL_MAX, |
| 277 | }, |
| 278 | }; |
| 279 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 280 | static int msm_hsic_init_vddcx(struct msm_hsic_hcd *mehci, int init) |
| 281 | { |
| 282 | int ret = 0; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 283 | int none_vol, min_vol, max_vol; |
| 284 | |
| 285 | if (!mehci->hsic_vddcx) { |
| 286 | mehci->vdd_type = VDDCX_CORNER; |
| 287 | mehci->hsic_vddcx = devm_regulator_get(mehci->dev, |
| 288 | "hsic_vdd_dig"); |
| 289 | if (IS_ERR(mehci->hsic_vddcx)) { |
| 290 | mehci->hsic_vddcx = devm_regulator_get(mehci->dev, |
| 291 | "HSIC_VDDCX"); |
| 292 | if (IS_ERR(mehci->hsic_vddcx)) { |
| 293 | dev_err(mehci->dev, "unable to get hsic vddcx\n"); |
| 294 | return PTR_ERR(mehci->hsic_vddcx); |
| 295 | } |
| 296 | mehci->vdd_type = VDDCX; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | none_vol = vdd_val[mehci->vdd_type][VDD_NONE]; |
| 301 | min_vol = vdd_val[mehci->vdd_type][VDD_MIN]; |
| 302 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 303 | |
| 304 | if (!init) |
| 305 | goto disable_reg; |
| 306 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 307 | ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 308 | if (ret) { |
| 309 | dev_err(mehci->dev, "unable to set the voltage" |
| 310 | "for hsic vddcx\n"); |
Mayank Rana | 189ac05 | 2012-03-24 04:35:02 +0530 | [diff] [blame] | 311 | return ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 312 | } |
| 313 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 314 | ret = regulator_enable(mehci->hsic_vddcx); |
| 315 | if (ret) { |
| 316 | dev_err(mehci->dev, "unable to enable hsic vddcx\n"); |
| 317 | goto reg_enable_err; |
| 318 | } |
| 319 | |
| 320 | return 0; |
| 321 | |
| 322 | disable_reg: |
| 323 | regulator_disable(mehci->hsic_vddcx); |
| 324 | reg_enable_err: |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 325 | regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol); |
| 326 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 327 | return ret; |
| 328 | |
| 329 | } |
| 330 | |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 331 | static int ulpi_read(struct msm_hsic_hcd *mehci, u32 reg) |
| 332 | { |
| 333 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
| 334 | unsigned long timeout; |
| 335 | |
| 336 | /* initiate read operation */ |
| 337 | writel_relaxed(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg), |
| 338 | USB_ULPI_VIEWPORT); |
| 339 | |
| 340 | /* wait for completion */ |
| 341 | timeout = jiffies + usecs_to_jiffies(ULPI_IO_TIMEOUT_USEC); |
| 342 | while (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN) { |
| 343 | if (time_after(jiffies, timeout)) { |
| 344 | dev_err(mehci->dev, "ulpi_read: timeout %08x\n", |
| 345 | readl_relaxed(USB_ULPI_VIEWPORT)); |
| 346 | return -ETIMEDOUT; |
| 347 | } |
| 348 | udelay(1); |
| 349 | } |
| 350 | |
| 351 | return ULPI_DATA_READ(readl_relaxed(USB_ULPI_VIEWPORT)); |
| 352 | } |
| 353 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 354 | static int ulpi_write(struct msm_hsic_hcd *mehci, u32 val, u32 reg) |
| 355 | { |
| 356 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
| 357 | int cnt = 0; |
| 358 | |
| 359 | /* initiate write operation */ |
| 360 | writel_relaxed(ULPI_RUN | ULPI_WRITE | |
| 361 | ULPI_ADDR(reg) | ULPI_DATA(val), |
| 362 | USB_ULPI_VIEWPORT); |
| 363 | |
| 364 | /* wait for completion */ |
| 365 | while (cnt < ULPI_IO_TIMEOUT_USEC) { |
| 366 | if (!(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN)) |
| 367 | break; |
| 368 | udelay(1); |
| 369 | cnt++; |
| 370 | } |
| 371 | |
| 372 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { |
| 373 | dev_err(mehci->dev, "ulpi_write: timeout\n"); |
| 374 | return -ETIMEDOUT; |
| 375 | } |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 380 | #define HSIC_DBG1 0X38 |
| 381 | #define ULPI_MANUAL_ENABLE BIT(4) |
| 382 | #define ULPI_LINESTATE_DATA BIT(5) |
| 383 | #define ULPI_LINESTATE_STROBE BIT(6) |
| 384 | static void ehci_msm_enable_ulpi_control(struct usb_hcd *hcd, u32 linestate) |
| 385 | { |
| 386 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 387 | int val; |
| 388 | |
| 389 | switch (linestate) { |
| 390 | case PORT_RESET: |
| 391 | val = ulpi_read(mehci, HSIC_DBG1); |
| 392 | val |= ULPI_MANUAL_ENABLE; |
| 393 | val &= ~(ULPI_LINESTATE_DATA | ULPI_LINESTATE_STROBE); |
| 394 | ulpi_write(mehci, val, HSIC_DBG1); |
| 395 | break; |
| 396 | default: |
| 397 | pr_info("%s: Unknown linestate:%0x\n", __func__, linestate); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | static void ehci_msm_disable_ulpi_control(struct usb_hcd *hcd) |
| 402 | { |
| 403 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 404 | int val; |
| 405 | |
| 406 | val = ulpi_read(mehci, HSIC_DBG1); |
| 407 | val &= ~ULPI_MANUAL_ENABLE; |
| 408 | ulpi_write(mehci, val, HSIC_DBG1); |
| 409 | } |
| 410 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 411 | static int msm_hsic_config_gpios(struct msm_hsic_hcd *mehci, int gpio_en) |
| 412 | { |
| 413 | int rc = 0; |
| 414 | struct msm_hsic_host_platform_data *pdata; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 415 | static int gpio_status; |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 416 | |
| 417 | pdata = mehci->dev->platform_data; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 418 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 419 | if (!pdata || !pdata->strobe || !pdata->data) |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 420 | return rc; |
| 421 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 422 | if (gpio_status == gpio_en) |
| 423 | return 0; |
| 424 | |
| 425 | gpio_status = gpio_en; |
| 426 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 427 | if (!gpio_en) |
| 428 | goto free_gpio; |
| 429 | |
| 430 | rc = gpio_request(pdata->strobe, "HSIC_STROBE_GPIO"); |
| 431 | if (rc < 0) { |
| 432 | dev_err(mehci->dev, "gpio request failed for HSIC STROBE\n"); |
| 433 | return rc; |
| 434 | } |
| 435 | |
| 436 | rc = gpio_request(pdata->data, "HSIC_DATA_GPIO"); |
| 437 | if (rc < 0) { |
| 438 | dev_err(mehci->dev, "gpio request failed for HSIC DATA\n"); |
| 439 | goto free_strobe; |
| 440 | } |
| 441 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 442 | if (mehci->wakeup_gpio) { |
| 443 | rc = gpio_request(mehci->wakeup_gpio, "HSIC_WAKEUP_GPIO"); |
| 444 | if (rc < 0) { |
| 445 | dev_err(mehci->dev, "gpio request failed for HSIC WAKEUP\n"); |
| 446 | goto free_data; |
| 447 | } |
| 448 | } |
| 449 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 450 | return 0; |
| 451 | |
| 452 | free_gpio: |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 453 | if (mehci->wakeup_gpio) |
| 454 | gpio_free(mehci->wakeup_gpio); |
| 455 | free_data: |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 456 | gpio_free(pdata->data); |
| 457 | free_strobe: |
| 458 | gpio_free(pdata->strobe); |
| 459 | |
| 460 | return rc; |
| 461 | } |
| 462 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 463 | static void msm_hsic_clk_reset(struct msm_hsic_hcd *mehci) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 464 | { |
| 465 | int ret; |
| 466 | |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 467 | ret = clk_reset(mehci->core_clk, CLK_RESET_ASSERT); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 468 | if (ret) { |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 469 | dev_err(mehci->dev, "hsic clk assert failed:%d\n", ret); |
| 470 | return; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 471 | } |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 472 | clk_disable(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 473 | |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 474 | ret = clk_reset(mehci->core_clk, CLK_RESET_DEASSERT); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 475 | if (ret) |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 476 | dev_err(mehci->dev, "hsic clk deassert failed:%d\n", ret); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 477 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 478 | usleep_range(10000, 12000); |
| 479 | |
| 480 | clk_enable(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 481 | } |
| 482 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 483 | #define HSIC_STROBE_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C0) |
| 484 | #define HSIC_DATA_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C4) |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 485 | #define HSIC_CAL_PAD_CTL (MSM_TLMM_BASE+0x20C8) |
| 486 | #define HSIC_LV_MODE 0x04 |
| 487 | #define HSIC_PAD_CALIBRATION 0xA8 |
| 488 | #define HSIC_GPIO_PAD_VAL 0x0A0AAA10 |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 489 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) |
| 490 | static int msm_hsic_reset(struct msm_hsic_hcd *mehci) |
| 491 | { |
| 492 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 493 | int ret; |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 494 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 495 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 496 | msm_hsic_clk_reset(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 497 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 498 | /* select ulpi phy */ |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 499 | writel_relaxed(0x80000000, USB_PORTSC); |
| 500 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 501 | mb(); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 502 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 503 | /* HSIC init sequence when HSIC signals (Strobe/Data) are |
| 504 | routed via GPIOs */ |
| 505 | if (pdata && pdata->strobe && pdata->data) { |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 506 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 507 | /* Enable LV_MODE in HSIC_CAL_PAD_CTL register */ |
| 508 | writel_relaxed(HSIC_LV_MODE, HSIC_CAL_PAD_CTL); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 509 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 510 | mb(); |
| 511 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 512 | /*set periodic calibration interval to ~2.048sec in |
| 513 | HSIC_IO_CAL_REG */ |
| 514 | ulpi_write(mehci, 0xFF, 0x33); |
| 515 | |
| 516 | /* Enable periodic IO calibration in HSIC_CFG register */ |
| 517 | ulpi_write(mehci, HSIC_PAD_CALIBRATION, 0x30); |
| 518 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 519 | /* Configure GPIO pins for HSIC functionality mode */ |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 520 | ret = msm_hsic_config_gpios(mehci, 1); |
| 521 | if (ret) { |
| 522 | dev_err(mehci->dev, " gpio configuarion failed\n"); |
| 523 | return ret; |
| 524 | } |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 525 | /* Set LV_MODE=0x1 and DCC=0x2 in HSIC_GPIO PAD_CTL register */ |
| 526 | writel_relaxed(HSIC_GPIO_PAD_VAL, HSIC_STROBE_GPIO_PAD_CTL); |
| 527 | writel_relaxed(HSIC_GPIO_PAD_VAL, HSIC_DATA_GPIO_PAD_CTL); |
| 528 | |
| 529 | mb(); |
| 530 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 531 | /* Enable HSIC mode in HSIC_CFG register */ |
| 532 | ulpi_write(mehci, 0x01, 0x31); |
| 533 | } else { |
| 534 | /* HSIC init sequence when HSIC signals (Strobe/Data) are routed |
| 535 | via dedicated I/O */ |
| 536 | |
| 537 | /* programmable length of connect signaling (33.2ns) */ |
| 538 | ret = ulpi_write(mehci, 3, HSIC_DBG1_REG); |
| 539 | if (ret) { |
| 540 | pr_err("%s: Unable to program length of connect " |
| 541 | "signaling\n", __func__); |
| 542 | } |
| 543 | |
| 544 | /*set periodic calibration interval to ~2.048sec in |
| 545 | HSIC_IO_CAL_REG */ |
| 546 | ulpi_write(mehci, 0xFF, 0x33); |
| 547 | |
| 548 | /* Enable HSIC mode in HSIC_CFG register */ |
| 549 | ulpi_write(mehci, 0xA9, 0x30); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 550 | } |
| 551 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 552 | /*disable auto resume*/ |
| 553 | ulpi_write(mehci, ULPI_IFC_CTRL_AUTORESUME, ULPI_CLR(ULPI_IFC_CTRL)); |
| 554 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 555 | return 0; |
| 556 | } |
| 557 | |
| 558 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) |
| 559 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) |
| 560 | |
| 561 | #ifdef CONFIG_PM_SLEEP |
| 562 | static int msm_hsic_suspend(struct msm_hsic_hcd *mehci) |
| 563 | { |
| 564 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 565 | int cnt = 0, ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 566 | u32 val; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 567 | int none_vol, max_vol; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 568 | |
| 569 | if (atomic_read(&mehci->in_lpm)) { |
| 570 | dev_dbg(mehci->dev, "%s called in lpm\n", __func__); |
| 571 | return 0; |
| 572 | } |
| 573 | |
Hemant Kumar | 7f37463 | 2012-05-31 20:10:32 -0700 | [diff] [blame] | 574 | if (!(readl_relaxed(USB_PORTSC) & PORT_PE)) { |
| 575 | dev_dbg(mehci->dev, "%s:port is not enabled skip suspend\n", |
| 576 | __func__); |
| 577 | return -EAGAIN; |
| 578 | } |
| 579 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 580 | disable_irq(hcd->irq); |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 581 | |
| 582 | /* make sure we don't race against a remote wakeup */ |
| 583 | if (test_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags) || |
| 584 | readl_relaxed(USB_PORTSC) & PORT_RESUME) { |
| 585 | dev_dbg(mehci->dev, "wakeup pending, aborting suspend\n"); |
| 586 | enable_irq(hcd->irq); |
| 587 | return -EBUSY; |
| 588 | } |
| 589 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 590 | /* |
| 591 | * PHY may take some time or even fail to enter into low power |
| 592 | * mode (LPM). Hence poll for 500 msec and reset the PHY and link |
| 593 | * in failure case. |
| 594 | */ |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 595 | val = readl_relaxed(USB_PORTSC); |
| 596 | val &= ~PORT_RWC_BITS; |
| 597 | val |= PORTSC_PHCD; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 598 | writel_relaxed(val, USB_PORTSC); |
| 599 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 600 | if (readl_relaxed(USB_PORTSC) & PORTSC_PHCD) |
| 601 | break; |
| 602 | udelay(1); |
| 603 | cnt++; |
| 604 | } |
| 605 | |
| 606 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) { |
| 607 | dev_err(mehci->dev, "Unable to suspend PHY\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 608 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 609 | msm_hsic_reset(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 610 | } |
| 611 | |
| 612 | /* |
| 613 | * PHY has capability to generate interrupt asynchronously in low |
| 614 | * power mode (LPM). This interrupt is level triggered. So USB IRQ |
| 615 | * line must be disabled till async interrupt enable bit is cleared |
| 616 | * in USBCMD register. Assert STP (ULPI interface STOP signal) to |
| 617 | * block data communication from PHY. |
| 618 | */ |
| 619 | writel_relaxed(readl_relaxed(USB_USBCMD) | ASYNC_INTR_CTRL | |
| 620 | ULPI_STP_CTRL, USB_USBCMD); |
| 621 | |
| 622 | /* |
| 623 | * Ensure that hardware is put in low power mode before |
| 624 | * clocks are turned OFF and VDD is allowed to minimize. |
| 625 | */ |
| 626 | mb(); |
| 627 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 628 | clk_disable_unprepare(mehci->core_clk); |
| 629 | clk_disable_unprepare(mehci->phy_clk); |
| 630 | clk_disable_unprepare(mehci->cal_clk); |
| 631 | clk_disable_unprepare(mehci->ahb_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 632 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 633 | none_vol = vdd_val[mehci->vdd_type][VDD_NONE]; |
| 634 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
| 635 | |
| 636 | ret = regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 637 | if (ret < 0) |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 638 | dev_err(mehci->dev, "unable to set vddcx voltage for VDD MIN\n"); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 639 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 640 | if (mehci->bus_perf_client && debug_bus_voting_enabled) { |
| 641 | ret = msm_bus_scale_client_update_request( |
| 642 | mehci->bus_perf_client, 0); |
| 643 | if (ret) |
| 644 | dev_err(mehci->dev, "%s: Failed to dvote for " |
| 645 | "bus bandwidth %d\n", __func__, ret); |
| 646 | } |
| 647 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 648 | atomic_set(&mehci->in_lpm, 1); |
| 649 | enable_irq(hcd->irq); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 650 | |
| 651 | mehci->wakeup_irq_enabled = 1; |
| 652 | enable_irq_wake(mehci->wakeup_irq); |
| 653 | enable_irq(mehci->wakeup_irq); |
| 654 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 655 | wake_unlock(&mehci->wlock); |
| 656 | |
| 657 | dev_info(mehci->dev, "HSIC-USB in low power mode\n"); |
| 658 | |
| 659 | return 0; |
| 660 | } |
| 661 | |
| 662 | static int msm_hsic_resume(struct msm_hsic_hcd *mehci) |
| 663 | { |
| 664 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 665 | int cnt = 0, ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 666 | unsigned temp; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 667 | int min_vol, max_vol; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 668 | |
| 669 | if (!atomic_read(&mehci->in_lpm)) { |
| 670 | dev_dbg(mehci->dev, "%s called in !in_lpm\n", __func__); |
| 671 | return 0; |
| 672 | } |
| 673 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 674 | if (mehci->wakeup_irq_enabled) { |
| 675 | disable_irq_wake(mehci->wakeup_irq); |
| 676 | disable_irq_nosync(mehci->wakeup_irq); |
| 677 | mehci->wakeup_irq_enabled = 0; |
| 678 | } |
| 679 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 680 | wake_lock(&mehci->wlock); |
| 681 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 682 | if (mehci->bus_perf_client && debug_bus_voting_enabled) { |
| 683 | ret = msm_bus_scale_client_update_request( |
| 684 | mehci->bus_perf_client, 1); |
| 685 | if (ret) |
| 686 | dev_err(mehci->dev, "%s: Failed to vote for " |
| 687 | "bus bandwidth %d\n", __func__, ret); |
| 688 | } |
| 689 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 690 | min_vol = vdd_val[mehci->vdd_type][VDD_MIN]; |
| 691 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
| 692 | |
| 693 | ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 694 | if (ret < 0) |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 695 | dev_err(mehci->dev, "unable to set nominal vddcx voltage (no VDD MIN)\n"); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 696 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 697 | clk_prepare_enable(mehci->core_clk); |
| 698 | clk_prepare_enable(mehci->phy_clk); |
| 699 | clk_prepare_enable(mehci->cal_clk); |
| 700 | clk_prepare_enable(mehci->ahb_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 701 | |
| 702 | temp = readl_relaxed(USB_USBCMD); |
| 703 | temp &= ~ASYNC_INTR_CTRL; |
| 704 | temp &= ~ULPI_STP_CTRL; |
| 705 | writel_relaxed(temp, USB_USBCMD); |
| 706 | |
| 707 | if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD)) |
| 708 | goto skip_phy_resume; |
| 709 | |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 710 | temp = readl_relaxed(USB_PORTSC); |
| 711 | temp &= ~(PORT_RWC_BITS | PORTSC_PHCD); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 712 | writel_relaxed(temp, USB_PORTSC); |
| 713 | while (cnt < PHY_RESUME_TIMEOUT_USEC) { |
| 714 | if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD) && |
| 715 | (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_SYNC_STATE)) |
| 716 | break; |
| 717 | udelay(1); |
| 718 | cnt++; |
| 719 | } |
| 720 | |
| 721 | if (cnt >= PHY_RESUME_TIMEOUT_USEC) { |
| 722 | /* |
| 723 | * This is a fatal error. Reset the link and |
| 724 | * PHY to make hsic working. |
| 725 | */ |
| 726 | dev_err(mehci->dev, "Unable to resume USB. Reset the hsic\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 727 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 728 | msm_hsic_reset(mehci); |
| 729 | } |
| 730 | |
| 731 | skip_phy_resume: |
| 732 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 733 | usb_hcd_resume_root_hub(hcd); |
| 734 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 735 | atomic_set(&mehci->in_lpm, 0); |
| 736 | |
| 737 | if (mehci->async_int) { |
| 738 | mehci->async_int = false; |
| 739 | pm_runtime_put_noidle(mehci->dev); |
| 740 | enable_irq(hcd->irq); |
| 741 | } |
| 742 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 743 | if (atomic_read(&mehci->pm_usage_cnt)) { |
| 744 | atomic_set(&mehci->pm_usage_cnt, 0); |
| 745 | pm_runtime_put_noidle(mehci->dev); |
| 746 | } |
| 747 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 748 | dev_info(mehci->dev, "HSIC-USB exited from low power mode\n"); |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | #endif |
| 753 | |
| 754 | static irqreturn_t msm_hsic_irq(struct usb_hcd *hcd) |
| 755 | { |
| 756 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 757 | |
| 758 | if (atomic_read(&mehci->in_lpm)) { |
| 759 | disable_irq_nosync(hcd->irq); |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 760 | dev_dbg(mehci->dev, "phy async intr\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 761 | mehci->async_int = true; |
| 762 | pm_runtime_get(mehci->dev); |
| 763 | return IRQ_HANDLED; |
| 764 | } |
| 765 | |
| 766 | return ehci_irq(hcd); |
| 767 | } |
| 768 | |
| 769 | static int ehci_hsic_reset(struct usb_hcd *hcd) |
| 770 | { |
| 771 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 772 | int retval; |
| 773 | |
| 774 | ehci->caps = USB_CAPLENGTH; |
| 775 | ehci->regs = USB_CAPLENGTH + |
| 776 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
| 777 | dbg_hcs_params(ehci, "reset"); |
| 778 | dbg_hcc_params(ehci, "reset"); |
| 779 | |
| 780 | /* cache the data to minimize the chip reads*/ |
| 781 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
| 782 | |
| 783 | hcd->has_tt = 1; |
| 784 | ehci->sbrn = HCD_USB2; |
| 785 | |
| 786 | retval = ehci_halt(ehci); |
| 787 | if (retval) |
| 788 | return retval; |
| 789 | |
| 790 | /* data structure init */ |
| 791 | retval = ehci_init(hcd); |
| 792 | if (retval) |
| 793 | return retval; |
| 794 | |
| 795 | retval = ehci_reset(ehci); |
| 796 | if (retval) |
| 797 | return retval; |
| 798 | |
| 799 | /* bursts of unspecified length. */ |
| 800 | writel_relaxed(0, USB_AHBBURST); |
| 801 | /* Use the AHB transactor */ |
Vijayavardhan Vennapusa | 5f32d7a | 2012-03-14 16:30:26 +0530 | [diff] [blame] | 802 | writel_relaxed(0x08, USB_AHBMODE); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 803 | /* Disable streaming mode and select host mode */ |
| 804 | writel_relaxed(0x13, USB_USBMODE); |
| 805 | |
| 806 | ehci_port_power(ehci, 1); |
| 807 | return 0; |
| 808 | } |
| 809 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 810 | static int ehci_hsic_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
| 811 | gfp_t mem_flags) |
| 812 | { |
| 813 | dbg_log_event(urb, event_to_str(URB_SUBMIT), 0); |
| 814 | return ehci_urb_enqueue(hcd, urb, mem_flags); |
| 815 | } |
| 816 | |
| 817 | static int ehci_hsic_bus_suspend(struct usb_hcd *hcd) |
| 818 | { |
| 819 | dbg_log_event(NULL, "Suspend RH", 0); |
| 820 | return ehci_bus_suspend(hcd); |
| 821 | } |
| 822 | |
| 823 | static int ehci_hsic_bus_resume(struct usb_hcd *hcd) |
| 824 | { |
| 825 | dbg_log_event(NULL, "Resume RH", 0); |
| 826 | return ehci_bus_resume(hcd); |
| 827 | } |
| 828 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 829 | static struct hc_driver msm_hsic_driver = { |
| 830 | .description = hcd_name, |
| 831 | .product_desc = "Qualcomm EHCI Host Controller using HSIC", |
| 832 | .hcd_priv_size = sizeof(struct msm_hsic_hcd), |
| 833 | |
| 834 | /* |
| 835 | * generic hardware linkage |
| 836 | */ |
| 837 | .irq = msm_hsic_irq, |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 838 | .flags = HCD_USB2 | HCD_MEMORY | HCD_OLD_ENUM, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 839 | |
| 840 | .reset = ehci_hsic_reset, |
| 841 | .start = ehci_run, |
| 842 | |
| 843 | .stop = ehci_stop, |
| 844 | .shutdown = ehci_shutdown, |
| 845 | |
| 846 | /* |
| 847 | * managing i/o requests and associated device resources |
| 848 | */ |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 849 | .urb_enqueue = ehci_hsic_urb_enqueue, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 850 | .urb_dequeue = ehci_urb_dequeue, |
| 851 | .endpoint_disable = ehci_endpoint_disable, |
| 852 | .endpoint_reset = ehci_endpoint_reset, |
| 853 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 854 | |
| 855 | /* |
| 856 | * scheduling support |
| 857 | */ |
| 858 | .get_frame_number = ehci_get_frame, |
| 859 | |
| 860 | /* |
| 861 | * root hub support |
| 862 | */ |
| 863 | .hub_status_data = ehci_hub_status_data, |
| 864 | .hub_control = ehci_hub_control, |
| 865 | .relinquish_port = ehci_relinquish_port, |
| 866 | .port_handed_over = ehci_port_handed_over, |
| 867 | |
| 868 | /* |
| 869 | * PM support |
| 870 | */ |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 871 | .bus_suspend = ehci_hsic_bus_suspend, |
| 872 | .bus_resume = ehci_hsic_bus_resume, |
| 873 | |
| 874 | .log_urb_complete = dbg_log_event, |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 875 | |
| 876 | .enable_ulpi_control = ehci_msm_enable_ulpi_control, |
| 877 | .disable_ulpi_control = ehci_msm_disable_ulpi_control, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 878 | }; |
| 879 | |
| 880 | static int msm_hsic_init_clocks(struct msm_hsic_hcd *mehci, u32 init) |
| 881 | { |
| 882 | int ret = 0; |
| 883 | |
| 884 | if (!init) |
| 885 | goto put_clocks; |
| 886 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 887 | /*core_clk is required for LINK protocol engine |
| 888 | *clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 889 | mehci->core_clk = clk_get(mehci->dev, "core_clk"); |
| 890 | if (IS_ERR(mehci->core_clk)) { |
| 891 | dev_err(mehci->dev, "failed to get core_clk\n"); |
| 892 | ret = PTR_ERR(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 893 | return ret; |
| 894 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 895 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 896 | /* alt_core_clk is for LINK to be used during PHY RESET |
| 897 | * clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 898 | mehci->alt_core_clk = clk_get(mehci->dev, "alt_core_clk"); |
| 899 | if (IS_ERR(mehci->alt_core_clk)) { |
| 900 | dev_err(mehci->dev, "failed to core_clk\n"); |
| 901 | ret = PTR_ERR(mehci->alt_core_clk); |
| 902 | goto put_core_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 903 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 904 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 905 | /* phy_clk is required for HSIC PHY operation |
| 906 | * clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 907 | mehci->phy_clk = clk_get(mehci->dev, "phy_clk"); |
| 908 | if (IS_ERR(mehci->phy_clk)) { |
| 909 | dev_err(mehci->dev, "failed to get phy_clk\n"); |
| 910 | ret = PTR_ERR(mehci->phy_clk); |
| 911 | goto put_alt_core_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 912 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 913 | |
| 914 | /* 10MHz cal_clk is required for calibration of I/O pads */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 915 | mehci->cal_clk = clk_get(mehci->dev, "cal_clk"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 916 | if (IS_ERR(mehci->cal_clk)) { |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 917 | dev_err(mehci->dev, "failed to get cal_clk\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 918 | ret = PTR_ERR(mehci->cal_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 919 | goto put_phy_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 920 | } |
| 921 | clk_set_rate(mehci->cal_clk, 10000000); |
| 922 | |
| 923 | /* ahb_clk is required for data transfers */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 924 | mehci->ahb_clk = clk_get(mehci->dev, "iface_clk"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 925 | if (IS_ERR(mehci->ahb_clk)) { |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 926 | dev_err(mehci->dev, "failed to get iface_clk\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 927 | ret = PTR_ERR(mehci->ahb_clk); |
| 928 | goto put_cal_clk; |
| 929 | } |
| 930 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 931 | clk_prepare_enable(mehci->core_clk); |
| 932 | clk_prepare_enable(mehci->phy_clk); |
| 933 | clk_prepare_enable(mehci->cal_clk); |
| 934 | clk_prepare_enable(mehci->ahb_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 935 | |
| 936 | return 0; |
| 937 | |
| 938 | put_clocks: |
Jack Pham | fd193eb | 2012-02-22 15:38:08 -0800 | [diff] [blame] | 939 | if (!atomic_read(&mehci->in_lpm)) { |
| 940 | clk_disable_unprepare(mehci->core_clk); |
| 941 | clk_disable_unprepare(mehci->phy_clk); |
| 942 | clk_disable_unprepare(mehci->cal_clk); |
| 943 | clk_disable_unprepare(mehci->ahb_clk); |
| 944 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 945 | clk_put(mehci->ahb_clk); |
| 946 | put_cal_clk: |
| 947 | clk_put(mehci->cal_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 948 | put_phy_clk: |
| 949 | clk_put(mehci->phy_clk); |
| 950 | put_alt_core_clk: |
| 951 | clk_put(mehci->alt_core_clk); |
| 952 | put_core_clk: |
| 953 | clk_put(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 954 | |
| 955 | return ret; |
| 956 | } |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 957 | static irqreturn_t hsic_peripheral_status_change(int irq, void *dev_id) |
| 958 | { |
| 959 | struct msm_hsic_hcd *mehci = dev_id; |
| 960 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 961 | pr_debug("%s: mehci:%p dev_id:%p\n", __func__, mehci, dev_id); |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 962 | |
| 963 | if (mehci) |
| 964 | msm_hsic_config_gpios(mehci, 0); |
| 965 | |
| 966 | return IRQ_HANDLED; |
| 967 | } |
| 968 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 969 | static irqreturn_t msm_hsic_wakeup_irq(int irq, void *data) |
| 970 | { |
| 971 | struct msm_hsic_hcd *mehci = data; |
| 972 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 973 | mehci->wakeup_int_cnt++; |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 974 | dbg_log_event(NULL, "Remote Wakeup IRQ", mehci->wakeup_int_cnt); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 975 | dev_dbg(mehci->dev, "%s: hsic remote wakeup interrupt cnt: %u\n", |
| 976 | __func__, mehci->wakeup_int_cnt); |
| 977 | |
| 978 | wake_lock(&mehci->wlock); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 979 | |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 980 | if (mehci->wakeup_irq_enabled) { |
| 981 | mehci->wakeup_irq_enabled = 0; |
| 982 | disable_irq_wake(irq); |
| 983 | disable_irq_nosync(irq); |
| 984 | } |
| 985 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 986 | if (!atomic_read(&mehci->pm_usage_cnt)) { |
| 987 | atomic_set(&mehci->pm_usage_cnt, 1); |
| 988 | pm_runtime_get(mehci->dev); |
| 989 | } |
| 990 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 991 | return IRQ_HANDLED; |
| 992 | } |
| 993 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 994 | static int ehci_hsic_msm_bus_show(struct seq_file *s, void *unused) |
| 995 | { |
| 996 | if (debug_bus_voting_enabled) |
| 997 | seq_printf(s, "enabled\n"); |
| 998 | else |
| 999 | seq_printf(s, "disabled\n"); |
| 1000 | |
| 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | static int ehci_hsic_msm_bus_open(struct inode *inode, struct file *file) |
| 1005 | { |
| 1006 | return single_open(file, ehci_hsic_msm_bus_show, inode->i_private); |
| 1007 | } |
| 1008 | |
| 1009 | static ssize_t ehci_hsic_msm_bus_write(struct file *file, |
| 1010 | const char __user *ubuf, size_t count, loff_t *ppos) |
| 1011 | { |
| 1012 | char buf[8]; |
| 1013 | int ret; |
| 1014 | struct seq_file *s = file->private_data; |
| 1015 | struct msm_hsic_hcd *mehci = s->private; |
| 1016 | |
| 1017 | memset(buf, 0x00, sizeof(buf)); |
| 1018 | |
| 1019 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 1020 | return -EFAULT; |
| 1021 | |
| 1022 | if (!strncmp(buf, "enable", 6)) { |
| 1023 | /* Do not vote here. Let hsic driver decide when to vote */ |
| 1024 | debug_bus_voting_enabled = true; |
| 1025 | } else { |
| 1026 | debug_bus_voting_enabled = false; |
| 1027 | if (mehci->bus_perf_client) { |
| 1028 | ret = msm_bus_scale_client_update_request( |
| 1029 | mehci->bus_perf_client, 0); |
| 1030 | if (ret) |
| 1031 | dev_err(mehci->dev, "%s: Failed to devote " |
| 1032 | "for bus bw %d\n", __func__, ret); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | return count; |
| 1037 | } |
| 1038 | |
| 1039 | const struct file_operations ehci_hsic_msm_bus_fops = { |
| 1040 | .open = ehci_hsic_msm_bus_open, |
| 1041 | .read = seq_read, |
| 1042 | .write = ehci_hsic_msm_bus_write, |
| 1043 | .llseek = seq_lseek, |
| 1044 | .release = single_release, |
| 1045 | }; |
| 1046 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1047 | static int ehci_hsic_msm_wakeup_cnt_show(struct seq_file *s, void *unused) |
| 1048 | { |
| 1049 | struct msm_hsic_hcd *mehci = s->private; |
| 1050 | |
| 1051 | seq_printf(s, "%u\n", mehci->wakeup_int_cnt); |
| 1052 | |
| 1053 | return 0; |
| 1054 | } |
| 1055 | |
| 1056 | static int ehci_hsic_msm_wakeup_cnt_open(struct inode *inode, struct file *f) |
| 1057 | { |
| 1058 | return single_open(f, ehci_hsic_msm_wakeup_cnt_show, inode->i_private); |
| 1059 | } |
| 1060 | |
| 1061 | const struct file_operations ehci_hsic_msm_wakeup_cnt_fops = { |
| 1062 | .open = ehci_hsic_msm_wakeup_cnt_open, |
| 1063 | .read = seq_read, |
| 1064 | .llseek = seq_lseek, |
| 1065 | .release = single_release, |
| 1066 | }; |
| 1067 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1068 | static int ehci_hsic_msm_data_events_show(struct seq_file *s, void *unused) |
| 1069 | { |
| 1070 | unsigned long flags; |
| 1071 | unsigned i; |
| 1072 | |
| 1073 | read_lock_irqsave(&dbg_hsic_data.lck, flags); |
| 1074 | |
| 1075 | i = dbg_hsic_data.idx; |
| 1076 | for (dbg_inc(&i); i != dbg_hsic_data.idx; dbg_inc(&i)) { |
| 1077 | if (!strnlen(dbg_hsic_data.buf[i], DBG_MSG_LEN)) |
| 1078 | continue; |
| 1079 | seq_printf(s, "%s\n", dbg_hsic_data.buf[i]); |
| 1080 | } |
| 1081 | |
| 1082 | read_unlock_irqrestore(&dbg_hsic_data.lck, flags); |
| 1083 | |
| 1084 | return 0; |
| 1085 | } |
| 1086 | |
| 1087 | static int ehci_hsic_msm_data_events_open(struct inode *inode, struct file *f) |
| 1088 | { |
| 1089 | return single_open(f, ehci_hsic_msm_data_events_show, inode->i_private); |
| 1090 | } |
| 1091 | |
| 1092 | const struct file_operations ehci_hsic_msm_dbg_data_fops = { |
| 1093 | .open = ehci_hsic_msm_data_events_open, |
| 1094 | .read = seq_read, |
| 1095 | .llseek = seq_lseek, |
| 1096 | .release = single_release, |
| 1097 | }; |
| 1098 | |
| 1099 | static int ehci_hsic_msm_ctrl_events_show(struct seq_file *s, void *unused) |
| 1100 | { |
| 1101 | unsigned long flags; |
| 1102 | unsigned i; |
| 1103 | |
| 1104 | read_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 1105 | |
| 1106 | i = dbg_hsic_ctrl.idx; |
| 1107 | for (dbg_inc(&i); i != dbg_hsic_ctrl.idx; dbg_inc(&i)) { |
| 1108 | if (!strnlen(dbg_hsic_ctrl.buf[i], DBG_MSG_LEN)) |
| 1109 | continue; |
| 1110 | seq_printf(s, "%s\n", dbg_hsic_ctrl.buf[i]); |
| 1111 | } |
| 1112 | |
| 1113 | read_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 1114 | |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
| 1118 | static int ehci_hsic_msm_ctrl_events_open(struct inode *inode, struct file *f) |
| 1119 | { |
| 1120 | return single_open(f, ehci_hsic_msm_ctrl_events_show, inode->i_private); |
| 1121 | } |
| 1122 | |
| 1123 | const struct file_operations ehci_hsic_msm_dbg_ctrl_fops = { |
| 1124 | .open = ehci_hsic_msm_ctrl_events_open, |
| 1125 | .read = seq_read, |
| 1126 | .llseek = seq_lseek, |
| 1127 | .release = single_release, |
| 1128 | }; |
| 1129 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1130 | static struct dentry *ehci_hsic_msm_dbg_root; |
| 1131 | static int ehci_hsic_msm_debugfs_init(struct msm_hsic_hcd *mehci) |
| 1132 | { |
| 1133 | struct dentry *ehci_hsic_msm_dentry; |
| 1134 | |
| 1135 | ehci_hsic_msm_dbg_root = debugfs_create_dir("ehci_hsic_msm_dbg", NULL); |
| 1136 | |
| 1137 | if (!ehci_hsic_msm_dbg_root || IS_ERR(ehci_hsic_msm_dbg_root)) |
| 1138 | return -ENODEV; |
| 1139 | |
| 1140 | ehci_hsic_msm_dentry = debugfs_create_file("bus_voting", |
| 1141 | S_IRUGO | S_IWUSR, |
| 1142 | ehci_hsic_msm_dbg_root, mehci, |
| 1143 | &ehci_hsic_msm_bus_fops); |
| 1144 | |
| 1145 | if (!ehci_hsic_msm_dentry) { |
| 1146 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1147 | return -ENODEV; |
| 1148 | } |
| 1149 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1150 | ehci_hsic_msm_dentry = debugfs_create_file("wakeup_cnt", |
| 1151 | S_IRUGO, |
| 1152 | ehci_hsic_msm_dbg_root, mehci, |
| 1153 | &ehci_hsic_msm_wakeup_cnt_fops); |
| 1154 | |
| 1155 | if (!ehci_hsic_msm_dentry) { |
| 1156 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1157 | return -ENODEV; |
| 1158 | } |
| 1159 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1160 | ehci_hsic_msm_dentry = debugfs_create_file("show_ctrl_events", |
| 1161 | S_IRUGO, |
| 1162 | ehci_hsic_msm_dbg_root, mehci, |
| 1163 | &ehci_hsic_msm_dbg_ctrl_fops); |
| 1164 | |
| 1165 | if (!ehci_hsic_msm_dentry) { |
| 1166 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1167 | return -ENODEV; |
| 1168 | } |
| 1169 | |
| 1170 | ehci_hsic_msm_dentry = debugfs_create_file("show_data_events", |
| 1171 | S_IRUGO, |
| 1172 | ehci_hsic_msm_dbg_root, mehci, |
| 1173 | &ehci_hsic_msm_dbg_data_fops); |
| 1174 | |
| 1175 | if (!ehci_hsic_msm_dentry) { |
| 1176 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1177 | return -ENODEV; |
| 1178 | } |
| 1179 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1180 | return 0; |
| 1181 | } |
| 1182 | |
| 1183 | static void ehci_hsic_msm_debugfs_cleanup(void) |
| 1184 | { |
| 1185 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1186 | } |
| 1187 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1188 | static int __devinit ehci_hsic_msm_probe(struct platform_device *pdev) |
| 1189 | { |
| 1190 | struct usb_hcd *hcd; |
| 1191 | struct resource *res; |
| 1192 | struct msm_hsic_hcd *mehci; |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 1193 | struct msm_hsic_host_platform_data *pdata; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1194 | int ret; |
| 1195 | |
| 1196 | dev_dbg(&pdev->dev, "ehci_msm-hsic probe\n"); |
| 1197 | |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1198 | /* After parent device's probe is executed, it will be put in suspend |
| 1199 | * mode. When child device's probe is called, driver core is not |
| 1200 | * resuming parent device due to which parent will be in suspend even |
| 1201 | * though child is active. Hence resume the parent device explicitly. |
| 1202 | */ |
| 1203 | if (pdev->dev.parent) |
| 1204 | pm_runtime_get_sync(pdev->dev.parent); |
| 1205 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1206 | hcd = usb_create_hcd(&msm_hsic_driver, &pdev->dev, |
| 1207 | dev_name(&pdev->dev)); |
| 1208 | if (!hcd) { |
| 1209 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
| 1210 | return -ENOMEM; |
| 1211 | } |
| 1212 | |
| 1213 | hcd->irq = platform_get_irq(pdev, 0); |
| 1214 | if (hcd->irq < 0) { |
| 1215 | dev_err(&pdev->dev, "Unable to get IRQ resource\n"); |
| 1216 | ret = hcd->irq; |
| 1217 | goto put_hcd; |
| 1218 | } |
| 1219 | |
| 1220 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1221 | if (!res) { |
| 1222 | dev_err(&pdev->dev, "Unable to get memory resource\n"); |
| 1223 | ret = -ENODEV; |
| 1224 | goto put_hcd; |
| 1225 | } |
| 1226 | |
| 1227 | hcd->rsrc_start = res->start; |
| 1228 | hcd->rsrc_len = resource_size(res); |
| 1229 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 1230 | if (!hcd->regs) { |
| 1231 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 1232 | ret = -ENOMEM; |
| 1233 | goto put_hcd; |
| 1234 | } |
| 1235 | |
| 1236 | mehci = hcd_to_hsic(hcd); |
| 1237 | mehci->dev = &pdev->dev; |
| 1238 | |
Hemant Kumar | 38ce5d8 | 2012-05-29 13:00:58 -0700 | [diff] [blame] | 1239 | mehci->ehci.susp_sof_bug = 1; |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 1240 | mehci->ehci.reset_sof_bug = 1; |
Hemant Kumar | 38ce5d8 | 2012-05-29 13:00:58 -0700 | [diff] [blame] | 1241 | |
Hemant Kumar | e404049 | 2012-06-21 17:35:42 -0700 | [diff] [blame^] | 1242 | mehci->ehci.resume_sof_bug = 1; |
| 1243 | |
Hemant Kumar | 933e040 | 2012-05-22 11:11:40 -0700 | [diff] [blame] | 1244 | mehci->ehci.max_log2_irq_thresh = 6; |
| 1245 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1246 | res = platform_get_resource_byname(pdev, |
| 1247 | IORESOURCE_IRQ, |
| 1248 | "peripheral_status_irq"); |
| 1249 | if (res) |
| 1250 | mehci->peripheral_status_irq = res->start; |
| 1251 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1252 | res = platform_get_resource_byname(pdev, IORESOURCE_IO, "wakeup"); |
| 1253 | if (res) { |
| 1254 | mehci->wakeup_gpio = res->start; |
| 1255 | mehci->wakeup_irq = MSM_GPIO_TO_INT(res->start); |
| 1256 | dev_dbg(mehci->dev, "wakeup_irq: %d\n", mehci->wakeup_irq); |
| 1257 | } |
| 1258 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1259 | ret = msm_hsic_init_clocks(mehci, 1); |
| 1260 | if (ret) { |
| 1261 | dev_err(&pdev->dev, "unable to initialize clocks\n"); |
| 1262 | ret = -ENODEV; |
| 1263 | goto unmap; |
| 1264 | } |
| 1265 | |
| 1266 | ret = msm_hsic_init_vddcx(mehci, 1); |
| 1267 | if (ret) { |
| 1268 | dev_err(&pdev->dev, "unable to initialize VDDCX\n"); |
| 1269 | ret = -ENODEV; |
| 1270 | goto deinit_clocks; |
| 1271 | } |
| 1272 | |
| 1273 | ret = msm_hsic_reset(mehci); |
| 1274 | if (ret) { |
| 1275 | dev_err(&pdev->dev, "unable to initialize PHY\n"); |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1276 | goto deinit_vddcx; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1277 | } |
| 1278 | |
| 1279 | ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
| 1280 | if (ret) { |
| 1281 | dev_err(&pdev->dev, "unable to register HCD\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1282 | goto unconfig_gpio; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1283 | } |
| 1284 | |
| 1285 | device_init_wakeup(&pdev->dev, 1); |
| 1286 | wake_lock_init(&mehci->wlock, WAKE_LOCK_SUSPEND, dev_name(&pdev->dev)); |
| 1287 | wake_lock(&mehci->wlock); |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1288 | |
| 1289 | if (mehci->peripheral_status_irq) { |
| 1290 | ret = request_threaded_irq(mehci->peripheral_status_irq, |
| 1291 | NULL, hsic_peripheral_status_change, |
| 1292 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
| 1293 | | IRQF_SHARED, |
| 1294 | "hsic_peripheral_status", mehci); |
| 1295 | if (ret) |
| 1296 | dev_err(&pdev->dev, "%s:request_irq:%d failed:%d", |
| 1297 | __func__, mehci->peripheral_status_irq, ret); |
| 1298 | } |
| 1299 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1300 | /* configure wakeup irq */ |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1301 | if (mehci->wakeup_irq) { |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1302 | ret = request_irq(mehci->wakeup_irq, msm_hsic_wakeup_irq, |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1303 | IRQF_TRIGGER_HIGH, |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1304 | "msm_hsic_wakeup", mehci); |
| 1305 | if (!ret) { |
| 1306 | disable_irq_nosync(mehci->wakeup_irq); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1307 | } else { |
| 1308 | dev_err(&pdev->dev, "request_irq(%d) failed: %d\n", |
| 1309 | mehci->wakeup_irq, ret); |
| 1310 | mehci->wakeup_irq = 0; |
| 1311 | } |
| 1312 | } |
| 1313 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1314 | ret = ehci_hsic_msm_debugfs_init(mehci); |
| 1315 | if (ret) |
| 1316 | dev_dbg(&pdev->dev, "mode debugfs file is" |
| 1317 | "not available\n"); |
| 1318 | |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1319 | pdata = mehci->dev->platform_data; |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1320 | if (pdata && pdata->bus_scale_table) { |
| 1321 | mehci->bus_perf_client = |
| 1322 | msm_bus_scale_register_client(pdata->bus_scale_table); |
| 1323 | /* Configure BUS performance parameters for MAX bandwidth */ |
| 1324 | if (mehci->bus_perf_client) { |
| 1325 | ret = msm_bus_scale_client_update_request( |
| 1326 | mehci->bus_perf_client, 1); |
| 1327 | if (ret) |
| 1328 | dev_err(&pdev->dev, "%s: Failed to vote for " |
| 1329 | "bus bandwidth %d\n", __func__, ret); |
| 1330 | } else { |
| 1331 | dev_err(&pdev->dev, "%s: Failed to register BUS " |
| 1332 | "scaling client!!\n", __func__); |
| 1333 | } |
| 1334 | } |
| 1335 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1336 | /* |
| 1337 | * This pdev->dev is assigned parent of root-hub by USB core, |
| 1338 | * hence, runtime framework automatically calls this driver's |
| 1339 | * runtime APIs based on root-hub's state. |
| 1340 | */ |
| 1341 | pm_runtime_set_active(&pdev->dev); |
| 1342 | pm_runtime_enable(&pdev->dev); |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1343 | /* Decrement the parent device's counter after probe. |
| 1344 | * As child is active, parent will not be put into |
| 1345 | * suspend mode. |
| 1346 | */ |
| 1347 | if (pdev->dev.parent) |
| 1348 | pm_runtime_put_sync(pdev->dev.parent); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1349 | |
| 1350 | return 0; |
| 1351 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1352 | unconfig_gpio: |
| 1353 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1354 | deinit_vddcx: |
| 1355 | msm_hsic_init_vddcx(mehci, 0); |
| 1356 | deinit_clocks: |
| 1357 | msm_hsic_init_clocks(mehci, 0); |
| 1358 | unmap: |
| 1359 | iounmap(hcd->regs); |
| 1360 | put_hcd: |
| 1361 | usb_put_hcd(hcd); |
| 1362 | |
| 1363 | return ret; |
| 1364 | } |
| 1365 | |
| 1366 | static int __devexit ehci_hsic_msm_remove(struct platform_device *pdev) |
| 1367 | { |
| 1368 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 1369 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1370 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1371 | if (mehci->peripheral_status_irq) |
| 1372 | free_irq(mehci->peripheral_status_irq, mehci); |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1373 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1374 | if (mehci->wakeup_irq) { |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1375 | if (mehci->wakeup_irq_enabled) |
| 1376 | disable_irq_wake(mehci->wakeup_irq); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1377 | free_irq(mehci->wakeup_irq, mehci); |
| 1378 | } |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1379 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1380 | if (mehci->bus_perf_client) |
| 1381 | msm_bus_scale_unregister_client(mehci->bus_perf_client); |
| 1382 | |
| 1383 | ehci_hsic_msm_debugfs_cleanup(); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1384 | device_init_wakeup(&pdev->dev, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1385 | pm_runtime_set_suspended(&pdev->dev); |
| 1386 | |
| 1387 | usb_remove_hcd(hcd); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1388 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1389 | msm_hsic_init_vddcx(mehci, 0); |
| 1390 | |
| 1391 | msm_hsic_init_clocks(mehci, 0); |
| 1392 | wake_lock_destroy(&mehci->wlock); |
| 1393 | iounmap(hcd->regs); |
| 1394 | usb_put_hcd(hcd); |
| 1395 | |
| 1396 | return 0; |
| 1397 | } |
| 1398 | |
| 1399 | #ifdef CONFIG_PM_SLEEP |
| 1400 | static int msm_hsic_pm_suspend(struct device *dev) |
| 1401 | { |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 1402 | int ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1403 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1404 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1405 | |
| 1406 | dev_dbg(dev, "ehci-msm-hsic PM suspend\n"); |
| 1407 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1408 | dbg_log_event(NULL, "PM Suspend", 0); |
| 1409 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1410 | if (device_may_wakeup(dev)) |
| 1411 | enable_irq_wake(hcd->irq); |
| 1412 | |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 1413 | ret = msm_hsic_suspend(mehci); |
| 1414 | |
| 1415 | if (ret && device_may_wakeup(dev)) |
| 1416 | disable_irq_wake(hcd->irq); |
| 1417 | |
| 1418 | return ret; |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1419 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1420 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1421 | static int msm_hsic_pm_resume(struct device *dev) |
| 1422 | { |
| 1423 | int ret; |
| 1424 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1425 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1426 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1427 | dbg_log_event(NULL, "PM Resume", 0); |
| 1428 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1429 | if (device_may_wakeup(dev)) |
| 1430 | disable_irq_wake(hcd->irq); |
| 1431 | |
| 1432 | ret = msm_hsic_resume(mehci); |
| 1433 | if (ret) |
| 1434 | return ret; |
| 1435 | |
| 1436 | /* Bring the device to full powered state upon system resume */ |
| 1437 | pm_runtime_disable(dev); |
| 1438 | pm_runtime_set_active(dev); |
| 1439 | pm_runtime_enable(dev); |
| 1440 | |
| 1441 | return 0; |
| 1442 | } |
| 1443 | #endif |
| 1444 | |
| 1445 | #ifdef CONFIG_PM_RUNTIME |
| 1446 | static int msm_hsic_runtime_idle(struct device *dev) |
| 1447 | { |
| 1448 | dev_dbg(dev, "EHCI runtime idle\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1449 | return 0; |
| 1450 | } |
| 1451 | |
| 1452 | static int msm_hsic_runtime_suspend(struct device *dev) |
| 1453 | { |
| 1454 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1455 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1456 | |
| 1457 | dev_dbg(dev, "EHCI runtime suspend\n"); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1458 | |
| 1459 | dbg_log_event(NULL, "Run Time PM Suspend", 0); |
| 1460 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1461 | return msm_hsic_suspend(mehci); |
| 1462 | } |
| 1463 | |
| 1464 | static int msm_hsic_runtime_resume(struct device *dev) |
| 1465 | { |
| 1466 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1467 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1468 | |
| 1469 | dev_dbg(dev, "EHCI runtime resume\n"); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1470 | |
| 1471 | dbg_log_event(NULL, "Run Time PM Resume", 0); |
| 1472 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1473 | return msm_hsic_resume(mehci); |
| 1474 | } |
| 1475 | #endif |
| 1476 | |
| 1477 | #ifdef CONFIG_PM |
| 1478 | static const struct dev_pm_ops msm_hsic_dev_pm_ops = { |
| 1479 | SET_SYSTEM_SLEEP_PM_OPS(msm_hsic_pm_suspend, msm_hsic_pm_resume) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1480 | SET_RUNTIME_PM_OPS(msm_hsic_runtime_suspend, msm_hsic_runtime_resume, |
| 1481 | msm_hsic_runtime_idle) |
| 1482 | }; |
| 1483 | #endif |
| 1484 | |
| 1485 | static struct platform_driver ehci_msm_hsic_driver = { |
| 1486 | .probe = ehci_hsic_msm_probe, |
| 1487 | .remove = __devexit_p(ehci_hsic_msm_remove), |
| 1488 | .driver = { |
| 1489 | .name = "msm_hsic_host", |
| 1490 | #ifdef CONFIG_PM |
| 1491 | .pm = &msm_hsic_dev_pm_ops, |
| 1492 | #endif |
| 1493 | }, |
| 1494 | }; |