2 * Intel Langwell USB OTG transceiver driver
3 * Copyright (C) 2008 - 2010, Intel Corporation.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 /* This driver helps to switch Langwell OTG controller function between host
20 * and peripheral. It works with EHCI driver and Langwell client controller
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/pci.h>
26 #include <linux/errno.h>
27 #include <linux/interrupt.h>
28 #include <linux/kernel.h>
29 #include <linux/device.h>
30 #include <linux/moduleparam.h>
31 #include <linux/usb/ch9.h>
32 #include <linux/usb/gadget.h>
33 #include <linux/usb.h>
34 #include <linux/usb/otg.h>
35 #include <linux/usb/hcd.h>
36 #include <linux/notifier.h>
37 #include <linux/delay.h>
38 #include <asm/intel_scu_ipc.h>
40 #include <linux/usb/langwell_otg.h>
42 #define DRIVER_DESC "Intel Langwell USB OTG transceiver driver"
43 #define DRIVER_VERSION "July 10, 2010"
45 MODULE_DESCRIPTION(DRIVER_DESC
);
46 MODULE_AUTHOR("Henry Yuan <hang.yuan@intel.com>, Hao Wu <hao.wu@intel.com>");
47 MODULE_VERSION(DRIVER_VERSION
);
48 MODULE_LICENSE("GPL");
50 static const char driver_name
[] = "langwell_otg";
52 static int langwell_otg_probe(struct pci_dev
*pdev
,
53 const struct pci_device_id
*id
);
54 static void langwell_otg_remove(struct pci_dev
*pdev
);
55 static int langwell_otg_suspend(struct pci_dev
*pdev
, pm_message_t message
);
56 static int langwell_otg_resume(struct pci_dev
*pdev
);
58 static int langwell_otg_set_host(struct otg_transceiver
*otg
,
59 struct usb_bus
*host
);
60 static int langwell_otg_set_peripheral(struct otg_transceiver
*otg
,
61 struct usb_gadget
*gadget
);
62 static int langwell_otg_start_srp(struct otg_transceiver
*otg
);
64 static const struct pci_device_id pci_ids
[] = {{
65 .class = ((PCI_CLASS_SERIAL_USB
<< 8) | 0xfe),
69 .subvendor
= PCI_ANY_ID
,
70 .subdevice
= PCI_ANY_ID
,
71 }, { /* end: all zeroes */ }
74 static struct pci_driver otg_pci_driver
= {
75 .name
= (char *) driver_name
,
78 .probe
= langwell_otg_probe
,
79 .remove
= langwell_otg_remove
,
81 .suspend
= langwell_otg_suspend
,
82 .resume
= langwell_otg_resume
,
86 static inline struct langwell_otg_timer
*otg_timer_initializer
87 (void (*function
)(unsigned long), unsigned long expires
, unsigned long data
)
89 struct langwell_otg_timer
*timer
;
90 timer
= kmalloc(sizeof(struct langwell_otg_timer
), GFP_KERNEL
);
94 timer
->function
= function
;
95 timer
->expires
= expires
;
100 static struct langwell_otg_timer
*a_wait_vrise_tmr
, *a_aidl_bdis_tmr
,
101 *b_se0_srp_tmr
, *b_srp_init_tmr
;
103 static struct list_head active_timers
;
105 static struct langwell_otg
*the_transceiver
;
107 /* host/client notify transceiver when event affects HNP state */
108 void langwell_update_transceiver(void)
110 struct langwell_otg
*lnw
= the_transceiver
;
112 dev_dbg(lnw
->dev
, "transceiver is updated\n");
117 queue_work(lnw
->qwork
, &lnw
->work
);
119 EXPORT_SYMBOL(langwell_update_transceiver
);
121 static int langwell_otg_set_host(struct otg_transceiver
*otg
,
122 struct usb_bus
*host
)
129 static int langwell_otg_set_peripheral(struct otg_transceiver
*otg
,
130 struct usb_gadget
*gadget
)
132 otg
->gadget
= gadget
;
137 static int langwell_otg_set_power(struct otg_transceiver
*otg
,
143 /* A-device drives vbus, controlled through IPC commands */
144 static int langwell_otg_set_vbus(struct otg_transceiver
*otg
, bool enabled
)
146 struct langwell_otg
*lnw
= the_transceiver
;
149 dev_dbg(lnw
->dev
, "%s <--- %s\n", __func__
, enabled
? "on" : "off");
152 sub_id
= 0x8; /* Turn on the VBus */
154 sub_id
= 0x9; /* Turn off the VBus */
156 if (intel_scu_ipc_simple_command(0xef, sub_id
)) {
157 dev_dbg(lnw
->dev
, "Failed to set Vbus via IPC commands\n");
161 dev_dbg(lnw
->dev
, "%s --->\n", __func__
);
166 /* charge vbus or discharge vbus through a resistor to ground */
167 static void langwell_otg_chrg_vbus(int on
)
169 struct langwell_otg
*lnw
= the_transceiver
;
172 val
= readl(lnw
->iotg
.base
+ CI_OTGSC
);
175 writel((val
& ~OTGSC_INTSTS_MASK
) | OTGSC_VC
,
176 lnw
->iotg
.base
+ CI_OTGSC
);
178 writel((val
& ~OTGSC_INTSTS_MASK
) | OTGSC_VD
,
179 lnw
->iotg
.base
+ CI_OTGSC
);
183 static int langwell_otg_start_srp(struct otg_transceiver
*otg
)
185 struct langwell_otg
*lnw
= the_transceiver
;
186 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
189 dev_dbg(lnw
->dev
, "%s --->\n", __func__
);
191 val
= readl(iotg
->base
+ CI_OTGSC
);
193 writel((val
& ~OTGSC_INTSTS_MASK
) | OTGSC_HADP
,
194 iotg
->base
+ CI_OTGSC
);
196 /* Check if the data plus is finished or not */
198 val
= readl(iotg
->base
+ CI_OTGSC
);
199 if (val
& (OTGSC_HADP
| OTGSC_DP
))
200 dev_dbg(lnw
->dev
, "DataLine SRP Error\n");
202 /* Disable interrupt - b_sess_vld */
203 val
= readl(iotg
->base
+ CI_OTGSC
);
204 val
&= (~(OTGSC_BSVIE
| OTGSC_BSEIE
));
205 writel(val
, iotg
->base
+ CI_OTGSC
);
207 /* Start VBus SRP, drive vbus to generate VBus pulse */
208 iotg
->otg
.set_vbus(&iotg
->otg
, true);
210 iotg
->otg
.set_vbus(&iotg
->otg
, false);
212 /* Enable interrupt - b_sess_vld*/
213 val
= readl(iotg
->base
+ CI_OTGSC
);
214 dev_dbg(lnw
->dev
, "after VBUS pulse otgsc = %x\n", val
);
216 val
|= (OTGSC_BSVIE
| OTGSC_BSEIE
);
217 writel(val
, iotg
->base
+ CI_OTGSC
);
219 /* If Vbus is valid, then update the hsm */
220 if (val
& OTGSC_BSV
) {
221 dev_dbg(lnw
->dev
, "no b_sess_vld interrupt\n");
223 lnw
->iotg
.hsm
.b_sess_vld
= 1;
224 langwell_update_transceiver();
227 dev_dbg(lnw
->dev
, "%s <---\n", __func__
);
231 /* stop SOF via bus_suspend */
232 static void langwell_otg_loc_sof(int on
)
234 struct langwell_otg
*lnw
= the_transceiver
;
238 dev_dbg(lnw
->dev
, "%s ---> %s\n", __func__
, on
? "suspend" : "resume");
240 hcd
= bus_to_hcd(lnw
->iotg
.otg
.host
);
242 err
= hcd
->driver
->bus_resume(hcd
);
244 err
= hcd
->driver
->bus_suspend(hcd
);
247 dev_dbg(lnw
->dev
, "Fail to resume/suspend USB bus - %d\n", err
);
249 dev_dbg(lnw
->dev
, "%s <---\n", __func__
);
252 static int langwell_otg_check_otgsc(void)
254 struct langwell_otg
*lnw
= the_transceiver
;
257 dev_dbg(lnw
->dev
, "check sync OTGSC and USBCFG registers\n");
259 otgsc
= readl(lnw
->iotg
.base
+ CI_OTGSC
);
260 usbcfg
= readl(lnw
->usbcfg
);
262 dev_dbg(lnw
->dev
, "OTGSC = %08x, USBCFG = %08x\n",
264 dev_dbg(lnw
->dev
, "OTGSC_AVV = %d\n", !!(otgsc
& OTGSC_AVV
));
265 dev_dbg(lnw
->dev
, "USBCFG.VBUSVAL = %d\n",
266 !!(usbcfg
& USBCFG_VBUSVAL
));
267 dev_dbg(lnw
->dev
, "OTGSC_ASV = %d\n", !!(otgsc
& OTGSC_ASV
));
268 dev_dbg(lnw
->dev
, "USBCFG.AVALID = %d\n",
269 !!(usbcfg
& USBCFG_AVALID
));
270 dev_dbg(lnw
->dev
, "OTGSC_BSV = %d\n", !!(otgsc
& OTGSC_BSV
));
271 dev_dbg(lnw
->dev
, "USBCFG.BVALID = %d\n",
272 !!(usbcfg
& USBCFG_BVALID
));
273 dev_dbg(lnw
->dev
, "OTGSC_BSE = %d\n", !!(otgsc
& OTGSC_BSE
));
274 dev_dbg(lnw
->dev
, "USBCFG.SESEND = %d\n",
275 !!(usbcfg
& USBCFG_SESEND
));
277 /* Check USBCFG VBusValid/AValid/BValid/SessEnd */
278 if (!!(otgsc
& OTGSC_AVV
) ^ !!(usbcfg
& USBCFG_VBUSVAL
)) {
279 dev_dbg(lnw
->dev
, "OTGSC.AVV != USBCFG.VBUSVAL\n");
282 if (!!(otgsc
& OTGSC_ASV
) ^ !!(usbcfg
& USBCFG_AVALID
)) {
283 dev_dbg(lnw
->dev
, "OTGSC.ASV != USBCFG.AVALID\n");
286 if (!!(otgsc
& OTGSC_BSV
) ^ !!(usbcfg
& USBCFG_BVALID
)) {
287 dev_dbg(lnw
->dev
, "OTGSC.BSV != USBCFG.BVALID\n");
290 if (!!(otgsc
& OTGSC_BSE
) ^ !!(usbcfg
& USBCFG_SESEND
)) {
291 dev_dbg(lnw
->dev
, "OTGSC.BSE != USBCFG.SESSEN\n");
295 dev_dbg(lnw
->dev
, "OTGSC and USBCFG are synced\n");
300 dev_warn(lnw
->dev
, "OTGSC isn't equal to USBCFG\n");
305 static void langwell_otg_phy_low_power(int on
)
307 struct langwell_otg
*lnw
= the_transceiver
;
308 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
312 dev_dbg(lnw
->dev
, "%s ---> %s mode\n",
313 __func__
, on
? "Low power" : "Normal");
317 val
= readb(iotg
->base
+ CI_HOSTPC1
+ 2);
320 /* Due to hardware issue, after set PHCD, sync will failed
321 * between USBCFG and OTGSC, so before set PHCD, check if
322 * sync is in process now. If the answer is "yes", then do
323 * not touch PHCD bit */
324 retval
= langwell_otg_check_otgsc();
326 dev_dbg(lnw
->dev
, "Skip PHCD programming..\n");
330 writeb(val
| phcd
, iotg
->base
+ CI_HOSTPC1
+ 2);
332 writeb(val
& ~phcd
, iotg
->base
+ CI_HOSTPC1
+ 2);
334 dev_dbg(lnw
->dev
, "%s <--- done\n", __func__
);
337 /* After drv vbus, add 5 ms delay to set PHCD */
338 static void langwell_otg_phy_low_power_wait(int on
)
340 struct langwell_otg
*lnw
= the_transceiver
;
342 dev_dbg(lnw
->dev
, "add 5ms delay before programing PHCD\n");
345 langwell_otg_phy_low_power(on
);
348 /* Enable/Disable OTG interrupt */
349 static void langwell_otg_intr(int on
)
351 struct langwell_otg
*lnw
= the_transceiver
;
352 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
355 dev_dbg(lnw
->dev
, "%s ---> %s\n", __func__
, on
? "on" : "off");
357 val
= readl(iotg
->base
+ CI_OTGSC
);
359 /* OTGSC_INT_MASK doesn't contains 1msInt */
361 val
= val
| (OTGSC_INT_MASK
);
362 writel(val
, iotg
->base
+ CI_OTGSC
);
364 val
= val
& ~(OTGSC_INT_MASK
);
365 writel(val
, iotg
->base
+ CI_OTGSC
);
368 dev_dbg(lnw
->dev
, "%s <---\n", __func__
);
371 /* set HAAR: Hardware Assist Auto-Reset */
372 static void langwell_otg_HAAR(int on
)
374 struct langwell_otg
*lnw
= the_transceiver
;
375 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
378 dev_dbg(lnw
->dev
, "%s ---> %s\n", __func__
, on
? "on" : "off");
380 val
= readl(iotg
->base
+ CI_OTGSC
);
382 writel((val
& ~OTGSC_INTSTS_MASK
) | OTGSC_HAAR
,
383 iotg
->base
+ CI_OTGSC
);
385 writel((val
& ~OTGSC_INTSTS_MASK
) & ~OTGSC_HAAR
,
386 iotg
->base
+ CI_OTGSC
);
388 dev_dbg(lnw
->dev
, "%s <---\n", __func__
);
391 /* set HABA: Hardware Assist B-Disconnect to A-Connect */
392 static void langwell_otg_HABA(int on
)
394 struct langwell_otg
*lnw
= the_transceiver
;
395 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
398 dev_dbg(lnw
->dev
, "%s ---> %s\n", __func__
, on
? "on" : "off");
400 val
= readl(iotg
->base
+ CI_OTGSC
);
402 writel((val
& ~OTGSC_INTSTS_MASK
) | OTGSC_HABA
,
403 iotg
->base
+ CI_OTGSC
);
405 writel((val
& ~OTGSC_INTSTS_MASK
) & ~OTGSC_HABA
,
406 iotg
->base
+ CI_OTGSC
);
408 dev_dbg(lnw
->dev
, "%s <---\n", __func__
);
411 static int langwell_otg_check_se0_srp(int on
)
413 struct langwell_otg
*lnw
= the_transceiver
;
414 int delay_time
= TB_SE0_SRP
* 10;
417 dev_dbg(lnw
->dev
, "%s --->\n", __func__
);
423 val
= readl(lnw
->iotg
.base
+ CI_PORTSC1
);
427 dev_dbg(lnw
->dev
, "%s <---\n", __func__
);
431 /* The timeout callback function to set time out bit */
432 static void set_tmout(unsigned long indicator
)
434 *(int *)indicator
= 1;
437 void langwell_otg_nsf_msg(unsigned long indicator
)
439 struct langwell_otg
*lnw
= the_transceiver
;
447 "OTG:NSF-%lu - deivce not responding\n", indicator
);
451 "OTG:NSF-%lu - deivce not supported\n", indicator
);
454 dev_warn(lnw
->dev
, "Do not have this kind of NSF\n");
459 /* Initialize timers */
460 static int langwell_otg_init_timers(struct otg_hsm
*hsm
)
462 /* HSM used timers */
463 a_wait_vrise_tmr
= otg_timer_initializer(&set_tmout
, TA_WAIT_VRISE
,
464 (unsigned long)&hsm
->a_wait_vrise_tmout
);
465 if (a_wait_vrise_tmr
== NULL
)
467 a_aidl_bdis_tmr
= otg_timer_initializer(&set_tmout
, TA_AIDL_BDIS
,
468 (unsigned long)&hsm
->a_aidl_bdis_tmout
);
469 if (a_aidl_bdis_tmr
== NULL
)
471 b_se0_srp_tmr
= otg_timer_initializer(&set_tmout
, TB_SE0_SRP
,
472 (unsigned long)&hsm
->b_se0_srp
);
473 if (b_se0_srp_tmr
== NULL
)
475 b_srp_init_tmr
= otg_timer_initializer(&set_tmout
, TB_SRP_INIT
,
476 (unsigned long)&hsm
->b_srp_init_tmout
);
477 if (b_srp_init_tmr
== NULL
)
484 static void langwell_otg_free_timers(void)
486 kfree(a_wait_vrise_tmr
);
487 kfree(a_aidl_bdis_tmr
);
488 kfree(b_se0_srp_tmr
);
489 kfree(b_srp_init_tmr
);
492 /* The timeout callback function to set time out bit */
493 static void langwell_otg_timer_fn(unsigned long indicator
)
495 struct langwell_otg
*lnw
= the_transceiver
;
497 *(int *)indicator
= 1;
499 dev_dbg(lnw
->dev
, "kernel timer - timeout\n");
501 langwell_update_transceiver();
504 /* kernel timer used instead of HW based interrupt */
505 static void langwell_otg_add_ktimer(enum langwell_otg_timer_type timers
)
507 struct langwell_otg
*lnw
= the_transceiver
;
508 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
509 unsigned long j
= jiffies
;
510 unsigned long data
, time
;
513 case TA_WAIT_VRISE_TMR
:
514 iotg
->hsm
.a_wait_vrise_tmout
= 0;
515 data
= (unsigned long)&iotg
->hsm
.a_wait_vrise_tmout
;
516 time
= TA_WAIT_VRISE
;
518 case TA_WAIT_BCON_TMR
:
519 iotg
->hsm
.a_wait_bcon_tmout
= 0;
520 data
= (unsigned long)&iotg
->hsm
.a_wait_bcon_tmout
;
523 case TA_AIDL_BDIS_TMR
:
524 iotg
->hsm
.a_aidl_bdis_tmout
= 0;
525 data
= (unsigned long)&iotg
->hsm
.a_aidl_bdis_tmout
;
528 case TB_ASE0_BRST_TMR
:
529 iotg
->hsm
.b_ase0_brst_tmout
= 0;
530 data
= (unsigned long)&iotg
->hsm
.b_ase0_brst_tmout
;
533 case TB_SRP_INIT_TMR
:
534 iotg
->hsm
.b_srp_init_tmout
= 0;
535 data
= (unsigned long)&iotg
->hsm
.b_srp_init_tmout
;
538 case TB_SRP_FAIL_TMR
:
539 iotg
->hsm
.b_srp_fail_tmout
= 0;
540 data
= (unsigned long)&iotg
->hsm
.b_srp_fail_tmout
;
543 case TB_BUS_SUSPEND_TMR
:
544 iotg
->hsm
.b_bus_suspend_tmout
= 0;
545 data
= (unsigned long)&iotg
->hsm
.b_bus_suspend_tmout
;
546 time
= TB_BUS_SUSPEND
;
549 dev_dbg(lnw
->dev
, "unknown timer, cannot enable it\n");
553 lnw
->hsm_timer
.data
= data
;
554 lnw
->hsm_timer
.function
= langwell_otg_timer_fn
;
555 lnw
->hsm_timer
.expires
= j
+ time
* HZ
/ 1000; /* milliseconds */
557 add_timer(&lnw
->hsm_timer
);
559 dev_dbg(lnw
->dev
, "add timer successfully\n");
562 /* Add timer to timer list */
563 static void langwell_otg_add_timer(void *gtimer
)
565 struct langwell_otg_timer
*timer
= (struct langwell_otg_timer
*)gtimer
;
566 struct langwell_otg_timer
*tmp_timer
;
567 struct intel_mid_otg_xceiv
*iotg
= &the_transceiver
->iotg
;
570 /* Check if the timer is already in the active list,
571 * if so update timer count
573 list_for_each_entry(tmp_timer
, &active_timers
, list
)
574 if (tmp_timer
== timer
) {
575 timer
->count
= timer
->expires
;
578 timer
->count
= timer
->expires
;
580 if (list_empty(&active_timers
)) {
581 val32
= readl(iotg
->base
+ CI_OTGSC
);
582 writel(val32
| OTGSC_1MSE
, iotg
->base
+ CI_OTGSC
);
585 list_add_tail(&timer
->list
, &active_timers
);
588 /* Remove timer from the timer list; clear timeout status */
589 static void langwell_otg_del_timer(void *gtimer
)
591 struct langwell_otg
*lnw
= the_transceiver
;
592 struct langwell_otg_timer
*timer
= (struct langwell_otg_timer
*)gtimer
;
593 struct langwell_otg_timer
*tmp_timer
, *del_tmp
;
596 list_for_each_entry_safe(tmp_timer
, del_tmp
, &active_timers
, list
)
597 if (tmp_timer
== timer
)
598 list_del(&timer
->list
);
600 if (list_empty(&active_timers
)) {
601 val32
= readl(lnw
->iotg
.base
+ CI_OTGSC
);
602 writel(val32
& ~OTGSC_1MSE
, lnw
->iotg
.base
+ CI_OTGSC
);
606 /* Reduce timer count by 1, and find timeout conditions.*/
607 static int langwell_otg_tick_timer(u32
*int_sts
)
609 struct langwell_otg
*lnw
= the_transceiver
;
610 struct langwell_otg_timer
*tmp_timer
, *del_tmp
;
613 list_for_each_entry_safe(tmp_timer
, del_tmp
, &active_timers
, list
) {
615 /* check if timer expires */
616 if (!tmp_timer
->count
) {
617 list_del(&tmp_timer
->list
);
618 tmp_timer
->function(tmp_timer
->data
);
623 if (list_empty(&active_timers
)) {
624 dev_dbg(lnw
->dev
, "tick timer: disable 1ms int\n");
625 *int_sts
= *int_sts
& ~OTGSC_1MSE
;
630 static void reset_otg(void)
632 struct langwell_otg
*lnw
= the_transceiver
;
633 int delay_time
= 1000;
636 dev_dbg(lnw
->dev
, "reseting OTG controller ...\n");
637 val
= readl(lnw
->iotg
.base
+ CI_USBCMD
);
638 writel(val
| USBCMD_RST
, lnw
->iotg
.base
+ CI_USBCMD
);
642 dev_dbg(lnw
->dev
, "reset timeout\n");
643 val
= readl(lnw
->iotg
.base
+ CI_USBCMD
);
646 dev_dbg(lnw
->dev
, "reset done.\n");
649 static void set_host_mode(void)
651 struct langwell_otg
*lnw
= the_transceiver
;
655 val
= readl(lnw
->iotg
.base
+ CI_USBMODE
);
656 val
= (val
& (~USBMODE_CM
)) | USBMODE_HOST
;
657 writel(val
, lnw
->iotg
.base
+ CI_USBMODE
);
660 static void set_client_mode(void)
662 struct langwell_otg
*lnw
= the_transceiver
;
666 val
= readl(lnw
->iotg
.base
+ CI_USBMODE
);
667 val
= (val
& (~USBMODE_CM
)) | USBMODE_DEVICE
;
668 writel(val
, lnw
->iotg
.base
+ CI_USBMODE
);
671 static void init_hsm(void)
673 struct langwell_otg
*lnw
= the_transceiver
;
674 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
677 /* read OTGSC after reset */
678 val32
= readl(lnw
->iotg
.base
+ CI_OTGSC
);
679 dev_dbg(lnw
->dev
, "%s: OTGSC init value = 0x%x\n", __func__
, val32
);
682 if (val32
& OTGSC_ID
) {
684 iotg
->otg
.default_a
= 0;
686 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
689 iotg
->otg
.default_a
= 1;
691 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
694 /* set session indicator */
695 if (val32
& OTGSC_BSE
)
696 iotg
->hsm
.b_sess_end
= 1;
697 if (val32
& OTGSC_BSV
)
698 iotg
->hsm
.b_sess_vld
= 1;
699 if (val32
& OTGSC_ASV
)
700 iotg
->hsm
.a_sess_vld
= 1;
701 if (val32
& OTGSC_AVV
)
702 iotg
->hsm
.a_vbus_vld
= 1;
704 /* defautly power the bus */
705 iotg
->hsm
.a_bus_req
= 1;
706 iotg
->hsm
.a_bus_drop
= 0;
707 /* defautly don't request bus as B device */
708 iotg
->hsm
.b_bus_req
= 0;
709 /* no system error */
710 iotg
->hsm
.a_clr_err
= 0;
712 langwell_otg_phy_low_power_wait(1);
715 static void update_hsm(void)
717 struct langwell_otg
*lnw
= the_transceiver
;
718 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
722 val32
= readl(lnw
->iotg
.base
+ CI_OTGSC
);
723 dev_dbg(lnw
->dev
, "%s: OTGSC value = 0x%x\n", __func__
, val32
);
725 iotg
->hsm
.id
= !!(val32
& OTGSC_ID
);
726 iotg
->hsm
.b_sess_end
= !!(val32
& OTGSC_BSE
);
727 iotg
->hsm
.b_sess_vld
= !!(val32
& OTGSC_BSV
);
728 iotg
->hsm
.a_sess_vld
= !!(val32
& OTGSC_ASV
);
729 iotg
->hsm
.a_vbus_vld
= !!(val32
& OTGSC_AVV
);
732 static irqreturn_t
otg_dummy_irq(int irq
, void *_dev
)
734 struct langwell_otg
*lnw
= the_transceiver
;
735 void __iomem
*reg_base
= _dev
;
739 val
= readl(reg_base
+ CI_USBMODE
);
740 if ((val
& USBMODE_CM
) != USBMODE_DEVICE
)
743 val
= readl(reg_base
+ CI_USBSTS
);
744 int_mask
= val
& INTR_DUMMY_MASK
;
749 /* clear hsm.b_conn here since host driver can't detect it
750 * otg_dummy_irq called means B-disconnect happened.
752 if (lnw
->iotg
.hsm
.b_conn
) {
753 lnw
->iotg
.hsm
.b_conn
= 0;
754 if (spin_trylock(&lnw
->wq_lock
)) {
755 langwell_update_transceiver();
756 spin_unlock(&lnw
->wq_lock
);
760 /* Clear interrupts */
761 writel(int_mask
, reg_base
+ CI_USBSTS
);
765 static irqreturn_t
otg_irq(int irq
, void *_dev
)
767 struct langwell_otg
*lnw
= _dev
;
768 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
773 int_sts
= readl(lnw
->iotg
.base
+ CI_OTGSC
);
774 int_en
= (int_sts
& OTGSC_INTEN_MASK
) >> 8;
775 int_mask
= int_sts
& int_en
;
779 if (int_mask
& OTGSC_IDIS
) {
780 dev_dbg(lnw
->dev
, "%s: id change int\n", __func__
);
781 iotg
->hsm
.id
= (int_sts
& OTGSC_ID
) ? 1 : 0;
782 dev_dbg(lnw
->dev
, "id = %d\n", iotg
->hsm
.id
);
785 if (int_mask
& OTGSC_DPIS
) {
786 dev_dbg(lnw
->dev
, "%s: data pulse int\n", __func__
);
787 iotg
->hsm
.a_srp_det
= (int_sts
& OTGSC_DPS
) ? 1 : 0;
788 dev_dbg(lnw
->dev
, "data pulse = %d\n", iotg
->hsm
.a_srp_det
);
791 if (int_mask
& OTGSC_BSEIS
) {
792 dev_dbg(lnw
->dev
, "%s: b session end int\n", __func__
);
793 iotg
->hsm
.b_sess_end
= (int_sts
& OTGSC_BSE
) ? 1 : 0;
794 dev_dbg(lnw
->dev
, "b_sess_end = %d\n", iotg
->hsm
.b_sess_end
);
797 if (int_mask
& OTGSC_BSVIS
) {
798 dev_dbg(lnw
->dev
, "%s: b session valid int\n", __func__
);
799 iotg
->hsm
.b_sess_vld
= (int_sts
& OTGSC_BSV
) ? 1 : 0;
800 dev_dbg(lnw
->dev
, "b_sess_vld = %d\n", iotg
->hsm
.b_sess_end
);
803 if (int_mask
& OTGSC_ASVIS
) {
804 dev_dbg(lnw
->dev
, "%s: a session valid int\n", __func__
);
805 iotg
->hsm
.a_sess_vld
= (int_sts
& OTGSC_ASV
) ? 1 : 0;
806 dev_dbg(lnw
->dev
, "a_sess_vld = %d\n", iotg
->hsm
.a_sess_vld
);
809 if (int_mask
& OTGSC_AVVIS
) {
810 dev_dbg(lnw
->dev
, "%s: a vbus valid int\n", __func__
);
811 iotg
->hsm
.a_vbus_vld
= (int_sts
& OTGSC_AVV
) ? 1 : 0;
812 dev_dbg(lnw
->dev
, "a_vbus_vld = %d\n", iotg
->hsm
.a_vbus_vld
);
816 if (int_mask
& OTGSC_1MSS
) {
817 /* need to schedule otg_work if any timer is expired */
818 if (langwell_otg_tick_timer(&int_sts
))
822 writel((int_sts
& ~OTGSC_INTSTS_MASK
) | int_mask
,
823 lnw
->iotg
.base
+ CI_OTGSC
);
825 langwell_update_transceiver();
830 static int langwell_otg_iotg_notify(struct notifier_block
*nb
,
831 unsigned long action
, void *data
)
833 struct langwell_otg
*lnw
= the_transceiver
;
834 struct intel_mid_otg_xceiv
*iotg
= data
;
844 case MID_OTG_NOTIFY_CONNECT
:
845 dev_dbg(lnw
->dev
, "Lnw OTG Notify Connect Event\n");
846 if (iotg
->otg
.default_a
== 1)
847 iotg
->hsm
.b_conn
= 1;
849 iotg
->hsm
.a_conn
= 1;
852 case MID_OTG_NOTIFY_DISCONN
:
853 dev_dbg(lnw
->dev
, "Lnw OTG Notify Disconnect Event\n");
854 if (iotg
->otg
.default_a
== 1)
855 iotg
->hsm
.b_conn
= 0;
857 iotg
->hsm
.a_conn
= 0;
860 case MID_OTG_NOTIFY_HSUSPEND
:
861 dev_dbg(lnw
->dev
, "Lnw OTG Notify Host Bus suspend Event\n");
862 if (iotg
->otg
.default_a
== 1)
863 iotg
->hsm
.a_suspend_req
= 1;
865 iotg
->hsm
.b_bus_req
= 0;
868 case MID_OTG_NOTIFY_HRESUME
:
869 dev_dbg(lnw
->dev
, "Lnw OTG Notify Host Bus resume Event\n");
870 if (iotg
->otg
.default_a
== 1)
871 iotg
->hsm
.b_bus_resume
= 1;
874 case MID_OTG_NOTIFY_CSUSPEND
:
875 dev_dbg(lnw
->dev
, "Lnw OTG Notify Client Bus suspend Event\n");
876 if (iotg
->otg
.default_a
== 1) {
877 if (iotg
->hsm
.b_bus_suspend_vld
== 2) {
878 iotg
->hsm
.b_bus_suspend
= 1;
879 iotg
->hsm
.b_bus_suspend_vld
= 0;
882 iotg
->hsm
.b_bus_suspend_vld
++;
886 if (iotg
->hsm
.a_bus_suspend
== 0) {
887 iotg
->hsm
.a_bus_suspend
= 1;
892 case MID_OTG_NOTIFY_CRESUME
:
893 dev_dbg(lnw
->dev
, "Lnw OTG Notify Client Bus resume Event\n");
894 if (iotg
->otg
.default_a
== 0)
895 iotg
->hsm
.a_bus_suspend
= 0;
898 case MID_OTG_NOTIFY_HOSTADD
:
899 dev_dbg(lnw
->dev
, "Lnw OTG Nofity Host Driver Add\n");
902 case MID_OTG_NOTIFY_HOSTREMOVE
:
903 dev_dbg(lnw
->dev
, "Lnw OTG Nofity Host Driver remove\n");
906 case MID_OTG_NOTIFY_CLIENTADD
:
907 dev_dbg(lnw
->dev
, "Lnw OTG Nofity Client Driver Add\n");
910 case MID_OTG_NOTIFY_CLIENTREMOVE
:
911 dev_dbg(lnw
->dev
, "Lnw OTG Nofity Client Driver remove\n");
915 dev_dbg(lnw
->dev
, "Lnw OTG Nofity unknown notify message\n");
920 langwell_update_transceiver();
925 static void langwell_otg_work(struct work_struct
*work
)
927 struct langwell_otg
*lnw
;
928 struct intel_mid_otg_xceiv
*iotg
;
930 struct pci_dev
*pdev
;
932 lnw
= container_of(work
, struct langwell_otg
, work
);
934 pdev
= to_pci_dev(lnw
->dev
);
936 dev_dbg(lnw
->dev
, "%s: old state = %s\n", __func__
,
937 otg_state_string(iotg
->otg
.state
));
939 switch (iotg
->otg
.state
) {
940 case OTG_STATE_UNDEFINED
:
941 case OTG_STATE_B_IDLE
:
943 langwell_otg_del_timer(b_srp_init_tmr
);
944 del_timer_sync(&lnw
->hsm_timer
);
946 iotg
->otg
.default_a
= 1;
947 iotg
->hsm
.a_srp_det
= 0;
949 langwell_otg_chrg_vbus(0);
951 langwell_otg_phy_low_power(1);
953 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
954 langwell_update_transceiver();
955 } else if (iotg
->hsm
.b_sess_vld
) {
956 langwell_otg_del_timer(b_srp_init_tmr
);
957 del_timer_sync(&lnw
->hsm_timer
);
958 iotg
->hsm
.b_sess_end
= 0;
959 iotg
->hsm
.a_bus_suspend
= 0;
960 langwell_otg_chrg_vbus(0);
962 if (lnw
->iotg
.start_peripheral
) {
963 lnw
->iotg
.start_peripheral(&lnw
->iotg
);
964 iotg
->otg
.state
= OTG_STATE_B_PERIPHERAL
;
966 dev_dbg(lnw
->dev
, "client driver not loaded\n");
968 } else if (iotg
->hsm
.b_srp_init_tmout
) {
969 iotg
->hsm
.b_srp_init_tmout
= 0;
970 dev_warn(lnw
->dev
, "SRP init timeout\n");
971 } else if (iotg
->hsm
.b_srp_fail_tmout
) {
972 iotg
->hsm
.b_srp_fail_tmout
= 0;
973 iotg
->hsm
.b_bus_req
= 0;
975 /* No silence failure */
976 langwell_otg_nsf_msg(6);
977 } else if (iotg
->hsm
.b_bus_req
&& iotg
->hsm
.b_sess_end
) {
978 del_timer_sync(&lnw
->hsm_timer
);
979 /* workaround for b_se0_srp detection */
980 retval
= langwell_otg_check_se0_srp(0);
982 iotg
->hsm
.b_bus_req
= 0;
983 dev_dbg(lnw
->dev
, "LS isn't SE0, try later\n");
985 /* clear the PHCD before start srp */
986 langwell_otg_phy_low_power(0);
989 langwell_otg_add_timer(b_srp_init_tmr
);
990 iotg
->otg
.start_srp(&iotg
->otg
);
991 langwell_otg_del_timer(b_srp_init_tmr
);
992 langwell_otg_add_ktimer(TB_SRP_FAIL_TMR
);
994 /* reset PHY low power mode here */
995 langwell_otg_phy_low_power_wait(1);
999 case OTG_STATE_B_SRP_INIT
:
1000 if (!iotg
->hsm
.id
) {
1001 iotg
->otg
.default_a
= 1;
1002 iotg
->hsm
.a_srp_det
= 0;
1005 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1006 langwell_otg_chrg_vbus(0);
1008 langwell_otg_phy_low_power(1);
1009 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
1010 langwell_update_transceiver();
1011 } else if (iotg
->hsm
.b_sess_vld
) {
1012 langwell_otg_chrg_vbus(0);
1013 if (lnw
->iotg
.start_peripheral
) {
1014 lnw
->iotg
.start_peripheral(&lnw
->iotg
);
1015 iotg
->otg
.state
= OTG_STATE_B_PERIPHERAL
;
1017 dev_dbg(lnw
->dev
, "client driver not loaded\n");
1020 case OTG_STATE_B_PERIPHERAL
:
1021 if (!iotg
->hsm
.id
) {
1022 iotg
->otg
.default_a
= 1;
1023 iotg
->hsm
.a_srp_det
= 0;
1025 langwell_otg_chrg_vbus(0);
1027 if (lnw
->iotg
.stop_peripheral
)
1028 lnw
->iotg
.stop_peripheral(&lnw
->iotg
);
1031 "client driver has been removed.\n");
1034 langwell_otg_phy_low_power(1);
1035 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
1036 langwell_update_transceiver();
1037 } else if (!iotg
->hsm
.b_sess_vld
) {
1038 iotg
->hsm
.b_hnp_enable
= 0;
1040 if (lnw
->iotg
.stop_peripheral
)
1041 lnw
->iotg
.stop_peripheral(&lnw
->iotg
);
1044 "client driver has been removed.\n");
1046 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1047 } else if (iotg
->hsm
.b_bus_req
&& iotg
->otg
.gadget
&&
1048 iotg
->otg
.gadget
->b_hnp_enable
&&
1049 iotg
->hsm
.a_bus_suspend
) {
1051 if (lnw
->iotg
.stop_peripheral
)
1052 lnw
->iotg
.stop_peripheral(&lnw
->iotg
);
1055 "client driver has been removed.\n");
1057 langwell_otg_HAAR(1);
1058 iotg
->hsm
.a_conn
= 0;
1060 if (lnw
->iotg
.start_host
) {
1061 lnw
->iotg
.start_host(&lnw
->iotg
);
1062 iotg
->otg
.state
= OTG_STATE_B_WAIT_ACON
;
1065 "host driver not loaded.\n");
1067 iotg
->hsm
.a_bus_resume
= 0;
1068 langwell_otg_add_ktimer(TB_ASE0_BRST_TMR
);
1072 case OTG_STATE_B_WAIT_ACON
:
1073 if (!iotg
->hsm
.id
) {
1074 /* delete hsm timer for b_ase0_brst_tmr */
1075 del_timer_sync(&lnw
->hsm_timer
);
1077 iotg
->otg
.default_a
= 1;
1078 iotg
->hsm
.a_srp_det
= 0;
1080 langwell_otg_chrg_vbus(0);
1082 langwell_otg_HAAR(0);
1083 if (lnw
->iotg
.stop_host
)
1084 lnw
->iotg
.stop_host(&lnw
->iotg
);
1087 "host driver has been removed.\n");
1090 langwell_otg_phy_low_power(1);
1091 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
1092 langwell_update_transceiver();
1093 } else if (!iotg
->hsm
.b_sess_vld
) {
1094 /* delete hsm timer for b_ase0_brst_tmr */
1095 del_timer_sync(&lnw
->hsm_timer
);
1097 iotg
->hsm
.b_hnp_enable
= 0;
1098 iotg
->hsm
.b_bus_req
= 0;
1100 langwell_otg_chrg_vbus(0);
1101 langwell_otg_HAAR(0);
1103 if (lnw
->iotg
.stop_host
)
1104 lnw
->iotg
.stop_host(&lnw
->iotg
);
1107 "host driver has been removed.\n");
1110 langwell_otg_phy_low_power(1);
1111 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1112 } else if (iotg
->hsm
.a_conn
) {
1113 /* delete hsm timer for b_ase0_brst_tmr */
1114 del_timer_sync(&lnw
->hsm_timer
);
1116 langwell_otg_HAAR(0);
1117 iotg
->otg
.state
= OTG_STATE_B_HOST
;
1118 langwell_update_transceiver();
1119 } else if (iotg
->hsm
.a_bus_resume
||
1120 iotg
->hsm
.b_ase0_brst_tmout
) {
1121 /* delete hsm timer for b_ase0_brst_tmr */
1122 del_timer_sync(&lnw
->hsm_timer
);
1124 langwell_otg_HAAR(0);
1125 langwell_otg_nsf_msg(7);
1127 if (lnw
->iotg
.stop_host
)
1128 lnw
->iotg
.stop_host(&lnw
->iotg
);
1131 "host driver has been removed.\n");
1133 iotg
->hsm
.a_bus_suspend
= 0;
1134 iotg
->hsm
.b_bus_req
= 0;
1136 if (lnw
->iotg
.start_peripheral
)
1137 lnw
->iotg
.start_peripheral(&lnw
->iotg
);
1140 "client driver not loaded.\n");
1142 iotg
->otg
.state
= OTG_STATE_B_PERIPHERAL
;
1146 case OTG_STATE_B_HOST
:
1147 if (!iotg
->hsm
.id
) {
1148 iotg
->otg
.default_a
= 1;
1149 iotg
->hsm
.a_srp_det
= 0;
1151 langwell_otg_chrg_vbus(0);
1153 if (lnw
->iotg
.stop_host
)
1154 lnw
->iotg
.stop_host(&lnw
->iotg
);
1157 "host driver has been removed.\n");
1160 langwell_otg_phy_low_power(1);
1161 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
1162 langwell_update_transceiver();
1163 } else if (!iotg
->hsm
.b_sess_vld
) {
1164 iotg
->hsm
.b_hnp_enable
= 0;
1165 iotg
->hsm
.b_bus_req
= 0;
1167 langwell_otg_chrg_vbus(0);
1168 if (lnw
->iotg
.stop_host
)
1169 lnw
->iotg
.stop_host(&lnw
->iotg
);
1172 "host driver has been removed.\n");
1175 langwell_otg_phy_low_power(1);
1176 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1177 } else if ((!iotg
->hsm
.b_bus_req
) ||
1178 (!iotg
->hsm
.a_conn
)) {
1179 iotg
->hsm
.b_bus_req
= 0;
1180 langwell_otg_loc_sof(0);
1182 if (lnw
->iotg
.stop_host
)
1183 lnw
->iotg
.stop_host(&lnw
->iotg
);
1186 "host driver has been removed.\n");
1188 iotg
->hsm
.a_bus_suspend
= 0;
1190 if (lnw
->iotg
.start_peripheral
)
1191 lnw
->iotg
.start_peripheral(&lnw
->iotg
);
1194 "client driver not loaded.\n");
1196 iotg
->otg
.state
= OTG_STATE_B_PERIPHERAL
;
1200 case OTG_STATE_A_IDLE
:
1201 iotg
->otg
.default_a
= 1;
1203 iotg
->otg
.default_a
= 0;
1204 iotg
->hsm
.b_bus_req
= 0;
1205 iotg
->hsm
.vbus_srp_up
= 0;
1207 langwell_otg_chrg_vbus(0);
1209 langwell_otg_phy_low_power(1);
1210 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1211 langwell_update_transceiver();
1212 } else if (!iotg
->hsm
.a_bus_drop
&&
1213 (iotg
->hsm
.a_srp_det
|| iotg
->hsm
.a_bus_req
)) {
1214 langwell_otg_phy_low_power(0);
1217 iotg
->otg
.set_vbus(&iotg
->otg
, true);
1219 iotg
->hsm
.vbus_srp_up
= 0;
1220 iotg
->hsm
.a_wait_vrise_tmout
= 0;
1221 langwell_otg_add_timer(a_wait_vrise_tmr
);
1222 iotg
->otg
.state
= OTG_STATE_A_WAIT_VRISE
;
1223 langwell_update_transceiver();
1224 } else if (!iotg
->hsm
.a_bus_drop
&& iotg
->hsm
.a_sess_vld
) {
1225 iotg
->hsm
.vbus_srp_up
= 1;
1226 } else if (!iotg
->hsm
.a_sess_vld
&& iotg
->hsm
.vbus_srp_up
) {
1228 langwell_otg_phy_low_power(0);
1231 iotg
->otg
.set_vbus(&iotg
->otg
, true);
1232 iotg
->hsm
.a_srp_det
= 1;
1233 iotg
->hsm
.vbus_srp_up
= 0;
1234 iotg
->hsm
.a_wait_vrise_tmout
= 0;
1235 langwell_otg_add_timer(a_wait_vrise_tmr
);
1236 iotg
->otg
.state
= OTG_STATE_A_WAIT_VRISE
;
1237 langwell_update_transceiver();
1238 } else if (!iotg
->hsm
.a_sess_vld
&&
1239 !iotg
->hsm
.vbus_srp_up
) {
1240 langwell_otg_phy_low_power(1);
1243 case OTG_STATE_A_WAIT_VRISE
:
1245 langwell_otg_del_timer(a_wait_vrise_tmr
);
1246 iotg
->hsm
.b_bus_req
= 0;
1247 iotg
->otg
.default_a
= 0;
1250 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1252 langwell_otg_phy_low_power_wait(1);
1253 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1254 } else if (iotg
->hsm
.a_vbus_vld
) {
1255 langwell_otg_del_timer(a_wait_vrise_tmr
);
1256 iotg
->hsm
.b_conn
= 0;
1257 if (lnw
->iotg
.start_host
)
1258 lnw
->iotg
.start_host(&lnw
->iotg
);
1260 dev_dbg(lnw
->dev
, "host driver not loaded.\n");
1264 langwell_otg_add_ktimer(TA_WAIT_BCON_TMR
);
1265 iotg
->otg
.state
= OTG_STATE_A_WAIT_BCON
;
1266 } else if (iotg
->hsm
.a_wait_vrise_tmout
) {
1267 iotg
->hsm
.b_conn
= 0;
1268 if (iotg
->hsm
.a_vbus_vld
) {
1269 if (lnw
->iotg
.start_host
)
1270 lnw
->iotg
.start_host(&lnw
->iotg
);
1273 "host driver not loaded.\n");
1276 langwell_otg_add_ktimer(TA_WAIT_BCON_TMR
);
1277 iotg
->otg
.state
= OTG_STATE_A_WAIT_BCON
;
1281 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1282 langwell_otg_phy_low_power_wait(1);
1283 iotg
->otg
.state
= OTG_STATE_A_VBUS_ERR
;
1287 case OTG_STATE_A_WAIT_BCON
:
1289 /* delete hsm timer for a_wait_bcon_tmr */
1290 del_timer_sync(&lnw
->hsm_timer
);
1292 iotg
->otg
.default_a
= 0;
1293 iotg
->hsm
.b_bus_req
= 0;
1295 if (lnw
->iotg
.stop_host
)
1296 lnw
->iotg
.stop_host(&lnw
->iotg
);
1299 "host driver has been removed.\n");
1302 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1304 langwell_otg_phy_low_power_wait(1);
1305 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1306 langwell_update_transceiver();
1307 } else if (!iotg
->hsm
.a_vbus_vld
) {
1308 /* delete hsm timer for a_wait_bcon_tmr */
1309 del_timer_sync(&lnw
->hsm_timer
);
1311 if (lnw
->iotg
.stop_host
)
1312 lnw
->iotg
.stop_host(&lnw
->iotg
);
1315 "host driver has been removed.\n");
1318 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1319 langwell_otg_phy_low_power_wait(1);
1320 iotg
->otg
.state
= OTG_STATE_A_VBUS_ERR
;
1321 } else if (iotg
->hsm
.a_bus_drop
||
1322 (iotg
->hsm
.a_wait_bcon_tmout
&&
1323 !iotg
->hsm
.a_bus_req
)) {
1324 /* delete hsm timer for a_wait_bcon_tmr */
1325 del_timer_sync(&lnw
->hsm_timer
);
1327 if (lnw
->iotg
.stop_host
)
1328 lnw
->iotg
.stop_host(&lnw
->iotg
);
1331 "host driver has been removed.\n");
1334 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1335 iotg
->otg
.state
= OTG_STATE_A_WAIT_VFALL
;
1336 } else if (iotg
->hsm
.b_conn
) {
1337 /* delete hsm timer for a_wait_bcon_tmr */
1338 del_timer_sync(&lnw
->hsm_timer
);
1340 iotg
->hsm
.a_suspend_req
= 0;
1341 iotg
->otg
.state
= OTG_STATE_A_HOST
;
1342 if (iotg
->hsm
.a_srp_det
&& iotg
->otg
.host
&&
1343 !iotg
->otg
.host
->b_hnp_enable
) {
1344 /* SRP capable peripheral-only device */
1345 iotg
->hsm
.a_bus_req
= 1;
1346 iotg
->hsm
.a_srp_det
= 0;
1347 } else if (!iotg
->hsm
.a_bus_req
&& iotg
->otg
.host
&&
1348 iotg
->otg
.host
->b_hnp_enable
) {
1349 /* It is not safe enough to do a fast
1350 * transition from A_WAIT_BCON to
1353 if (iotg
->hsm
.a_bus_req
)
1356 if (request_irq(pdev
->irq
,
1357 otg_dummy_irq
, IRQF_SHARED
,
1358 driver_name
, iotg
->base
) != 0) {
1360 "request interrupt %d fail\n",
1364 langwell_otg_HABA(1);
1365 iotg
->hsm
.b_bus_resume
= 0;
1366 iotg
->hsm
.a_aidl_bdis_tmout
= 0;
1368 langwell_otg_loc_sof(0);
1369 /* clear PHCD to enable HW timer */
1370 langwell_otg_phy_low_power(0);
1371 langwell_otg_add_timer(a_aidl_bdis_tmr
);
1372 iotg
->otg
.state
= OTG_STATE_A_SUSPEND
;
1373 } else if (!iotg
->hsm
.a_bus_req
&& iotg
->otg
.host
&&
1374 !iotg
->otg
.host
->b_hnp_enable
) {
1375 if (lnw
->iotg
.stop_host
)
1376 lnw
->iotg
.stop_host(&lnw
->iotg
);
1379 "host driver removed.\n");
1382 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1383 iotg
->otg
.state
= OTG_STATE_A_WAIT_VFALL
;
1387 case OTG_STATE_A_HOST
:
1389 iotg
->otg
.default_a
= 0;
1390 iotg
->hsm
.b_bus_req
= 0;
1392 if (lnw
->iotg
.stop_host
)
1393 lnw
->iotg
.stop_host(&lnw
->iotg
);
1396 "host driver has been removed.\n");
1399 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1401 langwell_otg_phy_low_power_wait(1);
1402 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1403 langwell_update_transceiver();
1404 } else if (iotg
->hsm
.a_bus_drop
||
1406 !iotg
->otg
.host
->b_hnp_enable
&&
1407 !iotg
->hsm
.a_bus_req
)) {
1408 if (lnw
->iotg
.stop_host
)
1409 lnw
->iotg
.stop_host(&lnw
->iotg
);
1412 "host driver has been removed.\n");
1415 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1416 iotg
->otg
.state
= OTG_STATE_A_WAIT_VFALL
;
1417 } else if (!iotg
->hsm
.a_vbus_vld
) {
1418 if (lnw
->iotg
.stop_host
)
1419 lnw
->iotg
.stop_host(&lnw
->iotg
);
1422 "host driver has been removed.\n");
1425 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1426 langwell_otg_phy_low_power_wait(1);
1427 iotg
->otg
.state
= OTG_STATE_A_VBUS_ERR
;
1428 } else if (iotg
->otg
.host
&&
1429 iotg
->otg
.host
->b_hnp_enable
&&
1430 !iotg
->hsm
.a_bus_req
) {
1431 /* Set HABA to enable hardware assistance to signal
1432 * A-connect after receiver B-disconnect. Hardware
1433 * will then set client mode and enable URE, SLE and
1434 * PCE after the assistance. otg_dummy_irq is used to
1435 * clean these ints when client driver is not resumed.
1437 if (request_irq(pdev
->irq
, otg_dummy_irq
, IRQF_SHARED
,
1438 driver_name
, iotg
->base
) != 0) {
1440 "request interrupt %d failed\n",
1445 langwell_otg_HABA(1);
1446 iotg
->hsm
.b_bus_resume
= 0;
1447 iotg
->hsm
.a_aidl_bdis_tmout
= 0;
1448 langwell_otg_loc_sof(0);
1449 /* clear PHCD to enable HW timer */
1450 langwell_otg_phy_low_power(0);
1451 langwell_otg_add_timer(a_aidl_bdis_tmr
);
1452 iotg
->otg
.state
= OTG_STATE_A_SUSPEND
;
1453 } else if (!iotg
->hsm
.b_conn
|| !iotg
->hsm
.a_bus_req
) {
1454 langwell_otg_add_ktimer(TA_WAIT_BCON_TMR
);
1455 iotg
->otg
.state
= OTG_STATE_A_WAIT_BCON
;
1458 case OTG_STATE_A_SUSPEND
:
1460 langwell_otg_del_timer(a_aidl_bdis_tmr
);
1461 langwell_otg_HABA(0);
1462 free_irq(pdev
->irq
, iotg
->base
);
1463 iotg
->otg
.default_a
= 0;
1464 iotg
->hsm
.b_bus_req
= 0;
1466 if (lnw
->iotg
.stop_host
)
1467 lnw
->iotg
.stop_host(&lnw
->iotg
);
1470 "host driver has been removed.\n");
1473 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1475 langwell_otg_phy_low_power(1);
1476 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1477 langwell_update_transceiver();
1478 } else if (iotg
->hsm
.a_bus_req
||
1479 iotg
->hsm
.b_bus_resume
) {
1480 langwell_otg_del_timer(a_aidl_bdis_tmr
);
1481 langwell_otg_HABA(0);
1482 free_irq(pdev
->irq
, iotg
->base
);
1483 iotg
->hsm
.a_suspend_req
= 0;
1484 langwell_otg_loc_sof(1);
1485 iotg
->otg
.state
= OTG_STATE_A_HOST
;
1486 } else if (iotg
->hsm
.a_aidl_bdis_tmout
||
1487 iotg
->hsm
.a_bus_drop
) {
1488 langwell_otg_del_timer(a_aidl_bdis_tmr
);
1489 langwell_otg_HABA(0);
1490 free_irq(pdev
->irq
, iotg
->base
);
1491 if (lnw
->iotg
.stop_host
)
1492 lnw
->iotg
.stop_host(&lnw
->iotg
);
1495 "host driver has been removed.\n");
1498 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1499 iotg
->otg
.state
= OTG_STATE_A_WAIT_VFALL
;
1500 } else if (!iotg
->hsm
.b_conn
&& iotg
->otg
.host
&&
1501 iotg
->otg
.host
->b_hnp_enable
) {
1502 langwell_otg_del_timer(a_aidl_bdis_tmr
);
1503 langwell_otg_HABA(0);
1504 free_irq(pdev
->irq
, iotg
->base
);
1506 if (lnw
->iotg
.stop_host
)
1507 lnw
->iotg
.stop_host(&lnw
->iotg
);
1510 "host driver has been removed.\n");
1512 iotg
->hsm
.b_bus_suspend
= 0;
1513 iotg
->hsm
.b_bus_suspend_vld
= 0;
1516 if (lnw
->iotg
.start_peripheral
)
1517 lnw
->iotg
.start_peripheral(&lnw
->iotg
);
1520 "client driver not loaded.\n");
1522 langwell_otg_add_ktimer(TB_BUS_SUSPEND_TMR
);
1523 iotg
->otg
.state
= OTG_STATE_A_PERIPHERAL
;
1525 } else if (!iotg
->hsm
.a_vbus_vld
) {
1526 langwell_otg_del_timer(a_aidl_bdis_tmr
);
1527 langwell_otg_HABA(0);
1528 free_irq(pdev
->irq
, iotg
->base
);
1529 if (lnw
->iotg
.stop_host
)
1530 lnw
->iotg
.stop_host(&lnw
->iotg
);
1533 "host driver has been removed.\n");
1536 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1537 langwell_otg_phy_low_power_wait(1);
1538 iotg
->otg
.state
= OTG_STATE_A_VBUS_ERR
;
1541 case OTG_STATE_A_PERIPHERAL
:
1543 /* delete hsm timer for b_bus_suspend_tmr */
1544 del_timer_sync(&lnw
->hsm_timer
);
1545 iotg
->otg
.default_a
= 0;
1546 iotg
->hsm
.b_bus_req
= 0;
1547 if (lnw
->iotg
.stop_peripheral
)
1548 lnw
->iotg
.stop_peripheral(&lnw
->iotg
);
1551 "client driver has been removed.\n");
1554 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1556 langwell_otg_phy_low_power_wait(1);
1557 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1558 langwell_update_transceiver();
1559 } else if (!iotg
->hsm
.a_vbus_vld
) {
1560 /* delete hsm timer for b_bus_suspend_tmr */
1561 del_timer_sync(&lnw
->hsm_timer
);
1563 if (lnw
->iotg
.stop_peripheral
)
1564 lnw
->iotg
.stop_peripheral(&lnw
->iotg
);
1567 "client driver has been removed.\n");
1570 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1571 langwell_otg_phy_low_power_wait(1);
1572 iotg
->otg
.state
= OTG_STATE_A_VBUS_ERR
;
1573 } else if (iotg
->hsm
.a_bus_drop
) {
1574 /* delete hsm timer for b_bus_suspend_tmr */
1575 del_timer_sync(&lnw
->hsm_timer
);
1577 if (lnw
->iotg
.stop_peripheral
)
1578 lnw
->iotg
.stop_peripheral(&lnw
->iotg
);
1581 "client driver has been removed.\n");
1584 iotg
->otg
.set_vbus(&iotg
->otg
, false);
1585 iotg
->otg
.state
= OTG_STATE_A_WAIT_VFALL
;
1586 } else if (iotg
->hsm
.b_bus_suspend
) {
1587 /* delete hsm timer for b_bus_suspend_tmr */
1588 del_timer_sync(&lnw
->hsm_timer
);
1590 if (lnw
->iotg
.stop_peripheral
)
1591 lnw
->iotg
.stop_peripheral(&lnw
->iotg
);
1594 "client driver has been removed.\n");
1596 if (lnw
->iotg
.start_host
)
1597 lnw
->iotg
.start_host(&lnw
->iotg
);
1600 "host driver not loaded.\n");
1601 langwell_otg_add_ktimer(TA_WAIT_BCON_TMR
);
1602 iotg
->otg
.state
= OTG_STATE_A_WAIT_BCON
;
1603 } else if (iotg
->hsm
.b_bus_suspend_tmout
) {
1605 val
= readl(lnw
->iotg
.base
+ CI_PORTSC1
);
1606 if (!(val
& PORTSC_SUSP
))
1609 if (lnw
->iotg
.stop_peripheral
)
1610 lnw
->iotg
.stop_peripheral(&lnw
->iotg
);
1613 "client driver has been removed.\n");
1615 if (lnw
->iotg
.start_host
)
1616 lnw
->iotg
.start_host(&lnw
->iotg
);
1619 "host driver not loaded.\n");
1620 langwell_otg_add_ktimer(TA_WAIT_BCON_TMR
);
1621 iotg
->otg
.state
= OTG_STATE_A_WAIT_BCON
;
1624 case OTG_STATE_A_VBUS_ERR
:
1626 iotg
->otg
.default_a
= 0;
1627 iotg
->hsm
.a_clr_err
= 0;
1628 iotg
->hsm
.a_srp_det
= 0;
1630 langwell_otg_phy_low_power(1);
1631 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1632 langwell_update_transceiver();
1633 } else if (iotg
->hsm
.a_clr_err
) {
1634 iotg
->hsm
.a_clr_err
= 0;
1635 iotg
->hsm
.a_srp_det
= 0;
1638 if (iotg
->otg
.state
== OTG_STATE_A_IDLE
)
1639 langwell_update_transceiver();
1641 /* FW will clear PHCD bit when any VBus
1642 * event detected. Reset PHCD to 1 again */
1643 langwell_otg_phy_low_power(1);
1646 case OTG_STATE_A_WAIT_VFALL
:
1648 iotg
->otg
.default_a
= 0;
1650 langwell_otg_phy_low_power(1);
1651 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
1652 langwell_update_transceiver();
1653 } else if (iotg
->hsm
.a_bus_req
) {
1656 iotg
->otg
.set_vbus(&iotg
->otg
, true);
1657 iotg
->hsm
.a_wait_vrise_tmout
= 0;
1658 langwell_otg_add_timer(a_wait_vrise_tmr
);
1659 iotg
->otg
.state
= OTG_STATE_A_WAIT_VRISE
;
1660 } else if (!iotg
->hsm
.a_sess_vld
) {
1661 iotg
->hsm
.a_srp_det
= 0;
1663 langwell_otg_phy_low_power(1);
1664 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
1671 dev_dbg(lnw
->dev
, "%s: new state = %s\n", __func__
,
1672 otg_state_string(iotg
->otg
.state
));
1676 show_registers(struct device
*_dev
, struct device_attribute
*attr
, char *buf
)
1678 struct langwell_otg
*lnw
= the_transceiver
;
1685 t
= scnprintf(next
, size
,
1689 "USBINTR = 0x%08x\n"
1690 "ASYNCLISTADDR = 0x%08x\n"
1691 "PORTSC1 = 0x%08x\n"
1692 "HOSTPC1 = 0x%08x\n"
1694 "USBMODE = 0x%08x\n",
1695 readl(lnw
->iotg
.base
+ 0x30),
1696 readl(lnw
->iotg
.base
+ 0x34),
1697 readl(lnw
->iotg
.base
+ 0x38),
1698 readl(lnw
->iotg
.base
+ 0x48),
1699 readl(lnw
->iotg
.base
+ 0x74),
1700 readl(lnw
->iotg
.base
+ 0xb4),
1701 readl(lnw
->iotg
.base
+ 0xf4),
1702 readl(lnw
->iotg
.base
+ 0xf8)
1707 return PAGE_SIZE
- size
;
1709 static DEVICE_ATTR(registers
, S_IRUGO
, show_registers
, NULL
);
1712 show_hsm(struct device
*_dev
, struct device_attribute
*attr
, char *buf
)
1714 struct langwell_otg
*lnw
= the_transceiver
;
1715 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
1723 iotg
->hsm
.a_set_b_hnp_en
= iotg
->otg
.host
->b_hnp_enable
;
1725 if (iotg
->otg
.gadget
)
1726 iotg
->hsm
.b_hnp_enable
= iotg
->otg
.gadget
->b_hnp_enable
;
1728 t
= scnprintf(next
, size
,
1730 "current state = %s\n"
1731 "a_bus_resume = \t%d\n"
1732 "a_bus_suspend = \t%d\n"
1734 "a_sess_vld = \t%d\n"
1735 "a_srp_det = \t%d\n"
1736 "a_vbus_vld = \t%d\n"
1737 "b_bus_resume = \t%d\n"
1738 "b_bus_suspend = \t%d\n"
1740 "b_se0_srp = \t%d\n"
1741 "b_sess_end = \t%d\n"
1742 "b_sess_vld = \t%d\n"
1744 "a_set_b_hnp_en = \t%d\n"
1745 "b_srp_done = \t%d\n"
1746 "b_hnp_enable = \t%d\n"
1747 "a_wait_vrise_tmout = \t%d\n"
1748 "a_wait_bcon_tmout = \t%d\n"
1749 "a_aidl_bdis_tmout = \t%d\n"
1750 "b_ase0_brst_tmout = \t%d\n"
1751 "a_bus_drop = \t%d\n"
1752 "a_bus_req = \t%d\n"
1753 "a_clr_err = \t%d\n"
1754 "a_suspend_req = \t%d\n"
1755 "b_bus_req = \t%d\n"
1756 "b_bus_suspend_tmout = \t%d\n"
1757 "b_bus_suspend_vld = \t%d\n",
1758 otg_state_string(iotg
->otg
.state
),
1759 iotg
->hsm
.a_bus_resume
,
1760 iotg
->hsm
.a_bus_suspend
,
1762 iotg
->hsm
.a_sess_vld
,
1763 iotg
->hsm
.a_srp_det
,
1764 iotg
->hsm
.a_vbus_vld
,
1765 iotg
->hsm
.b_bus_resume
,
1766 iotg
->hsm
.b_bus_suspend
,
1768 iotg
->hsm
.b_se0_srp
,
1769 iotg
->hsm
.b_sess_end
,
1770 iotg
->hsm
.b_sess_vld
,
1772 iotg
->hsm
.a_set_b_hnp_en
,
1773 iotg
->hsm
.b_srp_done
,
1774 iotg
->hsm
.b_hnp_enable
,
1775 iotg
->hsm
.a_wait_vrise_tmout
,
1776 iotg
->hsm
.a_wait_bcon_tmout
,
1777 iotg
->hsm
.a_aidl_bdis_tmout
,
1778 iotg
->hsm
.b_ase0_brst_tmout
,
1779 iotg
->hsm
.a_bus_drop
,
1780 iotg
->hsm
.a_bus_req
,
1781 iotg
->hsm
.a_clr_err
,
1782 iotg
->hsm
.a_suspend_req
,
1783 iotg
->hsm
.b_bus_req
,
1784 iotg
->hsm
.b_bus_suspend_tmout
,
1785 iotg
->hsm
.b_bus_suspend_vld
1790 return PAGE_SIZE
- size
;
1792 static DEVICE_ATTR(hsm
, S_IRUGO
, show_hsm
, NULL
);
1795 get_a_bus_req(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1797 struct langwell_otg
*lnw
= the_transceiver
;
1804 t
= scnprintf(next
, size
, "%d", lnw
->iotg
.hsm
.a_bus_req
);
1808 return PAGE_SIZE
- size
;
1812 set_a_bus_req(struct device
*dev
, struct device_attribute
*attr
,
1813 const char *buf
, size_t count
)
1815 struct langwell_otg
*lnw
= the_transceiver
;
1816 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
1818 if (!iotg
->otg
.default_a
)
1823 if (buf
[0] == '0') {
1824 iotg
->hsm
.a_bus_req
= 0;
1825 dev_dbg(lnw
->dev
, "User request: a_bus_req = 0\n");
1826 } else if (buf
[0] == '1') {
1827 /* If a_bus_drop is TRUE, a_bus_req can't be set */
1828 if (iotg
->hsm
.a_bus_drop
)
1830 iotg
->hsm
.a_bus_req
= 1;
1831 dev_dbg(lnw
->dev
, "User request: a_bus_req = 1\n");
1833 if (spin_trylock(&lnw
->wq_lock
)) {
1834 langwell_update_transceiver();
1835 spin_unlock(&lnw
->wq_lock
);
1839 static DEVICE_ATTR(a_bus_req
, S_IRUGO
| S_IWUSR
, get_a_bus_req
, set_a_bus_req
);
1842 get_a_bus_drop(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1844 struct langwell_otg
*lnw
= the_transceiver
;
1851 t
= scnprintf(next
, size
, "%d", lnw
->iotg
.hsm
.a_bus_drop
);
1855 return PAGE_SIZE
- size
;
1859 set_a_bus_drop(struct device
*dev
, struct device_attribute
*attr
,
1860 const char *buf
, size_t count
)
1862 struct langwell_otg
*lnw
= the_transceiver
;
1863 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
1865 if (!iotg
->otg
.default_a
)
1870 if (buf
[0] == '0') {
1871 iotg
->hsm
.a_bus_drop
= 0;
1872 dev_dbg(lnw
->dev
, "User request: a_bus_drop = 0\n");
1873 } else if (buf
[0] == '1') {
1874 iotg
->hsm
.a_bus_drop
= 1;
1875 iotg
->hsm
.a_bus_req
= 0;
1876 dev_dbg(lnw
->dev
, "User request: a_bus_drop = 1\n");
1877 dev_dbg(lnw
->dev
, "User request: and a_bus_req = 0\n");
1879 if (spin_trylock(&lnw
->wq_lock
)) {
1880 langwell_update_transceiver();
1881 spin_unlock(&lnw
->wq_lock
);
1885 static DEVICE_ATTR(a_bus_drop
, S_IRUGO
| S_IWUSR
, get_a_bus_drop
, set_a_bus_drop
);
1888 get_b_bus_req(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1890 struct langwell_otg
*lnw
= the_transceiver
;
1897 t
= scnprintf(next
, size
, "%d", lnw
->iotg
.hsm
.b_bus_req
);
1901 return PAGE_SIZE
- size
;
1905 set_b_bus_req(struct device
*dev
, struct device_attribute
*attr
,
1906 const char *buf
, size_t count
)
1908 struct langwell_otg
*lnw
= the_transceiver
;
1909 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
1911 if (iotg
->otg
.default_a
)
1917 if (buf
[0] == '0') {
1918 iotg
->hsm
.b_bus_req
= 0;
1919 dev_dbg(lnw
->dev
, "User request: b_bus_req = 0\n");
1920 } else if (buf
[0] == '1') {
1921 iotg
->hsm
.b_bus_req
= 1;
1922 dev_dbg(lnw
->dev
, "User request: b_bus_req = 1\n");
1924 if (spin_trylock(&lnw
->wq_lock
)) {
1925 langwell_update_transceiver();
1926 spin_unlock(&lnw
->wq_lock
);
1930 static DEVICE_ATTR(b_bus_req
, S_IRUGO
| S_IWUSR
, get_b_bus_req
, set_b_bus_req
);
1933 set_a_clr_err(struct device
*dev
, struct device_attribute
*attr
,
1934 const char *buf
, size_t count
)
1936 struct langwell_otg
*lnw
= the_transceiver
;
1937 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
1939 if (!iotg
->otg
.default_a
)
1944 if (buf
[0] == '1') {
1945 iotg
->hsm
.a_clr_err
= 1;
1946 dev_dbg(lnw
->dev
, "User request: a_clr_err = 1\n");
1948 if (spin_trylock(&lnw
->wq_lock
)) {
1949 langwell_update_transceiver();
1950 spin_unlock(&lnw
->wq_lock
);
1954 static DEVICE_ATTR(a_clr_err
, S_IWUSR
, NULL
, set_a_clr_err
);
1956 static struct attribute
*inputs_attrs
[] = {
1957 &dev_attr_a_bus_req
.attr
,
1958 &dev_attr_a_bus_drop
.attr
,
1959 &dev_attr_b_bus_req
.attr
,
1960 &dev_attr_a_clr_err
.attr
,
1964 static struct attribute_group debug_dev_attr_group
= {
1966 .attrs
= inputs_attrs
,
1969 static int langwell_otg_probe(struct pci_dev
*pdev
,
1970 const struct pci_device_id
*id
)
1972 unsigned long resource
, len
;
1973 void __iomem
*base
= NULL
;
1976 struct langwell_otg
*lnw
;
1977 char qname
[] = "langwell_otg_queue";
1980 dev_dbg(&pdev
->dev
, "\notg controller is detected.\n");
1981 if (pci_enable_device(pdev
) < 0) {
1986 lnw
= kzalloc(sizeof *lnw
, GFP_KERNEL
);
1991 the_transceiver
= lnw
;
1993 /* control register: BAR 0 */
1994 resource
= pci_resource_start(pdev
, 0);
1995 len
= pci_resource_len(pdev
, 0);
1996 if (!request_mem_region(resource
, len
, driver_name
)) {
2002 base
= ioremap_nocache(resource
, len
);
2007 lnw
->iotg
.base
= base
;
2009 if (!request_mem_region(USBCFG_ADDR
, USBCFG_LEN
, driver_name
)) {
2013 lnw
->cfg_region
= 1;
2015 /* For the SCCB.USBCFG register */
2016 base
= ioremap_nocache(USBCFG_ADDR
, USBCFG_LEN
);
2024 dev_dbg(&pdev
->dev
, "No IRQ.\n");
2029 lnw
->qwork
= create_singlethread_workqueue(qname
);
2031 dev_dbg(&pdev
->dev
, "cannot create workqueue %s\n", qname
);
2035 INIT_WORK(&lnw
->work
, langwell_otg_work
);
2037 /* OTG common part */
2038 lnw
->dev
= &pdev
->dev
;
2039 lnw
->iotg
.otg
.dev
= lnw
->dev
;
2040 lnw
->iotg
.otg
.label
= driver_name
;
2041 lnw
->iotg
.otg
.set_host
= langwell_otg_set_host
;
2042 lnw
->iotg
.otg
.set_peripheral
= langwell_otg_set_peripheral
;
2043 lnw
->iotg
.otg
.set_power
= langwell_otg_set_power
;
2044 lnw
->iotg
.otg
.set_vbus
= langwell_otg_set_vbus
;
2045 lnw
->iotg
.otg
.start_srp
= langwell_otg_start_srp
;
2046 lnw
->iotg
.otg
.state
= OTG_STATE_UNDEFINED
;
2048 if (otg_set_transceiver(&lnw
->iotg
.otg
)) {
2049 dev_dbg(lnw
->dev
, "can't set transceiver\n");
2057 spin_lock_init(&lnw
->lock
);
2058 spin_lock_init(&lnw
->wq_lock
);
2059 INIT_LIST_HEAD(&active_timers
);
2060 retval
= langwell_otg_init_timers(&lnw
->iotg
.hsm
);
2062 dev_dbg(&pdev
->dev
, "Failed to init timers\n");
2066 init_timer(&lnw
->hsm_timer
);
2067 ATOMIC_INIT_NOTIFIER_HEAD(&lnw
->iotg
.iotg_notifier
);
2069 lnw
->iotg_notifier
.notifier_call
= langwell_otg_iotg_notify
;
2071 retval
= intel_mid_otg_register_notifier(&lnw
->iotg
,
2072 &lnw
->iotg_notifier
);
2074 dev_dbg(lnw
->dev
, "Failed to register notifier\n");
2078 if (request_irq(pdev
->irq
, otg_irq
, IRQF_SHARED
,
2079 driver_name
, lnw
) != 0) {
2080 dev_dbg(lnw
->dev
, "request interrupt %d failed\n", pdev
->irq
);
2085 /* enable OTGSC int */
2086 val32
= OTGSC_DPIE
| OTGSC_BSEIE
| OTGSC_BSVIE
|
2087 OTGSC_ASVIE
| OTGSC_AVVIE
| OTGSC_IDIE
| OTGSC_IDPU
;
2088 writel(val32
, lnw
->iotg
.base
+ CI_OTGSC
);
2090 retval
= device_create_file(&pdev
->dev
, &dev_attr_registers
);
2093 "Can't register sysfs attribute: %d\n", retval
);
2097 retval
= device_create_file(&pdev
->dev
, &dev_attr_hsm
);
2099 dev_dbg(lnw
->dev
, "Can't hsm sysfs attribute: %d\n", retval
);
2103 retval
= sysfs_create_group(&pdev
->dev
.kobj
, &debug_dev_attr_group
);
2106 "Can't register sysfs attr group: %d\n", retval
);
2110 if (lnw
->iotg
.otg
.state
== OTG_STATE_A_IDLE
)
2111 langwell_update_transceiver();
2116 if (the_transceiver
)
2117 langwell_otg_remove(pdev
);
2122 static void langwell_otg_remove(struct pci_dev
*pdev
)
2124 struct langwell_otg
*lnw
= the_transceiver
;
2127 flush_workqueue(lnw
->qwork
);
2128 destroy_workqueue(lnw
->qwork
);
2130 intel_mid_otg_unregister_notifier(&lnw
->iotg
, &lnw
->iotg_notifier
);
2131 langwell_otg_free_timers();
2133 /* disable OTGSC interrupt as OTGSC doesn't change in reset */
2134 writel(0, lnw
->iotg
.base
+ CI_OTGSC
);
2137 free_irq(pdev
->irq
, lnw
);
2139 iounmap(lnw
->usbcfg
);
2140 if (lnw
->cfg_region
)
2141 release_mem_region(USBCFG_ADDR
, USBCFG_LEN
);
2143 iounmap(lnw
->iotg
.base
);
2145 release_mem_region(pci_resource_start(pdev
, 0),
2146 pci_resource_len(pdev
, 0));
2148 otg_set_transceiver(NULL
);
2149 pci_disable_device(pdev
);
2150 sysfs_remove_group(&pdev
->dev
.kobj
, &debug_dev_attr_group
);
2151 device_remove_file(&pdev
->dev
, &dev_attr_hsm
);
2152 device_remove_file(&pdev
->dev
, &dev_attr_registers
);
2157 static void transceiver_suspend(struct pci_dev
*pdev
)
2159 pci_save_state(pdev
);
2160 pci_set_power_state(pdev
, PCI_D3hot
);
2161 langwell_otg_phy_low_power(1);
2164 static int langwell_otg_suspend(struct pci_dev
*pdev
, pm_message_t message
)
2166 struct langwell_otg
*lnw
= the_transceiver
;
2167 struct intel_mid_otg_xceiv
*iotg
= &lnw
->iotg
;
2170 /* Disbale OTG interrupts */
2171 langwell_otg_intr(0);
2174 free_irq(pdev
->irq
, lnw
);
2176 /* Prevent more otg_work */
2177 flush_workqueue(lnw
->qwork
);
2178 destroy_workqueue(lnw
->qwork
);
2182 switch (iotg
->otg
.state
) {
2183 case OTG_STATE_A_WAIT_VFALL
:
2184 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
2185 case OTG_STATE_A_IDLE
:
2186 case OTG_STATE_B_IDLE
:
2187 case OTG_STATE_A_VBUS_ERR
:
2188 transceiver_suspend(pdev
);
2190 case OTG_STATE_A_WAIT_VRISE
:
2191 langwell_otg_del_timer(a_wait_vrise_tmr
);
2192 iotg
->hsm
.a_srp_det
= 0;
2195 iotg
->otg
.set_vbus(&iotg
->otg
, false);
2196 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
2197 transceiver_suspend(pdev
);
2199 case OTG_STATE_A_WAIT_BCON
:
2200 del_timer_sync(&lnw
->hsm_timer
);
2201 if (lnw
->iotg
.stop_host
)
2202 lnw
->iotg
.stop_host(&lnw
->iotg
);
2204 dev_dbg(&pdev
->dev
, "host driver has been removed.\n");
2206 iotg
->hsm
.a_srp_det
= 0;
2209 iotg
->otg
.set_vbus(&iotg
->otg
, false);
2210 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
2211 transceiver_suspend(pdev
);
2213 case OTG_STATE_A_HOST
:
2214 if (lnw
->iotg
.stop_host
)
2215 lnw
->iotg
.stop_host(&lnw
->iotg
);
2217 dev_dbg(&pdev
->dev
, "host driver has been removed.\n");
2219 iotg
->hsm
.a_srp_det
= 0;
2222 iotg
->otg
.set_vbus(&iotg
->otg
, false);
2224 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
2225 transceiver_suspend(pdev
);
2227 case OTG_STATE_A_SUSPEND
:
2228 langwell_otg_del_timer(a_aidl_bdis_tmr
);
2229 langwell_otg_HABA(0);
2230 if (lnw
->iotg
.stop_host
)
2231 lnw
->iotg
.stop_host(&lnw
->iotg
);
2233 dev_dbg(lnw
->dev
, "host driver has been removed.\n");
2234 iotg
->hsm
.a_srp_det
= 0;
2237 iotg
->otg
.set_vbus(&iotg
->otg
, false);
2238 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
2239 transceiver_suspend(pdev
);
2241 case OTG_STATE_A_PERIPHERAL
:
2242 del_timer_sync(&lnw
->hsm_timer
);
2244 if (lnw
->iotg
.stop_peripheral
)
2245 lnw
->iotg
.stop_peripheral(&lnw
->iotg
);
2248 "client driver has been removed.\n");
2249 iotg
->hsm
.a_srp_det
= 0;
2252 iotg
->otg
.set_vbus(&iotg
->otg
, false);
2253 iotg
->otg
.state
= OTG_STATE_A_IDLE
;
2254 transceiver_suspend(pdev
);
2256 case OTG_STATE_B_HOST
:
2257 if (lnw
->iotg
.stop_host
)
2258 lnw
->iotg
.stop_host(&lnw
->iotg
);
2260 dev_dbg(&pdev
->dev
, "host driver has been removed.\n");
2261 iotg
->hsm
.b_bus_req
= 0;
2262 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
2263 transceiver_suspend(pdev
);
2265 case OTG_STATE_B_PERIPHERAL
:
2266 if (lnw
->iotg
.stop_peripheral
)
2267 lnw
->iotg
.stop_peripheral(&lnw
->iotg
);
2270 "client driver has been removed.\n");
2271 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
2272 transceiver_suspend(pdev
);
2274 case OTG_STATE_B_WAIT_ACON
:
2275 /* delete hsm timer for b_ase0_brst_tmr */
2276 del_timer_sync(&lnw
->hsm_timer
);
2278 langwell_otg_HAAR(0);
2280 if (lnw
->iotg
.stop_host
)
2281 lnw
->iotg
.stop_host(&lnw
->iotg
);
2283 dev_dbg(&pdev
->dev
, "host driver has been removed.\n");
2284 iotg
->hsm
.b_bus_req
= 0;
2285 iotg
->otg
.state
= OTG_STATE_B_IDLE
;
2286 transceiver_suspend(pdev
);
2289 dev_dbg(lnw
->dev
, "error state before suspend\n");
2296 static void transceiver_resume(struct pci_dev
*pdev
)
2298 pci_restore_state(pdev
);
2299 pci_set_power_state(pdev
, PCI_D0
);
2302 static int langwell_otg_resume(struct pci_dev
*pdev
)
2304 struct langwell_otg
*lnw
= the_transceiver
;
2307 transceiver_resume(pdev
);
2309 lnw
->qwork
= create_singlethread_workqueue("langwell_otg_queue");
2311 dev_dbg(&pdev
->dev
, "cannot create langwell otg workqueuen");
2316 if (request_irq(pdev
->irq
, otg_irq
, IRQF_SHARED
,
2317 driver_name
, lnw
) != 0) {
2318 dev_dbg(&pdev
->dev
, "request interrupt %d failed\n", pdev
->irq
);
2323 /* enable OTG interrupts */
2324 langwell_otg_intr(1);
2328 langwell_update_transceiver();
2332 langwell_otg_intr(0);
2333 transceiver_suspend(pdev
);
2337 static int __init
langwell_otg_init(void)
2339 return pci_register_driver(&otg_pci_driver
);
2341 module_init(langwell_otg_init
);
2343 static void __exit
langwell_otg_cleanup(void)
2345 pci_unregister_driver(&otg_pci_driver
);
2347 module_exit(langwell_otg_cleanup
);