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