24 #include <linux/module.h>
25 #include <linux/kernel.h>
27 #include <linux/slab.h>
29 #include <linux/errno.h>
35 #include <linux/device.h>
36 #include <linux/usb/ch9.h>
39 #include <linux/time.h>
44 #include <asm/unaligned.h>
48 #define DRIVER_VERSION "Rev. 1.55"
49 #define DRIVER_AUTHOR "Jerry Huang/Li Yang"
50 #define DRIVER_DESC "Freescale USB OTG Transceiver Driver"
51 #define DRIVER_INFO DRIVER_DESC " " DRIVER_VERSION
62 static struct fsl_otg *fsl_otg_dev;
63 static int srp_wait_done;
100 static u32 (*_fsl_readl)(
const unsigned __iomem *
p);
103 #define fsl_readl(p) (*_fsl_readl)((p))
104 #define fsl_writel(v, p) (*_fsl_writel)((v), (p))
107 #define fsl_readl(addr) readl(addr)
108 #define fsl_writel(val, addr) writel(val, addr)
116 temp = 0x40000000 | (addr << 16);
128 temp = 0x60000000 | (addr << 16) | data;
279 fsl_otg_dev->
fsm.b_sess_vld)
280 fsl_otg_dev->
fsm.b_srp_done = 1;
290 VDBG(
"a_wait_enum timeout\n");
291 if (!fsl_otg_dev->
phy.otg->host->b_hnp_enable)
300 *(
int *)indicator = 1;
309 if (!a_wait_vrise_tmr)
314 if (!a_wait_bcon_tmr)
319 if (!a_aidl_bdis_tmr)
324 if (!b_ase0_brst_tmr)
338 (
unsigned long)&fsm);
339 if (!a_wait_enum_tmr)
349 if (!b_data_pulse_tmr)
354 if (!b_vbus_pulse_tmr)
364 if (a_wait_vrise_tmr !=
NULL)
365 kfree(a_wait_vrise_tmr);
366 if (a_wait_bcon_tmr !=
NULL)
367 kfree(a_wait_bcon_tmr);
368 if (a_aidl_bdis_tmr !=
NULL)
369 kfree(a_aidl_bdis_tmr);
370 if (b_ase0_brst_tmr !=
NULL)
371 kfree(b_ase0_brst_tmr);
372 if (b_se0_srp_tmr !=
NULL)
373 kfree(b_se0_srp_tmr);
374 if (b_srp_fail_tmr !=
NULL)
375 kfree(b_srp_fail_tmr);
376 if (a_wait_enum_tmr !=
NULL)
377 kfree(a_wait_enum_tmr);
380 if (b_srp_wait_tmr !=
NULL)
381 kfree(b_srp_wait_tmr);
382 if (b_data_pulse_tmr !=
NULL)
383 kfree(b_data_pulse_tmr);
384 if (b_vbus_pulse_tmr !=
NULL)
385 kfree(b_vbus_pulse_tmr);
399 if (tmp_timer == timer) {
414 if (tmp_timer == timer)
430 if (!tmp_timer->
count) {
462 dev = otg->
host->controller;
476 VDBG(
"host on......\n");
478 retval = dev->
driver->pm->resume(dev);
500 VDBG(
"host off......\n");
503 retval = dev->
driver->pm->suspend(dev);
527 VDBG(
"gadget %s\n", on ?
"on" :
"off");
528 dev = otg->
gadget->dev.parent;
535 dev->
driver->suspend(dev, otg_suspend_state);
545 static int fsl_otg_set_host(
struct usb_otg *otg,
struct usb_bus *
host)
553 if (otg_dev != fsl_otg_dev)
558 otg_dev->
fsm.a_bus_drop = 0;
559 otg_dev->
fsm.a_bus_req = 1;
562 VDBG(
"host off......\n");
565 otg->
host->is_b_host = otg_dev->
fsm.id;
594 static int fsl_otg_set_peripheral(
struct usb_otg *otg,
603 VDBG(
"otg_dev 0x%x\n", (
int)otg_dev);
604 VDBG(
"fsl_otg_dev 0x%x\n", (
int)fsl_otg_dev);
605 if (otg_dev != fsl_otg_dev)
611 usb_gadget_vbus_disconnect(otg->
gadget);
613 otg_dev->
fsm.b_bus_req = 0;
619 otg->
gadget->is_a_peripheral = !otg_dev->
fsm.id;
621 otg_dev->
fsm.b_bus_req = 1;
624 DBG(
"ID pin=%d\n", otg_dev->
fsm.id);
625 if (otg_dev->
fsm.id == 1) {
627 otg_drv_vbus(&otg_dev->
fsm, 0);
635 static int fsl_otg_set_power(
struct usb_phy *
phy,
unsigned mA)
640 pr_info(
"FSL OTG: Draw %d mA\n", mA);
662 otg_drv_vbus(fsm, 0);
668 static int fsl_otg_start_srp(
struct usb_otg *otg)
676 if (otg_dev != fsl_otg_dev)
679 otg_dev->
fsm.b_bus_req = 1;
686 static int fsl_otg_start_hnp(
struct usb_otg *otg)
694 if (otg_dev != fsl_otg_dev)
697 DBG(
"start_hnp...n");
700 otg_dev->
fsm.a_bus_req = 0;
716 u32 otg_int_src, otg_sc;
740 otg->
host->is_b_host = fsm->
id;
742 otg->
gadget->is_a_peripheral = !fsm->
id;
743 VDBG(
"ID int (ID is %d)\n", fsm->
id);
754 otg_drv_vbus(fsm, 1);
792 if (!fsl_otg_tc->
phy.otg) {
799 INIT_LIST_HEAD(&active_timers);
802 pr_info(
"Couldn't init OTG timers\n");
808 fsl_otg_tc->
fsm.ops = &fsl_otg_ops;
812 fsl_otg_tc->
phy.set_power = fsl_otg_set_power;
814 fsl_otg_tc->
phy.otg->phy = &fsl_otg_tc->
phy;
815 fsl_otg_tc->
phy.otg->set_host = fsl_otg_set_host;
816 fsl_otg_tc->
phy.otg->set_peripheral = fsl_otg_set_peripheral;
817 fsl_otg_tc->
phy.otg->start_hnp = fsl_otg_start_hnp;
818 fsl_otg_tc->
phy.otg->start_srp = fsl_otg_start_srp;
820 fsl_otg_dev = fsl_otg_tc;
853 fsm->
otg = p_otg->
phy.otg;
865 pdata->
regs = (
void *)usb_dr_regs;
867 if (pdata->
init && pdata->
init(pdev) != 0)
871 _fsl_readl = _fsl_readl_be;
872 _fsl_writel = _fsl_writel_be;
874 _fsl_readl = _fsl_readl_le;
875 _fsl_writel = _fsl_writel_le;
883 dev_dbg(p_otg->
phy.dev,
"can't get IRQ %d, error %d\n",
953 DBG(
"initial ID pin=%d\n", p_otg->
fsm.id);
967 static int show_fsl_usb2_otg_state(
struct device *
dev,
1004 "OTG state: %s\n\n",
1013 "a_bus_resume: %d\n"
1014 "a_bus_suspend: %d\n"
1019 "b_bus_resume: %d\n"
1020 "b_bus_suspend: %d\n"
1044 spin_unlock_irqrestore(&fsm->
lock, flags);
1058 static long fsl_otg_ioctl(
struct file *
file,
unsigned int cmd,
1069 fsl_otg_dev->
fsm.a_suspend_req =
arg;
1073 fsl_otg_dev->
fsm.a_bus_drop =
arg;
1077 fsl_otg_dev->
fsm.a_bus_req =
arg;
1081 fsl_otg_dev->
fsm.b_bus_req =
arg;
1093 static int fsl_otg_open(
struct inode *
inode,
struct file *file)
1098 static int fsl_otg_release(
struct inode *
inode,
struct file *file)
1108 .unlocked_ioctl = fsl_otg_ioctl,
1109 .open = fsl_otg_open,
1110 .release = fsl_otg_release,
1117 if (!pdev->
dev.platform_data)
1121 ret = fsl_otg_conf(pdev);
1123 dev_err(&pdev->
dev,
"Couldn't configure OTG module\n");
1130 dev_err(&pdev->
dev,
"Can't init FSL OTG device\n");
1136 dev_err(&pdev->
dev,
"unable to register FSL OTG device\n");
1142 dev_warn(&pdev->
dev,
"Can't register sysfs attribute\n");
1171 .probe = fsl_otg_probe,