blob: c18bccfb4b4e19622ddc8f53972765e83d507aa8 [file] [log] [blame]
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301/* ehci-msm-hsic.c - HSUSB Host Controller Driver Implementation
2 *
Manu Gautam5143b252012-01-05 19:25:23 -08003 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05304 *
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 Kumare6275972012-02-29 20:06:21 -080028#include <linux/debugfs.h>
29#include <linux/seq_file.h>
Ajay Dudaniab3bf192012-08-28 09:58:04 -070030#include <linux/wakelock.h>
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053031#include <linux/pm_runtime.h>
32#include <linux/regulator/consumer.h>
33
34#include <linux/usb/msm_hsusb_hw.h>
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +053035#include <linux/usb/msm_hsusb.h>
36#include <linux/gpio.h>
Amit Blayd6ea6102012-06-07 16:26:24 +030037#include <linux/spinlock.h>
Ajay Dudani11ab1d52012-08-17 17:12:26 -070038#include <linux/kthread.h>
39#include <linux/wait.h>
Pavankumar Kondetife2d4d32012-09-07 15:33:09 +053040#include <linux/pm_qos.h>
Amit Blayd6ea6102012-06-07 16:26:24 +030041
42#include <mach/msm_bus.h>
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053043#include <mach/clk.h>
44#include <mach/msm_iomap.h>
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +053045#include <mach/msm_xo.h>
Vamsi Krishna34f01582011-12-14 19:54:42 -080046#include <linux/spinlock.h>
Hemant Kumar45d211b2012-05-31 17:58:43 -070047#include <linux/cpu.h>
Amit Blayd6ea6102012-06-07 16:26:24 +030048#include <mach/rpm-regulator.h>
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053049
50#define MSM_USB_BASE (hcd->regs)
Hemant Kumar105d07f2012-07-02 15:33:07 -070051#define USB_REG_START_OFFSET 0x90
52#define USB_REG_END_OFFSET 0x250
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053053
Hemant Kumar2309eaa2012-08-14 16:46:42 -070054static struct workqueue_struct *ehci_wq;
Ajay Dudani11ab1d52012-08-17 17:12:26 -070055struct ehci_timer {
56#define GPT_LD(p) ((p) & 0x00FFFFFF)
57 u32 gptimer0_ld;
58#define GPT_RUN BIT(31)
59#define GPT_RESET BIT(30)
60#define GPT_MODE BIT(24)
61#define GPT_CNT(p) ((p) & 0x00FFFFFF)
62 u32 gptimer0_ctrl;
63
64 u32 gptimer1_ld;
65 u32 gptimer1_ctrl;
66};
Hemant Kumar2309eaa2012-08-14 16:46:42 -070067
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053068struct msm_hsic_hcd {
69 struct ehci_hcd ehci;
Hemant Kumar4cd49e12012-09-06 19:57:14 -070070 spinlock_t wakeup_lock;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053071 struct device *dev;
72 struct clk *ahb_clk;
Manu Gautam5143b252012-01-05 19:25:23 -080073 struct clk *core_clk;
74 struct clk *alt_core_clk;
75 struct clk *phy_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053076 struct clk *cal_clk;
77 struct regulator *hsic_vddcx;
Ajay Dudaniab3bf192012-08-28 09:58:04 -070078 bool async_int;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053079 atomic_t in_lpm;
Ajay Dudaniab3bf192012-08-28 09:58:04 -070080 struct wake_lock wlock;
Vamsi Krishna34f01582011-12-14 19:54:42 -080081 int peripheral_status_irq;
Vamsi Krishna6921cbe2012-02-21 18:34:43 -080082 int wakeup_irq;
Hemant Kumar6fd65032012-05-23 13:02:24 -070083 int wakeup_gpio;
Jack Phamfe441ea2012-03-23 17:03:15 -070084 bool wakeup_irq_enabled;
Ajay Dudaniab3bf192012-08-28 09:58:04 -070085 atomic_t pm_usage_cnt;
Hemant Kumare6275972012-02-29 20:06:21 -080086 uint32_t bus_perf_client;
Hemant Kumar6fd65032012-05-23 13:02:24 -070087 uint32_t wakeup_int_cnt;
Amit Blayd6ea6102012-06-07 16:26:24 +030088 enum usb_vdd_type vdd_type;
Hemant Kumar2309eaa2012-08-14 16:46:42 -070089
90 struct work_struct bus_vote_w;
91 bool bus_vote;
Ajay Dudani11ab1d52012-08-17 17:12:26 -070092
93 /* gp timer */
94 struct ehci_timer __iomem *timer;
95 struct completion gpt0_completion;
96 struct completion rt_completion;
97 int resume_status;
98 int resume_again;
Pavankumar Kondetife2d4d32012-09-07 15:33:09 +053099
100 struct pm_qos_request pm_qos_req_dma;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530101};
102
Hemant Kumar105d07f2012-07-02 15:33:07 -0700103struct msm_hsic_hcd *__mehci;
104
Hemant Kumare6275972012-02-29 20:06:21 -0800105static bool debug_bus_voting_enabled = true;
Hemant Kumar45d211b2012-05-31 17:58:43 -0700106
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700107static unsigned int enable_payload_log = 1;
108module_param(enable_payload_log, uint, S_IRUGO | S_IWUSR);
Hemant Kumar45d211b2012-05-31 17:58:43 -0700109static unsigned int enable_dbg_log = 1;
110module_param(enable_dbg_log, uint, S_IRUGO | S_IWUSR);
111/*by default log ep0 and efs sync ep*/
112static unsigned int ep_addr_rxdbg_mask = 9;
113module_param(ep_addr_rxdbg_mask, uint, S_IRUGO | S_IWUSR);
114static unsigned int ep_addr_txdbg_mask = 9;
115module_param(ep_addr_txdbg_mask, uint, S_IRUGO | S_IWUSR);
116
117/* Maximum debug message length */
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700118#define DBG_MSG_LEN 128UL
Hemant Kumar45d211b2012-05-31 17:58:43 -0700119
120/* Maximum number of messages */
121#define DBG_MAX_MSG 256UL
122
123#define TIME_BUF_LEN 20
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700124#define HEX_DUMP_LEN 72
Hemant Kumar45d211b2012-05-31 17:58:43 -0700125
126enum event_type {
127 EVENT_UNDEF = -1,
128 URB_SUBMIT,
129 URB_COMPLETE,
130 EVENT_NONE,
131};
132
133#define EVENT_STR_LEN 5
134
Hemant Kumar45d211b2012-05-31 17:58:43 -0700135static enum event_type str_to_event(const char *name)
136{
137 if (!strncasecmp("S", name, EVENT_STR_LEN))
138 return URB_SUBMIT;
139 if (!strncasecmp("C", name, EVENT_STR_LEN))
140 return URB_COMPLETE;
141 if (!strncasecmp("", name, EVENT_STR_LEN))
142 return EVENT_NONE;
143
144 return EVENT_UNDEF;
145}
146
147/*log ep0 activity*/
148static struct {
149 char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */
150 unsigned idx; /* index */
151 rwlock_t lck; /* lock */
152} dbg_hsic_ctrl = {
153 .idx = 0,
154 .lck = __RW_LOCK_UNLOCKED(lck)
155};
156
157static struct {
158 char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */
159 unsigned idx; /* index */
160 rwlock_t lck; /* lock */
161} dbg_hsic_data = {
162 .idx = 0,
163 .lck = __RW_LOCK_UNLOCKED(lck)
164};
165
166/**
167 * dbg_inc: increments debug event index
168 * @idx: buffer index
169 */
170static void dbg_inc(unsigned *idx)
171{
172 *idx = (*idx + 1) & (DBG_MAX_MSG-1);
173}
174
175/*get_timestamp - returns time of day in us */
176static char *get_timestamp(char *tbuf)
177{
178 unsigned long long t;
179 unsigned long nanosec_rem;
180
181 t = cpu_clock(smp_processor_id());
182 nanosec_rem = do_div(t, 1000000000)/1000;
183 scnprintf(tbuf, TIME_BUF_LEN, "[%5lu.%06lu] ", (unsigned long)t,
184 nanosec_rem);
185 return tbuf;
186}
187
188static int allow_dbg_log(int ep_addr)
189{
190 int dir, num;
191
192 dir = ep_addr & USB_DIR_IN ? USB_DIR_IN : USB_DIR_OUT;
193 num = ep_addr & ~USB_DIR_IN;
194 num = 1 << num;
195
196 if ((dir == USB_DIR_IN) && (num & ep_addr_rxdbg_mask))
197 return 1;
198 if ((dir == USB_DIR_OUT) && (num & ep_addr_txdbg_mask))
199 return 1;
200
201 return 0;
202}
203
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700204static char *get_hex_data(char *dbuf, struct urb *urb, int event, int status)
205{
206 int ep_addr = urb->ep->desc.bEndpointAddress;
207 char *ubuf = urb->transfer_buffer;
208 size_t len = event ? \
209 urb->actual_length : urb->transfer_buffer_length;
210
211 if (status == -EINPROGRESS)
212 status = 0;
213
214 /*Only dump ep in completions and epout submissions*/
215 if (len && !status &&
216 (((ep_addr & USB_DIR_IN) && event) ||
217 (!(ep_addr & USB_DIR_IN) && !event))) {
218 if (len >= 32)
219 len = 32;
220 hex_dump_to_buffer(ubuf, len, 32, 4, dbuf, HEX_DUMP_LEN, 0);
221 } else {
222 dbuf = "";
223 }
224
225 return dbuf;
226}
227
Hemant Kumar45d211b2012-05-31 17:58:43 -0700228static void dbg_log_event(struct urb *urb, char * event, unsigned extra)
229{
230 unsigned long flags;
231 int ep_addr;
232 char tbuf[TIME_BUF_LEN];
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700233 char dbuf[HEX_DUMP_LEN];
Hemant Kumar45d211b2012-05-31 17:58:43 -0700234
235 if (!enable_dbg_log)
236 return;
237
238 if (!urb) {
239 write_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
240 scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], DBG_MSG_LEN,
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700241 "%s: %s : %u", get_timestamp(tbuf), event, extra);
Hemant Kumar45d211b2012-05-31 17:58:43 -0700242 dbg_inc(&dbg_hsic_ctrl.idx);
243 write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags);
244 return;
245 }
246
247 ep_addr = urb->ep->desc.bEndpointAddress;
248 if (!allow_dbg_log(ep_addr))
249 return;
250
251 if ((ep_addr & 0x0f) == 0x0) {
252 /*submit event*/
253 if (!str_to_event(event)) {
254 write_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
255 scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx],
256 DBG_MSG_LEN, "%s: [%s : %p]:[%s] "
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700257 "%02x %02x %04x %04x %04x %u %d",
Hemant Kumar45d211b2012-05-31 17:58:43 -0700258 get_timestamp(tbuf), event, urb,
259 (ep_addr & USB_DIR_IN) ? "in" : "out",
260 urb->setup_packet[0], urb->setup_packet[1],
261 (urb->setup_packet[3] << 8) |
262 urb->setup_packet[2],
263 (urb->setup_packet[5] << 8) |
264 urb->setup_packet[4],
265 (urb->setup_packet[7] << 8) |
266 urb->setup_packet[6],
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700267 urb->transfer_buffer_length, extra);
Hemant Kumar45d211b2012-05-31 17:58:43 -0700268
269 dbg_inc(&dbg_hsic_ctrl.idx);
270 write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags);
271 } else {
272 write_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
273 scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx],
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700274 DBG_MSG_LEN, "%s: [%s : %p]:[%s] %u %d",
Hemant Kumar45d211b2012-05-31 17:58:43 -0700275 get_timestamp(tbuf), event, urb,
276 (ep_addr & USB_DIR_IN) ? "in" : "out",
277 urb->actual_length, extra);
278
279 dbg_inc(&dbg_hsic_ctrl.idx);
280 write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags);
281 }
282 } else {
283 write_lock_irqsave(&dbg_hsic_data.lck, flags);
284 scnprintf(dbg_hsic_data.buf[dbg_hsic_data.idx], DBG_MSG_LEN,
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700285 "%s: [%s : %p]:ep%d[%s] %u %d %s",
Hemant Kumar45d211b2012-05-31 17:58:43 -0700286 get_timestamp(tbuf), event, urb, ep_addr & 0x0f,
287 (ep_addr & USB_DIR_IN) ? "in" : "out",
288 str_to_event(event) ? urb->actual_length :
Hemant Kumardf2d84d2012-08-15 09:06:35 -0700289 urb->transfer_buffer_length, extra,
290 enable_payload_log ? get_hex_data(dbuf, urb,
291 str_to_event(event), extra) : "");
Hemant Kumar45d211b2012-05-31 17:58:43 -0700292
293 dbg_inc(&dbg_hsic_data.idx);
294 write_unlock_irqrestore(&dbg_hsic_data.lck, flags);
295 }
296}
297
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530298static inline struct msm_hsic_hcd *hcd_to_hsic(struct usb_hcd *hcd)
299{
300 return (struct msm_hsic_hcd *) (hcd->hcd_priv);
301}
302
303static inline struct usb_hcd *hsic_to_hcd(struct msm_hsic_hcd *mehci)
304{
305 return container_of((void *) mehci, struct usb_hcd, hcd_priv);
306}
307
Hemant Kumar105d07f2012-07-02 15:33:07 -0700308static void dump_hsic_regs(struct usb_hcd *hcd)
309{
310 int i;
311 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
312
313 if (atomic_read(&mehci->in_lpm))
314 return;
315
316 for (i = USB_REG_START_OFFSET; i <= USB_REG_END_OFFSET; i += 0x10)
317 pr_info("%p: %08x\t%08x\t%08x\t%08x\n", hcd->regs + i,
318 readl_relaxed(hcd->regs + i),
319 readl_relaxed(hcd->regs + i + 4),
320 readl_relaxed(hcd->regs + i + 8),
321 readl_relaxed(hcd->regs + i + 0xc));
322}
323
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530324#define ULPI_IO_TIMEOUT_USEC (10 * 1000)
325
Amit Blayd6ea6102012-06-07 16:26:24 +0300326#define USB_PHY_VDD_DIG_VOL_NONE 0 /*uV */
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700327#define USB_PHY_VDD_DIG_VOL_MIN 1000000 /* uV */
328#define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530329
Lena Salman8c8ba382012-02-14 15:59:31 +0200330#define HSIC_DBG1_REG 0x38
331
Amit Blayd6ea6102012-06-07 16:26:24 +0300332static const int vdd_val[VDD_TYPE_MAX][VDD_VAL_MAX] = {
333 { /* VDD_CX CORNER Voting */
334 [VDD_NONE] = RPM_VREG_CORNER_NONE,
335 [VDD_MIN] = RPM_VREG_CORNER_NOMINAL,
336 [VDD_MAX] = RPM_VREG_CORNER_HIGH,
337 },
338 { /* VDD_CX Voltage Voting */
339 [VDD_NONE] = USB_PHY_VDD_DIG_VOL_NONE,
340 [VDD_MIN] = USB_PHY_VDD_DIG_VOL_MIN,
341 [VDD_MAX] = USB_PHY_VDD_DIG_VOL_MAX,
342 },
343};
344
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530345static int msm_hsic_init_vddcx(struct msm_hsic_hcd *mehci, int init)
346{
347 int ret = 0;
Amit Blayd6ea6102012-06-07 16:26:24 +0300348 int none_vol, min_vol, max_vol;
349
350 if (!mehci->hsic_vddcx) {
351 mehci->vdd_type = VDDCX_CORNER;
352 mehci->hsic_vddcx = devm_regulator_get(mehci->dev,
353 "hsic_vdd_dig");
354 if (IS_ERR(mehci->hsic_vddcx)) {
355 mehci->hsic_vddcx = devm_regulator_get(mehci->dev,
356 "HSIC_VDDCX");
357 if (IS_ERR(mehci->hsic_vddcx)) {
358 dev_err(mehci->dev, "unable to get hsic vddcx\n");
359 return PTR_ERR(mehci->hsic_vddcx);
360 }
361 mehci->vdd_type = VDDCX;
362 }
363 }
364
365 none_vol = vdd_val[mehci->vdd_type][VDD_NONE];
366 min_vol = vdd_val[mehci->vdd_type][VDD_MIN];
367 max_vol = vdd_val[mehci->vdd_type][VDD_MAX];
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530368
369 if (!init)
370 goto disable_reg;
371
Amit Blayd6ea6102012-06-07 16:26:24 +0300372 ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530373 if (ret) {
374 dev_err(mehci->dev, "unable to set the voltage"
375 "for hsic vddcx\n");
Mayank Rana189ac052012-03-24 04:35:02 +0530376 return ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530377 }
378
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530379 ret = regulator_enable(mehci->hsic_vddcx);
380 if (ret) {
381 dev_err(mehci->dev, "unable to enable hsic vddcx\n");
382 goto reg_enable_err;
383 }
384
385 return 0;
386
387disable_reg:
388 regulator_disable(mehci->hsic_vddcx);
389reg_enable_err:
Amit Blayd6ea6102012-06-07 16:26:24 +0300390 regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol);
391
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530392 return ret;
393
394}
395
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -0700396static int ulpi_read(struct msm_hsic_hcd *mehci, u32 reg)
397{
398 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Devin Kim01e5a5b2012-08-30 02:52:45 -0700399 int cnt = 0;
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -0700400
401 /* initiate read operation */
402 writel_relaxed(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg),
403 USB_ULPI_VIEWPORT);
404
405 /* wait for completion */
Devin Kim01e5a5b2012-08-30 02:52:45 -0700406 while (cnt < ULPI_IO_TIMEOUT_USEC) {
407 if (!(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN))
408 break;
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -0700409 udelay(1);
Devin Kim01e5a5b2012-08-30 02:52:45 -0700410 cnt++;
411 }
412
413 if (cnt >= ULPI_IO_TIMEOUT_USEC) {
414 dev_err(mehci->dev, "ulpi_read: timeout ULPI_VIEWPORT: %08x\n",
415 readl_relaxed(USB_ULPI_VIEWPORT));
416 dev_err(mehci->dev, "PORTSC: %08x USBCMD: %08x FRINDEX: %08x\n",
417 readl_relaxed(USB_PORTSC),
418 readl_relaxed(USB_USBCMD),
419 readl_relaxed(USB_FRINDEX));
420
421 /*frame counter increments afte 125us*/
422 udelay(130);
423 dev_err(mehci->dev, "ulpi_read: FRINDEX: %08x\n",
424 readl_relaxed(USB_FRINDEX));
425 return -ETIMEDOUT;
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -0700426 }
427
428 return ULPI_DATA_READ(readl_relaxed(USB_ULPI_VIEWPORT));
429}
430
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530431static int ulpi_write(struct msm_hsic_hcd *mehci, u32 val, u32 reg)
432{
433 struct usb_hcd *hcd = hsic_to_hcd(mehci);
434 int cnt = 0;
435
436 /* initiate write operation */
437 writel_relaxed(ULPI_RUN | ULPI_WRITE |
438 ULPI_ADDR(reg) | ULPI_DATA(val),
439 USB_ULPI_VIEWPORT);
440
441 /* wait for completion */
442 while (cnt < ULPI_IO_TIMEOUT_USEC) {
443 if (!(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN))
444 break;
445 udelay(1);
446 cnt++;
447 }
448
449 if (cnt >= ULPI_IO_TIMEOUT_USEC) {
Devin Kim01e5a5b2012-08-30 02:52:45 -0700450 dev_err(mehci->dev, "ulpi_write: timeout ULPI_VIEWPORT: %08x\n",
451 readl_relaxed(USB_ULPI_VIEWPORT));
452 dev_err(mehci->dev, "PORTSC: %08x USBCMD: %08x FRINDEX: %08x\n",
453 readl_relaxed(USB_PORTSC),
454 readl_relaxed(USB_USBCMD),
455 readl_relaxed(USB_FRINDEX));
456
457 /*frame counter increments afte 125us*/
458 udelay(130);
459 dev_err(mehci->dev, "ulpi_write: FRINDEX: %08x\n",
460 readl_relaxed(USB_FRINDEX));
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530461 return -ETIMEDOUT;
462 }
463
464 return 0;
465}
466
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -0700467#define HSIC_DBG1 0X38
468#define ULPI_MANUAL_ENABLE BIT(4)
469#define ULPI_LINESTATE_DATA BIT(5)
470#define ULPI_LINESTATE_STROBE BIT(6)
471static void ehci_msm_enable_ulpi_control(struct usb_hcd *hcd, u32 linestate)
472{
473 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
474 int val;
475
476 switch (linestate) {
477 case PORT_RESET:
478 val = ulpi_read(mehci, HSIC_DBG1);
479 val |= ULPI_MANUAL_ENABLE;
480 val &= ~(ULPI_LINESTATE_DATA | ULPI_LINESTATE_STROBE);
481 ulpi_write(mehci, val, HSIC_DBG1);
482 break;
483 default:
484 pr_info("%s: Unknown linestate:%0x\n", __func__, linestate);
485 }
486}
487
488static void ehci_msm_disable_ulpi_control(struct usb_hcd *hcd)
489{
490 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
491 int val;
492
493 val = ulpi_read(mehci, HSIC_DBG1);
494 val &= ~ULPI_MANUAL_ENABLE;
495 ulpi_write(mehci, val, HSIC_DBG1);
496}
497
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530498static int msm_hsic_config_gpios(struct msm_hsic_hcd *mehci, int gpio_en)
499{
500 int rc = 0;
501 struct msm_hsic_host_platform_data *pdata;
Vamsi Krishna34f01582011-12-14 19:54:42 -0800502 static int gpio_status;
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530503
504 pdata = mehci->dev->platform_data;
Vamsi Krishna34f01582011-12-14 19:54:42 -0800505
Lena Salman8c8ba382012-02-14 15:59:31 +0200506 if (!pdata || !pdata->strobe || !pdata->data)
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530507 return rc;
508
Vamsi Krishna34f01582011-12-14 19:54:42 -0800509 if (gpio_status == gpio_en)
510 return 0;
511
512 gpio_status = gpio_en;
513
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530514 if (!gpio_en)
515 goto free_gpio;
516
517 rc = gpio_request(pdata->strobe, "HSIC_STROBE_GPIO");
518 if (rc < 0) {
519 dev_err(mehci->dev, "gpio request failed for HSIC STROBE\n");
520 return rc;
521 }
522
523 rc = gpio_request(pdata->data, "HSIC_DATA_GPIO");
524 if (rc < 0) {
525 dev_err(mehci->dev, "gpio request failed for HSIC DATA\n");
526 goto free_strobe;
527 }
528
Hemant Kumar6fd65032012-05-23 13:02:24 -0700529 if (mehci->wakeup_gpio) {
530 rc = gpio_request(mehci->wakeup_gpio, "HSIC_WAKEUP_GPIO");
531 if (rc < 0) {
532 dev_err(mehci->dev, "gpio request failed for HSIC WAKEUP\n");
533 goto free_data;
534 }
535 }
536
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530537 return 0;
538
539free_gpio:
Hemant Kumar6fd65032012-05-23 13:02:24 -0700540 if (mehci->wakeup_gpio)
541 gpio_free(mehci->wakeup_gpio);
542free_data:
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530543 gpio_free(pdata->data);
544free_strobe:
545 gpio_free(pdata->strobe);
546
547 return rc;
548}
549
Vamsi Krishna64b48612012-06-14 16:08:11 -0700550static void msm_hsic_clk_reset(struct msm_hsic_hcd *mehci)
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530551{
552 int ret;
553
Manu Gautam5143b252012-01-05 19:25:23 -0800554 ret = clk_reset(mehci->core_clk, CLK_RESET_ASSERT);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530555 if (ret) {
Vamsi Krishna64b48612012-06-14 16:08:11 -0700556 dev_err(mehci->dev, "hsic clk assert failed:%d\n", ret);
557 return;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530558 }
Vamsi Krishna64b48612012-06-14 16:08:11 -0700559 clk_disable(mehci->core_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530560
Manu Gautam5143b252012-01-05 19:25:23 -0800561 ret = clk_reset(mehci->core_clk, CLK_RESET_DEASSERT);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530562 if (ret)
Vamsi Krishna64b48612012-06-14 16:08:11 -0700563 dev_err(mehci->dev, "hsic clk deassert failed:%d\n", ret);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530564
Vamsi Krishna64b48612012-06-14 16:08:11 -0700565 usleep_range(10000, 12000);
566
567 clk_enable(mehci->core_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530568}
569
Vamsi Krishna64b48612012-06-14 16:08:11 -0700570#define HSIC_STROBE_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C0)
571#define HSIC_DATA_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C4)
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530572#define HSIC_CAL_PAD_CTL (MSM_TLMM_BASE+0x20C8)
573#define HSIC_LV_MODE 0x04
574#define HSIC_PAD_CALIBRATION 0xA8
575#define HSIC_GPIO_PAD_VAL 0x0A0AAA10
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530576#define LINK_RESET_TIMEOUT_USEC (250 * 1000)
577static int msm_hsic_reset(struct msm_hsic_hcd *mehci)
578{
579 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530580 int ret;
Lena Salman8c8ba382012-02-14 15:59:31 +0200581 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530582
Vamsi Krishna64b48612012-06-14 16:08:11 -0700583 msm_hsic_clk_reset(mehci);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530584
Vamsi Krishna64b48612012-06-14 16:08:11 -0700585 /* select ulpi phy */
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530586 writel_relaxed(0x80000000, USB_PORTSC);
587
Vamsi Krishna64b48612012-06-14 16:08:11 -0700588 mb();
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530589
Lena Salman8c8ba382012-02-14 15:59:31 +0200590 /* HSIC init sequence when HSIC signals (Strobe/Data) are
591 routed via GPIOs */
592 if (pdata && pdata->strobe && pdata->data) {
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530593
Lena Salman8c8ba382012-02-14 15:59:31 +0200594 /* Enable LV_MODE in HSIC_CAL_PAD_CTL register */
595 writel_relaxed(HSIC_LV_MODE, HSIC_CAL_PAD_CTL);
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530596
Vamsi Krishna64b48612012-06-14 16:08:11 -0700597 mb();
598
Lena Salman8c8ba382012-02-14 15:59:31 +0200599 /*set periodic calibration interval to ~2.048sec in
600 HSIC_IO_CAL_REG */
601 ulpi_write(mehci, 0xFF, 0x33);
602
603 /* Enable periodic IO calibration in HSIC_CFG register */
604 ulpi_write(mehci, HSIC_PAD_CALIBRATION, 0x30);
605
Vamsi Krishna64b48612012-06-14 16:08:11 -0700606 /* Configure GPIO pins for HSIC functionality mode */
Lena Salman8c8ba382012-02-14 15:59:31 +0200607 ret = msm_hsic_config_gpios(mehci, 1);
608 if (ret) {
609 dev_err(mehci->dev, " gpio configuarion failed\n");
610 return ret;
611 }
Vamsi Krishna64b48612012-06-14 16:08:11 -0700612 /* Set LV_MODE=0x1 and DCC=0x2 in HSIC_GPIO PAD_CTL register */
613 writel_relaxed(HSIC_GPIO_PAD_VAL, HSIC_STROBE_GPIO_PAD_CTL);
614 writel_relaxed(HSIC_GPIO_PAD_VAL, HSIC_DATA_GPIO_PAD_CTL);
615
616 mb();
617
Lena Salman8c8ba382012-02-14 15:59:31 +0200618 /* Enable HSIC mode in HSIC_CFG register */
619 ulpi_write(mehci, 0x01, 0x31);
620 } else {
621 /* HSIC init sequence when HSIC signals (Strobe/Data) are routed
622 via dedicated I/O */
623
624 /* programmable length of connect signaling (33.2ns) */
625 ret = ulpi_write(mehci, 3, HSIC_DBG1_REG);
626 if (ret) {
627 pr_err("%s: Unable to program length of connect "
628 "signaling\n", __func__);
629 }
630
631 /*set periodic calibration interval to ~2.048sec in
632 HSIC_IO_CAL_REG */
633 ulpi_write(mehci, 0xFF, 0x33);
634
635 /* Enable HSIC mode in HSIC_CFG register */
636 ulpi_write(mehci, 0xA9, 0x30);
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530637 }
638
Hemant Kumar6fd65032012-05-23 13:02:24 -0700639 /*disable auto resume*/
640 ulpi_write(mehci, ULPI_IFC_CTRL_AUTORESUME, ULPI_CLR(ULPI_IFC_CTRL));
641
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530642 return 0;
643}
644
645#define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000)
646#define PHY_RESUME_TIMEOUT_USEC (100 * 1000)
647
648#ifdef CONFIG_PM_SLEEP
649static int msm_hsic_suspend(struct msm_hsic_hcd *mehci)
650{
651 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +0530652 int cnt = 0, ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530653 u32 val;
Amit Blayd6ea6102012-06-07 16:26:24 +0300654 int none_vol, max_vol;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530655
656 if (atomic_read(&mehci->in_lpm)) {
657 dev_dbg(mehci->dev, "%s called in lpm\n", __func__);
658 return 0;
659 }
660
Hemant Kumar7f374632012-05-31 20:10:32 -0700661 if (!(readl_relaxed(USB_PORTSC) & PORT_PE)) {
662 dev_dbg(mehci->dev, "%s:port is not enabled skip suspend\n",
663 __func__);
664 return -EAGAIN;
665 }
666
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530667 disable_irq(hcd->irq);
Jack Phambe05fbb2012-05-16 10:56:26 -0700668
Ajay Dudaniab3bf192012-08-28 09:58:04 -0700669 /* make sure we don't race against a remote wakeup */
670 if (test_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags) ||
Jack Phambe05fbb2012-05-16 10:56:26 -0700671 readl_relaxed(USB_PORTSC) & PORT_RESUME) {
Ajay Dudaniab3bf192012-08-28 09:58:04 -0700672 dev_dbg(mehci->dev, "wakeup pending, aborting suspend\n");
Jack Phambe05fbb2012-05-16 10:56:26 -0700673 enable_irq(hcd->irq);
674 return -EBUSY;
675 }
676
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530677 /*
678 * PHY may take some time or even fail to enter into low power
679 * mode (LPM). Hence poll for 500 msec and reset the PHY and link
680 * in failure case.
681 */
Hemant Kumar3dbc5b32012-05-09 15:36:11 -0700682 val = readl_relaxed(USB_PORTSC);
683 val &= ~PORT_RWC_BITS;
684 val |= PORTSC_PHCD;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530685 writel_relaxed(val, USB_PORTSC);
686 while (cnt < PHY_SUSPEND_TIMEOUT_USEC) {
687 if (readl_relaxed(USB_PORTSC) & PORTSC_PHCD)
688 break;
689 udelay(1);
690 cnt++;
691 }
692
693 if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) {
694 dev_err(mehci->dev, "Unable to suspend PHY\n");
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530695 msm_hsic_config_gpios(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530696 msm_hsic_reset(mehci);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530697 }
698
699 /*
700 * PHY has capability to generate interrupt asynchronously in low
701 * power mode (LPM). This interrupt is level triggered. So USB IRQ
702 * line must be disabled till async interrupt enable bit is cleared
703 * in USBCMD register. Assert STP (ULPI interface STOP signal) to
704 * block data communication from PHY.
705 */
706 writel_relaxed(readl_relaxed(USB_USBCMD) | ASYNC_INTR_CTRL |
707 ULPI_STP_CTRL, USB_USBCMD);
708
709 /*
710 * Ensure that hardware is put in low power mode before
711 * clocks are turned OFF and VDD is allowed to minimize.
712 */
713 mb();
714
Manu Gautam28b1bac2012-01-30 16:43:06 +0530715 clk_disable_unprepare(mehci->core_clk);
716 clk_disable_unprepare(mehci->phy_clk);
717 clk_disable_unprepare(mehci->cal_clk);
718 clk_disable_unprepare(mehci->ahb_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530719
Amit Blayd6ea6102012-06-07 16:26:24 +0300720 none_vol = vdd_val[mehci->vdd_type][VDD_NONE];
721 max_vol = vdd_val[mehci->vdd_type][VDD_MAX];
722
723 ret = regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol);
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700724 if (ret < 0)
Amit Blayd6ea6102012-06-07 16:26:24 +0300725 dev_err(mehci->dev, "unable to set vddcx voltage for VDD MIN\n");
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700726
Hemant Kumare6275972012-02-29 20:06:21 -0800727 if (mehci->bus_perf_client && debug_bus_voting_enabled) {
Hemant Kumar2309eaa2012-08-14 16:46:42 -0700728 mehci->bus_vote = false;
729 queue_work(ehci_wq, &mehci->bus_vote_w);
Hemant Kumare6275972012-02-29 20:06:21 -0800730 }
731
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530732 atomic_set(&mehci->in_lpm, 1);
733 enable_irq(hcd->irq);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700734
735 mehci->wakeup_irq_enabled = 1;
736 enable_irq_wake(mehci->wakeup_irq);
737 enable_irq(mehci->wakeup_irq);
738
Ajay Dudaniab3bf192012-08-28 09:58:04 -0700739 wake_unlock(&mehci->wlock);
740
Devin Kim476bbd72012-07-19 18:11:11 -0700741 dev_dbg(mehci->dev, "HSIC-USB in low power mode\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530742
743 return 0;
744}
745
746static int msm_hsic_resume(struct msm_hsic_hcd *mehci)
747{
748 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +0530749 int cnt = 0, ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530750 unsigned temp;
Amit Blayd6ea6102012-06-07 16:26:24 +0300751 int min_vol, max_vol;
Hemant Kumar4cd49e12012-09-06 19:57:14 -0700752 unsigned long flags;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530753
754 if (!atomic_read(&mehci->in_lpm)) {
755 dev_dbg(mehci->dev, "%s called in !in_lpm\n", __func__);
756 return 0;
757 }
758
Hemant Kumar4cd49e12012-09-06 19:57:14 -0700759 spin_lock_irqsave(&mehci->wakeup_lock, flags);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700760 if (mehci->wakeup_irq_enabled) {
761 disable_irq_wake(mehci->wakeup_irq);
762 disable_irq_nosync(mehci->wakeup_irq);
763 mehci->wakeup_irq_enabled = 0;
764 }
Hemant Kumar4cd49e12012-09-06 19:57:14 -0700765 spin_unlock_irqrestore(&mehci->wakeup_lock, flags);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700766
Ajay Dudaniab3bf192012-08-28 09:58:04 -0700767 wake_lock(&mehci->wlock);
768
Hemant Kumare6275972012-02-29 20:06:21 -0800769 if (mehci->bus_perf_client && debug_bus_voting_enabled) {
Hemant Kumar2309eaa2012-08-14 16:46:42 -0700770 mehci->bus_vote = true;
771 queue_work(ehci_wq, &mehci->bus_vote_w);
Hemant Kumare6275972012-02-29 20:06:21 -0800772 }
773
Amit Blayd6ea6102012-06-07 16:26:24 +0300774 min_vol = vdd_val[mehci->vdd_type][VDD_MIN];
775 max_vol = vdd_val[mehci->vdd_type][VDD_MAX];
776
777 ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol);
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700778 if (ret < 0)
Amit Blayd6ea6102012-06-07 16:26:24 +0300779 dev_err(mehci->dev, "unable to set nominal vddcx voltage (no VDD MIN)\n");
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700780
Manu Gautam28b1bac2012-01-30 16:43:06 +0530781 clk_prepare_enable(mehci->core_clk);
782 clk_prepare_enable(mehci->phy_clk);
783 clk_prepare_enable(mehci->cal_clk);
784 clk_prepare_enable(mehci->ahb_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530785
786 temp = readl_relaxed(USB_USBCMD);
787 temp &= ~ASYNC_INTR_CTRL;
788 temp &= ~ULPI_STP_CTRL;
789 writel_relaxed(temp, USB_USBCMD);
790
791 if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD))
792 goto skip_phy_resume;
793
Hemant Kumar3dbc5b32012-05-09 15:36:11 -0700794 temp = readl_relaxed(USB_PORTSC);
795 temp &= ~(PORT_RWC_BITS | PORTSC_PHCD);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530796 writel_relaxed(temp, USB_PORTSC);
797 while (cnt < PHY_RESUME_TIMEOUT_USEC) {
798 if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD) &&
799 (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_SYNC_STATE))
800 break;
801 udelay(1);
802 cnt++;
803 }
804
805 if (cnt >= PHY_RESUME_TIMEOUT_USEC) {
806 /*
807 * This is a fatal error. Reset the link and
808 * PHY to make hsic working.
809 */
810 dev_err(mehci->dev, "Unable to resume USB. Reset the hsic\n");
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530811 msm_hsic_config_gpios(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530812 msm_hsic_reset(mehci);
813 }
814
815skip_phy_resume:
816
Hemant Kumar6fd65032012-05-23 13:02:24 -0700817 usb_hcd_resume_root_hub(hcd);
818
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530819 atomic_set(&mehci->in_lpm, 0);
820
821 if (mehci->async_int) {
822 mehci->async_int = false;
823 pm_runtime_put_noidle(mehci->dev);
Jack Phamdd5ad792012-07-26 10:31:03 -0700824 enable_irq(hcd->irq);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700825 }
826
Ajay Dudaniab3bf192012-08-28 09:58:04 -0700827 if (atomic_read(&mehci->pm_usage_cnt)) {
828 atomic_set(&mehci->pm_usage_cnt, 0);
829 pm_runtime_put_noidle(mehci->dev);
830 }
Jack Phamdd5ad792012-07-26 10:31:03 -0700831
Devin Kim476bbd72012-07-19 18:11:11 -0700832 dev_dbg(mehci->dev, "HSIC-USB exited from low power mode\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530833
834 return 0;
835}
836#endif
837
Hemant Kumar2309eaa2012-08-14 16:46:42 -0700838static void ehci_hsic_bus_vote_w(struct work_struct *w)
839{
840 struct msm_hsic_hcd *mehci =
841 container_of(w, struct msm_hsic_hcd, bus_vote_w);
842 int ret;
843
844 ret = msm_bus_scale_client_update_request(mehci->bus_perf_client,
845 mehci->bus_vote);
846 if (ret)
847 dev_err(mehci->dev, "%s: Failed to vote for bus bandwidth %d\n",
848 __func__, ret);
849}
850
Ajay Dudani11ab1d52012-08-17 17:12:26 -0700851#define STS_GPTIMER0_INTERRUPT BIT(24)
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530852static irqreturn_t msm_hsic_irq(struct usb_hcd *hcd)
853{
Ajay Dudani11ab1d52012-08-17 17:12:26 -0700854 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530855 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
Ajay Dudani11ab1d52012-08-17 17:12:26 -0700856 u32 status;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530857
858 if (atomic_read(&mehci->in_lpm)) {
859 disable_irq_nosync(hcd->irq);
Hemant Kumar3dbc5b32012-05-09 15:36:11 -0700860 dev_dbg(mehci->dev, "phy async intr\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530861 mehci->async_int = true;
862 pm_runtime_get(mehci->dev);
863 return IRQ_HANDLED;
864 }
865
Ajay Dudani11ab1d52012-08-17 17:12:26 -0700866 status = ehci_readl(ehci, &ehci->regs->status);
867
868 if (status & STS_GPTIMER0_INTERRUPT) {
869 int timeleft;
870
871 dbg_log_event(NULL, "FPR: gpt0_isr", 0);
872
873 timeleft = GPT_CNT(ehci_readl(ehci,
874 &mehci->timer->gptimer1_ctrl));
875 if (timeleft) {
876 ehci_writel(ehci, ehci_readl(ehci,
877 &ehci->regs->command) | CMD_RUN,
878 &ehci->regs->command);
879 } else
880 mehci->resume_again = 1;
881
882 dbg_log_event(NULL, "FPR: timeleft", timeleft);
883
884 complete(&mehci->gpt0_completion);
885 ehci_writel(ehci, STS_GPTIMER0_INTERRUPT, &ehci->regs->status);
886 }
887
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530888 return ehci_irq(hcd);
889}
890
891static int ehci_hsic_reset(struct usb_hcd *hcd)
892{
893 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Ajay Dudani11ab1d52012-08-17 17:12:26 -0700894 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530895 int retval;
896
Ajay Dudani11ab1d52012-08-17 17:12:26 -0700897 mehci->timer = USB_HS_GPTIMER_BASE;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530898 ehci->caps = USB_CAPLENGTH;
899 ehci->regs = USB_CAPLENGTH +
900 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
901 dbg_hcs_params(ehci, "reset");
902 dbg_hcc_params(ehci, "reset");
903
904 /* cache the data to minimize the chip reads*/
905 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
906
907 hcd->has_tt = 1;
908 ehci->sbrn = HCD_USB2;
909
910 retval = ehci_halt(ehci);
911 if (retval)
912 return retval;
913
914 /* data structure init */
915 retval = ehci_init(hcd);
916 if (retval)
917 return retval;
918
919 retval = ehci_reset(ehci);
920 if (retval)
921 return retval;
922
923 /* bursts of unspecified length. */
924 writel_relaxed(0, USB_AHBBURST);
925 /* Use the AHB transactor */
Vijayavardhan Vennapusa5f32d7a2012-03-14 16:30:26 +0530926 writel_relaxed(0x08, USB_AHBMODE);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530927 /* Disable streaming mode and select host mode */
928 writel_relaxed(0x13, USB_USBMODE);
929
930 ehci_port_power(ehci, 1);
931 return 0;
932}
933
Hemant Kumar45d211b2012-05-31 17:58:43 -0700934static int ehci_hsic_bus_suspend(struct usb_hcd *hcd)
935{
936 dbg_log_event(NULL, "Suspend RH", 0);
937 return ehci_bus_suspend(hcd);
938}
939
Ajay Dudani11ab1d52012-08-17 17:12:26 -0700940#define RESUME_RETRY_LIMIT 3
941#define RESUME_SIGNAL_TIME_MS (21 * 999)
942#define RESUME_SIGNAL_TIME_SOF_MS (23 * 999)
943static int msm_hsic_resume_thread(void *data)
944{
945 struct msm_hsic_hcd *mehci = data;
946 struct usb_hcd *hcd = hsic_to_hcd(mehci);
947 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
948 u32 temp;
949 unsigned long resume_needed = 0;
950 int retry_cnt = 0;
951 int tight_resume = 0;
Pavankumar Kondetife2d4d32012-09-07 15:33:09 +0530952 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
Ajay Dudani11ab1d52012-08-17 17:12:26 -0700953
954 dbg_log_event(NULL, "Resume RH", 0);
955
956 /* keep delay between bus states */
957 if (time_before(jiffies, ehci->next_statechange))
958 usleep_range(5000, 5000);
959
960 spin_lock_irq(&ehci->lock);
961 if (!HCD_HW_ACCESSIBLE(hcd)) {
962 spin_unlock_irq(&ehci->lock);
963 mehci->resume_status = -ESHUTDOWN;
964 complete(&mehci->rt_completion);
965 return 0;
966 }
967
968 if (unlikely(ehci->debug)) {
969 if (!dbgp_reset_prep())
970 ehci->debug = NULL;
971 else
972 dbgp_external_startup();
973 }
974
975 /* at least some APM implementations will try to deliver
976 * IRQs right away, so delay them until we're ready.
977 */
978 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
979
980 /* re-init operational registers */
981 ehci_writel(ehci, 0, &ehci->regs->segment);
982 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
983 ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
984
985 /*CMD_RUN will be set after, PORT_RESUME gets cleared*/
986 if (ehci->resume_sof_bug)
987 ehci->command &= ~CMD_RUN;
988
989 /* restore CMD_RUN, framelist size, and irq threshold */
990 ehci_writel(ehci, ehci->command, &ehci->regs->command);
991
992 /* manually resume the ports we suspended during bus_suspend() */
993resume_again:
994 if (retry_cnt >= RESUME_RETRY_LIMIT) {
995 pr_info("retry count(%d) reached max, resume in tight loop\n",
996 retry_cnt);
997 tight_resume = 1;
998 }
999
1000
1001 temp = ehci_readl(ehci, &ehci->regs->port_status[0]);
1002 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
1003 if (test_bit(0, &ehci->bus_suspended) && (temp & PORT_SUSPEND)) {
1004 temp |= PORT_RESUME;
1005 set_bit(0, &resume_needed);
1006 }
1007 dbg_log_event(NULL, "FPR: Set", temp);
1008 ehci_writel(ehci, temp, &ehci->regs->port_status[0]);
1009
1010 /* HSIC controller has a h/w bug due to which it can try to send SOFs
1011 * (start of frames) during port resume resulting in phy lockup. HSIC hw
1012 * controller in MSM clears FPR bit after driving the resume signal for
1013 * 20ms. Workaround is to stop SOFs before driving resume and then start
1014 * sending SOFs immediately. Need to send SOFs within 3ms of resume
1015 * completion otherwise peripheral may enter undefined state. As
1016 * usleep_range does not gurantee exact sleep time, GPTimer is used to
1017 * to time the resume sequence. If driver exceeds allowable time SOFs,
1018 * repeat the resume process.
1019 */
1020 if (ehci->resume_sof_bug && resume_needed) {
1021 if (!tight_resume) {
1022 mehci->resume_again = 0;
1023 ehci_writel(ehci, GPT_LD(RESUME_SIGNAL_TIME_MS),
1024 &mehci->timer->gptimer0_ld);
1025 ehci_writel(ehci, GPT_RESET | GPT_RUN,
1026 &mehci->timer->gptimer0_ctrl);
1027 ehci_writel(ehci, INTR_MASK | STS_GPTIMER0_INTERRUPT,
1028 &ehci->regs->intr_enable);
1029
1030 ehci_writel(ehci, GPT_LD(RESUME_SIGNAL_TIME_SOF_MS),
1031 &mehci->timer->gptimer1_ld);
1032 ehci_writel(ehci, GPT_RESET | GPT_RUN,
1033 &mehci->timer->gptimer1_ctrl);
1034
1035 spin_unlock_irq(&ehci->lock);
Pavankumar Kondetife2d4d32012-09-07 15:33:09 +05301036 if (pdata && pdata->swfi_latency)
1037 pm_qos_update_request(&mehci->pm_qos_req_dma,
1038 pdata->swfi_latency + 1);
Ajay Dudani11ab1d52012-08-17 17:12:26 -07001039 wait_for_completion(&mehci->gpt0_completion);
Pavankumar Kondetife2d4d32012-09-07 15:33:09 +05301040 if (pdata && pdata->swfi_latency)
1041 pm_qos_update_request(&mehci->pm_qos_req_dma,
1042 PM_QOS_DEFAULT_VALUE);
Ajay Dudani11ab1d52012-08-17 17:12:26 -07001043 spin_lock_irq(&ehci->lock);
1044 } else {
1045 dbg_log_event(NULL, "FPR: Tightloop", 0);
1046 /* do the resume in a tight loop */
1047 handshake(ehci, &ehci->regs->port_status[0],
1048 PORT_RESUME, 0, 22 * 1000);
1049 ehci_writel(ehci, ehci_readl(ehci,
1050 &ehci->regs->command) | CMD_RUN,
1051 &ehci->regs->command);
1052 }
1053
1054 if (mehci->resume_again) {
1055 int temp;
1056
1057 dbg_log_event(NULL, "FPR: Re-Resume", retry_cnt);
1058 pr_info("FPR: retry count: %d\n", retry_cnt);
1059 spin_unlock_irq(&ehci->lock);
1060 temp = ehci_readl(ehci, &ehci->regs->port_status[0]);
1061 temp &= ~PORT_RWC_BITS;
1062 temp |= PORT_SUSPEND;
1063 ehci_writel(ehci, temp, &ehci->regs->port_status[0]);
1064 /* Keep the bus idle for 5ms so that peripheral
1065 * can detect and initiate suspend
1066 */
1067 usleep_range(5000, 5000);
1068 dbg_log_event(NULL,
1069 "FPR: RResume",
1070 ehci_readl(ehci, &ehci->regs->port_status[0]));
1071 spin_lock_irq(&ehci->lock);
1072 mehci->resume_again = 0;
1073 retry_cnt++;
1074 goto resume_again;
1075 }
1076 }
1077
1078 dbg_log_event(NULL, "FPR: RT-Done", 0);
1079 mehci->resume_status = 1;
1080 spin_unlock_irq(&ehci->lock);
1081
1082 complete(&mehci->rt_completion);
1083
1084 return 0;
1085}
1086
Hemant Kumar45d211b2012-05-31 17:58:43 -07001087static int ehci_hsic_bus_resume(struct usb_hcd *hcd)
1088{
Ajay Dudani11ab1d52012-08-17 17:12:26 -07001089 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1090 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1091 u32 temp;
1092 struct task_struct *resume_thread = NULL;
1093
1094 mehci->resume_status = 0;
1095 resume_thread = kthread_run(msm_hsic_resume_thread,
1096 mehci, "hsic_resume_thread");
1097 if (IS_ERR(resume_thread)) {
1098 pr_err("Error creating resume thread:%lu\n",
1099 PTR_ERR(resume_thread));
1100 return PTR_ERR(resume_thread);
1101 }
1102
1103 wait_for_completion(&mehci->rt_completion);
1104
1105 if (mehci->resume_status < 0)
1106 return mehci->resume_status;
1107
1108 dbg_log_event(NULL, "FPR: Wokeup", 0);
1109 spin_lock_irq(&ehci->lock);
1110 (void) ehci_readl(ehci, &ehci->regs->command);
1111
1112 temp = 0;
1113 if (ehci->async->qh_next.qh)
1114 temp |= CMD_ASE;
1115 if (ehci->periodic_sched)
1116 temp |= CMD_PSE;
1117 if (temp) {
1118 ehci->command |= temp;
1119 ehci_writel(ehci, ehci->command, &ehci->regs->command);
1120 }
1121
1122 ehci->next_statechange = jiffies + msecs_to_jiffies(5);
1123 hcd->state = HC_STATE_RUNNING;
1124 ehci->rh_state = EHCI_RH_RUNNING;
1125
1126 /* Now we can safely re-enable irqs */
1127 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
1128
1129 spin_unlock_irq(&ehci->lock);
1130
1131 return 0;
Hemant Kumar45d211b2012-05-31 17:58:43 -07001132}
1133
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301134static struct hc_driver msm_hsic_driver = {
1135 .description = hcd_name,
1136 .product_desc = "Qualcomm EHCI Host Controller using HSIC",
1137 .hcd_priv_size = sizeof(struct msm_hsic_hcd),
1138
1139 /*
1140 * generic hardware linkage
1141 */
1142 .irq = msm_hsic_irq,
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -07001143 .flags = HCD_USB2 | HCD_MEMORY | HCD_OLD_ENUM,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301144
1145 .reset = ehci_hsic_reset,
1146 .start = ehci_run,
1147
1148 .stop = ehci_stop,
1149 .shutdown = ehci_shutdown,
1150
1151 /*
1152 * managing i/o requests and associated device resources
1153 */
Hemant Kumardf2d84d2012-08-15 09:06:35 -07001154 .urb_enqueue = ehci_urb_enqueue,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301155 .urb_dequeue = ehci_urb_dequeue,
1156 .endpoint_disable = ehci_endpoint_disable,
1157 .endpoint_reset = ehci_endpoint_reset,
1158 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
1159
1160 /*
1161 * scheduling support
1162 */
1163 .get_frame_number = ehci_get_frame,
1164
1165 /*
1166 * root hub support
1167 */
1168 .hub_status_data = ehci_hub_status_data,
1169 .hub_control = ehci_hub_control,
1170 .relinquish_port = ehci_relinquish_port,
1171 .port_handed_over = ehci_port_handed_over,
1172
1173 /*
1174 * PM support
1175 */
Hemant Kumar45d211b2012-05-31 17:58:43 -07001176 .bus_suspend = ehci_hsic_bus_suspend,
1177 .bus_resume = ehci_hsic_bus_resume,
1178
Hemant Kumardf2d84d2012-08-15 09:06:35 -07001179 .log_urb = dbg_log_event,
Hemant Kumar105d07f2012-07-02 15:33:07 -07001180 .dump_regs = dump_hsic_regs,
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -07001181
1182 .enable_ulpi_control = ehci_msm_enable_ulpi_control,
1183 .disable_ulpi_control = ehci_msm_disable_ulpi_control,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301184};
1185
1186static int msm_hsic_init_clocks(struct msm_hsic_hcd *mehci, u32 init)
1187{
1188 int ret = 0;
1189
1190 if (!init)
1191 goto put_clocks;
1192
Lena Salman8c8ba382012-02-14 15:59:31 +02001193 /*core_clk is required for LINK protocol engine
1194 *clock rate appropriately set by target specific clock driver */
Manu Gautam5143b252012-01-05 19:25:23 -08001195 mehci->core_clk = clk_get(mehci->dev, "core_clk");
1196 if (IS_ERR(mehci->core_clk)) {
1197 dev_err(mehci->dev, "failed to get core_clk\n");
1198 ret = PTR_ERR(mehci->core_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301199 return ret;
1200 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301201
Lena Salman8c8ba382012-02-14 15:59:31 +02001202 /* alt_core_clk is for LINK to be used during PHY RESET
1203 * clock rate appropriately set by target specific clock driver */
Manu Gautam5143b252012-01-05 19:25:23 -08001204 mehci->alt_core_clk = clk_get(mehci->dev, "alt_core_clk");
1205 if (IS_ERR(mehci->alt_core_clk)) {
1206 dev_err(mehci->dev, "failed to core_clk\n");
1207 ret = PTR_ERR(mehci->alt_core_clk);
1208 goto put_core_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301209 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301210
Lena Salman8c8ba382012-02-14 15:59:31 +02001211 /* phy_clk is required for HSIC PHY operation
1212 * clock rate appropriately set by target specific clock driver */
Manu Gautam5143b252012-01-05 19:25:23 -08001213 mehci->phy_clk = clk_get(mehci->dev, "phy_clk");
1214 if (IS_ERR(mehci->phy_clk)) {
1215 dev_err(mehci->dev, "failed to get phy_clk\n");
1216 ret = PTR_ERR(mehci->phy_clk);
1217 goto put_alt_core_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301218 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301219
1220 /* 10MHz cal_clk is required for calibration of I/O pads */
Manu Gautam5143b252012-01-05 19:25:23 -08001221 mehci->cal_clk = clk_get(mehci->dev, "cal_clk");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301222 if (IS_ERR(mehci->cal_clk)) {
Manu Gautam5143b252012-01-05 19:25:23 -08001223 dev_err(mehci->dev, "failed to get cal_clk\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301224 ret = PTR_ERR(mehci->cal_clk);
Manu Gautam5143b252012-01-05 19:25:23 -08001225 goto put_phy_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301226 }
1227 clk_set_rate(mehci->cal_clk, 10000000);
1228
1229 /* ahb_clk is required for data transfers */
Manu Gautam5143b252012-01-05 19:25:23 -08001230 mehci->ahb_clk = clk_get(mehci->dev, "iface_clk");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301231 if (IS_ERR(mehci->ahb_clk)) {
Manu Gautam5143b252012-01-05 19:25:23 -08001232 dev_err(mehci->dev, "failed to get iface_clk\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301233 ret = PTR_ERR(mehci->ahb_clk);
1234 goto put_cal_clk;
1235 }
1236
Manu Gautam28b1bac2012-01-30 16:43:06 +05301237 clk_prepare_enable(mehci->core_clk);
1238 clk_prepare_enable(mehci->phy_clk);
1239 clk_prepare_enable(mehci->cal_clk);
1240 clk_prepare_enable(mehci->ahb_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301241
1242 return 0;
1243
1244put_clocks:
Jack Phamfd193eb2012-02-22 15:38:08 -08001245 if (!atomic_read(&mehci->in_lpm)) {
1246 clk_disable_unprepare(mehci->core_clk);
1247 clk_disable_unprepare(mehci->phy_clk);
1248 clk_disable_unprepare(mehci->cal_clk);
1249 clk_disable_unprepare(mehci->ahb_clk);
1250 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301251 clk_put(mehci->ahb_clk);
1252put_cal_clk:
1253 clk_put(mehci->cal_clk);
Manu Gautam5143b252012-01-05 19:25:23 -08001254put_phy_clk:
1255 clk_put(mehci->phy_clk);
1256put_alt_core_clk:
1257 clk_put(mehci->alt_core_clk);
1258put_core_clk:
1259 clk_put(mehci->core_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301260
1261 return ret;
1262}
Vamsi Krishna34f01582011-12-14 19:54:42 -08001263static irqreturn_t hsic_peripheral_status_change(int irq, void *dev_id)
1264{
1265 struct msm_hsic_hcd *mehci = dev_id;
1266
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001267 pr_debug("%s: mehci:%p dev_id:%p\n", __func__, mehci, dev_id);
Vamsi Krishna34f01582011-12-14 19:54:42 -08001268
1269 if (mehci)
1270 msm_hsic_config_gpios(mehci, 0);
1271
1272 return IRQ_HANDLED;
1273}
1274
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001275static irqreturn_t msm_hsic_wakeup_irq(int irq, void *data)
1276{
1277 struct msm_hsic_hcd *mehci = data;
1278
Hemant Kumar6fd65032012-05-23 13:02:24 -07001279 mehci->wakeup_int_cnt++;
Hemant Kumar45d211b2012-05-31 17:58:43 -07001280 dbg_log_event(NULL, "Remote Wakeup IRQ", mehci->wakeup_int_cnt);
Hemant Kumar6fd65032012-05-23 13:02:24 -07001281 dev_dbg(mehci->dev, "%s: hsic remote wakeup interrupt cnt: %u\n",
1282 __func__, mehci->wakeup_int_cnt);
1283
Ajay Dudaniab3bf192012-08-28 09:58:04 -07001284 wake_lock(&mehci->wlock);
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001285
Hemant Kumar4cd49e12012-09-06 19:57:14 -07001286 spin_lock(&mehci->wakeup_lock);
Jack Phamfe441ea2012-03-23 17:03:15 -07001287 if (mehci->wakeup_irq_enabled) {
1288 mehci->wakeup_irq_enabled = 0;
1289 disable_irq_wake(irq);
1290 disable_irq_nosync(irq);
1291 }
Hemant Kumar4cd49e12012-09-06 19:57:14 -07001292 spin_unlock(&mehci->wakeup_lock);
Jack Phamfe441ea2012-03-23 17:03:15 -07001293
Ajay Dudaniab3bf192012-08-28 09:58:04 -07001294 if (!atomic_read(&mehci->pm_usage_cnt)) {
1295 atomic_set(&mehci->pm_usage_cnt, 1);
1296 pm_runtime_get(mehci->dev);
1297 }
1298
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001299 return IRQ_HANDLED;
1300}
1301
Hemant Kumare6275972012-02-29 20:06:21 -08001302static int ehci_hsic_msm_bus_show(struct seq_file *s, void *unused)
1303{
1304 if (debug_bus_voting_enabled)
1305 seq_printf(s, "enabled\n");
1306 else
1307 seq_printf(s, "disabled\n");
1308
1309 return 0;
1310}
1311
1312static int ehci_hsic_msm_bus_open(struct inode *inode, struct file *file)
1313{
1314 return single_open(file, ehci_hsic_msm_bus_show, inode->i_private);
1315}
1316
1317static ssize_t ehci_hsic_msm_bus_write(struct file *file,
1318 const char __user *ubuf, size_t count, loff_t *ppos)
1319{
1320 char buf[8];
1321 int ret;
1322 struct seq_file *s = file->private_data;
1323 struct msm_hsic_hcd *mehci = s->private;
1324
1325 memset(buf, 0x00, sizeof(buf));
1326
1327 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
1328 return -EFAULT;
1329
1330 if (!strncmp(buf, "enable", 6)) {
1331 /* Do not vote here. Let hsic driver decide when to vote */
1332 debug_bus_voting_enabled = true;
1333 } else {
1334 debug_bus_voting_enabled = false;
1335 if (mehci->bus_perf_client) {
1336 ret = msm_bus_scale_client_update_request(
1337 mehci->bus_perf_client, 0);
1338 if (ret)
1339 dev_err(mehci->dev, "%s: Failed to devote "
1340 "for bus bw %d\n", __func__, ret);
1341 }
1342 }
1343
1344 return count;
1345}
1346
1347const struct file_operations ehci_hsic_msm_bus_fops = {
1348 .open = ehci_hsic_msm_bus_open,
1349 .read = seq_read,
1350 .write = ehci_hsic_msm_bus_write,
1351 .llseek = seq_lseek,
1352 .release = single_release,
1353};
1354
Hemant Kumar6fd65032012-05-23 13:02:24 -07001355static int ehci_hsic_msm_wakeup_cnt_show(struct seq_file *s, void *unused)
1356{
1357 struct msm_hsic_hcd *mehci = s->private;
1358
1359 seq_printf(s, "%u\n", mehci->wakeup_int_cnt);
1360
1361 return 0;
1362}
1363
1364static int ehci_hsic_msm_wakeup_cnt_open(struct inode *inode, struct file *f)
1365{
1366 return single_open(f, ehci_hsic_msm_wakeup_cnt_show, inode->i_private);
1367}
1368
1369const struct file_operations ehci_hsic_msm_wakeup_cnt_fops = {
1370 .open = ehci_hsic_msm_wakeup_cnt_open,
1371 .read = seq_read,
1372 .llseek = seq_lseek,
1373 .release = single_release,
1374};
1375
Hemant Kumar45d211b2012-05-31 17:58:43 -07001376static int ehci_hsic_msm_data_events_show(struct seq_file *s, void *unused)
1377{
1378 unsigned long flags;
1379 unsigned i;
1380
1381 read_lock_irqsave(&dbg_hsic_data.lck, flags);
1382
1383 i = dbg_hsic_data.idx;
1384 for (dbg_inc(&i); i != dbg_hsic_data.idx; dbg_inc(&i)) {
1385 if (!strnlen(dbg_hsic_data.buf[i], DBG_MSG_LEN))
1386 continue;
1387 seq_printf(s, "%s\n", dbg_hsic_data.buf[i]);
1388 }
1389
1390 read_unlock_irqrestore(&dbg_hsic_data.lck, flags);
1391
1392 return 0;
1393}
1394
1395static int ehci_hsic_msm_data_events_open(struct inode *inode, struct file *f)
1396{
1397 return single_open(f, ehci_hsic_msm_data_events_show, inode->i_private);
1398}
1399
1400const struct file_operations ehci_hsic_msm_dbg_data_fops = {
1401 .open = ehci_hsic_msm_data_events_open,
1402 .read = seq_read,
1403 .llseek = seq_lseek,
1404 .release = single_release,
1405};
1406
1407static int ehci_hsic_msm_ctrl_events_show(struct seq_file *s, void *unused)
1408{
1409 unsigned long flags;
1410 unsigned i;
1411
1412 read_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
1413
1414 i = dbg_hsic_ctrl.idx;
1415 for (dbg_inc(&i); i != dbg_hsic_ctrl.idx; dbg_inc(&i)) {
1416 if (!strnlen(dbg_hsic_ctrl.buf[i], DBG_MSG_LEN))
1417 continue;
1418 seq_printf(s, "%s\n", dbg_hsic_ctrl.buf[i]);
1419 }
1420
1421 read_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags);
1422
1423 return 0;
1424}
1425
1426static int ehci_hsic_msm_ctrl_events_open(struct inode *inode, struct file *f)
1427{
1428 return single_open(f, ehci_hsic_msm_ctrl_events_show, inode->i_private);
1429}
1430
1431const struct file_operations ehci_hsic_msm_dbg_ctrl_fops = {
1432 .open = ehci_hsic_msm_ctrl_events_open,
1433 .read = seq_read,
1434 .llseek = seq_lseek,
1435 .release = single_release,
1436};
1437
Hemant Kumare6275972012-02-29 20:06:21 -08001438static struct dentry *ehci_hsic_msm_dbg_root;
1439static int ehci_hsic_msm_debugfs_init(struct msm_hsic_hcd *mehci)
1440{
1441 struct dentry *ehci_hsic_msm_dentry;
1442
1443 ehci_hsic_msm_dbg_root = debugfs_create_dir("ehci_hsic_msm_dbg", NULL);
1444
1445 if (!ehci_hsic_msm_dbg_root || IS_ERR(ehci_hsic_msm_dbg_root))
1446 return -ENODEV;
1447
1448 ehci_hsic_msm_dentry = debugfs_create_file("bus_voting",
1449 S_IRUGO | S_IWUSR,
1450 ehci_hsic_msm_dbg_root, mehci,
1451 &ehci_hsic_msm_bus_fops);
1452
1453 if (!ehci_hsic_msm_dentry) {
1454 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1455 return -ENODEV;
1456 }
1457
Hemant Kumar6fd65032012-05-23 13:02:24 -07001458 ehci_hsic_msm_dentry = debugfs_create_file("wakeup_cnt",
1459 S_IRUGO,
1460 ehci_hsic_msm_dbg_root, mehci,
1461 &ehci_hsic_msm_wakeup_cnt_fops);
1462
1463 if (!ehci_hsic_msm_dentry) {
1464 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1465 return -ENODEV;
1466 }
1467
Hemant Kumar45d211b2012-05-31 17:58:43 -07001468 ehci_hsic_msm_dentry = debugfs_create_file("show_ctrl_events",
1469 S_IRUGO,
1470 ehci_hsic_msm_dbg_root, mehci,
1471 &ehci_hsic_msm_dbg_ctrl_fops);
1472
1473 if (!ehci_hsic_msm_dentry) {
1474 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1475 return -ENODEV;
1476 }
1477
1478 ehci_hsic_msm_dentry = debugfs_create_file("show_data_events",
1479 S_IRUGO,
1480 ehci_hsic_msm_dbg_root, mehci,
1481 &ehci_hsic_msm_dbg_data_fops);
1482
1483 if (!ehci_hsic_msm_dentry) {
1484 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1485 return -ENODEV;
1486 }
1487
Hemant Kumare6275972012-02-29 20:06:21 -08001488 return 0;
1489}
1490
1491static void ehci_hsic_msm_debugfs_cleanup(void)
1492{
1493 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1494}
1495
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301496static int __devinit ehci_hsic_msm_probe(struct platform_device *pdev)
1497{
1498 struct usb_hcd *hcd;
1499 struct resource *res;
1500 struct msm_hsic_hcd *mehci;
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +05301501 struct msm_hsic_host_platform_data *pdata;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301502 int ret;
1503
1504 dev_dbg(&pdev->dev, "ehci_msm-hsic probe\n");
1505
Vijayavardhan Vennapusaafbbb8f2012-04-13 16:28:45 +05301506 /* After parent device's probe is executed, it will be put in suspend
1507 * mode. When child device's probe is called, driver core is not
1508 * resuming parent device due to which parent will be in suspend even
1509 * though child is active. Hence resume the parent device explicitly.
1510 */
1511 if (pdev->dev.parent)
1512 pm_runtime_get_sync(pdev->dev.parent);
1513
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301514 hcd = usb_create_hcd(&msm_hsic_driver, &pdev->dev,
1515 dev_name(&pdev->dev));
1516 if (!hcd) {
1517 dev_err(&pdev->dev, "Unable to create HCD\n");
1518 return -ENOMEM;
1519 }
1520
Pavankumar Kondeti1c851692012-09-18 17:52:51 +05301521 hcd_to_bus(hcd)->skip_resume = true;
1522
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301523 hcd->irq = platform_get_irq(pdev, 0);
1524 if (hcd->irq < 0) {
1525 dev_err(&pdev->dev, "Unable to get IRQ resource\n");
1526 ret = hcd->irq;
1527 goto put_hcd;
1528 }
1529
1530 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1531 if (!res) {
1532 dev_err(&pdev->dev, "Unable to get memory resource\n");
1533 ret = -ENODEV;
1534 goto put_hcd;
1535 }
1536
1537 hcd->rsrc_start = res->start;
1538 hcd->rsrc_len = resource_size(res);
1539 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
1540 if (!hcd->regs) {
1541 dev_err(&pdev->dev, "ioremap failed\n");
1542 ret = -ENOMEM;
1543 goto put_hcd;
1544 }
1545
1546 mehci = hcd_to_hsic(hcd);
1547 mehci->dev = &pdev->dev;
Ajay Dudanic4e40db2012-08-20 14:44:40 -07001548 pdata = mehci->dev->platform_data;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301549
Hemant Kumar4cd49e12012-09-06 19:57:14 -07001550 spin_lock_init(&mehci->wakeup_lock);
1551
Hemant Kumar38ce5d82012-05-29 13:00:58 -07001552 mehci->ehci.susp_sof_bug = 1;
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -07001553 mehci->ehci.reset_sof_bug = 1;
Hemant Kumar38ce5d82012-05-29 13:00:58 -07001554
Hemant Kumare4040492012-06-21 17:35:42 -07001555 mehci->ehci.resume_sof_bug = 1;
1556
Ajay Dudanic4e40db2012-08-20 14:44:40 -07001557 if (pdata)
1558 mehci->ehci.log2_irq_thresh = pdata->log2_irq_thresh;
Hemant Kumar933e0402012-05-22 11:11:40 -07001559
Vamsi Krishna34f01582011-12-14 19:54:42 -08001560 res = platform_get_resource_byname(pdev,
1561 IORESOURCE_IRQ,
1562 "peripheral_status_irq");
1563 if (res)
1564 mehci->peripheral_status_irq = res->start;
1565
Hemant Kumar6fd65032012-05-23 13:02:24 -07001566 res = platform_get_resource_byname(pdev, IORESOURCE_IO, "wakeup");
1567 if (res) {
1568 mehci->wakeup_gpio = res->start;
1569 mehci->wakeup_irq = MSM_GPIO_TO_INT(res->start);
1570 dev_dbg(mehci->dev, "wakeup_irq: %d\n", mehci->wakeup_irq);
1571 }
1572
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301573 ret = msm_hsic_init_clocks(mehci, 1);
1574 if (ret) {
1575 dev_err(&pdev->dev, "unable to initialize clocks\n");
1576 ret = -ENODEV;
1577 goto unmap;
1578 }
1579
1580 ret = msm_hsic_init_vddcx(mehci, 1);
1581 if (ret) {
1582 dev_err(&pdev->dev, "unable to initialize VDDCX\n");
1583 ret = -ENODEV;
1584 goto deinit_clocks;
1585 }
1586
Ajay Dudani11ab1d52012-08-17 17:12:26 -07001587 init_completion(&mehci->rt_completion);
1588 init_completion(&mehci->gpt0_completion);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301589 ret = msm_hsic_reset(mehci);
1590 if (ret) {
1591 dev_err(&pdev->dev, "unable to initialize PHY\n");
Vijayavardhan Vennapusaafbbb8f2012-04-13 16:28:45 +05301592 goto deinit_vddcx;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301593 }
1594
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001595 ehci_wq = create_singlethread_workqueue("ehci_wq");
1596 if (!ehci_wq) {
1597 dev_err(&pdev->dev, "unable to create workqueue\n");
1598 ret = -ENOMEM;
1599 goto deinit_vddcx;
1600 }
1601
1602 INIT_WORK(&mehci->bus_vote_w, ehci_hsic_bus_vote_w);
1603
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301604 ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
1605 if (ret) {
1606 dev_err(&pdev->dev, "unable to register HCD\n");
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +05301607 goto unconfig_gpio;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301608 }
1609
1610 device_init_wakeup(&pdev->dev, 1);
Ajay Dudaniab3bf192012-08-28 09:58:04 -07001611 wake_lock_init(&mehci->wlock, WAKE_LOCK_SUSPEND, dev_name(&pdev->dev));
1612 wake_lock(&mehci->wlock);
Vamsi Krishna34f01582011-12-14 19:54:42 -08001613
1614 if (mehci->peripheral_status_irq) {
1615 ret = request_threaded_irq(mehci->peripheral_status_irq,
1616 NULL, hsic_peripheral_status_change,
1617 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
1618 | IRQF_SHARED,
1619 "hsic_peripheral_status", mehci);
1620 if (ret)
1621 dev_err(&pdev->dev, "%s:request_irq:%d failed:%d",
1622 __func__, mehci->peripheral_status_irq, ret);
1623 }
1624
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001625 /* configure wakeup irq */
Hemant Kumar6fd65032012-05-23 13:02:24 -07001626 if (mehci->wakeup_irq) {
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001627 ret = request_irq(mehci->wakeup_irq, msm_hsic_wakeup_irq,
Hemant Kumar6fd65032012-05-23 13:02:24 -07001628 IRQF_TRIGGER_HIGH,
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001629 "msm_hsic_wakeup", mehci);
1630 if (!ret) {
1631 disable_irq_nosync(mehci->wakeup_irq);
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001632 } else {
1633 dev_err(&pdev->dev, "request_irq(%d) failed: %d\n",
1634 mehci->wakeup_irq, ret);
1635 mehci->wakeup_irq = 0;
1636 }
1637 }
1638
Hemant Kumare6275972012-02-29 20:06:21 -08001639 ret = ehci_hsic_msm_debugfs_init(mehci);
1640 if (ret)
1641 dev_dbg(&pdev->dev, "mode debugfs file is"
1642 "not available\n");
1643
1644 if (pdata && pdata->bus_scale_table) {
1645 mehci->bus_perf_client =
1646 msm_bus_scale_register_client(pdata->bus_scale_table);
1647 /* Configure BUS performance parameters for MAX bandwidth */
1648 if (mehci->bus_perf_client) {
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001649 mehci->bus_vote = true;
1650 queue_work(ehci_wq, &mehci->bus_vote_w);
Hemant Kumare6275972012-02-29 20:06:21 -08001651 } else {
1652 dev_err(&pdev->dev, "%s: Failed to register BUS "
1653 "scaling client!!\n", __func__);
1654 }
1655 }
1656
Hemant Kumar105d07f2012-07-02 15:33:07 -07001657 __mehci = mehci;
1658
Pavankumar Kondetife2d4d32012-09-07 15:33:09 +05301659 if (pdata && pdata->swfi_latency)
1660 pm_qos_add_request(&mehci->pm_qos_req_dma,
1661 PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
1662
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301663 /*
1664 * This pdev->dev is assigned parent of root-hub by USB core,
1665 * hence, runtime framework automatically calls this driver's
1666 * runtime APIs based on root-hub's state.
1667 */
1668 pm_runtime_set_active(&pdev->dev);
1669 pm_runtime_enable(&pdev->dev);
Vijayavardhan Vennapusaafbbb8f2012-04-13 16:28:45 +05301670 /* Decrement the parent device's counter after probe.
1671 * As child is active, parent will not be put into
1672 * suspend mode.
1673 */
1674 if (pdev->dev.parent)
1675 pm_runtime_put_sync(pdev->dev.parent);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301676
1677 return 0;
1678
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +05301679unconfig_gpio:
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001680 destroy_workqueue(ehci_wq);
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +05301681 msm_hsic_config_gpios(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301682deinit_vddcx:
1683 msm_hsic_init_vddcx(mehci, 0);
1684deinit_clocks:
1685 msm_hsic_init_clocks(mehci, 0);
1686unmap:
1687 iounmap(hcd->regs);
1688put_hcd:
1689 usb_put_hcd(hcd);
1690
1691 return ret;
1692}
1693
1694static int __devexit ehci_hsic_msm_remove(struct platform_device *pdev)
1695{
1696 struct usb_hcd *hcd = platform_get_drvdata(pdev);
1697 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
Pavankumar Kondetife2d4d32012-09-07 15:33:09 +05301698 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
1699
1700 if (pdata && pdata->swfi_latency)
1701 pm_qos_remove_request(&mehci->pm_qos_req_dma);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301702
Vamsi Krishna34f01582011-12-14 19:54:42 -08001703 if (mehci->peripheral_status_irq)
1704 free_irq(mehci->peripheral_status_irq, mehci);
Jack Phamfe441ea2012-03-23 17:03:15 -07001705
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001706 if (mehci->wakeup_irq) {
Jack Phamfe441ea2012-03-23 17:03:15 -07001707 if (mehci->wakeup_irq_enabled)
1708 disable_irq_wake(mehci->wakeup_irq);
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001709 free_irq(mehci->wakeup_irq, mehci);
1710 }
Vamsi Krishna34f01582011-12-14 19:54:42 -08001711
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001712 /*
1713 * If the update request is called after unregister, the request will
1714 * fail. Results are undefined if unregister is called in the middle of
1715 * update request.
1716 */
1717 mehci->bus_vote = false;
1718 cancel_work_sync(&mehci->bus_vote_w);
1719
Hemant Kumare6275972012-02-29 20:06:21 -08001720 if (mehci->bus_perf_client)
1721 msm_bus_scale_unregister_client(mehci->bus_perf_client);
1722
1723 ehci_hsic_msm_debugfs_cleanup();
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301724 device_init_wakeup(&pdev->dev, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301725 pm_runtime_set_suspended(&pdev->dev);
1726
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001727 destroy_workqueue(ehci_wq);
1728
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301729 usb_remove_hcd(hcd);
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +05301730 msm_hsic_config_gpios(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301731 msm_hsic_init_vddcx(mehci, 0);
1732
1733 msm_hsic_init_clocks(mehci, 0);
Ajay Dudaniab3bf192012-08-28 09:58:04 -07001734 wake_lock_destroy(&mehci->wlock);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301735 iounmap(hcd->regs);
1736 usb_put_hcd(hcd);
1737
1738 return 0;
1739}
1740
1741#ifdef CONFIG_PM_SLEEP
1742static int msm_hsic_pm_suspend(struct device *dev)
1743{
Jack Phambe05fbb2012-05-16 10:56:26 -07001744 int ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301745 struct usb_hcd *hcd = dev_get_drvdata(dev);
1746 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1747
1748 dev_dbg(dev, "ehci-msm-hsic PM suspend\n");
1749
Hemant Kumar45d211b2012-05-31 17:58:43 -07001750 dbg_log_event(NULL, "PM Suspend", 0);
1751
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301752 if (device_may_wakeup(dev))
1753 enable_irq_wake(hcd->irq);
1754
Jack Phambe05fbb2012-05-16 10:56:26 -07001755 ret = msm_hsic_suspend(mehci);
1756
1757 if (ret && device_may_wakeup(dev))
1758 disable_irq_wake(hcd->irq);
1759
1760 return ret;
Jack Phamfe441ea2012-03-23 17:03:15 -07001761}
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301762
Jack Pham16b06f82012-08-14 20:03:59 -07001763static int msm_hsic_pm_suspend_noirq(struct device *dev)
1764{
1765 struct usb_hcd *hcd = dev_get_drvdata(dev);
1766 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1767
1768 if (mehci->async_int) {
1769 dev_dbg(dev, "suspend_noirq: Aborting due to pending interrupt\n");
1770 return -EBUSY;
1771 }
1772
1773 return 0;
1774}
1775
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301776static int msm_hsic_pm_resume(struct device *dev)
1777{
1778 int ret;
1779 struct usb_hcd *hcd = dev_get_drvdata(dev);
1780 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1781
Jack Pham16b06f82012-08-14 20:03:59 -07001782 dev_dbg(dev, "ehci-msm-hsic PM resume\n");
Hemant Kumar45d211b2012-05-31 17:58:43 -07001783 dbg_log_event(NULL, "PM Resume", 0);
1784
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301785 if (device_may_wakeup(dev))
1786 disable_irq_wake(hcd->irq);
1787
Pavankumar Kondeti1c851692012-09-18 17:52:51 +05301788 /*
1789 * Keep HSIC in Low Power Mode if system is resumed
1790 * by any other wakeup source. HSIC is resumed later
1791 * when remote wakeup is received or interface driver
1792 * start I/O.
1793 */
1794 if (!atomic_read(&mehci->pm_usage_cnt))
1795 return 0;
1796
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301797 ret = msm_hsic_resume(mehci);
1798 if (ret)
1799 return ret;
1800
1801 /* Bring the device to full powered state upon system resume */
1802 pm_runtime_disable(dev);
1803 pm_runtime_set_active(dev);
1804 pm_runtime_enable(dev);
1805
1806 return 0;
1807}
1808#endif
1809
1810#ifdef CONFIG_PM_RUNTIME
1811static int msm_hsic_runtime_idle(struct device *dev)
1812{
1813 dev_dbg(dev, "EHCI runtime idle\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301814 return 0;
1815}
1816
1817static int msm_hsic_runtime_suspend(struct device *dev)
1818{
1819 struct usb_hcd *hcd = dev_get_drvdata(dev);
1820 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1821
1822 dev_dbg(dev, "EHCI runtime suspend\n");
Hemant Kumar45d211b2012-05-31 17:58:43 -07001823
1824 dbg_log_event(NULL, "Run Time PM Suspend", 0);
1825
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301826 return msm_hsic_suspend(mehci);
1827}
1828
1829static int msm_hsic_runtime_resume(struct device *dev)
1830{
1831 struct usb_hcd *hcd = dev_get_drvdata(dev);
1832 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1833
1834 dev_dbg(dev, "EHCI runtime resume\n");
Hemant Kumar45d211b2012-05-31 17:58:43 -07001835
1836 dbg_log_event(NULL, "Run Time PM Resume", 0);
1837
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301838 return msm_hsic_resume(mehci);
1839}
1840#endif
1841
1842#ifdef CONFIG_PM
1843static const struct dev_pm_ops msm_hsic_dev_pm_ops = {
1844 SET_SYSTEM_SLEEP_PM_OPS(msm_hsic_pm_suspend, msm_hsic_pm_resume)
Jack Pham16b06f82012-08-14 20:03:59 -07001845 .suspend_noirq = msm_hsic_pm_suspend_noirq,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301846 SET_RUNTIME_PM_OPS(msm_hsic_runtime_suspend, msm_hsic_runtime_resume,
1847 msm_hsic_runtime_idle)
1848};
1849#endif
1850
1851static struct platform_driver ehci_msm_hsic_driver = {
1852 .probe = ehci_hsic_msm_probe,
1853 .remove = __devexit_p(ehci_hsic_msm_remove),
1854 .driver = {
1855 .name = "msm_hsic_host",
1856#ifdef CONFIG_PM
1857 .pm = &msm_hsic_dev_pm_ops,
1858#endif
1859 },
1860};