blob: 7674d88f492c869ffb77f96620257634b911f8fc [file] [log] [blame]
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301/* ehci-msm-hsic.c - HSUSB Host Controller Driver Implementation
2 *
Ido Shayevitz95c46882013-01-20 13:47:46 +02003 * Copyright (c) 2011-2013, The Linux Foundation. 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
Manu Gautam863b74132012-11-21 14:30:04 +053034#include <linux/usb/ulpi.h>
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053035#include <linux/usb/msm_hsusb_hw.h>
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +053036#include <linux/usb/msm_hsusb.h>
37#include <linux/gpio.h>
Manu Gautam863b74132012-11-21 14:30:04 +053038#include <linux/of_gpio.h>
Amit Blayd6ea6102012-06-07 16:26:24 +030039#include <linux/spinlock.h>
Hemant Kumarbbcdcbc2012-08-30 14:23:38 -070040#include <linux/irq.h>
Vamsi Krishnafce1bd22012-08-17 17:12:26 -070041#include <linux/kthread.h>
42#include <linux/wait.h>
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +053043#include <linux/pm_qos.h>
Amit Blayd6ea6102012-06-07 16:26:24 +030044
45#include <mach/msm_bus.h>
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053046#include <mach/clk.h>
47#include <mach/msm_iomap.h>
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +053048#include <mach/msm_xo.h>
Vamsi Krishna34f01582011-12-14 19:54:42 -080049#include <linux/spinlock.h>
Hemant Kumar45d211b2012-05-31 17:58:43 -070050#include <linux/cpu.h>
Amit Blayd6ea6102012-06-07 16:26:24 +030051#include <mach/rpm-regulator.h>
Shimrit Malichi82d7cbc2013-03-12 15:36:54 +020052#include "hbm.c"
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053053
54#define MSM_USB_BASE (hcd->regs)
Hemant Kumar105d07f2012-07-02 15:33:07 -070055#define USB_REG_START_OFFSET 0x90
56#define USB_REG_END_OFFSET 0x250
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053057
Hemant Kumar2309eaa2012-08-14 16:46:42 -070058static struct workqueue_struct *ehci_wq;
Vamsi Krishnafce1bd22012-08-17 17:12:26 -070059struct ehci_timer {
60#define GPT_LD(p) ((p) & 0x00FFFFFF)
61 u32 gptimer0_ld;
62#define GPT_RUN BIT(31)
63#define GPT_RESET BIT(30)
64#define GPT_MODE BIT(24)
65#define GPT_CNT(p) ((p) & 0x00FFFFFF)
66 u32 gptimer0_ctrl;
67
68 u32 gptimer1_ld;
69 u32 gptimer1_ctrl;
70};
Hemant Kumar2309eaa2012-08-14 16:46:42 -070071
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053072struct msm_hsic_hcd {
73 struct ehci_hcd ehci;
Hemant Kumard343c012012-09-06 19:57:14 -070074 spinlock_t wakeup_lock;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053075 struct device *dev;
76 struct clk *ahb_clk;
Manu Gautam5143b252012-01-05 19:25:23 -080077 struct clk *core_clk;
78 struct clk *alt_core_clk;
79 struct clk *phy_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053080 struct clk *cal_clk;
Ido Shayevitz5dfbb132013-04-18 13:22:07 +030081 struct clk *inactivity_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053082 struct regulator *hsic_vddcx;
Ofir Cohen4cc55372012-11-20 11:17:24 +020083 struct regulator *hsic_gdsc;
Pavankumar Kondeti822fbe62013-01-28 17:04:39 +053084 atomic_t async_int;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +053085 atomic_t in_lpm;
Sudhir Sharma1673e302012-08-27 17:37:24 -070086 struct wake_lock wlock;
Vamsi Krishna34f01582011-12-14 19:54:42 -080087 int peripheral_status_irq;
Vamsi Krishna6921cbe2012-02-21 18:34:43 -080088 int wakeup_irq;
Jack Phamfe441ea2012-03-23 17:03:15 -070089 bool wakeup_irq_enabled;
Manu Gautam3fb60ca2013-02-13 18:33:33 +053090 int async_irq;
91 uint32_t async_int_cnt;
Sudhir Sharma1673e302012-08-27 17:37:24 -070092 atomic_t pm_usage_cnt;
Hemant Kumare6275972012-02-29 20:06:21 -080093 uint32_t bus_perf_client;
Hemant Kumar6fd65032012-05-23 13:02:24 -070094 uint32_t wakeup_int_cnt;
Amit Blayd6ea6102012-06-07 16:26:24 +030095 enum usb_vdd_type vdd_type;
Hemant Kumar2309eaa2012-08-14 16:46:42 -070096
97 struct work_struct bus_vote_w;
98 bool bus_vote;
Vamsi Krishnafce1bd22012-08-17 17:12:26 -070099
100 /* gp timer */
101 struct ehci_timer __iomem *timer;
102 struct completion gpt0_completion;
103 struct completion rt_completion;
104 int resume_status;
105 int resume_again;
Pavankumar Kondeti23720492013-01-29 14:41:58 +0530106 int bus_reset;
107 int reset_again;
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +0530108
109 struct pm_qos_request pm_qos_req_dma;
Shimrit Malichi82d7cbc2013-03-12 15:36:54 +0200110 unsigned enable_hbm:1;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530111};
112
Hemant Kumar105d07f2012-07-02 15:33:07 -0700113struct msm_hsic_hcd *__mehci;
114
Hemant Kumare6275972012-02-29 20:06:21 -0800115static bool debug_bus_voting_enabled = true;
Ofir Cohen4cc55372012-11-20 11:17:24 +0200116static u64 ehci_msm_hsic_dma_mask = DMA_BIT_MASK(32);
117
Manu Gautam863b74132012-11-21 14:30:04 +0530118static struct platform_driver ehci_msm_hsic_driver;
Hemant Kumar45d211b2012-05-31 17:58:43 -0700119
Hemant Kumar4d50a432012-08-15 09:06:35 -0700120static unsigned int enable_payload_log = 1;
121module_param(enable_payload_log, uint, S_IRUGO | S_IWUSR);
Hemant Kumar45d211b2012-05-31 17:58:43 -0700122static unsigned int enable_dbg_log = 1;
123module_param(enable_dbg_log, uint, S_IRUGO | S_IWUSR);
124/*by default log ep0 and efs sync ep*/
125static unsigned int ep_addr_rxdbg_mask = 9;
126module_param(ep_addr_rxdbg_mask, uint, S_IRUGO | S_IWUSR);
127static unsigned int ep_addr_txdbg_mask = 9;
128module_param(ep_addr_txdbg_mask, uint, S_IRUGO | S_IWUSR);
129
130/* Maximum debug message length */
Hemant Kumar4d50a432012-08-15 09:06:35 -0700131#define DBG_MSG_LEN 128UL
Hemant Kumar45d211b2012-05-31 17:58:43 -0700132
133/* Maximum number of messages */
134#define DBG_MAX_MSG 256UL
135
136#define TIME_BUF_LEN 20
Hemant Kumar4d50a432012-08-15 09:06:35 -0700137#define HEX_DUMP_LEN 72
Hemant Kumar45d211b2012-05-31 17:58:43 -0700138
139enum event_type {
140 EVENT_UNDEF = -1,
141 URB_SUBMIT,
142 URB_COMPLETE,
143 EVENT_NONE,
144};
145
146#define EVENT_STR_LEN 5
147
Hemant Kumar45d211b2012-05-31 17:58:43 -0700148static enum event_type str_to_event(const char *name)
149{
150 if (!strncasecmp("S", name, EVENT_STR_LEN))
151 return URB_SUBMIT;
152 if (!strncasecmp("C", name, EVENT_STR_LEN))
153 return URB_COMPLETE;
154 if (!strncasecmp("", name, EVENT_STR_LEN))
155 return EVENT_NONE;
156
157 return EVENT_UNDEF;
158}
159
160/*log ep0 activity*/
161static struct {
162 char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */
163 unsigned idx; /* index */
164 rwlock_t lck; /* lock */
165} dbg_hsic_ctrl = {
166 .idx = 0,
167 .lck = __RW_LOCK_UNLOCKED(lck)
168};
169
170static struct {
171 char (buf[DBG_MAX_MSG])[DBG_MSG_LEN]; /* buffer */
172 unsigned idx; /* index */
173 rwlock_t lck; /* lock */
174} dbg_hsic_data = {
175 .idx = 0,
176 .lck = __RW_LOCK_UNLOCKED(lck)
177};
178
179/**
180 * dbg_inc: increments debug event index
181 * @idx: buffer index
182 */
183static void dbg_inc(unsigned *idx)
184{
185 *idx = (*idx + 1) & (DBG_MAX_MSG-1);
186}
187
188/*get_timestamp - returns time of day in us */
189static char *get_timestamp(char *tbuf)
190{
191 unsigned long long t;
192 unsigned long nanosec_rem;
193
194 t = cpu_clock(smp_processor_id());
195 nanosec_rem = do_div(t, 1000000000)/1000;
196 scnprintf(tbuf, TIME_BUF_LEN, "[%5lu.%06lu] ", (unsigned long)t,
197 nanosec_rem);
198 return tbuf;
199}
200
201static int allow_dbg_log(int ep_addr)
202{
203 int dir, num;
204
205 dir = ep_addr & USB_DIR_IN ? USB_DIR_IN : USB_DIR_OUT;
206 num = ep_addr & ~USB_DIR_IN;
207 num = 1 << num;
208
209 if ((dir == USB_DIR_IN) && (num & ep_addr_rxdbg_mask))
210 return 1;
211 if ((dir == USB_DIR_OUT) && (num & ep_addr_txdbg_mask))
212 return 1;
213
214 return 0;
215}
216
Hemant Kumar4d50a432012-08-15 09:06:35 -0700217static char *get_hex_data(char *dbuf, struct urb *urb, int event, int status)
218{
219 int ep_addr = urb->ep->desc.bEndpointAddress;
220 char *ubuf = urb->transfer_buffer;
221 size_t len = event ? \
222 urb->actual_length : urb->transfer_buffer_length;
223
224 if (status == -EINPROGRESS)
225 status = 0;
226
227 /*Only dump ep in completions and epout submissions*/
228 if (len && !status &&
229 (((ep_addr & USB_DIR_IN) && event) ||
230 (!(ep_addr & USB_DIR_IN) && !event))) {
231 if (len >= 32)
232 len = 32;
233 hex_dump_to_buffer(ubuf, len, 32, 4, dbuf, HEX_DUMP_LEN, 0);
234 } else {
235 dbuf = "";
236 }
237
238 return dbuf;
239}
240
Hemant Kumar45d211b2012-05-31 17:58:43 -0700241static void dbg_log_event(struct urb *urb, char * event, unsigned extra)
242{
243 unsigned long flags;
244 int ep_addr;
245 char tbuf[TIME_BUF_LEN];
Hemant Kumar4d50a432012-08-15 09:06:35 -0700246 char dbuf[HEX_DUMP_LEN];
Hemant Kumar45d211b2012-05-31 17:58:43 -0700247
248 if (!enable_dbg_log)
249 return;
250
251 if (!urb) {
252 write_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
253 scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx], DBG_MSG_LEN,
Hemant Kumar4d50a432012-08-15 09:06:35 -0700254 "%s: %s : %u", get_timestamp(tbuf), event, extra);
Hemant Kumar45d211b2012-05-31 17:58:43 -0700255 dbg_inc(&dbg_hsic_ctrl.idx);
256 write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags);
257 return;
258 }
259
260 ep_addr = urb->ep->desc.bEndpointAddress;
261 if (!allow_dbg_log(ep_addr))
262 return;
263
264 if ((ep_addr & 0x0f) == 0x0) {
265 /*submit event*/
266 if (!str_to_event(event)) {
267 write_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
268 scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx],
269 DBG_MSG_LEN, "%s: [%s : %p]:[%s] "
Hemant Kumar4d50a432012-08-15 09:06:35 -0700270 "%02x %02x %04x %04x %04x %u %d",
Hemant Kumar45d211b2012-05-31 17:58:43 -0700271 get_timestamp(tbuf), event, urb,
272 (ep_addr & USB_DIR_IN) ? "in" : "out",
273 urb->setup_packet[0], urb->setup_packet[1],
274 (urb->setup_packet[3] << 8) |
275 urb->setup_packet[2],
276 (urb->setup_packet[5] << 8) |
277 urb->setup_packet[4],
278 (urb->setup_packet[7] << 8) |
279 urb->setup_packet[6],
Hemant Kumar4d50a432012-08-15 09:06:35 -0700280 urb->transfer_buffer_length, extra);
Hemant Kumar45d211b2012-05-31 17:58:43 -0700281
282 dbg_inc(&dbg_hsic_ctrl.idx);
283 write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags);
284 } else {
285 write_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
286 scnprintf(dbg_hsic_ctrl.buf[dbg_hsic_ctrl.idx],
Hemant Kumar4d50a432012-08-15 09:06:35 -0700287 DBG_MSG_LEN, "%s: [%s : %p]:[%s] %u %d",
Hemant Kumar45d211b2012-05-31 17:58:43 -0700288 get_timestamp(tbuf), event, urb,
289 (ep_addr & USB_DIR_IN) ? "in" : "out",
290 urb->actual_length, extra);
291
292 dbg_inc(&dbg_hsic_ctrl.idx);
293 write_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags);
294 }
295 } else {
296 write_lock_irqsave(&dbg_hsic_data.lck, flags);
297 scnprintf(dbg_hsic_data.buf[dbg_hsic_data.idx], DBG_MSG_LEN,
Hemant Kumar4d50a432012-08-15 09:06:35 -0700298 "%s: [%s : %p]:ep%d[%s] %u %d %s",
Hemant Kumar45d211b2012-05-31 17:58:43 -0700299 get_timestamp(tbuf), event, urb, ep_addr & 0x0f,
300 (ep_addr & USB_DIR_IN) ? "in" : "out",
301 str_to_event(event) ? urb->actual_length :
Hemant Kumar4d50a432012-08-15 09:06:35 -0700302 urb->transfer_buffer_length, extra,
303 enable_payload_log ? get_hex_data(dbuf, urb,
304 str_to_event(event), extra) : "");
Hemant Kumar45d211b2012-05-31 17:58:43 -0700305
306 dbg_inc(&dbg_hsic_data.idx);
307 write_unlock_irqrestore(&dbg_hsic_data.lck, flags);
308 }
309}
310
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530311static inline struct msm_hsic_hcd *hcd_to_hsic(struct usb_hcd *hcd)
312{
313 return (struct msm_hsic_hcd *) (hcd->hcd_priv);
314}
315
316static inline struct usb_hcd *hsic_to_hcd(struct msm_hsic_hcd *mehci)
317{
318 return container_of((void *) mehci, struct usb_hcd, hcd_priv);
319}
320
Hemant Kumar105d07f2012-07-02 15:33:07 -0700321static void dump_hsic_regs(struct usb_hcd *hcd)
322{
323 int i;
324 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
325
326 if (atomic_read(&mehci->in_lpm))
327 return;
328
329 for (i = USB_REG_START_OFFSET; i <= USB_REG_END_OFFSET; i += 0x10)
330 pr_info("%p: %08x\t%08x\t%08x\t%08x\n", hcd->regs + i,
331 readl_relaxed(hcd->regs + i),
332 readl_relaxed(hcd->regs + i + 4),
333 readl_relaxed(hcd->regs + i + 8),
334 readl_relaxed(hcd->regs + i + 0xc));
335}
336
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530337#define ULPI_IO_TIMEOUT_USEC (10 * 1000)
338
Amit Blayd6ea6102012-06-07 16:26:24 +0300339#define USB_PHY_VDD_DIG_VOL_NONE 0 /*uV */
Hemant Kumar3b743cd2012-10-17 13:48:10 -0700340#define USB_PHY_VDD_DIG_VOL_MIN 945000 /* uV */
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700341#define USB_PHY_VDD_DIG_VOL_MAX 1320000 /* uV */
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530342
Lena Salman8c8ba382012-02-14 15:59:31 +0200343#define HSIC_DBG1_REG 0x38
344
Amit Blayd6ea6102012-06-07 16:26:24 +0300345static const int vdd_val[VDD_TYPE_MAX][VDD_VAL_MAX] = {
346 { /* VDD_CX CORNER Voting */
347 [VDD_NONE] = RPM_VREG_CORNER_NONE,
348 [VDD_MIN] = RPM_VREG_CORNER_NOMINAL,
349 [VDD_MAX] = RPM_VREG_CORNER_HIGH,
350 },
351 { /* VDD_CX Voltage Voting */
352 [VDD_NONE] = USB_PHY_VDD_DIG_VOL_NONE,
353 [VDD_MIN] = USB_PHY_VDD_DIG_VOL_MIN,
354 [VDD_MAX] = USB_PHY_VDD_DIG_VOL_MAX,
355 },
356};
357
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530358static int msm_hsic_init_vddcx(struct msm_hsic_hcd *mehci, int init)
359{
360 int ret = 0;
Amit Blayd6ea6102012-06-07 16:26:24 +0300361 int none_vol, min_vol, max_vol;
362
363 if (!mehci->hsic_vddcx) {
364 mehci->vdd_type = VDDCX_CORNER;
365 mehci->hsic_vddcx = devm_regulator_get(mehci->dev,
366 "hsic_vdd_dig");
367 if (IS_ERR(mehci->hsic_vddcx)) {
368 mehci->hsic_vddcx = devm_regulator_get(mehci->dev,
369 "HSIC_VDDCX");
370 if (IS_ERR(mehci->hsic_vddcx)) {
371 dev_err(mehci->dev, "unable to get hsic vddcx\n");
372 return PTR_ERR(mehci->hsic_vddcx);
373 }
374 mehci->vdd_type = VDDCX;
375 }
376 }
377
378 none_vol = vdd_val[mehci->vdd_type][VDD_NONE];
379 min_vol = vdd_val[mehci->vdd_type][VDD_MIN];
380 max_vol = vdd_val[mehci->vdd_type][VDD_MAX];
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530381
382 if (!init)
383 goto disable_reg;
384
Amit Blayd6ea6102012-06-07 16:26:24 +0300385 ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530386 if (ret) {
387 dev_err(mehci->dev, "unable to set the voltage"
388 "for hsic vddcx\n");
Mayank Rana189ac052012-03-24 04:35:02 +0530389 return ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530390 }
391
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530392 ret = regulator_enable(mehci->hsic_vddcx);
393 if (ret) {
394 dev_err(mehci->dev, "unable to enable hsic vddcx\n");
395 goto reg_enable_err;
396 }
397
398 return 0;
399
400disable_reg:
401 regulator_disable(mehci->hsic_vddcx);
402reg_enable_err:
Amit Blayd6ea6102012-06-07 16:26:24 +0300403 regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol);
404
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530405 return ret;
406
407}
408
Ofir Cohen4cc55372012-11-20 11:17:24 +0200409/* Global Distributed Switch Controller (GDSC) init */
410static int msm_hsic_init_gdsc(struct msm_hsic_hcd *mehci, int init)
411{
412 int ret = 0;
413
414 if (IS_ERR(mehci->hsic_gdsc))
415 return 0;
416
417 if (!mehci->hsic_gdsc) {
418 mehci->hsic_gdsc = devm_regulator_get(mehci->dev,
419 "HSIC_GDSC");
420 if (IS_ERR(mehci->hsic_gdsc))
421 return 0;
422 }
423
424 if (init) {
425 ret = regulator_enable(mehci->hsic_gdsc);
426 if (ret) {
427 dev_err(mehci->dev, "unable to enable hsic gdsc\n");
428 return ret;
429 }
430 } else {
431 regulator_disable(mehci->hsic_gdsc);
432 }
433
434 return 0;
435
436}
437
Pavankumar Kondeti23720492013-01-29 14:41:58 +0530438static int __maybe_unused ulpi_read(struct msm_hsic_hcd *mehci, u32 reg)
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -0700439{
440 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Hemant Kumar8fdc3982012-08-21 12:22:27 -0700441 int cnt = 0;
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -0700442
443 /* initiate read operation */
444 writel_relaxed(ULPI_RUN | ULPI_READ | ULPI_ADDR(reg),
445 USB_ULPI_VIEWPORT);
446
447 /* wait for completion */
Hemant Kumar8fdc3982012-08-21 12:22:27 -0700448 while (cnt < ULPI_IO_TIMEOUT_USEC) {
449 if (!(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN))
450 break;
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -0700451 udelay(1);
Hemant Kumar8fdc3982012-08-21 12:22:27 -0700452 cnt++;
453 }
454
455 if (cnt >= ULPI_IO_TIMEOUT_USEC) {
456 dev_err(mehci->dev, "ulpi_read: timeout ULPI_VIEWPORT: %08x\n",
457 readl_relaxed(USB_ULPI_VIEWPORT));
458 dev_err(mehci->dev, "PORTSC: %08x USBCMD: %08x FRINDEX: %08x\n",
459 readl_relaxed(USB_PORTSC),
460 readl_relaxed(USB_USBCMD),
461 readl_relaxed(USB_FRINDEX));
462
463 /*frame counter increments afte 125us*/
464 udelay(130);
465 dev_err(mehci->dev, "ulpi_read: FRINDEX: %08x\n",
466 readl_relaxed(USB_FRINDEX));
467 return -ETIMEDOUT;
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -0700468 }
469
470 return ULPI_DATA_READ(readl_relaxed(USB_ULPI_VIEWPORT));
471}
472
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530473static int ulpi_write(struct msm_hsic_hcd *mehci, u32 val, u32 reg)
474{
475 struct usb_hcd *hcd = hsic_to_hcd(mehci);
476 int cnt = 0;
477
478 /* initiate write operation */
479 writel_relaxed(ULPI_RUN | ULPI_WRITE |
480 ULPI_ADDR(reg) | ULPI_DATA(val),
481 USB_ULPI_VIEWPORT);
482
483 /* wait for completion */
484 while (cnt < ULPI_IO_TIMEOUT_USEC) {
485 if (!(readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_RUN))
486 break;
487 udelay(1);
488 cnt++;
489 }
490
491 if (cnt >= ULPI_IO_TIMEOUT_USEC) {
Hemant Kumar8fdc3982012-08-21 12:22:27 -0700492 dev_err(mehci->dev, "ulpi_write: timeout ULPI_VIEWPORT: %08x\n",
493 readl_relaxed(USB_ULPI_VIEWPORT));
494 dev_err(mehci->dev, "PORTSC: %08x USBCMD: %08x FRINDEX: %08x\n",
495 readl_relaxed(USB_PORTSC),
496 readl_relaxed(USB_USBCMD),
497 readl_relaxed(USB_FRINDEX));
498
499 /*frame counter increments afte 125us*/
500 udelay(130);
501 dev_err(mehci->dev, "ulpi_write: FRINDEX: %08x\n",
502 readl_relaxed(USB_FRINDEX));
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530503 return -ETIMEDOUT;
504 }
505
506 return 0;
507}
508
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530509static int msm_hsic_config_gpios(struct msm_hsic_hcd *mehci, int gpio_en)
510{
511 int rc = 0;
512 struct msm_hsic_host_platform_data *pdata;
Vamsi Krishna34f01582011-12-14 19:54:42 -0800513 static int gpio_status;
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530514
515 pdata = mehci->dev->platform_data;
Vamsi Krishna34f01582011-12-14 19:54:42 -0800516
Lena Salman8c8ba382012-02-14 15:59:31 +0200517 if (!pdata || !pdata->strobe || !pdata->data)
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530518 return rc;
519
Vamsi Krishna34f01582011-12-14 19:54:42 -0800520 if (gpio_status == gpio_en)
521 return 0;
522
523 gpio_status = gpio_en;
524
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530525 if (!gpio_en)
526 goto free_gpio;
527
528 rc = gpio_request(pdata->strobe, "HSIC_STROBE_GPIO");
529 if (rc < 0) {
530 dev_err(mehci->dev, "gpio request failed for HSIC STROBE\n");
531 return rc;
532 }
533
534 rc = gpio_request(pdata->data, "HSIC_DATA_GPIO");
535 if (rc < 0) {
536 dev_err(mehci->dev, "gpio request failed for HSIC DATA\n");
537 goto free_strobe;
Hemant Kumar6fd65032012-05-23 13:02:24 -0700538 }
539
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530540 return 0;
541
542free_gpio:
543 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
Ofir Cohen07944aa2012-12-23 13:41:57 +0200554 /* alt_core_clk exists in targets that do not use asynchronous reset */
555 if (!IS_ERR(mehci->alt_core_clk)) {
556 ret = clk_reset(mehci->core_clk, CLK_RESET_ASSERT);
557 if (ret) {
558 dev_err(mehci->dev, "hsic clk assert failed:%d\n", ret);
559 return;
560 }
561
562 /* Since a hw bug, turn off the clock before complete reset */
563 clk_disable(mehci->core_clk);
564
565 ret = clk_reset(mehci->core_clk, CLK_RESET_DEASSERT);
566 if (ret)
567 dev_err(mehci->dev, "hsic clk deassert failed:%d\n",
568 ret);
569
570 usleep_range(10000, 12000);
571
572 clk_enable(mehci->core_clk);
573 } else {
574 /* Using asynchronous block reset to the hardware */
575 clk_disable_unprepare(mehci->core_clk);
576 clk_disable_unprepare(mehci->phy_clk);
577 clk_disable_unprepare(mehci->cal_clk);
578 clk_disable_unprepare(mehci->ahb_clk);
Ido Shayevitz5dfbb132013-04-18 13:22:07 +0300579 if (!IS_ERR(mehci->inactivity_clk))
580 clk_disable_unprepare(mehci->inactivity_clk);
Ofir Cohen07944aa2012-12-23 13:41:57 +0200581
582 ret = clk_reset(mehci->core_clk, CLK_RESET_ASSERT);
583 if (ret) {
584 dev_err(mehci->dev, "hsic clk assert failed:%d\n", ret);
585 return;
586 }
587 usleep_range(10000, 12000);
588
589 ret = clk_reset(mehci->core_clk, CLK_RESET_DEASSERT);
590 if (ret)
591 dev_err(mehci->dev, "hsic clk deassert failed:%d\n",
592 ret);
593 /*
594 * Required delay between the deassertion and
595 * clock enablement.
596 */
597 ndelay(200);
598 clk_prepare_enable(mehci->core_clk);
599 clk_prepare_enable(mehci->phy_clk);
600 clk_prepare_enable(mehci->cal_clk);
601 clk_prepare_enable(mehci->ahb_clk);
Ido Shayevitz5dfbb132013-04-18 13:22:07 +0300602 if (!IS_ERR(mehci->inactivity_clk))
603 clk_prepare_enable(mehci->inactivity_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530604 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530605}
606
Vamsi Krishna64b48612012-06-14 16:08:11 -0700607#define HSIC_STROBE_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C0)
608#define HSIC_DATA_GPIO_PAD_CTL (MSM_TLMM_BASE+0x20C4)
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530609#define HSIC_CAL_PAD_CTL (MSM_TLMM_BASE+0x20C8)
610#define HSIC_LV_MODE 0x04
611#define HSIC_PAD_CALIBRATION 0xA8
612#define HSIC_GPIO_PAD_VAL 0x0A0AAA10
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530613#define LINK_RESET_TIMEOUT_USEC (250 * 1000)
Ofir Cohen5dddb152012-11-14 11:18:50 +0200614
615static void msm_hsic_phy_reset(struct msm_hsic_hcd *mehci)
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530616{
617 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530618
Vamsi Krishna64b48612012-06-14 16:08:11 -0700619 msm_hsic_clk_reset(mehci);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530620
Vamsi Krishna64b48612012-06-14 16:08:11 -0700621 /* select ulpi phy */
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530622 writel_relaxed(0x80000000, USB_PORTSC);
Vamsi Krishna64b48612012-06-14 16:08:11 -0700623 mb();
Ofir Cohen5dddb152012-11-14 11:18:50 +0200624}
625
626static int msm_hsic_start(struct msm_hsic_hcd *mehci)
627{
628 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
629 int ret;
Manu Gautam863b74132012-11-21 14:30:04 +0530630 void __iomem *reg;
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530631
Vamsi Krishnabef91832013-03-11 14:10:20 -0700632 if (pdata && pdata->resume_gpio) {
633 ret = gpio_request(pdata->resume_gpio, "HSIC_RESUME_GPIO");
634 if (ret < 0) {
635 dev_err(mehci->dev,
636 "gpio req failed for hsic resume:%d\n", ret);
637 pdata->resume_gpio = 0;
638 }
639 }
640
Lena Salman8c8ba382012-02-14 15:59:31 +0200641 /* HSIC init sequence when HSIC signals (Strobe/Data) are
642 routed via GPIOs */
643 if (pdata && pdata->strobe && pdata->data) {
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530644
Manu Gautam863b74132012-11-21 14:30:04 +0530645 if (!pdata->ignore_cal_pad_config) {
646 /* Enable LV_MODE in HSIC_CAL_PAD_CTL register */
647 writel_relaxed(HSIC_LV_MODE, HSIC_CAL_PAD_CTL);
648 mb();
649 }
Vamsi Krishna64b48612012-06-14 16:08:11 -0700650
Lena Salman8c8ba382012-02-14 15:59:31 +0200651 /*set periodic calibration interval to ~2.048sec in
652 HSIC_IO_CAL_REG */
653 ulpi_write(mehci, 0xFF, 0x33);
654
655 /* Enable periodic IO calibration in HSIC_CFG register */
656 ulpi_write(mehci, HSIC_PAD_CALIBRATION, 0x30);
657
Vamsi Krishna64b48612012-06-14 16:08:11 -0700658 /* Configure GPIO pins for HSIC functionality mode */
Lena Salman8c8ba382012-02-14 15:59:31 +0200659 ret = msm_hsic_config_gpios(mehci, 1);
660 if (ret) {
661 dev_err(mehci->dev, " gpio configuarion failed\n");
Vamsi Krishnabef91832013-03-11 14:10:20 -0700662 goto free_resume_gpio;
Lena Salman8c8ba382012-02-14 15:59:31 +0200663 }
Manu Gautam863b74132012-11-21 14:30:04 +0530664 if (pdata->strobe_pad_offset) {
665 /* Set CORE_CTL_EN in STROBE GPIO PAD_CTL register */
666 reg = MSM_TLMM_BASE + pdata->strobe_pad_offset;
667 writel_relaxed(readl_relaxed(reg) | 0x2000000, reg);
668 } else {
669 /* Set LV_MODE=0x1 and DCC=0x2 in STROBE GPIO PAD_CTL */
670 reg = HSIC_STROBE_GPIO_PAD_CTL;
671 writel_relaxed(HSIC_GPIO_PAD_VAL, reg);
672 }
673
674 if (pdata->data_pad_offset) {
675 /* Set CORE_CTL_EN in HSIC_DATA GPIO PAD_CTL register */
676 reg = MSM_TLMM_BASE + pdata->data_pad_offset;
677 writel_relaxed(readl_relaxed(reg) | 0x2000000, reg);
678 } else {
679 /* Set LV_MODE=0x1 and DCC=0x2 in STROBE GPIO PAD_CTL */
680 reg = HSIC_DATA_GPIO_PAD_CTL;
681 writel_relaxed(HSIC_GPIO_PAD_VAL, reg);
682 }
Vamsi Krishna64b48612012-06-14 16:08:11 -0700683
684 mb();
685
Lena Salman8c8ba382012-02-14 15:59:31 +0200686 /* Enable HSIC mode in HSIC_CFG register */
687 ulpi_write(mehci, 0x01, 0x31);
688 } else {
689 /* HSIC init sequence when HSIC signals (Strobe/Data) are routed
690 via dedicated I/O */
691
692 /* programmable length of connect signaling (33.2ns) */
693 ret = ulpi_write(mehci, 3, HSIC_DBG1_REG);
694 if (ret) {
695 pr_err("%s: Unable to program length of connect "
696 "signaling\n", __func__);
697 }
698
699 /*set periodic calibration interval to ~2.048sec in
700 HSIC_IO_CAL_REG */
701 ulpi_write(mehci, 0xFF, 0x33);
702
703 /* Enable HSIC mode in HSIC_CFG register */
704 ulpi_write(mehci, 0xA9, 0x30);
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530705 }
706
Hemant Kumar6fd65032012-05-23 13:02:24 -0700707 /*disable auto resume*/
708 ulpi_write(mehci, ULPI_IFC_CTRL_AUTORESUME, ULPI_CLR(ULPI_IFC_CTRL));
709
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530710 return 0;
Vamsi Krishnabef91832013-03-11 14:10:20 -0700711
712free_resume_gpio:
713 if (pdata && pdata->resume_gpio)
714 gpio_free(pdata->resume_gpio);
715
716 return ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530717}
718
719#define PHY_SUSPEND_TIMEOUT_USEC (500 * 1000)
720#define PHY_RESUME_TIMEOUT_USEC (100 * 1000)
721
722#ifdef CONFIG_PM_SLEEP
Ofir Cohen5dddb152012-11-14 11:18:50 +0200723static int msm_hsic_reset(struct msm_hsic_hcd *mehci)
724{
725 /* reset HSIC phy */
726 msm_hsic_phy_reset(mehci);
727
728 /* HSIC init procedure (caliberation) */
729 return msm_hsic_start(mehci);
730}
731
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530732static int msm_hsic_suspend(struct msm_hsic_hcd *mehci)
733{
734 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +0530735 int cnt = 0, ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530736 u32 val;
Amit Blayd6ea6102012-06-07 16:26:24 +0300737 int none_vol, max_vol;
Hemant Kumarbc8bdf62012-10-17 12:29:51 -0700738 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530739
740 if (atomic_read(&mehci->in_lpm)) {
741 dev_dbg(mehci->dev, "%s called in lpm\n", __func__);
742 return 0;
743 }
744
745 disable_irq(hcd->irq);
Jack Phambe05fbb2012-05-16 10:56:26 -0700746
Sudhir Sharma1673e302012-08-27 17:37:24 -0700747 /* make sure we don't race against a remote wakeup */
748 if (test_bit(HCD_FLAG_WAKEUP_PENDING, &hcd->flags) ||
Jack Phambe05fbb2012-05-16 10:56:26 -0700749 readl_relaxed(USB_PORTSC) & PORT_RESUME) {
Sudhir Sharma1673e302012-08-27 17:37:24 -0700750 dev_dbg(mehci->dev, "wakeup pending, aborting suspend\n");
Jack Phambe05fbb2012-05-16 10:56:26 -0700751 enable_irq(hcd->irq);
752 return -EBUSY;
753 }
754
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530755 /*
756 * PHY may take some time or even fail to enter into low power
757 * mode (LPM). Hence poll for 500 msec and reset the PHY and link
758 * in failure case.
759 */
Hemant Kumar3dbc5b32012-05-09 15:36:11 -0700760 val = readl_relaxed(USB_PORTSC);
761 val &= ~PORT_RWC_BITS;
762 val |= PORTSC_PHCD;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530763 writel_relaxed(val, USB_PORTSC);
764 while (cnt < PHY_SUSPEND_TIMEOUT_USEC) {
765 if (readl_relaxed(USB_PORTSC) & PORTSC_PHCD)
766 break;
767 udelay(1);
768 cnt++;
769 }
770
771 if (cnt >= PHY_SUSPEND_TIMEOUT_USEC) {
772 dev_err(mehci->dev, "Unable to suspend PHY\n");
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530773 msm_hsic_config_gpios(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530774 msm_hsic_reset(mehci);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530775 }
776
777 /*
778 * PHY has capability to generate interrupt asynchronously in low
779 * power mode (LPM). This interrupt is level triggered. So USB IRQ
780 * line must be disabled till async interrupt enable bit is cleared
781 * in USBCMD register. Assert STP (ULPI interface STOP signal) to
Pavankumar Kondeti0c9f29c2013-01-28 21:37:59 +0530782 * block data communication from PHY. Enable asynchronous interrupt
783 * only when wakeup gpio IRQ is not present.
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530784 */
Pavankumar Kondeti0c9f29c2013-01-28 21:37:59 +0530785 if (mehci->wakeup_irq)
786 writel_relaxed(readl_relaxed(USB_USBCMD) |
787 ULPI_STP_CTRL, USB_USBCMD);
788 else
789 writel_relaxed(readl_relaxed(USB_USBCMD) | ASYNC_INTR_CTRL |
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530790 ULPI_STP_CTRL, USB_USBCMD);
791
792 /*
793 * Ensure that hardware is put in low power mode before
794 * clocks are turned OFF and VDD is allowed to minimize.
795 */
796 mb();
797
Manu Gautam28b1bac2012-01-30 16:43:06 +0530798 clk_disable_unprepare(mehci->core_clk);
799 clk_disable_unprepare(mehci->phy_clk);
800 clk_disable_unprepare(mehci->cal_clk);
801 clk_disable_unprepare(mehci->ahb_clk);
Ido Shayevitz5dfbb132013-04-18 13:22:07 +0300802 if (!IS_ERR(mehci->inactivity_clk))
803 clk_disable_unprepare(mehci->inactivity_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530804
Amit Blayd6ea6102012-06-07 16:26:24 +0300805 none_vol = vdd_val[mehci->vdd_type][VDD_NONE];
806 max_vol = vdd_val[mehci->vdd_type][VDD_MAX];
807
808 ret = regulator_set_voltage(mehci->hsic_vddcx, none_vol, max_vol);
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700809 if (ret < 0)
Amit Blayd6ea6102012-06-07 16:26:24 +0300810 dev_err(mehci->dev, "unable to set vddcx voltage for VDD MIN\n");
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700811
Hemant Kumare6275972012-02-29 20:06:21 -0800812 if (mehci->bus_perf_client && debug_bus_voting_enabled) {
Hemant Kumar2309eaa2012-08-14 16:46:42 -0700813 mehci->bus_vote = false;
814 queue_work(ehci_wq, &mehci->bus_vote_w);
Hemant Kumare6275972012-02-29 20:06:21 -0800815 }
816
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530817 atomic_set(&mehci->in_lpm, 1);
818 enable_irq(hcd->irq);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700819
Manu Gautam3fb60ca2013-02-13 18:33:33 +0530820 if (mehci->wakeup_irq) {
821 mehci->wakeup_irq_enabled = 1;
822 enable_irq_wake(mehci->wakeup_irq);
823 enable_irq(mehci->wakeup_irq);
824 }
Hemant Kumar6fd65032012-05-23 13:02:24 -0700825
Hemant Kumarbc8bdf62012-10-17 12:29:51 -0700826 if (pdata && pdata->standalone_latency)
827 pm_qos_update_request(&mehci->pm_qos_req_dma,
828 PM_QOS_DEFAULT_VALUE);
829
Sudhir Sharma1673e302012-08-27 17:37:24 -0700830 wake_unlock(&mehci->wlock);
831
Pavankumar Kondetiafbaf8e2013-02-22 11:58:44 +0530832 dev_dbg(mehci->dev, "HSIC-USB in low power mode\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530833
834 return 0;
835}
836
837static int msm_hsic_resume(struct msm_hsic_hcd *mehci)
838{
839 struct usb_hcd *hcd = hsic_to_hcd(mehci);
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +0530840 int cnt = 0, ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530841 unsigned temp;
Amit Blayd6ea6102012-06-07 16:26:24 +0300842 int min_vol, max_vol;
Hemant Kumard343c012012-09-06 19:57:14 -0700843 unsigned long flags;
Hemant Kumarbc8bdf62012-10-17 12:29:51 -0700844 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530845
846 if (!atomic_read(&mehci->in_lpm)) {
847 dev_dbg(mehci->dev, "%s called in !in_lpm\n", __func__);
848 return 0;
849 }
850
Pavankumar Kondeti822fbe62013-01-28 17:04:39 +0530851 /* Handles race with Async interrupt */
852 disable_irq(hcd->irq);
853
Hemant Kumarbc8bdf62012-10-17 12:29:51 -0700854 if (pdata && pdata->standalone_latency)
855 pm_qos_update_request(&mehci->pm_qos_req_dma,
856 pdata->standalone_latency + 1);
857
Manu Gautam3fb60ca2013-02-13 18:33:33 +0530858 if (mehci->wakeup_irq) {
859 spin_lock_irqsave(&mehci->wakeup_lock, flags);
860 if (mehci->wakeup_irq_enabled) {
861 disable_irq_wake(mehci->wakeup_irq);
862 disable_irq_nosync(mehci->wakeup_irq);
863 mehci->wakeup_irq_enabled = 0;
864 }
865 spin_unlock_irqrestore(&mehci->wakeup_lock, flags);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700866 }
867
Sudhir Sharma1673e302012-08-27 17:37:24 -0700868 wake_lock(&mehci->wlock);
869
Hemant Kumare6275972012-02-29 20:06:21 -0800870 if (mehci->bus_perf_client && debug_bus_voting_enabled) {
Hemant Kumar2309eaa2012-08-14 16:46:42 -0700871 mehci->bus_vote = true;
872 queue_work(ehci_wq, &mehci->bus_vote_w);
Hemant Kumare6275972012-02-29 20:06:21 -0800873 }
874
Amit Blayd6ea6102012-06-07 16:26:24 +0300875 min_vol = vdd_val[mehci->vdd_type][VDD_MIN];
876 max_vol = vdd_val[mehci->vdd_type][VDD_MAX];
877
878 ret = regulator_set_voltage(mehci->hsic_vddcx, min_vol, max_vol);
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700879 if (ret < 0)
Amit Blayd6ea6102012-06-07 16:26:24 +0300880 dev_err(mehci->dev, "unable to set nominal vddcx voltage (no VDD MIN)\n");
Vamsi Krishna45d88fa2011-11-02 13:28:42 -0700881
Manu Gautam28b1bac2012-01-30 16:43:06 +0530882 clk_prepare_enable(mehci->core_clk);
883 clk_prepare_enable(mehci->phy_clk);
884 clk_prepare_enable(mehci->cal_clk);
885 clk_prepare_enable(mehci->ahb_clk);
Ido Shayevitz5dfbb132013-04-18 13:22:07 +0300886 if (!IS_ERR(mehci->inactivity_clk))
887 clk_prepare_enable(mehci->inactivity_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530888
889 temp = readl_relaxed(USB_USBCMD);
890 temp &= ~ASYNC_INTR_CTRL;
891 temp &= ~ULPI_STP_CTRL;
892 writel_relaxed(temp, USB_USBCMD);
893
894 if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD))
895 goto skip_phy_resume;
896
Hemant Kumar3dbc5b32012-05-09 15:36:11 -0700897 temp = readl_relaxed(USB_PORTSC);
898 temp &= ~(PORT_RWC_BITS | PORTSC_PHCD);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530899 writel_relaxed(temp, USB_PORTSC);
900 while (cnt < PHY_RESUME_TIMEOUT_USEC) {
901 if (!(readl_relaxed(USB_PORTSC) & PORTSC_PHCD) &&
902 (readl_relaxed(USB_ULPI_VIEWPORT) & ULPI_SYNC_STATE))
903 break;
904 udelay(1);
905 cnt++;
906 }
907
908 if (cnt >= PHY_RESUME_TIMEOUT_USEC) {
909 /*
910 * This is a fatal error. Reset the link and
911 * PHY to make hsic working.
912 */
913 dev_err(mehci->dev, "Unable to resume USB. Reset the hsic\n");
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +0530914 msm_hsic_config_gpios(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530915 msm_hsic_reset(mehci);
916 }
917
918skip_phy_resume:
919
Hemant Kumar6fd65032012-05-23 13:02:24 -0700920 usb_hcd_resume_root_hub(hcd);
921
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530922 atomic_set(&mehci->in_lpm, 0);
923
Pavankumar Kondeti822fbe62013-01-28 17:04:39 +0530924 if (atomic_read(&mehci->async_int)) {
925 atomic_set(&mehci->async_int, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530926 pm_runtime_put_noidle(mehci->dev);
Jack Phamdd5ad792012-07-26 10:31:03 -0700927 enable_irq(hcd->irq);
Hemant Kumar6fd65032012-05-23 13:02:24 -0700928 }
929
Sudhir Sharma1673e302012-08-27 17:37:24 -0700930 if (atomic_read(&mehci->pm_usage_cnt)) {
931 atomic_set(&mehci->pm_usage_cnt, 0);
932 pm_runtime_put_noidle(mehci->dev);
933 }
Jack Phamdd5ad792012-07-26 10:31:03 -0700934
Pavankumar Kondeti822fbe62013-01-28 17:04:39 +0530935 enable_irq(hcd->irq);
Pavankumar Kondetiafbaf8e2013-02-22 11:58:44 +0530936 dev_dbg(mehci->dev, "HSIC-USB exited from low power mode\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530937
938 return 0;
939}
940#endif
941
Hemant Kumar2309eaa2012-08-14 16:46:42 -0700942static void ehci_hsic_bus_vote_w(struct work_struct *w)
943{
944 struct msm_hsic_hcd *mehci =
945 container_of(w, struct msm_hsic_hcd, bus_vote_w);
946 int ret;
947
948 ret = msm_bus_scale_client_update_request(mehci->bus_perf_client,
949 mehci->bus_vote);
950 if (ret)
951 dev_err(mehci->dev, "%s: Failed to vote for bus bandwidth %d\n",
952 __func__, ret);
953}
954
Pavankumar Kondeti23720492013-01-29 14:41:58 +0530955static int msm_hsic_reset_done(struct usb_hcd *hcd)
956{
957 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
958 u32 __iomem *status_reg = &ehci->regs->port_status[0];
959 int ret;
960
961 ehci_writel(ehci, ehci_readl(ehci, status_reg) & ~(PORT_RWC_BITS |
962 PORT_RESET), status_reg);
963
964 ret = handshake(ehci, status_reg, PORT_RESET, 0, 1 * 1000);
965
966 if (ret)
967 pr_err("reset handshake failed in %s\n", __func__);
968 else
969 ehci_writel(ehci, ehci_readl(ehci, &ehci->regs->command) |
970 CMD_RUN, &ehci->regs->command);
971
972 return ret;
973}
974
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700975#define STS_GPTIMER0_INTERRUPT BIT(24)
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530976static irqreturn_t msm_hsic_irq(struct usb_hcd *hcd)
977{
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700978 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530979 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700980 u32 status;
Pavankumar Kondeti822fbe62013-01-28 17:04:39 +0530981 int ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530982
983 if (atomic_read(&mehci->in_lpm)) {
Hemant Kumar3dbc5b32012-05-09 15:36:11 -0700984 dev_dbg(mehci->dev, "phy async intr\n");
Pavankumar Kondeti822fbe62013-01-28 17:04:39 +0530985 dbg_log_event(NULL, "Async IRQ", 0);
986 ret = pm_runtime_get(mehci->dev);
987 if ((ret == 1) || (ret == -EINPROGRESS)) {
988 pm_runtime_put_noidle(mehci->dev);
989 } else {
990 disable_irq_nosync(hcd->irq);
991 atomic_set(&mehci->async_int, 1);
992 }
993
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +0530994 return IRQ_HANDLED;
995 }
996
Vamsi Krishnafce1bd22012-08-17 17:12:26 -0700997 status = ehci_readl(ehci, &ehci->regs->status);
998
999 if (status & STS_GPTIMER0_INTERRUPT) {
1000 int timeleft;
1001
Pavankumar Kondeti23720492013-01-29 14:41:58 +05301002 dbg_log_event(NULL, "FPR: gpt0_isr", mehci->bus_reset);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001003
1004 timeleft = GPT_CNT(ehci_readl(ehci,
1005 &mehci->timer->gptimer1_ctrl));
1006 if (timeleft) {
Pavankumar Kondeti23720492013-01-29 14:41:58 +05301007 if (mehci->bus_reset) {
1008 ret = msm_hsic_reset_done(hcd);
1009 if (ret) {
1010 mehci->reset_again = 1;
1011 dbg_log_event(NULL, "RESET: fail", 0);
1012 }
1013 } else {
1014 ehci_writel(ehci, ehci_readl(ehci,
1015 &ehci->regs->command) | CMD_RUN,
1016 &ehci->regs->command);
1017 }
1018 } else {
1019 if (mehci->bus_reset)
1020 mehci->reset_again = 1;
1021 else
1022 mehci->resume_again = 1;
1023 }
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001024
1025 dbg_log_event(NULL, "FPR: timeleft", timeleft);
1026
1027 complete(&mehci->gpt0_completion);
1028 ehci_writel(ehci, STS_GPTIMER0_INTERRUPT, &ehci->regs->status);
1029 }
1030
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301031 return ehci_irq(hcd);
1032}
1033
1034static int ehci_hsic_reset(struct usb_hcd *hcd)
1035{
1036 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001037 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301038 int retval;
1039
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001040 mehci->timer = USB_HS_GPTIMER_BASE;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301041 ehci->caps = USB_CAPLENGTH;
1042 ehci->regs = USB_CAPLENGTH +
1043 HC_LENGTH(ehci, ehci_readl(ehci, &ehci->caps->hc_capbase));
1044 dbg_hcs_params(ehci, "reset");
1045 dbg_hcc_params(ehci, "reset");
1046
1047 /* cache the data to minimize the chip reads*/
1048 ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params);
1049
1050 hcd->has_tt = 1;
1051 ehci->sbrn = HCD_USB2;
1052
1053 retval = ehci_halt(ehci);
1054 if (retval)
1055 return retval;
1056
1057 /* data structure init */
1058 retval = ehci_init(hcd);
1059 if (retval)
1060 return retval;
1061
1062 retval = ehci_reset(ehci);
1063 if (retval)
1064 return retval;
1065
1066 /* bursts of unspecified length. */
1067 writel_relaxed(0, USB_AHBBURST);
1068 /* Use the AHB transactor */
Vijayavardhan Vennapusa5f32d7a2012-03-14 16:30:26 +05301069 writel_relaxed(0x08, USB_AHBMODE);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301070 /* Disable streaming mode and select host mode */
1071 writel_relaxed(0x13, USB_USBMODE);
1072
1073 ehci_port_power(ehci, 1);
1074 return 0;
1075}
1076
Jack Phamc0d41732012-09-28 17:45:38 -07001077#ifdef CONFIG_PM
1078
Pavankumar Kondeti23720492013-01-29 14:41:58 +05301079#define RESET_RETRY_LIMIT 3
1080#define RESET_SIGNAL_TIME_SOF_USEC (50 * 1000)
1081#define RESET_SIGNAL_TIME_USEC (20 * 1000)
1082static void ehci_hsic_reset_sof_bug_handler(struct usb_hcd *hcd, u32 val)
1083{
1084 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1085 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1086 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
1087 u32 __iomem *status_reg = &ehci->regs->port_status[0];
Pavankumar Kondetifc7d1d82013-03-05 09:43:22 +05301088 u32 cmd;
Pavankumar Kondeti23720492013-01-29 14:41:58 +05301089 unsigned long flags;
1090 int retries = 0, ret, cnt = RESET_SIGNAL_TIME_USEC;
1091
1092 if (pdata && pdata->swfi_latency)
1093 pm_qos_update_request(&mehci->pm_qos_req_dma,
1094 pdata->swfi_latency + 1);
1095
1096 mehci->bus_reset = 1;
Pavankumar Kondetifc7d1d82013-03-05 09:43:22 +05301097
1098 /* Halt the controller */
1099 cmd = ehci_readl(ehci, &ehci->regs->command);
1100 cmd &= ~CMD_RUN;
1101 ehci_writel(ehci, cmd, &ehci->regs->command);
1102 ret = handshake(ehci, &ehci->regs->status, STS_HALT,
1103 STS_HALT, 16 * 125);
1104 if (ret) {
1105 pr_err("halt handshake fatal error\n");
1106 dbg_log_event(NULL, "HALT: fatal", 0);
1107 goto fail;
1108 }
1109
Pavankumar Kondeti23720492013-01-29 14:41:58 +05301110retry:
1111 retries++;
1112 dbg_log_event(NULL, "RESET: start", retries);
1113 pr_debug("reset begin %d\n", retries);
1114 mehci->reset_again = 0;
1115 spin_lock_irqsave(&ehci->lock, flags);
1116 ehci_writel(ehci, val, status_reg);
1117 ehci_writel(ehci, GPT_LD(RESET_SIGNAL_TIME_USEC - 1),
1118 &mehci->timer->gptimer0_ld);
1119 ehci_writel(ehci, GPT_RESET | GPT_RUN,
1120 &mehci->timer->gptimer0_ctrl);
1121 ehci_writel(ehci, INTR_MASK | STS_GPTIMER0_INTERRUPT,
1122 &ehci->regs->intr_enable);
1123
1124 ehci_writel(ehci, GPT_LD(RESET_SIGNAL_TIME_SOF_USEC - 1),
1125 &mehci->timer->gptimer1_ld);
1126 ehci_writel(ehci, GPT_RESET | GPT_RUN,
1127 &mehci->timer->gptimer1_ctrl);
1128
1129 spin_unlock_irqrestore(&ehci->lock, flags);
1130 wait_for_completion(&mehci->gpt0_completion);
1131
1132 if (!mehci->reset_again)
1133 goto done;
1134
1135 if (handshake(ehci, status_reg, PORT_RESET, 0, 10 * 1000)) {
1136 pr_err("reset handshake fatal error\n");
1137 dbg_log_event(NULL, "RESET: fatal", retries);
1138 goto fail;
1139 }
1140
1141 if (retries < RESET_RETRY_LIMIT)
1142 goto retry;
1143
1144 /* complete reset in tight loop */
1145 pr_info("RESET in tight loop\n");
1146 dbg_log_event(NULL, "RESET: tight", 0);
1147
1148 spin_lock_irqsave(&ehci->lock, flags);
1149 ehci_writel(ehci, val, status_reg);
1150 while (cnt--)
1151 udelay(1);
1152 ret = msm_hsic_reset_done(hcd);
1153 spin_unlock_irqrestore(&ehci->lock, flags);
1154 if (ret) {
1155 pr_err("RESET in tight loop failed\n");
1156 dbg_log_event(NULL, "RESET: tight failed", 0);
1157 goto fail;
1158 }
1159
1160done:
1161 dbg_log_event(NULL, "RESET: done", retries);
1162 pr_debug("reset completed\n");
1163fail:
1164 mehci->bus_reset = 0;
1165 if (pdata && pdata->swfi_latency)
1166 pm_qos_update_request(&mehci->pm_qos_req_dma,
1167 PM_QOS_DEFAULT_VALUE);
1168}
1169
Hemant Kumar45d211b2012-05-31 17:58:43 -07001170static int ehci_hsic_bus_suspend(struct usb_hcd *hcd)
1171{
Pavankumar Kondetia723f742012-09-14 14:02:36 +05301172 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1173
1174 if (!(readl_relaxed(USB_PORTSC) & PORT_PE)) {
1175 dbg_log_event(NULL, "RH suspend attempt failed", 0);
1176 dev_dbg(mehci->dev, "%s:port is not enabled skip suspend\n",
1177 __func__);
1178 return -EAGAIN;
1179 }
1180
Hemant Kumar45d211b2012-05-31 17:58:43 -07001181 dbg_log_event(NULL, "Suspend RH", 0);
1182 return ehci_bus_suspend(hcd);
1183}
1184
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001185#define RESUME_RETRY_LIMIT 3
Pavankumar Kondetic4f817d2013-01-29 19:08:12 +05301186#define RESUME_SIGNAL_TIME_USEC (21 * 1000)
1187#define RESUME_SIGNAL_TIME_SOF_USEC (23 * 1000)
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001188static int msm_hsic_resume_thread(void *data)
1189{
1190 struct msm_hsic_hcd *mehci = data;
1191 struct usb_hcd *hcd = hsic_to_hcd(mehci);
1192 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1193 u32 temp;
1194 unsigned long resume_needed = 0;
1195 int retry_cnt = 0;
1196 int tight_resume = 0;
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05301197 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001198
1199 dbg_log_event(NULL, "Resume RH", 0);
1200
1201 /* keep delay between bus states */
1202 if (time_before(jiffies, ehci->next_statechange))
1203 usleep_range(5000, 5000);
1204
1205 spin_lock_irq(&ehci->lock);
1206 if (!HCD_HW_ACCESSIBLE(hcd)) {
1207 spin_unlock_irq(&ehci->lock);
1208 mehci->resume_status = -ESHUTDOWN;
1209 complete(&mehci->rt_completion);
1210 return 0;
1211 }
1212
1213 if (unlikely(ehci->debug)) {
1214 if (!dbgp_reset_prep())
1215 ehci->debug = NULL;
1216 else
1217 dbgp_external_startup();
1218 }
1219
1220 /* at least some APM implementations will try to deliver
1221 * IRQs right away, so delay them until we're ready.
1222 */
1223 ehci_writel(ehci, 0, &ehci->regs->intr_enable);
1224
1225 /* re-init operational registers */
1226 ehci_writel(ehci, 0, &ehci->regs->segment);
1227 ehci_writel(ehci, ehci->periodic_dma, &ehci->regs->frame_list);
1228 ehci_writel(ehci, (u32) ehci->async->qh_dma, &ehci->regs->async_next);
1229
1230 /*CMD_RUN will be set after, PORT_RESUME gets cleared*/
1231 if (ehci->resume_sof_bug)
1232 ehci->command &= ~CMD_RUN;
1233
1234 /* restore CMD_RUN, framelist size, and irq threshold */
1235 ehci_writel(ehci, ehci->command, &ehci->regs->command);
1236
1237 /* manually resume the ports we suspended during bus_suspend() */
1238resume_again:
1239 if (retry_cnt >= RESUME_RETRY_LIMIT) {
1240 pr_info("retry count(%d) reached max, resume in tight loop\n",
1241 retry_cnt);
1242 tight_resume = 1;
1243 }
1244
1245
1246 temp = ehci_readl(ehci, &ehci->regs->port_status[0]);
1247 temp &= ~(PORT_RWC_BITS | PORT_WAKE_BITS);
1248 if (test_bit(0, &ehci->bus_suspended) && (temp & PORT_SUSPEND)) {
1249 temp |= PORT_RESUME;
1250 set_bit(0, &resume_needed);
1251 }
1252 dbg_log_event(NULL, "FPR: Set", temp);
1253 ehci_writel(ehci, temp, &ehci->regs->port_status[0]);
1254
1255 /* HSIC controller has a h/w bug due to which it can try to send SOFs
1256 * (start of frames) during port resume resulting in phy lockup. HSIC hw
1257 * controller in MSM clears FPR bit after driving the resume signal for
1258 * 20ms. Workaround is to stop SOFs before driving resume and then start
1259 * sending SOFs immediately. Need to send SOFs within 3ms of resume
1260 * completion otherwise peripheral may enter undefined state. As
1261 * usleep_range does not gurantee exact sleep time, GPTimer is used to
1262 * to time the resume sequence. If driver exceeds allowable time SOFs,
1263 * repeat the resume process.
1264 */
1265 if (ehci->resume_sof_bug && resume_needed) {
1266 if (!tight_resume) {
1267 mehci->resume_again = 0;
Pavankumar Kondetic4f817d2013-01-29 19:08:12 +05301268 ehci_writel(ehci, GPT_LD(RESUME_SIGNAL_TIME_USEC - 1),
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001269 &mehci->timer->gptimer0_ld);
1270 ehci_writel(ehci, GPT_RESET | GPT_RUN,
1271 &mehci->timer->gptimer0_ctrl);
1272 ehci_writel(ehci, INTR_MASK | STS_GPTIMER0_INTERRUPT,
1273 &ehci->regs->intr_enable);
1274
Pavankumar Kondetic4f817d2013-01-29 19:08:12 +05301275 ehci_writel(ehci, GPT_LD(
1276 RESUME_SIGNAL_TIME_SOF_USEC - 1),
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001277 &mehci->timer->gptimer1_ld);
1278 ehci_writel(ehci, GPT_RESET | GPT_RUN,
1279 &mehci->timer->gptimer1_ctrl);
1280
1281 spin_unlock_irq(&ehci->lock);
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05301282 if (pdata && pdata->swfi_latency)
1283 pm_qos_update_request(&mehci->pm_qos_req_dma,
1284 pdata->swfi_latency + 1);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001285 wait_for_completion(&mehci->gpt0_completion);
Hemant Kumarbc8bdf62012-10-17 12:29:51 -07001286 if (pdata && pdata->standalone_latency)
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05301287 pm_qos_update_request(&mehci->pm_qos_req_dma,
Hemant Kumarbc8bdf62012-10-17 12:29:51 -07001288 pdata->standalone_latency + 1);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001289 spin_lock_irq(&ehci->lock);
1290 } else {
1291 dbg_log_event(NULL, "FPR: Tightloop", 0);
1292 /* do the resume in a tight loop */
1293 handshake(ehci, &ehci->regs->port_status[0],
1294 PORT_RESUME, 0, 22 * 1000);
1295 ehci_writel(ehci, ehci_readl(ehci,
1296 &ehci->regs->command) | CMD_RUN,
1297 &ehci->regs->command);
1298 }
1299
1300 if (mehci->resume_again) {
1301 int temp;
1302
1303 dbg_log_event(NULL, "FPR: Re-Resume", retry_cnt);
1304 pr_info("FPR: retry count: %d\n", retry_cnt);
1305 spin_unlock_irq(&ehci->lock);
1306 temp = ehci_readl(ehci, &ehci->regs->port_status[0]);
1307 temp &= ~PORT_RWC_BITS;
1308 temp |= PORT_SUSPEND;
1309 ehci_writel(ehci, temp, &ehci->regs->port_status[0]);
1310 /* Keep the bus idle for 5ms so that peripheral
1311 * can detect and initiate suspend
1312 */
1313 usleep_range(5000, 5000);
1314 dbg_log_event(NULL,
1315 "FPR: RResume",
1316 ehci_readl(ehci, &ehci->regs->port_status[0]));
1317 spin_lock_irq(&ehci->lock);
1318 mehci->resume_again = 0;
1319 retry_cnt++;
1320 goto resume_again;
1321 }
1322 }
1323
1324 dbg_log_event(NULL, "FPR: RT-Done", 0);
1325 mehci->resume_status = 1;
1326 spin_unlock_irq(&ehci->lock);
1327
1328 complete(&mehci->rt_completion);
1329
1330 return 0;
1331}
1332
Hemant Kumar45d211b2012-05-31 17:58:43 -07001333static int ehci_hsic_bus_resume(struct usb_hcd *hcd)
1334{
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001335 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1336 struct ehci_hcd *ehci = hcd_to_ehci(hcd);
1337 u32 temp;
1338 struct task_struct *resume_thread = NULL;
Vamsi Krishnabef91832013-03-11 14:10:20 -07001339 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
1340
1341 if (pdata->resume_gpio)
1342 gpio_direction_output(pdata->resume_gpio, 1);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001343
Manu Gautam3c598392013-03-22 16:59:10 +05301344 if (!mehci->ehci.resume_sof_bug) {
1345 ehci_bus_resume(hcd);
1346 } else {
1347 mehci->resume_status = 0;
1348 resume_thread = kthread_run(msm_hsic_resume_thread,
1349 mehci, "hsic_resume_thread");
1350 if (IS_ERR(resume_thread)) {
1351 pr_err("Error creating resume thread:%lu\n",
1352 PTR_ERR(resume_thread));
1353 return PTR_ERR(resume_thread);
1354 }
1355
1356 wait_for_completion(&mehci->rt_completion);
1357
1358 if (mehci->resume_status < 0)
1359 return mehci->resume_status;
1360
1361 dbg_log_event(NULL, "FPR: Wokeup", 0);
1362 spin_lock_irq(&ehci->lock);
1363 (void) ehci_readl(ehci, &ehci->regs->command);
1364
1365 temp = 0;
1366 if (ehci->async->qh_next.qh)
1367 temp |= CMD_ASE;
1368 if (ehci->periodic_sched)
1369 temp |= CMD_PSE;
1370 if (temp) {
1371 ehci->command |= temp;
1372 ehci_writel(ehci, ehci->command, &ehci->regs->command);
1373 }
1374
1375 ehci->next_statechange = jiffies + msecs_to_jiffies(5);
1376 hcd->state = HC_STATE_RUNNING;
1377 ehci->rh_state = EHCI_RH_RUNNING;
1378 ehci->command |= CMD_RUN;
1379
1380 /* Now we can safely re-enable irqs */
1381 ehci_writel(ehci, INTR_MASK, &ehci->regs->intr_enable);
1382
1383 spin_unlock_irq(&ehci->lock);
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001384 }
1385
Vamsi Krishnabef91832013-03-11 14:10:20 -07001386 if (pdata->resume_gpio)
1387 gpio_direction_output(pdata->resume_gpio, 0);
1388
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001389 return 0;
Hemant Kumar45d211b2012-05-31 17:58:43 -07001390}
1391
Jack Phamc0d41732012-09-28 17:45:38 -07001392#else
1393
1394#define ehci_hsic_bus_suspend NULL
1395#define ehci_hsic_bus_resume NULL
1396
1397#endif /* CONFIG_PM */
1398
Hemant Kumara3d4a6e2012-10-16 17:57:08 -07001399static void ehci_msm_set_autosuspend_delay(struct usb_device *dev)
1400{
1401 if (!dev->parent) /*for root hub no delay*/
1402 pm_runtime_set_autosuspend_delay(&dev->dev, 0);
1403 else
1404 pm_runtime_set_autosuspend_delay(&dev->dev, 200);
1405}
1406
Shimrit Malichi82d7cbc2013-03-12 15:36:54 +02001407static int ehci_msm_urb_enqueue(struct usb_hcd *hcd, struct urb *urb,
1408 gfp_t mem_flags)
1409{
1410 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
1411 struct usb_host_bam_type *usb_host_bam =
1412 (struct usb_host_bam_type *)urb->priv_data;
1413
1414 if (usb_host_bam && mehci && mehci->enable_hbm)
1415 return hbm_urb_enqueue(hcd, urb, mem_flags);
1416 return ehci_urb_enqueue(hcd, urb, mem_flags);
1417}
1418
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301419static struct hc_driver msm_hsic_driver = {
1420 .description = hcd_name,
1421 .product_desc = "Qualcomm EHCI Host Controller using HSIC",
1422 .hcd_priv_size = sizeof(struct msm_hsic_hcd),
1423
1424 /*
1425 * generic hardware linkage
1426 */
1427 .irq = msm_hsic_irq,
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -07001428 .flags = HCD_USB2 | HCD_MEMORY | HCD_OLD_ENUM,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301429
1430 .reset = ehci_hsic_reset,
1431 .start = ehci_run,
1432
1433 .stop = ehci_stop,
1434 .shutdown = ehci_shutdown,
1435
1436 /*
1437 * managing i/o requests and associated device resources
1438 */
Shimrit Malichi82d7cbc2013-03-12 15:36:54 +02001439 .urb_enqueue = ehci_msm_urb_enqueue,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301440 .urb_dequeue = ehci_urb_dequeue,
1441 .endpoint_disable = ehci_endpoint_disable,
1442 .endpoint_reset = ehci_endpoint_reset,
1443 .clear_tt_buffer_complete = ehci_clear_tt_buffer_complete,
1444
1445 /*
1446 * scheduling support
1447 */
1448 .get_frame_number = ehci_get_frame,
1449
1450 /*
1451 * root hub support
1452 */
1453 .hub_status_data = ehci_hub_status_data,
1454 .hub_control = ehci_hub_control,
1455 .relinquish_port = ehci_relinquish_port,
1456 .port_handed_over = ehci_port_handed_over,
1457
1458 /*
1459 * PM support
1460 */
Hemant Kumar45d211b2012-05-31 17:58:43 -07001461 .bus_suspend = ehci_hsic_bus_suspend,
1462 .bus_resume = ehci_hsic_bus_resume,
1463
Hemant Kumar4d50a432012-08-15 09:06:35 -07001464 .log_urb = dbg_log_event,
Hemant Kumar105d07f2012-07-02 15:33:07 -07001465 .dump_regs = dump_hsic_regs,
Vamsi Krishna8e6edcb2012-06-20 18:08:50 -07001466
Hemant Kumara3d4a6e2012-10-16 17:57:08 -07001467 .set_autosuspend_delay = ehci_msm_set_autosuspend_delay,
Pavankumar Kondeti23720492013-01-29 14:41:58 +05301468 .reset_sof_bug_handler = ehci_hsic_reset_sof_bug_handler,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301469};
1470
1471static int msm_hsic_init_clocks(struct msm_hsic_hcd *mehci, u32 init)
1472{
1473 int ret = 0;
1474
1475 if (!init)
1476 goto put_clocks;
1477
Lena Salman8c8ba382012-02-14 15:59:31 +02001478 /*core_clk is required for LINK protocol engine
1479 *clock rate appropriately set by target specific clock driver */
Manu Gautam5143b252012-01-05 19:25:23 -08001480 mehci->core_clk = clk_get(mehci->dev, "core_clk");
1481 if (IS_ERR(mehci->core_clk)) {
1482 dev_err(mehci->dev, "failed to get core_clk\n");
1483 ret = PTR_ERR(mehci->core_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301484 return ret;
1485 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301486
Ofir Cohen07944aa2012-12-23 13:41:57 +02001487 /* alt_core_clk is for LINK to be used during PHY RESET in
1488 * targets on which link does NOT use asynchronous reset methodology.
Lena Salman8c8ba382012-02-14 15:59:31 +02001489 * clock rate appropriately set by target specific clock driver */
Manu Gautam5143b252012-01-05 19:25:23 -08001490 mehci->alt_core_clk = clk_get(mehci->dev, "alt_core_clk");
Manu Gautam863b74132012-11-21 14:30:04 +05301491 if (IS_ERR(mehci->alt_core_clk))
1492 dev_dbg(mehci->dev, "failed to get alt_core_clk\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301493
Lena Salman8c8ba382012-02-14 15:59:31 +02001494 /* phy_clk is required for HSIC PHY operation
1495 * clock rate appropriately set by target specific clock driver */
Manu Gautam5143b252012-01-05 19:25:23 -08001496 mehci->phy_clk = clk_get(mehci->dev, "phy_clk");
1497 if (IS_ERR(mehci->phy_clk)) {
1498 dev_err(mehci->dev, "failed to get phy_clk\n");
1499 ret = PTR_ERR(mehci->phy_clk);
1500 goto put_alt_core_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301501 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301502
1503 /* 10MHz cal_clk is required for calibration of I/O pads */
Manu Gautam5143b252012-01-05 19:25:23 -08001504 mehci->cal_clk = clk_get(mehci->dev, "cal_clk");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301505 if (IS_ERR(mehci->cal_clk)) {
Manu Gautam5143b252012-01-05 19:25:23 -08001506 dev_err(mehci->dev, "failed to get cal_clk\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301507 ret = PTR_ERR(mehci->cal_clk);
Manu Gautam5143b252012-01-05 19:25:23 -08001508 goto put_phy_clk;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301509 }
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301510
1511 /* ahb_clk is required for data transfers */
Manu Gautam5143b252012-01-05 19:25:23 -08001512 mehci->ahb_clk = clk_get(mehci->dev, "iface_clk");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301513 if (IS_ERR(mehci->ahb_clk)) {
Manu Gautam5143b252012-01-05 19:25:23 -08001514 dev_err(mehci->dev, "failed to get iface_clk\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301515 ret = PTR_ERR(mehci->ahb_clk);
1516 goto put_cal_clk;
1517 }
1518
Ido Shayevitz5dfbb132013-04-18 13:22:07 +03001519 /*
1520 * Inactivity_clk is required for hsic bam inactivity timer.
1521 * This clock is not compulsory and is defined in clock lookup
1522 * only for targets that need to use the inactivity timer feature.
1523 */
1524 mehci->inactivity_clk = clk_get(mehci->dev, "inactivity_clk");
1525 if (IS_ERR(mehci->inactivity_clk))
1526 dev_dbg(mehci->dev, "failed to get inactivity_clk\n");
1527
Manu Gautam28b1bac2012-01-30 16:43:06 +05301528 clk_prepare_enable(mehci->core_clk);
1529 clk_prepare_enable(mehci->phy_clk);
1530 clk_prepare_enable(mehci->cal_clk);
1531 clk_prepare_enable(mehci->ahb_clk);
Ido Shayevitz5dfbb132013-04-18 13:22:07 +03001532 if (!IS_ERR(mehci->inactivity_clk))
1533 clk_prepare_enable(mehci->inactivity_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301534
1535 return 0;
1536
1537put_clocks:
Jack Phamfd193eb2012-02-22 15:38:08 -08001538 if (!atomic_read(&mehci->in_lpm)) {
1539 clk_disable_unprepare(mehci->core_clk);
1540 clk_disable_unprepare(mehci->phy_clk);
1541 clk_disable_unprepare(mehci->cal_clk);
1542 clk_disable_unprepare(mehci->ahb_clk);
Ido Shayevitz5dfbb132013-04-18 13:22:07 +03001543 if (!IS_ERR(mehci->inactivity_clk))
1544 clk_disable_unprepare(mehci->inactivity_clk);
Jack Phamfd193eb2012-02-22 15:38:08 -08001545 }
Ido Shayevitz5dfbb132013-04-18 13:22:07 +03001546 if (!IS_ERR(mehci->inactivity_clk))
1547 clk_put(mehci->inactivity_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301548 clk_put(mehci->ahb_clk);
1549put_cal_clk:
1550 clk_put(mehci->cal_clk);
Manu Gautam5143b252012-01-05 19:25:23 -08001551put_phy_clk:
1552 clk_put(mehci->phy_clk);
1553put_alt_core_clk:
Manu Gautam863b74132012-11-21 14:30:04 +05301554 if (!IS_ERR(mehci->alt_core_clk))
1555 clk_put(mehci->alt_core_clk);
Manu Gautam5143b252012-01-05 19:25:23 -08001556 clk_put(mehci->core_clk);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301557
1558 return ret;
1559}
Vamsi Krishna34f01582011-12-14 19:54:42 -08001560static irqreturn_t hsic_peripheral_status_change(int irq, void *dev_id)
1561{
1562 struct msm_hsic_hcd *mehci = dev_id;
1563
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001564 pr_debug("%s: mehci:%p dev_id:%p\n", __func__, mehci, dev_id);
Vamsi Krishna34f01582011-12-14 19:54:42 -08001565
1566 if (mehci)
1567 msm_hsic_config_gpios(mehci, 0);
1568
1569 return IRQ_HANDLED;
1570}
1571
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001572static irqreturn_t msm_hsic_wakeup_irq(int irq, void *data)
1573{
1574 struct msm_hsic_hcd *mehci = data;
Pavankumar Kondeti968cf272012-09-27 12:04:12 +05301575 int ret;
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001576
Manu Gautam3fb60ca2013-02-13 18:33:33 +05301577 if (irq == mehci->async_irq) {
1578 mehci->async_int_cnt++;
1579 dbg_log_event(NULL, "Remote Wakeup (ASYNC) IRQ",
1580 mehci->async_int_cnt);
1581 } else {
1582 mehci->wakeup_int_cnt++;
1583 dbg_log_event(NULL, "Remote Wakeup IRQ", mehci->wakeup_int_cnt);
1584 }
1585 dev_dbg(mehci->dev, "%s: hsic remote wakeup interrupt %d cnt: %u, %u\n",
1586 __func__, irq, mehci->wakeup_int_cnt, mehci->async_int_cnt);
Hemant Kumar6fd65032012-05-23 13:02:24 -07001587
Sudhir Sharma1673e302012-08-27 17:37:24 -07001588 wake_lock(&mehci->wlock);
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001589
Manu Gautam3fb60ca2013-02-13 18:33:33 +05301590 if (mehci->wakeup_irq) {
1591 spin_lock(&mehci->wakeup_lock);
1592 if (mehci->wakeup_irq_enabled) {
1593 mehci->wakeup_irq_enabled = 0;
1594 disable_irq_wake(irq);
1595 disable_irq_nosync(irq);
1596 }
1597 spin_unlock(&mehci->wakeup_lock);
Jack Phamfe441ea2012-03-23 17:03:15 -07001598 }
1599
Sudhir Sharma1673e302012-08-27 17:37:24 -07001600 if (!atomic_read(&mehci->pm_usage_cnt)) {
Pavankumar Kondeti968cf272012-09-27 12:04:12 +05301601 ret = pm_runtime_get(mehci->dev);
1602 /*
1603 * HSIC runtime resume can race with us.
1604 * if we are active (ret == 1) or resuming
1605 * (ret == -EINPROGRESS), decrement the
1606 * PM usage counter before returning.
1607 */
1608 if ((ret == 1) || (ret == -EINPROGRESS))
1609 pm_runtime_put_noidle(mehci->dev);
1610 else
1611 atomic_set(&mehci->pm_usage_cnt, 1);
Sudhir Sharma1673e302012-08-27 17:37:24 -07001612 }
1613
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08001614 return IRQ_HANDLED;
1615}
1616
Hemant Kumare6275972012-02-29 20:06:21 -08001617static int ehci_hsic_msm_bus_show(struct seq_file *s, void *unused)
1618{
1619 if (debug_bus_voting_enabled)
1620 seq_printf(s, "enabled\n");
1621 else
1622 seq_printf(s, "disabled\n");
1623
1624 return 0;
1625}
1626
1627static int ehci_hsic_msm_bus_open(struct inode *inode, struct file *file)
1628{
1629 return single_open(file, ehci_hsic_msm_bus_show, inode->i_private);
1630}
1631
1632static ssize_t ehci_hsic_msm_bus_write(struct file *file,
1633 const char __user *ubuf, size_t count, loff_t *ppos)
1634{
1635 char buf[8];
1636 int ret;
1637 struct seq_file *s = file->private_data;
1638 struct msm_hsic_hcd *mehci = s->private;
1639
1640 memset(buf, 0x00, sizeof(buf));
1641
1642 if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
1643 return -EFAULT;
1644
1645 if (!strncmp(buf, "enable", 6)) {
1646 /* Do not vote here. Let hsic driver decide when to vote */
1647 debug_bus_voting_enabled = true;
1648 } else {
1649 debug_bus_voting_enabled = false;
1650 if (mehci->bus_perf_client) {
1651 ret = msm_bus_scale_client_update_request(
1652 mehci->bus_perf_client, 0);
1653 if (ret)
1654 dev_err(mehci->dev, "%s: Failed to devote "
1655 "for bus bw %d\n", __func__, ret);
1656 }
1657 }
1658
1659 return count;
1660}
1661
1662const struct file_operations ehci_hsic_msm_bus_fops = {
1663 .open = ehci_hsic_msm_bus_open,
1664 .read = seq_read,
1665 .write = ehci_hsic_msm_bus_write,
1666 .llseek = seq_lseek,
1667 .release = single_release,
1668};
1669
Hemant Kumar6fd65032012-05-23 13:02:24 -07001670static int ehci_hsic_msm_wakeup_cnt_show(struct seq_file *s, void *unused)
1671{
1672 struct msm_hsic_hcd *mehci = s->private;
1673
1674 seq_printf(s, "%u\n", mehci->wakeup_int_cnt);
1675
1676 return 0;
1677}
1678
1679static int ehci_hsic_msm_wakeup_cnt_open(struct inode *inode, struct file *f)
1680{
1681 return single_open(f, ehci_hsic_msm_wakeup_cnt_show, inode->i_private);
1682}
1683
1684const struct file_operations ehci_hsic_msm_wakeup_cnt_fops = {
1685 .open = ehci_hsic_msm_wakeup_cnt_open,
1686 .read = seq_read,
1687 .llseek = seq_lseek,
1688 .release = single_release,
1689};
1690
Hemant Kumar45d211b2012-05-31 17:58:43 -07001691static int ehci_hsic_msm_data_events_show(struct seq_file *s, void *unused)
1692{
1693 unsigned long flags;
1694 unsigned i;
1695
1696 read_lock_irqsave(&dbg_hsic_data.lck, flags);
1697
1698 i = dbg_hsic_data.idx;
1699 for (dbg_inc(&i); i != dbg_hsic_data.idx; dbg_inc(&i)) {
1700 if (!strnlen(dbg_hsic_data.buf[i], DBG_MSG_LEN))
1701 continue;
1702 seq_printf(s, "%s\n", dbg_hsic_data.buf[i]);
1703 }
1704
1705 read_unlock_irqrestore(&dbg_hsic_data.lck, flags);
1706
1707 return 0;
1708}
1709
1710static int ehci_hsic_msm_data_events_open(struct inode *inode, struct file *f)
1711{
1712 return single_open(f, ehci_hsic_msm_data_events_show, inode->i_private);
1713}
1714
1715const struct file_operations ehci_hsic_msm_dbg_data_fops = {
1716 .open = ehci_hsic_msm_data_events_open,
1717 .read = seq_read,
1718 .llseek = seq_lseek,
1719 .release = single_release,
1720};
1721
1722static int ehci_hsic_msm_ctrl_events_show(struct seq_file *s, void *unused)
1723{
1724 unsigned long flags;
1725 unsigned i;
1726
1727 read_lock_irqsave(&dbg_hsic_ctrl.lck, flags);
1728
1729 i = dbg_hsic_ctrl.idx;
1730 for (dbg_inc(&i); i != dbg_hsic_ctrl.idx; dbg_inc(&i)) {
1731 if (!strnlen(dbg_hsic_ctrl.buf[i], DBG_MSG_LEN))
1732 continue;
1733 seq_printf(s, "%s\n", dbg_hsic_ctrl.buf[i]);
1734 }
1735
1736 read_unlock_irqrestore(&dbg_hsic_ctrl.lck, flags);
1737
1738 return 0;
1739}
1740
1741static int ehci_hsic_msm_ctrl_events_open(struct inode *inode, struct file *f)
1742{
1743 return single_open(f, ehci_hsic_msm_ctrl_events_show, inode->i_private);
1744}
1745
1746const struct file_operations ehci_hsic_msm_dbg_ctrl_fops = {
1747 .open = ehci_hsic_msm_ctrl_events_open,
1748 .read = seq_read,
1749 .llseek = seq_lseek,
1750 .release = single_release,
1751};
1752
Hemant Kumare6275972012-02-29 20:06:21 -08001753static struct dentry *ehci_hsic_msm_dbg_root;
1754static int ehci_hsic_msm_debugfs_init(struct msm_hsic_hcd *mehci)
1755{
1756 struct dentry *ehci_hsic_msm_dentry;
1757
1758 ehci_hsic_msm_dbg_root = debugfs_create_dir("ehci_hsic_msm_dbg", NULL);
1759
1760 if (!ehci_hsic_msm_dbg_root || IS_ERR(ehci_hsic_msm_dbg_root))
1761 return -ENODEV;
1762
1763 ehci_hsic_msm_dentry = debugfs_create_file("bus_voting",
1764 S_IRUGO | S_IWUSR,
1765 ehci_hsic_msm_dbg_root, mehci,
1766 &ehci_hsic_msm_bus_fops);
1767
1768 if (!ehci_hsic_msm_dentry) {
1769 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1770 return -ENODEV;
1771 }
1772
Hemant Kumar6fd65032012-05-23 13:02:24 -07001773 ehci_hsic_msm_dentry = debugfs_create_file("wakeup_cnt",
1774 S_IRUGO,
1775 ehci_hsic_msm_dbg_root, mehci,
1776 &ehci_hsic_msm_wakeup_cnt_fops);
1777
1778 if (!ehci_hsic_msm_dentry) {
1779 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1780 return -ENODEV;
1781 }
1782
Hemant Kumar45d211b2012-05-31 17:58:43 -07001783 ehci_hsic_msm_dentry = debugfs_create_file("show_ctrl_events",
1784 S_IRUGO,
1785 ehci_hsic_msm_dbg_root, mehci,
1786 &ehci_hsic_msm_dbg_ctrl_fops);
1787
1788 if (!ehci_hsic_msm_dentry) {
1789 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1790 return -ENODEV;
1791 }
1792
1793 ehci_hsic_msm_dentry = debugfs_create_file("show_data_events",
1794 S_IRUGO,
1795 ehci_hsic_msm_dbg_root, mehci,
1796 &ehci_hsic_msm_dbg_data_fops);
1797
1798 if (!ehci_hsic_msm_dentry) {
1799 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1800 return -ENODEV;
1801 }
1802
Hemant Kumare6275972012-02-29 20:06:21 -08001803 return 0;
1804}
1805
1806static void ehci_hsic_msm_debugfs_cleanup(void)
1807{
1808 debugfs_remove_recursive(ehci_hsic_msm_dbg_root);
1809}
1810
Manu Gautam863b74132012-11-21 14:30:04 +05301811struct msm_hsic_host_platform_data *msm_hsic_dt_to_pdata(
1812 struct platform_device *pdev)
1813{
1814 struct device_node *node = pdev->dev.of_node;
1815 struct msm_hsic_host_platform_data *pdata;
Ido Shayevitzca5dc492013-01-09 14:49:59 +02001816 int res_gpio;
Manu Gautam863b74132012-11-21 14:30:04 +05301817
1818 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
1819 if (!pdata) {
1820 dev_err(&pdev->dev, "unable to allocate platform data\n");
1821 return NULL;
1822 }
Manu Gautam863b74132012-11-21 14:30:04 +05301823
Ido Shayevitzca5dc492013-01-09 14:49:59 +02001824 res_gpio = of_get_named_gpio(node, "hsic,strobe-gpio", 0);
1825 if (res_gpio < 0)
1826 res_gpio = 0;
1827 pdata->strobe = res_gpio;
1828
1829 res_gpio = of_get_named_gpio(node, "hsic,data-gpio", 0);
1830 if (res_gpio < 0)
1831 res_gpio = 0;
1832 pdata->data = res_gpio;
Manu Gautam863b74132012-11-21 14:30:04 +05301833
Vamsi Krishnabef91832013-03-11 14:10:20 -07001834 res_gpio = of_get_named_gpio(node, "hsic,resume-gpio", 0);
1835 if (res_gpio < 0)
1836 res_gpio = 0;
1837 pdata->resume_gpio = res_gpio;
1838
Manu Gautam3c598392013-03-22 16:59:10 +05301839 pdata->phy_sof_workaround = of_property_read_bool(node,
1840 "qcom,phy-sof-workaround");
Manu Gautam863b74132012-11-21 14:30:04 +05301841 pdata->ignore_cal_pad_config = of_property_read_bool(node,
1842 "hsic,ignore-cal-pad-config");
1843 of_property_read_u32(node, "hsic,strobe-pad-offset",
1844 &pdata->strobe_pad_offset);
1845 of_property_read_u32(node, "hsic,data-pad-offset",
1846 &pdata->data_pad_offset);
1847
Ido Shayevitz95c46882013-01-20 13:47:46 +02001848 pdata->bus_scale_table = msm_bus_cl_get_pdata(pdev);
1849
Shimrit Malichi36a0c852013-03-10 11:39:10 +02001850 pdata->pool_64_bit_align = of_property_read_bool(node,
1851 "qcom,pool-64-bit-align");
Shimrit Malichi82d7cbc2013-03-12 15:36:54 +02001852 pdata->enable_hbm = of_property_read_bool(node,
1853 "qcom,enable-hbm");
Shimrit Malichi36a0c852013-03-10 11:39:10 +02001854
Manu Gautam863b74132012-11-21 14:30:04 +05301855 return pdata;
1856}
1857
1858
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301859static int __devinit ehci_hsic_msm_probe(struct platform_device *pdev)
1860{
1861 struct usb_hcd *hcd;
1862 struct resource *res;
1863 struct msm_hsic_hcd *mehci;
Vijayavardhan Vennapusa2b592824f2011-11-02 19:51:32 +05301864 struct msm_hsic_host_platform_data *pdata;
Manu Gautam16562792013-03-13 07:04:11 +05301865 unsigned long wakeup_irq_flags = 0;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301866 int ret;
1867
1868 dev_dbg(&pdev->dev, "ehci_msm-hsic probe\n");
1869
Manu Gautam863b74132012-11-21 14:30:04 +05301870 if (pdev->dev.of_node) {
1871 dev_dbg(&pdev->dev, "device tree enabled\n");
1872 pdev->dev.platform_data = msm_hsic_dt_to_pdata(pdev);
1873 dev_set_name(&pdev->dev, ehci_msm_hsic_driver.driver.name);
Manu Gautam16562792013-03-13 07:04:11 +05301874 } else {
1875 /* explicitly pass wakeup_irq flag for !DT */
1876 wakeup_irq_flags = IRQF_TRIGGER_HIGH;
Manu Gautam863b74132012-11-21 14:30:04 +05301877 }
1878 if (!pdev->dev.platform_data)
1879 dev_dbg(&pdev->dev, "No platform data given\n");
1880
Ofir Cohen4cc55372012-11-20 11:17:24 +02001881 if (!pdev->dev.dma_mask)
1882 pdev->dev.dma_mask = &ehci_msm_hsic_dma_mask;
1883 if (!pdev->dev.coherent_dma_mask)
1884 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
1885
Vijayavardhan Vennapusaafbbb8f2012-04-13 16:28:45 +05301886 /* After parent device's probe is executed, it will be put in suspend
1887 * mode. When child device's probe is called, driver core is not
1888 * resuming parent device due to which parent will be in suspend even
1889 * though child is active. Hence resume the parent device explicitly.
1890 */
1891 if (pdev->dev.parent)
1892 pm_runtime_get_sync(pdev->dev.parent);
1893
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301894 hcd = usb_create_hcd(&msm_hsic_driver, &pdev->dev,
1895 dev_name(&pdev->dev));
1896 if (!hcd) {
1897 dev_err(&pdev->dev, "Unable to create HCD\n");
1898 return -ENOMEM;
1899 }
1900
Pavankumar Kondeti6f199aa2012-09-18 17:52:51 +05301901 hcd_to_bus(hcd)->skip_resume = true;
1902
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301903 hcd->irq = platform_get_irq(pdev, 0);
1904 if (hcd->irq < 0) {
1905 dev_err(&pdev->dev, "Unable to get IRQ resource\n");
1906 ret = hcd->irq;
1907 goto put_hcd;
1908 }
1909
1910 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1911 if (!res) {
1912 dev_err(&pdev->dev, "Unable to get memory resource\n");
1913 ret = -ENODEV;
1914 goto put_hcd;
1915 }
1916
1917 hcd->rsrc_start = res->start;
1918 hcd->rsrc_len = resource_size(res);
1919 hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len);
1920 if (!hcd->regs) {
1921 dev_err(&pdev->dev, "ioremap failed\n");
1922 ret = -ENOMEM;
1923 goto put_hcd;
1924 }
1925
1926 mehci = hcd_to_hsic(hcd);
1927 mehci->dev = &pdev->dev;
Hemant Kumar30d361c2012-08-20 14:44:40 -07001928 pdata = mehci->dev->platform_data;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301929
Hemant Kumard343c012012-09-06 19:57:14 -07001930 spin_lock_init(&mehci->wakeup_lock);
1931
Manu Gautam3c598392013-03-22 16:59:10 +05301932 if (pdata->phy_sof_workaround) {
1933 mehci->ehci.susp_sof_bug = 1;
1934 mehci->ehci.reset_sof_bug = 1;
1935 mehci->ehci.resume_sof_bug = 1;
1936 }
Hemant Kumar38ce5d82012-05-29 13:00:58 -07001937
Shimrit Malichi36a0c852013-03-10 11:39:10 +02001938 mehci->ehci.pool_64_bit_align = pdata->pool_64_bit_align;
Shimrit Malichi82d7cbc2013-03-12 15:36:54 +02001939 mehci->enable_hbm = pdata->enable_hbm;
Hemant Kumare4040492012-06-21 17:35:42 -07001940
Hemant Kumar30d361c2012-08-20 14:44:40 -07001941 if (pdata)
1942 mehci->ehci.log2_irq_thresh = pdata->log2_irq_thresh;
Hemant Kumar933e0402012-05-22 11:11:40 -07001943
Ofir Cohen4cc55372012-11-20 11:17:24 +02001944 ret = msm_hsic_init_gdsc(mehci, 1);
1945 if (ret) {
1946 dev_err(&pdev->dev, "unable to initialize GDSC\n");
1947 ret = -ENODEV;
1948 goto put_hcd;
1949 }
1950
Vamsi Krishna34f01582011-12-14 19:54:42 -08001951 res = platform_get_resource_byname(pdev,
1952 IORESOURCE_IRQ,
1953 "peripheral_status_irq");
1954 if (res)
1955 mehci->peripheral_status_irq = res->start;
1956
Jack Pham0cc75c42012-10-10 02:03:50 +02001957 res = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "wakeup");
Hemant Kumar6fd65032012-05-23 13:02:24 -07001958 if (res) {
Jack Pham0cc75c42012-10-10 02:03:50 +02001959 mehci->wakeup_irq = res->start;
Hemant Kumar6fd65032012-05-23 13:02:24 -07001960 dev_dbg(mehci->dev, "wakeup_irq: %d\n", mehci->wakeup_irq);
1961 }
1962
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301963 ret = msm_hsic_init_clocks(mehci, 1);
1964 if (ret) {
1965 dev_err(&pdev->dev, "unable to initialize clocks\n");
1966 ret = -ENODEV;
1967 goto unmap;
1968 }
1969
1970 ret = msm_hsic_init_vddcx(mehci, 1);
1971 if (ret) {
1972 dev_err(&pdev->dev, "unable to initialize VDDCX\n");
1973 ret = -ENODEV;
1974 goto deinit_clocks;
1975 }
1976
Vamsi Krishnafce1bd22012-08-17 17:12:26 -07001977 init_completion(&mehci->rt_completion);
1978 init_completion(&mehci->gpt0_completion);
Ofir Cohen5dddb152012-11-14 11:18:50 +02001979
1980 msm_hsic_phy_reset(mehci);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301981
Hemant Kumar2309eaa2012-08-14 16:46:42 -07001982 ehci_wq = create_singlethread_workqueue("ehci_wq");
1983 if (!ehci_wq) {
1984 dev_err(&pdev->dev, "unable to create workqueue\n");
1985 ret = -ENOMEM;
1986 goto deinit_vddcx;
1987 }
1988
1989 INIT_WORK(&mehci->bus_vote_w, ehci_hsic_bus_vote_w);
1990
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05301991 ret = usb_add_hcd(hcd, hcd->irq, IRQF_SHARED);
1992 if (ret) {
1993 dev_err(&pdev->dev, "unable to register HCD\n");
Ofir Cohen5dddb152012-11-14 11:18:50 +02001994 goto destroy_wq;
1995 }
1996
1997 ret = msm_hsic_start(mehci);
1998 if (ret) {
1999 dev_err(&pdev->dev, "unable to initialize PHY\n");
2000 goto destroy_wq;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302001 }
2002
2003 device_init_wakeup(&pdev->dev, 1);
Sudhir Sharma1673e302012-08-27 17:37:24 -07002004 wake_lock_init(&mehci->wlock, WAKE_LOCK_SUSPEND, dev_name(&pdev->dev));
2005 wake_lock(&mehci->wlock);
Vamsi Krishna34f01582011-12-14 19:54:42 -08002006
2007 if (mehci->peripheral_status_irq) {
2008 ret = request_threaded_irq(mehci->peripheral_status_irq,
2009 NULL, hsic_peripheral_status_change,
2010 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING
2011 | IRQF_SHARED,
2012 "hsic_peripheral_status", mehci);
2013 if (ret)
2014 dev_err(&pdev->dev, "%s:request_irq:%d failed:%d",
2015 __func__, mehci->peripheral_status_irq, ret);
2016 }
2017
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08002018 /* configure wakeup irq */
Hemant Kumar6fd65032012-05-23 13:02:24 -07002019 if (mehci->wakeup_irq) {
Hemant Kumarbbcdcbc2012-08-30 14:23:38 -07002020 /* In case if wakeup gpio is pulled high at this point
2021 * remote wakeup interrupt fires right after request_irq.
2022 * Remote wake up interrupt only needs to be enabled when
2023 * HSIC bus goes to suspend.
2024 */
2025 irq_set_status_flags(mehci->wakeup_irq, IRQ_NOAUTOEN);
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08002026 ret = request_irq(mehci->wakeup_irq, msm_hsic_wakeup_irq,
Manu Gautam16562792013-03-13 07:04:11 +05302027 wakeup_irq_flags,
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08002028 "msm_hsic_wakeup", mehci);
Hemant Kumarbbcdcbc2012-08-30 14:23:38 -07002029 if (ret) {
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08002030 dev_err(&pdev->dev, "request_irq(%d) failed: %d\n",
2031 mehci->wakeup_irq, ret);
2032 mehci->wakeup_irq = 0;
2033 }
2034 }
2035
Manu Gautam3fb60ca2013-02-13 18:33:33 +05302036 mehci->async_irq = platform_get_irq_byname(pdev, "async_irq");
2037 if (mehci->async_irq < 0) {
2038 dev_dbg(&pdev->dev, "platform_get_irq for async_int failed\n");
2039 mehci->async_irq = 0;
2040 } else {
2041 ret = request_irq(mehci->async_irq, msm_hsic_wakeup_irq,
2042 IRQF_TRIGGER_RISING, "msm_hsic_async", mehci);
2043 if (ret) {
2044 dev_err(&pdev->dev, "request irq failed (ASYNC INT)\n");
2045 mehci->async_irq = 0;
Manu Gautam16562792013-03-13 07:04:11 +05302046 } else if (!mehci->wakeup_irq) {
2047 /* Async IRQ is used only in absence of dedicated irq */
Manu Gautam3fb60ca2013-02-13 18:33:33 +05302048 enable_irq_wake(mehci->async_irq);
2049 }
2050 }
2051
Hemant Kumare6275972012-02-29 20:06:21 -08002052 ret = ehci_hsic_msm_debugfs_init(mehci);
2053 if (ret)
2054 dev_dbg(&pdev->dev, "mode debugfs file is"
2055 "not available\n");
2056
2057 if (pdata && pdata->bus_scale_table) {
2058 mehci->bus_perf_client =
2059 msm_bus_scale_register_client(pdata->bus_scale_table);
2060 /* Configure BUS performance parameters for MAX bandwidth */
2061 if (mehci->bus_perf_client) {
Hemant Kumar2309eaa2012-08-14 16:46:42 -07002062 mehci->bus_vote = true;
2063 queue_work(ehci_wq, &mehci->bus_vote_w);
Hemant Kumare6275972012-02-29 20:06:21 -08002064 } else {
2065 dev_err(&pdev->dev, "%s: Failed to register BUS "
2066 "scaling client!!\n", __func__);
2067 }
2068 }
2069
Hemant Kumar105d07f2012-07-02 15:33:07 -07002070 __mehci = mehci;
2071
Hemant Kumarbc8bdf62012-10-17 12:29:51 -07002072 if (pdata && pdata->standalone_latency)
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05302073 pm_qos_add_request(&mehci->pm_qos_req_dma,
Hemant Kumarbc8bdf62012-10-17 12:29:51 -07002074 PM_QOS_CPU_DMA_LATENCY, pdata->standalone_latency + 1);
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05302075
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302076 /*
2077 * This pdev->dev is assigned parent of root-hub by USB core,
2078 * hence, runtime framework automatically calls this driver's
2079 * runtime APIs based on root-hub's state.
2080 */
2081 pm_runtime_set_active(&pdev->dev);
2082 pm_runtime_enable(&pdev->dev);
Vijayavardhan Vennapusaafbbb8f2012-04-13 16:28:45 +05302083 /* Decrement the parent device's counter after probe.
2084 * As child is active, parent will not be put into
2085 * suspend mode.
2086 */
2087 if (pdev->dev.parent)
2088 pm_runtime_put_sync(pdev->dev.parent);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302089
Shimrit Malichi82d7cbc2013-03-12 15:36:54 +02002090 if (mehci->enable_hbm)
2091 hbm_init(hcd);
2092
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302093 return 0;
2094
Ofir Cohen5dddb152012-11-14 11:18:50 +02002095destroy_wq:
Hemant Kumar2309eaa2012-08-14 16:46:42 -07002096 destroy_workqueue(ehci_wq);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302097deinit_vddcx:
2098 msm_hsic_init_vddcx(mehci, 0);
Ofir Cohen4cc55372012-11-20 11:17:24 +02002099 msm_hsic_init_gdsc(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302100deinit_clocks:
2101 msm_hsic_init_clocks(mehci, 0);
2102unmap:
2103 iounmap(hcd->regs);
2104put_hcd:
2105 usb_put_hcd(hcd);
2106
2107 return ret;
2108}
2109
2110static int __devexit ehci_hsic_msm_remove(struct platform_device *pdev)
2111{
2112 struct usb_hcd *hcd = platform_get_drvdata(pdev);
2113 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05302114 struct msm_hsic_host_platform_data *pdata = mehci->dev->platform_data;
2115
Ido Shayevitz65943492013-02-20 18:55:59 +02002116 /* If the device was removed no need to call pm_runtime_disable */
2117 if (pdev->dev.power.power_state.event != PM_EVENT_INVALID)
2118 pm_runtime_disable(&pdev->dev);
2119
2120 pm_runtime_set_suspended(&pdev->dev);
2121
Shimrit Malichi82d7cbc2013-03-12 15:36:54 +02002122 if (mehci->enable_hbm)
2123 hbm_uninit();
2124
Pavankumar Kondeti21a840e2013-02-12 21:43:56 +05302125 /* Remove the HCD prior to releasing our resources. */
2126 usb_remove_hcd(hcd);
2127
Hemant Kumarbc8bdf62012-10-17 12:29:51 -07002128 if (pdata && pdata->standalone_latency)
Pavankumar Kondeti4f5dc3b2012-09-07 15:33:09 +05302129 pm_qos_remove_request(&mehci->pm_qos_req_dma);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302130
Vamsi Krishna34f01582011-12-14 19:54:42 -08002131 if (mehci->peripheral_status_irq)
2132 free_irq(mehci->peripheral_status_irq, mehci);
Jack Phamfe441ea2012-03-23 17:03:15 -07002133
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08002134 if (mehci->wakeup_irq) {
Jack Phamfe441ea2012-03-23 17:03:15 -07002135 if (mehci->wakeup_irq_enabled)
2136 disable_irq_wake(mehci->wakeup_irq);
Vamsi Krishna6921cbe2012-02-21 18:34:43 -08002137 free_irq(mehci->wakeup_irq, mehci);
2138 }
Vamsi Krishna34f01582011-12-14 19:54:42 -08002139
Manu Gautam3fb60ca2013-02-13 18:33:33 +05302140 if (mehci->async_irq) {
Manu Gautam1a1a9c62013-03-19 17:37:11 +05302141 /* Async IRQ is used only in absence of dedicated wakeup irq */
2142 if (!mehci->wakeup_irq)
2143 disable_irq_wake(mehci->async_irq);
Manu Gautam3fb60ca2013-02-13 18:33:33 +05302144 free_irq(mehci->async_irq, mehci);
2145 }
Hemant Kumar2309eaa2012-08-14 16:46:42 -07002146 /*
2147 * If the update request is called after unregister, the request will
2148 * fail. Results are undefined if unregister is called in the middle of
2149 * update request.
2150 */
2151 mehci->bus_vote = false;
2152 cancel_work_sync(&mehci->bus_vote_w);
2153
Hemant Kumare6275972012-02-29 20:06:21 -08002154 if (mehci->bus_perf_client)
2155 msm_bus_scale_unregister_client(mehci->bus_perf_client);
2156
2157 ehci_hsic_msm_debugfs_cleanup();
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302158 device_init_wakeup(&pdev->dev, 0);
Ido Shayevitze50d9142013-02-17 20:43:26 +02002159
Hemant Kumar2309eaa2012-08-14 16:46:42 -07002160 destroy_workqueue(ehci_wq);
2161
Vijayavardhan Vennapusae3316a12011-10-15 06:05:17 +05302162 msm_hsic_config_gpios(mehci, 0);
Vamsi Krishnabef91832013-03-11 14:10:20 -07002163
2164 if (pdata && pdata->resume_gpio)
2165 gpio_free(pdata->resume_gpio);
2166
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302167 msm_hsic_init_vddcx(mehci, 0);
Ofir Cohen4cc55372012-11-20 11:17:24 +02002168 msm_hsic_init_gdsc(mehci, 0);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302169
2170 msm_hsic_init_clocks(mehci, 0);
Sudhir Sharma1673e302012-08-27 17:37:24 -07002171 wake_lock_destroy(&mehci->wlock);
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302172 iounmap(hcd->regs);
2173 usb_put_hcd(hcd);
2174
2175 return 0;
2176}
2177
2178#ifdef CONFIG_PM_SLEEP
2179static int msm_hsic_pm_suspend(struct device *dev)
2180{
Jack Phambe05fbb2012-05-16 10:56:26 -07002181 int ret;
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302182 struct usb_hcd *hcd = dev_get_drvdata(dev);
2183 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
2184
2185 dev_dbg(dev, "ehci-msm-hsic PM suspend\n");
2186
Hemant Kumar45d211b2012-05-31 17:58:43 -07002187 dbg_log_event(NULL, "PM Suspend", 0);
2188
Manu Gautam16562792013-03-13 07:04:11 +05302189 if (device_may_wakeup(dev) && !mehci->async_irq)
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302190 enable_irq_wake(hcd->irq);
2191
Jack Phambe05fbb2012-05-16 10:56:26 -07002192 ret = msm_hsic_suspend(mehci);
2193
Manu Gautam16562792013-03-13 07:04:11 +05302194 if (ret && device_may_wakeup(dev) && !mehci->async_irq)
Jack Phambe05fbb2012-05-16 10:56:26 -07002195 disable_irq_wake(hcd->irq);
2196
2197 return ret;
Jack Phamfe441ea2012-03-23 17:03:15 -07002198}
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302199
Jack Pham16b06f82012-08-14 20:03:59 -07002200static int msm_hsic_pm_suspend_noirq(struct device *dev)
2201{
2202 struct usb_hcd *hcd = dev_get_drvdata(dev);
2203 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
2204
Pavankumar Kondeti822fbe62013-01-28 17:04:39 +05302205 if (atomic_read(&mehci->async_int)) {
Jack Pham16b06f82012-08-14 20:03:59 -07002206 dev_dbg(dev, "suspend_noirq: Aborting due to pending interrupt\n");
2207 return -EBUSY;
2208 }
2209
2210 return 0;
2211}
2212
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302213static int msm_hsic_pm_resume(struct device *dev)
2214{
2215 int ret;
2216 struct usb_hcd *hcd = dev_get_drvdata(dev);
2217 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
2218
Jack Pham16b06f82012-08-14 20:03:59 -07002219 dev_dbg(dev, "ehci-msm-hsic PM resume\n");
Hemant Kumar45d211b2012-05-31 17:58:43 -07002220 dbg_log_event(NULL, "PM Resume", 0);
2221
Manu Gautam16562792013-03-13 07:04:11 +05302222 if (device_may_wakeup(dev) && !mehci->async_irq)
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302223 disable_irq_wake(hcd->irq);
2224
Pavankumar Kondeti6f199aa2012-09-18 17:52:51 +05302225 /*
2226 * Keep HSIC in Low Power Mode if system is resumed
2227 * by any other wakeup source. HSIC is resumed later
2228 * when remote wakeup is received or interface driver
2229 * start I/O.
2230 */
Pavankumar Kondeti41d004c2012-11-09 10:54:00 +05302231 if (!atomic_read(&mehci->pm_usage_cnt) &&
Pavankumar Kondeti822fbe62013-01-28 17:04:39 +05302232 !atomic_read(&mehci->async_int) &&
Pavankumar Kondeti41d004c2012-11-09 10:54:00 +05302233 pm_runtime_suspended(dev))
Pavankumar Kondeti6f199aa2012-09-18 17:52:51 +05302234 return 0;
2235
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302236 ret = msm_hsic_resume(mehci);
2237 if (ret)
2238 return ret;
2239
2240 /* Bring the device to full powered state upon system resume */
2241 pm_runtime_disable(dev);
2242 pm_runtime_set_active(dev);
2243 pm_runtime_enable(dev);
2244
2245 return 0;
2246}
2247#endif
2248
2249#ifdef CONFIG_PM_RUNTIME
2250static int msm_hsic_runtime_idle(struct device *dev)
2251{
2252 dev_dbg(dev, "EHCI runtime idle\n");
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302253 return 0;
2254}
2255
2256static int msm_hsic_runtime_suspend(struct device *dev)
2257{
2258 struct usb_hcd *hcd = dev_get_drvdata(dev);
2259 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
2260
2261 dev_dbg(dev, "EHCI runtime suspend\n");
Hemant Kumar45d211b2012-05-31 17:58:43 -07002262
2263 dbg_log_event(NULL, "Run Time PM Suspend", 0);
2264
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302265 return msm_hsic_suspend(mehci);
2266}
2267
2268static int msm_hsic_runtime_resume(struct device *dev)
2269{
2270 struct usb_hcd *hcd = dev_get_drvdata(dev);
2271 struct msm_hsic_hcd *mehci = hcd_to_hsic(hcd);
2272
2273 dev_dbg(dev, "EHCI runtime resume\n");
Hemant Kumar45d211b2012-05-31 17:58:43 -07002274
2275 dbg_log_event(NULL, "Run Time PM Resume", 0);
2276
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302277 return msm_hsic_resume(mehci);
2278}
2279#endif
2280
2281#ifdef CONFIG_PM
2282static const struct dev_pm_ops msm_hsic_dev_pm_ops = {
2283 SET_SYSTEM_SLEEP_PM_OPS(msm_hsic_pm_suspend, msm_hsic_pm_resume)
Jack Pham16b06f82012-08-14 20:03:59 -07002284 .suspend_noirq = msm_hsic_pm_suspend_noirq,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302285 SET_RUNTIME_PM_OPS(msm_hsic_runtime_suspend, msm_hsic_runtime_resume,
2286 msm_hsic_runtime_idle)
2287};
2288#endif
Ofir Cohen4cc55372012-11-20 11:17:24 +02002289static const struct of_device_id hsic_host_dt_match[] = {
2290 { .compatible = "qcom,hsic-host",
2291 },
2292 {}
2293};
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302294static struct platform_driver ehci_msm_hsic_driver = {
2295 .probe = ehci_hsic_msm_probe,
2296 .remove = __devexit_p(ehci_hsic_msm_remove),
2297 .driver = {
2298 .name = "msm_hsic_host",
2299#ifdef CONFIG_PM
2300 .pm = &msm_hsic_dev_pm_ops,
2301#endif
Ofir Cohen4cc55372012-11-20 11:17:24 +02002302 .of_match_table = hsic_host_dt_match,
Vijayavardhan Vennapusa39025fe2011-10-15 05:55:10 +05302303 },
2304};