2 * Faraday USB 2.0 EHCI Controller
4 * (C) Copyright 2010 Faraday Technology
5 * Dante Su <dantesu@faraday-tech.com>
7 * SPDX-License-Identifier: GPL-2.0+
13 #include <usb/fusbh200.h>
14 #include <usb/fotg210.h>
18 #ifndef CONFIG_USB_EHCI_BASE_LIST
19 #define CONFIG_USB_EHCI_BASE_LIST { CONFIG_USB_EHCI_BASE }
22 union ehci_faraday_regs
{
23 struct fusbh200_regs usb
;
24 struct fotg210_regs otg
;
27 static inline int ehci_is_fotg2xx(union ehci_faraday_regs
*regs
)
29 return !readl(®s
->usb
.easstr
);
33 * Create the appropriate control structures to manage
34 * a new EHCI host controller.
36 int ehci_hcd_init(int index
, struct ehci_hccr
**ret_hccr
,
37 struct ehci_hcor
**ret_hcor
)
39 struct ehci_hccr
*hccr
;
40 struct ehci_hcor
*hcor
;
41 union ehci_faraday_regs
*regs
;
42 uint32_t base_list
[] = CONFIG_USB_EHCI_BASE_LIST
;
44 if (index
< 0 || index
>= ARRAY_SIZE(base_list
))
46 regs
= (void __iomem
*)base_list
[index
];
47 hccr
= (struct ehci_hccr
*)®s
->usb
.hccr
;
48 hcor
= (struct ehci_hcor
*)®s
->usb
.hcor
;
50 if (ehci_is_fotg2xx(regs
)) {
51 /* A-device bus reset */
52 /* ... Power off A-device */
53 setbits_le32(®s
->otg
.otgcsr
, OTGCSR_A_BUSDROP
);
54 /* ... Drop vbus and bus traffic */
55 clrbits_le32(®s
->otg
.otgcsr
, OTGCSR_A_BUSREQ
);
57 /* ... Power on A-device */
58 clrbits_le32(®s
->otg
.otgcsr
, OTGCSR_A_BUSDROP
);
59 /* ... Drive vbus and bus traffic */
60 setbits_le32(®s
->otg
.otgcsr
, OTGCSR_A_BUSREQ
);
62 /* Disable OTG & DEV interrupts, triggered at level-high */
63 writel(IMR_IRQLH
| IMR_OTG
| IMR_DEV
, ®s
->otg
.imr
);
64 /* Clear all interrupt status */
65 writel(ISR_HOST
| ISR_OTG
| ISR_DEV
, ®s
->otg
.isr
);
67 /* Interrupt=level-high */
68 setbits_le32(®s
->usb
.bmcsr
, BMCSR_IRQLH
);
70 clrbits_le32(®s
->usb
.bmcsr
, BMCSR_VBUS_OFF
);
71 /* Disable all interrupts */
72 writel(0x00, ®s
->usb
.bmier
);
73 writel(0x1f, ®s
->usb
.bmisr
);
83 * Destroy the appropriate control structures corresponding
84 * the the EHCI host controller.
86 int ehci_hcd_stop(int index
)
92 * This ehci_set_usbmode() overrides the weak function
95 void ehci_set_usbmode(int index
)
97 /* nothing needs to be done */
101 * This ehci_get_port_speed() overrides the weak function
104 int ehci_get_port_speed(struct ehci_hcor
*hcor
, uint32_t reg
)
106 int spd
, ret
= PORTSC_PSPD_HS
;
107 union ehci_faraday_regs
*regs
= (void __iomem
*)((ulong
)hcor
- 0x10);
109 if (ehci_is_fotg2xx(regs
))
110 spd
= OTGCSR_SPD(readl(®s
->otg
.otgcsr
));
112 spd
= BMCSR_SPD(readl(®s
->usb
.bmcsr
));
115 case 0: /* full speed */
116 ret
= PORTSC_PSPD_FS
;
118 case 1: /* low speed */
119 ret
= PORTSC_PSPD_LS
;
121 case 2: /* high speed */
122 ret
= PORTSC_PSPD_HS
;
125 printf("ehci-faraday: invalid device speed\n");
133 * This ehci_get_portsc_register() overrides the weak function
136 uint32_t *ehci_get_portsc_register(struct ehci_hcor
*hcor
, int port
)
138 /* Faraday EHCI has one and only one portsc register */
140 /* Printing the message would cause a scan failure! */
141 debug("The request port(%d) is not configured\n", port
);
145 /* Faraday EHCI PORTSC register offset is 0x20 from hcor */
146 return (uint32_t *)((uint8_t *)hcor
+ 0x20);