From 5641a2b882728684a84c7f03587f6136eddd3b1e Mon Sep 17 00:00:00 2001 From: Zhihong Chen Date: Tue, 25 Nov 2025 11:15:18 +0800 Subject: [PATCH] port: update hpmicro port files for otg Signed-off-by: Zhihong Chen --- port/hpmicro/usb_dc_hpm.c | 2 +- port/hpmicro/usb_glue_hpm.c | 69 ++++++++++++++++++------------------- port/hpmicro/usb_hc_hpm.c | 20 ++++------- 3 files changed, 41 insertions(+), 50 deletions(-) diff --git a/port/hpmicro/usb_dc_hpm.c b/port/hpmicro/usb_dc_hpm.c index 61956c37..a3a9fdc1 100644 --- a/port/hpmicro/usb_dc_hpm.c +++ b/port/hpmicro/usb_dc_hpm.c @@ -103,7 +103,7 @@ int usb_dc_init(uint8_t busid) usb_device_init(g_hpm_udc[busid].handle, int_mask); #ifdef CONFIG_USB_OTG_ENABLE - g_hpm_udc[busid].handle->regs->OTGSC |= USB_OTGSC_IDIE_MASK; + usb_otgsc_enable_id_chg_int(g_hpm_udc[busid].handle->regs); #endif usb_dc_isr_connect(busid); diff --git a/port/hpmicro/usb_glue_hpm.c b/port/hpmicro/usb_glue_hpm.c index 6099d906..aa5f9cec 100644 --- a/port/hpmicro/usb_glue_hpm.c +++ b/port/hpmicro/usb_glue_hpm.c @@ -7,52 +7,71 @@ #include "hpm_common.h" #include "hpm_soc.h" #include "hpm_l1c_drv.h" +#include "hpm_usb_drv.h" #include "usb_config.h" void (*g_usb_hpm_irq[2])(uint8_t busid); uint8_t g_usb_hpm_busid[2]; +#ifndef CONFIG_CHERRYUSB_CUSTOM_IRQ_HANDLER +SDK_DECLARE_EXT_ISR_M(IRQn_USB0, hpm_isr_usb0) +#ifdef HPM_USB1_BASE +SDK_DECLARE_EXT_ISR_M(IRQn_USB1, hpm_isr_usb1) +#endif +#endif + #ifdef CONFIG_USB_OTG_ENABLE #include "usbotg_core.h" int usb_otg_init(uint8_t busid) { + (void)busid; + return 0; } int usb_otg_deinit(uint8_t busid) { + (void)busid; + return 0; } -SDK_DECLARE_EXT_ISR_M(IRQn_USB0, hpm_isr_usb0) void hpm_isr_usb0(void) { - bool is_idchange = false; - - is_idchange = USB_OTGSC_IDIS_GET(HPM_USB0->OTGSC); - if (is_idchange) { - HPM_USB0->OTGSC |= USB_OTGSC_IDIS_MASK; - usbotg_trigger_role_change(g_usb_hpm_busid[0], USB_OTGSC_ID_GET(HPM_USB0->OTGSC) ? USBOTG_MODE_DEVICE : USBOTG_MODE_HOST); + if (usb_otgsc_get_id_chg_flag(HPM_USB0)) { + usb_otgsc_clear_id_chg_flag(HPM_USB0); + usbotg_trigger_role_change(g_usb_hpm_busid[0], usb_otgsc_get_id_status(HPM_USB0) ? USBOTG_MODE_DEVICE : USBOTG_MODE_HOST); } USBOTG_IRQHandler(g_usb_hpm_busid[0]); } #ifdef HPM_USB1_BASE -SDK_DECLARE_EXT_ISR_M(IRQn_USB1, hpm_isr_usb1) void hpm_isr_usb1(void) { - bool is_idchange = false; - - is_idchange = USB_OTGSC_IDIS_GET(HPM_USB1->OTGSC); - if (is_idchange) { - HPM_USB1->OTGSC |= USB_OTGSC_IDIS_MASK; - usbotg_trigger_role_change(g_usb_hpm_busid[1], USB_OTGSC_ID_GET(HPM_USB1->OTGSC) ? USBOTG_MODE_DEVICE : USBOTG_MODE_HOST); + if (usb_otgsc_get_id_chg_flag(HPM_USB1)) { + usb_otgsc_clear_id_chg_flag(HPM_USB1); + usbotg_trigger_role_change(g_usb_hpm_busid[1], usb_otgsc_get_id_status(HPM_USB1) ? USBOTG_MODE_DEVICE : USBOTG_MODE_HOST); } USBOTG_IRQHandler(g_usb_hpm_busid[1]); } #endif + +#else + +void hpm_isr_usb0(void) +{ + g_usb_hpm_irq[0](g_usb_hpm_busid[0]); +} + +#ifdef HPM_USB1_BASE +void hpm_isr_usb1(void) +{ + g_usb_hpm_irq[1](g_usb_hpm_busid[1]); +} +#endif + #endif ATTR_WEAK void hpm_usb_isr_enable(uint32_t base) @@ -77,26 +96,6 @@ ATTR_WEAK void hpm_usb_isr_disable(uint32_t base) } } -#ifndef CONFIG_USB_OTG_ENABLE -#ifndef CONFIG_CHERRYUSB_CUSTOM_IRQ_HANDLER -SDK_DECLARE_EXT_ISR_M(IRQn_USB0, hpm_isr_usb0) -#endif -void hpm_isr_usb0(void) -{ - g_usb_hpm_irq[0](g_usb_hpm_busid[0]); -} - -#ifdef HPM_USB1_BASE -#ifndef CONFIG_CHERRYUSB_CUSTOM_IRQ_HANDLER -SDK_DECLARE_EXT_ISR_M(IRQn_USB1, hpm_isr_usb1) -#endif -void hpm_isr_usb1(void) -{ - g_usb_hpm_irq[1](g_usb_hpm_busid[1]); -} -#endif -#endif - #ifdef CONFIG_USB_DCACHE_ENABLE void usb_dcache_clean(uintptr_t addr, size_t size) { @@ -112,4 +111,4 @@ void usb_dcache_flush(uintptr_t addr, size_t size) { l1c_dc_flush(addr, size); } -#endif \ No newline at end of file +#endif diff --git a/port/hpmicro/usb_hc_hpm.c b/port/hpmicro/usb_hc_hpm.c index e6117d33..2c340573 100644 --- a/port/hpmicro/usb_hc_hpm.c +++ b/port/hpmicro/usb_hc_hpm.c @@ -55,39 +55,31 @@ void usb_hc_low_level2_init(struct usbh_bus *bus) usb_host_mode_init((USB_Type *)(bus->hcd.reg_base)); if (bus->hcd.reg_base == HPM_USB0_BASE) { -#ifdef CONFIG_USB_OTG_ENABLE - HPM_USB0->OTGSC |= USB_OTGSC_IDIE_MASK; -#endif g_usb_hpm_busid[0] = bus->hcd.hcd_id; g_usb_hpm_irq[0] = USBH_IRQHandler; - - hpm_usb_isr_enable(HPM_USB0_BASE); } else { #ifdef HPM_USB1_BASE -#ifdef CONFIG_USB_OTG_ENABLE - HPM_USB1->OTGSC |= USB_OTGSC_IDIE_MASK; -#endif g_usb_hpm_busid[1] = bus->hcd.hcd_id; g_usb_hpm_irq[1] = USBH_IRQHandler; - - hpm_usb_isr_enable(HPM_USB1_BASE); #endif } + +#ifdef CONFIG_USB_OTG_ENABLE + usb_otgsc_enable_id_chg_int((USB_Type *)(bus->hcd.reg_base)); +#endif + hpm_usb_isr_enable(bus->hcd.reg_base); } void usb_hc_low_level_deinit(struct usbh_bus *bus) { usb_phy_deinit((USB_Type *)(bus->hcd.reg_base)); + hpm_usb_isr_disable(bus->hcd.reg_base); if (bus->hcd.reg_base == HPM_USB0_BASE) { - hpm_usb_isr_disable(HPM_USB0_BASE); - g_usb_hpm_busid[0] = 0; g_usb_hpm_irq[0] = NULL; } else { #ifdef HPM_USB1_BASE - hpm_usb_isr_disable(HPM_USB1_BASE); - g_usb_hpm_busid[1] = 0; g_usb_hpm_irq[1] = NULL; #endif