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