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> |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 30 | #include <linux/wakelock.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 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> |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 38 | #include <linux/kthread.h> |
| 39 | #include <linux/wait.h> |
Pavankumar Kondeti | fe2d4d3 | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 40 | #include <linux/pm_qos.h> |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 41 | |
| 42 | #include <mach/msm_bus.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 43 | #include <mach/clk.h> |
| 44 | #include <mach/msm_iomap.h> |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 45 | #include <mach/msm_xo.h> |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 46 | #include <linux/spinlock.h> |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 47 | #include <linux/cpu.h> |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 48 | #include <mach/rpm-regulator.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 49 | |
| 50 | #define MSM_USB_BASE (hcd->regs) |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 51 | #define USB_REG_START_OFFSET 0x90 |
| 52 | #define USB_REG_END_OFFSET 0x250 |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 53 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 54 | static struct workqueue_struct *ehci_wq; |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 55 | struct ehci_timer { |
| 56 | #define GPT_LD(p) ((p) & 0x00FFFFFF) |
| 57 | u32 gptimer0_ld; |
| 58 | #define GPT_RUN BIT(31) |
| 59 | #define GPT_RESET BIT(30) |
| 60 | #define GPT_MODE BIT(24) |
| 61 | #define GPT_CNT(p) ((p) & 0x00FFFFFF) |
| 62 | u32 gptimer0_ctrl; |
| 63 | |
| 64 | u32 gptimer1_ld; |
| 65 | u32 gptimer1_ctrl; |
| 66 | }; |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 67 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 68 | struct msm_hsic_hcd { |
| 69 | struct ehci_hcd ehci; |
Hemant Kumar | 4cd49e1 | 2012-09-06 19:57:14 -0700 | [diff] [blame] | 70 | spinlock_t wakeup_lock; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 71 | struct device *dev; |
| 72 | struct clk *ahb_clk; |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 73 | struct clk *core_clk; |
| 74 | struct clk *alt_core_clk; |
| 75 | struct clk *phy_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 76 | struct clk *cal_clk; |
| 77 | struct regulator *hsic_vddcx; |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 78 | bool async_int; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 79 | atomic_t in_lpm; |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 80 | struct wake_lock wlock; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 81 | int peripheral_status_irq; |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 82 | int wakeup_irq; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 83 | int wakeup_gpio; |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 84 | bool wakeup_irq_enabled; |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 85 | atomic_t pm_usage_cnt; |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 86 | uint32_t bus_perf_client; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 87 | uint32_t wakeup_int_cnt; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 88 | enum usb_vdd_type vdd_type; |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 89 | |
| 90 | struct work_struct bus_vote_w; |
| 91 | bool bus_vote; |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 92 | |
| 93 | /* gp timer */ |
| 94 | struct ehci_timer __iomem *timer; |
| 95 | struct completion gpt0_completion; |
| 96 | struct completion rt_completion; |
| 97 | int resume_status; |
| 98 | int resume_again; |
Pavankumar Kondeti | fe2d4d3 | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 99 | |
| 100 | struct pm_qos_request pm_qos_req_dma; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 101 | }; |
| 102 | |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 103 | struct msm_hsic_hcd *__mehci; |
| 104 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 105 | static bool debug_bus_voting_enabled = true; |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 106 | |
| 107 | static unsigned int enable_dbg_log = 1; |
| 108 | module_param(enable_dbg_log, uint, S_IRUGO | S_IWUSR); |
| 109 | /*by default log ep0 and efs sync ep*/ |
| 110 | static unsigned int ep_addr_rxdbg_mask = 9; |
| 111 | module_param(ep_addr_rxdbg_mask, uint, S_IRUGO | S_IWUSR); |
| 112 | static unsigned int ep_addr_txdbg_mask = 9; |
| 113 | module_param(ep_addr_txdbg_mask, uint, S_IRUGO | S_IWUSR); |
| 114 | |
| 115 | /* Maximum debug message length */ |
| 116 | #define DBG_MSG_LEN 100UL |
| 117 | |
| 118 | /* Maximum number of messages */ |
| 119 | #define DBG_MAX_MSG 256UL |
| 120 | |
| 121 | #define TIME_BUF_LEN 20 |
| 122 | |
| 123 | enum event_type { |
| 124 | EVENT_UNDEF = -1, |
| 125 | URB_SUBMIT, |
| 126 | URB_COMPLETE, |
| 127 | EVENT_NONE, |
| 128 | }; |
| 129 | |
| 130 | #define EVENT_STR_LEN 5 |
| 131 | |
| 132 | static char *event_to_str(enum event_type e) |
| 133 | { |
| 134 | switch (e) { |
| 135 | case URB_SUBMIT: |
| 136 | return "S"; |
| 137 | case URB_COMPLETE: |
| 138 | return "C"; |
| 139 | case EVENT_NONE: |
| 140 | return "NONE"; |
| 141 | default: |
| 142 | return "UNDEF"; |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | static enum event_type str_to_event(const char *name) |
| 147 | { |
| 148 | if (!strncasecmp("S", name, EVENT_STR_LEN)) |
| 149 | return URB_SUBMIT; |
| 150 | if (!strncasecmp("C", name, EVENT_STR_LEN)) |
| 151 | return URB_COMPLETE; |
| 152 | if (!strncasecmp("", name, EVENT_STR_LEN)) |
| 153 | return EVENT_NONE; |
| 154 | |
| 155 | return EVENT_UNDEF; |
| 156 | } |
| 157 | |
| 158 | /*log ep0 activity*/ |
| 159 | static struct { |
| 160 | char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */ |
| 161 | unsigned idx; /* index */ |
| 162 | rwlock_t lck; /* lock */ |
| 163 | } dbg_hsic_ctrl = { |
| 164 | .idx = 0, |
| 165 | .lck = __RW_LOCK_UNLOCKED(lck) |
| 166 | }; |
| 167 | |
| 168 | static struct { |
| 169 | char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */ |
| 170 | unsigned idx; /* index */ |
| 171 | rwlock_t lck; /* lock */ |
| 172 | } dbg_hsic_data = { |
| 173 | .idx = 0, |
| 174 | .lck = __RW_LOCK_UNLOCKED(lck) |
| 175 | }; |
| 176 | |
| 177 | /** |
| 178 | * dbg_inc: increments debug event index |
| 179 | * @idx: buffer index |
| 180 | */ |
| 181 | static void dbg_inc(unsigned *idx) |
| 182 | { |
| 183 | *idx = (*idx + 1) & (DBG_MAX_MSG-1); |
| 184 | } |
| 185 | |
| 186 | /*get_timestamp - returns time of day in us */ |
| 187 | static char *get_timestamp(char *tbuf) |
| 188 | { |
| 189 | unsigned long long t; |
| 190 | unsigned long nanosec_rem; |
| 191 | |
| 192 | t = cpu_clock(smp_processor_id()); |
| 193 | nanosec_rem = do_div(t, 1000000000)/1000; |
| 194 | scnprintf(tbuf, TIME_BUF_LEN, "[%5lu.%06lu] ", (unsigned long)t, |
| 195 | nanosec_rem); |
| 196 | return tbuf; |
| 197 | } |
| 198 | |
| 199 | static int allow_dbg_log(int ep_addr) |
| 200 | { |
| 201 | int dir, num; |
| 202 | |
| 203 | dir = ep_addr & USB_DIR_IN ? USB_DIR_IN : USB_DIR_OUT; |
| 204 | num = ep_addr & ~USB_DIR_IN; |
| 205 | num = 1 << num; |
| 206 | |
| 207 | if ((dir == USB_DIR_IN) && (num & ep_addr_rxdbg_mask)) |
| 208 | return 1; |
| 209 | if ((dir == USB_DIR_OUT) && (num & ep_addr_txdbg_mask)) |
| 210 | return 1; |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | static void dbg_log_event(struct urb *urb, char * event, unsigned extra) |
| 216 | { |
| 217 | unsigned long flags; |
| 218 | int ep_addr; |
| 219 | char tbuf[TIME_BUF_LEN]; |
| 220 | |
| 221 | if (!enable_dbg_log) |
| 222 | return; |
| 223 | |
| 224 | if (!urb) { |
| 225 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 226 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], DBG_MSG_LEN, |
| 227 | "%s: %s : %u\n", get_timestamp(tbuf), event, extra); |
| 228 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 229 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 230 | return; |
| 231 | } |
| 232 | |
| 233 | ep_addr = urb->ep->desc.bEndpointAddress; |
| 234 | if (!allow_dbg_log(ep_addr)) |
| 235 | return; |
| 236 | |
| 237 | if ((ep_addr & 0x0f) == 0x0) { |
| 238 | /*submit event*/ |
| 239 | if (!str_to_event(event)) { |
| 240 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 241 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], |
| 242 | DBG_MSG_LEN, "%s: [%s : %p]:[%s] " |
| 243 | "%02x %02x %04x %04x %04x %u %d\n", |
| 244 | get_timestamp(tbuf), event, urb, |
| 245 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 246 | urb->setup_packet[0], urb->setup_packet[1], |
| 247 | (urb->setup_packet[3] << 8) | |
| 248 | urb->setup_packet[2], |
| 249 | (urb->setup_packet[5] << 8) | |
| 250 | urb->setup_packet[4], |
| 251 | (urb->setup_packet[7] << 8) | |
| 252 | urb->setup_packet[6], |
| 253 | urb->transfer_buffer_length, urb->status); |
| 254 | |
| 255 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 256 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 257 | } else { |
| 258 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 259 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], |
| 260 | DBG_MSG_LEN, "%s: [%s : %p]:[%s] %u %d\n", |
| 261 | get_timestamp(tbuf), event, urb, |
| 262 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 263 | urb->actual_length, extra); |
| 264 | |
| 265 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 266 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 267 | } |
| 268 | } else { |
| 269 | write_lock_irqsave(&dbg_hsic_data.lck, flags); |
| 270 | scnprintf(dbg_hsic_data.buf[dbg_hsic_data.idx], DBG_MSG_LEN, |
| 271 | "%s: [%s : %p]:ep%d[%s] %u %d\n", |
| 272 | get_timestamp(tbuf), event, urb, ep_addr & 0x0f, |
| 273 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 274 | str_to_event(event) ? urb->actual_length : |
| 275 | urb->transfer_buffer_length, |
| 276 | str_to_event(event) ? extra : urb->status); |
| 277 | |
| 278 | dbg_inc(&dbg_hsic_data.idx); |
| 279 | write_unlock_irqrestore(&dbg_hsic_data.lck, flags); |
| 280 | } |
| 281 | } |
| 282 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 283 | static inline struct msm_hsic_hcd *hcd_to_hsic(struct usb_hcd *hcd) |
| 284 | { |
| 285 | return (struct msm_hsic_hcd *) (hcd->hcd_priv); |
| 286 | } |
| 287 | |
| 288 | static inline struct usb_hcd *hsic_to_hcd(struct msm_hsic_hcd *mehci) |
| 289 | { |
| 290 | return container_of((void *) mehci, struct usb_hcd, hcd_priv); |
| 291 | } |
| 292 | |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 293 | static void dump_hsic_regs(struct usb_hcd *hcd) |
| 294 | { |
| 295 | int i; |
| 296 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 297 | |
| 298 | if (atomic_read(&mehci->in_lpm)) |
| 299 | return; |
| 300 | |
| 301 | for (i = USB_REG_START_OFFSET; i <= USB_REG_END_OFFSET; i += 0x10) |
| 302 | pr_info("%p: %08x\t%08x\t%08x\t%08x\n", hcd->regs + i, |
| 303 | readl_relaxed(hcd->regs + i), |
| 304 | readl_relaxed(hcd->regs + i + 4), |
| 305 | readl_relaxed(hcd->regs + i + 8), |
| 306 | readl_relaxed(hcd->regs + i + 0xc)); |
| 307 | } |
| 308 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 309 | #define ULPI_IO_TIMEOUT_USEC (10 * 1000) |
| 310 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 311 | #define USB_PHY_VDD_DIG_VOL_NONE 0 /*uV */ |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 312 | #define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */ |
| 313 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 314 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 315 | #define HSIC_DBG1_REG 0x38 |
| 316 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 317 | static const int vdd_val[VDD_TYPE_MAX][VDD_VAL_MAX] = { |
| 318 | { /* VDD_CX CORNER Voting */ |
| 319 | [VDD_NONE] = RPM_VREG_CORNER_NONE, |
| 320 | [VDD_MIN] = RPM_VREG_CORNER_NOMINAL, |
| 321 | [VDD_MAX] = RPM_VREG_CORNER_HIGH, |
| 322 | }, |
| 323 | { /* VDD_CX Voltage Voting */ |
| 324 | [VDD_NONE] = USB_PHY_VDD_DIG_VOL_NONE, |
| 325 | [VDD_MIN] = USB_PHY_VDD_DIG_VOL_MIN, |
| 326 | [VDD_MAX] = USB_PHY_VDD_DIG_VOL_MAX, |
| 327 | }, |
| 328 | }; |
| 329 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 330 | static int msm_hsic_init_vddcx(struct msm_hsic_hcd *mehci, int init) |
| 331 | { |
| 332 | int ret = 0; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 333 | int none_vol, min_vol, max_vol; |
| 334 | |
| 335 | if (!mehci->hsic_vddcx) { |
| 336 | mehci->vdd_type = VDDCX_CORNER; |
| 337 | mehci->hsic_vddcx = devm_regulator_get(mehci->dev, |
| 338 | "hsic_vdd_dig"); |
| 339 | if (IS_ERR(mehci->hsic_vddcx)) { |
| 340 | mehci->hsic_vddcx = devm_regulator_get(mehci->dev, |
| 341 | "HSIC_VDDCX"); |
| 342 | if (IS_ERR(mehci->hsic_vddcx)) { |
| 343 | dev_err(mehci->dev, "unable to get hsic vddcx\n"); |
| 344 | return PTR_ERR(mehci->hsic_vddcx); |
| 345 | } |
| 346 | mehci->vdd_type = VDDCX; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | none_vol = vdd_val[mehci->vdd_type][VDD_NONE]; |
| 351 | min_vol = vdd_val[mehci->vdd_type][VDD_MIN]; |
| 352 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 353 | |
| 354 | if (!init) |
| 355 | goto disable_reg; |
| 356 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 357 | ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 358 | if (ret) { |
| 359 | dev_err(mehci->dev, "unable to set the voltage" |
| 360 | "for hsic vddcx\n"); |
Mayank Rana | 189ac05 | 2012-03-24 04:35:02 +0530 | [diff] [blame] | 361 | return ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 362 | } |
| 363 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 364 | ret = regulator_enable(mehci->hsic_vddcx); |
| 365 | if (ret) { |
| 366 | dev_err(mehci->dev, "unable to enable hsic vddcx\n"); |
| 367 | goto reg_enable_err; |
| 368 | } |
| 369 | |
| 370 | return 0; |
| 371 | |
| 372 | disable_reg: |
| 373 | regulator_disable(mehci->hsic_vddcx); |
| 374 | reg_enable_err: |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 375 | regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol); |
| 376 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 377 | return ret; |
| 378 | |
| 379 | } |
| 380 | |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 381 | static int ulpi_read(struct msm_hsic_hcd *mehci, u32 reg) |
| 382 | { |
| 383 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Devin Kim | 01e5a5b | 2012-08-30 02:52:45 -0700 | [diff] [blame] | 384 | int cnt = 0; |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 385 | |
| 386 | /* initiate read operation */ |
| 387 | writel_relaxed(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg), |
| 388 | USB_ULPI_VIEWPORT); |
| 389 | |
| 390 | /* wait for completion */ |
Devin Kim | 01e5a5b | 2012-08-30 02:52:45 -0700 | [diff] [blame] | 391 | while (cnt < ULPI_IO_TIMEOUT_USEC) { |
| 392 | if (!(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN)) |
| 393 | break; |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 394 | udelay(1); |
Devin Kim | 01e5a5b | 2012-08-30 02:52:45 -0700 | [diff] [blame] | 395 | cnt++; |
| 396 | } |
| 397 | |
| 398 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { |
| 399 | dev_err(mehci->dev, "ulpi_read: timeout ULPI_VIEWPORT: %08x\n", |
| 400 | readl_relaxed(USB_ULPI_VIEWPORT)); |
| 401 | dev_err(mehci->dev, "PORTSC: %08x USBCMD: %08x FRINDEX: %08x\n", |
| 402 | readl_relaxed(USB_PORTSC), |
| 403 | readl_relaxed(USB_USBCMD), |
| 404 | readl_relaxed(USB_FRINDEX)); |
| 405 | |
| 406 | /*frame counter increments afte 125us*/ |
| 407 | udelay(130); |
| 408 | dev_err(mehci->dev, "ulpi_read: FRINDEX: %08x\n", |
| 409 | readl_relaxed(USB_FRINDEX)); |
| 410 | return -ETIMEDOUT; |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | return ULPI_DATA_READ(readl_relaxed(USB_ULPI_VIEWPORT)); |
| 414 | } |
| 415 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 416 | static int ulpi_write(struct msm_hsic_hcd *mehci, u32 val, u32 reg) |
| 417 | { |
| 418 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
| 419 | int cnt = 0; |
| 420 | |
| 421 | /* initiate write operation */ |
| 422 | writel_relaxed(ULPI_RUN | ULPI_WRITE | |
| 423 | ULPI_ADDR(reg) | ULPI_DATA(val), |
| 424 | USB_ULPI_VIEWPORT); |
| 425 | |
| 426 | /* wait for completion */ |
| 427 | while (cnt < ULPI_IO_TIMEOUT_USEC) { |
| 428 | if (!(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN)) |
| 429 | break; |
| 430 | udelay(1); |
| 431 | cnt++; |
| 432 | } |
| 433 | |
| 434 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { |
Devin Kim | 01e5a5b | 2012-08-30 02:52:45 -0700 | [diff] [blame] | 435 | dev_err(mehci->dev, "ulpi_write: timeout ULPI_VIEWPORT: %08x\n", |
| 436 | readl_relaxed(USB_ULPI_VIEWPORT)); |
| 437 | dev_err(mehci->dev, "PORTSC: %08x USBCMD: %08x FRINDEX: %08x\n", |
| 438 | readl_relaxed(USB_PORTSC), |
| 439 | readl_relaxed(USB_USBCMD), |
| 440 | readl_relaxed(USB_FRINDEX)); |
| 441 | |
| 442 | /*frame counter increments afte 125us*/ |
| 443 | udelay(130); |
| 444 | dev_err(mehci->dev, "ulpi_write: FRINDEX: %08x\n", |
| 445 | readl_relaxed(USB_FRINDEX)); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 446 | return -ETIMEDOUT; |
| 447 | } |
| 448 | |
| 449 | return 0; |
| 450 | } |
| 451 | |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 452 | #define HSIC_DBG1 0X38 |
| 453 | #define ULPI_MANUAL_ENABLE BIT(4) |
| 454 | #define ULPI_LINESTATE_DATA BIT(5) |
| 455 | #define ULPI_LINESTATE_STROBE BIT(6) |
| 456 | static void ehci_msm_enable_ulpi_control(struct usb_hcd *hcd, u32 linestate) |
| 457 | { |
| 458 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 459 | int val; |
| 460 | |
| 461 | switch (linestate) { |
| 462 | case PORT_RESET: |
| 463 | val = ulpi_read(mehci, HSIC_DBG1); |
| 464 | val |= ULPI_MANUAL_ENABLE; |
| 465 | val &= ~(ULPI_LINESTATE_DATA | ULPI_LINESTATE_STROBE); |
| 466 | ulpi_write(mehci, val, HSIC_DBG1); |
| 467 | break; |
| 468 | default: |
| 469 | pr_info("%s: Unknown linestate:%0x\n", __func__, linestate); |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | static void ehci_msm_disable_ulpi_control(struct usb_hcd *hcd) |
| 474 | { |
| 475 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 476 | int val; |
| 477 | |
| 478 | val = ulpi_read(mehci, HSIC_DBG1); |
| 479 | val &= ~ULPI_MANUAL_ENABLE; |
| 480 | ulpi_write(mehci, val, HSIC_DBG1); |
| 481 | } |
| 482 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 483 | static int msm_hsic_config_gpios(struct msm_hsic_hcd *mehci, int gpio_en) |
| 484 | { |
| 485 | int rc = 0; |
| 486 | struct msm_hsic_host_platform_data *pdata; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 487 | static int gpio_status; |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 488 | |
| 489 | pdata = mehci->dev->platform_data; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 490 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 491 | if (!pdata || !pdata->strobe || !pdata->data) |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 492 | return rc; |
| 493 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 494 | if (gpio_status == gpio_en) |
| 495 | return 0; |
| 496 | |
| 497 | gpio_status = gpio_en; |
| 498 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 499 | if (!gpio_en) |
| 500 | goto free_gpio; |
| 501 | |
| 502 | rc = gpio_request(pdata->strobe, "HSIC_STROBE_GPIO"); |
| 503 | if (rc < 0) { |
| 504 | dev_err(mehci->dev, "gpio request failed for HSIC STROBE\n"); |
| 505 | return rc; |
| 506 | } |
| 507 | |
| 508 | rc = gpio_request(pdata->data, "HSIC_DATA_GPIO"); |
| 509 | if (rc < 0) { |
| 510 | dev_err(mehci->dev, "gpio request failed for HSIC DATA\n"); |
| 511 | goto free_strobe; |
| 512 | } |
| 513 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 514 | if (mehci->wakeup_gpio) { |
| 515 | rc = gpio_request(mehci->wakeup_gpio, "HSIC_WAKEUP_GPIO"); |
| 516 | if (rc < 0) { |
| 517 | dev_err(mehci->dev, "gpio request failed for HSIC WAKEUP\n"); |
| 518 | goto free_data; |
| 519 | } |
| 520 | } |
| 521 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 522 | return 0; |
| 523 | |
| 524 | free_gpio: |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 525 | if (mehci->wakeup_gpio) |
| 526 | gpio_free(mehci->wakeup_gpio); |
| 527 | free_data: |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 528 | gpio_free(pdata->data); |
| 529 | free_strobe: |
| 530 | gpio_free(pdata->strobe); |
| 531 | |
| 532 | return rc; |
| 533 | } |
| 534 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 535 | static void msm_hsic_clk_reset(struct msm_hsic_hcd *mehci) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 536 | { |
| 537 | int ret; |
| 538 | |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 539 | ret = clk_reset(mehci->core_clk, CLK_RESET_ASSERT); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 540 | if (ret) { |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 541 | dev_err(mehci->dev, "hsic clk assert failed:%d\n", ret); |
| 542 | return; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 543 | } |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 544 | clk_disable(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 545 | |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 546 | ret = clk_reset(mehci->core_clk, CLK_RESET_DEASSERT); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 547 | if (ret) |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 548 | dev_err(mehci->dev, "hsic clk deassert failed:%d\n", ret); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 549 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 550 | usleep_range(10000, 12000); |
| 551 | |
| 552 | clk_enable(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 553 | } |
| 554 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 555 | #define HSIC_STROBE_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C0) |
| 556 | #define HSIC_DATA_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C4) |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 557 | #define HSIC_CAL_PAD_CTL (MSM_TLMM_BASE+0x20C8) |
| 558 | #define HSIC_LV_MODE 0x04 |
| 559 | #define HSIC_PAD_CALIBRATION 0xA8 |
| 560 | #define HSIC_GPIO_PAD_VAL 0x0A0AAA10 |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 561 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) |
| 562 | static int msm_hsic_reset(struct msm_hsic_hcd *mehci) |
| 563 | { |
| 564 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 565 | int ret; |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 566 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 567 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 568 | msm_hsic_clk_reset(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 569 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 570 | /* select ulpi phy */ |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 571 | writel_relaxed(0x80000000, USB_PORTSC); |
| 572 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 573 | mb(); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 574 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 575 | /* HSIC init sequence when HSIC signals (Strobe/Data) are |
| 576 | routed via GPIOs */ |
| 577 | if (pdata && pdata->strobe && pdata->data) { |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 578 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 579 | /* Enable LV_MODE in HSIC_CAL_PAD_CTL register */ |
| 580 | writel_relaxed(HSIC_LV_MODE, HSIC_CAL_PAD_CTL); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 581 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 582 | mb(); |
| 583 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 584 | /*set periodic calibration interval to ~2.048sec in |
| 585 | HSIC_IO_CAL_REG */ |
| 586 | ulpi_write(mehci, 0xFF, 0x33); |
| 587 | |
| 588 | /* Enable periodic IO calibration in HSIC_CFG register */ |
| 589 | ulpi_write(mehci, HSIC_PAD_CALIBRATION, 0x30); |
| 590 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 591 | /* Configure GPIO pins for HSIC functionality mode */ |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 592 | ret = msm_hsic_config_gpios(mehci, 1); |
| 593 | if (ret) { |
| 594 | dev_err(mehci->dev, " gpio configuarion failed\n"); |
| 595 | return ret; |
| 596 | } |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 597 | /* Set LV_MODE=0x1 and DCC=0x2 in HSIC_GPIO PAD_CTL register */ |
| 598 | writel_relaxed(HSIC_GPIO_PAD_VAL, HSIC_STROBE_GPIO_PAD_CTL); |
| 599 | writel_relaxed(HSIC_GPIO_PAD_VAL, HSIC_DATA_GPIO_PAD_CTL); |
| 600 | |
| 601 | mb(); |
| 602 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 603 | /* Enable HSIC mode in HSIC_CFG register */ |
| 604 | ulpi_write(mehci, 0x01, 0x31); |
| 605 | } else { |
| 606 | /* HSIC init sequence when HSIC signals (Strobe/Data) are routed |
| 607 | via dedicated I/O */ |
| 608 | |
| 609 | /* programmable length of connect signaling (33.2ns) */ |
| 610 | ret = ulpi_write(mehci, 3, HSIC_DBG1_REG); |
| 611 | if (ret) { |
| 612 | pr_err("%s: Unable to program length of connect " |
| 613 | "signaling\n", __func__); |
| 614 | } |
| 615 | |
| 616 | /*set periodic calibration interval to ~2.048sec in |
| 617 | HSIC_IO_CAL_REG */ |
| 618 | ulpi_write(mehci, 0xFF, 0x33); |
| 619 | |
| 620 | /* Enable HSIC mode in HSIC_CFG register */ |
| 621 | ulpi_write(mehci, 0xA9, 0x30); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 622 | } |
| 623 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 624 | /*disable auto resume*/ |
| 625 | ulpi_write(mehci, ULPI_IFC_CTRL_AUTORESUME, ULPI_CLR(ULPI_IFC_CTRL)); |
| 626 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) |
| 631 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) |
| 632 | |
| 633 | #ifdef CONFIG_PM_SLEEP |
| 634 | static int msm_hsic_suspend(struct msm_hsic_hcd *mehci) |
| 635 | { |
| 636 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 637 | int cnt = 0, ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 638 | u32 val; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 639 | int none_vol, max_vol; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 640 | |
| 641 | if (atomic_read(&mehci->in_lpm)) { |
| 642 | dev_dbg(mehci->dev, "%s called in lpm\n", __func__); |
| 643 | return 0; |
| 644 | } |
| 645 | |
Hemant Kumar | 7f37463 | 2012-05-31 20:10:32 -0700 | [diff] [blame] | 646 | if (!(readl_relaxed(USB_PORTSC) & PORT_PE)) { |
| 647 | dev_dbg(mehci->dev, "%s:port is not enabled skip suspend\n", |
| 648 | __func__); |
| 649 | return -EAGAIN; |
| 650 | } |
| 651 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 652 | disable_irq(hcd->irq); |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 653 | |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 654 | /* make sure we don't race against a remote wakeup */ |
| 655 | if (test_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags) || |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 656 | readl_relaxed(USB_PORTSC) & PORT_RESUME) { |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 657 | dev_dbg(mehci->dev, "wakeup pending, aborting suspend\n"); |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 658 | enable_irq(hcd->irq); |
| 659 | return -EBUSY; |
| 660 | } |
| 661 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 662 | /* |
| 663 | * PHY may take some time or even fail to enter into low power |
| 664 | * mode (LPM). Hence poll for 500 msec and reset the PHY and link |
| 665 | * in failure case. |
| 666 | */ |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 667 | val = readl_relaxed(USB_PORTSC); |
| 668 | val &= ~PORT_RWC_BITS; |
| 669 | val |= PORTSC_PHCD; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 670 | writel_relaxed(val, USB_PORTSC); |
| 671 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 672 | if (readl_relaxed(USB_PORTSC) & PORTSC_PHCD) |
| 673 | break; |
| 674 | udelay(1); |
| 675 | cnt++; |
| 676 | } |
| 677 | |
| 678 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) { |
| 679 | dev_err(mehci->dev, "Unable to suspend PHY\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 680 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 681 | msm_hsic_reset(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | /* |
| 685 | * PHY has capability to generate interrupt asynchronously in low |
| 686 | * power mode (LPM). This interrupt is level triggered. So USB IRQ |
| 687 | * line must be disabled till async interrupt enable bit is cleared |
| 688 | * in USBCMD register. Assert STP (ULPI interface STOP signal) to |
| 689 | * block data communication from PHY. |
| 690 | */ |
| 691 | writel_relaxed(readl_relaxed(USB_USBCMD) | ASYNC_INTR_CTRL | |
| 692 | ULPI_STP_CTRL, USB_USBCMD); |
| 693 | |
| 694 | /* |
| 695 | * Ensure that hardware is put in low power mode before |
| 696 | * clocks are turned OFF and VDD is allowed to minimize. |
| 697 | */ |
| 698 | mb(); |
| 699 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 700 | clk_disable_unprepare(mehci->core_clk); |
| 701 | clk_disable_unprepare(mehci->phy_clk); |
| 702 | clk_disable_unprepare(mehci->cal_clk); |
| 703 | clk_disable_unprepare(mehci->ahb_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 704 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 705 | none_vol = vdd_val[mehci->vdd_type][VDD_NONE]; |
| 706 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
| 707 | |
| 708 | ret = regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 709 | if (ret < 0) |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 710 | 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] | 711 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 712 | if (mehci->bus_perf_client && debug_bus_voting_enabled) { |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 713 | mehci->bus_vote = false; |
| 714 | queue_work(ehci_wq, &mehci->bus_vote_w); |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 715 | } |
| 716 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 717 | atomic_set(&mehci->in_lpm, 1); |
| 718 | enable_irq(hcd->irq); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 719 | |
| 720 | mehci->wakeup_irq_enabled = 1; |
| 721 | enable_irq_wake(mehci->wakeup_irq); |
| 722 | enable_irq(mehci->wakeup_irq); |
| 723 | |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 724 | wake_unlock(&mehci->wlock); |
| 725 | |
Devin Kim | 476bbd7 | 2012-07-19 18:11:11 -0700 | [diff] [blame] | 726 | dev_dbg(mehci->dev, "HSIC-USB in low power mode\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 727 | |
| 728 | return 0; |
| 729 | } |
| 730 | |
| 731 | static int msm_hsic_resume(struct msm_hsic_hcd *mehci) |
| 732 | { |
| 733 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 734 | int cnt = 0, ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 735 | unsigned temp; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 736 | int min_vol, max_vol; |
Hemant Kumar | 4cd49e1 | 2012-09-06 19:57:14 -0700 | [diff] [blame] | 737 | unsigned long flags; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 738 | |
| 739 | if (!atomic_read(&mehci->in_lpm)) { |
| 740 | dev_dbg(mehci->dev, "%s called in !in_lpm\n", __func__); |
| 741 | return 0; |
| 742 | } |
| 743 | |
Hemant Kumar | 4cd49e1 | 2012-09-06 19:57:14 -0700 | [diff] [blame] | 744 | spin_lock_irqsave(&mehci->wakeup_lock, flags); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 745 | if (mehci->wakeup_irq_enabled) { |
| 746 | disable_irq_wake(mehci->wakeup_irq); |
| 747 | disable_irq_nosync(mehci->wakeup_irq); |
| 748 | mehci->wakeup_irq_enabled = 0; |
| 749 | } |
Hemant Kumar | 4cd49e1 | 2012-09-06 19:57:14 -0700 | [diff] [blame] | 750 | spin_unlock_irqrestore(&mehci->wakeup_lock, flags); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 751 | |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 752 | wake_lock(&mehci->wlock); |
| 753 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 754 | if (mehci->bus_perf_client && debug_bus_voting_enabled) { |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 755 | mehci->bus_vote = true; |
| 756 | queue_work(ehci_wq, &mehci->bus_vote_w); |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 757 | } |
| 758 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 759 | min_vol = vdd_val[mehci->vdd_type][VDD_MIN]; |
| 760 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
| 761 | |
| 762 | ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 763 | if (ret < 0) |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 764 | 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] | 765 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 766 | clk_prepare_enable(mehci->core_clk); |
| 767 | clk_prepare_enable(mehci->phy_clk); |
| 768 | clk_prepare_enable(mehci->cal_clk); |
| 769 | clk_prepare_enable(mehci->ahb_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 770 | |
| 771 | temp = readl_relaxed(USB_USBCMD); |
| 772 | temp &= ~ASYNC_INTR_CTRL; |
| 773 | temp &= ~ULPI_STP_CTRL; |
| 774 | writel_relaxed(temp, USB_USBCMD); |
| 775 | |
| 776 | if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD)) |
| 777 | goto skip_phy_resume; |
| 778 | |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 779 | temp = readl_relaxed(USB_PORTSC); |
| 780 | temp &= ~(PORT_RWC_BITS | PORTSC_PHCD); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 781 | writel_relaxed(temp, USB_PORTSC); |
| 782 | while (cnt < PHY_RESUME_TIMEOUT_USEC) { |
| 783 | if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD) && |
| 784 | (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_SYNC_STATE)) |
| 785 | break; |
| 786 | udelay(1); |
| 787 | cnt++; |
| 788 | } |
| 789 | |
| 790 | if (cnt >= PHY_RESUME_TIMEOUT_USEC) { |
| 791 | /* |
| 792 | * This is a fatal error. Reset the link and |
| 793 | * PHY to make hsic working. |
| 794 | */ |
| 795 | dev_err(mehci->dev, "Unable to resume USB. Reset the hsic\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 796 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 797 | msm_hsic_reset(mehci); |
| 798 | } |
| 799 | |
| 800 | skip_phy_resume: |
| 801 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 802 | usb_hcd_resume_root_hub(hcd); |
| 803 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 804 | atomic_set(&mehci->in_lpm, 0); |
| 805 | |
| 806 | if (mehci->async_int) { |
| 807 | mehci->async_int = false; |
| 808 | pm_runtime_put_noidle(mehci->dev); |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 809 | enable_irq(hcd->irq); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 812 | if (atomic_read(&mehci->pm_usage_cnt)) { |
| 813 | atomic_set(&mehci->pm_usage_cnt, 0); |
| 814 | pm_runtime_put_noidle(mehci->dev); |
| 815 | } |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 816 | |
Devin Kim | 476bbd7 | 2012-07-19 18:11:11 -0700 | [diff] [blame] | 817 | dev_dbg(mehci->dev, "HSIC-USB exited from low power mode\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | #endif |
| 822 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 823 | static void ehci_hsic_bus_vote_w(struct work_struct *w) |
| 824 | { |
| 825 | struct msm_hsic_hcd *mehci = |
| 826 | container_of(w, struct msm_hsic_hcd, bus_vote_w); |
| 827 | int ret; |
| 828 | |
| 829 | ret = msm_bus_scale_client_update_request(mehci->bus_perf_client, |
| 830 | mehci->bus_vote); |
| 831 | if (ret) |
| 832 | dev_err(mehci->dev, "%s: Failed to vote for bus bandwidth %d\n", |
| 833 | __func__, ret); |
| 834 | } |
| 835 | |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 836 | #define STS_GPTIMER0_INTERRUPT BIT(24) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 837 | static irqreturn_t msm_hsic_irq(struct usb_hcd *hcd) |
| 838 | { |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 839 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 840 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 841 | u32 status; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 842 | |
| 843 | if (atomic_read(&mehci->in_lpm)) { |
| 844 | disable_irq_nosync(hcd->irq); |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 845 | dev_dbg(mehci->dev, "phy async intr\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 846 | mehci->async_int = true; |
| 847 | pm_runtime_get(mehci->dev); |
| 848 | return IRQ_HANDLED; |
| 849 | } |
| 850 | |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 851 | status = ehci_readl(ehci, &ehci->regs->status); |
| 852 | |
| 853 | if (status & STS_GPTIMER0_INTERRUPT) { |
| 854 | int timeleft; |
| 855 | |
| 856 | dbg_log_event(NULL, "FPR: gpt0_isr", 0); |
| 857 | |
| 858 | timeleft = GPT_CNT(ehci_readl(ehci, |
| 859 | &mehci->timer->gptimer1_ctrl)); |
| 860 | if (timeleft) { |
| 861 | ehci_writel(ehci, ehci_readl(ehci, |
| 862 | &ehci->regs->command) | CMD_RUN, |
| 863 | &ehci->regs->command); |
| 864 | } else |
| 865 | mehci->resume_again = 1; |
| 866 | |
| 867 | dbg_log_event(NULL, "FPR: timeleft", timeleft); |
| 868 | |
| 869 | complete(&mehci->gpt0_completion); |
| 870 | ehci_writel(ehci, STS_GPTIMER0_INTERRUPT, &ehci->regs->status); |
| 871 | } |
| 872 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 873 | return ehci_irq(hcd); |
| 874 | } |
| 875 | |
| 876 | static int ehci_hsic_reset(struct usb_hcd *hcd) |
| 877 | { |
| 878 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 879 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 880 | int retval; |
| 881 | |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 882 | mehci->timer = USB_HS_GPTIMER_BASE; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 883 | ehci->caps = USB_CAPLENGTH; |
| 884 | ehci->regs = USB_CAPLENGTH + |
| 885 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
| 886 | dbg_hcs_params(ehci, "reset"); |
| 887 | dbg_hcc_params(ehci, "reset"); |
| 888 | |
| 889 | /* cache the data to minimize the chip reads*/ |
| 890 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
| 891 | |
| 892 | hcd->has_tt = 1; |
| 893 | ehci->sbrn = HCD_USB2; |
| 894 | |
| 895 | retval = ehci_halt(ehci); |
| 896 | if (retval) |
| 897 | return retval; |
| 898 | |
| 899 | /* data structure init */ |
| 900 | retval = ehci_init(hcd); |
| 901 | if (retval) |
| 902 | return retval; |
| 903 | |
| 904 | retval = ehci_reset(ehci); |
| 905 | if (retval) |
| 906 | return retval; |
| 907 | |
| 908 | /* bursts of unspecified length. */ |
| 909 | writel_relaxed(0, USB_AHBBURST); |
| 910 | /* Use the AHB transactor */ |
Vijayavardhan Vennapusa | 5f32d7a | 2012-03-14 16:30:26 +0530 | [diff] [blame] | 911 | writel_relaxed(0x08, USB_AHBMODE); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 912 | /* Disable streaming mode and select host mode */ |
| 913 | writel_relaxed(0x13, USB_USBMODE); |
| 914 | |
| 915 | ehci_port_power(ehci, 1); |
| 916 | return 0; |
| 917 | } |
| 918 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 919 | static int ehci_hsic_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
| 920 | gfp_t mem_flags) |
| 921 | { |
| 922 | dbg_log_event(urb, event_to_str(URB_SUBMIT), 0); |
| 923 | return ehci_urb_enqueue(hcd, urb, mem_flags); |
| 924 | } |
| 925 | |
| 926 | static int ehci_hsic_bus_suspend(struct usb_hcd *hcd) |
| 927 | { |
| 928 | dbg_log_event(NULL, "Suspend RH", 0); |
| 929 | return ehci_bus_suspend(hcd); |
| 930 | } |
| 931 | |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 932 | #define RESUME_RETRY_LIMIT 3 |
| 933 | #define RESUME_SIGNAL_TIME_MS (21 * 999) |
| 934 | #define RESUME_SIGNAL_TIME_SOF_MS (23 * 999) |
| 935 | static int msm_hsic_resume_thread(void *data) |
| 936 | { |
| 937 | struct msm_hsic_hcd *mehci = data; |
| 938 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
| 939 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 940 | u32 temp; |
| 941 | unsigned long resume_needed = 0; |
| 942 | int retry_cnt = 0; |
| 943 | int tight_resume = 0; |
Pavankumar Kondeti | fe2d4d3 | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 944 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 945 | |
| 946 | dbg_log_event(NULL, "Resume RH", 0); |
| 947 | |
| 948 | /* keep delay between bus states */ |
| 949 | if (time_before(jiffies, ehci->next_statechange)) |
| 950 | usleep_range(5000, 5000); |
| 951 | |
| 952 | spin_lock_irq(&ehci->lock); |
| 953 | if (!HCD_HW_ACCESSIBLE(hcd)) { |
| 954 | spin_unlock_irq(&ehci->lock); |
| 955 | mehci->resume_status = -ESHUTDOWN; |
| 956 | complete(&mehci->rt_completion); |
| 957 | return 0; |
| 958 | } |
| 959 | |
| 960 | if (unlikely(ehci->debug)) { |
| 961 | if (!dbgp_reset_prep()) |
| 962 | ehci->debug = NULL; |
| 963 | else |
| 964 | dbgp_external_startup(); |
| 965 | } |
| 966 | |
| 967 | /* at least some APM implementations will try to deliver |
| 968 | * IRQs right away, so delay them until we're ready. |
| 969 | */ |
| 970 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); |
| 971 | |
| 972 | /* re-init operational registers */ |
| 973 | ehci_writel(ehci, 0, &ehci->regs->segment); |
| 974 | ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); |
| 975 | ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next); |
| 976 | |
| 977 | /*CMD_RUN will be set after, PORT_RESUME gets cleared*/ |
| 978 | if (ehci->resume_sof_bug) |
| 979 | ehci->command &= ~CMD_RUN; |
| 980 | |
| 981 | /* restore CMD_RUN, framelist size, and irq threshold */ |
| 982 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
| 983 | |
| 984 | /* manually resume the ports we suspended during bus_suspend() */ |
| 985 | resume_again: |
| 986 | if (retry_cnt >= RESUME_RETRY_LIMIT) { |
| 987 | pr_info("retry count(%d) reached max, resume in tight loop\n", |
| 988 | retry_cnt); |
| 989 | tight_resume = 1; |
| 990 | } |
| 991 | |
| 992 | |
| 993 | temp = ehci_readl(ehci, &ehci->regs->port_status[0]); |
| 994 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); |
| 995 | if (test_bit(0, &ehci->bus_suspended) && (temp & PORT_SUSPEND)) { |
| 996 | temp |= PORT_RESUME; |
| 997 | set_bit(0, &resume_needed); |
| 998 | } |
| 999 | dbg_log_event(NULL, "FPR: Set", temp); |
| 1000 | ehci_writel(ehci, temp, &ehci->regs->port_status[0]); |
| 1001 | |
| 1002 | /* HSIC controller has a h/w bug due to which it can try to send SOFs |
| 1003 | * (start of frames) during port resume resulting in phy lockup. HSIC hw |
| 1004 | * controller in MSM clears FPR bit after driving the resume signal for |
| 1005 | * 20ms. Workaround is to stop SOFs before driving resume and then start |
| 1006 | * sending SOFs immediately. Need to send SOFs within 3ms of resume |
| 1007 | * completion otherwise peripheral may enter undefined state. As |
| 1008 | * usleep_range does not gurantee exact sleep time, GPTimer is used to |
| 1009 | * to time the resume sequence. If driver exceeds allowable time SOFs, |
| 1010 | * repeat the resume process. |
| 1011 | */ |
| 1012 | if (ehci->resume_sof_bug && resume_needed) { |
| 1013 | if (!tight_resume) { |
| 1014 | mehci->resume_again = 0; |
| 1015 | ehci_writel(ehci, GPT_LD(RESUME_SIGNAL_TIME_MS), |
| 1016 | &mehci->timer->gptimer0_ld); |
| 1017 | ehci_writel(ehci, GPT_RESET | GPT_RUN, |
| 1018 | &mehci->timer->gptimer0_ctrl); |
| 1019 | ehci_writel(ehci, INTR_MASK | STS_GPTIMER0_INTERRUPT, |
| 1020 | &ehci->regs->intr_enable); |
| 1021 | |
| 1022 | ehci_writel(ehci, GPT_LD(RESUME_SIGNAL_TIME_SOF_MS), |
| 1023 | &mehci->timer->gptimer1_ld); |
| 1024 | ehci_writel(ehci, GPT_RESET | GPT_RUN, |
| 1025 | &mehci->timer->gptimer1_ctrl); |
| 1026 | |
| 1027 | spin_unlock_irq(&ehci->lock); |
Pavankumar Kondeti | fe2d4d3 | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 1028 | if (pdata && pdata->swfi_latency) |
| 1029 | pm_qos_update_request(&mehci->pm_qos_req_dma, |
| 1030 | pdata->swfi_latency + 1); |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1031 | wait_for_completion(&mehci->gpt0_completion); |
Pavankumar Kondeti | fe2d4d3 | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 1032 | if (pdata && pdata->swfi_latency) |
| 1033 | pm_qos_update_request(&mehci->pm_qos_req_dma, |
| 1034 | PM_QOS_DEFAULT_VALUE); |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1035 | spin_lock_irq(&ehci->lock); |
| 1036 | } else { |
| 1037 | dbg_log_event(NULL, "FPR: Tightloop", 0); |
| 1038 | /* do the resume in a tight loop */ |
| 1039 | handshake(ehci, &ehci->regs->port_status[0], |
| 1040 | PORT_RESUME, 0, 22 * 1000); |
| 1041 | ehci_writel(ehci, ehci_readl(ehci, |
| 1042 | &ehci->regs->command) | CMD_RUN, |
| 1043 | &ehci->regs->command); |
| 1044 | } |
| 1045 | |
| 1046 | if (mehci->resume_again) { |
| 1047 | int temp; |
| 1048 | |
| 1049 | dbg_log_event(NULL, "FPR: Re-Resume", retry_cnt); |
| 1050 | pr_info("FPR: retry count: %d\n", retry_cnt); |
| 1051 | spin_unlock_irq(&ehci->lock); |
| 1052 | temp = ehci_readl(ehci, &ehci->regs->port_status[0]); |
| 1053 | temp &= ~PORT_RWC_BITS; |
| 1054 | temp |= PORT_SUSPEND; |
| 1055 | ehci_writel(ehci, temp, &ehci->regs->port_status[0]); |
| 1056 | /* Keep the bus idle for 5ms so that peripheral |
| 1057 | * can detect and initiate suspend |
| 1058 | */ |
| 1059 | usleep_range(5000, 5000); |
| 1060 | dbg_log_event(NULL, |
| 1061 | "FPR: RResume", |
| 1062 | ehci_readl(ehci, &ehci->regs->port_status[0])); |
| 1063 | spin_lock_irq(&ehci->lock); |
| 1064 | mehci->resume_again = 0; |
| 1065 | retry_cnt++; |
| 1066 | goto resume_again; |
| 1067 | } |
| 1068 | } |
| 1069 | |
| 1070 | dbg_log_event(NULL, "FPR: RT-Done", 0); |
| 1071 | mehci->resume_status = 1; |
| 1072 | spin_unlock_irq(&ehci->lock); |
| 1073 | |
| 1074 | complete(&mehci->rt_completion); |
| 1075 | |
| 1076 | return 0; |
| 1077 | } |
| 1078 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1079 | static int ehci_hsic_bus_resume(struct usb_hcd *hcd) |
| 1080 | { |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1081 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1082 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 1083 | u32 temp; |
| 1084 | struct task_struct *resume_thread = NULL; |
| 1085 | |
| 1086 | mehci->resume_status = 0; |
| 1087 | resume_thread = kthread_run(msm_hsic_resume_thread, |
| 1088 | mehci, "hsic_resume_thread"); |
| 1089 | if (IS_ERR(resume_thread)) { |
| 1090 | pr_err("Error creating resume thread:%lu\n", |
| 1091 | PTR_ERR(resume_thread)); |
| 1092 | return PTR_ERR(resume_thread); |
| 1093 | } |
| 1094 | |
| 1095 | wait_for_completion(&mehci->rt_completion); |
| 1096 | |
| 1097 | if (mehci->resume_status < 0) |
| 1098 | return mehci->resume_status; |
| 1099 | |
| 1100 | dbg_log_event(NULL, "FPR: Wokeup", 0); |
| 1101 | spin_lock_irq(&ehci->lock); |
| 1102 | (void) ehci_readl(ehci, &ehci->regs->command); |
| 1103 | |
| 1104 | temp = 0; |
| 1105 | if (ehci->async->qh_next.qh) |
| 1106 | temp |= CMD_ASE; |
| 1107 | if (ehci->periodic_sched) |
| 1108 | temp |= CMD_PSE; |
| 1109 | if (temp) { |
| 1110 | ehci->command |= temp; |
| 1111 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
| 1112 | } |
| 1113 | |
| 1114 | ehci->next_statechange = jiffies + msecs_to_jiffies(5); |
| 1115 | hcd->state = HC_STATE_RUNNING; |
| 1116 | ehci->rh_state = EHCI_RH_RUNNING; |
| 1117 | |
| 1118 | /* Now we can safely re-enable irqs */ |
| 1119 | ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); |
| 1120 | |
| 1121 | spin_unlock_irq(&ehci->lock); |
| 1122 | |
| 1123 | return 0; |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1126 | static struct hc_driver msm_hsic_driver = { |
| 1127 | .description = hcd_name, |
| 1128 | .product_desc = "Qualcomm EHCI Host Controller using HSIC", |
| 1129 | .hcd_priv_size = sizeof(struct msm_hsic_hcd), |
| 1130 | |
| 1131 | /* |
| 1132 | * generic hardware linkage |
| 1133 | */ |
| 1134 | .irq = msm_hsic_irq, |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 1135 | .flags = HCD_USB2 | HCD_MEMORY | HCD_OLD_ENUM, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1136 | |
| 1137 | .reset = ehci_hsic_reset, |
| 1138 | .start = ehci_run, |
| 1139 | |
| 1140 | .stop = ehci_stop, |
| 1141 | .shutdown = ehci_shutdown, |
| 1142 | |
| 1143 | /* |
| 1144 | * managing i/o requests and associated device resources |
| 1145 | */ |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1146 | .urb_enqueue = ehci_hsic_urb_enqueue, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1147 | .urb_dequeue = ehci_urb_dequeue, |
| 1148 | .endpoint_disable = ehci_endpoint_disable, |
| 1149 | .endpoint_reset = ehci_endpoint_reset, |
| 1150 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 1151 | |
| 1152 | /* |
| 1153 | * scheduling support |
| 1154 | */ |
| 1155 | .get_frame_number = ehci_get_frame, |
| 1156 | |
| 1157 | /* |
| 1158 | * root hub support |
| 1159 | */ |
| 1160 | .hub_status_data = ehci_hub_status_data, |
| 1161 | .hub_control = ehci_hub_control, |
| 1162 | .relinquish_port = ehci_relinquish_port, |
| 1163 | .port_handed_over = ehci_port_handed_over, |
| 1164 | |
| 1165 | /* |
| 1166 | * PM support |
| 1167 | */ |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1168 | .bus_suspend = ehci_hsic_bus_suspend, |
| 1169 | .bus_resume = ehci_hsic_bus_resume, |
| 1170 | |
| 1171 | .log_urb_complete = dbg_log_event, |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 1172 | .dump_regs = dump_hsic_regs, |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 1173 | |
| 1174 | .enable_ulpi_control = ehci_msm_enable_ulpi_control, |
| 1175 | .disable_ulpi_control = ehci_msm_disable_ulpi_control, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1176 | }; |
| 1177 | |
| 1178 | static int msm_hsic_init_clocks(struct msm_hsic_hcd *mehci, u32 init) |
| 1179 | { |
| 1180 | int ret = 0; |
| 1181 | |
| 1182 | if (!init) |
| 1183 | goto put_clocks; |
| 1184 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 1185 | /*core_clk is required for LINK protocol engine |
| 1186 | *clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1187 | mehci->core_clk = clk_get(mehci->dev, "core_clk"); |
| 1188 | if (IS_ERR(mehci->core_clk)) { |
| 1189 | dev_err(mehci->dev, "failed to get core_clk\n"); |
| 1190 | ret = PTR_ERR(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1191 | return ret; |
| 1192 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1193 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 1194 | /* alt_core_clk is for LINK to be used during PHY RESET |
| 1195 | * clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1196 | mehci->alt_core_clk = clk_get(mehci->dev, "alt_core_clk"); |
| 1197 | if (IS_ERR(mehci->alt_core_clk)) { |
| 1198 | dev_err(mehci->dev, "failed to core_clk\n"); |
| 1199 | ret = PTR_ERR(mehci->alt_core_clk); |
| 1200 | goto put_core_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1201 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1202 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 1203 | /* phy_clk is required for HSIC PHY operation |
| 1204 | * clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1205 | mehci->phy_clk = clk_get(mehci->dev, "phy_clk"); |
| 1206 | if (IS_ERR(mehci->phy_clk)) { |
| 1207 | dev_err(mehci->dev, "failed to get phy_clk\n"); |
| 1208 | ret = PTR_ERR(mehci->phy_clk); |
| 1209 | goto put_alt_core_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1210 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1211 | |
| 1212 | /* 10MHz cal_clk is required for calibration of I/O pads */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1213 | mehci->cal_clk = clk_get(mehci->dev, "cal_clk"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1214 | if (IS_ERR(mehci->cal_clk)) { |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1215 | dev_err(mehci->dev, "failed to get cal_clk\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1216 | ret = PTR_ERR(mehci->cal_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1217 | goto put_phy_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1218 | } |
| 1219 | clk_set_rate(mehci->cal_clk, 10000000); |
| 1220 | |
| 1221 | /* ahb_clk is required for data transfers */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1222 | mehci->ahb_clk = clk_get(mehci->dev, "iface_clk"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1223 | if (IS_ERR(mehci->ahb_clk)) { |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1224 | dev_err(mehci->dev, "failed to get iface_clk\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1225 | ret = PTR_ERR(mehci->ahb_clk); |
| 1226 | goto put_cal_clk; |
| 1227 | } |
| 1228 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 1229 | clk_prepare_enable(mehci->core_clk); |
| 1230 | clk_prepare_enable(mehci->phy_clk); |
| 1231 | clk_prepare_enable(mehci->cal_clk); |
| 1232 | clk_prepare_enable(mehci->ahb_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1233 | |
| 1234 | return 0; |
| 1235 | |
| 1236 | put_clocks: |
Jack Pham | fd193eb | 2012-02-22 15:38:08 -0800 | [diff] [blame] | 1237 | if (!atomic_read(&mehci->in_lpm)) { |
| 1238 | clk_disable_unprepare(mehci->core_clk); |
| 1239 | clk_disable_unprepare(mehci->phy_clk); |
| 1240 | clk_disable_unprepare(mehci->cal_clk); |
| 1241 | clk_disable_unprepare(mehci->ahb_clk); |
| 1242 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1243 | clk_put(mehci->ahb_clk); |
| 1244 | put_cal_clk: |
| 1245 | clk_put(mehci->cal_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1246 | put_phy_clk: |
| 1247 | clk_put(mehci->phy_clk); |
| 1248 | put_alt_core_clk: |
| 1249 | clk_put(mehci->alt_core_clk); |
| 1250 | put_core_clk: |
| 1251 | clk_put(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1252 | |
| 1253 | return ret; |
| 1254 | } |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1255 | static irqreturn_t hsic_peripheral_status_change(int irq, void *dev_id) |
| 1256 | { |
| 1257 | struct msm_hsic_hcd *mehci = dev_id; |
| 1258 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1259 | 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] | 1260 | |
| 1261 | if (mehci) |
| 1262 | msm_hsic_config_gpios(mehci, 0); |
| 1263 | |
| 1264 | return IRQ_HANDLED; |
| 1265 | } |
| 1266 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1267 | static irqreturn_t msm_hsic_wakeup_irq(int irq, void *data) |
| 1268 | { |
| 1269 | struct msm_hsic_hcd *mehci = data; |
| 1270 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1271 | mehci->wakeup_int_cnt++; |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1272 | dbg_log_event(NULL, "Remote Wakeup IRQ", mehci->wakeup_int_cnt); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1273 | dev_dbg(mehci->dev, "%s: hsic remote wakeup interrupt cnt: %u\n", |
| 1274 | __func__, mehci->wakeup_int_cnt); |
| 1275 | |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 1276 | wake_lock(&mehci->wlock); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1277 | |
Hemant Kumar | 4cd49e1 | 2012-09-06 19:57:14 -0700 | [diff] [blame] | 1278 | spin_lock(&mehci->wakeup_lock); |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1279 | if (mehci->wakeup_irq_enabled) { |
| 1280 | mehci->wakeup_irq_enabled = 0; |
| 1281 | disable_irq_wake(irq); |
| 1282 | disable_irq_nosync(irq); |
| 1283 | } |
Hemant Kumar | 4cd49e1 | 2012-09-06 19:57:14 -0700 | [diff] [blame] | 1284 | spin_unlock(&mehci->wakeup_lock); |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1285 | |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 1286 | if (!atomic_read(&mehci->pm_usage_cnt)) { |
| 1287 | atomic_set(&mehci->pm_usage_cnt, 1); |
| 1288 | pm_runtime_get(mehci->dev); |
| 1289 | } |
| 1290 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1291 | return IRQ_HANDLED; |
| 1292 | } |
| 1293 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1294 | static int ehci_hsic_msm_bus_show(struct seq_file *s, void *unused) |
| 1295 | { |
| 1296 | if (debug_bus_voting_enabled) |
| 1297 | seq_printf(s, "enabled\n"); |
| 1298 | else |
| 1299 | seq_printf(s, "disabled\n"); |
| 1300 | |
| 1301 | return 0; |
| 1302 | } |
| 1303 | |
| 1304 | static int ehci_hsic_msm_bus_open(struct inode *inode, struct file *file) |
| 1305 | { |
| 1306 | return single_open(file, ehci_hsic_msm_bus_show, inode->i_private); |
| 1307 | } |
| 1308 | |
| 1309 | static ssize_t ehci_hsic_msm_bus_write(struct file *file, |
| 1310 | const char __user *ubuf, size_t count, loff_t *ppos) |
| 1311 | { |
| 1312 | char buf[8]; |
| 1313 | int ret; |
| 1314 | struct seq_file *s = file->private_data; |
| 1315 | struct msm_hsic_hcd *mehci = s->private; |
| 1316 | |
| 1317 | memset(buf, 0x00, sizeof(buf)); |
| 1318 | |
| 1319 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 1320 | return -EFAULT; |
| 1321 | |
| 1322 | if (!strncmp(buf, "enable", 6)) { |
| 1323 | /* Do not vote here. Let hsic driver decide when to vote */ |
| 1324 | debug_bus_voting_enabled = true; |
| 1325 | } else { |
| 1326 | debug_bus_voting_enabled = false; |
| 1327 | if (mehci->bus_perf_client) { |
| 1328 | ret = msm_bus_scale_client_update_request( |
| 1329 | mehci->bus_perf_client, 0); |
| 1330 | if (ret) |
| 1331 | dev_err(mehci->dev, "%s: Failed to devote " |
| 1332 | "for bus bw %d\n", __func__, ret); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | return count; |
| 1337 | } |
| 1338 | |
| 1339 | const struct file_operations ehci_hsic_msm_bus_fops = { |
| 1340 | .open = ehci_hsic_msm_bus_open, |
| 1341 | .read = seq_read, |
| 1342 | .write = ehci_hsic_msm_bus_write, |
| 1343 | .llseek = seq_lseek, |
| 1344 | .release = single_release, |
| 1345 | }; |
| 1346 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1347 | static int ehci_hsic_msm_wakeup_cnt_show(struct seq_file *s, void *unused) |
| 1348 | { |
| 1349 | struct msm_hsic_hcd *mehci = s->private; |
| 1350 | |
| 1351 | seq_printf(s, "%u\n", mehci->wakeup_int_cnt); |
| 1352 | |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
| 1356 | static int ehci_hsic_msm_wakeup_cnt_open(struct inode *inode, struct file *f) |
| 1357 | { |
| 1358 | return single_open(f, ehci_hsic_msm_wakeup_cnt_show, inode->i_private); |
| 1359 | } |
| 1360 | |
| 1361 | const struct file_operations ehci_hsic_msm_wakeup_cnt_fops = { |
| 1362 | .open = ehci_hsic_msm_wakeup_cnt_open, |
| 1363 | .read = seq_read, |
| 1364 | .llseek = seq_lseek, |
| 1365 | .release = single_release, |
| 1366 | }; |
| 1367 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1368 | static int ehci_hsic_msm_data_events_show(struct seq_file *s, void *unused) |
| 1369 | { |
| 1370 | unsigned long flags; |
| 1371 | unsigned i; |
| 1372 | |
| 1373 | read_lock_irqsave(&dbg_hsic_data.lck, flags); |
| 1374 | |
| 1375 | i = dbg_hsic_data.idx; |
| 1376 | for (dbg_inc(&i); i != dbg_hsic_data.idx; dbg_inc(&i)) { |
| 1377 | if (!strnlen(dbg_hsic_data.buf[i], DBG_MSG_LEN)) |
| 1378 | continue; |
| 1379 | seq_printf(s, "%s\n", dbg_hsic_data.buf[i]); |
| 1380 | } |
| 1381 | |
| 1382 | read_unlock_irqrestore(&dbg_hsic_data.lck, flags); |
| 1383 | |
| 1384 | return 0; |
| 1385 | } |
| 1386 | |
| 1387 | static int ehci_hsic_msm_data_events_open(struct inode *inode, struct file *f) |
| 1388 | { |
| 1389 | return single_open(f, ehci_hsic_msm_data_events_show, inode->i_private); |
| 1390 | } |
| 1391 | |
| 1392 | const struct file_operations ehci_hsic_msm_dbg_data_fops = { |
| 1393 | .open = ehci_hsic_msm_data_events_open, |
| 1394 | .read = seq_read, |
| 1395 | .llseek = seq_lseek, |
| 1396 | .release = single_release, |
| 1397 | }; |
| 1398 | |
| 1399 | static int ehci_hsic_msm_ctrl_events_show(struct seq_file *s, void *unused) |
| 1400 | { |
| 1401 | unsigned long flags; |
| 1402 | unsigned i; |
| 1403 | |
| 1404 | read_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 1405 | |
| 1406 | i = dbg_hsic_ctrl.idx; |
| 1407 | for (dbg_inc(&i); i != dbg_hsic_ctrl.idx; dbg_inc(&i)) { |
| 1408 | if (!strnlen(dbg_hsic_ctrl.buf[i], DBG_MSG_LEN)) |
| 1409 | continue; |
| 1410 | seq_printf(s, "%s\n", dbg_hsic_ctrl.buf[i]); |
| 1411 | } |
| 1412 | |
| 1413 | read_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 1414 | |
| 1415 | return 0; |
| 1416 | } |
| 1417 | |
| 1418 | static int ehci_hsic_msm_ctrl_events_open(struct inode *inode, struct file *f) |
| 1419 | { |
| 1420 | return single_open(f, ehci_hsic_msm_ctrl_events_show, inode->i_private); |
| 1421 | } |
| 1422 | |
| 1423 | const struct file_operations ehci_hsic_msm_dbg_ctrl_fops = { |
| 1424 | .open = ehci_hsic_msm_ctrl_events_open, |
| 1425 | .read = seq_read, |
| 1426 | .llseek = seq_lseek, |
| 1427 | .release = single_release, |
| 1428 | }; |
| 1429 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1430 | static struct dentry *ehci_hsic_msm_dbg_root; |
| 1431 | static int ehci_hsic_msm_debugfs_init(struct msm_hsic_hcd *mehci) |
| 1432 | { |
| 1433 | struct dentry *ehci_hsic_msm_dentry; |
| 1434 | |
| 1435 | ehci_hsic_msm_dbg_root = debugfs_create_dir("ehci_hsic_msm_dbg", NULL); |
| 1436 | |
| 1437 | if (!ehci_hsic_msm_dbg_root || IS_ERR(ehci_hsic_msm_dbg_root)) |
| 1438 | return -ENODEV; |
| 1439 | |
| 1440 | ehci_hsic_msm_dentry = debugfs_create_file("bus_voting", |
| 1441 | S_IRUGO | S_IWUSR, |
| 1442 | ehci_hsic_msm_dbg_root, mehci, |
| 1443 | &ehci_hsic_msm_bus_fops); |
| 1444 | |
| 1445 | if (!ehci_hsic_msm_dentry) { |
| 1446 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1447 | return -ENODEV; |
| 1448 | } |
| 1449 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1450 | ehci_hsic_msm_dentry = debugfs_create_file("wakeup_cnt", |
| 1451 | S_IRUGO, |
| 1452 | ehci_hsic_msm_dbg_root, mehci, |
| 1453 | &ehci_hsic_msm_wakeup_cnt_fops); |
| 1454 | |
| 1455 | if (!ehci_hsic_msm_dentry) { |
| 1456 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1457 | return -ENODEV; |
| 1458 | } |
| 1459 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1460 | ehci_hsic_msm_dentry = debugfs_create_file("show_ctrl_events", |
| 1461 | S_IRUGO, |
| 1462 | ehci_hsic_msm_dbg_root, mehci, |
| 1463 | &ehci_hsic_msm_dbg_ctrl_fops); |
| 1464 | |
| 1465 | if (!ehci_hsic_msm_dentry) { |
| 1466 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1467 | return -ENODEV; |
| 1468 | } |
| 1469 | |
| 1470 | ehci_hsic_msm_dentry = debugfs_create_file("show_data_events", |
| 1471 | S_IRUGO, |
| 1472 | ehci_hsic_msm_dbg_root, mehci, |
| 1473 | &ehci_hsic_msm_dbg_data_fops); |
| 1474 | |
| 1475 | if (!ehci_hsic_msm_dentry) { |
| 1476 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1477 | return -ENODEV; |
| 1478 | } |
| 1479 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1480 | return 0; |
| 1481 | } |
| 1482 | |
| 1483 | static void ehci_hsic_msm_debugfs_cleanup(void) |
| 1484 | { |
| 1485 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1486 | } |
| 1487 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1488 | static int __devinit ehci_hsic_msm_probe(struct platform_device *pdev) |
| 1489 | { |
| 1490 | struct usb_hcd *hcd; |
| 1491 | struct resource *res; |
| 1492 | struct msm_hsic_hcd *mehci; |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 1493 | struct msm_hsic_host_platform_data *pdata; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1494 | int ret; |
| 1495 | |
| 1496 | dev_dbg(&pdev->dev, "ehci_msm-hsic probe\n"); |
| 1497 | |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1498 | /* After parent device's probe is executed, it will be put in suspend |
| 1499 | * mode. When child device's probe is called, driver core is not |
| 1500 | * resuming parent device due to which parent will be in suspend even |
| 1501 | * though child is active. Hence resume the parent device explicitly. |
| 1502 | */ |
| 1503 | if (pdev->dev.parent) |
| 1504 | pm_runtime_get_sync(pdev->dev.parent); |
| 1505 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1506 | hcd = usb_create_hcd(&msm_hsic_driver, &pdev->dev, |
| 1507 | dev_name(&pdev->dev)); |
| 1508 | if (!hcd) { |
| 1509 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
| 1510 | return -ENOMEM; |
| 1511 | } |
| 1512 | |
Pavankumar Kondeti | 1c85169 | 2012-09-18 17:52:51 +0530 | [diff] [blame] | 1513 | hcd_to_bus(hcd)->skip_resume = true; |
| 1514 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1515 | hcd->irq = platform_get_irq(pdev, 0); |
| 1516 | if (hcd->irq < 0) { |
| 1517 | dev_err(&pdev->dev, "Unable to get IRQ resource\n"); |
| 1518 | ret = hcd->irq; |
| 1519 | goto put_hcd; |
| 1520 | } |
| 1521 | |
| 1522 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1523 | if (!res) { |
| 1524 | dev_err(&pdev->dev, "Unable to get memory resource\n"); |
| 1525 | ret = -ENODEV; |
| 1526 | goto put_hcd; |
| 1527 | } |
| 1528 | |
| 1529 | hcd->rsrc_start = res->start; |
| 1530 | hcd->rsrc_len = resource_size(res); |
| 1531 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 1532 | if (!hcd->regs) { |
| 1533 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 1534 | ret = -ENOMEM; |
| 1535 | goto put_hcd; |
| 1536 | } |
| 1537 | |
| 1538 | mehci = hcd_to_hsic(hcd); |
| 1539 | mehci->dev = &pdev->dev; |
Ajay Dudani | c4e40db | 2012-08-20 14:44:40 -0700 | [diff] [blame] | 1540 | pdata = mehci->dev->platform_data; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1541 | |
Hemant Kumar | 4cd49e1 | 2012-09-06 19:57:14 -0700 | [diff] [blame] | 1542 | spin_lock_init(&mehci->wakeup_lock); |
| 1543 | |
Hemant Kumar | 38ce5d8 | 2012-05-29 13:00:58 -0700 | [diff] [blame] | 1544 | mehci->ehci.susp_sof_bug = 1; |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 1545 | mehci->ehci.reset_sof_bug = 1; |
Hemant Kumar | 38ce5d8 | 2012-05-29 13:00:58 -0700 | [diff] [blame] | 1546 | |
Hemant Kumar | e404049 | 2012-06-21 17:35:42 -0700 | [diff] [blame] | 1547 | mehci->ehci.resume_sof_bug = 1; |
| 1548 | |
Ajay Dudani | c4e40db | 2012-08-20 14:44:40 -0700 | [diff] [blame] | 1549 | if (pdata) |
| 1550 | mehci->ehci.log2_irq_thresh = pdata->log2_irq_thresh; |
Hemant Kumar | 933e040 | 2012-05-22 11:11:40 -0700 | [diff] [blame] | 1551 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1552 | res = platform_get_resource_byname(pdev, |
| 1553 | IORESOURCE_IRQ, |
| 1554 | "peripheral_status_irq"); |
| 1555 | if (res) |
| 1556 | mehci->peripheral_status_irq = res->start; |
| 1557 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1558 | res = platform_get_resource_byname(pdev, IORESOURCE_IO, "wakeup"); |
| 1559 | if (res) { |
| 1560 | mehci->wakeup_gpio = res->start; |
| 1561 | mehci->wakeup_irq = MSM_GPIO_TO_INT(res->start); |
| 1562 | dev_dbg(mehci->dev, "wakeup_irq: %d\n", mehci->wakeup_irq); |
| 1563 | } |
| 1564 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1565 | ret = msm_hsic_init_clocks(mehci, 1); |
| 1566 | if (ret) { |
| 1567 | dev_err(&pdev->dev, "unable to initialize clocks\n"); |
| 1568 | ret = -ENODEV; |
| 1569 | goto unmap; |
| 1570 | } |
| 1571 | |
| 1572 | ret = msm_hsic_init_vddcx(mehci, 1); |
| 1573 | if (ret) { |
| 1574 | dev_err(&pdev->dev, "unable to initialize VDDCX\n"); |
| 1575 | ret = -ENODEV; |
| 1576 | goto deinit_clocks; |
| 1577 | } |
| 1578 | |
Ajay Dudani | 11ab1d5 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1579 | init_completion(&mehci->rt_completion); |
| 1580 | init_completion(&mehci->gpt0_completion); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1581 | ret = msm_hsic_reset(mehci); |
| 1582 | if (ret) { |
| 1583 | dev_err(&pdev->dev, "unable to initialize PHY\n"); |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1584 | goto deinit_vddcx; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1585 | } |
| 1586 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 1587 | ehci_wq = create_singlethread_workqueue("ehci_wq"); |
| 1588 | if (!ehci_wq) { |
| 1589 | dev_err(&pdev->dev, "unable to create workqueue\n"); |
| 1590 | ret = -ENOMEM; |
| 1591 | goto deinit_vddcx; |
| 1592 | } |
| 1593 | |
| 1594 | INIT_WORK(&mehci->bus_vote_w, ehci_hsic_bus_vote_w); |
| 1595 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1596 | ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
| 1597 | if (ret) { |
| 1598 | dev_err(&pdev->dev, "unable to register HCD\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1599 | goto unconfig_gpio; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1600 | } |
| 1601 | |
| 1602 | device_init_wakeup(&pdev->dev, 1); |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 1603 | wake_lock_init(&mehci->wlock, WAKE_LOCK_SUSPEND, dev_name(&pdev->dev)); |
| 1604 | wake_lock(&mehci->wlock); |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1605 | |
| 1606 | if (mehci->peripheral_status_irq) { |
| 1607 | ret = request_threaded_irq(mehci->peripheral_status_irq, |
| 1608 | NULL, hsic_peripheral_status_change, |
| 1609 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
| 1610 | | IRQF_SHARED, |
| 1611 | "hsic_peripheral_status", mehci); |
| 1612 | if (ret) |
| 1613 | dev_err(&pdev->dev, "%s:request_irq:%d failed:%d", |
| 1614 | __func__, mehci->peripheral_status_irq, ret); |
| 1615 | } |
| 1616 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1617 | /* configure wakeup irq */ |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1618 | if (mehci->wakeup_irq) { |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1619 | ret = request_irq(mehci->wakeup_irq, msm_hsic_wakeup_irq, |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1620 | IRQF_TRIGGER_HIGH, |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1621 | "msm_hsic_wakeup", mehci); |
| 1622 | if (!ret) { |
| 1623 | disable_irq_nosync(mehci->wakeup_irq); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1624 | } else { |
| 1625 | dev_err(&pdev->dev, "request_irq(%d) failed: %d\n", |
| 1626 | mehci->wakeup_irq, ret); |
| 1627 | mehci->wakeup_irq = 0; |
| 1628 | } |
| 1629 | } |
| 1630 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1631 | ret = ehci_hsic_msm_debugfs_init(mehci); |
| 1632 | if (ret) |
| 1633 | dev_dbg(&pdev->dev, "mode debugfs file is" |
| 1634 | "not available\n"); |
| 1635 | |
| 1636 | if (pdata && pdata->bus_scale_table) { |
| 1637 | mehci->bus_perf_client = |
| 1638 | msm_bus_scale_register_client(pdata->bus_scale_table); |
| 1639 | /* Configure BUS performance parameters for MAX bandwidth */ |
| 1640 | if (mehci->bus_perf_client) { |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 1641 | mehci->bus_vote = true; |
| 1642 | queue_work(ehci_wq, &mehci->bus_vote_w); |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1643 | } else { |
| 1644 | dev_err(&pdev->dev, "%s: Failed to register BUS " |
| 1645 | "scaling client!!\n", __func__); |
| 1646 | } |
| 1647 | } |
| 1648 | |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 1649 | __mehci = mehci; |
| 1650 | |
Pavankumar Kondeti | fe2d4d3 | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 1651 | if (pdata && pdata->swfi_latency) |
| 1652 | pm_qos_add_request(&mehci->pm_qos_req_dma, |
| 1653 | PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE); |
| 1654 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1655 | /* |
| 1656 | * This pdev->dev is assigned parent of root-hub by USB core, |
| 1657 | * hence, runtime framework automatically calls this driver's |
| 1658 | * runtime APIs based on root-hub's state. |
| 1659 | */ |
| 1660 | pm_runtime_set_active(&pdev->dev); |
| 1661 | pm_runtime_enable(&pdev->dev); |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1662 | /* Decrement the parent device's counter after probe. |
| 1663 | * As child is active, parent will not be put into |
| 1664 | * suspend mode. |
| 1665 | */ |
| 1666 | if (pdev->dev.parent) |
| 1667 | pm_runtime_put_sync(pdev->dev.parent); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1668 | |
| 1669 | return 0; |
| 1670 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1671 | unconfig_gpio: |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 1672 | destroy_workqueue(ehci_wq); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1673 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1674 | deinit_vddcx: |
| 1675 | msm_hsic_init_vddcx(mehci, 0); |
| 1676 | deinit_clocks: |
| 1677 | msm_hsic_init_clocks(mehci, 0); |
| 1678 | unmap: |
| 1679 | iounmap(hcd->regs); |
| 1680 | put_hcd: |
| 1681 | usb_put_hcd(hcd); |
| 1682 | |
| 1683 | return ret; |
| 1684 | } |
| 1685 | |
| 1686 | static int __devexit ehci_hsic_msm_remove(struct platform_device *pdev) |
| 1687 | { |
| 1688 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 1689 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
Pavankumar Kondeti | fe2d4d3 | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 1690 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
| 1691 | |
| 1692 | if (pdata && pdata->swfi_latency) |
| 1693 | pm_qos_remove_request(&mehci->pm_qos_req_dma); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1694 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1695 | if (mehci->peripheral_status_irq) |
| 1696 | free_irq(mehci->peripheral_status_irq, mehci); |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1697 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1698 | if (mehci->wakeup_irq) { |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1699 | if (mehci->wakeup_irq_enabled) |
| 1700 | disable_irq_wake(mehci->wakeup_irq); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1701 | free_irq(mehci->wakeup_irq, mehci); |
| 1702 | } |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1703 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 1704 | /* |
| 1705 | * If the update request is called after unregister, the request will |
| 1706 | * fail. Results are undefined if unregister is called in the middle of |
| 1707 | * update request. |
| 1708 | */ |
| 1709 | mehci->bus_vote = false; |
| 1710 | cancel_work_sync(&mehci->bus_vote_w); |
| 1711 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1712 | if (mehci->bus_perf_client) |
| 1713 | msm_bus_scale_unregister_client(mehci->bus_perf_client); |
| 1714 | |
| 1715 | ehci_hsic_msm_debugfs_cleanup(); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1716 | device_init_wakeup(&pdev->dev, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1717 | pm_runtime_set_suspended(&pdev->dev); |
| 1718 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 1719 | destroy_workqueue(ehci_wq); |
| 1720 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1721 | usb_remove_hcd(hcd); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 1722 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1723 | msm_hsic_init_vddcx(mehci, 0); |
| 1724 | |
| 1725 | msm_hsic_init_clocks(mehci, 0); |
Ajay Dudani | ab3bf19 | 2012-08-28 09:58:04 -0700 | [diff] [blame] | 1726 | wake_lock_destroy(&mehci->wlock); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1727 | iounmap(hcd->regs); |
| 1728 | usb_put_hcd(hcd); |
| 1729 | |
| 1730 | return 0; |
| 1731 | } |
| 1732 | |
| 1733 | #ifdef CONFIG_PM_SLEEP |
| 1734 | static int msm_hsic_pm_suspend(struct device *dev) |
| 1735 | { |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 1736 | int ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1737 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1738 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1739 | |
| 1740 | dev_dbg(dev, "ehci-msm-hsic PM suspend\n"); |
| 1741 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1742 | dbg_log_event(NULL, "PM Suspend", 0); |
| 1743 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1744 | if (device_may_wakeup(dev)) |
| 1745 | enable_irq_wake(hcd->irq); |
| 1746 | |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 1747 | ret = msm_hsic_suspend(mehci); |
| 1748 | |
| 1749 | if (ret && device_may_wakeup(dev)) |
| 1750 | disable_irq_wake(hcd->irq); |
| 1751 | |
| 1752 | return ret; |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1753 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1754 | |
Jack Pham | 16b06f8 | 2012-08-14 20:03:59 -0700 | [diff] [blame] | 1755 | static int msm_hsic_pm_suspend_noirq(struct device *dev) |
| 1756 | { |
| 1757 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1758 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1759 | |
| 1760 | if (mehci->async_int) { |
| 1761 | dev_dbg(dev, "suspend_noirq: Aborting due to pending interrupt\n"); |
| 1762 | return -EBUSY; |
| 1763 | } |
| 1764 | |
| 1765 | return 0; |
| 1766 | } |
| 1767 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1768 | static int msm_hsic_pm_resume(struct device *dev) |
| 1769 | { |
| 1770 | int ret; |
| 1771 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1772 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1773 | |
Jack Pham | 16b06f8 | 2012-08-14 20:03:59 -0700 | [diff] [blame] | 1774 | dev_dbg(dev, "ehci-msm-hsic PM resume\n"); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1775 | dbg_log_event(NULL, "PM Resume", 0); |
| 1776 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1777 | if (device_may_wakeup(dev)) |
| 1778 | disable_irq_wake(hcd->irq); |
| 1779 | |
Pavankumar Kondeti | 1c85169 | 2012-09-18 17:52:51 +0530 | [diff] [blame] | 1780 | /* |
| 1781 | * Keep HSIC in Low Power Mode if system is resumed |
| 1782 | * by any other wakeup source. HSIC is resumed later |
| 1783 | * when remote wakeup is received or interface driver |
| 1784 | * start I/O. |
| 1785 | */ |
| 1786 | if (!atomic_read(&mehci->pm_usage_cnt)) |
| 1787 | return 0; |
| 1788 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1789 | ret = msm_hsic_resume(mehci); |
| 1790 | if (ret) |
| 1791 | return ret; |
| 1792 | |
| 1793 | /* Bring the device to full powered state upon system resume */ |
| 1794 | pm_runtime_disable(dev); |
| 1795 | pm_runtime_set_active(dev); |
| 1796 | pm_runtime_enable(dev); |
| 1797 | |
| 1798 | return 0; |
| 1799 | } |
| 1800 | #endif |
| 1801 | |
| 1802 | #ifdef CONFIG_PM_RUNTIME |
| 1803 | static int msm_hsic_runtime_idle(struct device *dev) |
| 1804 | { |
| 1805 | dev_dbg(dev, "EHCI runtime idle\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1806 | return 0; |
| 1807 | } |
| 1808 | |
| 1809 | static int msm_hsic_runtime_suspend(struct device *dev) |
| 1810 | { |
| 1811 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1812 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1813 | |
| 1814 | dev_dbg(dev, "EHCI runtime suspend\n"); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1815 | |
| 1816 | dbg_log_event(NULL, "Run Time PM Suspend", 0); |
| 1817 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1818 | return msm_hsic_suspend(mehci); |
| 1819 | } |
| 1820 | |
| 1821 | static int msm_hsic_runtime_resume(struct device *dev) |
| 1822 | { |
| 1823 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 1824 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1825 | |
| 1826 | dev_dbg(dev, "EHCI runtime resume\n"); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1827 | |
| 1828 | dbg_log_event(NULL, "Run Time PM Resume", 0); |
| 1829 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1830 | return msm_hsic_resume(mehci); |
| 1831 | } |
| 1832 | #endif |
| 1833 | |
| 1834 | #ifdef CONFIG_PM |
| 1835 | static const struct dev_pm_ops msm_hsic_dev_pm_ops = { |
| 1836 | SET_SYSTEM_SLEEP_PM_OPS(msm_hsic_pm_suspend, msm_hsic_pm_resume) |
Jack Pham | 16b06f8 | 2012-08-14 20:03:59 -0700 | [diff] [blame] | 1837 | .suspend_noirq = msm_hsic_pm_suspend_noirq, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1838 | SET_RUNTIME_PM_OPS(msm_hsic_runtime_suspend, msm_hsic_runtime_resume, |
| 1839 | msm_hsic_runtime_idle) |
| 1840 | }; |
| 1841 | #endif |
| 1842 | |
| 1843 | static struct platform_driver ehci_msm_hsic_driver = { |
| 1844 | .probe = ehci_hsic_msm_probe, |
| 1845 | .remove = __devexit_p(ehci_hsic_msm_remove), |
| 1846 | .driver = { |
| 1847 | .name = "msm_hsic_host", |
| 1848 | #ifdef CONFIG_PM |
| 1849 | .pm = &msm_hsic_dev_pm_ops, |
| 1850 | #endif |
| 1851 | }, |
| 1852 | }; |