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