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