Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1 | /* ehci-msm-hsic.c - HSUSB Host Controller Driver Implementation |
| 2 | * |
Ido Shayevitz | 95c4688 | 2013-01-20 13:47:46 +0200 | [diff] [blame] | 3 | * Copyright (c) 2011-2013, The Linux Foundation. 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> |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -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 | |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 34 | #include <linux/usb/ulpi.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 35 | #include <linux/usb/msm_hsusb_hw.h> |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 36 | #include <linux/usb/msm_hsusb.h> |
| 37 | #include <linux/gpio.h> |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 38 | #include <linux/of_gpio.h> |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 39 | #include <linux/spinlock.h> |
Hemant Kumar | bbcdcbc | 2012-08-30 14:23:38 -0700 | [diff] [blame] | 40 | #include <linux/irq.h> |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 41 | #include <linux/kthread.h> |
| 42 | #include <linux/wait.h> |
Pavankumar Kondeti | 4f5dc3b | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 43 | #include <linux/pm_qos.h> |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 44 | |
| 45 | #include <mach/msm_bus.h> |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 46 | #include <mach/clk.h> |
| 47 | #include <mach/msm_iomap.h> |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 48 | #include <mach/msm_xo.h> |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 49 | #include <linux/spinlock.h> |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 50 | #include <linux/cpu.h> |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 51 | #include <mach/rpm-regulator.h> |
Shimrit Malichi | 82d7cbc | 2013-03-12 15:36:54 +0200 | [diff] [blame] | 52 | #include "hbm.c" |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 53 | |
| 54 | #define MSM_USB_BASE (hcd->regs) |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 55 | #define USB_REG_START_OFFSET 0x90 |
| 56 | #define USB_REG_END_OFFSET 0x250 |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 57 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 58 | static struct workqueue_struct *ehci_wq; |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 59 | struct ehci_timer { |
| 60 | #define GPT_LD(p) ((p) & 0x00FFFFFF) |
| 61 | u32 gptimer0_ld; |
| 62 | #define GPT_RUN BIT(31) |
| 63 | #define GPT_RESET BIT(30) |
| 64 | #define GPT_MODE BIT(24) |
| 65 | #define GPT_CNT(p) ((p) & 0x00FFFFFF) |
| 66 | u32 gptimer0_ctrl; |
| 67 | |
| 68 | u32 gptimer1_ld; |
| 69 | u32 gptimer1_ctrl; |
| 70 | }; |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 71 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 72 | struct msm_hsic_hcd { |
| 73 | struct ehci_hcd ehci; |
Hemant Kumar | d343c01 | 2012-09-06 19:57:14 -0700 | [diff] [blame] | 74 | spinlock_t wakeup_lock; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 75 | struct device *dev; |
| 76 | struct clk *ahb_clk; |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 77 | struct clk *core_clk; |
| 78 | struct clk *alt_core_clk; |
| 79 | struct clk *phy_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 80 | struct clk *cal_clk; |
Ido Shayevitz | 5dfbb13 | 2013-04-18 13:22:07 +0300 | [diff] [blame] | 81 | struct clk *inactivity_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 82 | struct regulator *hsic_vddcx; |
Ofir Cohen | 4cc5537 | 2012-11-20 11:17:24 +0200 | [diff] [blame] | 83 | struct regulator *hsic_gdsc; |
Pavankumar Kondeti | 822fbe6 | 2013-01-28 17:04:39 +0530 | [diff] [blame] | 84 | atomic_t async_int; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 85 | atomic_t in_lpm; |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 86 | struct wake_lock wlock; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 87 | int peripheral_status_irq; |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 88 | int wakeup_irq; |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 89 | bool wakeup_irq_enabled; |
Manu Gautam | 3fb60ca | 2013-02-13 18:33:33 +0530 | [diff] [blame] | 90 | int async_irq; |
| 91 | uint32_t async_int_cnt; |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 92 | atomic_t pm_usage_cnt; |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 93 | uint32_t bus_perf_client; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 94 | uint32_t wakeup_int_cnt; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 95 | enum usb_vdd_type vdd_type; |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 96 | |
| 97 | struct work_struct bus_vote_w; |
| 98 | bool bus_vote; |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 99 | |
| 100 | /* gp timer */ |
| 101 | struct ehci_timer __iomem *timer; |
| 102 | struct completion gpt0_completion; |
| 103 | struct completion rt_completion; |
| 104 | int resume_status; |
| 105 | int resume_again; |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 106 | int bus_reset; |
| 107 | int reset_again; |
Pavankumar Kondeti | 4f5dc3b | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 108 | |
| 109 | struct pm_qos_request pm_qos_req_dma; |
Shimrit Malichi | 82d7cbc | 2013-03-12 15:36:54 +0200 | [diff] [blame] | 110 | unsigned enable_hbm:1; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 111 | }; |
| 112 | |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 113 | struct msm_hsic_hcd *__mehci; |
| 114 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 115 | static bool debug_bus_voting_enabled = true; |
Ofir Cohen | 4cc5537 | 2012-11-20 11:17:24 +0200 | [diff] [blame] | 116 | static u64 ehci_msm_hsic_dma_mask = DMA_BIT_MASK(32); |
| 117 | |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 118 | static struct platform_driver ehci_msm_hsic_driver; |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 119 | |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 120 | static unsigned int enable_payload_log = 1; |
| 121 | module_param(enable_payload_log, uint, S_IRUGO | S_IWUSR); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 122 | static unsigned int enable_dbg_log = 1; |
| 123 | module_param(enable_dbg_log, uint, S_IRUGO | S_IWUSR); |
| 124 | /*by default log ep0 and efs sync ep*/ |
| 125 | static unsigned int ep_addr_rxdbg_mask = 9; |
| 126 | module_param(ep_addr_rxdbg_mask, uint, S_IRUGO | S_IWUSR); |
| 127 | static unsigned int ep_addr_txdbg_mask = 9; |
| 128 | module_param(ep_addr_txdbg_mask, uint, S_IRUGO | S_IWUSR); |
| 129 | |
| 130 | /* Maximum debug message length */ |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 131 | #define DBG_MSG_LEN 128UL |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 132 | |
| 133 | /* Maximum number of messages */ |
| 134 | #define DBG_MAX_MSG 256UL |
| 135 | |
| 136 | #define TIME_BUF_LEN 20 |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 137 | #define HEX_DUMP_LEN 72 |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 138 | |
| 139 | enum event_type { |
| 140 | EVENT_UNDEF = -1, |
| 141 | URB_SUBMIT, |
| 142 | URB_COMPLETE, |
| 143 | EVENT_NONE, |
| 144 | }; |
| 145 | |
| 146 | #define EVENT_STR_LEN 5 |
| 147 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 148 | static enum event_type str_to_event(const char *name) |
| 149 | { |
| 150 | if (!strncasecmp("S", name, EVENT_STR_LEN)) |
| 151 | return URB_SUBMIT; |
| 152 | if (!strncasecmp("C", name, EVENT_STR_LEN)) |
| 153 | return URB_COMPLETE; |
| 154 | if (!strncasecmp("", name, EVENT_STR_LEN)) |
| 155 | return EVENT_NONE; |
| 156 | |
| 157 | return EVENT_UNDEF; |
| 158 | } |
| 159 | |
| 160 | /*log ep0 activity*/ |
| 161 | static struct { |
| 162 | char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */ |
| 163 | unsigned idx; /* index */ |
| 164 | rwlock_t lck; /* lock */ |
| 165 | } dbg_hsic_ctrl = { |
| 166 | .idx = 0, |
| 167 | .lck = __RW_LOCK_UNLOCKED(lck) |
| 168 | }; |
| 169 | |
| 170 | static struct { |
| 171 | char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */ |
| 172 | unsigned idx; /* index */ |
| 173 | rwlock_t lck; /* lock */ |
| 174 | } dbg_hsic_data = { |
| 175 | .idx = 0, |
| 176 | .lck = __RW_LOCK_UNLOCKED(lck) |
| 177 | }; |
| 178 | |
| 179 | /** |
| 180 | * dbg_inc: increments debug event index |
| 181 | * @idx: buffer index |
| 182 | */ |
| 183 | static void dbg_inc(unsigned *idx) |
| 184 | { |
| 185 | *idx = (*idx + 1) & (DBG_MAX_MSG-1); |
| 186 | } |
| 187 | |
| 188 | /*get_timestamp - returns time of day in us */ |
| 189 | static char *get_timestamp(char *tbuf) |
| 190 | { |
| 191 | unsigned long long t; |
| 192 | unsigned long nanosec_rem; |
| 193 | |
| 194 | t = cpu_clock(smp_processor_id()); |
| 195 | nanosec_rem = do_div(t, 1000000000)/1000; |
| 196 | scnprintf(tbuf, TIME_BUF_LEN, "[%5lu.%06lu] ", (unsigned long)t, |
| 197 | nanosec_rem); |
| 198 | return tbuf; |
| 199 | } |
| 200 | |
| 201 | static int allow_dbg_log(int ep_addr) |
| 202 | { |
| 203 | int dir, num; |
| 204 | |
| 205 | dir = ep_addr & USB_DIR_IN ? USB_DIR_IN : USB_DIR_OUT; |
| 206 | num = ep_addr & ~USB_DIR_IN; |
| 207 | num = 1 << num; |
| 208 | |
| 209 | if ((dir == USB_DIR_IN) && (num & ep_addr_rxdbg_mask)) |
| 210 | return 1; |
| 211 | if ((dir == USB_DIR_OUT) && (num & ep_addr_txdbg_mask)) |
| 212 | return 1; |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 217 | static char *get_hex_data(char *dbuf, struct urb *urb, int event, int status) |
| 218 | { |
| 219 | int ep_addr = urb->ep->desc.bEndpointAddress; |
| 220 | char *ubuf = urb->transfer_buffer; |
| 221 | size_t len = event ? \ |
| 222 | urb->actual_length : urb->transfer_buffer_length; |
| 223 | |
| 224 | if (status == -EINPROGRESS) |
| 225 | status = 0; |
| 226 | |
| 227 | /*Only dump ep in completions and epout submissions*/ |
| 228 | if (len && !status && |
| 229 | (((ep_addr & USB_DIR_IN) && event) || |
| 230 | (!(ep_addr & USB_DIR_IN) && !event))) { |
| 231 | if (len >= 32) |
| 232 | len = 32; |
| 233 | hex_dump_to_buffer(ubuf, len, 32, 4, dbuf, HEX_DUMP_LEN, 0); |
| 234 | } else { |
| 235 | dbuf = ""; |
| 236 | } |
| 237 | |
| 238 | return dbuf; |
| 239 | } |
| 240 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 241 | static void dbg_log_event(struct urb *urb, char * event, unsigned extra) |
| 242 | { |
| 243 | unsigned long flags; |
| 244 | int ep_addr; |
| 245 | char tbuf[TIME_BUF_LEN]; |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 246 | char dbuf[HEX_DUMP_LEN]; |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 247 | |
| 248 | if (!enable_dbg_log) |
| 249 | return; |
| 250 | |
| 251 | if (!urb) { |
| 252 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 253 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], DBG_MSG_LEN, |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 254 | "%s: %s : %u", get_timestamp(tbuf), event, extra); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 255 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 256 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 257 | return; |
| 258 | } |
| 259 | |
| 260 | ep_addr = urb->ep->desc.bEndpointAddress; |
| 261 | if (!allow_dbg_log(ep_addr)) |
| 262 | return; |
| 263 | |
| 264 | if ((ep_addr & 0x0f) == 0x0) { |
| 265 | /*submit event*/ |
| 266 | if (!str_to_event(event)) { |
| 267 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 268 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], |
| 269 | DBG_MSG_LEN, "%s: [%s : %p]:[%s] " |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 270 | "%02x %02x %04x %04x %04x %u %d", |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 271 | get_timestamp(tbuf), event, urb, |
| 272 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 273 | urb->setup_packet[0], urb->setup_packet[1], |
| 274 | (urb->setup_packet[3] << 8) | |
| 275 | urb->setup_packet[2], |
| 276 | (urb->setup_packet[5] << 8) | |
| 277 | urb->setup_packet[4], |
| 278 | (urb->setup_packet[7] << 8) | |
| 279 | urb->setup_packet[6], |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 280 | urb->transfer_buffer_length, extra); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 281 | |
| 282 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 283 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 284 | } else { |
| 285 | write_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 286 | scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 287 | DBG_MSG_LEN, "%s: [%s : %p]:[%s] %u %d", |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 288 | get_timestamp(tbuf), event, urb, |
| 289 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 290 | urb->actual_length, extra); |
| 291 | |
| 292 | dbg_inc(&dbg_hsic_ctrl.idx); |
| 293 | write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 294 | } |
| 295 | } else { |
| 296 | write_lock_irqsave(&dbg_hsic_data.lck, flags); |
| 297 | scnprintf(dbg_hsic_data.buf[dbg_hsic_data.idx], DBG_MSG_LEN, |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 298 | "%s: [%s : %p]:ep%d[%s] %u %d %s", |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 299 | get_timestamp(tbuf), event, urb, ep_addr & 0x0f, |
| 300 | (ep_addr & USB_DIR_IN) ? "in" : "out", |
| 301 | str_to_event(event) ? urb->actual_length : |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 302 | urb->transfer_buffer_length, extra, |
| 303 | enable_payload_log ? get_hex_data(dbuf, urb, |
| 304 | str_to_event(event), extra) : ""); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 305 | |
| 306 | dbg_inc(&dbg_hsic_data.idx); |
| 307 | write_unlock_irqrestore(&dbg_hsic_data.lck, flags); |
| 308 | } |
| 309 | } |
| 310 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 311 | static inline struct msm_hsic_hcd *hcd_to_hsic(struct usb_hcd *hcd) |
| 312 | { |
| 313 | return (struct msm_hsic_hcd *) (hcd->hcd_priv); |
| 314 | } |
| 315 | |
| 316 | static inline struct usb_hcd *hsic_to_hcd(struct msm_hsic_hcd *mehci) |
| 317 | { |
| 318 | return container_of((void *) mehci, struct usb_hcd, hcd_priv); |
| 319 | } |
| 320 | |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 321 | static void dump_hsic_regs(struct usb_hcd *hcd) |
| 322 | { |
| 323 | int i; |
| 324 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 325 | |
| 326 | if (atomic_read(&mehci->in_lpm)) |
| 327 | return; |
| 328 | |
| 329 | for (i = USB_REG_START_OFFSET; i <= USB_REG_END_OFFSET; i += 0x10) |
| 330 | pr_info("%p: %08x\t%08x\t%08x\t%08x\n", hcd->regs + i, |
| 331 | readl_relaxed(hcd->regs + i), |
| 332 | readl_relaxed(hcd->regs + i + 4), |
| 333 | readl_relaxed(hcd->regs + i + 8), |
| 334 | readl_relaxed(hcd->regs + i + 0xc)); |
| 335 | } |
| 336 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 337 | #define ULPI_IO_TIMEOUT_USEC (10 * 1000) |
| 338 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 339 | #define USB_PHY_VDD_DIG_VOL_NONE 0 /*uV */ |
Hemant Kumar | 3b743cd | 2012-10-17 13:48:10 -0700 | [diff] [blame] | 340 | #define USB_PHY_VDD_DIG_VOL_MIN 945000 /* uV */ |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 341 | #define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */ |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 342 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 343 | #define HSIC_DBG1_REG 0x38 |
| 344 | |
Vijayavardhan Vennapusa | 29af414 | 2013-08-12 13:10:07 +0530 | [diff] [blame] | 345 | static int vdd_val[VDD_TYPE_MAX][VDD_VAL_MAX] = { |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 346 | { /* VDD_CX CORNER Voting */ |
| 347 | [VDD_NONE] = RPM_VREG_CORNER_NONE, |
| 348 | [VDD_MIN] = RPM_VREG_CORNER_NOMINAL, |
| 349 | [VDD_MAX] = RPM_VREG_CORNER_HIGH, |
| 350 | }, |
| 351 | { /* VDD_CX Voltage Voting */ |
| 352 | [VDD_NONE] = USB_PHY_VDD_DIG_VOL_NONE, |
| 353 | [VDD_MIN] = USB_PHY_VDD_DIG_VOL_MIN, |
| 354 | [VDD_MAX] = USB_PHY_VDD_DIG_VOL_MAX, |
| 355 | }, |
| 356 | }; |
| 357 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 358 | static int msm_hsic_init_vddcx(struct msm_hsic_hcd *mehci, int init) |
| 359 | { |
| 360 | int ret = 0; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 361 | int none_vol, min_vol, max_vol; |
Vijayavardhan Vennapusa | 29af414 | 2013-08-12 13:10:07 +0530 | [diff] [blame] | 362 | u32 tmp[3]; |
| 363 | int len = 0; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 364 | |
| 365 | if (!mehci->hsic_vddcx) { |
| 366 | mehci->vdd_type = VDDCX_CORNER; |
| 367 | mehci->hsic_vddcx = devm_regulator_get(mehci->dev, |
| 368 | "hsic_vdd_dig"); |
| 369 | if (IS_ERR(mehci->hsic_vddcx)) { |
| 370 | mehci->hsic_vddcx = devm_regulator_get(mehci->dev, |
| 371 | "HSIC_VDDCX"); |
| 372 | if (IS_ERR(mehci->hsic_vddcx)) { |
| 373 | dev_err(mehci->dev, "unable to get hsic vddcx\n"); |
| 374 | return PTR_ERR(mehci->hsic_vddcx); |
| 375 | } |
| 376 | mehci->vdd_type = VDDCX; |
| 377 | } |
Vijayavardhan Vennapusa | 29af414 | 2013-08-12 13:10:07 +0530 | [diff] [blame] | 378 | |
| 379 | if (mehci->dev->of_node) { |
| 380 | of_get_property(mehci->dev->of_node, |
| 381 | "hsic,vdd-voltage-level", |
| 382 | &len); |
| 383 | if (len == sizeof(tmp)) { |
| 384 | of_property_read_u32_array(mehci->dev->of_node, |
| 385 | "hsic,vdd-voltage-level", |
| 386 | tmp, len/sizeof(*tmp)); |
| 387 | vdd_val[mehci->vdd_type][VDD_NONE] = tmp[0]; |
| 388 | vdd_val[mehci->vdd_type][VDD_MIN] = tmp[1]; |
| 389 | vdd_val[mehci->vdd_type][VDD_MAX] = tmp[2]; |
| 390 | } else { |
| 391 | dev_dbg(mehci->dev, "Use default vdd config\n"); |
| 392 | } |
| 393 | } |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | none_vol = vdd_val[mehci->vdd_type][VDD_NONE]; |
| 397 | min_vol = vdd_val[mehci->vdd_type][VDD_MIN]; |
| 398 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 399 | |
| 400 | if (!init) |
| 401 | goto disable_reg; |
| 402 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 403 | ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 404 | if (ret) { |
| 405 | dev_err(mehci->dev, "unable to set the voltage" |
| 406 | "for hsic vddcx\n"); |
Mayank Rana | 189ac05 | 2012-03-24 04:35:02 +0530 | [diff] [blame] | 407 | return ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 408 | } |
| 409 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 410 | ret = regulator_enable(mehci->hsic_vddcx); |
| 411 | if (ret) { |
| 412 | dev_err(mehci->dev, "unable to enable hsic vddcx\n"); |
| 413 | goto reg_enable_err; |
| 414 | } |
| 415 | |
| 416 | return 0; |
| 417 | |
| 418 | disable_reg: |
| 419 | regulator_disable(mehci->hsic_vddcx); |
| 420 | reg_enable_err: |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 421 | regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol); |
| 422 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 423 | return ret; |
| 424 | |
| 425 | } |
| 426 | |
Ofir Cohen | 4cc5537 | 2012-11-20 11:17:24 +0200 | [diff] [blame] | 427 | /* Global Distributed Switch Controller (GDSC) init */ |
| 428 | static int msm_hsic_init_gdsc(struct msm_hsic_hcd *mehci, int init) |
| 429 | { |
| 430 | int ret = 0; |
| 431 | |
| 432 | if (IS_ERR(mehci->hsic_gdsc)) |
| 433 | return 0; |
| 434 | |
| 435 | if (!mehci->hsic_gdsc) { |
| 436 | mehci->hsic_gdsc = devm_regulator_get(mehci->dev, |
| 437 | "HSIC_GDSC"); |
| 438 | if (IS_ERR(mehci->hsic_gdsc)) |
| 439 | return 0; |
| 440 | } |
| 441 | |
| 442 | if (init) { |
| 443 | ret = regulator_enable(mehci->hsic_gdsc); |
| 444 | if (ret) { |
| 445 | dev_err(mehci->dev, "unable to enable hsic gdsc\n"); |
| 446 | return ret; |
| 447 | } |
| 448 | } else { |
| 449 | regulator_disable(mehci->hsic_gdsc); |
| 450 | } |
| 451 | |
| 452 | return 0; |
| 453 | |
| 454 | } |
| 455 | |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 456 | static int __maybe_unused ulpi_read(struct msm_hsic_hcd *mehci, u32 reg) |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 457 | { |
| 458 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Hemant Kumar | 8fdc398 | 2012-08-21 12:22:27 -0700 | [diff] [blame] | 459 | int cnt = 0; |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 460 | |
| 461 | /* initiate read operation */ |
| 462 | writel_relaxed(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg), |
| 463 | USB_ULPI_VIEWPORT); |
| 464 | |
| 465 | /* wait for completion */ |
Hemant Kumar | 8fdc398 | 2012-08-21 12:22:27 -0700 | [diff] [blame] | 466 | while (cnt < ULPI_IO_TIMEOUT_USEC) { |
| 467 | if (!(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN)) |
| 468 | break; |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 469 | udelay(1); |
Hemant Kumar | 8fdc398 | 2012-08-21 12:22:27 -0700 | [diff] [blame] | 470 | cnt++; |
| 471 | } |
| 472 | |
| 473 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { |
| 474 | dev_err(mehci->dev, "ulpi_read: timeout ULPI_VIEWPORT: %08x\n", |
| 475 | readl_relaxed(USB_ULPI_VIEWPORT)); |
| 476 | dev_err(mehci->dev, "PORTSC: %08x USBCMD: %08x FRINDEX: %08x\n", |
| 477 | readl_relaxed(USB_PORTSC), |
| 478 | readl_relaxed(USB_USBCMD), |
| 479 | readl_relaxed(USB_FRINDEX)); |
| 480 | |
| 481 | /*frame counter increments afte 125us*/ |
| 482 | udelay(130); |
| 483 | dev_err(mehci->dev, "ulpi_read: FRINDEX: %08x\n", |
| 484 | readl_relaxed(USB_FRINDEX)); |
| 485 | return -ETIMEDOUT; |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | return ULPI_DATA_READ(readl_relaxed(USB_ULPI_VIEWPORT)); |
| 489 | } |
| 490 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 491 | static int ulpi_write(struct msm_hsic_hcd *mehci, u32 val, u32 reg) |
| 492 | { |
| 493 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
| 494 | int cnt = 0; |
| 495 | |
| 496 | /* initiate write operation */ |
| 497 | writel_relaxed(ULPI_RUN | ULPI_WRITE | |
| 498 | ULPI_ADDR(reg) | ULPI_DATA(val), |
| 499 | USB_ULPI_VIEWPORT); |
| 500 | |
| 501 | /* wait for completion */ |
| 502 | while (cnt < ULPI_IO_TIMEOUT_USEC) { |
| 503 | if (!(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN)) |
| 504 | break; |
| 505 | udelay(1); |
| 506 | cnt++; |
| 507 | } |
| 508 | |
| 509 | if (cnt >= ULPI_IO_TIMEOUT_USEC) { |
Hemant Kumar | 8fdc398 | 2012-08-21 12:22:27 -0700 | [diff] [blame] | 510 | dev_err(mehci->dev, "ulpi_write: timeout ULPI_VIEWPORT: %08x\n", |
| 511 | readl_relaxed(USB_ULPI_VIEWPORT)); |
| 512 | dev_err(mehci->dev, "PORTSC: %08x USBCMD: %08x FRINDEX: %08x\n", |
| 513 | readl_relaxed(USB_PORTSC), |
| 514 | readl_relaxed(USB_USBCMD), |
| 515 | readl_relaxed(USB_FRINDEX)); |
| 516 | |
| 517 | /*frame counter increments afte 125us*/ |
| 518 | udelay(130); |
| 519 | dev_err(mehci->dev, "ulpi_write: FRINDEX: %08x\n", |
| 520 | readl_relaxed(USB_FRINDEX)); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 521 | return -ETIMEDOUT; |
| 522 | } |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 527 | static int msm_hsic_config_gpios(struct msm_hsic_hcd *mehci, int gpio_en) |
| 528 | { |
| 529 | int rc = 0; |
| 530 | struct msm_hsic_host_platform_data *pdata; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 531 | static int gpio_status; |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 532 | |
| 533 | pdata = mehci->dev->platform_data; |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 534 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 535 | if (!pdata || !pdata->strobe || !pdata->data) |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 536 | return rc; |
| 537 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 538 | if (gpio_status == gpio_en) |
| 539 | return 0; |
| 540 | |
| 541 | gpio_status = gpio_en; |
| 542 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 543 | if (!gpio_en) |
| 544 | goto free_gpio; |
| 545 | |
| 546 | rc = gpio_request(pdata->strobe, "HSIC_STROBE_GPIO"); |
| 547 | if (rc < 0) { |
| 548 | dev_err(mehci->dev, "gpio request failed for HSIC STROBE\n"); |
| 549 | return rc; |
| 550 | } |
| 551 | |
| 552 | rc = gpio_request(pdata->data, "HSIC_DATA_GPIO"); |
| 553 | if (rc < 0) { |
| 554 | dev_err(mehci->dev, "gpio request failed for HSIC DATA\n"); |
| 555 | goto free_strobe; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 558 | return 0; |
| 559 | |
| 560 | free_gpio: |
| 561 | gpio_free(pdata->data); |
| 562 | free_strobe: |
| 563 | gpio_free(pdata->strobe); |
| 564 | |
| 565 | return rc; |
| 566 | } |
| 567 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 568 | static void msm_hsic_clk_reset(struct msm_hsic_hcd *mehci) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 569 | { |
| 570 | int ret; |
| 571 | |
Ofir Cohen | 07944aa | 2012-12-23 13:41:57 +0200 | [diff] [blame] | 572 | /* alt_core_clk exists in targets that do not use asynchronous reset */ |
| 573 | if (!IS_ERR(mehci->alt_core_clk)) { |
| 574 | ret = clk_reset(mehci->core_clk, CLK_RESET_ASSERT); |
| 575 | if (ret) { |
| 576 | dev_err(mehci->dev, "hsic clk assert failed:%d\n", ret); |
| 577 | return; |
| 578 | } |
| 579 | |
| 580 | /* Since a hw bug, turn off the clock before complete reset */ |
| 581 | clk_disable(mehci->core_clk); |
| 582 | |
| 583 | ret = clk_reset(mehci->core_clk, CLK_RESET_DEASSERT); |
| 584 | if (ret) |
| 585 | dev_err(mehci->dev, "hsic clk deassert failed:%d\n", |
| 586 | ret); |
| 587 | |
| 588 | usleep_range(10000, 12000); |
| 589 | |
| 590 | clk_enable(mehci->core_clk); |
| 591 | } else { |
| 592 | /* Using asynchronous block reset to the hardware */ |
| 593 | clk_disable_unprepare(mehci->core_clk); |
| 594 | clk_disable_unprepare(mehci->phy_clk); |
| 595 | clk_disable_unprepare(mehci->cal_clk); |
| 596 | clk_disable_unprepare(mehci->ahb_clk); |
Ido Shayevitz | 5dfbb13 | 2013-04-18 13:22:07 +0300 | [diff] [blame] | 597 | if (!IS_ERR(mehci->inactivity_clk)) |
| 598 | clk_disable_unprepare(mehci->inactivity_clk); |
Ofir Cohen | 07944aa | 2012-12-23 13:41:57 +0200 | [diff] [blame] | 599 | |
| 600 | ret = clk_reset(mehci->core_clk, CLK_RESET_ASSERT); |
| 601 | if (ret) { |
| 602 | dev_err(mehci->dev, "hsic clk assert failed:%d\n", ret); |
| 603 | return; |
| 604 | } |
| 605 | usleep_range(10000, 12000); |
| 606 | |
| 607 | ret = clk_reset(mehci->core_clk, CLK_RESET_DEASSERT); |
| 608 | if (ret) |
| 609 | dev_err(mehci->dev, "hsic clk deassert failed:%d\n", |
| 610 | ret); |
| 611 | /* |
| 612 | * Required delay between the deassertion and |
| 613 | * clock enablement. |
| 614 | */ |
| 615 | ndelay(200); |
| 616 | clk_prepare_enable(mehci->core_clk); |
| 617 | clk_prepare_enable(mehci->phy_clk); |
| 618 | clk_prepare_enable(mehci->cal_clk); |
| 619 | clk_prepare_enable(mehci->ahb_clk); |
Ido Shayevitz | 5dfbb13 | 2013-04-18 13:22:07 +0300 | [diff] [blame] | 620 | if (!IS_ERR(mehci->inactivity_clk)) |
| 621 | clk_prepare_enable(mehci->inactivity_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 622 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 623 | } |
| 624 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 625 | #define HSIC_STROBE_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C0) |
| 626 | #define HSIC_DATA_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C4) |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 627 | #define HSIC_CAL_PAD_CTL (MSM_TLMM_BASE+0x20C8) |
| 628 | #define HSIC_LV_MODE 0x04 |
| 629 | #define HSIC_PAD_CALIBRATION 0xA8 |
| 630 | #define HSIC_GPIO_PAD_VAL 0x0A0AAA10 |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 631 | #define LINK_RESET_TIMEOUT_USEC (250 * 1000) |
Ofir Cohen | 5dddb15 | 2012-11-14 11:18:50 +0200 | [diff] [blame] | 632 | |
| 633 | static void msm_hsic_phy_reset(struct msm_hsic_hcd *mehci) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 634 | { |
| 635 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 636 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 637 | msm_hsic_clk_reset(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 638 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 639 | /* select ulpi phy */ |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 640 | writel_relaxed(0x80000000, USB_PORTSC); |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 641 | mb(); |
Ofir Cohen | 5dddb15 | 2012-11-14 11:18:50 +0200 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | static int msm_hsic_start(struct msm_hsic_hcd *mehci) |
| 645 | { |
| 646 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
| 647 | int ret; |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 648 | void __iomem *reg; |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 649 | |
Vamsi Krishna | bef9183 | 2013-03-11 14:10:20 -0700 | [diff] [blame] | 650 | if (pdata && pdata->resume_gpio) { |
| 651 | ret = gpio_request(pdata->resume_gpio, "HSIC_RESUME_GPIO"); |
| 652 | if (ret < 0) { |
| 653 | dev_err(mehci->dev, |
| 654 | "gpio req failed for hsic resume:%d\n", ret); |
| 655 | pdata->resume_gpio = 0; |
| 656 | } |
| 657 | } |
| 658 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 659 | /* HSIC init sequence when HSIC signals (Strobe/Data) are |
| 660 | routed via GPIOs */ |
| 661 | if (pdata && pdata->strobe && pdata->data) { |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 662 | |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 663 | if (!pdata->ignore_cal_pad_config) { |
| 664 | /* Enable LV_MODE in HSIC_CAL_PAD_CTL register */ |
| 665 | writel_relaxed(HSIC_LV_MODE, HSIC_CAL_PAD_CTL); |
| 666 | mb(); |
| 667 | } |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 668 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 669 | /*set periodic calibration interval to ~2.048sec in |
| 670 | HSIC_IO_CAL_REG */ |
| 671 | ulpi_write(mehci, 0xFF, 0x33); |
| 672 | |
| 673 | /* Enable periodic IO calibration in HSIC_CFG register */ |
| 674 | ulpi_write(mehci, HSIC_PAD_CALIBRATION, 0x30); |
| 675 | |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 676 | /* Configure GPIO pins for HSIC functionality mode */ |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 677 | ret = msm_hsic_config_gpios(mehci, 1); |
| 678 | if (ret) { |
| 679 | dev_err(mehci->dev, " gpio configuarion failed\n"); |
Vamsi Krishna | bef9183 | 2013-03-11 14:10:20 -0700 | [diff] [blame] | 680 | goto free_resume_gpio; |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 681 | } |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 682 | if (pdata->strobe_pad_offset) { |
| 683 | /* Set CORE_CTL_EN in STROBE GPIO PAD_CTL register */ |
| 684 | reg = MSM_TLMM_BASE + pdata->strobe_pad_offset; |
| 685 | writel_relaxed(readl_relaxed(reg) | 0x2000000, reg); |
| 686 | } else { |
| 687 | /* Set LV_MODE=0x1 and DCC=0x2 in STROBE GPIO PAD_CTL */ |
| 688 | reg = HSIC_STROBE_GPIO_PAD_CTL; |
| 689 | writel_relaxed(HSIC_GPIO_PAD_VAL, reg); |
| 690 | } |
| 691 | |
| 692 | if (pdata->data_pad_offset) { |
| 693 | /* Set CORE_CTL_EN in HSIC_DATA GPIO PAD_CTL register */ |
| 694 | reg = MSM_TLMM_BASE + pdata->data_pad_offset; |
| 695 | writel_relaxed(readl_relaxed(reg) | 0x2000000, reg); |
| 696 | } else { |
| 697 | /* Set LV_MODE=0x1 and DCC=0x2 in STROBE GPIO PAD_CTL */ |
| 698 | reg = HSIC_DATA_GPIO_PAD_CTL; |
| 699 | writel_relaxed(HSIC_GPIO_PAD_VAL, reg); |
| 700 | } |
Vamsi Krishna | 64b4861 | 2012-06-14 16:08:11 -0700 | [diff] [blame] | 701 | |
| 702 | mb(); |
| 703 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 704 | /* Enable HSIC mode in HSIC_CFG register */ |
| 705 | ulpi_write(mehci, 0x01, 0x31); |
| 706 | } else { |
| 707 | /* HSIC init sequence when HSIC signals (Strobe/Data) are routed |
| 708 | via dedicated I/O */ |
| 709 | |
| 710 | /* programmable length of connect signaling (33.2ns) */ |
| 711 | ret = ulpi_write(mehci, 3, HSIC_DBG1_REG); |
| 712 | if (ret) { |
| 713 | pr_err("%s: Unable to program length of connect " |
| 714 | "signaling\n", __func__); |
| 715 | } |
| 716 | |
| 717 | /*set periodic calibration interval to ~2.048sec in |
| 718 | HSIC_IO_CAL_REG */ |
| 719 | ulpi_write(mehci, 0xFF, 0x33); |
| 720 | |
| 721 | /* Enable HSIC mode in HSIC_CFG register */ |
| 722 | ulpi_write(mehci, 0xA9, 0x30); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 723 | } |
| 724 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 725 | /*disable auto resume*/ |
| 726 | ulpi_write(mehci, ULPI_IFC_CTRL_AUTORESUME, ULPI_CLR(ULPI_IFC_CTRL)); |
| 727 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 728 | return 0; |
Vamsi Krishna | bef9183 | 2013-03-11 14:10:20 -0700 | [diff] [blame] | 729 | |
| 730 | free_resume_gpio: |
| 731 | if (pdata && pdata->resume_gpio) |
| 732 | gpio_free(pdata->resume_gpio); |
| 733 | |
| 734 | return ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 735 | } |
| 736 | |
| 737 | #define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000) |
| 738 | #define PHY_RESUME_TIMEOUT_USEC (100 * 1000) |
| 739 | |
| 740 | #ifdef CONFIG_PM_SLEEP |
Ofir Cohen | 5dddb15 | 2012-11-14 11:18:50 +0200 | [diff] [blame] | 741 | static int msm_hsic_reset(struct msm_hsic_hcd *mehci) |
| 742 | { |
| 743 | /* reset HSIC phy */ |
| 744 | msm_hsic_phy_reset(mehci); |
| 745 | |
| 746 | /* HSIC init procedure (caliberation) */ |
| 747 | return msm_hsic_start(mehci); |
| 748 | } |
| 749 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 750 | static int msm_hsic_suspend(struct msm_hsic_hcd *mehci) |
| 751 | { |
| 752 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 753 | int cnt = 0, ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 754 | u32 val; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 755 | int none_vol, max_vol; |
Hemant Kumar | bc8bdf6 | 2012-10-17 12:29:51 -0700 | [diff] [blame] | 756 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 757 | |
| 758 | if (atomic_read(&mehci->in_lpm)) { |
| 759 | dev_dbg(mehci->dev, "%s called in lpm\n", __func__); |
| 760 | return 0; |
| 761 | } |
| 762 | |
| 763 | disable_irq(hcd->irq); |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 764 | |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 765 | /* make sure we don't race against a remote wakeup */ |
| 766 | if (test_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags) || |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 767 | readl_relaxed(USB_PORTSC) & PORT_RESUME) { |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 768 | dev_dbg(mehci->dev, "wakeup pending, aborting suspend\n"); |
Jack Pham | be05fbb | 2012-05-16 10:56:26 -0700 | [diff] [blame] | 769 | enable_irq(hcd->irq); |
| 770 | return -EBUSY; |
| 771 | } |
| 772 | |
Ido Shayevitz | aa165c5 | 2013-05-12 16:01:28 +0200 | [diff] [blame] | 773 | if (pdata->consider_ipa_handshake) { |
| 774 | dev_dbg(mehci->dev, "%s:Wait for resources release\n", |
| 775 | __func__); |
| 776 | if (!msm_bam_hsic_lpm_ok()) { |
| 777 | dev_dbg(mehci->dev, "%s:Prod+Cons not released\n", |
| 778 | __func__); |
| 779 | enable_irq(hcd->irq); |
| 780 | return -EBUSY; |
| 781 | } |
| 782 | dev_dbg(mehci->dev, "%s:Prod+Cons resources released\n", |
| 783 | __func__); |
| 784 | } |
| 785 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 786 | /* |
| 787 | * PHY may take some time or even fail to enter into low power |
| 788 | * mode (LPM). Hence poll for 500 msec and reset the PHY and link |
| 789 | * in failure case. |
| 790 | */ |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 791 | val = readl_relaxed(USB_PORTSC); |
| 792 | val &= ~PORT_RWC_BITS; |
| 793 | val |= PORTSC_PHCD; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 794 | writel_relaxed(val, USB_PORTSC); |
| 795 | while (cnt < PHY_SUSPEND_TIMEOUT_USEC) { |
| 796 | if (readl_relaxed(USB_PORTSC) & PORTSC_PHCD) |
| 797 | break; |
| 798 | udelay(1); |
| 799 | cnt++; |
| 800 | } |
| 801 | |
| 802 | if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) { |
| 803 | dev_err(mehci->dev, "Unable to suspend PHY\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 804 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 805 | msm_hsic_reset(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /* |
| 809 | * PHY has capability to generate interrupt asynchronously in low |
| 810 | * power mode (LPM). This interrupt is level triggered. So USB IRQ |
| 811 | * line must be disabled till async interrupt enable bit is cleared |
| 812 | * in USBCMD register. Assert STP (ULPI interface STOP signal) to |
Pavankumar Kondeti | 0c9f29c | 2013-01-28 21:37:59 +0530 | [diff] [blame] | 813 | * block data communication from PHY. Enable asynchronous interrupt |
| 814 | * only when wakeup gpio IRQ is not present. |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 815 | */ |
Pavankumar Kondeti | 0c9f29c | 2013-01-28 21:37:59 +0530 | [diff] [blame] | 816 | if (mehci->wakeup_irq) |
| 817 | writel_relaxed(readl_relaxed(USB_USBCMD) | |
| 818 | ULPI_STP_CTRL, USB_USBCMD); |
| 819 | else |
| 820 | writel_relaxed(readl_relaxed(USB_USBCMD) | ASYNC_INTR_CTRL | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 821 | ULPI_STP_CTRL, USB_USBCMD); |
| 822 | |
| 823 | /* |
| 824 | * Ensure that hardware is put in low power mode before |
| 825 | * clocks are turned OFF and VDD is allowed to minimize. |
| 826 | */ |
| 827 | mb(); |
| 828 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 829 | clk_disable_unprepare(mehci->core_clk); |
| 830 | clk_disable_unprepare(mehci->phy_clk); |
| 831 | clk_disable_unprepare(mehci->cal_clk); |
| 832 | clk_disable_unprepare(mehci->ahb_clk); |
Ido Shayevitz | 5dfbb13 | 2013-04-18 13:22:07 +0300 | [diff] [blame] | 833 | if (!IS_ERR(mehci->inactivity_clk)) |
| 834 | clk_disable_unprepare(mehci->inactivity_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 835 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 836 | none_vol = vdd_val[mehci->vdd_type][VDD_NONE]; |
| 837 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
| 838 | |
| 839 | ret = regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 840 | if (ret < 0) |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 841 | 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] | 842 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 843 | if (mehci->bus_perf_client && debug_bus_voting_enabled) { |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 844 | mehci->bus_vote = false; |
| 845 | queue_work(ehci_wq, &mehci->bus_vote_w); |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 846 | } |
| 847 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 848 | atomic_set(&mehci->in_lpm, 1); |
| 849 | enable_irq(hcd->irq); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 850 | |
Manu Gautam | 3fb60ca | 2013-02-13 18:33:33 +0530 | [diff] [blame] | 851 | if (mehci->wakeup_irq) { |
| 852 | mehci->wakeup_irq_enabled = 1; |
| 853 | enable_irq_wake(mehci->wakeup_irq); |
| 854 | enable_irq(mehci->wakeup_irq); |
| 855 | } |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 856 | |
Hemant Kumar | bc8bdf6 | 2012-10-17 12:29:51 -0700 | [diff] [blame] | 857 | if (pdata && pdata->standalone_latency) |
| 858 | pm_qos_update_request(&mehci->pm_qos_req_dma, |
| 859 | PM_QOS_DEFAULT_VALUE); |
| 860 | |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 861 | wake_unlock(&mehci->wlock); |
| 862 | |
Ido Shayevitz | aa165c5 | 2013-05-12 16:01:28 +0200 | [diff] [blame] | 863 | dev_info(mehci->dev, "HSIC-USB in low power mode\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 864 | |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | static int msm_hsic_resume(struct msm_hsic_hcd *mehci) |
| 869 | { |
| 870 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 871 | int cnt = 0, ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 872 | unsigned temp; |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 873 | int min_vol, max_vol; |
Hemant Kumar | d343c01 | 2012-09-06 19:57:14 -0700 | [diff] [blame] | 874 | unsigned long flags; |
Hemant Kumar | bc8bdf6 | 2012-10-17 12:29:51 -0700 | [diff] [blame] | 875 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 876 | |
| 877 | if (!atomic_read(&mehci->in_lpm)) { |
| 878 | dev_dbg(mehci->dev, "%s called in !in_lpm\n", __func__); |
| 879 | return 0; |
| 880 | } |
| 881 | |
Ido Shayevitz | aa165c5 | 2013-05-12 16:01:28 +0200 | [diff] [blame] | 882 | if (pdata->consider_ipa_handshake) { |
| 883 | dev_dbg(mehci->dev, "%s:Wait for producer resource\n", |
| 884 | __func__); |
| 885 | msm_bam_wait_for_hsic_prod_granted(); |
| 886 | dev_dbg(mehci->dev, "%s:Producer resource obtained\n", |
| 887 | __func__); |
| 888 | } |
| 889 | |
Pavankumar Kondeti | 822fbe6 | 2013-01-28 17:04:39 +0530 | [diff] [blame] | 890 | /* Handles race with Async interrupt */ |
| 891 | disable_irq(hcd->irq); |
| 892 | |
Hemant Kumar | bc8bdf6 | 2012-10-17 12:29:51 -0700 | [diff] [blame] | 893 | if (pdata && pdata->standalone_latency) |
| 894 | pm_qos_update_request(&mehci->pm_qos_req_dma, |
| 895 | pdata->standalone_latency + 1); |
| 896 | |
Manu Gautam | 3fb60ca | 2013-02-13 18:33:33 +0530 | [diff] [blame] | 897 | if (mehci->wakeup_irq) { |
| 898 | spin_lock_irqsave(&mehci->wakeup_lock, flags); |
| 899 | if (mehci->wakeup_irq_enabled) { |
| 900 | disable_irq_wake(mehci->wakeup_irq); |
| 901 | disable_irq_nosync(mehci->wakeup_irq); |
| 902 | mehci->wakeup_irq_enabled = 0; |
| 903 | } |
| 904 | spin_unlock_irqrestore(&mehci->wakeup_lock, flags); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 905 | } |
| 906 | |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 907 | wake_lock(&mehci->wlock); |
| 908 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 909 | if (mehci->bus_perf_client && debug_bus_voting_enabled) { |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 910 | mehci->bus_vote = true; |
| 911 | queue_work(ehci_wq, &mehci->bus_vote_w); |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 912 | } |
| 913 | |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 914 | min_vol = vdd_val[mehci->vdd_type][VDD_MIN]; |
| 915 | max_vol = vdd_val[mehci->vdd_type][VDD_MAX]; |
| 916 | |
| 917 | ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol); |
Vamsi Krishna | 45d88fa | 2011-11-02 13:28:42 -0700 | [diff] [blame] | 918 | if (ret < 0) |
Amit Blay | d6ea610 | 2012-06-07 16:26:24 +0300 | [diff] [blame] | 919 | 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] | 920 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 921 | clk_prepare_enable(mehci->core_clk); |
| 922 | clk_prepare_enable(mehci->phy_clk); |
| 923 | clk_prepare_enable(mehci->cal_clk); |
| 924 | clk_prepare_enable(mehci->ahb_clk); |
Ido Shayevitz | 5dfbb13 | 2013-04-18 13:22:07 +0300 | [diff] [blame] | 925 | if (!IS_ERR(mehci->inactivity_clk)) |
| 926 | clk_prepare_enable(mehci->inactivity_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 927 | |
| 928 | temp = readl_relaxed(USB_USBCMD); |
| 929 | temp &= ~ASYNC_INTR_CTRL; |
| 930 | temp &= ~ULPI_STP_CTRL; |
| 931 | writel_relaxed(temp, USB_USBCMD); |
| 932 | |
| 933 | if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD)) |
| 934 | goto skip_phy_resume; |
| 935 | |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 936 | temp = readl_relaxed(USB_PORTSC); |
| 937 | temp &= ~(PORT_RWC_BITS | PORTSC_PHCD); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 938 | writel_relaxed(temp, USB_PORTSC); |
| 939 | while (cnt < PHY_RESUME_TIMEOUT_USEC) { |
| 940 | if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD) && |
| 941 | (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_SYNC_STATE)) |
| 942 | break; |
| 943 | udelay(1); |
| 944 | cnt++; |
| 945 | } |
| 946 | |
| 947 | if (cnt >= PHY_RESUME_TIMEOUT_USEC) { |
| 948 | /* |
| 949 | * This is a fatal error. Reset the link and |
| 950 | * PHY to make hsic working. |
| 951 | */ |
| 952 | dev_err(mehci->dev, "Unable to resume USB. Reset the hsic\n"); |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 953 | msm_hsic_config_gpios(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 954 | msm_hsic_reset(mehci); |
| 955 | } |
| 956 | |
| 957 | skip_phy_resume: |
| 958 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 959 | usb_hcd_resume_root_hub(hcd); |
| 960 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 961 | atomic_set(&mehci->in_lpm, 0); |
| 962 | |
Pavankumar Kondeti | 822fbe6 | 2013-01-28 17:04:39 +0530 | [diff] [blame] | 963 | if (atomic_read(&mehci->async_int)) { |
| 964 | atomic_set(&mehci->async_int, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 965 | pm_runtime_put_noidle(mehci->dev); |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 966 | enable_irq(hcd->irq); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 967 | } |
| 968 | |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 969 | if (atomic_read(&mehci->pm_usage_cnt)) { |
| 970 | atomic_set(&mehci->pm_usage_cnt, 0); |
| 971 | pm_runtime_put_noidle(mehci->dev); |
| 972 | } |
Jack Pham | dd5ad79 | 2012-07-26 10:31:03 -0700 | [diff] [blame] | 973 | |
Pavankumar Kondeti | 822fbe6 | 2013-01-28 17:04:39 +0530 | [diff] [blame] | 974 | enable_irq(hcd->irq); |
Ido Shayevitz | aa165c5 | 2013-05-12 16:01:28 +0200 | [diff] [blame] | 975 | dev_info(mehci->dev, "HSIC-USB exited from low power mode\n"); |
| 976 | |
| 977 | if (pdata->consider_ipa_handshake) { |
| 978 | dev_dbg(mehci->dev, "%s:Notify usb bam on resume complete\n", |
| 979 | __func__); |
| 980 | msm_bam_hsic_notify_on_resume(); |
| 981 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | #endif |
| 986 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 987 | static void ehci_hsic_bus_vote_w(struct work_struct *w) |
| 988 | { |
| 989 | struct msm_hsic_hcd *mehci = |
| 990 | container_of(w, struct msm_hsic_hcd, bus_vote_w); |
| 991 | int ret; |
| 992 | |
| 993 | ret = msm_bus_scale_client_update_request(mehci->bus_perf_client, |
| 994 | mehci->bus_vote); |
| 995 | if (ret) |
| 996 | dev_err(mehci->dev, "%s: Failed to vote for bus bandwidth %d\n", |
| 997 | __func__, ret); |
| 998 | } |
| 999 | |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 1000 | static int msm_hsic_reset_done(struct usb_hcd *hcd) |
| 1001 | { |
| 1002 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 1003 | u32 __iomem *status_reg = &ehci->regs->port_status[0]; |
| 1004 | int ret; |
| 1005 | |
| 1006 | ehci_writel(ehci, ehci_readl(ehci, status_reg) & ~(PORT_RWC_BITS | |
| 1007 | PORT_RESET), status_reg); |
| 1008 | |
| 1009 | ret = handshake(ehci, status_reg, PORT_RESET, 0, 1 * 1000); |
| 1010 | |
| 1011 | if (ret) |
| 1012 | pr_err("reset handshake failed in %s\n", __func__); |
| 1013 | else |
| 1014 | ehci_writel(ehci, ehci_readl(ehci, &ehci->regs->command) | |
| 1015 | CMD_RUN, &ehci->regs->command); |
| 1016 | |
| 1017 | return ret; |
| 1018 | } |
| 1019 | |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1020 | #define STS_GPTIMER0_INTERRUPT BIT(24) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1021 | static irqreturn_t msm_hsic_irq(struct usb_hcd *hcd) |
| 1022 | { |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1023 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1024 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1025 | u32 status; |
Pavankumar Kondeti | 822fbe6 | 2013-01-28 17:04:39 +0530 | [diff] [blame] | 1026 | int ret; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1027 | |
| 1028 | if (atomic_read(&mehci->in_lpm)) { |
Hemant Kumar | 3dbc5b3 | 2012-05-09 15:36:11 -0700 | [diff] [blame] | 1029 | dev_dbg(mehci->dev, "phy async intr\n"); |
Pavankumar Kondeti | 822fbe6 | 2013-01-28 17:04:39 +0530 | [diff] [blame] | 1030 | dbg_log_event(NULL, "Async IRQ", 0); |
| 1031 | ret = pm_runtime_get(mehci->dev); |
| 1032 | if ((ret == 1) || (ret == -EINPROGRESS)) { |
| 1033 | pm_runtime_put_noidle(mehci->dev); |
| 1034 | } else { |
| 1035 | disable_irq_nosync(hcd->irq); |
| 1036 | atomic_set(&mehci->async_int, 1); |
| 1037 | } |
| 1038 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1039 | return IRQ_HANDLED; |
| 1040 | } |
| 1041 | |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1042 | status = ehci_readl(ehci, &ehci->regs->status); |
| 1043 | |
| 1044 | if (status & STS_GPTIMER0_INTERRUPT) { |
| 1045 | int timeleft; |
| 1046 | |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 1047 | dbg_log_event(NULL, "FPR: gpt0_isr", mehci->bus_reset); |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1048 | |
| 1049 | timeleft = GPT_CNT(ehci_readl(ehci, |
| 1050 | &mehci->timer->gptimer1_ctrl)); |
| 1051 | if (timeleft) { |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 1052 | if (mehci->bus_reset) { |
| 1053 | ret = msm_hsic_reset_done(hcd); |
| 1054 | if (ret) { |
| 1055 | mehci->reset_again = 1; |
| 1056 | dbg_log_event(NULL, "RESET: fail", 0); |
| 1057 | } |
| 1058 | } else { |
| 1059 | ehci_writel(ehci, ehci_readl(ehci, |
| 1060 | &ehci->regs->command) | CMD_RUN, |
| 1061 | &ehci->regs->command); |
| 1062 | } |
| 1063 | } else { |
| 1064 | if (mehci->bus_reset) |
| 1065 | mehci->reset_again = 1; |
| 1066 | else |
| 1067 | mehci->resume_again = 1; |
| 1068 | } |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1069 | |
| 1070 | dbg_log_event(NULL, "FPR: timeleft", timeleft); |
| 1071 | |
| 1072 | complete(&mehci->gpt0_completion); |
| 1073 | ehci_writel(ehci, STS_GPTIMER0_INTERRUPT, &ehci->regs->status); |
| 1074 | } |
| 1075 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1076 | return ehci_irq(hcd); |
| 1077 | } |
| 1078 | |
| 1079 | static int ehci_hsic_reset(struct usb_hcd *hcd) |
| 1080 | { |
| 1081 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1082 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
Amit Blay | 1dfbbcc | 2013-05-26 17:33:13 +0300 | [diff] [blame] | 1083 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1084 | int retval; |
| 1085 | |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1086 | mehci->timer = USB_HS_GPTIMER_BASE; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1087 | ehci->caps = USB_CAPLENGTH; |
| 1088 | ehci->regs = USB_CAPLENGTH + |
| 1089 | HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase)); |
| 1090 | dbg_hcs_params(ehci, "reset"); |
| 1091 | dbg_hcc_params(ehci, "reset"); |
| 1092 | |
| 1093 | /* cache the data to minimize the chip reads*/ |
| 1094 | ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); |
| 1095 | |
| 1096 | hcd->has_tt = 1; |
| 1097 | ehci->sbrn = HCD_USB2; |
| 1098 | |
| 1099 | retval = ehci_halt(ehci); |
| 1100 | if (retval) |
| 1101 | return retval; |
| 1102 | |
| 1103 | /* data structure init */ |
| 1104 | retval = ehci_init(hcd); |
| 1105 | if (retval) |
| 1106 | return retval; |
| 1107 | |
| 1108 | retval = ehci_reset(ehci); |
| 1109 | if (retval) |
| 1110 | return retval; |
| 1111 | |
| 1112 | /* bursts of unspecified length. */ |
| 1113 | writel_relaxed(0, USB_AHBBURST); |
Amit Blay | 1dfbbcc | 2013-05-26 17:33:13 +0300 | [diff] [blame] | 1114 | |
| 1115 | /* Use the AHB transactor and configure async bridge bypass */ |
| 1116 | #define MSM_USB_ASYNC_BRIDGE_BYPASS BIT(31) |
| 1117 | if (pdata->ahb_async_bridge_bypass) |
| 1118 | writel_relaxed(0x08 | MSM_USB_ASYNC_BRIDGE_BYPASS, USB_AHBMODE); |
| 1119 | else |
| 1120 | writel_relaxed(0x08, USB_AHBMODE); |
| 1121 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1122 | /* Disable streaming mode and select host mode */ |
| 1123 | writel_relaxed(0x13, USB_USBMODE); |
| 1124 | |
| 1125 | ehci_port_power(ehci, 1); |
| 1126 | return 0; |
| 1127 | } |
| 1128 | |
Jack Pham | c0d4173 | 2012-09-28 17:45:38 -0700 | [diff] [blame] | 1129 | #ifdef CONFIG_PM |
| 1130 | |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 1131 | #define RESET_RETRY_LIMIT 3 |
| 1132 | #define RESET_SIGNAL_TIME_SOF_USEC (50 * 1000) |
| 1133 | #define RESET_SIGNAL_TIME_USEC (20 * 1000) |
| 1134 | static void ehci_hsic_reset_sof_bug_handler(struct usb_hcd *hcd, u32 val) |
| 1135 | { |
| 1136 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 1137 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1138 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
| 1139 | u32 __iomem *status_reg = &ehci->regs->port_status[0]; |
Pavankumar Kondeti | fc7d1d8 | 2013-03-05 09:43:22 +0530 | [diff] [blame] | 1140 | u32 cmd; |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 1141 | unsigned long flags; |
| 1142 | int retries = 0, ret, cnt = RESET_SIGNAL_TIME_USEC; |
Pavankumar Kondeti | 4152d80 | 2013-07-22 15:32:17 +0530 | [diff] [blame] | 1143 | s32 next_latency = 0; |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 1144 | |
Pavankumar Kondeti | 4152d80 | 2013-07-22 15:32:17 +0530 | [diff] [blame] | 1145 | if (pdata && pdata->swfi_latency) { |
| 1146 | next_latency = pdata->swfi_latency + 1; |
| 1147 | pm_qos_update_request(&mehci->pm_qos_req_dma, next_latency); |
| 1148 | if (pdata->standalone_latency) |
| 1149 | next_latency = pdata->standalone_latency + 1; |
| 1150 | else |
| 1151 | next_latency = PM_QOS_DEFAULT_VALUE; |
| 1152 | } |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 1153 | |
| 1154 | mehci->bus_reset = 1; |
Pavankumar Kondeti | fc7d1d8 | 2013-03-05 09:43:22 +0530 | [diff] [blame] | 1155 | |
| 1156 | /* Halt the controller */ |
| 1157 | cmd = ehci_readl(ehci, &ehci->regs->command); |
| 1158 | cmd &= ~CMD_RUN; |
| 1159 | ehci_writel(ehci, cmd, &ehci->regs->command); |
| 1160 | ret = handshake(ehci, &ehci->regs->status, STS_HALT, |
| 1161 | STS_HALT, 16 * 125); |
| 1162 | if (ret) { |
| 1163 | pr_err("halt handshake fatal error\n"); |
| 1164 | dbg_log_event(NULL, "HALT: fatal", 0); |
| 1165 | goto fail; |
| 1166 | } |
| 1167 | |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 1168 | retry: |
| 1169 | retries++; |
| 1170 | dbg_log_event(NULL, "RESET: start", retries); |
| 1171 | pr_debug("reset begin %d\n", retries); |
| 1172 | mehci->reset_again = 0; |
| 1173 | spin_lock_irqsave(&ehci->lock, flags); |
| 1174 | ehci_writel(ehci, val, status_reg); |
| 1175 | ehci_writel(ehci, GPT_LD(RESET_SIGNAL_TIME_USEC - 1), |
| 1176 | &mehci->timer->gptimer0_ld); |
| 1177 | ehci_writel(ehci, GPT_RESET | GPT_RUN, |
| 1178 | &mehci->timer->gptimer0_ctrl); |
| 1179 | ehci_writel(ehci, INTR_MASK | STS_GPTIMER0_INTERRUPT, |
| 1180 | &ehci->regs->intr_enable); |
| 1181 | |
| 1182 | ehci_writel(ehci, GPT_LD(RESET_SIGNAL_TIME_SOF_USEC - 1), |
| 1183 | &mehci->timer->gptimer1_ld); |
| 1184 | ehci_writel(ehci, GPT_RESET | GPT_RUN, |
| 1185 | &mehci->timer->gptimer1_ctrl); |
| 1186 | |
| 1187 | spin_unlock_irqrestore(&ehci->lock, flags); |
| 1188 | wait_for_completion(&mehci->gpt0_completion); |
| 1189 | |
| 1190 | if (!mehci->reset_again) |
| 1191 | goto done; |
| 1192 | |
| 1193 | if (handshake(ehci, status_reg, PORT_RESET, 0, 10 * 1000)) { |
| 1194 | pr_err("reset handshake fatal error\n"); |
| 1195 | dbg_log_event(NULL, "RESET: fatal", retries); |
| 1196 | goto fail; |
| 1197 | } |
| 1198 | |
| 1199 | if (retries < RESET_RETRY_LIMIT) |
| 1200 | goto retry; |
| 1201 | |
| 1202 | /* complete reset in tight loop */ |
| 1203 | pr_info("RESET in tight loop\n"); |
| 1204 | dbg_log_event(NULL, "RESET: tight", 0); |
| 1205 | |
| 1206 | spin_lock_irqsave(&ehci->lock, flags); |
| 1207 | ehci_writel(ehci, val, status_reg); |
| 1208 | while (cnt--) |
| 1209 | udelay(1); |
| 1210 | ret = msm_hsic_reset_done(hcd); |
| 1211 | spin_unlock_irqrestore(&ehci->lock, flags); |
| 1212 | if (ret) { |
| 1213 | pr_err("RESET in tight loop failed\n"); |
| 1214 | dbg_log_event(NULL, "RESET: tight failed", 0); |
| 1215 | goto fail; |
| 1216 | } |
| 1217 | |
| 1218 | done: |
| 1219 | dbg_log_event(NULL, "RESET: done", retries); |
| 1220 | pr_debug("reset completed\n"); |
| 1221 | fail: |
| 1222 | mehci->bus_reset = 0; |
Pavankumar Kondeti | 4152d80 | 2013-07-22 15:32:17 +0530 | [diff] [blame] | 1223 | if (next_latency) |
| 1224 | pm_qos_update_request(&mehci->pm_qos_req_dma, next_latency); |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 1225 | } |
| 1226 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1227 | static int ehci_hsic_bus_suspend(struct usb_hcd *hcd) |
| 1228 | { |
Pavankumar Kondeti | a723f74 | 2012-09-14 14:02:36 +0530 | [diff] [blame] | 1229 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1230 | |
| 1231 | if (!(readl_relaxed(USB_PORTSC) & PORT_PE)) { |
| 1232 | dbg_log_event(NULL, "RH suspend attempt failed", 0); |
| 1233 | dev_dbg(mehci->dev, "%s:port is not enabled skip suspend\n", |
| 1234 | __func__); |
| 1235 | return -EAGAIN; |
| 1236 | } |
| 1237 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1238 | dbg_log_event(NULL, "Suspend RH", 0); |
| 1239 | return ehci_bus_suspend(hcd); |
| 1240 | } |
| 1241 | |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1242 | #define RESUME_RETRY_LIMIT 3 |
Pavankumar Kondeti | c4f817d | 2013-01-29 19:08:12 +0530 | [diff] [blame] | 1243 | #define RESUME_SIGNAL_TIME_USEC (21 * 1000) |
| 1244 | #define RESUME_SIGNAL_TIME_SOF_USEC (23 * 1000) |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1245 | static int msm_hsic_resume_thread(void *data) |
| 1246 | { |
| 1247 | struct msm_hsic_hcd *mehci = data; |
| 1248 | struct usb_hcd *hcd = hsic_to_hcd(mehci); |
| 1249 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 1250 | u32 temp; |
| 1251 | unsigned long resume_needed = 0; |
| 1252 | int retry_cnt = 0; |
| 1253 | int tight_resume = 0; |
Pavankumar Kondeti | 4f5dc3b | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 1254 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
Pavankumar Kondeti | 4152d80 | 2013-07-22 15:32:17 +0530 | [diff] [blame] | 1255 | s32 next_latency = 0; |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1256 | |
| 1257 | dbg_log_event(NULL, "Resume RH", 0); |
| 1258 | |
Pavankumar Kondeti | 4152d80 | 2013-07-22 15:32:17 +0530 | [diff] [blame] | 1259 | if (pdata && pdata->swfi_latency) { |
| 1260 | next_latency = pdata->swfi_latency + 1; |
| 1261 | pm_qos_update_request(&mehci->pm_qos_req_dma, next_latency); |
| 1262 | if (pdata->standalone_latency) |
| 1263 | next_latency = pdata->standalone_latency + 1; |
| 1264 | else |
| 1265 | next_latency = PM_QOS_DEFAULT_VALUE; |
| 1266 | } |
| 1267 | |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1268 | /* keep delay between bus states */ |
| 1269 | if (time_before(jiffies, ehci->next_statechange)) |
| 1270 | usleep_range(5000, 5000); |
| 1271 | |
| 1272 | spin_lock_irq(&ehci->lock); |
| 1273 | if (!HCD_HW_ACCESSIBLE(hcd)) { |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1274 | mehci->resume_status = -ESHUTDOWN; |
Pavankumar Kondeti | 4152d80 | 2013-07-22 15:32:17 +0530 | [diff] [blame] | 1275 | goto exit; |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | if (unlikely(ehci->debug)) { |
| 1279 | if (!dbgp_reset_prep()) |
| 1280 | ehci->debug = NULL; |
| 1281 | else |
| 1282 | dbgp_external_startup(); |
| 1283 | } |
| 1284 | |
| 1285 | /* at least some APM implementations will try to deliver |
| 1286 | * IRQs right away, so delay them until we're ready. |
| 1287 | */ |
| 1288 | ehci_writel(ehci, 0, &ehci->regs->intr_enable); |
| 1289 | |
| 1290 | /* re-init operational registers */ |
| 1291 | ehci_writel(ehci, 0, &ehci->regs->segment); |
| 1292 | ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list); |
| 1293 | ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next); |
| 1294 | |
| 1295 | /*CMD_RUN will be set after, PORT_RESUME gets cleared*/ |
| 1296 | if (ehci->resume_sof_bug) |
| 1297 | ehci->command &= ~CMD_RUN; |
| 1298 | |
| 1299 | /* restore CMD_RUN, framelist size, and irq threshold */ |
| 1300 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
| 1301 | |
| 1302 | /* manually resume the ports we suspended during bus_suspend() */ |
| 1303 | resume_again: |
| 1304 | if (retry_cnt >= RESUME_RETRY_LIMIT) { |
| 1305 | pr_info("retry count(%d) reached max, resume in tight loop\n", |
| 1306 | retry_cnt); |
| 1307 | tight_resume = 1; |
| 1308 | } |
| 1309 | |
| 1310 | |
| 1311 | temp = ehci_readl(ehci, &ehci->regs->port_status[0]); |
| 1312 | temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS); |
| 1313 | if (test_bit(0, &ehci->bus_suspended) && (temp & PORT_SUSPEND)) { |
| 1314 | temp |= PORT_RESUME; |
| 1315 | set_bit(0, &resume_needed); |
| 1316 | } |
| 1317 | dbg_log_event(NULL, "FPR: Set", temp); |
| 1318 | ehci_writel(ehci, temp, &ehci->regs->port_status[0]); |
| 1319 | |
| 1320 | /* HSIC controller has a h/w bug due to which it can try to send SOFs |
| 1321 | * (start of frames) during port resume resulting in phy lockup. HSIC hw |
| 1322 | * controller in MSM clears FPR bit after driving the resume signal for |
| 1323 | * 20ms. Workaround is to stop SOFs before driving resume and then start |
| 1324 | * sending SOFs immediately. Need to send SOFs within 3ms of resume |
| 1325 | * completion otherwise peripheral may enter undefined state. As |
| 1326 | * usleep_range does not gurantee exact sleep time, GPTimer is used to |
| 1327 | * to time the resume sequence. If driver exceeds allowable time SOFs, |
| 1328 | * repeat the resume process. |
| 1329 | */ |
| 1330 | if (ehci->resume_sof_bug && resume_needed) { |
| 1331 | if (!tight_resume) { |
| 1332 | mehci->resume_again = 0; |
Pavankumar Kondeti | c4f817d | 2013-01-29 19:08:12 +0530 | [diff] [blame] | 1333 | ehci_writel(ehci, GPT_LD(RESUME_SIGNAL_TIME_USEC - 1), |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1334 | &mehci->timer->gptimer0_ld); |
| 1335 | ehci_writel(ehci, GPT_RESET | GPT_RUN, |
| 1336 | &mehci->timer->gptimer0_ctrl); |
| 1337 | ehci_writel(ehci, INTR_MASK | STS_GPTIMER0_INTERRUPT, |
| 1338 | &ehci->regs->intr_enable); |
| 1339 | |
Pavankumar Kondeti | c4f817d | 2013-01-29 19:08:12 +0530 | [diff] [blame] | 1340 | ehci_writel(ehci, GPT_LD( |
| 1341 | RESUME_SIGNAL_TIME_SOF_USEC - 1), |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1342 | &mehci->timer->gptimer1_ld); |
| 1343 | ehci_writel(ehci, GPT_RESET | GPT_RUN, |
| 1344 | &mehci->timer->gptimer1_ctrl); |
| 1345 | |
| 1346 | spin_unlock_irq(&ehci->lock); |
| 1347 | wait_for_completion(&mehci->gpt0_completion); |
| 1348 | spin_lock_irq(&ehci->lock); |
| 1349 | } else { |
| 1350 | dbg_log_event(NULL, "FPR: Tightloop", 0); |
| 1351 | /* do the resume in a tight loop */ |
| 1352 | handshake(ehci, &ehci->regs->port_status[0], |
| 1353 | PORT_RESUME, 0, 22 * 1000); |
| 1354 | ehci_writel(ehci, ehci_readl(ehci, |
| 1355 | &ehci->regs->command) | CMD_RUN, |
| 1356 | &ehci->regs->command); |
| 1357 | } |
| 1358 | |
| 1359 | if (mehci->resume_again) { |
| 1360 | int temp; |
| 1361 | |
| 1362 | dbg_log_event(NULL, "FPR: Re-Resume", retry_cnt); |
| 1363 | pr_info("FPR: retry count: %d\n", retry_cnt); |
| 1364 | spin_unlock_irq(&ehci->lock); |
| 1365 | temp = ehci_readl(ehci, &ehci->regs->port_status[0]); |
| 1366 | temp &= ~PORT_RWC_BITS; |
| 1367 | temp |= PORT_SUSPEND; |
| 1368 | ehci_writel(ehci, temp, &ehci->regs->port_status[0]); |
| 1369 | /* Keep the bus idle for 5ms so that peripheral |
| 1370 | * can detect and initiate suspend |
| 1371 | */ |
| 1372 | usleep_range(5000, 5000); |
| 1373 | dbg_log_event(NULL, |
| 1374 | "FPR: RResume", |
| 1375 | ehci_readl(ehci, &ehci->regs->port_status[0])); |
| 1376 | spin_lock_irq(&ehci->lock); |
| 1377 | mehci->resume_again = 0; |
| 1378 | retry_cnt++; |
| 1379 | goto resume_again; |
| 1380 | } |
| 1381 | } |
| 1382 | |
| 1383 | dbg_log_event(NULL, "FPR: RT-Done", 0); |
| 1384 | mehci->resume_status = 1; |
Pavankumar Kondeti | 4152d80 | 2013-07-22 15:32:17 +0530 | [diff] [blame] | 1385 | exit: |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1386 | spin_unlock_irq(&ehci->lock); |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1387 | complete(&mehci->rt_completion); |
Pavankumar Kondeti | 4152d80 | 2013-07-22 15:32:17 +0530 | [diff] [blame] | 1388 | if (next_latency) |
| 1389 | pm_qos_update_request(&mehci->pm_qos_req_dma, next_latency); |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1390 | |
| 1391 | return 0; |
| 1392 | } |
| 1393 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1394 | static int ehci_hsic_bus_resume(struct usb_hcd *hcd) |
| 1395 | { |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1396 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1397 | struct ehci_hcd *ehci = hcd_to_ehci(hcd); |
| 1398 | u32 temp; |
| 1399 | struct task_struct *resume_thread = NULL; |
Vamsi Krishna | bef9183 | 2013-03-11 14:10:20 -0700 | [diff] [blame] | 1400 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
| 1401 | |
| 1402 | if (pdata->resume_gpio) |
| 1403 | gpio_direction_output(pdata->resume_gpio, 1); |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1404 | |
Manu Gautam | 3c59839 | 2013-03-22 16:59:10 +0530 | [diff] [blame] | 1405 | if (!mehci->ehci.resume_sof_bug) { |
| 1406 | ehci_bus_resume(hcd); |
| 1407 | } else { |
| 1408 | mehci->resume_status = 0; |
| 1409 | resume_thread = kthread_run(msm_hsic_resume_thread, |
| 1410 | mehci, "hsic_resume_thread"); |
| 1411 | if (IS_ERR(resume_thread)) { |
| 1412 | pr_err("Error creating resume thread:%lu\n", |
| 1413 | PTR_ERR(resume_thread)); |
| 1414 | return PTR_ERR(resume_thread); |
| 1415 | } |
| 1416 | |
| 1417 | wait_for_completion(&mehci->rt_completion); |
| 1418 | |
| 1419 | if (mehci->resume_status < 0) |
| 1420 | return mehci->resume_status; |
| 1421 | |
| 1422 | dbg_log_event(NULL, "FPR: Wokeup", 0); |
| 1423 | spin_lock_irq(&ehci->lock); |
| 1424 | (void) ehci_readl(ehci, &ehci->regs->command); |
| 1425 | |
| 1426 | temp = 0; |
| 1427 | if (ehci->async->qh_next.qh) |
| 1428 | temp |= CMD_ASE; |
| 1429 | if (ehci->periodic_sched) |
| 1430 | temp |= CMD_PSE; |
| 1431 | if (temp) { |
| 1432 | ehci->command |= temp; |
| 1433 | ehci_writel(ehci, ehci->command, &ehci->regs->command); |
| 1434 | } |
| 1435 | |
| 1436 | ehci->next_statechange = jiffies + msecs_to_jiffies(5); |
| 1437 | hcd->state = HC_STATE_RUNNING; |
| 1438 | ehci->rh_state = EHCI_RH_RUNNING; |
| 1439 | ehci->command |= CMD_RUN; |
| 1440 | |
| 1441 | /* Now we can safely re-enable irqs */ |
| 1442 | ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable); |
| 1443 | |
| 1444 | spin_unlock_irq(&ehci->lock); |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1445 | } |
| 1446 | |
Vamsi Krishna | bef9183 | 2013-03-11 14:10:20 -0700 | [diff] [blame] | 1447 | if (pdata->resume_gpio) |
| 1448 | gpio_direction_output(pdata->resume_gpio, 0); |
| 1449 | |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 1450 | return 0; |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1451 | } |
| 1452 | |
Jack Pham | c0d4173 | 2012-09-28 17:45:38 -0700 | [diff] [blame] | 1453 | #else |
| 1454 | |
| 1455 | #define ehci_hsic_bus_suspend NULL |
| 1456 | #define ehci_hsic_bus_resume NULL |
| 1457 | |
| 1458 | #endif /* CONFIG_PM */ |
| 1459 | |
Hemant Kumar | a3d4a6e | 2012-10-16 17:57:08 -0700 | [diff] [blame] | 1460 | static void ehci_msm_set_autosuspend_delay(struct usb_device *dev) |
| 1461 | { |
| 1462 | if (!dev->parent) /*for root hub no delay*/ |
| 1463 | pm_runtime_set_autosuspend_delay(&dev->dev, 0); |
| 1464 | else |
| 1465 | pm_runtime_set_autosuspend_delay(&dev->dev, 200); |
| 1466 | } |
| 1467 | |
Shimrit Malichi | 82d7cbc | 2013-03-12 15:36:54 +0200 | [diff] [blame] | 1468 | static int ehci_msm_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, |
| 1469 | gfp_t mem_flags) |
| 1470 | { |
| 1471 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 1472 | struct usb_host_bam_type *usb_host_bam = |
| 1473 | (struct usb_host_bam_type *)urb->priv_data; |
| 1474 | |
| 1475 | if (usb_host_bam && mehci && mehci->enable_hbm) |
| 1476 | return hbm_urb_enqueue(hcd, urb, mem_flags); |
| 1477 | return ehci_urb_enqueue(hcd, urb, mem_flags); |
| 1478 | } |
| 1479 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1480 | static struct hc_driver msm_hsic_driver = { |
| 1481 | .description = hcd_name, |
| 1482 | .product_desc = "Qualcomm EHCI Host Controller using HSIC", |
| 1483 | .hcd_priv_size = sizeof(struct msm_hsic_hcd), |
| 1484 | |
| 1485 | /* |
| 1486 | * generic hardware linkage |
| 1487 | */ |
| 1488 | .irq = msm_hsic_irq, |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 1489 | .flags = HCD_USB2 | HCD_MEMORY | HCD_OLD_ENUM, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1490 | |
| 1491 | .reset = ehci_hsic_reset, |
| 1492 | .start = ehci_run, |
| 1493 | |
| 1494 | .stop = ehci_stop, |
| 1495 | .shutdown = ehci_shutdown, |
| 1496 | |
| 1497 | /* |
| 1498 | * managing i/o requests and associated device resources |
| 1499 | */ |
Shimrit Malichi | 82d7cbc | 2013-03-12 15:36:54 +0200 | [diff] [blame] | 1500 | .urb_enqueue = ehci_msm_urb_enqueue, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1501 | .urb_dequeue = ehci_urb_dequeue, |
| 1502 | .endpoint_disable = ehci_endpoint_disable, |
| 1503 | .endpoint_reset = ehci_endpoint_reset, |
| 1504 | .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete, |
| 1505 | |
| 1506 | /* |
| 1507 | * scheduling support |
| 1508 | */ |
| 1509 | .get_frame_number = ehci_get_frame, |
| 1510 | |
| 1511 | /* |
| 1512 | * root hub support |
| 1513 | */ |
| 1514 | .hub_status_data = ehci_hub_status_data, |
| 1515 | .hub_control = ehci_hub_control, |
| 1516 | .relinquish_port = ehci_relinquish_port, |
| 1517 | .port_handed_over = ehci_port_handed_over, |
| 1518 | |
| 1519 | /* |
| 1520 | * PM support |
| 1521 | */ |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1522 | .bus_suspend = ehci_hsic_bus_suspend, |
| 1523 | .bus_resume = ehci_hsic_bus_resume, |
| 1524 | |
Hemant Kumar | 4d50a43 | 2012-08-15 09:06:35 -0700 | [diff] [blame] | 1525 | .log_urb = dbg_log_event, |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 1526 | .dump_regs = dump_hsic_regs, |
Vamsi Krishna | 8e6edcb | 2012-06-20 18:08:50 -0700 | [diff] [blame] | 1527 | |
Hemant Kumar | a3d4a6e | 2012-10-16 17:57:08 -0700 | [diff] [blame] | 1528 | .set_autosuspend_delay = ehci_msm_set_autosuspend_delay, |
Pavankumar Kondeti | 2372049 | 2013-01-29 14:41:58 +0530 | [diff] [blame] | 1529 | .reset_sof_bug_handler = ehci_hsic_reset_sof_bug_handler, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1530 | }; |
| 1531 | |
| 1532 | static int msm_hsic_init_clocks(struct msm_hsic_hcd *mehci, u32 init) |
| 1533 | { |
| 1534 | int ret = 0; |
| 1535 | |
| 1536 | if (!init) |
| 1537 | goto put_clocks; |
| 1538 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 1539 | /*core_clk is required for LINK protocol engine |
| 1540 | *clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1541 | mehci->core_clk = clk_get(mehci->dev, "core_clk"); |
| 1542 | if (IS_ERR(mehci->core_clk)) { |
| 1543 | dev_err(mehci->dev, "failed to get core_clk\n"); |
| 1544 | ret = PTR_ERR(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1545 | return ret; |
| 1546 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1547 | |
Ofir Cohen | 07944aa | 2012-12-23 13:41:57 +0200 | [diff] [blame] | 1548 | /* alt_core_clk is for LINK to be used during PHY RESET in |
| 1549 | * targets on which link does NOT use asynchronous reset methodology. |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 1550 | * clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1551 | mehci->alt_core_clk = clk_get(mehci->dev, "alt_core_clk"); |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1552 | if (IS_ERR(mehci->alt_core_clk)) |
| 1553 | dev_dbg(mehci->dev, "failed to get alt_core_clk\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1554 | |
Lena Salman | 8c8ba38 | 2012-02-14 15:59:31 +0200 | [diff] [blame] | 1555 | /* phy_clk is required for HSIC PHY operation |
| 1556 | * clock rate appropriately set by target specific clock driver */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1557 | mehci->phy_clk = clk_get(mehci->dev, "phy_clk"); |
| 1558 | if (IS_ERR(mehci->phy_clk)) { |
| 1559 | dev_err(mehci->dev, "failed to get phy_clk\n"); |
| 1560 | ret = PTR_ERR(mehci->phy_clk); |
| 1561 | goto put_alt_core_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1562 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1563 | |
| 1564 | /* 10MHz cal_clk is required for calibration of I/O pads */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1565 | mehci->cal_clk = clk_get(mehci->dev, "cal_clk"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1566 | if (IS_ERR(mehci->cal_clk)) { |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1567 | dev_err(mehci->dev, "failed to get cal_clk\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1568 | ret = PTR_ERR(mehci->cal_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1569 | goto put_phy_clk; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1570 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1571 | |
| 1572 | /* ahb_clk is required for data transfers */ |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1573 | mehci->ahb_clk = clk_get(mehci->dev, "iface_clk"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1574 | if (IS_ERR(mehci->ahb_clk)) { |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1575 | dev_err(mehci->dev, "failed to get iface_clk\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1576 | ret = PTR_ERR(mehci->ahb_clk); |
| 1577 | goto put_cal_clk; |
| 1578 | } |
| 1579 | |
Ido Shayevitz | 5dfbb13 | 2013-04-18 13:22:07 +0300 | [diff] [blame] | 1580 | /* |
| 1581 | * Inactivity_clk is required for hsic bam inactivity timer. |
| 1582 | * This clock is not compulsory and is defined in clock lookup |
| 1583 | * only for targets that need to use the inactivity timer feature. |
| 1584 | */ |
| 1585 | mehci->inactivity_clk = clk_get(mehci->dev, "inactivity_clk"); |
| 1586 | if (IS_ERR(mehci->inactivity_clk)) |
| 1587 | dev_dbg(mehci->dev, "failed to get inactivity_clk\n"); |
| 1588 | |
Manu Gautam | 28b1bac | 2012-01-30 16:43:06 +0530 | [diff] [blame] | 1589 | clk_prepare_enable(mehci->core_clk); |
| 1590 | clk_prepare_enable(mehci->phy_clk); |
| 1591 | clk_prepare_enable(mehci->cal_clk); |
| 1592 | clk_prepare_enable(mehci->ahb_clk); |
Ido Shayevitz | 5dfbb13 | 2013-04-18 13:22:07 +0300 | [diff] [blame] | 1593 | if (!IS_ERR(mehci->inactivity_clk)) |
| 1594 | clk_prepare_enable(mehci->inactivity_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1595 | |
| 1596 | return 0; |
| 1597 | |
| 1598 | put_clocks: |
Jack Pham | fd193eb | 2012-02-22 15:38:08 -0800 | [diff] [blame] | 1599 | if (!atomic_read(&mehci->in_lpm)) { |
| 1600 | clk_disable_unprepare(mehci->core_clk); |
| 1601 | clk_disable_unprepare(mehci->phy_clk); |
| 1602 | clk_disable_unprepare(mehci->cal_clk); |
| 1603 | clk_disable_unprepare(mehci->ahb_clk); |
Ido Shayevitz | 5dfbb13 | 2013-04-18 13:22:07 +0300 | [diff] [blame] | 1604 | if (!IS_ERR(mehci->inactivity_clk)) |
| 1605 | clk_disable_unprepare(mehci->inactivity_clk); |
Jack Pham | fd193eb | 2012-02-22 15:38:08 -0800 | [diff] [blame] | 1606 | } |
Ido Shayevitz | 5dfbb13 | 2013-04-18 13:22:07 +0300 | [diff] [blame] | 1607 | if (!IS_ERR(mehci->inactivity_clk)) |
| 1608 | clk_put(mehci->inactivity_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1609 | clk_put(mehci->ahb_clk); |
| 1610 | put_cal_clk: |
| 1611 | clk_put(mehci->cal_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1612 | put_phy_clk: |
| 1613 | clk_put(mehci->phy_clk); |
| 1614 | put_alt_core_clk: |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1615 | if (!IS_ERR(mehci->alt_core_clk)) |
| 1616 | clk_put(mehci->alt_core_clk); |
Manu Gautam | 5143b25 | 2012-01-05 19:25:23 -0800 | [diff] [blame] | 1617 | clk_put(mehci->core_clk); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1618 | |
| 1619 | return ret; |
| 1620 | } |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 1621 | static irqreturn_t hsic_peripheral_status_change(int irq, void *dev_id) |
| 1622 | { |
| 1623 | struct msm_hsic_hcd *mehci = dev_id; |
| 1624 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1625 | 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] | 1626 | |
| 1627 | if (mehci) |
| 1628 | msm_hsic_config_gpios(mehci, 0); |
| 1629 | |
| 1630 | return IRQ_HANDLED; |
| 1631 | } |
| 1632 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1633 | static irqreturn_t msm_hsic_wakeup_irq(int irq, void *data) |
| 1634 | { |
| 1635 | struct msm_hsic_hcd *mehci = data; |
Pavankumar Kondeti | 968cf27 | 2012-09-27 12:04:12 +0530 | [diff] [blame] | 1636 | int ret; |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1637 | |
Manu Gautam | 3fb60ca | 2013-02-13 18:33:33 +0530 | [diff] [blame] | 1638 | if (irq == mehci->async_irq) { |
| 1639 | mehci->async_int_cnt++; |
| 1640 | dbg_log_event(NULL, "Remote Wakeup (ASYNC) IRQ", |
| 1641 | mehci->async_int_cnt); |
| 1642 | } else { |
| 1643 | mehci->wakeup_int_cnt++; |
| 1644 | dbg_log_event(NULL, "Remote Wakeup IRQ", mehci->wakeup_int_cnt); |
| 1645 | } |
| 1646 | dev_dbg(mehci->dev, "%s: hsic remote wakeup interrupt %d cnt: %u, %u\n", |
| 1647 | __func__, irq, mehci->wakeup_int_cnt, mehci->async_int_cnt); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1648 | |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 1649 | wake_lock(&mehci->wlock); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1650 | |
Manu Gautam | 3fb60ca | 2013-02-13 18:33:33 +0530 | [diff] [blame] | 1651 | if (mehci->wakeup_irq) { |
| 1652 | spin_lock(&mehci->wakeup_lock); |
| 1653 | if (mehci->wakeup_irq_enabled) { |
| 1654 | mehci->wakeup_irq_enabled = 0; |
| 1655 | disable_irq_wake(irq); |
| 1656 | disable_irq_nosync(irq); |
| 1657 | } |
| 1658 | spin_unlock(&mehci->wakeup_lock); |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 1659 | } |
| 1660 | |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 1661 | if (!atomic_read(&mehci->pm_usage_cnt)) { |
Pavankumar Kondeti | 968cf27 | 2012-09-27 12:04:12 +0530 | [diff] [blame] | 1662 | ret = pm_runtime_get(mehci->dev); |
| 1663 | /* |
| 1664 | * HSIC runtime resume can race with us. |
| 1665 | * if we are active (ret == 1) or resuming |
| 1666 | * (ret == -EINPROGRESS), decrement the |
| 1667 | * PM usage counter before returning. |
| 1668 | */ |
| 1669 | if ((ret == 1) || (ret == -EINPROGRESS)) |
| 1670 | pm_runtime_put_noidle(mehci->dev); |
| 1671 | else |
| 1672 | atomic_set(&mehci->pm_usage_cnt, 1); |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 1673 | } |
| 1674 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 1675 | return IRQ_HANDLED; |
| 1676 | } |
| 1677 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1678 | static int ehci_hsic_msm_bus_show(struct seq_file *s, void *unused) |
| 1679 | { |
| 1680 | if (debug_bus_voting_enabled) |
| 1681 | seq_printf(s, "enabled\n"); |
| 1682 | else |
| 1683 | seq_printf(s, "disabled\n"); |
| 1684 | |
| 1685 | return 0; |
| 1686 | } |
| 1687 | |
| 1688 | static int ehci_hsic_msm_bus_open(struct inode *inode, struct file *file) |
| 1689 | { |
| 1690 | return single_open(file, ehci_hsic_msm_bus_show, inode->i_private); |
| 1691 | } |
| 1692 | |
| 1693 | static ssize_t ehci_hsic_msm_bus_write(struct file *file, |
| 1694 | const char __user *ubuf, size_t count, loff_t *ppos) |
| 1695 | { |
| 1696 | char buf[8]; |
| 1697 | int ret; |
| 1698 | struct seq_file *s = file->private_data; |
| 1699 | struct msm_hsic_hcd *mehci = s->private; |
| 1700 | |
| 1701 | memset(buf, 0x00, sizeof(buf)); |
| 1702 | |
| 1703 | if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 1704 | return -EFAULT; |
| 1705 | |
| 1706 | if (!strncmp(buf, "enable", 6)) { |
| 1707 | /* Do not vote here. Let hsic driver decide when to vote */ |
| 1708 | debug_bus_voting_enabled = true; |
| 1709 | } else { |
| 1710 | debug_bus_voting_enabled = false; |
| 1711 | if (mehci->bus_perf_client) { |
| 1712 | ret = msm_bus_scale_client_update_request( |
| 1713 | mehci->bus_perf_client, 0); |
| 1714 | if (ret) |
| 1715 | dev_err(mehci->dev, "%s: Failed to devote " |
| 1716 | "for bus bw %d\n", __func__, ret); |
| 1717 | } |
| 1718 | } |
| 1719 | |
| 1720 | return count; |
| 1721 | } |
| 1722 | |
| 1723 | const struct file_operations ehci_hsic_msm_bus_fops = { |
| 1724 | .open = ehci_hsic_msm_bus_open, |
| 1725 | .read = seq_read, |
| 1726 | .write = ehci_hsic_msm_bus_write, |
| 1727 | .llseek = seq_lseek, |
| 1728 | .release = single_release, |
| 1729 | }; |
| 1730 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1731 | static int ehci_hsic_msm_wakeup_cnt_show(struct seq_file *s, void *unused) |
| 1732 | { |
| 1733 | struct msm_hsic_hcd *mehci = s->private; |
| 1734 | |
| 1735 | seq_printf(s, "%u\n", mehci->wakeup_int_cnt); |
| 1736 | |
| 1737 | return 0; |
| 1738 | } |
| 1739 | |
| 1740 | static int ehci_hsic_msm_wakeup_cnt_open(struct inode *inode, struct file *f) |
| 1741 | { |
| 1742 | return single_open(f, ehci_hsic_msm_wakeup_cnt_show, inode->i_private); |
| 1743 | } |
| 1744 | |
| 1745 | const struct file_operations ehci_hsic_msm_wakeup_cnt_fops = { |
| 1746 | .open = ehci_hsic_msm_wakeup_cnt_open, |
| 1747 | .read = seq_read, |
| 1748 | .llseek = seq_lseek, |
| 1749 | .release = single_release, |
| 1750 | }; |
| 1751 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1752 | static int ehci_hsic_msm_data_events_show(struct seq_file *s, void *unused) |
| 1753 | { |
| 1754 | unsigned long flags; |
| 1755 | unsigned i; |
| 1756 | |
| 1757 | read_lock_irqsave(&dbg_hsic_data.lck, flags); |
| 1758 | |
| 1759 | i = dbg_hsic_data.idx; |
| 1760 | for (dbg_inc(&i); i != dbg_hsic_data.idx; dbg_inc(&i)) { |
| 1761 | if (!strnlen(dbg_hsic_data.buf[i], DBG_MSG_LEN)) |
| 1762 | continue; |
| 1763 | seq_printf(s, "%s\n", dbg_hsic_data.buf[i]); |
| 1764 | } |
| 1765 | |
| 1766 | read_unlock_irqrestore(&dbg_hsic_data.lck, flags); |
| 1767 | |
| 1768 | return 0; |
| 1769 | } |
| 1770 | |
| 1771 | static int ehci_hsic_msm_data_events_open(struct inode *inode, struct file *f) |
| 1772 | { |
| 1773 | return single_open(f, ehci_hsic_msm_data_events_show, inode->i_private); |
| 1774 | } |
| 1775 | |
| 1776 | const struct file_operations ehci_hsic_msm_dbg_data_fops = { |
| 1777 | .open = ehci_hsic_msm_data_events_open, |
| 1778 | .read = seq_read, |
| 1779 | .llseek = seq_lseek, |
| 1780 | .release = single_release, |
| 1781 | }; |
| 1782 | |
| 1783 | static int ehci_hsic_msm_ctrl_events_show(struct seq_file *s, void *unused) |
| 1784 | { |
| 1785 | unsigned long flags; |
| 1786 | unsigned i; |
| 1787 | |
| 1788 | read_lock_irqsave(&dbg_hsic_ctrl.lck, flags); |
| 1789 | |
| 1790 | i = dbg_hsic_ctrl.idx; |
| 1791 | for (dbg_inc(&i); i != dbg_hsic_ctrl.idx; dbg_inc(&i)) { |
| 1792 | if (!strnlen(dbg_hsic_ctrl.buf[i], DBG_MSG_LEN)) |
| 1793 | continue; |
| 1794 | seq_printf(s, "%s\n", dbg_hsic_ctrl.buf[i]); |
| 1795 | } |
| 1796 | |
| 1797 | read_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags); |
| 1798 | |
| 1799 | return 0; |
| 1800 | } |
| 1801 | |
| 1802 | static int ehci_hsic_msm_ctrl_events_open(struct inode *inode, struct file *f) |
| 1803 | { |
| 1804 | return single_open(f, ehci_hsic_msm_ctrl_events_show, inode->i_private); |
| 1805 | } |
| 1806 | |
| 1807 | const struct file_operations ehci_hsic_msm_dbg_ctrl_fops = { |
| 1808 | .open = ehci_hsic_msm_ctrl_events_open, |
| 1809 | .read = seq_read, |
| 1810 | .llseek = seq_lseek, |
| 1811 | .release = single_release, |
| 1812 | }; |
| 1813 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1814 | static struct dentry *ehci_hsic_msm_dbg_root; |
| 1815 | static int ehci_hsic_msm_debugfs_init(struct msm_hsic_hcd *mehci) |
| 1816 | { |
| 1817 | struct dentry *ehci_hsic_msm_dentry; |
| 1818 | |
| 1819 | ehci_hsic_msm_dbg_root = debugfs_create_dir("ehci_hsic_msm_dbg", NULL); |
| 1820 | |
| 1821 | if (!ehci_hsic_msm_dbg_root || IS_ERR(ehci_hsic_msm_dbg_root)) |
| 1822 | return -ENODEV; |
| 1823 | |
| 1824 | ehci_hsic_msm_dentry = debugfs_create_file("bus_voting", |
| 1825 | S_IRUGO | S_IWUSR, |
| 1826 | ehci_hsic_msm_dbg_root, mehci, |
| 1827 | &ehci_hsic_msm_bus_fops); |
| 1828 | |
| 1829 | if (!ehci_hsic_msm_dentry) { |
| 1830 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1831 | return -ENODEV; |
| 1832 | } |
| 1833 | |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 1834 | ehci_hsic_msm_dentry = debugfs_create_file("wakeup_cnt", |
| 1835 | S_IRUGO, |
| 1836 | ehci_hsic_msm_dbg_root, mehci, |
| 1837 | &ehci_hsic_msm_wakeup_cnt_fops); |
| 1838 | |
| 1839 | if (!ehci_hsic_msm_dentry) { |
| 1840 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1841 | return -ENODEV; |
| 1842 | } |
| 1843 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 1844 | ehci_hsic_msm_dentry = debugfs_create_file("show_ctrl_events", |
| 1845 | S_IRUGO, |
| 1846 | ehci_hsic_msm_dbg_root, mehci, |
| 1847 | &ehci_hsic_msm_dbg_ctrl_fops); |
| 1848 | |
| 1849 | if (!ehci_hsic_msm_dentry) { |
| 1850 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1851 | return -ENODEV; |
| 1852 | } |
| 1853 | |
| 1854 | ehci_hsic_msm_dentry = debugfs_create_file("show_data_events", |
| 1855 | S_IRUGO, |
| 1856 | ehci_hsic_msm_dbg_root, mehci, |
| 1857 | &ehci_hsic_msm_dbg_data_fops); |
| 1858 | |
| 1859 | if (!ehci_hsic_msm_dentry) { |
| 1860 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1861 | return -ENODEV; |
| 1862 | } |
| 1863 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 1864 | return 0; |
| 1865 | } |
| 1866 | |
| 1867 | static void ehci_hsic_msm_debugfs_cleanup(void) |
| 1868 | { |
| 1869 | debugfs_remove_recursive(ehci_hsic_msm_dbg_root); |
| 1870 | } |
| 1871 | |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1872 | struct msm_hsic_host_platform_data *msm_hsic_dt_to_pdata( |
| 1873 | struct platform_device *pdev) |
| 1874 | { |
| 1875 | struct device_node *node = pdev->dev.of_node; |
| 1876 | struct msm_hsic_host_platform_data *pdata; |
Ido Shayevitz | ca5dc49 | 2013-01-09 14:49:59 +0200 | [diff] [blame] | 1877 | int res_gpio; |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1878 | |
| 1879 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 1880 | if (!pdata) { |
| 1881 | dev_err(&pdev->dev, "unable to allocate platform data\n"); |
| 1882 | return NULL; |
| 1883 | } |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1884 | |
Ido Shayevitz | ca5dc49 | 2013-01-09 14:49:59 +0200 | [diff] [blame] | 1885 | res_gpio = of_get_named_gpio(node, "hsic,strobe-gpio", 0); |
| 1886 | if (res_gpio < 0) |
| 1887 | res_gpio = 0; |
| 1888 | pdata->strobe = res_gpio; |
| 1889 | |
| 1890 | res_gpio = of_get_named_gpio(node, "hsic,data-gpio", 0); |
| 1891 | if (res_gpio < 0) |
| 1892 | res_gpio = 0; |
| 1893 | pdata->data = res_gpio; |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1894 | |
Vamsi Krishna | bef9183 | 2013-03-11 14:10:20 -0700 | [diff] [blame] | 1895 | res_gpio = of_get_named_gpio(node, "hsic,resume-gpio", 0); |
| 1896 | if (res_gpio < 0) |
| 1897 | res_gpio = 0; |
| 1898 | pdata->resume_gpio = res_gpio; |
| 1899 | |
Manu Gautam | 3c59839 | 2013-03-22 16:59:10 +0530 | [diff] [blame] | 1900 | pdata->phy_sof_workaround = of_property_read_bool(node, |
| 1901 | "qcom,phy-sof-workaround"); |
Manu Gautam | caa99d4 | 2013-07-25 12:01:02 +0530 | [diff] [blame] | 1902 | pdata->phy_susp_sof_workaround = of_property_read_bool(node, |
| 1903 | "qcom,phy-susp-sof-workaround"); |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1904 | pdata->ignore_cal_pad_config = of_property_read_bool(node, |
| 1905 | "hsic,ignore-cal-pad-config"); |
| 1906 | of_property_read_u32(node, "hsic,strobe-pad-offset", |
| 1907 | &pdata->strobe_pad_offset); |
| 1908 | of_property_read_u32(node, "hsic,data-pad-offset", |
| 1909 | &pdata->data_pad_offset); |
Ming-yi Lin | 9eed5e0 | 2013-07-18 14:06:24 +0800 | [diff] [blame] | 1910 | of_property_read_u32(node, "hsic,reset-delay", |
| 1911 | &pdata->reset_delay); |
Vamsi Krishna | faee5da | 2013-06-14 12:41:10 -0700 | [diff] [blame] | 1912 | of_property_read_u32(node, "hsic,log2-itc", |
| 1913 | &pdata->log2_irq_thresh); |
| 1914 | if (pdata->log2_irq_thresh > 6) |
| 1915 | pdata->log2_irq_thresh = 0; |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1916 | |
Ido Shayevitz | 95c4688 | 2013-01-20 13:47:46 +0200 | [diff] [blame] | 1917 | pdata->bus_scale_table = msm_bus_cl_get_pdata(pdev); |
| 1918 | |
Shimrit Malichi | 36a0c85 | 2013-03-10 11:39:10 +0200 | [diff] [blame] | 1919 | pdata->pool_64_bit_align = of_property_read_bool(node, |
| 1920 | "qcom,pool-64-bit-align"); |
Shimrit Malichi | 82d7cbc | 2013-03-12 15:36:54 +0200 | [diff] [blame] | 1921 | pdata->enable_hbm = of_property_read_bool(node, |
| 1922 | "qcom,enable-hbm"); |
Shimrit Malichi | 08f0734 | 2013-04-24 13:09:12 +0300 | [diff] [blame] | 1923 | pdata->disable_park_mode = (of_property_read_bool(node, |
| 1924 | "qcom,disable-park-mode")); |
Ido Shayevitz | aa165c5 | 2013-05-12 16:01:28 +0200 | [diff] [blame] | 1925 | pdata->consider_ipa_handshake = (of_property_read_bool(node, |
| 1926 | "hsic,consider-ipa-handshake")); |
Amit Blay | 1dfbbcc | 2013-05-26 17:33:13 +0300 | [diff] [blame] | 1927 | pdata->ahb_async_bridge_bypass = of_property_read_bool(node, |
| 1928 | "qcom,ahb-async-bridge-bypass"); |
Vamsi Krishna | 4f66c2c | 2013-06-21 11:33:59 -0700 | [diff] [blame] | 1929 | pdata->disable_cerr = of_property_read_bool(node, |
| 1930 | "hsic,disable-cerr"); |
Shimrit Malichi | 36a0c85 | 2013-03-10 11:39:10 +0200 | [diff] [blame] | 1931 | |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1932 | return pdata; |
| 1933 | } |
| 1934 | |
| 1935 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1936 | static int __devinit ehci_hsic_msm_probe(struct platform_device *pdev) |
| 1937 | { |
| 1938 | struct usb_hcd *hcd; |
| 1939 | struct resource *res; |
| 1940 | struct msm_hsic_hcd *mehci; |
Vijayavardhan Vennapusa | 2b592824f | 2011-11-02 19:51:32 +0530 | [diff] [blame] | 1941 | struct msm_hsic_host_platform_data *pdata; |
Manu Gautam | 1656279 | 2013-03-13 07:04:11 +0530 | [diff] [blame] | 1942 | unsigned long wakeup_irq_flags = 0; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1943 | int ret; |
| 1944 | |
| 1945 | dev_dbg(&pdev->dev, "ehci_msm-hsic probe\n"); |
| 1946 | |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1947 | if (pdev->dev.of_node) { |
| 1948 | dev_dbg(&pdev->dev, "device tree enabled\n"); |
| 1949 | pdev->dev.platform_data = msm_hsic_dt_to_pdata(pdev); |
| 1950 | dev_set_name(&pdev->dev, ehci_msm_hsic_driver.driver.name); |
Manu Gautam | 1656279 | 2013-03-13 07:04:11 +0530 | [diff] [blame] | 1951 | } else { |
| 1952 | /* explicitly pass wakeup_irq flag for !DT */ |
| 1953 | wakeup_irq_flags = IRQF_TRIGGER_HIGH; |
Manu Gautam | 863b7413 | 2012-11-21 14:30:04 +0530 | [diff] [blame] | 1954 | } |
| 1955 | if (!pdev->dev.platform_data) |
| 1956 | dev_dbg(&pdev->dev, "No platform data given\n"); |
| 1957 | |
Ofir Cohen | 4cc5537 | 2012-11-20 11:17:24 +0200 | [diff] [blame] | 1958 | if (!pdev->dev.dma_mask) |
| 1959 | pdev->dev.dma_mask = &ehci_msm_hsic_dma_mask; |
| 1960 | if (!pdev->dev.coherent_dma_mask) |
| 1961 | pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32); |
| 1962 | |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 1963 | /* After parent device's probe is executed, it will be put in suspend |
| 1964 | * mode. When child device's probe is called, driver core is not |
| 1965 | * resuming parent device due to which parent will be in suspend even |
| 1966 | * though child is active. Hence resume the parent device explicitly. |
| 1967 | */ |
| 1968 | if (pdev->dev.parent) |
| 1969 | pm_runtime_get_sync(pdev->dev.parent); |
| 1970 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1971 | hcd = usb_create_hcd(&msm_hsic_driver, &pdev->dev, |
| 1972 | dev_name(&pdev->dev)); |
| 1973 | if (!hcd) { |
| 1974 | dev_err(&pdev->dev, "Unable to create HCD\n"); |
| 1975 | return -ENOMEM; |
| 1976 | } |
| 1977 | |
Pavankumar Kondeti | 6f199aa | 2012-09-18 17:52:51 +0530 | [diff] [blame] | 1978 | hcd_to_bus(hcd)->skip_resume = true; |
| 1979 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 1980 | hcd->irq = platform_get_irq(pdev, 0); |
| 1981 | if (hcd->irq < 0) { |
| 1982 | dev_err(&pdev->dev, "Unable to get IRQ resource\n"); |
| 1983 | ret = hcd->irq; |
| 1984 | goto put_hcd; |
| 1985 | } |
| 1986 | |
| 1987 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1988 | if (!res) { |
| 1989 | dev_err(&pdev->dev, "Unable to get memory resource\n"); |
| 1990 | ret = -ENODEV; |
| 1991 | goto put_hcd; |
| 1992 | } |
| 1993 | |
| 1994 | hcd->rsrc_start = res->start; |
| 1995 | hcd->rsrc_len = resource_size(res); |
| 1996 | hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); |
| 1997 | if (!hcd->regs) { |
| 1998 | dev_err(&pdev->dev, "ioremap failed\n"); |
| 1999 | ret = -ENOMEM; |
| 2000 | goto put_hcd; |
| 2001 | } |
| 2002 | |
| 2003 | mehci = hcd_to_hsic(hcd); |
| 2004 | mehci->dev = &pdev->dev; |
Hemant Kumar | 30d361c | 2012-08-20 14:44:40 -0700 | [diff] [blame] | 2005 | pdata = mehci->dev->platform_data; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2006 | |
Hemant Kumar | d343c01 | 2012-09-06 19:57:14 -0700 | [diff] [blame] | 2007 | spin_lock_init(&mehci->wakeup_lock); |
| 2008 | |
Manu Gautam | 3c59839 | 2013-03-22 16:59:10 +0530 | [diff] [blame] | 2009 | if (pdata->phy_sof_workaround) { |
Manu Gautam | caa99d4 | 2013-07-25 12:01:02 +0530 | [diff] [blame] | 2010 | /* Enable ALL workarounds related to PHY SOF bugs */ |
Manu Gautam | 3c59839 | 2013-03-22 16:59:10 +0530 | [diff] [blame] | 2011 | mehci->ehci.susp_sof_bug = 1; |
| 2012 | mehci->ehci.reset_sof_bug = 1; |
| 2013 | mehci->ehci.resume_sof_bug = 1; |
Manu Gautam | caa99d4 | 2013-07-25 12:01:02 +0530 | [diff] [blame] | 2014 | } else if (pdata->phy_susp_sof_workaround) { |
| 2015 | /* Only SUSP SOF hardware bug exists, rest all not present */ |
| 2016 | mehci->ehci.susp_sof_bug = 1; |
Manu Gautam | 3c59839 | 2013-03-22 16:59:10 +0530 | [diff] [blame] | 2017 | } |
Hemant Kumar | 38ce5d8 | 2012-05-29 13:00:58 -0700 | [diff] [blame] | 2018 | |
Ming-yi Lin | 9eed5e0 | 2013-07-18 14:06:24 +0800 | [diff] [blame] | 2019 | if (pdata->reset_delay) |
| 2020 | mehci->ehci.reset_delay = pdata->reset_delay; |
| 2021 | |
Shimrit Malichi | 36a0c85 | 2013-03-10 11:39:10 +0200 | [diff] [blame] | 2022 | mehci->ehci.pool_64_bit_align = pdata->pool_64_bit_align; |
Shimrit Malichi | 82d7cbc | 2013-03-12 15:36:54 +0200 | [diff] [blame] | 2023 | mehci->enable_hbm = pdata->enable_hbm; |
Hemant Kumar | e404049 | 2012-06-21 17:35:42 -0700 | [diff] [blame] | 2024 | |
Vamsi Krishna | 4f66c2c | 2013-06-21 11:33:59 -0700 | [diff] [blame] | 2025 | if (pdata) { |
Hemant Kumar | 30d361c | 2012-08-20 14:44:40 -0700 | [diff] [blame] | 2026 | mehci->ehci.log2_irq_thresh = pdata->log2_irq_thresh; |
Vamsi Krishna | 4f66c2c | 2013-06-21 11:33:59 -0700 | [diff] [blame] | 2027 | mehci->ehci.disable_cerr = pdata->disable_cerr; |
| 2028 | } |
Hemant Kumar | 933e040 | 2012-05-22 11:11:40 -0700 | [diff] [blame] | 2029 | |
Ofir Cohen | 4cc5537 | 2012-11-20 11:17:24 +0200 | [diff] [blame] | 2030 | ret = msm_hsic_init_gdsc(mehci, 1); |
| 2031 | if (ret) { |
| 2032 | dev_err(&pdev->dev, "unable to initialize GDSC\n"); |
| 2033 | ret = -ENODEV; |
| 2034 | goto put_hcd; |
| 2035 | } |
| 2036 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 2037 | res = platform_get_resource_byname(pdev, |
| 2038 | IORESOURCE_IRQ, |
| 2039 | "peripheral_status_irq"); |
| 2040 | if (res) |
| 2041 | mehci->peripheral_status_irq = res->start; |
| 2042 | |
Jack Pham | 0cc75c4 | 2012-10-10 02:03:50 +0200 | [diff] [blame] | 2043 | res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "wakeup"); |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 2044 | if (res) { |
Jack Pham | 0cc75c4 | 2012-10-10 02:03:50 +0200 | [diff] [blame] | 2045 | mehci->wakeup_irq = res->start; |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 2046 | dev_dbg(mehci->dev, "wakeup_irq: %d\n", mehci->wakeup_irq); |
| 2047 | } |
| 2048 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2049 | ret = msm_hsic_init_clocks(mehci, 1); |
| 2050 | if (ret) { |
| 2051 | dev_err(&pdev->dev, "unable to initialize clocks\n"); |
| 2052 | ret = -ENODEV; |
| 2053 | goto unmap; |
| 2054 | } |
| 2055 | |
| 2056 | ret = msm_hsic_init_vddcx(mehci, 1); |
| 2057 | if (ret) { |
| 2058 | dev_err(&pdev->dev, "unable to initialize VDDCX\n"); |
| 2059 | ret = -ENODEV; |
| 2060 | goto deinit_clocks; |
| 2061 | } |
| 2062 | |
Vamsi Krishna | fce1bd2 | 2012-08-17 17:12:26 -0700 | [diff] [blame] | 2063 | init_completion(&mehci->rt_completion); |
| 2064 | init_completion(&mehci->gpt0_completion); |
Ofir Cohen | 5dddb15 | 2012-11-14 11:18:50 +0200 | [diff] [blame] | 2065 | |
| 2066 | msm_hsic_phy_reset(mehci); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2067 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 2068 | ehci_wq = create_singlethread_workqueue("ehci_wq"); |
| 2069 | if (!ehci_wq) { |
| 2070 | dev_err(&pdev->dev, "unable to create workqueue\n"); |
| 2071 | ret = -ENOMEM; |
| 2072 | goto deinit_vddcx; |
| 2073 | } |
| 2074 | |
| 2075 | INIT_WORK(&mehci->bus_vote_w, ehci_hsic_bus_vote_w); |
| 2076 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2077 | ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED); |
| 2078 | if (ret) { |
| 2079 | dev_err(&pdev->dev, "unable to register HCD\n"); |
Ofir Cohen | 5dddb15 | 2012-11-14 11:18:50 +0200 | [diff] [blame] | 2080 | goto destroy_wq; |
| 2081 | } |
| 2082 | |
| 2083 | ret = msm_hsic_start(mehci); |
| 2084 | if (ret) { |
| 2085 | dev_err(&pdev->dev, "unable to initialize PHY\n"); |
| 2086 | goto destroy_wq; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | device_init_wakeup(&pdev->dev, 1); |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 2090 | wake_lock_init(&mehci->wlock, WAKE_LOCK_SUSPEND, dev_name(&pdev->dev)); |
| 2091 | wake_lock(&mehci->wlock); |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 2092 | |
| 2093 | if (mehci->peripheral_status_irq) { |
| 2094 | ret = request_threaded_irq(mehci->peripheral_status_irq, |
| 2095 | NULL, hsic_peripheral_status_change, |
| 2096 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING |
| 2097 | | IRQF_SHARED, |
| 2098 | "hsic_peripheral_status", mehci); |
| 2099 | if (ret) |
| 2100 | dev_err(&pdev->dev, "%s:request_irq:%d failed:%d", |
| 2101 | __func__, mehci->peripheral_status_irq, ret); |
| 2102 | } |
| 2103 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 2104 | /* configure wakeup irq */ |
Hemant Kumar | 6fd6503 | 2012-05-23 13:02:24 -0700 | [diff] [blame] | 2105 | if (mehci->wakeup_irq) { |
Hemant Kumar | bbcdcbc | 2012-08-30 14:23:38 -0700 | [diff] [blame] | 2106 | /* In case if wakeup gpio is pulled high at this point |
| 2107 | * remote wakeup interrupt fires right after request_irq. |
| 2108 | * Remote wake up interrupt only needs to be enabled when |
| 2109 | * HSIC bus goes to suspend. |
| 2110 | */ |
| 2111 | irq_set_status_flags(mehci->wakeup_irq, IRQ_NOAUTOEN); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 2112 | ret = request_irq(mehci->wakeup_irq, msm_hsic_wakeup_irq, |
Manu Gautam | 1656279 | 2013-03-13 07:04:11 +0530 | [diff] [blame] | 2113 | wakeup_irq_flags, |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 2114 | "msm_hsic_wakeup", mehci); |
Hemant Kumar | bbcdcbc | 2012-08-30 14:23:38 -0700 | [diff] [blame] | 2115 | if (ret) { |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 2116 | dev_err(&pdev->dev, "request_irq(%d) failed: %d\n", |
| 2117 | mehci->wakeup_irq, ret); |
| 2118 | mehci->wakeup_irq = 0; |
| 2119 | } |
| 2120 | } |
| 2121 | |
Manu Gautam | 3fb60ca | 2013-02-13 18:33:33 +0530 | [diff] [blame] | 2122 | mehci->async_irq = platform_get_irq_byname(pdev, "async_irq"); |
| 2123 | if (mehci->async_irq < 0) { |
| 2124 | dev_dbg(&pdev->dev, "platform_get_irq for async_int failed\n"); |
| 2125 | mehci->async_irq = 0; |
| 2126 | } else { |
| 2127 | ret = request_irq(mehci->async_irq, msm_hsic_wakeup_irq, |
| 2128 | IRQF_TRIGGER_RISING, "msm_hsic_async", mehci); |
| 2129 | if (ret) { |
| 2130 | dev_err(&pdev->dev, "request irq failed (ASYNC INT)\n"); |
| 2131 | mehci->async_irq = 0; |
Manu Gautam | 1656279 | 2013-03-13 07:04:11 +0530 | [diff] [blame] | 2132 | } else if (!mehci->wakeup_irq) { |
| 2133 | /* Async IRQ is used only in absence of dedicated irq */ |
Manu Gautam | 3fb60ca | 2013-02-13 18:33:33 +0530 | [diff] [blame] | 2134 | enable_irq_wake(mehci->async_irq); |
| 2135 | } |
| 2136 | } |
| 2137 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 2138 | ret = ehci_hsic_msm_debugfs_init(mehci); |
| 2139 | if (ret) |
| 2140 | dev_dbg(&pdev->dev, "mode debugfs file is" |
| 2141 | "not available\n"); |
| 2142 | |
| 2143 | if (pdata && pdata->bus_scale_table) { |
| 2144 | mehci->bus_perf_client = |
| 2145 | msm_bus_scale_register_client(pdata->bus_scale_table); |
| 2146 | /* Configure BUS performance parameters for MAX bandwidth */ |
| 2147 | if (mehci->bus_perf_client) { |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 2148 | mehci->bus_vote = true; |
| 2149 | queue_work(ehci_wq, &mehci->bus_vote_w); |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 2150 | } else { |
| 2151 | dev_err(&pdev->dev, "%s: Failed to register BUS " |
| 2152 | "scaling client!!\n", __func__); |
| 2153 | } |
| 2154 | } |
| 2155 | |
Hemant Kumar | 105d07f | 2012-07-02 15:33:07 -0700 | [diff] [blame] | 2156 | __mehci = mehci; |
| 2157 | |
Hemant Kumar | bc8bdf6 | 2012-10-17 12:29:51 -0700 | [diff] [blame] | 2158 | if (pdata && pdata->standalone_latency) |
Pavankumar Kondeti | 4f5dc3b | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 2159 | pm_qos_add_request(&mehci->pm_qos_req_dma, |
Hemant Kumar | bc8bdf6 | 2012-10-17 12:29:51 -0700 | [diff] [blame] | 2160 | PM_QOS_CPU_DMA_LATENCY, pdata->standalone_latency + 1); |
Pavankumar Kondeti | 4f5dc3b | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 2161 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2162 | /* |
| 2163 | * This pdev->dev is assigned parent of root-hub by USB core, |
| 2164 | * hence, runtime framework automatically calls this driver's |
| 2165 | * runtime APIs based on root-hub's state. |
| 2166 | */ |
| 2167 | pm_runtime_set_active(&pdev->dev); |
| 2168 | pm_runtime_enable(&pdev->dev); |
Vijayavardhan Vennapusa | afbbb8f | 2012-04-13 16:28:45 +0530 | [diff] [blame] | 2169 | /* Decrement the parent device's counter after probe. |
| 2170 | * As child is active, parent will not be put into |
| 2171 | * suspend mode. |
| 2172 | */ |
| 2173 | if (pdev->dev.parent) |
| 2174 | pm_runtime_put_sync(pdev->dev.parent); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2175 | |
Shimrit Malichi | 82d7cbc | 2013-03-12 15:36:54 +0200 | [diff] [blame] | 2176 | if (mehci->enable_hbm) |
Shimrit Malichi | 08f0734 | 2013-04-24 13:09:12 +0300 | [diff] [blame] | 2177 | hbm_init(hcd, pdata->disable_park_mode); |
Shimrit Malichi | 82d7cbc | 2013-03-12 15:36:54 +0200 | [diff] [blame] | 2178 | |
Jack Pham | 06306d5 | 2013-06-06 15:28:13 -0700 | [diff] [blame] | 2179 | if (pdata && pdata->consider_ipa_handshake) |
| 2180 | msm_bam_set_hsic_host_dev(&pdev->dev); |
Ido Shayevitz | aa165c5 | 2013-05-12 16:01:28 +0200 | [diff] [blame] | 2181 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2182 | return 0; |
| 2183 | |
Ofir Cohen | 5dddb15 | 2012-11-14 11:18:50 +0200 | [diff] [blame] | 2184 | destroy_wq: |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 2185 | destroy_workqueue(ehci_wq); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2186 | deinit_vddcx: |
| 2187 | msm_hsic_init_vddcx(mehci, 0); |
Ofir Cohen | 4cc5537 | 2012-11-20 11:17:24 +0200 | [diff] [blame] | 2188 | msm_hsic_init_gdsc(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2189 | deinit_clocks: |
| 2190 | msm_hsic_init_clocks(mehci, 0); |
| 2191 | unmap: |
| 2192 | iounmap(hcd->regs); |
| 2193 | put_hcd: |
| 2194 | usb_put_hcd(hcd); |
| 2195 | |
| 2196 | return ret; |
| 2197 | } |
| 2198 | |
| 2199 | static int __devexit ehci_hsic_msm_remove(struct platform_device *pdev) |
| 2200 | { |
| 2201 | struct usb_hcd *hcd = platform_get_drvdata(pdev); |
| 2202 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
Pavankumar Kondeti | 4f5dc3b | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 2203 | struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data; |
| 2204 | |
Jack Pham | 06306d5 | 2013-06-06 15:28:13 -0700 | [diff] [blame] | 2205 | if (pdata && pdata->consider_ipa_handshake) |
| 2206 | msm_bam_set_hsic_host_dev(NULL); |
Ido Shayevitz | aa165c5 | 2013-05-12 16:01:28 +0200 | [diff] [blame] | 2207 | |
Ido Shayevitz | 6594349 | 2013-02-20 18:55:59 +0200 | [diff] [blame] | 2208 | /* If the device was removed no need to call pm_runtime_disable */ |
| 2209 | if (pdev->dev.power.power_state.event != PM_EVENT_INVALID) |
| 2210 | pm_runtime_disable(&pdev->dev); |
| 2211 | |
| 2212 | pm_runtime_set_suspended(&pdev->dev); |
| 2213 | |
Shimrit Malichi | 82d7cbc | 2013-03-12 15:36:54 +0200 | [diff] [blame] | 2214 | if (mehci->enable_hbm) |
| 2215 | hbm_uninit(); |
| 2216 | |
Pavankumar Kondeti | 21a840e | 2013-02-12 21:43:56 +0530 | [diff] [blame] | 2217 | /* Remove the HCD prior to releasing our resources. */ |
| 2218 | usb_remove_hcd(hcd); |
| 2219 | |
Hemant Kumar | bc8bdf6 | 2012-10-17 12:29:51 -0700 | [diff] [blame] | 2220 | if (pdata && pdata->standalone_latency) |
Pavankumar Kondeti | 4f5dc3b | 2012-09-07 15:33:09 +0530 | [diff] [blame] | 2221 | pm_qos_remove_request(&mehci->pm_qos_req_dma); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2222 | |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 2223 | if (mehci->peripheral_status_irq) |
| 2224 | free_irq(mehci->peripheral_status_irq, mehci); |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 2225 | |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 2226 | if (mehci->wakeup_irq) { |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 2227 | if (mehci->wakeup_irq_enabled) |
| 2228 | disable_irq_wake(mehci->wakeup_irq); |
Vamsi Krishna | 6921cbe | 2012-02-21 18:34:43 -0800 | [diff] [blame] | 2229 | free_irq(mehci->wakeup_irq, mehci); |
| 2230 | } |
Vamsi Krishna | 34f0158 | 2011-12-14 19:54:42 -0800 | [diff] [blame] | 2231 | |
Manu Gautam | 3fb60ca | 2013-02-13 18:33:33 +0530 | [diff] [blame] | 2232 | if (mehci->async_irq) { |
Manu Gautam | 1a1a9c6 | 2013-03-19 17:37:11 +0530 | [diff] [blame] | 2233 | /* Async IRQ is used only in absence of dedicated wakeup irq */ |
| 2234 | if (!mehci->wakeup_irq) |
| 2235 | disable_irq_wake(mehci->async_irq); |
Manu Gautam | 3fb60ca | 2013-02-13 18:33:33 +0530 | [diff] [blame] | 2236 | free_irq(mehci->async_irq, mehci); |
| 2237 | } |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 2238 | /* |
| 2239 | * If the update request is called after unregister, the request will |
| 2240 | * fail. Results are undefined if unregister is called in the middle of |
| 2241 | * update request. |
| 2242 | */ |
| 2243 | mehci->bus_vote = false; |
| 2244 | cancel_work_sync(&mehci->bus_vote_w); |
| 2245 | |
Hemant Kumar | e627597 | 2012-02-29 20:06:21 -0800 | [diff] [blame] | 2246 | if (mehci->bus_perf_client) |
| 2247 | msm_bus_scale_unregister_client(mehci->bus_perf_client); |
| 2248 | |
| 2249 | ehci_hsic_msm_debugfs_cleanup(); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2250 | device_init_wakeup(&pdev->dev, 0); |
Ido Shayevitz | e50d914 | 2013-02-17 20:43:26 +0200 | [diff] [blame] | 2251 | |
Hemant Kumar | 2309eaa | 2012-08-14 16:46:42 -0700 | [diff] [blame] | 2252 | destroy_workqueue(ehci_wq); |
| 2253 | |
Vijayavardhan Vennapusa | e3316a1 | 2011-10-15 06:05:17 +0530 | [diff] [blame] | 2254 | msm_hsic_config_gpios(mehci, 0); |
Vamsi Krishna | bef9183 | 2013-03-11 14:10:20 -0700 | [diff] [blame] | 2255 | |
| 2256 | if (pdata && pdata->resume_gpio) |
| 2257 | gpio_free(pdata->resume_gpio); |
| 2258 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2259 | msm_hsic_init_vddcx(mehci, 0); |
Ofir Cohen | 4cc5537 | 2012-11-20 11:17:24 +0200 | [diff] [blame] | 2260 | msm_hsic_init_gdsc(mehci, 0); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2261 | |
| 2262 | msm_hsic_init_clocks(mehci, 0); |
Sudhir Sharma | 1673e30 | 2012-08-27 17:37:24 -0700 | [diff] [blame] | 2263 | wake_lock_destroy(&mehci->wlock); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2264 | iounmap(hcd->regs); |
| 2265 | usb_put_hcd(hcd); |
| 2266 | |
| 2267 | return 0; |
| 2268 | } |
| 2269 | |
| 2270 | #ifdef CONFIG_PM_SLEEP |
| 2271 | static int msm_hsic_pm_suspend(struct device *dev) |
| 2272 | { |
| 2273 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 2274 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 2275 | |
| 2276 | dev_dbg(dev, "ehci-msm-hsic PM suspend\n"); |
| 2277 | |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 2278 | dbg_log_event(NULL, "PM Suspend", 0); |
| 2279 | |
Pavankumar Kondeti | 1081f3e | 2013-04-25 13:51:24 +0530 | [diff] [blame] | 2280 | if (!atomic_read(&mehci->in_lpm)) { |
| 2281 | dev_info(dev, "abort suspend\n"); |
| 2282 | dbg_log_event(NULL, "PM Suspend abort", 0); |
| 2283 | return -EBUSY; |
| 2284 | } |
| 2285 | |
Manu Gautam | 1656279 | 2013-03-13 07:04:11 +0530 | [diff] [blame] | 2286 | if (device_may_wakeup(dev) && !mehci->async_irq) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2287 | enable_irq_wake(hcd->irq); |
| 2288 | |
Pavankumar Kondeti | 1081f3e | 2013-04-25 13:51:24 +0530 | [diff] [blame] | 2289 | return 0; |
Jack Pham | fe441ea | 2012-03-23 17:03:15 -0700 | [diff] [blame] | 2290 | } |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2291 | |
Jack Pham | 16b06f8 | 2012-08-14 20:03:59 -0700 | [diff] [blame] | 2292 | static int msm_hsic_pm_suspend_noirq(struct device *dev) |
| 2293 | { |
| 2294 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 2295 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 2296 | |
Pavankumar Kondeti | 822fbe6 | 2013-01-28 17:04:39 +0530 | [diff] [blame] | 2297 | if (atomic_read(&mehci->async_int)) { |
Jack Pham | 16b06f8 | 2012-08-14 20:03:59 -0700 | [diff] [blame] | 2298 | dev_dbg(dev, "suspend_noirq: Aborting due to pending interrupt\n"); |
| 2299 | return -EBUSY; |
| 2300 | } |
| 2301 | |
| 2302 | return 0; |
| 2303 | } |
| 2304 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2305 | static int msm_hsic_pm_resume(struct device *dev) |
| 2306 | { |
| 2307 | int ret; |
| 2308 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 2309 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 2310 | |
Jack Pham | 16b06f8 | 2012-08-14 20:03:59 -0700 | [diff] [blame] | 2311 | dev_dbg(dev, "ehci-msm-hsic PM resume\n"); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 2312 | dbg_log_event(NULL, "PM Resume", 0); |
| 2313 | |
Manu Gautam | 1656279 | 2013-03-13 07:04:11 +0530 | [diff] [blame] | 2314 | if (device_may_wakeup(dev) && !mehci->async_irq) |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2315 | disable_irq_wake(hcd->irq); |
| 2316 | |
Pavankumar Kondeti | 6f199aa | 2012-09-18 17:52:51 +0530 | [diff] [blame] | 2317 | /* |
| 2318 | * Keep HSIC in Low Power Mode if system is resumed |
| 2319 | * by any other wakeup source. HSIC is resumed later |
| 2320 | * when remote wakeup is received or interface driver |
| 2321 | * start I/O. |
| 2322 | */ |
Pavankumar Kondeti | 41d004c | 2012-11-09 10:54:00 +0530 | [diff] [blame] | 2323 | if (!atomic_read(&mehci->pm_usage_cnt) && |
Pavankumar Kondeti | 822fbe6 | 2013-01-28 17:04:39 +0530 | [diff] [blame] | 2324 | !atomic_read(&mehci->async_int) && |
Pavankumar Kondeti | 41d004c | 2012-11-09 10:54:00 +0530 | [diff] [blame] | 2325 | pm_runtime_suspended(dev)) |
Pavankumar Kondeti | 6f199aa | 2012-09-18 17:52:51 +0530 | [diff] [blame] | 2326 | return 0; |
| 2327 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2328 | ret = msm_hsic_resume(mehci); |
| 2329 | if (ret) |
| 2330 | return ret; |
| 2331 | |
| 2332 | /* Bring the device to full powered state upon system resume */ |
| 2333 | pm_runtime_disable(dev); |
| 2334 | pm_runtime_set_active(dev); |
| 2335 | pm_runtime_enable(dev); |
| 2336 | |
| 2337 | return 0; |
| 2338 | } |
| 2339 | #endif |
| 2340 | |
| 2341 | #ifdef CONFIG_PM_RUNTIME |
| 2342 | static int msm_hsic_runtime_idle(struct device *dev) |
| 2343 | { |
| 2344 | dev_dbg(dev, "EHCI runtime idle\n"); |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2345 | return 0; |
| 2346 | } |
| 2347 | |
| 2348 | static int msm_hsic_runtime_suspend(struct device *dev) |
| 2349 | { |
| 2350 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 2351 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 2352 | |
| 2353 | dev_dbg(dev, "EHCI runtime suspend\n"); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 2354 | |
| 2355 | dbg_log_event(NULL, "Run Time PM Suspend", 0); |
| 2356 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2357 | return msm_hsic_suspend(mehci); |
| 2358 | } |
| 2359 | |
| 2360 | static int msm_hsic_runtime_resume(struct device *dev) |
| 2361 | { |
| 2362 | struct usb_hcd *hcd = dev_get_drvdata(dev); |
| 2363 | struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd); |
| 2364 | |
| 2365 | dev_dbg(dev, "EHCI runtime resume\n"); |
Hemant Kumar | 45d211b | 2012-05-31 17:58:43 -0700 | [diff] [blame] | 2366 | |
| 2367 | dbg_log_event(NULL, "Run Time PM Resume", 0); |
| 2368 | |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2369 | return msm_hsic_resume(mehci); |
| 2370 | } |
| 2371 | #endif |
| 2372 | |
| 2373 | #ifdef CONFIG_PM |
| 2374 | static const struct dev_pm_ops msm_hsic_dev_pm_ops = { |
| 2375 | 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] | 2376 | .suspend_noirq = msm_hsic_pm_suspend_noirq, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2377 | SET_RUNTIME_PM_OPS(msm_hsic_runtime_suspend, msm_hsic_runtime_resume, |
| 2378 | msm_hsic_runtime_idle) |
| 2379 | }; |
| 2380 | #endif |
Ofir Cohen | 4cc5537 | 2012-11-20 11:17:24 +0200 | [diff] [blame] | 2381 | static const struct of_device_id hsic_host_dt_match[] = { |
| 2382 | { .compatible = "qcom,hsic-host", |
| 2383 | }, |
| 2384 | {} |
| 2385 | }; |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2386 | static struct platform_driver ehci_msm_hsic_driver = { |
| 2387 | .probe = ehci_hsic_msm_probe, |
| 2388 | .remove = __devexit_p(ehci_hsic_msm_remove), |
| 2389 | .driver = { |
| 2390 | .name = "msm_hsic_host", |
| 2391 | #ifdef CONFIG_PM |
| 2392 | .pm = &msm_hsic_dev_pm_ops, |
| 2393 | #endif |
Ofir Cohen | 4cc5537 | 2012-11-20 11:17:24 +0200 | [diff] [blame] | 2394 | .of_match_table = hsic_host_dt_match, |
Vijayavardhan Vennapusa | 39025fe | 2011-10-15 05:55:10 +0530 | [diff] [blame] | 2395 | }, |
| 2396 | }; |