blob: 7b616e4107be7bf40bedb78d0caf14877c6b1141 [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>
Sudhir Sharma1673e302012-08-27 17:37:24 -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>
Hemant Kumarbbcdcbc2012-08-30 14:23:38 -070038#include <linux/irq.h>
Vamsi Krishnafce1bd22012-08-17 17:12:26 -070039#include <linux/kthread.h>
40#include <linux/wait.h>
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +053041#include <linux/pm_qos.h>
Amit Blayd6ea6102012-06-07 16:26:24 +030042
43#include <mach/msm_bus.h>
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053044#include <mach/clk.h>
45#include <mach/msm_iomap.h>
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +053046#include <mach/msm_xo.h>
Vamsi Krishna34f01582011-12-14 19:54:42 -080047#include <linux/spinlock.h>
Hemant Kumar45d211b2012-05-31 17:58:43 -070048#include <linux/cpu.h>
Amit Blayd6ea6102012-06-07 16:26:24 +030049#include <mach/rpm-regulator.h>
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053050
51#define MSM_USB_BASE (hcd->regs)
Hemant Kumar105d07f2012-07-02 15:33:07 -070052#define USB_REG_START_OFFSET 0x90
53#define USB_REG_END_OFFSET 0x250
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053054
Hemant Kumar2309eaa2012-08-14 16:46:42 -070055static struct workqueue_struct *ehci_wq;
Vamsi Krishnafce1bd22012-08-17 17:12:26 -070056struct ehci_timer {
57#define GPT_LD(p) ((p) & 0x00FFFFFF)
58 u32 gptimer0_ld;
59#define GPT_RUN BIT(31)
60#define GPT_RESET BIT(30)
61#define GPT_MODE BIT(24)
62#define GPT_CNT(p) ((p) & 0x00FFFFFF)
63 u32 gptimer0_ctrl;
64
65 u32 gptimer1_ld;
66 u32 gptimer1_ctrl;
67};
Hemant Kumar2309eaa2012-08-14 16:46:42 -070068
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053069struct msm_hsic_hcd {
70 struct ehci_hcd ehci;
Hemant Kumard343c012012-09-06 19:57:14 -070071 spinlock_t wakeup_lock;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053072 struct device *dev;
73 struct clk *ahb_clk;
Manu Gautam5143b252012-01-05 19:25:23 -080074 struct clk *core_clk;
75 struct clk *alt_core_clk;
76 struct clk *phy_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053077 struct clk *cal_clk;
78 struct regulator *hsic_vddcx;
Sudhir Sharma1673e302012-08-27 17:37:24 -070079 bool async_int;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053080 atomic_t in_lpm;
Sudhir Sharma1673e302012-08-27 17:37:24 -070081 struct wake_lock wlock;
Vamsi Krishna34f01582011-12-14 19:54:42 -080082 int peripheral_status_irq;
Vamsi Krishna6921cbe2012-02-21 18:34:43 -080083 int wakeup_irq;
Jack Phamfe441ea2012-03-23 17:03:15 -070084 bool wakeup_irq_enabled;
Sudhir Sharma1673e302012-08-27 17:37:24 -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;
Vamsi Krishnafce1bd22012-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 Kondeti4f5dc3b2012-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 Kumar4d50a432012-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 Kumar4d50a432012-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 Kumar4d50a432012-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 Kumar4d50a432012-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 Kumar4d50a432012-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 Kumar4d50a432012-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 Kumar4d50a432012-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 Kumar4d50a432012-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 Kumar4d50a432012-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 Kumar4d50a432012-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 Kumar4d50a432012-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);
Hemant Kumar8fdc3982012-08-21 12:22:27 -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 */
Hemant Kumar8fdc3982012-08-21 12:22:27 -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);
Hemant Kumar8fdc3982012-08-21 12:22:27 -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) {
Hemant Kumar8fdc3982012-08-21 12:22:27 -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;
Hemant Kumar6fd65032012-05-23 13:02:24 -0700527 }
528
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530529 return 0;
530
531free_gpio:
532 gpio_free(pdata->data);
533free_strobe:
534 gpio_free(pdata->strobe);
535
536 return rc;
537}
538
Vamsi Krishna64b48612012-06-14 16:08:11 -0700539static void msm_hsic_clk_reset(struct msm_hsic_hcd *mehci)
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530540{
541 int ret;
542
Manu Gautam5143b252012-01-05 19:25:23 -0800543 ret = clk_reset(mehci->core_clk, CLK_RESET_ASSERT);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530544 if (ret) {
Vamsi Krishna64b48612012-06-14 16:08:11 -0700545 dev_err(mehci->dev, "hsic clk assert failed:%d\n", ret);
546 return;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530547 }
Vamsi Krishna64b48612012-06-14 16:08:11 -0700548 clk_disable(mehci->core_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530549
Manu Gautam5143b252012-01-05 19:25:23 -0800550 ret = clk_reset(mehci->core_clk, CLK_RESET_DEASSERT);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530551 if (ret)
Vamsi Krishna64b48612012-06-14 16:08:11 -0700552 dev_err(mehci->dev, "hsic clk deassert failed:%d\n", ret);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530553
Vamsi Krishna64b48612012-06-14 16:08:11 -0700554 usleep_range(10000, 12000);
555
556 clk_enable(mehci->core_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530557}
558
Vamsi Krishna64b48612012-06-14 16:08:11 -0700559#define HSIC_STROBE_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C0)
560#define HSIC_DATA_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C4)
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530561#define HSIC_CAL_PAD_CTL (MSM_TLMM_BASE+0x20C8)
562#define HSIC_LV_MODE 0x04
563#define HSIC_PAD_CALIBRATION 0xA8
564#define HSIC_GPIO_PAD_VAL 0x0A0AAA10
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530565#define LINK_RESET_TIMEOUT_USEC (250 * 1000)
566static int msm_hsic_reset(struct msm_hsic_hcd *mehci)
567{
568 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530569 int ret;
Lena Salman8c8ba382012-02-14 15:59:31 +0200570 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530571
Vamsi Krishna64b48612012-06-14 16:08:11 -0700572 msm_hsic_clk_reset(mehci);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530573
Vamsi Krishna64b48612012-06-14 16:08:11 -0700574 /* select ulpi phy */
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530575 writel_relaxed(0x80000000, USB_PORTSC);
576
Vamsi Krishna64b48612012-06-14 16:08:11 -0700577 mb();
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530578
Lena Salman8c8ba382012-02-14 15:59:31 +0200579 /* HSIC init sequence when HSIC signals (Strobe/Data) are
580 routed via GPIOs */
581 if (pdata && pdata->strobe && pdata->data) {
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530582
Lena Salman8c8ba382012-02-14 15:59:31 +0200583 /* Enable LV_MODE in HSIC_CAL_PAD_CTL register */
584 writel_relaxed(HSIC_LV_MODE, HSIC_CAL_PAD_CTL);
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530585
Vamsi Krishna64b48612012-06-14 16:08:11 -0700586 mb();
587
Lena Salman8c8ba382012-02-14 15:59:31 +0200588 /*set periodic calibration interval to ~2.048sec in
589 HSIC_IO_CAL_REG */
590 ulpi_write(mehci, 0xFF, 0x33);
591
592 /* Enable periodic IO calibration in HSIC_CFG register */
593 ulpi_write(mehci, HSIC_PAD_CALIBRATION, 0x30);
594
Vamsi Krishna64b48612012-06-14 16:08:11 -0700595 /* Configure GPIO pins for HSIC functionality mode */
Lena Salman8c8ba382012-02-14 15:59:31 +0200596 ret = msm_hsic_config_gpios(mehci, 1);
597 if (ret) {
598 dev_err(mehci->dev, " gpio configuarion failed\n");
599 return ret;
600 }
Vamsi Krishna64b48612012-06-14 16:08:11 -0700601 /* Set LV_MODE=0x1 and DCC=0x2 in HSIC_GPIO PAD_CTL register */
602 writel_relaxed(HSIC_GPIO_PAD_VAL, HSIC_STROBE_GPIO_PAD_CTL);
603 writel_relaxed(HSIC_GPIO_PAD_VAL, HSIC_DATA_GPIO_PAD_CTL);
604
605 mb();
606
Lena Salman8c8ba382012-02-14 15:59:31 +0200607 /* Enable HSIC mode in HSIC_CFG register */
608 ulpi_write(mehci, 0x01, 0x31);
609 } else {
610 /* HSIC init sequence when HSIC signals (Strobe/Data) are routed
611 via dedicated I/O */
612
613 /* programmable length of connect signaling (33.2ns) */
614 ret = ulpi_write(mehci, 3, HSIC_DBG1_REG);
615 if (ret) {
616 pr_err("%s: Unable to program length of connect "
617 "signaling\n", __func__);
618 }
619
620 /*set periodic calibration interval to ~2.048sec in
621 HSIC_IO_CAL_REG */
622 ulpi_write(mehci, 0xFF, 0x33);
623
624 /* Enable HSIC mode in HSIC_CFG register */
625 ulpi_write(mehci, 0xA9, 0x30);
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530626 }
627
Hemant Kumar6fd65032012-05-23 13:02:24 -0700628 /*disable auto resume*/
629 ulpi_write(mehci, ULPI_IFC_CTRL_AUTORESUME, ULPI_CLR(ULPI_IFC_CTRL));
630
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530631 return 0;
632}
633
634#define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000)
635#define PHY_RESUME_TIMEOUT_USEC (100 * 1000)
636
637#ifdef CONFIG_PM_SLEEP
638static int msm_hsic_suspend(struct msm_hsic_hcd *mehci)
639{
640 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +0530641 int cnt = 0, ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530642 u32 val;
Amit Blayd6ea6102012-06-07 16:26:24 +0300643 int none_vol, max_vol;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530644
645 if (atomic_read(&mehci->in_lpm)) {
646 dev_dbg(mehci->dev, "%s called in lpm\n", __func__);
647 return 0;
648 }
649
650 disable_irq(hcd->irq);
Jack Phambe05fbb2012-05-16 10:56:26 -0700651
Sudhir Sharma1673e302012-08-27 17:37:24 -0700652 /* make sure we don't race against a remote wakeup */
653 if (test_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags) ||
Jack Phambe05fbb2012-05-16 10:56:26 -0700654 readl_relaxed(USB_PORTSC) & PORT_RESUME) {
Sudhir Sharma1673e302012-08-27 17:37:24 -0700655 dev_dbg(mehci->dev, "wakeup pending, aborting suspend\n");
Jack Phambe05fbb2012-05-16 10:56:26 -0700656 enable_irq(hcd->irq);
657 return -EBUSY;
658 }
659
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530660 /*
661 * PHY may take some time or even fail to enter into low power
662 * mode (LPM). Hence poll for 500 msec and reset the PHY and link
663 * in failure case.
664 */
Hemant Kumar3dbc5b32012-05-09 15:36:11 -0700665 val = readl_relaxed(USB_PORTSC);
666 val &= ~PORT_RWC_BITS;
667 val |= PORTSC_PHCD;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530668 writel_relaxed(val, USB_PORTSC);
669 while (cnt < PHY_SUSPEND_TIMEOUT_USEC) {
670 if (readl_relaxed(USB_PORTSC) & PORTSC_PHCD)
671 break;
672 udelay(1);
673 cnt++;
674 }
675
676 if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) {
677 dev_err(mehci->dev, "Unable to suspend PHY\n");
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530678 msm_hsic_config_gpios(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530679 msm_hsic_reset(mehci);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530680 }
681
682 /*
683 * PHY has capability to generate interrupt asynchronously in low
684 * power mode (LPM). This interrupt is level triggered. So USB IRQ
685 * line must be disabled till async interrupt enable bit is cleared
686 * in USBCMD register. Assert STP (ULPI interface STOP signal) to
687 * block data communication from PHY.
688 */
689 writel_relaxed(readl_relaxed(USB_USBCMD) | ASYNC_INTR_CTRL |
690 ULPI_STP_CTRL, USB_USBCMD);
691
692 /*
693 * Ensure that hardware is put in low power mode before
694 * clocks are turned OFF and VDD is allowed to minimize.
695 */
696 mb();
697
Manu Gautam28b1bac2012-01-30 16:43:06 +0530698 clk_disable_unprepare(mehci->core_clk);
699 clk_disable_unprepare(mehci->phy_clk);
700 clk_disable_unprepare(mehci->cal_clk);
701 clk_disable_unprepare(mehci->ahb_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530702
Amit Blayd6ea6102012-06-07 16:26:24 +0300703 none_vol = vdd_val[mehci->vdd_type][VDD_NONE];
704 max_vol = vdd_val[mehci->vdd_type][VDD_MAX];
705
706 ret = regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol);
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700707 if (ret < 0)
Amit Blayd6ea6102012-06-07 16:26:24 +0300708 dev_err(mehci->dev, "unable to set vddcx voltage for VDD MIN\n");
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700709
Hemant Kumare6275972012-02-29 20:06:21 -0800710 if (mehci->bus_perf_client && debug_bus_voting_enabled) {
Hemant Kumar2309eaa2012-08-14 16:46:42 -0700711 mehci->bus_vote = false;
712 queue_work(ehci_wq, &mehci->bus_vote_w);
Hemant Kumare6275972012-02-29 20:06:21 -0800713 }
714
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530715 atomic_set(&mehci->in_lpm, 1);
716 enable_irq(hcd->irq);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700717
718 mehci->wakeup_irq_enabled = 1;
719 enable_irq_wake(mehci->wakeup_irq);
720 enable_irq(mehci->wakeup_irq);
721
Sudhir Sharma1673e302012-08-27 17:37:24 -0700722 wake_unlock(&mehci->wlock);
723
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530724 dev_info(mehci->dev, "HSIC-USB in low power mode\n");
725
726 return 0;
727}
728
729static int msm_hsic_resume(struct msm_hsic_hcd *mehci)
730{
731 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +0530732 int cnt = 0, ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530733 unsigned temp;
Amit Blayd6ea6102012-06-07 16:26:24 +0300734 int min_vol, max_vol;
Hemant Kumard343c012012-09-06 19:57:14 -0700735 unsigned long flags;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530736
737 if (!atomic_read(&mehci->in_lpm)) {
738 dev_dbg(mehci->dev, "%s called in !in_lpm\n", __func__);
739 return 0;
740 }
741
Hemant Kumard343c012012-09-06 19:57:14 -0700742 spin_lock_irqsave(&mehci->wakeup_lock, flags);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700743 if (mehci->wakeup_irq_enabled) {
744 disable_irq_wake(mehci->wakeup_irq);
745 disable_irq_nosync(mehci->wakeup_irq);
746 mehci->wakeup_irq_enabled = 0;
747 }
Hemant Kumard343c012012-09-06 19:57:14 -0700748 spin_unlock_irqrestore(&mehci->wakeup_lock, flags);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700749
Sudhir Sharma1673e302012-08-27 17:37:24 -0700750 wake_lock(&mehci->wlock);
751
Hemant Kumare6275972012-02-29 20:06:21 -0800752 if (mehci->bus_perf_client && debug_bus_voting_enabled) {
Hemant Kumar2309eaa2012-08-14 16:46:42 -0700753 mehci->bus_vote = true;
754 queue_work(ehci_wq, &mehci->bus_vote_w);
Hemant Kumare6275972012-02-29 20:06:21 -0800755 }
756
Amit Blayd6ea6102012-06-07 16:26:24 +0300757 min_vol = vdd_val[mehci->vdd_type][VDD_MIN];
758 max_vol = vdd_val[mehci->vdd_type][VDD_MAX];
759
760 ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol);
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700761 if (ret < 0)
Amit Blayd6ea6102012-06-07 16:26:24 +0300762 dev_err(mehci->dev, "unable to set nominal vddcx voltage (no VDD MIN)\n");
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700763
Manu Gautam28b1bac2012-01-30 16:43:06 +0530764 clk_prepare_enable(mehci->core_clk);
765 clk_prepare_enable(mehci->phy_clk);
766 clk_prepare_enable(mehci->cal_clk);
767 clk_prepare_enable(mehci->ahb_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530768
769 temp = readl_relaxed(USB_USBCMD);
770 temp &= ~ASYNC_INTR_CTRL;
771 temp &= ~ULPI_STP_CTRL;
772 writel_relaxed(temp, USB_USBCMD);
773
774 if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD))
775 goto skip_phy_resume;
776
Hemant Kumar3dbc5b32012-05-09 15:36:11 -0700777 temp = readl_relaxed(USB_PORTSC);
778 temp &= ~(PORT_RWC_BITS | PORTSC_PHCD);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530779 writel_relaxed(temp, USB_PORTSC);
780 while (cnt < PHY_RESUME_TIMEOUT_USEC) {
781 if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD) &&
782 (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_SYNC_STATE))
783 break;
784 udelay(1);
785 cnt++;
786 }
787
788 if (cnt >= PHY_RESUME_TIMEOUT_USEC) {
789 /*
790 * This is a fatal error. Reset the link and
791 * PHY to make hsic working.
792 */
793 dev_err(mehci->dev, "Unable to resume USB. Reset the hsic\n");
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530794 msm_hsic_config_gpios(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530795 msm_hsic_reset(mehci);
796 }
797
798skip_phy_resume:
799
Hemant Kumar6fd65032012-05-23 13:02:24 -0700800 usb_hcd_resume_root_hub(hcd);
801
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530802 atomic_set(&mehci->in_lpm, 0);
803
804 if (mehci->async_int) {
805 mehci->async_int = false;
806 pm_runtime_put_noidle(mehci->dev);
Jack Phamdd5ad792012-07-26 10:31:03 -0700807 enable_irq(hcd->irq);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700808 }
809
Sudhir Sharma1673e302012-08-27 17:37:24 -0700810 if (atomic_read(&mehci->pm_usage_cnt)) {
811 atomic_set(&mehci->pm_usage_cnt, 0);
812 pm_runtime_put_noidle(mehci->dev);
813 }
Jack Phamdd5ad792012-07-26 10:31:03 -0700814
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530815 dev_info(mehci->dev, "HSIC-USB exited from low power mode\n");
816
817 return 0;
818}
819#endif
820
Hemant Kumar2309eaa2012-08-14 16:46:42 -0700821static void ehci_hsic_bus_vote_w(struct work_struct *w)
822{
823 struct msm_hsic_hcd *mehci =
824 container_of(w, struct msm_hsic_hcd, bus_vote_w);
825 int ret;
826
827 ret = msm_bus_scale_client_update_request(mehci->bus_perf_client,
828 mehci->bus_vote);
829 if (ret)
830 dev_err(mehci->dev, "%s: Failed to vote for bus bandwidth %d\n",
831 __func__, ret);
832}
833
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700834#define STS_GPTIMER0_INTERRUPT BIT(24)
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530835static irqreturn_t msm_hsic_irq(struct usb_hcd *hcd)
836{
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700837 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530838 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700839 u32 status;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530840
841 if (atomic_read(&mehci->in_lpm)) {
842 disable_irq_nosync(hcd->irq);
Hemant Kumar3dbc5b32012-05-09 15:36:11 -0700843 dev_dbg(mehci->dev, "phy async intr\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530844 mehci->async_int = true;
845 pm_runtime_get(mehci->dev);
846 return IRQ_HANDLED;
847 }
848
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700849 status = ehci_readl(ehci, &ehci->regs->status);
850
851 if (status & STS_GPTIMER0_INTERRUPT) {
852 int timeleft;
853
854 dbg_log_event(NULL, "FPR: gpt0_isr", 0);
855
856 timeleft = GPT_CNT(ehci_readl(ehci,
857 &mehci->timer->gptimer1_ctrl));
858 if (timeleft) {
859 ehci_writel(ehci, ehci_readl(ehci,
860 &ehci->regs->command) | CMD_RUN,
861 &ehci->regs->command);
862 } else
863 mehci->resume_again = 1;
864
865 dbg_log_event(NULL, "FPR: timeleft", timeleft);
866
867 complete(&mehci->gpt0_completion);
868 ehci_writel(ehci, STS_GPTIMER0_INTERRUPT, &ehci->regs->status);
869 }
870
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530871 return ehci_irq(hcd);
872}
873
874static int ehci_hsic_reset(struct usb_hcd *hcd)
875{
876 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700877 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530878 int retval;
879
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700880 mehci->timer = USB_HS_GPTIMER_BASE;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530881 ehci->caps = USB_CAPLENGTH;
882 ehci->regs = USB_CAPLENGTH +
883 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
884 dbg_hcs_params(ehci, "reset");
885 dbg_hcc_params(ehci, "reset");
886
887 /* cache the data to minimize the chip reads*/
888 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
889
890 hcd->has_tt = 1;
891 ehci->sbrn = HCD_USB2;
892
893 retval = ehci_halt(ehci);
894 if (retval)
895 return retval;
896
897 /* data structure init */
898 retval = ehci_init(hcd);
899 if (retval)
900 return retval;
901
902 retval = ehci_reset(ehci);
903 if (retval)
904 return retval;
905
906 /* bursts of unspecified length. */
907 writel_relaxed(0, USB_AHBBURST);
908 /* Use the AHB transactor */
Vijayavardhan Vennapusa5f32d7a2012-03-14 16:30:26 +0530909 writel_relaxed(0x08, USB_AHBMODE);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530910 /* Disable streaming mode and select host mode */
911 writel_relaxed(0x13, USB_USBMODE);
912
913 ehci_port_power(ehci, 1);
914 return 0;
915}
916
Jack Phamc0d41732012-09-28 17:45:38 -0700917#ifdef CONFIG_PM
918
Hemant Kumar45d211b2012-05-31 17:58:43 -0700919static int ehci_hsic_bus_suspend(struct usb_hcd *hcd)
920{
Pavankumar Kondetia723f742012-09-14 14:02:36 +0530921 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
922
923 if (!(readl_relaxed(USB_PORTSC) & PORT_PE)) {
924 dbg_log_event(NULL, "RH suspend attempt failed", 0);
925 dev_dbg(mehci->dev, "%s:port is not enabled skip suspend\n",
926 __func__);
927 return -EAGAIN;
928 }
929
Hemant Kumar45d211b2012-05-31 17:58:43 -0700930 dbg_log_event(NULL, "Suspend RH", 0);
931 return ehci_bus_suspend(hcd);
932}
933
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700934#define RESUME_RETRY_LIMIT 3
935#define RESUME_SIGNAL_TIME_MS (21 * 999)
936#define RESUME_SIGNAL_TIME_SOF_MS (23 * 999)
937static int msm_hsic_resume_thread(void *data)
938{
939 struct msm_hsic_hcd *mehci = data;
940 struct usb_hcd *hcd = hsic_to_hcd(mehci);
941 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
942 u32 temp;
943 unsigned long resume_needed = 0;
944 int retry_cnt = 0;
945 int tight_resume = 0;
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +0530946 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700947
948 dbg_log_event(NULL, "Resume RH", 0);
949
950 /* keep delay between bus states */
951 if (time_before(jiffies, ehci->next_statechange))
952 usleep_range(5000, 5000);
953
954 spin_lock_irq(&ehci->lock);
955 if (!HCD_HW_ACCESSIBLE(hcd)) {
956 spin_unlock_irq(&ehci->lock);
957 mehci->resume_status = -ESHUTDOWN;
958 complete(&mehci->rt_completion);
959 return 0;
960 }
961
962 if (unlikely(ehci->debug)) {
963 if (!dbgp_reset_prep())
964 ehci->debug = NULL;
965 else
966 dbgp_external_startup();
967 }
968
969 /* at least some APM implementations will try to deliver
970 * IRQs right away, so delay them until we're ready.
971 */
972 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
973
974 /* re-init operational registers */
975 ehci_writel(ehci, 0, &ehci->regs->segment);
976 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
977 ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
978
979 /*CMD_RUN will be set after, PORT_RESUME gets cleared*/
980 if (ehci->resume_sof_bug)
981 ehci->command &= ~CMD_RUN;
982
983 /* restore CMD_RUN, framelist size, and irq threshold */
984 ehci_writel(ehci, ehci->command, &ehci->regs->command);
985
986 /* manually resume the ports we suspended during bus_suspend() */
987resume_again:
988 if (retry_cnt >= RESUME_RETRY_LIMIT) {
989 pr_info("retry count(%d) reached max, resume in tight loop\n",
990 retry_cnt);
991 tight_resume = 1;
992 }
993
994
995 temp = ehci_readl(ehci, &ehci->regs->port_status[0]);
996 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
997 if (test_bit(0, &ehci->bus_suspended) && (temp & PORT_SUSPEND)) {
998 temp |= PORT_RESUME;
999 set_bit(0, &resume_needed);
1000 }
1001 dbg_log_event(NULL, "FPR: Set", temp);
1002 ehci_writel(ehci, temp, &ehci->regs->port_status[0]);
1003
1004 /* HSIC controller has a h/w bug due to which it can try to send SOFs
1005 * (start of frames) during port resume resulting in phy lockup. HSIC hw
1006 * controller in MSM clears FPR bit after driving the resume signal for
1007 * 20ms. Workaround is to stop SOFs before driving resume and then start
1008 * sending SOFs immediately. Need to send SOFs within 3ms of resume
1009 * completion otherwise peripheral may enter undefined state. As
1010 * usleep_range does not gurantee exact sleep time, GPTimer is used to
1011 * to time the resume sequence. If driver exceeds allowable time SOFs,
1012 * repeat the resume process.
1013 */
1014 if (ehci->resume_sof_bug && resume_needed) {
1015 if (!tight_resume) {
1016 mehci->resume_again = 0;
1017 ehci_writel(ehci, GPT_LD(RESUME_SIGNAL_TIME_MS),
1018 &mehci->timer->gptimer0_ld);
1019 ehci_writel(ehci, GPT_RESET | GPT_RUN,
1020 &mehci->timer->gptimer0_ctrl);
1021 ehci_writel(ehci, INTR_MASK | STS_GPTIMER0_INTERRUPT,
1022 &ehci->regs->intr_enable);
1023
1024 ehci_writel(ehci, GPT_LD(RESUME_SIGNAL_TIME_SOF_MS),
1025 &mehci->timer->gptimer1_ld);
1026 ehci_writel(ehci, GPT_RESET | GPT_RUN,
1027 &mehci->timer->gptimer1_ctrl);
1028
1029 spin_unlock_irq(&ehci->lock);
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05301030 if (pdata && pdata->swfi_latency)
1031 pm_qos_update_request(&mehci->pm_qos_req_dma,
1032 pdata->swfi_latency + 1);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001033 wait_for_completion(&mehci->gpt0_completion);
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05301034 if (pdata && pdata->swfi_latency)
1035 pm_qos_update_request(&mehci->pm_qos_req_dma,
1036 PM_QOS_DEFAULT_VALUE);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001037 spin_lock_irq(&ehci->lock);
1038 } else {
1039 dbg_log_event(NULL, "FPR: Tightloop", 0);
1040 /* do the resume in a tight loop */
1041 handshake(ehci, &ehci->regs->port_status[0],
1042 PORT_RESUME, 0, 22 * 1000);
1043 ehci_writel(ehci, ehci_readl(ehci,
1044 &ehci->regs->command) | CMD_RUN,
1045 &ehci->regs->command);
1046 }
1047
1048 if (mehci->resume_again) {
1049 int temp;
1050
1051 dbg_log_event(NULL, "FPR: Re-Resume", retry_cnt);
1052 pr_info("FPR: retry count: %d\n", retry_cnt);
1053 spin_unlock_irq(&ehci->lock);
1054 temp = ehci_readl(ehci, &ehci->regs->port_status[0]);
1055 temp &= ~PORT_RWC_BITS;
1056 temp |= PORT_SUSPEND;
1057 ehci_writel(ehci, temp, &ehci->regs->port_status[0]);
1058 /* Keep the bus idle for 5ms so that peripheral
1059 * can detect and initiate suspend
1060 */
1061 usleep_range(5000, 5000);
1062 dbg_log_event(NULL,
1063 "FPR: RResume",
1064 ehci_readl(ehci, &ehci->regs->port_status[0]));
1065 spin_lock_irq(&ehci->lock);
1066 mehci->resume_again = 0;
1067 retry_cnt++;
1068 goto resume_again;
1069 }
1070 }
1071
1072 dbg_log_event(NULL, "FPR: RT-Done", 0);
1073 mehci->resume_status = 1;
1074 spin_unlock_irq(&ehci->lock);
1075
1076 complete(&mehci->rt_completion);
1077
1078 return 0;
1079}
1080
Hemant Kumar45d211b2012-05-31 17:58:43 -07001081static int ehci_hsic_bus_resume(struct usb_hcd *hcd)
1082{
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001083 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1084 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1085 u32 temp;
1086 struct task_struct *resume_thread = NULL;
1087
1088 mehci->resume_status = 0;
1089 resume_thread = kthread_run(msm_hsic_resume_thread,
1090 mehci, "hsic_resume_thread");
1091 if (IS_ERR(resume_thread)) {
1092 pr_err("Error creating resume thread:%lu\n",
1093 PTR_ERR(resume_thread));
1094 return PTR_ERR(resume_thread);
1095 }
1096
1097 wait_for_completion(&mehci->rt_completion);
1098
1099 if (mehci->resume_status < 0)
1100 return mehci->resume_status;
1101
1102 dbg_log_event(NULL, "FPR: Wokeup", 0);
1103 spin_lock_irq(&ehci->lock);
1104 (void) ehci_readl(ehci, &ehci->regs->command);
1105
1106 temp = 0;
1107 if (ehci->async->qh_next.qh)
1108 temp |= CMD_ASE;
1109 if (ehci->periodic_sched)
1110 temp |= CMD_PSE;
1111 if (temp) {
1112 ehci->command |= temp;
1113 ehci_writel(ehci, ehci->command, &ehci->regs->command);
1114 }
1115
1116 ehci->next_statechange = jiffies + msecs_to_jiffies(5);
1117 hcd->state = HC_STATE_RUNNING;
1118 ehci->rh_state = EHCI_RH_RUNNING;
1119
1120 /* Now we can safely re-enable irqs */
1121 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
1122
1123 spin_unlock_irq(&ehci->lock);
1124
1125 return 0;
Hemant Kumar45d211b2012-05-31 17:58:43 -07001126}
1127
Jack Phamc0d41732012-09-28 17:45:38 -07001128#else
1129
1130#define ehci_hsic_bus_suspend NULL
1131#define ehci_hsic_bus_resume NULL
1132
1133#endif /* CONFIG_PM */
1134
Hemant Kumara3d4a6e2012-10-16 17:57:08 -07001135static void ehci_msm_set_autosuspend_delay(struct usb_device *dev)
1136{
1137 if (!dev->parent) /*for root hub no delay*/
1138 pm_runtime_set_autosuspend_delay(&dev->dev, 0);
1139 else
1140 pm_runtime_set_autosuspend_delay(&dev->dev, 200);
1141}
1142
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301143static struct hc_driver msm_hsic_driver = {
1144 .description = hcd_name,
1145 .product_desc = "Qualcomm EHCI Host Controller using HSIC",
1146 .hcd_priv_size = sizeof(struct msm_hsic_hcd),
1147
1148 /*
1149 * generic hardware linkage
1150 */
1151 .irq = msm_hsic_irq,
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -07001152 .flags = HCD_USB2 | HCD_MEMORY | HCD_OLD_ENUM,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301153
1154 .reset = ehci_hsic_reset,
1155 .start = ehci_run,
1156
1157 .stop = ehci_stop,
1158 .shutdown = ehci_shutdown,
1159
1160 /*
1161 * managing i/o requests and associated device resources
1162 */
Hemant Kumar4d50a432012-08-15 09:06:35 -07001163 .urb_enqueue = ehci_urb_enqueue,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301164 .urb_dequeue = ehci_urb_dequeue,
1165 .endpoint_disable = ehci_endpoint_disable,
1166 .endpoint_reset = ehci_endpoint_reset,
1167 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
1168
1169 /*
1170 * scheduling support
1171 */
1172 .get_frame_number = ehci_get_frame,
1173
1174 /*
1175 * root hub support
1176 */
1177 .hub_status_data = ehci_hub_status_data,
1178 .hub_control = ehci_hub_control,
1179 .relinquish_port = ehci_relinquish_port,
1180 .port_handed_over = ehci_port_handed_over,
1181
1182 /*
1183 * PM support
1184 */
Hemant Kumar45d211b2012-05-31 17:58:43 -07001185 .bus_suspend = ehci_hsic_bus_suspend,
1186 .bus_resume = ehci_hsic_bus_resume,
1187
Hemant Kumar4d50a432012-08-15 09:06:35 -07001188 .log_urb = dbg_log_event,
Hemant Kumar105d07f2012-07-02 15:33:07 -07001189 .dump_regs = dump_hsic_regs,
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -07001190
1191 .enable_ulpi_control = ehci_msm_enable_ulpi_control,
1192 .disable_ulpi_control = ehci_msm_disable_ulpi_control,
Hemant Kumara3d4a6e2012-10-16 17:57:08 -07001193
1194 .set_autosuspend_delay = ehci_msm_set_autosuspend_delay,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301195};
1196
1197static int msm_hsic_init_clocks(struct msm_hsic_hcd *mehci, u32 init)
1198{
1199 int ret = 0;
1200
1201 if (!init)
1202 goto put_clocks;
1203
Lena Salman8c8ba382012-02-14 15:59:31 +02001204 /*core_clk is required for LINK protocol engine
1205 *clock rate appropriately set by target specific clock driver */
Manu Gautam5143b252012-01-05 19:25:23 -08001206 mehci->core_clk = clk_get(mehci->dev, "core_clk");
1207 if (IS_ERR(mehci->core_clk)) {
1208 dev_err(mehci->dev, "failed to get core_clk\n");
1209 ret = PTR_ERR(mehci->core_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301210 return ret;
1211 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301212
Lena Salman8c8ba382012-02-14 15:59:31 +02001213 /* alt_core_clk is for LINK to be used during PHY RESET
1214 * clock rate appropriately set by target specific clock driver */
Manu Gautam5143b252012-01-05 19:25:23 -08001215 mehci->alt_core_clk = clk_get(mehci->dev, "alt_core_clk");
1216 if (IS_ERR(mehci->alt_core_clk)) {
1217 dev_err(mehci->dev, "failed to core_clk\n");
1218 ret = PTR_ERR(mehci->alt_core_clk);
1219 goto put_core_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301220 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301221
Lena Salman8c8ba382012-02-14 15:59:31 +02001222 /* phy_clk is required for HSIC PHY operation
1223 * clock rate appropriately set by target specific clock driver */
Manu Gautam5143b252012-01-05 19:25:23 -08001224 mehci->phy_clk = clk_get(mehci->dev, "phy_clk");
1225 if (IS_ERR(mehci->phy_clk)) {
1226 dev_err(mehci->dev, "failed to get phy_clk\n");
1227 ret = PTR_ERR(mehci->phy_clk);
1228 goto put_alt_core_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301229 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301230
1231 /* 10MHz cal_clk is required for calibration of I/O pads */
Manu Gautam5143b252012-01-05 19:25:23 -08001232 mehci->cal_clk = clk_get(mehci->dev, "cal_clk");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301233 if (IS_ERR(mehci->cal_clk)) {
Manu Gautam5143b252012-01-05 19:25:23 -08001234 dev_err(mehci->dev, "failed to get cal_clk\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301235 ret = PTR_ERR(mehci->cal_clk);
Manu Gautam5143b252012-01-05 19:25:23 -08001236 goto put_phy_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301237 }
1238 clk_set_rate(mehci->cal_clk, 10000000);
1239
1240 /* ahb_clk is required for data transfers */
Manu Gautam5143b252012-01-05 19:25:23 -08001241 mehci->ahb_clk = clk_get(mehci->dev, "iface_clk");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301242 if (IS_ERR(mehci->ahb_clk)) {
Manu Gautam5143b252012-01-05 19:25:23 -08001243 dev_err(mehci->dev, "failed to get iface_clk\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301244 ret = PTR_ERR(mehci->ahb_clk);
1245 goto put_cal_clk;
1246 }
1247
Manu Gautam28b1bac2012-01-30 16:43:06 +05301248 clk_prepare_enable(mehci->core_clk);
1249 clk_prepare_enable(mehci->phy_clk);
1250 clk_prepare_enable(mehci->cal_clk);
1251 clk_prepare_enable(mehci->ahb_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301252
1253 return 0;
1254
1255put_clocks:
Jack Phamfd193eb2012-02-22 15:38:08 -08001256 if (!atomic_read(&mehci->in_lpm)) {
1257 clk_disable_unprepare(mehci->core_clk);
1258 clk_disable_unprepare(mehci->phy_clk);
1259 clk_disable_unprepare(mehci->cal_clk);
1260 clk_disable_unprepare(mehci->ahb_clk);
1261 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301262 clk_put(mehci->ahb_clk);
1263put_cal_clk:
1264 clk_put(mehci->cal_clk);
Manu Gautam5143b252012-01-05 19:25:23 -08001265put_phy_clk:
1266 clk_put(mehci->phy_clk);
1267put_alt_core_clk:
1268 clk_put(mehci->alt_core_clk);
1269put_core_clk:
1270 clk_put(mehci->core_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301271
1272 return ret;
1273}
Vamsi Krishna34f01582011-12-14 19:54:42 -08001274static irqreturn_t hsic_peripheral_status_change(int irq, void *dev_id)
1275{
1276 struct msm_hsic_hcd *mehci = dev_id;
1277
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001278 pr_debug("%s: mehci:%p dev_id:%p\n", __func__, mehci, dev_id);
Vamsi Krishna34f01582011-12-14 19:54:42 -08001279
1280 if (mehci)
1281 msm_hsic_config_gpios(mehci, 0);
1282
1283 return IRQ_HANDLED;
1284}
1285
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001286static irqreturn_t msm_hsic_wakeup_irq(int irq, void *data)
1287{
1288 struct msm_hsic_hcd *mehci = data;
Pavankumar Kondeti968cf272012-09-27 12:04:12 +05301289 int ret;
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001290
Hemant Kumar6fd65032012-05-23 13:02:24 -07001291 mehci->wakeup_int_cnt++;
Hemant Kumar45d211b2012-05-31 17:58:43 -07001292 dbg_log_event(NULL, "Remote Wakeup IRQ", mehci->wakeup_int_cnt);
Hemant Kumar6fd65032012-05-23 13:02:24 -07001293 dev_dbg(mehci->dev, "%s: hsic remote wakeup interrupt cnt: %u\n",
1294 __func__, mehci->wakeup_int_cnt);
1295
Sudhir Sharma1673e302012-08-27 17:37:24 -07001296 wake_lock(&mehci->wlock);
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001297
Hemant Kumard343c012012-09-06 19:57:14 -07001298 spin_lock(&mehci->wakeup_lock);
Jack Phamfe441ea2012-03-23 17:03:15 -07001299 if (mehci->wakeup_irq_enabled) {
1300 mehci->wakeup_irq_enabled = 0;
1301 disable_irq_wake(irq);
1302 disable_irq_nosync(irq);
1303 }
Hemant Kumard343c012012-09-06 19:57:14 -07001304 spin_unlock(&mehci->wakeup_lock);
Jack Phamfe441ea2012-03-23 17:03:15 -07001305
Sudhir Sharma1673e302012-08-27 17:37:24 -07001306 if (!atomic_read(&mehci->pm_usage_cnt)) {
Pavankumar Kondeti968cf272012-09-27 12:04:12 +05301307 ret = pm_runtime_get(mehci->dev);
1308 /*
1309 * HSIC runtime resume can race with us.
1310 * if we are active (ret == 1) or resuming
1311 * (ret == -EINPROGRESS), decrement the
1312 * PM usage counter before returning.
1313 */
1314 if ((ret == 1) || (ret == -EINPROGRESS))
1315 pm_runtime_put_noidle(mehci->dev);
1316 else
1317 atomic_set(&mehci->pm_usage_cnt, 1);
Sudhir Sharma1673e302012-08-27 17:37:24 -07001318 }
1319
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001320 return IRQ_HANDLED;
1321}
1322
Hemant Kumare6275972012-02-29 20:06:21 -08001323static int ehci_hsic_msm_bus_show(struct seq_file *s, void *unused)
1324{
1325 if (debug_bus_voting_enabled)
1326 seq_printf(s, "enabled\n");
1327 else
1328 seq_printf(s, "disabled\n");
1329
1330 return 0;
1331}
1332
1333static int ehci_hsic_msm_bus_open(struct inode *inode, struct file *file)
1334{
1335 return single_open(file, ehci_hsic_msm_bus_show, inode->i_private);
1336}
1337
1338static ssize_t ehci_hsic_msm_bus_write(struct file *file,
1339 const char __user *ubuf, size_t count, loff_t *ppos)
1340{
1341 char buf[8];
1342 int ret;
1343 struct seq_file *s = file->private_data;
1344 struct msm_hsic_hcd *mehci = s->private;
1345
1346 memset(buf, 0x00, sizeof(buf));
1347
1348 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
1349 return -EFAULT;
1350
1351 if (!strncmp(buf, "enable", 6)) {
1352 /* Do not vote here. Let hsic driver decide when to vote */
1353 debug_bus_voting_enabled = true;
1354 } else {
1355 debug_bus_voting_enabled = false;
1356 if (mehci->bus_perf_client) {
1357 ret = msm_bus_scale_client_update_request(
1358 mehci->bus_perf_client, 0);
1359 if (ret)
1360 dev_err(mehci->dev, "%s: Failed to devote "
1361 "for bus bw %d\n", __func__, ret);
1362 }
1363 }
1364
1365 return count;
1366}
1367
1368const struct file_operations ehci_hsic_msm_bus_fops = {
1369 .open = ehci_hsic_msm_bus_open,
1370 .read = seq_read,
1371 .write = ehci_hsic_msm_bus_write,
1372 .llseek = seq_lseek,
1373 .release = single_release,
1374};
1375
Hemant Kumar6fd65032012-05-23 13:02:24 -07001376static int ehci_hsic_msm_wakeup_cnt_show(struct seq_file *s, void *unused)
1377{
1378 struct msm_hsic_hcd *mehci = s->private;
1379
1380 seq_printf(s, "%u\n", mehci->wakeup_int_cnt);
1381
1382 return 0;
1383}
1384
1385static int ehci_hsic_msm_wakeup_cnt_open(struct inode *inode, struct file *f)
1386{
1387 return single_open(f, ehci_hsic_msm_wakeup_cnt_show, inode->i_private);
1388}
1389
1390const struct file_operations ehci_hsic_msm_wakeup_cnt_fops = {
1391 .open = ehci_hsic_msm_wakeup_cnt_open,
1392 .read = seq_read,
1393 .llseek = seq_lseek,
1394 .release = single_release,
1395};
1396
Hemant Kumar45d211b2012-05-31 17:58:43 -07001397static int ehci_hsic_msm_data_events_show(struct seq_file *s, void *unused)
1398{
1399 unsigned long flags;
1400 unsigned i;
1401
1402 read_lock_irqsave(&dbg_hsic_data.lck, flags);
1403
1404 i = dbg_hsic_data.idx;
1405 for (dbg_inc(&i); i != dbg_hsic_data.idx; dbg_inc(&i)) {
1406 if (!strnlen(dbg_hsic_data.buf[i], DBG_MSG_LEN))
1407 continue;
1408 seq_printf(s, "%s\n", dbg_hsic_data.buf[i]);
1409 }
1410
1411 read_unlock_irqrestore(&dbg_hsic_data.lck, flags);
1412
1413 return 0;
1414}
1415
1416static int ehci_hsic_msm_data_events_open(struct inode *inode, struct file *f)
1417{
1418 return single_open(f, ehci_hsic_msm_data_events_show, inode->i_private);
1419}
1420
1421const struct file_operations ehci_hsic_msm_dbg_data_fops = {
1422 .open = ehci_hsic_msm_data_events_open,
1423 .read = seq_read,
1424 .llseek = seq_lseek,
1425 .release = single_release,
1426};
1427
1428static int ehci_hsic_msm_ctrl_events_show(struct seq_file *s, void *unused)
1429{
1430 unsigned long flags;
1431 unsigned i;
1432
1433 read_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
1434
1435 i = dbg_hsic_ctrl.idx;
1436 for (dbg_inc(&i); i != dbg_hsic_ctrl.idx; dbg_inc(&i)) {
1437 if (!strnlen(dbg_hsic_ctrl.buf[i], DBG_MSG_LEN))
1438 continue;
1439 seq_printf(s, "%s\n", dbg_hsic_ctrl.buf[i]);
1440 }
1441
1442 read_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags);
1443
1444 return 0;
1445}
1446
1447static int ehci_hsic_msm_ctrl_events_open(struct inode *inode, struct file *f)
1448{
1449 return single_open(f, ehci_hsic_msm_ctrl_events_show, inode->i_private);
1450}
1451
1452const struct file_operations ehci_hsic_msm_dbg_ctrl_fops = {
1453 .open = ehci_hsic_msm_ctrl_events_open,
1454 .read = seq_read,
1455 .llseek = seq_lseek,
1456 .release = single_release,
1457};
1458
Hemant Kumare6275972012-02-29 20:06:21 -08001459static struct dentry *ehci_hsic_msm_dbg_root;
1460static int ehci_hsic_msm_debugfs_init(struct msm_hsic_hcd *mehci)
1461{
1462 struct dentry *ehci_hsic_msm_dentry;
1463
1464 ehci_hsic_msm_dbg_root = debugfs_create_dir("ehci_hsic_msm_dbg", NULL);
1465
1466 if (!ehci_hsic_msm_dbg_root || IS_ERR(ehci_hsic_msm_dbg_root))
1467 return -ENODEV;
1468
1469 ehci_hsic_msm_dentry = debugfs_create_file("bus_voting",
1470 S_IRUGO | S_IWUSR,
1471 ehci_hsic_msm_dbg_root, mehci,
1472 &ehci_hsic_msm_bus_fops);
1473
1474 if (!ehci_hsic_msm_dentry) {
1475 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1476 return -ENODEV;
1477 }
1478
Hemant Kumar6fd65032012-05-23 13:02:24 -07001479 ehci_hsic_msm_dentry = debugfs_create_file("wakeup_cnt",
1480 S_IRUGO,
1481 ehci_hsic_msm_dbg_root, mehci,
1482 &ehci_hsic_msm_wakeup_cnt_fops);
1483
1484 if (!ehci_hsic_msm_dentry) {
1485 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1486 return -ENODEV;
1487 }
1488
Hemant Kumar45d211b2012-05-31 17:58:43 -07001489 ehci_hsic_msm_dentry = debugfs_create_file("show_ctrl_events",
1490 S_IRUGO,
1491 ehci_hsic_msm_dbg_root, mehci,
1492 &ehci_hsic_msm_dbg_ctrl_fops);
1493
1494 if (!ehci_hsic_msm_dentry) {
1495 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1496 return -ENODEV;
1497 }
1498
1499 ehci_hsic_msm_dentry = debugfs_create_file("show_data_events",
1500 S_IRUGO,
1501 ehci_hsic_msm_dbg_root, mehci,
1502 &ehci_hsic_msm_dbg_data_fops);
1503
1504 if (!ehci_hsic_msm_dentry) {
1505 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1506 return -ENODEV;
1507 }
1508
Hemant Kumare6275972012-02-29 20:06:21 -08001509 return 0;
1510}
1511
1512static void ehci_hsic_msm_debugfs_cleanup(void)
1513{
1514 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1515}
1516
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301517static int __devinit ehci_hsic_msm_probe(struct platform_device *pdev)
1518{
1519 struct usb_hcd *hcd;
1520 struct resource *res;
1521 struct msm_hsic_hcd *mehci;
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +05301522 struct msm_hsic_host_platform_data *pdata;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301523 int ret;
1524
1525 dev_dbg(&pdev->dev, "ehci_msm-hsic probe\n");
1526
Vijayavardhan Vennapusaafbbb8f2012-04-13 16:28:45 +05301527 /* After parent device's probe is executed, it will be put in suspend
1528 * mode. When child device's probe is called, driver core is not
1529 * resuming parent device due to which parent will be in suspend even
1530 * though child is active. Hence resume the parent device explicitly.
1531 */
1532 if (pdev->dev.parent)
1533 pm_runtime_get_sync(pdev->dev.parent);
1534
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301535 hcd = usb_create_hcd(&msm_hsic_driver, &pdev->dev,
1536 dev_name(&pdev->dev));
1537 if (!hcd) {
1538 dev_err(&pdev->dev, "Unable to create HCD\n");
1539 return -ENOMEM;
1540 }
1541
Pavankumar Kondeti6f199aa2012-09-18 17:52:51 +05301542 hcd_to_bus(hcd)->skip_resume = true;
1543
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301544 hcd->irq = platform_get_irq(pdev, 0);
1545 if (hcd->irq < 0) {
1546 dev_err(&pdev->dev, "Unable to get IRQ resource\n");
1547 ret = hcd->irq;
1548 goto put_hcd;
1549 }
1550
1551 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1552 if (!res) {
1553 dev_err(&pdev->dev, "Unable to get memory resource\n");
1554 ret = -ENODEV;
1555 goto put_hcd;
1556 }
1557
1558 hcd->rsrc_start = res->start;
1559 hcd->rsrc_len = resource_size(res);
1560 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
1561 if (!hcd->regs) {
1562 dev_err(&pdev->dev, "ioremap failed\n");
1563 ret = -ENOMEM;
1564 goto put_hcd;
1565 }
1566
1567 mehci = hcd_to_hsic(hcd);
1568 mehci->dev = &pdev->dev;
Hemant Kumar30d361c2012-08-20 14:44:40 -07001569 pdata = mehci->dev->platform_data;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301570
Hemant Kumard343c012012-09-06 19:57:14 -07001571 spin_lock_init(&mehci->wakeup_lock);
1572
Hemant Kumar38ce5d82012-05-29 13:00:58 -07001573 mehci->ehci.susp_sof_bug = 1;
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -07001574 mehci->ehci.reset_sof_bug = 1;
Hemant Kumar38ce5d82012-05-29 13:00:58 -07001575
Hemant Kumare4040492012-06-21 17:35:42 -07001576 mehci->ehci.resume_sof_bug = 1;
1577
Hemant Kumar30d361c2012-08-20 14:44:40 -07001578 if (pdata)
1579 mehci->ehci.log2_irq_thresh = pdata->log2_irq_thresh;
Hemant Kumar933e0402012-05-22 11:11:40 -07001580
Vamsi Krishna34f01582011-12-14 19:54:42 -08001581 res = platform_get_resource_byname(pdev,
1582 IORESOURCE_IRQ,
1583 "peripheral_status_irq");
1584 if (res)
1585 mehci->peripheral_status_irq = res->start;
1586
Jack Pham0cc75c42012-10-10 02:03:50 +02001587 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "wakeup");
Hemant Kumar6fd65032012-05-23 13:02:24 -07001588 if (res) {
Jack Pham0cc75c42012-10-10 02:03:50 +02001589 mehci->wakeup_irq = res->start;
Hemant Kumar6fd65032012-05-23 13:02:24 -07001590 dev_dbg(mehci->dev, "wakeup_irq: %d\n", mehci->wakeup_irq);
1591 }
1592
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301593 ret = msm_hsic_init_clocks(mehci, 1);
1594 if (ret) {
1595 dev_err(&pdev->dev, "unable to initialize clocks\n");
1596 ret = -ENODEV;
1597 goto unmap;
1598 }
1599
1600 ret = msm_hsic_init_vddcx(mehci, 1);
1601 if (ret) {
1602 dev_err(&pdev->dev, "unable to initialize VDDCX\n");
1603 ret = -ENODEV;
1604 goto deinit_clocks;
1605 }
1606
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001607 init_completion(&mehci->rt_completion);
1608 init_completion(&mehci->gpt0_completion);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301609 ret = msm_hsic_reset(mehci);
1610 if (ret) {
1611 dev_err(&pdev->dev, "unable to initialize PHY\n");
Vijayavardhan Vennapusaafbbb8f2012-04-13 16:28:45 +05301612 goto deinit_vddcx;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301613 }
1614
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001615 ehci_wq = create_singlethread_workqueue("ehci_wq");
1616 if (!ehci_wq) {
1617 dev_err(&pdev->dev, "unable to create workqueue\n");
1618 ret = -ENOMEM;
1619 goto deinit_vddcx;
1620 }
1621
1622 INIT_WORK(&mehci->bus_vote_w, ehci_hsic_bus_vote_w);
1623
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301624 ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
1625 if (ret) {
1626 dev_err(&pdev->dev, "unable to register HCD\n");
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +05301627 goto unconfig_gpio;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301628 }
1629
1630 device_init_wakeup(&pdev->dev, 1);
Sudhir Sharma1673e302012-08-27 17:37:24 -07001631 wake_lock_init(&mehci->wlock, WAKE_LOCK_SUSPEND, dev_name(&pdev->dev));
1632 wake_lock(&mehci->wlock);
Vamsi Krishna34f01582011-12-14 19:54:42 -08001633
1634 if (mehci->peripheral_status_irq) {
1635 ret = request_threaded_irq(mehci->peripheral_status_irq,
1636 NULL, hsic_peripheral_status_change,
1637 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
1638 | IRQF_SHARED,
1639 "hsic_peripheral_status", mehci);
1640 if (ret)
1641 dev_err(&pdev->dev, "%s:request_irq:%d failed:%d",
1642 __func__, mehci->peripheral_status_irq, ret);
1643 }
1644
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001645 /* configure wakeup irq */
Hemant Kumar6fd65032012-05-23 13:02:24 -07001646 if (mehci->wakeup_irq) {
Hemant Kumarbbcdcbc2012-08-30 14:23:38 -07001647 /* In case if wakeup gpio is pulled high at this point
1648 * remote wakeup interrupt fires right after request_irq.
1649 * Remote wake up interrupt only needs to be enabled when
1650 * HSIC bus goes to suspend.
1651 */
1652 irq_set_status_flags(mehci->wakeup_irq, IRQ_NOAUTOEN);
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001653 ret = request_irq(mehci->wakeup_irq, msm_hsic_wakeup_irq,
Hemant Kumar6fd65032012-05-23 13:02:24 -07001654 IRQF_TRIGGER_HIGH,
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001655 "msm_hsic_wakeup", mehci);
Hemant Kumarbbcdcbc2012-08-30 14:23:38 -07001656 if (ret) {
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001657 dev_err(&pdev->dev, "request_irq(%d) failed: %d\n",
1658 mehci->wakeup_irq, ret);
1659 mehci->wakeup_irq = 0;
1660 }
1661 }
1662
Hemant Kumare6275972012-02-29 20:06:21 -08001663 ret = ehci_hsic_msm_debugfs_init(mehci);
1664 if (ret)
1665 dev_dbg(&pdev->dev, "mode debugfs file is"
1666 "not available\n");
1667
1668 if (pdata && pdata->bus_scale_table) {
1669 mehci->bus_perf_client =
1670 msm_bus_scale_register_client(pdata->bus_scale_table);
1671 /* Configure BUS performance parameters for MAX bandwidth */
1672 if (mehci->bus_perf_client) {
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001673 mehci->bus_vote = true;
1674 queue_work(ehci_wq, &mehci->bus_vote_w);
Hemant Kumare6275972012-02-29 20:06:21 -08001675 } else {
1676 dev_err(&pdev->dev, "%s: Failed to register BUS "
1677 "scaling client!!\n", __func__);
1678 }
1679 }
1680
Hemant Kumar105d07f2012-07-02 15:33:07 -07001681 __mehci = mehci;
1682
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05301683 if (pdata && pdata->swfi_latency)
1684 pm_qos_add_request(&mehci->pm_qos_req_dma,
1685 PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
1686
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301687 /*
1688 * This pdev->dev is assigned parent of root-hub by USB core,
1689 * hence, runtime framework automatically calls this driver's
1690 * runtime APIs based on root-hub's state.
1691 */
1692 pm_runtime_set_active(&pdev->dev);
1693 pm_runtime_enable(&pdev->dev);
Vijayavardhan Vennapusaafbbb8f2012-04-13 16:28:45 +05301694 /* Decrement the parent device's counter after probe.
1695 * As child is active, parent will not be put into
1696 * suspend mode.
1697 */
1698 if (pdev->dev.parent)
1699 pm_runtime_put_sync(pdev->dev.parent);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301700
1701 return 0;
1702
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +05301703unconfig_gpio:
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001704 destroy_workqueue(ehci_wq);
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +05301705 msm_hsic_config_gpios(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301706deinit_vddcx:
1707 msm_hsic_init_vddcx(mehci, 0);
1708deinit_clocks:
1709 msm_hsic_init_clocks(mehci, 0);
1710unmap:
1711 iounmap(hcd->regs);
1712put_hcd:
1713 usb_put_hcd(hcd);
1714
1715 return ret;
1716}
1717
1718static int __devexit ehci_hsic_msm_remove(struct platform_device *pdev)
1719{
1720 struct usb_hcd *hcd = platform_get_drvdata(pdev);
1721 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05301722 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
1723
1724 if (pdata && pdata->swfi_latency)
1725 pm_qos_remove_request(&mehci->pm_qos_req_dma);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301726
Vamsi Krishna34f01582011-12-14 19:54:42 -08001727 if (mehci->peripheral_status_irq)
1728 free_irq(mehci->peripheral_status_irq, mehci);
Jack Phamfe441ea2012-03-23 17:03:15 -07001729
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001730 if (mehci->wakeup_irq) {
Jack Phamfe441ea2012-03-23 17:03:15 -07001731 if (mehci->wakeup_irq_enabled)
1732 disable_irq_wake(mehci->wakeup_irq);
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001733 free_irq(mehci->wakeup_irq, mehci);
1734 }
Vamsi Krishna34f01582011-12-14 19:54:42 -08001735
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001736 /*
1737 * If the update request is called after unregister, the request will
1738 * fail. Results are undefined if unregister is called in the middle of
1739 * update request.
1740 */
1741 mehci->bus_vote = false;
1742 cancel_work_sync(&mehci->bus_vote_w);
1743
Hemant Kumare6275972012-02-29 20:06:21 -08001744 if (mehci->bus_perf_client)
1745 msm_bus_scale_unregister_client(mehci->bus_perf_client);
1746
1747 ehci_hsic_msm_debugfs_cleanup();
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301748 device_init_wakeup(&pdev->dev, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301749 pm_runtime_set_suspended(&pdev->dev);
1750
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001751 destroy_workqueue(ehci_wq);
1752
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301753 usb_remove_hcd(hcd);
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +05301754 msm_hsic_config_gpios(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301755 msm_hsic_init_vddcx(mehci, 0);
1756
1757 msm_hsic_init_clocks(mehci, 0);
Sudhir Sharma1673e302012-08-27 17:37:24 -07001758 wake_lock_destroy(&mehci->wlock);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301759 iounmap(hcd->regs);
1760 usb_put_hcd(hcd);
1761
1762 return 0;
1763}
1764
1765#ifdef CONFIG_PM_SLEEP
1766static int msm_hsic_pm_suspend(struct device *dev)
1767{
Jack Phambe05fbb2012-05-16 10:56:26 -07001768 int ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301769 struct usb_hcd *hcd = dev_get_drvdata(dev);
1770 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1771
1772 dev_dbg(dev, "ehci-msm-hsic PM suspend\n");
1773
Hemant Kumar45d211b2012-05-31 17:58:43 -07001774 dbg_log_event(NULL, "PM Suspend", 0);
1775
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301776 if (device_may_wakeup(dev))
1777 enable_irq_wake(hcd->irq);
1778
Jack Phambe05fbb2012-05-16 10:56:26 -07001779 ret = msm_hsic_suspend(mehci);
1780
1781 if (ret && device_may_wakeup(dev))
1782 disable_irq_wake(hcd->irq);
1783
1784 return ret;
Jack Phamfe441ea2012-03-23 17:03:15 -07001785}
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301786
Jack Pham16b06f82012-08-14 20:03:59 -07001787static int msm_hsic_pm_suspend_noirq(struct device *dev)
1788{
1789 struct usb_hcd *hcd = dev_get_drvdata(dev);
1790 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1791
1792 if (mehci->async_int) {
1793 dev_dbg(dev, "suspend_noirq: Aborting due to pending interrupt\n");
1794 return -EBUSY;
1795 }
1796
1797 return 0;
1798}
1799
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301800static int msm_hsic_pm_resume(struct device *dev)
1801{
1802 int ret;
1803 struct usb_hcd *hcd = dev_get_drvdata(dev);
1804 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1805
Jack Pham16b06f82012-08-14 20:03:59 -07001806 dev_dbg(dev, "ehci-msm-hsic PM resume\n");
Hemant Kumar45d211b2012-05-31 17:58:43 -07001807 dbg_log_event(NULL, "PM Resume", 0);
1808
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301809 if (device_may_wakeup(dev))
1810 disable_irq_wake(hcd->irq);
1811
Pavankumar Kondeti6f199aa2012-09-18 17:52:51 +05301812 /*
1813 * Keep HSIC in Low Power Mode if system is resumed
1814 * by any other wakeup source. HSIC is resumed later
1815 * when remote wakeup is received or interface driver
1816 * start I/O.
1817 */
1818 if (!atomic_read(&mehci->pm_usage_cnt))
1819 return 0;
1820
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301821 ret = msm_hsic_resume(mehci);
1822 if (ret)
1823 return ret;
1824
1825 /* Bring the device to full powered state upon system resume */
1826 pm_runtime_disable(dev);
1827 pm_runtime_set_active(dev);
1828 pm_runtime_enable(dev);
1829
1830 return 0;
1831}
1832#endif
1833
1834#ifdef CONFIG_PM_RUNTIME
1835static int msm_hsic_runtime_idle(struct device *dev)
1836{
1837 dev_dbg(dev, "EHCI runtime idle\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301838 return 0;
1839}
1840
1841static int msm_hsic_runtime_suspend(struct device *dev)
1842{
1843 struct usb_hcd *hcd = dev_get_drvdata(dev);
1844 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1845
1846 dev_dbg(dev, "EHCI runtime suspend\n");
Hemant Kumar45d211b2012-05-31 17:58:43 -07001847
1848 dbg_log_event(NULL, "Run Time PM Suspend", 0);
1849
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301850 return msm_hsic_suspend(mehci);
1851}
1852
1853static int msm_hsic_runtime_resume(struct device *dev)
1854{
1855 struct usb_hcd *hcd = dev_get_drvdata(dev);
1856 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1857
1858 dev_dbg(dev, "EHCI runtime resume\n");
Hemant Kumar45d211b2012-05-31 17:58:43 -07001859
1860 dbg_log_event(NULL, "Run Time PM Resume", 0);
1861
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301862 return msm_hsic_resume(mehci);
1863}
1864#endif
1865
1866#ifdef CONFIG_PM
1867static const struct dev_pm_ops msm_hsic_dev_pm_ops = {
1868 SET_SYSTEM_SLEEP_PM_OPS(msm_hsic_pm_suspend, msm_hsic_pm_resume)
Jack Pham16b06f82012-08-14 20:03:59 -07001869 .suspend_noirq = msm_hsic_pm_suspend_noirq,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301870 SET_RUNTIME_PM_OPS(msm_hsic_runtime_suspend, msm_hsic_runtime_resume,
1871 msm_hsic_runtime_idle)
1872};
1873#endif
1874
1875static struct platform_driver ehci_msm_hsic_driver = {
1876 .probe = ehci_hsic_msm_probe,
1877 .remove = __devexit_p(ehci_hsic_msm_remove),
1878 .driver = {
1879 .name = "msm_hsic_host",
1880#ifdef CONFIG_PM
1881 .pm = &msm_hsic_dev_pm_ops,
1882#endif
1883 },
1884};