2023-08-30 16:21:18 +08:00
|
|
|
#include "usbh_core.h"
|
|
|
|
|
#include "hpm_common.h"
|
|
|
|
|
#include "hpm_soc.h"
|
|
|
|
|
#include "hpm_usb_drv.h"
|
|
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
#if !defined(CONFIG_USB_EHCI_HPMICRO) || !CONFIG_USB_EHCI_HPMICRO
|
|
|
|
|
#error "hpm ehci must set CONFIG_USB_EHCI_HPMICRO=1"
|
|
|
|
|
#endif
|
2023-08-30 16:21:18 +08:00
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
#if !defined(CONFIG_USB_EHCI_HCOR_OFFSET) || CONFIG_USB_EHCI_HCOR_OFFSET != 0x140
|
|
|
|
|
#error "hpm ehci must config CONFIG_USB_EHCI_HCOR_OFFSET to 0x140"
|
|
|
|
|
#endif
|
2023-08-30 16:21:18 +08:00
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
#if defined(CONFIG_USB_EHCI_PRINT_HW_PARAM) || !defined(CONFIG_USB_EHCI_PORT_POWER)
|
|
|
|
|
#error "hpm ehci must enable CONFIG_USB_EHCI_PORT_POWER and disable CONFIG_USB_EHCI_PRINT_HW_PARAM"
|
|
|
|
|
#endif
|
2023-08-30 16:21:18 +08:00
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
struct usbh_bus *hpm_usb_bus0;
|
2023-08-30 16:21:18 +08:00
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
#ifdef HPM_USB1_BASE
|
|
|
|
|
struct usbh_bus *hpm_usb_bus1;
|
|
|
|
|
#endif
|
2023-08-30 16:21:18 +08:00
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
const uint8_t hpm_irq_table[] = {
|
|
|
|
|
IRQn_USB0,
|
|
|
|
|
#ifdef HPM_USB1_BASE
|
|
|
|
|
IRQn_USB1
|
|
|
|
|
#endif
|
|
|
|
|
};
|
2023-08-30 16:21:18 +08:00
|
|
|
|
|
|
|
|
static void usb_host_mode_init(USB_Type *ptr)
|
|
|
|
|
{
|
|
|
|
|
/* Set mode to host, must be set immediately after reset */
|
|
|
|
|
ptr->USBMODE &= ~USB_USBMODE_CM_MASK;
|
|
|
|
|
ptr->USBMODE |= USB_USBMODE_CM_SET(3);
|
|
|
|
|
|
|
|
|
|
/* Set the endian */
|
|
|
|
|
ptr->USBMODE &= ~USB_USBMODE_ES_MASK;
|
|
|
|
|
|
|
|
|
|
/* Set parallel interface signal */
|
|
|
|
|
ptr->PORTSC1 &= ~USB_PORTSC1_STS_MASK;
|
|
|
|
|
|
|
|
|
|
/* Set parallel transceiver width */
|
|
|
|
|
ptr->PORTSC1 &= ~USB_PORTSC1_PTW_MASK;
|
|
|
|
|
|
|
|
|
|
/* Not use interrupt threshold. */
|
|
|
|
|
ptr->USBCMD &= ~USB_USBCMD_ITC_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
void usb_hc_low_level_init(struct usbh_bus *bus)
|
2023-08-30 16:21:18 +08:00
|
|
|
{
|
2024-01-27 08:47:24 +08:00
|
|
|
usb_phy_init((USB_Type *)(bus->hcd.reg_base));
|
|
|
|
|
intc_m_enable_irq(hpm_irq_table[bus->hcd.hcd_id]);
|
2023-08-30 16:21:18 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
void usb_hc_low_level2_init(struct usbh_bus *bus)
|
2023-08-30 16:21:18 +08:00
|
|
|
{
|
2024-01-27 08:47:24 +08:00
|
|
|
usb_host_mode_init((USB_Type *)(bus->hcd.reg_base));
|
2023-08-30 16:21:18 +08:00
|
|
|
}
|
|
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
uint8_t usbh_get_port_speed(struct usbh_bus *bus, const uint8_t port)
|
2023-08-30 16:21:18 +08:00
|
|
|
{
|
2024-01-27 08:47:24 +08:00
|
|
|
(void)port;
|
2023-08-30 16:21:18 +08:00
|
|
|
uint8_t speed;
|
|
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
speed = usb_get_port_speed((USB_Type *)(bus->hcd.reg_base));
|
2023-08-30 16:21:18 +08:00
|
|
|
|
|
|
|
|
if (speed == 0x00) {
|
|
|
|
|
return USB_SPEED_FULL;
|
|
|
|
|
}
|
|
|
|
|
if (speed == 0x01) {
|
|
|
|
|
return USB_SPEED_LOW;
|
|
|
|
|
}
|
|
|
|
|
if (speed == 0x02) {
|
|
|
|
|
return USB_SPEED_HIGH;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
extern void USBH_IRQHandler(struct usbh_bus *bus);
|
2023-08-30 16:21:18 +08:00
|
|
|
|
2024-01-27 08:47:24 +08:00
|
|
|
void isr_usbh0(void)
|
2023-08-30 16:21:18 +08:00
|
|
|
{
|
2024-01-27 08:47:24 +08:00
|
|
|
USBH_IRQHandler(hpm_usb_bus0);
|
2023-08-30 16:21:18 +08:00
|
|
|
}
|
2024-01-27 08:47:24 +08:00
|
|
|
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbh0)
|
2023-08-30 16:21:18 +08:00
|
|
|
|
|
|
|
|
#ifdef HPM_USB1_BASE
|
2024-01-27 08:47:24 +08:00
|
|
|
void isr_usbh1(void)
|
2023-08-30 16:21:18 +08:00
|
|
|
{
|
2024-01-27 08:47:24 +08:00
|
|
|
USBH_IRQHandler(hpm_usb_bus1);
|
2023-08-30 16:21:18 +08:00
|
|
|
}
|
2024-01-27 08:47:24 +08:00
|
|
|
SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbh1)
|
|
|
|
|
#endif
|