summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhihong Chen <[email protected]>2024-02-20 13:33:55 +0800
committersakumisu <[email protected]>2024-02-20 14:28:10 +0800
commit0e3e9477cc3ec0baea9339292b16a25ca03a4e9a (patch)
tree46aa7cca1a4f568b33151e0747b9d625db6f3991
parent56c90ab6f941ee9b7b93ae8e130d2e3defa4a009 (diff)
port: HPMicro: decoupling the relationship between busid and usbid
- decoupling the relationship between busid and usbid Signed-off-by: Zhihong Chen <[email protected]>
-rw-r--r--port/ehci/usb_glue_hpm.c26
-rw-r--r--port/hpm/usb_dc_hpm.c48
2 files changed, 40 insertions, 34 deletions
diff --git a/port/ehci/usb_glue_hpm.c b/port/ehci/usb_glue_hpm.c
index e57075f5..9cf5f922 100644
--- a/port/ehci/usb_glue_hpm.c
+++ b/port/ehci/usb_glue_hpm.c
@@ -15,12 +15,8 @@
#error "hpm ehci must enable CONFIG_USB_EHCI_PORT_POWER"
#endif
-const uint8_t hpm_irq_table[] = {
- IRQn_USB0,
-#ifdef HPM_USB1_BASE
- IRQn_USB1
-#endif
-};
+static uint32_t _hcd_irqnum[CONFIG_USBHOST_MAX_BUS];
+static uint8_t _hcd_busid[CONFIG_USBHOST_MAX_BUS];
static void usb_host_mode_init(USB_Type *ptr)
{
@@ -43,8 +39,20 @@ static void usb_host_mode_init(USB_Type *ptr)
void usb_hc_low_level_init(struct usbh_bus *bus)
{
+ if (bus->hcd.reg_base == HPM_USB0_BASE) {
+ _hcd_irqnum[bus->hcd.hcd_id] = IRQn_USB0;
+ _hcd_busid[0] = bus->hcd.hcd_id;
+ } else {
+#ifdef HPM_USB1_BASE
+ if (bus->hcd.reg_base == HPM_USB1_BASE) {
+ _hcd_irqnum[bus->hcd.hcd_id] = IRQn_USB1;
+ _hcd_busid[1] = bus->hcd.hcd_id;
+ }
+#endif
+ }
+
usb_phy_init((USB_Type *)(bus->hcd.reg_base));
- intc_m_enable_irq(hpm_irq_table[bus->hcd.hcd_id]);
+ intc_m_enable_irq(_hcd_irqnum[bus->hcd.hcd_id]);
}
void usb_hc_low_level2_init(struct usbh_bus *bus)
@@ -76,14 +84,14 @@ extern void USBH_IRQHandler(uint8_t busid);
void isr_usbh0(void)
{
- USBH_IRQHandler(0);
+ USBH_IRQHandler(_hcd_busid[0]);
}
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbh0)
#ifdef HPM_USB1_BASE
void isr_usbh1(void)
{
- USBH_IRQHandler(1);
+ USBH_IRQHandler(_hcd_busid[1]);
}
SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbh1)
#endif
diff --git a/port/hpm/usb_dc_hpm.c b/port/hpm/usb_dc_hpm.c
index 3cc5da88..797961e0 100644
--- a/port/hpm/usb_dc_hpm.c
+++ b/port/hpm/usb_dc_hpm.c
@@ -28,6 +28,9 @@ struct hpm_ep_state {
uint32_t actual_xfer_len;
};
+/*---------------------------------------------------------------------*
+ * Variable Definitions
+ *---------------------------------------------------------------------*/
/* Driver state */
struct hpm_udc {
usb_device_handle_t *handle;
@@ -40,26 +43,8 @@ static ATTR_PLACE_AT_NONCACHEABLE_WITH_ALIGNMENT(USB_SOC_DCD_DATA_RAM_ADDRESS_AL
static ATTR_PLACE_AT_NONCACHEABLE_WITH_ALIGNMENT(USB_SOC_DCD_DATA_RAM_ADDRESS_ALIGNMENT) dcd_data_t _dcd_data1;
#endif
static ATTR_PLACE_AT_NONCACHEABLE usb_device_handle_t usb_device_handle[CONFIG_USBDEV_MAX_BUS];
-
-/*---------------------------------------------------------------------*
- * Macro Typedef Declaration
- *---------------------------------------------------------------------*/
-typedef struct {
- USB_Type* regs; /* register base*/
- const uint32_t irqnum; /* IRQ number */
- const uint8_t ep_count; /* Max bi-directional Endpoints */
-} dcd_controller_t;
-
-/*---------------------------------------------------------------------*
- * Variable Definitions
- *---------------------------------------------------------------------*/
-static const dcd_controller_t _dcd_controller[] =
-{
- { .regs = (USB_Type*) HPM_USB0_BASE, .irqnum = IRQn_USB0, .ep_count = USB_SOC_DCD_MAX_ENDPOINT_COUNT },
-#ifdef HPM_USB1_BASE
- { .regs = (USB_Type*) HPM_USB1_BASE, .irqnum = IRQn_USB1, .ep_count = USB_SOC_DCD_MAX_ENDPOINT_COUNT }
-#endif
-};
+static uint32_t _dcd_irqnum[CONFIG_USBDEV_MAX_BUS];
+static uint8_t _dcd_busid[CONFIG_USBDEV_MAX_BUS];
/* Index to bit position in register */
static inline uint8_t ep_idx2bit(uint8_t ep_idx)
@@ -83,7 +68,20 @@ int usb_dc_init(uint8_t busid)
memset(&g_hpm_udc[busid], 0, sizeof(struct hpm_udc));
g_hpm_udc[busid].handle = &usb_device_handle[busid];
- g_hpm_udc[busid].handle->regs = _dcd_controller[busid].regs;
+ g_hpm_udc[busid].handle->regs = (USB_Type *)g_usbdev_bus[busid].reg_base;
+
+ if (g_usbdev_bus[busid].reg_base == HPM_USB0_BASE) {
+ _dcd_irqnum[busid] = IRQn_USB0;
+ _dcd_busid[0] = busid;
+ } else {
+#ifdef HPM_USB1_BASE
+ if (g_usbdev_bus[busid].reg_base == HPM_USB1_BASE) {
+ _dcd_irqnum[busid] = IRQn_USB1;
+ _dcd_busid[1] = busid;
+ }
+#endif
+ }
+
if (busid == 0) {
g_hpm_udc[busid].handle->dcd_data = &_dcd_data0;
} else if (busid == 1) {
@@ -100,13 +98,13 @@ int usb_dc_init(uint8_t busid)
usb_device_init(g_hpm_udc[busid].handle, int_mask);
- intc_m_enable_irq(_dcd_controller[busid].irqnum);
+ intc_m_enable_irq(_dcd_irqnum[busid]);
return 0;
}
int usb_dc_deinit(uint8_t busid)
{
- intc_m_disable_irq(_dcd_controller[busid].irqnum);
+ intc_m_disable_irq(_dcd_irqnum[busid]);
usb_device_deinit(g_hpm_udc[busid].handle);
@@ -325,14 +323,14 @@ void USBD_IRQHandler(uint8_t busid)
void isr_usbd0(void)
{
- USBD_IRQHandler(0);
+ USBD_IRQHandler(_dcd_busid[0]);
}
SDK_DECLARE_EXT_ISR_M(IRQn_USB0, isr_usbd0)
#ifdef HPM_USB1_BASE
void isr_usbd1(void)
{
- USBD_IRQHandler(1);
+ USBD_IRQHandler(_dcd_busid[1]);
}
SDK_DECLARE_EXT_ISR_M(IRQn_USB1, isr_usbd1)
#endif \ No newline at end of file