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