summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsakumisu <[email protected]>2026-10-11 21:52:31 +0800
committersakumisu <[email protected]>2026-10-11 21:52:36 +0800
commitd3c8b19b304e91e8f83ef341a71dee23b3851414 (patch)
tree06bf81949e11bf47c1dcd8b9e255004bec142aa2
parenta4ec68319fa83fbb8e529ff6cf58d44a29821ddc (diff)
update(port/dwc2/gd): add gd reg patch, all todo
Signed-off-by: sakumisu <[email protected]>
-rw-r--r--port/dwc2/usb_dwc2_param.h11
-rw-r--r--port/dwc2/usb_glue_gd.c94
2 files changed, 80 insertions, 25 deletions
diff --git a/port/dwc2/usb_dwc2_param.h b/port/dwc2/usb_dwc2_param.h
index 74e436c2..24d523ab 100644
--- a/port/dwc2/usb_dwc2_param.h
+++ b/port/dwc2/usb_dwc2_param.h
@@ -295,13 +295,22 @@ static inline void dwc2_get_hwparams(uint32_t reg_base, struct dwc2_hw_params *h
unsigned int width;
uint32_t snpsid, hwcfg1, hwcfg2, hwcfg3, hwcfg4;
+#if defined(CONFIG_USB_DWC2_GD)
+ extern void dwc2_get_gd_reg(uint32_t reg_base,
+ uint32_t *snpsid,
+ uint32_t *hwcfg1,
+ uint32_t *hwcfg2,
+ uint32_t *hwcfg3,
+ uint32_t *hwcfg4);
+ dwc2_get_gd_reg(reg_base, &snpsid, &hwcfg1, &hwcfg2, &hwcfg3, &hwcfg4);
+#else
snpsid = dwc2_readl(reg_base + GSNPSID_OFFSET);
hwcfg1 = dwc2_readl(reg_base + GHWCFG1_OFFSET);
hwcfg2 = dwc2_readl(reg_base + GHWCFG2_OFFSET);
hwcfg3 = dwc2_readl(reg_base + GHWCFG3_OFFSET);
hwcfg4 = dwc2_readl(reg_base + GHWCFG4_OFFSET);
-
+#endif
/* snpsid */
hw->snpsid = snpsid;
diff --git a/port/dwc2/usb_glue_gd.c b/port/dwc2/usb_glue_gd.c
index 1a236862..a702515c 100644
--- a/port/dwc2/usb_glue_gd.c
+++ b/port/dwc2/usb_glue_gd.c
@@ -3,41 +3,65 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
-#include "usb_config.h"
-#include "stdint.h"
-#include "usb_dwc2_reg.h"
+#include "usbd_core.h"
+#include "usbh_core.h"
+#include "usb_dwc2_param.h"
-#if 1
-#error you need to modify some usb register values then use this chip
+#if !defined(CONFIG_USB_DWC2_GD)
+#error must define CONFIG_USB_DWC2_GD when use GD32 chips
#endif
-#if CONFIG_USBDEV_EP_NUM != 4 && CONFIG_USBDEV_EP_NUM != 6
-#error "gd32 only has 4 endpoints for pa11/pa12 and 6 endpoints for pb14/pb15"
-#endif
+// TODO: Implement this function to read the GD32-specific USB controller registers.
+void dwc2_get_gd_reg(uint32_t reg_base,
+ uint32_t *snpsid,
+ uint32_t *hwcfg1,
+ uint32_t *hwcfg2,
+ uint32_t *hwcfg3,
+ uint32_t *hwcfg4)
+{
+}
-/* you can find this config in function:usb_core_init, file:drv_usb_core.c, for example:
- *
- * usb_regs->gr->GCCFG |= GCCFG_PWRON | GCCFG_VBUSACEN | GCCFG_VBUSBCEN;
- *
-*/
+// TODO
+void usb_dc_low_level_init(uint8_t busid)
+{
+}
-uint32_t usbd_get_dwc2_gccfg_conf(uint32_t reg_base)
+// TODO
+void usb_dc_low_level_deinit(uint8_t busid)
{
-#ifdef CONFIG_USB_HS
- return 0;
-#else
- return ((1 << 16) | (1 << 18) | (1 << 19) | (1 << 21));
-#endif
}
-uint32_t usbh_get_dwc2_gccfg_conf(uint32_t reg_base)
+// TODO
+void usb_hc_low_level_init(struct usbh_bus *bus)
{
-#ifdef CONFIG_USB_HS
- return 0;
-#else
- return ((1 << 16) | (1 << 18) | (1 << 19) | (1 << 21));
+}
+
+// TODO
+void usb_hc_low_level_deinit(struct usbh_bus *bus)
+{
+}
+
+// TODO
+#ifndef CONFIG_USB_DWC2_CUSTOM_PARAM
+void dwc2_get_user_params(uint32_t reg_base, struct dwc2_user_params *params)
+{
+ // if (reg_base == 0x40040000UL) { // USB_OTG_HS_PERIPH_BASE
+ // memcpy(params, &param_pb14_pb15, sizeof(struct dwc2_user_params));
+ // } else {
+ // memcpy(params, &param_pa11_pa12, sizeof(struct dwc2_user_params));
+ // }
+#ifdef CONFIG_USB_DWC2_CUSTOM_FIFO
+ struct usb_dwc2_user_fifo_config s_dwc2_fifo_config;
+
+ dwc2_get_user_fifo_config(reg_base, &s_dwc2_fifo_config);
+
+ params->device_rx_fifo_size = s_dwc2_fifo_config.device_rx_fifo_size;
+ for (uint8_t i = 0; i < MAX_EPS_CHANNELS; i++) {
+ params->device_tx_fifo_size[i] = s_dwc2_fifo_config.device_tx_fifo_size[i];
+ }
#endif
}
+#endif
extern uint32_t SystemCoreClock;
@@ -48,3 +72,25 @@ void usbd_dwc2_delay_ms(uint8_t ms)
__asm volatile("nop");
}
}
+
+uint32_t usbd_dwc2_get_system_clock(void)
+{
+ return SystemCoreClock;
+}
+
+#ifdef CONFIG_USB_DCACHE_ENABLE
+void usb_dcache_clean(uintptr_t addr, size_t size)
+{
+ SCB_CleanDCache_by_Addr((void *)addr, size);
+}
+
+void usb_dcache_invalidate(uintptr_t addr, size_t size)
+{
+ SCB_InvalidateDCache_by_Addr((void *)addr, size);
+}
+
+void usb_dcache_flush(uintptr_t addr, size_t size)
+{
+ SCB_CleanInvalidateDCache_by_Addr((void *)addr, size);
+}
+#endif \ No newline at end of file