From 2a2661bd727d32f02f9a96e60411ee3dbeb21808 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Fri, 13 Nov 2026 11:21:10 +0530 Subject: [PATCH 01/17] src: portable: support for dwc3 and xhci * Support for DWC3 controller with xHCI host mode support Signed-off-by: Sourav Raj K K --- hw/bsp/socfpga/family.cmake | 15 + src/portable/synopsys/dwc3/dwc3.c | 50 + src/portable/synopsys/dwc3/dwc3.h | 27 + src/portable/synopsys/dwc3/dwc3_ll.c | 169 ++ src/portable/synopsys/dwc3/dwc3_ll.h | 63 + src/portable/synopsys/dwc3/dwc3_socfpga.h | 286 ++ src/portable/synopsys/dwc3/hcd_dwc3.c | 1434 +++++++++ src/portable/synopsys/dwc3/socfpga_usb3_reg.h | 2660 +++++++++++++++++ src/portable/xhci/xhci.c | 184 ++ src/portable/xhci/xhci.h | 360 +++ src/portable/xhci/xhci_cap.c | 74 + src/portable/xhci/xhci_commands.c | 245 ++ src/portable/xhci/xhci_commands.h | 127 + src/portable/xhci/xhci_context.c | 467 +++ src/portable/xhci/xhci_context.h | 125 + src/portable/xhci/xhci_doorbell.c | 40 + src/portable/xhci/xhci_doorbell.h | 37 + src/portable/xhci/xhci_endpoints.c | 408 +++ src/portable/xhci/xhci_endpoints.h | 97 + src/portable/xhci/xhci_events.c | 245 ++ src/portable/xhci/xhci_events.h | 228 ++ src/portable/xhci/xhci_interrupts.c | 109 + src/portable/xhci/xhci_interrupts.h | 40 + src/portable/xhci/xhci_rings.c | 260 ++ src/portable/xhci/xhci_rings.h | 122 + 25 files changed, 7872 insertions(+) create mode 100644 src/portable/synopsys/dwc3/dwc3.c create mode 100644 src/portable/synopsys/dwc3/dwc3.h create mode 100644 src/portable/synopsys/dwc3/dwc3_ll.c create mode 100644 src/portable/synopsys/dwc3/dwc3_ll.h create mode 100644 src/portable/synopsys/dwc3/dwc3_socfpga.h create mode 100644 src/portable/synopsys/dwc3/hcd_dwc3.c create mode 100644 src/portable/synopsys/dwc3/socfpga_usb3_reg.h create mode 100644 src/portable/xhci/xhci.c create mode 100644 src/portable/xhci/xhci.h create mode 100644 src/portable/xhci/xhci_cap.c create mode 100644 src/portable/xhci/xhci_commands.c create mode 100644 src/portable/xhci/xhci_commands.h create mode 100644 src/portable/xhci/xhci_context.c create mode 100644 src/portable/xhci/xhci_context.h create mode 100644 src/portable/xhci/xhci_doorbell.c create mode 100644 src/portable/xhci/xhci_doorbell.h create mode 100644 src/portable/xhci/xhci_endpoints.c create mode 100644 src/portable/xhci/xhci_endpoints.h create mode 100644 src/portable/xhci/xhci_events.c create mode 100644 src/portable/xhci/xhci_events.h create mode 100644 src/portable/xhci/xhci_interrupts.c create mode 100644 src/portable/xhci/xhci_interrupts.h create mode 100644 src/portable/xhci/xhci_rings.c create mode 100644 src/portable/xhci/xhci_rings.h diff --git a/hw/bsp/socfpga/family.cmake b/hw/bsp/socfpga/family.cmake index aa79dea09..d1244c20b 100644 --- a/hw/bsp/socfpga/family.cmake +++ b/hw/bsp/socfpga/family.cmake @@ -21,9 +21,12 @@ target_compile_definitions(agilex5-tinyusb PUBLIC CFG_TUSB_MCU=OPT_MCU_SOCFPGA C target_include_directories(agilex5-tinyusb PUBLIC ${FREERTOS_TOP_DIR}/drivers/usb_otg ${FREERTOS_TOP_DIR}/tinyusb/src/class/msc + ${FREERTOS_TOP_DIR}/tinyusb/src/common ${FREERTOS_TOP_DIR}/tinyusb/apps/ ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc2/ ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc3/ + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/ + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci ) # Add TinyUSB target and port source @@ -39,5 +42,17 @@ target_include_directories(agilex5-tinyusb PUBLIC # Synopsys dwc3 controller ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc3/hcd_dwc3.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc3/dwc3_common.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/dwc3.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/dwc3_ll.c + + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_cap.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_commands.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_context.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_doorbell.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_endpoints.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_events.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_interrupts.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_rings.c ) target_link_libraries(agilex5-tinyusb PRIVATE socfpga_drivers m) diff --git a/src/portable/synopsys/dwc3/dwc3.c b/src/portable/synopsys/dwc3/dwc3.c new file mode 100644 index 000000000..3ef5b1f30 --- /dev/null +++ b/src/portable/synopsys/dwc3/dwc3.c @@ -0,0 +1,50 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * HAL driver implementation for DWC3 driver + */ + +#include "dwc3.h" +#include "dwc3_ll.h" +#include "osal_log.h" +#include "socfpga_defines.h" + +int dwc3_init(void) +{ + uint32_t ghwparams0 = RD_REG32(USBBASE + USB3_GHWPARAMS0); + uint32_t ghwparams1 = RD_REG32(USBBASE + USB3_GHWPARAMS1); + uint32_t ghwparams3 = RD_REG32(USBBASE + USB3_GHWPARAMS3); + uint32_t phy_info; + int ret = 0; + + phy_info = get_usb3_phy_info(ghwparams3); + switch (phy_info) + { + case DWC3_SS_PHY_3_0: + INFO("Device supportes USB 3.0 Only"); + break; + + case DWC3_SS_PHY_3_1: + INFO("Device supportes USB 3.1 Gen1"); + break; + + default: + INFO("Device does not support USB3.1"); + break; + } + + usb2_phy_setup(ghwparams3); + + setup_dwc3_gctl(ghwparams1); + + ret = dwc3_set_usb_host_mode(ghwparams0); + if (ret != 0) + { + ERROR("Unable to setup DWC3 in host mode"); + return ret; + } + + return 0; +} diff --git a/src/portable/synopsys/dwc3/dwc3.h b/src/portable/synopsys/dwc3/dwc3.h new file mode 100644 index 000000000..1c5b03069 --- /dev/null +++ b/src/portable/synopsys/dwc3/dwc3.h @@ -0,0 +1,27 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025-2026 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for DWC3 driver + */ + +#ifndef __SOCFPGA_DWC3_H__ +#define __SOCFPGA_DWC3_H__ + +#include +#include "socfpga_usb3_reg.h" +#include "socfpga_defines.h" + +/** + * @brief Initialize the DWC3 controller. + * + * Initializes the USB2/USB3 PHY and sets the USB mode to host. + * + * @return + * 0 - on success + * errno - on failure + */ +int dwc3_init(void); + +#endif /* _SOCFPGA_DWC3_H_ */ diff --git a/src/portable/synopsys/dwc3/dwc3_ll.c b/src/portable/synopsys/dwc3/dwc3_ll.c new file mode 100644 index 000000000..6976214c0 --- /dev/null +++ b/src/portable/synopsys/dwc3/dwc3_ll.c @@ -0,0 +1,169 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Low level driver implementation for DWC3 driver + */ + +#include "dwc3_ll.h" +#include "socfpga_usb3_reg.h" +#include "socfpga_defines.h" +#include + +/* + * @brief Configures the DWC3 to operate in host mode + */ +int dwc3_set_usb_host_mode(uint32_t ghwparams0) +{ + uint32_t reg_val; + uint8_t usb_mode = (uint8_t) (ghwparams0 & + USB3_GHWPARAMS0_GHWPARAMS0_2_0_MASK); + + if (usb_mode == DWC3_GHWPARAMS0_MODE_DRD) + { + /* Suspend both USB3 & USB2 PHYs before setting HOST mode */ + reg_val = RD_REG32((USBBASE + USB3_GUSB3PIPECTL)); + reg_val &= ~(USB3_GUSB3PIPECTL_SUSPENDENABLE_MASK); + WR_REG32((USBBASE + USB3_GUSB3PIPECTL), reg_val); + + reg_val = RD_REG32((USBBASE + USB3_GUSB2PHYCFG)); + reg_val &= ~(USB3_GUSB2PHYCFG_SUSPENDUSB20_MASK); + WR_REG32((USBBASE + USB3_GUSB2PHYCFG), reg_val); + + /* Clear 12, 13 bit of GCTL register before setting to host mode */ + reg_val = RD_REG32((USBBASE + USB3_GCTL)); + reg_val &= ~(USB3_GCTL_PRTCAPDIR_MASK); + reg_val |= (USB_MODE_HOST << USB3_GCTL_PRTCAPDIR_POS); + WR_REG32((USBBASE + USB3_GCTL), reg_val); + + reg_val = RD_REG32((USBBASE + USB3_GCTL)); + reg_val |= (USB3_GCTL_CORESOFTRESET_MASK); + WR_REG32((USBBASE + USB3_GCTL), reg_val); + + osal_task_delay(100); + + reg_val = RD_REG32((USBBASE + USB3_GCTL)); + reg_val &= ~(USB3_GCTL_CORESOFTRESET_MASK); + WR_REG32((USBBASE + USB3_GCTL), reg_val); + + reg_val = RD_REG32((USBBASE + USB3_GUSB2PHYCFG)); + reg_val |= (USB3_GUSB2PHYCFG_SUSPENDUSB20_MASK); + WR_REG32((USBBASE + USB3_GUSB2PHYCFG), reg_val); + + reg_val = RD_REG32((USBBASE + USB3_GUSB3PIPECTL)); + reg_val |= ((uint32_t) 1U << 17); + WR_REG32((USBBASE + USB3_GUSB3PIPECTL), reg_val); + + } + else if (usb_mode == DWC3_GHWPARAMS0_MODE_HOST) + { + /* Do nothing as usb mode is host by default */ + } + else + { + /* Host mode not supported by controller*/ + return -EOPNOTSUPP; + } + + return 0; +} + +/* + * @brief Configures the USB2 phy + */ +void usb2_phy_setup(uint32_t ghwparams3) +{ + uint32_t reg_val; + uint8_t hs_phy; + + /* Select HS phy interface */ + hs_phy = (uint8_t) ((ghwparams3 & USB3_GHWPARAMS3_GHWPARAMS3_3_2_MASK) >> + USB3_GHWPARAMS3_GHWPARAMS3_3_2_POS); + + switch (hs_phy) + { + case DWC3_HS_PHY_UTMI: break; + + case DWC3_HS_PHY_ULPI: + break; + + case DWC3_HS_PHY_UTMI_ULPI: + /* select ULPI phy */ + reg_val = RD_REG32(USBBASE + USB3_GUSB2PHYCFG); + reg_val |= USB3_GUSB2PHYCFG_ULPI_UTMI_SEL_MASK; + WR_REG32((USBBASE + USB3_GUSB2PHYCFG), reg_val); + break; + default: + /*do nothing*/ + break; + } +} + +/* + * @brief Get the USB3 phy info + */ +uint32_t get_usb3_phy_info(uint32_t ghwparams3) +{ + uint8_t ss_phy; + + /* SS phy interface */ + ss_phy = (uint8_t) ((ghwparams3 & USB3_GHWPARAMS3_GHWPARAMS3_1_0_MASK) >> + USB3_GHWPARAMS3_GHWPARAMS3_1_0_POS); + + if (ss_phy == DWC3_SS_PHY_DIS) + { + /* SS PHY is disabled */ + return DWC3_SS_PHY_DIS; + } + else if (ss_phy == DWC3_SS_PHY_3_0) + { + /* Controller supports USB3.0 only */ + return DWC3_SS_PHY_3_0; + } + else if (ss_phy == DWC3_SS_PHY_3_1) + { + /* Controller supports USB3.1 */ + return DWC3_SS_PHY_3_1; + } + else + { + /* Invalid SS PHY info */ + } + + return DWC3_SS_PHY_DIS; + +} + +/* + * @brief Configure the DWC3 GCTL register + */ +void setup_dwc3_gctl(uint32_t ghwparams1) +{ + uint32_t reg_val; + uint8_t power_opt_mode; + + reg_val = RD_REG32(USBBASE + USB3_GCTL); + reg_val &= ~USB3_GCTL_SCALEDOWN_MASK; + + power_opt_mode = (uint8_t) ((ghwparams1 & + USB3_GHWPARAMS1_GHWPARAMS1_25_24_MASK) >> + USB3_GHWPARAMS1_GHWPARAMS1_25_24_POS); + + switch (power_opt_mode) + { + + case 1: /* clock gating only supported */ + /* Enable clock gating in GCTL reg */ + reg_val &= ~USB3_GCTL_DSBLCLKGTNG_MASK; + break; + case 2: + /* enable hibernation */ + reg_val |= USB3_GCTL_GBLHIBERNATIONEN_MASK; + + default: /*do nothing */ + break; + } + + WR_REG32((USBBASE + USB3_GCTL), reg_val); +} diff --git a/src/portable/synopsys/dwc3/dwc3_ll.h b/src/portable/synopsys/dwc3/dwc3_ll.h new file mode 100644 index 000000000..85cc504f5 --- /dev/null +++ b/src/portable/synopsys/dwc3/dwc3_ll.h @@ -0,0 +1,63 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025-2026 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for DWC3 low level driver + */ + +#ifndef _SOCFPGA_DWC3_LL_H_ +#define _SOCFPGA_DWC3_LL_H_ + +#include +#include "socfpga_usb3_reg.h" + +#define USB_MODE_HOST ((uint32_t) 1) /* !< USB host mode */ + +#define DWC3_HS_PHY_DIS (0U) /* !< HS phy is disabled */ +#define DWC3_HS_PHY_UTMI (1U) /* !< HS phy interface is UTMI */ +#define DWC3_HS_PHY_ULPI (2U) /* !< HS phy interface is ULPI */ +#define DWC3_HS_PHY_UTMI_ULPI (3U) /* !< DWC3 supports both UTMI/ULPI HS phy interface */ + +#define DWC3_SS_PHY_DIS (0U) /* !< DWC3 SS phy interface is disabled */ +#define DWC3_SS_PHY_3_0 (1U) /* !< DWC3 supports only USB3.0 mode */ +#define DWC3_SS_PHY_3_1 (2U) /* !< DWC3 supports USB3.1 mode */ + +#define DWC3_GHWPARAMS0_MODE_GADGET (0U) /* !< DWC3 Core is in gadget mode */ +#define DWC3_GHWPARAMS0_MODE_HOST (1U) /* !< DWC3 Core is in host mode*/ +#define DWC3_GHWPARAMS0_MODE_DRD (2U) /* !< DWC3 Core is in DRD mode*/ + + +/** + * @brief Configure the usb2 phy. + * + * @param[in] ghwparams3 ghwparams3 register value + */ +void usb2_phy_setup(uint32_t ghwparams3); + +/** + * @brief Get info regarding USB3.1 phy. + * + * @param[in] ghwparams3 ghwparams3 register value + * @return usb3 SS phy info + */ +uint32_t get_usb3_phy_info(uint32_t ghwparams3); + +/** + * @brief Configure the GCTL register. + * + * @param[in] ghwparams1 ghwparams1 register value + */ +void setup_dwc3_gctl(uint32_t ghwparams1); + +/** + * @brief Configure the controller in host mode. + * + * @param[in] ghwparams0 ghwparams0 register value + * @return + * RET_SUCCESS: if host mode setup is successful + * RET_FAIL: if host mode setup fails + */ +int dwc3_set_usb_host_mode(uint32_t ghwparams0); + +#endif /* _SOCFPGA_DWC3_LL_H_ */ diff --git a/src/portable/synopsys/dwc3/dwc3_socfpga.h b/src/portable/synopsys/dwc3/dwc3_socfpga.h new file mode 100644 index 000000000..e3d538f29 --- /dev/null +++ b/src/portable/synopsys/dwc3/dwc3_socfpga.h @@ -0,0 +1,286 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021, Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#ifndef DWC3_SOCFPGA_H_ +#define DWC3_SOCFPGA_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +// EP_MAX : Max number of bi-directional endpoints including EP0 +// EP_FIFO_SIZE : Size of dedicated USB SRAM +#if CFG_TUSB_MCU == OPT_MCU_STM32F1 + + #define USB_OTG_HS_PERIPH_BASE USB_OTG_HS_BASE_NS + #define OTG_HS_IRQn USB_OTG_HS_IRQn + #define EP_MAX_HS 9 + #define EP_FIFO_SIZE_HS 4096 +#else + #error "Unsupported MCUs" +#endif + +// OTG HS always has higher number of endpoints than FS +#ifdef USB_OTG_HS_PERIPH_BASE + #define DWC2_EP_MAX EP_MAX_HS +#else + #define DWC2_EP_MAX EP_MAX_FS +#endif + +// On STM32 for consistency we associate +// - Port0 to OTG_FS, and Port1 to OTG_HS +static const dwc2_controller_t _dwc2_controller[] = { + #ifdef USB_OTG_FS_PERIPH_BASE + { .reg_base = USB_OTG_FS_PERIPH_BASE, .irqnum = OTG_FS_IRQn, .ep_count = EP_MAX_FS, .ep_fifo_size = EP_FIFO_SIZE_FS }, + #endif + + #ifdef USB_OTG_HS_PERIPH_BASE + { .reg_base = USB_OTG_HS_PERIPH_BASE, .irqnum = OTG_HS_IRQn, .ep_count = EP_MAX_HS, .ep_fifo_size = EP_FIFO_SIZE_HS }, + #endif +}; + +//--------------------------------------------------------------------+ +// +//--------------------------------------------------------------------+ + +// SystemCoreClock is already included by family header +// extern uint32_t SystemCoreClock; + +TU_ATTR_ALWAYS_INLINE static inline void dwc2_int_set(uint8_t rhport, tusb_role_t role, bool enabled) { + (void) role; + const IRQn_Type irqn = (IRQn_Type) _dwc2_controller[rhport].irqnum; + if (enabled) { + NVIC_EnableIRQ(irqn); + } else { + NVIC_DisableIRQ(irqn); + } +} + +#define dwc2_dcd_int_enable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, true) +#define dwc2_dcd_int_disable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, false) + + +TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) { + // try to delay for 1 ms + uint32_t count = SystemCoreClock / 1000; + while (count--) __NOP(); +} + +// MCU specific PHY init, called BEFORE core reset +// - dwc2 3.30a (H5) use USB_HS_PHYC +// - dwc2 4.11a (U5) use femtoPHY +// - dwc2 x.xxx (WBA) use USB_OTG_HS +static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) { + if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) { + // Enable on-chip FS PHY + dwc2->stm32_gccfg |= STM32_GCCFG_PWRDWN; + + // https://community.st.com/t5/stm32cubemx-mcus/why-stm32h743-usb-fs-doesn-t-work-if-freertos-tickless-idle/m-p/349480#M18867 + // H7 running on full-speed phy need to disable ULPI clock in sleep mode. + // Otherwise, USB won't work when mcu executing WFI/WFE instruction i.e tick-less RTOS. + // Note: there may be other family that is affected by this, but only H7 and F7 is tested so far + #if defined(USB_OTG_FS_PERIPH_BASE) && defined(RCC_AHB1LPENR_USB2OTGFSULPILPEN) + if ( USB_OTG_FS_PERIPH_BASE == (uint32_t) dwc2 ) { + RCC->AHB1LPENR &= ~RCC_AHB1LPENR_USB2OTGFSULPILPEN; + } + #endif + + #if defined(USB_OTG_HS_PERIPH_BASE) && defined(RCC_AHB1LPENR_USB1OTGHSULPILPEN) + if ( USB_OTG_HS_PERIPH_BASE == (uint32_t) dwc2 ) { + RCC->AHB1LPENR &= ~RCC_AHB1LPENR_USB1OTGHSULPILPEN; + } + #endif + + #if defined(USB_OTG_HS_PERIPH_BASE) && defined(RCC_AHB1LPENR_OTGHSULPILPEN) + if ( USB_OTG_HS_PERIPH_BASE == (uint32_t) dwc2 ) { + RCC->AHB1LPENR &= ~RCC_AHB1LPENR_OTGHSULPILPEN; + } + #endif + + } else { +#if CFG_TUSB_MCU != OPT_MCU_STM32U5 && CFG_TUSB_MCU != OPT_MCU_STM32WBA + // Disable FS PHY, TODO on U5A5 (dwc2 4.11a) 16th bit is 'Host CDP behavior enable' + dwc2->stm32_gccfg &= ~STM32_GCCFG_PWRDWN; +#endif + // Enable on-chip HS PHY + if (hs_phy_type == GHWCFG2_HSPHY_UTMI || hs_phy_type == GHWCFG2_HSPHY_UTMI_ULPI) { + #ifdef USB_HS_PHYC + // Enable UTMI HS PHY + dwc2->stm32_gccfg |= STM32_GCCFG_PHYHSEN; + + // Enable LDO + USB_HS_PHYC->USB_HS_PHYC_LDO |= USB_HS_PHYC_LDO_ENABLE; + + // Wait until LDO ready + while ( 0 == (USB_HS_PHYC->USB_HS_PHYC_LDO & USB_HS_PHYC_LDO_STATUS) ) {} + + uint32_t phyc_pll = 0; + + // TODO Try to get HSE_VALUE from registers instead of depending CFLAGS + switch ( HSE_VALUE ) + { + case 12000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12MHZ ; break; + case 12500000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12_5MHZ ; break; + case 16000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_16MHZ ; break; + case 24000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_24MHZ ; break; + case 25000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_25MHZ ; break; + case 32000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_Msk ; break; // Value not defined in header + default: + TU_ASSERT(false, ); + } + USB_HS_PHYC->USB_HS_PHYC_PLL = phyc_pll; + + // Control the tuning interface of the High Speed PHY + // Use magic value (USB_HS_PHYC_TUNE_VALUE) from ST driver for F7 + USB_HS_PHYC->USB_HS_PHYC_TUNE |= 0x00000F13U; + + // Enable PLL internal PHY + USB_HS_PHYC->USB_HS_PHYC_PLL |= USB_HS_PHYC_PLL_PLLEN; + + // Wait ~2ms until the PLL is ready (there's no RDY bit to query) + tusb_time_delay_ms_api(2); + #else + + #endif + } + } +} + +// MCU specific PHY update, it is called AFTER init() and core reset +static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint8_t hs_phy_type) { + // used to set turnaround time for fullspeed, nothing to do in highspeed mode + if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) { + // Turnaround timeout depends on the AHB clock dictated by STM32 Reference Manual + uint32_t turnaround; + + if (SystemCoreClock >= 32000000u) { + turnaround = 0x6u; + } else if (SystemCoreClock >= 27500000u) { + turnaround = 0x7u; + } else if (SystemCoreClock >= 24000000u) { + turnaround = 0x8u; + } else if (SystemCoreClock >= 21800000u) { + turnaround = 0x9u; + } + else if (SystemCoreClock >= 20000000u) { + turnaround = 0xAu; + } + else if (SystemCoreClock >= 18500000u) { + turnaround = 0xBu; + } + else if (SystemCoreClock >= 17200000u) { + turnaround = 0xCu; + } + else if (SystemCoreClock >= 16000000u) { + turnaround = 0xDu; + } + else if (SystemCoreClock >= 15000000u) { + turnaround = 0xEu; + } + else { + turnaround = 0xFu; + } + + dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_TRDT_Msk) | (turnaround << GUSBCFG_TRDT_Pos); + } +} + +//------------- DCache -------------// +#if CFG_TUD_MEM_DCACHE_ENABLE || CFG_TUH_MEM_DCACHE_ENABLE + +typedef struct { + uintptr_t start; + uintptr_t end; +} mem_region_t; + +// Can be used to define additional uncached regions +#ifndef CFG_DWC2_MEM_UNCACHED_REGIONS +#define CFG_DWC2_MEM_UNCACHED_REGIONS +#endif + +static mem_region_t uncached_regions[] = { + // DTCM (although USB DMA can't transfer to/from DTCM) +#if CFG_TUSB_MCU == OPT_MCU_STM32H7 + {.start = 0x20000000, .end = 0x2001FFFF}, +#elif CFG_TUSB_MCU == OPT_MCU_STM32H7RS + // DTCM (although USB DMA can't transfer to/from DTCM) + {.start = 0x20000000, .end = 0x2002FFFF}, +#elif CFG_TUSB_MCU == OPT_MCU_STM32F7 + // DTCM + {.start = 0x20000000, .end = 0x2000FFFF}, +#else +#error "Cache maintenance is not supported yet" +#endif + CFG_DWC2_MEM_UNCACHED_REGIONS +}; + +TU_ATTR_ALWAYS_INLINE static inline uint32_t round_up_to_cache_line_size(uint32_t size) { + if (size & (CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT-1)) { + size = (size & ~(CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT-1)) + CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT; + } + return size; +} + +TU_ATTR_ALWAYS_INLINE static inline bool is_cache_mem(uintptr_t addr) { + for (unsigned int i = 0; i < TU_ARRAY_SIZE(uncached_regions); i++) { + if (uncached_regions[i].start <= addr && addr <= uncached_regions[i].end) { return false; } + } + return true; +} + +TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_clean(void const* addr, uint32_t data_size) { + const uintptr_t addr32 = (uintptr_t) addr; + if (is_cache_mem(addr32)) { + data_size = round_up_to_cache_line_size(data_size); + SCB_CleanDCache_by_Addr((uint32_t *) addr32, (int32_t) data_size); + } + return true; +} + +TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_invalidate(void const* addr, uint32_t data_size) { + const uintptr_t addr32 = (uintptr_t) addr; + if (is_cache_mem(addr32)) { + data_size = round_up_to_cache_line_size(data_size); + SCB_InvalidateDCache_by_Addr((void*) addr32, (int32_t) data_size); + } + return true; +} + +TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_clean_invalidate(void const* addr, uint32_t data_size) { + const uintptr_t addr32 = (uintptr_t) addr; + if (is_cache_mem(addr32)) { + data_size = round_up_to_cache_line_size(data_size); + SCB_CleanInvalidateDCache_by_Addr((uint32_t *) addr32, (int32_t) data_size); + } + return true; +} +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/portable/synopsys/dwc3/hcd_dwc3.c b/src/portable/synopsys/dwc3/hcd_dwc3.c new file mode 100644 index 000000000..257fa2833 --- /dev/null +++ b/src/portable/synopsys/dwc3/hcd_dwc3.c @@ -0,0 +1,1434 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2024 Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#include "tusb_option.h" + +#if CFG_TUH_ENABLED && defined(TUP_USBIP_DWC2) && !CFG_TUH_MAX3421 + +#if !(CFG_TUH_DWC2_SLAVE_ENABLE || CFG_TUH_DWC2_DMA_ENABLE) +#error DWC2 require either CFG_TUH_DWC2_SLAVE_ENABLE or CFG_TUH_DWC2_DMA_ENABLE to be enabled +#endif + +// Debug level for DWC2 +#define DWC2_DEBUG 2 + +#include "host/hcd.h" +#include "host/usbh.h" +#include "dwc2_common.h" + +// Max number of endpoints application can open, can be larger than DWC2_CHANNEL_COUNT_MAX +#ifndef CFG_TUH_DWC2_ENDPOINT_MAX +#define CFG_TUH_DWC2_ENDPOINT_MAX 16 +#endif + +#define DWC2_CHANNEL_COUNT_MAX 16 // absolute max channel count +TU_VERIFY_STATIC(CFG_TUH_DWC2_ENDPOINT_MAX <= 255, "currently only use 8-bit for index"); + +enum { + HPRT_W1_MASK = HPRT_CONN_DETECT | HPRT_ENABLE | HPRT_ENABLE_CHANGE | HPRT_OVER_CURRENT_CHANGE | HPRT_SUSPEND +}; + +enum { + HCD_XFER_ERROR_MAX = 3 +}; + +enum { + HCD_XFER_PERIOD_SPLIT_NYET_MAX = 3 +}; + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +// Host driver struct for each opened endpoint +typedef struct { + union { + uint32_t hcchar; + dwc2_channel_char_t hcchar_bm; + }; + union { + uint32_t hcsplt; + dwc2_channel_split_t hcsplt_bm; + }; + + struct TU_ATTR_PACKED { + uint32_t uframe_interval : 18; // micro-frame interval + uint32_t speed : 2; + uint32_t next_pid : 2; // PID for next transfer + uint32_t next_do_ping : 1; // Do PING for next transfer if possible (highspeed OUT) + // uint32_t : 9; + }; + + uint32_t uframe_countdown; // micro-frame count down to transfer for periodic, only need 18-bit + + uint8_t* buffer; + uint16_t buflen; +} hcd_endpoint_t; + +// Additional info for each channel when it is active +typedef struct { + volatile bool allocated; + uint8_t ep_id; + struct TU_ATTR_PACKED { + uint8_t err_count : 3; + uint8_t period_split_nyet_count : 3; + uint8_t halted_nyet : 1; + }; + uint8_t result; + + uint16_t xferred_bytes; // bytes that accumulate transferred though USB bus for the whole hcd_edpt_xfer(), which can + // be composed of multiple channel_xfer_start() (retry with NAK/NYET) + uint16_t fifo_bytes; // bytes written/read from/to FIFO (may not be transferred on USB bus). +} hcd_xfer_t; + +typedef struct { + hcd_xfer_t xfer[DWC2_CHANNEL_COUNT_MAX]; + hcd_endpoint_t edpt[CFG_TUH_DWC2_ENDPOINT_MAX]; +} hcd_data_t; + +hcd_data_t _hcd_data; + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- +TU_ATTR_ALWAYS_INLINE static inline uint8_t dwc2_channel_count(const dwc2_regs_t* dwc2) { + const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; + return tu_min8(ghwcfg2.num_host_ch + 1, DWC2_CHANNEL_COUNT_MAX); +} + +TU_ATTR_ALWAYS_INLINE static inline tusb_speed_t hprt_speed_get(dwc2_regs_t* dwc2) { + tusb_speed_t speed; + const dwc2_hprt_t hprt = {.value = dwc2->hprt}; + switch(hprt.speed) { + case HPRT_SPEED_HIGH: speed = TUSB_SPEED_HIGH; break; + case HPRT_SPEED_FULL: speed = TUSB_SPEED_FULL; break; + case HPRT_SPEED_LOW : speed = TUSB_SPEED_LOW ; break; + default: + speed = TUSB_SPEED_INVALID; + TU_BREAKPOINT(); + break; + } + return speed; +} + +TU_ATTR_ALWAYS_INLINE static inline bool dma_host_enabled(const dwc2_regs_t* dwc2) { + (void) dwc2; + // Internal DMA only + const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; + return CFG_TUH_DWC2_DMA_ENABLE && ghwcfg2.arch == GHWCFG2_ARCH_INTERNAL_DMA; +} + +#if CFG_TUH_MEM_DCACHE_ENABLE +bool hcd_dcache_clean(const void* addr, uint32_t data_size) { + TU_VERIFY(addr && data_size); + return dwc2_dcache_clean(addr, data_size); +} + +bool hcd_dcache_invalidate(const void* addr, uint32_t data_size) { + TU_VERIFY(addr && data_size); + return dwc2_dcache_invalidate(addr, data_size); +} + +bool hcd_dcache_clean_invalidate(const void* addr, uint32_t data_size) { + TU_VERIFY(addr && data_size); + return dwc2_dcache_clean_invalidate(addr, data_size); +} +#endif + +// Allocate a channel for new transfer +TU_ATTR_ALWAYS_INLINE static inline uint8_t channel_alloc(dwc2_regs_t* dwc2) { + const uint8_t max_channel = dwc2_channel_count(dwc2); + for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + if (!xfer->allocated) { + tu_memclr(xfer, sizeof(hcd_xfer_t)); + xfer->allocated = true; + return ch_id; + } + } + return TUSB_INDEX_INVALID_8; +} + +// Check if is periodic (interrupt/isochronous) +TU_ATTR_ALWAYS_INLINE static inline bool channel_is_periodic(uint32_t hcchar) { + const dwc2_channel_char_t hcchar_bm = {.value = hcchar}; + return hcchar_bm.ep_type == HCCHAR_EPTYPE_INTERRUPT || hcchar_bm.ep_type == HCCHAR_EPTYPE_ISOCHRONOUS; +} + +TU_ATTR_ALWAYS_INLINE static inline uint8_t req_queue_avail(const dwc2_regs_t* dwc2, bool is_period) { + if (is_period) { + const dwc2_hptxsts_t hptxsts = {.value = dwc2->hptxsts}; + return hptxsts.req_queue_available; + } else { + const dwc2_hnptxsts_t hnptxsts = {.value = dwc2->hnptxsts}; + return hnptxsts.req_queue_available; + } +} + +TU_ATTR_ALWAYS_INLINE static inline void channel_dealloc(dwc2_regs_t* dwc2, uint8_t ch_id) { + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + xfer->allocated = false; + dwc2->haintmsk &= ~TU_BIT(ch_id); +} + +TU_ATTR_ALWAYS_INLINE static inline bool channel_disable(const dwc2_regs_t* dwc2, dwc2_channel_t* channel) { + // disable also require request queue + TU_ASSERT(req_queue_avail(dwc2, channel_is_periodic(channel->hcchar))); + channel->hcintmsk |= HCINT_HALTED; + channel->hcchar |= HCCHAR_CHDIS | HCCHAR_CHENA; // must set both CHDIS and CHENA + return true; +} + +// attempt to send IN token to receive data +TU_ATTR_ALWAYS_INLINE static inline bool channel_send_in_token(const dwc2_regs_t* dwc2, dwc2_channel_t* channel) { + TU_ASSERT(req_queue_avail(dwc2, channel_is_periodic(channel->hcchar))); + channel->hcchar |= HCCHAR_CHENA; + return true; +} + +// Find currently enabled channel. Note: EP0 is bidirectional +TU_ATTR_ALWAYS_INLINE static inline uint8_t channel_find_enabled(dwc2_regs_t* dwc2, uint8_t dev_addr, uint8_t ep_num, uint8_t ep_dir) { + const uint8_t max_channel = dwc2_channel_count(dwc2); + for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { + if (_hcd_data.xfer[ch_id].allocated) { + const dwc2_channel_char_t hcchar = {.value = dwc2->channel[ch_id].hcchar}; + if (hcchar.dev_addr == dev_addr && hcchar.ep_num == ep_num && (ep_num == 0 || hcchar.ep_dir == ep_dir)) { + return ch_id; + } + } + } + return TUSB_INDEX_INVALID_8; +} + + +// Allocate a new endpoint +TU_ATTR_ALWAYS_INLINE static inline uint8_t edpt_alloc(void) { + for (uint32_t i = 0; i < CFG_TUH_DWC2_ENDPOINT_MAX; i++) { + hcd_endpoint_t* edpt = &_hcd_data.edpt[i]; + if (edpt->hcchar_bm.enable == 0) { + tu_memclr(edpt, sizeof(hcd_endpoint_t)); + edpt->hcchar_bm.enable = 1; + return i; + } + } + return TUSB_INDEX_INVALID_8; +} + +// Find a endpoint that is opened previously with hcd_edpt_open() +// Note: EP0 is bidirectional +TU_ATTR_ALWAYS_INLINE static inline uint8_t edpt_find_opened(uint8_t dev_addr, uint8_t ep_num, uint8_t ep_dir) { + for (uint8_t i = 0; i < (uint8_t)CFG_TUH_DWC2_ENDPOINT_MAX; i++) { + const dwc2_channel_char_t* hcchar_bm = &_hcd_data.edpt[i].hcchar_bm; + if (hcchar_bm->enable && hcchar_bm->dev_addr == dev_addr && + hcchar_bm->ep_num == ep_num && (ep_num == 0 || hcchar_bm->ep_dir == ep_dir)) { + return i; + } + } + return TUSB_INDEX_INVALID_8; +} + +TU_ATTR_ALWAYS_INLINE static inline uint16_t cal_packet_count(uint16_t len, uint16_t ep_size) { + if (len == 0) { + return 1; + } else { + return tu_div_ceil(len, ep_size); + } +} + +TU_ATTR_ALWAYS_INLINE static inline uint8_t cal_next_pid(uint8_t pid, uint8_t packet_count) { + if (packet_count & 0x01) { + return pid ^ 0x02; // toggle DATA0 and DATA1 + } else { + return pid; + } +} + +//-------------------------------------------------------------------- +// +//-------------------------------------------------------------------- + +/* USB Data FIFO Layout + + The FIFO is split up into + - EPInfo: for storing DMA metadata (check dcd_dwc2.c for more details) + - 1 RX FIFO: for receiving data + - 1 TX FIFO for non-periodic (NPTX) + - 1 TX FIFO for periodic (PTX) + + We allocated TX FIFO from top to bottom (using top pointer), this to allow the RX FIFO to grow dynamically which is + possible since the free space is located between the RX and TX FIFOs. + + ----------------- ep_fifo_size + | HCDMAn | + |--------------|-- gdfifocfg.EPINFOBASE (max is ghwcfg3.dfifo_depth) + | Non-Periodic | + | TX FIFO | + |--------------|--- GNPTXFSIZ.addr (fixed size) + | Periodic | + | TX FIFO | + |--------------|--- HPTXFSIZ.addr (expandable downward) + | FREE | + | | + |--------------|-- GRXFSIZ (expandable upward) + | RX FIFO | + ---------------- 0 +*/ + +/* Programming Guide 2.1.2 FIFO RAM allocation + * RX + * - Largest-EPsize/4 + 2 (status info). recommended x2 if high bandwidth or multiple ISO are used. + * - 2 for transfer complete and channel halted status + * - 1 for each Control/Bulk out endpoint to Handle NAK/NYET (i.e max is number of host channel) + * + * TX non-periodic (NPTX) + * - At least largest-EPsize/4, recommended x2 + * + * TX periodic (PTX) + * - At least largest-EPsize*MulCount/4 (MulCount up to 3 for high-bandwidth ISO/interrupt) +*/ +static void dfifo_host_init(uint8_t rhport) { + const dwc2_controller_t* dwc2_controller = &_dwc2_controller[rhport]; + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; + + // Scatter/Gather DMA mode is not yet supported. Buffer DMA only need 1 words per channel + const bool is_dma = dma_host_enabled(dwc2); + uint16_t dfifo_top = dwc2_controller->ep_fifo_size/4; + if (is_dma) { + dfifo_top -= ghwcfg2.num_host_ch; + } + + // fixed allocation for now, improve later: + // - ptx_largest is limited to 256 for FS since most FS core only has 1024 bytes total + bool is_highspeed = dwc2_core_is_highspeed(dwc2, TUSB_ROLE_HOST); + uint32_t nptx_largest = is_highspeed ? TUSB_EPSIZE_BULK_HS/4 : TUSB_EPSIZE_BULK_FS/4; + uint32_t ptx_largest = is_highspeed ? TUSB_EPSIZE_ISO_HS_MAX/4 : 256/4; + + uint16_t nptxfsiz = 2 * nptx_largest; + uint16_t rxfsiz = 2 * (ptx_largest + 2) + ghwcfg2.num_host_ch; + TU_ASSERT(dfifo_top >= (nptxfsiz + rxfsiz),); + uint16_t ptxfsiz = dfifo_top - (nptxfsiz + rxfsiz); + + dwc2->gdfifocfg = (dfifo_top << GDFIFOCFG_EPINFOBASE_SHIFT) | dfifo_top; + + dfifo_top -= rxfsiz; + dwc2->grxfsiz = rxfsiz; + + dfifo_top -= nptxfsiz; + dwc2->gnptxfsiz = tu_u32_from_u16(nptxfsiz, dfifo_top); + + dfifo_top -= ptxfsiz; + dwc2->hptxfsiz = tu_u32_from_u16(ptxfsiz, dfifo_top); +} + +//--------------------------------------------------------------------+ +// Controller API +//--------------------------------------------------------------------+ + +// optional hcd configuration, called by tuh_configure() +bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) { + (void) rhport; + (void) cfg_id; + (void) cfg_param; + + return true; +} + +// Initialize controller to host mode +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + (void) rh_init; + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + + tu_memclr(&_hcd_data, sizeof(_hcd_data)); + + // Core Initialization + const bool is_highspeed = dwc2_core_is_highspeed(dwc2, TUSB_ROLE_HOST); + const bool is_dma = dma_host_enabled(dwc2); + TU_ASSERT(dwc2_core_init(rhport, is_highspeed, is_dma)); + + //------------- 3.1 Host Initialization -------------// + + // work at max supported speed + dwc2->hcfg &= ~HCFG_FSLS_ONLY; + + // Enable HFIR reload + if (dwc2->gsnpsid >= DWC2_CORE_REV_2_92a) { + dwc2->hfir |= HFIR_RELOAD_CTRL; + } + + // force host mode and wait for mode switch + dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_FDMOD) | GUSBCFG_FHMOD; +#if CFG_TUSB_MCU == OPT_MCU_STM32N6 + // No hardware detection of Vbus B-session is available on the STM32N6 + dwc2->stm32_gccfg &= ~STM32_GCCFG_VBVALOVAL; +#endif + while ((dwc2->gintsts & GINTSTS_CMOD) != GINTSTS_CMODE_HOST) {} + + // configure fixed-allocated fifo scheme + dfifo_host_init(rhport); + + dwc2->hprt = HPRT_W1_MASK; // clear all write-1-clear bits + dwc2->hprt = HPRT_POWER; // turn on VBUS + + // Enable required interrupts + dwc2->gintmsk |= GINTSTS_OTGINT | GINTSTS_CONIDSTSCHNG | GINTSTS_HPRTINT | GINTSTS_HCINT | GINTSTS_DISCINT; + + // NPTX can hold at least 2 packet, change interrupt level to half-empty + uint32_t gahbcfg = dwc2->gahbcfg & ~GAHBCFG_TX_FIFO_EPMTY_LVL; + gahbcfg |= GAHBCFG_GINT; // Enable global interrupt + dwc2->gahbcfg = gahbcfg; + + return true; +} + +// Enable USB interrupt +void hcd_int_enable (uint8_t rhport) { + dwc2_int_set(rhport, TUSB_ROLE_HOST, true); +} + +// Disable USB interrupt +void hcd_int_disable(uint8_t rhport) { + dwc2_int_set(rhport, TUSB_ROLE_HOST, false); +} + +// Get frame number (1ms) +uint32_t hcd_frame_number(uint8_t rhport) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + return dwc2->hfnum & HFNUM_FRNUM_Msk; +} + +//--------------------------------------------------------------------+ +// Port API +//--------------------------------------------------------------------+ + +// Get the current connect status of roothub port +bool hcd_port_connect_status(uint8_t rhport) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + return dwc2->hprt & HPRT_CONN_STATUS; +} + +// Reset USB bus on the port. Return immediately, bus reset sequence may not be complete. +// Some port would require hcd_port_reset_end() to be invoked after 10ms to complete the reset sequence. +void hcd_port_reset(uint8_t rhport) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + uint32_t hprt = dwc2->hprt & ~HPRT_W1_MASK; + hprt |= HPRT_RESET; + dwc2->hprt = hprt; +} + +// Complete bus reset sequence, may be required by some controllers +void hcd_port_reset_end(uint8_t rhport) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + uint32_t hprt = dwc2->hprt & ~HPRT_W1_MASK; // skip w1c bits + hprt &= ~HPRT_RESET; + dwc2->hprt = hprt; +} + +// Get port link speed +tusb_speed_t hcd_port_speed_get(uint8_t rhport) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const tusb_speed_t speed = hprt_speed_get(dwc2); + return speed; +} + +// HCD closes all opened endpoints belong to this device +void hcd_device_close(uint8_t rhport, uint8_t dev_addr) { + (void) rhport; + for (uint8_t i = 0; i < (uint8_t) CFG_TUH_DWC2_ENDPOINT_MAX; i++) { + hcd_endpoint_t* edpt = &_hcd_data.edpt[i]; + if (edpt->hcchar_bm.enable && edpt->hcchar_bm.dev_addr == dev_addr) { + tu_memclr(edpt, sizeof(hcd_endpoint_t)); + } + } +} + +//--------------------------------------------------------------------+ +// Endpoints API +//--------------------------------------------------------------------+ + +// Open an endpoint +bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t* desc_ep) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const tusb_speed_t rh_speed = hprt_speed_get(dwc2); + + tuh_bus_info_t bus_info; + tuh_bus_info_get(dev_addr, &bus_info); + + // find a free endpoint + const uint8_t ep_id = edpt_alloc(); + TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); + hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; + + dwc2_channel_char_t* hcchar_bm = &edpt->hcchar_bm; + hcchar_bm->ep_size = tu_edpt_packet_size(desc_ep); + hcchar_bm->ep_num = tu_edpt_number(desc_ep->bEndpointAddress); + hcchar_bm->ep_dir = tu_edpt_dir(desc_ep->bEndpointAddress); + hcchar_bm->low_speed_dev = (bus_info.speed == TUSB_SPEED_LOW) ? 1 : 0; + hcchar_bm->ep_type = desc_ep->bmAttributes.xfer; // ep_type matches TUSB_XFER_* + hcchar_bm->err_multi_count = 0; + hcchar_bm->dev_addr = dev_addr; + hcchar_bm->odd_frame = 0; + hcchar_bm->disable = 0; + hcchar_bm->enable = 1; + + dwc2_channel_split_t* hcsplt_bm = &edpt->hcsplt_bm; + hcsplt_bm->hub_port = bus_info.hub_port; + hcsplt_bm->hub_addr = bus_info.hub_addr; + hcsplt_bm->xact_pos = 0; + hcsplt_bm->split_compl = 0; + hcsplt_bm->split_en = (rh_speed == TUSB_SPEED_HIGH && bus_info.speed != TUSB_SPEED_HIGH) ? 1 : 0; + + edpt->speed = bus_info.speed; + edpt->next_pid = HCTSIZ_PID_DATA0; + if (desc_ep->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) { + edpt->uframe_interval = 1 << (desc_ep->bInterval - 1); + if (bus_info.speed == TUSB_SPEED_FULL) { + edpt->uframe_interval <<= 3; + } + } else if (desc_ep->bmAttributes.xfer == TUSB_XFER_INTERRUPT) { + if (bus_info.speed == TUSB_SPEED_HIGH) { + edpt->uframe_interval = 1 << (desc_ep->bInterval - 1); + } else { + edpt->uframe_interval = desc_ep->bInterval << 3; + } + } + + return true; +} + +bool hcd_edpt_close(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) { + (void) rhport; (void) daddr; (void) ep_addr; + return false; // TODO not implemented yet +} + +// clean up channel after part of transfer is done but the whole urb is not complete +static void channel_xfer_out_wrapup(dwc2_regs_t* dwc2, uint8_t ch_id) { + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + const dwc2_channel_t* channel = &dwc2->channel[ch_id]; + hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; + + const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; + edpt->next_pid = hctsiz.pid; // save PID + + /* Since hctsiz.xfersize field reflects the number of bytes transferred via the AHB, not the USB) + * For IN: we can use hctsiz.xfersize as remaining bytes. + * For OUT: Must use the hctsiz.pktcnt field to determine how much data has been transferred. This field reflects the + * number of packets that have been transferred via the USB. This is always an integral number of packets if the + * transfer was halted before its normal completion. + */ + const uint16_t remain_packets = hctsiz.packet_count; + const dwc2_channel_char_t hcchar = {.value = channel->hcchar}; + const uint16_t total_packets = cal_packet_count(edpt->buflen, hcchar.ep_size); + const uint16_t actual_bytes = (total_packets - remain_packets) * hcchar.ep_size; + + xfer->fifo_bytes = 0; + xfer->xferred_bytes += actual_bytes; + edpt->buffer += actual_bytes; + edpt->buflen -= actual_bytes; +} + +static bool channel_xfer_start(dwc2_regs_t* dwc2, uint8_t ch_id) { + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; + dwc2_channel_char_t* hcchar_bm = &edpt->hcchar_bm; + dwc2_channel_t* channel = &dwc2->channel[ch_id]; + bool const is_period = channel_is_periodic(edpt->hcchar); + + // clear previous state + xfer->fifo_bytes = 0; + + // hchar: restore but don't enable yet + if (is_period) { + hcchar_bm->odd_frame = 1 - (dwc2->hfnum & 1); // transfer on next frame + } + channel->hcchar = (edpt->hcchar & ~HCCHAR_CHENA); + + // hctsiz: zero length packet still count as 1 + const uint16_t packet_count = cal_packet_count(edpt->buflen, hcchar_bm->ep_size); + dwc2_channel_tsize_t hctsiz = {.value = 0}; + hctsiz.pid = edpt->next_pid; // next PID is set in transfer complete interrupt + hctsiz.packet_count = packet_count; + hctsiz.xfer_size = edpt->buflen; + if (edpt->next_do_ping && edpt->speed == TUSB_SPEED_HIGH && + edpt->next_pid != HCTSIZ_PID_SETUP && hcchar_bm->ep_dir == TUSB_DIR_OUT) { + hctsiz.do_ping = 1; + } + channel->hctsiz = hctsiz.value; + edpt->next_do_ping = 0; + + // pre-calculate next PID based on packet count, adjusted in transfer complete interrupt if short packet + if (hcchar_bm->ep_num == 0) { + edpt->next_pid = HCTSIZ_PID_DATA1; // control data and status stage always start with DATA1 + } else { + edpt->next_pid = cal_next_pid(edpt->next_pid, packet_count); + } + + channel->hcsplt = edpt->hcsplt; + channel->hcint = 0xFFFFFFFFU; // clear all channel interrupts + + if (dma_host_enabled(dwc2)) { + uint32_t hcintmsk = HCINT_HALTED; + channel->hcintmsk = hcintmsk; + dwc2->haintmsk |= TU_BIT(ch_id); + + channel->hcdma = (uint32_t) edpt->buffer; + + if (hcchar_bm->ep_dir == TUSB_DIR_IN) { + channel_send_in_token(dwc2, channel); + } else { + hcd_dcache_clean(edpt->buffer, edpt->buflen); + channel->hcchar |= HCCHAR_CHENA; + } + } else { + uint32_t hcintmsk = HCINT_NAK | HCINT_XACT_ERR | HCINT_STALL | HCINT_XFER_COMPLETE | HCINT_DATATOGGLE_ERR; + if (hcchar_bm->ep_dir == TUSB_DIR_IN) { + hcintmsk |= HCINT_BABBLE_ERR | HCINT_DATATOGGLE_ERR | HCINT_ACK; + } else { + hcintmsk |= HCINT_NYET; + if (edpt->hcsplt_bm.split_en || hctsiz.do_ping) { + hcintmsk |= HCINT_ACK; + } + } + channel->hcintmsk = hcintmsk; + dwc2->haintmsk |= TU_BIT(ch_id); + + // enable channel for slave mode: + // - OUT: it will enable corresponding FIFO channel + // - IN : it will write an IN request to the Non-periodic Request Queue, this will have dwc2 trying to send + // IN Token. If we got NAK, we have to re-enable the channel again in the interrupt. Due to the way usbh stack only + // call hcd_edpt_xfer() once, we will need to manage de-allocate/re-allocate IN channel dynamically. + if (hcchar_bm->ep_dir == TUSB_DIR_IN) { + channel_send_in_token(dwc2, channel); + } else { + channel->hcchar |= HCCHAR_CHENA; + if (edpt->buflen > 0) { + // To prevent conflict with other channel, we will enable periodic/non-periodic FIFO empty interrupt accordingly + // And write packet in the interrupt handler + dwc2->gintmsk |= (is_period ? GINTSTS_PTX_FIFO_EMPTY : GINTSTS_NPTX_FIFO_EMPTY); + } + } + } + + return true; +} + +// kick-off transfer with an endpoint +static bool edpt_xfer_kickoff(dwc2_regs_t* dwc2, uint8_t ep_id) { + uint8_t ch_id = channel_alloc(dwc2); + TU_ASSERT(ch_id < 16); // all channel are in used + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + xfer->ep_id = ep_id; + xfer->result = XFER_RESULT_INVALID; + + return channel_xfer_start(dwc2, ch_id); +} + +// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked +bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const uint8_t ep_num = tu_edpt_number(ep_addr); + const uint8_t ep_dir = tu_edpt_dir(ep_addr); + + uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir); + TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); + hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; + + edpt->buffer = buffer; + edpt->buflen = buflen; + + if (ep_num == 0) { + // update ep_dir since control endpoint can switch direction + edpt->hcchar_bm.ep_dir = ep_dir; + } + + return edpt_xfer_kickoff(dwc2, ep_id); +} + +// Abort a queued transfer. Note: it can only abort transfer that has not been started +// Return true if a queued transfer is aborted, false if there is no transfer to abort +bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const uint8_t ep_num = tu_edpt_number(ep_addr); + const uint8_t ep_dir = tu_edpt_dir(ep_addr); + const uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir); + TU_VERIFY(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); + + // hcd_int_disable(rhport); + + // Find enabled channeled and disable it, channel will be de-allocated in the interrupt handler + const uint8_t ch_id = channel_find_enabled(dwc2, dev_addr, ep_num, ep_dir); + if (ch_id < 16) { + dwc2_channel_t* channel = &dwc2->channel[ch_id]; + channel_disable(dwc2, channel); + } + + // hcd_int_enable(rhport); + + return true; +} + +// Submit a special transfer to send 8-byte Setup Packet, when complete hcd_event_xfer_complete() must be invoked +bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, const uint8_t setup_packet[8]) { + uint8_t ep_id = edpt_find_opened(dev_addr, 0, TUSB_DIR_OUT); + TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); // no opened endpoint + hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; + edpt->next_pid = HCTSIZ_PID_SETUP; + + return hcd_edpt_xfer(rhport, dev_addr, 0, (uint8_t*)(uintptr_t) setup_packet, 8); +} + +// clear stall, data toggle is also reset to DATA0 +bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { + (void) rhport; + const uint8_t ep_num = tu_edpt_number(ep_addr); + const uint8_t ep_dir = tu_edpt_dir(ep_addr); + const uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir); + TU_VERIFY(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); + hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; + + edpt->next_pid = HCTSIZ_PID_DATA0; + + return true; +} + +//-------------------------------------------------------------------- +// HCD Event Handler +//-------------------------------------------------------------------- + +// retry an IN transfer, channel must be halted +static void channel_xfer_in_retry(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; + dwc2_channel_t* channel = &dwc2->channel[ch_id]; + dwc2_channel_char_t hcchar = {.value = channel->hcchar}; + + if (channel_is_periodic(hcchar.value)){ + const dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; + // retry immediately for periodic split NYET if we haven't reach max retry + if (hcsplt.split_en && hcsplt.split_compl && (hcint & HCINT_NYET || xfer->halted_nyet)) { + xfer->period_split_nyet_count++; + xfer->halted_nyet = 0; + if (xfer->period_split_nyet_count < HCD_XFER_PERIOD_SPLIT_NYET_MAX) { + hcchar.odd_frame = 1 - (dwc2->hfnum & 1); // transfer on next frame + channel->hcchar = hcchar.value; + channel_send_in_token(dwc2, channel); + return; + } else { + // too many NYET, de-allocate channel with below code + xfer->period_split_nyet_count = 0; + } + } + + const uint32_t ucount = (hprt_speed_get(dwc2) == TUSB_SPEED_HIGH ? 1 : 8); + if (edpt->uframe_interval == ucount) { + // retry on next frame if bInterval is 1 + hcchar.odd_frame = 1 - (dwc2->hfnum & 1); + channel->hcchar = hcchar.value; + channel_send_in_token(dwc2, channel); + } else { + // otherwise, de-allocate channel, enable SOF set frame counter for later transfer + const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; + edpt->next_pid = hctsiz.pid; // save PID + edpt->uframe_countdown = edpt->uframe_interval - ucount; + // enable SOF interrupt if not already enabled + if (!(dwc2->gintmsk & GINTMSK_SOFM)) { + dwc2->gintsts = GINTSTS_SOF; + dwc2->gintmsk |= GINTMSK_SOFM; + } + // already halted, de-allocate channel (called from DMA isr) + channel_dealloc(dwc2, ch_id); + } + } else { + // for control/bulk: retry immediately + channel_send_in_token(dwc2, channel); + } +} + +#if CFG_TUSB_DEBUG +TU_ATTR_ALWAYS_INLINE static inline void print_hcint(uint32_t hcint) { + const char* str[] = { + "XFRC", "HALTED", "AHBERR", "STALL", + "NAK", "ACK", "NYET", "XERR", + "BBLERR", "FRMOR", "DTERR", "BNA", + "XCSERR", "DESC_LST" + }; + + for(uint32_t i=0; i<14; i++) { + if (hcint & TU_BIT(i)) { + TU_LOG1("%s ", str[i]); + } + } + TU_LOG1("\r\n"); +} +#endif + +#if CFG_TUH_DWC2_SLAVE_ENABLE +static void handle_rxflvl_irq(uint8_t rhport) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + + // Pop control word off FIFO + const dwc2_grxstsp_t grxstsp = {.value= dwc2->grxstsp}; + const uint8_t ch_id = grxstsp.ep_ch_num; + + switch (grxstsp.packet_status) { + case GRXSTS_PKTSTS_RX_DATA: { + // In packet received, pop this entry --> ACK interrupt + const uint16_t byte_count = grxstsp.byte_count; + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX,); + hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; + + if (byte_count) { + dfifo_read_packet(dwc2, edpt->buffer + xfer->xferred_bytes, byte_count); + xfer->xferred_bytes += byte_count; + xfer->fifo_bytes = byte_count; + } + break; + } + + case GRXSTS_PKTSTS_RX_COMPLETE: + // In transfer complete: After this entry is popped from the rx FIFO, dwc2 asserts a Transfer Completed + // interrupt --> handle_channel_irq() + break; + + case GRXSTS_PKTSTS_HOST_DATATOGGLE_ERR: + TU_ASSERT(0, ); // maybe try to change DToggle + break; + + case GRXSTS_PKTSTS_HOST_CHANNEL_HALTED: + // triggered when channel.hcchar_bm.disable is set + // TODO handle later + break; + + default: break; // ignore other status + } +} + +// return true if there is still pending data and need more ISR +static bool handle_txfifo_empty(dwc2_regs_t* dwc2, bool is_periodic) { + // Use period txsts for both p/np to get request queue space available (1-bit difference, it is small enough) + const dwc2_hptxsts_t txsts = {.value = (is_periodic ? dwc2->hptxsts : dwc2->hnptxsts)}; + + const uint8_t max_channel = dwc2_channel_count(dwc2); + for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { + dwc2_channel_t* channel = &dwc2->channel[ch_id]; + const dwc2_channel_char_t hcchar = {.value = channel->hcchar}; + // skip writing to FIFO if channel is expecting halted. + if (!(channel->hcintmsk & HCINT_HALTED) && (hcchar.ep_dir == TUSB_DIR_OUT)) { + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); + hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; + const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; + const uint16_t remain_packets = hctsiz.packet_count; + for (uint16_t i = 0; i < remain_packets; i++) { + const uint16_t remain_bytes = edpt->buflen - xfer->fifo_bytes; + const uint16_t xact_bytes = tu_min16(remain_bytes, hcchar.ep_size); + + // skip if there is not enough space in FIFO and RequestQueue. + // Packet's last word written to FIFO will trigger a request queue + if ((xact_bytes > (txsts.fifo_available << 2)) || (txsts.req_queue_available == 0)) { + return true; + } + + dfifo_write_packet(dwc2, ch_id, edpt->buffer + xfer->fifo_bytes, xact_bytes); + xfer->fifo_bytes += xact_bytes; + } + } + } + + return false; // no channel has pending data +} + +static bool handle_channel_in_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + dwc2_channel_t* channel = &dwc2->channel[ch_id]; + hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; + dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; + const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; + bool is_done = false; + + // if (hcsplt.split_en) { + // if (edpt->hcchar_bm.ep_num == 1) { + // TU_LOG1("Frame %u, ch %u: ep %u, hcint 0x%04lX ", dwc2->hfnum_bm.num, ch_id, hcsplt.ep_num, hcint); + // print_hcint(hcint); + // } + + if (hcint & HCINT_XFER_COMPLETE) { + if (edpt->hcchar_bm.ep_num != 0) { + edpt->next_pid = hctsiz.pid; // save pid (already toggled) + } + + const uint16_t remain_packets = hctsiz.packet_count; + if (hcsplt.split_en && remain_packets && xfer->fifo_bytes == edpt->hcchar_bm.ep_size) { + // Split can only complete 1 transaction (up to 1 packet) at a time, schedule more + hcsplt.split_compl = 0; + channel->hcsplt = hcsplt.value; + } else { + xfer->result = XFER_RESULT_SUCCESS; + } + + channel_disable(dwc2, channel); + } else if (hcint & (HCINT_XACT_ERR | HCINT_BABBLE_ERR | HCINT_STALL)) { + if (hcint & HCINT_STALL) { + xfer->result = XFER_RESULT_STALLED; + } else if (hcint & HCINT_BABBLE_ERR) { + xfer->result = XFER_RESULT_FAILED; + } else if (hcint & HCINT_XACT_ERR) { + xfer->err_count++; + channel->hcintmsk |= HCINT_ACK; + } + + channel_disable(dwc2, channel); + } else if (hcint & HCINT_NYET) { + // restart complete split + hcsplt.split_compl = 1; + channel->hcsplt = hcsplt.value; + xfer->halted_nyet = 1; + channel_disable(dwc2, channel); + } else if (hcint & HCINT_NAK) { + // NAK received, disable channel to flush all posted request and try again + if (hcsplt.split_en) { + hcsplt.split_compl = 0; // restart with start-split + channel->hcsplt = hcsplt.value; + } + + channel_disable(dwc2, channel); + } else if (hcint & HCINT_ACK) { + xfer->err_count = 0; + + if (hcsplt.split_en) { + if (!hcsplt.split_compl) { + // start split is ACK --> do complete split + channel->hcintmsk |= HCINT_NYET; + hcsplt.split_compl = 1; + channel->hcsplt = hcsplt.value; + channel_send_in_token(dwc2, channel); + } else { + // do nothing for complete split with DATA, this will trigger XferComplete and handled there + } + } else { + // ACK with data + const uint16_t remain_packets = hctsiz.packet_count; + if (remain_packets) { + // still more packet to receive, also reset to start split + hcsplt.split_compl = 0; + channel->hcsplt = hcsplt.value; + channel_send_in_token(dwc2, channel); + } + } + } else if (hcint & HCINT_HALTED) { + channel->hcintmsk &= ~HCINT_HALTED; + if (xfer->result != XFER_RESULT_INVALID) { + is_done = true; + } else if (xfer->err_count == HCD_XFER_ERROR_MAX) { + xfer->result = XFER_RESULT_FAILED; + is_done = true; + } else { + // got here due to NAK or NYET + channel_xfer_in_retry(dwc2, ch_id, hcint); + } + } else if (hcint & HCINT_DATATOGGLE_ERR) { + xfer->err_count = 0; + TU_ASSERT(false); + } + return is_done; +} + +static bool handle_channel_out_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + dwc2_channel_t* channel = &dwc2->channel[ch_id]; + hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; + dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; + bool is_done = false; + + if (hcint & HCINT_XFER_COMPLETE) { + is_done = true; + xfer->result = XFER_RESULT_SUCCESS; + channel->hcintmsk &= ~HCINT_ACK; + if (hcint & HCINT_NYET) { + // complete transfer with NYET, do ping next time + edpt->next_do_ping = 1; + } + } else if (hcint & HCINT_STALL) { + xfer->result = XFER_RESULT_STALLED; + channel_disable(dwc2, channel); + } else if (hcint & HCINT_NYET) { + xfer->err_count = 0; + if (hcsplt.split_en) { + // retry complete split + hcsplt.split_compl = 1; + channel->hcsplt = hcsplt.value; + channel->hcchar |= HCCHAR_CHENA; + } else { + edpt->next_do_ping = 1; + channel_xfer_out_wrapup(dwc2, ch_id); + channel_disable(dwc2, channel); + } + } else if (hcint & (HCINT_NAK | HCINT_XACT_ERR)) { + // clean up transfer so far, disable and start again later + channel_xfer_out_wrapup(dwc2, ch_id); + channel_disable(dwc2, channel); + if (hcint & HCINT_XACT_ERR) { + xfer->err_count++; + channel->hcintmsk |= HCINT_ACK; + } else { + // NAK disable channel to flush all posted request and try again + edpt->next_do_ping = 1; + xfer->err_count = 0; + } + } else if (hcint & HCINT_HALTED) { + channel->hcintmsk &= ~HCINT_HALTED; + if (xfer->result != XFER_RESULT_INVALID) { + is_done = true; + } else if (xfer->err_count == HCD_XFER_ERROR_MAX) { + xfer->result = XFER_RESULT_FAILED; + is_done = true; + } else { + // Got here due to NAK or NYET + TU_ASSERT(channel_xfer_start(dwc2, ch_id)); + } + } else if (hcint & HCINT_ACK) { + xfer->err_count = 0; + channel->hcintmsk &= ~HCINT_ACK; + if (hcsplt.split_en) { + if (!hcsplt.split_compl) { + // ACK for start split --> do complete split + hcsplt.split_compl = 1; + channel->hcsplt = hcsplt.value; + channel->hcchar |= HCCHAR_CHENA; + } + } else { + // ACK interrupt is only enabled for Split and PING + // ACK for PING, which mean device is ready to receive data + channel->hctsiz &= ~HCTSIZ_DOPING; // HC already cleared PING bit, but we clear anyway + channel->hcchar |= HCCHAR_CHENA; + } + } + + if (is_done) { + xfer->xferred_bytes += xfer->fifo_bytes; + xfer->fifo_bytes = 0; + } + + return is_done; +} +#endif + +#if CFG_TUH_DWC2_DMA_ENABLE +static bool handle_channel_in_dma(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + dwc2_channel_t* channel = &dwc2->channel[ch_id]; + hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; + dwc2_channel_char_t hcchar = {.value = channel->hcchar}; + dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; + const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; + + bool is_done = false; + + // TU_LOG1("in hcint = %02lX\r\n", hcint); + + if (hcint & HCINT_HALTED) { + if (hcint & (HCINT_XFER_COMPLETE | HCINT_STALL | HCINT_BABBLE_ERR)) { + const uint16_t remain_bytes = (uint16_t) hctsiz.xfer_size; + const uint16_t remain_packets = hctsiz.packet_count; + const uint16_t actual_len = edpt->buflen - remain_bytes; + xfer->xferred_bytes += actual_len; + + is_done = true; + + if (hcint & HCINT_STALL) { + xfer->result = XFER_RESULT_STALLED; + } else if (hcint & HCINT_BABBLE_ERR) { + xfer->result = XFER_RESULT_FAILED; + } else if (hcsplt.split_en && remain_packets && actual_len == hcchar.ep_size) { + // Split can only complete 1 transaction (up to 1 packet) at a time, schedule more + is_done = false; + edpt->buffer += actual_len; + edpt->buflen -= actual_len; + + hcsplt.split_compl = 0; + channel->hcsplt = hcsplt.value; + channel_xfer_in_retry(dwc2, ch_id, hcint); + } else { + xfer->result = XFER_RESULT_SUCCESS; + } + + xfer->err_count = 0; + channel->hcintmsk &= ~HCINT_ACK; + } else if (hcint & HCINT_XACT_ERR) { + xfer->err_count++; + if (xfer->err_count >= HCD_XFER_ERROR_MAX) { + is_done = true; + xfer->result = XFER_RESULT_FAILED; + } else { + channel->hcintmsk |= HCINT_ACK | HCINT_NAK | HCINT_DATATOGGLE_ERR; + hcsplt.split_compl = 0; + channel->hcsplt = hcsplt.value; + channel_xfer_in_retry(dwc2, ch_id, hcint); + } + } else if (hcint & HCINT_NYET) { + // Must handle nyet before nak or ack. Could get a nyet at the same time as either of those on a BULK/CONTROL + // OUT that started with a PING. The nyet takes precedence. + if (hcsplt.split_en) { + // split not yet mean hub has no data, retry complete split + hcsplt.split_compl = 1; + channel->hcsplt = hcsplt.value; + channel_xfer_in_retry(dwc2, ch_id, hcint); + } + } else if (hcint & HCINT_ACK) { + xfer->err_count = 0; + channel->hcintmsk &= ~HCINT_ACK; + if (hcsplt.split_en) { + // start split is ACK --> do complete split + // TODO: for ISO must use xact_pos to plan complete split based on microframe (up to 187.5 bytes/uframe) + hcsplt.split_compl = 1; + channel->hcsplt = hcsplt.value; + if (channel_is_periodic(channel->hcchar)) { + hcchar.odd_frame = 1 - (dwc2->hfnum & 1); // transfer on next frame + channel->hcchar = hcchar.value; + } + channel_send_in_token(dwc2, channel); + } + } else if (hcint & (HCINT_NAK | HCINT_DATATOGGLE_ERR)) { + xfer->err_count = 0; + channel->hcintmsk &= ~(HCINT_NAK | HCINT_DATATOGGLE_ERR); + hcsplt.split_compl = 0; // restart with start-split + channel->hcsplt = hcsplt.value; + channel_xfer_in_retry(dwc2, ch_id, hcint); + } else if (hcint & HCINT_FARME_OVERRUN) { + // retry start-split in next binterval + channel_xfer_in_retry(dwc2, ch_id, hcint); + } + } + + return is_done; +} + +static bool handle_channel_out_dma(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + dwc2_channel_t* channel = &dwc2->channel[ch_id]; + hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; + const dwc2_channel_char_t hcchar = {.value = channel->hcchar}; + dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; + + bool is_done = false; + + // TU_LOG1("out hcint = %02lX\r\n", hcint); + + if (hcint & HCINT_HALTED) { + if (hcint & (HCINT_XFER_COMPLETE | HCINT_STALL)) { + is_done = true; + xfer->err_count = 0; + if (hcint & HCINT_XFER_COMPLETE) { + xfer->result = XFER_RESULT_SUCCESS; + xfer->xferred_bytes += edpt->buflen; + } else { + xfer->result = XFER_RESULT_STALLED; + channel_xfer_out_wrapup(dwc2, ch_id); + } + channel->hcintmsk &= ~HCINT_ACK; + } else if (hcint & HCINT_XACT_ERR) { + if (hcint & (HCINT_NAK | HCINT_NYET | HCINT_ACK)) { + xfer->err_count = 0; + // clean up transfer so far and start again + channel_xfer_out_wrapup(dwc2, ch_id); + channel_xfer_start(dwc2, ch_id); + } else { + xfer->err_count++; + if (xfer->err_count >= HCD_XFER_ERROR_MAX) { + xfer->result = XFER_RESULT_FAILED; + is_done = true; + } else { + // clean up transfer so far and start again + channel_xfer_out_wrapup(dwc2, ch_id); + channel_xfer_start(dwc2, ch_id); + } + } + } else if (hcint & HCINT_NYET) { + if (hcsplt.split_en && hcsplt.split_compl) { + // split not yet mean hub has no data, retry complete split + hcsplt.split_compl = 1; + channel->hcsplt = hcsplt.value; + channel->hcchar |= HCCHAR_CHENA; + } + } else if (hcint & HCINT_ACK) { + xfer->err_count = 0; + if (hcsplt.split_en && !hcsplt.split_compl) { + // start split is ACK --> do complete split + hcsplt.split_compl = 1; + channel->hcsplt = hcsplt.value; + channel->hcchar |= HCCHAR_CHENA; + } + } + } else if (hcint & HCINT_ACK) { + xfer->err_count = 0; + channel->hcintmsk &= ~HCINT_ACK; + } + + return is_done; +} +#endif + +static void handle_channel_irq(uint8_t rhport, bool in_isr) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const bool is_dma = dma_host_enabled(dwc2); + const uint8_t max_channel = dwc2_channel_count(dwc2); + + for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { + if (tu_bit_test(dwc2->haint, ch_id)) { + dwc2_channel_t* channel = &dwc2->channel[ch_id]; + hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; + TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX,); + dwc2_channel_char_t hcchar = {.value = channel->hcchar}; + + const uint32_t hcint = channel->hcint; + channel->hcint = hcint; // clear interrupt + + bool is_done = false; + if (is_dma) { + #if CFG_TUH_DWC2_DMA_ENABLE + if (hcchar.ep_dir == TUSB_DIR_OUT) { + is_done = handle_channel_out_dma(dwc2, ch_id, hcint); + } else { + is_done = handle_channel_in_dma(dwc2, ch_id, hcint); + if (is_done && (channel->hcdma > xfer->xferred_bytes)) { + // hcdma is increased by word --> need to align4 + hcd_dcache_invalidate((void*) tu_align4(channel->hcdma - xfer->xferred_bytes), xfer->xferred_bytes); + } + } + #endif + } else { + #if CFG_TUH_DWC2_SLAVE_ENABLE + if (hcchar.ep_dir == TUSB_DIR_OUT) { + is_done = handle_channel_out_slave(dwc2, ch_id, hcint); + } else { + is_done = handle_channel_in_slave(dwc2, ch_id, hcint); + } + #endif + } + + if (is_done) { + const uint8_t ep_addr = tu_edpt_addr(hcchar.ep_num, hcchar.ep_dir); + hcd_event_xfer_complete(hcchar.dev_addr, ep_addr, xfer->xferred_bytes, (xfer_result_t)xfer->result, in_isr); + channel_dealloc(dwc2, ch_id); + } + } + } +} + +// SOF is enabled for scheduled periodic transfer +static bool handle_sof_irq(uint8_t rhport, bool in_isr) { + (void) in_isr; + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + dwc2->gintsts = GINTSTS_SOF; // Clear the SOF interrupt flag + + bool more_isr = false; + + // If highspeed then SOF is 125us, else 1ms + const uint32_t ucount = (hprt_speed_get(dwc2) == TUSB_SPEED_HIGH ? 1 : 8); + + for(uint8_t ep_id = 0; ep_id < CFG_TUH_DWC2_ENDPOINT_MAX; ep_id++) { + hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; + if (edpt->hcchar_bm.enable && channel_is_periodic(edpt->hcchar) && edpt->uframe_countdown > 0) { + edpt->uframe_countdown -= tu_min32(ucount, edpt->uframe_countdown); + if (edpt->uframe_countdown == 0) { + if (!edpt_xfer_kickoff(dwc2, ep_id)) { + edpt->uframe_countdown = ucount; // failed to start, try again next frame + } + } + + more_isr = true; + } + } + + return more_isr; +} + +// Config HCFG FS/LS clock and HFIR for SOF interval according to link speed (value is in PHY clock unit) +static void port0_enable(dwc2_regs_t* dwc2, tusb_speed_t speed) { + uint32_t hcfg = dwc2->hcfg & ~HCFG_FSLS_PHYCLK_SEL; + + const dwc2_gusbcfg_t gusbcfg = {.value = dwc2->gusbcfg}; + uint32_t phy_clock; + + if (gusbcfg.phy_sel) { + phy_clock = 48; // dedicated FS is 48Mhz + if (speed == TUSB_SPEED_LOW) { + hcfg |= HCFG_FSLS_PHYCLK_SEL_6MHZ; + } else { + hcfg |= HCFG_FSLS_PHYCLK_SEL_48MHZ; + } + } else { + if (gusbcfg.ulpi_utmi_sel) { + phy_clock = 60; // ULPI 8-bit is 60Mhz + } else { + // UTMI+ 16-bit is 30Mhz, 8-bit is 60Mhz + phy_clock = gusbcfg.phy_if16 ? 30 : 60; + + // Enable UTMI+ low power mode 48Mhz external clock if not highspeed + if (speed == TUSB_SPEED_HIGH) { + dwc2->gusbcfg &= ~GUSBCFG_PHYLPCS; + } else { + dwc2->gusbcfg |= GUSBCFG_PHYLPCS; + // may need to reset port + } + } + hcfg |= HCFG_FSLS_PHYCLK_SEL_30_60MHZ; + } + + dwc2->hcfg = hcfg; + + uint32_t hfir = dwc2->hfir & ~HFIR_FRIVL_Msk; + if (speed == TUSB_SPEED_HIGH) { + hfir |= 125*phy_clock - 1; // The "- 1" is the correct value. The Synopsys databook was corrected in 3.30a + } else { + hfir |= 1000*phy_clock - 1; + } + + dwc2->hfir = hfir; +} + +/* Handle Host Port interrupt, possible source are: + - Connection Detection + - Enable Change + - Over Current Change +*/ +static void handle_hprt_irq(uint8_t rhport, bool in_isr) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const dwc2_hprt_t hprt_bm = {.value = dwc2->hprt}; + uint32_t hprt = hprt_bm.value & ~HPRT_W1_MASK; + + if (hprt_bm.conn_detected) { + // Port Connect Detect + hprt |= HPRT_CONN_DETECT; + + if (hprt_bm.conn_status) { + hcd_event_device_attach(rhport, in_isr); + } + } + + if (hprt_bm.enable_change) { + // Port enable change + hprt |= HPRT_ENABLE_CHANGE; + + if (hprt_bm.enable) { + // Port enable + const tusb_speed_t speed = hprt_speed_get(dwc2); + port0_enable(dwc2, speed); + } else { + // TU_ASSERT(false, ); + } + } + + dwc2->hprt = hprt; // clear interrupt +} + +/* Interrupt Hierarchy + HCINTn HPRT + | | + HAINT.CHn | + | | + GINTSTS : HCInt | PrtInt | NPTxFEmp | PTxFEmpp | RXFLVL | SOF +*/ +void hcd_int_handler(uint8_t rhport, bool in_isr) { + dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const uint32_t gintmsk = dwc2->gintmsk; + const uint32_t gintsts = dwc2->gintsts & gintmsk; + + // TU_LOG1_HEX(gintsts); + + if (gintsts & GINTSTS_CONIDSTSCHNG) { + // Connector ID status change + dwc2->gintsts = GINTSTS_CONIDSTSCHNG; + + //if (dwc2->gotgctl) + // dwc2->hprt = HPRT_POWER; // power on port to turn on VBUS + //dwc2->gintmsk |= GINTMSK_PRTIM; + // TODO wait for SRP if OTG + } + + if (gintsts & GINTSTS_SOF) { + const bool more_sof = handle_sof_irq(rhport, in_isr); + if (!more_sof) { + dwc2->gintmsk &= ~GINTSTS_SOF; + } + } + + if (gintsts & GINTSTS_HPRTINT) { + // Host port interrupt: source is cleared in HPRT register + // TU_LOG1_HEX(dwc2->hprt); + handle_hprt_irq(rhport, in_isr); + } + + if (gintsts & GINTSTS_HCINT) { + // Host Channel interrupt: source is cleared in HCINT register + // must be handled after TX FIFO empty + handle_channel_irq(rhport, in_isr); + } + + if (gintsts & GINTSTS_DISCINT) { + // Device disconnected + dwc2->gintsts = GINTSTS_DISCINT; + + if (!(dwc2->hprt & HPRT_CONN_STATUS)) { + hcd_event_device_remove(rhport, in_isr); + } + } + +#if CFG_TUH_DWC2_SLAVE_ENABLE + // RxFIFO non-empty interrupt handling + if (gintsts & GINTSTS_RXFLVL) { + // RXFLVL bit is read-only + dwc2->gintmsk &= ~GINTSTS_RXFLVL; // disable RXFLVL interrupt while reading + + do { + handle_rxflvl_irq(rhport); // read all packets + } while(dwc2->gintsts & GINTSTS_RXFLVL); + + dwc2->gintmsk |= GINTSTS_RXFLVL; + } + + if (gintsts & GINTSTS_NPTX_FIFO_EMPTY) { + // NPTX FIFO empty interrupt, this is read-only and cleared by hardware when FIFO is written + const bool more_nptxfe = handle_txfifo_empty(dwc2, false); + if (!more_nptxfe) { + // no more pending packet, disable interrupt + dwc2->gintmsk &= ~GINTSTS_NPTX_FIFO_EMPTY; + } + } + + if (gintsts & GINTSTS_PTX_FIFO_EMPTY) { + // PTX FIFO empty interrupt, this is read-only and cleared by hardware when FIFO is written + const bool more_ptxfe = handle_txfifo_empty(dwc2, true); + if (!more_ptxfe) { + // no more pending packet, disable interrupt + dwc2->gintmsk &= ~GINTSTS_PTX_FIFO_EMPTY; + } + } +#endif +} + +#endif diff --git a/src/portable/synopsys/dwc3/socfpga_usb3_reg.h b/src/portable/synopsys/dwc3/socfpga_usb3_reg.h new file mode 100644 index 000000000..d39c52544 --- /dev/null +++ b/src/portable/synopsys/dwc3/socfpga_usb3_reg.h @@ -0,0 +1,2660 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * This contains the register defintions for Agilex5 USB3.1 controller + */ + +#ifndef __SOCFPGA_USB3_REG_H__ +#define __SOCFPGA_USB3_REG_H__ + +/* USB 3.1 controller base address */ +#define USBBASE (0x11000000U) + +/* CAPLENGTH */ +#define USB3_CAPLENGTH 0x0000U +/* HCSPARAMS1 */ +#define USB3_HCSPARAMS1 0x0004U +/* HCSPARAMS2 */ +#define USB3_HCSPARAMS2 0x0008U +/* HCSPARAMS3 */ +#define USB3_HCSPARAMS3 0x000CU +/* HCCPARAMS1 */ +#define USB3_HCCPARAMS1 0x0010U +/* DBOFF */ +#define USB3_DBOFF 0x0014U +/* RTSOFF */ +#define USB3_RTSOFF 0x0018U +/* HCCPARAMS2 */ +#define USB3_HCCPARAMS2 0x001CU +/* USBCMD */ +#define USB3_USBCMD 0x0020U +/* USBSTS */ +#define USB3_USBSTS 0x0024U +/* PAGESIZE */ +#define USB3_PAGESIZE 0x0028U +/* DNCTRL */ +#define USB3_DNCTRL 0x0034U +/* CRCR_LO */ +#define USB3_CRCR_LO 0x0038U +/* CRCR_HI */ +#define USB3_CRCR_HI 0x003CU +/* DCBAAP_LO */ +#define USB3_DCBAAP_LO 0x0050U +/* DCBAAP_HI */ +#define USB3_DCBAAP_HI 0x0054U +/* CONFIG */ +#define USB3_CONFIG 0x0058U +/* PORTSC_20 */ +#define USB3_PORTSC_20 0x0000U +/* PORTPMSC_20 */ +#define USB3_PORTPMSC_20 0x0004U +/* PORTLI_20 */ +#define USB3_PORTLI_20 0x0008U +/* PORTHLPMC_20 */ +#define USB3_PORTHLPMC_20 0x000CU +/* PORTSC_30 */ +#define USB3_PORTSC_30 0x0000U +/* PORTPMSC_30 */ +#define USB3_PORTPMSC_30 0x0004U +/* PORTLI_30 */ +#define USB3_PORTLI_30 0x0008U +/* PORTHLPMC_30 */ +#define USB3_PORTHLPMC_30 0x000CU +/* USBLEGSUP */ +#define USB3_USBLEGSUP 0x0440U +/* USBLEGCTLSTS */ +#define USB3_USBLEGCTLSTS 0x0444U +/* SUPTPRT2_DW0 */ +#define USB3_SUPTPRT2_DW0 0x0450U +/* SUPTPRT2_DW1 */ +#define USB3_SUPTPRT2_DW1 0x0454U +/* SUPTPRT2_DW2 */ +#define USB3_SUPTPRT2_DW2 0x0458U +/* SUPTPRT2_DW3 */ +#define USB3_SUPTPRT2_DW3 0x045CU +/* SUPTPRT3_DW0 */ +#define USB3_SUPTPRT3_DW0 0x0000U +/* SUPTPRT3_DW1 */ +#define USB3_SUPTPRT3_DW1 0x0004U +/* SUPTPRT3_DW2 */ +#define USB3_SUPTPRT3_DW2 0x0008U +/* SUPTPRT3_DW3 */ +#define USB3_SUPTPRT3_DW3 0x000CU +/* SUPTPRT3_DW4 */ +#define USB3_SUPTPRT3_DW4 0x0010U +/* SUPTPRT3_DW5 */ +#define USB3_SUPTPRT3_DW5 0x0014U +/* SUPTPRT3_DW6 */ +#define USB3_SUPTPRT3_DW6 0x0018U +/* SUPTPRT3_DW7 */ +#define USB3_SUPTPRT3_DW7 0x001CU +/* DCID */ +#define USB3_DCID 0x0480U +/* DCDB */ +#define USB3_DCDB 0x0484U +/* DCERSTSZ */ +#define USB3_DCERSTSZ 0x0488U +/* RSVD0 */ +#define USB3_RSVD0 0x048CU +/* DCERSTBA_LO */ +#define USB3_DCERSTBA_LO 0x0490U +/* DCERSTBA_HI */ +#define USB3_DCERSTBA_HI 0x0494U +/* DCERDP_LO */ +#define USB3_DCERDP_LO 0x0498U +/* DCERDP_HI */ +#define USB3_DCERDP_HI 0x049CU +/* DCCTRL */ +#define USB3_DCCTRL 0x04A0U +/* DCST */ +#define USB3_DCST 0x04A4U +/* DCPORTSC */ +#define USB3_DCPORTSC 0x04A8U +/* RSVD1 */ +#define USB3_RSVD1 0x04ACU +/* DCCP_LO */ +#define USB3_DCCP_LO 0x04B0U +/* DCCP_HI */ +#define USB3_DCCP_HI 0x04B4U +/* DCDDI1 */ +#define USB3_DCDDI1 0x04B8U +/* DCDDI2 */ +#define USB3_DCDDI2 0x04BCU +/* MFINDEX */ +#define USB3_MFINDEX 0x1000U +/* RsvdZ */ +#define USB3_RSVDZ 0x1004U +/* IMAN */ +#define USB3_IMAN 0x0020U +/* IMOD */ +#define USB3_IMOD 0x0004U +/* ERSTSZ */ +#define USB3_ERSTSZ 0x0028U +/* RsvdP */ +#define USB3_RSVDP 0x000CU +/* ERSTBA_LO */ +#define USB3_ERSTBA_LO 0x0030U +/* ERSTBA_HI */ +#define USB3_ERSTBA_HI 0x0014U +/* ERDP_LO */ +#define USB3_ERDP_LO 0x0038U +/* ERDP_HI */ +#define USB3_ERDP_HI 0x001CU +/* DB */ +#define USB3_DB 0x0000U +/* GSBUSCFG0 */ +#define USB3_GSBUSCFG0 0xC100U +/* GSBUSCFG1 */ +#define USB3_GSBUSCFG1 0xC104U +/* GTXTHRCFG */ +#define USB3_GTXTHRCFG 0xC108U +/* GRXTHRCFG */ +#define USB3_GRXTHRCFG 0xC10CU +/* GCTL */ +#define USB3_GCTL 0xC110U +/* GPMSTS */ +#define USB3_GPMSTS 0xC114U +/* GSTS */ +#define USB3_GSTS 0xC118U +/* GUCTL1 */ +#define USB3_GUCTL1 0xC11CU +/* USB31_IP_NAME */ +#define USB3_USB31_IP_NAME 0xC120U +/* GGPIO */ +#define USB3_GGPIO 0xC124U +/* GUID */ +#define USB3_GUID 0xC128U +/* GUCTL */ +#define USB3_GUCTL 0xC12CU +/* GBUSERRADDRLO */ +#define USB3_GBUSERRADDRLO 0xC130U +/* GBUSERRADDRHI */ +#define USB3_GBUSERRADDRHI 0xC134U +/* GPRTBIMAPLO */ +#define USB3_GPRTBIMAPLO 0xC138U +/* GPRTBIMAPHI */ +#define USB3_GPRTBIMAPHI 0xC13CU +/* GHWPARAMS0 */ +#define USB3_GHWPARAMS0 0xC140U +/* GHWPARAMS1 */ +#define USB3_GHWPARAMS1 0xC144U +/* GHWPARAMS2 */ +#define USB3_GHWPARAMS2 0xC148U +/* GHWPARAMS3 */ +#define USB3_GHWPARAMS3 0xC14CU +/* GHWPARAMS4 */ +#define USB3_GHWPARAMS4 0xC150U +/* GHWPARAMS5 */ +#define USB3_GHWPARAMS5 0xC154U +/* GHWPARAMS6 */ +#define USB3_GHWPARAMS6 0xC158U +/* GHWPARAMS7 */ +#define USB3_GHWPARAMS7 0xC15CU +/* GDBGFIFOSPACE */ +#define USB3_GDBGFIFOSPACE 0xC160U +/* GBMUCTL */ +#define USB3_GBMUCTL 0xC164U +/* GDBGBMU */ +#define USB3_GDBGBMU 0xC16CU +/* GDBGLSPMUX */ +#define USB3_GDBGLSPMUX 0xC170U +/* GDBGLSP */ +#define USB3_GDBGLSP 0xC174U +/* GDBGEPINFO0 */ +#define USB3_GDBGEPINFO0 0xC178U +/* GDBGEPINFO1 */ +#define USB3_GDBGEPINFO1 0xC17CU +/* GPRTBIMAP_HSLO */ +#define USB3_GPRTBIMAP_HSLO 0xC180U +/* GPRTBIMAP_HSHI */ +#define USB3_GPRTBIMAP_HSHI 0xC184U +/* GPRTBIMAP_FSLO */ +#define USB3_GPRTBIMAP_FSLO 0xC188U +/* GPRTBIMAP_FSHI */ +#define USB3_GPRTBIMAP_FSHI 0xC18CU +/* GHMSOCBWOR */ +#define USB3_GHMSOCBWOR 0xC190U +/* USB31_VER_NUMBER */ +#define USB3_USB31_VER_NUMBER 0xC1A0U +/* USB31_VER_TYPE */ +#define USB3_USB31_VER_TYPE 0xC1A4U +/* GSYSBLKWINCTRL */ +#define USB3_GSYSBLKWINCTRL 0xC1B0U +/* GPCIEL1EXTLAT */ +#define USB3_GPCIEL1EXTLAT 0xC1B4U +/* GUSB2PHYCFG */ +#define USB3_GUSB2PHYCFG 0xC200U +/* GUSB2PHYACC_ULPI */ +#define USB3_GUSB2PHYACC_ULPI 0x0000U +/* GUSB3PIPECTL */ +#define USB3_GUSB3PIPECTL 0xC2C0U +/* GTXFIFOSIZ0 */ +#define USB3_GTXFIFOSIZ0 0x0000U +/* GTXFIFOSIZ1 */ +#define USB3_GTXFIFOSIZ1 0x0004U +/* GTXFIFOSIZ2 */ +#define USB3_GTXFIFOSIZ2 0x0008U +/* GTXFIFOSIZ3 */ +#define USB3_GTXFIFOSIZ3 0x000CU +/* GTXFIFOSIZ4 */ +#define USB3_GTXFIFOSIZ4 0x0010U +/* GTXFIFOSIZ5 */ +#define USB3_GTXFIFOSIZ5 0x0014U +/* GTXFIFOSIZ6 */ +#define USB3_GTXFIFOSIZ6 0x0018U +/* GTXFIFOSIZ7 */ +#define USB3_GTXFIFOSIZ7 0x001CU +/* GTXFIFOSIZ8 */ +#define USB3_GTXFIFOSIZ8 0x0020U +/* GTXFIFOSIZ9 */ +#define USB3_GTXFIFOSIZ9 0x0024U +/* GTXFIFOSIZ10 */ +#define USB3_GTXFIFOSIZ10 0x0028U +/* GTXFIFOSIZ11 */ +#define USB3_GTXFIFOSIZ11 0x002CU +/* GTXFIFOSIZ12 */ +#define USB3_GTXFIFOSIZ12 0x0030U +/* GTXFIFOSIZ13 */ +#define USB3_GTXFIFOSIZ13 0x0034U +/* GTXFIFOSIZ14 */ +#define USB3_GTXFIFOSIZ14 0x0038U +/* GTXFIFOSIZ15 */ +#define USB3_GTXFIFOSIZ15 0x003CU +/* GRXFIFOSIZ0 */ +#define USB3_GRXFIFOSIZ0 0x0000U +/* GRXFIFOSIZ1 */ +#define USB3_GRXFIFOSIZ1 0x0004U +/* GRXFIFOSIZ2 */ +#define USB3_GRXFIFOSIZ2 0x0008U +/* GRXFIFOSIZ3 */ +#define USB3_GRXFIFOSIZ3 0x000CU +/* GRXFIFOSIZ4 */ +#define USB3_GRXFIFOSIZ4 0x0010U +/* GRXFIFOSIZ5 */ +#define USB3_GRXFIFOSIZ5 0x0014U +/* GEVNTADRLO */ +#define USB3_GEVNTADRLO 0x0000U +/* GEVNTADRHI */ +#define USB3_GEVNTADRHI 0x0004U +/* GEVNTSIZ */ +#define USB3_GEVNTSIZ 0x0008U +/* GEVNTCOUNT */ +#define USB3_GEVNTCOUNT 0x000CU +/* GHWPARAMS8 */ +#define USB3_GHWPARAMS8 0xC600U +/* GSMACCTL */ +#define USB3_GSMACCTL 0xC604U +/* GUCTL2 */ +#define USB3_GUCTL2 0xC608U +/* GUCTL3 */ +#define USB3_GUCTL3 0xC60CU +/* GTXFIFOPRIDEV */ +#define USB3_GTXFIFOPRIDEV 0xC610U +/* GTXFIFOPRIHST */ +#define USB3_GTXFIFOPRIHST 0xC618U +/* GRXFIFOPRIHST */ +#define USB3_GRXFIFOPRIHST 0xC61CU +/* GFIFOPRIDBC */ +#define USB3_GFIFOPRIDBC 0xC620U +/* GDMAHLRATIO */ +#define USB3_GDMAHLRATIO 0xC624U +/* GOSTDDMA_ASYNC */ +#define USB3_GOSTDDMA_ASYNC 0xC628U +/* GOSTDDMA_PRD */ +#define USB3_GOSTDDMA_PRD 0xC62CU +/* GFLADJ */ +#define USB3_GFLADJ 0xC630U +/* GUCTL4 */ +#define USB3_GUCTL4 0xC634U +/* GUCTL5 */ +#define USB3_GUCTL5 0xC638U +/* GUSB2RHBCTL */ +#define USB3_GUSB2RHBCTL 0x0000U +/* DCFG */ +#define USB3_DCFG 0xC700U +/* DCTL */ +#define USB3_DCTL 0xC704U +/* DEVTEN */ +#define USB3_DEVTEN 0xC708U +/* DSTS */ +#define USB3_DSTS 0xC70CU +/* DGCMDPAR */ +#define USB3_DGCMDPAR 0xC710U +/* DGCMD */ +#define USB3_DGCMD 0xC714U +/* DCTL1 */ +#define USB3_DCTL1 0xC718U +/* DALEPENA */ +#define USB3_DALEPENA 0xC720U +/* DLDMENA */ +#define USB3_DLDMENA 0xC724U +/* Rsvd */ +#define USB3_RSVD 0x0000U +/* DEPCMDPAR2 */ +#define USB3_DEPCMDPAR2 0x0000U +/* DEPCMDPAR1 */ +#define USB3_DEPCMDPAR1 0x0004U +/* DEPCMDPAR0 */ +#define USB3_DEPCMDPAR0 0x0008U +/* DEPCMD */ +#define USB3_DEPCMD 0x000CU +/* DEV_IMOD */ +#define USB3_DEV_IMOD 0x0000U +/* rsvd0_reg */ +#define USB3_RSVD0_REG 0xCC00U +/* LU1LFPSRXTIM */ +#define USB3_LU1LFPSRXTIM 0x0000U +/* LU1LFPSTXTIM */ +#define USB3_LU1LFPSTXTIM 0x0004U +/* LU2LFPSRXTIM */ +#define USB3_LU2LFPSRXTIM 0x0008U +/* LU2LFPSTXTIM */ +#define USB3_LU2LFPSTXTIM 0x000CU +/* LU3LFPSRXTIM */ +#define USB3_LU3LFPSRXTIM 0x0010U +/* LU3LFPSTXTIM */ +#define USB3_LU3LFPSTXTIM 0x0014U +/* LPINGLFPSTIM */ +#define USB3_LPINGLFPSTIM 0x0018U +/* LPOLLLFPSTXTIM */ +#define USB3_LPOLLLFPSTXTIM 0x001CU +/* LSKIPFREQ */ +#define USB3_LSKIPFREQ 0x0020U +/* LLUCTL */ +#define USB3_LLUCTL 0x0024U +/* LPTMDPDELAY */ +#define USB3_LPTMDPDELAY 0x0028U +/* LSCDTIM1 */ +#define USB3_LSCDTIM1 0x002CU +/* LSCDTIM2 */ +#define USB3_LSCDTIM2 0x0030U +/* LSCDTIM3 */ +#define USB3_LSCDTIM3 0x0034U +/* LSCDTIM4 */ +#define USB3_LSCDTIM4 0x0038U +/* LLPBMTIM1 */ +#define USB3_LLPBMTIM1 0x003CU +/* LLPBMTIM2 */ +#define USB3_LLPBMTIM2 0x0040U +/* LLPBMTXTIM */ +#define USB3_LLPBMTXTIM 0x0044U +/* LLINKERRINJ */ +#define USB3_LLINKERRINJ 0x0048U +/* LLINKERRINJEN */ +#define USB3_LLINKERRINJEN 0x004CU +/* GDBGLTSSM */ +#define USB3_GDBGLTSSM 0x0050U +/* GDBGLNMCC */ +#define USB3_GDBGLNMCC 0x0054U +/* LLINKDBGCTRL */ +#define USB3_LLINKDBGCTRL 0x0058U +/* LLINKDBGCNTTRIG */ +#define USB3_LLINKDBGCNTTRIG 0x005CU +/* LCSR_TX_DEEMPH */ +#define USB3_LCSR_TX_DEEMPH 0x0060U +/* LCSR_TX_DEEMPH_1 */ +#define USB3_LCSR_TX_DEEMPH_1 0x0064U +/* LCSR_TX_DEEMPH_2 */ +#define USB3_LCSR_TX_DEEMPH_2 0x0068U +/* LCSR_TX_DEEMPH_3 */ +#define USB3_LCSR_TX_DEEMPH_3 0x006CU +/* LCSRPTMDEBUG1 */ +#define USB3_LCSRPTMDEBUG1 0x0070U +/* LCSRPTMDEBUG2 */ +#define USB3_LCSRPTMDEBUG2 0x0074U +/* LPTMDPDELAY2 */ +#define USB3_LPTMDPDELAY2 0x0078U +/* BU31RHBDBG */ +#define USB3_BU31RHBDBG 0x0000U +/* BRAMHIADDR */ +#define USB3_BRAMHIADDR 0xD84CU +/* BRSERRCNT */ +#define USB3_BRSERRCNT 0xD850U +/* BRMERRCNT */ +#define USB3_BRMERRCNT 0xD854U +/* BRAMECCERR */ +#define USB3_BRAMECCERR 0xD858U +/* BRERRCTL */ +#define USB3_BRERRCTL 0xD85CU +/* BRAM0ADDRERR */ +#define USB3_BRAM0ADDRERR 0xD860U +/* BRAM1ADDRERR */ +#define USB3_BRAM1ADDRERR 0xD864U +/* BRAM2ADDRERR */ +#define USB3_BRAM2ADDRERR 0xD868U +/* BRAM3ADDRERR */ +#define USB3_BRAM3ADDRERR 0xD86CU +/* BRAM4ADDRERR */ +#define USB3_BRAM4ADDRERR 0xD870U +/* BLOOPBCKCTRL */ +#define USB3_BLOOPBCKCTRL 0xD900U +/* BLOOPBCKTFERSZ */ +#define USB3_BLOOPBCKTFERSZ 0xD904U +/* BBISTDATAPATSEED */ +#define USB3_BBISTDATAPATSEED 0xD908U +/* BBISTCTRL */ +#define USB3_BBISTCTRL 0xD90CU +/* BBISTXFERSTS0 */ +#define USB3_BBISTXFERSTS0 0xD910U +/* BBISTXFERSTS1 */ +#define USB3_BBISTXFERSTS1 0xD914U +/* BBISTXFERSTS2 */ +#define USB3_BBISTXFERSTS2 0xD918U +/* BBISTXFERSTS3 */ +#define USB3_BBISTXFERSTS3 0xD91CU +/* BBISTEXPDATASTS0 */ +#define USB3_BBISTEXPDATASTS0 0xD920U +/* BBISTEXPDATASTS1 */ +#define USB3_BBISTEXPDATASTS1 0xD924U +/* BBISTEXPDATASTS2 */ +#define USB3_BBISTEXPDATASTS2 0xD928U +/* BBISTEXPDATASTS3 */ +#define USB3_BBISTEXPDATASTS3 0xD92CU +/* BBISTRCVDDATASTS0 */ +#define USB3_BBISTRCVDDATASTS0 0xD930U +/* BBISTRCVDDATASTS1 */ +#define USB3_BBISTRCVDDATASTS1 0xD934U +/* BBISTRCVDDATASTS2 */ +#define USB3_BBISTRCVDDATASTS2 0xD938U +/* BBISTRCVDDATASTS3 */ +#define USB3_BBISTRCVDDATASTS3 0xD93CU +/* rsvd_reg */ +#define USB3_RSVD_REG 0xDA00U + +/* Bit fields of CAPLENGTH register */ +#define USB3_CAPLENGTH_HCIVERSION_MASK 0xFFFF0000U +#define USB3_CAPLENGTH_HCIVERSION_POS 16U +#define USB3_CAPLENGTH_CAPLENGTH_MASK 0x000000FFU +#define USB3_CAPLENGTH_CAPLENGTH_POS 0U + +/* Bit fields of HCSPARAMS1 register */ +#define USB3_HCSPARAMS1_MAXPORTS_MASK 0xFF000000U +#define USB3_HCSPARAMS1_MAXPORTS_POS 24U +#define USB3_HCSPARAMS1_MAXINTRS_MASK 0x0007FF00U +#define USB3_HCSPARAMS1_MAXINTRS_POS 8U +#define USB3_HCSPARAMS1_MAXSLOTS_MASK 0x000000FFU +#define USB3_HCSPARAMS1_MAXSLOTS_POS 0U + +/* Bit fields of HCSPARAMS2 register */ +#define USB3_HCSPARAMS2_MAXSCRATCHPADBUFS_MASK 0xF8000000U +#define USB3_HCSPARAMS2_MAXSCRATCHPADBUFS_POS 27U +#define USB3_HCSPARAMS2_SPR_MASK 0x04000000U +#define USB3_HCSPARAMS2_SPR_POS 26U +#define USB3_HCSPARAMS2_MAXSCRATCHPADBUFS_HI_MASK 0x03E00000U +#define USB3_HCSPARAMS2_MAXSCRATCHPADBUFS_HI_POS 21U +#define USB3_HCSPARAMS2_ERSTMAX_MASK 0x000000F0U +#define USB3_HCSPARAMS2_ERSTMAX_POS 4U +#define USB3_HCSPARAMS2_IST_MASK 0x0000000FU +#define USB3_HCSPARAMS2_IST_POS 0U + +/* Bit fields of HCSPARAMS3 register */ +#define USB3_HCSPARAMS3_U2_DEVICE_EXIT_LAT_MASK 0xFFFF0000U +#define USB3_HCSPARAMS3_U2_DEVICE_EXIT_LAT_POS 16U +#define USB3_HCSPARAMS3_U1_DEVICE_EXIT_LAT_MASK 0x000000FFU +#define USB3_HCSPARAMS3_U1_DEVICE_EXIT_LAT_POS 0U + +/* Bit fields of HCCPARAMS1 register */ +#define USB3_HCCPARAMS1_XECP_MASK 0xFFFF0000U +#define USB3_HCCPARAMS1_XECP_POS 16U +#define USB3_HCCPARAMS1_MAXPSASIZE_MASK 0x0000F000U +#define USB3_HCCPARAMS1_MAXPSASIZE_POS 12U +#define USB3_HCCPARAMS1_CFC_MASK 0x00000800U +#define USB3_HCCPARAMS1_CFC_POS 11U +#define USB3_HCCPARAMS1_SEC_MASK 0x00000400U +#define USB3_HCCPARAMS1_SEC_POS 10U +#define USB3_HCCPARAMS1_SPC_MASK 0x00000200U +#define USB3_HCCPARAMS1_SPC_POS 9U +#define USB3_HCCPARAMS1_PAE_MASK 0x00000100U +#define USB3_HCCPARAMS1_PAE_POS 8U +#define USB3_HCCPARAMS1_NSS_MASK 0x00000080U +#define USB3_HCCPARAMS1_NSS_POS 7U +#define USB3_HCCPARAMS1_LTC_MASK 0x00000040U +#define USB3_HCCPARAMS1_LTC_POS 6U +#define USB3_HCCPARAMS1_LHRC_MASK 0x00000020U +#define USB3_HCCPARAMS1_LHRC_POS 5U +#define USB3_HCCPARAMS1_PIND_MASK 0x00000010U +#define USB3_HCCPARAMS1_PIND_POS 4U +#define USB3_HCCPARAMS1_PPC_MASK 0x00000008U +#define USB3_HCCPARAMS1_PPC_POS 3U +#define USB3_HCCPARAMS1_CSZ_MASK 0x00000004U +#define USB3_HCCPARAMS1_CSZ_POS 2U +#define USB3_HCCPARAMS1_BNC_MASK 0x00000002U +#define USB3_HCCPARAMS1_BNC_POS 1U +#define USB3_HCCPARAMS1_AC64_MASK 0x00000001U +#define USB3_HCCPARAMS1_AC64_POS 0U + +/* Bit fields of DBOFF register */ +#define USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK 0xFFFFFFFCU +#define USB3_DBOFF_DOORBELL_ARRAY_OFFSET_POS 2U + +/* Bit fields of RTSOFF register */ +#define USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK 0xFFFFFFE0U +#define USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_POS 5U + +/* Bit fields of HCCPARAMS2 register */ +#define USB3_HCCPARAMS2_ETC_TSC_MASK 0x00000080U +#define USB3_HCCPARAMS2_ETC_TSC_POS 7U +#define USB3_HCCPARAMS2_ETC_MASK 0x00000040U +#define USB3_HCCPARAMS2_ETC_POS 6U +#define USB3_HCCPARAMS2_CIC_MASK 0x00000020U +#define USB3_HCCPARAMS2_CIC_POS 5U +#define USB3_HCCPARAMS2_LEC_MASK 0x00000010U +#define USB3_HCCPARAMS2_LEC_POS 4U +#define USB3_HCCPARAMS2_CTC_MASK 0x00000008U +#define USB3_HCCPARAMS2_CTC_POS 3U +#define USB3_HCCPARAMS2_FSC_MASK 0x00000004U +#define USB3_HCCPARAMS2_FSC_POS 2U +#define USB3_HCCPARAMS2_CMC_MASK 0x00000002U +#define USB3_HCCPARAMS2_CMC_POS 1U +#define USB3_HCCPARAMS2_U3C_MASK 0x00000001U +#define USB3_HCCPARAMS2_U3C_POS 0U + +/* Bit fields of USBCMD register */ +#define USB3_USBCMD_ETE_MASK 0x00004000U +#define USB3_USBCMD_ETE_POS 14U +#define USB3_USBCMD_CME_MASK 0x00002000U +#define USB3_USBCMD_CME_POS 13U +#define USB3_USBCMD_EU3S_MASK 0x00000800U +#define USB3_USBCMD_EU3S_POS 11U +#define USB3_USBCMD_EWE_MASK 0x00000400U +#define USB3_USBCMD_EWE_POS 10U +#define USB3_USBCMD_CRS_MASK 0x00000200U +#define USB3_USBCMD_CRS_POS 9U +#define USB3_USBCMD_CSS_MASK 0x00000100U +#define USB3_USBCMD_CSS_POS 8U +#define USB3_USBCMD_LHCRST_MASK 0x00000080U +#define USB3_USBCMD_LHCRST_POS 7U +#define USB3_USBCMD_HSEE_MASK 0x00000008U +#define USB3_USBCMD_HSEE_POS 3U +#define USB3_USBCMD_INTE_MASK 0x00000004U +#define USB3_USBCMD_INTE_POS 2U +#define USB3_USBCMD_HCRST_MASK 0x00000002U +#define USB3_USBCMD_HCRST_POS 1U +#define USB3_USBCMD_R_S_MASK 0x00000001U +#define USB3_USBCMD_R_S_POS 0U + +/* Bit fields of USBSTS register */ +#define USB3_USBSTS_HCE_MASK 0x00001000U +#define USB3_USBSTS_HCE_POS 12U +#define USB3_USBSTS_CNR_MASK 0x00000800U +#define USB3_USBSTS_CNR_POS 11U +#define USB3_USBSTS_SRE_MASK 0x00000400U +#define USB3_USBSTS_SRE_POS 10U +#define USB3_USBSTS_RSS_MASK 0x00000200U +#define USB3_USBSTS_RSS_POS 9U +#define USB3_USBSTS_SSS_MASK 0x00000100U +#define USB3_USBSTS_SSS_POS 8U +#define USB3_USBSTS_PCD_MASK 0x00000010U +#define USB3_USBSTS_PCD_POS 4U +#define USB3_USBSTS_EINT_MASK 0x00000008U +#define USB3_USBSTS_EINT_POS 3U +#define USB3_USBSTS_HSE_MASK 0x00000004U +#define USB3_USBSTS_HSE_POS 2U +#define USB3_USBSTS_HCH_MASK 0x00000001U +#define USB3_USBSTS_HCH_POS 0U + +/* Bit fields of PAGESIZE register */ +#define USB3_PAGESIZE_PAGE_SIZE_MASK 0x0000FFFFU +#define USB3_PAGESIZE_PAGE_SIZE_POS 0U + +/* Bit fields of DNCTRL register */ +#define USB3_DNCTRL_N0_N15_MASK 0x0000FFFFU +#define USB3_DNCTRL_N0_N15_POS 0U + +/* Bit fields of CRCR_LO register */ +#define USB3_CRCR_LO_CMD_RING_PNTR_MASK 0xFFFFFFC0U +#define USB3_CRCR_LO_CMD_RING_PNTR_POS 6U +#define USB3_CRCR_LO_CRR_MASK 0x00000008U +#define USB3_CRCR_LO_CRR_POS 3U +#define USB3_CRCR_LO_CA_MASK 0x00000004U +#define USB3_CRCR_LO_CA_POS 2U +#define USB3_CRCR_LO_CS_MASK 0x00000002U +#define USB3_CRCR_LO_CS_POS 1U +#define USB3_CRCR_LO_RCS_MASK 0x00000001U +#define USB3_CRCR_LO_RCS_POS 0U + +/* Bit fields of CRCR_HI register */ +#define USB3_CRCR_HI_CMD_RING_PNTR_MASK 0xFFFFFFFFU +#define USB3_CRCR_HI_CMD_RING_PNTR_POS 0U + +/* Bit fields of DCBAAP_LO register */ +#define USB3_DCBAAP_LO_DEVICE_CONTEXT_BAAP_MASK 0xFFFFFFC0U +#define USB3_DCBAAP_LO_DEVICE_CONTEXT_BAAP_POS 6U + +/* Bit fields of DCBAAP_HI register */ +#define USB3_DCBAAP_HI_DEVICE_CONTEXT_BAAP_MASK 0xFFFFFFFFU +#define USB3_DCBAAP_HI_DEVICE_CONTEXT_BAAP_POS 0U + +/* Bit fields of CONFIG register */ +#define USB3_CONFIG_CIE_MASK 0x00000200U +#define USB3_CONFIG_CIE_POS 9U +#define USB3_CONFIG_U3E_MASK 0x00000100U +#define USB3_CONFIG_U3E_POS 8U +#define USB3_CONFIG_MAXSLOTSEN_MASK 0x000000FFU +#define USB3_CONFIG_MAXSLOTSEN_POS 0U + +/* Bit fields of PORTSC_20 register */ +#define USB3_PORTSC_20_DR_MASK 0x40000000U +#define USB3_PORTSC_20_DR_POS 30U +#define USB3_PORTSC_20_WOE_MASK 0x08000000U +#define USB3_PORTSC_20_WOE_POS 27U +#define USB3_PORTSC_20_WDE_MASK 0x04000000U +#define USB3_PORTSC_20_WDE_POS 26U +#define USB3_PORTSC_20_WCE_MASK 0x02000000U +#define USB3_PORTSC_20_WCE_POS 25U +#define USB3_PORTSC_20_CAS_MASK 0x01000000U +#define USB3_PORTSC_20_CAS_POS 24U +#define USB3_PORTSC_20_PLC_MASK 0x00400000U +#define USB3_PORTSC_20_PLC_POS 22U +#define USB3_PORTSC_20_PRC_MASK 0x00200000U +#define USB3_PORTSC_20_PRC_POS 21U +#define USB3_PORTSC_20_OCC_MASK 0x00100000U +#define USB3_PORTSC_20_OCC_POS 20U +#define USB3_PORTSC_20_PEC_MASK 0x00040000U +#define USB3_PORTSC_20_PEC_POS 18U +#define USB3_PORTSC_20_CSC_MASK 0x00020000U +#define USB3_PORTSC_20_CSC_POS 17U +#define USB3_PORTSC_20_LWS_MASK 0x00010000U +#define USB3_PORTSC_20_LWS_POS 16U +#define USB3_PORTSC_20_PIC_MASK 0x0000C000U +#define USB3_PORTSC_20_PIC_POS 14U +#define USB3_PORTSC_20_PORTSPEED_MASK 0x00003C00U +#define USB3_PORTSC_20_PORTSPEED_POS 10U +#define USB3_PORTSC_20_PP_MASK 0x00000200U +#define USB3_PORTSC_20_PP_POS 9U +#define USB3_PORTSC_20_PLS_MASK 0x000001E0U +#define USB3_PORTSC_20_PLS_POS 5U +#define USB3_PORTSC_20_PR_MASK 0x00000010U +#define USB3_PORTSC_20_PR_POS 4U +#define USB3_PORTSC_20_OCA_MASK 0x00000008U +#define USB3_PORTSC_20_OCA_POS 3U +#define USB3_PORTSC_20_PED_MASK 0x00000002U +#define USB3_PORTSC_20_PED_POS 1U +#define USB3_PORTSC_20_CCS_MASK 0x00000001U +#define USB3_PORTSC_20_CCS_POS 0U + +/* Bit fields of PORTPMSC_20 register */ +#define USB3_PORTPMSC_20_PRTTSTCTRL_MASK 0xF0000000U +#define USB3_PORTPMSC_20_PRTTSTCTRL_POS 28U +#define USB3_PORTPMSC_20_HLE_MASK 0x00010000U +#define USB3_PORTPMSC_20_HLE_POS 16U +#define USB3_PORTPMSC_20_L1DSLOT_MASK 0x0000FF00U +#define USB3_PORTPMSC_20_L1DSLOT_POS 8U +#define USB3_PORTPMSC_20_BESL_MASK 0x000000F0U +#define USB3_PORTPMSC_20_BESL_POS 4U +#define USB3_PORTPMSC_20_RWE_MASK 0x00000008U +#define USB3_PORTPMSC_20_RWE_POS 3U +#define USB3_PORTPMSC_20_L1S_MASK 0x00000007U +#define USB3_PORTPMSC_20_L1S_POS 0U + +/* Bit fields of PORTLI_20 register */ + +/* Bit fields of PORTHLPMC_20 register */ +#define USB3_PORTHLPMC_20_BESLD_MASK 0x00003C00U +#define USB3_PORTHLPMC_20_BESLD_POS 10U +#define USB3_PORTHLPMC_20_L1_TIMEOUT_MASK 0x000003FCU +#define USB3_PORTHLPMC_20_L1_TIMEOUT_POS 2U +#define USB3_PORTHLPMC_20_HIRDM_MASK 0x00000003U +#define USB3_PORTHLPMC_20_HIRDM_POS 0U + +/* Bit fields of PORTSC_30 register */ +#define USB3_PORTSC_30_WPR_MASK 0x80000000U +#define USB3_PORTSC_30_WPR_POS 31U +#define USB3_PORTSC_30_DR_MASK 0x40000000U +#define USB3_PORTSC_30_DR_POS 30U +#define USB3_PORTSC_30_WOE_MASK 0x08000000U +#define USB3_PORTSC_30_WOE_POS 27U +#define USB3_PORTSC_30_WDE_MASK 0x04000000U +#define USB3_PORTSC_30_WDE_POS 26U +#define USB3_PORTSC_30_WCE_MASK 0x02000000U +#define USB3_PORTSC_30_WCE_POS 25U +#define USB3_PORTSC_30_CAS_MASK 0x01000000U +#define USB3_PORTSC_30_CAS_POS 24U +#define USB3_PORTSC_30_CEC_MASK 0x00800000U +#define USB3_PORTSC_30_CEC_POS 23U +#define USB3_PORTSC_30_PLC_MASK 0x00400000U +#define USB3_PORTSC_30_PLC_POS 22U +#define USB3_PORTSC_30_PRC_MASK 0x00200000U +#define USB3_PORTSC_30_PRC_POS 21U +#define USB3_PORTSC_30_OCC_MASK 0x00100000U +#define USB3_PORTSC_30_OCC_POS 20U +#define USB3_PORTSC_30_WRC_MASK 0x00080000U +#define USB3_PORTSC_30_WRC_POS 19U +#define USB3_PORTSC_30_PEC_MASK 0x00040000U +#define USB3_PORTSC_30_PEC_POS 18U +#define USB3_PORTSC_30_CSC_MASK 0x00020000U +#define USB3_PORTSC_30_CSC_POS 17U +#define USB3_PORTSC_30_LWS_MASK 0x00010000U +#define USB3_PORTSC_30_LWS_POS 16U +#define USB3_PORTSC_30_PIC_MASK 0x0000C000U +#define USB3_PORTSC_30_PIC_POS 14U +#define USB3_PORTSC_30_PORTSPEED_MASK 0x00003C00U +#define USB3_PORTSC_30_PORTSPEED_POS 10U +#define USB3_PORTSC_30_PP_MASK 0x00000200U +#define USB3_PORTSC_30_PP_POS 9U +#define USB3_PORTSC_30_PLS_MASK 0x000001E0U +#define USB3_PORTSC_30_PLS_POS 5U +#define USB3_PORTSC_30_PR_MASK 0x00000010U +#define USB3_PORTSC_30_PR_POS 4U +#define USB3_PORTSC_30_OCA_MASK 0x00000008U +#define USB3_PORTSC_30_OCA_POS 3U +#define USB3_PORTSC_30_PED_MASK 0x00000002U +#define USB3_PORTSC_30_PED_POS 1U +#define USB3_PORTSC_30_CCS_MASK 0x00000001U +#define USB3_PORTSC_30_CCS_POS 0U + +/* Bit fields of PORTPMSC_30 register */ +#define USB3_PORTPMSC_30_FLA_MASK 0x00010000U +#define USB3_PORTPMSC_30_FLA_POS 16U +#define USB3_PORTPMSC_30_U2_TIMEOUT_MASK 0x0000FF00U +#define USB3_PORTPMSC_30_U2_TIMEOUT_POS 8U +#define USB3_PORTPMSC_30_U1_TIMEOUT_MASK 0x000000FFU +#define USB3_PORTPMSC_30_U1_TIMEOUT_POS 0U + +/* Bit fields of PORTLI_30 register */ +#define USB3_PORTLI_30_TLC_MASK 0x00F00000U +#define USB3_PORTLI_30_TLC_POS 20U +#define USB3_PORTLI_30_RLC_MASK 0x000F0000U +#define USB3_PORTLI_30_RLC_POS 16U +#define USB3_PORTLI_30_LINK_ERROR_COUNT_MASK 0x0000FFFFU +#define USB3_PORTLI_30_LINK_ERROR_COUNT_POS 0U + +/* Bit fields of PORTHLPMC_30 register */ + +/* Bit fields of USBLEGSUP register */ +#define USB3_USBLEGSUP_HC_OS_OWNED_MASK 0x01000000U +#define USB3_USBLEGSUP_HC_OS_OWNED_POS 24U +#define USB3_USBLEGSUP_HC_BIOS_OWNED_MASK 0x00010000U +#define USB3_USBLEGSUP_HC_BIOS_OWNED_POS 16U +#define USB3_USBLEGSUP_NEXT_CAPABILITY_POINTER_MASK 0x0000FF00U +#define USB3_USBLEGSUP_NEXT_CAPABILITY_POINTER_POS 8U +#define USB3_USBLEGSUP_CAPABILITY_ID_MASK 0x000000FFU +#define USB3_USBLEGSUP_CAPABILITY_ID_POS 0U + +/* Bit fields of USBLEGCTLSTS register */ +#define USB3_USBLEGCTLSTS_SMI_ON_BAR_MASK 0x80000000U +#define USB3_USBLEGCTLSTS_SMI_ON_BAR_POS 31U +#define USB3_USBLEGCTLSTS_SMI_ON_PCI_MASK 0x40000000U +#define USB3_USBLEGCTLSTS_SMI_ON_PCI_POS 30U +#define USB3_USBLEGCTLSTS_SMI_ON_OS_MASK 0x20000000U +#define USB3_USBLEGCTLSTS_SMI_ON_OS_POS 29U +#define USB3_USBLEGCTLSTS_SMI_ON_HOST_MASK 0x00100000U +#define USB3_USBLEGCTLSTS_SMI_ON_HOST_POS 20U +#define USB3_USBLEGCTLSTS_SMI_ON_EVENT_MASK 0x00010000U +#define USB3_USBLEGCTLSTS_SMI_ON_EVENT_POS 16U +#define USB3_USBLEGCTLSTS_SMI_ON_BAR_E_MASK 0x00008000U +#define USB3_USBLEGCTLSTS_SMI_ON_BAR_E_POS 15U +#define USB3_USBLEGCTLSTS_SMI_ON_PCI_E_MASK 0x00004000U +#define USB3_USBLEGCTLSTS_SMI_ON_PCI_E_POS 14U +#define USB3_USBLEGCTLSTS_SMI_ON_OS_E_MASK 0x00002000U +#define USB3_USBLEGCTLSTS_SMI_ON_OS_E_POS 13U +#define USB3_USBLEGCTLSTS_SMI_ON_HOST_E_MASK 0x00000010U +#define USB3_USBLEGCTLSTS_SMI_ON_HOST_E_POS 4U +#define USB3_USBLEGCTLSTS_USB_SMI_ENABLE_MASK 0x00000001U +#define USB3_USBLEGCTLSTS_USB_SMI_ENABLE_POS 0U + +/* Bit fields of SUPTPRT2_DW0 register */ +#define USB3_SUPTPRT2_DW0_MAJOR_REVISION_MASK 0xFF000000U +#define USB3_SUPTPRT2_DW0_MAJOR_REVISION_POS 24U +#define USB3_SUPTPRT2_DW0_MINOR_REVISION_MASK 0x00FF0000U +#define USB3_SUPTPRT2_DW0_MINOR_REVISION_POS 16U +#define USB3_SUPTPRT2_DW0_NEXT_CAPABILITY_POINTER_MASK 0x0000FF00U +#define USB3_SUPTPRT2_DW0_NEXT_CAPABILITY_POINTER_POS 8U +#define USB3_SUPTPRT2_DW0_CAPABILITY_ID_MASK 0x000000FFU +#define USB3_SUPTPRT2_DW0_CAPABILITY_ID_POS 0U + +/* Bit fields of SUPTPRT2_DW1 register */ +#define USB3_SUPTPRT2_DW1_NAME_STRING_MASK 0xFFFFFFFFU +#define USB3_SUPTPRT2_DW1_NAME_STRING_POS 0U + +/* Bit fields of SUPTPRT2_DW2 register */ +#define USB3_SUPTPRT2_DW2_PSIC_MASK 0xF0000000U +#define USB3_SUPTPRT2_DW2_PSIC_POS 28U +#define USB3_SUPTPRT2_DW2_MHD_MASK 0x0E000000U +#define USB3_SUPTPRT2_DW2_MHD_POS 25U +#define USB3_SUPTPRT2_DW2_BLC_MASK 0x00100000U +#define USB3_SUPTPRT2_DW2_BLC_POS 20U +#define USB3_SUPTPRT2_DW2_HLC_MASK 0x00080000U +#define USB3_SUPTPRT2_DW2_HLC_POS 19U +#define USB3_SUPTPRT2_DW2_IHI_MASK 0x00040000U +#define USB3_SUPTPRT2_DW2_IHI_POS 18U +#define USB3_SUPTPRT2_DW2_HSO_MASK 0x00020000U +#define USB3_SUPTPRT2_DW2_HSO_POS 17U +#define USB3_SUPTPRT2_DW2_L1C_MASK 0x00010000U +#define USB3_SUPTPRT2_DW2_L1C_POS 16U +#define USB3_SUPTPRT2_DW2_COMPATIBLE_PORT_COUNT_MASK 0x0000FF00U +#define USB3_SUPTPRT2_DW2_COMPATIBLE_PORT_COUNT_POS 8U +#define USB3_SUPTPRT2_DW2_COMPATIBLE_PORT_OFFSET_MASK 0x000000FFU +#define USB3_SUPTPRT2_DW2_COMPATIBLE_PORT_OFFSET_POS 0U + +/* Bit fields of SUPTPRT2_DW3 register */ +#define USB3_SUPTPRT2_DW3_PROTCL_SLT_TY_MASK 0x0000001FU +#define USB3_SUPTPRT2_DW3_PROTCL_SLT_TY_POS 0U + +/* Bit fields of SUPTPRT3_DW0 register */ +#define USB3_SUPTPRT3_DW0_MAJOR_REVISION_MASK 0xFF000000U +#define USB3_SUPTPRT3_DW0_MAJOR_REVISION_POS 24U +#define USB3_SUPTPRT3_DW0_MINOR_REVISION_MASK 0x00FF0000U +#define USB3_SUPTPRT3_DW0_MINOR_REVISION_POS 16U +#define USB3_SUPTPRT3_DW0_NEXT_CAPABILITY_POINTER_MASK 0x0000FF00U +#define USB3_SUPTPRT3_DW0_NEXT_CAPABILITY_POINTER_POS 8U +#define USB3_SUPTPRT3_DW0_CAPABILITY_ID_MASK 0x000000FFU +#define USB3_SUPTPRT3_DW0_CAPABILITY_ID_POS 0U + +/* Bit fields of SUPTPRT3_DW1 register */ +#define USB3_SUPTPRT3_DW1_NAME_STRING_MASK 0xFFFFFFFFU +#define USB3_SUPTPRT3_DW1_NAME_STRING_POS 0U + +/* Bit fields of SUPTPRT3_DW2 register */ +#define USB3_SUPTPRT3_DW2_PSIC_MASK 0xF0000000U +#define USB3_SUPTPRT3_DW2_PSIC_POS 28U +#define USB3_SUPTPRT3_DW2_COMPATIBLE_PORT_COUNT_MASK 0x0000FF00U +#define USB3_SUPTPRT3_DW2_COMPATIBLE_PORT_COUNT_POS 8U +#define USB3_SUPTPRT3_DW2_COMPATIBLE_PORT_OFFSET_MASK 0x000000FFU +#define USB3_SUPTPRT3_DW2_COMPATIBLE_PORT_OFFSET_POS 0U + +/* Bit fields of SUPTPRT3_DW3 register */ +#define USB3_SUPTPRT3_DW3_PROTCL_SLT_TY_MASK 0x0000001FU +#define USB3_SUPTPRT3_DW3_PROTCL_SLT_TY_POS 0U + +/* Bit fields of SUPTPRT3_DW4 register */ +#define USB3_SUPTPRT3_DW4_PSIM_MASK 0xFFFF0000U +#define USB3_SUPTPRT3_DW4_PSIM_POS 16U +#define USB3_SUPTPRT3_DW4_LP_MASK 0x0000C000U +#define USB3_SUPTPRT3_DW4_LP_POS 14U +#define USB3_SUPTPRT3_DW4_PFD_MASK 0x00000100U +#define USB3_SUPTPRT3_DW4_PFD_POS 8U +#define USB3_SUPTPRT3_DW4_PLT_MASK 0x000000C0U +#define USB3_SUPTPRT3_DW4_PLT_POS 6U +#define USB3_SUPTPRT3_DW4_PSIE_MASK 0x00000030U +#define USB3_SUPTPRT3_DW4_PSIE_POS 4U +#define USB3_SUPTPRT3_DW4_PSIV_MASK 0x0000000FU +#define USB3_SUPTPRT3_DW4_PSIV_POS 0U + +/* Bit fields of SUPTPRT3_DW5 register */ +#define USB3_SUPTPRT3_DW5_PSIM_MASK 0xFFFF0000U +#define USB3_SUPTPRT3_DW5_PSIM_POS 16U +#define USB3_SUPTPRT3_DW5_LP_MASK 0x0000C000U +#define USB3_SUPTPRT3_DW5_LP_POS 14U +#define USB3_SUPTPRT3_DW5_PFD_MASK 0x00000100U +#define USB3_SUPTPRT3_DW5_PFD_POS 8U +#define USB3_SUPTPRT3_DW5_PLT_MASK 0x000000C0U +#define USB3_SUPTPRT3_DW5_PLT_POS 6U +#define USB3_SUPTPRT3_DW5_PSIE_MASK 0x00000030U +#define USB3_SUPTPRT3_DW5_PSIE_POS 4U +#define USB3_SUPTPRT3_DW5_PSIV_MASK 0x0000000FU +#define USB3_SUPTPRT3_DW5_PSIV_POS 0U + +/* Bit fields of SUPTPRT3_DW6 register */ + +/* Bit fields of SUPTPRT3_DW7 register */ + +/* Bit fields of DCID register */ +#define USB3_DCID_DCERSTMAX_MASK 0x001F0000U +#define USB3_DCID_DCERSTMAX_POS 16U +#define USB3_DCID_NEXT_CAPABILITY_POINTER_MASK 0x0000FF00U +#define USB3_DCID_NEXT_CAPABILITY_POINTER_POS 8U +#define USB3_DCID_CAPABILITY_ID_MASK 0x000000FFU +#define USB3_DCID_CAPABILITY_ID_POS 0U + +/* Bit fields of DCDB register */ +#define USB3_DCDB_DBTARGET_MASK 0x0000FF00U +#define USB3_DCDB_DBTARGET_POS 8U + +/* Bit fields of DCERSTSZ register */ +#define USB3_DCERSTSZ_ERS_TABLE_SIZE_MASK 0x0000FFFFU +#define USB3_DCERSTSZ_ERS_TABLE_SIZE_POS 0U + +/* Bit fields of RSVD0 register */ + +/* Bit fields of DCERSTBA_LO register */ +#define USB3_DCERSTBA_LO_ERS_TABLE_BAR_MASK 0xFFFFFFF0U +#define USB3_DCERSTBA_LO_ERS_TABLE_BAR_POS 4U + +/* Bit fields of DCERSTBA_HI register */ +#define USB3_DCERSTBA_HI_ERS_TABLE_BAR_MASK 0xFFFFFFFFU +#define USB3_DCERSTBA_HI_ERS_TABLE_BAR_POS 0U + +/* Bit fields of DCERDP_LO register */ +#define USB3_DCERDP_LO_DEQUEUE_POINTER_MASK 0xFFFFFFF0U +#define USB3_DCERDP_LO_DEQUEUE_POINTER_POS 4U +#define USB3_DCERDP_LO_DESI_MASK 0x00000007U +#define USB3_DCERDP_LO_DESI_POS 0U + +/* Bit fields of DCERDP_HI register */ +#define USB3_DCERDP_HI_DEQUEUE_POINTER_MASK 0xFFFFFFFFU +#define USB3_DCERDP_HI_DEQUEUE_POINTER_POS 0U + +/* Bit fields of DCCTRL register */ +#define USB3_DCCTRL_DCE_MASK 0x80000000U +#define USB3_DCCTRL_DCE_POS 31U +#define USB3_DCCTRL_DEVICE_ADDRESS_MASK 0x7F000000U +#define USB3_DCCTRL_DEVICE_ADDRESS_POS 24U +#define USB3_DCCTRL_DEBUG_MAX_BURST_SIZE_MASK 0x00FF0000U +#define USB3_DCCTRL_DEBUG_MAX_BURST_SIZE_POS 16U +#define USB3_DCCTRL_DRC_MASK 0x00000010U +#define USB3_DCCTRL_DRC_POS 4U +#define USB3_DCCTRL_HIT_MASK 0x00000008U +#define USB3_DCCTRL_HIT_POS 3U +#define USB3_DCCTRL_HOT_MASK 0x00000004U +#define USB3_DCCTRL_HOT_POS 2U +#define USB3_DCCTRL_LSE_MASK 0x00000002U +#define USB3_DCCTRL_LSE_POS 1U +#define USB3_DCCTRL_DCR_MASK 0x00000001U +#define USB3_DCCTRL_DCR_POS 0U + +/* Bit fields of DCST register */ +#define USB3_DCST_DEBUG_PORT_NUMBER_MASK 0xFF000000U +#define USB3_DCST_DEBUG_PORT_NUMBER_POS 24U +#define USB3_DCST_SBR_MASK 0x00000002U +#define USB3_DCST_SBR_POS 1U +#define USB3_DCST_ER_MASK 0x00000001U +#define USB3_DCST_ER_POS 0U + +/* Bit fields of DCPORTSC register */ +#define USB3_DCPORTSC_CEC_MASK 0x00800000U +#define USB3_DCPORTSC_CEC_POS 23U +#define USB3_DCPORTSC_PLC_MASK 0x00400000U +#define USB3_DCPORTSC_PLC_POS 22U +#define USB3_DCPORTSC_PRC_MASK 0x00200000U +#define USB3_DCPORTSC_PRC_POS 21U +#define USB3_DCPORTSC_CSC_MASK 0x00020000U +#define USB3_DCPORTSC_CSC_POS 17U +#define USB3_DCPORTSC_PORTSPEED_MASK 0x00003C00U +#define USB3_DCPORTSC_PORTSPEED_POS 10U +#define USB3_DCPORTSC_PLS_MASK 0x000001E0U +#define USB3_DCPORTSC_PLS_POS 5U +#define USB3_DCPORTSC_PR_MASK 0x00000010U +#define USB3_DCPORTSC_PR_POS 4U +#define USB3_DCPORTSC_PED_MASK 0x00000002U +#define USB3_DCPORTSC_PED_POS 1U +#define USB3_DCPORTSC_CCS_MASK 0x00000001U +#define USB3_DCPORTSC_CCS_POS 0U + +/* Bit fields of RSVD1 register */ + +/* Bit fields of DCCP_LO register */ +#define USB3_DCCP_LO_DCCPR_MASK 0xFFFFFFF0U +#define USB3_DCCP_LO_DCCPR_POS 4U + +/* Bit fields of DCCP_HI register */ +#define USB3_DCCP_HI_DCCPR_MASK 0xFFFFFFFFU +#define USB3_DCCP_HI_DCCPR_POS 0U + +/* Bit fields of DCDDI1 register */ +#define USB3_DCDDI1_VENDORID_MASK 0xFFFF0000U +#define USB3_DCDDI1_VENDORID_POS 16U +#define USB3_DCDDI1_DBCPROTOCOL_MASK 0x000000FFU +#define USB3_DCDDI1_DBCPROTOCOL_POS 0U + +/* Bit fields of DCDDI2 register */ +#define USB3_DCDDI2_DEVICEREV_MASK 0xFFFF0000U +#define USB3_DCDDI2_DEVICEREV_POS 16U +#define USB3_DCDDI2_PRODUCTID_MASK 0x0000FFFFU +#define USB3_DCDDI2_PRODUCTID_POS 0U + +/* Bit fields of MFINDEX register */ +#define USB3_MFINDEX_MICROFRAME_INDEX_MASK 0x00003FFFU +#define USB3_MFINDEX_MICROFRAME_INDEX_POS 0U + +/* Bit fields of RsvdZ register */ + +/* Bit fields of IMAN register */ +#define USB3_IMAN_IE_MASK 0x00000002U +#define USB3_IMAN_IE_POS 1U +#define USB3_IMAN_IP_MASK 0x00000001U +#define USB3_IMAN_IP_POS 0U + +/* Bit fields of IMOD register */ +#define USB3_IMOD_IMODC_MASK 0xFFFF0000U +#define USB3_IMOD_IMODC_POS 16U +#define USB3_IMOD_IMODI_MASK 0x0000FFFFU +#define USB3_IMOD_IMODI_POS 0U + +/* Bit fields of ERSTSZ register */ +#define USB3_ERSTSZ_ERS_TABLE_SIZE_MASK 0x0000FFFFU +#define USB3_ERSTSZ_ERS_TABLE_SIZE_POS 0U + +/* Bit fields of RsvdP register */ + +/* Bit fields of ERSTBA_LO register */ +#define USB3_ERSTBA_LO_ERS_TABLE_BAR_MASK 0xFFFFFFC0U +#define USB3_ERSTBA_LO_ERS_TABLE_BAR_POS 6U + +/* Bit fields of ERSTBA_HI register */ +#define USB3_ERSTBA_HI_ERS_TABLE_BAR_MASK 0xFFFFFFFFU +#define USB3_ERSTBA_HI_ERS_TABLE_BAR_POS 0U + +/* Bit fields of ERDP_LO register */ +#define USB3_ERDP_LO_ERD_PNTR_MASK 0xFFFFFFF0U +#define USB3_ERDP_LO_ERD_PNTR_POS 4U +#define USB3_ERDP_LO_EHB_MASK 0x00000008U +#define USB3_ERDP_LO_EHB_POS 3U +#define USB3_ERDP_LO_DESI_MASK 0x00000007U +#define USB3_ERDP_LO_DESI_POS 0U + +/* Bit fields of ERDP_HI register */ +#define USB3_ERDP_HI_ERD_PNTR_MASK 0xFFFFFFFFU +#define USB3_ERDP_HI_ERD_PNTR_POS 0U + +/* Bit fields of DB register */ +#define USB3_DB_DB_STREAM_ID_MASK 0xFFFF0000U +#define USB3_DB_DB_STREAM_ID_POS 16U +#define USB3_DB_DB_TARGET_MASK 0x000000FFU +#define USB3_DB_DB_TARGET_POS 0U + +/* Bit fields of GSBUSCFG0 register */ +#define USB3_GSBUSCFG0_DATRDREQINFO_MASK 0xF0000000U +#define USB3_GSBUSCFG0_DATRDREQINFO_POS 28U +#define USB3_GSBUSCFG0_DESRDREQINFO_MASK 0x0F000000U +#define USB3_GSBUSCFG0_DESRDREQINFO_POS 24U +#define USB3_GSBUSCFG0_DATWRREQINFO_MASK 0x00F00000U +#define USB3_GSBUSCFG0_DATWRREQINFO_POS 20U +#define USB3_GSBUSCFG0_DESWRREQINFO_MASK 0x000F0000U +#define USB3_GSBUSCFG0_DESWRREQINFO_POS 16U +#define USB3_GSBUSCFG0_DATBIGEND_MASK 0x00000800U +#define USB3_GSBUSCFG0_DATBIGEND_POS 11U +#define USB3_GSBUSCFG0_DESBIGEND_MASK 0x00000400U +#define USB3_GSBUSCFG0_DESBIGEND_POS 10U +#define USB3_GSBUSCFG0_INCR256BRSTENA_MASK 0x00000080U +#define USB3_GSBUSCFG0_INCR256BRSTENA_POS 7U +#define USB3_GSBUSCFG0_INCR128BRSTENA_MASK 0x00000040U +#define USB3_GSBUSCFG0_INCR128BRSTENA_POS 6U +#define USB3_GSBUSCFG0_INCR64BRSTENA_MASK 0x00000020U +#define USB3_GSBUSCFG0_INCR64BRSTENA_POS 5U +#define USB3_GSBUSCFG0_INCR32BRSTENA_MASK 0x00000010U +#define USB3_GSBUSCFG0_INCR32BRSTENA_POS 4U +#define USB3_GSBUSCFG0_INCR16BRSTENA_MASK 0x00000008U +#define USB3_GSBUSCFG0_INCR16BRSTENA_POS 3U +#define USB3_GSBUSCFG0_INCR8BRSTENA_MASK 0x00000004U +#define USB3_GSBUSCFG0_INCR8BRSTENA_POS 2U +#define USB3_GSBUSCFG0_INCR4BRSTENA_MASK 0x00000002U +#define USB3_GSBUSCFG0_INCR4BRSTENA_POS 1U +#define USB3_GSBUSCFG0_INCRBRSTENA_MASK 0x00000001U +#define USB3_GSBUSCFG0_INCRBRSTENA_POS 0U + +/* Bit fields of GSBUSCFG1 register */ +#define USB3_GSBUSCFG1_EXTDPIPETRANSLIMIT_MASK 0x0001E000U +#define USB3_GSBUSCFG1_EXTDPIPETRANSLIMIT_POS 13U +#define USB3_GSBUSCFG1_EN1KPAGE_MASK 0x00001000U +#define USB3_GSBUSCFG1_EN1KPAGE_POS 12U +#define USB3_GSBUSCFG1_PIPETRANSLIMIT_MASK 0x00000F00U +#define USB3_GSBUSCFG1_PIPETRANSLIMIT_POS 8U + +/* Bit fields of GTXTHRCFG register */ +#define USB3_GTXTHRCFG_USBTXPKTCNTSEL_MASK 0x04000000U +#define USB3_GTXTHRCFG_USBTXPKTCNTSEL_POS 26U +#define USB3_GTXTHRCFG_USBTXPKTCNT_MASK 0x03E00000U +#define USB3_GTXTHRCFG_USBTXPKTCNT_POS 21U +#define USB3_GTXTHRCFG_USBMAXTXBURSTSIZE_MASK 0x001F0000U +#define USB3_GTXTHRCFG_USBMAXTXBURSTSIZE_POS 16U +#define USB3_GTXTHRCFG_USBTXTHRNUMPKTSEL_HS_PRD_MASK 0x00008000U +#define USB3_GTXTHRCFG_USBTXTHRNUMPKTSEL_HS_PRD_POS 15U +#define USB3_GTXTHRCFG_USBTXTHRNUMPKT_HS_PRD_MASK 0x00006000U +#define USB3_GTXTHRCFG_USBTXTHRNUMPKT_HS_PRD_POS 13U +#define USB3_GTXTHRCFG_USBTXTHRNUMPKTSEL_PRD_MASK 0x00000400U +#define USB3_GTXTHRCFG_USBTXTHRNUMPKTSEL_PRD_POS 10U +#define USB3_GTXTHRCFG_USBTXTHRNUMPKT_PRD_MASK 0x000003E0U +#define USB3_GTXTHRCFG_USBTXTHRNUMPKT_PRD_POS 5U +#define USB3_GTXTHRCFG_USBMAXTXBURSTSIZE_PRD_MASK 0x0000001FU +#define USB3_GTXTHRCFG_USBMAXTXBURSTSIZE_PRD_POS 0U + +/* Bit fields of GRXTHRCFG register */ +#define USB3_GRXTHRCFG_USBRXPKTCNTSEL_MASK 0x04000000U +#define USB3_GRXTHRCFG_USBRXPKTCNTSEL_POS 26U +#define USB3_GRXTHRCFG_USBRXPKTCNT_MASK 0x03E00000U +#define USB3_GRXTHRCFG_USBRXPKTCNT_POS 21U +#define USB3_GRXTHRCFG_USBMAXRXBURSTSIZE_MASK 0x001F0000U +#define USB3_GRXTHRCFG_USBMAXRXBURSTSIZE_POS 16U +#define USB3_GRXTHRCFG_USBRXTHRNUMPKTSEL_HS_PRD_MASK 0x00008000U +#define USB3_GRXTHRCFG_USBRXTHRNUMPKTSEL_HS_PRD_POS 15U +#define USB3_GRXTHRCFG_USBRXTHRNUMPKT_HS_PRD_MASK 0x00006000U +#define USB3_GRXTHRCFG_USBRXTHRNUMPKT_HS_PRD_POS 13U +#define USB3_GRXTHRCFG_USBRXTHRNUMPKTSEL_PRD_MASK 0x00000400U +#define USB3_GRXTHRCFG_USBRXTHRNUMPKTSEL_PRD_POS 10U +#define USB3_GRXTHRCFG_USBRXTHRNUMPKT_PRD_MASK 0x000003E0U +#define USB3_GRXTHRCFG_USBRXTHRNUMPKT_PRD_POS 5U +#define USB3_GRXTHRCFG_USBMAXRXBURSTSIZE_PRD_MASK 0x0000001FU +#define USB3_GRXTHRCFG_USBMAXRXBURSTSIZE_PRD_POS 0U + +/* Bit fields of GCTL register */ +#define USB3_GCTL_PWRDNSCALE_MASK 0xFFF80000U +#define USB3_GCTL_PWRDNSCALE_POS 19U +#define USB3_GCTL_MASTERFILTBYPASS_MASK 0x00040000U +#define USB3_GCTL_MASTERFILTBYPASS_POS 18U +#define USB3_GCTL_BYPSSETADDR_MASK 0x00020000U +#define USB3_GCTL_BYPSSETADDR_POS 17U +#define USB3_GCTL_U2RSTECN_MASK 0x00010000U +#define USB3_GCTL_U2RSTECN_POS 16U +#define USB3_GCTL_FRMSCLDWN_MASK 0x0000C000U +#define USB3_GCTL_FRMSCLDWN_POS 14U +#define USB3_GCTL_PRTCAPDIR_MASK 0x00003000U +#define USB3_GCTL_PRTCAPDIR_POS 12U +#define USB3_GCTL_CORESOFTRESET_MASK 0x00000800U +#define USB3_GCTL_CORESOFTRESET_POS 11U +#define USB3_GCTL_U1U2TIMERSCALE_MASK 0x00000200U +#define USB3_GCTL_U1U2TIMERSCALE_POS 9U +#define USB3_GCTL_DEBUGATTACH_MASK 0x00000100U +#define USB3_GCTL_DEBUGATTACH_POS 8U +#define USB3_GCTL_RAMCLKSEL_MASK 0x000000C0U +#define USB3_GCTL_RAMCLKSEL_POS 6U +#define USB3_GCTL_SCALEDOWN_MASK 0x00000030U +#define USB3_GCTL_SCALEDOWN_POS 4U +#define USB3_GCTL_DISSCRAMBLE_MASK 0x00000008U +#define USB3_GCTL_DISSCRAMBLE_POS 3U +#define USB3_GCTL_U2EXIT_LFPS_MASK 0x00000004U +#define USB3_GCTL_U2EXIT_LFPS_POS 2U +#define USB3_GCTL_GBLHIBERNATIONEN_MASK 0x00000002U +#define USB3_GCTL_GBLHIBERNATIONEN_POS 1U +#define USB3_GCTL_DSBLCLKGTNG_MASK 0x00000001U +#define USB3_GCTL_DSBLCLKGTNG_POS 0U + +/* Bit fields of GPMSTS register */ +#define USB3_GPMSTS_PORTSEL_MASK 0xF0000000U +#define USB3_GPMSTS_PORTSEL_POS 28U +#define USB3_GPMSTS_U3WAKEUP_MASK 0x0001F000U +#define USB3_GPMSTS_U3WAKEUP_POS 12U +#define USB3_GPMSTS_U2WAKEUP_MASK 0x000003FFU +#define USB3_GPMSTS_U2WAKEUP_POS 0U + +/* Bit fields of GSTS register */ +#define USB3_GSTS_CBELT_MASK 0xFFF00000U +#define USB3_GSTS_CBELT_POS 20U +#define USB3_GSTS_HOST_IP_MASK 0x00000080U +#define USB3_GSTS_HOST_IP_POS 7U +#define USB3_GSTS_DEVICE_IP_MASK 0x00000040U +#define USB3_GSTS_DEVICE_IP_POS 6U +#define USB3_GSTS_CSRTIMEOUT_MASK 0x00000020U +#define USB3_GSTS_CSRTIMEOUT_POS 5U +#define USB3_GSTS_BUSERRADDRVLD_MASK 0x00000010U +#define USB3_GSTS_BUSERRADDRVLD_POS 4U +#define USB3_GSTS_CURMOD_MASK 0x00000003U +#define USB3_GSTS_CURMOD_POS 0U + +/* Bit fields of GUCTL1 register */ +#define USB3_GUCTL1_DEV_DECOUPLE_L1L2_EVT_MASK 0x80000000U +#define USB3_GUCTL1_DEV_DECOUPLE_L1L2_EVT_POS 31U +#define USB3_GUCTL1_DS_RXDET_MAX_TOUT_CTRL_MASK 0x40000000U +#define USB3_GUCTL1_DS_RXDET_MAX_TOUT_CTRL_POS 30U +#define USB3_GUCTL1_FILTER_SE0_FSLS_EOP_MASK 0x20000000U +#define USB3_GUCTL1_FILTER_SE0_FSLS_EOP_POS 29U +#define USB3_GUCTL1_TX_IPGAP_LINECHECK_DIS_MASK 0x10000000U +#define USB3_GUCTL1_TX_IPGAP_LINECHECK_DIS_POS 28U +#define USB3_GUCTL1_DEV_TRB_OUT_SPR_IND_MASK 0x08000000U +#define USB3_GUCTL1_DEV_TRB_OUT_SPR_IND_POS 27U +#define USB3_GUCTL1_DEV_L1_EXIT_BY_HW_MASK 0x01000000U +#define USB3_GUCTL1_DEV_L1_EXIT_BY_HW_POS 24U +#define USB3_GUCTL1_IP_GAP_ADD_ON_MASK 0x00E00000U +#define USB3_GUCTL1_IP_GAP_ADD_ON_POS 21U +#define USB3_GUCTL1_HW_LPM_CAP_DISABLE_MASK 0x00004000U +#define USB3_GUCTL1_HW_LPM_CAP_DISABLE_POS 14U +#define USB3_GUCTL1_HW_LPM_HLE_DISABLE_MASK 0x00002000U +#define USB3_GUCTL1_HW_LPM_HLE_DISABLE_POS 13U +#define USB3_GUCTL1_DISUSB2REFCLKGTNG_MASK 0x00001000U +#define USB3_GUCTL1_DISUSB2REFCLKGTNG_POS 12U +#define USB3_GUCTL1_DISREFCLKGTNG_MASK 0x00000800U +#define USB3_GUCTL1_DISREFCLKGTNG_POS 11U +#define USB3_GUCTL1_RESUME_OPMODE_HS_HOST_MASK 0x00000400U +#define USB3_GUCTL1_RESUME_OPMODE_HS_HOST_POS 10U +#define USB3_GUCTL1_L1_SUSP_THRLD_EN_FOR_HOST_MASK 0x00000100U +#define USB3_GUCTL1_L1_SUSP_THRLD_EN_FOR_HOST_POS 8U +#define USB3_GUCTL1_L1_SUSP_THRLD_FOR_HOST_MASK 0x000000F0U +#define USB3_GUCTL1_L1_SUSP_THRLD_FOR_HOST_POS 4U +#define USB3_GUCTL1_HC_ERRATA_ENABLE_MASK 0x00000008U +#define USB3_GUCTL1_HC_ERRATA_ENABLE_POS 3U +#define USB3_GUCTL1_HC_PARCHK_DISABLE_MASK 0x00000004U +#define USB3_GUCTL1_HC_PARCHK_DISABLE_POS 2U +#define USB3_GUCTL1_LOA_FILTER_EN_MASK 0x00000001U +#define USB3_GUCTL1_LOA_FILTER_EN_POS 0U + +/* Bit fields of USB31_IP_NAME register */ +#define USB3_USB31_IP_NAME_SYNOPSYSIP_MASK 0xFFFFFFFFU +#define USB3_USB31_IP_NAME_SYNOPSYSIP_POS 0U + +/* Bit fields of GGPIO register */ +#define USB3_GGPIO_GPO_MASK 0xFFFF0000U +#define USB3_GGPIO_GPO_POS 16U +#define USB3_GGPIO_GPI_MASK 0x0000FFFFU +#define USB3_GGPIO_GPI_POS 0U + +/* Bit fields of GUID register */ +#define USB3_GUID_USERID_MASK 0xFFFFFFFFU +#define USB3_GUID_USERID_POS 0U + +/* Bit fields of GUCTL register */ +#define USB3_GUCTL_REFCLKPER_MASK 0xFFC00000U +#define USB3_GUCTL_REFCLKPER_POS 22U +#define USB3_GUCTL_NOEXTRDL_MASK 0x00200000U +#define USB3_GUCTL_NOEXTRDL_POS 21U +#define USB3_GUCTL_DMAIGNOREHCE_MASK 0x00100000U +#define USB3_GUCTL_DMAIGNOREHCE_POS 20U +#define USB3_GUCTL_IGNOREHCETIMEOUT_MASK 0x00080000U +#define USB3_GUCTL_IGNOREHCETIMEOUT_POS 19U +#define USB3_GUCTL_EN_EXTD_TBC_CAP_MASK 0x00040000U +#define USB3_GUCTL_EN_EXTD_TBC_CAP_POS 18U +#define USB3_GUCTL_SPRSCTRLTRANSEN_MASK 0x00020000U +#define USB3_GUCTL_SPRSCTRLTRANSEN_POS 17U +#define USB3_GUCTL_RESBWHSEPS_MASK 0x00010000U +#define USB3_GUCTL_RESBWHSEPS_POS 16U +#define USB3_GUCTL_USBHSTINIMMRETRYEN_MASK 0x00004000U +#define USB3_GUCTL_USBHSTINIMMRETRYEN_POS 14U +#define USB3_GUCTL_EXTCAPSUPPTEN_MASK 0x00001000U +#define USB3_GUCTL_EXTCAPSUPPTEN_POS 12U +#define USB3_GUCTL_INSRTEXTRFSBODI_MASK 0x00000800U +#define USB3_GUCTL_INSRTEXTRFSBODI_POS 11U +#define USB3_GUCTL_DTOUT_MASK 0x000007FFU +#define USB3_GUCTL_DTOUT_POS 0U + +/* Bit fields of GBUSERRADDRLO register */ +#define USB3_GBUSERRADDRLO_BUSERRADDR_MASK 0xFFFFFFFFU +#define USB3_GBUSERRADDRLO_BUSERRADDR_POS 0U + +/* Bit fields of GBUSERRADDRHI register */ +#define USB3_GBUSERRADDRHI_BUSERRADDR_MASK 0xFFFFFFFFU +#define USB3_GBUSERRADDRHI_BUSERRADDR_POS 0U + +/* Bit fields of GPRTBIMAPLO register */ +#define USB3_GPRTBIMAPLO_BINUM8_MASK 0xF0000000U +#define USB3_GPRTBIMAPLO_BINUM8_POS 28U +#define USB3_GPRTBIMAPLO_BINUM7_MASK 0x0F000000U +#define USB3_GPRTBIMAPLO_BINUM7_POS 24U +#define USB3_GPRTBIMAPLO_BINUM6_MASK 0x00F00000U +#define USB3_GPRTBIMAPLO_BINUM6_POS 20U +#define USB3_GPRTBIMAPLO_BINUM5_MASK 0x000F0000U +#define USB3_GPRTBIMAPLO_BINUM5_POS 16U +#define USB3_GPRTBIMAPLO_BINUM4_MASK 0x0000F000U +#define USB3_GPRTBIMAPLO_BINUM4_POS 12U +#define USB3_GPRTBIMAPLO_BINUM3_MASK 0x00000F00U +#define USB3_GPRTBIMAPLO_BINUM3_POS 8U +#define USB3_GPRTBIMAPLO_BINUM2_MASK 0x000000F0U +#define USB3_GPRTBIMAPLO_BINUM2_POS 4U +#define USB3_GPRTBIMAPLO_BINUM1_MASK 0x0000000FU +#define USB3_GPRTBIMAPLO_BINUM1_POS 0U + +/* Bit fields of GPRTBIMAPHI register */ +#define USB3_GPRTBIMAPHI_BINUM15_MASK 0x0F000000U +#define USB3_GPRTBIMAPHI_BINUM15_POS 24U +#define USB3_GPRTBIMAPHI_BINUM14_MASK 0x00F00000U +#define USB3_GPRTBIMAPHI_BINUM14_POS 20U +#define USB3_GPRTBIMAPHI_BINUM13_MASK 0x000F0000U +#define USB3_GPRTBIMAPHI_BINUM13_POS 16U +#define USB3_GPRTBIMAPHI_BINUM12_MASK 0x0000F000U +#define USB3_GPRTBIMAPHI_BINUM12_POS 12U +#define USB3_GPRTBIMAPHI_BINUM11_MASK 0x00000F00U +#define USB3_GPRTBIMAPHI_BINUM11_POS 8U +#define USB3_GPRTBIMAPHI_BINUM10_MASK 0x000000F0U +#define USB3_GPRTBIMAPHI_BINUM10_POS 4U +#define USB3_GPRTBIMAPHI_BINUM9_MASK 0x0000000FU +#define USB3_GPRTBIMAPHI_BINUM9_POS 0U + +/* Bit fields of GHWPARAMS0 register */ +#define USB3_GHWPARAMS0_GHWPARAMS0_31_24_MASK 0xFF000000U +#define USB3_GHWPARAMS0_GHWPARAMS0_31_24_POS 24U +#define USB3_GHWPARAMS0_GHWPARAMS0_23_16_MASK 0x00FF0000U +#define USB3_GHWPARAMS0_GHWPARAMS0_23_16_POS 16U +#define USB3_GHWPARAMS0_GHWPARAMS0_15_8_MASK 0x0000FF00U +#define USB3_GHWPARAMS0_GHWPARAMS0_15_8_POS 8U +#define USB3_GHWPARAMS0_GHWPARAMS0_7_6_MASK 0x000000C0U +#define USB3_GHWPARAMS0_GHWPARAMS0_7_6_POS 6U +#define USB3_GHWPARAMS0_GHWPARAMS0_5_3_MASK 0x00000038U +#define USB3_GHWPARAMS0_GHWPARAMS0_5_3_POS 3U +#define USB3_GHWPARAMS0_GHWPARAMS0_2_0_MASK 0x00000007U +#define USB3_GHWPARAMS0_GHWPARAMS0_2_0_POS 0U + +/* Bit fields of GHWPARAMS1 register */ +#define USB3_GHWPARAMS1_GHWPARAMS1_31_MASK 0x80000000U +#define USB3_GHWPARAMS1_GHWPARAMS1_31_POS 31U +#define USB3_GHWPARAMS1_GHWPARAMS1_30_MASK 0x40000000U +#define USB3_GHWPARAMS1_GHWPARAMS1_30_POS 30U +#define USB3_GHWPARAMS1_GHWPARAMS1_29_MASK 0x20000000U +#define USB3_GHWPARAMS1_GHWPARAMS1_29_POS 29U +#define USB3_GHWPARAMS1_GHWPARAMS1_28_MASK 0x10000000U +#define USB3_GHWPARAMS1_GHWPARAMS1_28_POS 28U +#define USB3_GHWPARAMS1_GHWPARAMS1_27_MASK 0x08000000U +#define USB3_GHWPARAMS1_GHWPARAMS1_27_POS 27U +#define USB3_GHWPARAMS1_GHWPARAMS1_26_MASK 0x04000000U +#define USB3_GHWPARAMS1_GHWPARAMS1_26_POS 26U +#define USB3_GHWPARAMS1_GHWPARAMS1_25_24_MASK 0x03000000U +#define USB3_GHWPARAMS1_GHWPARAMS1_25_24_POS 24U +#define USB3_GHWPARAMS1_GHWPARAMS1_23_MASK 0x00800000U +#define USB3_GHWPARAMS1_GHWPARAMS1_23_POS 23U +#define USB3_GHWPARAMS1_GHWPARAMS1_22_17_MASK 0x007E0000U +#define USB3_GHWPARAMS1_GHWPARAMS1_22_17_POS 17U +#define USB3_GHWPARAMS1_GHWPARAMS1_16_14_MASK 0x0001C000U +#define USB3_GHWPARAMS1_GHWPARAMS1_16_14_POS 14U +#define USB3_GHWPARAMS1_GHWPARAMS1_13_11_MASK 0x00003800U +#define USB3_GHWPARAMS1_GHWPARAMS1_13_11_POS 11U +#define USB3_GHWPARAMS1_GHWPARAMS1_10_8_MASK 0x00000700U +#define USB3_GHWPARAMS1_GHWPARAMS1_10_8_POS 8U +#define USB3_GHWPARAMS1_GHWPARAMS1_7_4_MASK 0x000000F0U +#define USB3_GHWPARAMS1_GHWPARAMS1_7_4_POS 4U +#define USB3_GHWPARAMS1_GHWPARAMS1_3_0_MASK 0x0000000FU +#define USB3_GHWPARAMS1_GHWPARAMS1_3_0_POS 0U + +/* Bit fields of GHWPARAMS2 register */ +#define USB3_GHWPARAMS2_GHWPARAMS2_31_0_MASK 0xFFFFFFFFU +#define USB3_GHWPARAMS2_GHWPARAMS2_31_0_POS 0U + +/* Bit fields of GHWPARAMS3 register */ +#define USB3_GHWPARAMS3_GHWPARAMS3_31_MASK 0x80000000U +#define USB3_GHWPARAMS3_GHWPARAMS3_31_POS 31U +#define USB3_GHWPARAMS3_GHWPARAMS3_30_23_MASK 0x7F800000U +#define USB3_GHWPARAMS3_GHWPARAMS3_30_23_POS 23U +#define USB3_GHWPARAMS3_GHWPARAMS3_22_18_MASK 0x007C0000U +#define USB3_GHWPARAMS3_GHWPARAMS3_22_18_POS 18U +#define USB3_GHWPARAMS3_GHWPARAMS3_17_12_MASK 0x0003F000U +#define USB3_GHWPARAMS3_GHWPARAMS3_17_12_POS 12U +#define USB3_GHWPARAMS3_GHWPARAMS3_11_MASK 0x00000800U +#define USB3_GHWPARAMS3_GHWPARAMS3_11_POS 11U +#define USB3_GHWPARAMS3_GHWPARAMS3_10_MASK 0x00000400U +#define USB3_GHWPARAMS3_GHWPARAMS3_10_POS 10U +#define USB3_GHWPARAMS3_GHWPARAMS3_9_8_MASK 0x00000300U +#define USB3_GHWPARAMS3_GHWPARAMS3_9_8_POS 8U +#define USB3_GHWPARAMS3_GHWPARAMS3_7_6_MASK 0x000000C0U +#define USB3_GHWPARAMS3_GHWPARAMS3_7_6_POS 6U +#define USB3_GHWPARAMS3_GHWPARAMS3_5_4_MASK 0x00000030U +#define USB3_GHWPARAMS3_GHWPARAMS3_5_4_POS 4U +#define USB3_GHWPARAMS3_GHWPARAMS3_3_2_MASK 0x0000000CU +#define USB3_GHWPARAMS3_GHWPARAMS3_3_2_POS 2U +#define USB3_GHWPARAMS3_GHWPARAMS3_1_0_MASK 0x00000003U +#define USB3_GHWPARAMS3_GHWPARAMS3_1_0_POS 0U + +/* Bit fields of GHWPARAMS4 register */ +#define USB3_GHWPARAMS4_GHWPARAMS4_31_28_MASK 0xF0000000U +#define USB3_GHWPARAMS4_GHWPARAMS4_31_28_POS 28U +#define USB3_GHWPARAMS4_GHWPARAMS4_27_23_MASK 0x0F800000U +#define USB3_GHWPARAMS4_GHWPARAMS4_27_23_POS 23U +#define USB3_GHWPARAMS4_GHWPARAMS4_22_MASK 0x00400000U +#define USB3_GHWPARAMS4_GHWPARAMS4_22_POS 22U +#define USB3_GHWPARAMS4_GHWPARAMS4_21_MASK 0x00200000U +#define USB3_GHWPARAMS4_GHWPARAMS4_21_POS 21U +#define USB3_GHWPARAMS4_GHWPARAMS4_20_17_MASK 0x001E0000U +#define USB3_GHWPARAMS4_GHWPARAMS4_20_17_POS 17U +#define USB3_GHWPARAMS4_GHWPARAMS4_16_13_MASK 0x0001E000U +#define USB3_GHWPARAMS4_GHWPARAMS4_16_13_POS 13U +#define USB3_GHWPARAMS4_GHWPARAMS4_12_6_MASK 0x00001FC0U +#define USB3_GHWPARAMS4_GHWPARAMS4_12_6_POS 6U +#define USB3_GHWPARAMS4_GHWPARAMS4_5_0_MASK 0x0000003FU +#define USB3_GHWPARAMS4_GHWPARAMS4_5_0_POS 0U + +/* Bit fields of GHWPARAMS5 register */ +#define USB3_GHWPARAMS5_GHWPARAMS5_31_29_MASK 0xE0000000U +#define USB3_GHWPARAMS5_GHWPARAMS5_31_29_POS 29U +#define USB3_GHWPARAMS5_GHWPARAMS5_28_23_MASK 0x1F800000U +#define USB3_GHWPARAMS5_GHWPARAMS5_28_23_POS 23U +#define USB3_GHWPARAMS5_GHWPARAMS5_22_17_MASK 0x007E0000U +#define USB3_GHWPARAMS5_GHWPARAMS5_22_17_POS 17U +#define USB3_GHWPARAMS5_GHWPARAMS5_16_11_MASK 0x0001F800U +#define USB3_GHWPARAMS5_GHWPARAMS5_16_11_POS 11U +#define USB3_GHWPARAMS5_GHWPARAMS5_10_5_MASK 0x000007E0U +#define USB3_GHWPARAMS5_GHWPARAMS5_10_5_POS 5U +#define USB3_GHWPARAMS5_GHWPARAMS5_4_0_MASK 0x0000001FU +#define USB3_GHWPARAMS5_GHWPARAMS5_4_0_POS 0U + +/* Bit fields of GHWPARAMS6 register */ +#define USB3_GHWPARAMS6_GHWPARAMS6_31_16_MASK 0xFFFF0000U +#define USB3_GHWPARAMS6_GHWPARAMS6_31_16_POS 16U +#define USB3_GHWPARAMS6_BUSFLTRSSUPPORT_MASK 0x00008000U +#define USB3_GHWPARAMS6_BUSFLTRSSUPPORT_POS 15U +#define USB3_GHWPARAMS6_GHWPARAMS6_14_10_MASK 0x00007C00U +#define USB3_GHWPARAMS6_GHWPARAMS6_14_10_POS 10U +#define USB3_GHWPARAMS6_GHWPARAMS6_9_8_MASK 0x00000300U +#define USB3_GHWPARAMS6_GHWPARAMS6_9_8_POS 8U +#define USB3_GHWPARAMS6_GHWPARAMS6_7_MASK 0x00000080U +#define USB3_GHWPARAMS6_GHWPARAMS6_7_POS 7U +#define USB3_GHWPARAMS6_GHWPARAMS6_6_MASK 0x00000040U +#define USB3_GHWPARAMS6_GHWPARAMS6_6_POS 6U +#define USB3_GHWPARAMS6_GHWPARAMS6_5_0_MASK 0x0000003FU +#define USB3_GHWPARAMS6_GHWPARAMS6_5_0_POS 0U + +/* Bit fields of GHWPARAMS7 register */ +#define USB3_GHWPARAMS7_GHWPARAMS7_31_16_MASK 0xFFFF0000U +#define USB3_GHWPARAMS7_GHWPARAMS7_31_16_POS 16U +#define USB3_GHWPARAMS7_GHWPARAMS7_15_0_MASK 0x0000FFFFU +#define USB3_GHWPARAMS7_GHWPARAMS7_15_0_POS 0U + +/* Bit fields of GDBGFIFOSPACE register */ +#define USB3_GDBGFIFOSPACE_SPACE_AVAILABLE_MASK 0xFFFF0000U +#define USB3_GDBGFIFOSPACE_SPACE_AVAILABLE_POS 16U +#define USB3_GDBGFIFOSPACE_FIFO_QUEUE_SELECT_MASK 0x000001FFU +#define USB3_GDBGFIFOSPACE_FIFO_QUEUE_SELECT_POS 0U + +/* Bit fields of GBMUCTL register */ +#define USB3_GBMUCTL_SEPARATE_PSQ_EN_MASK 0x00000020U +#define USB3_GBMUCTL_SEPARATE_PSQ_EN_POS 5U +#define USB3_GBMUCTL_AXI_STORDER_EN_MASK 0x00000004U +#define USB3_GBMUCTL_AXI_STORDER_EN_POS 2U +#define USB3_GBMUCTL_ACTIVE_ID_EN_MASK 0x00000002U +#define USB3_GBMUCTL_ACTIVE_ID_EN_POS 1U + +/* Bit fields of GDBGBMU register */ +#define USB3_GDBGBMU_BMU_BCU_MASK 0xFFFFFF00U +#define USB3_GDBGBMU_BMU_BCU_POS 8U +#define USB3_GDBGBMU_BMU_DCU_MASK 0x000000F0U +#define USB3_GDBGBMU_BMU_DCU_POS 4U +#define USB3_GDBGBMU_BMU_CCU_MASK 0x0000000FU +#define USB3_GDBGBMU_BMU_CCU_POS 0U + +/* Bit fields of GDBGLSPMUX register */ +#define USB3_GDBGLSPMUX_LOGIC_ANALYZER_TRACE_MASK 0x00FF0000U +#define USB3_GDBGLSPMUX_LOGIC_ANALYZER_TRACE_POS 16U +#define USB3_GDBGLSPMUX_LSPSELECT_MASK 0x00007FFFU +#define USB3_GDBGLSPMUX_LSPSELECT_POS 0U + +/* Bit fields of GDBGLSP register */ +#define USB3_GDBGLSP_LSPDEBUG_MASK 0xFFFFFFFFU +#define USB3_GDBGLSP_LSPDEBUG_POS 0U + +/* Bit fields of GDBGEPINFO0 register */ +#define USB3_GDBGEPINFO0_EPDEBUG_MASK 0xFFFFFFFFU +#define USB3_GDBGEPINFO0_EPDEBUG_POS 0U + +/* Bit fields of GDBGEPINFO1 register */ +#define USB3_GDBGEPINFO1_EPDEBUG_MASK 0xFFFFFFFFU +#define USB3_GDBGEPINFO1_EPDEBUG_POS 0U + +/* Bit fields of GPRTBIMAP_HSLO register */ +#define USB3_GPRTBIMAP_HSLO_BINUM8_MASK 0xF0000000U +#define USB3_GPRTBIMAP_HSLO_BINUM8_POS 28U +#define USB3_GPRTBIMAP_HSLO_BINUM7_MASK 0x0F000000U +#define USB3_GPRTBIMAP_HSLO_BINUM7_POS 24U +#define USB3_GPRTBIMAP_HSLO_BINUM6_MASK 0x00F00000U +#define USB3_GPRTBIMAP_HSLO_BINUM6_POS 20U +#define USB3_GPRTBIMAP_HSLO_BINUM5_MASK 0x000F0000U +#define USB3_GPRTBIMAP_HSLO_BINUM5_POS 16U +#define USB3_GPRTBIMAP_HSLO_BINUM4_MASK 0x0000F000U +#define USB3_GPRTBIMAP_HSLO_BINUM4_POS 12U +#define USB3_GPRTBIMAP_HSLO_BINUM3_MASK 0x00000F00U +#define USB3_GPRTBIMAP_HSLO_BINUM3_POS 8U +#define USB3_GPRTBIMAP_HSLO_BINUM2_MASK 0x000000F0U +#define USB3_GPRTBIMAP_HSLO_BINUM2_POS 4U +#define USB3_GPRTBIMAP_HSLO_BINUM1_MASK 0x0000000FU +#define USB3_GPRTBIMAP_HSLO_BINUM1_POS 0U + +/* Bit fields of GPRTBIMAP_HSHI register */ +#define USB3_GPRTBIMAP_HSHI_BINUM15_MASK 0x0F000000U +#define USB3_GPRTBIMAP_HSHI_BINUM15_POS 24U +#define USB3_GPRTBIMAP_HSHI_BINUM14_MASK 0x00F00000U +#define USB3_GPRTBIMAP_HSHI_BINUM14_POS 20U +#define USB3_GPRTBIMAP_HSHI_BINUM13_MASK 0x000F0000U +#define USB3_GPRTBIMAP_HSHI_BINUM13_POS 16U +#define USB3_GPRTBIMAP_HSHI_BINUM12_MASK 0x0000F000U +#define USB3_GPRTBIMAP_HSHI_BINUM12_POS 12U +#define USB3_GPRTBIMAP_HSHI_BINUM11_MASK 0x00000F00U +#define USB3_GPRTBIMAP_HSHI_BINUM11_POS 8U +#define USB3_GPRTBIMAP_HSHI_BINUM10_MASK 0x000000F0U +#define USB3_GPRTBIMAP_HSHI_BINUM10_POS 4U +#define USB3_GPRTBIMAP_HSHI_BINUM9_MASK 0x0000000FU +#define USB3_GPRTBIMAP_HSHI_BINUM9_POS 0U + +/* Bit fields of GPRTBIMAP_FSLO register */ +#define USB3_GPRTBIMAP_FSLO_BINUM8_MASK 0xF0000000U +#define USB3_GPRTBIMAP_FSLO_BINUM8_POS 28U +#define USB3_GPRTBIMAP_FSLO_BINUM7_MASK 0x0F000000U +#define USB3_GPRTBIMAP_FSLO_BINUM7_POS 24U +#define USB3_GPRTBIMAP_FSLO_BINUM6_MASK 0x00F00000U +#define USB3_GPRTBIMAP_FSLO_BINUM6_POS 20U +#define USB3_GPRTBIMAP_FSLO_BINUM5_MASK 0x000F0000U +#define USB3_GPRTBIMAP_FSLO_BINUM5_POS 16U +#define USB3_GPRTBIMAP_FSLO_BINUM4_MASK 0x0000F000U +#define USB3_GPRTBIMAP_FSLO_BINUM4_POS 12U +#define USB3_GPRTBIMAP_FSLO_BINUM3_MASK 0x00000F00U +#define USB3_GPRTBIMAP_FSLO_BINUM3_POS 8U +#define USB3_GPRTBIMAP_FSLO_BINUM2_MASK 0x000000F0U +#define USB3_GPRTBIMAP_FSLO_BINUM2_POS 4U +#define USB3_GPRTBIMAP_FSLO_BINUM1_MASK 0x0000000FU +#define USB3_GPRTBIMAP_FSLO_BINUM1_POS 0U + +/* Bit fields of GPRTBIMAP_FSHI register */ +#define USB3_GPRTBIMAP_FSHI_BINUM15_MASK 0x0F000000U +#define USB3_GPRTBIMAP_FSHI_BINUM15_POS 24U +#define USB3_GPRTBIMAP_FSHI_BINUM14_MASK 0x00F00000U +#define USB3_GPRTBIMAP_FSHI_BINUM14_POS 20U +#define USB3_GPRTBIMAP_FSHI_BINUM13_MASK 0x000F0000U +#define USB3_GPRTBIMAP_FSHI_BINUM13_POS 16U +#define USB3_GPRTBIMAP_FSHI_BINUM12_MASK 0x0000F000U +#define USB3_GPRTBIMAP_FSHI_BINUM12_POS 12U +#define USB3_GPRTBIMAP_FSHI_BINUM11_MASK 0x00000F00U +#define USB3_GPRTBIMAP_FSHI_BINUM11_POS 8U +#define USB3_GPRTBIMAP_FSHI_BINUM10_MASK 0x000000F0U +#define USB3_GPRTBIMAP_FSHI_BINUM10_POS 4U +#define USB3_GPRTBIMAP_FSHI_BINUM9_MASK 0x0000000FU +#define USB3_GPRTBIMAP_FSHI_BINUM9_POS 0U + +/* Bit fields of GHMSOCBWOR register */ +#define USB3_GHMSOCBWOR_OVRD_PORT_SOC_BW_MASK 0x80000000U +#define USB3_GHMSOCBWOR_OVRD_PORT_SOC_BW_POS 31U +#define USB3_GHMSOCBWOR_OVRD_COMMON_SOC_RD_WR_MASK 0x40000000U +#define USB3_GHMSOCBWOR_OVRD_COMMON_SOC_RD_WR_POS 30U +#define USB3_GHMSOCBWOR_OVRD_SOC_WR_UF_KB_BANDWIDTH_MASK 0x3FFF8000U +#define USB3_GHMSOCBWOR_OVRD_SOC_WR_UF_KB_BANDWIDTH_POS 15U +#define USB3_GHMSOCBWOR_OVRD_SOC_RD_UF_KB_BANDWIDTH_MASK 0x00007FFFU +#define USB3_GHMSOCBWOR_OVRD_SOC_RD_UF_KB_BANDWIDTH_POS 0U + +/* Bit fields of USB31_VER_NUMBER register */ +#define USB3_USB31_VER_NUMBER_VERSION_NUM_MASK 0xFFFFFFFFU +#define USB3_USB31_VER_NUMBER_VERSION_NUM_POS 0U + +/* Bit fields of USB31_VER_TYPE register */ +#define USB3_USB31_VER_TYPE_VERSIONTYPE_MASK 0xFFFFFFFFU +#define USB3_USB31_VER_TYPE_VERSIONTYPE_POS 0U + +/* Bit fields of GSYSBLKWINCTRL register */ +#define USB3_GSYSBLKWINCTRL_SYS_BLOCKING_OK_ALL_THE_TIME_MASK 0x80000000U +#define USB3_GSYSBLKWINCTRL_SYS_BLOCKING_OK_ALL_THE_TIME_POS 31U +#define USB3_GSYSBLKWINCTRL_DISABLE_NO_BLOCKING_WINDOW_MASK 0x40000000U +#define USB3_GSYSBLKWINCTRL_DISABLE_NO_BLOCKING_WINDOW_POS 30U +#define USB3_GSYSBLKWINCTRL_ERST_PREFETCHING_EN_MASK 0x20000000U +#define USB3_GSYSBLKWINCTRL_ERST_PREFETCHING_EN_POS 29U +#define USB3_GSYSBLKWINCTRL_ERST_PREFETCHING_WATERMARK_MASK 0x1F000000U +#define USB3_GSYSBLKWINCTRL_ERST_PREFETCHING_WATERMARK_POS 24U +#define USB3_GSYSBLKWINCTRL_END_NO_BLOCKING_TIME_MASK 0x0000FF00U +#define USB3_GSYSBLKWINCTRL_END_NO_BLOCKING_TIME_POS 8U +#define USB3_GSYSBLKWINCTRL_BEGININING_NO_BLOCKING_TIME_MASK 0x000000FFU +#define USB3_GSYSBLKWINCTRL_BEGININING_NO_BLOCKING_TIME_POS 0U + +/* Bit fields of GPCIEL1EXTLAT register */ +#define USB3_GPCIEL1EXTLAT_PCIE_L1_EXIT_MODE_CTRL_MASK 0xC0000000U +#define USB3_GPCIEL1EXTLAT_PCIE_L1_EXIT_MODE_CTRL_POS 30U +#define USB3_GPCIEL1EXTLAT_PCIE_L1_EXIT_LATENCY_MASK 0x00000FFFU +#define USB3_GPCIEL1EXTLAT_PCIE_L1_EXIT_LATENCY_POS 0U + +/* Bit fields of GUSB2PHYCFG register */ +#define USB3_GUSB2PHYCFG_PHYSOFTRST_MASK 0x80000000U +#define USB3_GUSB2PHYCFG_PHYSOFTRST_POS 31U +#define USB3_GUSB2PHYCFG_ULPI_LPM_WITH_OPMODE_CHK_MASK 0x20000000U +#define USB3_GUSB2PHYCFG_ULPI_LPM_WITH_OPMODE_CHK_POS 29U +#define USB3_GUSB2PHYCFG_HSIC_CON_WIDTH_ADJ_MASK 0x18000000U +#define USB3_GUSB2PHYCFG_HSIC_CON_WIDTH_ADJ_POS 27U +#define USB3_GUSB2PHYCFG_INV_SEL_HSIC_MASK 0x04000000U +#define USB3_GUSB2PHYCFG_INV_SEL_HSIC_POS 26U +#define USB3_GUSB2PHYCFG_OVRD_FSLS_DISC_TIME_MASK 0x02000000U +#define USB3_GUSB2PHYCFG_OVRD_FSLS_DISC_TIME_POS 25U +#define USB3_GUSB2PHYCFG_LSTRD_MASK 0x01C00000U +#define USB3_GUSB2PHYCFG_LSTRD_POS 22U +#define USB3_GUSB2PHYCFG_LSIPD_MASK 0x00380000U +#define USB3_GUSB2PHYCFG_LSIPD_POS 19U +#define USB3_GUSB2PHYCFG_ULPIEXTVBUSINDIACTOR_MASK 0x00040000U +#define USB3_GUSB2PHYCFG_ULPIEXTVBUSINDIACTOR_POS 18U +#define USB3_GUSB2PHYCFG_ULPIEXTVBUSDRV_MASK 0x00020000U +#define USB3_GUSB2PHYCFG_ULPIEXTVBUSDRV_POS 17U +#define USB3_GUSB2PHYCFG_ULPIAUTORES_MASK 0x00008000U +#define USB3_GUSB2PHYCFG_ULPIAUTORES_POS 15U +#define USB3_GUSB2PHYCFG_EUSB2OPMODE_MASK 0x00004000U +#define USB3_GUSB2PHYCFG_EUSB2OPMODE_POS 14U +#define USB3_GUSB2PHYCFG_USBTRDTIM_MASK 0x00003C00U +#define USB3_GUSB2PHYCFG_USBTRDTIM_POS 10U +#define USB3_GUSB2PHYCFG_XCVRDLY_MASK 0x00000200U +#define USB3_GUSB2PHYCFG_XCVRDLY_POS 9U +#define USB3_GUSB2PHYCFG_ENBLSLPM_MASK 0x00000100U +#define USB3_GUSB2PHYCFG_ENBLSLPM_POS 8U +#define USB3_GUSB2PHYCFG_PHYSEL_MASK 0x00000080U +#define USB3_GUSB2PHYCFG_PHYSEL_POS 7U +#define USB3_GUSB2PHYCFG_SUSPENDUSB20_MASK 0x00000040U +#define USB3_GUSB2PHYCFG_SUSPENDUSB20_POS 6U +#define USB3_GUSB2PHYCFG_FSINTF_MASK 0x00000020U +#define USB3_GUSB2PHYCFG_FSINTF_POS 5U +#define USB3_GUSB2PHYCFG_ULPI_UTMI_SEL_MASK 0x00000010U +#define USB3_GUSB2PHYCFG_ULPI_UTMI_SEL_POS 4U +#define USB3_GUSB2PHYCFG_PHYIF_MASK 0x00000008U +#define USB3_GUSB2PHYCFG_PHYIF_POS 3U +#define USB3_GUSB2PHYCFG_TOUTCAL_MASK 0x00000007U +#define USB3_GUSB2PHYCFG_TOUTCAL_POS 0U + +/* Bit fields of GUSB2PHYACC_ULPI register */ +#define USB3_GUSB2PHYACC_ULPI_DISUIPIDRVR_MASK 0x04000000U +#define USB3_GUSB2PHYACC_ULPI_DISUIPIDRVR_POS 26U +#define USB3_GUSB2PHYACC_ULPI_NEWREGREQ_MASK 0x02000000U +#define USB3_GUSB2PHYACC_ULPI_NEWREGREQ_POS 25U +#define USB3_GUSB2PHYACC_ULPI_VSTSDONE_MASK 0x01000000U +#define USB3_GUSB2PHYACC_ULPI_VSTSDONE_POS 24U +#define USB3_GUSB2PHYACC_ULPI_VSTSBSY_MASK 0x00800000U +#define USB3_GUSB2PHYACC_ULPI_VSTSBSY_POS 23U +#define USB3_GUSB2PHYACC_ULPI_REGWR_MASK 0x00400000U +#define USB3_GUSB2PHYACC_ULPI_REGWR_POS 22U +#define USB3_GUSB2PHYACC_ULPI_REGADDR_MASK 0x003F0000U +#define USB3_GUSB2PHYACC_ULPI_REGADDR_POS 16U +#define USB3_GUSB2PHYACC_ULPI_EXTREGADDR_MASK 0x0000FF00U +#define USB3_GUSB2PHYACC_ULPI_EXTREGADDR_POS 8U +#define USB3_GUSB2PHYACC_ULPI_REGDATA_MASK 0x000000FFU +#define USB3_GUSB2PHYACC_ULPI_REGDATA_POS 0U + +/* Bit fields of GUSB3PIPECTL register */ +#define USB3_GUSB3PIPECTL_PHYSOFTRST_MASK 0x80000000U +#define USB3_GUSB3PIPECTL_PHYSOFTRST_POS 31U +#define USB3_GUSB3PIPECTL_HSTPRTCMPL_MASK 0x40000000U +#define USB3_GUSB3PIPECTL_HSTPRTCMPL_POS 30U +#define USB3_GUSB3PIPECTL_U2P3OK_MASK 0x20000000U +#define USB3_GUSB3PIPECTL_U2P3OK_POS 29U +#define USB3_GUSB3PIPECTL_DISRXDETP3_MASK 0x10000000U +#define USB3_GUSB3PIPECTL_DISRXDETP3_POS 28U +#define USB3_GUSB3PIPECTL_UX_EXIT_IN_PX_MASK 0x08000000U +#define USB3_GUSB3PIPECTL_UX_EXIT_IN_PX_POS 27U +#define USB3_GUSB3PIPECTL_PING_ENHANCEMENT_EN_MASK 0x04000000U +#define USB3_GUSB3PIPECTL_PING_ENHANCEMENT_EN_POS 26U +#define USB3_GUSB3PIPECTL_U1U2EXITFAIL_TO_RECOV_MASK 0x02000000U +#define USB3_GUSB3PIPECTL_U1U2EXITFAIL_TO_RECOV_POS 25U +#define USB3_GUSB3PIPECTL_REQUEST_P1P2P3_MASK 0x01000000U +#define USB3_GUSB3PIPECTL_REQUEST_P1P2P3_POS 24U +#define USB3_GUSB3PIPECTL_STARTRXDETU3RXDET_MASK 0x00800000U +#define USB3_GUSB3PIPECTL_STARTRXDETU3RXDET_POS 23U +#define USB3_GUSB3PIPECTL_DISRXDETU3RXDET_MASK 0x00400000U +#define USB3_GUSB3PIPECTL_DISRXDETU3RXDET_POS 22U +#define USB3_GUSB3PIPECTL_DELAYP1P2P3_MASK 0x00380000U +#define USB3_GUSB3PIPECTL_DELAYP1P2P3_POS 19U +#define USB3_GUSB3PIPECTL_DELAYP1TRANS_MASK 0x00040000U +#define USB3_GUSB3PIPECTL_DELAYP1TRANS_POS 18U +#define USB3_GUSB3PIPECTL_SUSPENDENABLE_MASK 0x00020000U +#define USB3_GUSB3PIPECTL_SUSPENDENABLE_POS 17U +#define USB3_GUSB3PIPECTL_DATWIDTH_MASK 0x00018000U +#define USB3_GUSB3PIPECTL_DATWIDTH_POS 15U +#define USB3_GUSB3PIPECTL_ABORTRXDETINU2_MASK 0x00004000U +#define USB3_GUSB3PIPECTL_ABORTRXDETINU2_POS 14U +#define USB3_GUSB3PIPECTL_SKIPRXDET_MASK 0x00002000U +#define USB3_GUSB3PIPECTL_SKIPRXDET_POS 13U +#define USB3_GUSB3PIPECTL_LFPSP0ALGN_MASK 0x00001000U +#define USB3_GUSB3PIPECTL_LFPSP0ALGN_POS 12U +#define USB3_GUSB3PIPECTL_P3P2TRANOK_MASK 0x00000800U +#define USB3_GUSB3PIPECTL_P3P2TRANOK_POS 11U +#define USB3_GUSB3PIPECTL_P3EXSIGP2_MASK 0x00000400U +#define USB3_GUSB3PIPECTL_P3EXSIGP2_POS 10U +#define USB3_GUSB3PIPECTL_LFPSFILTER_MASK 0x00000200U +#define USB3_GUSB3PIPECTL_LFPSFILTER_POS 9U +#define USB3_GUSB3PIPECTL_RX_DETECT_TO_POLLING_LFPS_CONTROL_MASK 0x00000100U +#define USB3_GUSB3PIPECTL_RX_DETECT_TO_POLLING_LFPS_CONTROL_POS 8U +#define USB3_GUSB3PIPECTL_TX_SWING_MASK 0x00000040U +#define USB3_GUSB3PIPECTL_TX_SWING_POS 6U +#define USB3_GUSB3PIPECTL_TX_MARGIN_MASK 0x00000038U +#define USB3_GUSB3PIPECTL_TX_MARGIN_POS 3U +#define USB3_GUSB3PIPECTL_SS_TX_DE_EMPHASIS_MASK 0x00000006U +#define USB3_GUSB3PIPECTL_SS_TX_DE_EMPHASIS_POS 1U +#define USB3_GUSB3PIPECTL_ELASTIC_BUFFER_MODE_MASK 0x00000001U +#define USB3_GUSB3PIPECTL_ELASTIC_BUFFER_MODE_POS 0U + +/* Bit fields of GTXFIFOSIZ0 register */ +#define USB3_GTXFIFOSIZ0_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ0_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ0_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ0_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ1 register */ +#define USB3_GTXFIFOSIZ1_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ1_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ1_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ1_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ2 register */ +#define USB3_GTXFIFOSIZ2_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ2_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ2_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ2_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ3 register */ +#define USB3_GTXFIFOSIZ3_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ3_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ3_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ3_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ4 register */ +#define USB3_GTXFIFOSIZ4_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ4_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ4_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ4_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ5 register */ +#define USB3_GTXFIFOSIZ5_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ5_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ5_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ5_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ6 register */ +#define USB3_GTXFIFOSIZ6_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ6_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ6_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ6_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ7 register */ +#define USB3_GTXFIFOSIZ7_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ7_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ7_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ7_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ8 register */ +#define USB3_GTXFIFOSIZ8_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ8_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ8_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ8_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ9 register */ +#define USB3_GTXFIFOSIZ9_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ9_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ9_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ9_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ10 register */ +#define USB3_GTXFIFOSIZ10_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ10_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ10_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ10_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ11 register */ +#define USB3_GTXFIFOSIZ11_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ11_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ11_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ11_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ12 register */ +#define USB3_GTXFIFOSIZ12_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ12_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ12_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ12_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ13 register */ +#define USB3_GTXFIFOSIZ13_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ13_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ13_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ13_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ14 register */ +#define USB3_GTXFIFOSIZ14_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ14_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ14_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ14_TXFDEP_N_POS 0U + +/* Bit fields of GTXFIFOSIZ15 register */ +#define USB3_GTXFIFOSIZ15_TXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GTXFIFOSIZ15_TXFSTADDR_N_POS 16U +#define USB3_GTXFIFOSIZ15_TXFDEP_N_MASK 0x00007FFFU +#define USB3_GTXFIFOSIZ15_TXFDEP_N_POS 0U + +/* Bit fields of GRXFIFOSIZ0 register */ +#define USB3_GRXFIFOSIZ0_RXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GRXFIFOSIZ0_RXFSTADDR_N_POS 16U +#define USB3_GRXFIFOSIZ0_RXFDEP_N_MASK 0x00007FFFU +#define USB3_GRXFIFOSIZ0_RXFDEP_N_POS 0U + +/* Bit fields of GRXFIFOSIZ1 register */ +#define USB3_GRXFIFOSIZ1_RXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GRXFIFOSIZ1_RXFSTADDR_N_POS 16U +#define USB3_GRXFIFOSIZ1_RXFDEP_N_MASK 0x00007FFFU +#define USB3_GRXFIFOSIZ1_RXFDEP_N_POS 0U + +/* Bit fields of GRXFIFOSIZ2 register */ +#define USB3_GRXFIFOSIZ2_RXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GRXFIFOSIZ2_RXFSTADDR_N_POS 16U +#define USB3_GRXFIFOSIZ2_RXFDEP_N_MASK 0x00007FFFU +#define USB3_GRXFIFOSIZ2_RXFDEP_N_POS 0U + +/* Bit fields of GRXFIFOSIZ3 register */ +#define USB3_GRXFIFOSIZ3_RXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GRXFIFOSIZ3_RXFSTADDR_N_POS 16U +#define USB3_GRXFIFOSIZ3_RXFDEP_N_MASK 0x00007FFFU +#define USB3_GRXFIFOSIZ3_RXFDEP_N_POS 0U + +/* Bit fields of GRXFIFOSIZ4 register */ +#define USB3_GRXFIFOSIZ4_RXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GRXFIFOSIZ4_RXFSTADDR_N_POS 16U +#define USB3_GRXFIFOSIZ4_RXFDEP_N_MASK 0x00007FFFU +#define USB3_GRXFIFOSIZ4_RXFDEP_N_POS 0U + +/* Bit fields of GRXFIFOSIZ5 register */ +#define USB3_GRXFIFOSIZ5_RXFSTADDR_N_MASK 0xFFFF0000U +#define USB3_GRXFIFOSIZ5_RXFSTADDR_N_POS 16U +#define USB3_GRXFIFOSIZ5_RXFDEP_N_MASK 0x00007FFFU +#define USB3_GRXFIFOSIZ5_RXFDEP_N_POS 0U + +/* Bit fields of GEVNTADRLO register */ +#define USB3_GEVNTADRLO_EVNTADRLO_MASK 0xFFFFFFFFU +#define USB3_GEVNTADRLO_EVNTADRLO_POS 0U + +/* Bit fields of GEVNTADRHI register */ +#define USB3_GEVNTADRHI_EVNTADRHI_MASK 0xFFFFFFFFU +#define USB3_GEVNTADRHI_EVNTADRHI_POS 0U + +/* Bit fields of GEVNTSIZ register */ +#define USB3_GEVNTSIZ_EVNTINTRPTMASK_MASK 0x80000000U +#define USB3_GEVNTSIZ_EVNTINTRPTMASK_POS 31U +#define USB3_GEVNTSIZ_EVENTSIZ_MASK 0x0000FFFFU +#define USB3_GEVNTSIZ_EVENTSIZ_POS 0U + +/* Bit fields of GEVNTCOUNT register */ +#define USB3_GEVNTCOUNT_EVNT_HANDLER_BUSY_MASK 0x80000000U +#define USB3_GEVNTCOUNT_EVNT_HANDLER_BUSY_POS 31U +#define USB3_GEVNTCOUNT_EVNTCOUNT_MASK 0x0000FFFFU +#define USB3_GEVNTCOUNT_EVNTCOUNT_POS 0U + +/* Bit fields of GHWPARAMS8 register */ +#define USB3_GHWPARAMS8_GHWPARAMS8_32_0_MASK 0xFFFFFFFFU +#define USB3_GHWPARAMS8_GHWPARAMS8_32_0_POS 0U + +/* Bit fields of GSMACCTL register */ +#define USB3_GSMACCTL_DBG_TIS_INDEX_MASK 0xC0000000U +#define USB3_GSMACCTL_DBG_TIS_INDEX_POS 30U +#define USB3_GSMACCTL_DBG_PTL_ADDR_MASK 0x3C000000U +#define USB3_GSMACCTL_DBG_PTL_ADDR_POS 26U +#define USB3_GSMACCTL_HOSTIN_SIGNLE_EN_MASK 0x00020000U +#define USB3_GSMACCTL_HOSTIN_SIGNLE_EN_POS 17U +#define USB3_GSMACCTL_HOSTOUT_SINGLE_EN_MASK 0x00010000U +#define USB3_GSMACCTL_HOSTOUT_SINGLE_EN_POS 16U +#define USB3_GSMACCTL_SINGLE_PSQDIR_EN_MASK 0x00000008U +#define USB3_GSMACCTL_SINGLE_PSQDIR_EN_POS 3U +#define USB3_GSMACCTL_HOST_MASK_NUMP0_MASK 0x00000004U +#define USB3_GSMACCTL_HOST_MASK_NUMP0_POS 2U +#define USB3_GSMACCTL_IGNORE_BABBLE_MASK 0x00000002U +#define USB3_GSMACCTL_IGNORE_BABBLE_POS 1U +#define USB3_GSMACCTL_SINGLE_TBT_REQ_MASK 0x00000001U +#define USB3_GSMACCTL_SINGLE_TBT_REQ_POS 0U + +/* Bit fields of GUCTL2 register */ +#define USB3_GUCTL2_PERIODIC_UF_THR_MASK 0xFE000000U +#define USB3_GUCTL2_PERIODIC_UF_THR_POS 25U +#define USB3_GUCTL2_ASYNC_UF_THR_MASK 0x01FC0000U +#define USB3_GUCTL2_ASYNC_UF_THR_POS 18U +#define USB3_GUCTL2_PERIODIC_TXDMA_UF_THR_MASK 0x0003F800U +#define USB3_GUCTL2_PERIODIC_TXDMA_UF_THR_POS 11U +#define USB3_GUCTL2_SVC_OPP_PER_SSP_MASK 0x00000600U +#define USB3_GUCTL2_SVC_OPP_PER_SSP_POS 9U +#define USB3_GUCTL2_SVC_OPP_PER_SS_MASK 0x00000180U +#define USB3_GUCTL2_SVC_OPP_PER_SS_POS 7U +#define USB3_GUCTL2_SVC_OPP_PER_HS_MASK 0x00000060U +#define USB3_GUCTL2_SVC_OPP_PER_HS_POS 5U +#define USB3_GUCTL2_SVC_OPP_PER_FSLS_MASK 0x00000018U +#define USB3_GUCTL2_SVC_OPP_PER_FSLS_POS 3U +#define USB3_GUCTL2_MAX_REISU_CNT_MASK 0x00000006U +#define USB3_GUCTL2_MAX_REISU_CNT_POS 1U +#define USB3_GUCTL2_SCHEDDULE_LT_THR_MASK 0x00000001U +#define USB3_GUCTL2_SCHEDDULE_LT_THR_POS 0U + +/* Bit fields of GUCTL3 register */ +#define USB3_GUCTL3_CFGEP_CMD_SWITCHING_TIME_CTRL_MASK 0x01C00000U +#define USB3_GUCTL3_CFGEP_CMD_SWITCHING_TIME_CTRL_POS 22U +#define USB3_GUCTL3_BLOCK_CONCURRENT_IN_CTRL_XFERS_MASK 0x00200000U +#define USB3_GUCTL3_BLOCK_CONCURRENT_IN_CTRL_XFERS_POS 21U +#define USB3_GUCTL3_SSBI_SINGLE_EP_MODE_DISABLE_MASK 0x00100000U +#define USB3_GUCTL3_SSBI_SINGLE_EP_MODE_DISABLE_POS 20U +#define USB3_GUCTL3_DISEXTBUSCLKGT_U1U2L1_MASK 0x00080000U +#define USB3_GUCTL3_DISEXTBUSCLKGT_U1U2L1_POS 19U +#define USB3_GUCTL3_DISEXTBUSCLKGT_MASK 0x00040000U +#define USB3_GUCTL3_DISEXTBUSCLKGT_POS 18U +#define USB3_GUCTL3_USB20_RETRY_DISABLE_MASK 0x00010000U +#define USB3_GUCTL3_USB20_RETRY_DISABLE_POS 16U +#define USB3_GUCTL3_SVC_OPP_PER_HS_SEP_MASK 0x00001E00U +#define USB3_GUCTL3_SVC_OPP_PER_HS_SEP_POS 9U +#define USB3_GUCTL3_BARB_BURST_ENABLE_MASK 0x00000100U +#define USB3_GUCTL3_BARB_BURST_ENABLE_POS 8U +#define USB3_GUCTL3_INTR_EP_PING_ENABLE_MASK 0x00000080U +#define USB3_GUCTL3_INTR_EP_PING_ENABLE_POS 7U +#define USB3_GUCTL3_PERIODIC_UF_THR_FSLS_MASK 0x0000007FU +#define USB3_GUCTL3_PERIODIC_UF_THR_FSLS_POS 0U + +/* Bit fields of GTXFIFOPRIDEV register */ +#define USB3_GTXFIFOPRIDEV_GTXFIFOPRIDEV_MASK 0x0000FFFFU +#define USB3_GTXFIFOPRIDEV_GTXFIFOPRIDEV_POS 0U + +/* Bit fields of GTXFIFOPRIHST register */ +#define USB3_GTXFIFOPRIHST_GTXFIFOPRIHST_MASK 0x0000007FU +#define USB3_GTXFIFOPRIHST_GTXFIFOPRIHST_POS 0U + +/* Bit fields of GRXFIFOPRIHST register */ +#define USB3_GRXFIFOPRIHST_GRXFIFOPRIHST_MASK 0x0000003FU +#define USB3_GRXFIFOPRIHST_GRXFIFOPRIHST_POS 0U + +/* Bit fields of GFIFOPRIDBC register */ +#define USB3_GFIFOPRIDBC_GFIFOPRIDBC_MASK 0x00000003U +#define USB3_GFIFOPRIDBC_GFIFOPRIDBC_POS 0U + +/* Bit fields of GDMAHLRATIO register */ +#define USB3_GDMAHLRATIO_HSTRXFIFO_MAC_MASK 0x1F000000U +#define USB3_GDMAHLRATIO_HSTRXFIFO_MAC_POS 24U +#define USB3_GDMAHLRATIO_HSTTXFIFO_MAC_MASK 0x001F0000U +#define USB3_GDMAHLRATIO_HSTTXFIFO_MAC_POS 16U +#define USB3_GDMAHLRATIO_HSTRXFIFO_DMA_MASK 0x00001F00U +#define USB3_GDMAHLRATIO_HSTRXFIFO_DMA_POS 8U +#define USB3_GDMAHLRATIO_HSTTXFIFO_DMA_MASK 0x0000001FU +#define USB3_GDMAHLRATIO_HSTTXFIFO_DMA_POS 0U + +/* Bit fields of GOSTDDMA_ASYNC register */ +#define USB3_GOSTDDMA_ASYNC_OSTDRX_ASYNC_MASK 0xFF000000U +#define USB3_GOSTDDMA_ASYNC_OSTDRX_ASYNC_POS 24U +#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_ACTIVE_MASK 0x00FF0000U +#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_ACTIVE_POS 16U +#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_INACTIVE_MASK 0x0000FF00U +#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_INACTIVE_POS 8U +#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_MASK 0x000000FFU +#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_POS 0U + +/* Bit fields of GOSTDDMA_PRD register */ +#define USB3_GOSTDDMA_PRD_OSTDRX_PRD_MASK 0xFF000000U +#define USB3_GOSTDDMA_PRD_OSTDRX_PRD_POS 24U +#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_ACTIVE_MASK 0x00FF0000U +#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_ACTIVE_POS 16U +#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_INACTIVE_MASK 0x0000FF00U +#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_INACTIVE_POS 8U +#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_MASK 0x000000FFU +#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_POS 0U + +/* Bit fields of GFLADJ register */ +#define USB3_GFLADJ_GFLADJ_REFCLK_240MHZDECR_PLS1_MASK 0x80000000U +#define USB3_GFLADJ_GFLADJ_REFCLK_240MHZDECR_PLS1_POS 31U +#define USB3_GFLADJ_GFLADJ_REFCLK_240MHZ_DECR_MASK 0x7F000000U +#define USB3_GFLADJ_GFLADJ_REFCLK_240MHZ_DECR_POS 24U +#define USB3_GFLADJ_GFLADJ_REFCLK_LPM_SEL_MASK 0x00800000U +#define USB3_GFLADJ_GFLADJ_REFCLK_LPM_SEL_POS 23U +#define USB3_GFLADJ_GFLADJ_REFCLK_FLADJ_MASK 0x003FFF00U +#define USB3_GFLADJ_GFLADJ_REFCLK_FLADJ_POS 8U +#define USB3_GFLADJ_GFLADJ_30MHZ_SDBND_SEL_MASK 0x00000080U +#define USB3_GFLADJ_GFLADJ_30MHZ_SDBND_SEL_POS 7U +#define USB3_GFLADJ_GFLADJ_30MHZ_MASK 0x0000003FU +#define USB3_GFLADJ_GFLADJ_30MHZ_POS 0U + +/* Bit fields of GUCTL4 register */ +#define USB3_GUCTL4_SSP_BWD_OVHD_ADJ_MASK 0x7C000000U +#define USB3_GUCTL4_SSP_BWD_OVHD_ADJ_POS 26U +#define USB3_GUCTL4_LOA_EOP_CHECK_CLKS_WORD_MASK 0x00180000U +#define USB3_GUCTL4_LOA_EOP_CHECK_CLKS_WORD_POS 19U +#define USB3_GUCTL4_LOA_EOP_CHECK_CLKS_BYTE_MASK 0x00060000U +#define USB3_GUCTL4_LOA_EOP_CHECK_CLKS_BYTE_POS 17U +#define USB3_GUCTL4_CSR_TIMEOUT_VL_MASK 0x0001FFFFU +#define USB3_GUCTL4_CSR_TIMEOUT_VL_POS 0U + +/* Bit fields of GUCTL5 register */ + +/* Bit fields of GUSB2RHBCTL register */ +#define USB3_GUSB2RHBCTL_OVRD_FS_INT_PKT_DEL_MASK 0x000FF000U +#define USB3_GUSB2RHBCTL_OVRD_FS_INT_PKT_DEL_POS 12U +#define USB3_GUSB2RHBCTL_OVRD_HS_INT_PKT_DEL_MASK 0x00000FF0U +#define USB3_GUSB2RHBCTL_OVRD_HS_INT_PKT_DEL_POS 4U +#define USB3_GUSB2RHBCTL_OVRD_L1TIMEOUT_MASK 0x0000000FU +#define USB3_GUSB2RHBCTL_OVRD_L1TIMEOUT_POS 0U + +/* Bit fields of DCFG register */ +#define USB3_DCFG_IGNSTRMPP_MASK 0x00800000U +#define USB3_DCFG_IGNSTRMPP_POS 23U +#define USB3_DCFG_LPMCAP_MASK 0x00400000U +#define USB3_DCFG_LPMCAP_POS 22U +#define USB3_DCFG_NUMP_MASK 0x003E0000U +#define USB3_DCFG_NUMP_POS 17U +#define USB3_DCFG_INTRNUM_MASK 0x0001F000U +#define USB3_DCFG_INTRNUM_POS 12U +#define USB3_DCFG_DEVADDR_MASK 0x000003F8U +#define USB3_DCFG_DEVADDR_POS 3U +#define USB3_DCFG_DEVSPD_MASK 0x00000007U +#define USB3_DCFG_DEVSPD_POS 0U + +/* Bit fields of DCTL register */ +#define USB3_DCTL_RUN_STOP_MASK 0x80000000U +#define USB3_DCTL_RUN_STOP_POS 31U +#define USB3_DCTL_CSFTRST_MASK 0x40000000U +#define USB3_DCTL_CSFTRST_POS 30U +#define USB3_DCTL_HIRDTHRES_MASK 0x1F000000U +#define USB3_DCTL_HIRDTHRES_POS 24U +#define USB3_DCTL_LPM_NYET_THRES_MASK 0x00F00000U +#define USB3_DCTL_LPM_NYET_THRES_POS 20U +#define USB3_DCTL_KEEPCONNECT_MASK 0x00080000U +#define USB3_DCTL_KEEPCONNECT_POS 19U +#define USB3_DCTL_L1HIBERNATIONEN_MASK 0x00040000U +#define USB3_DCTL_L1HIBERNATIONEN_POS 18U +#define USB3_DCTL_CRS_MASK 0x00020000U +#define USB3_DCTL_CRS_POS 17U +#define USB3_DCTL_CSS_MASK 0x00010000U +#define USB3_DCTL_CSS_POS 16U +#define USB3_DCTL_INITU2ENA_MASK 0x00001000U +#define USB3_DCTL_INITU2ENA_POS 12U +#define USB3_DCTL_ACCEPTU2ENA_MASK 0x00000800U +#define USB3_DCTL_ACCEPTU2ENA_POS 11U +#define USB3_DCTL_INITU1ENA_MASK 0x00000400U +#define USB3_DCTL_INITU1ENA_POS 10U +#define USB3_DCTL_ACCEPTU1ENA_MASK 0x00000200U +#define USB3_DCTL_ACCEPTU1ENA_POS 9U +#define USB3_DCTL_ULSTCHNGREQ_MASK 0x000001E0U +#define USB3_DCTL_ULSTCHNGREQ_POS 5U +#define USB3_DCTL_TSTCTL_MASK 0x0000001EU +#define USB3_DCTL_TSTCTL_POS 1U + +/* Bit fields of DEVTEN register */ +#define USB3_DEVTEN_LDMEVTEN_MASK 0x00008000U +#define USB3_DEVTEN_LDMEVTEN_POS 15U +#define USB3_DEVTEN_L1WKUPEVTEN_MASK 0x00004000U +#define USB3_DEVTEN_L1WKUPEVTEN_POS 14U +#define USB3_DEVTEN_VENDEVTSTRCVDEN_MASK 0x00001000U +#define USB3_DEVTEN_VENDEVTSTRCVDEN_POS 12U +#define USB3_DEVTEN_ERRTICERREVTEN_MASK 0x00000200U +#define USB3_DEVTEN_ERRTICERREVTEN_POS 9U +#define USB3_DEVTEN_L1SUSPEN_MASK 0x00000100U +#define USB3_DEVTEN_L1SUSPEN_POS 8U +#define USB3_DEVTEN_SOFTEVTEN_MASK 0x00000080U +#define USB3_DEVTEN_SOFTEVTEN_POS 7U +#define USB3_DEVTEN_U3L2L1SUSPEN_MASK 0x00000040U +#define USB3_DEVTEN_U3L2L1SUSPEN_POS 6U +#define USB3_DEVTEN_HIBERNATIONREQEVTEN_MASK 0x00000020U +#define USB3_DEVTEN_HIBERNATIONREQEVTEN_POS 5U +#define USB3_DEVTEN_WKUPEVTEN_MASK 0x00000010U +#define USB3_DEVTEN_WKUPEVTEN_POS 4U +#define USB3_DEVTEN_ULSTCNGEN_MASK 0x00000008U +#define USB3_DEVTEN_ULSTCNGEN_POS 3U +#define USB3_DEVTEN_CONNECTDONEEVTEN_MASK 0x00000004U +#define USB3_DEVTEN_CONNECTDONEEVTEN_POS 2U +#define USB3_DEVTEN_USBRSTEVTEN_MASK 0x00000002U +#define USB3_DEVTEN_USBRSTEVTEN_POS 1U +#define USB3_DEVTEN_DISSCONNEVTEN_MASK 0x00000001U +#define USB3_DEVTEN_DISSCONNEVTEN_POS 0U + +/* Bit fields of DSTS register */ +#define USB3_DSTS_DCNRD_MASK 0x20000000U +#define USB3_DSTS_DCNRD_POS 29U +#define USB3_DSTS_SRE_MASK 0x10000000U +#define USB3_DSTS_SRE_POS 28U +#define USB3_DSTS_RSS_MASK 0x02000000U +#define USB3_DSTS_RSS_POS 25U +#define USB3_DSTS_SSS_MASK 0x01000000U +#define USB3_DSTS_SSS_POS 24U +#define USB3_DSTS_COREIDLE_MASK 0x00800000U +#define USB3_DSTS_COREIDLE_POS 23U +#define USB3_DSTS_DEVCTRLHLT_MASK 0x00400000U +#define USB3_DSTS_DEVCTRLHLT_POS 22U +#define USB3_DSTS_USBLNKST_MASK 0x003C0000U +#define USB3_DSTS_USBLNKST_POS 18U +#define USB3_DSTS_RXFIFOEMPTY_MASK 0x00020000U +#define USB3_DSTS_RXFIFOEMPTY_POS 17U +#define USB3_DSTS_SOFFN_MASK 0x0001FFF8U +#define USB3_DSTS_SOFFN_POS 3U +#define USB3_DSTS_CONNECTSPD_MASK 0x00000007U +#define USB3_DSTS_CONNECTSPD_POS 0U + +/* Bit fields of DGCMDPAR register */ +#define USB3_DGCMDPAR_PARAMETER_MASK 0xFFFFFFFFU +#define USB3_DGCMDPAR_PARAMETER_POS 0U + +/* Bit fields of DGCMD register */ +#define USB3_DGCMD_CMDSTATUS_MASK 0x0000F000U +#define USB3_DGCMD_CMDSTATUS_POS 12U +#define USB3_DGCMD_CMDACT_MASK 0x00000400U +#define USB3_DGCMD_CMDACT_POS 10U +#define USB3_DGCMD_CMDIOC_MASK 0x00000100U +#define USB3_DGCMD_CMDIOC_POS 8U +#define USB3_DGCMD_CMDTYP_MASK 0x000000FFU +#define USB3_DGCMD_CMDTYP_POS 0U + +/* Bit fields of DCTL1 register */ +#define USB3_DCTL1_EN_ENDXFER_ON_RJCT_STRM_MASK 0x00000004U +#define USB3_DCTL1_EN_ENDXFER_ON_RJCT_STRM_POS 2U +#define USB3_DCTL1_DIS_CLRSPR_SXFER_MASK 0x00000002U +#define USB3_DCTL1_DIS_CLRSPR_SXFER_POS 1U + +/* Bit fields of DALEPENA register */ +#define USB3_DALEPENA_USBACTEP_MASK 0xFFFFFFFFU +#define USB3_DALEPENA_USBACTEP_POS 0U + +/* Bit fields of DLDMENA register */ +#define USB3_DLDMENA_LDMADJ_MASK 0xFFFF0000U +#define USB3_DLDMENA_LDMADJ_POS 16U +#define USB3_DLDMENA_LDMDUR_MASK 0x0000FF00U +#define USB3_DLDMENA_LDMDUR_POS 8U +#define USB3_DLDMENA_NOLOWPWRDUR_MASK 0x000000F0U +#define USB3_DLDMENA_NOLOWPWRDUR_POS 4U +#define USB3_DLDMENA_LDMRQS_MASK 0x0000000EU +#define USB3_DLDMENA_LDMRQS_POS 1U +#define USB3_DLDMENA_LDMENA_MASK 0x00000001U +#define USB3_DLDMENA_LDMENA_POS 0U + +/* Bit fields of Rsvd register */ + +/* Bit fields of DEPCMDPAR2 register */ +#define USB3_DEPCMDPAR2_PARAMETER_MASK 0xFFFFFFFFU +#define USB3_DEPCMDPAR2_PARAMETER_POS 0U + +/* Bit fields of DEPCMDPAR1 register */ +#define USB3_DEPCMDPAR1_PARAMETER_MASK 0xFFFFFFFFU +#define USB3_DEPCMDPAR1_PARAMETER_POS 0U + +/* Bit fields of DEPCMDPAR0 register */ +#define USB3_DEPCMDPAR0_PARAMETER_MASK 0xFFFFFFFFU +#define USB3_DEPCMDPAR0_PARAMETER_POS 0U + +/* Bit fields of DEPCMD register */ +#define USB3_DEPCMD_COMMANDPARAM_MASK 0xFFFF0000U +#define USB3_DEPCMD_COMMANDPARAM_POS 16U +#define USB3_DEPCMD_CMDSTATUS_MASK 0x0000F000U +#define USB3_DEPCMD_CMDSTATUS_POS 12U +#define USB3_DEPCMD_HIPRI_FORCERM_MASK 0x00000800U +#define USB3_DEPCMD_HIPRI_FORCERM_POS 11U +#define USB3_DEPCMD_CMDACT_MASK 0x00000400U +#define USB3_DEPCMD_CMDACT_POS 10U +#define USB3_DEPCMD_CMDIOC_MASK 0x00000100U +#define USB3_DEPCMD_CMDIOC_POS 8U +#define USB3_DEPCMD_CMDTYP_MASK 0x0000000FU +#define USB3_DEPCMD_CMDTYP_POS 0U + +/* Bit fields of DEV_IMOD register */ +#define USB3_DEV_IMOD_DEVICE_IMODC_MASK 0xFFFF0000U +#define USB3_DEV_IMOD_DEVICE_IMODC_POS 16U +#define USB3_DEV_IMOD_DEVICE_IMODI_MASK 0x0000FFFFU +#define USB3_DEV_IMOD_DEVICE_IMODI_POS 0U + +/* Bit fields of rsvd0_reg register */ +#define USB3_RSVD0_REG_RSVD_FIELD_MASK 0xFFFFFFFFU +#define USB3_RSVD0_REG_RSVD_FIELD_POS 0U + +/* Bit fields of LU1LFPSRXTIM register */ +#define USB3_LU1LFPSRXTIM_GEN2_U1_LFPS_EXIT_RX_CLK_MASK 0xFF000000U +#define USB3_LU1LFPSRXTIM_GEN2_U1_LFPS_EXIT_RX_CLK_POS 24U +#define USB3_LU1LFPSRXTIM_GEN2_U1_EXIT_RSP_RX_CLK_MASK 0x00FF0000U +#define USB3_LU1LFPSRXTIM_GEN2_U1_EXIT_RSP_RX_CLK_POS 16U +#define USB3_LU1LFPSRXTIM_GEN1_U1_LFPS_EXIT_RX_CLK_MASK 0x0000FF00U +#define USB3_LU1LFPSRXTIM_GEN1_U1_LFPS_EXIT_RX_CLK_POS 8U +#define USB3_LU1LFPSRXTIM_GEN1_U1_EXIT_RSP_RX_CLK_MASK 0x000000FFU +#define USB3_LU1LFPSRXTIM_GEN1_U1_EXIT_RSP_RX_CLK_POS 0U + +/* Bit fields of LU1LFPSTXTIM register */ +#define USB3_LU1LFPSTXTIM_GEN2_U1_EXIT_RESP_TX_CLK_MASK 0x3FFF0000U +#define USB3_LU1LFPSTXTIM_GEN2_U1_EXIT_RESP_TX_CLK_POS 16U +#define USB3_LU1LFPSTXTIM_GEN1_U1_EXIT_RSP_TX_CLK_MASK 0x00003FFFU +#define USB3_LU1LFPSTXTIM_GEN1_U1_EXIT_RSP_TX_CLK_POS 0U + +/* Bit fields of LU2LFPSRXTIM register */ +#define USB3_LU2LFPSRXTIM_GEN2_U2_LFPS_EXIT_RX_CLK_MASK 0xFF000000U +#define USB3_LU2LFPSRXTIM_GEN2_U2_LFPS_EXIT_RX_CLK_POS 24U +#define USB3_LU2LFPSRXTIM_GEN2_U2_EXIT_RSP_RX_CLK_MASK 0x00FF0000U +#define USB3_LU2LFPSRXTIM_GEN2_U2_EXIT_RSP_RX_CLK_POS 16U +#define USB3_LU2LFPSRXTIM_GEN1_U2_LFPS_EXIT_RX_CLK_MASK 0x0000FF00U +#define USB3_LU2LFPSRXTIM_GEN1_U2_LFPS_EXIT_RX_CLK_POS 8U +#define USB3_LU2LFPSRXTIM_GEN1_U2_EXIT_RSP_RX_CLK_MASK 0x000000FFU +#define USB3_LU2LFPSRXTIM_GEN1_U2_EXIT_RSP_RX_CLK_POS 0U + +/* Bit fields of LU2LFPSTXTIM register */ +#define USB3_LU2LFPSTXTIM_U2_EXIT_RSP_TX_US_MASK 0x00003FFFU +#define USB3_LU2LFPSTXTIM_U2_EXIT_RSP_TX_US_POS 0U + +/* Bit fields of LU3LFPSRXTIM register */ +#define USB3_LU3LFPSRXTIM_GEN2_U3_LFPS_EXIT_RX_CLK_MASK 0xFF000000U +#define USB3_LU3LFPSRXTIM_GEN2_U3_LFPS_EXIT_RX_CLK_POS 24U +#define USB3_LU3LFPSRXTIM_GEN2_U3_EXIT_RSP_RX_CLK_MASK 0x00FF0000U +#define USB3_LU3LFPSRXTIM_GEN2_U3_EXIT_RSP_RX_CLK_POS 16U +#define USB3_LU3LFPSRXTIM_GEN1_U3_LFPS_EXIT_RX_CLK_MASK 0x0000FF00U +#define USB3_LU3LFPSRXTIM_GEN1_U3_LFPS_EXIT_RX_CLK_POS 8U +#define USB3_LU3LFPSRXTIM_GEN1_U3_EXIT_RSP_RX_CLK_MASK 0x000000FFU +#define USB3_LU3LFPSRXTIM_GEN1_U3_EXIT_RSP_RX_CLK_POS 0U + +/* Bit fields of LU3LFPSTXTIM register */ +#define USB3_LU3LFPSTXTIM_GEN2_U3_EXIT_TX_CLK_MASK 0x3FFF0000U +#define USB3_LU3LFPSTXTIM_GEN2_U3_EXIT_TX_CLK_POS 16U +#define USB3_LU3LFPSTXTIM_GEN1_U3_EXIT_RSP_TX_CLK_MASK 0x00003FFFU +#define USB3_LU3LFPSTXTIM_GEN1_U3_EXIT_RSP_TX_CLK_POS 0U + +/* Bit fields of LPINGLFPSTIM register */ +#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_BURST_CLK_MASK 0xFC000000U +#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_BURST_CLK_POS 26U +#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_MAX_CLK_MASK 0x03F00000U +#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_MAX_CLK_POS 20U +#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_MIN_CLK_MASK 0x000F0000U +#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_MIN_CLK_POS 16U +#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_BURST_CLK_MASK 0x0000FC00U +#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_BURST_CLK_POS 10U +#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_MAX_CLK_MASK 0x000003F0U +#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_MAX_CLK_POS 4U +#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_MIN_CLK_MASK 0x0000000FU +#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_MIN_CLK_POS 0U + +/* Bit fields of LPOLLLFPSTXTIM register */ +#define USB3_LPOLLLFPSTXTIM_LFPS_POLL_SPACE_CLK_MASK 0x003FF800U +#define USB3_LPOLLLFPSTXTIM_LFPS_POLL_SPACE_CLK_POS 11U +#define USB3_LPOLLLFPSTXTIM_LFPS_POLL_BURST_CLK_MASK 0x000007FFU +#define USB3_LPOLLLFPSTXTIM_LFPS_POLL_BURST_CLK_POS 0U + +/* Bit fields of LSKIPFREQ register */ +#define USB3_LSKIPFREQ_U1_RESID_TIMER_US_MASK 0x70000000U +#define USB3_LSKIPFREQ_U1_RESID_TIMER_US_POS 28U +#define USB3_LSKIPFREQ_EN_PM_TIMER_US_MASK 0x08000000U +#define USB3_LSKIPFREQ_EN_PM_TIMER_US_POS 27U +#define USB3_LSKIPFREQ_PM_LC_TIMER_US_MASK 0x07000000U +#define USB3_LSKIPFREQ_PM_LC_TIMER_US_POS 24U +#define USB3_LSKIPFREQ_PM_ENTRY_TIMER_US_MASK 0x00F00000U +#define USB3_LSKIPFREQ_PM_ENTRY_TIMER_US_POS 20U +#define USB3_LSKIPFREQ_GEN2_SKP_FREQ_MASK 0x000FF000U +#define USB3_LSKIPFREQ_GEN2_SKP_FREQ_POS 12U +#define USB3_LSKIPFREQ_GEN1_SKP_FREQ_MASK 0x00000FFFU +#define USB3_LSKIPFREQ_GEN1_SKP_FREQ_POS 0U + +/* Bit fields of LLUCTL register */ +#define USB3_LLUCTL_INVERSE_SYNC_HEADER_MASK 0x40000000U +#define USB3_LLUCTL_INVERSE_SYNC_HEADER_POS 30U +#define USB3_LLUCTL_SUPPORT_P4_PG_MASK 0x20000000U +#define USB3_LLUCTL_SUPPORT_P4_PG_POS 29U +#define USB3_LLUCTL_SUPPORT_P4_MASK 0x10000000U +#define USB3_LLUCTL_SUPPORT_P4_POS 28U +#define USB3_LLUCTL_DELAY_TX_GEN1_DP_MASK 0x0F000000U +#define USB3_LLUCTL_DELAY_TX_GEN1_DP_POS 24U +#define USB3_LLUCTL_DISRXDET_LTSSM_TIMER_OVRRD_MASK 0x00800000U +#define USB3_LLUCTL_DISRXDET_LTSSM_TIMER_OVRRD_POS 23U +#define USB3_LLUCTL_FORCE_DPP_TRUNCATE_MASK 0x00400000U +#define USB3_LLUCTL_FORCE_DPP_TRUNCATE_POS 22U +#define USB3_LLUCTL_EN_DPP_TRUNCATE_MASK 0x00200000U +#define USB3_LLUCTL_EN_DPP_TRUNCATE_POS 21U +#define USB3_LLUCTL_PENDING_HP_TIMER_US_MASK 0x001F0000U +#define USB3_LLUCTL_PENDING_HP_TIMER_US_POS 16U +#define USB3_LLUCTL_EN_US_HP_TIMER_MASK 0x00008000U +#define USB3_LLUCTL_EN_US_HP_TIMER_POS 15U +#define USB3_LLUCTL_RING_BUF_D_DELAY_MASK 0x00006000U +#define USB3_LLUCTL_RING_BUF_D_DELAY_POS 13U +#define USB3_LLUCTL_U2P3CPMOK_MASK 0x00001000U +#define USB3_LLUCTL_U2P3CPMOK_POS 12U +#define USB3_LLUCTL_EN_RESET_PIPE_AFTER_PHY_MUX_MASK 0x00000800U +#define USB3_LLUCTL_EN_RESET_PIPE_AFTER_PHY_MUX_POS 11U +#define USB3_LLUCTL_FORCE_GEN1_MASK 0x00000400U +#define USB3_LLUCTL_FORCE_GEN1_POS 10U +#define USB3_LLUCTL_GEN2_LOOPBACK_ENTRY_MODE_MASK 0x00000200U +#define USB3_LLUCTL_GEN2_LOOPBACK_ENTRY_MODE_POS 9U +#define USB3_LLUCTL_GEN1_LOOPBACK_ENTRY_MODE_MASK 0x00000100U +#define USB3_LLUCTL_GEN1_LOOPBACK_ENTRY_MODE_POS 8U +#define USB3_LLUCTL_MASK_PIPE_RESET_MASK 0x00000080U +#define USB3_LLUCTL_MASK_PIPE_RESET_POS 7U +#define USB3_LLUCTL_DELAY_UX_AFTER_LPMA_MASK 0x00000040U +#define USB3_LLUCTL_DELAY_UX_AFTER_LPMA_POS 6U +#define USB3_LLUCTL_NO_UX_EXIT_P0_TRANS_MASK 0x00000020U +#define USB3_LLUCTL_NO_UX_EXIT_P0_TRANS_POS 5U +#define USB3_LLUCTL_TX_TS1_CNT_MASK 0x0000001FU +#define USB3_LLUCTL_TX_TS1_CNT_POS 0U + +/* Bit fields of LPTMDPDELAY register */ +#define USB3_LPTMDPDELAY_RX_PATH_DELAY_GEN2_MASK 0xF8000000U +#define USB3_LPTMDPDELAY_RX_PATH_DELAY_GEN2_POS 27U +#define USB3_LPTMDPDELAY_TX_PATH_DELAY_GEN2_MASK 0x07C00000U +#define USB3_LPTMDPDELAY_TX_PATH_DELAY_GEN2_POS 22U +#define USB3_LPTMDPDELAY_P3CPMP4_RESIDENCY_MASK 0x003FFC00U +#define USB3_LPTMDPDELAY_P3CPMP4_RESIDENCY_POS 10U +#define USB3_LPTMDPDELAY_RX_PATH_DELAY_MASK 0x000003E0U +#define USB3_LPTMDPDELAY_RX_PATH_DELAY_POS 5U +#define USB3_LPTMDPDELAY_TX_PATH_DELAY_MASK 0x0000001FU +#define USB3_LPTMDPDELAY_TX_PATH_DELAY_POS 0U + +/* Bit fields of LSCDTIM1 register */ +#define USB3_LSCDTIM1_SCD_BIT0_RPT_MAX_CLK_MASK 0x00FFF000U +#define USB3_LSCDTIM1_SCD_BIT0_RPT_MAX_CLK_POS 12U +#define USB3_LSCDTIM1_CD_BIT0_RPT_MIN_CLK_MASK 0x00000FFFU +#define USB3_LSCDTIM1_CD_BIT0_RPT_MIN_CLK_POS 0U + +/* Bit fields of LSCDTIM2 register */ +#define USB3_LSCDTIM2_SCD_BIT1_RPT_MAX_CLK_MASK 0x00FFF000U +#define USB3_LSCDTIM2_SCD_BIT1_RPT_MAX_CLK_POS 12U +#define USB3_LSCDTIM2_CD_BIT1_RPT_MIN_CLK_MASK 0x00000FFFU +#define USB3_LSCDTIM2_CD_BIT1_RPT_MIN_CLK_POS 0U + +/* Bit fields of LSCDTIM3 register */ +#define USB3_LSCDTIM3_LFPS_SCD_SPACE1_CLK_MASK 0xFFF00000U +#define USB3_LSCDTIM3_LFPS_SCD_SPACE1_CLK_POS 20U +#define USB3_LSCDTIM3_LFPS_SCD_SPACE0_CLK_MASK 0x000FFF00U +#define USB3_LSCDTIM3_LFPS_SCD_SPACE0_CLK_POS 8U +#define USB3_LSCDTIM3_LFPS_SCD_BURST_CLK_MASK 0x000000FFU +#define USB3_LSCDTIM3_LFPS_SCD_BURST_CLK_POS 0U + +/* Bit fields of LSCDTIM4 register */ +#define USB3_LSCDTIM4_LFPS_SCD_LAST_SPACE_MASK 0x00000FFFU +#define USB3_LSCDTIM4_LFPS_SCD_LAST_SPACE_POS 0U + +/* Bit fields of LLPBMTIM1 register */ +#define USB3_LLPBMTIM1_LFPS_LBPS1_BURST_MAX_CLK_MASK 0xFF000000U +#define USB3_LLPBMTIM1_LFPS_LBPS1_BURST_MAX_CLK_POS 24U +#define USB3_LLPBMTIM1_LFPS_LBPS1_BURST_MIN_CLK_MASK 0x00FF0000U +#define USB3_LLPBMTIM1_LFPS_LBPS1_BURST_MIN_CLK_POS 16U +#define USB3_LLPBMTIM1_LFPS_LBPS0_BURST_MAX_CLK_MASK 0x0000FF00U +#define USB3_LLPBMTIM1_LFPS_LBPS0_BURST_MAX_CLK_POS 8U +#define USB3_LLPBMTIM1_LFPS_LBPS0_BURST_MIN_CLK_MASK 0x000000FFU +#define USB3_LLPBMTIM1_LFPS_LBPS0_BURST_MIN_CLK_POS 0U + +/* Bit fields of LLPBMTIM2 register */ +#define USB3_LLPBMTIM2_LFPS_LBPM_TPWM_MAX_CLK_MASK 0x0003FE00U +#define USB3_LLPBMTIM2_LFPS_LBPM_TPWM_MAX_CLK_POS 9U +#define USB3_LLPBMTIM2_LFPS_LBPM_TPWM_MIN_CLK_MASK 0x000001FFU +#define USB3_LLPBMTIM2_LFPS_LBPM_TPWM_MIN_CLK_POS 0U + +/* Bit fields of LLPBMTXTIM register */ +#define USB3_LLPBMTXTIM_LFPS_LPBS_TPWM_CLK_MASK 0x3FF00000U +#define USB3_LLPBMTXTIM_LFPS_LPBS_TPWM_CLK_POS 20U +#define USB3_LLPBMTXTIM_LFPS_LBPS_BURST1_CLK_MASK 0x0003FF00U +#define USB3_LLPBMTXTIM_LFPS_LBPS_BURST1_CLK_POS 8U +#define USB3_LLPBMTXTIM_LFPS_LBPS_BURST0_CLK_MASK 0x000000FFU +#define USB3_LLPBMTXTIM_LFPS_LBPS_BURST0_CLK_POS 0U + +/* Bit fields of LLINKERRINJ register */ +#define USB3_LLINKERRINJ_PIPE_TXDATA_MASK 0x80000000U +#define USB3_LLINKERRINJ_PIPE_TXDATA_POS 31U +#define USB3_LLINKERRINJ_TX_INSERT_DEFER_MASK 0x40000000U +#define USB3_LLINKERRINJ_TX_INSERT_DEFER_POS 30U +#define USB3_LLINKERRINJ_TX_INSERT_DELAY_MASK 0x20000000U +#define USB3_LLINKERRINJ_TX_INSERT_DELAY_POS 29U +#define USB3_LLINKERRINJ_TX_TS2_MASK 0x10000000U +#define USB3_LLINKERRINJ_TX_TS2_POS 28U +#define USB3_LLINKERRINJ_TX_TS1_MASK 0x08000000U +#define USB3_LLINKERRINJ_TX_TS1_POS 27U +#define USB3_LLINKERRINJ_TX_TSEQ_MASK 0x04000000U +#define USB3_LLINKERRINJ_TX_TSEQ_POS 26U +#define USB3_LLINKERRINJ_TX_LFR_MASK 0x02000000U +#define USB3_LLINKERRINJ_TX_LFR_POS 25U +#define USB3_LLINKERRINJ_TX_DELAY_CREDIT_RL_MASK 0x01000000U +#define USB3_LLINKERRINJ_TX_DELAY_CREDIT_RL_POS 24U +#define USB3_LLINKERRINJ_TX_ONE_SRT_FRAME_SYBL_MASK 0x00800000U +#define USB3_LLINKERRINJ_TX_ONE_SRT_FRAME_SYBL_POS 23U +#define USB3_LLINKERRINJ_TX_ALL_END_FRAME_SYBL_MASK 0x00400000U +#define USB3_LLINKERRINJ_TX_ALL_END_FRAME_SYBL_POS 22U +#define USB3_LLINKERRINJ_TX_ONE_END_FRAME_SYBL_MASK 0x00200000U +#define USB3_LLINKERRINJ_TX_ONE_END_FRAME_SYBL_POS 21U +#define USB3_LLINKERRINJ_TX_ALL_FRAME_SYBL_MASK 0x00100000U +#define USB3_LLINKERRINJ_TX_ALL_FRAME_SYBL_POS 20U +#define USB3_LLINKERRINJ_TX_ONE_FRAME_SYBL_MASK 0x00080000U +#define USB3_LLINKERRINJ_TX_ONE_FRAME_SYBL_POS 19U +#define USB3_LLINKERRINJ_TX_CRC32_MASK 0x00040000U +#define USB3_LLINKERRINJ_TX_CRC32_POS 18U +#define USB3_LLINKERRINJ_TX_CRC16_MASK 0x00020000U +#define USB3_LLINKERRINJ_TX_CRC16_POS 17U +#define USB3_LLINKERRINJ_TX_CRC5_MASK 0x00010000U +#define USB3_LLINKERRINJ_TX_CRC5_POS 16U +#define USB3_LLINKERRINJ_RX_PIPE_RXDATA_MASK 0x00008000U +#define USB3_LLINKERRINJ_RX_PIPE_RXDATA_POS 15U +#define USB3_LLINKERRINJ_RX_INSERT_DEFER_MASK 0x00004000U +#define USB3_LLINKERRINJ_RX_INSERT_DEFER_POS 14U +#define USB3_LLINKERRINJ_RX_INSERT_DELAY_MASK 0x00002000U +#define USB3_LLINKERRINJ_RX_INSERT_DELAY_POS 13U +#define USB3_LLINKERRINJ_RX_TS2_MASK 0x00001000U +#define USB3_LLINKERRINJ_RX_TS2_POS 12U +#define USB3_LLINKERRINJ_RX_TS1_MASK 0x00000800U +#define USB3_LLINKERRINJ_RX_TS1_POS 11U +#define USB3_LLINKERRINJ_RX_TSEQ_MASK 0x00000400U +#define USB3_LLINKERRINJ_RX_TSEQ_POS 10U +#define USB3_LLINKERRINJ_RX_LFR_MASK 0x00000200U +#define USB3_LLINKERRINJ_RX_LFR_POS 9U +#define USB3_LLINKERRINJ_RX_ALL_START_FRAME_SYBL_MASK 0x00000100U +#define USB3_LLINKERRINJ_RX_ALL_START_FRAME_SYBL_POS 8U +#define USB3_LLINKERRINJ_RX_ONE_SRT_FRAME_SYBL_MASK 0x00000080U +#define USB3_LLINKERRINJ_RX_ONE_SRT_FRAME_SYBL_POS 7U +#define USB3_LLINKERRINJ_RX_ALL_END_FRAME_SYBL_MASK 0x00000040U +#define USB3_LLINKERRINJ_RX_ALL_END_FRAME_SYBL_POS 6U +#define USB3_LLINKERRINJ_RX_ONE_END_FRAME_SYBL_MASK 0x00000020U +#define USB3_LLINKERRINJ_RX_ONE_END_FRAME_SYBL_POS 5U +#define USB3_LLINKERRINJ_RX_ALL_FRAME_SYBL_MASK 0x00000010U +#define USB3_LLINKERRINJ_RX_ALL_FRAME_SYBL_POS 4U +#define USB3_LLINKERRINJ_RX_ONE_FRAME_SYBL_MASK 0x00000008U +#define USB3_LLINKERRINJ_RX_ONE_FRAME_SYBL_POS 3U +#define USB3_LLINKERRINJ_RX_CRC32_MASK 0x00000004U +#define USB3_LLINKERRINJ_RX_CRC32_POS 2U +#define USB3_LLINKERRINJ_RX_CRC16_MASK 0x00000002U +#define USB3_LLINKERRINJ_RX_CRC16_POS 1U +#define USB3_LLINKERRINJ_RX_CRC5_MASK 0x00000001U +#define USB3_LLINKERRINJ_RX_CRC5_POS 0U + +/* Bit fields of LLINKERRINJEN register */ +#define USB3_LLINKERRINJEN_DISABLE_INJ_ERR_CNT_MASK 0xFFFF0000U +#define USB3_LLINKERRINJEN_DISABLE_INJ_ERR_CNT_POS 16U +#define USB3_LLINKERRINJEN_B2B_ERR_CNT_MASK 0x0000FFFFU +#define USB3_LLINKERRINJEN_B2B_ERR_CNT_POS 0U + +/* Bit fields of GDBGLTSSM register */ +#define USB3_GDBGLTSSM_RXELECIDLE_MASK 0x40000000U +#define USB3_GDBGLTSSM_RXELECIDLE_POS 30U +#define USB3_GDBGLTSSM_LTDBTIMEOUT_MASK 0x04000000U +#define USB3_GDBGLTSSM_LTDBTIMEOUT_POS 26U +#define USB3_GDBGLTSSM_LTDBLINKSTATE_MASK 0x03C00000U +#define USB3_GDBGLTSSM_LTDBLINKSTATE_POS 22U +#define USB3_GDBGLTSSM_LTDBSUBSTATE_MASK 0x003C0000U +#define USB3_GDBGLTSSM_LTDBSUBSTATE_POS 18U +#define USB3_GDBGLTSSM_ELASTICBUFFERMODE_MASK 0x00020000U +#define USB3_GDBGLTSSM_ELASTICBUFFERMODE_POS 17U +#define USB3_GDBGLTSSM_TXELECLDLE_MASK 0x00010000U +#define USB3_GDBGLTSSM_TXELECLDLE_POS 16U +#define USB3_GDBGLTSSM_RXPOLARITY_MASK 0x00008000U +#define USB3_GDBGLTSSM_RXPOLARITY_POS 15U +#define USB3_GDBGLTSSM_TXDETRXLOOPBACK_MASK 0x00004000U +#define USB3_GDBGLTSSM_TXDETRXLOOPBACK_POS 14U +#define USB3_GDBGLTSSM_LTDBPHYCMDSTATE_MASK 0x00003800U +#define USB3_GDBGLTSSM_LTDBPHYCMDSTATE_POS 11U +#define USB3_GDBGLTSSM_POWERDOWN_MASK 0x00000600U +#define USB3_GDBGLTSSM_POWERDOWN_POS 9U +#define USB3_GDBGLTSSM_RXEQTRAIN_MASK 0x00000100U +#define USB3_GDBGLTSSM_RXEQTRAIN_POS 8U +#define USB3_GDBGLTSSM_TXDEEMPHASIS_MASK 0x000000C0U +#define USB3_GDBGLTSSM_TXDEEMPHASIS_POS 6U +#define USB3_GDBGLTSSM_LTDBCLKSTATE_MASK 0x00000038U +#define USB3_GDBGLTSSM_LTDBCLKSTATE_POS 3U +#define USB3_GDBGLTSSM_TXSWING_MASK 0x00000004U +#define USB3_GDBGLTSSM_TXSWING_POS 2U +#define USB3_GDBGLTSSM_RXTERMINATION_MASK 0x00000002U +#define USB3_GDBGLTSSM_RXTERMINATION_POS 1U +#define USB3_GDBGLTSSM_TXONESZEROS_MASK 0x00000001U +#define USB3_GDBGLTSSM_TXONESZEROS_POS 0U + +/* Bit fields of GDBGLNMCC register */ +#define USB3_GDBGLNMCC_LNMCC_LSERC_MASK 0xFFFF0000U +#define USB3_GDBGLNMCC_LNMCC_LSERC_POS 16U +#define USB3_GDBGLNMCC_LNMCC_BERC_MASK 0x000001FFU +#define USB3_GDBGLNMCC_LNMCC_BERC_POS 0U + +/* Bit fields of LLINKDBGCTRL register */ +#define USB3_LLINKDBGCTRL_RETRY_DP_MASK 0x80000000U +#define USB3_LLINKDBGCTRL_RETRY_DP_POS 31U +#define USB3_LLINKDBGCTRL_TRIGGER_END_STS_MASK 0x40000000U +#define USB3_LLINKDBGCTRL_TRIGGER_END_STS_POS 30U +#define USB3_LLINKDBGCTRL_TRIGGER_START_STS_MASK 0x20000000U +#define USB3_LLINKDBGCTRL_TRIGGER_START_STS_POS 29U +#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_DESCRAMBLED_MASK 0x10000000U +#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_DESCRAMBLED_POS 28U +#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_SCRAMBLED_MASK 0x08000000U +#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_SCRAMBLED_POS 27U +#define USB3_LLINKDBGCTRL_PIPE_TXDETECTRXLB_TRIGGER_MASK 0x04000000U +#define USB3_LLINKDBGCTRL_PIPE_TXDETECTRXLB_TRIGGER_POS 26U +#define USB3_LLINKDBGCTRL_PIPE_RXLECIDLE_TRIGGER_MASK 0x02000000U +#define USB3_LLINKDBGCTRL_PIPE_RXLECIDLE_TRIGGER_POS 25U +#define USB3_LLINKDBGCTRL_PIPE_PHYSTATUS_TRIGGER_MASK 0x01000000U +#define USB3_LLINKDBGCTRL_PIPE_PHYSTATUS_TRIGGER_POS 24U +#define USB3_LLINKDBGCTRL_SUB_STATE_TRIGGER_MASK 0x00F00000U +#define USB3_LLINKDBGCTRL_SUB_STATE_TRIGGER_POS 20U +#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_MASK 0x000F0000U +#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_POS 16U +#define USB3_LLINKDBGCTRL_PERI_RSC_RXFIFO_NUMBER_MASK 0x0000F000U +#define USB3_LLINKDBGCTRL_PERI_RSC_RXFIFO_NUMBER_POS 12U +#define USB3_LLINKDBGCTRL_PERI_RSC_TXFIFO_NUMBER_MASK 0x00000F00U +#define USB3_LLINKDBGCTRL_PERI_RSC_TXFIFO_NUMBER_POS 8U +#define USB3_LLINKDBGCTRL_RXFIFO_NUMBER_MASK 0x000000F0U +#define USB3_LLINKDBGCTRL_RXFIFO_NUMBER_POS 4U +#define USB3_LLINKDBGCTRL_TXFIFO_NUMBER_MASK 0x0000000FU +#define USB3_LLINKDBGCTRL_TXFIFO_NUMBER_POS 0U + +/* Bit fields of LLINKDBGCNTTRIG register */ +#define USB3_LLINKDBGCNTTRIG_STP_CNT_MASK 0xFFFF0000U +#define USB3_LLINKDBGCNTTRIG_STP_CNT_POS 16U +#define USB3_LLINKDBGCNTTRIG_SRT_CNT_MASK 0x0000FFFFU +#define USB3_LLINKDBGCNTTRIG_SRT_CNT_POS 0U + +/* Bit fields of LCSR_TX_DEEMPH register */ +#define USB3_LCSR_TX_DEEMPH_CSR_TX_DEEMPH_FIELD_1_MASK 0x0003FFFFU +#define USB3_LCSR_TX_DEEMPH_CSR_TX_DEEMPH_FIELD_1_POS 0U + +/* Bit fields of LCSR_TX_DEEMPH_1 register */ +#define USB3_LCSR_TX_DEEMPH_1_CSR_TX_DEEMPH_1_FIELD_1_MASK 0x0003FFFFU +#define USB3_LCSR_TX_DEEMPH_1_CSR_TX_DEEMPH_1_FIELD_1_POS 0U + +/* Bit fields of LCSR_TX_DEEMPH_2 register */ +#define USB3_LCSR_TX_DEEMPH_2_CSR_TX_DEEMPH_2_FIELD_1_MASK 0x0003FFFFU +#define USB3_LCSR_TX_DEEMPH_2_CSR_TX_DEEMPH_2_FIELD_1_POS 0U + +/* Bit fields of LCSR_TX_DEEMPH_3 register */ +#define USB3_LCSR_TX_DEEMPH_3_CSR_TX_DEEMPH_3_FIELD_1_MASK 0x0003FFFFU +#define USB3_LCSR_TX_DEEMPH_3_CSR_TX_DEEMPH_3_FIELD_1_POS 0U + +/* Bit fields of LCSRPTMDEBUG1 register */ +#define USB3_LCSRPTMDEBUG1_LDM_T32_MASK 0x3FFE0000U +#define USB3_LCSRPTMDEBUG1_LDM_T32_POS 17U +#define USB3_LCSRPTMDEBUG1_LDM_T1_MASK 0x0001FFFFU +#define USB3_LCSRPTMDEBUG1_LDM_T1_POS 0U + +/* Bit fields of LCSRPTMDEBUG2 register */ +#define USB3_LCSRPTMDEBUG2_LDM_T4_MASK 0x0001FFFFU +#define USB3_LCSRPTMDEBUG2_LDM_T4_POS 0U + +/* Bit fields of LPTMDPDELAY2 register */ +#define USB3_LPTMDPDELAY2_LINK_RX_DELAY_GEN2_MASK 0x000F8000U +#define USB3_LPTMDPDELAY2_LINK_RX_DELAY_GEN2_POS 15U +#define USB3_LPTMDPDELAY2_LINK_TX_DELAY_GEN2_MASK 0x00007C00U +#define USB3_LPTMDPDELAY2_LINK_TX_DELAY_GEN2_POS 10U +#define USB3_LPTMDPDELAY2_LINK_RX_DELAY_GEN1_MASK 0x000003E0U +#define USB3_LPTMDPDELAY2_LINK_RX_DELAY_GEN1_POS 5U +#define USB3_LPTMDPDELAY2_LINK_TX_DELAY_GEN1_MASK 0x0000001FU +#define USB3_LPTMDPDELAY2_LINK_TX_DELAY_GEN1_POS 0U + +/* Bit fields of BU31RHBDBG register */ +#define USB3_BU31RHBDBG_TPCFG_TOUT_CTRL_MASK 0x00000008U +#define USB3_BU31RHBDBG_TPCFG_TOUT_CTRL_POS 3U +#define USB3_BU31RHBDBG_PCAP_MASK 0x00000006U +#define USB3_BU31RHBDBG_PCAP_POS 1U +#define USB3_BU31RHBDBG_OVRCUR_MASK 0x00000001U +#define USB3_BU31RHBDBG_OVRCUR_POS 0U + +/* Bit fields of BRAMHIADDR register */ +#define USB3_BRAMHIADDR_RAM_SELECT_MASK 0x001C0000U +#define USB3_BRAMHIADDR_RAM_SELECT_POS 18U +#define USB3_BRAMHIADDR_RAMHIADDR_MASK 0x0003F000U +#define USB3_BRAMHIADDR_RAMHIADDR_POS 12U + +/* Bit fields of BRSERRCNT register */ +#define USB3_BRSERRCNT_RAM4SERRCNT_MASK 0x3F000000U +#define USB3_BRSERRCNT_RAM4SERRCNT_POS 24U +#define USB3_BRSERRCNT_RAM3SERRCNT_MASK 0x00FC0000U +#define USB3_BRSERRCNT_RAM3SERRCNT_POS 18U +#define USB3_BRSERRCNT_RAM2SERRCNT_MASK 0x0003F000U +#define USB3_BRSERRCNT_RAM2SERRCNT_POS 12U +#define USB3_BRSERRCNT_RAM1SERRCNT_MASK 0x00000FC0U +#define USB3_BRSERRCNT_RAM1SERRCNT_POS 6U +#define USB3_BRSERRCNT_RAM0SERRCNT_MASK 0x0000003FU +#define USB3_BRSERRCNT_RAM0SERRCNT_POS 0U + +/* Bit fields of BRMERRCNT register */ +#define USB3_BRMERRCNT_RAM4MERRCNT_MASK 0x3F000000U +#define USB3_BRMERRCNT_RAM4MERRCNT_POS 24U +#define USB3_BRMERRCNT_RAM3MERRCNT_MASK 0x00FC0000U +#define USB3_BRMERRCNT_RAM3MERRCNT_POS 18U +#define USB3_BRMERRCNT_RAM2MERRCNT_MASK 0x0003F000U +#define USB3_BRMERRCNT_RAM2MERRCNT_POS 12U +#define USB3_BRMERRCNT_RAM1MERRCNT_MASK 0x00000FC0U +#define USB3_BRMERRCNT_RAM1MERRCNT_POS 6U +#define USB3_BRMERRCNT_RAM0MERRCNT_MASK 0x0000003FU +#define USB3_BRMERRCNT_RAM0MERRCNT_POS 0U + +/* Bit fields of BRAMECCERR register */ +#define USB3_BRAMECCERR_RAMSERR_MASK 0x00000800U +#define USB3_BRAMECCERR_RAMSERR_POS 11U +#define USB3_BRAMECCERR_RAMMERR_MASK 0x00000400U +#define USB3_BRAMECCERR_RAMMERR_POS 10U +#define USB3_BRAMECCERR_RAMSERRVEC_MASK 0x000003E0U +#define USB3_BRAMECCERR_RAMSERRVEC_POS 5U +#define USB3_BRAMECCERR_RAMMERRVEC_MASK 0x0000001FU +#define USB3_BRAMECCERR_RAMMERRVEC_POS 0U + +/* Bit fields of BRERRCTL register */ +#define USB3_BRERRCTL_RSERRCLR_MASK 0x00000002U +#define USB3_BRERRCTL_RSERRCLR_POS 1U +#define USB3_BRERRCTL_RMERRCLR_MASK 0x00000001U +#define USB3_BRERRCTL_RMERRCLR_POS 0U + +/* Bit fields of BRAM0ADDRERR register */ +#define USB3_BRAM0ADDRERR_RAM0ERRLOC_MASK 0x0000FFFFU +#define USB3_BRAM0ADDRERR_RAM0ERRLOC_POS 0U + +/* Bit fields of BRAM1ADDRERR register */ +#define USB3_BRAM1ADDRERR_RAM1ERRLOC_MASK 0x0000FFFFU +#define USB3_BRAM1ADDRERR_RAM1ERRLOC_POS 0U + +/* Bit fields of BRAM2ADDRERR register */ +#define USB3_BRAM2ADDRERR_RAM2ERRLOC_MASK 0x0000FFFFU +#define USB3_BRAM2ADDRERR_RAM2ERRLOC_POS 0U + +/* Bit fields of BRAM3ADDRERR register */ +#define USB3_BRAM3ADDRERR_RAM3ERRLOC_MASK 0x0000FFFFU +#define USB3_BRAM3ADDRERR_RAM3ERRLOC_POS 0U + +/* Bit fields of BRAM4ADDRERR register */ +#define USB3_BRAM4ADDRERR_RAM4ERRLOC_MASK 0x0000FFFFU +#define USB3_BRAM4ADDRERR_RAM4ERRLOC_POS 0U + +/* Bit fields of BLOOPBCKCTRL register */ +#define USB3_BLOOPBCKCTRL_LOOPBACK_PRTNUM_MASK 0x000000F0U +#define USB3_BLOOPBCKCTRL_LOOPBACK_PRTNUM_POS 4U +#define USB3_BLOOPBCKCTRL_LOOPBACK_LEVEL_MASK 0x0000000CU +#define USB3_BLOOPBCKCTRL_LOOPBACK_LEVEL_POS 2U +#define USB3_BLOOPBCKCTRL_LOOPBACK_MODE_MASK 0x00000002U +#define USB3_BLOOPBCKCTRL_LOOPBACK_MODE_POS 1U +#define USB3_BLOOPBCKCTRL_LOOPBACK_MODE_EN_MASK 0x00000001U +#define USB3_BLOOPBCKCTRL_LOOPBACK_MODE_EN_POS 0U + +/* Bit fields of BLOOPBCKTFERSZ register */ +#define USB3_BLOOPBCKTFERSZ_LOOPBACK_XFER_SZ_MASK 0x00FFFFFFU +#define USB3_BLOOPBCKTFERSZ_LOOPBACK_XFER_SZ_POS 0U + +/* Bit fields of BBISTDATAPATSEED register */ +#define USB3_BBISTDATAPATSEED_BIST_PATTERN_SEED_MASK 0xFFFFFFFFU +#define USB3_BBISTDATAPATSEED_BIST_PATTERN_SEED_POS 0U + +/* Bit fields of BBISTCTRL register */ +#define USB3_BBISTCTRL_START_BIST_TEST_MASK 0x80000000U +#define USB3_BBISTCTRL_START_BIST_TEST_POS 31U +#define USB3_BBISTCTRL_BIST_TEST_TYPE_MASK 0x40000000U +#define USB3_BBISTCTRL_BIST_TEST_TYPE_POS 30U +#define USB3_BBISTCTRL_FAIL_MASK 0x20000000U +#define USB3_BBISTCTRL_FAIL_POS 29U +#define USB3_BBISTCTRL_BIST_PATTERN_MASK 0x07000000U +#define USB3_BBISTCTRL_BIST_PATTERN_POS 24U +#define USB3_BBISTCTRL_BIST_ITERATION_CNT_MASK 0x00FFFFFFU +#define USB3_BBISTCTRL_BIST_ITERATION_CNT_POS 0U + +/* Bit fields of BBISTXFERSTS0 register */ +#define USB3_BBISTXFERSTS0_BIST_PENDING_TRANS_SIZE_MASK 0x00FFFFFFU +#define USB3_BBISTXFERSTS0_BIST_PENDING_TRANS_SIZE_POS 0U + +/* Bit fields of BBISTXFERSTS1 register */ +#define USB3_BBISTXFERSTS1_FAILED_PENDING_TRANS_SIZE_MASK 0x00FFFFFFU +#define USB3_BBISTXFERSTS1_FAILED_PENDING_TRANS_SIZE_POS 0U + +/* Bit fields of BBISTXFERSTS2 register */ +#define USB3_BBISTXFERSTS2_FAILED_ITERATION_MASK 0x00FFFFFFU +#define USB3_BBISTXFERSTS2_FAILED_ITERATION_POS 0U + +/* Bit fields of BBISTXFERSTS3 register */ +#define USB3_BBISTXFERSTS3_LOOPBACK_STATEMACHINE_MASK 0x0000000FU +#define USB3_BBISTXFERSTS3_LOOPBACK_STATEMACHINE_POS 0U + +/* Bit fields of BBISTEXPDATASTS0 register */ +#define USB3_BBISTEXPDATASTS0_EXP_DATA_MASK 0xFFFFFFFFU +#define USB3_BBISTEXPDATASTS0_EXP_DATA_POS 0U + +/* Bit fields of BBISTEXPDATASTS1 register */ +#define USB3_BBISTEXPDATASTS1_EXP_DATA_MASK 0xFFFFFFFFU +#define USB3_BBISTEXPDATASTS1_EXP_DATA_POS 0U + +/* Bit fields of BBISTEXPDATASTS2 register */ +#define USB3_BBISTEXPDATASTS2_EXP_DATA_MASK 0xFFFFFFFFU +#define USB3_BBISTEXPDATASTS2_EXP_DATA_POS 0U + +/* Bit fields of BBISTEXPDATASTS3 register */ +#define USB3_BBISTEXPDATASTS3_EXP_DATA_MASK 0xFFFFFFFFU +#define USB3_BBISTEXPDATASTS3_EXP_DATA_POS 0U + +/* Bit fields of BBISTRCVDDATASTS0 register */ +#define USB3_BBISTRCVDDATASTS0_RECEIVED_DATA_MASK 0xFFFFFFFFU +#define USB3_BBISTRCVDDATASTS0_RECEIVED_DATA_POS 0U + +/* Bit fields of BBISTRCVDDATASTS1 register */ +#define USB3_BBISTRCVDDATASTS1_RECEIVED_DATA_MASK 0xFFFFFFFFU +#define USB3_BBISTRCVDDATASTS1_RECEIVED_DATA_POS 0U + +/* Bit fields of BBISTRCVDDATASTS2 register */ +#define USB3_BBISTRCVDDATASTS2_RECEIVED_DATA_MASK 0xFFFFFFFFU +#define USB3_BBISTRCVDDATASTS2_RECEIVED_DATA_POS 0U + +/* Bit fields of BBISTRCVDDATASTS3 register */ +#define USB3_BBISTRCVDDATASTS3_RECEIVED_DATA_MASK 0xFFFFFFFFU +#define USB3_BBISTRCVDDATASTS3_RECEIVED_DATA_POS 0U + +/* Bit fields of rsvd_reg register */ +#define USB3_RSVD_REG_RSVD_FIELD_MASK 0xFFFFFFFFU +#define USB3_RSVD_REG_RSVD_FIELD_POS 0U + +#endif diff --git a/src/portable/xhci/xhci.c b/src/portable/xhci/xhci.c new file mode 100644 index 000000000..62b2a64d9 --- /dev/null +++ b/src/portable/xhci/xhci.c @@ -0,0 +1,184 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. + */ + +#include "xhci.h" +#include "socfpga_defines.h" +#include "osal.h" +#include "osal_log.h" + +int is_ptr_mem_aligned(uint64_t addr, uint32_t byte) +{ + uint64_t fact = 0UL; + + /* Check if the address is byte aligned or not */ + switch (byte) + { + case 8U: + fact = 0x7UL; + break; + + case 16U: + fact = 0xFUL; + break; + + case 32U: + fact = 0x1FUL; + break; + + case 64U: + fact = 0x3FUL; + break; + + case 128U: + fact = 0x7FUL; + break; + + default: + fact = 0xFFUL; + break; + } + + if (fact == 0xFFUL) + { + return ENOMEM; + } + + if ((addr & fact) == 0UL) + { + return 0; + } + + return -EIO; +} + +static int configure_xhci_max_slots(void) +{ + volatile uint32_t config_reg_val; + uint32_t hcsparams1; + uint32_t max_slots; + + hcsparams1 = RD_REG32((USBBASE + USB3_HCSPARAMS1)); + max_slots = (hcsparams1 & USB3_HCSPARAMS1_MAXSLOTS_MASK) + >> USB3_HCSPARAMS1_MAXSLOTS_POS; + + DEBUG("MaxSlots is : %x", max_slots); + + config_reg_val = RD_REG32((USBBASE + USB3_CONFIG)); + max_slots |= (config_reg_val & (~USB3_CONFIG_MAXSLOTSEN_MASK)); + WR_REG32((USBBASE + USB3_CONFIG), max_slots); + + config_reg_val = RD_REG32((USBBASE + USB3_CONFIG)); + if ((config_reg_val & USB3_CONFIG_MAXSLOTSEN_MASK) == 0U) + { + ERROR("Max Slot Enable Bit Not configurred Correctly"); + return -EIO; + } + return 0; +} + +void start_xhci_controller(void) +{ + uint32_t reg_val; + + reg_val = RD_REG32((USBBASE + USB3_USBCMD)); + reg_val |= (START_XHCI << USB3_USBCMD_R_S_POS); + WR_REG32((USBBASE + USB3_USBCMD), reg_val); +} + +/* + * wait for the xhci controller to be ready + */ +static int wait_for_controller_ready(void) +{ + uint32_t reg_val; + volatile uint16_t loop = 100; + + do + { + reg_val = RD_REG32((USBBASE + USB3_USBSTS)); + /* check for CNR flag */ + if ((reg_val & USB3_USBSTS_CNR_MASK) == 0U) + { + break; + } + + osal_task_delay(10); + --loop; + + }while(loop > 0); + + if(loop > 0) + { + INFO("xHCI Controller Ready"); + return 0; + } + + return -ETIMEDOUT; +} + +int xhci_reset(void) +{ + volatile uint32_t reg_val, err_flag = 0U, loop = 1000U; + + reg_val = RD_REG32((USBBASE + USB3_USBCMD)); + /* Reset the Host Controller */ + reg_val |= (USB3_USBCMD_HCRST_MASK); + WR_REG32((USBBASE + USB3_USBCMD), reg_val); + + INFO("Initiating Controller Reset"); + do + { + reg_val = RD_REG32((USBBASE + USB3_USBCMD)); + if ((reg_val & USB3_USBCMD_HCRST_MASK) == 0U) + { + err_flag = 1U; + break; + } + osal_task_delay(10); + + --loop; + }while(loop > 0U); + + if (err_flag == 0U) + { + INFO("Timeout Occurred"); + return -ETIMEDOUT; + } + + INFO("xHCI controller reset successful"); + return 0; +} + +bool xhci_init(struct xhci_data *xhci) +{ + int ret; + + get_xhc_cap_params(xhci); + + if(wait_for_controller_ready() != 0) + { + return false; + } + + ret = xhci_reset(); + if( ret != 0 ) + { + ERROR("xhci reset failed"); + return false; + } + + configure_xhci_max_slots(); + + alloc_xhci_contexts(xhci); + + init_xhci_context_params(xhci); + + start_xhci_controller(); + + return true; +} diff --git a/src/portable/xhci/xhci.h b/src/portable/xhci/xhci.h new file mode 100644 index 000000000..d84926e5c --- /dev/null +++ b/src/portable/xhci/xhci.h @@ -0,0 +1,360 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025-2026 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for xHCI implementation + */ + +#ifndef __XHCI_H__ +#define __XHCI_H__ + +#include +#include +#include "xhci_context.h" +#include "xhci_rings.h" + +#define LINK_TRB (6U) /* !< Link TRB id */ +#define TRB_FIELD (10U) /* !< TRB id field position */ +#define SLOTID_FIELD (24U) /* !< Slot id field position */ +#define XHC_DEV_ADDR_MSK (0xffU) /* !< device address field mask */ +#define XHCI_CR_TRB_LEN (16) /* !< xHCI command ring length */ +#define XHCI_CR_CCS_FLAG (1U) /* !< xHCI command ring CCS flag */ +#define XHCI_EP_TR_RING_ALIGN (16) /* !< EP transfer ring alignment requirement */ +#define EP_TRB_SEG_LENGTH (512U) /* !< EP TR segment length */ +#define XHCI_EVENT_RING_SEG_LENGTH (512U) /* !< Event Ring segment length */ +#define START_XHCI (1U) /* !< Start the xHCI controller */ + +typedef enum +{ + ISO_OUT = 1, /* !< Isochronous OUT EP */ + BULK_OUT, /* !< Bulk OUT EP */ + INTERRUPT_OUT, /* !< Interrupt OUT EP */ + CONTROL, /* !< Control EP */ + ISO_IN, /* !< Isochronous IN EP */ + BULK_IN, /* !< Bulk IN EP */ + INTERRUPT_IN, /* !< Interrupt IN EP */ +}xhci_ep_type_t; + +/** + * @brief USB Standard Endpoint Descriptor. + * + * Describes an endpoint’s characteristics such as type, address, maximum packet size, + * and polling interval. It is used during USB enumeration to inform the host of + * endpoint capabilities. + */ +typedef struct +{ + uint8_t bLength; /*!< Size of this descriptor in bytes */ + uint8_t bDescriptorType; /*!< ENDPOINT descriptor type (0x05) */ + uint8_t bEndpointAddress; /*!< The address of the endpoint on the USB device (bit 7 indicates direction: 0 = OUT, 1 = IN) */ + uint8_t bmAttributes; /*!< Endpoint attributes: transfer type (bits 0–1), synchronization type (bits 2–3), usage type (bits 4–5) */ + uint16_t wMaxPacketSize; /*!< Maximum packet size this endpoint is capable of sending or receiving */ + uint8_t bInterval; /*!< Interval for polling endpoint for data transfers (in frames or microframes, depending on transfer type) */ +}/*! \cond */ +__attribute__ ((packed)) +/*! \endcond */ usb_endpoint_descriptor_t; + +/** + * @brief Represents a standard USB control transfer setup packet. + * + * This structure defines the setup packet used in USB control transfers. + * It corresponds to the standard USB setup packet format defined by the USB specification. + */ +typedef struct +{ + uint8_t bmRequestType; /*!< Characteristics of the request: + - Direction (bit 7) + - Type (bits 5..6) + - Recipient (bits 0..4) */ + uint8_t bRequest; /*!< Specific request code */ + uint16_t wValue; /*!< Word-sized field that varies according to request */ + uint16_t wIndex; /*!< Typically used to pass an index or offset (e.g., interface or endpoint) */ + uint16_t wLength; /*!< Number of bytes to transfer if there is a data stage */ +}/*! \cond */ +__attribute__ ((packed)) +/*! \endcond */ usb_control_request_t; + +/* + * @struct xhci_cap_reg + * @brief structure to store xhci capability register parameters + */ +typedef struct __attribute__ ((packed)) +{ + uint8_t caplength; /* !< caplength register */ + uint8_t rsvd; /* !< reserved */ + uint16_t hciversion; /* !< hci version */ + union + { + struct hcsparams1_reg_ + { + uint32_t max_dev_slots : 8; /* !< max device slots supported by xHCI */ + uint32_t max_interrupters : 11; /* !< max interrupters */ + uint32_t rsvd : 5; /* !< reserved */ + uint32_t max_ports : 8; /* !< Max ports supported by the xHCI */ + + } hcsparams1_params __attribute__ ((packed)); + uint32_t hcsparams1; + }; + uint32_t hcsparams2; /* !< xHCI hcsparams2 register */ + uint32_t hcsparams3; /* !< xHCI hcsparams3 register */ + uint32_t hccparams1; /* !< xHCI hccparams1 register */ + union + { + struct dboff_reg + { + uint32_t db_array_offset : 30; /* !< Doorbell register offset */ + uint32_t rsvd : 2; /* !< reserved */ + } dboff_params __attribute__ ((packed)); + uint32_t dboff; + }; + union + { + struct rtsoff_reg + { + uint32_t rts_offset : 27; /* !< Runtime register space offset */ + uint32_t rsvd : 5; /* !< reserved */ + + } rtsoff_params __attribute__ ((packed)); + uint32_t rtsoff; + }; + uint32_t hccparams2; +} xhci_cap_reg_t; + +/* + * @struct xhci_oper_reg_params + * @brief stores xhci operational base, runtime tbase and doorbell base + * address + */ +typedef struct xhci_oper_reg_params +{ + uint64_t xhci_op_base; /* !< operation base offset */ + uint64_t xhci_runtime_base; /* !< Runtime base offset */ + uint64_t xhci_db_base; /* !< Doorbell register offset */ +}xhci_oper_reg_params_t; + +#define DEV_ADDRESS_FIELD 32 +#define SLOT_STATE_FIELD 59 + +/* + * @struct ep_priv + * @brief stores endpoint specific parameters + */ +struct ep_priv +{ + xhci_trb_t *ep_tr_enq_ptr; /* !< TR enqueue pointer */ + usb_endpoint_descriptor_t ep_desc; /* !< endpoint descriptor */ + uint8_t pcs_flag; /* !< pcs flag for EP TR */ + uint8_t ep_addr; /* !< endpoint address */ + uint8_t ep_index; /* !< endpoint index */ + xhci_ep_type_t ep_type; /* !< endpoint type */ +} __attribute__ ((packed)); + +/* + * struct to store MSC specific endpoint data + */ +typedef struct +{ + struct ep_priv ep_in; /* !< Endpoint IN specific parameters */ + struct ep_priv ep_out; /* !< Endpoint OUT specific parameters */ + +}msc_eps_params_t; + +struct xhci_device_data +{ + uint8_t slot_id; /* !< slot id of the device */ + uint8_t dev_addr; /* !< address of the device */ + uint8_t dev_speed; /* !< speed of the device */ + uint8_t rh_port; /* !< RH port of the device */ +}; + +/* + * @brief xhci controller structure + */ +struct xhci_data +{ + struct xhci_device_data dev_data; /* !< device specific data */ + struct ep_priv ep0; /* !< EP 0 params */ + msc_eps_params_t msc_eps; /* !< MSC specific endpoint params */ + + xcr_command_ring_t *xcr_ring; /* !< xHCI command ring */ + xer_event_ring_t xer_ring; /* !< xHCI event ring */ + + xhci_cap_reg_t *xhc_cap_ptr; /* !< xHCI capability register pointer */ + xhci_oper_reg_params_t op_regs; /* !< xHCI operational register */ + + xhci_ip_device_context_t *ip_ctx; /* !< xHCI input context */ + xhci_op_device_context_t *op_ctx; /* !< xHCI output context */ + + struct xhci_device_context_array *dcbaa; /* !< dcbaa pointer array */ +}; + +/** + * @brief allocate xhci context memories + * @param[in] xhci_ptr - reference of xhci hcd controller + * @return + * 0, on successful allocation + * errno, incase of failure + */ +int alloc_xhci_contexts(struct xhci_data *xhci_ptr); + +/** + * @brief update the output device context entry for the corresponding device + * slot id + * @param[in] xhci_ptr : reference to xhci hcd structure + */ +void update_dcbaa_entry(struct xhci_data *xhci_ptr); + +/** + * @brief deallocate xhci context memories + * @param[in] xhci_ptr - reference of xhci hcd controller + */ +void deallocate_xhci_context(struct xhci_data *xhci_ptr); + +/** + * @brief allocate xhci input context + * @param[in] xhci_ptr - reference of xhci hcd controller + * @return + * 0, on successful allocation + * errno, incase of failure + */ +int alloc_input_device_context(struct xhci_data *xhci_ptr); + +/** + * @brief : allocate xhci output device context + * @param[in] xhci_ptr - reference of xhci hcd controller + * @return + * 0, on successful allocation + * errno, incase of failure + */ +int alloc_output_device_context(struct xhci_data *xhci_ptr); + +/** + * @brief initialize input device context data structure + * @param[in] xhci - reference of xhci hcd controller + * @return + * 0, on successful allocation + * errno, incase of failure + */ +int init_input_device_context(struct xhci_data *xhci_ptr); + +/** + * @brief allocate xhci device context base address array and store the base + * address array into DCBAA register + * @param[in] xhci_ptr - reference of xhci hcd controller + * @return + * 0, on successful allocation + * errno, incase of failure + */ +int alloc_dcbaa(struct xhci_data *xhci_ptr); + +/** + * @brief update xhci slot context data structure + * @param[in] xhci_ptr - reference of xhci hcd controller + */ +void update_xhc_slot_context(struct xhci_data *xhci_ptr); + +/** + * @brief initialize endpoint context data structure + * @param[in] xhci - reference of xhci hcd controller + * @param[in] ep_type - endpoint type (bulk, control etc) + * @return + * RET_SUCCESS, on successful allocation + * RET_FAIL, incase of failure + */ +void init_xhc_endpoint_context(struct xhci_data *xhci, xhci_ep_type_t ep_type); + +/** + * @brief return the device address from the output context data structure + * @param[in] xhci - reference of xhci hcd controller + * @return device address + */ +uint8_t get_xhc_device_address(struct xhci_data *xhci_ptr); + +/*XHCI capability register APIs*/ + +/** + * @brief function to return the operational register parameters of xhci + * controller + * @return operational register parameters + */ +xhci_oper_reg_params_t get_xhci_op_registers(void); + +/** + * @brief function to get the xhci capability parameters controller + * @param[in] xhci - reference of xhci hcd controller + * @return + * 0, if operation is successful + * errno, on failure + */ +int get_xhc_cap_params(struct xhci_data *xhci); + +/** + * @brief function to check if the pointer address passed is byte aligned + * @param[in] ptr - reference to xhci strucute + * @return + * 0, on successful allocation + * errno, incase of failure + */ +int init_xhc_event_ring(struct xhci_data *xhci_ptr); + +/** + * @brief Initialize xHCI context parameters. + * @param[in] xhci_ptr reference xhci data structure + * @return + * 0, on successful allocation + * errno, incase of failure + */ +int init_xhci_context_params(struct xhci_data *xhci_ptr); + +/* Generic xhci APIS */ + +/** + * @brief function to check if the pointer address passed is byte aligned + * @param[in] ptr - pointer to be checked byte aligned or not + * @param[in] byte - pointer byte alignment size + * @return + * 0 on successful allocation + * errno, incase of failure + */ +int is_ptr_mem_aligned(uint64_t addr, uint32_t byte); + +/** + * @brief parse the endpoint descriptors + * @param[in] xhci_ptr reference to xhci hcd structure + * @param[in] desc endpoint descriptor + * @return + * 0 on successful allocation + * errno, incase of failure + */ + +int xhci_parse_endpoint_descriptor(struct xhci_data *xhci_ptr, + usb_endpoint_descriptor_t *desc); + +/** + * @brief Display device info + */ +void display_xhci_device_params(struct xhci_device_data *dev_data); + +/** + * @brief reset the xHCI controller + * @return + * 0, on success + * errno, on failure + */ +int xhci_reset(void); + +/** + * @brief start the xHCI controller + */ +void start_xhci_controller(void); + +/** + * @brief Initialize the xHCI registers + * @return + * true on successful initialization + * false incase of failure + */ +bool xhci_init(struct xhci_data *xhci); + +#endif /*__XHCI_H__ */ diff --git a/src/portable/xhci/xhci_cap.c b/src/portable/xhci/xhci_cap.c new file mode 100644 index 000000000..ef8c32900 --- /dev/null +++ b/src/portable/xhci/xhci_cap.c @@ -0,0 +1,74 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. + * Capabilities sub-module + */ + +#include +#include +#include +#include "xhci.h" +#include "osal_log.h" + +/* + * @brief read the host controller capability registers + */ +int get_xhc_cap_params(struct xhci_data *xhci) +{ + uint32_t caplength = RD_REG32(USBBASE + USB3_CAPLENGTH); + uint32_t dboff = RD_REG32(USBBASE + USB3_DBOFF); + uint32_t rtsoff = RD_REG32(USBBASE + USB3_RTSOFF); + + xhci->xhc_cap_ptr = (xhci_cap_reg_t *)USBBASE; + + DEBUG("CAPLENGTH : %x", + (caplength & USB3_CAPLENGTH_CAPLENGTH_MASK)); + DEBUG("HCSPARAMS1 : %x", + RD_REG32(USBBASE + USB3_HCSPARAMS1)); + DEBUG("HCSPARAMS2 : %x", + RD_REG32(USBBASE + USB3_HCSPARAMS2)); + DEBUG("HCSPARAMS3 : %x", + RD_REG32(USBBASE + USB3_HCSPARAMS3)); + DEBUG("HCCPARAMS1 : %x", + RD_REG32(USBBASE + USB3_HCCPARAMS1)); + DEBUG("DBOFF : %x", + (dboff & USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK)); + DEBUG("RTOFF : %x", + (rtsoff & USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK)); + DEBUG("HCCPARAMS2 : %x", + RD_REG32(USBBASE + USB3_HCCPARAMS2)); + + xhci->op_regs.xhci_op_base = (uint64_t)USBBASE + + (uint64_t)(caplength & USB3_CAPLENGTH_CAPLENGTH_MASK); + xhci->op_regs.xhci_runtime_base = (uint64_t)USBBASE + + (uint64_t)(rtsoff & USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK); + xhci->op_regs.xhci_db_base = (uint64_t)USBBASE + + (uint64_t)(dboff & USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK); + + DEBUG("Operational base : %lx ", + xhci->op_regs.xhci_op_base); + DEBUG("Runtime base : %lx ", + xhci->op_regs.xhci_runtime_base); + DEBUG("Doorbell base : %lx ", + xhci->op_regs.xhci_db_base); + + return 0; +} + +xhci_oper_reg_params_t get_xhci_op_registers(void) +{ + xhci_oper_reg_params_t op_reg = {0}; + uint32_t cap = RD_REG32(USBBASE + offsetof(xhci_cap_reg_t, caplength)); + uint32_t dboff = RD_REG32(USBBASE + offsetof(xhci_cap_reg_t, dboff)); + uint32_t rtsoff = RD_REG32(USBBASE + offsetof(xhci_cap_reg_t, rtsoff)); + /* CAPLENGTH[7:0] */ + op_reg.xhci_op_base = (uint64_t)USBBASE + (uint64_t)(cap & 0xFFU); + /* DBOFF[31:2] */ + op_reg.xhci_db_base = (uint64_t)USBBASE + (uint64_t)(dboff & ~0x3U); + /* RSTOFF[31:5] */ + op_reg.xhci_runtime_base = (uint64_t)USBBASE + (uint64_t)(rtsoff & ~0x1FU); + return op_reg; +} diff --git a/src/portable/xhci/xhci_commands.c b/src/portable/xhci/xhci_commands.c new file mode 100644 index 000000000..d3c28d128 --- /dev/null +++ b/src/portable/xhci/xhci_commands.c @@ -0,0 +1,245 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. + * Commands sub-module. + */ + +#include "xhci_commands.h" +#include "xhci_doorbell.h" +#include "socfpga_cache.h" +#include "socfpga_defines.h" +#include "osal_log.h" + +xhci_trb_t *get_cmdring_enq_ptr(xcr_command_ring_t *cmd_ring) +{ + xhci_trb_t *enq_ptr = cmd_ring->xcr_enqueue_ptr; + if ((enq_ptr == NULL) || (cmd_ring == NULL)) + { + return NULL; + } + volatile uint32_t c_bit; + + while (true) + { + if (is_link_trb(enq_ptr) == 1) + { + enq_ptr = get_next_trb_segment(enq_ptr, &cmd_ring->xcr_ccs_flag); + } + c_bit = (enq_ptr->control & 0x00000001U); + if (c_bit == cmd_ring->xcr_ccs_flag) + { + enq_ptr = enq_ptr + 1; + } + else + { + break; + } + } + + return enq_ptr; +} + +void set_device_address(struct xhci_data *xhci_ptr) +{ + uint32_t cmd_ctrl_flags; + xhci_trb_t *enq_ptr; + + enq_ptr = get_cmdring_enq_ptr(xhci_ptr->xcr_ring); + if (enq_ptr == NULL) + { + return; + } + + enq_ptr->buffer = (uint64_t)xhci_ptr->ip_ctx; + + cmd_ctrl_flags = (1 << SLOT_ID_FIELD); + cmd_ctrl_flags |= (ADDRESS_DEVICE_CMD << TRB_FIELD); + cmd_ctrl_flags |= xhci_ptr->xcr_ring->xcr_ccs_flag; + enq_ptr->control = cmd_ctrl_flags; + + cache_force_write_back((void *) xhci_ptr->xcr_ring->xcr_enqueue_ptr, + (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + + ring_xhci_host_db(); +} + +void reset_command_ring(xcr_command_ring_t *xcr_ring) +{ + uint32_t crcr_reg; + uint32_t crcr_addr; + + /* first stop the command ring operation */ + crcr_reg = RD_REG32((USBBASE + USB3_CRCR_LO)); + crcr_reg |= (0x2U); + WR_REG32((USBBASE + USB3_CRCR_LO), crcr_reg); + + crcr_addr = ((uint32_t)(uintptr_t) (&xcr_ring->xcr_dequeue_ptr) & + 0xffffffffU); + WR_REG32((USBBASE + USB3_CRCR_LO), crcr_addr); +} + +void enable_slot_command(xcr_command_ring_t *xcr_ring) +{ + xhci_trb_t *enq_ptr; + uint32_t cmd_ctrl_flags; + + enq_ptr = get_cmdring_enq_ptr(xcr_ring); + if (enq_ptr == NULL) + { + return; + } + + cmd_ctrl_flags = ((uint32_t) ENABLE_SLOT_CMD << TRB_FIELD); + cmd_ctrl_flags |= xcr_ring->xcr_ccs_flag; + + enq_ptr->control = cmd_ctrl_flags; + + cache_force_write_back((void *) xcr_ring->xcr_enqueue_ptr, + (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + + /* call doorbell register */ + ring_xhci_host_db(); + +} +void disable_slot_command(xcr_command_ring_t *xcr_ring, uint32_t slotid) +{ + xhci_trb_t *enq_ptr; + uint32_t cmd_ctrl_flags; + + enq_ptr = get_cmdring_enq_ptr(xcr_ring); + if (enq_ptr == NULL) + { + return; + } + + cmd_ctrl_flags = ((uint32_t) DISABLE_SLOT_CMD << TRB_FIELD); + cmd_ctrl_flags |= (slotid << SLOTID_FIELD); + cmd_ctrl_flags |= xcr_ring->xcr_ccs_flag; + + enq_ptr->control = cmd_ctrl_flags; + + cache_force_write_back((void *) xcr_ring->xcr_enqueue_ptr, + (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + + /* call doorbell register */ + ring_xhci_host_db(); +} + +void configure_endpoint(struct xhci_data *xhci_ptr) +{ + uint32_t cmd_ctrl_flags; + xhci_trb_t *enq_ptr; + + enq_ptr = get_cmdring_enq_ptr(xhci_ptr->xcr_ring); + if ((enq_ptr == NULL) || (xhci_ptr == NULL)) + { + return; + } + + enq_ptr->buffer = (uint64_t)xhci_ptr->ip_ctx; + enq_ptr->status = 0U; + + cmd_ctrl_flags = 0; + cmd_ctrl_flags |= ((uint32_t) 1 << SLOT_ID_FIELD); + cmd_ctrl_flags |= ((uint32_t) CONFIGURE_ENDPOINT_CMD << TRB_FIELD); + cmd_ctrl_flags |= xhci_ptr->xcr_ring->xcr_ccs_flag; + + enq_ptr->control = cmd_ctrl_flags; + + cache_force_write_back((void *) xhci_ptr->xcr_ring->xcr_enqueue_ptr, + XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + + ring_xhci_host_db(); +} + +static void stop_endpoint_command(xcr_command_ring_t *xcr_ring) +{ + uint32_t cmd_ctrl_flags; + xhci_trb_t *enq_ptr; + + enq_ptr = get_cmdring_enq_ptr(xcr_ring); + if (enq_ptr == NULL) + { + return; + } + + enq_ptr->buffer = 0U; + enq_ptr->status = 0U; + + cmd_ctrl_flags = 0; + cmd_ctrl_flags |= ((uint32_t) 1U << SLOT_ID_FIELD); + cmd_ctrl_flags |= ((uint32_t) 1U << SP_BIT_FIELD); + cmd_ctrl_flags |= ((uint32_t) 1U << ENDPOINT_ID_FIELD); + cmd_ctrl_flags |= ((uint32_t) STOP_ENDPOINT_CMD << TRB_FIELD); + cmd_ctrl_flags |= xcr_ring->xcr_ccs_flag; + + enq_ptr->control = cmd_ctrl_flags; + + cache_force_write_back((void *) xcr_ring->xcr_enqueue_ptr, + (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + + ring_xhci_host_db(); +} + +void update_ep_transfer_ring(xcr_command_ring_t *xcr_ring, xhci_trb_t *xtr_ring) +{ + uint32_t cmd_ctrl_flags; + xhci_trb_t *enq_ptr; + if (xtr_ring == NULL) + { + return; + } + /* + * first stop the endpoint using stop endpoint command xhci_trb_t + * Then update the TR pointer + */ + stop_endpoint_command(xcr_ring); + + enq_ptr = get_cmdring_enq_ptr(xcr_ring); + + enq_ptr->buffer = (uint64_t)xtr_ring; + enq_ptr->status = 0U; + + cmd_ctrl_flags = 0; + cmd_ctrl_flags |= ((uint32_t) 1U << SLOT_ID_FIELD); + cmd_ctrl_flags |= ((uint32_t) 1U << ENDPOINT_ID_FIELD); + cmd_ctrl_flags |= ((uint32_t) SET_TR_DEQUEUE_PTR_CMD << TRB_FIELD); + cmd_ctrl_flags |= xcr_ring->xcr_ccs_flag; + + enq_ptr->control = cmd_ctrl_flags; + + cache_force_write_back((void *) xcr_ring->xcr_enqueue_ptr, + (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + + ring_xhci_host_db(); +} + +void evaluate_endpoint(struct xhci_data *xhci_ptr) +{ + uint32_t cmd_ctrl_flags = 0U; + const uint8_t slotid = xhci_ptr->dev_data.slot_id; + xhci_trb_t *enq_ptr; + + if (xhci_ptr == NULL) + { + return; + } + + enq_ptr = get_cmdring_enq_ptr(xhci_ptr->xcr_ring); + + enq_ptr->buffer = (uint64_t)xhci_ptr->ip_ctx; + enq_ptr->status = 0U; + + cmd_ctrl_flags |= ((uint32_t) slotid << SLOT_ID_FIELD); + cmd_ctrl_flags |= ((uint32_t) EVALUATE_CONTEXT_CMD << TRB_FIELD); + cmd_ctrl_flags |= xhci_ptr->xcr_ring->xcr_ccs_flag; + enq_ptr->control = cmd_ctrl_flags; + + cache_force_write_back((void *) xhci_ptr->xcr_ring->xcr_enqueue_ptr, + (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + + ring_xhci_host_db(); +} diff --git a/src/portable/xhci/xhci_commands.h b/src/portable/xhci/xhci_commands.h new file mode 100644 index 000000000..9e326dc46 --- /dev/null +++ b/src/portable/xhci/xhci_commands.h @@ -0,0 +1,127 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for commands sub-module in SoC FPGA USB3.1 XHCI low level driver. + */ + +#ifndef __XHCI_COMMANDS_H__ +#define __XHCI_COMMANDS_H__ + +#include +#include "xhci.h" + +/* XHCI specific command ring IDs */ +#define ENABLE_SLOT_CMD (9U) /* !< ID for enable slot command TRB */ +#define DISABLE_SLOT_CMD (10U) /* !< ID for disable slot command TRB */ +#define ADDRESS_DEVICE_CMD (11U) /* !< ID for address device command TRB */ +#define CONFIGURE_ENDPOINT_CMD (12U) /* !< ID for configure endpoint command TRB */ +#define EVALUATE_CONTEXT_CMD (13U) /* !< ID for evaluate context command TRB */ + +/* @struct : xcc_event_t + * @brief : structure to store the command completion Event TRB data + */ +typedef struct __attribute__ ((packed)) +{ + uint64_t cmd_trb_ptr; /*!< address of command TRB that generated the event. */ + union + { + struct cmd_compl_status_field + { + uint32_t compl_parameter : 24; /*!< command completion parameter */ + uint32_t compl_code : 8; /*!< Completion code */ + } cc_status_params __attribute__ ((packed)); + uint32_t status_field; + }; + union + { + struct cmd_compl_ctrl_field + { + uint32_t cbit : 1; /*!< cycle bit of the TRB */ + uint32_t rzvd : 9; /*!< reserved*/ + uint32_t trb_id : 6; /*!< TRB id for command completion event */ + uint32_t vf_id : 8; /*!< Virtual function id. Valid only if VF are enabled */ + uint32_t slot_id : 8; /*!< Slot id of the associated command TRB */ + } cc_ctrl_params __attribute__ ((packed)); + uint32_t control_field; + }; +} xcc_event_t; + +#define RESET_ENDPOINT_CMD 14U /*!< reset endpoint command trb id*/ +#define STOP_ENDPOINT_CMD 15U /*!< stop endpoint command trb id*/ +#define SET_TR_DEQUEUE_PTR_CMD 16U /*!< set tr dequeue pointer command trb id*/ + +#define ENDPOINT_ID_FIELD 15 /*!< endpoint field position in the trb structure */ +#define SP_BIT_FIELD 23 /*!< SP bit field position in the trb structure */ +#define SLOT_ID_FIELD 24 /*!< slot id field position in the trb structure */ + + +typedef enum +{ + COMMAND_SUCCESS = 1, + COMMAND_FAILIURE = 0, + +}xhci_command_status_t; + +/* + * @func : reset_command_ring + * @brief : reset the command ring + * @param[in] xhci reference to command ring structure + */ +void reset_command_ring(xcr_command_ring_t *xcr_ring); + +/* + * @func : set_device_address + * @brief : send the USB set address command to device + * @param[in] xhci reference to xhci structure + */ +void set_device_address(struct xhci_data *xhci_ptr); + +/* + * @func : enable_slot_command + * @brief : send the USB enable slot command + * @param[in] xhci reference to xhci command ring structure + */ +void enable_slot_command(xcr_command_ring_t *xcr_ring); + +/* + * @func : disable_slot_command + * @brief : send the USB disable slot command + * @param[in] xhci reference to xhci command structure + * @param[in] xhci slot id to be disabled + */ +void disable_slot_command(xcr_command_ring_t *xcr_ring, uint32_t slotid); + +/* + * @func : configure_endpoint + * @brief : send the USB configure endpoint command to device + * @param[in] xhci reference to xhci structure + */ +void configure_endpoint(struct xhci_data *xhci_ptr); + +/* + * @func : evaluate_endpoint: + * @brief : send the USB evaluate endpoint command + * @param[in] xhci reference to xhci structure + */ +void evaluate_endpoint(struct xhci_data *xhci_ptr); + +/* + * @func : update_ep_transfer_ring + * @brief : Update the endpoint transfer ring + * @param[in] xhci reference to xhci structure + * @param[in] xtr_ring updated endpoint transfer ring + */ +void update_ep_transfer_ring(xcr_command_ring_t *xcr_ring, + xhci_trb_t *xtr_ring); + +/* + * @func : get_cmdring_enq_ptr + * @brief : find the enqueue pointer location for the ring + * @param[in] cmd_ring command ring reference pointer + * @return xhci_trb_t* reference to enqueue pointer + */ +xhci_trb_t *get_cmdring_enq_ptr(xcr_command_ring_t *cmd_ring); + +#endif /*__XHCI_COMMANDS_H__*/ diff --git a/src/portable/xhci/xhci_context.c b/src/portable/xhci/xhci_context.c new file mode 100644 index 000000000..28123d0ca --- /dev/null +++ b/src/portable/xhci/xhci_context.c @@ -0,0 +1,467 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. + * Context sub-module. + */ + +/* + * xHCI are data structures that are associated with a device which stores the state information. + * + * Following are the xHCI context structures + * + * -> Device context + * -> Slot context + * -> Endpoint context + * -> Input Context + * -> Input Control Context + * -> Output Context + * + * Each device has its own associated context structures. xHCI implements the DCBAA structure + * to associate a device slot with the associated device context data structure. + * The DCBAA structure can be indexed by the device slot ID. + * + * DCBAA + * +-----------+ + * | Slot 0 |------------------->+------------------+ + * +-----------+ | sractchpad buf | + * | Slot 1 | +------------------+ + * +-----------+------------------->+------------------+ + * | ... | | Slot Context | + * +-----------+ +------------------+ +---------------+ + * | Slot n | | Endpoint 0 (bi) |------------>| transfer ring | + * +-----------+ +------------------+ +---------------+ + * | Endpoint 1 (out) | . + * +------------------+ . + * | Endpoint 1 (in) | . + * +------------------+ . + * | ... | . + * +------------------+ +---------------+ + * | Endpoint 15 (in) |------------>| transfer ring | + * +------------------+ +---------------+ + */ + +#include "xhci.h" +#include "socfpga_cache.h" +#include "socfpga_defines.h" +#include "xhci_endpoints.h" +#include "xhci_context.h" +#include "xhci_events.h" +#include "osal_log.h" + +int alloc_xhci_contexts(struct xhci_data *xhci_ptr) +{ + int ret = 0; + xhci_ptr->xcr_ring = alloc_command_ring(); + if (xhci_ptr->xcr_ring == NULL) + { + ERROR("Cannot allocate memory!!!"); + ret = -ENOMEM; + } + + if (alloc_input_device_context(xhci_ptr) != 0) + { + ERROR("Cannot allocate memory!!!"); + ret = -ENOMEM; + } + + if (alloc_output_device_context(xhci_ptr) != 0) + { + ERROR("Cannot allocate memory!!!"); + ret = -ENOMEM; + } + + if (ret != 0) + { + if (xhci_ptr->xcr_ring != NULL) + { + vPortFree((void *)xhci_ptr->xcr_ring); + } + if (xhci_ptr->ip_ctx != NULL) + { + vPortFree((void *)xhci_ptr->ip_ctx); + } + if (xhci_ptr->op_ctx != NULL) + { + vPortFree((void *)xhci_ptr->op_ctx); + } + } + INFO("xHCI contexts allocated successfully"); + return ret; +} + +void deallocate_xhci_context(struct xhci_data *xhci_ptr) +{ + const uint32_t slotid = xhci_ptr->dev_data.slot_id; + + /* remove the output context address from dcbaa */ + xhci_ptr->dcbaa->dev_context_ptrs[slotid] = 0UL; + + /* free bulk endpoint tr rings */ + if (xhci_ptr->msc_eps.ep_out.ep_tr_enq_ptr != NULL) + { + vPortFree((void *)(uintptr_t)(xhci_ptr->msc_eps.ep_out.ep_tr_enq_ptr)); + } + if (xhci_ptr->msc_eps.ep_in.ep_tr_enq_ptr != NULL) + { + vPortFree((void *)(uintptr_t)(xhci_ptr->msc_eps.ep_in.ep_tr_enq_ptr)); + } + + /* Free Control EP TR ring */ + if (xhci_ptr->ep0.ep_tr_enq_ptr != NULL) + { + vPortFree((void *)(uintptr_t)(xhci_ptr->ep0.ep_tr_enq_ptr)); + } + + /* clear input and output context data structures */ + bzero(xhci_ptr->op_ctx, sizeof(xhci_op_device_context_t)); + bzero(xhci_ptr->ip_ctx, sizeof(xhci_ip_device_context_t)); + + xhci_ptr->dev_data.slot_id = 0U; + xhci_ptr->dev_data.rh_port = 0U; + INFO("xHCI contexts deallocated successfully"); +} + +int init_xhci_context_params(struct xhci_data *xhci_ptr) +{ + /* Initialize all device parameters to 0 */ + xhci_ptr->dev_data.slot_id = 0U; + xhci_ptr->dev_data.dev_addr = 0U; + xhci_ptr->dev_data.dev_speed = 0U; + xhci_ptr->dev_data.rh_port = 0U; + + if (alloc_dcbaa(xhci_ptr) != 0) + { + return -ENOMEM; + } + + if (xhci_crcr_init(xhci_ptr->xcr_ring) != 0) + { + return -ENOMEM; + } + + if (init_xhc_event_ring(xhci_ptr) != 0) + { + return -ENOMEM; + } + + return 0; +} + +/** + * @brief function to allocate memory for input context and initialize them to 0 + */ +int alloc_input_device_context(struct xhci_data *xhci_ptr) +{ + xhci_ptr->ip_ctx = (xhci_ip_device_context_t *)pvPortMallocCoherent( + sizeof(xhci_ip_device_context_t)); + if (xhci_ptr->ip_ctx == NULL) + { + ERROR("Cannot allocate memory!!!"); + return -ENOMEM; + } + + bzero(xhci_ptr->ip_ctx, sizeof(xhci_ip_device_context_t)); + return 0; +} + +int init_input_device_context(struct xhci_data *xhci_ptr) +{ + xhci_ip_device_context_t *input_ctx = xhci_ptr->ip_ctx; + + uint64_t ep0_max_pkt_size = 0UL; + uint8_t dev_speed; + uint8_t rh_port; + uint8_t context_entries; + uint64_t add_flags = 0UL; + int ret = 0; + xhci_trb_t *xep0_tr_ptr; + + /* + * Input Control Context + * Select A0, A1 flags + */ + add_flags = (DCI_SLOT_CONTEXT << SLOT_CONTEXT_POS); + add_flags |= (EP0_DCI << EP0_DCI_POS); + input_ctx->xi_context.xic_context_flags = ((uint64_t)add_flags << 32); + + /* + * Slot contexts + * Context Entries -> 1 + * Speed -> 3 ( from PORTSC PLS bits ) + * RH port number -> 1 + */ + dev_speed = xhci_ptr->dev_data.dev_speed; + rh_port = xhci_ptr->dev_data.rh_port; + + switch (dev_speed) + { + case 4: + PRINT("xHCI - SS device attached"); + ep0_max_pkt_size = EP0_MAX_PKT_SIZE_SS; + break; + case 3: + PRINT("xHCI - HS device attached"); + ep0_max_pkt_size = EP0_MAX_PKT_SIZE_HS; + break; + case 2: + PRINT("xHCI - LS device attached"); + ep0_max_pkt_size = EP0_MAX_PKT_SIZE_FS; + break; + case 1: + PRINT("xHCI - FS device attached"); + ep0_max_pkt_size = EP0_MAX_PKT_SIZE_LS; + break; + default: + /* resource unavalable, try again */ + PRINT("XHCI - Device enumeration failed"); + ret = -EAGAIN; + break; + } + + if (ret != 0) + { + return ret; + } + + /* Update the slot context fields */ + + /*get the context entry field for the control endpoint */ + context_entries = get_ep_dci(0U); + + input_ctx->xs_context.xsc_info1 = ((uint64_t)dev_speed << 20); + input_ctx->xs_context.xsc_info1 |= ((uint64_t)context_entries << 27); + input_ctx->xs_context.xsc_info1 |= ((uint64_t)rh_port << 48); + + /* + * Endpoint Contexts + * EP Type -> 4 ( Control ) + * Max Packet Size -> 8 ( for LS ) + * Cerr -> 3 + * TR Dequeue pointer + * DCS -> 1 + * Avg. TRB Length -> 8 + */ + xep0_tr_ptr = allocate_ring_segment(XHCI_EP_TR_RING_ALIGN, + EP_TRB_SEG_LENGTH); + if (xep0_tr_ptr == NULL) + { + ERROR("Cannot allocate memory!!!"); + return -ENOMEM; + } + + input_ctx->xe_context[0].xec_info = ((uint64_t)CONTROL << 35); + input_ctx->xe_context[0].xec_info |= ((uint64_t)ep0_max_pkt_size << + EP_CTX_MAX_PKT_SIZE_POS); + input_ctx->xe_context[0].xec_info |= ((uint64_t)3U << 33); + + input_ctx->xe_context[0].xec_dequeue = (uint64_t)xep0_tr_ptr; + input_ctx->xe_context[0].xec_dequeue |= EP0_CCS_FLAG; + + input_ctx->xe_context[0].xec_info2 = EP_DEFAULT_TRB_LEN; + + xhci_ptr->ep0.ep_addr = 0x00U; + xhci_ptr->ep0.ep_index = 1U; + xhci_ptr->ep0.pcs_flag = 1U; + xhci_ptr->ep0.ep_type = CONTROL; + xhci_ptr->ep0.ep_tr_enq_ptr = xep0_tr_ptr; + + return 0; +} + +int alloc_output_device_context(struct xhci_data *xhci_ptr) +{ + xhci_ptr->op_ctx = (xhci_op_device_context_t *)pvPortMallocCoherent( + sizeof(xhci_op_device_context_t)); + if (xhci_ptr->op_ctx == NULL) + { + ERROR("Canot allocate memory!!!"); + return -ENOMEM; + } + + bzero(xhci_ptr->op_ctx, sizeof(xhci_op_device_context_t)); + + return 0; +} + +void init_xhc_endpoint_context(struct xhci_data *xhci, xhci_ep_type_t ep_type) +{ + usb_endpoint_descriptor_t *ep_desc; + xhci_trb_t *tr_ptr; + uint8_t pcs_flag; + uint8_t ep_index; + + if (ep_type == BULK_OUT) + { + ep_desc = &xhci->msc_eps.ep_out.ep_desc; + pcs_flag = xhci->msc_eps.ep_out.pcs_flag; + ep_index = xhci->msc_eps.ep_out.ep_index; + tr_ptr = xhci->msc_eps.ep_out.ep_tr_enq_ptr; + } + + /* ep_type = BULK_IN */ + else + { + ep_desc = &xhci->msc_eps.ep_in.ep_desc; + pcs_flag = xhci->msc_eps.ep_in.pcs_flag; + ep_index = xhci->msc_eps.ep_in.ep_index; + tr_ptr = xhci->msc_eps.ep_in.ep_tr_enq_ptr; + } + + if (ep_desc == NULL) + { + return; + } + + xhci->ip_ctx->xe_context[ep_index].xec_info = ((uint64_t)ep_type << 35); + xhci->ip_ctx->xe_context[ep_index].xec_dequeue = (uint64_t)tr_ptr; + xhci->ip_ctx->xe_context[ep_index].xec_dequeue |= pcs_flag; + + /* packet size */ + xhci->ip_ctx->xe_context[ep_index].xec_info |= + ((uint64_t)ep_desc->wMaxPacketSize << EP_CTX_MAX_PKT_SIZE_POS); + + /* Cerr = 3 */ + xhci->ip_ctx->xe_context[ep_index].xec_info |= ((uint64_t)3U << 33); +} + +int alloc_dcbaa(struct xhci_data *xhci_ptr) +{ + xhci_ptr->dcbaa = (struct xhci_device_context_array *)pvPortMallocCoherent( + sizeof(struct xhci_device_context_array)); + if (xhci_ptr->dcbaa == NULL) + { + return -ENOMEM; + } + for (int i = 0; i < 256; i++) + { + xhci_ptr->dcbaa->dev_context_ptrs[i] = 0UL; + } + + WR_REG64((USBBASE + USB3_DCBAAP_LO), (uint64_t)xhci_ptr->dcbaa); + DEBUG("xHCI DCBAA register updated"); + + return 0; +} + +void update_dcbaa_entry(struct xhci_data *xhci_ptr) +{ + const uint32_t slotid = xhci_ptr->dev_data.slot_id; + xhci_ptr->dcbaa->dev_context_ptrs[slotid] = (uint64_t)xhci_ptr->op_ctx; +} + +void update_xhc_slot_context(struct xhci_data *xhci_ptr) +{ + const uint8_t dci_bulk_in = get_ep_dci(xhci_ptr->msc_eps.ep_in.ep_addr); + const uint8_t dci_bulk_out = get_ep_dci(xhci_ptr->msc_eps.ep_out.ep_addr); + const uint8_t context_entry_val = (dci_bulk_in > dci_bulk_out) + ? dci_bulk_in : dci_bulk_out; + uint64_t add_flags = 0UL; + + add_flags |= (DCI_SLOT_CONTEXT << SLOT_CONTEXT_POS); + add_flags |= (uint64_t)(1UL) << (dci_bulk_out); + add_flags |= (uint64_t)1UL << (dci_bulk_in); + + xhci_ptr->ip_ctx->xi_context.xic_context_flags = (add_flags << 32); + + xhci_ptr->ip_ctx->xs_context.xsc_info1 &= SLOT_CONTEXT_ENTRIES_MSK; + xhci_ptr->ip_ctx->xs_context.xsc_info1 |= ((uint64_t)context_entry_val << + SLOT_CONTEXT_ENTRIES_POS); +} + +void display_xhci_device_params(struct xhci_device_data *dev_data) +{ + char const *dev_speed[] = {"Null", "Low Speed", "Full Speed", "High Speed"}; + + DEBUG("Device address : %d", dev_data->dev_addr); + DEBUG("Device Slot: %d", dev_data->slot_id); + DEBUG("Device rh port: %d", dev_data->rh_port); + DEBUG("Device speed : %s", dev_speed[dev_data->dev_speed]); + + /* Suppressing unused variable warning when not using DEBUG logs. */ + (void)dev_data; + (void)dev_speed; +} + +void update_device_dev_speed(struct xhci_data *xhci_ptr) +{ + xhci_ptr->dev_data.dev_speed = get_xhc_port_speed( + xhci_ptr->dev_data.rh_port); +} + +void update_device_slot_id(struct xhci_device_data *dev_data, uint8_t slot_id) +{ + dev_data->slot_id = slot_id; +} + +void update_device_rh_params(struct xhci_data *xhci_ptr, + xhci_psceg_params_t rh_params) +{ + xhci_ptr->dev_data.rh_port = (uint8_t) rh_params.rhport; +} + +void update_device_address(struct xhci_data *xhci_ptr) +{ + xhci_ptr->dev_data.dev_addr = get_xhc_device_address(xhci_ptr); +} + +uint8_t get_xhc_device_address(struct xhci_data *xhci_ptr) +{ + uint8_t daddr = 0; + + daddr = (uint8_t) ((xhci_ptr->op_ctx->slot_context.xsc_info2 >> + DEV_ADDRESS_FIELD) & XHC_DEV_ADDR_MSK); + + return daddr; +} + +void update_endpoint_packetsize(xhci_ip_device_context_t *ip_ctx, + uint16_t max_pkt_size) +{ + ip_ctx->xe_context[0].xec_info &= EP_CTX_MAX_PKT_SIZE_MSK; + ip_ctx->xe_context[0].xec_info |= ((uint64_t)max_pkt_size << + EP_CTX_MAX_PKT_SIZE_POS); +} + +void display_ip_context(xhci_ip_device_context_t *ip_ctx) +{ + DEBUG(" Input control Contexts "); + DEBUG(" Field 1 : %lx", ip_ctx->xi_context.xic_context_flags); + + DEBUG(" Slot Contexts "); + DEBUG(" Field 1 : %lx", ip_ctx->xs_context.xsc_info1); + DEBUG(" Field 2 : %lx", ip_ctx->xs_context.xsc_info2); + + DEBUG(" Endpoint 0 Contexts "); + DEBUG(" Field 1 : %lx", ip_ctx->xe_context[0].xec_info); + DEBUG(" Field 2 : %lx", ip_ctx->xe_context[0].xec_dequeue); + DEBUG(" Field 3 : %lx", ip_ctx->xe_context[0].xec_info2); + + (void)ip_ctx; +} + +void display_op_context(xhci_op_device_context_t *op_ctx) +{ + DEBUG(" Slot Contexts "); + DEBUG(" Field 1 : %lx", op_ctx->slot_context.xsc_info1); + DEBUG(" Field 2 : %lx", op_ctx->slot_context.xsc_info2); + + DEBUG(" Endpoint 0 Contexts "); + DEBUG(" Field 1 : %lx", op_ctx->EP_0.xec_info); + DEBUG(" Field 2 : %lx", op_ctx->EP_0.xec_dequeue); + DEBUG(" Field 3 : %lx", op_ctx->EP_0.xec_info2); + + DEBUG(" Endpoint 1 OUT Contexts "); + DEBUG(" Field 1 : %lx", op_ctx->EP[0].xec_info); + DEBUG(" Field 2 : %lx", op_ctx->EP[0].xec_dequeue); + DEBUG(" Field 3 : %lx", op_ctx->EP[0].xec_info2); + + DEBUG(" Endpoint 2 IN Contexts "); + DEBUG(" Field 1 : %lx", op_ctx->EP[3].xec_info); + DEBUG(" Field 2 : %lx", op_ctx->EP[3].xec_dequeue); + DEBUG(" Field 3 : %lx \r\n", op_ctx->EP[3].xec_info2); + + (void)op_ctx; +} diff --git a/src/portable/xhci/xhci_context.h b/src/portable/xhci/xhci_context.h new file mode 100644 index 000000000..2973c78a1 --- /dev/null +++ b/src/portable/xhci/xhci_context.h @@ -0,0 +1,125 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for context sub-module of SoC FPGA USB3.1 XHCI low level driver + */ + +#ifndef __XCHI_CONTEXT_H__ +#define __XCHI_CONTEXT_H__ + +#include "socfpga_usb3_reg.h" +#include "socfpga_defines.h" + +/* MASK and POS for Input control context */ +#define DCI_SLOT_CONTEXT (1UL) /* !< Select slot context in Input control context */ +#define SLOT_CONTEXT_POS (0) /* !< Slot context Index position in Input control context */ +#define SLOT_CONTEXT_ENTRIES_MSK (0xffffffff07ffffffUL) /* !< Context entries bit mask in slot context data structure */ +#define SLOT_CONTEXT_ENTRIES_POS (27) /* !< Bit position for contrxt entries in slot context structure */ +#define EP0_DCI (1UL) /* !< Endpoint 0 Device context index */ +#define EP0_DCI_POS (1) /* !< Endpoint 0 bitfield position in device context */ +#define EP0_CCS_FLAG (1U) /* !< EP0 Cycle bit */ + +/* + * endpoint context bit mask and position + */ +#define EP_CTX_MAX_PKT_SIZE_POS (48) /* !< Endpoint 0 packet size configuration location in endpoint context structure */ +#define EP_CTX_MAX_PKT_SIZE_MSK (0x0000ffffffffffffUL) /* !< Endpoint 0 packet size configuration bitmask in endpoint context structure */ + +/* + * Endpoint 0 max packet sizes + */ +#define EP0_MAX_PKT_SIZE_SS (512UL) /* !< Max. packet size for SS device */ +#define EP0_MAX_PKT_SIZE_HS (64UL) /* !< Max. packet size for HS device */ +#define EP0_MAX_PKT_SIZE_FS (8UL) /* !< Max. packet size for FS device */ +#define EP0_MAX_PKT_SIZE_LS (8UL) /* !< Max. packet size for LS device */ + +#define EP_DEFAULT_TRB_LEN (8U) /* !< xhci default trb len */ + +/* + * @struct : slot xhci_slot_context_t + * @brief : slot context data structure + * @note : Refer page 444 of xhci Document + */ +typedef struct __attribute__ ((packed)){ + uint64_t xsc_info1; + uint64_t xsc_info2; + uint64_t xsc_reserved[6]; +} xhci_slot_context_t; + +/* + * @struct : xhci_endpoint_context_t + * @brief : endpoint context data structure + */ +typedef struct __attribute__ ((packed)){ + uint64_t xec_info; + uint64_t xec_dequeue; + uint64_t xec_info2; + uint64_t xec_reserved[5]; +} xhci_endpoint_context_t; + +/* + * @struct : xhci_input_control_context_t + * @brief : input control context data structure + */ +typedef struct __attribute__ ((packed)){ + uint64_t xic_context_flags; /* drop/add flags for contexts */ + uint64_t xic_reserved[7]; +} xhci_input_control_context_t; + +/* + * @struct : xhci_ip_device_context_t + * @brief : Input Device Context data structure + */ +typedef struct __attribute__ ((packed)) +{ + xhci_input_control_context_t xi_context; + xhci_slot_context_t xs_context; + xhci_endpoint_context_t xe_context[31]; +} xhci_ip_device_context_t; + +/* + * @struct : xhci_op_device_context_t + * @brief : Output Device Context Data Structure + */ +typedef struct __attribute__ ((packed)) +{ + xhci_slot_context_t slot_context; /* slot context followed by endpoint context */ + xhci_endpoint_context_t EP_0; /* EP 0 context */ + xhci_endpoint_context_t EP[30]; /* EP 1 - 30 contexts */ +} xhci_op_device_context_t; + +/* Device Context Base Address Array */ +/* + * @struct : xhci_device_context_array + * @brief : device context base address array structure + */ +struct xhci_device_context_array { + uint64_t dev_context_ptrs[256]; +}; + +/* + * @func : update_endpoint_packetsize + * @brief : update the endpoint context with max packet size + * @param[in] ip_ctx reference to input context data structure + * @param[in] max_pkt_size max packet size + */ +void update_endpoint_packetsize(xhci_ip_device_context_t *ip_ctx, + uint16_t max_pkt_size); + +/* + * @func : display_op_context + * @brief : Display the output context data structure + * @param[in] op_ctx reference to output context data structure + */ +void display_op_context(xhci_op_device_context_t *op_ctx); + +/* + * @func : display_ip_context + * @brief : Display the input context data structure + * @param[in] ip_ctx reference to input context data structure + */ +void display_ip_context(xhci_ip_device_context_t *ip_ctx); + +#endif /* __XCHI_CONTEXT_H__ */ diff --git a/src/portable/xhci/xhci_doorbell.c b/src/portable/xhci/xhci_doorbell.c new file mode 100644 index 000000000..111b8a082 --- /dev/null +++ b/src/portable/xhci/xhci_doorbell.c @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. + * Doorbell submodule. + */ + +#include "xhci_doorbell.h" +#include "socfpga_defines.h" + +void ring_xhci_host_db(void) +{ + xhci_oper_reg_params_t op_regs; + + op_regs = get_xhci_op_registers(); + WR_REG32((op_regs.xhci_db_base + USB3_DB), XHCI_COMMAND_DOORBELL); +} +void ring_xhci_ep0_db(xhci_oper_reg_params_t *op_regs) +{ + uint64_t db_reg; + uint32_t slot_id = 1U; + + db_reg = (op_regs->xhci_db_base + USB3_DB) + + (XHCI_DB_REG_SIZE * (uint64_t) slot_id); + + WR_REG32((uint32_t) db_reg, XHCI_DB_EP0_TARGET); +} + +void ring_xhci_ep_doorbell(xhci_oper_reg_params_t *op_regs, uint8_t db_target) +{ + uint64_t db_reg; + uint32_t slot_id = 1U; + + db_reg = (op_regs->xhci_db_base + USB3_DB) + + (XHCI_DB_REG_SIZE * (uint64_t) slot_id); + + WR_REG32((uint32_t) db_reg, db_target); +} diff --git a/src/portable/xhci/xhci_doorbell.h b/src/portable/xhci/xhci_doorbell.h new file mode 100644 index 000000000..db97a18b2 --- /dev/null +++ b/src/portable/xhci/xhci_doorbell.h @@ -0,0 +1,37 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for Doorbell sub-module of SoC FPGA USB3.1 XHCI low level driver + */ + +#ifndef __XHCI_DOORBELL_H__ +#define __XHCI_DOORBELL_H__ + +#include "xhci.h" + +#define XHCI_DB_REG_SIZE (4U) /* !< Doorbell register size */ +#define XHCI_DB_EP0_TARGET (0x1U) /* !< doorbell target for endpoint 0 transfers */ + +#define XHCI_COMMAND_DOORBELL (0U << USB3_DB_DB_TARGET_POS) /* !< Doorbell target for command ring */ + +/* + * @brief ring the XHCI host controller command doorbell + */ +void ring_xhci_host_db(void); + +/* + * @brief ring the XHCI host controller Endpoint 0 doorbell + * @param[in] op_regs reference to operation register structure + */ +void ring_xhci_ep0_db(xhci_oper_reg_params_t *op_regs); + +/* + * @brief ring the XHCI host controller doorbell + * @param[in] op_regs reference to operation register structure + * @param[in] db_target doorbell target to ring + */ +void ring_xhci_ep_doorbell(xhci_oper_reg_params_t *op_regs, uint8_t db_target); + +#endif /* __XHCI_DOORBELL_H__ */ diff --git a/src/portable/xhci/xhci_endpoints.c b/src/portable/xhci/xhci_endpoints.c new file mode 100644 index 000000000..e4fb2c605 --- /dev/null +++ b/src/portable/xhci/xhci_endpoints.c @@ -0,0 +1,408 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. + * Endpoints sub-module. + */ + +#include "xhci_doorbell.h" +#include "xhci.h" +#include "xhci_endpoints.h" +#include "xhci_rings.h" +#include "osal_log.h" +#include "socfpga_cache.h" + +/** + * @brief Setup the TRB with the control transfer data. For xHCI, control transfer consists of 3 stages. + * ( Data stage is optional). All the 3 stages are populated in this api. + */ +void configure_setup_stage(struct xhci_data *xhci, void *buffer, + usb_control_request_t *setup_req) +{ + uint32_t end_ctrl_flags = 0U; + xhci_trb_t *ptr = xhci->ep0.ep_tr_enq_ptr; + if (ptr == NULL) + { + return; + } + do + { + if (is_link_trb(ptr) == 1) + { + ptr = get_next_trb_segment(ptr, &xhci->ep0.pcs_flag); + } + /* check for Enqueue pointer location */ + if ((ptr->control & 0x1U) == 1U) + { + ptr = ptr + 1; + } + else + { + break; + } + }while(true); + + ptr->buffer = ((uint64_t) setup_req->bmRequestType & 0xffU); + ptr->buffer |= ((uint64_t) setup_req->bRequest << 8); + ptr->buffer |= ((uint64_t) setup_req->wValue << 16); + ptr->buffer |= ((uint64_t)setup_req->wIndex << 32); + ptr->buffer |= ((uint64_t)setup_req->wLength << 48); + + /* transfer length = 8 for control transfers */ + ptr->status = SETUP_STAGE_TRB_LEN; + + end_ctrl_flags |= ((uint32_t) SETUP_STAGE_TRB << 10); + end_ctrl_flags |= ((uint32_t) SETUP_STAGE_DIR_IN << 16); + end_ctrl_flags |= (1U << IDT_FLAG); + end_ctrl_flags |= xhci->ep0.pcs_flag; + + /* PCS FLAG */ + ptr->control = end_ctrl_flags; + + ptr++; + + if (is_link_trb(ptr) == 1) + { + ptr = get_next_trb_segment(ptr, &xhci->ep0.pcs_flag); + } + + if (setup_req->wLength > 0U) + { + /* Data Stage TRB */ + ptr->status = (uint32_t)setup_req->wLength; + ptr->buffer = (uint64_t)buffer; + + end_ctrl_flags = 0U; + + /* TRB TYPE = 3 */ + end_ctrl_flags |= ((uint32_t) DATA_STAGE_TRB << 10); + end_ctrl_flags |= ((uint32_t) DATA_STAGE_DIR_IN << 16); + end_ctrl_flags |= xhci->ep0.pcs_flag; + + ptr->control = end_ctrl_flags; + + ptr++; + + if (is_link_trb(ptr) == 1) + { + ptr = get_next_trb_segment(ptr, &xhci->ep0.pcs_flag); + } + } + + /* Status Stage TRB + * IOC =1 + * PCS flag + */ + + end_ctrl_flags = 0U; + end_ctrl_flags |= ((uint32_t) STATUS_STAGE_TRB << 10); + end_ctrl_flags |= (1U << IOC_FLAG); + end_ctrl_flags |= ((uint32_t) STATUS_STAGE_DIR_OUT << 16); + end_ctrl_flags |= xhci->ep0.pcs_flag; + + ptr->control = end_ctrl_flags; + + cache_force_write_back((void *) xhci->ep0.ep_tr_enq_ptr, + EP_TRB_SEG_LENGTH * sizeof(xhci_trb_t)); +} + +/** + * @brief Get the endpoint DCI from the endpoint address + */ +uint8_t get_ep_dci(uint8_t ep_addr) +{ + uint8_t ep_dir; + uint8_t ep_num; + uint8_t ep_dci; + + ep_dir = get_endpoint_dir(ep_addr); + ep_num = get_endpoint_num(ep_addr); + + if (ep_num == 0U) + { + ep_dci = 1U; + } + else + { + /* EP DCI is ICI -1 */ + ep_dci = (ep_num * 2U) + ep_dir; + } + + return ep_dci; +} + +/* + * @brief Get the td_size as per the xHCI spec for the transfer + */ +static uint32_t get_td_size(uint16_t bytes_trasnferred, + uint16_t trb_transfer_len, uint32_t total_len, + uint16_t mps, bool is_last_trb) +{ + uint32_t total_pkt_count; + uint32_t total_pkt_xferred; + uint32_t td_size; + + if (is_last_trb == true) + { + return 0U; + } + + if (mps == 0U) + { + return 0U; + } + total_pkt_count = ROUNDUP(total_len, mps); + total_pkt_xferred = ROUNDDOWN((bytes_trasnferred + trb_transfer_len), + (uint32_t) mps); + + td_size = total_pkt_count - total_pkt_xferred; + + if (td_size > MAX_TD_SIZE) + { + td_size = MAX_TD_SIZE; + } + + return td_size; +} + +/* + * @brief Populate endpoint transfer rings for bulk transfer + */ +static void fill_endpoint_transfer_ring(struct ep_priv *ep_ctx, void *buffer, + uint32_t len) +{ + uint32_t ep_pcs_flag; + uint16_t e_mps = ep_ctx->ep_desc.wMaxPacketSize; + + volatile uint32_t trb_transfer_len; + volatile uint32_t bytes_xferred; + volatile uint32_t total_bytes; + + volatile uint32_t status_field; + volatile uint32_t end_ctrl_flags; + volatile uint32_t td_size; + + uint32_t bytes_pending; + uint64_t addr; + bool last_trb = false; + volatile uint32_t c_bit; + + xhci_trb_t *ptr = ep_ctx->ep_tr_enq_ptr; + if (ptr == NULL) + { + return; + } + + while (true) + { + if (is_link_trb(ptr) == 1) + { + ptr = get_next_trb_segment(ptr, &ep_ctx->pcs_flag); + } + + c_bit = (ptr->control & 0x00000001U); + if (c_bit == ep_ctx->pcs_flag) + { + ptr = ptr + 1; + } + else + { + break; + } + } + + trb_transfer_len = 0U; + bytes_xferred = 0U; + total_bytes = len; + bytes_pending = len; + addr = (uint64_t)buffer; + + for (bytes_xferred = 0U; bytes_xferred < total_bytes; + bytes_xferred += trb_transfer_len) + { + ep_pcs_flag = ep_ctx->pcs_flag; + status_field = 0U; + end_ctrl_flags = 0U; + + if (bytes_pending > MAX_TRB_LEN) + { + trb_transfer_len = 65536; + } + else + { + trb_transfer_len = bytes_pending; + } + + if ((bytes_xferred + trb_transfer_len) > total_bytes) + { + trb_transfer_len = total_bytes - bytes_xferred; + } + + if ((bytes_xferred + trb_transfer_len) < total_bytes) + { + end_ctrl_flags |= (1U << CH_FLAG); + } + /* Last TRB of the TD, Next will be Event TRB */ + if ((bytes_xferred + trb_transfer_len) >= total_bytes) + { + end_ctrl_flags |= (1U << ENT_FLAG); + end_ctrl_flags |= (1U << CH_FLAG); + last_trb = true; + } + + td_size = get_td_size(bytes_xferred, trb_transfer_len, total_bytes, + e_mps, last_trb); + + status_field |= (td_size << 16); + status_field |= trb_transfer_len; + + end_ctrl_flags |= ((uint32_t) NORMAL_TRB << TRB_FIELD); + end_ctrl_flags |= (ep_pcs_flag); + + ptr->buffer = addr; + ptr->status = status_field; + ptr->control = end_ctrl_flags; + + addr += (uint64_t)trb_transfer_len; + bytes_pending -= trb_transfer_len; + + ptr++; + + if (is_link_trb(ptr) == 1) + { + ptr = get_next_trb_segment(ptr, &ep_ctx->pcs_flag); + } + } + + ptr->buffer = (uint64_t)ep_ctx->ep_tr_enq_ptr; + ptr->status = 0U; + + end_ctrl_flags = 0U; + end_ctrl_flags |= (1U << IOC_FLAG); + end_ctrl_flags |= ((uint32_t) EVENT_DATA_TRB << TRB_FIELD); + end_ctrl_flags |= (ep_ctx->pcs_flag); + + ptr->control = end_ctrl_flags; + cache_force_write_back((void *) ep_ctx->ep_tr_enq_ptr, + EP_TRB_SEG_LENGTH * sizeof(xhci_trb_t)); +} + +/** + * @brief Initiate an endpoint transfer on bulk endpoints + */ +bool endpoint_transfer(struct xhci_data *xhci, int ep_num, uint8_t dir, + void *buffer, uint32_t buflen) +{ + uint8_t ICI; + ICI = (uint8_t)((uint32_t) ep_num * 2U) + dir + 1U; + uint8_t db_target = (uint8_t)(ICI - 1U); + + /* Out transfer */ + if (dir == 0U) + { + INFO("Endpoint OUT transfer on endpoint - %d with bytes - %d ", ep_num, + buflen); + fill_endpoint_transfer_ring(&xhci->msc_eps.ep_out, buffer, buflen); + ring_xhci_ep_doorbell(&xhci->op_regs, db_target); + } + /* In Transfer */ + else if (dir == 1U) + { + INFO("Endpoint IN transfer on endpoint - %d with bytes - %d ", ep_num, + buflen); + fill_endpoint_transfer_ring(&xhci->msc_eps.ep_in, buffer, buflen); + ring_xhci_ep_doorbell(&xhci->op_regs, db_target); + } + else + { + return false; + } + return true; +} + +int xhci_parse_endpoint_descriptor(struct xhci_data *xhci_ptr, + usb_endpoint_descriptor_t *desc) +{ + const uint8_t ep_dir = get_endpoint_dir(desc->bEndpointAddress); + uint8_t max_streams = 0; + if (ep_dir == USB_EP_DIR_IN) + { + xhci_ptr->msc_eps.ep_in.ep_desc.bLength = desc->bLength; + xhci_ptr->msc_eps.ep_in.ep_desc.bDescriptorType = desc->bDescriptorType; + xhci_ptr->msc_eps.ep_in.ep_desc.bEndpointAddress = + desc->bEndpointAddress; + xhci_ptr->msc_eps.ep_in.ep_desc.bmAttributes = desc->bmAttributes; + xhci_ptr->msc_eps.ep_in.ep_desc.wMaxPacketSize = desc->wMaxPacketSize; + xhci_ptr->msc_eps.ep_in.ep_desc.bInterval = desc->bInterval; + + xhci_ptr->msc_eps.ep_in.ep_type = BULK_IN; + xhci_ptr->msc_eps.ep_in.pcs_flag = 1U; + + /* For xHCI spec, endpoint context index is ep_dci -1 */ + xhci_ptr->msc_eps.ep_in.ep_index = get_ep_dci(desc->bEndpointAddress) - + 0x1U; + xhci_ptr->msc_eps.ep_in.ep_addr = desc->bEndpointAddress; + + if (max_streams > 0U) + { + /* Stream support not enabled */ + return -ENOTSUP; + } + else + { + xhci_trb_t *enq_ptr; + enq_ptr = allocate_ring_segment(XHCI_EP_TR_RING_ALIGN, + EP_TRB_SEG_LENGTH); + if (enq_ptr == NULL) + { + ERROR("Canot allocate memory!!!"); + return -ENOMEM; + } + + xhci_ptr->msc_eps.ep_in.ep_tr_enq_ptr = enq_ptr; + } + } + + if (ep_dir == USB_EP_DIR_OUT) + { + xhci_trb_t *enq_ptr; + max_streams = 0; + + xhci_ptr->msc_eps.ep_out.ep_desc.bLength = desc->bLength; + xhci_ptr->msc_eps.ep_out.ep_desc.bDescriptorType = + desc->bDescriptorType; + xhci_ptr->msc_eps.ep_out.ep_desc.bEndpointAddress = + desc->bEndpointAddress; + xhci_ptr->msc_eps.ep_out.ep_desc.bmAttributes = desc->bmAttributes; + xhci_ptr->msc_eps.ep_out.ep_desc.wMaxPacketSize = desc->wMaxPacketSize; + xhci_ptr->msc_eps.ep_out.ep_desc.bInterval = desc->bInterval; + + xhci_ptr->msc_eps.ep_out.ep_type = BULK_OUT; + xhci_ptr->msc_eps.ep_out.pcs_flag = 1U; + + /* For xHCI spec, endpoint context index is ep_dci -1 */ + xhci_ptr->msc_eps.ep_out.ep_index = get_ep_dci(desc->bEndpointAddress) - + 0x1U; + xhci_ptr->msc_eps.ep_out.ep_addr = desc->bEndpointAddress; + + if (max_streams > 0U) + { + /* Stream support not enabled */ + return -ENOTSUP; + } + else + { + enq_ptr = allocate_ring_segment(XHCI_EP_TR_RING_ALIGN, + EP_TRB_SEG_LENGTH); + if (enq_ptr == NULL) + { + ERROR("Cannot allocate memory!!!"); + return -ENOMEM; + } + xhci_ptr->msc_eps.ep_out.ep_tr_enq_ptr = enq_ptr; + } + } + return 0; +} diff --git a/src/portable/xhci/xhci_endpoints.h b/src/portable/xhci/xhci_endpoints.h new file mode 100644 index 000000000..05fb63378 --- /dev/null +++ b/src/portable/xhci/xhci_endpoints.h @@ -0,0 +1,97 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for Endpoints sub-module of SoC FPGA USB3.1 XHCI low level driver + */ + +#ifndef __XHCI_ENDPOINTS_H__ +#define __XHCI_ENDPOINTS_H__ + +#include +#include +#include "xhci.h" + +#define USB_EP_DIR_IN_MSK (0x80U) /* !< Endpoint direction mask for xhci */ +#define USB_EP_DIR_OUT (0U) /* !< OUT endpoint */ +#define USB_EP_DIR_IN (1U) /* !< IN endpoint */ + +#define SETUP_STAGE_TRB (2U) /* !< trb id of setup stage */ +#define DATA_STAGE_TRB (3U) /* !< trb id of data stage */ +#define STATUS_STAGE_TRB (4U) /* !< trb id of status stage*/ +#define NORMAL_TRB (1U) /* !< trb id of normal trb*/ +#define EVENT_DATA_TRB (7U) /* !< trb id of event data trb*/ + +#define ENT_FLAG (1) /* !< Bit position for Evaluate Next TRB field */ +#define CH_FLAG (4) /* !< Bit position for CHAIN bit field */ +#define IOC_FLAG (5) /* !< Bit position for IOC field */ +#define IDT_FLAG (6) /* !< Bit position for IDT field */ + +#define SETUP_STAGE_TRB_LEN (8U) /* !< xhci setup stage TRB len */ + +#define STATUS_STAGE_DIR_OUT (0U) /* !< xhci status stage direction is OUT */ +#define STATUS_STAGE_DIR_IN (1U) /* !< xhci status stage direction is IN */ + +#define DATA_STAGE_DIR_IN (1U) /* !< xhci data stage direction is IN */ +#define SETUP_STAGE_DIR_IN (3U) /* !< xhci setup stage direction is IN*/ + +#define ROUNDUP(x, y) (((x) + (y) - 1U) / (y)) +#define ROUNDDOWN(x, y) (((x) + (y)) / (y)) +#define MIN(x, y) (((x) < (y)) ? (x): (y)) +#define MAX_TD_SIZE (31U) + +#define MAX_TRB_LEN (65536U) + +/* + * @brief get the endpoint direction + * @param[in] ep_addr : endpoint address + * @return endpoint direction + */ +static inline uint8_t get_endpoint_dir(uint8_t ep_addr) +{ + return (uint8_t)(((ep_addr & + USB_EP_DIR_IN_MSK) != 0U) ? USB_EP_DIR_IN : USB_EP_DIR_OUT); +} + +/* + * @brief get the endpoint number + * @param[in] ep_addr endpoint address + * @return endpoint number + */ +static inline uint8_t get_endpoint_num(uint8_t ep_addr) +{ + return (uint8_t)(ep_addr & 0x3U); +} + +/* + * @brief find the xhci device context index from the endpoint number + * @param[in] xhci_ptr - endpoint address + * @return device context index + */ +uint8_t get_ep_dci(uint8_t ep_addr); + +/** + * @brief initialize the endpoint0 transfer ring for control transfers + * @param[in] xhci reference to xhci hcd structure + * @param[in] buffer reference to buffer to hold the control transfer data + * @param[in] setup_req reference to the USB control request + */ +void configure_setup_stage(struct xhci_data *xhci, void *buffer, + usb_control_request_t *setup_req); + +/** + * @brief handle the bulk endpoint transfer + * @param[in] xhci reference to xhci hcd structure + * @param[in] ep_num endpoint number to initiate the transfer + * @param[in] dir endpoint direction + * @param[in] buffer reference to buffer to hold the control transfer data + * @param[in] buflen number of bytes of data to transfer out/in + * @return + * true , on successful transfer + * false , on failure + */ +bool endpoint_transfer(struct xhci_data *xhci, int ep_num, uint8_t dir, + void *buffer, uint32_t buflen); + +#endif /*__XHCI_ENDPOINTS_H__ */ diff --git a/src/portable/xhci/xhci_events.c b/src/portable/xhci/xhci_events.c new file mode 100644 index 000000000..c9551db73 --- /dev/null +++ b/src/portable/xhci/xhci_events.c @@ -0,0 +1,245 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025-2026 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. + * Events sub-module + */ + +#include +#include "xhci_events.h" +#include "socfpga_defines.h" +#include "socfpga_cache.h" +#include "osal_log.h" + +static void erdp_register_update(); + +void display_event_trbs(struct xhci_data *xhci) +{ + cache_force_invalidate((void *) xhci->xer_ring.xer_enqueue_ptr, + (size_t) (XHCI_EVENT_RING_SEG_LENGTH * sizeof(xhci_trb_t))); + for (int i = 0; i < 10; i++) + { + DEBUG(" ID --> %d", i); + DEBUG(" Address : %p", &xhci->xer_ring.xer_enqueue_ptr[i]); + DEBUG(" Buffer : %lx", xhci->xer_ring.xer_enqueue_ptr[i].buffer); + DEBUG(" Status : %x", xhci->xer_ring.xer_enqueue_ptr[i].status); + DEBUG(" Control : %x", xhci->xer_ring.xer_enqueue_ptr[i].control); + DEBUG(" TRB Value is : %d", + ((xhci->xer_ring.xer_enqueue_ptr[i].control) & 0xfc00U) >> 10); + } +} + +uint8_t get_xhc_port_speed(uint8_t rhport) +{ + uint32_t portsc_reg_val, portsc_reg; + uint8_t port_speed; + + xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); + portsc_reg = (uint32_t) ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + + portsc_reg_val = RD_REG32(portsc_reg); + port_speed = (uint8_t) ((portsc_reg_val & USB3_PORTSC_20_PORTSPEED_MASK) >> + USB3_PORTSC_20_PORTSPEED_POS); + + return port_speed; +} + +/* + * @note : Bit 0 of PORTSC register returns the device connect/disconnect + * status + */ +bool xhci_port_status(uint8_t rhport) +{ + uint32_t reg_val; + uint32_t portsc_reg; + + xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); + portsc_reg = (uint32_t) ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + + /*Bit 0 gives attach/detach status */ + reg_val = RD_REG32(portsc_reg); + if ((reg_val & 1U) != 0U) + { + return true; + } + return false; +} + +/* reset the RH port */ +void reset_xhci_port(uint8_t rhport) +{ + uint32_t reg_val; + xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); + uint32_t portsc_reg = (uint32_t) ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + + reg_val = RD_REG32(portsc_reg); + reg_val |= (USB3_PORTSC_20_PR_MASK); + WR_REG32(portsc_reg, reg_val); + INFO("xHCI port reset initiated on port : %d", rhport); +} + +bool is_xhci_port_reset_end(uint8_t rhport) +{ + volatile uint32_t reg_val, portsc_reg; + uint32_t loop = 100U; + + xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); + portsc_reg = ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + do + { + reg_val = RD_REG32(portsc_reg); + if ((reg_val & (1U << 4)) == 0U) + { + break; + } + + loop--; + osal_task_delay(10); + }while(loop > 0U); + + if (loop == 0U) + { + ERROR("usb3 port reset failure"); + return false; + } + + INFO("xHCI port reset completede on port : %d", rhport); + return true; +} + +xhci_event_trb_t get_xhc_event(struct xhci_data *xhci_ptr) +{ + uint64_t erdp_addr; + xhci_event_trb_type_t trb_id; + xhci_event_trb_t event = {0}; + + /* decrement the event ring trb count */ + xhci_ptr->xer_ring.trb_count -= 1U; + + erdp_addr = RD_REG32(ERDP); + erdp_addr &= 0xfffffff0UL; + + cache_force_invalidate((void *)erdp_addr, sizeof(xhci_trb_t)); + + xhci_trb_t *event_trb = (xhci_trb_t *)(uint64_t)erdp_addr; + + trb_id = (xhci_event_trb_type_t)((event_trb->control & 0xfc00U) >> 10); + + if (trb_id == TRANSFER_EVENT) + { + event.tr_event.tr_trb_ptr = event_trb->buffer; + event.tr_event.status_field = event_trb->status; + event.tr_event.control_field = event_trb->control; + } + else if (trb_id == COMMAND_COMPLETION_EVENT) + { + event.cc_event.cmd_trb_ptr = event_trb->buffer; + event.cc_event.status_field = event_trb->status; + event.cc_event.control_field = event_trb->control; + } + else if (trb_id == PORT_STATUS_CHANGE_EVENT) + { + event.psc_event.buf = event_trb->buffer; + event.psc_event.status_field = event_trb->status; + event.psc_event.control_field = event_trb->control; + } + else + { + /* error TRB type */ + configASSERT(trb_id >= 0); + } + erdp_register_update(&xhci_ptr->xer_ring); + return event; +} + +static void erdp_register_update(xer_event_ring_t *xer_ring) +{ + uint32_t trb_count; + uint64_t erdp_addr; + + trb_count = xer_ring->trb_count; + + if (trb_count == 0U) + { + erdp_addr = RD_REG32(ERDP); + erdp_addr = (uint64_t)xer_ring->xer_enqueue_ptr; + /* EHB flag */ + erdp_addr |= 8UL; + /* reload the event ring trb count to initial value of EP_TRB_SEG_LENGTH */ + xer_ring->trb_count = XHCI_EVENT_RING_SEG_LENGTH; + } + else + { + erdp_addr = RD_REG32(ERDP); + erdp_addr += 0x10U; + } + WR_REG64(ERDP, erdp_addr); +} + +xhci_psceg_params_t handle_psceg_event(xpsc_event_t psc_event) +{ + uint32_t portsc_reg, portsc_register, temp = 0U; + xhci_psceg_params_t port_params = { 0 }; + + uint8_t rhport = (uint8_t) ((psc_event.buf & 0xff000000UL) >> 24); + + xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); + portsc_register = (uint32_t) ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + portsc_reg = RD_REG32(portsc_register); + + if ((portsc_reg & USB3_PORTSC_20_CSC_MASK) > 0U) + { + /* device connected to RH PORT */ + if ((portsc_reg & USB3_PORTSC_20_CCS_MASK) == 1U) + { + /* acknowledge the status bit change */ + temp |= (USB3_PORTSC_20_CSC_MASK); + port_params.rhport = rhport; + port_params.dev_attach_flag = 1; + } + else + /* device detach event from RH PORT */ + { + /* acknowledge the status bit change */ + temp |= (USB3_PORTSC_20_CSC_MASK); + port_params.rhport = rhport; + port_params.dev_attach_flag = -1; + } + } + if ((portsc_reg & USB3_PORTSC_20_PRC_MASK) > 0U) + { + /*Port Reset Event */ + temp |= USB3_PORTSC_20_PRC_MASK; + } + if ((portsc_reg & USB3_PORTSC_30_WRC_MASK) > 0U) + { + /*Warm PR Event */ + temp |= USB3_PORTSC_30_WRC_MASK; + } + + portsc_reg &= ~PORTSC_CLEAR_FLAGS; + portsc_reg |= temp; + WR_REG32(portsc_register, portsc_reg); + + return port_params; +} + +void xhci_warm_reset(uint8_t rhport) +{ + uint32_t reg_val, portsc_register; + xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); + + portsc_register = (uint32_t) ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + + reg_val = RD_REG32(portsc_register); + reg_val |= USB3_PORTSC_30_WPR_MASK; + WR_REG32(portsc_register, reg_val); +} diff --git a/src/portable/xhci/xhci_events.h b/src/portable/xhci/xhci_events.h new file mode 100644 index 000000000..18aa01101 --- /dev/null +++ b/src/portable/xhci/xhci_events.h @@ -0,0 +1,228 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for Events sub-module of SoC FPGA USB3.1 XHCI low level driver + */ + +#ifndef __XHCI_EVENTS_H__ +#define __XHCI_EVENTS_H__ + +#include +#include "xhci.h" +#include "xhci_commands.h" + +/* XHCI specific event completion codes */ +#define EVENT_SUCCESS (1U) + +#define PORTSC_REG_OFFSET (0x00000400UL) /*!< XHCI PORTSC register offset */ + +#define PORTSC_CLEAR_FLAGS (0x80FF01FFU) /*!< flag used to reset any of the PORTSC register status flags */ + +typedef enum +{ + DATA_BUFFER_ERROR = 2, /* !< HC is unable to keep up with reception of data*/ + BABBLE_DETECTED_ERROR, /* !< Babbling is detected during the transaction generated by this TRB */ + USB_TRANSACTION_ERROR, /* !< Host did not receive a valid response from device */ + TRB_ERROR, /* !< Asserted when a TRB parameter error has occurred */ + STALL_ERROR, /* !< Asserted due to a stall condition */ + + PARAMETER_ERROR = 17, /* !< Asserted by a command if the context parameter is invalid */ + CONTEXT_STATE_ERROR = 19, /* !< Asserted if transition is made from illegal context state */ + COMMAND_RING_STOPPED = 24, /* !< Asserted due to a Command Stop operation */ + STOPPED_LENGTH_INVALID =27 /* !< Asserted in a Transfer Event if the transfer was terminated by a Stop + Endpoint Command and the Transfer Event TRB Transfer Length field is + invalid*/ +}xhci_completion_code_t; + +/* XHCI specific EVENT Identification codes */ +typedef enum +{ + TRANSFER_EVENT = 32, /* !< Transfer event TRB id */ + COMMAND_COMPLETION_EVENT, /* !< Command Completion event TRB id */ + PORT_STATUS_CHANGE_EVENT, /* !< PSCEG event TRB id */ +}xhci_event_trb_type_t; + +/* @struct xtc_event_t + * @brief structure to store the transfer completion Event TRB data + */ +typedef struct __attribute__ ((packed)) +{ + uint64_t tr_trb_ptr; /* !< address of the TRB that generated this event */ + union + { + struct transfer_compl_status_field + { + uint32_t transfer_len : 24; /* !< Number of bytes transferred */ + uint32_t compl_code : 8; /* !< completion code of this event */ + } tc_status_params __attribute__ ((packed)); + uint32_t status_field; + }; + union + { + struct trasfer_compl_ctrl_field + { + uint32_t cbit : 1; /* !< cycle bit */ + uint32_t rzvd0 : 1; /* !< reserved */ + uint32_t ed_bit : 1; /* !< Event Data bit.When set to ‘1’, the event was generated by an Event Data TRB and the + Parameter Component (TRB Pointer field) contains a 64-bit value provided by the Event Data + TRB. If cleared to ‘0’, the Parameter Component (TRB Pointer field) contains a pointer to the TRB + that generated this event.*/ + uint32_t rzvd1 : 7; /* !< reserved */ + uint32_t trb_id : 6; /* !< TRB id */ + uint32_t ep_dci : 5; /* !< Endpoint id through which the transfer occurred */ + uint32_t rzvd2 : 3; /* !< reserved */ + uint32_t slot_id : 8; /* !< Slot id of the associated context*/ + } tc_ctrl_params __attribute__ ((packed)); + uint32_t control_field; + }; + +} xtc_event_t; + +/* @struct xpsc_event_t + * @brief structure to store the PSC completion Event TRB data + */ +typedef struct __attribute__ ((packed)) +{ + uint64_t buf; /* !< Stores the port id of the port that generated this event */ + union + { + struct psc_status_field + { + uint32_t rzvd : 24; /* !< reserved */ + uint32_t compl_code : 8; /* !< Completion code of this event. It is always one for PSCEG */ + } psc_status_params __attribute__ ((packed)); + uint32_t status_field; + }; + union + { + struct psc_ctrl_field + { + uint32_t cbit : 1; /* !< cycle bit */ + uint32_t rzvd1 : 9; /* !< reserved */ + uint32_t trb_id : 6; /* !< trb id */ + uint32_t rzvd2 : 16; /* !< reserved */ + } psc_event __attribute__ ((packed)); + uint32_t control_field; + }; + +} xpsc_event_t; + +/* @struct generic_event_trb + * @brief generic structure template for event trb + */ +struct generic_event_trb +{ + uint64_t buffer; /* !< buffer field of a trb */ + uint32_t status; /* !< Status field of a trb */ + union + { + uint32_t control_field; + struct ctrl_flags + { + uint32_t cbit : 1; /* !< cycle bit */ + uint32_t rzvd0 : 9; /* !< reserved */ + uint32_t trb_type : 6; /* !< trb id */ + uint32_t rzvd1 : 16; /* !< reserved */ + } trb_control_field __attribute__ ((packed)); + }; +}; + +typedef union +{ + xcc_event_t cc_event; + xtc_event_t tr_event; + xpsc_event_t psc_event; + struct generic_event_trb event_trb; +}xhci_event_trb_t; + +/* Structure to store the event ring parameters */ +typedef struct +{ + uint32_t rhport; /* !< root hub port id of the device*/ + int dev_attach_flag; /* !< 1 indicated device attach, 0 indicated device detach */ +}xhci_psceg_params_t; + +/* + * @brief function to display the event ring TRBs + * @param[in] xhci reference to xhci data structure + */ +void display_event_trbs(struct xhci_data *xhci); + +/* + * @brief get the xhci event from the event ring + * @param[in] xhci reference to xhci data structure + * @return + * event ring parameters + */ +xhci_event_trb_t get_xhc_event(struct xhci_data *xhci_ptr); + +/* + * @brief Get the xhci RH port link speed + * @param[in] rhport rh port id of the corresponding port + */ +uint8_t get_xhc_port_speed(uint8_t rhport); + +/* + * @brief get the RH port conntect status + * @param[in] rhport rh port id of the corresponding port + */ +bool xhci_port_status(uint8_t rhport); + +/* + * @brief check if rh port reset is completed + * @param[in] rhport rh port id of the corresponding port + * @return + * true if port reset ends successfully + * false if port reset is unsuccessful + */ +bool is_xhci_port_reset_end(uint8_t rhport); + +/* + * @brief reset the xhci RH port + * @param[in] rhport rh port id of the corresponding port + */ +void reset_xhci_port(uint8_t rhport); + +/* + * @brief handle all the PSCEG event + * @param[in] psc_event PSCEG event TRB + * @return port number and attach/detach flag + */ +xhci_psceg_params_t handle_psceg_event(xpsc_event_t psc_event); + +/* + * @brief update the device address in the xhci structure + * @param[in] xhci - reference of xhci hcd controller + */ +void update_device_address(struct xhci_data *xhci_ptr); + +/* + * @brief update the device speed in the xhci structure + * @param[in] xhci_ptr - reference of xhci hcd controller + */ +void update_device_dev_speed(struct xhci_data *xhci_ptr); + +/* + * @brief update the device slot id in the xhci structure + * @param[in] dev_data - reference of xhci_device_data structure + * @param[in] slot_id - slot id of the attached device + */ +void update_device_slot_id(struct xhci_device_data *dev_data, uint8_t slot_id); + +/* + * @brief update the device roothub parameters in the xhci structure + * @param[in] xhci_ptr - reference of xhci hcd controller + * @param[in] rh_params - roothub parameters + */ +void update_device_rh_params(struct xhci_data *xhci_ptr, + xhci_psceg_params_t rh_params); + +/* + * @brief Issue warm reset + * @param[in] rhport The port id for which WR should be done + */ +void xhci_warm_reset(uint8_t rhport); + +#endif /* __XHCI_EVENTS_H__ */ diff --git a/src/portable/xhci/xhci_interrupts.c b/src/portable/xhci/xhci_interrupts.c new file mode 100644 index 000000000..b472d3f76 --- /dev/null +++ b/src/portable/xhci/xhci_interrupts.c @@ -0,0 +1,109 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. + * Interrupt sub-module. + */ + +#include "xhci.h" +#include "xhci_interrupts.h" +#include "socfpga_interrupt.h" +#include "socfpga_usb3_reg.h" +#include "socfpga_defines.h" +#include "socfpga_interrupt_priority.h" +#include "osal_log.h" + +void socfpga_usb3_handler(void *handler); + +void enable_xhci_interrupts(void) +{ + volatile uint32_t reg_val; + struct xhci_oper_reg_params op_regs; + + op_regs = get_xhci_op_registers(); + + reg_val = RD_REG32((op_regs.xhci_runtime_base + USB3_IMAN)); + reg_val |= USB3_IMAN_IE_MASK; + WR_REG32((op_regs.xhci_runtime_base + USB3_IMAN), reg_val); + + reg_val = RD_REG32((USBBASE + USB3_USBCMD)); + reg_val |= USB3_USBCMD_INTE_MASK; + WR_REG32((USBBASE + USB3_USBCMD), reg_val); +} + +void disable_xhci_interrupts(void) +{ + + volatile uint32_t reg_val; + struct xhci_oper_reg_params op_regs; + + op_regs = get_xhci_op_registers(); + + reg_val = RD_REG32((op_regs.xhci_runtime_base + USB3_IMAN)); + reg_val &= ~(USB3_IMAN_IE_MASK); + WR_REG32((op_regs.xhci_runtime_base + USB3_IMAN), reg_val); + + reg_val = RD_REG32((op_regs.xhci_runtime_base + USB3_IMAN)); + reg_val &= ~(USB3_IMAN_IP_MASK); + WR_REG32((op_regs.xhci_runtime_base + USB3_IMAN), reg_val); + + reg_val = RD_REG32((USBBASE + USB3_USBCMD)); + reg_val &= ~(USB3_USBCMD_INTE_MASK); + WR_REG32((USBBASE + USB3_USBCMD), reg_val); +} + +bool register_usb3ISR(xhci_int_ptr_t int_handler) +{ + int err; + + err = interrupt_register_isr(USB1IRQ, socfpga_usb3_handler, + int_handler); + if (err != 0) + { + return false; + } + + err = interrupt_enable(USB1IRQ, GIC_INTERRUPT_PRIORITY_USB3); + if (err != 0) + { + ERROR("Failed to enable interrupt"); + return false; + } + + INFO("Interrupt handler registered successfully"); + return true; +} + +void socfpga_usb3_handler(void *handler) +{ + xhci_int_ptr_t usb3_int_handler; + uint32_t reg_val; + struct xhci_oper_reg_params op_regs; + + op_regs = get_xhci_op_registers(); + + usb3_int_handler = (xhci_int_ptr_t) handler; + + reg_val = RD_REG32((USBBASE + USB3_USBSTS)); + + if (((reg_val & USB3_USBSTS_HSE_MASK) != 0U) || ((reg_val & + USB3_USBSTS_HCE_MASK) != 0U)) + { + (void) xhci_reset(); + start_xhci_controller(); + return; + } + + reg_val |= (USB3_USBSTS_EINT_MASK); + WR_REG32((USBBASE + USB3_USBSTS), reg_val); + + reg_val = RD_REG32((op_regs.xhci_runtime_base + USB3_IMAN)); + reg_val |= USB3_IMAN_IP_MASK; + WR_REG32((op_regs.xhci_runtime_base + USB3_IMAN), reg_val); + + /* rh_port = 1 -> RH port number as per tinyusb stack */ + /* in_isr = true, ISR flag for tinyusb stack */ + usb3_int_handler->int_handler(1, true); +} diff --git a/src/portable/xhci/xhci_interrupts.h b/src/portable/xhci/xhci_interrupts.h new file mode 100644 index 000000000..154f3aab5 --- /dev/null +++ b/src/portable/xhci/xhci_interrupts.h @@ -0,0 +1,40 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for Interrupts sub-module of SoC FPGA USB3.1 XHCI low level driver + */ + +#ifndef __XHCI_INTERRUPTS_H__ +#define __XHCI_INTERRUPTS_H__ + +#include + +/* Function pointer for tinyusb interrupt handler */ +typedef void (*tusb_int_ptr)(uint8_t rhport, bool in_isr); + +/* descriptor to pass to interrupt handler */ +struct xhci_int_desc +{ + tusb_int_ptr int_handler; /* !< pointer to tinyusb interrupt handler */ +}; + +typedef struct xhci_int_desc *xhci_int_ptr_t; +/* + * @brief enable xhci interrupts + */ +void enable_xhci_interrupts(void); + +/* + * @brief disable the xhci interrupts + */ +void disable_xhci_interrupts(void); + +/* + * @brief register USB3 ISR + * @param[in] int_handler - pointer to tinyusb interrupt handler + */ +bool register_usb3ISR(xhci_int_ptr_t int_handler); + +#endif /* __XHCI_INTERRUPTS_H__ */ diff --git a/src/portable/xhci/xhci_rings.c b/src/portable/xhci/xhci_rings.c new file mode 100644 index 000000000..274c12d44 --- /dev/null +++ b/src/portable/xhci/xhci_rings.c @@ -0,0 +1,260 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025-2026 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. + * Rings sub-module. + */ + +#include +#include "socfpga_cache.h" +#include "socfpga_defines.h" +#include "osal_log.h" +#include "xhci.h" + +/*************************************************************************************************/ +/* xHCI Rings */ +/*************************************************************************************************/ +/* + * xHCI rings are implemented with the help of TRB ( Transfer Request Block ). A TRB is the + * basic data storage unit of the xhci controller. TRB is owned either by the producer/consumer. + * The producer is responsible for creating a TRB, while consumer is responsible for the + * consumption of the trb. + * + * xHCI rings are classified as : + * + * -> Command Ring + * Command ring is used to send any xHCI specific commands to the controller. Here, the + * SW is the producer and xHCI is the consumer. + * -> Event Ring + * xHCI reports the status of all the events via the event ring. SW is the consumer of + * this ring. + * -> Transfer Ring + * Transfer rings are associated with endpoints to carry out transfers. + */ + +int xhci_crcr_init(xcr_command_ring_t *xcr_ring) +{ + uint32_t crcr_write_val; + int ret; + + xcr_ring->xcr_dequeue_ptr = allocate_ring_segment(64, XHCI_CR_TRB_LEN); + if (xcr_ring->xcr_dequeue_ptr == NULL) + { + return -ENOMEM; + } + + /* memory alignment check */ + ret = is_ptr_mem_aligned((uint64_t)xcr_ring->xcr_dequeue_ptr, 64U); + if (ret != 0) + { + if (xcr_ring->xcr_dequeue_ptr != NULL) + { + vPortFree(xcr_ring->xcr_dequeue_ptr); + } + return ret; + } + + xcr_ring->xcr_enqueue_ptr = xcr_ring->xcr_dequeue_ptr; + xcr_ring->xcr_ccs_flag = XHCI_CR_CCS_FLAG; + + crcr_write_val = (((uint32_t)(uintptr_t) xcr_ring->xcr_dequeue_ptr) & + USB3_CRCR_LO_CMD_RING_PNTR_MASK); + crcr_write_val |= (xcr_ring->xcr_ccs_flag); + + WR_REG32((USBBASE + USB3_CRCR_LO), crcr_write_val); + INFO("Command Ring Register updated"); + + return 0; +} + +int init_xhc_event_ring(struct xhci_data *xhci_ptr) +{ + int ret; + uint64_t ring_addr; + uint64_t erdp_reg_val; + uint64_t rt_base_addr; + + uint32_t reg_val; + xer_event_ring_t *xer_ring; + + xer_ring = &xhci_ptr->xer_ring; + + rt_base_addr = xhci_ptr->op_regs.xhci_runtime_base; + + reg_val = RD_REG32((rt_base_addr + USB3_ERSTSZ)); + reg_val &= ~(USB3_ERSTSZ_ERS_TABLE_SIZE_MASK); + reg_val |= XHCI_EVENT_RING_TABLE_SZ; + WR_REG32((rt_base_addr + USB3_ERSTSZ), reg_val); + + xer_ring->erst_ptr = (xhci_erst_entry_t *)(uintptr_t) pvPortAlignedAlloc(64, + 1U * sizeof(xhci_erst_entry_t)); + if (xer_ring->erst_ptr == NULL) + { + ERROR("Canot allocate memory!!!"); + return -ENOMEM; + } + + ret = is_ptr_mem_aligned((uint64_t)xer_ring->erst_ptr, 64U); + if (ret != 0) + { + ERROR("Memory alignment error!!!"); + if (xer_ring->erst_ptr != NULL) + { + vPortFree(xer_ring->erst_ptr); + } + return ret; + } + + bzero(xer_ring->erst_ptr, sizeof(xhci_erst_entry_t)); + + xer_ring->xer_enqueue_ptr = (xhci_trb_t *)(uintptr_t) pvPortAlignedAlloc(64, + XHCI_EVENT_RING_SEG_LENGTH * sizeof(xhci_trb_t)); + + if (xer_ring->xer_enqueue_ptr == NULL) + { + ERROR("Canot allocate memory!!!"); + return -ENOMEM; + } + + /* memory alignment check */ + ret = is_ptr_mem_aligned((uint64_t)xer_ring->xer_enqueue_ptr, 64U); + if (ret != 0) + { + ERROR("Memory alignment error!!!"); + if (xer_ring->xer_enqueue_ptr != NULL) + { + vPortFree(xer_ring->xer_enqueue_ptr); + } + return ret; + } + bzero(xer_ring->xer_enqueue_ptr, + XHCI_EVENT_RING_SEG_LENGTH * sizeof(xhci_trb_t)); + + xer_ring->trb_count = XHCI_EVENT_RING_SEG_LENGTH; + + xer_ring->erst_ptr->seg_addr = (uint64_t)xer_ring->xer_enqueue_ptr; + /* number of trbs in the segment */ + xer_ring->erst_ptr->seg_size = XHCI_EVENT_RING_SEG_LENGTH; + xer_ring->erst_ptr->rsvd = 0U; + + ring_addr = (uint64_t)xer_ring->erst_ptr; + reg_val = RD_REG32((rt_base_addr + USB3_ERSTBA_LO)); + reg_val |= (uint32_t) (ring_addr & ~(0x3fUL)); + WR_REG64((rt_base_addr + USB3_ERSTBA_LO), reg_val); + + ring_addr = (uint64_t) (xer_ring->xer_enqueue_ptr); + erdp_reg_val = RD_REG32((rt_base_addr + USB3_ERDP_LO)); + erdp_reg_val &= ~(USB3_ERDP_LO_ERD_PNTR_MASK); + erdp_reg_val |= ring_addr; + WR_REG64((rt_base_addr + USB3_ERDP_LO), erdp_reg_val); + + cache_force_write_back((void *)(uintptr_t) xer_ring->erst_ptr, + sizeof(xhci_erst_entry_t)); + cache_force_write_back((void *)(uintptr_t) xer_ring->xer_enqueue_ptr, + XHCI_EVENT_RING_SEG_LENGTH * sizeof(xhci_trb_t)); + + INFO("Event Ring configured successfully"); + return 0; +} + +xhci_trb_t *allocate_ring_segment(int req_byte_align, int req_trb_len) +{ + int ret; + xhci_trb_t *xtr = NULL; + xhci_trb_t *link_trb; + uint32_t ring_ctrl_flags = 0U; + + xtr = (xhci_trb_t *)pvPortAlignedAlloc(req_byte_align, + (size_t)req_trb_len * sizeof(xhci_trb_t)); + if (xtr == NULL) + { + ERROR("Cannot allocate memory!!!"); + return NULL; + } + + bzero(xtr, (size_t)req_trb_len * sizeof(xhci_trb_t)); + + /* memory alignment check */ + ret = is_ptr_mem_aligned((uint64_t)xtr, (uint32_t)req_byte_align); + if (ret != 0) + { + ERROR("Memory alignment error!!!"); + if (xtr != NULL) + { + vPortFree(xtr); + } + return NULL; + } + + link_trb = xtr + req_trb_len - 1; + + /* link trb points to the first trb of the ring */ + link_trb->buffer = (uint64_t)(uintptr_t)xtr; + link_trb->status = 0U; + + ring_ctrl_flags |= (1U << 1); + ring_ctrl_flags |= ((uint32_t) LINK_TRB << 10); + link_trb->control = ring_ctrl_flags; + + cache_force_write_back(xtr, (size_t) req_trb_len * sizeof(xhci_trb_t)); + + return xtr; +} + +xcr_command_ring_t *alloc_command_ring(void) +{ + xcr_command_ring_t *xcr_ring; + xcr_ring = (xcr_command_ring_t *)malloc(sizeof(xcr_command_ring_t)); + if (xcr_ring == NULL) + { + ERROR("Canot allocate memory!!!"); + return NULL; + } + return xcr_ring; +} + +int is_link_trb(xhci_trb_t *ptr) +{ + uint32_t trb_id; + + trb_id = (ptr->control & 0xfc00U) >> 10; + + if (trb_id == LINK_TRB) + { + return 1; + } + + return 0; +} + +xhci_trb_t *get_next_trb_segment(xhci_trb_t *ptr, uint8_t *pcs_flag) +{ + uint32_t link_ctrl = 0U; + xhci_trb_t *next_seg_trb_ptr = NULL; + + xhci_trb_t *link_trb = ptr; + + link_ctrl = link_trb->control; + link_ctrl &= ~(0x00000001U); + link_ctrl |= (*pcs_flag); + + link_trb->control = link_ctrl; + cache_force_write_back((void *)(uintptr_t) link_trb, sizeof(xhci_trb_t)); + + if ((link_trb->control & 0x00000002U) != 0U) + { + if (*pcs_flag != 0U) + { + *pcs_flag = 0U; + } + else + { + *pcs_flag = 1U; + } + } + next_seg_trb_ptr = (xhci_trb_t *)link_trb->buffer; + + return next_seg_trb_ptr; +} diff --git a/src/portable/xhci/xhci_rings.h b/src/portable/xhci/xhci_rings.h new file mode 100644 index 000000000..f1ed115f9 --- /dev/null +++ b/src/portable/xhci/xhci_rings.h @@ -0,0 +1,122 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for Rings sub-module of SoC FPGA USB3.1 XHCI low level driver + */ + +#ifndef __XHCI_RINGS_H__ +#define __XHCI_RINGS_H__ + +#include +#include + +#define XHCI_EVENT_RING_TABLE_SZ 1U +#define ERDP 0x11001038U +#define PORTSC 0x11000420U + +/* + * @struct xhci_trb_t + * @brief basic transfer request block for xhci controller + * @note refer to section 4.11.11 of xhci document + */ +typedef struct __attribute__ ((packed)){ + uint64_t buffer; /*!< Bits 0-63: TRB-specific parameters (e.g., buffer pointer, device address, etc.) */ + uint32_t status; /*!< Bits 64-95: Status information (e.g., transfer length, completion code, etc.)*/ + uint32_t control; /*!< Bits 96-127: TRB type, flags, and Cycle Bit */ +} xhci_trb_t; + +/* + *@struct xhci_event_segment_t + *@brief Event ring segment table + */ +typedef struct __attribute__ ((packed)) { + uint64_t xes_addr; /*!< store the address of event ring segment */ + uint16_t xes_size; /*!< number of TRB supported by the ring */ + uint16_t xes_rsvd0; + uint32_t xes_rsvd1; +} xhci_event_segment_t; + +/* + *@struct xcr_command_ring_t + *@brief Command Ring for xhci + */ +typedef struct __attribute__ ((packed)) +{ + xhci_trb_t *xcr_enqueue_ptr; /* !< xhci command ring enqueue pointer*/ + xhci_trb_t *xcr_dequeue_ptr; /* !< xhci command ring dequeue pointer*/ + uint8_t xcr_ccs_flag; /* !< xhci command ring consumer cycle state flag*/ + +} xcr_command_ring_t; + +/* + * @struct xhci_erst_entry_t + * @brief Event Ring Segment table Entry ( ERST) + */ +typedef struct __attribute__ ((packed)) +{ + uint64_t seg_addr; /* !< xhci event ring segment address*/ + uint32_t seg_size; /* !< xhci event ring segment size */ + uint32_t rsvd; /* reserved */ +} xhci_erst_entry_t; + +/* + * @struct xer_event_ring_t + * @brief xhci event ring + */ +typedef struct __attribute__ ((packed)) +{ + uint32_t trb_count; /*!< Number of trbs in the event ring */ + xhci_trb_t *xer_enqueue_ptr; /*!< xhci event ring enqueue pointer*/ + xhci_erst_entry_t *erst_ptr; /* !< reference to xhci event ring segment table */ + +} xer_event_ring_t; + + +/* XHCI operational register APIS */ + +/** + * @brief initialize XHCI command ring + * @params[in] xcr_ring reference to XHCI command ring structure + * @return + * 0 on successful command ring initialisation + * errno on failure + */ +int xhci_crcr_init(xcr_command_ring_t *xcr_ring); + +/** + * @brief allocate ring segment for command/transfer/events rings + * @param[in] req_byte_align alignment of the trb + * @param[in] req_trb_len length of the trb ring + * @return + * xhci_trb_t* reference to Transfer ring structure + * NULL, if allocation is unsuccessful + */ +xhci_trb_t *allocate_ring_segment(int req_byte_align, int req_trb_len); + +/** + * @brief allocate xhci command ring structure + * @return + * xcr_command_ring_t* reference to command ring structure + */ +xcr_command_ring_t *alloc_command_ring(void); + +/** + * @brief check whether the trb is a link trb or not + * @params[in] ptr reference to a trb structure + * @return + * 1 - if it is a link trb + * 0 - if it is not a link trb + */ +int is_link_trb(xhci_trb_t *ptr); + +/** + * @brief find the next segment of the transfer ring/command ring + * @param[in] ptr reference to current trb segment + * @param[in] pcs_flag reference to current segment pcs flag + * @return xhci_trb_t* reference to new trb segment + */ +xhci_trb_t *get_next_trb_segment(xhci_trb_t *ptr, uint8_t *pcs_flag); + +#endif /* __XHCI_RINGS_H__ */ From 427a955c99d3b102ba68831234692ac97595033c Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Fri, 13 Nov 2026 16:01:19 +0530 Subject: [PATCH 02/17] bitfileds for DWC3 register map Signed-off-by: Sourav Raj K K --- src/portable/synopsys/dwc3/dwc3_type.h | 1892 ++++++++++++++++++++++++ 1 file changed, 1892 insertions(+) create mode 100644 src/portable/synopsys/dwc3/dwc3_type.h diff --git a/src/portable/synopsys/dwc3/dwc3_type.h b/src/portable/synopsys/dwc3/dwc3_type.h new file mode 100644 index 000000000..172a7d3ae --- /dev/null +++ b/src/portable/synopsys/dwc3/dwc3_type.h @@ -0,0 +1,1892 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025-2026 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Agilex 5 DWC3 global register bitfields and register map. + * Field positions follow the Agilex 5 HPS register map. + */ + +#ifndef TYPE_H_ +#define TYPE_H_ + +#include +#include +#include "tusb_compiler.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Bit positions for GSBUSCFG0. */ +#define GSBUSCFG0_INCRBRSTENA_POS 0U +#define GSBUSCFG0_INCR4BRSTENA_POS 1U +#define GSBUSCFG0_INCR8BRSTENA_POS 2U +#define GSBUSCFG0_INCR16BRSTENA_POS 3U +#define GSBUSCFG0_INCR32BRSTENA_POS 4U +#define GSBUSCFG0_INCR64BRSTENA_POS 5U +#define GSBUSCFG0_INCR128BRSTENA_POS 6U +#define GSBUSCFG0_INCR256BRSTENA_POS 7U +#define GSBUSCFG0_RESERVED_9_8_POS 8U +#define GSBUSCFG0_DESBIGEND_POS 10U +#define GSBUSCFG0_DATBIGEND_POS 11U +#define GSBUSCFG0_RESERVED_15_12_POS 12U +#define GSBUSCFG0_DESWRREQINFO_POS 16U +#define GSBUSCFG0_DATWRREQINFO_POS 20U +#define GSBUSCFG0_DESRDREQINFO_POS 24U +#define GSBUSCFG0_DATRDREQINFO_POS 28U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t incrbrstena : 1; // 0 + uint32_t incr4_brstena : 1; // 1 + uint32_t incr8_brstena : 1; // 2 + uint32_t incr16_brstena : 1; // 3 + uint32_t incr32_brstena : 1; // 4 + uint32_t incr64_brstena : 1; // 5 + uint32_t incr128_brstena : 1; // 6 + uint32_t incr256_brstena : 1; // 7 + uint32_t reserved_9_8 : 2; // 8..9 + uint32_t desbigend : 1; // 10 + uint32_t datbigend : 1; // 11 + uint32_t reserved_15_12 : 4; // 12..15 + uint32_t deswrreqinfo : 4; // 16..19 + uint32_t datwrreqinfo : 4; // 20..23 + uint32_t desrdreqinfo : 4; // 24..27 + uint32_t datrdreqinfo : 4; // 28..31 + }; +} dwc3_gsbuscfg0_t; +TU_VERIFY_STATIC(sizeof(dwc3_gsbuscfg0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GSBUSCFG1. */ +#define GSBUSCFG1_RESERVED_7_0_POS 0U +#define GSBUSCFG1_PIPETRANSLIMIT_POS 8U +#define GSBUSCFG1_EN1KPAGE_POS 12U +#define GSBUSCFG1_EXTDPIPETRANSLIMIT_POS 13U +#define GSBUSCFG1_RESERVED_31_17_POS 17U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_7_0 : 8; // 0..7 + uint32_t pipe_trans_limit : 4; // 8..11 + uint32_t en1_kpage : 1; // 12 + uint32_t extd_pipe_trans_limit : 4; // 13..16 + uint32_t reserved_31_17 : 15; // 17..31 + }; +} dwc3_gsbuscfg1_t; +TU_VERIFY_STATIC(sizeof(dwc3_gsbuscfg1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXTHRCFG. */ +#define GTXTHRCFG_USBMAXTXBURSTSIZE_PRD_POS 0U +#define GTXTHRCFG_USBTXTHRNUMPKT_PRD_POS 5U +#define GTXTHRCFG_USBTXTHRNUMPKTSEL_PRD_POS 10U +#define GTXTHRCFG_RESERVED_12_11_POS 11U +#define GTXTHRCFG_USBTXTHRNUMPKT_HS_PRD_POS 13U +#define GTXTHRCFG_USBTXTHRNUMPKTSEL_HS_PRD_POS 15U +#define GTXTHRCFG_USBMAXTXBURSTSIZE_POS 16U +#define GTXTHRCFG_USBTXPKTCNT_POS 21U +#define GTXTHRCFG_USBTXPKTCNTSEL_POS 26U +#define GTXTHRCFG_RESERVED_31_27_POS 27U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t usb_max_tx_burst_size_prd : 5; // 0..4 + uint32_t usb_tx_thr_num_pkt_prd : 5; // 5..9 + uint32_t usb_tx_thr_num_pkt_sel_prd : 1; // 10 + uint32_t reserved_12_11 : 2; // 11..12 + uint32_t usb_tx_thr_num_pkt_hs_prd : 2; // 13..14 + uint32_t usb_tx_thr_num_pkt_sel_hs_prd : 1; // 15 + uint32_t usb_max_tx_burst_size : 5; // 16..20 + uint32_t usb_tx_pkt_cnt : 5; // 21..25 + uint32_t usb_tx_pkt_cnt_sel : 1; // 26 + uint32_t reserved_31_27 : 5; // 27..31 + }; +} dwc3_gtxthrcfg_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxthrcfg_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GRXTHRCFG. */ +#define GRXTHRCFG_USBMAXRXBURSTSIZE_PRD_POS 0U +#define GRXTHRCFG_USBRXTHRNUMPKT_PRD_POS 5U +#define GRXTHRCFG_USBRXTHRNUMPKTSEL_PRD_POS 10U +#define GRXTHRCFG_RESERVED_12_11_POS 11U +#define GRXTHRCFG_USBRXTHRNUMPKT_HS_PRD_POS 13U +#define GRXTHRCFG_USBRXTHRNUMPKTSEL_HS_PRD_POS 15U +#define GRXTHRCFG_USBMAXRXBURSTSIZE_POS 16U +#define GRXTHRCFG_USBRXPKTCNT_POS 21U +#define GRXTHRCFG_USBRXPKTCNTSEL_POS 26U +#define GRXTHRCFG_RESERVED_31_27_POS 27U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t usb_max_rx_burst_size_prd : 5; // 0..4 + uint32_t usb_rx_thr_num_pkt_prd : 5; // 5..9 + uint32_t usb_rx_thr_num_pkt_sel_prd : 1; // 10 + uint32_t reserved_12_11 : 2; // 11..12 + uint32_t usb_rx_thr_num_pkt_hs_prd : 2; // 13..14 + uint32_t usb_rx_thr_num_pkt_sel_hs_prd : 1; // 15 + uint32_t usb_max_rx_burst_size : 5; // 16..20 + uint32_t usb_rx_pkt_cnt : 5; // 21..25 + uint32_t usb_rx_pkt_cnt_sel : 1; // 26 + uint32_t reserved_31_27 : 5; // 27..31 + }; +} dwc3_grxthrcfg_t; +TU_VERIFY_STATIC(sizeof(dwc3_grxthrcfg_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GCTL. */ +#define GCTL_DSBLCLKGTNG_POS 0U +#define GCTL_GBLHIBERNATIONEN_POS 1U +#define GCTL_U2EXIT_LFPS_POS 2U +#define GCTL_DISSCRAMBLE_POS 3U +#define GCTL_SCALEDOWN_POS 4U +#define GCTL_RAMCLKSEL_POS 6U +#define GCTL_DEBUGATTACH_POS 8U +#define GCTL_U1U2TIMERSCALE_POS 9U +#define GCTL_RESERVED_10_POS 10U +#define GCTL_CORESOFTRESET_POS 11U +#define GCTL_PRTCAPDIR_POS 12U +#define GCTL_FRMSCLDWN_POS 14U +#define GCTL_U2RSTECN_POS 16U +#define GCTL_BYPSSETADDR_POS 17U +#define GCTL_MASTERFILTBYPASS_POS 18U +#define GCTL_PWRDNSCALE_POS 19U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t dsblclkgtng : 1; // 0 + uint32_t gbl_hibernation_en : 1; // 1 + uint32_t u2_exit_lfps : 1; // 2 + uint32_t disscramble : 1; // 3 + uint32_t scaledown : 2; // 4..5 + uint32_t ramclksel : 2; // 6..7 + uint32_t debugattach : 1; // 8 + uint32_t u1_u2_timer_scale : 1; // 9 + uint32_t reserved_10 : 1; // 10 + uint32_t coresoftreset : 1; // 11 + uint32_t prtcapdir : 2; // 12..13 + uint32_t frmscldwn : 2; // 14..15 + uint32_t u2_rstecn : 1; // 16 + uint32_t bypssetaddr : 1; // 17 + uint32_t masterfiltbypass : 1; // 18 + uint32_t pwrdnscale : 13; // 19..31 + }; +} dwc3_gctl_t; +TU_VERIFY_STATIC(sizeof(dwc3_gctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GPMSTS. */ +#define GPMSTS_U2WAKEUP_POS 0U +#define GPMSTS_RESERVED_11_10_POS 10U +#define GPMSTS_U3WAKEUP_POS 12U +#define GPMSTS_RESERVED_27_17_POS 17U +#define GPMSTS_PORTSEL_POS 28U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t u2_wakeup : 10; // 0..9 + uint32_t reserved_11_10 : 2; // 10..11 + uint32_t u3_wakeup : 5; // 12..16 + uint32_t reserved_27_17 : 11; // 17..27 + uint32_t port_sel : 4; // 28..31 + }; +} dwc3_gpmsts_t; +TU_VERIFY_STATIC(sizeof(dwc3_gpmsts_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GSTS. */ +#define GSTS_CURMOD_POS 0U +#define GSTS_RESERVED_3_2_POS 2U +#define GSTS_BUSERRADDRVLD_POS 4U +#define GSTS_CSRTIMEOUT_POS 5U +#define GSTS_DEVICE_IP_POS 6U +#define GSTS_HOST_IP_POS 7U +#define GSTS_RESERVED_11_8_POS 8U +#define GSTS_RESERVED_19_12_POS 12U +#define GSTS_CBELT_POS 20U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t curmod : 2; // 0..1 + uint32_t reserved_3_2 : 2; // 2..3 + uint32_t buserraddrvld : 1; // 4 + uint32_t csr_timeout : 1; // 5 + uint32_t device_ip : 1; // 6 + uint32_t host_ip : 1; // 7 + uint32_t reserved_11_8 : 4; // 8..11 + uint32_t reserved_19_12 : 8; // 12..19 + uint32_t cbelt : 12; // 20..31 + }; +} dwc3_gsts_t; +TU_VERIFY_STATIC(sizeof(dwc3_gsts_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUCTL1. */ +#define GUCTL1_LOA_FILTER_EN_POS 0U +#define GUCTL1_RESERVED_1_POS 1U +#define GUCTL1_HC_PARCHK_DISABLE_POS 2U +#define GUCTL1_HC_ERRATA_ENABLE_POS 3U +#define GUCTL1_L1_SUSP_THRLD_FOR_HOST_POS 4U +#define GUCTL1_L1_SUSP_THRLD_EN_FOR_HOST_POS 8U +#define GUCTL1_RESERVED_9_POS 9U +#define GUCTL1_RESUME_OPMODE_HS_HOST_POS 10U +#define GUCTL1_DISREFCLKGTNG_POS 11U +#define GUCTL1_DISUSB2REFCLKGTNG_POS 12U +#define GUCTL1_HW_LPM_HLE_DISABLE_POS 13U +#define GUCTL1_HW_LPM_CAP_DISABLE_POS 14U +#define GUCTL1_RESERVED_19_15_POS 15U +#define GUCTL1_RESERVED_20_POS 20U +#define GUCTL1_IP_GAP_ADD_ON_POS 21U +#define GUCTL1_DEV_L1_EXIT_BY_HW_POS 24U +#define GUCTL1_RESERVED_25_POS 25U +#define GUCTL1_RESERVED_26_POS 26U +#define GUCTL1_DEV_TRB_OUT_SPR_IND_POS 27U +#define GUCTL1_TX_IPGAP_LINECHECK_DIS_POS 28U +#define GUCTL1_FILTER_SE0_FSLS_EOP_POS 29U +#define GUCTL1_DS_RXDET_MAX_TOUT_CTRL_POS 30U +#define GUCTL1_DEV_DECOUPLE_L1L2_EVT_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t loa_filter_en : 1; // 0 + uint32_t reserved_1 : 1; // 1 + uint32_t hc_parchk_disable : 1; // 2 + uint32_t hc_errata_enable : 1; // 3 + uint32_t l1_susp_thrld_for_host : 4; // 4..7 + uint32_t l1_susp_thrld_en_for_host : 1; // 8 + uint32_t reserved_9 : 1; // 9 + uint32_t resume_opmode_hs_host : 1; // 10 + uint32_t dis_ref_clk_gtng : 1; // 11 + uint32_t dis_usb2_ref_clk_gtng : 1; // 12 + uint32_t hw_lpm_hle_disable : 1; // 13 + uint32_t hw_lpm_cap_disable : 1; // 14 + uint32_t reserved_19_15 : 5; // 15..19 + uint32_t reserved_20 : 1; // 20 + uint32_t ip_gap_add_on : 3; // 21..23 + uint32_t dev_l1_exit_by_hw : 1; // 24 + uint32_t reserved_25 : 1; // 25 + uint32_t reserved_26 : 1; // 26 + uint32_t dev_trb_out_spr_ind : 1; // 27 + uint32_t tx_ipgap_linecheck_dis : 1; // 28 + uint32_t filter_se0_fsls_eop : 1; // 29 + uint32_t ds_rxdet_max_tout_ctrl : 1; // 30 + uint32_t dev_decouple_l1_l2_evt : 1; // 31 + }; +} dwc3_guctl1_t; +TU_VERIFY_STATIC(sizeof(dwc3_guctl1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for USB31_IP_NAME. */ +#define USB31_IP_NAME_SYNOPSYSIP_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t synopsysip : 32; // 0..31 + }; +} dwc3_usb31_ip_name_t; +TU_VERIFY_STATIC(sizeof(dwc3_usb31_ip_name_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GGPIO. */ +#define GGPIO_GPI_POS 0U +#define GGPIO_GPO_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gpi : 16; // 0..15 + uint32_t gpo : 16; // 16..31 + }; +} dwc3_ggpio_t; +TU_VERIFY_STATIC(sizeof(dwc3_ggpio_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUID. */ +#define GUID_USERID_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t userid : 32; // 0..31 + }; +} dwc3_guid_t; +TU_VERIFY_STATIC(sizeof(dwc3_guid_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUCTL. */ +#define GUCTL_DTOUT_POS 0U +#define GUCTL_INSRTEXTRFSBODI_POS 11U +#define GUCTL_EXTCAPSUPPTEN_POS 12U +#define GUCTL_RESERVED_13_POS 13U +#define GUCTL_USBHSTINIMMRETRYEN_POS 14U +#define GUCTL_RESERVED_15_POS 15U +#define GUCTL_RESBWHSEPS_POS 16U +#define GUCTL_SPRSCTRLTRANSEN_POS 17U +#define GUCTL_EN_EXTD_TBC_CAP_POS 18U +#define GUCTL_IGNOREHCETIMEOUT_POS 19U +#define GUCTL_DMAIGNOREHCE_POS 20U +#define GUCTL_NOEXTRDL_POS 21U +#define GUCTL_REFCLKPER_POS 22U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t dtout : 11; // 0..10 + uint32_t insrt_extr_fsbodi : 1; // 11 + uint32_t ext_cap_suppt_en : 1; // 12 + uint32_t reserved_13 : 1; // 13 + uint32_t usb_hst_in_imm_retry_en : 1; // 14 + uint32_t reserved_15 : 1; // 15 + uint32_t res_bw_hseps : 1; // 16 + uint32_t sprs_ctrl_trans_en : 1; // 17 + uint32_t en_extd_tbc_cap : 1; // 18 + uint32_t ignore_hce_timeout : 1; // 19 + uint32_t dma_ignore_hce : 1; // 20 + uint32_t no_extr_dl : 1; // 21 + uint32_t refclkper : 10; // 22..31 + }; +} dwc3_guctl_t; +TU_VERIFY_STATIC(sizeof(dwc3_guctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GBUSERRADDRLO. */ +#define GBUSERRADDRLO_BUSERRADDR_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t buserraddr : 32; // 0..31 + }; +} dwc3_gbuserraddrlo_t; +TU_VERIFY_STATIC(sizeof(dwc3_gbuserraddrlo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GBUSERRADDRHI. */ +#define GBUSERRADDRHI_BUSERRADDR_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t buserraddr : 32; // 0..31 + }; +} dwc3_gbuserraddrhi_t; +TU_VERIFY_STATIC(sizeof(dwc3_gbuserraddrhi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GPRTBIMAPLO. */ +#define GPRTBIMAPLO_BINUM1_POS 0U +#define GPRTBIMAPLO_BINUM2_POS 4U +#define GPRTBIMAPLO_BINUM3_POS 8U +#define GPRTBIMAPLO_BINUM4_POS 12U +#define GPRTBIMAPLO_BINUM5_POS 16U +#define GPRTBIMAPLO_BINUM6_POS 20U +#define GPRTBIMAPLO_BINUM7_POS 24U +#define GPRTBIMAPLO_BINUM8_POS 28U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum1 : 4; // 0..3 + uint32_t binum2 : 4; // 4..7 + uint32_t binum3 : 4; // 8..11 + uint32_t binum4 : 4; // 12..15 + uint32_t binum5 : 4; // 16..19 + uint32_t binum6 : 4; // 20..23 + uint32_t binum7 : 4; // 24..27 + uint32_t binum8 : 4; // 28..31 + }; +} dwc3_gprtbimaplo_t; +TU_VERIFY_STATIC(sizeof(dwc3_gprtbimaplo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GPRTBIMAPHI. */ +#define GPRTBIMAPHI_BINUM9_POS 0U +#define GPRTBIMAPHI_BINUM10_POS 4U +#define GPRTBIMAPHI_BINUM11_POS 8U +#define GPRTBIMAPHI_BINUM12_POS 12U +#define GPRTBIMAPHI_BINUM13_POS 16U +#define GPRTBIMAPHI_BINUM14_POS 20U +#define GPRTBIMAPHI_BINUM15_POS 24U +#define GPRTBIMAPHI_RESERVED_31_28_POS 28U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum9 : 4; // 0..3 + uint32_t binum10 : 4; // 4..7 + uint32_t binum11 : 4; // 8..11 + uint32_t binum12 : 4; // 12..15 + uint32_t binum13 : 4; // 16..19 + uint32_t binum14 : 4; // 20..23 + uint32_t binum15 : 4; // 24..27 + uint32_t reserved_31_28 : 4; // 28..31 + }; +} dwc3_gprtbimaphi_t; +TU_VERIFY_STATIC(sizeof(dwc3_gprtbimaphi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GHWPARAMS0. */ +#define GHWPARAMS0_GHWPARAMS0_2_0_POS 0U +#define GHWPARAMS0_GHWPARAMS0_5_3_POS 3U +#define GHWPARAMS0_GHWPARAMS0_7_6_POS 6U +#define GHWPARAMS0_GHWPARAMS0_15_8_POS 8U +#define GHWPARAMS0_GHWPARAMS0_23_16_POS 16U +#define GHWPARAMS0_GHWPARAMS0_31_24_POS 24U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams0_2_0 : 3; // 0..2 + uint32_t ghwparams0_5_3 : 3; // 3..5 + uint32_t ghwparams0_7_6 : 2; // 6..7 + uint32_t ghwparams0_15_8 : 8; // 8..15 + uint32_t ghwparams0_23_16 : 8; // 16..23 + uint32_t ghwparams0_31_24 : 8; // 24..31 + }; +} dwc3_ghwparams0_t; +TU_VERIFY_STATIC(sizeof(dwc3_ghwparams0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GHWPARAMS1. */ +#define GHWPARAMS1_GHWPARAMS1_3_0_POS 0U +#define GHWPARAMS1_GHWPARAMS1_7_4_POS 4U +#define GHWPARAMS1_GHWPARAMS1_10_8_POS 8U +#define GHWPARAMS1_GHWPARAMS1_13_11_POS 11U +#define GHWPARAMS1_GHWPARAMS1_16_14_POS 14U +#define GHWPARAMS1_GHWPARAMS1_22_17_POS 17U +#define GHWPARAMS1_GHWPARAMS1_23_POS 23U +#define GHWPARAMS1_GHWPARAMS1_25_24_POS 24U +#define GHWPARAMS1_GHWPARAMS1_26_POS 26U +#define GHWPARAMS1_GHWPARAMS1_27_POS 27U +#define GHWPARAMS1_GHWPARAMS1_28_POS 28U +#define GHWPARAMS1_GHWPARAMS1_29_POS 29U +#define GHWPARAMS1_GHWPARAMS1_30_POS 30U +#define GHWPARAMS1_GHWPARAMS1_31_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams1_3_0 : 4; // 0..3 + uint32_t ghwparams1_7_4 : 4; // 4..7 + uint32_t ghwparams1_10_8 : 3; // 8..10 + uint32_t ghwparams1_13_11 : 3; // 11..13 + uint32_t ghwparams1_16_14 : 3; // 14..16 + uint32_t ghwparams1_22_17 : 6; // 17..22 + uint32_t ghwparams1_23 : 1; // 23 + uint32_t ghwparams1_25_24 : 2; // 24..25 + uint32_t ghwparams1_26 : 1; // 26 + uint32_t ghwparams1_27 : 1; // 27 + uint32_t ghwparams1_28 : 1; // 28 + uint32_t ghwparams1_29 : 1; // 29 + uint32_t ghwparams1_30 : 1; // 30 + uint32_t ghwparams1_31 : 1; // 31 + }; +} dwc3_ghwparams1_t; +TU_VERIFY_STATIC(sizeof(dwc3_ghwparams1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GHWPARAMS2. */ +#define GHWPARAMS2_GHWPARAMS2_31_0_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams2_31_0 : 32; // 0..31 + }; +} dwc3_ghwparams2_t; +TU_VERIFY_STATIC(sizeof(dwc3_ghwparams2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GHWPARAMS3. */ +#define GHWPARAMS3_GHWPARAMS3_1_0_POS 0U +#define GHWPARAMS3_GHWPARAMS3_3_2_POS 2U +#define GHWPARAMS3_GHWPARAMS3_5_4_POS 4U +#define GHWPARAMS3_GHWPARAMS3_7_6_POS 6U +#define GHWPARAMS3_GHWPARAMS3_9_8_POS 8U +#define GHWPARAMS3_GHWPARAMS3_10_POS 10U +#define GHWPARAMS3_GHWPARAMS3_11_POS 11U +#define GHWPARAMS3_GHWPARAMS3_17_12_POS 12U +#define GHWPARAMS3_GHWPARAMS3_22_18_POS 18U +#define GHWPARAMS3_GHWPARAMS3_30_23_POS 23U +#define GHWPARAMS3_GHWPARAMS3_31_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams3_1_0 : 2; // 0..1 + uint32_t ghwparams3_3_2 : 2; // 2..3 + uint32_t ghwparams3_5_4 : 2; // 4..5 + uint32_t ghwparams3_7_6 : 2; // 6..7 + uint32_t ghwparams3_9_8 : 2; // 8..9 + uint32_t ghwparams3_10 : 1; // 10 + uint32_t ghwparams3_11 : 1; // 11 + uint32_t ghwparams3_17_12 : 6; // 12..17 + uint32_t ghwparams3_22_18 : 5; // 18..22 + uint32_t ghwparams3_30_23 : 8; // 23..30 + uint32_t ghwparams3_31 : 1; // 31 + }; +} dwc3_ghwparams3_t; +TU_VERIFY_STATIC(sizeof(dwc3_ghwparams3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GHWPARAMS4. */ +#define GHWPARAMS4_GHWPARAMS4_5_0_POS 0U +#define GHWPARAMS4_GHWPARAMS4_12_6_POS 6U +#define GHWPARAMS4_GHWPARAMS4_16_13_POS 13U +#define GHWPARAMS4_GHWPARAMS4_20_17_POS 17U +#define GHWPARAMS4_GHWPARAMS4_21_POS 21U +#define GHWPARAMS4_GHWPARAMS4_22_POS 22U +#define GHWPARAMS4_GHWPARAMS4_27_23_POS 23U +#define GHWPARAMS4_GHWPARAMS4_31_28_POS 28U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams4_5_0 : 6; // 0..5 + uint32_t ghwparams4_12_6 : 7; // 6..12 + uint32_t ghwparams4_16_13 : 4; // 13..16 + uint32_t ghwparams4_20_17 : 4; // 17..20 + uint32_t ghwparams4_21 : 1; // 21 + uint32_t ghwparams4_22 : 1; // 22 + uint32_t ghwparams4_27_23 : 5; // 23..27 + uint32_t ghwparams4_31_28 : 4; // 28..31 + }; +} dwc3_ghwparams4_t; +TU_VERIFY_STATIC(sizeof(dwc3_ghwparams4_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GHWPARAMS5. */ +#define GHWPARAMS5_GHWPARAMS5_4_0_POS 0U +#define GHWPARAMS5_GHWPARAMS5_10_5_POS 5U +#define GHWPARAMS5_GHWPARAMS5_16_11_POS 11U +#define GHWPARAMS5_GHWPARAMS5_22_17_POS 17U +#define GHWPARAMS5_GHWPARAMS5_28_23_POS 23U +#define GHWPARAMS5_GHWPARAMS5_31_29_POS 29U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams5_4_0 : 5; // 0..4 + uint32_t ghwparams5_10_5 : 6; // 5..10 + uint32_t ghwparams5_16_11 : 6; // 11..16 + uint32_t ghwparams5_22_17 : 6; // 17..22 + uint32_t ghwparams5_28_23 : 6; // 23..28 + uint32_t ghwparams5_31_29 : 3; // 29..31 + }; +} dwc3_ghwparams5_t; +TU_VERIFY_STATIC(sizeof(dwc3_ghwparams5_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GHWPARAMS6. */ +#define GHWPARAMS6_GHWPARAMS6_5_0_POS 0U +#define GHWPARAMS6_GHWPARAMS6_6_POS 6U +#define GHWPARAMS6_GHWPARAMS6_7_POS 7U +#define GHWPARAMS6_GHWPARAMS6_9_8_POS 8U +#define GHWPARAMS6_GHWPARAMS6_14_10_POS 10U +#define GHWPARAMS6_BUSFLTRSSUPPORT_POS 15U +#define GHWPARAMS6_GHWPARAMS6_31_16_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams6_5_0 : 6; // 0..5 + uint32_t ghwparams6_6 : 1; // 6 + uint32_t ghwparams6_7 : 1; // 7 + uint32_t ghwparams6_9_8 : 2; // 8..9 + uint32_t ghwparams6_14_10 : 5; // 10..14 + uint32_t bus_fltrs_support : 1; // 15 + uint32_t ghwparams6_31_16 : 16; // 16..31 + }; +} dwc3_ghwparams6_t; +TU_VERIFY_STATIC(sizeof(dwc3_ghwparams6_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GHWPARAMS7. */ +#define GHWPARAMS7_GHWPARAMS7_15_0_POS 0U +#define GHWPARAMS7_GHWPARAMS7_31_16_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams7_15_0 : 16; // 0..15 + uint32_t ghwparams7_31_16 : 16; // 16..31 + }; +} dwc3_ghwparams7_t; +TU_VERIFY_STATIC(sizeof(dwc3_ghwparams7_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GDBGFIFOSPACE. */ +#define GDBGFIFOSPACE_FIFO_QUEUE_SELECT_POS 0U +#define GDBGFIFOSPACE_RESERVED_15_9_POS 9U +#define GDBGFIFOSPACE_SPACE_AVAILABLE_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t fifo_queue_select : 9; // 0..8 + uint32_t reserved_15_9 : 7; // 9..15 + uint32_t space_available : 16; // 16..31 + }; +} dwc3_gdbgfifospace_t; +TU_VERIFY_STATIC(sizeof(dwc3_gdbgfifospace_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GBMUCTL. */ +#define GBMUCTL_RESERVED_0_POS 0U +#define GBMUCTL_ACTIVE_ID_EN_POS 1U +#define GBMUCTL_AXI_STORDER_EN_POS 2U +#define GBMUCTL_RESERVED_4_3_POS 3U +#define GBMUCTL_SEPARATE_PSQ_EN_POS 5U +#define GBMUCTL_RESERVED_15_6_POS 6U +#define GBMUCTL_RESERVED_31_16_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_0 : 1; // 0 + uint32_t active_id_en : 1; // 1 + uint32_t axi_storder_en : 1; // 2 + uint32_t reserved_4_3 : 2; // 3..4 + uint32_t separate_psq_en : 1; // 5 + uint32_t reserved_15_6 : 10; // 6..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} dwc3_gbmuctl_t; +TU_VERIFY_STATIC(sizeof(dwc3_gbmuctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GDBGBMU. */ +#define GDBGBMU_BMU_CCU_POS 0U +#define GDBGBMU_BMU_DCU_POS 4U +#define GDBGBMU_BMU_BCU_POS 8U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t bmu_ccu : 4; // 0..3 + uint32_t bmu_dcu : 4; // 4..7 + uint32_t bmu_bcu : 24; // 8..31 + }; +} dwc3_gdbgbmu_t; +TU_VERIFY_STATIC(sizeof(dwc3_gdbgbmu_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GDBGLSPMUX. */ +#define GDBGLSPMUX_LSPSELECT_POS 0U +#define GDBGLSPMUX_RESERVED_15_POS 15U +#define GDBGLSPMUX_LOGIC_ANALYZER_TRACE_POS 16U +#define GDBGLSPMUX_RESERVED_31_24_POS 24U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lspselect : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t logic_analyzer_trace : 8; // 16..23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} dwc3_gdbglspmux_t; +TU_VERIFY_STATIC(sizeof(dwc3_gdbglspmux_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GDBGLSP. */ +#define GDBGLSP_LSPDEBUG_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lspdebug : 32; // 0..31 + }; +} dwc3_gdbglsp_t; +TU_VERIFY_STATIC(sizeof(dwc3_gdbglsp_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GDBGEPINFO0. */ +#define GDBGEPINFO0_EPDEBUG_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t epdebug : 32; // 0..31 + }; +} dwc3_gdbgepinfo0_t; +TU_VERIFY_STATIC(sizeof(dwc3_gdbgepinfo0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GDBGEPINFO1. */ +#define GDBGEPINFO1_EPDEBUG_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t epdebug : 32; // 0..31 + }; +} dwc3_gdbgepinfo1_t; +TU_VERIFY_STATIC(sizeof(dwc3_gdbgepinfo1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GPRTBIMAP_HSLO. */ +#define GPRTBIMAP_HSLO_BINUM1_POS 0U +#define GPRTBIMAP_HSLO_BINUM2_POS 4U +#define GPRTBIMAP_HSLO_BINUM3_POS 8U +#define GPRTBIMAP_HSLO_BINUM4_POS 12U +#define GPRTBIMAP_HSLO_BINUM5_POS 16U +#define GPRTBIMAP_HSLO_BINUM6_POS 20U +#define GPRTBIMAP_HSLO_BINUM7_POS 24U +#define GPRTBIMAP_HSLO_BINUM8_POS 28U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum1 : 4; // 0..3 + uint32_t binum2 : 4; // 4..7 + uint32_t binum3 : 4; // 8..11 + uint32_t binum4 : 4; // 12..15 + uint32_t binum5 : 4; // 16..19 + uint32_t binum6 : 4; // 20..23 + uint32_t binum7 : 4; // 24..27 + uint32_t binum8 : 4; // 28..31 + }; +} dwc3_gprtbimap_hslo_t; +TU_VERIFY_STATIC(sizeof(dwc3_gprtbimap_hslo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GPRTBIMAP_HSHI. */ +#define GPRTBIMAP_HSHI_BINUM9_POS 0U +#define GPRTBIMAP_HSHI_BINUM10_POS 4U +#define GPRTBIMAP_HSHI_BINUM11_POS 8U +#define GPRTBIMAP_HSHI_BINUM12_POS 12U +#define GPRTBIMAP_HSHI_BINUM13_POS 16U +#define GPRTBIMAP_HSHI_BINUM14_POS 20U +#define GPRTBIMAP_HSHI_BINUM15_POS 24U +#define GPRTBIMAP_HSHI_RESERVED_31_28_POS 28U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum9 : 4; // 0..3 + uint32_t binum10 : 4; // 4..7 + uint32_t binum11 : 4; // 8..11 + uint32_t binum12 : 4; // 12..15 + uint32_t binum13 : 4; // 16..19 + uint32_t binum14 : 4; // 20..23 + uint32_t binum15 : 4; // 24..27 + uint32_t reserved_31_28 : 4; // 28..31 + }; +} dwc3_gprtbimap_hshi_t; +TU_VERIFY_STATIC(sizeof(dwc3_gprtbimap_hshi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GPRTBIMAP_FSLO. */ +#define GPRTBIMAP_FSLO_BINUM1_POS 0U +#define GPRTBIMAP_FSLO_BINUM2_POS 4U +#define GPRTBIMAP_FSLO_BINUM3_POS 8U +#define GPRTBIMAP_FSLO_BINUM4_POS 12U +#define GPRTBIMAP_FSLO_BINUM5_POS 16U +#define GPRTBIMAP_FSLO_BINUM6_POS 20U +#define GPRTBIMAP_FSLO_BINUM7_POS 24U +#define GPRTBIMAP_FSLO_BINUM8_POS 28U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum1 : 4; // 0..3 + uint32_t binum2 : 4; // 4..7 + uint32_t binum3 : 4; // 8..11 + uint32_t binum4 : 4; // 12..15 + uint32_t binum5 : 4; // 16..19 + uint32_t binum6 : 4; // 20..23 + uint32_t binum7 : 4; // 24..27 + uint32_t binum8 : 4; // 28..31 + }; +} dwc3_gprtbimap_fslo_t; +TU_VERIFY_STATIC(sizeof(dwc3_gprtbimap_fslo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GPRTBIMAP_FSHI. */ +#define GPRTBIMAP_FSHI_BINUM9_POS 0U +#define GPRTBIMAP_FSHI_BINUM10_POS 4U +#define GPRTBIMAP_FSHI_BINUM11_POS 8U +#define GPRTBIMAP_FSHI_BINUM12_POS 12U +#define GPRTBIMAP_FSHI_BINUM13_POS 16U +#define GPRTBIMAP_FSHI_BINUM14_POS 20U +#define GPRTBIMAP_FSHI_BINUM15_POS 24U +#define GPRTBIMAP_FSHI_RESERVED_31_28_POS 28U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum9 : 4; // 0..3 + uint32_t binum10 : 4; // 4..7 + uint32_t binum11 : 4; // 8..11 + uint32_t binum12 : 4; // 12..15 + uint32_t binum13 : 4; // 16..19 + uint32_t binum14 : 4; // 20..23 + uint32_t binum15 : 4; // 24..27 + uint32_t reserved_31_28 : 4; // 28..31 + }; +} dwc3_gprtbimap_fshi_t; +TU_VERIFY_STATIC(sizeof(dwc3_gprtbimap_fshi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GHMSOCBWOR. */ +#define GHMSOCBWOR_OVRD_SOC_RD_UF_KB_BANDWIDTH_POS 0U +#define GHMSOCBWOR_OVRD_SOC_WR_UF_KB_BANDWIDTH_POS 15U +#define GHMSOCBWOR_OVRD_COMMON_SOC_RD_WR_POS 30U +#define GHMSOCBWOR_OVRD_PORT_SOC_BW_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ovrd_soc_rd_u_f_k_b_bandwidth : 15; // 0..14 + uint32_t ovrd_soc_wr_u_f_k_b_bandwidth : 15; // 15..29 + uint32_t ovrd_common_soc_rd_wr : 1; // 30 + uint32_t ovrd_port_soc_bw : 1; // 31 + }; +} dwc3_ghmsocbwor_t; +TU_VERIFY_STATIC(sizeof(dwc3_ghmsocbwor_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for USB31_VER_NUMBER. */ +#define USB31_VER_NUMBER_VERSION_NUM_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t version_num : 32; // 0..31 + }; +} dwc3_usb31_ver_number_t; +TU_VERIFY_STATIC(sizeof(dwc3_usb31_ver_number_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for USB31_VER_TYPE. */ +#define USB31_VER_TYPE_VERSIONTYPE_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t versiontype : 32; // 0..31 + }; +} dwc3_usb31_ver_type_t; +TU_VERIFY_STATIC(sizeof(dwc3_usb31_ver_type_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GSYSBLKWINCTRL. */ +#define GSYSBLKWINCTRL_BEGININING_NO_BLOCKING_TIME_POS 0U +#define GSYSBLKWINCTRL_END_NO_BLOCKING_TIME_POS 8U +#define GSYSBLKWINCTRL_RESERVED_23_16_POS 16U +#define GSYSBLKWINCTRL_ERST_PREFETCHING_WATERMARK_POS 24U +#define GSYSBLKWINCTRL_ERST_PREFETCHING_EN_POS 29U +#define GSYSBLKWINCTRL_DISABLE_NO_BLOCKING_WINDOW_POS 30U +#define GSYSBLKWINCTRL_SYS_BLOCKING_OK_ALL_THE_TIME_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t beginining_no_blocking_time : 8; // 0..7 + uint32_t end_no_blocking_time : 8; // 8..15 + uint32_t reserved_23_16 : 8; // 16..23 + uint32_t erst_prefetching_watermark : 5; // 24..28 + uint32_t erst_prefetching_en : 1; // 29 + uint32_t disable_no_blocking_window : 1; // 30 + uint32_t sys_blocking_ok_all_the_time : 1; // 31 + }; +} dwc3_gsysblkwinctrl_t; +TU_VERIFY_STATIC(sizeof(dwc3_gsysblkwinctrl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GPCIEL1EXTLAT. */ +#define GPCIEL1EXTLAT_PCIE_L1_EXIT_LATENCY_POS 0U +#define GPCIEL1EXTLAT_RESERVED_29_12_POS 12U +#define GPCIEL1EXTLAT_PCIE_L1_EXIT_MODE_CTRL_POS 30U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t pcie_l1_exit_latency : 12; // 0..11 + uint32_t reserved_29_12 : 18; // 12..29 + uint32_t pcie_l1_exit_mode_ctrl : 2; // 30..31 + }; +} dwc3_gpciel1_extlat_t; +TU_VERIFY_STATIC(sizeof(dwc3_gpciel1_extlat_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUSB2PHYCFG. */ +#define GUSB2PHYCFG_TOUTCAL_POS 0U +#define GUSB2PHYCFG_PHYIF_POS 3U +#define GUSB2PHYCFG_ULPI_UTMI_SEL_POS 4U +#define GUSB2PHYCFG_FSINTF_POS 5U +#define GUSB2PHYCFG_SUSPENDUSB20_POS 6U +#define GUSB2PHYCFG_PHYSEL_POS 7U +#define GUSB2PHYCFG_ENBLSLPM_POS 8U +#define GUSB2PHYCFG_XCVRDLY_POS 9U +#define GUSB2PHYCFG_USBTRDTIM_POS 10U +#define GUSB2PHYCFG_EUSB2OPMODE_POS 14U +#define GUSB2PHYCFG_ULPIAUTORES_POS 15U +#define GUSB2PHYCFG_RESERVED_16_POS 16U +#define GUSB2PHYCFG_ULPIEXTVBUSDRV_POS 17U +#define GUSB2PHYCFG_ULPIEXTVBUSINDIACTOR_POS 18U +#define GUSB2PHYCFG_LSIPD_POS 19U +#define GUSB2PHYCFG_LSTRD_POS 22U +#define GUSB2PHYCFG_OVRD_FSLS_DISC_TIME_POS 25U +#define GUSB2PHYCFG_INV_SEL_HSIC_POS 26U +#define GUSB2PHYCFG_HSIC_CON_WIDTH_ADJ_POS 27U +#define GUSB2PHYCFG_ULPI_LPM_WITH_OPMODE_CHK_POS 29U +#define GUSB2PHYCFG_RESERVED_30_POS 30U +#define GUSB2PHYCFG_PHYSOFTRST_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t t_out_cal : 3; // 0..2 + uint32_t phyif : 1; // 3 + uint32_t ulpi_utmi_sel : 1; // 4 + uint32_t fsintf : 1; // 5 + uint32_t suspendusb20 : 1; // 6 + uint32_t physel : 1; // 7 + uint32_t enblslpm : 1; // 8 + uint32_t xcvrdly : 1; // 9 + uint32_t usbtrdtim : 4; // 10..13 + uint32_t e_usb2_opmode : 1; // 14 + uint32_t ulpiautores : 1; // 15 + uint32_t reserved_16 : 1; // 16 + uint32_t ulpiextvbusdrv : 1; // 17 + uint32_t ulpiextvbusindiactor : 1; // 18 + uint32_t lsipd : 3; // 19..21 + uint32_t lstrd : 3; // 22..24 + uint32_t ovrd_fsls_disc_time : 1; // 25 + uint32_t inv_sel_hsic : 1; // 26 + uint32_t hsic_con_width_adj : 2; // 27..28 + uint32_t ulpi_lpm_with_opmode_chk : 1; // 29 + uint32_t reserved_30 : 1; // 30 + uint32_t physoftrst : 1; // 31 + }; +} dwc3_gusb2_phycfg_t; +TU_VERIFY_STATIC(sizeof(dwc3_gusb2_phycfg_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUSB2PHYACC_ULPI. */ +#define GUSB2PHYACC_ULPI_REGDATA_POS 0U +#define GUSB2PHYACC_ULPI_EXTREGADDR_POS 8U +#define GUSB2PHYACC_ULPI_REGADDR_POS 16U +#define GUSB2PHYACC_ULPI_REGWR_POS 22U +#define GUSB2PHYACC_ULPI_VSTSBSY_POS 23U +#define GUSB2PHYACC_ULPI_VSTSDONE_POS 24U +#define GUSB2PHYACC_ULPI_NEWREGREQ_POS 25U +#define GUSB2PHYACC_ULPI_DISUIPIDRVR_POS 26U +#define GUSB2PHYACC_ULPI_RESERVED_31_27_POS 27U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t regdata : 8; // 0..7 + uint32_t extregaddr : 8; // 8..15 + uint32_t regaddr : 6; // 16..21 + uint32_t regwr : 1; // 22 + uint32_t vstsbsy : 1; // 23 + uint32_t vstsdone : 1; // 24 + uint32_t newregreq : 1; // 25 + uint32_t disuipidrvr : 1; // 26 + uint32_t reserved_31_27 : 5; // 27..31 + }; +} dwc3_gusb2_phyacc_ulpi_t; +TU_VERIFY_STATIC(sizeof(dwc3_gusb2_phyacc_ulpi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUSB3PIPECTL. */ +#define GUSB3PIPECTL_ELASTIC_BUFFER_MODE_POS 0U +#define GUSB3PIPECTL_SS_TX_DE_EMPHASIS_POS 1U +#define GUSB3PIPECTL_TX_MARGIN_POS 3U +#define GUSB3PIPECTL_TX_SWING_POS 6U +#define GUSB3PIPECTL_RESERVED_7_POS 7U +#define GUSB3PIPECTL_RX_DETECT_TO_POLLING_LFPS_CONTROL_POS 8U +#define GUSB3PIPECTL_LFPSFILTER_POS 9U +#define GUSB3PIPECTL_P3EXSIGP2_POS 10U +#define GUSB3PIPECTL_P3P2TRANOK_POS 11U +#define GUSB3PIPECTL_LFPSP0ALGN_POS 12U +#define GUSB3PIPECTL_SKIPRXDET_POS 13U +#define GUSB3PIPECTL_ABORTRXDETINU2_POS 14U +#define GUSB3PIPECTL_DATWIDTH_POS 15U +#define GUSB3PIPECTL_SUSPENDENABLE_POS 17U +#define GUSB3PIPECTL_DELAYP1TRANS_POS 18U +#define GUSB3PIPECTL_DELAYP1P2P3_POS 19U +#define GUSB3PIPECTL_DISRXDETU3RXDET_POS 22U +#define GUSB3PIPECTL_STARTRXDETU3RXDET_POS 23U +#define GUSB3PIPECTL_REQUEST_P1P2P3_POS 24U +#define GUSB3PIPECTL_U1U2EXITFAIL_TO_RECOV_POS 25U +#define GUSB3PIPECTL_PING_ENHANCEMENT_EN_POS 26U +#define GUSB3PIPECTL_UX_EXIT_IN_PX_POS 27U +#define GUSB3PIPECTL_DISRXDETP3_POS 28U +#define GUSB3PIPECTL_U2P3OK_POS 29U +#define GUSB3PIPECTL_HSTPRTCMPL_POS 30U +#define GUSB3PIPECTL_PHYSOFTRST_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t elastic_buffer_mode : 1; // 0 + uint32_t ss_tx_de_emphasis : 2; // 1..2 + uint32_t tx_margin : 3; // 3..5 + uint32_t tx_swing : 1; // 6 + uint32_t reserved_7 : 1; // 7 + uint32_t rx_detect_to_polling_lfps_control : 1; // 8 + uint32_t lfpsfilter : 1; // 9 + uint32_t p3_ex_sig_p2 : 1; // 10 + uint32_t p3_p2_tran_ok : 1; // 11 + uint32_t lfpsp0_algn : 1; // 12 + uint32_t skip_rx_det : 1; // 13 + uint32_t abort_rx_det_in_u2 : 1; // 14 + uint32_t datwidth : 2; // 15..16 + uint32_t suspendenable : 1; // 17 + uint32_t delayp1_trans : 1; // 18 + uint32_t delay_p1_p2_p3 : 3; // 19..21 + uint32_t dis_rx_det_u3_rx_det : 1; // 22 + uint32_t start_rx_det_u3_rx_det : 1; // 23 + uint32_t request_p1p2p3 : 1; // 24 + uint32_t u1u2exitfail_to_recov : 1; // 25 + uint32_t ping_enhancement_en : 1; // 26 + uint32_t ux_exit_in_px : 1; // 27 + uint32_t dis_rx_det_p3 : 1; // 28 + uint32_t u2_p3ok : 1; // 29 + uint32_t hst_prt_cmpl : 1; // 30 + uint32_t phy_soft_rst : 1; // 31 + }; +} dwc3_gusb3_pipectl_t; +TU_VERIFY_STATIC(sizeof(dwc3_gusb3_pipectl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ0. */ +#define GTXFIFOSIZ0_TXFDEP_N_POS 0U +#define GTXFIFOSIZ0_RESERVED_15_POS 15U +#define GTXFIFOSIZ0_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz0_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ1. */ +#define GTXFIFOSIZ1_TXFDEP_N_POS 0U +#define GTXFIFOSIZ1_RESERVED_15_POS 15U +#define GTXFIFOSIZ1_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz1_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ2. */ +#define GTXFIFOSIZ2_TXFDEP_N_POS 0U +#define GTXFIFOSIZ2_RESERVED_15_POS 15U +#define GTXFIFOSIZ2_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz2_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ3. */ +#define GTXFIFOSIZ3_TXFDEP_N_POS 0U +#define GTXFIFOSIZ3_RESERVED_15_POS 15U +#define GTXFIFOSIZ3_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz3_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ4. */ +#define GTXFIFOSIZ4_TXFDEP_N_POS 0U +#define GTXFIFOSIZ4_RESERVED_15_POS 15U +#define GTXFIFOSIZ4_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz4_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz4_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ5. */ +#define GTXFIFOSIZ5_TXFDEP_N_POS 0U +#define GTXFIFOSIZ5_RESERVED_15_POS 15U +#define GTXFIFOSIZ5_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz5_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz5_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ6. */ +#define GTXFIFOSIZ6_TXFDEP_N_POS 0U +#define GTXFIFOSIZ6_RESERVED_15_POS 15U +#define GTXFIFOSIZ6_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz6_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz6_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ7. */ +#define GTXFIFOSIZ7_TXFDEP_N_POS 0U +#define GTXFIFOSIZ7_RESERVED_15_POS 15U +#define GTXFIFOSIZ7_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz7_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz7_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ8. */ +#define GTXFIFOSIZ8_TXFDEP_N_POS 0U +#define GTXFIFOSIZ8_RESERVED_15_POS 15U +#define GTXFIFOSIZ8_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz8_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz8_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ9. */ +#define GTXFIFOSIZ9_TXFDEP_N_POS 0U +#define GTXFIFOSIZ9_RESERVED_15_POS 15U +#define GTXFIFOSIZ9_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz9_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz9_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ10. */ +#define GTXFIFOSIZ10_TXFDEP_N_POS 0U +#define GTXFIFOSIZ10_RESERVED_15_POS 15U +#define GTXFIFOSIZ10_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz10_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz10_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ11. */ +#define GTXFIFOSIZ11_TXFDEP_N_POS 0U +#define GTXFIFOSIZ11_RESERVED_15_POS 15U +#define GTXFIFOSIZ11_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz11_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz11_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ12. */ +#define GTXFIFOSIZ12_TXFDEP_N_POS 0U +#define GTXFIFOSIZ12_RESERVED_15_POS 15U +#define GTXFIFOSIZ12_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz12_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz12_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ13. */ +#define GTXFIFOSIZ13_TXFDEP_N_POS 0U +#define GTXFIFOSIZ13_RESERVED_15_POS 15U +#define GTXFIFOSIZ13_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz13_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz13_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ14. */ +#define GTXFIFOSIZ14_TXFDEP_N_POS 0U +#define GTXFIFOSIZ14_RESERVED_15_POS 15U +#define GTXFIFOSIZ14_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz14_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz14_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOSIZ15. */ +#define GTXFIFOSIZ15_TXFDEP_N_POS 0U +#define GTXFIFOSIZ15_RESERVED_15_POS 15U +#define GTXFIFOSIZ15_TXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} dwc3_gtxfifosiz15_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifosiz15_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GRXFIFOSIZ0. */ +#define GRXFIFOSIZ0_RXFDEP_N_POS 0U +#define GRXFIFOSIZ0_RESERVED_15_POS 15U +#define GRXFIFOSIZ0_RXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} dwc3_grxfifosiz0_t; +TU_VERIFY_STATIC(sizeof(dwc3_grxfifosiz0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GRXFIFOSIZ1. */ +#define GRXFIFOSIZ1_RXFDEP_N_POS 0U +#define GRXFIFOSIZ1_RESERVED_15_POS 15U +#define GRXFIFOSIZ1_RXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} dwc3_grxfifosiz1_t; +TU_VERIFY_STATIC(sizeof(dwc3_grxfifosiz1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GRXFIFOSIZ2. */ +#define GRXFIFOSIZ2_RXFDEP_N_POS 0U +#define GRXFIFOSIZ2_RESERVED_15_POS 15U +#define GRXFIFOSIZ2_RXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} dwc3_grxfifosiz2_t; +TU_VERIFY_STATIC(sizeof(dwc3_grxfifosiz2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GRXFIFOSIZ3. */ +#define GRXFIFOSIZ3_RXFDEP_N_POS 0U +#define GRXFIFOSIZ3_RESERVED_15_POS 15U +#define GRXFIFOSIZ3_RXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} dwc3_grxfifosiz3_t; +TU_VERIFY_STATIC(sizeof(dwc3_grxfifosiz3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GRXFIFOSIZ4. */ +#define GRXFIFOSIZ4_RXFDEP_N_POS 0U +#define GRXFIFOSIZ4_RESERVED_15_POS 15U +#define GRXFIFOSIZ4_RXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} dwc3_grxfifosiz4_t; +TU_VERIFY_STATIC(sizeof(dwc3_grxfifosiz4_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GRXFIFOSIZ5. */ +#define GRXFIFOSIZ5_RXFDEP_N_POS 0U +#define GRXFIFOSIZ5_RESERVED_15_POS 15U +#define GRXFIFOSIZ5_RXFSTADDR_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} dwc3_grxfifosiz5_t; +TU_VERIFY_STATIC(sizeof(dwc3_grxfifosiz5_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GEVNTADRLO. */ +#define GEVNTADRLO_EVNTADRLO_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t evntadrlo : 32; // 0..31 + }; +} dwc3_gevntadrlo_t; +TU_VERIFY_STATIC(sizeof(dwc3_gevntadrlo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GEVNTADRHI. */ +#define GEVNTADRHI_EVNTADRHI_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t evntadrhi : 32; // 0..31 + }; +} dwc3_gevntadrhi_t; +TU_VERIFY_STATIC(sizeof(dwc3_gevntadrhi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GEVNTSIZ. */ +#define GEVNTSIZ_EVENTSIZ_POS 0U +#define GEVNTSIZ_RESERVED_30_16_POS 16U +#define GEVNTSIZ_EVNTINTRPTMASK_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t eventsiz : 16; // 0..15 + uint32_t reserved_30_16 : 15; // 16..30 + uint32_t evntintrptmask : 1; // 31 + }; +} dwc3_gevntsiz_t; +TU_VERIFY_STATIC(sizeof(dwc3_gevntsiz_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GEVNTCOUNT. */ +#define GEVNTCOUNT_EVNTCOUNT_POS 0U +#define GEVNTCOUNT_RESERVED_30_16_POS 16U +#define GEVNTCOUNT_EVNT_HANDLER_BUSY_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t evntcount : 16; // 0..15 + uint32_t reserved_30_16 : 15; // 16..30 + uint32_t evnt_handler_busy : 1; // 31 + }; +} dwc3_gevntcount_t; +TU_VERIFY_STATIC(sizeof(dwc3_gevntcount_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GHWPARAMS8. */ +#define GHWPARAMS8_GHWPARAMS8_32_0_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams8_32_0 : 32; // 0..31 + }; +} dwc3_ghwparams8_t; +TU_VERIFY_STATIC(sizeof(dwc3_ghwparams8_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GSMACCTL. */ +#define GSMACCTL_SINGLE_TBT_REQ_POS 0U +#define GSMACCTL_IGNORE_BABBLE_POS 1U +#define GSMACCTL_HOST_MASK_NUMP0_POS 2U +#define GSMACCTL_SINGLE_PSQDIR_EN_POS 3U +#define GSMACCTL_RESERVED_15_4_POS 4U +#define GSMACCTL_HOSTOUT_SINGLE_EN_POS 16U +#define GSMACCTL_HOSTIN_SIGNLE_EN_POS 17U +#define GSMACCTL_RESERVED_25_8_POS 18U +#define GSMACCTL_DBG_PTL_ADDR_POS 26U +#define GSMACCTL_DBG_TIS_INDEX_POS 30U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t single_tbt_req : 1; // 0 + uint32_t ignore_babble : 1; // 1 + uint32_t host_mask_nump0 : 1; // 2 + uint32_t single_psqdir_en : 1; // 3 + uint32_t reserved_15_4 : 12; // 4..15 + uint32_t hostout_single_en : 1; // 16 + uint32_t hostin_signle_en : 1; // 17 + uint32_t reserved_25_8 : 8; // 18..25 + uint32_t dbg_ptl_addr : 4; // 26..29 + uint32_t dbg_tis_index : 2; // 30..31 + }; +} dwc3_gsmacctl_t; +TU_VERIFY_STATIC(sizeof(dwc3_gsmacctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUCTL2. */ +#define GUCTL2_SCHEDDULE_LT_THR_POS 0U +#define GUCTL2_MAX_REISU_CNT_POS 1U +#define GUCTL2_SVC_OPP_PER_FSLS_POS 3U +#define GUCTL2_SVC_OPP_PER_HS_POS 5U +#define GUCTL2_SVC_OPP_PER_SS_POS 7U +#define GUCTL2_SVC_OPP_PER_SSP_POS 9U +#define GUCTL2_PERIODIC_TXDMA_UF_THR_POS 11U +#define GUCTL2_ASYNC_UF_THR_POS 18U +#define GUCTL2_PERIODIC_UF_THR_POS 25U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t scheddule_lt_thr : 1; // 0 + uint32_t max_reisu_cnt : 2; // 1..2 + uint32_t svc_opp_per_fsls : 2; // 3..4 + uint32_t svc_opp_per_hs : 2; // 5..6 + uint32_t svc_opp_per_ss : 2; // 7..8 + uint32_t svc_opp_per_ssp : 2; // 9..10 + uint32_t periodic_txdma_uf_thr : 7; // 11..17 + uint32_t async_uf_thr : 7; // 18..24 + uint32_t periodic_uf_thr : 7; // 25..31 + }; +} dwc3_guctl2_t; +TU_VERIFY_STATIC(sizeof(dwc3_guctl2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUCTL3. */ +#define GUCTL3_PERIODIC_UF_THR_FSLS_POS 0U +#define GUCTL3_INTR_EP_PING_ENABLE_POS 7U +#define GUCTL3_BARB_BURST_ENABLE_POS 8U +#define GUCTL3_SVC_OPP_PER_HS_SEP_POS 9U +#define GUCTL3_RESERVED_13_POS 13U +#define GUCTL3_RESERVED_14_POS 14U +#define GUCTL3_RESERVED_15_POS 15U +#define GUCTL3_USB20_RETRY_DISABLE_POS 16U +#define GUCTL3_RSVD_PERI_BANDWIDTH_FS_POS 17U +#define GUCTL3_DISEXTBUSCLKGT_POS 18U +#define GUCTL3_DISEXTBUSCLKGT_U1U2L1_POS 19U +#define GUCTL3_SSBI_SINGLE_EP_MODE_DISABLE_POS 20U +#define GUCTL3_BLOCK_CONCURRENT_IN_CTRL_XFERS_POS 21U +#define GUCTL3_CFGEP_CMD_SWITCHING_TIME_CTRL_POS 22U +#define GUCTL3_RESERVED_30_22_POS 25U +#define GUCTL3_RESERVED_31_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t periodic_uf_thr_fsls : 7; // 0..6 + uint32_t intr_ep_ping_enable : 1; // 7 + uint32_t barb_burst_enable : 1; // 8 + uint32_t svc_opp_per_hs_sep : 4; // 9..12 + uint32_t reserved_13 : 1; // 13 + uint32_t reserved_14 : 1; // 14 + uint32_t reserved_15 : 1; // 15 + uint32_t usb20_retry_disable : 1; // 16 + uint32_t rsvd_peri_bandwidth_fs : 1; // 17 + uint32_t disextbusclkgt : 1; // 18 + uint32_t disextbusclkgt_u1_u2_l1 : 1; // 19 + uint32_t ssbi_single_ep_mode_disable : 1; // 20 + uint32_t block_concurrent_in_ctrl_xfers : 1; // 21 + uint32_t cfgep_cmd_switching_time_ctrl : 3; // 22..24 + uint32_t reserved_30_22 : 6; // 25..30 + uint32_t reserved_31 : 1; // 31 + }; +} dwc3_guctl3_t; +TU_VERIFY_STATIC(sizeof(dwc3_guctl3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOPRIDEV. */ +#define GTXFIFOPRIDEV_GTXFIFOPRIDEV_POS 0U +#define GTXFIFOPRIDEV_RESERVED_31_N_POS 16U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gtxfifopridev : 16; // 0..15 + uint32_t reserved_31_n : 16; // 16..31 + }; +} dwc3_gtxfifopridev_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifopridev_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GTXFIFOPRIHST. */ +#define GTXFIFOPRIHST_GTXFIFOPRIHST_POS 0U +#define GTXFIFOPRIHST_RESERVED_31_Y_POS 7U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gtxfifoprihst : 7; // 0..6 + uint32_t reserved_31_y : 25; // 7..31 + }; +} dwc3_gtxfifoprihst_t; +TU_VERIFY_STATIC(sizeof(dwc3_gtxfifoprihst_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GRXFIFOPRIHST. */ +#define GRXFIFOPRIHST_GRXFIFOPRIHST_POS 0U +#define GRXFIFOPRIHST_RESERVED_31_Y_POS 6U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t grxfifoprihst : 6; // 0..5 + uint32_t reserved_31_y : 26; // 6..31 + }; +} dwc3_grxfifoprihst_t; +TU_VERIFY_STATIC(sizeof(dwc3_grxfifoprihst_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GFIFOPRIDBC. */ +#define GFIFOPRIDBC_GFIFOPRIDBC_POS 0U +#define GFIFOPRIDBC_RESERVED_31_2_POS 2U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gfifopridbc : 2; // 0..1 + uint32_t reserved_31_2 : 30; // 2..31 + }; +} dwc3_gfifopridbc_t; +TU_VERIFY_STATIC(sizeof(dwc3_gfifopridbc_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GDMAHLRATIO. */ +#define GDMAHLRATIO_HSTTXFIFO_DMA_POS 0U +#define GDMAHLRATIO_RESERVED_7_5_POS 5U +#define GDMAHLRATIO_HSTRXFIFO_DMA_POS 8U +#define GDMAHLRATIO_RESERVED_15_13_POS 13U +#define GDMAHLRATIO_HSTTXFIFO_MAC_POS 16U +#define GDMAHLRATIO_RESERVED_23_21_POS 21U +#define GDMAHLRATIO_HSTRXFIFO_MAC_POS 24U +#define GDMAHLRATIO_RESERVED_31_29_POS 29U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t hsttxfifo_dma : 5; // 0..4 + uint32_t reserved_7_5 : 3; // 5..7 + uint32_t hstrxfifo_dma : 5; // 8..12 + uint32_t reserved_15_13 : 3; // 13..15 + uint32_t hsttxfifo_mac : 5; // 16..20 + uint32_t reserved_23_21 : 3; // 21..23 + uint32_t hstrxfifo_mac : 5; // 24..28 + uint32_t reserved_31_29 : 3; // 29..31 + }; +} dwc3_gdmahlratio_t; +TU_VERIFY_STATIC(sizeof(dwc3_gdmahlratio_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GOSTDDMA_ASYNC. */ +#define GOSTDDMA_ASYNC_OSTDTX_ASYNC_POS 0U +#define GOSTDDMA_ASYNC_OSTDTX_ASYNC_INACTIVE_POS 8U +#define GOSTDDMA_ASYNC_OSTDTX_ASYNC_ACTIVE_POS 16U +#define GOSTDDMA_ASYNC_OSTDRX_ASYNC_POS 24U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ostdtx_async : 8; // 0..7 + uint32_t ostdtx_async_inactive : 8; // 8..15 + uint32_t ostdtx_async_active : 8; // 16..23 + uint32_t ostdrx_async : 8; // 24..31 + }; +} dwc3_gostddma_async_t; +TU_VERIFY_STATIC(sizeof(dwc3_gostddma_async_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GOSTDDMA_PRD. */ +#define GOSTDDMA_PRD_OSTDTX_PRD_POS 0U +#define GOSTDDMA_PRD_OSTDTX_PRD_INACTIVE_POS 8U +#define GOSTDDMA_PRD_OSTDTX_PRD_ACTIVE_POS 16U +#define GOSTDDMA_PRD_OSTDRX_PRD_POS 24U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ostdtx_prd : 8; // 0..7 + uint32_t ostdtx_prd_inactive : 8; // 8..15 + uint32_t ostdtx_prd_active : 8; // 16..23 + uint32_t ostdrx_prd : 8; // 24..31 + }; +} dwc3_gostddma_prd_t; +TU_VERIFY_STATIC(sizeof(dwc3_gostddma_prd_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GFLADJ. */ +#define GFLADJ_GFLADJ_30MHZ_POS 0U +#define GFLADJ_RESERVED_6_POS 6U +#define GFLADJ_GFLADJ_30MHZ_SDBND_SEL_POS 7U +#define GFLADJ_GFLADJ_REFCLK_FLADJ_POS 8U +#define GFLADJ_RESERVED_22_POS 22U +#define GFLADJ_GFLADJ_REFCLK_LPM_SEL_POS 23U +#define GFLADJ_GFLADJ_REFCLK_240MHZ_DECR_POS 24U +#define GFLADJ_GFLADJ_REFCLK_240MHZDECR_PLS1_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gfladj_30_mhz : 6; // 0..5 + uint32_t reserved_6 : 1; // 6 + uint32_t gfladj_30_mhz_sdbnd_sel : 1; // 7 + uint32_t gfladj_refclk_fladj : 14; // 8..21 + uint32_t reserved_22 : 1; // 22 + uint32_t gfladj_refclk_lpm_sel : 1; // 23 + uint32_t gfladj_refclk_240_mhz_decr : 7; // 24..30 + uint32_t gfladj_refclk_240_mhzdecr_pls1 : 1; // 31 + }; +} dwc3_gfladj_t; +TU_VERIFY_STATIC(sizeof(dwc3_gfladj_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUCTL4. */ +#define GUCTL4_CSR_TIMEOUT_VL_POS 0U +#define GUCTL4_LOA_EOP_CHECK_CLKS_BYTE_POS 17U +#define GUCTL4_LOA_EOP_CHECK_CLKS_WORD_POS 19U +#define GUCTL4_RESERVED_25_21_POS 21U +#define GUCTL4_SSP_BWD_OVHD_ADJ_POS 26U +#define GUCTL4_RESERVED_31_POS 31U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t csr_timeout_vl : 17; // 0..16 + uint32_t loa_eop_check_clks_byte : 2; // 17..18 + uint32_t loa_eop_check_clks_word : 2; // 19..20 + uint32_t reserved_25_21 : 5; // 21..25 + uint32_t ssp_bwd_ovhd_adj : 5; // 26..30 + uint32_t reserved_31 : 1; // 31 + }; +} dwc3_guctl4_t; +TU_VERIFY_STATIC(sizeof(dwc3_guctl4_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUCTL5. */ +#define GUCTL5_RESERVED_31_0_POS 0U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} dwc3_guctl5_t; +TU_VERIFY_STATIC(sizeof(dwc3_guctl5_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit positions for GUSB2RHBCTL. */ +#define GUSB2RHBCTL_OVRD_L1TIMEOUT_POS 0U +#define GUSB2RHBCTL_OVRD_HS_INT_PKT_DEL_POS 4U +#define GUSB2RHBCTL_OVRD_FS_INT_PKT_DEL_POS 12U +#define GUSB2RHBCTL_RESERVED_31_20_POS 20U + +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ovrd_l1_timeout : 4; // 0..3 + uint32_t ovrd_hs_int_pkt_del : 8; // 4..11 + uint32_t ovrd_fs_int_pkt_del : 8; // 12..19 + uint32_t reserved_31_20 : 12; // 20..31 + }; +} dwc3_gusb2_rhbctl_t; +TU_VERIFY_STATIC(sizeof(dwc3_gusb2_rhbctl_t) == sizeof(uint32_t), "incorrect size"); + +typedef struct { + volatile dwc3_gsbuscfg0_t gsbuscfg0; // 0x000 + volatile dwc3_gsbuscfg1_t gsbuscfg1; // 0x004 + volatile dwc3_gtxthrcfg_t gtxthrcfg; // 0x008 + volatile dwc3_grxthrcfg_t grxthrcfg; // 0x00c + volatile dwc3_gctl_t gctl; // 0x010 + volatile dwc3_gpmsts_t gpmsts; // 0x014 + volatile dwc3_gsts_t gsts; // 0x018 + volatile dwc3_guctl1_t guctl1; // 0x01c + volatile dwc3_usb31_ip_name_t usb31_ip_name; // 0x020 + volatile dwc3_ggpio_t ggpio; // 0x024 + volatile dwc3_guid_t guid; // 0x028 + volatile dwc3_guctl_t guctl; // 0x02c + volatile dwc3_gbuserraddrlo_t gbuserraddrlo; // 0x030 + volatile dwc3_gbuserraddrhi_t gbuserraddrhi; // 0x034 + volatile dwc3_gprtbimaplo_t gprtbimaplo; // 0x038 + volatile dwc3_gprtbimaphi_t gprtbimaphi; // 0x03c + volatile dwc3_ghwparams0_t ghwparams0; // 0x040 + volatile dwc3_ghwparams1_t ghwparams1; // 0x044 + volatile dwc3_ghwparams2_t ghwparams2; // 0x048 + volatile dwc3_ghwparams3_t ghwparams3; // 0x04c + volatile dwc3_ghwparams4_t ghwparams4; // 0x050 + volatile dwc3_ghwparams5_t ghwparams5; // 0x054 + volatile dwc3_ghwparams6_t ghwparams6; // 0x058 + volatile dwc3_ghwparams7_t ghwparams7; // 0x05c + volatile dwc3_gdbgfifospace_t gdbgfifospace; // 0x060 + volatile dwc3_gbmuctl_t gbmuctl; // 0x064 + uint32_t reserved_068[1]; + volatile dwc3_gdbgbmu_t gdbgbmu; // 0x06c + volatile dwc3_gdbglspmux_t gdbglspmux; // 0x070 + volatile dwc3_gdbglsp_t gdbglsp; // 0x074 + volatile dwc3_gdbgepinfo0_t gdbgepinfo0; // 0x078 + volatile dwc3_gdbgepinfo1_t gdbgepinfo1; // 0x07c + volatile dwc3_gprtbimap_hslo_t gprtbimap_hslo; // 0x080 + volatile dwc3_gprtbimap_hshi_t gprtbimap_hshi; // 0x084 + volatile dwc3_gprtbimap_fslo_t gprtbimap_fslo; // 0x088 + volatile dwc3_gprtbimap_fshi_t gprtbimap_fshi; // 0x08c + volatile dwc3_ghmsocbwor_t ghmsocbwor; // 0x090 + uint32_t reserved_094[3]; + volatile dwc3_usb31_ver_number_t usb31_ver_number; // 0x0a0 + volatile dwc3_usb31_ver_type_t usb31_ver_type; // 0x0a4 + uint32_t reserved_0a8[2]; + volatile dwc3_gsysblkwinctrl_t gsysblkwinctrl; // 0x0b0 + volatile dwc3_gpciel1_extlat_t gpciel1_extlat; // 0x0b4 + uint32_t reserved_0b8[18]; + volatile dwc3_gusb2_phycfg_t gusb2_phycfg; // 0x100 + uint32_t reserved_104[31]; + volatile dwc3_gusb2_phyacc_ulpi_t gusb2_phyacc_ulpi; // 0x180 + uint32_t reserved_184[15]; + volatile dwc3_gusb3_pipectl_t gusb3_pipectl; // 0x1c0 + uint32_t reserved_1c4[15]; + volatile dwc3_gtxfifosiz0_t gtxfifosiz0; // 0x200 + volatile dwc3_gtxfifosiz1_t gtxfifosiz1; // 0x204 + volatile dwc3_gtxfifosiz2_t gtxfifosiz2; // 0x208 + volatile dwc3_gtxfifosiz3_t gtxfifosiz3; // 0x20c + volatile dwc3_gtxfifosiz4_t gtxfifosiz4; // 0x210 + volatile dwc3_gtxfifosiz5_t gtxfifosiz5; // 0x214 + volatile dwc3_gtxfifosiz6_t gtxfifosiz6; // 0x218 + volatile dwc3_gtxfifosiz7_t gtxfifosiz7; // 0x21c + volatile dwc3_gtxfifosiz8_t gtxfifosiz8; // 0x220 + volatile dwc3_gtxfifosiz9_t gtxfifosiz9; // 0x224 + volatile dwc3_gtxfifosiz10_t gtxfifosiz10; // 0x228 + volatile dwc3_gtxfifosiz11_t gtxfifosiz11; // 0x22c + volatile dwc3_gtxfifosiz12_t gtxfifosiz12; // 0x230 + volatile dwc3_gtxfifosiz13_t gtxfifosiz13; // 0x234 + volatile dwc3_gtxfifosiz14_t gtxfifosiz14; // 0x238 + volatile dwc3_gtxfifosiz15_t gtxfifosiz15; // 0x23c + uint32_t reserved_240[16]; + volatile dwc3_grxfifosiz0_t grxfifosiz0; // 0x280 + volatile dwc3_grxfifosiz1_t grxfifosiz1; // 0x284 + volatile dwc3_grxfifosiz2_t grxfifosiz2; // 0x288 + volatile dwc3_grxfifosiz3_t grxfifosiz3; // 0x28c + volatile dwc3_grxfifosiz4_t grxfifosiz4; // 0x290 + volatile dwc3_grxfifosiz5_t grxfifosiz5; // 0x294 + uint32_t reserved_298[26]; + volatile dwc3_gevntadrlo_t gevntadrlo; // 0x300 + volatile dwc3_gevntadrhi_t gevntadrhi; // 0x304 + volatile dwc3_gevntsiz_t gevntsiz; // 0x308 + volatile dwc3_gevntcount_t gevntcount; // 0x30c + uint32_t reserved_310[124]; + volatile dwc3_ghwparams8_t ghwparams8; // 0x500 + volatile dwc3_gsmacctl_t gsmacctl; // 0x504 + volatile dwc3_guctl2_t guctl2; // 0x508 + volatile dwc3_guctl3_t guctl3; // 0x50c + volatile dwc3_gtxfifopridev_t gtxfifopridev; // 0x510 + uint32_t reserved_514[1]; + volatile dwc3_gtxfifoprihst_t gtxfifoprihst; // 0x518 + volatile dwc3_grxfifoprihst_t grxfifoprihst; // 0x51c + volatile dwc3_gfifopridbc_t gfifopridbc; // 0x520 + volatile dwc3_gdmahlratio_t gdmahlratio; // 0x524 + volatile dwc3_gostddma_async_t gostddma_async; // 0x528 + volatile dwc3_gostddma_prd_t gostddma_prd; // 0x52c + volatile dwc3_gfladj_t gfladj; // 0x530 + volatile dwc3_guctl4_t guctl4; // 0x534 + volatile dwc3_guctl5_t guctl5; // 0x538 + uint32_t reserved_53c[1]; + volatile dwc3_gusb2_rhbctl_t gusb2_rhbctl; // 0x540 +} dwc3_gbl_regs_t; + +#define GBL_REG_BASE 0x1100C100U + +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gsbuscfg0) == 0x000, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gsbuscfg1) == 0x004, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxthrcfg) == 0x008, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, grxthrcfg) == 0x00c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gctl) == 0x010, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gpmsts) == 0x014, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gsts) == 0x018, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, guctl1) == 0x01c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, usb31_ip_name) == 0x020, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ggpio) == 0x024, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, guid) == 0x028, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, guctl) == 0x02c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gbuserraddrlo) == 0x030, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gbuserraddrhi) == 0x034, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gprtbimaplo) == 0x038, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gprtbimaphi) == 0x03c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ghwparams0) == 0x040, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ghwparams1) == 0x044, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ghwparams2) == 0x048, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ghwparams3) == 0x04c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ghwparams4) == 0x050, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ghwparams5) == 0x054, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ghwparams6) == 0x058, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ghwparams7) == 0x05c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gdbgfifospace) == 0x060, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gbmuctl) == 0x064, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gdbgbmu) == 0x06c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gdbglspmux) == 0x070, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gdbglsp) == 0x074, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gdbgepinfo0) == 0x078, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gdbgepinfo1) == 0x07c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gprtbimap_hslo) == 0x080, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gprtbimap_hshi) == 0x084, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gprtbimap_fslo) == 0x088, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gprtbimap_fshi) == 0x08c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ghmsocbwor) == 0x090, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, usb31_ver_number) == 0x0a0, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, usb31_ver_type) == 0x0a4, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gsysblkwinctrl) == 0x0b0, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gpciel1_extlat) == 0x0b4, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gusb2_phycfg) == 0x100, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gusb2_phyacc_ulpi) == 0x180, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gusb3_pipectl) == 0x1c0, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz0) == 0x200, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz1) == 0x204, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz2) == 0x208, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz3) == 0x20c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz4) == 0x210, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz5) == 0x214, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz6) == 0x218, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz7) == 0x21c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz8) == 0x220, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz9) == 0x224, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz10) == 0x228, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz11) == 0x22c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz12) == 0x230, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz13) == 0x234, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz14) == 0x238, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifosiz15) == 0x23c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, grxfifosiz0) == 0x280, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, grxfifosiz1) == 0x284, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, grxfifosiz2) == 0x288, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, grxfifosiz3) == 0x28c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, grxfifosiz4) == 0x290, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, grxfifosiz5) == 0x294, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gevntadrlo) == 0x300, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gevntadrhi) == 0x304, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gevntsiz) == 0x308, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gevntcount) == 0x30c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, ghwparams8) == 0x500, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gsmacctl) == 0x504, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, guctl2) == 0x508, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, guctl3) == 0x50c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifopridev) == 0x510, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxfifoprihst) == 0x518, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, grxfifoprihst) == 0x51c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gfifopridbc) == 0x520, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gdmahlratio) == 0x524, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gostddma_async) == 0x528, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gostddma_prd) == 0x52c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gfladj) == 0x530, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, guctl4) == 0x534, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, guctl5) == 0x538, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gusb2_rhbctl) == 0x540, "incorrect register offset"); +TU_VERIFY_STATIC(sizeof(dwc3_gbl_regs_t) == 0x544, "incorrect register map size"); + +#ifdef __cplusplus +} +#endif + +#endif /* TYPE_H_ */ From e4f5dcdf7dbcec8f770ceec4fb1bb7a49f878ae4 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Mon, 16 Nov 2026 14:44:04 +0530 Subject: [PATCH 03/17] dwc3: code-restructure * remove dwc3.c and ll.c and move the content to hcd_dwc3.c Signed-off-by: Sourav Raj K K --- hw/bsp/socfpga/family.cmake | 4 +- src/portable/synopsys/dwc3/dwc3.c | 50 - src/portable/synopsys/dwc3/dwc3.h | 1 + src/portable/synopsys/dwc3/dwc3_common.h | 35 + src/portable/synopsys/dwc3/dwc3_ll.c | 169 --- src/portable/synopsys/dwc3/dwc3_ll.h | 63 - src/portable/synopsys/dwc3/dwc3_socfpga.h | 245 +--- src/portable/synopsys/dwc3/dwc3_type.h | 18 +- src/portable/synopsys/dwc3/hcd_dwc3.c | 1432 ++------------------- 9 files changed, 132 insertions(+), 1885 deletions(-) delete mode 100644 src/portable/synopsys/dwc3/dwc3.c create mode 100644 src/portable/synopsys/dwc3/dwc3_common.h delete mode 100644 src/portable/synopsys/dwc3/dwc3_ll.c delete mode 100644 src/portable/synopsys/dwc3/dwc3_ll.h diff --git a/hw/bsp/socfpga/family.cmake b/hw/bsp/socfpga/family.cmake index d1244c20b..de31423a7 100644 --- a/hw/bsp/socfpga/family.cmake +++ b/hw/bsp/socfpga/family.cmake @@ -40,10 +40,10 @@ target_include_directories(agilex5-tinyusb PUBLIC ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc2/dwc2_common.c # Synopsys dwc3 controller + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/hcd_dwc3.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc3/hcd_dwc3.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc3/dwc3_common.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/dwc3.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/dwc3_ll.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_cap.c diff --git a/src/portable/synopsys/dwc3/dwc3.c b/src/portable/synopsys/dwc3/dwc3.c deleted file mode 100644 index 3ef5b1f30..000000000 --- a/src/portable/synopsys/dwc3/dwc3.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation - * - * SPDX-License-Identifier: MIT-0 - * - * HAL driver implementation for DWC3 driver - */ - -#include "dwc3.h" -#include "dwc3_ll.h" -#include "osal_log.h" -#include "socfpga_defines.h" - -int dwc3_init(void) -{ - uint32_t ghwparams0 = RD_REG32(USBBASE + USB3_GHWPARAMS0); - uint32_t ghwparams1 = RD_REG32(USBBASE + USB3_GHWPARAMS1); - uint32_t ghwparams3 = RD_REG32(USBBASE + USB3_GHWPARAMS3); - uint32_t phy_info; - int ret = 0; - - phy_info = get_usb3_phy_info(ghwparams3); - switch (phy_info) - { - case DWC3_SS_PHY_3_0: - INFO("Device supportes USB 3.0 Only"); - break; - - case DWC3_SS_PHY_3_1: - INFO("Device supportes USB 3.1 Gen1"); - break; - - default: - INFO("Device does not support USB3.1"); - break; - } - - usb2_phy_setup(ghwparams3); - - setup_dwc3_gctl(ghwparams1); - - ret = dwc3_set_usb_host_mode(ghwparams0); - if (ret != 0) - { - ERROR("Unable to setup DWC3 in host mode"); - return ret; - } - - return 0; -} diff --git a/src/portable/synopsys/dwc3/dwc3.h b/src/portable/synopsys/dwc3/dwc3.h index 1c5b03069..cadbbd9a1 100644 --- a/src/portable/synopsys/dwc3/dwc3.h +++ b/src/portable/synopsys/dwc3/dwc3.h @@ -11,6 +11,7 @@ #include #include "socfpga_usb3_reg.h" +#include "dwc3_type.h" #include "socfpga_defines.h" /** diff --git a/src/portable/synopsys/dwc3/dwc3_common.h b/src/portable/synopsys/dwc3/dwc3_common.h new file mode 100644 index 000000000..1ecbb7f9d --- /dev/null +++ b/src/portable/synopsys/dwc3/dwc3_common.h @@ -0,0 +1,35 @@ + + +#ifndef TUSB_DWC3_COMMON_H +#define TUSB_DWC3_COMMON_H + +#include "common/tusb_common.h" +#include "dwc3_type.h" +#include "osal_log.h" + +#if TU_CHECK_MCU(OPT_MCU_SOCFPGA) + #include "dwc3_socfpga.h" +#else + #error "Unsupported MCUs" +#endif + +#define USB_MODE_HOST ((uint32_t) 1) /* !< USB host mode */ + +#define DWC3_HS_PHY_DIS (0U) /* !< HS phy is disabled */ +#define DWC3_HS_PHY_UTMI (1U) /* !< HS phy interface is UTMI */ +#define DWC3_HS_PHY_ULPI (2U) /* !< HS phy interface is ULPI */ +#define DWC3_HS_PHY_UTMI_ULPI (3U) /* !< DWC3 supports both UTMI/ULPI HS phy interface */ + +#define DWC3_SS_PHY_DIS (0U) /* !< DWC3 SS phy interface is disabled */ +#define DWC3_SS_PHY_3_0 (1U) /* !< DWC3 supports only USB3.0 mode */ +#define DWC3_SS_PHY_3_1 (2U) /* !< DWC3 supports USB3.1 mode */ + +#define DWC3_GHWPARAMS0_MODE_GADGET (0U) /* !< DWC3 Core is in gadget mode */ +#define DWC3_GHWPARAMS0_MODE_HOST (1U) /* !< DWC3 Core is in host mode*/ +#define DWC3_GHWPARAMS0_MODE_DRD (2U) /* !< DWC3 Core is in DRD mode*/ + +TU_ATTR_ALWAYS_INLINE static inline dwc3_gbl_regs_t* DWC2_REG(uint8_t rhport) { + return (dwc3_gbl_regs_t*)_dwc3_controller[rhport].reg_base; +} + +#endif diff --git a/src/portable/synopsys/dwc3/dwc3_ll.c b/src/portable/synopsys/dwc3/dwc3_ll.c deleted file mode 100644 index 6976214c0..000000000 --- a/src/portable/synopsys/dwc3/dwc3_ll.c +++ /dev/null @@ -1,169 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation - * - * SPDX-License-Identifier: MIT-0 - * - * Low level driver implementation for DWC3 driver - */ - -#include "dwc3_ll.h" -#include "socfpga_usb3_reg.h" -#include "socfpga_defines.h" -#include - -/* - * @brief Configures the DWC3 to operate in host mode - */ -int dwc3_set_usb_host_mode(uint32_t ghwparams0) -{ - uint32_t reg_val; - uint8_t usb_mode = (uint8_t) (ghwparams0 & - USB3_GHWPARAMS0_GHWPARAMS0_2_0_MASK); - - if (usb_mode == DWC3_GHWPARAMS0_MODE_DRD) - { - /* Suspend both USB3 & USB2 PHYs before setting HOST mode */ - reg_val = RD_REG32((USBBASE + USB3_GUSB3PIPECTL)); - reg_val &= ~(USB3_GUSB3PIPECTL_SUSPENDENABLE_MASK); - WR_REG32((USBBASE + USB3_GUSB3PIPECTL), reg_val); - - reg_val = RD_REG32((USBBASE + USB3_GUSB2PHYCFG)); - reg_val &= ~(USB3_GUSB2PHYCFG_SUSPENDUSB20_MASK); - WR_REG32((USBBASE + USB3_GUSB2PHYCFG), reg_val); - - /* Clear 12, 13 bit of GCTL register before setting to host mode */ - reg_val = RD_REG32((USBBASE + USB3_GCTL)); - reg_val &= ~(USB3_GCTL_PRTCAPDIR_MASK); - reg_val |= (USB_MODE_HOST << USB3_GCTL_PRTCAPDIR_POS); - WR_REG32((USBBASE + USB3_GCTL), reg_val); - - reg_val = RD_REG32((USBBASE + USB3_GCTL)); - reg_val |= (USB3_GCTL_CORESOFTRESET_MASK); - WR_REG32((USBBASE + USB3_GCTL), reg_val); - - osal_task_delay(100); - - reg_val = RD_REG32((USBBASE + USB3_GCTL)); - reg_val &= ~(USB3_GCTL_CORESOFTRESET_MASK); - WR_REG32((USBBASE + USB3_GCTL), reg_val); - - reg_val = RD_REG32((USBBASE + USB3_GUSB2PHYCFG)); - reg_val |= (USB3_GUSB2PHYCFG_SUSPENDUSB20_MASK); - WR_REG32((USBBASE + USB3_GUSB2PHYCFG), reg_val); - - reg_val = RD_REG32((USBBASE + USB3_GUSB3PIPECTL)); - reg_val |= ((uint32_t) 1U << 17); - WR_REG32((USBBASE + USB3_GUSB3PIPECTL), reg_val); - - } - else if (usb_mode == DWC3_GHWPARAMS0_MODE_HOST) - { - /* Do nothing as usb mode is host by default */ - } - else - { - /* Host mode not supported by controller*/ - return -EOPNOTSUPP; - } - - return 0; -} - -/* - * @brief Configures the USB2 phy - */ -void usb2_phy_setup(uint32_t ghwparams3) -{ - uint32_t reg_val; - uint8_t hs_phy; - - /* Select HS phy interface */ - hs_phy = (uint8_t) ((ghwparams3 & USB3_GHWPARAMS3_GHWPARAMS3_3_2_MASK) >> - USB3_GHWPARAMS3_GHWPARAMS3_3_2_POS); - - switch (hs_phy) - { - case DWC3_HS_PHY_UTMI: break; - - case DWC3_HS_PHY_ULPI: - break; - - case DWC3_HS_PHY_UTMI_ULPI: - /* select ULPI phy */ - reg_val = RD_REG32(USBBASE + USB3_GUSB2PHYCFG); - reg_val |= USB3_GUSB2PHYCFG_ULPI_UTMI_SEL_MASK; - WR_REG32((USBBASE + USB3_GUSB2PHYCFG), reg_val); - break; - default: - /*do nothing*/ - break; - } -} - -/* - * @brief Get the USB3 phy info - */ -uint32_t get_usb3_phy_info(uint32_t ghwparams3) -{ - uint8_t ss_phy; - - /* SS phy interface */ - ss_phy = (uint8_t) ((ghwparams3 & USB3_GHWPARAMS3_GHWPARAMS3_1_0_MASK) >> - USB3_GHWPARAMS3_GHWPARAMS3_1_0_POS); - - if (ss_phy == DWC3_SS_PHY_DIS) - { - /* SS PHY is disabled */ - return DWC3_SS_PHY_DIS; - } - else if (ss_phy == DWC3_SS_PHY_3_0) - { - /* Controller supports USB3.0 only */ - return DWC3_SS_PHY_3_0; - } - else if (ss_phy == DWC3_SS_PHY_3_1) - { - /* Controller supports USB3.1 */ - return DWC3_SS_PHY_3_1; - } - else - { - /* Invalid SS PHY info */ - } - - return DWC3_SS_PHY_DIS; - -} - -/* - * @brief Configure the DWC3 GCTL register - */ -void setup_dwc3_gctl(uint32_t ghwparams1) -{ - uint32_t reg_val; - uint8_t power_opt_mode; - - reg_val = RD_REG32(USBBASE + USB3_GCTL); - reg_val &= ~USB3_GCTL_SCALEDOWN_MASK; - - power_opt_mode = (uint8_t) ((ghwparams1 & - USB3_GHWPARAMS1_GHWPARAMS1_25_24_MASK) >> - USB3_GHWPARAMS1_GHWPARAMS1_25_24_POS); - - switch (power_opt_mode) - { - - case 1: /* clock gating only supported */ - /* Enable clock gating in GCTL reg */ - reg_val &= ~USB3_GCTL_DSBLCLKGTNG_MASK; - break; - case 2: - /* enable hibernation */ - reg_val |= USB3_GCTL_GBLHIBERNATIONEN_MASK; - - default: /*do nothing */ - break; - } - - WR_REG32((USBBASE + USB3_GCTL), reg_val); -} diff --git a/src/portable/synopsys/dwc3/dwc3_ll.h b/src/portable/synopsys/dwc3/dwc3_ll.h deleted file mode 100644 index 85cc504f5..000000000 --- a/src/portable/synopsys/dwc3/dwc3_ll.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (C) 2025-2026 Altera Corporation - * - * SPDX-License-Identifier: MIT-0 - * - * Header file for DWC3 low level driver - */ - -#ifndef _SOCFPGA_DWC3_LL_H_ -#define _SOCFPGA_DWC3_LL_H_ - -#include -#include "socfpga_usb3_reg.h" - -#define USB_MODE_HOST ((uint32_t) 1) /* !< USB host mode */ - -#define DWC3_HS_PHY_DIS (0U) /* !< HS phy is disabled */ -#define DWC3_HS_PHY_UTMI (1U) /* !< HS phy interface is UTMI */ -#define DWC3_HS_PHY_ULPI (2U) /* !< HS phy interface is ULPI */ -#define DWC3_HS_PHY_UTMI_ULPI (3U) /* !< DWC3 supports both UTMI/ULPI HS phy interface */ - -#define DWC3_SS_PHY_DIS (0U) /* !< DWC3 SS phy interface is disabled */ -#define DWC3_SS_PHY_3_0 (1U) /* !< DWC3 supports only USB3.0 mode */ -#define DWC3_SS_PHY_3_1 (2U) /* !< DWC3 supports USB3.1 mode */ - -#define DWC3_GHWPARAMS0_MODE_GADGET (0U) /* !< DWC3 Core is in gadget mode */ -#define DWC3_GHWPARAMS0_MODE_HOST (1U) /* !< DWC3 Core is in host mode*/ -#define DWC3_GHWPARAMS0_MODE_DRD (2U) /* !< DWC3 Core is in DRD mode*/ - - -/** - * @brief Configure the usb2 phy. - * - * @param[in] ghwparams3 ghwparams3 register value - */ -void usb2_phy_setup(uint32_t ghwparams3); - -/** - * @brief Get info regarding USB3.1 phy. - * - * @param[in] ghwparams3 ghwparams3 register value - * @return usb3 SS phy info - */ -uint32_t get_usb3_phy_info(uint32_t ghwparams3); - -/** - * @brief Configure the GCTL register. - * - * @param[in] ghwparams1 ghwparams1 register value - */ -void setup_dwc3_gctl(uint32_t ghwparams1); - -/** - * @brief Configure the controller in host mode. - * - * @param[in] ghwparams0 ghwparams0 register value - * @return - * RET_SUCCESS: if host mode setup is successful - * RET_FAIL: if host mode setup fails - */ -int dwc3_set_usb_host_mode(uint32_t ghwparams0); - -#endif /* _SOCFPGA_DWC3_LL_H_ */ diff --git a/src/portable/synopsys/dwc3/dwc3_socfpga.h b/src/portable/synopsys/dwc3/dwc3_socfpga.h index e3d538f29..325242067 100644 --- a/src/portable/synopsys/dwc3/dwc3_socfpga.h +++ b/src/portable/synopsys/dwc3/dwc3_socfpga.h @@ -31,254 +31,19 @@ extern "C" { #endif -// EP_MAX : Max number of bi-directional endpoints including EP0 -// EP_FIFO_SIZE : Size of dedicated USB SRAM -#if CFG_TUSB_MCU == OPT_MCU_STM32F1 - - #define USB_OTG_HS_PERIPH_BASE USB_OTG_HS_BASE_NS - #define OTG_HS_IRQn USB_OTG_HS_IRQn - #define EP_MAX_HS 9 - #define EP_FIFO_SIZE_HS 4096 +#if CFG_TUSB_MCU == OPT_MCU_SOCFPGA + #define SOCFPGA_USB3_REG_BASE (0x1100C100U) + #define OTG_HS_IRQn 126 // IRQ num for USB1 = 126 #else #error "Unsupported MCUs" #endif -// OTG HS always has higher number of endpoints than FS -#ifdef USB_OTG_HS_PERIPH_BASE - #define DWC2_EP_MAX EP_MAX_HS -#else - #define DWC2_EP_MAX EP_MAX_FS -#endif - // On STM32 for consistency we associate // - Port0 to OTG_FS, and Port1 to OTG_HS -static const dwc2_controller_t _dwc2_controller[] = { - #ifdef USB_OTG_FS_PERIPH_BASE - { .reg_base = USB_OTG_FS_PERIPH_BASE, .irqnum = OTG_FS_IRQn, .ep_count = EP_MAX_FS, .ep_fifo_size = EP_FIFO_SIZE_FS }, - #endif - - #ifdef USB_OTG_HS_PERIPH_BASE - { .reg_base = USB_OTG_HS_PERIPH_BASE, .irqnum = OTG_HS_IRQn, .ep_count = EP_MAX_HS, .ep_fifo_size = EP_FIFO_SIZE_HS }, - #endif +static const dwc3_controller_t _dwc3_controller[] = { + { .reg_base = SOCFPGA_USB3_REG_BASE, .irqnum = OTG_HS_IRQn, }, }; -//--------------------------------------------------------------------+ -// -//--------------------------------------------------------------------+ - -// SystemCoreClock is already included by family header -// extern uint32_t SystemCoreClock; - -TU_ATTR_ALWAYS_INLINE static inline void dwc2_int_set(uint8_t rhport, tusb_role_t role, bool enabled) { - (void) role; - const IRQn_Type irqn = (IRQn_Type) _dwc2_controller[rhport].irqnum; - if (enabled) { - NVIC_EnableIRQ(irqn); - } else { - NVIC_DisableIRQ(irqn); - } -} - -#define dwc2_dcd_int_enable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, true) -#define dwc2_dcd_int_disable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, false) - - -TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) { - // try to delay for 1 ms - uint32_t count = SystemCoreClock / 1000; - while (count--) __NOP(); -} - -// MCU specific PHY init, called BEFORE core reset -// - dwc2 3.30a (H5) use USB_HS_PHYC -// - dwc2 4.11a (U5) use femtoPHY -// - dwc2 x.xxx (WBA) use USB_OTG_HS -static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) { - if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) { - // Enable on-chip FS PHY - dwc2->stm32_gccfg |= STM32_GCCFG_PWRDWN; - - // https://community.st.com/t5/stm32cubemx-mcus/why-stm32h743-usb-fs-doesn-t-work-if-freertos-tickless-idle/m-p/349480#M18867 - // H7 running on full-speed phy need to disable ULPI clock in sleep mode. - // Otherwise, USB won't work when mcu executing WFI/WFE instruction i.e tick-less RTOS. - // Note: there may be other family that is affected by this, but only H7 and F7 is tested so far - #if defined(USB_OTG_FS_PERIPH_BASE) && defined(RCC_AHB1LPENR_USB2OTGFSULPILPEN) - if ( USB_OTG_FS_PERIPH_BASE == (uint32_t) dwc2 ) { - RCC->AHB1LPENR &= ~RCC_AHB1LPENR_USB2OTGFSULPILPEN; - } - #endif - - #if defined(USB_OTG_HS_PERIPH_BASE) && defined(RCC_AHB1LPENR_USB1OTGHSULPILPEN) - if ( USB_OTG_HS_PERIPH_BASE == (uint32_t) dwc2 ) { - RCC->AHB1LPENR &= ~RCC_AHB1LPENR_USB1OTGHSULPILPEN; - } - #endif - - #if defined(USB_OTG_HS_PERIPH_BASE) && defined(RCC_AHB1LPENR_OTGHSULPILPEN) - if ( USB_OTG_HS_PERIPH_BASE == (uint32_t) dwc2 ) { - RCC->AHB1LPENR &= ~RCC_AHB1LPENR_OTGHSULPILPEN; - } - #endif - - } else { -#if CFG_TUSB_MCU != OPT_MCU_STM32U5 && CFG_TUSB_MCU != OPT_MCU_STM32WBA - // Disable FS PHY, TODO on U5A5 (dwc2 4.11a) 16th bit is 'Host CDP behavior enable' - dwc2->stm32_gccfg &= ~STM32_GCCFG_PWRDWN; -#endif - // Enable on-chip HS PHY - if (hs_phy_type == GHWCFG2_HSPHY_UTMI || hs_phy_type == GHWCFG2_HSPHY_UTMI_ULPI) { - #ifdef USB_HS_PHYC - // Enable UTMI HS PHY - dwc2->stm32_gccfg |= STM32_GCCFG_PHYHSEN; - - // Enable LDO - USB_HS_PHYC->USB_HS_PHYC_LDO |= USB_HS_PHYC_LDO_ENABLE; - - // Wait until LDO ready - while ( 0 == (USB_HS_PHYC->USB_HS_PHYC_LDO & USB_HS_PHYC_LDO_STATUS) ) {} - - uint32_t phyc_pll = 0; - - // TODO Try to get HSE_VALUE from registers instead of depending CFLAGS - switch ( HSE_VALUE ) - { - case 12000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12MHZ ; break; - case 12500000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12_5MHZ ; break; - case 16000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_16MHZ ; break; - case 24000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_24MHZ ; break; - case 25000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_25MHZ ; break; - case 32000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_Msk ; break; // Value not defined in header - default: - TU_ASSERT(false, ); - } - USB_HS_PHYC->USB_HS_PHYC_PLL = phyc_pll; - - // Control the tuning interface of the High Speed PHY - // Use magic value (USB_HS_PHYC_TUNE_VALUE) from ST driver for F7 - USB_HS_PHYC->USB_HS_PHYC_TUNE |= 0x00000F13U; - - // Enable PLL internal PHY - USB_HS_PHYC->USB_HS_PHYC_PLL |= USB_HS_PHYC_PLL_PLLEN; - - // Wait ~2ms until the PLL is ready (there's no RDY bit to query) - tusb_time_delay_ms_api(2); - #else - - #endif - } - } -} - -// MCU specific PHY update, it is called AFTER init() and core reset -static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint8_t hs_phy_type) { - // used to set turnaround time for fullspeed, nothing to do in highspeed mode - if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) { - // Turnaround timeout depends on the AHB clock dictated by STM32 Reference Manual - uint32_t turnaround; - - if (SystemCoreClock >= 32000000u) { - turnaround = 0x6u; - } else if (SystemCoreClock >= 27500000u) { - turnaround = 0x7u; - } else if (SystemCoreClock >= 24000000u) { - turnaround = 0x8u; - } else if (SystemCoreClock >= 21800000u) { - turnaround = 0x9u; - } - else if (SystemCoreClock >= 20000000u) { - turnaround = 0xAu; - } - else if (SystemCoreClock >= 18500000u) { - turnaround = 0xBu; - } - else if (SystemCoreClock >= 17200000u) { - turnaround = 0xCu; - } - else if (SystemCoreClock >= 16000000u) { - turnaround = 0xDu; - } - else if (SystemCoreClock >= 15000000u) { - turnaround = 0xEu; - } - else { - turnaround = 0xFu; - } - - dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_TRDT_Msk) | (turnaround << GUSBCFG_TRDT_Pos); - } -} - -//------------- DCache -------------// -#if CFG_TUD_MEM_DCACHE_ENABLE || CFG_TUH_MEM_DCACHE_ENABLE - -typedef struct { - uintptr_t start; - uintptr_t end; -} mem_region_t; - -// Can be used to define additional uncached regions -#ifndef CFG_DWC2_MEM_UNCACHED_REGIONS -#define CFG_DWC2_MEM_UNCACHED_REGIONS -#endif - -static mem_region_t uncached_regions[] = { - // DTCM (although USB DMA can't transfer to/from DTCM) -#if CFG_TUSB_MCU == OPT_MCU_STM32H7 - {.start = 0x20000000, .end = 0x2001FFFF}, -#elif CFG_TUSB_MCU == OPT_MCU_STM32H7RS - // DTCM (although USB DMA can't transfer to/from DTCM) - {.start = 0x20000000, .end = 0x2002FFFF}, -#elif CFG_TUSB_MCU == OPT_MCU_STM32F7 - // DTCM - {.start = 0x20000000, .end = 0x2000FFFF}, -#else -#error "Cache maintenance is not supported yet" -#endif - CFG_DWC2_MEM_UNCACHED_REGIONS -}; - -TU_ATTR_ALWAYS_INLINE static inline uint32_t round_up_to_cache_line_size(uint32_t size) { - if (size & (CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT-1)) { - size = (size & ~(CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT-1)) + CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT; - } - return size; -} - -TU_ATTR_ALWAYS_INLINE static inline bool is_cache_mem(uintptr_t addr) { - for (unsigned int i = 0; i < TU_ARRAY_SIZE(uncached_regions); i++) { - if (uncached_regions[i].start <= addr && addr <= uncached_regions[i].end) { return false; } - } - return true; -} - -TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_clean(void const* addr, uint32_t data_size) { - const uintptr_t addr32 = (uintptr_t) addr; - if (is_cache_mem(addr32)) { - data_size = round_up_to_cache_line_size(data_size); - SCB_CleanDCache_by_Addr((uint32_t *) addr32, (int32_t) data_size); - } - return true; -} - -TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_invalidate(void const* addr, uint32_t data_size) { - const uintptr_t addr32 = (uintptr_t) addr; - if (is_cache_mem(addr32)) { - data_size = round_up_to_cache_line_size(data_size); - SCB_InvalidateDCache_by_Addr((void*) addr32, (int32_t) data_size); - } - return true; -} - -TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_clean_invalidate(void const* addr, uint32_t data_size) { - const uintptr_t addr32 = (uintptr_t) addr; - if (is_cache_mem(addr32)) { - data_size = round_up_to_cache_line_size(data_size); - SCB_CleanInvalidateDCache_by_Addr((uint32_t *) addr32, (int32_t) data_size); - } - return true; -} -#endif - #ifdef __cplusplus } #endif diff --git a/src/portable/synopsys/dwc3/dwc3_type.h b/src/portable/synopsys/dwc3/dwc3_type.h index 172a7d3ae..fe8f523b2 100644 --- a/src/portable/synopsys/dwc3/dwc3_type.h +++ b/src/portable/synopsys/dwc3/dwc3_type.h @@ -7,8 +7,8 @@ * Field positions follow the Agilex 5 HPS register map. */ -#ifndef TYPE_H_ -#define TYPE_H_ +#ifndef SOCFPGA_USB_GLOBAL_TYPE_H_ +#define SOCFPGA_USB_GLOBAL_TYPE_H_ #include #include @@ -18,6 +18,16 @@ extern "C" { #endif +// Controller +typedef struct +{ + uintptr_t reg_base; + uint32_t irqnum; + uint8_t ep_count; + uint8_t ep_in_count; + uint32_t ep_fifo_size; +} dwc3_controller_t; + /* Bit positions for GSBUSCFG0. */ #define GSBUSCFG0_INCRBRSTENA_POS 0U #define GSBUSCFG0_INCR4BRSTENA_POS 1U @@ -1797,8 +1807,6 @@ typedef struct { volatile dwc3_gusb2_rhbctl_t gusb2_rhbctl; // 0x540 } dwc3_gbl_regs_t; -#define GBL_REG_BASE 0x1100C100U - TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gsbuscfg0) == 0x000, "incorrect register offset"); TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gsbuscfg1) == 0x004, "incorrect register offset"); TU_VERIFY_STATIC(offsetof(dwc3_gbl_regs_t, gtxthrcfg) == 0x008, "incorrect register offset"); @@ -1889,4 +1897,4 @@ TU_VERIFY_STATIC(sizeof(dwc3_gbl_regs_t) == 0x544, "incorrect register map size" } #endif -#endif /* TYPE_H_ */ +#endif /* SOCFPGA_USB_GLOBAL_TYPE_H_ */ diff --git a/src/portable/synopsys/dwc3/hcd_dwc3.c b/src/portable/synopsys/dwc3/hcd_dwc3.c index 257fa2833..4020a60e6 100644 --- a/src/portable/synopsys/dwc3/hcd_dwc3.c +++ b/src/portable/synopsys/dwc3/hcd_dwc3.c @@ -28,1407 +28,127 @@ #if CFG_TUH_ENABLED && defined(TUP_USBIP_DWC2) && !CFG_TUH_MAX3421 -#if !(CFG_TUH_DWC2_SLAVE_ENABLE || CFG_TUH_DWC2_DMA_ENABLE) -#error DWC2 require either CFG_TUH_DWC2_SLAVE_ENABLE or CFG_TUH_DWC2_DMA_ENABLE to be enabled -#endif - -// Debug level for DWC2 -#define DWC2_DEBUG 2 - #include "host/hcd.h" #include "host/usbh.h" -#include "dwc2_common.h" - -// Max number of endpoints application can open, can be larger than DWC2_CHANNEL_COUNT_MAX -#ifndef CFG_TUH_DWC2_ENDPOINT_MAX -#define CFG_TUH_DWC2_ENDPOINT_MAX 16 -#endif - -#define DWC2_CHANNEL_COUNT_MAX 16 // absolute max channel count -TU_VERIFY_STATIC(CFG_TUH_DWC2_ENDPOINT_MAX <= 255, "currently only use 8-bit for index"); - -enum { - HPRT_W1_MASK = HPRT_CONN_DETECT | HPRT_ENABLE | HPRT_ENABLE_CHANGE | HPRT_OVER_CURRENT_CHANGE | HPRT_SUSPEND -}; - -enum { - HCD_XFER_ERROR_MAX = 3 -}; - -enum { - HCD_XFER_PERIOD_SPLIT_NYET_MAX = 3 -}; - -//-------------------------------------------------------------------- -// -//-------------------------------------------------------------------- - -// Host driver struct for each opened endpoint -typedef struct { - union { - uint32_t hcchar; - dwc2_channel_char_t hcchar_bm; - }; - union { - uint32_t hcsplt; - dwc2_channel_split_t hcsplt_bm; - }; - - struct TU_ATTR_PACKED { - uint32_t uframe_interval : 18; // micro-frame interval - uint32_t speed : 2; - uint32_t next_pid : 2; // PID for next transfer - uint32_t next_do_ping : 1; // Do PING for next transfer if possible (highspeed OUT) - // uint32_t : 9; - }; - - uint32_t uframe_countdown; // micro-frame count down to transfer for periodic, only need 18-bit - - uint8_t* buffer; - uint16_t buflen; -} hcd_endpoint_t; - -// Additional info for each channel when it is active -typedef struct { - volatile bool allocated; - uint8_t ep_id; - struct TU_ATTR_PACKED { - uint8_t err_count : 3; - uint8_t period_split_nyet_count : 3; - uint8_t halted_nyet : 1; - }; - uint8_t result; - - uint16_t xferred_bytes; // bytes that accumulate transferred though USB bus for the whole hcd_edpt_xfer(), which can - // be composed of multiple channel_xfer_start() (retry with NAK/NYET) - uint16_t fifo_bytes; // bytes written/read from/to FIFO (may not be transferred on USB bus). -} hcd_xfer_t; - -typedef struct { - hcd_xfer_t xfer[DWC2_CHANNEL_COUNT_MAX]; - hcd_endpoint_t edpt[CFG_TUH_DWC2_ENDPOINT_MAX]; -} hcd_data_t; - -hcd_data_t _hcd_data; - -//-------------------------------------------------------------------- -// -//-------------------------------------------------------------------- -TU_ATTR_ALWAYS_INLINE static inline uint8_t dwc2_channel_count(const dwc2_regs_t* dwc2) { - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - return tu_min8(ghwcfg2.num_host_ch + 1, DWC2_CHANNEL_COUNT_MAX); -} - -TU_ATTR_ALWAYS_INLINE static inline tusb_speed_t hprt_speed_get(dwc2_regs_t* dwc2) { - tusb_speed_t speed; - const dwc2_hprt_t hprt = {.value = dwc2->hprt}; - switch(hprt.speed) { - case HPRT_SPEED_HIGH: speed = TUSB_SPEED_HIGH; break; - case HPRT_SPEED_FULL: speed = TUSB_SPEED_FULL; break; - case HPRT_SPEED_LOW : speed = TUSB_SPEED_LOW ; break; - default: - speed = TUSB_SPEED_INVALID; - TU_BREAKPOINT(); - break; - } - return speed; -} - -TU_ATTR_ALWAYS_INLINE static inline bool dma_host_enabled(const dwc2_regs_t* dwc2) { - (void) dwc2; - // Internal DMA only - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - return CFG_TUH_DWC2_DMA_ENABLE && ghwcfg2.arch == GHWCFG2_ARCH_INTERNAL_DMA; -} - -#if CFG_TUH_MEM_DCACHE_ENABLE -bool hcd_dcache_clean(const void* addr, uint32_t data_size) { - TU_VERIFY(addr && data_size); - return dwc2_dcache_clean(addr, data_size); -} - -bool hcd_dcache_invalidate(const void* addr, uint32_t data_size) { - TU_VERIFY(addr && data_size); - return dwc2_dcache_invalidate(addr, data_size); -} - -bool hcd_dcache_clean_invalidate(const void* addr, uint32_t data_size) { - TU_VERIFY(addr && data_size); - return dwc2_dcache_clean_invalidate(addr, data_size); -} -#endif - -// Allocate a channel for new transfer -TU_ATTR_ALWAYS_INLINE static inline uint8_t channel_alloc(dwc2_regs_t* dwc2) { - const uint8_t max_channel = dwc2_channel_count(dwc2); - for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - if (!xfer->allocated) { - tu_memclr(xfer, sizeof(hcd_xfer_t)); - xfer->allocated = true; - return ch_id; - } - } - return TUSB_INDEX_INVALID_8; -} - -// Check if is periodic (interrupt/isochronous) -TU_ATTR_ALWAYS_INLINE static inline bool channel_is_periodic(uint32_t hcchar) { - const dwc2_channel_char_t hcchar_bm = {.value = hcchar}; - return hcchar_bm.ep_type == HCCHAR_EPTYPE_INTERRUPT || hcchar_bm.ep_type == HCCHAR_EPTYPE_ISOCHRONOUS; -} - -TU_ATTR_ALWAYS_INLINE static inline uint8_t req_queue_avail(const dwc2_regs_t* dwc2, bool is_period) { - if (is_period) { - const dwc2_hptxsts_t hptxsts = {.value = dwc2->hptxsts}; - return hptxsts.req_queue_available; - } else { - const dwc2_hnptxsts_t hnptxsts = {.value = dwc2->hnptxsts}; - return hnptxsts.req_queue_available; - } -} - -TU_ATTR_ALWAYS_INLINE static inline void channel_dealloc(dwc2_regs_t* dwc2, uint8_t ch_id) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - xfer->allocated = false; - dwc2->haintmsk &= ~TU_BIT(ch_id); -} - -TU_ATTR_ALWAYS_INLINE static inline bool channel_disable(const dwc2_regs_t* dwc2, dwc2_channel_t* channel) { - // disable also require request queue - TU_ASSERT(req_queue_avail(dwc2, channel_is_periodic(channel->hcchar))); - channel->hcintmsk |= HCINT_HALTED; - channel->hcchar |= HCCHAR_CHDIS | HCCHAR_CHENA; // must set both CHDIS and CHENA - return true; -} - -// attempt to send IN token to receive data -TU_ATTR_ALWAYS_INLINE static inline bool channel_send_in_token(const dwc2_regs_t* dwc2, dwc2_channel_t* channel) { - TU_ASSERT(req_queue_avail(dwc2, channel_is_periodic(channel->hcchar))); - channel->hcchar |= HCCHAR_CHENA; - return true; -} - -// Find currently enabled channel. Note: EP0 is bidirectional -TU_ATTR_ALWAYS_INLINE static inline uint8_t channel_find_enabled(dwc2_regs_t* dwc2, uint8_t dev_addr, uint8_t ep_num, uint8_t ep_dir) { - const uint8_t max_channel = dwc2_channel_count(dwc2); - for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { - if (_hcd_data.xfer[ch_id].allocated) { - const dwc2_channel_char_t hcchar = {.value = dwc2->channel[ch_id].hcchar}; - if (hcchar.dev_addr == dev_addr && hcchar.ep_num == ep_num && (ep_num == 0 || hcchar.ep_dir == ep_dir)) { - return ch_id; - } - } - } - return TUSB_INDEX_INVALID_8; -} - - -// Allocate a new endpoint -TU_ATTR_ALWAYS_INLINE static inline uint8_t edpt_alloc(void) { - for (uint32_t i = 0; i < CFG_TUH_DWC2_ENDPOINT_MAX; i++) { - hcd_endpoint_t* edpt = &_hcd_data.edpt[i]; - if (edpt->hcchar_bm.enable == 0) { - tu_memclr(edpt, sizeof(hcd_endpoint_t)); - edpt->hcchar_bm.enable = 1; - return i; - } - } - return TUSB_INDEX_INVALID_8; -} - -// Find a endpoint that is opened previously with hcd_edpt_open() -// Note: EP0 is bidirectional -TU_ATTR_ALWAYS_INLINE static inline uint8_t edpt_find_opened(uint8_t dev_addr, uint8_t ep_num, uint8_t ep_dir) { - for (uint8_t i = 0; i < (uint8_t)CFG_TUH_DWC2_ENDPOINT_MAX; i++) { - const dwc2_channel_char_t* hcchar_bm = &_hcd_data.edpt[i].hcchar_bm; - if (hcchar_bm->enable && hcchar_bm->dev_addr == dev_addr && - hcchar_bm->ep_num == ep_num && (ep_num == 0 || hcchar_bm->ep_dir == ep_dir)) { - return i; - } - } - return TUSB_INDEX_INVALID_8; -} - -TU_ATTR_ALWAYS_INLINE static inline uint16_t cal_packet_count(uint16_t len, uint16_t ep_size) { - if (len == 0) { - return 1; - } else { - return tu_div_ceil(len, ep_size); - } -} - -TU_ATTR_ALWAYS_INLINE static inline uint8_t cal_next_pid(uint8_t pid, uint8_t packet_count) { - if (packet_count & 0x01) { - return pid ^ 0x02; // toggle DATA0 and DATA1 - } else { - return pid; - } -} - -//-------------------------------------------------------------------- -// -//-------------------------------------------------------------------- - -/* USB Data FIFO Layout - - The FIFO is split up into - - EPInfo: for storing DMA metadata (check dcd_dwc2.c for more details) - - 1 RX FIFO: for receiving data - - 1 TX FIFO for non-periodic (NPTX) - - 1 TX FIFO for periodic (PTX) - - We allocated TX FIFO from top to bottom (using top pointer), this to allow the RX FIFO to grow dynamically which is - possible since the free space is located between the RX and TX FIFOs. - - ----------------- ep_fifo_size - | HCDMAn | - |--------------|-- gdfifocfg.EPINFOBASE (max is ghwcfg3.dfifo_depth) - | Non-Periodic | - | TX FIFO | - |--------------|--- GNPTXFSIZ.addr (fixed size) - | Periodic | - | TX FIFO | - |--------------|--- HPTXFSIZ.addr (expandable downward) - | FREE | - | | - |--------------|-- GRXFSIZ (expandable upward) - | RX FIFO | - ---------------- 0 -*/ - -/* Programming Guide 2.1.2 FIFO RAM allocation - * RX - * - Largest-EPsize/4 + 2 (status info). recommended x2 if high bandwidth or multiple ISO are used. - * - 2 for transfer complete and channel halted status - * - 1 for each Control/Bulk out endpoint to Handle NAK/NYET (i.e max is number of host channel) - * - * TX non-periodic (NPTX) - * - At least largest-EPsize/4, recommended x2 - * - * TX periodic (PTX) - * - At least largest-EPsize*MulCount/4 (MulCount up to 3 for high-bandwidth ISO/interrupt) -*/ -static void dfifo_host_init(uint8_t rhport) { - const dwc2_controller_t* dwc2_controller = &_dwc2_controller[rhport]; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - - // Scatter/Gather DMA mode is not yet supported. Buffer DMA only need 1 words per channel - const bool is_dma = dma_host_enabled(dwc2); - uint16_t dfifo_top = dwc2_controller->ep_fifo_size/4; - if (is_dma) { - dfifo_top -= ghwcfg2.num_host_ch; - } - - // fixed allocation for now, improve later: - // - ptx_largest is limited to 256 for FS since most FS core only has 1024 bytes total - bool is_highspeed = dwc2_core_is_highspeed(dwc2, TUSB_ROLE_HOST); - uint32_t nptx_largest = is_highspeed ? TUSB_EPSIZE_BULK_HS/4 : TUSB_EPSIZE_BULK_FS/4; - uint32_t ptx_largest = is_highspeed ? TUSB_EPSIZE_ISO_HS_MAX/4 : 256/4; - - uint16_t nptxfsiz = 2 * nptx_largest; - uint16_t rxfsiz = 2 * (ptx_largest + 2) + ghwcfg2.num_host_ch; - TU_ASSERT(dfifo_top >= (nptxfsiz + rxfsiz),); - uint16_t ptxfsiz = dfifo_top - (nptxfsiz + rxfsiz); - - dwc2->gdfifocfg = (dfifo_top << GDFIFOCFG_EPINFOBASE_SHIFT) | dfifo_top; - - dfifo_top -= rxfsiz; - dwc2->grxfsiz = rxfsiz; - - dfifo_top -= nptxfsiz; - dwc2->gnptxfsiz = tu_u32_from_u16(nptxfsiz, dfifo_top); - - dfifo_top -= ptxfsiz; - dwc2->hptxfsiz = tu_u32_from_u16(ptxfsiz, dfifo_top); -} +#include "dwc3_common.h" //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ -// optional hcd configuration, called by tuh_configure() -bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) { - (void) rhport; - (void) cfg_id; - (void) cfg_param; - - return true; -} - // Initialize controller to host mode -bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { - (void) rh_init; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - - tu_memclr(&_hcd_data, sizeof(_hcd_data)); - - // Core Initialization - const bool is_highspeed = dwc2_core_is_highspeed(dwc2, TUSB_ROLE_HOST); - const bool is_dma = dma_host_enabled(dwc2); - TU_ASSERT(dwc2_core_init(rhport, is_highspeed, is_dma)); - - //------------- 3.1 Host Initialization -------------// - - // work at max supported speed - dwc2->hcfg &= ~HCFG_FSLS_ONLY; - - // Enable HFIR reload - if (dwc2->gsnpsid >= DWC2_CORE_REV_2_92a) { - dwc2->hfir |= HFIR_RELOAD_CTRL; - } - - // force host mode and wait for mode switch - dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_FDMOD) | GUSBCFG_FHMOD; -#if CFG_TUSB_MCU == OPT_MCU_STM32N6 - // No hardware detection of Vbus B-session is available on the STM32N6 - dwc2->stm32_gccfg &= ~STM32_GCCFG_VBVALOVAL; -#endif - while ((dwc2->gintsts & GINTSTS_CMOD) != GINTSTS_CMODE_HOST) {} - - // configure fixed-allocated fifo scheme - dfifo_host_init(rhport); - - dwc2->hprt = HPRT_W1_MASK; // clear all write-1-clear bits - dwc2->hprt = HPRT_POWER; // turn on VBUS - - // Enable required interrupts - dwc2->gintmsk |= GINTSTS_OTGINT | GINTSTS_CONIDSTSCHNG | GINTSTS_HPRTINT | GINTSTS_HCINT | GINTSTS_DISCINT; - - // NPTX can hold at least 2 packet, change interrupt level to half-empty - uint32_t gahbcfg = dwc2->gahbcfg & ~GAHBCFG_TX_FIFO_EPMTY_LVL; - gahbcfg |= GAHBCFG_GINT; // Enable global interrupt - dwc2->gahbcfg = gahbcfg; - - return true; -} - -// Enable USB interrupt -void hcd_int_enable (uint8_t rhport) { - dwc2_int_set(rhport, TUSB_ROLE_HOST, true); -} - -// Disable USB interrupt -void hcd_int_disable(uint8_t rhport) { - dwc2_int_set(rhport, TUSB_ROLE_HOST, false); -} - -// Get frame number (1ms) -uint32_t hcd_frame_number(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - return dwc2->hfnum & HFNUM_FRNUM_Msk; -} - -//--------------------------------------------------------------------+ -// Port API -//--------------------------------------------------------------------+ - -// Get the current connect status of roothub port -bool hcd_port_connect_status(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - return dwc2->hprt & HPRT_CONN_STATUS; -} - -// Reset USB bus on the port. Return immediately, bus reset sequence may not be complete. -// Some port would require hcd_port_reset_end() to be invoked after 10ms to complete the reset sequence. -void hcd_port_reset(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - uint32_t hprt = dwc2->hprt & ~HPRT_W1_MASK; - hprt |= HPRT_RESET; - dwc2->hprt = hprt; -} - -// Complete bus reset sequence, may be required by some controllers -void hcd_port_reset_end(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - uint32_t hprt = dwc2->hprt & ~HPRT_W1_MASK; // skip w1c bits - hprt &= ~HPRT_RESET; - dwc2->hprt = hprt; -} - -// Get port link speed -tusb_speed_t hcd_port_speed_get(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const tusb_speed_t speed = hprt_speed_get(dwc2); - return speed; -} - -// HCD closes all opened endpoints belong to this device -void hcd_device_close(uint8_t rhport, uint8_t dev_addr) { - (void) rhport; - for (uint8_t i = 0; i < (uint8_t) CFG_TUH_DWC2_ENDPOINT_MAX; i++) { - hcd_endpoint_t* edpt = &_hcd_data.edpt[i]; - if (edpt->hcchar_bm.enable && edpt->hcchar_bm.dev_addr == dev_addr) { - tu_memclr(edpt, sizeof(hcd_endpoint_t)); - } - } -} - -//--------------------------------------------------------------------+ -// Endpoints API -//--------------------------------------------------------------------+ - -// Open an endpoint -bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t* desc_ep) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const tusb_speed_t rh_speed = hprt_speed_get(dwc2); - - tuh_bus_info_t bus_info; - tuh_bus_info_get(dev_addr, &bus_info); - - // find a free endpoint - const uint8_t ep_id = edpt_alloc(); - TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); - hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; - - dwc2_channel_char_t* hcchar_bm = &edpt->hcchar_bm; - hcchar_bm->ep_size = tu_edpt_packet_size(desc_ep); - hcchar_bm->ep_num = tu_edpt_number(desc_ep->bEndpointAddress); - hcchar_bm->ep_dir = tu_edpt_dir(desc_ep->bEndpointAddress); - hcchar_bm->low_speed_dev = (bus_info.speed == TUSB_SPEED_LOW) ? 1 : 0; - hcchar_bm->ep_type = desc_ep->bmAttributes.xfer; // ep_type matches TUSB_XFER_* - hcchar_bm->err_multi_count = 0; - hcchar_bm->dev_addr = dev_addr; - hcchar_bm->odd_frame = 0; - hcchar_bm->disable = 0; - hcchar_bm->enable = 1; - - dwc2_channel_split_t* hcsplt_bm = &edpt->hcsplt_bm; - hcsplt_bm->hub_port = bus_info.hub_port; - hcsplt_bm->hub_addr = bus_info.hub_addr; - hcsplt_bm->xact_pos = 0; - hcsplt_bm->split_compl = 0; - hcsplt_bm->split_en = (rh_speed == TUSB_SPEED_HIGH && bus_info.speed != TUSB_SPEED_HIGH) ? 1 : 0; - - edpt->speed = bus_info.speed; - edpt->next_pid = HCTSIZ_PID_DATA0; - if (desc_ep->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) { - edpt->uframe_interval = 1 << (desc_ep->bInterval - 1); - if (bus_info.speed == TUSB_SPEED_FULL) { - edpt->uframe_interval <<= 3; - } - } else if (desc_ep->bmAttributes.xfer == TUSB_XFER_INTERRUPT) { - if (bus_info.speed == TUSB_SPEED_HIGH) { - edpt->uframe_interval = 1 << (desc_ep->bInterval - 1); - } else { - edpt->uframe_interval = desc_ep->bInterval << 3; - } - } - - return true; -} - -bool hcd_edpt_close(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) { - (void) rhport; (void) daddr; (void) ep_addr; - return false; // TODO not implemented yet -} - -// clean up channel after part of transfer is done but the whole urb is not complete -static void channel_xfer_out_wrapup(dwc2_regs_t* dwc2, uint8_t ch_id) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - const dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - - const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; - edpt->next_pid = hctsiz.pid; // save PID - - /* Since hctsiz.xfersize field reflects the number of bytes transferred via the AHB, not the USB) - * For IN: we can use hctsiz.xfersize as remaining bytes. - * For OUT: Must use the hctsiz.pktcnt field to determine how much data has been transferred. This field reflects the - * number of packets that have been transferred via the USB. This is always an integral number of packets if the - * transfer was halted before its normal completion. - */ - const uint16_t remain_packets = hctsiz.packet_count; - const dwc2_channel_char_t hcchar = {.value = channel->hcchar}; - const uint16_t total_packets = cal_packet_count(edpt->buflen, hcchar.ep_size); - const uint16_t actual_bytes = (total_packets - remain_packets) * hcchar.ep_size; - - xfer->fifo_bytes = 0; - xfer->xferred_bytes += actual_bytes; - edpt->buffer += actual_bytes; - edpt->buflen -= actual_bytes; -} - -static bool channel_xfer_start(dwc2_regs_t* dwc2, uint8_t ch_id) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_char_t* hcchar_bm = &edpt->hcchar_bm; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - bool const is_period = channel_is_periodic(edpt->hcchar); - - // clear previous state - xfer->fifo_bytes = 0; - - // hchar: restore but don't enable yet - if (is_period) { - hcchar_bm->odd_frame = 1 - (dwc2->hfnum & 1); // transfer on next frame - } - channel->hcchar = (edpt->hcchar & ~HCCHAR_CHENA); - - // hctsiz: zero length packet still count as 1 - const uint16_t packet_count = cal_packet_count(edpt->buflen, hcchar_bm->ep_size); - dwc2_channel_tsize_t hctsiz = {.value = 0}; - hctsiz.pid = edpt->next_pid; // next PID is set in transfer complete interrupt - hctsiz.packet_count = packet_count; - hctsiz.xfer_size = edpt->buflen; - if (edpt->next_do_ping && edpt->speed == TUSB_SPEED_HIGH && - edpt->next_pid != HCTSIZ_PID_SETUP && hcchar_bm->ep_dir == TUSB_DIR_OUT) { - hctsiz.do_ping = 1; - } - channel->hctsiz = hctsiz.value; - edpt->next_do_ping = 0; - - // pre-calculate next PID based on packet count, adjusted in transfer complete interrupt if short packet - if (hcchar_bm->ep_num == 0) { - edpt->next_pid = HCTSIZ_PID_DATA1; // control data and status stage always start with DATA1 - } else { - edpt->next_pid = cal_next_pid(edpt->next_pid, packet_count); - } - - channel->hcsplt = edpt->hcsplt; - channel->hcint = 0xFFFFFFFFU; // clear all channel interrupts - - if (dma_host_enabled(dwc2)) { - uint32_t hcintmsk = HCINT_HALTED; - channel->hcintmsk = hcintmsk; - dwc2->haintmsk |= TU_BIT(ch_id); - - channel->hcdma = (uint32_t) edpt->buffer; - - if (hcchar_bm->ep_dir == TUSB_DIR_IN) { - channel_send_in_token(dwc2, channel); - } else { - hcd_dcache_clean(edpt->buffer, edpt->buflen); - channel->hcchar |= HCCHAR_CHENA; - } - } else { - uint32_t hcintmsk = HCINT_NAK | HCINT_XACT_ERR | HCINT_STALL | HCINT_XFER_COMPLETE | HCINT_DATATOGGLE_ERR; - if (hcchar_bm->ep_dir == TUSB_DIR_IN) { - hcintmsk |= HCINT_BABBLE_ERR | HCINT_DATATOGGLE_ERR | HCINT_ACK; - } else { - hcintmsk |= HCINT_NYET; - if (edpt->hcsplt_bm.split_en || hctsiz.do_ping) { - hcintmsk |= HCINT_ACK; - } - } - channel->hcintmsk = hcintmsk; - dwc2->haintmsk |= TU_BIT(ch_id); +bool dwc3_init() { - // enable channel for slave mode: - // - OUT: it will enable corresponding FIFO channel - // - IN : it will write an IN request to the Non-periodic Request Queue, this will have dwc2 trying to send - // IN Token. If we got NAK, we have to re-enable the channel again in the interrupt. Due to the way usbh stack only - // call hcd_edpt_xfer() once, we will need to manage de-allocate/re-allocate IN channel dynamically. - if (hcchar_bm->ep_dir == TUSB_DIR_IN) { - channel_send_in_token(dwc2, channel); - } else { - channel->hcchar |= HCCHAR_CHENA; - if (edpt->buflen > 0) { - // To prevent conflict with other channel, we will enable periodic/non-periodic FIFO empty interrupt accordingly - // And write packet in the interrupt handler - dwc2->gintmsk |= (is_period ? GINTSTS_PTX_FIFO_EMPTY : GINTSTS_NPTX_FIFO_EMPTY); - } - } - } - - return true; -} - -// kick-off transfer with an endpoint -static bool edpt_xfer_kickoff(dwc2_regs_t* dwc2, uint8_t ep_id) { - uint8_t ch_id = channel_alloc(dwc2); - TU_ASSERT(ch_id < 16); // all channel are in used - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - xfer->ep_id = ep_id; - xfer->result = XFER_RESULT_INVALID; - - return channel_xfer_start(dwc2, ch_id); -} - -// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked -bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint8_t ep_num = tu_edpt_number(ep_addr); - const uint8_t ep_dir = tu_edpt_dir(ep_addr); - - uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir); - TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); - hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; - - edpt->buffer = buffer; - edpt->buflen = buflen; - - if (ep_num == 0) { - // update ep_dir since control endpoint can switch direction - edpt->hcchar_bm.ep_dir = ep_dir; - } - - return edpt_xfer_kickoff(dwc2, ep_id); -} - -// Abort a queued transfer. Note: it can only abort transfer that has not been started -// Return true if a queued transfer is aborted, false if there is no transfer to abort -bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint8_t ep_num = tu_edpt_number(ep_addr); - const uint8_t ep_dir = tu_edpt_dir(ep_addr); - const uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir); - TU_VERIFY(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); - - // hcd_int_disable(rhport); - - // Find enabled channeled and disable it, channel will be de-allocated in the interrupt handler - const uint8_t ch_id = channel_find_enabled(dwc2, dev_addr, ep_num, ep_dir); - if (ch_id < 16) { - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - channel_disable(dwc2, channel); - } - - // hcd_int_enable(rhport); - - return true; -} - -// Submit a special transfer to send 8-byte Setup Packet, when complete hcd_event_xfer_complete() must be invoked -bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, const uint8_t setup_packet[8]) { - uint8_t ep_id = edpt_find_opened(dev_addr, 0, TUSB_DIR_OUT); - TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); // no opened endpoint - hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; - edpt->next_pid = HCTSIZ_PID_SETUP; - - return hcd_edpt_xfer(rhport, dev_addr, 0, (uint8_t*)(uintptr_t) setup_packet, 8); -} - -// clear stall, data toggle is also reset to DATA0 -bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { - (void) rhport; - const uint8_t ep_num = tu_edpt_number(ep_addr); - const uint8_t ep_dir = tu_edpt_dir(ep_addr); - const uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir); - TU_VERIFY(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); - hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; - - edpt->next_pid = HCTSIZ_PID_DATA0; - - return true; -} - -//-------------------------------------------------------------------- -// HCD Event Handler -//-------------------------------------------------------------------- - -// retry an IN transfer, channel must be halted -static void channel_xfer_in_retry(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - dwc2_channel_char_t hcchar = {.value = channel->hcchar}; - - if (channel_is_periodic(hcchar.value)){ - const dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; - // retry immediately for periodic split NYET if we haven't reach max retry - if (hcsplt.split_en && hcsplt.split_compl && (hcint & HCINT_NYET || xfer->halted_nyet)) { - xfer->period_split_nyet_count++; - xfer->halted_nyet = 0; - if (xfer->period_split_nyet_count < HCD_XFER_PERIOD_SPLIT_NYET_MAX) { - hcchar.odd_frame = 1 - (dwc2->hfnum & 1); // transfer on next frame - channel->hcchar = hcchar.value; - channel_send_in_token(dwc2, channel); - return; - } else { - // too many NYET, de-allocate channel with below code - xfer->period_split_nyet_count = 0; - } - } - - const uint32_t ucount = (hprt_speed_get(dwc2) == TUSB_SPEED_HIGH ? 1 : 8); - if (edpt->uframe_interval == ucount) { - // retry on next frame if bInterval is 1 - hcchar.odd_frame = 1 - (dwc2->hfnum & 1); - channel->hcchar = hcchar.value; - channel_send_in_token(dwc2, channel); - } else { - // otherwise, de-allocate channel, enable SOF set frame counter for later transfer - const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; - edpt->next_pid = hctsiz.pid; // save PID - edpt->uframe_countdown = edpt->uframe_interval - ucount; - // enable SOF interrupt if not already enabled - if (!(dwc2->gintmsk & GINTMSK_SOFM)) { - dwc2->gintsts = GINTSTS_SOF; - dwc2->gintmsk |= GINTMSK_SOFM; - } - // already halted, de-allocate channel (called from DMA isr) - channel_dealloc(dwc2, ch_id); - } - } else { - // for control/bulk: retry immediately - channel_send_in_token(dwc2, channel); - } -} - -#if CFG_TUSB_DEBUG -TU_ATTR_ALWAYS_INLINE static inline void print_hcint(uint32_t hcint) { - const char* str[] = { - "XFRC", "HALTED", "AHBERR", "STALL", - "NAK", "ACK", "NYET", "XERR", - "BBLERR", "FRMOR", "DTERR", "BNA", - "XCSERR", "DESC_LST" - }; - - for(uint32_t i=0; i<14; i++) { - if (hcint & TU_BIT(i)) { - TU_LOG1("%s ", str[i]); - } - } - TU_LOG1("\r\n"); -} -#endif + printf("DWC3 Init start\r\n"); + dwc3_gbl_regs_t* dwc3 = (dwc3_gbl_regs_t*) (uintptr_t) _dwc3_controller[0].reg_base; -#if CFG_TUH_DWC2_SLAVE_ENABLE -static void handle_rxflvl_irq(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); + const dwc3_ghwparams0_t ghwparams0 = {.value = dwc3->ghwparams0.value}; + const dwc3_ghwparams1_t ghwparams1 = {.value = dwc3->ghwparams1.value}; + const dwc3_ghwparams3_t ghwparams3 = {.value = dwc3->ghwparams3.value}; - // Pop control word off FIFO - const dwc2_grxstsp_t grxstsp = {.value= dwc2->grxstsp}; - const uint8_t ch_id = grxstsp.ep_ch_num; - - switch (grxstsp.packet_status) { - case GRXSTS_PKTSTS_RX_DATA: { - // In packet received, pop this entry --> ACK interrupt - const uint16_t byte_count = grxstsp.byte_count; - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX,); - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - - if (byte_count) { - dfifo_read_packet(dwc2, edpt->buffer + xfer->xferred_bytes, byte_count); - xfer->xferred_bytes += byte_count; - xfer->fifo_bytes = byte_count; - } + switch (ghwparams3.ghwparams3_1_0) { + case DWC3_SS_PHY_3_0: + INFO("Device supportes USB 3.0 Only"); break; - } - case GRXSTS_PKTSTS_RX_COMPLETE: - // In transfer complete: After this entry is popped from the rx FIFO, dwc2 asserts a Transfer Completed - // interrupt --> handle_channel_irq() + case DWC3_SS_PHY_3_1: + INFO("Device supportes USB 3.1 Gen1"); break; - case GRXSTS_PKTSTS_HOST_DATATOGGLE_ERR: - TU_ASSERT(0, ); // maybe try to change DToggle - break; - - case GRXSTS_PKTSTS_HOST_CHANNEL_HALTED: - // triggered when channel.hcchar_bm.disable is set - // TODO handle later + default: + INFO("Device does not support USB3.1"); break; - - default: break; // ignore other status } -} - -// return true if there is still pending data and need more ISR -static bool handle_txfifo_empty(dwc2_regs_t* dwc2, bool is_periodic) { - // Use period txsts for both p/np to get request queue space available (1-bit difference, it is small enough) - const dwc2_hptxsts_t txsts = {.value = (is_periodic ? dwc2->hptxsts : dwc2->hnptxsts)}; - - const uint8_t max_channel = dwc2_channel_count(dwc2); - for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - const dwc2_channel_char_t hcchar = {.value = channel->hcchar}; - // skip writing to FIFO if channel is expecting halted. - if (!(channel->hcintmsk & HCINT_HALTED) && (hcchar.ep_dir == TUSB_DIR_OUT)) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; - const uint16_t remain_packets = hctsiz.packet_count; - for (uint16_t i = 0; i < remain_packets; i++) { - const uint16_t remain_bytes = edpt->buflen - xfer->fifo_bytes; - const uint16_t xact_bytes = tu_min16(remain_bytes, hcchar.ep_size); - - // skip if there is not enough space in FIFO and RequestQueue. - // Packet's last word written to FIFO will trigger a request queue - if ((xact_bytes > (txsts.fifo_available << 2)) || (txsts.req_queue_available == 0)) { - return true; - } - - dfifo_write_packet(dwc2, ch_id, edpt->buffer + xfer->fifo_bytes, xact_bytes); - xfer->fifo_bytes += xact_bytes; - } - } - } - - return false; // no channel has pending data -} - -static bool handle_channel_in_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; - const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; - bool is_done = false; - - // if (hcsplt.split_en) { - // if (edpt->hcchar_bm.ep_num == 1) { - // TU_LOG1("Frame %u, ch %u: ep %u, hcint 0x%04lX ", dwc2->hfnum_bm.num, ch_id, hcsplt.ep_num, hcint); - // print_hcint(hcint); - // } - if (hcint & HCINT_XFER_COMPLETE) { - if (edpt->hcchar_bm.ep_num != 0) { - edpt->next_pid = hctsiz.pid; // save pid (already toggled) - } - - const uint16_t remain_packets = hctsiz.packet_count; - if (hcsplt.split_en && remain_packets && xfer->fifo_bytes == edpt->hcchar_bm.ep_size) { - // Split can only complete 1 transaction (up to 1 packet) at a time, schedule more - hcsplt.split_compl = 0; - channel->hcsplt = hcsplt.value; - } else { - xfer->result = XFER_RESULT_SUCCESS; - } + printf("HWPARAMS : %x, %x, %x\r\n", ghwparams0.value, ghwparams1.value, ghwparams3.value); - channel_disable(dwc2, channel); - } else if (hcint & (HCINT_XACT_ERR | HCINT_BABBLE_ERR | HCINT_STALL)) { - if (hcint & HCINT_STALL) { - xfer->result = XFER_RESULT_STALLED; - } else if (hcint & HCINT_BABBLE_ERR) { - xfer->result = XFER_RESULT_FAILED; - } else if (hcint & HCINT_XACT_ERR) { - xfer->err_count++; - channel->hcintmsk |= HCINT_ACK; - } - - channel_disable(dwc2, channel); - } else if (hcint & HCINT_NYET) { - // restart complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - xfer->halted_nyet = 1; - channel_disable(dwc2, channel); - } else if (hcint & HCINT_NAK) { - // NAK received, disable channel to flush all posted request and try again - if (hcsplt.split_en) { - hcsplt.split_compl = 0; // restart with start-split - channel->hcsplt = hcsplt.value; - } - - channel_disable(dwc2, channel); - } else if (hcint & HCINT_ACK) { - xfer->err_count = 0; - - if (hcsplt.split_en) { - if (!hcsplt.split_compl) { - // start split is ACK --> do complete split - channel->hcintmsk |= HCINT_NYET; - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel_send_in_token(dwc2, channel); - } else { - // do nothing for complete split with DATA, this will trigger XferComplete and handled there - } - } else { - // ACK with data - const uint16_t remain_packets = hctsiz.packet_count; - if (remain_packets) { - // still more packet to receive, also reset to start split - hcsplt.split_compl = 0; - channel->hcsplt = hcsplt.value; - channel_send_in_token(dwc2, channel); - } - } - } else if (hcint & HCINT_HALTED) { - channel->hcintmsk &= ~HCINT_HALTED; - if (xfer->result != XFER_RESULT_INVALID) { - is_done = true; - } else if (xfer->err_count == HCD_XFER_ERROR_MAX) { - xfer->result = XFER_RESULT_FAILED; - is_done = true; - } else { - // got here due to NAK or NYET - channel_xfer_in_retry(dwc2, ch_id, hcint); - } - } else if (hcint & HCINT_DATATOGGLE_ERR) { - xfer->err_count = 0; - TU_ASSERT(false); - } - return is_done; -} - -static bool handle_channel_out_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; - bool is_done = false; + switch (ghwparams3.ghwparams3_3_2) { + case DWC3_HS_PHY_UTMI: + case DWC3_HS_PHY_ULPI: + break; - if (hcint & HCINT_XFER_COMPLETE) { - is_done = true; - xfer->result = XFER_RESULT_SUCCESS; - channel->hcintmsk &= ~HCINT_ACK; - if (hcint & HCINT_NYET) { - // complete transfer with NYET, do ping next time - edpt->next_do_ping = 1; - } - } else if (hcint & HCINT_STALL) { - xfer->result = XFER_RESULT_STALLED; - channel_disable(dwc2, channel); - } else if (hcint & HCINT_NYET) { - xfer->err_count = 0; - if (hcsplt.split_en) { - // retry complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel->hcchar |= HCCHAR_CHENA; - } else { - edpt->next_do_ping = 1; - channel_xfer_out_wrapup(dwc2, ch_id); - channel_disable(dwc2, channel); - } - } else if (hcint & (HCINT_NAK | HCINT_XACT_ERR)) { - // clean up transfer so far, disable and start again later - channel_xfer_out_wrapup(dwc2, ch_id); - channel_disable(dwc2, channel); - if (hcint & HCINT_XACT_ERR) { - xfer->err_count++; - channel->hcintmsk |= HCINT_ACK; - } else { - // NAK disable channel to flush all posted request and try again - edpt->next_do_ping = 1; - xfer->err_count = 0; - } - } else if (hcint & HCINT_HALTED) { - channel->hcintmsk &= ~HCINT_HALTED; - if (xfer->result != XFER_RESULT_INVALID) { - is_done = true; - } else if (xfer->err_count == HCD_XFER_ERROR_MAX) { - xfer->result = XFER_RESULT_FAILED; - is_done = true; - } else { - // Got here due to NAK or NYET - TU_ASSERT(channel_xfer_start(dwc2, ch_id)); - } - } else if (hcint & HCINT_ACK) { - xfer->err_count = 0; - channel->hcintmsk &= ~HCINT_ACK; - if (hcsplt.split_en) { - if (!hcsplt.split_compl) { - // ACK for start split --> do complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel->hcchar |= HCCHAR_CHENA; - } - } else { - // ACK interrupt is only enabled for Split and PING - // ACK for PING, which mean device is ready to receive data - channel->hctsiz &= ~HCTSIZ_DOPING; // HC already cleared PING bit, but we clear anyway - channel->hcchar |= HCCHAR_CHENA; + case DWC3_HS_PHY_UTMI_ULPI: { + dwc3_gusb2_phycfg_t gusb2_phycfg = {.value = dwc3->gusb2_phycfg.value}; + gusb2_phycfg.ulpi_utmi_sel = 1; + dwc3->gusb2_phycfg.value = gusb2_phycfg.value; + break; } - } - if (is_done) { - xfer->xferred_bytes += xfer->fifo_bytes; - xfer->fifo_bytes = 0; + default: + break; } - return is_done; -} -#endif - -#if CFG_TUH_DWC2_DMA_ENABLE -static bool handle_channel_in_dma(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_char_t hcchar = {.value = channel->hcchar}; - dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; - const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; - - bool is_done = false; - - // TU_LOG1("in hcint = %02lX\r\n", hcint); - - if (hcint & HCINT_HALTED) { - if (hcint & (HCINT_XFER_COMPLETE | HCINT_STALL | HCINT_BABBLE_ERR)) { - const uint16_t remain_bytes = (uint16_t) hctsiz.xfer_size; - const uint16_t remain_packets = hctsiz.packet_count; - const uint16_t actual_len = edpt->buflen - remain_bytes; - xfer->xferred_bytes += actual_len; - - is_done = true; - - if (hcint & HCINT_STALL) { - xfer->result = XFER_RESULT_STALLED; - } else if (hcint & HCINT_BABBLE_ERR) { - xfer->result = XFER_RESULT_FAILED; - } else if (hcsplt.split_en && remain_packets && actual_len == hcchar.ep_size) { - // Split can only complete 1 transaction (up to 1 packet) at a time, schedule more - is_done = false; - edpt->buffer += actual_len; - edpt->buflen -= actual_len; + dwc3_gctl_t gctl = {.value = dwc3->gctl.value}; + gctl.scaledown = 0; + switch (ghwparams1.ghwparams1_25_24) { + case 1: + gctl.dsblclkgtng = 0; + break; - hcsplt.split_compl = 0; - channel->hcsplt = hcsplt.value; - channel_xfer_in_retry(dwc2, ch_id, hcint); - } else { - xfer->result = XFER_RESULT_SUCCESS; - } + case 2: + gctl.gbl_hibernation_en = 1; + break; - xfer->err_count = 0; - channel->hcintmsk &= ~HCINT_ACK; - } else if (hcint & HCINT_XACT_ERR) { - xfer->err_count++; - if (xfer->err_count >= HCD_XFER_ERROR_MAX) { - is_done = true; - xfer->result = XFER_RESULT_FAILED; - } else { - channel->hcintmsk |= HCINT_ACK | HCINT_NAK | HCINT_DATATOGGLE_ERR; - hcsplt.split_compl = 0; - channel->hcsplt = hcsplt.value; - channel_xfer_in_retry(dwc2, ch_id, hcint); - } - } else if (hcint & HCINT_NYET) { - // Must handle nyet before nak or ack. Could get a nyet at the same time as either of those on a BULK/CONTROL - // OUT that started with a PING. The nyet takes precedence. - if (hcsplt.split_en) { - // split not yet mean hub has no data, retry complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel_xfer_in_retry(dwc2, ch_id, hcint); - } - } else if (hcint & HCINT_ACK) { - xfer->err_count = 0; - channel->hcintmsk &= ~HCINT_ACK; - if (hcsplt.split_en) { - // start split is ACK --> do complete split - // TODO: for ISO must use xact_pos to plan complete split based on microframe (up to 187.5 bytes/uframe) - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - if (channel_is_periodic(channel->hcchar)) { - hcchar.odd_frame = 1 - (dwc2->hfnum & 1); // transfer on next frame - channel->hcchar = hcchar.value; - } - channel_send_in_token(dwc2, channel); - } - } else if (hcint & (HCINT_NAK | HCINT_DATATOGGLE_ERR)) { - xfer->err_count = 0; - channel->hcintmsk &= ~(HCINT_NAK | HCINT_DATATOGGLE_ERR); - hcsplt.split_compl = 0; // restart with start-split - channel->hcsplt = hcsplt.value; - channel_xfer_in_retry(dwc2, ch_id, hcint); - } else if (hcint & HCINT_FARME_OVERRUN) { - // retry start-split in next binterval - channel_xfer_in_retry(dwc2, ch_id, hcint); - } + default: + break; } + dwc3->gctl.value = gctl.value; - return is_done; -} - -static bool handle_channel_out_dma(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - const dwc2_channel_char_t hcchar = {.value = channel->hcchar}; - dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; + switch (ghwparams0.ghwparams0_2_0) { + case DWC3_GHWPARAMS0_MODE_DRD: { + dwc3_gusb3_pipectl_t gusb3_pipectl = {.value = dwc3->gusb3_pipectl.value}; + gusb3_pipectl.suspendenable = 0; + dwc3->gusb3_pipectl.value = gusb3_pipectl.value; - bool is_done = false; + dwc3_gusb2_phycfg_t gusb2_phycfg = {.value = dwc3->gusb2_phycfg.value}; + gusb2_phycfg.suspendusb20 = 0; + dwc3->gusb2_phycfg.value = gusb2_phycfg.value; - // TU_LOG1("out hcint = %02lX\r\n", hcint); - - if (hcint & HCINT_HALTED) { - if (hcint & (HCINT_XFER_COMPLETE | HCINT_STALL)) { - is_done = true; - xfer->err_count = 0; - if (hcint & HCINT_XFER_COMPLETE) { - xfer->result = XFER_RESULT_SUCCESS; - xfer->xferred_bytes += edpt->buflen; - } else { - xfer->result = XFER_RESULT_STALLED; - channel_xfer_out_wrapup(dwc2, ch_id); - } - channel->hcintmsk &= ~HCINT_ACK; - } else if (hcint & HCINT_XACT_ERR) { - if (hcint & (HCINT_NAK | HCINT_NYET | HCINT_ACK)) { - xfer->err_count = 0; - // clean up transfer so far and start again - channel_xfer_out_wrapup(dwc2, ch_id); - channel_xfer_start(dwc2, ch_id); - } else { - xfer->err_count++; - if (xfer->err_count >= HCD_XFER_ERROR_MAX) { - xfer->result = XFER_RESULT_FAILED; - is_done = true; - } else { - // clean up transfer so far and start again - channel_xfer_out_wrapup(dwc2, ch_id); - channel_xfer_start(dwc2, ch_id); - } - } - } else if (hcint & HCINT_NYET) { - if (hcsplt.split_en && hcsplt.split_compl) { - // split not yet mean hub has no data, retry complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel->hcchar |= HCCHAR_CHENA; - } - } else if (hcint & HCINT_ACK) { - xfer->err_count = 0; - if (hcsplt.split_en && !hcsplt.split_compl) { - // start split is ACK --> do complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel->hcchar |= HCCHAR_CHENA; - } - } - } else if (hcint & HCINT_ACK) { - xfer->err_count = 0; - channel->hcintmsk &= ~HCINT_ACK; - } - - return is_done; -} -#endif + gctl.value = dwc3->gctl.value; + gctl.prtcapdir = USB_MODE_HOST; + dwc3->gctl.value = gctl.value; -static void handle_channel_irq(uint8_t rhport, bool in_isr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const bool is_dma = dma_host_enabled(dwc2); - const uint8_t max_channel = dwc2_channel_count(dwc2); + gctl.value = dwc3->gctl.value; + gctl.coresoftreset = 1; + dwc3->gctl.value = gctl.value; - for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { - if (tu_bit_test(dwc2->haint, ch_id)) { - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX,); - dwc2_channel_char_t hcchar = {.value = channel->hcchar}; + osal_task_delay(100); - const uint32_t hcint = channel->hcint; - channel->hcint = hcint; // clear interrupt + gctl.value = dwc3->gctl.value; + gctl.coresoftreset = 0; + dwc3->gctl.value = gctl.value; - bool is_done = false; - if (is_dma) { - #if CFG_TUH_DWC2_DMA_ENABLE - if (hcchar.ep_dir == TUSB_DIR_OUT) { - is_done = handle_channel_out_dma(dwc2, ch_id, hcint); - } else { - is_done = handle_channel_in_dma(dwc2, ch_id, hcint); - if (is_done && (channel->hcdma > xfer->xferred_bytes)) { - // hcdma is increased by word --> need to align4 - hcd_dcache_invalidate((void*) tu_align4(channel->hcdma - xfer->xferred_bytes), xfer->xferred_bytes); - } - } - #endif - } else { - #if CFG_TUH_DWC2_SLAVE_ENABLE - if (hcchar.ep_dir == TUSB_DIR_OUT) { - is_done = handle_channel_out_slave(dwc2, ch_id, hcint); - } else { - is_done = handle_channel_in_slave(dwc2, ch_id, hcint); - } - #endif - } + gusb2_phycfg.value = dwc3->gusb2_phycfg.value; + gusb2_phycfg.suspendusb20 = 1; + dwc3->gusb2_phycfg.value = gusb2_phycfg.value; - if (is_done) { - const uint8_t ep_addr = tu_edpt_addr(hcchar.ep_num, hcchar.ep_dir); - hcd_event_xfer_complete(hcchar.dev_addr, ep_addr, xfer->xferred_bytes, (xfer_result_t)xfer->result, in_isr); - channel_dealloc(dwc2, ch_id); - } + gusb3_pipectl.value = dwc3->gusb3_pipectl.value; + gusb3_pipectl.suspendenable = 1; + dwc3->gusb3_pipectl.value = gusb3_pipectl.value; + break; } - } -} - -// SOF is enabled for scheduled periodic transfer -static bool handle_sof_irq(uint8_t rhport, bool in_isr) { - (void) in_isr; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - dwc2->gintsts = GINTSTS_SOF; // Clear the SOF interrupt flag - - bool more_isr = false; - // If highspeed then SOF is 125us, else 1ms - const uint32_t ucount = (hprt_speed_get(dwc2) == TUSB_SPEED_HIGH ? 1 : 8); - - for(uint8_t ep_id = 0; ep_id < CFG_TUH_DWC2_ENDPOINT_MAX; ep_id++) { - hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; - if (edpt->hcchar_bm.enable && channel_is_periodic(edpt->hcchar) && edpt->uframe_countdown > 0) { - edpt->uframe_countdown -= tu_min32(ucount, edpt->uframe_countdown); - if (edpt->uframe_countdown == 0) { - if (!edpt_xfer_kickoff(dwc2, ep_id)) { - edpt->uframe_countdown = ucount; // failed to start, try again next frame - } - } + case DWC3_GHWPARAMS0_MODE_HOST: + break; - more_isr = true; - } + default: + ERROR("Unable to setup DWC3 in host mode"); + return false; } - return more_isr; + return true; } -// Config HCFG FS/LS clock and HFIR for SOF interval according to link speed (value is in PHY clock unit) -static void port0_enable(dwc2_regs_t* dwc2, tusb_speed_t speed) { - uint32_t hcfg = dwc2->hcfg & ~HCFG_FSLS_PHYCLK_SEL; - - const dwc2_gusbcfg_t gusbcfg = {.value = dwc2->gusbcfg}; - uint32_t phy_clock; - - if (gusbcfg.phy_sel) { - phy_clock = 48; // dedicated FS is 48Mhz - if (speed == TUSB_SPEED_LOW) { - hcfg |= HCFG_FSLS_PHYCLK_SEL_6MHZ; - } else { - hcfg |= HCFG_FSLS_PHYCLK_SEL_48MHZ; - } - } else { - if (gusbcfg.ulpi_utmi_sel) { - phy_clock = 60; // ULPI 8-bit is 60Mhz - } else { - // UTMI+ 16-bit is 30Mhz, 8-bit is 60Mhz - phy_clock = gusbcfg.phy_if16 ? 30 : 60; - - // Enable UTMI+ low power mode 48Mhz external clock if not highspeed - if (speed == TUSB_SPEED_HIGH) { - dwc2->gusbcfg &= ~GUSBCFG_PHYLPCS; - } else { - dwc2->gusbcfg |= GUSBCFG_PHYLPCS; - // may need to reset port - } - } - hcfg |= HCFG_FSLS_PHYCLK_SEL_30_60MHZ; - } - - dwc2->hcfg = hcfg; - - uint32_t hfir = dwc2->hfir & ~HFIR_FRIVL_Msk; - if (speed == TUSB_SPEED_HIGH) { - hfir |= 125*phy_clock - 1; // The "- 1" is the correct value. The Synopsys databook was corrected in 3.30a - } else { - hfir |= 1000*phy_clock - 1; - } - - dwc2->hfir = hfir; +#if 0 +// Enable USB interrupt +void hcd_int_enable (uint8_t rhport) { + dwc2_int_set(rhport, TUSB_ROLE_HOST, true); } -/* Handle Host Port interrupt, possible source are: - - Connection Detection - - Enable Change - - Over Current Change -*/ -static void handle_hprt_irq(uint8_t rhport, bool in_isr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const dwc2_hprt_t hprt_bm = {.value = dwc2->hprt}; - uint32_t hprt = hprt_bm.value & ~HPRT_W1_MASK; - - if (hprt_bm.conn_detected) { - // Port Connect Detect - hprt |= HPRT_CONN_DETECT; - - if (hprt_bm.conn_status) { - hcd_event_device_attach(rhport, in_isr); - } - } - - if (hprt_bm.enable_change) { - // Port enable change - hprt |= HPRT_ENABLE_CHANGE; - - if (hprt_bm.enable) { - // Port enable - const tusb_speed_t speed = hprt_speed_get(dwc2); - port0_enable(dwc2, speed); - } else { - // TU_ASSERT(false, ); - } - } - - dwc2->hprt = hprt; // clear interrupt +// Disable USB interrupt +void hcd_int_disable(uint8_t rhport) { + dwc2_int_set(rhport, TUSB_ROLE_HOST, false); } -/* Interrupt Hierarchy - HCINTn HPRT - | | - HAINT.CHn | - | | - GINTSTS : HCInt | PrtInt | NPTxFEmp | PTxFEmpp | RXFLVL | SOF -*/ -void hcd_int_handler(uint8_t rhport, bool in_isr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint32_t gintmsk = dwc2->gintmsk; - const uint32_t gintsts = dwc2->gintsts & gintmsk; - - // TU_LOG1_HEX(gintsts); - - if (gintsts & GINTSTS_CONIDSTSCHNG) { - // Connector ID status change - dwc2->gintsts = GINTSTS_CONIDSTSCHNG; - - //if (dwc2->gotgctl) - // dwc2->hprt = HPRT_POWER; // power on port to turn on VBUS - //dwc2->gintmsk |= GINTMSK_PRTIM; - // TODO wait for SRP if OTG - } - - if (gintsts & GINTSTS_SOF) { - const bool more_sof = handle_sof_irq(rhport, in_isr); - if (!more_sof) { - dwc2->gintmsk &= ~GINTSTS_SOF; - } - } - - if (gintsts & GINTSTS_HPRTINT) { - // Host port interrupt: source is cleared in HPRT register - // TU_LOG1_HEX(dwc2->hprt); - handle_hprt_irq(rhport, in_isr); - } - - if (gintsts & GINTSTS_HCINT) { - // Host Channel interrupt: source is cleared in HCINT register - // must be handled after TX FIFO empty - handle_channel_irq(rhport, in_isr); - } - - if (gintsts & GINTSTS_DISCINT) { - // Device disconnected - dwc2->gintsts = GINTSTS_DISCINT; - - if (!(dwc2->hprt & HPRT_CONN_STATUS)) { - hcd_event_device_remove(rhport, in_isr); - } - } - -#if CFG_TUH_DWC2_SLAVE_ENABLE - // RxFIFO non-empty interrupt handling - if (gintsts & GINTSTS_RXFLVL) { - // RXFLVL bit is read-only - dwc2->gintmsk &= ~GINTSTS_RXFLVL; // disable RXFLVL interrupt while reading - - do { - handle_rxflvl_irq(rhport); // read all packets - } while(dwc2->gintsts & GINTSTS_RXFLVL); - - dwc2->gintmsk |= GINTSTS_RXFLVL; - } - - if (gintsts & GINTSTS_NPTX_FIFO_EMPTY) { - // NPTX FIFO empty interrupt, this is read-only and cleared by hardware when FIFO is written - const bool more_nptxfe = handle_txfifo_empty(dwc2, false); - if (!more_nptxfe) { - // no more pending packet, disable interrupt - dwc2->gintmsk &= ~GINTSTS_NPTX_FIFO_EMPTY; - } - } - - if (gintsts & GINTSTS_PTX_FIFO_EMPTY) { - // PTX FIFO empty interrupt, this is read-only and cleared by hardware when FIFO is written - const bool more_ptxfe = handle_txfifo_empty(dwc2, true); - if (!more_ptxfe) { - // no more pending packet, disable interrupt - dwc2->gintmsk &= ~GINTSTS_PTX_FIFO_EMPTY; - } - } #endif -} - #endif From 88b447fe5847793cb1bf3695f006f63a1be7c69c Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Tue, 17 Nov 2026 16:20:12 +0530 Subject: [PATCH 04/17] src: portable: xhci: initial commit for xHCI port Signed-off-by: Sourav Raj K K --- apps/msc_app.c | 4 +- apps/usb_main.c | 3 +- hw/bsp/socfpga/family.cmake | 5 +- src/common/tusb_mcu.h | 1 + src/portable/synopsys/dwc3/dwc3_socfpga.h | 14 + src/portable/synopsys/dwc3/hcd_dwc3.c | 17 +- src/portable/xhci/xhci.c | 598 +++++++++++++++++++++- src/portable/xhci/xhci.h | 2 +- src/portable/xhci/xhci_api.h | 20 + src/portable/xhci/xhci_common.c | 83 +++ src/portable/xhci/xhci_common.h | 86 ++++ 11 files changed, 818 insertions(+), 15 deletions(-) create mode 100644 src/portable/xhci/xhci_api.h create mode 100644 src/portable/xhci/xhci_common.c create mode 100644 src/portable/xhci/xhci_common.h diff --git a/apps/msc_app.c b/apps/msc_app.c index 8326d4fa4..8483fdd5d 100644 --- a/apps/msc_app.c +++ b/apps/msc_app.c @@ -31,6 +31,8 @@ #define MSC_BLOCK_SIZE (512) +void hcd_device_close(uint8_t rhport, uint8_t dev_addr); + static volatile int msc_mount_complete = 0; static scsi_inquiry_resp_t inquiry_resp; static volatile bool status_flag_cb = true; @@ -97,7 +99,7 @@ void tuh_msc_umount_cb(uint8_t dev_addr) tuh_bus_info_get(dev_addr, &dev_info); if( dev_info.rhport != SOCFPGA_USB2_OTG_PORT ) { - hcd_dwc3_device_close(dev_info.rhport); + hcd_device_close(dev_info.rhport, 0); } PRINT("A MassStorage device is unmounted, address - %d\r\n", dev_addr); } diff --git a/apps/usb_main.c b/apps/usb_main.c index 904711b56..7eb77b3d3 100644 --- a/apps/usb_main.c +++ b/apps/usb_main.c @@ -39,7 +39,7 @@ void usb_task(void *arg) .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_AUTO }; - +#if 0 /*initialize host stack for usb otg HS port*/ if (!tusb_init(USB_OTG_PORT, &host_init)) { @@ -50,6 +50,7 @@ void usb_task(void *arg) { PRINT("USB OTG port initialized successfully"); } +#endif /*initialize host stack for usb3 SS port*/ if (!tusb_init(USB3_SS_PORT, &host_init)) diff --git a/hw/bsp/socfpga/family.cmake b/hw/bsp/socfpga/family.cmake index de31423a7..87a349a14 100644 --- a/hw/bsp/socfpga/family.cmake +++ b/hw/bsp/socfpga/family.cmake @@ -33,7 +33,7 @@ target_include_directories(agilex5-tinyusb PUBLIC tinyusb_target_add(agilex5-tinyusb) target_sources(agilex5-tinyusb PUBLIC - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/hcd_socfpga.c + #${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/hcd_socfpga.c # Synopsys dwc2 controller ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc2/hcd_dwc2.c @@ -42,9 +42,8 @@ target_include_directories(agilex5-tinyusb PUBLIC # Synopsys dwc3 controller ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/hcd_dwc3.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc3/hcd_dwc3.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc3/dwc3_common.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_common.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_cap.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_commands.c diff --git a/src/common/tusb_mcu.h b/src/common/tusb_mcu.h index e61b99e52..97a922a9b 100644 --- a/src/common/tusb_mcu.h +++ b/src/common/tusb_mcu.h @@ -623,6 +623,7 @@ #elif TU_CHECK_MCU(OPT_MCU_SOCFPGA) #define TUP_USBIP_DWC2 + #define TUP_USBIP_XHCI #define CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT 64 #endif diff --git a/src/portable/synopsys/dwc3/dwc3_socfpga.h b/src/portable/synopsys/dwc3/dwc3_socfpga.h index 325242067..2c7371fb8 100644 --- a/src/portable/synopsys/dwc3/dwc3_socfpga.h +++ b/src/portable/synopsys/dwc3/dwc3_socfpga.h @@ -34,6 +34,9 @@ extern "C" { #if CFG_TUSB_MCU == OPT_MCU_SOCFPGA #define SOCFPGA_USB3_REG_BASE (0x1100C100U) #define OTG_HS_IRQn 126 // IRQ num for USB1 = 126 + #include "socfpga_interrupt.h" + #include "socfpga_interrupt_priority.h" + #include "socfpga_rst_mngr.h" #else #error "Unsupported MCUs" #endif @@ -44,6 +47,17 @@ static const dwc3_controller_t _dwc3_controller[] = { { .reg_base = SOCFPGA_USB3_REG_BASE, .irqnum = OTG_HS_IRQn, }, }; +//--------------------------------------------------------------------+ +// Controller bring-up +//--------------------------------------------------------------------+ +TU_ATTR_ALWAYS_INLINE static inline bool dwc3_mcu_init(uint8_t rhport) { + (void) rhport; + if (rstmgr_deassert_reset(_dwc3_controller[0].irqnum) != 0) { + return false; + } + return true; +} + #ifdef __cplusplus } #endif diff --git a/src/portable/synopsys/dwc3/hcd_dwc3.c b/src/portable/synopsys/dwc3/hcd_dwc3.c index 4020a60e6..7e5bf7b5e 100644 --- a/src/portable/synopsys/dwc3/hcd_dwc3.c +++ b/src/portable/synopsys/dwc3/hcd_dwc3.c @@ -31,17 +31,24 @@ #include "host/hcd.h" #include "host/usbh.h" #include "dwc3_common.h" +#include "xhci_api.h" //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ // Initialize controller to host mode -bool dwc3_init() { +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + + (void) rh_init; + + if (rhport == 1) + return true; - printf("DWC3 Init start\r\n"); dwc3_gbl_regs_t* dwc3 = (dwc3_gbl_regs_t*) (uintptr_t) _dwc3_controller[0].reg_base; + dwc3_mcu_init(rhport); + const dwc3_ghwparams0_t ghwparams0 = {.value = dwc3->ghwparams0.value}; const dwc3_ghwparams1_t ghwparams1 = {.value = dwc3->ghwparams1.value}; const dwc3_ghwparams3_t ghwparams3 = {.value = dwc3->ghwparams3.value}; @@ -136,6 +143,12 @@ bool dwc3_init() { return false; } + if (xhci_init() == false) + { + ERROR("xHCI init failed !!!"); + return false; + } + return true; } diff --git a/src/portable/xhci/xhci.c b/src/portable/xhci/xhci.c index 62b2a64d9..897bdb48e 100644 --- a/src/portable/xhci/xhci.c +++ b/src/portable/xhci/xhci.c @@ -1,11 +1,90 @@ /* - * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * The MIT License (MIT) * - * SPDX-License-Identifier: MIT-0 + * Copyright (c) 2021 Koji Kitayama + * Portions copyrighted (c) 2021 Roland Winistoerfer * - * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. */ +#include "tusb_option.h" + +#if CFG_TUH_ENABLED && defined(TUP_USBIP_XHCI) + +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ +#include "osal/osal.h" + +#include "host/hcd.h" +#include "host/usbh.h" +#include "host/usbh_pvt.h" + +#include "xhci.h" +#include "osal.h" +#include "osal_log.h" + +#include +#include "tusb.h" +#include "tusb_private.h" +#include "xhci_common.h" + +#if CFG_TUSB_MCU == OPT_MCU_SOCFPGA + #include "socfpga_defines.h" + #include "xhci_events.h" + #include "xhci_commands.h" + #include "xhci_endpoints.h" + #include "xhci_interrupts.h" + #include "xhci_doorbell.h" + #include "socfpga_cache.h" +#endif + +typedef struct +{ + uint8_t *buffer; + uint32_t buflen; +} hcd_dwc3_endpoint_t; + +#define XHCI_DCI_MAX 31 +hcd_dwc3_endpoint_t ep_data[XHCI_DCI_MAX]; + +static void hcd_xhci_set_configuration(); +static void hcd_dwc3_update_device_address( uint8_t daddr ); + +struct xhci_data xhci_handle __attribute__((aligned(64))); +static struct xhci_int_desc usb3_int_desc; +static tusb_control_request_t ctrl_req; +static int usb_set_config = 0; +uint8_t device_addr = 0; + + +//--------------------------------------------------------------------+ +// INCLUDE +//--------------------------------------------------------------------+ +#include "osal/osal.h" + +#include "host/hcd.h" +#include "host/usbh.h" +#include "host/usbh_pvt.h" + #include "xhci.h" #include "socfpga_defines.h" #include "osal.h" @@ -154,11 +233,29 @@ int xhci_reset(void) return 0; } -bool xhci_init(struct xhci_data *xhci) +bool xhci_init() { int ret; - get_xhc_cap_params(xhci); + xhci_int_ptr_t usb3_int_ptr = &usb3_int_desc; + + usb3_int_ptr->int_handler = tusb_int_handler; + if (register_usb3ISR(usb3_int_ptr) == false) + { + return false; + } + + ret = init_hcd_params(); + if (ret != 0) + { + ERROR("hcd error -%d", ret); + return false; + } + + //clear xHCI data structure members + tu_memclr(&xhci_handle, sizeof(xhci_handle)); + + get_xhc_cap_params(&xhci_handle); if(wait_for_controller_ready() != 0) { @@ -174,11 +271,498 @@ bool xhci_init(struct xhci_data *xhci) configure_xhci_max_slots(); - alloc_xhci_contexts(xhci); + alloc_xhci_contexts(&xhci_handle); - init_xhci_context_params(xhci); + init_xhci_context_params(&xhci_handle); start_xhci_controller(); return true; } + +bool hcd_edpt_close(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) +{ + (void)rhport; + (void)daddr; + (void)ep_addr; + return true; +} + +void hcd_int_enable( uint8_t rhport ) +{ + if(rhport == 1) + enable_xhci_interrupts(); +} + +void hcd_int_disable( uint8_t rhport ) +{ + (void) rhport; + /* disable_xhci_interrupts(); */ +} + +/*--------------------------------------------------------------------+ + * Port API + *--------------------------------------------------------------------+*/ +bool hcd_port_connect_status( uint8_t rhport ) +{ + bool ret; + + ret = xhci_port_status(rhport); + + return ret; +} + +void hcd_port_reset( uint8_t rhport ) +{ + if(rhport == 1) + reset_xhci_port(rhport); +} + +static bool hcd_enable_slot( void ) +{ + enable_slot_command(xhci_handle.xcr_ring); + + if (wait_for_command_completion_event(&xhci_handle, + ENABLE_SLOT_CMD) != 0) + { + return false; + } + + return true; +} + +static bool hcd_send_address_cmd( void ) +{ + int ret; + + update_device_dev_speed(&xhci_handle); + + ret = init_input_device_context(&xhci_handle); + if (ret != 0) + { + ERROR("XHCI Error -%d!!!", ret); + return false; + } + + update_dcbaa_entry(&xhci_handle); + + set_device_address(&xhci_handle); + + if (wait_for_command_completion_event(&xhci_handle, + ADDRESS_DEVICE_CMD) != 0) + { + return false; + } + + update_device_address(&xhci_handle); + + if (xhci_handle.dev_data.dev_addr == 0U) + { + return false; /* device address can not be zero after address command is sent */ + } + + display_xhci_device_params(&xhci_handle.dev_data); + display_ip_context(xhci_handle.ip_ctx); + display_op_context(xhci_handle.op_ctx); + display_event_trbs(&xhci_handle); + + return true; +} + +static void hcd_dwc3_update_device_address( uint8_t daddr ) +{ + device_addr = daddr; +} + +void hcd_port_reset_end( uint8_t rhport ) +{ + if ( rhport == (uint32_t) SOCFPGA_USB3_HS_PORT ) + { + is_xhci_port_reset_end(rhport); + } + + hcd_enable_slot(); + + hcd_send_address_cmd(); +} + +tusb_speed_t hcd_port_speed_get( uint8_t rhport ) +{ + uint8_t dev_speed; + tusb_speed_t ret; + + dev_speed = get_xhc_port_speed(rhport); + switch (dev_speed) + { + case 4: + ret = TUSB_SPEED_SS; + break; + case 3: + ret = TUSB_SPEED_HIGH; + break; + case 2: + ret = TUSB_SPEED_FULL; + break; + case 1: + ret = TUSB_SPEED_LOW; + break; + default: + ret = TUSB_SPEED_INVALID; + break; + } + return ret; +} + +void hcd_device_close(uint8_t rhport, uint8_t dev_addr) +{ + if (dev_addr == 0) + return; + + (void)dev_addr; + uint32_t slotid; + + if (rhport == SOCFPGA_USB3_SS_PORT) + { + /* Issue WR for usb3 ports only */ + xhci_warm_reset(rhport); + } + + slotid = xhci_handle.dev_data.slot_id; + + if (slotid != 0U) + { + disable_slot_command(xhci_handle.xcr_ring, slotid); + + if (wait_for_command_completion_event(&xhci_handle, + DISABLE_SLOT_CMD) != 0) + { + ERROR("xHCI command failed"); + return; + } + + dealloc_usb_port(&xhci_handle); + device_addr = 0U; + usb_set_config = 0; + } +} + +/*--------------------------------------------------------------------+ + * Endpoints API + *--------------------------------------------------------------------+*/ +static void hcd_xhci_set_configuration() +{ + update_xhc_slot_context(&xhci_handle); + + init_xhc_endpoint_context(&xhci_handle, BULK_OUT); + + init_xhc_endpoint_context(&xhci_handle, BULK_IN); + + configure_endpoint(&xhci_handle); + + if (wait_for_command_completion_event(&xhci_handle, + CONFIGURE_ENDPOINT_CMD) != 0) + { + return; + } +} + +bool hcd_setup_send( uint8_t rhport, uint8_t daddr, uint8_t const setup_packet[ 8 ] ) +{ + (void)rhport; + memcpy(&ctrl_req, &setup_packet[0], sizeof(ctrl_req)); + + if ((tusb_request_code_t) setup_packet[ 1 ] == TUSB_REQ_SET_CONFIGURATION) + { + hcd_xhci_set_configuration(); + usb_set_config = 1; + } + + if ((tusb_request_code_t) setup_packet[ 1 ] == TUSB_REQ_SET_ADDRESS) + { + hcd_dwc3_update_device_address(ctrl_req.wValue); + } + hcd_event_xfer_complete(daddr, 0, 8, XFER_RESULT_SUCCESS, true); + + return true; +} + +bool hcd_edpt_open( uint8_t rhport, uint8_t daddr, tusb_desc_endpoint_t const *ep_desc ) +{ + (void) rhport; + (void) daddr; + (void) ep_desc; + + return true; +} + +bool hcd_edpt_xfer(uint8_t rhport, uint8_t daddr, uint8_t ep_addr, uint8_t * buffer, uint32_t buflen) +{ + const uint8_t ep_num = tu_edpt_number(ep_addr); + const unsigned dir = (uint32_t) tu_edpt_dir(ep_addr); + const uint8_t ep_dci = get_ep_dci(ep_addr); + + (void)rhport; + // There is no separate data stage for xHCI controller. Hence skip the tinyusb enumeration step for data stage + if( buffer == NULL && (buflen == 0) && (usb_set_config == 0)) + { + if( usb_set_config == 1 ) + { + usb_set_config = 0; + } + hcd_event_xfer_complete(daddr, ep_num, 8, XFER_RESULT_SUCCESS, true); + return true; + } + + ep_data[ep_dci].buffer = buffer; + ep_data[ep_dci].buflen = buflen; + + if( ep_num == 0 ) + { + configure_setup_stage(&xhci_handle, buffer, (usb_control_request_t *)&ctrl_req); + ring_xhci_ep0_db(&xhci_handle.op_regs); + } + else + { + if( dir == TUSB_DIR_OUT ) + { + cache_force_write_back(buffer, buflen); + } + endpoint_transfer(&xhci_handle, (int) ep_num, (uint8_t) dir, buffer, buflen); + } + + return true; +} + +bool hcd_edpt_abort_xfer( uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr ) +{ + (void) rhport; + (void) dev_addr; + (void) ep_addr; + + return false; +} + +static void handle_endpoint_transfer(uint8_t ep_dci, uint8_t ep_addr) +{ + uint8_t *buffer = ep_data[ep_dci].buffer; + uint32_t buflen = ep_data[ep_dci].buflen; + const unsigned dir = (uint32_t) tu_edpt_dir(ep_addr); + const uint8_t ep_num = tu_edpt_number(ep_addr); + + if(ep_num == 0 && buflen != 0) + { + cache_force_invalidate(buffer, buflen); + } + + if( dir == TUSB_DIR_IN ) + { + cache_force_invalidate(buffer, buflen); + } + +} + +void hcd_int_handler( uint8_t rhport, bool in_isr ) +{ + (void) rhport; + /* + * array to convert XHCI DCI to corresponding endpoint address for the + * tinyusb stack + */ + const uint8_t DCI2EP[ 30 ] = + { + 0x00, 0x01, 0x81, 0x02, 0x82, 0x3, 0x83, + 0x04, 0x84, 0x05, 0x85, 0x06, 0x86 + }; + uint8_t ep_num; + int ep_dci; + + xhci_event_trb_type_t trb_id; + + xpsc_event_t psc_event; + xtc_event_t tr_event; + xcc_event_t cc_event; + xhci_psceg_params_t rh_params; + + xhci_event_trb_t event_data; + + event_data = get_xhc_event(&xhci_handle); + + trb_id = + (xhci_event_trb_type_t) event_data.event_trb.trb_control_field. + trb_type; + + switch (trb_id) + { + case TRANSFER_EVENT: + tr_event = event_data.tr_event; + if (tr_event.tc_status_params.compl_code == (uint32_t)EVENT_SUCCESS) + { + uint32_t xfer_bytes = tr_event.tc_status_params.transfer_len; + ep_dci = (int) event_data.tr_event.tc_ctrl_params.ep_dci; + ep_num = DCI2EP[ ep_dci - 1 ]; + handle_endpoint_transfer(ep_dci, ep_num); + hcd_event_xfer_complete(device_addr, ep_num, xfer_bytes, XFER_RESULT_SUCCESS, + true); + } + break; + + case PORT_STATUS_CHANGE_EVENT: + psc_event = event_data.psc_event; + rh_params = handle_psceg_event(psc_event); + + /* RH port id should be always less than maximum supported port */ + if ((rh_params.rhport < 1U) || (rh_params.rhport > + xhci_handle.xhc_cap_ptr->hcsparams1_params.max_ports)) + { + break; + } + if (rh_params.dev_attach_flag == 1) + { + hcd_event_device_attach(rh_params.rhport, in_isr); + update_device_rh_params(&xhci_handle, rh_params); + } + else if (rh_params.dev_attach_flag == -1) + { + hcd_event_device_remove(rh_params.rhport, in_isr); + } + else + { + /* Nothing to be handled for tinyusb stack */ + } + break; + + case COMMAND_COMPLETION_EVENT: + cc_event = event_data.cc_event; + xhci_command_event_complete(cc_event); + break; + + default: /* do nothing */ + break; + } + +} + +bool hcd_evaluate_xhci_context( void ) +{ + tusb_desc_device_t usb_desc; + TU_ASSERT(tuh_descriptor_get_device_local(device_addr, &usb_desc)); + const uint16_t bcd_usb = usb_desc.bcdUSB; + uint16_t desc_max_pkt_size; + const uint16_t ep0_pkt_size = + (xhci_handle.ip_ctx->xe_context[ 0 ].xec_info & + ~EP_CTX_MAX_PKT_SIZE_MSK) >> EP_CTX_MAX_PKT_SIZE_POS; + + if (bcd_usb >= 0x300U) + { + desc_max_pkt_size = (uint16_t) pow(2, usb_desc.bMaxPacketSize0); + } + else + { + desc_max_pkt_size = usb_desc.bMaxPacketSize0; + } + + if (ep0_pkt_size != desc_max_pkt_size) + { + update_endpoint_packetsize(xhci_handle.ip_ctx, desc_max_pkt_size); + + evaluate_endpoint(&xhci_handle); + + if (wait_for_command_completion_event(&xhci_handle, EVALUATE_CONTEXT_CMD) != 0) + { + return false; + } + + return true; + } + + return true; +} + +bool hcd_parse_full_conf_descriptor(tusb_desc_configuration_t *desc_cfg, uint8_t rhport) +{ + (void) rhport; + const uint8_t usb_speed = xhci_handle.dev_data.dev_speed; + + uint16_t const total_len = tu_le16toh(desc_cfg->wTotalLength); + uint8_t const *desc_end = ((uint8_t const*) desc_cfg) + total_len; + uint8_t const *p_desc = tu_desc_next(desc_cfg); + uint8_t assoc_itf_count = 1; + uint32_t err_flag = 0U; + + usb_endpoint_descriptor_t xhci_ep_desc; + + DEBUG("Parsing Complete Configuration Descriptors"); + + while (p_desc < desc_end) + { + TU_ASSERT(TUSB_DESC_INTERFACE == tu_desc_type(p_desc)); + + tusb_desc_interface_t const *desc_itf = + (tusb_desc_interface_t const*) (uintptr_t) p_desc; + + /* Check if the device belongs to MSC */ + if (desc_itf->bInterfaceClass != 8) + { + PRINT("Device does not support MSC"); + PRINT("Enumeration process completed"); + return false; + } + + uint16_t const drv_len = tu_desc_get_interface_total_len(desc_itf, + assoc_itf_count, (uint16_t) (desc_end - p_desc)); + + tusb_desc_endpoint_t const *ep_desc = + (tusb_desc_endpoint_t const*) (uintptr_t) tu_desc_next( + desc_itf); + + for (int i = 0; i < 2; i++) + { + TU_ASSERT( TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType && + TUSB_XFER_BULK == ep_desc->bmAttributes.xfer); + + xhci_ep_desc.bLength = ep_desc->bLength; + xhci_ep_desc.bDescriptorType = ep_desc->bDescriptorType; + xhci_ep_desc.bEndpointAddress = ep_desc->bEndpointAddress; + (void) memcpy(&xhci_ep_desc.bmAttributes, &ep_desc->bmAttributes, + sizeof(xhci_ep_desc.bmAttributes)); + xhci_ep_desc.wMaxPacketSize = ep_desc->wMaxPacketSize; + xhci_ep_desc.bInterval = ep_desc->bInterval; + + /* USB3.0 Mode */ + if (usb_speed == XHCI_SPEED_SS) + { + ep_desc = + (tusb_desc_endpoint_t const*) (uintptr_t) tu_desc_next( + ep_desc); + + ep_desc = + (tusb_desc_endpoint_t const*) (uintptr_t) tu_desc_next( + ep_desc); + } + else + { + ep_desc = + (tusb_desc_endpoint_t const*) (uintptr_t) tu_desc_next( + ep_desc); + } + + if (xhci_parse_endpoint_descriptor(&xhci_handle, &xhci_ep_desc) != 0) + { + ERROR("Failed to parse endpoint descriptor"); + return false; + } + err_flag = 1U; + } + + p_desc += drv_len; + } + + if (err_flag == 0U) + { + return false; + } + + return true; +} + +#endif diff --git a/src/portable/xhci/xhci.h b/src/portable/xhci/xhci.h index d84926e5c..addc40728 100644 --- a/src/portable/xhci/xhci.h +++ b/src/portable/xhci/xhci.h @@ -355,6 +355,6 @@ void start_xhci_controller(void); * true on successful initialization * false incase of failure */ -bool xhci_init(struct xhci_data *xhci); +bool xhci_init(); #endif /*__XHCI_H__ */ diff --git a/src/portable/xhci/xhci_api.h b/src/portable/xhci/xhci_api.h new file mode 100644 index 000000000..34e30bf07 --- /dev/null +++ b/src/portable/xhci/xhci_api.h @@ -0,0 +1,20 @@ +#ifndef _TUSB_XHCI_API_H_ +#define _TUSB_XHCI_API_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +//--------------------------------------------------------------------+ +// API Implemented by XHCI +//--------------------------------------------------------------------+ + +// Initialize EHCI driver +bool xhci_init(); + +#ifdef __cplusplus + } +#endif + +#endif + diff --git a/src/portable/xhci/xhci_common.c b/src/portable/xhci/xhci_common.c new file mode 100644 index 000000000..2e5496659 --- /dev/null +++ b/src/portable/xhci/xhci_common.c @@ -0,0 +1,83 @@ +/* + * Copyright (c) 2024, Intel Corporation. + * + * SPDX-License-Identifier: MIT + * + * HAL implementation for USB3 + */ +#include +#include +#include +#include +#include "tusb_config.h" +#include "osal_log.h" +#include "osal.h" +#include "xhci_commands.h" +#include "xhci_events.h" +#include "xhci_common.h" + +#define XHCI_SPEED_SS (4) +#define XHCI_QUEUE_SZ (10U) + +/* tinyusb specific queue initialization method */ +OSAL_QUEUE_DEF(usbh_int_set, xhci_event_params, XHCI_QUEUE_SZ, xcc_event_t); + +static QueueHandle_t xhci_queue; + +void dealloc_usb_port( struct xhci_data *xhci_handle ) +{ + deallocate_xhci_context(xhci_handle); +} + +int init_hcd_params( void ) +{ + xhci_queue = osal_queue_create(&xhci_event_params); + if ( xhci_queue == NULL ) + { + ERROR("Error in creating queue !!!"); + return -ENOMEM; + } + return 0; +} + +int wait_for_command_completion_event( struct xhci_data *xhci_ptr, int type ) +{ + xcc_event_t event = {0}; + while ( true ) + { + if ( osal_queue_receive(xhci_queue, &event, UINT32_MAX) == pdTRUE ) + { + DEBUG("CC event values are"); + DEBUG("pointer : %lx", event.cmd_trb_ptr); + DEBUG("Status field : %x", event.status_field); + DEBUG("Control fields : %x", event.control_field); + break; + } + } + + if ( ((event.status_field & 0xff000000U) >> 24) != 1U ) + { + return -1; + } + + switch (type) + { + case ENABLE_SLOT_CMD: + /* Get slot id from the CC event trb */ + update_device_slot_id(&xhci_ptr->dev_data, + (uint8_t) ((event.control_field & 0xff000000U) >> 24)); + break; + + default: /*do nothing*/ + break; + } + + xhci_ptr->xcr_ring->xcr_dequeue_ptr = (xhci_trb_t*) (event.cmd_trb_ptr); + + return 0; +} + +void xhci_command_event_complete( xcc_event_t event ) +{ + (void) osal_queue_send(xhci_queue, &event); +} diff --git a/src/portable/xhci/xhci_common.h b/src/portable/xhci/xhci_common.h new file mode 100644 index 000000000..55ad2ef83 --- /dev/null +++ b/src/portable/xhci/xhci_common.h @@ -0,0 +1,86 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Header file for xHCI implementation + */ + +#ifndef __HCD_SOCFPGA_H__ +#define __HCD_SOCFPGA_H__ + +#include +#include "xhci.h" +#include "xhci_events.h" +#include + +#define XHCI_SPEED_SS (4) +#define XHCI_QUEUE_SZ (10U) + +/* + * @brief deallocate all the usb3 port memory + * @param[in] handle usb3 port reference handle + */ +void dealloc_usb_port(struct xhci_data *xhci_handle); + +/* + * @brief api to check whether the reset process has completed or not + * @param[in] rhport portid of the correspondinf port + * @return + * - true, if operation is successul, + * - false, if the operation fails + */ +bool usb_port_reset_end(uint8_t rhport); + +/* + * @brief common usb api to reset the port + * @param[in] rhport RH port number + */ +void reset_usb_port(uint8_t rhport); + +/* + * @brief initialize the HCD queue + * @return + * 0, if initalization is successful, + * errno, incase of any failure + */ +int init_hcd_params(void); + +/* + * @brief wait for the command completio event + * @param[in] xhci_ptr reference to xhci context data structure + * @param[in[ type to specify the type of command completed by xHCI + * @return + * - NO_ERROR, if command is executed succssfully + * - -1, if command completion event reports failure + */ +int wait_for_command_completion_event(struct xhci_data *xhci_ptr, int type); + +/* + * @brief notify about the completion of command ring operation + * @param[in] command completion event params + */ +void xhci_command_event_complete(xcc_event_t event); + +bool hcd_dwc3_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); +void hcd_dwc3_int_enable (uint8_t rhport); +void hcd_dwc3_int_disable(uint8_t rhport); + +uint32_t hcd_dwc3_frame_number(uint8_t rhport); +bool hcd_dwc3_port_connect_status(uint8_t rhport); +void hcd_dwc3_port_reset(uint8_t rhport); + +void hcd_dwc3_port_reset_end(uint8_t rhport); +tusb_speed_t hcd_dwc3_port_speed_get(uint8_t rhport); + +bool hcd_dwc3_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t* desc_ep); +bool hcd_dwc3_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint32_t buflen); +bool hcd_dwc3_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); +bool hcd_dwc3_setup_send(uint8_t rhport, uint8_t dev_addr, const uint8_t setup_packet[8]); +bool hcd_dwc3_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); +bool hcd_dwc3_parse_full_conf_descriptor( tusb_desc_configuration_t *desc_cfg ); +void hcd_dwc3_device_close( uint8_t rhport ); + +void hcd_dwc3_int_handler(uint8_t rhport, bool in_isr); + +#endif /* __HCD_SOCFPGA_H__ */ From 89dea353db1808351e804d075ee3d9804f85393e Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Wed, 18 Nov 2026 17:39:47 +0530 Subject: [PATCH 05/17] hcd multi instance support and rename api functionality Signed-off-by: Sourav Raj K K --- apps/usb_main.c | 8 ++ hw/bsp/socfpga/family.cmake | 62 +++++++++- hw/bsp/socfpga/hcd_socfpga_multi.c | 51 ++++++++ src/CMakeLists.txt | 13 ++ src/common/tusb_mcu.h | 2 + src/host/hcd.h | 93 ++++++++++++++- src/host/hcd_multi.c | 186 +++++++++++++++++++++++++++++ src/host/hcd_rename.h | 113 ++++++++++++++++++ src/host/usbh.c | 7 ++ src/portable/xhci/xhci_common.h | 21 ---- src/tusb_option.h | 17 +++ 11 files changed, 545 insertions(+), 28 deletions(-) create mode 100644 hw/bsp/socfpga/hcd_socfpga_multi.c create mode 100644 src/host/hcd_multi.c create mode 100644 src/host/hcd_rename.h diff --git a/apps/usb_main.c b/apps/usb_main.c index 7eb77b3d3..9181518e5 100644 --- a/apps/usb_main.c +++ b/apps/usb_main.c @@ -12,6 +12,14 @@ #define USB3_HS_PORT (1) #define USB3_SS_PORT (2) +/* Host controllers in this build, set by hw/bsp/socfpga/family.cmake (SOCFPGA_HCD) */ +#ifndef SOCFPGA_HCD_DWC2 +#define SOCFPGA_HCD_DWC2 1 +#endif +#ifndef SOCFPGA_HCD_DWC3 +#define SOCFPGA_HCD_DWC3 1 +#endif + int usb_wait_to_mount(int timeout) { while (timeout >= 0) diff --git a/hw/bsp/socfpga/family.cmake b/hw/bsp/socfpga/family.cmake index 87a349a14..5eea846e0 100644 --- a/hw/bsp/socfpga/family.cmake +++ b/hw/bsp/socfpga/family.cmake @@ -12,11 +12,40 @@ endif () set(RHPORT_DEVICE_SPEED OPT_MODE_HIGH_SPEED) +# ---------------------- +# Host controller selection +# dwc2 : USB2.0 OTG (DWC2), rhport 0 +# dwc3 : USB3.1 (DWC3 in xHCI host mode), rhports 1 (USB2 port) and 2 (USB3 port) +# both : both controllers in one image (CFG_TUH_HCD_MULTI), routed per rhport by +# hw/bsp/socfpga/hcd_socfpga_multi.c +# dwc2/dwc3 build exactly one standard TinyUSB HCD. +# ---------------------- +set(SOCFPGA_HCD "both" CACHE STRING "SoC FPGA host controller driver: dwc2, dwc3 or both") +set_property(CACHE SOCFPGA_HCD PROPERTY STRINGS dwc2 dwc3 both) +option(SOCFPGA_HCD_WERROR "Build the TinyUSB library with -Wall -Wextra -Werror" OFF) + +set(TUSB_SRC ${FREERTOS_TOP_DIR}/tinyusb/src) + +if (SOCFPGA_HCD STREQUAL "dwc2") + set(SOCFPGA_HCD_DWC2 1) + set(SOCFPGA_HCD_DWC3 0) +elseif (SOCFPGA_HCD STREQUAL "dwc3") + set(SOCFPGA_HCD_DWC2 0) + set(SOCFPGA_HCD_DWC3 1) +elseif (SOCFPGA_HCD STREQUAL "both") + set(SOCFPGA_HCD_DWC2 1) + set(SOCFPGA_HCD_DWC3 1) +else () + message(FATAL_ERROR "SOCFPGA_HCD must be dwc2, dwc3 or both (got '${SOCFPGA_HCD}')") +endif () +message(STATUS "SoC FPGA TinyUSB HCD : ${SOCFPGA_HCD}") + add_subdirectory(${FREERTOS_TOP_DIR}/tinyusb/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb) add_library(agilex5-tinyusb STATIC) -target_compile_definitions(agilex5-tinyusb PUBLIC CFG_TUSB_MCU=OPT_MCU_SOCFPGA CFG_TUSB_OS=OPT_OS_FREERTOS BOARD_TUH_MAX_SPEED=${RHPORT_DEVICE_SPEED}) +target_compile_definitions(agilex5-tinyusb PUBLIC CFG_TUSB_MCU=OPT_MCU_SOCFPGA CFG_TUSB_OS=OPT_OS_FREERTOS BOARD_TUH_MAX_SPEED=${RHPORT_DEVICE_SPEED} + SOCFPGA_HCD_DWC2=${SOCFPGA_HCD_DWC2} SOCFPGA_HCD_DWC3=${SOCFPGA_HCD_DWC3}) target_include_directories(agilex5-tinyusb PUBLIC ${FREERTOS_TOP_DIR}/drivers/usb_otg @@ -32,17 +61,16 @@ target_include_directories(agilex5-tinyusb PUBLIC # Add TinyUSB target and port source tinyusb_target_add(agilex5-tinyusb) - target_sources(agilex5-tinyusb PUBLIC - #${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/hcd_socfpga.c - +set(SOCFPGA_DWC2_SRCS # Synopsys dwc2 controller ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc2/hcd_dwc2.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc2/dwc2_common.c + ) +set(SOCFPGA_DWC3_SRCS # Synopsys dwc3 controller ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/hcd_dwc3.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_common.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_cap.c @@ -53,5 +81,27 @@ target_include_directories(agilex5-tinyusb PUBLIC ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_events.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_interrupts.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_rings.c - ) +) + +if (SOCFPGA_HCD STREQUAL "both") + # Both unmodified drivers, each with its hcd_* API renamed; hcd_multi.c (added by + # tinyusb_target_add) dispatches per rhport through the BSP table. + target_compile_definitions(agilex5-tinyusb PUBLIC CFG_TUH_HCD_MULTI=1 CFG_TUH_HCD_MULTI_COUNT=3) + tinyusb_hcd_multi_add(agilex5-tinyusb dwc2 ${SOCFPGA_DWC2_SRCS}) + tinyusb_hcd_multi_add(agilex5-tinyusb dwc3 ${SOCFPGA_DWC3_SRCS}) + target_sources(agilex5-tinyusb PRIVATE + ${CMAKE_CURRENT_LIST_DIR}/hcd_socfpga_multi.c + ${FREERTOS_TOP_DIR}/tinyusb/src/host/hcd_multi.c + ) +elseif (SOCFPGA_HCD_DWC2) + target_sources(agilex5-tinyusb PRIVATE ${SOCFPGA_DWC2_SRCS}) +else () + target_sources(agilex5-tinyusb PRIVATE ${SOCFPGA_DWC3_SRCS}) +endif () + +if (SOCFPGA_HCD_WERROR) + target_compile_options(agilex5-tinyusb PRIVATE -Wall -Wextra -Werror) +endif () + + target_link_libraries(agilex5-tinyusb PRIVATE socfpga_drivers m) diff --git a/hw/bsp/socfpga/hcd_socfpga_multi.c b/hw/bsp/socfpga/hcd_socfpga_multi.c new file mode 100644 index 000000000..9c12fedbc --- /dev/null +++ b/hw/bsp/socfpga/hcd_socfpga_multi.c @@ -0,0 +1,51 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2025 Altera Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +// Agilex 5 host controller map for CFG_TUH_HCD_MULTI (SOCFPGA_HCD=both): +// rhport 0 : USB0, DWC2 USB2.0 OTG +// rhport 1 : USB1, DWC3 xHCI root-hub port 1 (USB2.0), owns the interrupt +// rhport 2 : USB1, DWC3 xHCI root-hub port 2 (USB3.x), owns controller init + +#include "tusb_option.h" + +#if CFG_TUH_ENABLED && CFG_TUH_HCD_MULTI + +#include "host/hcd.h" +#include "common/tusb_private.h" + +TU_VERIFY_STATIC(CFG_TUH_HCD_MULTI_COUNT == 3, "Agilex 5 map has 3 rhport entries"); +TU_VERIFY_STATIC(CFG_TUH_HCD_MULTI_COUNT <= TUP_USBIP_CONTROLLER_NUM, "rhport entries exceed controller number"); + +TUH_HCD_DRIVER_DEFINE(dwc2); +TUH_HCD_DRIVER_DEFINE(dwc3); + +hcd_driver_t const* const tuh_hcd_drivers[CFG_TUH_HCD_MULTI_COUNT] = { + [0] = &hcd_dwc2_driver, + [1] = &hcd_dwc3_driver, + [2] = &hcd_dwc3_driver, +}; + +#endif diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 951683104..ddbeb67db 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,6 +25,7 @@ function(tinyusb_target_add TARGET) # host ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/host/usbh.c ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/host/hub.c + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/host/hcd_multi.c ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/class/cdc/cdc_host.c ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/class/hid/hid_host.c ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/class/midi/midi_host.c @@ -39,3 +40,15 @@ function(tinyusb_target_add TARGET) ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../lib/networking ) endfunction() + +# CFG_TUH_HCD_MULTI: add the sources of one host controller driver instance to TARGET, compiled with +# TUH_HCD_NAME= and host/hcd_rename.h force-included (renames its hcd_* API to hcd__*). +# Pass every source of the driver, including helper sources. See src/host/hcd_rename.h. +# tinyusb_hcd_multi_add( ...) +function(tinyusb_hcd_multi_add TARGET NAME) + set(_srcs ${ARGN}) + target_sources(${TARGET} PRIVATE ${_srcs}) + set_property(SOURCE ${_srcs} APPEND PROPERTY COMPILE_DEFINITIONS TUH_HCD_NAME=${NAME}) + set_property(SOURCE ${_srcs} APPEND PROPERTY COMPILE_OPTIONS + -include ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/host/hcd_rename.h) +endfunction() diff --git a/src/common/tusb_mcu.h b/src/common/tusb_mcu.h index 97a922a9b..803964275 100644 --- a/src/common/tusb_mcu.h +++ b/src/common/tusb_mcu.h @@ -622,7 +622,9 @@ #define TUP_DCD_ENDPOINT_MAX 8 #elif TU_CHECK_MCU(OPT_MCU_SOCFPGA) + // USB0: DWC2 USB2.0 OTG, USB1: DWC3 USB3.1 (xHCI host) #define TUP_USBIP_DWC2 + #define TUP_USBIP_DWC3 #define TUP_USBIP_XHCI #define CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT 64 diff --git a/src/host/hcd.h b/src/host/hcd.h index 52268a067..003965adf 100644 --- a/src/host/hcd.h +++ b/src/host/hcd.h @@ -35,6 +35,10 @@ extern "C" { #endif +#if defined(TUH_HCD_NAME) && !CFG_TUH_HCD_MULTI + #error "TUH_HCD_NAME / host/hcd_rename.h used while CFG_TUH_HCD_MULTI == 0" +#endif + //--------------------------------------------------------------------+ // Configuration //--------------------------------------------------------------------+ @@ -175,9 +179,96 @@ bool hcd_setup_send(uint8_t rhport, uint8_t daddr, uint8_t const setup_packet[8] // clear stall, data toggle is also reset to DATA0 bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); -// parse xHCI configuration descriptor +// [optional] configure endpoints from the full configuration descriptor before SET_CONFIGURATION +// completes (needed by xHCI). Default (weak, in usbh.c) returns true. bool hcd_parse_full_conf_descriptor(tusb_desc_configuration_t *desc_cfg, uint8_t rhport); +//--------------------------------------------------------------------+ +// Multiple HCD support (CFG_TUH_HCD_MULTI), see host/hcd_rename.h +//--------------------------------------------------------------------+ +#if CFG_TUH_HCD_MULTI + +typedef struct { + const char* name; // "dwc2", "dwc3" (debug/logging) + bool (*configure)(uint8_t, uint32_t, const void*); // optional + bool (*init)(uint8_t, const tusb_rhport_init_t*); + bool (*deinit)(uint8_t); // optional + void (*int_handler)(uint8_t, bool); + void (*int_enable)(uint8_t); + void (*int_disable)(uint8_t); + uint32_t (*frame_number)(uint8_t); // optional + bool (*port_connect_status)(uint8_t); + void (*port_reset)(uint8_t); + void (*port_reset_end)(uint8_t); + tusb_speed_t (*port_speed_get)(uint8_t); + void (*device_close)(uint8_t, uint8_t); + bool (*edpt_open)(uint8_t, uint8_t, tusb_desc_endpoint_t const*); + bool (*edpt_close)(uint8_t, uint8_t, uint8_t); // optional + bool (*edpt_xfer)(uint8_t, uint8_t, uint8_t, uint8_t*, uint32_t); + bool (*edpt_abort_xfer)(uint8_t, uint8_t, uint8_t); // optional + bool (*setup_send)(uint8_t, uint8_t, uint8_t const[8]); + bool (*edpt_clear_stall)(uint8_t, uint8_t, uint8_t); // optional + bool (*parse_full_conf_descriptor)(tusb_desc_configuration_t*, uint8_t); // optional +} hcd_driver_t; + +// Per-rhport driver table, provided by the application/BSP (NULL for unused rhports) +extern hcd_driver_t const* const tuh_hcd_drivers[CFG_TUH_HCD_MULTI_COUNT]; + +#define _TUH_HCD_FN(_n, _o) hcd_##_n##_##_o + +// Prototypes of the renamed API of driver _n. Optional ops are weak: unimplemented ones resolve to NULL. +#define TUH_HCD_DRIVER_DECLARE(_n) \ + TU_ATTR_WEAK bool _TUH_HCD_FN(_n, configure)(uint8_t rhport, uint32_t cfg_id, const void* cfg_param); \ + bool _TUH_HCD_FN(_n, init)(uint8_t rhport, const tusb_rhport_init_t* rh_init); \ + TU_ATTR_WEAK bool _TUH_HCD_FN(_n, deinit)(uint8_t rhport); \ + void _TUH_HCD_FN(_n, int_handler)(uint8_t rhport, bool in_isr); \ + void _TUH_HCD_FN(_n, int_enable)(uint8_t rhport); \ + void _TUH_HCD_FN(_n, int_disable)(uint8_t rhport); \ + TU_ATTR_WEAK uint32_t _TUH_HCD_FN(_n, frame_number)(uint8_t rhport); \ + bool _TUH_HCD_FN(_n, port_connect_status)(uint8_t rhport); \ + void _TUH_HCD_FN(_n, port_reset)(uint8_t rhport); \ + void _TUH_HCD_FN(_n, port_reset_end)(uint8_t rhport); \ + tusb_speed_t _TUH_HCD_FN(_n, port_speed_get)(uint8_t rhport); \ + void _TUH_HCD_FN(_n, device_close)(uint8_t rhport, uint8_t dev_addr); \ + bool _TUH_HCD_FN(_n, edpt_open)(uint8_t rhport, uint8_t daddr, tusb_desc_endpoint_t const* ep_desc); \ + TU_ATTR_WEAK bool _TUH_HCD_FN(_n, edpt_close)(uint8_t rhport, uint8_t daddr, uint8_t ep_addr); \ + bool _TUH_HCD_FN(_n, edpt_xfer)(uint8_t rhport, uint8_t daddr, uint8_t ep_addr, uint8_t* buffer, uint32_t buflen); \ + TU_ATTR_WEAK bool _TUH_HCD_FN(_n, edpt_abort_xfer)(uint8_t rhport, uint8_t daddr, uint8_t ep_addr); \ + bool _TUH_HCD_FN(_n, setup_send)(uint8_t rhport, uint8_t daddr, uint8_t const setup_packet[8]); \ + TU_ATTR_WEAK bool _TUH_HCD_FN(_n, edpt_clear_stall)(uint8_t rhport, uint8_t daddr, uint8_t ep_addr); \ + TU_ATTR_WEAK bool _TUH_HCD_FN(_n, parse_full_conf_descriptor)(tusb_desc_configuration_t* desc_cfg, uint8_t rhport) + +// Defines `hcd_driver_t const hcd_<_n>_driver` with every op of driver _n (use in BSP/application only) +#define TUH_HCD_DRIVER_DEFINE(_n) \ + TUH_HCD_DRIVER_DECLARE(_n); \ + hcd_driver_t const hcd_##_n##_driver = { \ + .name = #_n, \ + .configure = _TUH_HCD_FN(_n, configure), \ + .init = _TUH_HCD_FN(_n, init), \ + .deinit = _TUH_HCD_FN(_n, deinit), \ + .int_handler = _TUH_HCD_FN(_n, int_handler), \ + .int_enable = _TUH_HCD_FN(_n, int_enable), \ + .int_disable = _TUH_HCD_FN(_n, int_disable), \ + .frame_number = _TUH_HCD_FN(_n, frame_number), \ + .port_connect_status = _TUH_HCD_FN(_n, port_connect_status), \ + .port_reset = _TUH_HCD_FN(_n, port_reset), \ + .port_reset_end = _TUH_HCD_FN(_n, port_reset_end), \ + .port_speed_get = _TUH_HCD_FN(_n, port_speed_get), \ + .device_close = _TUH_HCD_FN(_n, device_close), \ + .edpt_open = _TUH_HCD_FN(_n, edpt_open), \ + .edpt_close = _TUH_HCD_FN(_n, edpt_close), \ + .edpt_xfer = _TUH_HCD_FN(_n, edpt_xfer), \ + .edpt_abort_xfer = _TUH_HCD_FN(_n, edpt_abort_xfer), \ + .setup_send = _TUH_HCD_FN(_n, setup_send), \ + .edpt_clear_stall = _TUH_HCD_FN(_n, edpt_clear_stall), \ + .parse_full_conf_descriptor = _TUH_HCD_FN(_n, parse_full_conf_descriptor), \ + } + +// Log every rhport entry and which optional ops are present (CFG_TUSB_DEBUG >= 2) +void tuh_hcd_multi_log(void); + +#endif // CFG_TUH_HCD_MULTI + //--------------------------------------------------------------------+ // USBH implemented API //--------------------------------------------------------------------+ diff --git a/src/host/hcd_multi.c b/src/host/hcd_multi.c new file mode 100644 index 000000000..aad2e16d9 --- /dev/null +++ b/src/host/hcd_multi.c @@ -0,0 +1,186 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2025 Altera Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +// Standard hcd_* API for CFG_TUH_HCD_MULTI builds: each call is dispatched by rhport to the driver +// registered in tuh_hcd_drivers[]. Missing optional ops return the same default as the weak stubs +// in usbh.c. See host/hcd_rename.h for the overall design. + +#include "tusb_option.h" + +#if CFG_TUH_ENABLED && CFG_TUH_HCD_MULTI + +#include "host/hcd.h" + +//--------------------------------------------------------------------+ +// Helper +//--------------------------------------------------------------------+ +TU_ATTR_ALWAYS_INLINE static inline hcd_driver_t const* hcd_drv(uint8_t rhport) { + return (rhport < CFG_TUH_HCD_MULTI_COUNT) ? tuh_hcd_drivers[rhport] : NULL; +} + +// Fetch the driver of rhport, or assert and return _ret if the rhport has no driver +#define HCD_DRV_OR_RETURN(_drv, _rhport, _ret) \ + hcd_driver_t const* _drv = hcd_drv(_rhport); \ + TU_ASSERT(_drv != NULL, _ret) + +#define HCD_DRV_OR_RETURN_VOID(_drv, _rhport) \ + hcd_driver_t const* _drv = hcd_drv(_rhport); \ + TU_ASSERT(_drv != NULL, ) + +void tuh_hcd_multi_log(void) { +#if CFG_TUSB_DEBUG >= 2 + #define _HCD_OP_STR(_d, _op) ((_d)->_op ? "y" : "-") + TU_LOG2("HCD multi: %u rhport entries\r\n", (unsigned) CFG_TUH_HCD_MULTI_COUNT); + for (uint8_t i = 0; i < CFG_TUH_HCD_MULTI_COUNT; i++) { + hcd_driver_t const* d = tuh_hcd_drivers[i]; + if (d == NULL) { + TU_LOG2(" rhport %u: none\r\n", i); + continue; + } + TU_LOG2(" rhport %u: %s configure=%s deinit=%s frame_number=%s edpt_close=%s abort=%s clear_stall=%s" + " parse_conf=%s\r\n", + i, d->name, _HCD_OP_STR(d, configure), _HCD_OP_STR(d, deinit), _HCD_OP_STR(d, frame_number), + _HCD_OP_STR(d, edpt_close), _HCD_OP_STR(d, edpt_abort_xfer), _HCD_OP_STR(d, edpt_clear_stall), + _HCD_OP_STR(d, parse_full_conf_descriptor)); + } + #undef _HCD_OP_STR +#endif +} + +//--------------------------------------------------------------------+ +// Controller API +//--------------------------------------------------------------------+ +bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) { + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->configure ? drv->configure(rhport, cfg_id, cfg_param) : false; +} + +bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { + static bool logged = false; + if (!logged) { + logged = true; + tuh_hcd_multi_log(); + } + + printf("MULTI Init\r\n"); + + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->init(rhport, rh_init); +} + +bool hcd_deinit(uint8_t rhport) { + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->deinit ? drv->deinit(rhport) : false; +} + +// Called from the controller ISR: table lookup + call only, nothing blocking +void hcd_int_handler(uint8_t rhport, bool in_isr) { + HCD_DRV_OR_RETURN_VOID(drv, rhport); + drv->int_handler(rhport, in_isr); +} + +void hcd_int_enable(uint8_t rhport) { + HCD_DRV_OR_RETURN_VOID(drv, rhport); + drv->int_enable(rhport); +} + +void hcd_int_disable(uint8_t rhport) { + HCD_DRV_OR_RETURN_VOID(drv, rhport); + drv->int_disable(rhport); +} + +uint32_t hcd_frame_number(uint8_t rhport) { + HCD_DRV_OR_RETURN(drv, rhport, 0); + return drv->frame_number ? drv->frame_number(rhport) : 0; +} + +//--------------------------------------------------------------------+ +// Port API +//--------------------------------------------------------------------+ +bool hcd_port_connect_status(uint8_t rhport) { + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->port_connect_status(rhport); +} + +void hcd_port_reset(uint8_t rhport) { + HCD_DRV_OR_RETURN_VOID(drv, rhport); + drv->port_reset(rhport); +} + +void hcd_port_reset_end(uint8_t rhport) { + HCD_DRV_OR_RETURN_VOID(drv, rhport); + drv->port_reset_end(rhport); +} + +tusb_speed_t hcd_port_speed_get(uint8_t rhport) { + HCD_DRV_OR_RETURN(drv, rhport, TUSB_SPEED_INVALID); + return drv->port_speed_get(rhport); +} + +void hcd_device_close(uint8_t rhport, uint8_t dev_addr) { + HCD_DRV_OR_RETURN_VOID(drv, rhport); + drv->device_close(rhport, dev_addr); +} + +//--------------------------------------------------------------------+ +// Endpoints API +//--------------------------------------------------------------------+ +bool hcd_edpt_open(uint8_t rhport, uint8_t daddr, tusb_desc_endpoint_t const* ep_desc) { + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->edpt_open(rhport, daddr, ep_desc); +} + +bool hcd_edpt_close(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) { + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->edpt_close ? drv->edpt_close(rhport, daddr, ep_addr) : false; +} + +bool hcd_edpt_xfer(uint8_t rhport, uint8_t daddr, uint8_t ep_addr, uint8_t* buffer, uint32_t buflen) { + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->edpt_xfer(rhport, daddr, ep_addr, buffer, buflen); +} + +bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) { + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->edpt_abort_xfer ? drv->edpt_abort_xfer(rhport, daddr, ep_addr) : false; +} + +bool hcd_setup_send(uint8_t rhport, uint8_t daddr, uint8_t const setup_packet[8]) { + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->setup_send(rhport, daddr, setup_packet); +} + +bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) { + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->edpt_clear_stall ? drv->edpt_clear_stall(rhport, daddr, ep_addr) : false; +} + +bool hcd_parse_full_conf_descriptor(tusb_desc_configuration_t* desc_cfg, uint8_t rhport) { + HCD_DRV_OR_RETURN(drv, rhport, false); + return drv->parse_full_conf_descriptor ? drv->parse_full_conf_descriptor(desc_cfg, rhport) : true; +} + +#endif diff --git a/src/host/hcd_rename.h b/src/host/hcd_rename.h new file mode 100644 index 000000000..66ff7668c --- /dev/null +++ b/src/host/hcd_rename.h @@ -0,0 +1,113 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2025 Altera Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +/* Multiple host controller drivers (CFG_TUH_HCD_MULTI) + * =================================================== + * + * Every TinyUSB HCD implements the same fixed API from host/hcd.h (hcd_init, hcd_edpt_xfer, ...). + * To link several unmodified HCDs into one image, each driver translation unit is compiled with + * this header force-included, which renames that API to hcd__* (e.g. hcd_dwc2_init). + * host/hcd_multi.c then provides the standard hcd_* symbols used by usbh.c/hub.c and dispatches + * each call by rhport through the table tuh_hcd_drivers[] supplied by the application/BSP. + * With CFG_TUH_HCD_MULTI = 0 (default) none of this is compiled and the build is unchanged. + * + * Adding an HCD instance (e.g. a third driver "foo"): + * 1. Build all sources of the driver, including helper sources that reference the hcd_* API, + * _hcd_data or hcd_dcache_*, with + * -DTUH_HCD_NAME=foo -include host/hcd_rename.h + * The driver sources themselves need no changes. CMake: tinyusb_hcd_multi_add() in + * src/CMakeLists.txt. Make: target-specific CFLAGS on those objects. + * 2. Compile host/hcd_multi.c and set CFG_TUH_HCD_MULTI=1, CFG_TUH_HCD_MULTI_COUNT=. + * 3. In the BSP/application (never in src/portable): + * TUH_HCD_DRIVER_DEFINE(foo); + * hcd_driver_t const* const tuh_hcd_drivers[CFG_TUH_HCD_MULTI_COUNT] = { + * [0] = &hcd_dwc2_driver, [1] = &hcd_foo_driver, ... + * }; + * The table is indexed by rhport; one driver may serve several rhports. Unused rhports are NULL. + * + * Optional ops (configure, deinit, frame_number, edpt_close, edpt_abort_xfer, edpt_clear_stall, + * parse_full_conf_descriptor) are declared weak by TUH_HCD_DRIVER_DEFINE(); an op a driver does not + * implement resolves to NULL in its table, and hcd_multi.c returns the same default as the weak stub + * in usbh.c. The weak declarations live in the table TU only, so driver definitions stay strong. + * + * Decisions: + * - hcd_event_* inline helpers in hcd.h are NOT renamed: they carry rhport and route back to usbh. + * - hcd_dcache_clean/invalidate/clean_invalidate are always renamed per driver. They are called by + * drivers only (usbh.c just provides weak no-op defaults), and each driver may need a different + * implementation (dwc2 uses its own cache helpers). + * - Including this header with CFG_TUH_HCD_MULTI == 0 is an error (checked here when the macro is + * already visible, and again in host/hcd.h once tusb_option.h has been processed). + * - It must be the first thing in a driver TU (hence -include), so that the hcd.h prototypes are + * renamed as well. + */ + +#ifndef TUSB_HCD_RENAME_H_ +#define TUSB_HCD_RENAME_H_ + +#ifndef TUH_HCD_NAME + #error "Define TUH_HCD_NAME (e.g. dwc2) before including host/hcd_rename.h" +#endif + +#if defined(CFG_TUH_HCD_MULTI) && !CFG_TUH_HCD_MULTI + #error "host/hcd_rename.h is only for CFG_TUH_HCD_MULTI builds" +#endif + +// Self-contained concat (tusb_compiler.h is not included yet at this point). +// _TUH_HCD_XCAT(hcd, dwc2, init) -> hcd_dwc2_init +#define _TUH_HCD_CAT(_p, _n, _o) _p##_##_n##_##_o +#define _TUH_HCD_XCAT(_p, _n, _o) _TUH_HCD_CAT(_p, _n, _o) +#define TUH_HCD_SYM(_o) _TUH_HCD_XCAT(hcd, TUH_HCD_NAME, _o) + +// Controller +#define hcd_configure TUH_HCD_SYM(configure) +#define hcd_init TUH_HCD_SYM(init) +#define hcd_deinit TUH_HCD_SYM(deinit) +#define hcd_int_handler TUH_HCD_SYM(int_handler) +#define hcd_int_enable TUH_HCD_SYM(int_enable) +#define hcd_int_disable TUH_HCD_SYM(int_disable) +#define hcd_frame_number TUH_HCD_SYM(frame_number) +// Port +#define hcd_port_connect_status TUH_HCD_SYM(port_connect_status) +#define hcd_port_reset TUH_HCD_SYM(port_reset) +#define hcd_port_reset_end TUH_HCD_SYM(port_reset_end) +#define hcd_port_speed_get TUH_HCD_SYM(port_speed_get) +#define hcd_device_close TUH_HCD_SYM(device_close) +// Endpoint +#define hcd_edpt_open TUH_HCD_SYM(edpt_open) +#define hcd_edpt_close TUH_HCD_SYM(edpt_close) +#define hcd_edpt_xfer TUH_HCD_SYM(edpt_xfer) +#define hcd_edpt_abort_xfer TUH_HCD_SYM(edpt_abort_xfer) +#define hcd_setup_send TUH_HCD_SYM(setup_send) +#define hcd_edpt_clear_stall TUH_HCD_SYM(edpt_clear_stall) +#define hcd_parse_full_conf_descriptor TUH_HCD_SYM(parse_full_conf_descriptor) + +// Per-driver globals that would clash +#define _hcd_data _TUH_HCD_XCAT(_hcd, TUH_HCD_NAME, data) +#define hcd_dcache_clean TUH_HCD_SYM(dcache_clean) +#define hcd_dcache_invalidate TUH_HCD_SYM(dcache_invalidate) +#define hcd_dcache_clean_invalidate TUH_HCD_SYM(dcache_clean_invalidate) + +#endif diff --git a/src/host/usbh.c b/src/host/usbh.c index bbddd0a01..eaee1bdda 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -60,6 +60,13 @@ TU_ATTR_WEAK bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg return false; } +// Optional: HCDs that must configure endpoint contexts from the whole configuration descriptor +// (e.g. xHCI) override this. Others accept the configuration unchanged. +TU_ATTR_WEAK bool hcd_parse_full_conf_descriptor(tusb_desc_configuration_t* desc_cfg, uint8_t rhport) { + (void) desc_cfg; (void) rhport; + return true; +} + TU_ATTR_WEAK void tuh_enum_descriptor_device_cb(uint8_t daddr, const tusb_desc_device_t *desc_device) { (void) daddr; (void) desc_device; } diff --git a/src/portable/xhci/xhci_common.h b/src/portable/xhci/xhci_common.h index 55ad2ef83..043cd8d83 100644 --- a/src/portable/xhci/xhci_common.h +++ b/src/portable/xhci/xhci_common.h @@ -62,25 +62,4 @@ int wait_for_command_completion_event(struct xhci_data *xhci_ptr, int type); */ void xhci_command_event_complete(xcc_event_t event); -bool hcd_dwc3_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); -void hcd_dwc3_int_enable (uint8_t rhport); -void hcd_dwc3_int_disable(uint8_t rhport); - -uint32_t hcd_dwc3_frame_number(uint8_t rhport); -bool hcd_dwc3_port_connect_status(uint8_t rhport); -void hcd_dwc3_port_reset(uint8_t rhport); - -void hcd_dwc3_port_reset_end(uint8_t rhport); -tusb_speed_t hcd_dwc3_port_speed_get(uint8_t rhport); - -bool hcd_dwc3_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t* desc_ep); -bool hcd_dwc3_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint32_t buflen); -bool hcd_dwc3_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); -bool hcd_dwc3_setup_send(uint8_t rhport, uint8_t dev_addr, const uint8_t setup_packet[8]); -bool hcd_dwc3_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); -bool hcd_dwc3_parse_full_conf_descriptor( tusb_desc_configuration_t *desc_cfg ); -void hcd_dwc3_device_close( uint8_t rhport ); - -void hcd_dwc3_int_handler(uint8_t rhport, bool in_isr); - #endif /* __HCD_SOCFPGA_H__ */ diff --git a/src/tusb_option.h b/src/tusb_option.h index 42c164c49..3fc28629d 100644 --- a/src/tusb_option.h +++ b/src/tusb_option.h @@ -603,6 +603,23 @@ #define CFG_TUH_MEM_DCACHE_LINE_SIZE CFG_TUSB_MEM_DCACHE_LINE_SIZE #endif +// Multiple host controller drivers (HCD) in one image. When enabled, the standard hcd_* API is +// provided by host/hcd_multi.c, which dispatches per rhport through the application/BSP table +// tuh_hcd_drivers[CFG_TUH_HCD_MULTI_COUNT]. Each driver is compiled with host/hcd_rename.h, +// see that header for details. +#ifndef CFG_TUH_HCD_MULTI + #define CFG_TUH_HCD_MULTI 0 +#endif + +#if CFG_TUH_HCD_MULTI + // number of entries in tuh_hcd_drivers[], indexed by rhport (0 .. CFG_TUH_HCD_MULTI_COUNT-1) + #ifndef CFG_TUH_HCD_MULTI_COUNT + #error "CFG_TUH_HCD_MULTI requires CFG_TUH_HCD_MULTI_COUNT (number of rhport entries in tuh_hcd_drivers[])" + #elif CFG_TUH_HCD_MULTI_COUNT < 2 + #error "CFG_TUH_HCD_MULTI_COUNT must be at least 2" + #endif +#endif + //------------- CLASS -------------// #ifndef CFG_TUH_HUB From 4232e1bf1829685b7b7c5b7e446f2b28e19ac065 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Thu, 19 Nov 2026 11:13:01 +0530 Subject: [PATCH 06/17] dwc2 support in host mode Signed-off-by: Sourav Raj K K --- apps/msc_app.c | 1 - apps/usb_main.c | 4 +- hw/bsp/socfpga/family.cmake | 9 +- src/common/tusb_mcu.h | 1 + src/portable/synopsys/dwc2/dwc2_common.h | 2 + src/portable/synopsys/dwc2/dwc2_socfpga.h | 276 ++++++++++++++++++++++ src/portable/synopsys/dwc2/hcd_dwc2.c | 25 +- src/portable/synopsys/dwc3/hcd_dwc3.c | 2 - 8 files changed, 305 insertions(+), 15 deletions(-) create mode 100644 src/portable/synopsys/dwc2/dwc2_socfpga.h diff --git a/apps/msc_app.c b/apps/msc_app.c index 8483fdd5d..278d46a2f 100644 --- a/apps/msc_app.c +++ b/apps/msc_app.c @@ -27,7 +27,6 @@ #include "tusb.h" #include "osal_log.h" #include "socfpga_cache.h" -#include "hcd_dwc3.h" #define MSC_BLOCK_SIZE (512) diff --git a/apps/usb_main.c b/apps/usb_main.c index 9181518e5..d84228a61 100644 --- a/apps/usb_main.c +++ b/apps/usb_main.c @@ -47,7 +47,7 @@ void usb_task(void *arg) .role = TUSB_ROLE_HOST, .speed = TUSB_SPEED_AUTO }; -#if 0 + /*initialize host stack for usb otg HS port*/ if (!tusb_init(USB_OTG_PORT, &host_init)) { @@ -58,7 +58,6 @@ void usb_task(void *arg) { PRINT("USB OTG port initialized successfully"); } -#endif /*initialize host stack for usb3 SS port*/ if (!tusb_init(USB3_SS_PORT, &host_init)) @@ -78,6 +77,7 @@ void usb_task(void *arg) PRINT("USB3.1 port initialized successfully"); } } + while (1) { tuh_task(); diff --git a/hw/bsp/socfpga/family.cmake b/hw/bsp/socfpga/family.cmake index 5eea846e0..1b03f6750 100644 --- a/hw/bsp/socfpga/family.cmake +++ b/hw/bsp/socfpga/family.cmake @@ -52,19 +52,18 @@ target_include_directories(agilex5-tinyusb PUBLIC ${FREERTOS_TOP_DIR}/tinyusb/src/class/msc ${FREERTOS_TOP_DIR}/tinyusb/src/common ${FREERTOS_TOP_DIR}/tinyusb/apps/ - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc2/ - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc3/ ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/ + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc2/ ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci ) # Add TinyUSB target and port source - tinyusb_target_add(agilex5-tinyusb) +tinyusb_target_add(agilex5-tinyusb) set(SOCFPGA_DWC2_SRCS # Synopsys dwc2 controller - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc2/hcd_dwc2.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/socfpga/dwc2/dwc2_common.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc2/hcd_dwc2.c + ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c ) set(SOCFPGA_DWC3_SRCS diff --git a/src/common/tusb_mcu.h b/src/common/tusb_mcu.h index 803964275..4ef304afb 100644 --- a/src/common/tusb_mcu.h +++ b/src/common/tusb_mcu.h @@ -626,6 +626,7 @@ #define TUP_USBIP_DWC2 #define TUP_USBIP_DWC3 #define TUP_USBIP_XHCI + #define TUP_USBIP_DWC2_SOCFPGA #define CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT 64 #endif diff --git a/src/portable/synopsys/dwc2/dwc2_common.h b/src/portable/synopsys/dwc2/dwc2_common.h index 33219f786..b92640e1c 100644 --- a/src/portable/synopsys/dwc2/dwc2_common.h +++ b/src/portable/synopsys/dwc2/dwc2_common.h @@ -51,6 +51,8 @@ #include "dwc2_xmc.h" #elif defined(TUP_USBIP_DWC2_AT32) #include "dwc2_at32.h" +#elif defined(TUP_USBIP_DWC2_SOCFPGA) + #include "dwc2_socfpga.h" #else #error "Unsupported MCUs" #endif diff --git a/src/portable/synopsys/dwc2/dwc2_socfpga.h b/src/portable/synopsys/dwc2/dwc2_socfpga.h new file mode 100644 index 000000000..8b045cc79 --- /dev/null +++ b/src/portable/synopsys/dwc2/dwc2_socfpga.h @@ -0,0 +1,276 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2021, Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +#ifndef DWC2_SOCFPGA_H_ +#define DWC2_SOCFPGA_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#if CFG_TUSB_MCU == OPT_MCU_SOCFPGA + #include "socfpga_rst_mngr.h" + #include "socfpga_interrupt.h" + #include "socfpga_cache.h" + #include "socfpga_gpio.h" + #include "osal_log.h" + //toggle gpio for usb2 reset + #define USB_GPIO_TOGGLE 1 + #define USBOTG_BASE_ADDR (0x10B00000U) +#else + #error "Unsupported MCUs" +#endif + +// OTG HS always has higher number of endpoints than FS +#ifdef USB_OTG_HS_PERIPH_BASE + #define DWC2_EP_MAX EP_MAX_HS +#else + #define DWC2_EP_MAX EP_MAX_FS +#endif + +// On Agilex5 socfpga, we associate: +// - Port0 to USB_OTG +static const dwc2_controller_t _dwc2_controller[] = { + { .reg_base = USBOTG_BASE_ADDR, .irqnum = USB0IRQ, .ep_count = 15, .ep_fifo_size = 8192 }, +}; + +//--------------------------------------------------------------------+ +// +//--------------------------------------------------------------------+ + +static void dwc2_int_handler_wrap() { + hcd_int_handler(0, true); +} + +TU_ATTR_ALWAYS_INLINE static inline void dwc2_int_set(uint8_t rhport, tusb_role_t role, bool enabled) { + (void) role; + (void) rhport; + (void) enabled; + int intr_ret; + + intr_ret = interrupt_register_isr(USB0IRQ, dwc2_int_handler_wrap, NULL); + if (intr_ret != 0) + { + ERROR("Failed to enable interrupt"); + return; + } + + intr_ret = interrupt_enable(USB0IRQ, GIC_INTERRUPT_PRIORITY_USB2); + if (intr_ret != 0) + { + ERROR("Failed to enable interrupt"); + return; + } + + INFO("Interrupt handler registered successfully"); + +} + +#define dwc2_dcd_int_enable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, true) +#define dwc2_dcd_int_disable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, false) + + +TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) { + // try to delay for 1 ms + osal_task_delay(1); +} + +// MCU specific PHY init, called BEFORE core reset +// - dwc2 3.30a (H5) use USB_HS_PHYC +// - dwc2 4.11a (U5) use femtoPHY +static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) { + if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) { + // Enable on-chip FS PHY + dwc2->stm32_gccfg |= STM32_GCCFG_PWRDWN; + + // https://community.st.com/t5/stm32cubemx-mcus/why-stm32h743-usb-fs-doesn-t-work-if-freertos-tickless-idle/m-p/349480#M18867 + // H7 running on full-speed phy need to disable ULPI clock in sleep mode. + // Otherwise, USB won't work when mcu executing WFI/WFE instruction i.e tick-less RTOS. + // Note: there may be other family that is affected by this, but only H7 and F7 is tested so far + #if defined(USB_OTG_FS_PERIPH_BASE) && defined(RCC_AHB1LPENR_USB2OTGFSULPILPEN) + if ( USB_OTG_FS_PERIPH_BASE == (uint32_t) dwc2 ) { + RCC->AHB1LPENR &= ~RCC_AHB1LPENR_USB2OTGFSULPILPEN; + } + #endif + + #if defined(USB_OTG_HS_PERIPH_BASE) && defined(RCC_AHB1LPENR_USB1OTGHSULPILPEN) + if ( USB_OTG_HS_PERIPH_BASE == (uint32_t) dwc2 ) { + RCC->AHB1LPENR &= ~RCC_AHB1LPENR_USB1OTGHSULPILPEN; + } + #endif + + #if defined(USB_OTG_HS_PERIPH_BASE) && defined(RCC_AHB1LPENR_OTGHSULPILPEN) + if ( USB_OTG_HS_PERIPH_BASE == (uint32_t) dwc2 ) { + RCC->AHB1LPENR &= ~RCC_AHB1LPENR_OTGHSULPILPEN; + } + #endif + + } else { +#if CFG_TUSB_MCU != OPT_MCU_STM32U5 + // Disable FS PHY, TODO on U5A5 (dwc2 4.11a) 16th bit is 'Host CDP behavior enable' + dwc2->stm32_gccfg &= ~STM32_GCCFG_PWRDWN; +#endif + + // Enable on-chip HS PHY + if (hs_phy_type == GHWCFG2_HSPHY_UTMI || hs_phy_type == GHWCFG2_HSPHY_UTMI_ULPI) { + #ifdef USB_HS_PHYC + // Enable UTMI HS PHY + dwc2->stm32_gccfg |= STM32_GCCFG_PHYHSEN; + + // Enable LDO + USB_HS_PHYC->USB_HS_PHYC_LDO |= USB_HS_PHYC_LDO_ENABLE; + + // Wait until LDO ready + while ( 0 == (USB_HS_PHYC->USB_HS_PHYC_LDO & USB_HS_PHYC_LDO_STATUS) ) {} + + uint32_t phyc_pll = 0; + + // TODO Try to get HSE_VALUE from registers instead of depending CFLAGS + switch ( HSE_VALUE ) + { + case 12000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12MHZ ; break; + case 12500000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12_5MHZ ; break; + case 16000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_16MHZ ; break; + case 24000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_24MHZ ; break; + case 25000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_25MHZ ; break; + case 32000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_Msk ; break; // Value not defined in header + default: + TU_ASSERT(false, ); + } + USB_HS_PHYC->USB_HS_PHYC_PLL = phyc_pll; + + // Control the tuning interface of the High Speed PHY + // Use magic value (USB_HS_PHYC_TUNE_VALUE) from ST driver for F7 + USB_HS_PHYC->USB_HS_PHYC_TUNE |= 0x00000F13U; + + // Enable PLL internal PHY + USB_HS_PHYC->USB_HS_PHYC_PLL |= USB_HS_PHYC_PLL_PLLEN; + #else + + #endif + } + } +} + +// MCU specific PHY update, it is called AFTER init() and core reset +static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint8_t hs_phy_type) { + // used to set turnaround time for fullspeed, nothing to do in highspeed mode + (void)dwc2; + if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) { + // Turnaround timeout depends on the AHB clock dictated by STM32 Reference Manual + } +} + +#if( USB_GPIO_TOGGLE == 1 ) +static inline bool is_pin_gpio(uint8_t pin) +{ + uint32_t val; + val = RD_REG32(PINMUX_REG(pin)); + val &= PINMUX_MASK; + return (val == PINMUX_GPIO); +} + +/* + * @brief Configure the pin as gpio in pinmux + */ +static inline void config_pinmux(uint8_t pin) +{ + uint32_t reg_val; + if (is_pin_gpio(pin) == false) + { + /* Change pin functionality to gpio */ + reg_val = RD_REG32(PINMUX_REG(pin)); + reg_val = (reg_val & ~PINMUX_MASK) | PINMUX_GPIO; + WR_REG32(PINMUX_REG(pin), reg_val); + } +} + +// gpio reset for socfpga usb2 controller +static inline int usb2_gpio_reset() +{ + #define GPIO_USB_RESET GPIO1_PIN4 + + gpio_handle_t led; + int led_config = GPIO_DIR_OUT; + int ret; + + config_pinmux(GPIO_USB_RESET); + led = gpio_open(GPIO_USB_RESET); + + ret = gpio_ioctl(led, SET_GPIO_DIR, &led_config); + + if( ret != 0 ) + { + gpio_close(led); + return -1; + } + + gpio_write_sync(led, 1); + + osal_task_delay(10); + + return 0; +} +#endif + +//------------- DCache -------------// +#if CFG_TUD_MEM_DCACHE_ENABLE || CFG_TUH_MEM_DCACHE_ENABLE + +TU_ATTR_ALWAYS_INLINE static inline uint32_t round_up_to_cache_line_size(uint32_t size) { + if (size & (CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT-1)) { + size = (size & ~(CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT-1)) + CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT; + } + return size; +} + +TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_clean(void const* addr, uint32_t data_size) { + const uintptr_t addr32 = (uintptr_t) addr; + data_size = round_up_to_cache_line_size(data_size); + cache_force_write_back((uint32_t *) addr32, (int32_t) data_size); + return true; +} + +TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_invalidate(void const* addr, uint32_t data_size) { + const uintptr_t addr32 = (uintptr_t) addr; + data_size = round_up_to_cache_line_size(data_size); + cache_force_invalidate((uint32_t *) addr32, (int32_t) data_size); + return true; +} + +TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_clean_invalidate(void const* addr, uint32_t data_size) { + const uintptr_t addr32 = (uintptr_t) addr; + data_size = round_up_to_cache_line_size(data_size); + cache_force_invalidate((uint32_t *) addr32, (int32_t) data_size); + cache_force_write_back((uint32_t *) addr32, (int32_t) data_size); + return true; +} +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/portable/synopsys/dwc2/hcd_dwc2.c b/src/portable/synopsys/dwc2/hcd_dwc2.c index 257fa2833..3327c1a35 100644 --- a/src/portable/synopsys/dwc2/hcd_dwc2.c +++ b/src/portable/synopsys/dwc2/hcd_dwc2.c @@ -85,7 +85,7 @@ typedef struct { uint32_t uframe_countdown; // micro-frame count down to transfer for periodic, only need 18-bit uint8_t* buffer; - uint16_t buflen; + uint32_t buflen; } hcd_endpoint_t; // Additional info for each channel when it is active @@ -99,7 +99,7 @@ typedef struct { }; uint8_t result; - uint16_t xferred_bytes; // bytes that accumulate transferred though USB bus for the whole hcd_edpt_xfer(), which can + uint32_t xferred_bytes; // bytes that accumulate transferred though USB bus for the whole hcd_edpt_xfer(), which can // be composed of multiple channel_xfer_start() (retry with NAK/NYET) uint16_t fifo_bytes; // bytes written/read from/to FIFO (may not be transferred on USB bus). } hcd_xfer_t; @@ -362,8 +362,23 @@ bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { (void) rh_init; dwc2_regs_t* dwc2 = DWC2_REG(rhport); + printf("Port number : %d\r\n", rhport); + tu_memclr(&_hcd_data, sizeof(_hcd_data)); +#if (CFG_TUSB_MCU == OPT_MCU_SOCFPGA) + +#if USB_GPIO_TOGGLE == 1 + TU_ASSERT((usb2_gpio_reset() == 0)); +#endif + + TU_ASSERT((rstmgr_assert_reset(RST_USB0) == 0)); + + TU_ASSERT((rstmgr_deassert_reset(RST_USB0) == 0)); + + TU_ASSERT((rstmgr_deassert_reset(RST_USB0ECC) == 0)); +#endif + // Core Initialization const bool is_highspeed = dwc2_core_is_highspeed(dwc2, TUSB_ROLE_HOST); const bool is_dma = dma_host_enabled(dwc2); @@ -594,7 +609,7 @@ static bool channel_xfer_start(dwc2_regs_t* dwc2, uint8_t ch_id) { channel->hcintmsk = hcintmsk; dwc2->haintmsk |= TU_BIT(ch_id); - channel->hcdma = (uint32_t) edpt->buffer; + channel->hcdma = (uint32_t)(uintptr_t) edpt->buffer; if (hcchar_bm->ep_dir == TUSB_DIR_IN) { channel_send_in_token(dwc2, channel); @@ -647,7 +662,7 @@ static bool edpt_xfer_kickoff(dwc2_regs_t* dwc2, uint8_t ep_id) { } // Submit a transfer, when complete hcd_event_xfer_complete() must be invoked -bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t buflen) { +bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint32_t buflen) { dwc2_regs_t* dwc2 = DWC2_REG(rhport); const uint8_t ep_num = tu_edpt_number(ep_addr); const uint8_t ep_dir = tu_edpt_dir(ep_addr); @@ -1216,7 +1231,7 @@ static void handle_channel_irq(uint8_t rhport, bool in_isr) { is_done = handle_channel_in_dma(dwc2, ch_id, hcint); if (is_done && (channel->hcdma > xfer->xferred_bytes)) { // hcdma is increased by word --> need to align4 - hcd_dcache_invalidate((void*) tu_align4(channel->hcdma - xfer->xferred_bytes), xfer->xferred_bytes); + hcd_dcache_invalidate((void*)(uintptr_t) tu_align4(channel->hcdma - xfer->xferred_bytes), xfer->xferred_bytes); } } #endif diff --git a/src/portable/synopsys/dwc3/hcd_dwc3.c b/src/portable/synopsys/dwc3/hcd_dwc3.c index 7e5bf7b5e..3e9887db6 100644 --- a/src/portable/synopsys/dwc3/hcd_dwc3.c +++ b/src/portable/synopsys/dwc3/hcd_dwc3.c @@ -67,8 +67,6 @@ bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { break; } - printf("HWPARAMS : %x, %x, %x\r\n", ghwparams0.value, ghwparams1.value, ghwparams3.value); - switch (ghwparams3.ghwparams3_3_2) { case DWC3_HS_PHY_UTMI: case DWC3_HS_PHY_ULPI: From 7b7bea9ac23f98425501a9e9514d7bd74ba70fd5 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Thu, 19 Nov 2026 11:50:44 +0530 Subject: [PATCH 07/17] remove socfpga folder * portable layer is moved to synopsys and xHCI layers Signed-off-by: Sourav Raj K K --- src/portable/socfpga/dwc2/dwc2_common.c | 322 --- src/portable/socfpga/dwc2/dwc2_common.h | 105 - src/portable/socfpga/dwc2/dwc2_socfpga.h | 225 --- src/portable/socfpga/dwc2/dwc2_type.h | 2286 ---------------------- src/portable/socfpga/dwc2/hcd_dwc2.c | 1512 -------------- src/portable/socfpga/dwc2/hcd_dwc2.h | 29 - src/portable/socfpga/dwc3/dwc3_common.c | 95 - src/portable/socfpga/dwc3/hcd_dwc3.c | 591 ------ src/portable/socfpga/dwc3/hcd_dwc3.h | 86 - src/portable/socfpga/hcd_socfpga.c | 269 --- 10 files changed, 5520 deletions(-) delete mode 100644 src/portable/socfpga/dwc2/dwc2_common.c delete mode 100644 src/portable/socfpga/dwc2/dwc2_common.h delete mode 100644 src/portable/socfpga/dwc2/dwc2_socfpga.h delete mode 100644 src/portable/socfpga/dwc2/dwc2_type.h delete mode 100644 src/portable/socfpga/dwc2/hcd_dwc2.c delete mode 100644 src/portable/socfpga/dwc2/hcd_dwc2.h delete mode 100644 src/portable/socfpga/dwc3/dwc3_common.c delete mode 100644 src/portable/socfpga/dwc3/hcd_dwc3.c delete mode 100644 src/portable/socfpga/dwc3/hcd_dwc3.h delete mode 100644 src/portable/socfpga/hcd_socfpga.c diff --git a/src/portable/socfpga/dwc2/dwc2_common.c b/src/portable/socfpga/dwc2/dwc2_common.c deleted file mode 100644 index b001f343d..000000000 --- a/src/portable/socfpga/dwc2/dwc2_common.c +++ /dev/null @@ -1,322 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2024 Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#include "tusb_option.h" - -#define DWC2_COMMON_DEBUG 2 - -#if defined(TUP_USBIP_DWC2) && (CFG_TUH_ENABLED || CFG_TUD_ENABLED) - -#if CFG_TUD_ENABLED -#include "device/dcd.h" -#endif - -#if CFG_TUH_ENABLED -#include "host/hcd.h" -#include "host/usbh.h" -#endif - -#include "dwc2_common.h" - -//-------------------------------------------------------------------- -// -//-------------------------------------------------------------------- -static void reset_core(dwc2_regs_t* dwc2) { - // reset core - dwc2->grstctl |= GRSTCTL_CSRST; - - if ((dwc2->gsnpsid & DWC2_CORE_REV_MASK) < (DWC2_CORE_REV_4_20a & DWC2_CORE_REV_MASK)) { - // prior v42.0 CSRST is self-clearing - while (dwc2->grstctl & GRSTCTL_CSRST) {} - } else { - // From v4.20a CSRST bit is write only, CSRT_DONE (w1c) is introduced for checking. - // CSRST must also be explicitly cleared - while (!(dwc2->grstctl & GRSTCTL_CSRST_DONE)) {} - dwc2->grstctl = (dwc2->grstctl & ~GRSTCTL_CSRST) | GRSTCTL_CSRST_DONE; - } - - while (!(dwc2->grstctl & GRSTCTL_AHBIDL)) {} // wait for AHB master IDLE -} - -static void phy_fs_init(dwc2_regs_t* dwc2) { - TU_LOG(DWC2_COMMON_DEBUG, "Fullspeed PHY init\r\n"); - - uint32_t gusbcfg = dwc2->gusbcfg; - - // Select FS PHY - gusbcfg |= GUSBCFG_PHYSEL; - dwc2->gusbcfg = gusbcfg; - - // MCU specific PHY init before reset - dwc2_phy_init(dwc2, GHWCFG2_HSPHY_NOT_SUPPORTED); - - // Reset core after selecting PHY - reset_core(dwc2); - - // USB turnaround time is critical for certification where long cables and 5-Hubs are used. - // So if you need the AHB to run at less than 30 MHz, and if USB turnaround time is not critical, - // these bits can be programmed to a larger value. Default is 5 - gusbcfg &= ~GUSBCFG_TRDT_Msk; - gusbcfg |= 5u << GUSBCFG_TRDT_Pos; - dwc2->gusbcfg = gusbcfg; - - // MCU specific PHY update post reset - dwc2_phy_update(dwc2, GHWCFG2_HSPHY_NOT_SUPPORTED); -} - -static void phy_hs_init(dwc2_regs_t* dwc2) { - uint32_t gusbcfg = dwc2->gusbcfg; - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - const dwc2_ghwcfg4_t ghwcfg4 = {.value = dwc2->ghwcfg4}; - - // De-select FS PHY - gusbcfg &= ~GUSBCFG_PHYSEL; - - if (ghwcfg2.hs_phy_type == GHWCFG2_HSPHY_ULPI) { - TU_LOG(DWC2_COMMON_DEBUG, "Highspeed ULPI PHY init\r\n"); - - // Select ULPI PHY (external) - gusbcfg |= GUSBCFG_ULPI_UTMI_SEL; - - // ULPI is always 8-bit interface - gusbcfg &= ~GUSBCFG_PHYIF16; - - // ULPI select single data rate - gusbcfg &= ~GUSBCFG_DDRSEL; - - // default internal VBUS Indicator and Drive - gusbcfg &= ~(GUSBCFG_ULPIEVBUSD | GUSBCFG_ULPIEVBUSI); - - // Disable FS/LS ULPI - gusbcfg &= ~(GUSBCFG_ULPIFSLS | GUSBCFG_ULPICSM); - } else { - TU_LOG(DWC2_COMMON_DEBUG, "Highspeed UTMI+ PHY init\r\n"); - - // Select UTMI+ PHY (internal) - gusbcfg &= ~GUSBCFG_ULPI_UTMI_SEL; - - // Set 16-bit interface if supported - if (ghwcfg4.phy_data_width) { - #if CFG_TUSB_MCU != OPT_MCU_AT32F402_405 // at32f402_405 does not actually support 16-bit - gusbcfg |= GUSBCFG_PHYIF16; // 16 bit - #endif - } else { - gusbcfg &= ~GUSBCFG_PHYIF16; // 8 bit - } - } - - // Apply config - dwc2->gusbcfg = gusbcfg; - - // mcu specific phy init - dwc2_phy_init(dwc2, ghwcfg2.hs_phy_type); - - // Reset core after selecting PHY - reset_core(dwc2); - - // Set turn-around, must after core reset otherwise it will be clear - // - 9 if using 8-bit PHY interface - // - 5 if using 16-bit PHY interface - gusbcfg &= ~GUSBCFG_TRDT_Msk; - -#if CFG_TUSB_MCU == OPT_MCU_AT32F402_405 // at32f402_405 does not actually support 16-bit - gusbcfg |= 9u << GUSBCFG_TRDT_Pos; -#else - gusbcfg |= (dwc2->ghwcfg4_bm.phy_data_width ? 5u : 9u) << GUSBCFG_TRDT_Pos; -#endif - - dwc2->gusbcfg = gusbcfg; - - // MCU specific PHY update post reset - dwc2_phy_update(dwc2, ghwcfg2.hs_phy_type); -} - -static bool check_dwc2(dwc2_regs_t* dwc2) { -#if CFG_TUSB_DEBUG >= DWC2_COMMON_DEBUG - // print guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4 - // Run 'python dwc2_info.py' and check dwc2_info.md for bit-field value and comparison with other ports - volatile uint32_t const* p = (volatile uint32_t const*) &dwc2->guid; - TU_LOG1("guid, gsnpsid, ghwcfg1, ghwcfg2, ghwcfg3, ghwcfg4\r\n"); - for (size_t i = 0; i < 5; i++) { - TU_LOG1("0x%08" PRIX32 ", ", p[i]); - } - TU_LOG1("0x%08" PRIX32 "\r\n", p[5]); -#endif - - // For some reason: GD32VF103 gsnpsid and all hwcfg register are always zero (skip it) - (void)dwc2; -#if !TU_CHECK_MCU(OPT_MCU_GD32VF103) - enum { GSNPSID_ID_MASK = TU_GENMASK(31, 16) }; - const uint32_t gsnpsid = dwc2->gsnpsid & GSNPSID_ID_MASK; - TU_ASSERT(gsnpsid == DWC2_OTG_ID || gsnpsid == DWC2_FS_IOT_ID || gsnpsid == DWC2_HS_IOT_ID); -#endif - - return true; -} - -//-------------------------------------------------------------------- -// -//-------------------------------------------------------------------- -bool dwc2_core_is_highspeed(dwc2_regs_t* dwc2, tusb_role_t role) { - (void)dwc2; -#if CFG_TUD_ENABLED - if (role == TUSB_ROLE_DEVICE && !TUD_OPT_HIGH_SPEED) { - return false; - } -#endif -#if CFG_TUH_ENABLED - if (role == TUSB_ROLE_HOST && !TUH_OPT_HIGH_SPEED) { - return false; - } -#endif - - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - return ghwcfg2.hs_phy_type != GHWCFG2_HSPHY_NOT_SUPPORTED; -} - -/* dwc2 has several PHYs option - * - UTMI+ is internal highspeed PHY, clock can be 30 Mhz (8-bit) or 60 Mhz (16-bit) - * - ULPI is external highspeed PHY, clock is 60Mhz with only 8-bit interface - * - Dedicated FS PHY is internal with clock 48Mhz. - * - * In addition, UTMI+/ULPI can be shared to run at fullspeed mode with 48Mhz - * -*/ -bool dwc2_core_init(uint8_t rhport, bool is_highspeed, bool is_dma) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - - // Check Synopsys ID register, failed if controller clock/power is not enabled - TU_ASSERT(check_dwc2(dwc2)); - - // disable global interrupt - dwc2->gahbcfg &= ~GAHBCFG_GINT; - - if (is_highspeed) { - phy_hs_init(dwc2); - } else { - phy_fs_init(dwc2); - } - - /* Set HS/FS Timeout Calibration to 7 (max available value). - * The number of PHY clocks that the application programs in - * this field is added to the high/full speed interpacket timeout - * duration in the core to account for any additional delays - * introduced by the PHY. This can be required, because the delay - * introduced by the PHY in generating the linestate condition - * can vary from one PHY to another. */ - dwc2->gusbcfg |= (7ul << GUSBCFG_TOCAL_Pos); - - // Enable PHY clock TODO stop/gate clock when suspended mode - dwc2->pcgcctl &= ~(PCGCCTL_STOPPCLK | PCGCCTL_GATEHCLK | PCGCCTL_PWRCLMP | PCGCCTL_RSTPDWNMODULE); - - dfifo_flush_tx(dwc2, 0x10); // all tx fifo - dfifo_flush_rx(dwc2); - - // Clear pending and disable all interrupts - dwc2->gintsts = 0xFFFFFFFFU; - dwc2->gotgint = 0xFFFFFFFFU; - dwc2->gintmsk = 0; - - TU_LOG(DWC2_COMMON_DEBUG, "DMA = %u\r\n", is_dma); - - if (is_dma) { - // DMA seems to be only settable after a core reset, and not possible to switch on-the-fly - dwc2->gahbcfg |= GAHBCFG_DMAEN | GAHBCFG_HBSTLEN_2; - } else { - dwc2->gintmsk |= GINTSTS_RXFLVL; - } - - return true; -} - -// void dwc2_core_handle_common_irq(uint8_t rhport, bool in_isr) { -// (void) in_isr; -// dwc2_regs_t * const dwc2 = DWC2_REG(rhport); -// const uint32_t int_mask = dwc2->gintmsk; -// const uint32_t int_status = dwc2->gintsts & int_mask; -// -// // Device disconnect -// if (int_status & GINTSTS_DISCINT) { -// dwc2->gintsts = GINTSTS_DISCINT; -// } -// -// } - -//-------------------------------------------------------------------- -// DFIFO -//-------------------------------------------------------------------- -// Read a single data packet from receive DFIFO -void dfifo_read_packet(dwc2_regs_t* dwc2, uint8_t* dst, uint16_t len) { - const volatile uint32_t* rx_fifo = dwc2->fifo[0]; - - // Reading full available 32 bit words from fifo - uint16_t word_count = len >> 2; - while (word_count--) { - tu_unaligned_write32(dst, *rx_fifo); - dst += 4; - } - - // Read the remaining 1-3 bytes from fifo - const uint8_t bytes_rem = len & 0x03; - if (bytes_rem != 0) { - const uint32_t tmp = *rx_fifo; - dst[0] = tu_u32_byte0(tmp); - if (bytes_rem > 1) { - dst[1] = tu_u32_byte1(tmp); - } - if (bytes_rem > 2) { - dst[2] = tu_u32_byte2(tmp); - } - } -} - -// Write a single data packet to DFIFO -void dfifo_write_packet(dwc2_regs_t* dwc2, uint8_t fifo_num, const uint8_t* src, uint16_t len) { - volatile uint32_t* tx_fifo = dwc2->fifo[fifo_num]; - - // Pushing full available 32 bit words to fifo - uint16_t word_count = len >> 2; - while (word_count--) { - *tx_fifo = tu_unaligned_read32(src); - src += 4; - } - - // Write the remaining 1-3 bytes into fifo - const uint8_t bytes_rem = len & 0x03; - if (bytes_rem) { - uint32_t tmp_word = src[0]; - if (bytes_rem > 1) { - tmp_word |= (src[1] << 8); - } - if (bytes_rem > 2) { - tmp_word |= (src[2] << 16); - } - - *tx_fifo = tmp_word; - } -} - -#endif diff --git a/src/portable/socfpga/dwc2/dwc2_common.h b/src/portable/socfpga/dwc2/dwc2_common.h deleted file mode 100644 index b90e2eb7d..000000000 --- a/src/portable/socfpga/dwc2/dwc2_common.h +++ /dev/null @@ -1,105 +0,0 @@ -/* -* The MIT License (MIT) - * - * Copyright (c) 2024 Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#ifndef TUSB_DWC2_COMMON_H -#define TUSB_DWC2_COMMON_H - -#include "common/tusb_common.h" -#include "dwc2_type.h" - -// Following symbols must be defined by port header -// - _dwc2_controller[]: array of controllers -// - DWC2_EP_MAX: largest EP counts of all controllers -// - dwc2_phy_init/dwc2_phy_update: phy init called before and after core reset -// - dwc2_dcd_int_enable/dwc2_dcd_int_disable -// - dwc2_remote_wakeup_delay - -#if defined(TUP_USBIP_DWC2_STM32) - #include "dwc2_stm32.h" -#elif defined(TUP_USBIP_DWC2_ESP32) - #include "dwc2_esp32.h" -#elif TU_CHECK_MCU(OPT_MCU_GD32VF103) - #include "dwc2_gd32.h" -#elif TU_CHECK_MCU(OPT_MCU_BCM2711, OPT_MCU_BCM2835, OPT_MCU_BCM2837) - #include "dwc2_bcm.h" -#elif TU_CHECK_MCU(OPT_MCU_EFM32GG) - #include "dwc2_efm32.h" -#elif TU_CHECK_MCU(OPT_MCU_XMC4000) - #include "dwc2_xmc.h" -#elif defined(TUP_USBIP_DWC2_AT32) - #include "dwc2_at32.h" -#elif TU_CHECK_MCU(OPT_MCU_SOCFPGA) - #include "dwc2_socfpga.h" -#else - #error "Unsupported MCUs" -#endif - -enum { - DWC2_CONTROLLER_COUNT = TU_ARRAY_SIZE(_dwc2_controller) -}; - -enum { - OTG_INT_COMMON = 0 // GINTSTS_DISCINT | GINTSTS_CONIDSTSCHNG -}; - -//--------------------------------------------------------------------+ -// Core/Controller -//--------------------------------------------------------------------+ -TU_ATTR_ALWAYS_INLINE static inline dwc2_regs_t* DWC2_REG(uint8_t rhport) { - if (rhport >= DWC2_CONTROLLER_COUNT) { - // user mis-configured, ignore and use first controller - rhport = 0; - } - return (dwc2_regs_t*)_dwc2_controller[rhport].reg_base; -} - -bool dwc2_core_is_highspeed(dwc2_regs_t* dwc2, tusb_role_t role); -bool dwc2_core_init(uint8_t rhport, bool is_highspeed, bool is_dma); -void dwc2_core_handle_common_irq(uint8_t rhport, bool in_isr); - -//--------------------------------------------------------------------+ -// DFIFO -//--------------------------------------------------------------------+ -TU_ATTR_ALWAYS_INLINE static inline void dfifo_flush_tx(dwc2_regs_t* dwc2, uint8_t fnum) { - // flush TX fifo and wait for it cleared - dwc2->grstctl = GRSTCTL_TXFFLSH | (fnum << GRSTCTL_TXFNUM_Pos); - while (dwc2->grstctl & GRSTCTL_TXFFLSH_Msk) {} -} - -TU_ATTR_ALWAYS_INLINE static inline void dfifo_flush_rx(dwc2_regs_t* dwc2) { - // flush RX fifo and wait for it cleared - dwc2->grstctl = GRSTCTL_RXFFLSH; - while (dwc2->grstctl & GRSTCTL_RXFFLSH_Msk) {} -} - -void dfifo_read_packet(dwc2_regs_t* dwc2, uint8_t* dst, uint16_t len); -void dfifo_write_packet(dwc2_regs_t* dwc2, uint8_t fifo_num, uint8_t const* src, uint16_t len); - -//--------------------------------------------------------------------+ -// DMA -//--------------------------------------------------------------------+ - -#endif diff --git a/src/portable/socfpga/dwc2/dwc2_socfpga.h b/src/portable/socfpga/dwc2/dwc2_socfpga.h deleted file mode 100644 index 37e2970c0..000000000 --- a/src/portable/socfpga/dwc2/dwc2_socfpga.h +++ /dev/null @@ -1,225 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021, Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#ifndef DWC2_SOCFPGA_H_ -#define DWC2_SOCFPGA_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -// EP_MAX : Max number of bi-directional endpoints including EP0 -// EP_FIFO_SIZE : Size of dedicated USB SRAM -#if CFG_TUSB_MCU == OPT_MCU_SOCFPGA - #include "socfpga_usb_otg_reg.h" - #include "socfpga_interrupt.h" - #include "socfpga_cache.h" - #include "socfpga_gpio.h" - #include "osal_log.h" - //toggle gpio for usb2 reset - #define USB_GPIO_TOGGLE 0 -#else - #error "Unsupported MCUs" -#endif - -// OTG HS always has higher number of endpoints than FS -#ifdef USB_OTG_HS_PERIPH_BASE - #define DWC2_EP_MAX EP_MAX_HS -#else - #define DWC2_EP_MAX EP_MAX_FS -#endif - -// On Agilex5 socfpga, we associate: -// - Port0 to USB_OTG -static const dwc2_controller_t _dwc2_controller[] = { - { .reg_base = USBOTG_BASE_ADDR, .irqnum = USB0IRQ, .ep_count = 15, .ep_fifo_size = 8192 }, -}; - -//--------------------------------------------------------------------+ -// -//--------------------------------------------------------------------+ - -static void dwc2_int_handler_wrap() { - hcd_int_handler(0, true); -} - -TU_ATTR_ALWAYS_INLINE static inline void dwc2_int_set(uint8_t rhport, tusb_role_t role, bool enabled) { - (void) role; - (void) rhport; - (void) enabled; - int intr_ret; - - intr_ret = interrupt_register_isr(USB0IRQ, dwc2_int_handler_wrap, NULL); - if (intr_ret != 0) - { - ERROR("Failed to enable interrupt"); - return; - } - - intr_ret = interrupt_enable(USB0IRQ, GIC_INTERRUPT_PRIORITY_USB2); - if (intr_ret != 0) - { - ERROR("Failed to enable interrupt"); - return; - } - - INFO("Interrupt handler registered successfully"); - -} - -#define dwc2_dcd_int_enable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, true) -#define dwc2_dcd_int_disable(_rhport) dwc2_int_set(_rhport, TUSB_ROLE_DEVICE, false) - - -TU_ATTR_ALWAYS_INLINE static inline void dwc2_remote_wakeup_delay(void) { - // try to delay for 1 ms - osal_task_delay(1); -} - -// MCU specific PHY init, called BEFORE core reset -// - dwc2 3.30a (H5) use USB_HS_PHYC -// - dwc2 4.11a (U5) use femtoPHY -static inline void dwc2_phy_init(dwc2_regs_t* dwc2, uint8_t hs_phy_type) { - if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) { - // Enable on-chip FS PHY - dwc2->stm32_gccfg |= STM32_GCCFG_PWRDWN; - - // https://community.st.com/t5/stm32cubemx-mcus/why-stm32h743-usb-fs-doesn-t-work-if-freertos-tickless-idle/m-p/349480#M18867 - // H7 running on full-speed phy need to disable ULPI clock in sleep mode. - // Otherwise, USB won't work when mcu executing WFI/WFE instruction i.e tick-less RTOS. - // Note: there may be other family that is affected by this, but only H7 and F7 is tested so far - #if defined(USB_OTG_FS_PERIPH_BASE) && defined(RCC_AHB1LPENR_USB2OTGFSULPILPEN) - if ( USB_OTG_FS_PERIPH_BASE == (uint32_t) dwc2 ) { - RCC->AHB1LPENR &= ~RCC_AHB1LPENR_USB2OTGFSULPILPEN; - } - #endif - - #if defined(USB_OTG_HS_PERIPH_BASE) && defined(RCC_AHB1LPENR_USB1OTGHSULPILPEN) - if ( USB_OTG_HS_PERIPH_BASE == (uint32_t) dwc2 ) { - RCC->AHB1LPENR &= ~RCC_AHB1LPENR_USB1OTGHSULPILPEN; - } - #endif - - #if defined(USB_OTG_HS_PERIPH_BASE) && defined(RCC_AHB1LPENR_OTGHSULPILPEN) - if ( USB_OTG_HS_PERIPH_BASE == (uint32_t) dwc2 ) { - RCC->AHB1LPENR &= ~RCC_AHB1LPENR_OTGHSULPILPEN; - } - #endif - - } else { -#if CFG_TUSB_MCU != OPT_MCU_STM32U5 - // Disable FS PHY, TODO on U5A5 (dwc2 4.11a) 16th bit is 'Host CDP behavior enable' - dwc2->stm32_gccfg &= ~STM32_GCCFG_PWRDWN; -#endif - - // Enable on-chip HS PHY - if (hs_phy_type == GHWCFG2_HSPHY_UTMI || hs_phy_type == GHWCFG2_HSPHY_UTMI_ULPI) { - #ifdef USB_HS_PHYC - // Enable UTMI HS PHY - dwc2->stm32_gccfg |= STM32_GCCFG_PHYHSEN; - - // Enable LDO - USB_HS_PHYC->USB_HS_PHYC_LDO |= USB_HS_PHYC_LDO_ENABLE; - - // Wait until LDO ready - while ( 0 == (USB_HS_PHYC->USB_HS_PHYC_LDO & USB_HS_PHYC_LDO_STATUS) ) {} - - uint32_t phyc_pll = 0; - - // TODO Try to get HSE_VALUE from registers instead of depending CFLAGS - switch ( HSE_VALUE ) - { - case 12000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12MHZ ; break; - case 12500000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_12_5MHZ ; break; - case 16000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_16MHZ ; break; - case 24000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_24MHZ ; break; - case 25000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_25MHZ ; break; - case 32000000: phyc_pll = USB_HS_PHYC_PLL1_PLLSEL_Msk ; break; // Value not defined in header - default: - TU_ASSERT(false, ); - } - USB_HS_PHYC->USB_HS_PHYC_PLL = phyc_pll; - - // Control the tuning interface of the High Speed PHY - // Use magic value (USB_HS_PHYC_TUNE_VALUE) from ST driver for F7 - USB_HS_PHYC->USB_HS_PHYC_TUNE |= 0x00000F13U; - - // Enable PLL internal PHY - USB_HS_PHYC->USB_HS_PHYC_PLL |= USB_HS_PHYC_PLL_PLLEN; - #else - - #endif - } - } -} - -// MCU specific PHY update, it is called AFTER init() and core reset -static inline void dwc2_phy_update(dwc2_regs_t* dwc2, uint8_t hs_phy_type) { - // used to set turnaround time for fullspeed, nothing to do in highspeed mode - (void)dwc2; - if (hs_phy_type == GHWCFG2_HSPHY_NOT_SUPPORTED) { - // Turnaround timeout depends on the AHB clock dictated by STM32 Reference Manual - } -} - -//------------- DCache -------------// -#if CFG_TUD_MEM_DCACHE_ENABLE || CFG_TUH_MEM_DCACHE_ENABLE - -TU_ATTR_ALWAYS_INLINE static inline uint32_t round_up_to_cache_line_size(uint32_t size) { - if (size & (CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT-1)) { - size = (size & ~(CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT-1)) + CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT; - } - return size; -} - -TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_clean(void const* addr, uint32_t data_size) { - const uintptr_t addr32 = (uintptr_t) addr; - data_size = round_up_to_cache_line_size(data_size); - cache_force_write_back((uint32_t *) addr32, (int32_t) data_size); - return true; -} - -TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_invalidate(void const* addr, uint32_t data_size) { - const uintptr_t addr32 = (uintptr_t) addr; - data_size = round_up_to_cache_line_size(data_size); - cache_force_invalidate((uint32_t *) addr32, (int32_t) data_size); - return true; -} - -TU_ATTR_ALWAYS_INLINE static inline bool dwc2_dcache_clean_invalidate(void const* addr, uint32_t data_size) { - const uintptr_t addr32 = (uintptr_t) addr; - data_size = round_up_to_cache_line_size(data_size); - cache_force_invalidate((uint32_t *) addr32, (int32_t) data_size); - cache_force_write_back((uint32_t *) addr32, (int32_t) data_size); - return true; -} -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/portable/socfpga/dwc2/dwc2_type.h b/src/portable/socfpga/dwc2/dwc2_type.h deleted file mode 100644 index 0a8dacf5f..000000000 --- a/src/portable/socfpga/dwc2/dwc2_type.h +++ /dev/null @@ -1,2286 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2024, hathach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ -/**

© Copyright (c) 2019 STMicroelectronics. - * All rights reserved.

- * - * This software component is licensed by ST under BSD 3-Clause license, - * the "License"; You may not use this file except in compliance with the - * License. You may obtain a copy of the License at: - * opensource.org/licenses/BSD-3-Clause - */ - -#ifndef TUSB_DWC2_TYPES_H_ -#define TUSB_DWC2_TYPES_H_ - -#include "stdint.h" - -#ifdef __cplusplus - extern "C" { -#endif - -// Controller -typedef struct -{ - uintptr_t reg_base; - uint32_t irqnum; - uint8_t ep_count; - uint8_t ep_in_count; - uint32_t ep_fifo_size; -}dwc2_controller_t; - -// DWC OTG HW Release versions -#define DWC2_CORE_REV_2_71a 0x4f54271a -#define DWC2_CORE_REV_2_72a 0x4f54272a -#define DWC2_CORE_REV_2_80a 0x4f54280a -#define DWC2_CORE_REV_2_90a 0x4f54290a -#define DWC2_CORE_REV_2_91a 0x4f54291a -#define DWC2_CORE_REV_2_92a 0x4f54292a -#define DWC2_CORE_REV_2_94a 0x4f54294a -#define DWC2_CORE_REV_3_00a 0x4f54300a -#define DWC2_CORE_REV_3_10a 0x4f54310a -#define DWC2_CORE_REV_4_00a 0x4f54400a -#define DWC2_CORE_REV_4_11a 0x4f54411a -#define DWC2_CORE_REV_4_20a 0x4f54420a -#define DWC2_FS_IOT_REV_1_00a 0x5531100a -#define DWC2_HS_IOT_REV_1_00a 0x5532100a -#define DWC2_CORE_REV_MASK 0x0000ffff - -// DWC OTG HW Core ID -#define DWC2_OTG_ID 0x4f540000 -#define DWC2_FS_IOT_ID 0x55310000 -#define DWC2_HS_IOT_ID 0x55320000 - -#if 0 -// HS PHY -typedef struct -{ - volatile uint32_t HS_PHYC_PLL; // 000h This register is used to control the PLL of the HS PHY. - volatile uint32_t Reserved04; // 004h Reserved - volatile uint32_t Reserved08; // 008h Reserved - volatile uint32_t HS_PHYC_TUNE; // 00Ch This register is used to control the tuning interface of the High Speed PHY. - volatile uint32_t Reserved10; // 010h Reserved - volatile uint32_t Reserved14; // 014h Reserved - volatile uint32_t HS_PHYC_LDO; // 018h This register is used to control the regulator (LDO). -} HS_PHYC_GlobalTypeDef; -#endif - -enum { - GOTGCTL_OTG_VERSION_1_3 = 0, - GOTGCTL_OTG_VERSION_2_0 = 1, -}; - -enum { - GHWCFG2_OPMODE_HNP_SRP = 0, - GHWCFG2_OPMODE_SRP = 1, - GHWCFG2_OPMODE_NON_HNP_NON_SRP = 2, - GHWCFG2_OPMODE_SRP_DEVICE = 3, - GHWCFFG2_OPMODE_NON_OTG_DEVICE = 4, - GHWCFG2_OPMODE_SRP_HOST = 5, - GHWCFG2_OPMODE_NON_OTG_HOST = 6, -}; -enum { - GHWCFG2_ARCH_SLAVE_ONLY = 0, - GHWCFG2_ARCH_EXTERNAL_DMA = 1, - GHWCFG2_ARCH_INTERNAL_DMA = 2, -}; - -enum { - GHWCFG2_HSPHY_NOT_SUPPORTED = 0, - GHWCFG2_HSPHY_UTMI = 1, // internal PHY (mostly) - GHWCFG2_HSPHY_ULPI = 2, // external PHY (mostly) - GHWCFG2_HSPHY_UTMI_ULPI = 3, // both - -}; - -enum { - GHWCFG2_FSPHY_NOT_SUPPORTED = 0, - GHWCFG2_FSPHY_DEDICATED = 1, // have dedicated FS PHY - GHWCFG2_FSPHY_UTMI = 2, // shared with UTMI+ - GHWCFG2_FSPHY_ULPI = 3, // shared with ULPI -}; - -enum { - GHWCFFG4_PHY_DATA_WIDTH_8 = 0, - GHWCFFG4_PHY_DATA_WIDTH_16 = 1, - GHWCFFG4_PHY_DATA_WIDTH_8_16 = 2, // software selectable -}; - -enum { - HPRT_SPEED_HIGH = 0, - HPRT_SPEED_FULL = 1, - HPRT_SPEED_LOW = 2 -}; - -enum { - GINTSTS_CMODE_DEVICE = 0, - GINTSTS_CMODE_HOST = 1, -}; - -enum { - HCTSIZ_PID_DATA0 = 0, // 00b - HCTSIZ_PID_DATA2 = 1, // 01b - HCTSIZ_PID_DATA1 = 2, // 10b - HCTSIZ_PID_SETUP = 3, // 11b -}; -enum { - HCTSIZ_PID_MDATA = 3, -}; - -enum { - GRXSTS_PKTSTS_GLOBAL_OUT_NAK = 1, - GRXSTS_PKTSTS_RX_DATA = 2, - GRXSTS_PKTSTS_RX_COMPLETE = 3, - GRXSTS_PKTSTS_SETUP_DONE = 4, - GRXSTS_PKTSTS_HOST_DATATOGGLE_ERR = 5, - GRXSTS_PKTSTS_SETUP_RX = 6, - GRXSTS_PKTSTS_HOST_CHANNEL_HALTED = 7 -}; - -// Same as TUSB_XFER_* -enum { - HCCHAR_EPTYPE_CONTROL = 0, - HCCHAR_EPTYPE_ISOCHRONOUS = 1, - HCCHAR_EPTYPE_BULK = 2, - HCCHAR_EPTYPE_INTERRUPT = 3 -}; - -enum { - DCFG_SPEED_HIGH = 0, // Highspeed with 30/60 Mhz - DCFG_SPEED_FULL_30_60MHZ = 1, // Fullspeed with UTMI+/ULPI 30/60 Mhz - DCFG_SPEED_LOW = 2, // Lowspeed with FS PHY at 6 Mhz - DCFG_SPEED_FULL_48MHZ = 3, // Fullspeed with dedicated FS PHY at 48 Mhz -}; - -// Same as TUSB_XFER_* -enum { - DEPCTL_EPTYPE_CONTROL = 0, - DEPCTL_EPTYPE_ISOCHRONOUS = 1, - DEPCTL_EPTYPE_BULK = 2, - DEPCTL_EPTYPE_INTERRUPT = 3 -}; - -//-------------------------------------------------------------------- -// Common Register Bitfield -//-------------------------------------------------------------------- -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t ses_req_scs : 1; // 0 Session request success - uint32_t ses_req : 1; // 1 Session request - uint32_t vbval_ov_en : 1; // 2 VBUS valid override enable - uint32_t vbval_ov_val : 1; // 3 VBUS valid override value - uint32_t aval_ov_en : 1; // 4 A-peripheral session valid override enable - uint32_t aval_ov_al : 1; // 5 A-peripheral session valid override value - uint32_t bval_ov_en : 1; // 6 B-peripheral session valid override enable - uint32_t bval_ov_val : 1; // 7 B-peripheral session valid override value - uint32_t hng_scs : 1; // 8 Host negotiation success - uint32_t hnp_rq : 1; // 9 HNP (host negotiation protocol) request - uint32_t host_set_hnp_en : 1; // 10 Host set HNP enable - uint32_t dev_hnp_en : 1; // 11 Device HNP enabled - uint32_t embedded_host_en : 1; // 12 Embedded host enable - uint32_t rsv13_14 : 2; // 13.14 Reserved - uint32_t dbnc_filter_bypass : 1; // 15 Debounce filter bypass - uint32_t cid_status : 1; // 16 Connector ID status - uint32_t dbnc_done : 1; // 17 Debounce done - uint32_t ases_valid : 1; // 18 A-session valid - uint32_t bses_valid : 1; // 19 B-session valid - uint32_t otg_ver : 1; // 20 OTG version 0: v1.3, 1: v2.0 - uint32_t current_mode : 1; // 21 Current mode of operation. Only from v3.00a - uint32_t mult_val_id_bc : 5; // 22..26 Multi-valued input pin ID battery charger - uint32_t chirp_en : 1; // 27 Chirp detection enable - uint32_t rsv28_30 : 3; // 28.30: Reserved - uint32_t test_mode_corr_eusb2 : 1; // 31 Test mode control for eUSB2 PHY - }; -} dwc2_gotgctl_t; -TU_VERIFY_STATIC(sizeof(dwc2_gotgctl_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t rsv0_1 : 2; // 0..1 Reserved - uint32_t ses_end_det : 1; // 2 Session end detected - uint32_t rsv3_7 : 5; // 3..7 Reserved - uint32_t srs_status_change : 1; // 8 Session request success status change - uint32_t hns_status_change : 1; // 9 Host negotiation success status change - uint32_t rsv10_16 : 7; // 10..16 Reserved - uint32_t hng_det : 1; // 17 Host negotiation detected - uint32_t adev_timeout_change : 1; // 18 A-device timeout change - uint32_t dbnc_done : 1; // 19 Debounce done - uint32_t mult_val_lp_change : 1; // 20 Multi-valued input pin change - uint32_t rsv21_31 :11; // 21..31 Reserved - }; -} dwc2_gotgint_t; -TU_VERIFY_STATIC(sizeof(dwc2_gotgint_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t gintmask : 1; // 0 Global interrupt mask - uint32_t hbst_len : 4; // 1..4 Burst length/type - uint32_t dma_en : 1; // 5 DMA enable - uint32_t rsv6 : 1; // 6 Reserved - uint32_t nptxf_empty_lvl : 1; // 7 Non-periodic Tx FIFO empty level - uint32_t ptxf_empty_lvl : 1; // 8 Periodic Tx FIFO empty level - uint32_t rsv9_20 : 12; // 9.20: Reserved - uint32_t remote_mem_support : 1; // 21 Remote memory support - uint32_t notify_all_dma_write : 1; // 22 Notify all DMA writes - uint32_t ahb_single : 1; // 23 AHB single - uint32_t inv_desc_endian : 1; // 24 Inverse descriptor endian - uint32_t rsv25_31 : 7; // 25..31 Reserved - }; -} dwc2_gahbcfg_t; -TU_VERIFY_STATIC(sizeof(dwc2_gahbcfg_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t timeout_cal : 3; /* 0..2 Timeout calibration. - The USB standard timeout value for high-speed operation is 736 to 816 (inclusive) bit times. The USB standard - timeout value for full- speed operation is 16 to 18 (inclusive) bit times. The application must program this field - based on the speed of enumeration. The number of bit times added per PHY clock are as follows: - - High-speed: PHY clock One 30-MHz = 16 bit times, One 60-MHz = 8 bit times - - Full-speed: PHY clock One 30-MHz = 0.4 bit times, One 60-MHz = 0.2 bit times, One 48-MHz = 0.25 bit times */ - uint32_t phy_if16 : 1; // 3 PHY interface. 0: 8 bits, 1: 16 bits - uint32_t ulpi_utmi_sel : 1; // 4 ULPI/UTMI select. 0: UTMI+, 1: ULPI - uint32_t fs_intf_sel : 1; // 5 Fullspeed serial interface select. 0: 6-pin, 1: 3-pin - uint32_t phy_sel : 1; // 6 HS/FS PHY selection. 0: HS UTMI+ or ULPI, 1: FS serial transceiver - uint32_t ddr_sel : 1; // 7 ULPI DDR select. 0: Single data rate 8-bit, 1: Double data rate 4-bit - uint32_t srp_capable : 1; // 8 SRP-capable - uint32_t hnp_capable : 1; // 9 HNP-capable - uint32_t turnaround_time : 4; // 10..13 Turnaround time. 9: 8-bit UTMI+, 5: 16-bit UTMI+ - uint32_t rsv14 : 1; // 14 Reserved - uint32_t phy_low_power_clk_sel : 1; /* 15 PHY low-power clock select either 480-MHz or 48-MHz (low-power) PHY mode. - In FS/LS modes, the PHY can usually operate on a 48-MHz clock to save power. This bit is valid only for UTMI+ PHYs. - - 0: 480 Mhz internal PLL: the UTMI interface operates at either 60 MHz (8 bit) or 30 MHz (16-bit) - - 1 48 Mhz external clock: the UTMI interface operates at 48 MHz in FS mode and at either 48 or 6 MHz in LS mode */ - uint32_t otg_i2c_sel : 1; // 16 OTG I2C interface select. 0: UTMI-FS, 1: I2C for OTG signals - uint32_t ulpi_fsls : 1; /* 17 ULPI FS/LS select. 0: ULPI, 1: ULPI FS/LS. - valid only when the FS serial transceiver is selected on the ULPI PHY. */ - uint32_t ulpi_auto_resume : 1; // 18 ULPI Auto-resume - uint32_t ulpi_clk_sus_m : 1; // 19 ULPI Clock SuspendM - uint32_t ulpi_ext_vbus_drv : 1; // 20 ULPI External VBUS Drive - uint32_t ulpi_int_vbus_indicator : 1; // 21 ULPI Internal VBUS Indicator - uint32_t term_sel_dl_pulse : 1; // 22 TermSel DLine pulsing - uint32_t indicator_complement : 1; // 23 Indicator complement - uint32_t indicator_pass_through : 1; // 24 Indicator pass through - uint32_t ulpi_if_protect_disable : 1; // 25 ULPI interface protect disable - uint32_t ic_usb_capable : 1; // 26 IC_USB Capable - uint32_t ic_usb_traf_ctl : 1; // 27 IC_USB Traffic Control - uint32_t tx_end_delay : 1; // 28 TX end delay - uint32_t force_host_mode : 1; // 29 Force host mode - uint32_t force_dev_mode : 1; // 30 Force device mode - uint32_t corrupt_tx_pkt : 1; // 31 Corrupt Tx packet. 0: normal, 1: debug - }; -} dwc2_gusbcfg_t; -TU_VERIFY_STATIC(sizeof(dwc2_gusbcfg_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t core_soft_rst : 1; // 0 Core Soft Reset - uint32_t piufs_soft_rst : 1; // 1 PIU FS Dedicated Controller Soft Reset - uint32_t frame_counter_rst : 1; // 2 Frame Counter Reset (host) - uint32_t intoken_q_flush : 1; // 3 IN Token Queue Flush - uint32_t rx_fifo_flush : 1; // 4 RX FIFO Flush - uint32_t tx_fifo_flush : 1; // 5 TX FIFO Flush - uint32_t tx_fifo_num : 5; // 6..10 TX FIFO Number - uint32_t rsv11_28 :18; // 11..28 Reserved - uint32_t core_soft_rst_done : 1; // 29 Core Soft Reset Done, from v4.20a - uint32_t dma_req : 1; // 30 DMA Request - uint32_t ahb_idle : 1; // 31 AHB Idle - }; -} dwc2_grstctl_t; -TU_VERIFY_STATIC(sizeof(dwc2_grstctl_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t ep_ch_num : 4; // 0..3 Endpoint/Channel Number - uint32_t byte_count :11; // 4..14 Byte Count - uint32_t dpid : 2; // 15..16 Data PID - uint32_t packet_status : 4; // 17..20 Packet Status - uint32_t frame_number : 4; // 21..24 Frame Number - uint32_t rsv25_31 : 7; // 25..31 Reserved - }; -} dwc2_grxstsp_t; -TU_VERIFY_STATIC(sizeof(dwc2_grxstsp_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t op_mode : 3; // 0..2 HNP/SRP Host/Device/OTG mode - uint32_t arch : 2; // 3..4 Slave/External/Internal DMA - uint32_t single_point : 1; // 5 0: support hub and split | 1: no hub, no split - uint32_t hs_phy_type : 2; // 6..7 0: not supported | 1: UTMI+ | 2: ULPI | 3: UTMI+ and ULPI - uint32_t fs_phy_type : 2; // 8..9 0: not supported | 1: dedicated | 2: UTMI+ | 3: ULPI - uint32_t num_dev_ep : 4; // 10..13 Number of device endpoints (excluding EP0) - uint32_t num_host_ch : 4; // 14..17 Number of host channel (excluding control) - uint32_t period_channel_support : 1; // 18 Support Periodic OUT Host Channel - uint32_t enable_dynamic_fifo : 1; // 19 Dynamic FIFO Sizing Enabled - uint32_t mul_proc_intrpt : 1; // 20 Multi-Processor Interrupt enabled (OTG_MULTI_PROC_INTRPT) - uint32_t reserved21 : 1; // 21 reserved - uint32_t nptx_q_depth : 2; // 22..23 Non-periodic request queue depth: 0 = 2. 1 = 4, 2 = 8 - uint32_t ptx_q_depth : 2; // 24..25 Host periodic request queue depth: 0 = 2. 1 = 4, 2 = 8 - uint32_t token_q_depth : 5; // 26..30 Device IN token sequence learning queue depth: 0-30 - uint32_t otg_enable_ic_usb : 1; // 31 IC_USB mode specified for mode of operation - }; -} dwc2_ghwcfg2_t; -TU_VERIFY_STATIC(sizeof(dwc2_ghwcfg2_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t xfer_size_width : 4; // 0..3 Transfer size counter in bits = 11 + n (max 19 bits) - uint32_t packet_size_width : 3; // 4..6 Packet size counter in bits = 4 + n (max 10 bits) - uint32_t otg_enable : 1; // 7 OTG capable - uint32_t i2c_enable : 1; // 8 I2C interface is available - uint32_t vendor_ctrl_itf : 1; // 9 Vendor control interface is available - uint32_t optional_feature_removed : 1; // 10 remove User ID, GPIO, SOF toggle & counter to save gate count - uint32_t synch_reset : 1; // 11 0: async reset | 1: synch reset - uint32_t otg_adp_support : 1; // 12 ADP logic is present along with HSOTG controller - uint32_t otg_enable_hsic : 1; // 13 1: HSIC-capable with shared UTMI PHY interface | 0: non-HSIC - uint32_t battery_charger_support : 1; // s14 upport battery charger - uint32_t lpm_mode : 1; // 15 LPM mode - uint32_t dfifo_depth : 16; // DFIFO depth - EP_LOC_CNT in terms of 32-bit words - }; -} dwc2_ghwcfg3_t; -TU_VERIFY_STATIC(sizeof(dwc2_ghwcfg3_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t num_dev_period_in_ep : 4; // 0..3 Number of Device Periodic IN Endpoints - uint32_t partial_powerdown : 1; // 4 Partial Power Down Enabled - uint32_t ahb_freq_min : 1; // 5 1: minimum of AHB frequency is less than 60 MHz - uint32_t hibernation : 1; // 6 Hibernation feature is enabled - uint32_t extended_hibernation : 1; // 7 Extended Hibernation feature is enabled - uint32_t reserved8 : 1; // 8 Reserved - uint32_t enhanced_lpm_support1 : 1; // 9 Enhanced LPM Support1 - uint32_t service_interval_flow : 1; // 10 Service Interval flow is supported - uint32_t ipg_isoc_support : 1; // 11 Interpacket GAP ISO OUT worst-case is supported - uint32_t acg_support : 1; // 12 Active clock gating is supported - uint32_t enhanced_lpm_support : 1; // 13 Enhanced LPM Support - uint32_t phy_data_width : 2; // 14..15 0: 8 bits | 1: 16 bits | 2: 8/16 software selectable - uint32_t ctrl_ep_num : 4; // 16..19 Number of Device control endpoints in addition to EP0 - uint32_t iddg_filter : 1; // 20 IDDG Filter Enabled - uint32_t vbus_valid_filter : 1; // 21 VBUS Valid Filter Enabled - uint32_t a_valid_filter : 1; // 22 A Valid Filter Enabled - uint32_t b_valid_filter : 1; // 23 B Valid Filter Enabled - uint32_t session_end_filter : 1; // 24 Session End Filter Enabled - uint32_t dedicated_fifos : 1; // 25 Dedicated tx fifo for device IN Endpoint - uint32_t num_dev_in_eps : 4; // 26..29 Number of Device IN Endpoints including EP0 - uint32_t dma_desc_enabled : 1; // scatter/gather DMA configuration enabled - uint32_t dma_desc_dynamic : 1; // Dynamic scatter/gather DMA - }; -} dwc2_ghwcfg4_t; -TU_VERIFY_STATIC(sizeof(dwc2_ghwcfg4_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t fifo_available : 16; // 0..15 Number of words available in the Tx FIFO - uint32_t req_queue_available : 8; // 16..23 Number of spaces available in the NPT transmit request queue for both IN and OU - // 24..31 is top entry in the request queue that is currently being processed by the MAC - uint32_t qtop_terminate : 1; // 24 Last entry for selected channel - uint32_t qtop_type : 2; // 25..26 Token (0) In/Out (1) ZLP, (2) Ping/cspit, (3) Channel halt command - uint32_t qtop_ch_num : 4; // 27..30 Channel number - }; -} dwc2_hnptxsts_t; -TU_VERIFY_STATIC(sizeof(dwc2_hnptxsts_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t fifo_available :16; // 0..15 Number of words available in the Tx FIFO - uint32_t req_queue_available : 7; // 16..22 Number of spaces available in the PTX transmit request queue - uint32_t qtop_terminate : 1; // 23 Last entry for selected channel - uint32_t qtop_last_period : 1; // 24 Last entry for selected channel is a periodic entry - uint32_t qtop_type : 2; // 25..26 Token (0) In/Out (1) ZLP, (2) Ping/cspit, (3) Channel halt command - uint32_t qtop_ch_num : 4; // 27..30 Channel number - uint32_t qtop_odd_frame : 1; // 31 Send in odd frame - }; -} dwc2_hptxsts_t; -TU_VERIFY_STATIC(sizeof(dwc2_hptxsts_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t conn_status : 1; // 0 Port connect status - uint32_t conn_detected : 1; // 1 Port connect detected - uint32_t enable : 1; // 2 Port enable status - uint32_t enable_change : 1; // 3 Port enable change - uint32_t over_current_active : 1; // 4 Port Over-current active - uint32_t over_current_change : 1; // 5 Port Over-current change - uint32_t resume : 1; // 6 Port resume - uint32_t suspend : 1; // 7 Port suspend - uint32_t reset : 1; // 8 Port reset - uint32_t rsv9 : 1; // 9 Reserved - uint32_t line_status : 2; // 10..11 Line status - uint32_t power : 1; // 12 Port power - uint32_t test_control : 4; // 13..16 Port Test control - uint32_t speed : 2; // 17..18 Port speed - uint32_t rsv19_31 :13; // 19..31 Reserved - }; -} dwc2_hprt_t; -TU_VERIFY_STATIC(sizeof(dwc2_hprt_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t ep_size : 11; // 0..10 Maximum packet size - uint32_t ep_num : 4; // 11..14 Endpoint number - uint32_t ep_dir : 1; // 15 Endpoint direction - uint32_t rsv16 : 1; // 16 Reserved - uint32_t low_speed_dev : 1; // 17 Low-speed device - uint32_t ep_type : 2; // 18..19 Endpoint type - uint32_t err_multi_count : 2; // 20..21 Error (splitEn = 1) / Multi (SplitEn = 0) count - uint32_t dev_addr : 7; // 22..28 Device address - uint32_t odd_frame : 1; // 29 Odd frame - uint32_t disable : 1; // 30 Channel disable - uint32_t enable : 1; // 31 Channel enable - }; -} dwc2_channel_char_t; -TU_VERIFY_STATIC(sizeof(dwc2_channel_char_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t hub_port : 7; // 0..6 Hub port number - uint32_t hub_addr : 7; // 7..13 Hub address - uint32_t xact_pos : 2; // 14..15 Transaction position - uint32_t split_compl : 1; // 16 Split completion - uint32_t rsv17_30 : 14; // 17..30 Reserved - uint32_t split_en : 1; // 31 Split enable - }; -} dwc2_channel_split_t; -TU_VERIFY_STATIC(sizeof(dwc2_channel_split_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t xfer_size : 19; // 0..18 Transfer size in bytes - uint32_t packet_count : 10; // 19..28 Number of packets - uint32_t pid : 2; // 29..30 Packet ID - uint32_t do_ping : 1; // 31 Do PING - }; -} dwc2_channel_tsize_t; -TU_VERIFY_STATIC(sizeof(dwc2_channel_tsize_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t num : 16; // 0..15 Frame number - uint32_t remainning : 16; // 16..31 Frame remaining - }; -} dwc2_hfnum_t; -TU_VERIFY_STATIC(sizeof(dwc2_hfnum_t) == 4, "incorrect size"); - -// Host Channel -typedef struct { - volatile uint32_t hcchar; // 500 + 20*ch Host Channel Characteristics - volatile uint32_t hcsplt; // 504 + 20*ch Host Channel Split Control - volatile uint32_t hcint; // 508 + 20*ch Host Channel Interrupt - volatile uint32_t hcintmsk; // 50C + 20*ch Host Channel Interrupt Mask - volatile uint32_t hctsiz; // 510 + 20*ch Host Channel Transfer Size - volatile uint32_t hcdma; // 514 + 20*ch Host Channel DMA Address - uint32_t reserved518; // 518 + 20*ch - volatile uint32_t hcdmab; // 51C + 20*ch Host Channel DMA Address -} dwc2_channel_t; - -//-------------------------------------------------------------------- -// Device Register Bitfield -//-------------------------------------------------------------------- -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t speed : 2; // 0..1 Speed - uint32_t nzsts_out_handshake : 1; // 2 Non-zero-length status OUT handshake - uint32_t en_32khz_suspsend : 1; // 3 Enable 32-kHz SUSPEND mode - uint32_t address : 7; // 4..10 Device address - uint32_t period_frame_interval : 2; // 11..12 Periodic frame interval - uint32_t en_out_nak : 1; // 13 Enable Device OUT NAK - uint32_t xcvr_delay : 1; // 14 Transceiver delay - uint32_t erratic_int_mask : 1; // 15 Erratic interrupt mask - uint32_t rsv16 : 1; // 16 Reserved - uint32_t ipg_iso_support : 1; // 17 Interpacket gap ISO support - uint32_t epin_mismatch_count : 5; // 18..22 EP IN mismatch count - uint32_t dma_desc : 1; // 23 Enable scatter/gather DMA descriptor - uint32_t period_schedule_interval : 2; // 24..25 Periodic schedule interval for scatter/gather DMA - uint32_t resume_valid : 6; // 26..31 Resume valid period - }; -} dwc2_dcfg_t; -TU_VERIFY_STATIC(sizeof(dwc2_dcfg_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t remote_wakeup_signal : 1; // 0 Remote wakeup signal - uint32_t soft_disconnet : 1; // 1 Soft disconnect - uint32_t gnp_in_nak_status : 1; // 2 Global non-periodic NAK IN status - uint32_t gout_nak_status : 1; // 3 Global OUT NAK status - uint32_t test_control : 3; // 4..6 Test control - uint32_t set_gnp_in_nak : 1; // 7 Set global non-periodic IN NAK - uint32_t clear_gnp_in_nak : 1; // 8 Clear global non-periodic IN NAK - uint32_t set_gout_nak : 1; // 9 Set global OUT NAK - uint32_t clear_gout_nak : 1; // 10 Clear global OUT NAK - uint32_t poweron_prog_done : 1; // 11 Power-on programming done - uint32_t rsv12 : 1; // 12 Reserved - uint32_t global_multi_count : 2; // 13..14 Global multi-count - uint32_t ignore_frame_number : 1; // 15 Ignore frame number - uint32_t nak_on_babble : 1; // 16 NAK on babble - uint32_t en_cont_on_bna : 1; // 17 Enable continue on BNA - uint32_t deep_sleep_besl_reject : 1; // 18 Deep sleep BESL reject - uint32_t service_interval : 1; // 19 Service interval for ISO IN endpoint - uint32_t rsv20_31 :12; // 20..31 Reserved - }; -} dwc2_dctl_t; -TU_VERIFY_STATIC(sizeof(dwc2_dctl_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t suspend_status : 1; // 0 Suspend status - uint32_t enum_speed : 2; // 1..2 Enumerated speed - uint32_t erratic_err : 1; // 3 Erratic error - uint32_t rsv4_7 : 4; // 4..7 Reserved - uint32_t frame_number :14; // 8..21 Frame/MicroFrame number - uint32_t line_status : 2; // 22..23 Line status - uint32_t rsv24_31 : 8; // 24..31 Reserved - }; -} dwc2_dsts_t; -TU_VERIFY_STATIC(sizeof(dwc2_dsts_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t xfer_complete : 1; // 0 Transfer complete - uint32_t disabled : 1; // 1 Endpoint disabled - uint32_t ahb_err : 1; // 2 AHB error - uint32_t timeout : 1; // 3 Timeout - uint32_t in_rx_txfe : 1; // 4 IN token received when TxFIFO is empty - uint32_t in_rx_ep_mismatch : 1; // 5 IN token received with EP mismatch - uint32_t in_ep_nak_effective : 1; // 6 IN endpoint NAK effective - uint32_t txfifo_empty : 1; // 7 TX FIFO empty - uint32_t txfifo_underrun : 1; // 8 Tx FIFO under run - uint32_t bna : 1; // 9 Buffer not available - uint32_t rsv10 : 1; // 10 Reserved - uint32_t iso_packet_drop : 1; // 11 Isochronous OUT packet drop status - uint32_t babble_err : 1; // 12 Babble error - uint32_t nak : 1; // 13 NAK - uint32_t nyet : 1; // 14 NYET - uint32_t rsv14_31 :17; // 15..31 Reserved - }; -} dwc2_diepint_t; -TU_VERIFY_STATIC(sizeof(dwc2_diepint_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t mps : 11; // 0..10 Maximum packet size, EP0 only use 2 bits - uint32_t next_ep : 4; // 11..14 Next endpoint number - uint32_t active : 1; // 15 Active - uint32_t dpid_iso_odd : 1; // 16 DATA0/DATA1 for bulk/interrupt, odd frame for isochronous - uint32_t nak_status : 1; // 17 NAK status - uint32_t type : 2; // 18..19 Endpoint type - uint32_t rsv20 : 1; // 20 Reserved - uint32_t stall : 1; // 21 Stall - uint32_t tx_fifo_num : 4; // 22..25 Tx FIFO number (IN) - uint32_t clear_nak : 1; // 26 Clear NAK - uint32_t set_nak : 1; // 27 Set NAK - uint32_t set_data0_iso_even : 1; // 28 Set DATA0 if bulk/interrupt, even frame for isochronous - uint32_t set_data1_iso_odd : 1; // 29 Set DATA1 if bulk/interrupt, odd frame for isochronous - uint32_t disable : 1; // 30 Disable - uint32_t enable : 1; // 31 Enable - }; -} dwc2_depctl_t; -TU_VERIFY_STATIC(sizeof(dwc2_depctl_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t xfer_complete : 1; // 0 Transfer complete - uint32_t disabled : 1; // 1 Endpoint disabled - uint32_t ahb_err : 1; // 2 AHB error - uint32_t setup_phase_done : 1; // 3 Setup phase done - uint32_t out_rx_ep_disabled : 1; // 4 OUT token received when endpoint disabled - uint32_t status_phase_rx : 1; // 5 Status phase received - uint32_t setup_b2b : 1; // 6 Setup packet back-to-back - uint32_t rsv7 : 1; // 7 Reserved - uint32_t out_packet_err : 1; // 8 OUT packet error - uint32_t bna : 1; // 9 Buffer not available - uint32_t rsv10 : 1; // 10 Reserved - uint32_t iso_packet_drop : 1; // 11 Isochronous OUT packet drop status - uint32_t babble_err : 1; // 12 Babble error - uint32_t nak : 1; // 13 NAK - uint32_t nyet : 1; // 14 NYET - uint32_t setup_packet_rx : 1; // 15 Setup packet received (Buffer DMA Mode only) - uint32_t rsv16_31 :16; // 16..31 Reserved - }; -} dwc2_doepint_t; -TU_VERIFY_STATIC(sizeof(dwc2_doepint_t) == 4, "incorrect size"); - -typedef union { - uint32_t value; - struct TU_ATTR_PACKED { - uint32_t xfer_size : 19; // 0..18 Transfer size in bytes - uint32_t packet_count : 10; // 19..28 Number of packets - uint32_t mc_pid : 2; // 29..30 IN: Multi Count, OUT: PID - }; -} dwc2_ep_tsize_t; -TU_VERIFY_STATIC(sizeof(dwc2_ep_tsize_t) == 4, "incorrect size"); - -// Device IN/OUT Endpoint -typedef struct { - union { - volatile uint32_t diepctl; - volatile uint32_t doepctl; - volatile uint32_t ctl; - }; - uint32_t rsv04; - union { - volatile uint32_t intr; - volatile uint32_t diepint; - volatile uint32_t doepint; - }; - uint32_t rsv0c; - union { - volatile uint32_t dieptsiz; - volatile uint32_t doeptsiz; - volatile uint32_t tsiz; - }; - union { - volatile uint32_t diepdma; - volatile uint32_t doepdma; - }; - volatile uint32_t dtxfsts; - uint32_t rsv1c; -} dwc2_dep_t; - -TU_VERIFY_STATIC(sizeof(dwc2_dep_t) == 0x20, "incorrect size"); - -//-------------------------------------------------------------------- -// CSR Register Map -//-------------------------------------------------------------------- -typedef struct { - //------------- Core Global ------------- - volatile uint32_t gotgctl; // 000 OTG Control and Status - volatile uint32_t gotgint; // 004 OTG Interrupt - volatile uint32_t gahbcfg; // 008 AHB Configuration - volatile uint32_t gusbcfg; // 00c USB Configuration - volatile uint32_t grstctl; // 010 Reset - volatile uint32_t gintsts; // 014 Interrupt - volatile uint32_t gintmsk; // 018 Interrupt Mask - volatile uint32_t grxstsr; // 01c Receive Status Debug Read - volatile uint32_t grxstsp; // 020 Receive Status Read/Pop - volatile uint32_t grxfsiz; // 024 Receive FIFO Size - union { - volatile uint32_t dieptxf0; // 028 EP0 Tx FIFO Size - volatile uint32_t gnptxfsiz; // 028 Non-periodic Transmit FIFO Size - }; - union { - volatile uint32_t hnptxsts; // 02c Non-periodic Transmit FIFO/Queue Status - volatile uint32_t gnptxsts; - }; - volatile uint32_t gi2cctl; // 030 I2C Address - volatile uint32_t gpvndctl; // 034 PHY Vendor Control - union { - volatile uint32_t ggpio; // 038 General Purpose IO - volatile uint32_t stm32_gccfg; // 038 STM32 General Core Configuration - }; - volatile uint32_t guid; // 03C User (Application programmable) ID - volatile uint32_t gsnpsid; // 040 Synopsys ID + Release version - volatile uint32_t ghwcfg1; // 044 User Hardware Configuration1: endpoint dir (2 bit per ep) - volatile uint32_t ghwcfg2; // 048 User Hardware Configuration2 - volatile uint32_t ghwcfg3; // 04C User Hardware Configuration3 - union { - volatile uint32_t ghwcfg4; // 050 User Hardware Configuration4 - volatile dwc2_ghwcfg4_t ghwcfg4_bm; - }; - volatile uint32_t glpmcfg; // 054 Core LPM Configuration - volatile uint32_t gpwrdn; // 058 Power Down - volatile uint32_t gdfifocfg; // 05C DFIFO Software Configuration - volatile uint32_t gadpctl; // 060 ADP Timer, Control and Status - uint32_t reserved64[39]; // 064..0FF - volatile uint32_t hptxfsiz; // 100 Host Periodic Tx FIFO Size - volatile uint32_t dieptxf[15]; // 104..13C Device Periodic Transmit FIFO Size - uint32_t reserved140[176]; // 140..3FF - - //------------ Host ------------- - volatile uint32_t hcfg; // 400 Host Configuration - volatile uint32_t hfir; // 404 Host Frame Interval - volatile uint32_t hfnum; // 408 Host Frame Number / Frame Remaining - uint32_t reserved40c; // 40C - volatile uint32_t hptxsts; // 410 Host Periodic TX FIFO / Queue Status - volatile uint32_t haint; // 414 Host All Channels Interrupt - volatile uint32_t haintmsk; // 418 Host All Channels Interrupt Mask - volatile uint32_t hflbaddr; // 41C Host Frame List Base Address - uint32_t reserved420[8]; // 420..43F - volatile uint32_t hprt; // 440 Host Port Control and Status - uint32_t reserved444[47]; // 444..4FF - - //------------- Host Channel -------- - dwc2_channel_t channel[16]; // 500..6FF Host Channels 0-15 - uint32_t reserved700[64]; // 700..7FF - - //------------- Device ----------- - volatile uint32_t dcfg; // 800 Device Configuration - volatile uint32_t dctl; // 804 Device Control - volatile uint32_t dsts; // 808 Device Status (RO) - uint32_t reserved80c; // 80C - volatile uint32_t diepmsk; // 810 Device IN Endpoint Interrupt Mask - volatile uint32_t doepmsk; // 814 Device OUT Endpoint Interrupt Mask - volatile uint32_t daint; // 818 Device All Endpoints Interrupt - volatile uint32_t daintmsk; // 81C Device All Endpoints Interrupt Mask - volatile uint32_t dtknqr1; // 820 Device IN token sequence learning queue read1 - volatile uint32_t dtknqr2; // 824 Device IN token sequence learning queue read2 - volatile uint32_t dvbusdis; // 828 Device VBUS Discharge Time - volatile uint32_t dvbuspulse; // 82C Device VBUS Pulsing Time - volatile uint32_t dthrctl; // 830 Device threshold Control - volatile uint32_t diepempmsk; // 834 Device IN Endpoint FIFO Empty Interrupt Mask - - // Device Each Endpoint (IN/OUT) Interrupt/Mask for generating dedicated EP interrupt line require - // OTG_MULTI_PROC_INTRPT=1 - volatile uint32_t deachint; // 838 Device Each Endpoint Interrupt - volatile uint32_t deachmsk; // 83C Device Each Endpoint Interrupt mask - volatile uint32_t diepeachmsk[16]; // 840..87C Device Each IN Endpoint mask - volatile uint32_t doepeachmsk[16]; // 880..8BF Device Each OUT Endpoint mask - uint32_t reserved8c0[16]; // 8C0..8FF - - //------------- Device Endpoint ----- - union { - dwc2_dep_t ep[2][16]; // 0: IN, 1 OUT - struct { - dwc2_dep_t epin[16]; // 900..AFF IN Endpoints - dwc2_dep_t epout[16]; // B00..CFF OUT Endpoints - }; - }; - uint32_t reservedd00[64]; // D00..DFF - - //------------- Power Clock --------- - volatile uint32_t pcgcctl; // E00 Power and Clock Gating Characteristic Control - volatile uint32_t pcgcctl1; // E04 Power and Clock Gating Characteristic Control 1 - uint32_t reservede08[126]; // E08..FFF - - //------------- FIFOs ------------- - // Word-accessed only using first pointer since it auto shift - volatile uint32_t fifo[16][0x400]; // 1000..FFFF Endpoint FIFO -} dwc2_regs_t; - -TU_VERIFY_STATIC(offsetof(dwc2_regs_t, hcfg ) == 0x0400, "incorrect size"); -TU_VERIFY_STATIC(offsetof(dwc2_regs_t, channel) == 0x0500, "incorrect size"); -TU_VERIFY_STATIC(offsetof(dwc2_regs_t, dcfg ) == 0x0800, "incorrect size"); -TU_VERIFY_STATIC(offsetof(dwc2_regs_t, epin ) == 0x0900, "incorrect size"); -TU_VERIFY_STATIC(offsetof(dwc2_regs_t, epout ) == 0x0B00, "incorrect size"); -TU_VERIFY_STATIC(offsetof(dwc2_regs_t, pcgcctl) == 0x0E00, "incorrect size"); -TU_VERIFY_STATIC(offsetof(dwc2_regs_t, fifo ) == 0x1000, "incorrect size"); - -//--------------------------------------------------------------------+ -// Register Bit Definitions -//--------------------------------------------------------------------+ - -/******************** Bit definition for GOTGCTL register ********************/ -#define GOTGCTL_SRQSCS_Pos (0U) -#define GOTGCTL_SRQSCS_Msk (0x1UL << GOTGCTL_SRQSCS_Pos) // 0x00000001 -#define GOTGCTL_SRQSCS GOTGCTL_SRQSCS_Msk // Session request success -#define GOTGCTL_SRQ_Pos (1U) -#define GOTGCTL_SRQ_Msk (0x1UL << GOTGCTL_SRQ_Pos) // 0x00000002 -#define GOTGCTL_SRQ GOTGCTL_SRQ_Msk // Session request -#define GOTGCTL_VBVALOEN_Pos (2U) -#define GOTGCTL_VBVALOEN_Msk (0x1UL << GOTGCTL_VBVALOEN_Pos) // 0x00000004 -#define GOTGCTL_VBVALOEN GOTGCTL_VBVALOEN_Msk // VBUS valid override enable -#define GOTGCTL_VBVALOVAL_Pos (3U) -#define GOTGCTL_VBVALOVAL_Msk (0x1UL << GOTGCTL_VBVALOVAL_Pos) // 0x00000008 -#define GOTGCTL_VBVALOVAL GOTGCTL_VBVALOVAL_Msk // VBUS valid override value -#define GOTGCTL_AVALOEN_Pos (4U) -#define GOTGCTL_AVALOEN_Msk (0x1UL << GOTGCTL_AVALOEN_Pos) // 0x00000010 -#define GOTGCTL_AVALOEN GOTGCTL_AVALOEN_Msk // A-peripheral session valid override enable -#define GOTGCTL_AVALOVAL_Pos (5U) -#define GOTGCTL_AVALOVAL_Msk (0x1UL << GOTGCTL_AVALOVAL_Pos) // 0x00000020 -#define GOTGCTL_AVALOVAL GOTGCTL_AVALOVAL_Msk // A-peripheral session valid override value -#define GOTGCTL_BVALOEN_Pos (6U) -#define GOTGCTL_BVALOEN_Msk (0x1UL << GOTGCTL_BVALOEN_Pos) // 0x00000040 -#define GOTGCTL_BVALOEN GOTGCTL_BVALOEN_Msk // B-peripheral session valid override enable -#define GOTGCTL_BVALOVAL_Pos (7U) -#define GOTGCTL_BVALOVAL_Msk (0x1UL << GOTGCTL_BVALOVAL_Pos) // 0x00000080 -#define GOTGCTL_BVALOVAL GOTGCTL_BVALOVAL_Msk // B-peripheral session valid override value -#define GOTGCTL_HNGSCS_Pos (8U) -#define GOTGCTL_HNGSCS_Msk (0x1UL << GOTGCTL_HNGSCS_Pos) // 0x00000100 -#define GOTGCTL_HNGSCS GOTGCTL_HNGSCS_Msk // Host set HNP enable -#define GOTGCTL_HNPRQ_Pos (9U) -#define GOTGCTL_HNPRQ_Msk (0x1UL << GOTGCTL_HNPRQ_Pos) // 0x00000200 -#define GOTGCTL_HNPRQ GOTGCTL_HNPRQ_Msk // HNP request -#define GOTGCTL_HSHNPEN_Pos (10U) -#define GOTGCTL_HSHNPEN_Msk (0x1UL << GOTGCTL_HSHNPEN_Pos) // 0x00000400 -#define GOTGCTL_HSHNPEN GOTGCTL_HSHNPEN_Msk // Host set HNP enable -#define GOTGCTL_DHNPEN_Pos (11U) -#define GOTGCTL_DHNPEN_Msk (0x1UL << GOTGCTL_DHNPEN_Pos) // 0x00000800 -#define GOTGCTL_DHNPEN GOTGCTL_DHNPEN_Msk // Device HNP enabled -#define GOTGCTL_EHEN_Pos (12U) -#define GOTGCTL_EHEN_Msk (0x1UL << GOTGCTL_EHEN_Pos) // 0x00001000 -#define GOTGCTL_EHEN GOTGCTL_EHEN_Msk // Embedded host enable -#define GOTGCTL_CIDSTS_Pos (16U) -#define GOTGCTL_CIDSTS_Msk (0x1UL << GOTGCTL_CIDSTS_Pos) // 0x00010000 -#define GOTGCTL_CIDSTS GOTGCTL_CIDSTS_Msk // Connector ID status -#define GOTGCTL_DBCT_Pos (17U) -#define GOTGCTL_DBCT_Msk (0x1UL << GOTGCTL_DBCT_Pos) // 0x00020000 -#define GOTGCTL_DBCT GOTGCTL_DBCT_Msk // Long/short debounce time -#define GOTGCTL_ASVLD_Pos (18U) -#define GOTGCTL_ASVLD_Msk (0x1UL << GOTGCTL_ASVLD_Pos) // 0x00040000 -#define GOTGCTL_ASVLD GOTGCTL_ASVLD_Msk // A-session valid -#define GOTGCTL_BSESVLD_Pos (19U) -#define GOTGCTL_BSESVLD_Msk (0x1UL << GOTGCTL_BSESVLD_Pos) // 0x00080000 -#define GOTGCTL_BSESVLD GOTGCTL_BSESVLD_Msk // B-session valid -#define GOTGCTL_OTGVER_Pos (20U) -#define GOTGCTL_OTGVER_Msk (0x1UL << GOTGCTL_OTGVER_Pos) // 0x00100000 -#define GOTGCTL_OTGVER GOTGCTL_OTGVER_Msk // OTG version - -/******************** Bit definition for HCFG register ********************/ -#define HCFG_FSLS_PHYCLK_SEL_Pos (0U) -#define HCFG_FSLS_PHYCLK_SEL_Msk (0x3UL << HCFG_FSLS_PHYCLK_SEL_Pos) // 0x00000003 -#define HCFG_FSLS_PHYCLK_SEL HCFG_FSLS_PHYCLK_SEL_Msk // FS/LS PHY clock select -#define HCFG_FSLS_PHYCLK_SEL_30_60MHZ (0x0UL << HCFG_FSLS_PHYCLK_SEL_Pos) // 0x00000000 -#define HCFG_FSLS_PHYCLK_SEL_48MHZ (0x1UL << HCFG_FSLS_PHYCLK_SEL_Pos) // 0x00000001 -#define HCFG_FSLS_PHYCLK_SEL_6MHZ (0x2UL << HCFG_FSLS_PHYCLK_SEL_Pos) // 0x00000002 - -#define HCFG_FSLS_ONLY_Pos (2U) -#define HCFG_FSLS_ONLY_Msk (0x1UL << HCFG_FSLS_ONLY_Pos) // 0x00000004 -#define HCFG_FSLS_ONLY HCFG_FSLS_ONLY_Msk // FS- and LS-only support - -/******************** Bit definition for PCGCR register ********************/ -#define PCGCR_STPPCLK_Pos (0U) -#define PCGCR_STPPCLK_Msk (0x1UL << PCGCR_STPPCLK_Pos) // 0x00000001 -#define PCGCR_STPPCLK PCGCR_STPPCLK_Msk // Stop PHY clock -#define PCGCR_GATEHCLK_Pos (1U) -#define PCGCR_GATEHCLK_Msk (0x1UL << PCGCR_GATEHCLK_Pos) // 0x00000002 -#define PCGCR_GATEHCLK PCGCR_GATEHCLK_Msk // Gate HCLK -#define PCGCR_PHYSUSP_Pos (4U) -#define PCGCR_PHYSUSP_Msk (0x1UL << PCGCR_PHYSUSP_Pos) // 0x00000010 -#define PCGCR_PHYSUSP PCGCR_PHYSUSP_Msk // PHY suspended - -/******************** Bit definition for GOTGINT register ********************/ -#define GOTGINT_SEDET_Pos (2U) -#define GOTGINT_SEDET_Msk (0x1UL << GOTGINT_SEDET_Pos) // 0x00000004 -#define GOTGINT_SEDET GOTGINT_SEDET_Msk // Session end detected -#define GOTGINT_SRSSCHG_Pos (8U) -#define GOTGINT_SRSSCHG_Msk (0x1UL << GOTGINT_SRSSCHG_Pos) // 0x00000100 -#define GOTGINT_SRSSCHG GOTGINT_SRSSCHG_Msk // Session request success status change -#define GOTGINT_HNSSCHG_Pos (9U) -#define GOTGINT_HNSSCHG_Msk (0x1UL << GOTGINT_HNSSCHG_Pos) // 0x00000200 -#define GOTGINT_HNSSCHG GOTGINT_HNSSCHG_Msk // Host negotiation success status change -#define GOTGINT_HNGDET_Pos (17U) -#define GOTGINT_HNGDET_Msk (0x1UL << GOTGINT_HNGDET_Pos) // 0x00020000 -#define GOTGINT_HNGDET GOTGINT_HNGDET_Msk // Host negotiation detected -#define GOTGINT_ADTOCHG_Pos (18U) -#define GOTGINT_ADTOCHG_Msk (0x1UL << GOTGINT_ADTOCHG_Pos) // 0x00040000 -#define GOTGINT_ADTOCHG GOTGINT_ADTOCHG_Msk // A-device timeout change -#define GOTGINT_DBCDNE_Pos (19U) -#define GOTGINT_DBCDNE_Msk (0x1UL << GOTGINT_DBCDNE_Pos) // 0x00080000 -#define GOTGINT_DBCDNE GOTGINT_DBCDNE_Msk // Debounce done -#define GOTGINT_IDCHNG_Pos (20U) -#define GOTGINT_IDCHNG_Msk (0x1UL << GOTGINT_IDCHNG_Pos) // 0x00100000 -#define GOTGINT_IDCHNG GOTGINT_IDCHNG_Msk // Change in ID pin input value - -/******************** Bit definition for DCFG register ********************/ -#define DCFG_DSPD_Pos (0U) -#define DCFG_DSPD_Msk (0x3UL << DCFG_DSPD_Pos) // 0x00000003 -#define DCFG_DSPD_HS 0 // Highspeed -#define DCFG_DSPD_FS_HSPHY 1 // Fullspeed on HS PHY -#define DCFG_DSPD_LS 2 // Lowspeed -#define DCFG_DSPD_FS 3 // Fullspeed on FS PHY - -#define DCFG_NZLSOHSK_Pos (2U) -#define DCFG_NZLSOHSK_Msk (0x1UL << DCFG_NZLSOHSK_Pos) // 0x00000004 -#define DCFG_NZLSOHSK DCFG_NZLSOHSK_Msk // Nonzero-length status OUT handshake - -#define DCFG_DAD_Pos (4U) -#define DCFG_DAD_Msk (0x7FUL << DCFG_DAD_Pos) // 0x000007F0 -#define DCFG_DAD DCFG_DAD_Msk // Device address -#define DCFG_DAD_0 (0x01UL << DCFG_DAD_Pos) // 0x00000010 -#define DCFG_DAD_1 (0x02UL << DCFG_DAD_Pos) // 0x00000020 -#define DCFG_DAD_2 (0x04UL << DCFG_DAD_Pos) // 0x00000040 -#define DCFG_DAD_3 (0x08UL << DCFG_DAD_Pos) // 0x00000080 -#define DCFG_DAD_4 (0x10UL << DCFG_DAD_Pos) // 0x00000100 -#define DCFG_DAD_5 (0x20UL << DCFG_DAD_Pos) // 0x00000200 -#define DCFG_DAD_6 (0x40UL << DCFG_DAD_Pos) // 0x00000400 - -#define DCFG_PFIVL_Pos (11U) -#define DCFG_PFIVL_Msk (0x3UL << DCFG_PFIVL_Pos) // 0x00001800 -#define DCFG_PFIVL DCFG_PFIVL_Msk // Periodic (micro)frame interval -#define DCFG_PFIVL_0 (0x1UL << DCFG_PFIVL_Pos) // 0x00000800 -#define DCFG_PFIVL_1 (0x2UL << DCFG_PFIVL_Pos) // 0x00001000 - -#define DCFG_XCVRDLY_Pos (14U) -#define DCFG_XCVRDLY_Msk (0x1UL << DCFG_XCVRDLY_Pos) // 0x00004000 -#define DCFG_XCVRDLY DCFG_XCVRDLY_Msk // Enables delay between xcvr_sel and txvalid during device chirp - -#define DCFG_PERSCHIVL_Pos (24U) -#define DCFG_PERSCHIVL_Msk (0x3UL << DCFG_PERSCHIVL_Pos) // 0x03000000 -#define DCFG_PERSCHIVL DCFG_PERSCHIVL_Msk // Periodic scheduling interval -#define DCFG_PERSCHIVL_0 (0x1UL << DCFG_PERSCHIVL_Pos) // 0x01000000 -#define DCFG_PERSCHIVL_1 (0x2UL << DCFG_PERSCHIVL_Pos) // 0x02000000 - -/******************** Bit definition for DCTL register ********************/ -#define DCTL_RWUSIG_Pos (0U) -#define DCTL_RWUSIG_Msk (0x1UL << DCTL_RWUSIG_Pos) // 0x00000001 -#define DCTL_RWUSIG DCTL_RWUSIG_Msk // Remote wakeup signaling -#define DCTL_SDIS_Pos (1U) -#define DCTL_SDIS_Msk (0x1UL << DCTL_SDIS_Pos) // 0x00000002 -#define DCTL_SDIS DCTL_SDIS_Msk // Soft disconnect -#define DCTL_GINSTS_Pos (2U) -#define DCTL_GINSTS_Msk (0x1UL << DCTL_GINSTS_Pos) // 0x00000004 -#define DCTL_GINSTS DCTL_GINSTS_Msk // Global IN NAK status -#define DCTL_GONSTS_Pos (3U) -#define DCTL_GONSTS_Msk (0x1UL << DCTL_GONSTS_Pos) // 0x00000008 -#define DCTL_GONSTS DCTL_GONSTS_Msk // Global OUT NAK status - -#define DCTL_TCTL_Pos (4U) -#define DCTL_TCTL_Msk (0x7UL << DCTL_TCTL_Pos) // 0x00000070 -#define DCTL_TCTL DCTL_TCTL_Msk // Test control -#define DCTL_TCTL_0 (0x1UL << DCTL_TCTL_Pos) // 0x00000010 -#define DCTL_TCTL_1 (0x2UL << DCTL_TCTL_Pos) // 0x00000020 -#define DCTL_TCTL_2 (0x4UL << DCTL_TCTL_Pos) // 0x00000040 -#define DCTL_SGINAK_Pos (7U) -#define DCTL_SGINAK_Msk (0x1UL << DCTL_SGINAK_Pos) // 0x00000080 -#define DCTL_SGINAK DCTL_SGINAK_Msk // Set global IN NAK -#define DCTL_CGINAK_Pos (8U) -#define DCTL_CGINAK_Msk (0x1UL << DCTL_CGINAK_Pos) // 0x00000100 -#define DCTL_CGINAK DCTL_CGINAK_Msk // Clear global IN NAK -#define DCTL_SGONAK_Pos (9U) -#define DCTL_SGONAK_Msk (0x1UL << DCTL_SGONAK_Pos) // 0x00000200 -#define DCTL_SGONAK DCTL_SGONAK_Msk // Set global OUT NAK -#define DCTL_CGONAK_Pos (10U) -#define DCTL_CGONAK_Msk (0x1UL << DCTL_CGONAK_Pos) // 0x00000400 -#define DCTL_CGONAK DCTL_CGONAK_Msk // Clear global OUT NAK -#define DCTL_POPRGDNE_Pos (11U) -#define DCTL_POPRGDNE_Msk (0x1UL << DCTL_POPRGDNE_Pos) // 0x00000800 -#define DCTL_POPRGDNE DCTL_POPRGDNE_Msk // Power-on programming done - -/******************** Bit definition for HFIR register ********************/ -#define HFIR_FRIVL_Pos (0U) -#define HFIR_FRIVL_Msk (0xFFFFUL << HFIR_FRIVL_Pos) // 0x0000FFFF -#define HFIR_FRIVL HFIR_FRIVL_Msk // Frame interval -#define HFIR_RELOAD_CTRL_Pos (16U) // available since v2.92a -#define HFIR_RELOAD_CTRL_Msk (0x1UL << HFIR_RELOAD_CTRL_Pos) -#define HFIR_RELOAD_CTRL HFIR_RELOAD_CTRL_Msk - -/******************** Bit definition for HFNUM register ********************/ -#define HFNUM_FRNUM_Pos (0U) -#define HFNUM_FRNUM_Msk (0xFFFFUL << HFNUM_FRNUM_Pos) // 0x0000FFFF -#define HFNUM_FRNUM HFNUM_FRNUM_Msk // Frame number -#define HFNUM_FTREM_Pos (16U) -#define HFNUM_FTREM_Msk (0xFFFFUL << HFNUM_FTREM_Pos) // 0xFFFF0000 -#define HFNUM_FTREM HFNUM_FTREM_Msk // Frame time remaining - -/******************** Bit definition for DSTS register ********************/ -#define DSTS_SUSPSTS_Pos (0U) -#define DSTS_SUSPSTS_Msk (0x1UL << DSTS_SUSPSTS_Pos) // 0x00000001 -#define DSTS_SUSPSTS DSTS_SUSPSTS_Msk // Suspend status -#define DSTS_ENUMSPD_Pos (1U) -#define DSTS_ENUMSPD_Msk (0x3UL << DSTS_ENUMSPD_Pos) // 0x00000006 -#define DSTS_ENUMSPD DSTS_ENUMSPD_Msk // Enumerated speed -#define DSTS_ENUMSPD_HS 0 // Highspeed -#define DSTS_ENUMSPD_FS_HSPHY 1 // Fullspeed on HS PHY -#define DSTS_ENUMSPD_LS 2 // Lowspeed -#define DSTS_ENUMSPD_FS 3 // Fullspeed on FS PHY - - -#define DSTS_EERR_Pos (3U) -#define DSTS_EERR_Msk (0x1UL << DSTS_EERR_Pos) // 0x00000008 -#define DSTS_EERR DSTS_EERR_Msk // Erratic error -#define DSTS_FNSOF_Pos (8U) -#define DSTS_FNSOF_Msk (0x3FFFUL << DSTS_FNSOF_Pos) // 0x003FFF00 -#define DSTS_FNSOF DSTS_FNSOF_Msk // Frame number of the received SOF - -/******************** Bit definition for GAHBCFG register ********************/ -#define GAHBCFG_GINT_Pos (0U) -#define GAHBCFG_GINT_Msk (0x1UL << GAHBCFG_GINT_Pos) // 0x00000001 -#define GAHBCFG_GINT GAHBCFG_GINT_Msk // Global interrupt mask -#define GAHBCFG_HBSTLEN_Pos (1U) -#define GAHBCFG_HBSTLEN_Msk (0xFUL << GAHBCFG_HBSTLEN_Pos) // 0x0000001E -#define GAHBCFG_HBSTLEN GAHBCFG_HBSTLEN_Msk // Burst length/type -#define GAHBCFG_HBSTLEN_0 (0x0UL << GAHBCFG_HBSTLEN_Pos) // Single -#define GAHBCFG_HBSTLEN_1 (0x1UL << GAHBCFG_HBSTLEN_Pos) // INCR -#define GAHBCFG_HBSTLEN_2 (0x3UL << GAHBCFG_HBSTLEN_Pos) // INCR4 -#define GAHBCFG_HBSTLEN_3 (0x5UL << GAHBCFG_HBSTLEN_Pos) // INCR8 -#define GAHBCFG_HBSTLEN_4 (0x7UL << GAHBCFG_HBSTLEN_Pos) // INCR16 -#define GAHBCFG_DMAEN_Pos (5U) -#define GAHBCFG_DMAEN_Msk (0x1UL << GAHBCFG_DMAEN_Pos) // 0x00000020 -#define GAHBCFG_DMAEN GAHBCFG_DMAEN_Msk // DMA enable -#define GAHBCFG_TX_FIFO_EPMTY_LVL_Pos (7U) -#define GAHBCFG_TX_FIFO_EPMTY_LVL_Msk (0x1UL << GAHBCFG_TX_FIFO_EPMTY_LVL_Pos) // 0x00000080 -#define GAHBCFG_TX_FIFO_EPMTY_LVL GAHBCFG_TX_FIFO_EPMTY_LVL_Msk // TxFIFO empty level -#define GAHBCFG_PTX_FIFO_EPMTY_LVL_Pos (8U) -#define GAHBCFG_PTX_FIFO_EPMTY_LVL_Msk (0x1UL << GAHBCFG_PTX_FIFO_EPMTY_LVL_Pos) // 0x00000100 -#define GAHBCFG_PTX_FIFO_EPMTY_LVL GAHBCFG_PTX_FIFO_EPMTY_LVL_Msk // Periodic TxFIFO empty level - -/******************** Bit definition for GUSBCFG register ********************/ -#define GUSBCFG_TOCAL_Pos (0U) -#define GUSBCFG_TOCAL_Msk (0x7UL << GUSBCFG_TOCAL_Pos) // 0x00000007 -#define GUSBCFG_TOCAL GUSBCFG_TOCAL_Msk // HS/FS timeout calibration -#define GUSBCFG_PHYIF16_Pos (3U) -#define GUSBCFG_PHYIF16_Msk (0x1UL << GUSBCFG_PHYIF16_Pos) // 0x00000008 -#define GUSBCFG_PHYIF16 GUSBCFG_PHYIF16_Msk // PHY Interface (PHYIf) -#define GUSBCFG_ULPI_UTMI_SEL_Pos (4U) -#define GUSBCFG_ULPI_UTMI_SEL_Msk (0x1UL << GUSBCFG_ULPI_UTMI_SEL_Pos) // 0x00000010 -#define GUSBCFG_ULPI_UTMI_SEL GUSBCFG_ULPI_UTMI_SEL_Msk // ULPI or UTMI+ Select (ULPI_UTMI_Sel) -#define GUSBCFG_PHYSEL_Pos (6U) -#define GUSBCFG_PHYSEL_Msk (0x1UL << GUSBCFG_PHYSEL_Pos) // 0x00000040 -#define GUSBCFG_PHYSEL GUSBCFG_PHYSEL_Msk // USB 2.0 high-speed ULPI PHY or USB 1.1 full-speed serial transceiver select -#define GUSBCFG_DDRSEL TU_BIT(7) // Single Data Rate (SDR) or Double Data Rate (DDR) or ULPI interface. -#define GUSBCFG_SRPCAP_Pos (8U) -#define GUSBCFG_SRPCAP_Msk (0x1UL << GUSBCFG_SRPCAP_Pos) // 0x00000100 -#define GUSBCFG_SRPCAP GUSBCFG_SRPCAP_Msk // SRP-capable -#define GUSBCFG_HNPCAP_Pos (9U) -#define GUSBCFG_HNPCAP_Msk (0x1UL << GUSBCFG_HNPCAP_Pos) // 0x00000200 -#define GUSBCFG_HNPCAP GUSBCFG_HNPCAP_Msk // HNP-capable -#define GUSBCFG_TRDT_Pos (10U) -#define GUSBCFG_TRDT_Msk (0xFUL << GUSBCFG_TRDT_Pos) // 0x00003C00 -#define GUSBCFG_TRDT GUSBCFG_TRDT_Msk // USB turnaround time -#define GUSBCFG_PHYLPCS_Pos (15U) -#define GUSBCFG_PHYLPCS_Msk (0x1UL << GUSBCFG_PHYLPCS_Pos) // 0x00008000 -#define GUSBCFG_PHYLPCS GUSBCFG_PHYLPCS_Msk // PHY Low-power clock select -#define GUSBCFG_ULPIFSLS_Pos (17U) -#define GUSBCFG_ULPIFSLS_Msk (0x1UL << GUSBCFG_ULPIFSLS_Pos) // 0x00020000 -#define GUSBCFG_ULPIFSLS GUSBCFG_ULPIFSLS_Msk // ULPI FS/LS select -#define GUSBCFG_ULPIAR_Pos (18U) -#define GUSBCFG_ULPIAR_Msk (0x1UL << GUSBCFG_ULPIAR_Pos) // 0x00040000 -#define GUSBCFG_ULPIAR GUSBCFG_ULPIAR_Msk // ULPI Auto-resume -#define GUSBCFG_ULPICSM_Pos (19U) -#define GUSBCFG_ULPICSM_Msk (0x1UL << GUSBCFG_ULPICSM_Pos) // 0x00080000 -#define GUSBCFG_ULPICSM GUSBCFG_ULPICSM_Msk // ULPI Clock SuspendM -#define GUSBCFG_ULPIEVBUSD_Pos (20U) -#define GUSBCFG_ULPIEVBUSD_Msk (0x1UL << GUSBCFG_ULPIEVBUSD_Pos) // 0x00100000 -#define GUSBCFG_ULPIEVBUSD GUSBCFG_ULPIEVBUSD_Msk // ULPI External VBUS Drive -#define GUSBCFG_ULPIEVBUSI_Pos (21U) -#define GUSBCFG_ULPIEVBUSI_Msk (0x1UL << GUSBCFG_ULPIEVBUSI_Pos) // 0x00200000 -#define GUSBCFG_ULPIEVBUSI GUSBCFG_ULPIEVBUSI_Msk // ULPI external VBUS indicator -#define GUSBCFG_TSDPS_Pos (22U) -#define GUSBCFG_TSDPS_Msk (0x1UL << GUSBCFG_TSDPS_Pos) // 0x00400000 -#define GUSBCFG_TSDPS GUSBCFG_TSDPS_Msk // TermSel DLine pulsing selection -#define GUSBCFG_PCCI_Pos (23U) -#define GUSBCFG_PCCI_Msk (0x1UL << GUSBCFG_PCCI_Pos) // 0x00800000 -#define GUSBCFG_PCCI GUSBCFG_PCCI_Msk // Indicator complement -#define GUSBCFG_PTCI_Pos (24U) -#define GUSBCFG_PTCI_Msk (0x1UL << GUSBCFG_PTCI_Pos) // 0x01000000 -#define GUSBCFG_PTCI GUSBCFG_PTCI_Msk // Indicator pass through -#define GUSBCFG_ULPIIPD_Pos (25U) -#define GUSBCFG_ULPIIPD_Msk (0x1UL << GUSBCFG_ULPIIPD_Pos) // 0x02000000 -#define GUSBCFG_ULPIIPD GUSBCFG_ULPIIPD_Msk // ULPI interface protect disable -#define GUSBCFG_FHMOD_Pos (29U) -#define GUSBCFG_FHMOD_Msk (0x1UL << GUSBCFG_FHMOD_Pos) // 0x20000000 -#define GUSBCFG_FHMOD GUSBCFG_FHMOD_Msk // Forced host mode -#define GUSBCFG_FDMOD_Pos (30U) -#define GUSBCFG_FDMOD_Msk (0x1UL << GUSBCFG_FDMOD_Pos) // 0x40000000 -#define GUSBCFG_FDMOD GUSBCFG_FDMOD_Msk // Forced peripheral mode -#define GUSBCFG_CTXPKT_Pos (31U) -#define GUSBCFG_CTXPKT_Msk (0x1UL << GUSBCFG_CTXPKT_Pos) // 0x80000000 -#define GUSBCFG_CTXPKT GUSBCFG_CTXPKT_Msk // Corrupt Tx packet - -/******************** Bit definition for GRSTCTL register ********************/ -#define GRSTCTL_CSRST_Pos (0U) -#define GRSTCTL_CSRST_Msk (0x1UL << GRSTCTL_CSRST_Pos) // 0x00000001 -#define GRSTCTL_CSRST GRSTCTL_CSRST_Msk // Core soft reset -#define GRSTCTL_HSRST_Pos (1U) -#define GRSTCTL_HSRST_Msk (0x1UL << GRSTCTL_HSRST_Pos) // 0x00000002 -#define GRSTCTL_HSRST GRSTCTL_HSRST_Msk // HCLK soft reset -#define GRSTCTL_FCRST_Pos (2U) -#define GRSTCTL_FCRST_Msk (0x1UL << GRSTCTL_FCRST_Pos) // 0x00000004 -#define GRSTCTL_FCRST GRSTCTL_FCRST_Msk // Host frame counter reset -#define GRSTCTL_RXFFLSH_Pos (4U) -#define GRSTCTL_RXFFLSH_Msk (0x1UL << GRSTCTL_RXFFLSH_Pos) // 0x00000010 -#define GRSTCTL_RXFFLSH GRSTCTL_RXFFLSH_Msk // RxFIFO flush -#define GRSTCTL_TXFFLSH_Pos (5U) -#define GRSTCTL_TXFFLSH_Msk (0x1UL << GRSTCTL_TXFFLSH_Pos) // 0x00000020 -#define GRSTCTL_TXFFLSH GRSTCTL_TXFFLSH_Msk // TxFIFO flush -#define GRSTCTL_TXFNUM_Pos (6U) -#define GRSTCTL_TXFNUM_Msk (0x1FUL << GRSTCTL_TXFNUM_Pos) // 0x000007C0 -#define GRSTCTL_TXFNUM GRSTCTL_TXFNUM_Msk // TxFIFO number -#define GRSTCTL_TXFNUM_0 (0x01UL << GRSTCTL_TXFNUM_Pos) // 0x00000040 -#define GRSTCTL_TXFNUM_1 (0x02UL << GRSTCTL_TXFNUM_Pos) // 0x00000080 -#define GRSTCTL_TXFNUM_2 (0x04UL << GRSTCTL_TXFNUM_Pos) // 0x00000100 -#define GRSTCTL_TXFNUM_3 (0x08UL << GRSTCTL_TXFNUM_Pos) // 0x00000200 -#define GRSTCTL_TXFNUM_4 (0x10UL << GRSTCTL_TXFNUM_Pos) // 0x00000400 -#define GRSTCTL_CSRST_DONE_Pos (29) -#define GRSTCTL_CSRST_DONE (1u << GRSTCTL_CSRST_DONE_Pos) // Reset Done, only available from v4.20a -#define GRSTCTL_DMAREQ_Pos (30U) -#define GRSTCTL_DMAREQ_Msk (0x1UL << GRSTCTL_DMAREQ_Pos) // 0x40000000 -#define GRSTCTL_DMAREQ GRSTCTL_DMAREQ_Msk // DMA request signal -#define GRSTCTL_AHBIDL_Pos (31U) -#define GRSTCTL_AHBIDL_Msk (0x1UL << GRSTCTL_AHBIDL_Pos) // 0x80000000 -#define GRSTCTL_AHBIDL GRSTCTL_AHBIDL_Msk // AHB master idle - -/******************** Bit definition for DIEPMSK register ********************/ -#define DIEPMSK_XFRCM_Pos (0U) -#define DIEPMSK_XFRCM_Msk (0x1UL << DIEPMSK_XFRCM_Pos) // 0x00000001 -#define DIEPMSK_XFRCM DIEPMSK_XFRCM_Msk // Transfer completed interrupt mask -#define DIEPMSK_EPDM_Pos (1U) -#define DIEPMSK_EPDM_Msk (0x1UL << DIEPMSK_EPDM_Pos) // 0x00000002 -#define DIEPMSK_EPDM DIEPMSK_EPDM_Msk // Endpoint disabled interrupt mask -#define DIEPMSK_TOM_Pos (3U) -#define DIEPMSK_TOM_Msk (0x1UL << DIEPMSK_TOM_Pos) // 0x00000008 -#define DIEPMSK_TOM DIEPMSK_TOM_Msk // Timeout condition mask (nonisochronous endpoints) -#define DIEPMSK_ITTXFEMSK_Pos (4U) -#define DIEPMSK_ITTXFEMSK_Msk (0x1UL << DIEPMSK_ITTXFEMSK_Pos) // 0x00000010 -#define DIEPMSK_ITTXFEMSK DIEPMSK_ITTXFEMSK_Msk // IN token received when TxFIFO empty mask -#define DIEPMSK_INEPNMM_Pos (5U) -#define DIEPMSK_INEPNMM_Msk (0x1UL << DIEPMSK_INEPNMM_Pos) // 0x00000020 -#define DIEPMSK_INEPNMM DIEPMSK_INEPNMM_Msk // IN token received with EP mismatch mask -#define DIEPMSK_INEPNEM_Pos (6U) -#define DIEPMSK_INEPNEM_Msk (0x1UL << DIEPMSK_INEPNEM_Pos) // 0x00000040 -#define DIEPMSK_INEPNEM DIEPMSK_INEPNEM_Msk // IN endpoint NAK effective mask -#define DIEPMSK_TXFURM_Pos (8U) -#define DIEPMSK_TXFURM_Msk (0x1UL << DIEPMSK_TXFURM_Pos) // 0x00000100 -#define DIEPMSK_TXFURM DIEPMSK_TXFURM_Msk // FIFO underrun mask -#define DIEPMSK_BIM_Pos (9U) -#define DIEPMSK_BIM_Msk (0x1UL << DIEPMSK_BIM_Pos) // 0x00000200 -#define DIEPMSK_BIM DIEPMSK_BIM_Msk // BNA interrupt mask - -/******************** Bit definition for HPTXSTS register ********************/ -#define HPTXSTS_PTXFSAVL_Pos (0U) -#define HPTXSTS_PTXFSAVL_Msk (0xFFFFUL << HPTXSTS_PTXFSAVL_Pos) // 0x0000FFFF -#define HPTXSTS_PTXFSAVL HPTXSTS_PTXFSAVL_Msk // Periodic transmit data FIFO space available -#define HPTXSTS_PTXQSAV_Pos (16U) -#define HPTXSTS_PTXQSAV_Msk (0xFFUL << HPTXSTS_PTXQSAV_Pos) // 0x00FF0000 -#define HPTXSTS_PTXQSAV HPTXSTS_PTXQSAV_Msk // Periodic transmit request queue space available -#define HPTXSTS_PTXQSAV_0 (0x01UL << HPTXSTS_PTXQSAV_Pos) // 0x00010000 -#define HPTXSTS_PTXQSAV_1 (0x02UL << HPTXSTS_PTXQSAV_Pos) // 0x00020000 -#define HPTXSTS_PTXQSAV_2 (0x04UL << HPTXSTS_PTXQSAV_Pos) // 0x00040000 -#define HPTXSTS_PTXQSAV_3 (0x08UL << HPTXSTS_PTXQSAV_Pos) // 0x00080000 -#define HPTXSTS_PTXQSAV_4 (0x10UL << HPTXSTS_PTXQSAV_Pos) // 0x00100000 -#define HPTXSTS_PTXQSAV_5 (0x20UL << HPTXSTS_PTXQSAV_Pos) // 0x00200000 -#define HPTXSTS_PTXQSAV_6 (0x40UL << HPTXSTS_PTXQSAV_Pos) // 0x00400000 -#define HPTXSTS_PTXQSAV_7 (0x80UL << HPTXSTS_PTXQSAV_Pos) // 0x00800000 - -#define HPTXSTS_PTXQTOP_Pos (24U) -#define HPTXSTS_PTXQTOP_Msk (0xFFUL << HPTXSTS_PTXQTOP_Pos) // 0xFF000000 -#define HPTXSTS_PTXQTOP HPTXSTS_PTXQTOP_Msk // Top of the periodic transmit request queue -#define HPTXSTS_PTXQTOP_0 (0x01UL << HPTXSTS_PTXQTOP_Pos) // 0x01000000 -#define HPTXSTS_PTXQTOP_1 (0x02UL << HPTXSTS_PTXQTOP_Pos) // 0x02000000 -#define HPTXSTS_PTXQTOP_2 (0x04UL << HPTXSTS_PTXQTOP_Pos) // 0x04000000 -#define HPTXSTS_PTXQTOP_3 (0x08UL << HPTXSTS_PTXQTOP_Pos) // 0x08000000 -#define HPTXSTS_PTXQTOP_4 (0x10UL << HPTXSTS_PTXQTOP_Pos) // 0x10000000 -#define HPTXSTS_PTXQTOP_5 (0x20UL << HPTXSTS_PTXQTOP_Pos) // 0x20000000 -#define HPTXSTS_PTXQTOP_6 (0x40UL << HPTXSTS_PTXQTOP_Pos) // 0x40000000 -#define HPTXSTS_PTXQTOP_7 (0x80UL << HPTXSTS_PTXQTOP_Pos) // 0x80000000 - -/******************** Bit definition for HAINT register ********************/ -#define HAINT_HAINT_Pos (0U) -#define HAINT_HAINT_Msk (0xFFFFUL << HAINT_HAINT_Pos) // 0x0000FFFF -#define HAINT_HAINT HAINT_HAINT_Msk // Channel interrupts - -/******************** Bit definition for DOEPMSK register ********************/ -#define DOEPMSK_XFRCM_Pos (0U) -#define DOEPMSK_XFRCM_Msk (0x1UL << DOEPMSK_XFRCM_Pos) // 0x00000001 -#define DOEPMSK_XFRCM DOEPMSK_XFRCM_Msk // Transfer completed interrupt mask -#define DOEPMSK_EPDM_Pos (1U) -#define DOEPMSK_EPDM_Msk (0x1UL << DOEPMSK_EPDM_Pos) // 0x00000002 -#define DOEPMSK_EPDM DOEPMSK_EPDM_Msk // Endpoint disabled interrupt mask -#define DOEPMSK_AHBERRM_Pos (2U) -#define DOEPMSK_AHBERRM_Msk (0x1UL << DOEPMSK_AHBERRM_Pos) // 0x00000004 -#define DOEPMSK_AHBERRM DOEPMSK_AHBERRM_Msk // OUT transaction AHB Error interrupt mask -#define DOEPMSK_STUPM_Pos (3U) -#define DOEPMSK_STUPM_Msk (0x1UL << DOEPMSK_STUPM_Pos) // 0x00000008 -#define DOEPMSK_STUPM DOEPMSK_STUPM_Msk // SETUP phase done mask -#define DOEPMSK_OTEPDM_Pos (4U) -#define DOEPMSK_OTEPDM_Msk (0x1UL << DOEPMSK_OTEPDM_Pos) // 0x00000010 -#define DOEPMSK_OTEPDM DOEPMSK_OTEPDM_Msk // OUT token received when endpoint disabled mask -#define DOEPMSK_OTEPSPRM_Pos (5U) -#define DOEPMSK_OTEPSPRM_Msk (0x1UL << DOEPMSK_OTEPSPRM_Pos) // 0x00000020 -#define DOEPMSK_OTEPSPRM DOEPMSK_OTEPSPRM_Msk // Status Phase Received mask -#define DOEPMSK_B2BSTUP_Pos (6U) -#define DOEPMSK_B2BSTUP_Msk (0x1UL << DOEPMSK_B2BSTUP_Pos) // 0x00000040 -#define DOEPMSK_B2BSTUP DOEPMSK_B2BSTUP_Msk // Back-to-back SETUP packets received mask -#define DOEPMSK_OPEM_Pos (8U) -#define DOEPMSK_OPEM_Msk (0x1UL << DOEPMSK_OPEM_Pos) // 0x00000100 -#define DOEPMSK_OPEM DOEPMSK_OPEM_Msk // OUT packet error mask -#define DOEPMSK_BOIM_Pos (9U) -#define DOEPMSK_BOIM_Msk (0x1UL << DOEPMSK_BOIM_Pos) // 0x00000200 -#define DOEPMSK_BOIM DOEPMSK_BOIM_Msk // BNA interrupt mask -#define DOEPMSK_BERRM_Pos (12U) -#define DOEPMSK_BERRM_Msk (0x1UL << DOEPMSK_BERRM_Pos) // 0x00001000 -#define DOEPMSK_BERRM DOEPMSK_BERRM_Msk // Babble error interrupt mask -#define DOEPMSK_NAKM_Pos (13U) -#define DOEPMSK_NAKM_Msk (0x1UL << DOEPMSK_NAKM_Pos) // 0x00002000 -#define DOEPMSK_NAKM DOEPMSK_NAKM_Msk // OUT Packet NAK interrupt mask -#define DOEPMSK_NYETM_Pos (14U) -#define DOEPMSK_NYETM_Msk (0x1UL << DOEPMSK_NYETM_Pos) // 0x00004000 -#define DOEPMSK_NYETM DOEPMSK_NYETM_Msk // NYET interrupt mask - -/******************** Bit definition for GINTSTS register ********************/ -#define GINTSTS_CMOD_Pos (0U) -#define GINTSTS_CMOD_Msk (0x1UL << GINTSTS_CMOD_Pos) // 0x00000001 -#define GINTSTS_CMOD GINTSTS_CMOD_Msk // Current mode of operation -#define GINTSTS_MMIS_Pos (1U) -#define GINTSTS_MMIS_Msk (0x1UL << GINTSTS_MMIS_Pos) // 0x00000002 -#define GINTSTS_MMIS GINTSTS_MMIS_Msk // Mode mismatch interrupt -#define GINTSTS_OTGINT_Pos (2U) -#define GINTSTS_OTGINT_Msk (0x1UL << GINTSTS_OTGINT_Pos) // 0x00000004 -#define GINTSTS_OTGINT GINTSTS_OTGINT_Msk // OTG interrupt -#define GINTSTS_SOF_Pos (3U) -#define GINTSTS_SOF_Msk (0x1UL << GINTSTS_SOF_Pos) // 0x00000008 -#define GINTSTS_SOF GINTSTS_SOF_Msk // Start of frame -#define GINTSTS_RXFLVL_Pos (4U) -#define GINTSTS_RXFLVL_Msk (0x1UL << GINTSTS_RXFLVL_Pos) // 0x00000010 -#define GINTSTS_RXFLVL GINTSTS_RXFLVL_Msk // RxFIFO nonempty -#define GINTSTS_NPTX_FIFO_EMPTY_Pos (5U) -#define GINTSTS_NPTX_FIFO_EMPTY_Msk (0x1UL << GINTSTS_NPTX_FIFO_EMPTY_Pos) // 0x00000020 -#define GINTSTS_NPTX_FIFO_EMPTY GINTSTS_NPTX_FIFO_EMPTY_Msk // Nonperiodic TxFIFO empty -#define GINTSTS_GINAKEFF_Pos (6U) -#define GINTSTS_GINAKEFF_Msk (0x1UL << GINTSTS_GINAKEFF_Pos) // 0x00000040 -#define GINTSTS_GINAKEFF GINTSTS_GINAKEFF_Msk // Global IN nonperiodic NAK effective -#define GINTSTS_BOUTNAKEFF_Pos (7U) -#define GINTSTS_BOUTNAKEFF_Msk (0x1UL << GINTSTS_BOUTNAKEFF_Pos) // 0x00000080 -#define GINTSTS_BOUTNAKEFF GINTSTS_BOUTNAKEFF_Msk // Global OUT NAK effective -#define GINTSTS_ESUSP_Pos (10U) -#define GINTSTS_ESUSP_Msk (0x1UL << GINTSTS_ESUSP_Pos) // 0x00000400 -#define GINTSTS_ESUSP GINTSTS_ESUSP_Msk // Early suspend -#define GINTSTS_USBSUSP_Pos (11U) -#define GINTSTS_USBSUSP_Msk (0x1UL << GINTSTS_USBSUSP_Pos) // 0x00000800 -#define GINTSTS_USBSUSP GINTSTS_USBSUSP_Msk // USB suspend -#define GINTSTS_USBRST_Pos (12U) -#define GINTSTS_USBRST_Msk (0x1UL << GINTSTS_USBRST_Pos) // 0x00001000 -#define GINTSTS_USBRST GINTSTS_USBRST_Msk // USB reset -#define GINTSTS_ENUMDNE_Pos (13U) -#define GINTSTS_ENUMDNE_Msk (0x1UL << GINTSTS_ENUMDNE_Pos) // 0x00002000 -#define GINTSTS_ENUMDNE GINTSTS_ENUMDNE_Msk // Enumeration done -#define GINTSTS_ISOODRP_Pos (14U) -#define GINTSTS_ISOODRP_Msk (0x1UL << GINTSTS_ISOODRP_Pos) // 0x00004000 -#define GINTSTS_ISOODRP GINTSTS_ISOODRP_Msk // Isochronous OUT packet dropped interrupt -#define GINTSTS_EOPF_Pos (15U) -#define GINTSTS_EOPF_Msk (0x1UL << GINTSTS_EOPF_Pos) // 0x00008000 -#define GINTSTS_EOPF GINTSTS_EOPF_Msk // End of periodic frame interrupt -#define GINTSTS_IEPINT_Pos (18U) -#define GINTSTS_IEPINT_Msk (0x1UL << GINTSTS_IEPINT_Pos) // 0x00040000 -#define GINTSTS_IEPINT GINTSTS_IEPINT_Msk // IN endpoint interrupt -#define GINTSTS_OEPINT_Pos (19U) -#define GINTSTS_OEPINT_Msk (0x1UL << GINTSTS_OEPINT_Pos) // 0x00080000 -#define GINTSTS_OEPINT GINTSTS_OEPINT_Msk // OUT endpoint interrupt -#define GINTSTS_IISOIXFR_Pos (20U) -#define GINTSTS_IISOIXFR_Msk (0x1UL << GINTSTS_IISOIXFR_Pos) // 0x00100000 -#define GINTSTS_IISOIXFR GINTSTS_IISOIXFR_Msk // Incomplete isochronous IN transfer -#define GINTSTS_PXFR_INCOMPISOOUT_Pos (21U) -#define GINTSTS_PXFR_INCOMPISOOUT_Msk (0x1UL << GINTSTS_PXFR_INCOMPISOOUT_Pos) // 0x00200000 -#define GINTSTS_PXFR_INCOMPISOOUT GINTSTS_PXFR_INCOMPISOOUT_Msk // Incomplete periodic transfer -#define GINTSTS_DATAFSUSP_Pos (22U) -#define GINTSTS_DATAFSUSP_Msk (0x1UL << GINTSTS_DATAFSUSP_Pos) // 0x00400000 -#define GINTSTS_DATAFSUSP GINTSTS_DATAFSUSP_Msk // Data fetch suspended -#define GINTSTS_RSTDET_Pos (23U) -#define GINTSTS_RSTDET_Msk (0x1UL << GINTSTS_RSTDET_Pos) // 0x00800000 -#define GINTSTS_RSTDET GINTSTS_RSTDET_Msk // Reset detected interrupt -#define GINTSTS_HPRTINT_Pos (24U) -#define GINTSTS_HPRTINT_Msk (0x1UL << GINTSTS_HPRTINT_Pos) // 0x01000000 -#define GINTSTS_HPRTINT GINTSTS_HPRTINT_Msk // Host port interrupt -#define GINTSTS_HCINT_Pos (25U) -#define GINTSTS_HCINT_Msk (0x1UL << GINTSTS_HCINT_Pos) // 0x02000000 -#define GINTSTS_HCINT GINTSTS_HCINT_Msk // Host channels interrupt -#define GINTSTS_PTX_FIFO_EMPTY_Pos (26U) -#define GINTSTS_PTX_FIFO_EMPTY_Msk (0x1UL << GINTSTS_PTX_FIFO_EMPTY_Pos) // 0x04000000 -#define GINTSTS_PTX_FIFO_EMPTY GINTSTS_PTX_FIFO_EMPTY_Msk // Periodic TxFIFO empty -#define GINTSTS_LPMINT_Pos (27U) -#define GINTSTS_LPMINT_Msk (0x1UL << GINTSTS_LPMINT_Pos) // 0x08000000 -#define GINTSTS_LPMINT GINTSTS_LPMINT_Msk // LPM interrupt -#define GINTSTS_CONIDSTSCHNG_Pos (28U) -#define GINTSTS_CONIDSTSCHNG_Msk (0x1UL << GINTSTS_CONIDSTSCHNG_Pos) // 0x10000000 -#define GINTSTS_CONIDSTSCHNG GINTSTS_CONIDSTSCHNG_Msk // Connector ID status change -#define GINTSTS_DISCINT_Pos (29U) -#define GINTSTS_DISCINT_Msk (0x1UL << GINTSTS_DISCINT_Pos) // 0x20000000 -#define GINTSTS_DISCINT GINTSTS_DISCINT_Msk // Disconnect detected interrupt -#define GINTSTS_SRQINT_Pos (30U) -#define GINTSTS_SRQINT_Msk (0x1UL << GINTSTS_SRQINT_Pos) // 0x40000000 -#define GINTSTS_SRQINT GINTSTS_SRQINT_Msk // Session request/new session detected interrupt -#define GINTSTS_WKUINT_Pos (31U) -#define GINTSTS_WKUINT_Msk (0x1UL << GINTSTS_WKUINT_Pos) // 0x80000000 -#define GINTSTS_WKUINT GINTSTS_WKUINT_Msk // Resume/remote wakeup detected interrupt - -/******************** Bit definition for GINTMSK register ********************/ -#define GINTMSK_MMISM_Pos (1U) -#define GINTMSK_MMISM_Msk (0x1UL << GINTMSK_MMISM_Pos) // 0x00000002 -#define GINTMSK_MMISM GINTMSK_MMISM_Msk // Mode mismatch interrupt mask -#define GINTMSK_OTGINT_Pos (2U) -#define GINTMSK_OTGINT_Msk (0x1UL << GINTMSK_OTGINT_Pos) // 0x00000004 -#define GINTMSK_OTGINT GINTMSK_OTGINT_Msk // OTG interrupt mask -#define GINTMSK_SOFM_Pos (3U) -#define GINTMSK_SOFM_Msk (0x1UL << GINTMSK_SOFM_Pos) // 0x00000008 -#define GINTMSK_SOFM GINTMSK_SOFM_Msk // Start of frame mask -#define GINTMSK_RXFLVLM_Pos (4U) -#define GINTMSK_RXFLVLM_Msk (0x1UL << GINTMSK_RXFLVLM_Pos) // 0x00000010 -#define GINTMSK_RXFLVLM GINTMSK_RXFLVLM_Msk // Receive FIFO nonempty mask -#define GINTMSK_NPTXFEM_Pos (5U) -#define GINTMSK_NPTXFEM_Msk (0x1UL << GINTMSK_NPTXFEM_Pos) // 0x00000020 -#define GINTMSK_NPTXFEM GINTMSK_NPTXFEM_Msk // Nonperiodic TxFIFO empty mask -#define GINTMSK_GINAKEFFM_Pos (6U) -#define GINTMSK_GINAKEFFM_Msk (0x1UL << GINTMSK_GINAKEFFM_Pos) // 0x00000040 -#define GINTMSK_GINAKEFFM GINTMSK_GINAKEFFM_Msk // Global nonperiodic IN NAK effective mask -#define GINTMSK_GONAKEFFM_Pos (7U) -#define GINTMSK_GONAKEFFM_Msk (0x1UL << GINTMSK_GONAKEFFM_Pos) // 0x00000080 -#define GINTMSK_GONAKEFFM GINTMSK_GONAKEFFM_Msk // Global OUT NAK effective mask -#define GINTMSK_ESUSPM_Pos (10U) -#define GINTMSK_ESUSPM_Msk (0x1UL << GINTMSK_ESUSPM_Pos) // 0x00000400 -#define GINTMSK_ESUSPM GINTMSK_ESUSPM_Msk // Early suspend mask -#define GINTMSK_USBSUSPM_Pos (11U) -#define GINTMSK_USBSUSPM_Msk (0x1UL << GINTMSK_USBSUSPM_Pos) // 0x00000800 -#define GINTMSK_USBSUSPM GINTMSK_USBSUSPM_Msk // USB suspend mask -#define GINTMSK_USBRST_Pos (12U) -#define GINTMSK_USBRST_Msk (0x1UL << GINTMSK_USBRST_Pos) // 0x00001000 -#define GINTMSK_USBRST GINTMSK_USBRST_Msk // USB reset mask -#define GINTMSK_ENUMDNEM_Pos (13U) -#define GINTMSK_ENUMDNEM_Msk (0x1UL << GINTMSK_ENUMDNEM_Pos) // 0x00002000 -#define GINTMSK_ENUMDNEM GINTMSK_ENUMDNEM_Msk // Enumeration done mask -#define GINTMSK_ISOODRPM_Pos (14U) -#define GINTMSK_ISOODRPM_Msk (0x1UL << GINTMSK_ISOODRPM_Pos) // 0x00004000 -#define GINTMSK_ISOODRPM GINTMSK_ISOODRPM_Msk // Isochronous OUT packet dropped interrupt mask -#define GINTMSK_EOPFM_Pos (15U) -#define GINTMSK_EOPFM_Msk (0x1UL << GINTMSK_EOPFM_Pos) // 0x00008000 -#define GINTMSK_EOPFM GINTMSK_EOPFM_Msk // End of periodic frame interrupt mask -#define GINTMSK_EPMISM_Pos (17U) -#define GINTMSK_EPMISM_Msk (0x1UL << GINTMSK_EPMISM_Pos) // 0x00020000 -#define GINTMSK_EPMISM GINTMSK_EPMISM_Msk // Endpoint mismatch interrupt mask -#define GINTMSK_IEPINT_Pos (18U) -#define GINTMSK_IEPINT_Msk (0x1UL << GINTMSK_IEPINT_Pos) // 0x00040000 -#define GINTMSK_IEPINT GINTMSK_IEPINT_Msk // IN endpoints interrupt mask -#define GINTMSK_OEPINT_Pos (19U) -#define GINTMSK_OEPINT_Msk (0x1UL << GINTMSK_OEPINT_Pos) // 0x00080000 -#define GINTMSK_OEPINT GINTMSK_OEPINT_Msk // OUT endpoints interrupt mask -#define GINTMSK_IISOIXFRM_Pos (20U) -#define GINTMSK_IISOIXFRM_Msk (0x1UL << GINTMSK_IISOIXFRM_Pos) // 0x00100000 -#define GINTMSK_IISOIXFRM GINTMSK_IISOIXFRM_Msk // Incomplete isochronous IN transfer mask -#define GINTMSK_PXFRM_IISOOXFRM_Pos (21U) -#define GINTMSK_PXFRM_IISOOXFRM_Msk (0x1UL << GINTMSK_PXFRM_IISOOXFRM_Pos) // 0x00200000 -#define GINTMSK_PXFRM_IISOOXFRM GINTMSK_PXFRM_IISOOXFRM_Msk // Incomplete periodic transfer mask -#define GINTMSK_FSUSPM_Pos (22U) -#define GINTMSK_FSUSPM_Msk (0x1UL << GINTMSK_FSUSPM_Pos) // 0x00400000 -#define GINTMSK_FSUSPM GINTMSK_FSUSPM_Msk // Data fetch suspended mask -#define GINTMSK_RSTDEM_Pos (23U) -#define GINTMSK_RSTDEM_Msk (0x1UL << GINTMSK_RSTDEM_Pos) // 0x00800000 -#define GINTMSK_RSTDEM GINTMSK_RSTDEM_Msk // Reset detected interrupt mask -#define GINTMSK_PRTIM_Pos (24U) -#define GINTMSK_PRTIM_Msk (0x1UL << GINTMSK_PRTIM_Pos) // 0x01000000 -#define GINTMSK_PRTIM GINTMSK_PRTIM_Msk // Host port interrupt mask -#define GINTMSK_HCIM_Pos (25U) -#define GINTMSK_HCIM_Msk (0x1UL << GINTMSK_HCIM_Pos) // 0x02000000 -#define GINTMSK_HCIM GINTMSK_HCIM_Msk // Host channels interrupt mask -#define GINTMSK_PTXFEM_Pos (26U) -#define GINTMSK_PTXFEM_Msk (0x1UL << GINTMSK_PTXFEM_Pos) // 0x04000000 -#define GINTMSK_PTXFEM GINTMSK_PTXFEM_Msk // Periodic TxFIFO empty mask -#define GINTMSK_LPMINTM_Pos (27U) -#define GINTMSK_LPMINTM_Msk (0x1UL << GINTMSK_LPMINTM_Pos) // 0x08000000 -#define GINTMSK_LPMINTM GINTMSK_LPMINTM_Msk // LPM interrupt Mask -#define GINTMSK_CONIDSTSCHNGM_Pos (28U) -#define GINTMSK_CONIDSTSCHNGM_Msk (0x1UL << GINTMSK_CONIDSTSCHNGM_Pos) // 0x10000000 -#define GINTMSK_CONIDSTSCHNGM GINTMSK_CONIDSTSCHNGM_Msk // Connector ID status change mask -#define GINTMSK_DISCINT_Pos (29U) -#define GINTMSK_DISCINT_Msk (0x1UL << GINTMSK_DISCINT_Pos) // 0x20000000 -#define GINTMSK_DISCINT GINTMSK_DISCINT_Msk // Disconnect detected interrupt mask -#define GINTMSK_SRQIM_Pos (30U) -#define GINTMSK_SRQIM_Msk (0x1UL << GINTMSK_SRQIM_Pos) // 0x40000000 -#define GINTMSK_SRQIM GINTMSK_SRQIM_Msk // Session request/new session detected interrupt mask -#define GINTMSK_WUIM_Pos (31U) -#define GINTMSK_WUIM_Msk (0x1UL << GINTMSK_WUIM_Pos) // 0x80000000 -#define GINTMSK_WUIM GINTMSK_WUIM_Msk // Resume/remote wakeup detected interrupt mask - -/******************** Bit definition for DAINT register ********************/ -#define DAINT_IEPINT_Pos (0U) -#define DAINT_IEPINT_Msk (0xFFFFUL << DAINT_IEPINT_Pos) // 0x0000FFFF -#define DAINT_IEPINT DAINT_IEPINT_Msk // IN endpoint interrupt bits -#define DAINT_OEPINT_Pos (16U) -#define DAINT_OEPINT_Msk (0xFFFFUL << DAINT_OEPINT_Pos) // 0xFFFF0000 -#define DAINT_OEPINT DAINT_OEPINT_Msk // OUT endpoint interrupt bits - -/******************** Bit definition for HAINTMSK register ********************/ -#define HAINTMSK_HAINTM_Pos (0U) -#define HAINTMSK_HAINTM_Msk (0xFFFFUL << HAINTMSK_HAINTM_Pos) // 0x0000FFFF -#define HAINTMSK_HAINTM HAINTMSK_HAINTM_Msk // Channel interrupt mask - -/******************** Bit definition for GRXSTSP register ********************/ -#define GRXSTSP_EPNUM_Pos (0U) -#define GRXSTSP_EPNUM_Msk (0xFUL << GRXSTSP_EPNUM_Pos) // 0x0000000F -#define GRXSTSP_EPNUM GRXSTSP_EPNUM_Msk // IN EP interrupt mask bits -#define GRXSTSP_BCNT_Pos (4U) -#define GRXSTSP_BCNT_Msk (0x7FFUL << GRXSTSP_BCNT_Pos) // 0x00007FF0 -#define GRXSTSP_BCNT GRXSTSP_BCNT_Msk // OUT EP interrupt mask bits -#define GRXSTSP_DPID_Pos (15U) -#define GRXSTSP_DPID_Msk (0x3UL << GRXSTSP_DPID_Pos) // 0x00018000 -#define GRXSTSP_DPID GRXSTSP_DPID_Msk // OUT EP interrupt mask bits -#define GRXSTSP_PKTSTS_Pos (17U) -#define GRXSTSP_PKTSTS_Msk (0xFUL << GRXSTSP_PKTSTS_Pos) // 0x001E0000 -#define GRXSTSP_PKTSTS GRXSTSP_PKTSTS_Msk // OUT EP interrupt mask bits - -/******************** Bit definition for DAINTMSK register ********************/ -#define DAINTMSK_IEPM_Pos (0U) -#define DAINTMSK_IEPM_Msk (0xFFFFUL << DAINTMSK_IEPM_Pos) // 0x0000FFFF -#define DAINTMSK_IEPM DAINTMSK_IEPM_Msk // IN EP interrupt mask bits -#define DAINTMSK_OEPM_Pos (16U) -#define DAINTMSK_OEPM_Msk (0xFFFFUL << DAINTMSK_OEPM_Pos) // 0xFFFF0000 -#define DAINTMSK_OEPM DAINTMSK_OEPM_Msk // OUT EP interrupt mask bits - -#define DAINT_SHIFT(_dir) ((_dir == TUSB_DIR_IN) ? 0 : 16) - -#if 0 -/******************** Bit definition for OTG register ********************/ -#define CHNUM_Pos (0U) -#define CHNUM_Msk (0xFUL << CHNUM_Pos) // 0x0000000F -#define CHNUM CHNUM_Msk // Channel number -#define CHNUM_0 (0x1UL << CHNUM_Pos) // 0x00000001 -#define CHNUM_1 (0x2UL << CHNUM_Pos) // 0x00000002 -#define CHNUM_2 (0x4UL << CHNUM_Pos) // 0x00000004 -#define CHNUM_3 (0x8UL << CHNUM_Pos) // 0x00000008 -#define BCNT_Pos (4U) -#define BCNT_Msk (0x7FFUL << BCNT_Pos) // 0x00007FF0 -#define BCNT BCNT_Msk // Byte count - -#define DPID_Pos (15U) -#define DPID_Msk (0x3UL << DPID_Pos) // 0x00018000 -#define DPID DPID_Msk // Data PID -#define DPID_0 (0x1UL << DPID_Pos) // 0x00008000 -#define DPID_1 (0x2UL << DPID_Pos) // 0x00010000 - -#define PKTSTS_Pos (17U) -#define PKTSTS_Msk (0xFUL << PKTSTS_Pos) // 0x001E0000 -#define PKTSTS PKTSTS_Msk // Packet status -#define PKTSTS_0 (0x1UL << PKTSTS_Pos) // 0x00020000 -#define PKTSTS_1 (0x2UL << PKTSTS_Pos) // 0x00040000 -#define PKTSTS_2 (0x4UL << PKTSTS_Pos) // 0x00080000 -#define PKTSTS_3 (0x8UL << PKTSTS_Pos) // 0x00100000 - -#define EPNUM_Pos (0U) -#define EPNUM_Msk (0xFUL << EPNUM_Pos) // 0x0000000F -#define EPNUM EPNUM_Msk // Endpoint number -#define EPNUM_0 (0x1UL << EPNUM_Pos) // 0x00000001 -#define EPNUM_1 (0x2UL << EPNUM_Pos) // 0x00000002 -#define EPNUM_2 (0x4UL << EPNUM_Pos) // 0x00000004 -#define EPNUM_3 (0x8UL << EPNUM_Pos) // 0x00000008 - -#define FRMNUM_Pos (21U) -#define FRMNUM_Msk (0xFUL << FRMNUM_Pos) // 0x01E00000 -#define FRMNUM FRMNUM_Msk // Frame number -#define FRMNUM_0 (0x1UL << FRMNUM_Pos) // 0x00200000 -#define FRMNUM_1 (0x2UL << FRMNUM_Pos) // 0x00400000 -#define FRMNUM_2 (0x4UL << FRMNUM_Pos) // 0x00800000 -#define FRMNUM_3 (0x8UL << FRMNUM_Pos) // 0x01000000 -#endif - -/******************** Bit definition for GRXFSIZ register ********************/ -#define GRXFSIZ_RXFD_Pos (0U) -#define GRXFSIZ_RXFD_Msk (0xFFFFUL << GRXFSIZ_RXFD_Pos) // 0x0000FFFF -#define GRXFSIZ_RXFD GRXFSIZ_RXFD_Msk // RxFIFO depth - -/******************** Bit definition for DVBUSDIS register ********************/ -#define DVBUSDIS_VBUSDT_Pos (0U) -#define DVBUSDIS_VBUSDT_Msk (0xFFFFUL << DVBUSDIS_VBUSDT_Pos) // 0x0000FFFF -#define DVBUSDIS_VBUSDT DVBUSDIS_VBUSDT_Msk // Device VBUS discharge time - -/******************** Bit definition for OTG register ********************/ -#define GNPTXFSIZ_NPTXFSA_Pos (0U) -#define GNPTXFSIZ_NPTXFSA_Msk (0xFFFFUL << GNPTXFSIZ_NPTXFSA_Pos) // 0x0000FFFF -#define GNPTXFSIZ_NPTXFSA GNPTXFSIZ_NPTXFSA_Msk // Nonperiodic transmit RAM start address -#define GNPTXFSIZ_NPTXFD_Pos (16U) -#define GNPTXFSIZ_NPTXFD_Msk (0xFFFFUL << GNPTXFSIZ_NPTXFD_Pos) // 0xFFFF0000 -#define GNPTXFSIZ_NPTXFD GNPTXFSIZ_NPTXFD_Msk // Nonperiodic TxFIFO depth -#define DIEPTXF0_TX0FSA_Pos (0U) -#define DIEPTXF0_TX0FSA_Msk (0xFFFFUL << DIEPTXF0_TX0FSA_Pos) // 0x0000FFFF -#define DIEPTXF0_TX0FSA DIEPTXF0_TX0FSA_Msk // Endpoint 0 transmit RAM start address -#define DIEPTXF0_TX0FD_Pos (16U) -#define DIEPTXF0_TX0FD_Msk (0xFFFFUL << DIEPTXF0_TX0FD_Pos) // 0xFFFF0000 -#define DIEPTXF0_TX0FD DIEPTXF0_TX0FD_Msk // Endpoint 0 TxFIFO depth - -/******************** Bit definition for DVBUSPULSE register ********************/ -#define DVBUSPULSE_DVBUSP_Pos (0U) -#define DVBUSPULSE_DVBUSP_Msk (0xFFFUL << DVBUSPULSE_DVBUSP_Pos) // 0x00000FFF -#define DVBUSPULSE_DVBUSP DVBUSPULSE_DVBUSP_Msk // Device VBUS pulsing time - -/******************** Bit definition for GNPTXSTS register ********************/ -#define GNPTXSTS_NPTXFSAV_Pos (0U) -#define GNPTXSTS_NPTXFSAV_Msk (0xFFFFUL << GNPTXSTS_NPTXFSAV_Pos) // 0x0000FFFF -#define GNPTXSTS_NPTXFSAV GNPTXSTS_NPTXFSAV_Msk // Nonperiodic TxFIFO space available - -#define GNPTXSTS_NPTQXSAV_Pos (16U) -#define GNPTXSTS_NPTQXSAV_Msk (0xFFUL << GNPTXSTS_NPTQXSAV_Pos) // 0x00FF0000 -#define GNPTXSTS_NPTQXSAV GNPTXSTS_NPTQXSAV_Msk // Nonperiodic transmit request queue space available -#define GNPTXSTS_NPTQXSAV_0 (0x01UL << GNPTXSTS_NPTQXSAV_Pos) // 0x00010000 -#define GNPTXSTS_NPTQXSAV_1 (0x02UL << GNPTXSTS_NPTQXSAV_Pos) // 0x00020000 -#define GNPTXSTS_NPTQXSAV_2 (0x04UL << GNPTXSTS_NPTQXSAV_Pos) // 0x00040000 -#define GNPTXSTS_NPTQXSAV_3 (0x08UL << GNPTXSTS_NPTQXSAV_Pos) // 0x00080000 -#define GNPTXSTS_NPTQXSAV_4 (0x10UL << GNPTXSTS_NPTQXSAV_Pos) // 0x00100000 -#define GNPTXSTS_NPTQXSAV_5 (0x20UL << GNPTXSTS_NPTQXSAV_Pos) // 0x00200000 -#define GNPTXSTS_NPTQXSAV_6 (0x40UL << GNPTXSTS_NPTQXSAV_Pos) // 0x00400000 -#define GNPTXSTS_NPTQXSAV_7 (0x80UL << GNPTXSTS_NPTQXSAV_Pos) // 0x00800000 - -#define GNPTXSTS_NPTXQTOP_Pos (24U) -#define GNPTXSTS_NPTXQTOP_Msk (0x7FUL << GNPTXSTS_NPTXQTOP_Pos) // 0x7F000000 -#define GNPTXSTS_NPTXQTOP GNPTXSTS_NPTXQTOP_Msk // Top of the nonperiodic transmit request queue -#define GNPTXSTS_NPTXQTOP_0 (0x01UL << GNPTXSTS_NPTXQTOP_Pos) // 0x01000000 -#define GNPTXSTS_NPTXQTOP_1 (0x02UL << GNPTXSTS_NPTXQTOP_Pos) // 0x02000000 -#define GNPTXSTS_NPTXQTOP_2 (0x04UL << GNPTXSTS_NPTXQTOP_Pos) // 0x04000000 -#define GNPTXSTS_NPTXQTOP_3 (0x08UL << GNPTXSTS_NPTXQTOP_Pos) // 0x08000000 -#define GNPTXSTS_NPTXQTOP_4 (0x10UL << GNPTXSTS_NPTXQTOP_Pos) // 0x10000000 -#define GNPTXSTS_NPTXQTOP_5 (0x20UL << GNPTXSTS_NPTXQTOP_Pos) // 0x20000000 -#define GNPTXSTS_NPTXQTOP_6 (0x40UL << GNPTXSTS_NPTXQTOP_Pos) // 0x40000000 - -/******************** Bit definition for DTHRCTL register ********************/ -#define DTHRCTL_NONISOTHREN_Pos (0U) -#define DTHRCTL_NONISOTHREN_Msk (0x1UL << DTHRCTL_NONISOTHREN_Pos) // 0x00000001 -#define DTHRCTL_NONISOTHREN DTHRCTL_NONISOTHREN_Msk // Nonisochronous IN endpoints threshold enable -#define DTHRCTL_ISOTHREN_Pos (1U) -#define DTHRCTL_ISOTHREN_Msk (0x1UL << DTHRCTL_ISOTHREN_Pos) // 0x00000002 -#define DTHRCTL_ISOTHREN DTHRCTL_ISOTHREN_Msk // ISO IN endpoint threshold enable - -#define DTHRCTL_TXTHRLEN_Pos (2U) -#define DTHRCTL_TXTHRLEN_Msk (0x1FFUL << DTHRCTL_TXTHRLEN_Pos) // 0x000007FC -#define DTHRCTL_TXTHRLEN DTHRCTL_TXTHRLEN_Msk // Transmit threshold length -#define DTHRCTL_TXTHRLEN_0 (0x001UL << DTHRCTL_TXTHRLEN_Pos) // 0x00000004 -#define DTHRCTL_TXTHRLEN_1 (0x002UL << DTHRCTL_TXTHRLEN_Pos) // 0x00000008 -#define DTHRCTL_TXTHRLEN_2 (0x004UL << DTHRCTL_TXTHRLEN_Pos) // 0x00000010 -#define DTHRCTL_TXTHRLEN_3 (0x008UL << DTHRCTL_TXTHRLEN_Pos) // 0x00000020 -#define DTHRCTL_TXTHRLEN_4 (0x010UL << DTHRCTL_TXTHRLEN_Pos) // 0x00000040 -#define DTHRCTL_TXTHRLEN_5 (0x020UL << DTHRCTL_TXTHRLEN_Pos) // 0x00000080 -#define DTHRCTL_TXTHRLEN_6 (0x040UL << DTHRCTL_TXTHRLEN_Pos) // 0x00000100 -#define DTHRCTL_TXTHRLEN_7 (0x080UL << DTHRCTL_TXTHRLEN_Pos) // 0x00000200 -#define DTHRCTL_TXTHRLEN_8 (0x100UL << DTHRCTL_TXTHRLEN_Pos) // 0x00000400 -#define DTHRCTL_RXTHREN_Pos (16U) -#define DTHRCTL_RXTHREN_Msk (0x1UL << DTHRCTL_RXTHREN_Pos) // 0x00010000 -#define DTHRCTL_RXTHREN DTHRCTL_RXTHREN_Msk // Receive threshold enable - -#define DTHRCTL_RXTHRLEN_Pos (17U) -#define DTHRCTL_RXTHRLEN_Msk (0x1FFUL << DTHRCTL_RXTHRLEN_Pos) // 0x03FE0000 -#define DTHRCTL_RXTHRLEN DTHRCTL_RXTHRLEN_Msk // Receive threshold length -#define DTHRCTL_RXTHRLEN_0 (0x001UL << DTHRCTL_RXTHRLEN_Pos) // 0x00020000 -#define DTHRCTL_RXTHRLEN_1 (0x002UL << DTHRCTL_RXTHRLEN_Pos) // 0x00040000 -#define DTHRCTL_RXTHRLEN_2 (0x004UL << DTHRCTL_RXTHRLEN_Pos) // 0x00080000 -#define DTHRCTL_RXTHRLEN_3 (0x008UL << DTHRCTL_RXTHRLEN_Pos) // 0x00100000 -#define DTHRCTL_RXTHRLEN_4 (0x010UL << DTHRCTL_RXTHRLEN_Pos) // 0x00200000 -#define DTHRCTL_RXTHRLEN_5 (0x020UL << DTHRCTL_RXTHRLEN_Pos) // 0x00400000 -#define DTHRCTL_RXTHRLEN_6 (0x040UL << DTHRCTL_RXTHRLEN_Pos) // 0x00800000 -#define DTHRCTL_RXTHRLEN_7 (0x080UL << DTHRCTL_RXTHRLEN_Pos) // 0x01000000 -#define DTHRCTL_RXTHRLEN_8 (0x100UL << DTHRCTL_RXTHRLEN_Pos) // 0x02000000 -#define DTHRCTL_ARPEN_Pos (27U) -#define DTHRCTL_ARPEN_Msk (0x1UL << DTHRCTL_ARPEN_Pos) // 0x08000000 -#define DTHRCTL_ARPEN DTHRCTL_ARPEN_Msk // Arbiter parking enable - -/******************** Bit definition for DIEPEMPMSK register ********************/ -#define DIEPEMPMSK_INEPTXFEM_Pos (0U) -#define DIEPEMPMSK_INEPTXFEM_Msk (0xFFFFUL << DIEPEMPMSK_INEPTXFEM_Pos) // 0x0000FFFF -#define DIEPEMPMSK_INEPTXFEM DIEPEMPMSK_INEPTXFEM_Msk // IN EP Tx FIFO empty interrupt mask bits - -/******************** Bit definition for DEACHINT register ********************/ -#define DEACHINT_IEP1INT_Pos (1U) -#define DEACHINT_IEP1INT_Msk (0x1UL << DEACHINT_IEP1INT_Pos) // 0x00000002 -#define DEACHINT_IEP1INT DEACHINT_IEP1INT_Msk // IN endpoint 1interrupt bit -#define DEACHINT_OEP1INT_Pos (17U) -#define DEACHINT_OEP1INT_Msk (0x1UL << DEACHINT_OEP1INT_Pos) // 0x00020000 -#define DEACHINT_OEP1INT DEACHINT_OEP1INT_Msk // OUT endpoint 1 interrupt bit - -/******************** Bit definition for GCCFG register ********************/ -#define STM32_GCCFG_DCDET_Pos (0U) -#define STM32_GCCFG_DCDET_Msk (0x1UL << STM32_GCCFG_DCDET_Pos) // 0x00000001 -#define STM32_GCCFG_DCDET STM32_GCCFG_DCDET_Msk // Data contact detection (DCD) status - -#define STM32_GCCFG_PDET_Pos (1U) -#define STM32_GCCFG_PDET_Msk (0x1UL << STM32_GCCFG_PDET_Pos) // 0x00000002 -#define STM32_GCCFG_PDET STM32_GCCFG_PDET_Msk // Primary detection (PD) status - -#define STM32_GCCFG_SDET_Pos (2U) -#define STM32_GCCFG_SDET_Msk (0x1UL << STM32_GCCFG_SDET_Pos) // 0x00000004 -#define STM32_GCCFG_SDET STM32_GCCFG_SDET_Msk // Secondary detection (SD) status - -#define STM32_GCCFG_PS2DET_Pos (3U) -#define STM32_GCCFG_PS2DET_Msk (0x1UL << STM32_GCCFG_PS2DET_Pos) // 0x00000008 -#define STM32_GCCFG_PS2DET STM32_GCCFG_PS2DET_Msk // DM pull-up detection status - -#define STM32_GCCFG_PWRDWN_Pos (16U) -#define STM32_GCCFG_PWRDWN_Msk (0x1UL << STM32_GCCFG_PWRDWN_Pos) // 0x00010000 -#define STM32_GCCFG_PWRDWN STM32_GCCFG_PWRDWN_Msk // Power down - -#define STM32_GCCFG_BCDEN_Pos (17U) -#define STM32_GCCFG_BCDEN_Msk (0x1UL << STM32_GCCFG_BCDEN_Pos) // 0x00020000 -#define STM32_GCCFG_BCDEN STM32_GCCFG_BCDEN_Msk // Battery charging detector (BCD) enable - -#define STM32_GCCFG_DCDEN_Pos (18U) -#define STM32_GCCFG_DCDEN_Msk (0x1UL << STM32_GCCFG_DCDEN_Pos) // 0x00040000 -#define STM32_GCCFG_DCDEN STM32_GCCFG_DCDEN_Msk // Data contact detection (DCD) mode enable*/ - -#define STM32_GCCFG_PDEN_Pos (19U) -#define STM32_GCCFG_PDEN_Msk (0x1UL << STM32_GCCFG_PDEN_Pos) // 0x00080000 -#define STM32_GCCFG_PDEN STM32_GCCFG_PDEN_Msk // Primary detection (PD) mode enable*/ - -#define STM32_GCCFG_SDEN_Pos (20U) -#define STM32_GCCFG_SDEN_Msk (0x1UL << STM32_GCCFG_SDEN_Pos) // 0x00100000 -#define STM32_GCCFG_SDEN STM32_GCCFG_SDEN_Msk // Secondary detection (SD) mode enable - -#define STM32_GCCFG_VBDEN_Pos (21U) -#define STM32_GCCFG_VBDEN_Msk (0x1UL << STM32_GCCFG_VBDEN_Pos) // 0x00200000 -#define STM32_GCCFG_VBDEN STM32_GCCFG_VBDEN_Msk // VBUS mode enable - -#define STM32_GCCFG_OTGIDEN_Pos (22U) -#define STM32_GCCFG_OTGIDEN_Msk (0x1UL << STM32_GCCFG_OTGIDEN_Pos) // 0x00400000 -#define STM32_GCCFG_OTGIDEN STM32_GCCFG_OTGIDEN_Msk // OTG Id enable - -#define STM32_GCCFG_PHYHSEN_Pos (23U) -#define STM32_GCCFG_PHYHSEN_Msk (0x1UL << STM32_GCCFG_PHYHSEN_Pos) // 0x00800000 -#define STM32_GCCFG_PHYHSEN STM32_GCCFG_PHYHSEN_Msk // HS PHY enable - -// TODO stm32u5a5 SDEN is 22nd bit, conflict with 20th bit above -//#define STM32_GCCFG_SDEN_Pos (22U) -//#define STM32_GCCFG_SDEN_Msk (0x1U << STM32_GCCFG_SDEN_Pos) // 0x00400000 -//#define STM32_GCCFG_SDEN STM32_GCCFG_SDEN_Msk // Secondary detection (PD) mode enable - -// TODO stm32u5a5 VBVALOVA is 23rd bit, conflict with PHYHSEN bit above -#define STM32_GCCFG_VBVALOVAL_Pos (23U) -#define STM32_GCCFG_VBVALOVAL_Msk (0x1U << STM32_GCCFG_VBVALOVAL_Pos) // 0x00800000 -#define STM32_GCCFG_VBVALOVAL STM32_GCCFG_VBVALOVAL_Msk // Value of VBUSVLDEXT0 femtoPHY input - -#define STM32_GCCFG_VBVALEXTOEN_Pos (24U) -#define STM32_GCCFG_VBVALEXTOEN_Msk (0x1U << STM32_GCCFG_VBVALEXTOEN_Pos) // 0x01000000 -#define STM32_GCCFG_VBVALEXTOEN STM32_GCCFG_VBVALEXTOEN_Msk // Enables of VBUSVLDEXT0 femtoPHY input override - -#define STM32_GCCFG_PULLDOWNEN_Pos (25U) -#define STM32_GCCFG_PULLDOWNEN_Msk (0x1U << STM32_GCCFG_PULLDOWNEN_Pos) // 0x02000000 -#define STM32_GCCFG_PULLDOWNEN STM32_GCCFG_PULLDOWNEN_Msk // Enables of femtoPHY pulldown resistors, used when ID PAD is disabled - - -/******************** Bit definition for DEACHINTMSK register ********************/ -#define DEACHINTMSK_IEP1INTM_Pos (1U) -#define DEACHINTMSK_IEP1INTM_Msk (0x1UL << DEACHINTMSK_IEP1INTM_Pos) // 0x00000002 -#define DEACHINTMSK_IEP1INTM DEACHINTMSK_IEP1INTM_Msk // IN Endpoint 1 interrupt mask bit -#define DEACHINTMSK_OEP1INTM_Pos (17U) -#define DEACHINTMSK_OEP1INTM_Msk (0x1UL << DEACHINTMSK_OEP1INTM_Pos) // 0x00020000 -#define DEACHINTMSK_OEP1INTM DEACHINTMSK_OEP1INTM_Msk // OUT Endpoint 1 interrupt mask bit - -/******************** Bit definition for CID register ********************/ -#define CID_PRODUCT_ID_Pos (0U) -#define CID_PRODUCT_ID_Msk (0xFFFFFFFFUL << CID_PRODUCT_ID_Pos) // 0xFFFFFFFF -#define CID_PRODUCT_ID CID_PRODUCT_ID_Msk // Product ID field - -/******************** Bit definition for GLPMCFG register ********************/ -#define GLPMCFG_LPMEN_Pos (0U) -#define GLPMCFG_LPMEN_Msk (0x1UL << GLPMCFG_LPMEN_Pos) // 0x00000001 -#define GLPMCFG_LPMEN GLPMCFG_LPMEN_Msk // LPM support enable -#define GLPMCFG_LPMACK_Pos (1U) -#define GLPMCFG_LPMACK_Msk (0x1UL << GLPMCFG_LPMACK_Pos) // 0x00000002 -#define GLPMCFG_LPMACK GLPMCFG_LPMACK_Msk // LPM Token acknowledge enable -#define GLPMCFG_BESL_Pos (2U) -#define GLPMCFG_BESL_Msk (0xFUL << GLPMCFG_BESL_Pos) // 0x0000003C -#define GLPMCFG_BESL GLPMCFG_BESL_Msk // BESL value received with last ACKed LPM Token -#define GLPMCFG_REMWAKE_Pos (6U) -#define GLPMCFG_REMWAKE_Msk (0x1UL << GLPMCFG_REMWAKE_Pos) // 0x00000040 -#define GLPMCFG_REMWAKE GLPMCFG_REMWAKE_Msk // bRemoteWake value received with last ACKed LPM Token -#define GLPMCFG_L1SSEN_Pos (7U) -#define GLPMCFG_L1SSEN_Msk (0x1UL << GLPMCFG_L1SSEN_Pos) // 0x00000080 -#define GLPMCFG_L1SSEN GLPMCFG_L1SSEN_Msk // L1 shallow sleep enable -#define GLPMCFG_BESLTHRS_Pos (8U) -#define GLPMCFG_BESLTHRS_Msk (0xFUL << GLPMCFG_BESLTHRS_Pos) // 0x00000F00 -#define GLPMCFG_BESLTHRS GLPMCFG_BESLTHRS_Msk // BESL threshold -#define GLPMCFG_L1DSEN_Pos (12U) -#define GLPMCFG_L1DSEN_Msk (0x1UL << GLPMCFG_L1DSEN_Pos) // 0x00001000 -#define GLPMCFG_L1DSEN GLPMCFG_L1DSEN_Msk // L1 deep sleep enable -#define GLPMCFG_LPMRSP_Pos (13U) -#define GLPMCFG_LPMRSP_Msk (0x3UL << GLPMCFG_LPMRSP_Pos) // 0x00006000 -#define GLPMCFG_LPMRSP GLPMCFG_LPMRSP_Msk // LPM response -#define GLPMCFG_SLPSTS_Pos (15U) -#define GLPMCFG_SLPSTS_Msk (0x1UL << GLPMCFG_SLPSTS_Pos) // 0x00008000 -#define GLPMCFG_SLPSTS GLPMCFG_SLPSTS_Msk // Port sleep status -#define GLPMCFG_L1RSMOK_Pos (16U) -#define GLPMCFG_L1RSMOK_Msk (0x1UL << GLPMCFG_L1RSMOK_Pos) // 0x00010000 -#define GLPMCFG_L1RSMOK GLPMCFG_L1RSMOK_Msk // Sleep State Resume OK -#define GLPMCFG_LPMCHIDX_Pos (17U) -#define GLPMCFG_LPMCHIDX_Msk (0xFUL << GLPMCFG_LPMCHIDX_Pos) // 0x001E0000 -#define GLPMCFG_LPMCHIDX GLPMCFG_LPMCHIDX_Msk // LPM Channel Index -#define GLPMCFG_LPMRCNT_Pos (21U) -#define GLPMCFG_LPMRCNT_Msk (0x7UL << GLPMCFG_LPMRCNT_Pos) // 0x00E00000 -#define GLPMCFG_LPMRCNT GLPMCFG_LPMRCNT_Msk // LPM retry count -#define GLPMCFG_SNDLPM_Pos (24U) -#define GLPMCFG_SNDLPM_Msk (0x1UL << GLPMCFG_SNDLPM_Pos) // 0x01000000 -#define GLPMCFG_SNDLPM GLPMCFG_SNDLPM_Msk // Send LPM transaction -#define GLPMCFG_LPMRCNTSTS_Pos (25U) -#define GLPMCFG_LPMRCNTSTS_Msk (0x7UL << GLPMCFG_LPMRCNTSTS_Pos) // 0x0E000000 -#define GLPMCFG_LPMRCNTSTS GLPMCFG_LPMRCNTSTS_Msk // LPM retry count status -#define GLPMCFG_ENBESL_Pos (28U) -#define GLPMCFG_ENBESL_Msk (0x1UL << GLPMCFG_ENBESL_Pos) // 0x10000000 -#define GLPMCFG_ENBESL GLPMCFG_ENBESL_Msk // Enable best effort service latency - -// GDFIFOCFG -#define GDFIFOCFG_EPINFOBASE_MASK (0xffff << 16) -#define GDFIFOCFG_EPINFOBASE_SHIFT 16 -#define GDFIFOCFG_GDFIFOCFG_MASK (0xffff << 0) -#define GDFIFOCFG_GDFIFOCFG_SHIFT 0 - -/******************** Bit definition for DIEPEACHMSK1 register ********************/ -#define DIEPEACHMSK1_XFRCM_Pos (0U) -#define DIEPEACHMSK1_XFRCM_Msk (0x1UL << DIEPEACHMSK1_XFRCM_Pos) // 0x00000001 -#define DIEPEACHMSK1_XFRCM DIEPEACHMSK1_XFRCM_Msk // Transfer completed interrupt mask -#define DIEPEACHMSK1_EPDM_Pos (1U) -#define DIEPEACHMSK1_EPDM_Msk (0x1UL << DIEPEACHMSK1_EPDM_Pos) // 0x00000002 -#define DIEPEACHMSK1_EPDM DIEPEACHMSK1_EPDM_Msk // Endpoint disabled interrupt mask -#define DIEPEACHMSK1_TOM_Pos (3U) -#define DIEPEACHMSK1_TOM_Msk (0x1UL << DIEPEACHMSK1_TOM_Pos) // 0x00000008 -#define DIEPEACHMSK1_TOM DIEPEACHMSK1_TOM_Msk // Timeout condition mask (nonisochronous endpoints) -#define DIEPEACHMSK1_ITTXFEMSK_Pos (4U) -#define DIEPEACHMSK1_ITTXFEMSK_Msk (0x1UL << DIEPEACHMSK1_ITTXFEMSK_Pos) // 0x00000010 -#define DIEPEACHMSK1_ITTXFEMSK DIEPEACHMSK1_ITTXFEMSK_Msk // IN token received when TxFIFO empty mask -#define DIEPEACHMSK1_INEPNMM_Pos (5U) -#define DIEPEACHMSK1_INEPNMM_Msk (0x1UL << DIEPEACHMSK1_INEPNMM_Pos) // 0x00000020 -#define DIEPEACHMSK1_INEPNMM DIEPEACHMSK1_INEPNMM_Msk // IN token received with EP mismatch mask -#define DIEPEACHMSK1_INEPNEM_Pos (6U) -#define DIEPEACHMSK1_INEPNEM_Msk (0x1UL << DIEPEACHMSK1_INEPNEM_Pos) // 0x00000040 -#define DIEPEACHMSK1_INEPNEM DIEPEACHMSK1_INEPNEM_Msk // IN endpoint NAK effective mask -#define DIEPEACHMSK1_TXFURM_Pos (8U) -#define DIEPEACHMSK1_TXFURM_Msk (0x1UL << DIEPEACHMSK1_TXFURM_Pos) // 0x00000100 -#define DIEPEACHMSK1_TXFURM DIEPEACHMSK1_TXFURM_Msk // FIFO underrun mask -#define DIEPEACHMSK1_BIM_Pos (9U) -#define DIEPEACHMSK1_BIM_Msk (0x1UL << DIEPEACHMSK1_BIM_Pos) // 0x00000200 -#define DIEPEACHMSK1_BIM DIEPEACHMSK1_BIM_Msk // BNA interrupt mask -#define DIEPEACHMSK1_NAKM_Pos (13U) -#define DIEPEACHMSK1_NAKM_Msk (0x1UL << DIEPEACHMSK1_NAKM_Pos) // 0x00002000 -#define DIEPEACHMSK1_NAKM DIEPEACHMSK1_NAKM_Msk // NAK interrupt mask - -/******************** Bit definition for HPRT register ********************/ -#define HPRT_CONN_STATUS_Pos (0U) -#define HPRT_CONN_STATUS_Msk (0x1UL << HPRT_CONN_STATUS_Pos) // 0x00000001 -#define HPRT_CONN_STATUS HPRT_CONN_STATUS_Msk // Port connect status -#define HPRT_CONN_DETECT_Pos (1U) -#define HPRT_CONN_DETECT_Msk (0x1UL << HPRT_CONN_DETECT_Pos) // 0x00000002 -#define HPRT_CONN_DETECT HPRT_CONN_DETECT_Msk // Port connect detected -#define HPRT_ENABLE_Pos (2U) -#define HPRT_ENABLE_Msk (0x1UL << HPRT_ENABLE_Pos) // 0x00000004 -#define HPRT_ENABLE HPRT_ENABLE_Msk // Port enable -#define HPRT_ENABLE_CHANGE_Pos (3U) -#define HPRT_ENABLE_CHANGE_Msk (0x1UL << HPRT_ENABLE_CHANGE_Pos) // 0x00000008 -#define HPRT_ENABLE_CHANGE HPRT_ENABLE_CHANGE_Msk // Port enable/disable change -#define HPRT_OVER_CURRENT_ACTIVE_Pos (4U) -#define HPRT_OVER_CURRENT_ACTIVE_Msk (0x1UL << HPRT_OVER_CURRENT_ACTIVE_Pos) // 0x00000010 -#define HPRT_OVER_CURRENT_ACTIVE HPRT_OVER_CURRENT_ACTIVE_Msk // Port overcurrent active -#define HPRT_OVER_CURRENT_CHANGE_Pos (5U) -#define HPRT_OVER_CURRENT_CHANGE_Msk (0x1UL << HPRT_OVER_CURRENT_CHANGE_Pos) // 0x00000020 -#define HPRT_OVER_CURRENT_CHANGE HPRT_OVER_CURRENT_CHANGE_Msk // Port overcurrent change -#define HPRT_RESUME_Pos (6U) -#define HPRT_RESUME_Msk (0x1UL << HPRT_RESUME_Pos) // 0x00000040 -#define HPRT_RESUME HPRT_RESUME_Msk // Port resume -#define HPRT_SUSPEND_Pos (7U) -#define HPRT_SUSPEND_Msk (0x1UL << HPRT_SUSPEND_Pos) // 0x00000080 -#define HPRT_SUSPEND HPRT_SUSPEND_Msk // Port suspend -#define HPRT_RESET_Pos (8U) -#define HPRT_RESET_Msk (0x1UL << HPRT_RESET_Pos) // 0x00000100 -#define HPRT_RESET HPRT_RESET_Msk // Port reset -#define HPRT_LINE_STATUS_Pos (10U) -#define HPRT_LINE_STATUS_Msk (0x3UL << HPRT_LINE_STATUS_Pos) // 0x00000C00 -#define HPRT_LINE_STATUS HPRT_LINE_STATUS_Msk // Port line status -#define HPRT_LINE_STATUS_0 (0x1UL << HPRT_LINE_STATUS_Pos) // 0x00000400 -#define HPRT_LINE_STATUS_1 (0x2UL << HPRT_LINE_STATUS_Pos) // 0x00000800 -#define HPRT_POWER_Pos (12U) -#define HPRT_POWER_Msk (0x1UL << HPRT_POWER_Pos) // 0x00001000 -#define HPRT_POWER HPRT_POWER_Msk // Port power -#define HPRT_TEST_CONTROL_Pos (13U) -#define HPRT_TEST_CONTROL_Msk (0xFUL << HPRT_TEST_CONTROL_Pos) // 0x0001E000 -#define HPRT_TEST_CONTROL HPRT_TEST_CONTROL_Msk // Port test control -#define HPRT_TEST_CONTROL_0 (0x1UL << HPRT_TEST_CONTROL_Pos) // 0x00002000 -#define HPRT_TEST_CONTROL_1 (0x2UL << HPRT_TEST_CONTROL_Pos) // 0x00004000 -#define HPRT_TEST_CONTROL_2 (0x4UL << HPRT_TEST_CONTROL_Pos) // 0x00008000 -#define HPRT_TEST_CONTROL_3 (0x8UL << HPRT_TEST_CONTROL_Pos) // 0x00010000 -#define HPRT_SPEED_Pos (17U) -#define HPRT_SPEED_Msk (0x3UL << HPRT_SPEED_Pos) // 0x00060000 -#define HPRT_SPEED HPRT_SPEED_Msk // Port speed -#define HPRT_SPEED_0 (0x1UL << HPRT_SPEED_Pos) // 0x00020000 -#define HPRT_SPEED_1 (0x2UL << HPRT_SPEED_Pos) // 0x00040000 - -/******************** Bit definition for DOEPEACHMSK1 register ********************/ -#define DOEPEACHMSK1_XFRCM_Pos (0U) -#define DOEPEACHMSK1_XFRCM_Msk (0x1UL << DOEPEACHMSK1_XFRCM_Pos) // 0x00000001 -#define DOEPEACHMSK1_XFRCM DOEPEACHMSK1_XFRCM_Msk // Transfer completed interrupt mask -#define DOEPEACHMSK1_EPDM_Pos (1U) -#define DOEPEACHMSK1_EPDM_Msk (0x1UL << DOEPEACHMSK1_EPDM_Pos) // 0x00000002 -#define DOEPEACHMSK1_EPDM DOEPEACHMSK1_EPDM_Msk // Endpoint disabled interrupt mask -#define DOEPEACHMSK1_TOM_Pos (3U) -#define DOEPEACHMSK1_TOM_Msk (0x1UL << DOEPEACHMSK1_TOM_Pos) // 0x00000008 -#define DOEPEACHMSK1_TOM DOEPEACHMSK1_TOM_Msk // Timeout condition mask -#define DOEPEACHMSK1_ITTXFEMSK_Pos (4U) -#define DOEPEACHMSK1_ITTXFEMSK_Msk (0x1UL << DOEPEACHMSK1_ITTXFEMSK_Pos) // 0x00000010 -#define DOEPEACHMSK1_ITTXFEMSK DOEPEACHMSK1_ITTXFEMSK_Msk // IN token received when TxFIFO empty mask -#define DOEPEACHMSK1_INEPNMM_Pos (5U) -#define DOEPEACHMSK1_INEPNMM_Msk (0x1UL << DOEPEACHMSK1_INEPNMM_Pos) // 0x00000020 -#define DOEPEACHMSK1_INEPNMM DOEPEACHMSK1_INEPNMM_Msk // IN token received with EP mismatch mask -#define DOEPEACHMSK1_INEPNEM_Pos (6U) -#define DOEPEACHMSK1_INEPNEM_Msk (0x1UL << DOEPEACHMSK1_INEPNEM_Pos) // 0x00000040 -#define DOEPEACHMSK1_INEPNEM DOEPEACHMSK1_INEPNEM_Msk // IN endpoint NAK effective mask -#define DOEPEACHMSK1_TXFURM_Pos (8U) -#define DOEPEACHMSK1_TXFURM_Msk (0x1UL << DOEPEACHMSK1_TXFURM_Pos) // 0x00000100 -#define DOEPEACHMSK1_TXFURM DOEPEACHMSK1_TXFURM_Msk // OUT packet error mask -#define DOEPEACHMSK1_BIM_Pos (9U) -#define DOEPEACHMSK1_BIM_Msk (0x1UL << DOEPEACHMSK1_BIM_Pos) // 0x00000200 -#define DOEPEACHMSK1_BIM DOEPEACHMSK1_BIM_Msk // BNA interrupt mask -#define DOEPEACHMSK1_BERRM_Pos (12U) -#define DOEPEACHMSK1_BERRM_Msk (0x1UL << DOEPEACHMSK1_BERRM_Pos) // 0x00001000 -#define DOEPEACHMSK1_BERRM DOEPEACHMSK1_BERRM_Msk // Bubble error interrupt mask -#define DOEPEACHMSK1_NAKM_Pos (13U) -#define DOEPEACHMSK1_NAKM_Msk (0x1UL << DOEPEACHMSK1_NAKM_Pos) // 0x00002000 -#define DOEPEACHMSK1_NAKM DOEPEACHMSK1_NAKM_Msk // NAK interrupt mask -#define DOEPEACHMSK1_NYETM_Pos (14U) -#define DOEPEACHMSK1_NYETM_Msk (0x1UL << DOEPEACHMSK1_NYETM_Pos) // 0x00004000 -#define DOEPEACHMSK1_NYETM DOEPEACHMSK1_NYETM_Msk // NYET interrupt mask - -/******************** Bit definition for HPTXFSIZ register ********************/ -#define HPTXFSIZ_PTXSA_Pos (0U) -#define HPTXFSIZ_PTXSA_Msk (0xFFFFUL << HPTXFSIZ_PTXSA_Pos) // 0x0000FFFF -#define HPTXFSIZ_PTXSA HPTXFSIZ_PTXSA_Msk // Host periodic TxFIFO start address -#define HPTXFSIZ_PTXFD_Pos (16U) -#define HPTXFSIZ_PTXFD_Msk (0xFFFFUL << HPTXFSIZ_PTXFD_Pos) // 0xFFFF0000 -#define HPTXFSIZ_PTXFD HPTXFSIZ_PTXFD_Msk // Host periodic TxFIFO depth - -/******************** Bit definition for DIEPCTL register ********************/ -#define DIEPCTL_MPSIZ_Pos (0U) -#define DIEPCTL_MPSIZ_Msk (0x7FFUL << DIEPCTL_MPSIZ_Pos) // 0x000007FF -#define DIEPCTL_MPSIZ DIEPCTL_MPSIZ_Msk // Maximum packet size -#define DIEPCTL_USBAEP_Pos (15U) -#define DIEPCTL_USBAEP_Msk (0x1UL << DIEPCTL_USBAEP_Pos) // 0x00008000 -#define DIEPCTL_USBAEP DIEPCTL_USBAEP_Msk // USB active endpoint -#define DIEPCTL_EONUM_DPID_Pos (16U) -#define DIEPCTL_EONUM_DPID_Msk (0x1UL << DIEPCTL_EONUM_DPID_Pos) // 0x00010000 -#define DIEPCTL_EONUM_DPID DIEPCTL_EONUM_DPID_Msk // Even/odd frame -#define DIEPCTL_NAKSTS_Pos (17U) -#define DIEPCTL_NAKSTS_Msk (0x1UL << DIEPCTL_NAKSTS_Pos) // 0x00020000 -#define DIEPCTL_NAKSTS DIEPCTL_NAKSTS_Msk // NAK status - -#define DIEPCTL_EPTYP_Pos (18U) -#define DIEPCTL_EPTYP_Msk (0x3UL << DIEPCTL_EPTYP_Pos) // 0x000C0000 -#define DIEPCTL_EPTYP DIEPCTL_EPTYP_Msk // Endpoint type -#define DIEPCTL_EPTYP_0 (0x1UL << DIEPCTL_EPTYP_Pos) // 0x00040000 -#define DIEPCTL_EPTYP_1 (0x2UL << DIEPCTL_EPTYP_Pos) // 0x00080000 -#define DIEPCTL_STALL_Pos (21U) -#define DIEPCTL_STALL_Msk (0x1UL << DIEPCTL_STALL_Pos) // 0x00200000 -#define DIEPCTL_STALL DIEPCTL_STALL_Msk // STALL handshake - -#define DIEPCTL_TXFNUM_Pos (22U) -#define DIEPCTL_TXFNUM_Msk (0xFUL << DIEPCTL_TXFNUM_Pos) // 0x03C00000 -#define DIEPCTL_TXFNUM DIEPCTL_TXFNUM_Msk // TxFIFO number -#define DIEPCTL_TXFNUM_0 (0x1UL << DIEPCTL_TXFNUM_Pos) // 0x00400000 -#define DIEPCTL_TXFNUM_1 (0x2UL << DIEPCTL_TXFNUM_Pos) // 0x00800000 -#define DIEPCTL_TXFNUM_2 (0x4UL << DIEPCTL_TXFNUM_Pos) // 0x01000000 -#define DIEPCTL_TXFNUM_3 (0x8UL << DIEPCTL_TXFNUM_Pos) // 0x02000000 -#define DIEPCTL_CNAK_Pos (26U) -#define DIEPCTL_CNAK_Msk (0x1UL << DIEPCTL_CNAK_Pos) // 0x04000000 -#define DIEPCTL_CNAK DIEPCTL_CNAK_Msk // Clear NAK -#define DIEPCTL_SNAK_Pos (27U) -#define DIEPCTL_SNAK_Msk (0x1UL << DIEPCTL_SNAK_Pos) // 0x08000000 -#define DIEPCTL_SNAK DIEPCTL_SNAK_Msk // Set NAK -#define DIEPCTL_SD0PID_SEVNFRM_Pos (28U) -#define DIEPCTL_SD0PID_SEVNFRM_Msk (0x1UL << DIEPCTL_SD0PID_SEVNFRM_Pos) // 0x10000000 -#define DIEPCTL_SD0PID_SEVNFRM DIEPCTL_SD0PID_SEVNFRM_Msk // Set DATA0 PID -#define DIEPCTL_SODDFRM_Pos (29U) -#define DIEPCTL_SODDFRM_Msk (0x1UL << DIEPCTL_SODDFRM_Pos) // 0x20000000 -#define DIEPCTL_SODDFRM DIEPCTL_SODDFRM_Msk // Set odd frame -#define DIEPCTL_EPDIS_Pos (30U) -#define DIEPCTL_EPDIS_Msk (0x1UL << DIEPCTL_EPDIS_Pos) // 0x40000000 -#define DIEPCTL_EPDIS DIEPCTL_EPDIS_Msk // Endpoint disable -#define DIEPCTL_EPENA_Pos (31U) -#define DIEPCTL_EPENA_Msk (0x1UL << DIEPCTL_EPENA_Pos) // 0x80000000 -#define DIEPCTL_EPENA DIEPCTL_EPENA_Msk // Endpoint enable - -/******************** Bit definition for HCCHAR register ********************/ -#define HCCHAR_MPSIZ_Pos (0U) -#define HCCHAR_MPSIZ_Msk (0x7FFUL << HCCHAR_MPSIZ_Pos) // 0x000007FF -#define HCCHAR_MPSIZ HCCHAR_MPSIZ_Msk // Maximum packet size - -#define HCCHAR_EPNUM_Pos (11U) -#define HCCHAR_EPNUM_Msk (0xFUL << HCCHAR_EPNUM_Pos) // 0x00007800 -#define HCCHAR_EPNUM HCCHAR_EPNUM_Msk // Endpoint number -#define HCCHAR_EPNUM_0 (0x1UL << HCCHAR_EPNUM_Pos) // 0x00000800 -#define HCCHAR_EPNUM_1 (0x2UL << HCCHAR_EPNUM_Pos) // 0x00001000 -#define HCCHAR_EPNUM_2 (0x4UL << HCCHAR_EPNUM_Pos) // 0x00002000 -#define HCCHAR_EPNUM_3 (0x8UL << HCCHAR_EPNUM_Pos) // 0x00004000 -#define HCCHAR_EPDIR_Pos (15U) -#define HCCHAR_EPDIR_Msk (0x1UL << HCCHAR_EPDIR_Pos) // 0x00008000 -#define HCCHAR_EPDIR HCCHAR_EPDIR_Msk // Endpoint direction -#define HCCHAR_LSDEV_Pos (17U) -#define HCCHAR_LSDEV_Msk (0x1UL << HCCHAR_LSDEV_Pos) // 0x00020000 -#define HCCHAR_LSDEV HCCHAR_LSDEV_Msk // Low-speed device - -#define HCCHAR_EPTYP_Pos (18U) -#define HCCHAR_EPTYP_Msk (0x3UL << HCCHAR_EPTYP_Pos) // 0x000C0000 -#define HCCHAR_EPTYP HCCHAR_EPTYP_Msk // Endpoint type -#define HCCHAR_EPTYP_0 (0x1UL << HCCHAR_EPTYP_Pos) // 0x00040000 -#define HCCHAR_EPTYP_1 (0x2UL << HCCHAR_EPTYP_Pos) // 0x00080000 - -#define HCCHAR_MC_Pos (20U) -#define HCCHAR_MC_Msk (0x3UL << HCCHAR_MC_Pos) // 0x00300000 -#define HCCHAR_MC HCCHAR_MC_Msk // Multi Count (MC) / Error Count (EC) -#define HCCHAR_MC_0 (0x1UL << HCCHAR_MC_Pos) // 0x00100000 -#define HCCHAR_MC_1 (0x2UL << HCCHAR_MC_Pos) // 0x00200000 - -#define HCCHAR_DAD_Pos (22U) -#define HCCHAR_DAD_Msk (0x7FUL << HCCHAR_DAD_Pos) // 0x1FC00000 -#define HCCHAR_DAD HCCHAR_DAD_Msk // Device address -#define HCCHAR_DAD_0 (0x01UL << HCCHAR_DAD_Pos) // 0x00400000 -#define HCCHAR_DAD_1 (0x02UL << HCCHAR_DAD_Pos) // 0x00800000 -#define HCCHAR_DAD_2 (0x04UL << HCCHAR_DAD_Pos) // 0x01000000 -#define HCCHAR_DAD_3 (0x08UL << HCCHAR_DAD_Pos) // 0x02000000 -#define HCCHAR_DAD_4 (0x10UL << HCCHAR_DAD_Pos) // 0x04000000 -#define HCCHAR_DAD_5 (0x20UL << HCCHAR_DAD_Pos) // 0x08000000 -#define HCCHAR_DAD_6 (0x40UL << HCCHAR_DAD_Pos) // 0x10000000 -#define HCCHAR_ODDFRM_Pos (29U) -#define HCCHAR_ODDFRM_Msk (0x1UL << HCCHAR_ODDFRM_Pos) // 0x20000000 -#define HCCHAR_ODDFRM HCCHAR_ODDFRM_Msk // Odd frame -#define HCCHAR_CHDIS_Pos (30U) -#define HCCHAR_CHDIS_Msk (0x1UL << HCCHAR_CHDIS_Pos) // 0x40000000 -#define HCCHAR_CHDIS HCCHAR_CHDIS_Msk // Channel disable -#define HCCHAR_CHENA_Pos (31U) -#define HCCHAR_CHENA_Msk (0x1UL << HCCHAR_CHENA_Pos) // 0x80000000 -#define HCCHAR_CHENA HCCHAR_CHENA_Msk // Channel enable - -/******************** Bit definition for HCSPLT register ********************/ - -#define HCSPLT_PRTADDR_Pos (0U) -#define HCSPLT_PRTADDR_Msk (0x7FUL << HCSPLT_PRTADDR_Pos) // 0x0000007F -#define HCSPLT_PRTADDR HCSPLT_PRTADDR_Msk // Port address -#define HCSPLT_PRTADDR_0 (0x01UL << HCSPLT_PRTADDR_Pos) // 0x00000001 -#define HCSPLT_PRTADDR_1 (0x02UL << HCSPLT_PRTADDR_Pos) // 0x00000002 -#define HCSPLT_PRTADDR_2 (0x04UL << HCSPLT_PRTADDR_Pos) // 0x00000004 -#define HCSPLT_PRTADDR_3 (0x08UL << HCSPLT_PRTADDR_Pos) // 0x00000008 -#define HCSPLT_PRTADDR_4 (0x10UL << HCSPLT_PRTADDR_Pos) // 0x00000010 -#define HCSPLT_PRTADDR_5 (0x20UL << HCSPLT_PRTADDR_Pos) // 0x00000020 -#define HCSPLT_PRTADDR_6 (0x40UL << HCSPLT_PRTADDR_Pos) // 0x00000040 - -#define HCSPLT_HUBADDR_Pos (7U) -#define HCSPLT_HUBADDR_Msk (0x7FUL << HCSPLT_HUBADDR_Pos) // 0x00003F80 -#define HCSPLT_HUBADDR HCSPLT_HUBADDR_Msk // Hub address -#define HCSPLT_HUBADDR_0 (0x01UL << HCSPLT_HUBADDR_Pos) // 0x00000080 -#define HCSPLT_HUBADDR_1 (0x02UL << HCSPLT_HUBADDR_Pos) // 0x00000100 -#define HCSPLT_HUBADDR_2 (0x04UL << HCSPLT_HUBADDR_Pos) // 0x00000200 -#define HCSPLT_HUBADDR_3 (0x08UL << HCSPLT_HUBADDR_Pos) // 0x00000400 -#define HCSPLT_HUBADDR_4 (0x10UL << HCSPLT_HUBADDR_Pos) // 0x00000800 -#define HCSPLT_HUBADDR_5 (0x20UL << HCSPLT_HUBADDR_Pos) // 0x00001000 -#define HCSPLT_HUBADDR_6 (0x40UL << HCSPLT_HUBADDR_Pos) // 0x00002000 - -#define HCSPLT_XACTPOS_Pos (14U) -#define HCSPLT_XACTPOS_Msk (0x3UL << HCSPLT_XACTPOS_Pos) // 0x0000C000 -#define HCSPLT_XACTPOS HCSPLT_XACTPOS_Msk // XACTPOS -#define HCSPLT_XACTPOS_0 (0x1UL << HCSPLT_XACTPOS_Pos) // 0x00004000 -#define HCSPLT_XACTPOS_1 (0x2UL << HCSPLT_XACTPOS_Pos) // 0x00008000 -#define HCSPLT_COMPLSPLT_Pos (16U) -#define HCSPLT_COMPLSPLT_Msk (0x1UL << HCSPLT_COMPLSPLT_Pos) // 0x00010000 -#define HCSPLT_COMPLSPLT HCSPLT_COMPLSPLT_Msk // Do complete split -#define HCSPLT_SPLITEN_Pos (31U) -#define HCSPLT_SPLITEN_Msk (0x1UL << HCSPLT_SPLITEN_Pos) // 0x80000000 -#define HCSPLT_SPLITEN HCSPLT_SPLITEN_Msk // Split enable - -/******************** Bit definition for HCINT register ********************/ -#define HCINT_XFER_COMPLETE_Pos (0U) -#define HCINT_XFER_COMPLETE_Msk (0x1UL << HCINT_XFER_COMPLETE_Pos) // 0x00000001 -#define HCINT_XFER_COMPLETE HCINT_XFER_COMPLETE_Msk // Transfer completed -#define HCINT_HALTED_Pos (1U) -#define HCINT_HALTED_Msk (0x1UL << HCINT_HALTED_Pos) // 0x00000002 -#define HCINT_HALTED HCINT_HALTED_Msk // Channel halted -#define HCINT_AHB_ERR_Pos (2U) -#define HCINT_AHB_ERR_Msk (0x1UL << HCINT_AHB_ERR_Pos) // 0x00000004 -#define HCINT_AHB_ERR HCINT_AHB_ERR_Msk // AHB error -#define HCINT_STALL_Pos (3U) -#define HCINT_STALL_Msk (0x1UL << HCINT_STALL_Pos) // 0x00000008 -#define HCINT_STALL HCINT_STALL_Msk // STALL response received interrupt -#define HCINT_NAK_Pos (4U) -#define HCINT_NAK_Msk (0x1UL << HCINT_NAK_Pos) // 0x00000010 -#define HCINT_NAK HCINT_NAK_Msk // NAK response received interrupt -#define HCINT_ACK_Pos (5U) -#define HCINT_ACK_Msk (0x1UL << HCINT_ACK_Pos) // 0x00000020 -#define HCINT_ACK HCINT_ACK_Msk // ACK response received/transmitted interrupt -#define HCINT_NYET_Pos (6U) -#define HCINT_NYET_Msk (0x1UL << HCINT_NYET_Pos) // 0x00000040 -#define HCINT_NYET HCINT_NYET_Msk // Response received interrupt -#define HCINT_XACT_ERR_Pos (7U) -#define HCINT_XACT_ERR_Msk (0x1UL << HCINT_XACT_ERR_Pos) // 0x00000080 -#define HCINT_XACT_ERR HCINT_XACT_ERR_Msk // Transaction error -#define HCINT_BABBLE_ERR_Pos (8U) -#define HCINT_BABBLE_ERR_Msk (0x1UL << HCINT_BABBLE_ERR_Pos) // 0x00000100 -#define HCINT_BABBLE_ERR HCINT_BABBLE_ERR_Msk // Babble error -#define HCINT_FARME_OVERRUN_Pos (9U) -#define HCINT_FARME_OVERRUN_Msk (0x1UL << HCINT_FARME_OVERRUN_Pos) // 0x00000200 -#define HCINT_FARME_OVERRUN HCINT_FARME_OVERRUN_Msk // Frame overrun -#define HCINT_DATATOGGLE_ERR_Pos (10U) -#define HCINT_DATATOGGLE_ERR_Msk (0x1UL << HCINT_DATATOGGLE_ERR_Pos) // 0x00000400 -#define HCINT_DATATOGGLE_ERR HCINT_DATATOGGLE_ERR_Msk // Data toggle error -#define HCINT_BUFFER_NA_Pos (11U) -#define HCINT_BUFFER_NA_Msk (0x1UL << HCINT_BUFFER_NA_Pos) // 0x00000800 -#define HCINT_BUFFER_NA HCINT_BUFFER_NA_Msk // Buffer not available interrupt -#define HCINT_XCS_XACT_ERR_Pos (12U) -#define HCINT_XCS_XACT_ERR_Msk (0x1UL << HCINT_XCS_XACT_ERR_Pos) // 0x00001000 -#define HCINT_XCS_XACT_ERR HCINT_XCS_XACT_ERR_Msk // Excessive transaction error -#define HCINT_DESC_ROLLOVER_Pos (13U) -#define HCINT_DESC_ROLLOVER_Msk (0x1UL << HCINT_DESC_ROLLOVER_Pos) // 0x00002000 -#define HCINT_DESC_ROLLOVER HCINT_DESC_ROLLOVER_Msk // Descriptor rollover - -/******************** Bit definition for DIEPINT register ********************/ -#define DIEPINT_XFRC_Pos (0U) -#define DIEPINT_XFRC_Msk (0x1UL << DIEPINT_XFRC_Pos) // 0x00000001 -#define DIEPINT_XFRC DIEPINT_XFRC_Msk // Transfer completed interrupt -#define DIEPINT_EPDISD_Pos (1U) -#define DIEPINT_EPDISD_Msk (0x1UL << DIEPINT_EPDISD_Pos) // 0x00000002 -#define DIEPINT_EPDISD DIEPINT_EPDISD_Msk // Endpoint disabled interrupt -#define DIEPINT_AHBERR_Pos (2U) -#define DIEPINT_AHBERR_Msk (0x1UL << DIEPINT_AHBERR_Pos) // 0x00000004 -#define DIEPINT_AHBERR DIEPINT_AHBERR_Msk // AHB Error (AHBErr) during an IN transaction -#define DIEPINT_TOC_Pos (3U) -#define DIEPINT_TOC_Msk (0x1UL << DIEPINT_TOC_Pos) // 0x00000008 -#define DIEPINT_TOC DIEPINT_TOC_Msk // Timeout condition -#define DIEPINT_ITTXFE_Pos (4U) -#define DIEPINT_ITTXFE_Msk (0x1UL << DIEPINT_ITTXFE_Pos) // 0x00000010 -#define DIEPINT_ITTXFE DIEPINT_ITTXFE_Msk // IN token received when TxFIFO is empty -#define DIEPINT_INEPNM_Pos (5U) -#define DIEPINT_INEPNM_Msk (0x1UL << DIEPINT_INEPNM_Pos) // 0x00000020 -#define DIEPINT_INEPNM DIEPINT_INEPNM_Msk // IN token received with EP mismatch -#define DIEPINT_INEPNE_Pos (6U) -#define DIEPINT_INEPNE_Msk (0x1UL << DIEPINT_INEPNE_Pos) // 0x00000040 -#define DIEPINT_INEPNE DIEPINT_INEPNE_Msk // IN endpoint NAK effective -#define DIEPINT_TXFE_Pos (7U) -#define DIEPINT_TXFE_Msk (0x1UL << DIEPINT_TXFE_Pos) // 0x00000080 -#define DIEPINT_TXFE DIEPINT_TXFE_Msk // Transmit FIFO empty -#define DIEPINT_TXFIFOUDRN_Pos (8U) -#define DIEPINT_TXFIFOUDRN_Msk (0x1UL << DIEPINT_TXFIFOUDRN_Pos) // 0x00000100 -#define DIEPINT_TXFIFOUDRN DIEPINT_TXFIFOUDRN_Msk // Transmit Fifo Underrun -#define DIEPINT_BNA_Pos (9U) -#define DIEPINT_BNA_Msk (0x1UL << DIEPINT_BNA_Pos) // 0x00000200 -#define DIEPINT_BNA DIEPINT_BNA_Msk // Buffer not available interrupt -#define DIEPINT_PKTDRPSTS_Pos (11U) -#define DIEPINT_PKTDRPSTS_Msk (0x1UL << DIEPINT_PKTDRPSTS_Pos) // 0x00000800 -#define DIEPINT_PKTDRPSTS DIEPINT_PKTDRPSTS_Msk // Packet dropped status -#define DIEPINT_BERR_Pos (12U) -#define DIEPINT_BERR_Msk (0x1UL << DIEPINT_BERR_Pos) // 0x00001000 -#define DIEPINT_BERR DIEPINT_BERR_Msk // Babble error interrupt -#define DIEPINT_NAK_Pos (13U) -#define DIEPINT_NAK_Msk (0x1UL << DIEPINT_NAK_Pos) // 0x00002000 -#define DIEPINT_NAK DIEPINT_NAK_Msk // NAK interrupt - -/******************** Bit definition for DIEPTSIZ register ********************/ - -#define DIEPTSIZ_XFRSIZ_Pos (0U) -#define DIEPTSIZ_XFRSIZ_Msk (0x7FFFFUL << DIEPTSIZ_XFRSIZ_Pos) // 0x0007FFFF -#define DIEPTSIZ_XFRSIZ DIEPTSIZ_XFRSIZ_Msk // Transfer size -#define DIEPTSIZ_PKTCNT_Pos (19U) -#define DIEPTSIZ_PKTCNT_Msk (0x3FFUL << DIEPTSIZ_PKTCNT_Pos) // 0x1FF80000 -#define DIEPTSIZ_PKTCNT DIEPTSIZ_PKTCNT_Msk // Packet count -#define DIEPTSIZ_MULCNT_Pos (29U) -#define DIEPTSIZ_MULCNT_Msk (0x3UL << DIEPTSIZ_MULCNT_Pos) // 0x60000000 -#define DIEPTSIZ_MULCNT DIEPTSIZ_MULCNT_Msk // Packet count - /******************** Bit definition for HCTSIZ register ********************/ -#define HCTSIZ_XFRSIZ_Pos (0U) -#define HCTSIZ_XFRSIZ_Msk (0x7FFFFUL << HCTSIZ_XFRSIZ_Pos) // 0x0007FFFF -#define HCTSIZ_XFRSIZ HCTSIZ_XFRSIZ_Msk // Transfer size -#define HCTSIZ_PKTCNT_Pos (19U) -#define HCTSIZ_PKTCNT_Msk (0x3FFUL << HCTSIZ_PKTCNT_Pos) // 0x1FF80000 -#define HCTSIZ_PKTCNT HCTSIZ_PKTCNT_Msk // Packet count -#define HCTSIZ_DOPING_Pos (31U) -#define HCTSIZ_DOPING_Msk (0x1UL << HCTSIZ_DOPING_Pos) // 0x80000000 -#define HCTSIZ_DOPING HCTSIZ_DOPING_Msk // Do PING -#define HCTSIZ_PID_Pos (29U) -#define HCTSIZ_PID_Msk (0x3UL << HCTSIZ_PID_Pos) // 0x60000000 -#define HCTSIZ_PID HCTSIZ_PID_Msk // Data PID - -/******************** Bit definition for DIEPDMA register ********************/ -#define DIEPDMA_DMAADDR_Pos (0U) -#define DIEPDMA_DMAADDR_Msk (0xFFFFFFFFUL << DIEPDMA_DMAADDR_Pos) // 0xFFFFFFFF -#define DIEPDMA_DMAADDR DIEPDMA_DMAADDR_Msk // DMA address - -/******************** Bit definition for HCDMA register ********************/ -#define HCDMA_DMAADDR_Pos (0U) -#define HCDMA_DMAADDR_Msk (0xFFFFFFFFUL << HCDMA_DMAADDR_Pos) // 0xFFFFFFFF -#define HCDMA_DMAADDR HCDMA_DMAADDR_Msk // DMA address - - /******************** Bit definition for DTXFSTS register ********************/ -#define DTXFSTS_INEPTFSAV_Pos (0U) -#define DTXFSTS_INEPTFSAV_Msk (0xFFFFUL << DTXFSTS_INEPTFSAV_Pos) // 0x0000FFFF -#define DTXFSTS_INEPTFSAV DTXFSTS_INEPTFSAV_Msk // IN endpoint TxFIFO space available - - /******************** Bit definition for DIEPTXF register ********************/ -#define DIEPTXF_INEPTXSA_Pos (0U) -#define DIEPTXF_INEPTXSA_Msk (0xFFFFUL << DIEPTXF_INEPTXSA_Pos) // 0x0000FFFF -#define DIEPTXF_INEPTXSA DIEPTXF_INEPTXSA_Msk // IN endpoint FIFOx transmit RAM start address -#define DIEPTXF_INEPTXFD_Pos (16U) -#define DIEPTXF_INEPTXFD_Msk (0xFFFFUL << DIEPTXF_INEPTXFD_Pos) // 0xFFFF0000 -#define DIEPTXF_INEPTXFD DIEPTXF_INEPTXFD_Msk // IN endpoint TxFIFO depth - - -/******************** Bit definition for Common EPCTL register ********************/ -#define EPCTL_MPSIZ_Pos (0U) -#define EPCTL_MPSIZ_Msk (0x7FFUL << EPCTL_MPSIZ_Pos) // 0x000007FF -#define EPCTL_MPSIZ EPCTL_MPSIZ_Msk // Maximum packet size //Bit 1 -#define EPCTL_USBAEP_Pos (15U) -#define EPCTL_USBAEP_Msk (0x1UL << EPCTL_USBAEP_Pos) // 0x00008000 -#define EPCTL_USBAEP EPCTL_USBAEP_Msk // USB active endpoint -#define EPCTL_NAKSTS_Pos (17U) -#define EPCTL_NAKSTS_Msk (0x1UL << EPCTL_NAKSTS_Pos) // 0x00020000 -#define EPCTL_NAKSTS EPCTL_NAKSTS_Msk // NAK status -#define EPCTL_EPTYP_Pos (18U) -#define EPCTL_EPTYP_Msk (0x3UL << EPCTL_EPTYP_Pos) // 0x000C0000 -#define EPCTL_EPTYP EPCTL_EPTYP_Msk // Endpoint type -#define EPCTL_EPTYP_0 (0x1UL << EPCTL_EPTYP_Pos) // 0x00040000 -#define EPCTL_EPTYP_1 (0x2UL << EPCTL_EPTYP_Pos) // 0x00080000 -#define EPCTL_SNPM EPCTL_SNPM_Msk // Snoop mode -#define EPCTL_STALL_Pos (21U) -#define EPCTL_STALL_Msk (0x1UL << EPCTL_STALL_Pos) // 0x00200000 -#define EPCTL_STALL EPCTL_STALL_Msk // STALL handshake -#define EPCTL_CNAK_Pos (26U) -#define EPCTL_CNAK_Msk (0x1UL << EPCTL_CNAK_Pos) // 0x04000000 -#define EPCTL_CNAK EPCTL_CNAK_Msk // Clear NAK -#define EPCTL_SNAK_Pos (27U) -#define EPCTL_SNAK_Msk (0x1UL << EPCTL_SNAK_Pos) // 0x08000000 -#define EPCTL_SNAK EPCTL_SNAK_Msk // Set NAK -#define EPCTL_SD0PID_SEVNFRM_Pos (28U) -#define EPCTL_SD0PID_SEVNFRM_Msk (0x1UL << EPCTL_SD0PID_SEVNFRM_Pos) // 0x10000000 -#define EPCTL_SD0PID_SEVNFRM EPCTL_SD0PID_SEVNFRM_Msk // Set DATA0 PID -#define EPCTL_SODDFRM_Pos (29U) -#define EPCTL_SODDFRM_Msk (0x1UL << EPCTL_SODDFRM_Pos) // 0x20000000 -#define EPCTL_SODDFRM EPCTL_SODDFRM_Msk // Set odd frame -#define EPCTL_EPDIS_Pos (30U) -#define EPCTL_EPDIS_Msk (0x1UL << EPCTL_EPDIS_Pos) // 0x40000000 -#define EPCTL_EPDIS EPCTL_EPDIS_Msk // Endpoint disable -#define EPCTL_EPENA_Pos (31U) -#define EPCTL_EPENA_Msk (0x1UL << EPCTL_EPENA_Pos) // 0x80000000 -#define EPCTL_EPENA EPCTL_EPENA_Msk // Endpoint enable - -/******************** Bit definition for DOEPCTL register ********************/ -#define DOEPCTL_MPSIZ_Pos (0U) -#define DOEPCTL_MPSIZ_Msk (0x7FFUL << DOEPCTL_MPSIZ_Pos) // 0x000007FF -#define DOEPCTL_MPSIZ DOEPCTL_MPSIZ_Msk // Maximum packet size //Bit 1 -#define DOEPCTL_USBAEP_Pos (15U) -#define DOEPCTL_USBAEP_Msk (0x1UL << DOEPCTL_USBAEP_Pos) // 0x00008000 -#define DOEPCTL_USBAEP DOEPCTL_USBAEP_Msk // USB active endpoint -#define DOEPCTL_NAKSTS_Pos (17U) -#define DOEPCTL_NAKSTS_Msk (0x1UL << DOEPCTL_NAKSTS_Pos) // 0x00020000 -#define DOEPCTL_NAKSTS DOEPCTL_NAKSTS_Msk // NAK status -#define DOEPCTL_SD0PID_SEVNFRM_Pos (28U) -#define DOEPCTL_SD0PID_SEVNFRM_Msk (0x1UL << DOEPCTL_SD0PID_SEVNFRM_Pos) // 0x10000000 -#define DOEPCTL_SD0PID_SEVNFRM DOEPCTL_SD0PID_SEVNFRM_Msk // Set DATA0 PID -#define DOEPCTL_SODDFRM_Pos (29U) -#define DOEPCTL_SODDFRM_Msk (0x1UL << DOEPCTL_SODDFRM_Pos) // 0x20000000 -#define DOEPCTL_SODDFRM DOEPCTL_SODDFRM_Msk // Set odd frame -#define DOEPCTL_EPTYP_Pos (18U) -#define DOEPCTL_EPTYP_Msk (0x3UL << DOEPCTL_EPTYP_Pos) // 0x000C0000 -#define DOEPCTL_EPTYP DOEPCTL_EPTYP_Msk // Endpoint type -#define DOEPCTL_EPTYP_0 (0x1UL << DOEPCTL_EPTYP_Pos) // 0x00040000 -#define DOEPCTL_EPTYP_1 (0x2UL << DOEPCTL_EPTYP_Pos) // 0x00080000 -#define DOEPCTL_SNPM_Pos (20U) -#define DOEPCTL_SNPM_Msk (0x1UL << DOEPCTL_SNPM_Pos) // 0x00100000 -#define DOEPCTL_SNPM DOEPCTL_SNPM_Msk // Snoop mode -#define DOEPCTL_STALL_Pos (21U) -#define DOEPCTL_STALL_Msk (0x1UL << DOEPCTL_STALL_Pos) // 0x00200000 -#define DOEPCTL_STALL DOEPCTL_STALL_Msk // STALL handshake -#define DOEPCTL_CNAK_Pos (26U) -#define DOEPCTL_CNAK_Msk (0x1UL << DOEPCTL_CNAK_Pos) // 0x04000000 -#define DOEPCTL_CNAK DOEPCTL_CNAK_Msk // Clear NAK -#define DOEPCTL_SNAK_Pos (27U) -#define DOEPCTL_SNAK_Msk (0x1UL << DOEPCTL_SNAK_Pos) // 0x08000000 -#define DOEPCTL_SNAK DOEPCTL_SNAK_Msk // Set NAK -#define DOEPCTL_EPDIS_Pos (30U) -#define DOEPCTL_EPDIS_Msk (0x1UL << DOEPCTL_EPDIS_Pos) // 0x40000000 -#define DOEPCTL_EPDIS DOEPCTL_EPDIS_Msk // Endpoint disable -#define DOEPCTL_EPENA_Pos (31U) -#define DOEPCTL_EPENA_Msk (0x1UL << DOEPCTL_EPENA_Pos) // 0x80000000 -#define DOEPCTL_EPENA DOEPCTL_EPENA_Msk // Endpoint enable - -/******************** Bit definition for DOEPINT register ********************/ -#define DOEPINT_XFRC_Pos (0U) -#define DOEPINT_XFRC_Msk (0x1UL << DOEPINT_XFRC_Pos) // 0x00000001 -#define DOEPINT_XFRC DOEPINT_XFRC_Msk // Transfer completed interrupt -#define DOEPINT_EPDISD_Pos (1U) -#define DOEPINT_EPDISD_Msk (0x1UL << DOEPINT_EPDISD_Pos) // 0x00000002 -#define DOEPINT_EPDISD DOEPINT_EPDISD_Msk // Endpoint disabled interrupt -#define DOEPINT_AHBERR_Pos (2U) -#define DOEPINT_AHBERR_Msk (0x1UL << DOEPINT_AHBERR_Pos) // 0x00000004 -#define DOEPINT_AHBERR DOEPINT_AHBERR_Msk // AHB Error (AHBErr) during an OUT transaction - -#define DOEPINT_SETUP_Pos (3U) -#define DOEPINT_SETUP_Msk (0x1UL << DOEPINT_SETUP_Pos) // 0x00000008 -#define DOEPINT_SETUP DOEPINT_SETUP_Msk // SETUP phase done - -#define DOEPINT_OTEPDIS_Pos (4U) -#define DOEPINT_OTEPDIS_Msk (0x1UL << DOEPINT_OTEPDIS_Pos) // 0x00000010 -#define DOEPINT_OTEPDIS DOEPINT_OTEPDIS_Msk // OUT token received when endpoint disabled - -#define DOEPINT_STSPHSRX_Pos (5U) -#define DOEPINT_STSPHSRX_Msk (0x1UL << DOEPINT_STSPHSRX_Pos) // 0x00000020 -#define DOEPINT_STSPHSRX DOEPINT_STSPHSRX_Msk // Status Phase Received For Control Write - -#define DOEPINT_B2BSTUP_Pos (6U) -#define DOEPINT_B2BSTUP_Msk (0x1UL << DOEPINT_B2BSTUP_Pos) // 0x00000040 -#define DOEPINT_B2BSTUP DOEPINT_B2BSTUP_Msk // Back-to-back SETUP packets received -#define DOEPINT_OUTPKTERR_Pos (8U) -#define DOEPINT_OUTPKTERR_Msk (0x1UL << DOEPINT_OUTPKTERR_Pos) // 0x00000100 -#define DOEPINT_OUTPKTERR DOEPINT_OUTPKTERR_Msk // OUT packet error -#define DOEPINT_NAK_Pos (13U) -#define DOEPINT_NAK_Msk (0x1UL << DOEPINT_NAK_Pos) // 0x00002000 -#define DOEPINT_NAK DOEPINT_NAK_Msk // NAK Packet is transmitted by the device -#define DOEPINT_NYET_Pos (14U) -#define DOEPINT_NYET_Msk (0x1UL << DOEPINT_NYET_Pos) // 0x00004000 -#define DOEPINT_NYET DOEPINT_NYET_Msk // NYET interrupt - -#define DOEPINT_STPKTRX_Pos (15U) -#define DOEPINT_STPKTRX_Msk (0x1UL << DOEPINT_STPKTRX_Pos) // 0x00008000 -#define DOEPINT_STPKTRX DOEPINT_STPKTRX_Msk // Setup Packet Received - -/******************** Bit definition for DOEPTSIZ register ********************/ -#define DOEPTSIZ_XFRSIZ_Pos (0U) -#define DOEPTSIZ_XFRSIZ_Msk (0x7FFFFUL << DOEPTSIZ_XFRSIZ_Pos) // 0x0007FFFF -#define DOEPTSIZ_XFRSIZ DOEPTSIZ_XFRSIZ_Msk // Transfer size -#define DOEPTSIZ_PKTCNT_Pos (19U) -#define DOEPTSIZ_PKTCNT_Msk (0x3FFUL << DOEPTSIZ_PKTCNT_Pos) // 0x1FF80000 -#define DOEPTSIZ_PKTCNT DOEPTSIZ_PKTCNT_Msk // Packet count - -#define DOEPTSIZ_STUPCNT_Pos (29U) -#define DOEPTSIZ_STUPCNT_Msk (0x3UL << DOEPTSIZ_STUPCNT_Pos) // 0x60000000 -#define DOEPTSIZ_STUPCNT DOEPTSIZ_STUPCNT_Msk // SETUP packet count -#define DOEPTSIZ_STUPCNT_0 (0x1UL << DOEPTSIZ_STUPCNT_Pos) // 0x20000000 -#define DOEPTSIZ_STUPCNT_1 (0x2UL << DOEPTSIZ_STUPCNT_Pos) // 0x40000000 - -/******************** Bit definition for PCGCTL register ********************/ -#define PCGCCTL_IF_DEV_MODE TU_BIT(31) -#define PCGCCTL_P2HD_PRT_SPD_MASK (0x3ul << 29) -#define PCGCCTL_P2HD_PRT_SPD_SHIFT 29 -#define PCGCCTL_P2HD_DEV_ENUM_SPD_MASK (0x3ul << 27) -#define PCGCCTL_P2HD_DEV_ENUM_SPD_SHIFT 27 -#define PCGCCTL_MAC_DEV_ADDR_MASK (0x7ful << 20) -#define PCGCCTL_MAC_DEV_ADDR_SHIFT 20 -#define PCGCCTL_MAX_TERMSEL TU_BIT(19) -#define PCGCCTL_MAX_XCVRSELECT_MASK (0x3ul << 17) -#define PCGCCTL_MAX_XCVRSELECT_SHIFT 17 -#define PCGCCTL_PORT_POWER TU_BIT(16) -#define PCGCCTL_PRT_CLK_SEL_MASK (0x3ul << 14) -#define PCGCCTL_PRT_CLK_SEL_SHIFT 14 -#define PCGCCTL_ESS_REG_RESTORED TU_BIT(13) -#define PCGCCTL_EXTND_HIBER_SWITCH TU_BIT(12) -#define PCGCCTL_EXTND_HIBER_PWRCLMP TU_BIT(11) -#define PCGCCTL_ENBL_EXTND_HIBER TU_BIT(10) -#define PCGCCTL_RESTOREMODE TU_BIT(9) -#define PCGCCTL_RESETAFTSUSP TU_BIT(8) -#define PCGCCTL_DEEP_SLEEP TU_BIT(7) -#define PCGCCTL_PHY_IN_SLEEP TU_BIT(6) -#define PCGCCTL_ENBL_SLEEP_GATING TU_BIT(5) -#define PCGCCTL_RSTPDWNMODULE TU_BIT(3) -#define PCGCCTL_PWRCLMP TU_BIT(2) -#define PCGCCTL_GATEHCLK TU_BIT(1) -#define PCGCCTL_STOPPCLK TU_BIT(0) - -#define PCGCTL1_TIMER (0x3ul << 1) -#define PCGCTL1_GATEEN TU_BIT(0) - -#ifdef __cplusplus - } -#endif - -#endif diff --git a/src/portable/socfpga/dwc2/hcd_dwc2.c b/src/portable/socfpga/dwc2/hcd_dwc2.c deleted file mode 100644 index 3ec48d5fa..000000000 --- a/src/portable/socfpga/dwc2/hcd_dwc2.c +++ /dev/null @@ -1,1512 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2024 Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#include "tusb_option.h" - -#if CFG_TUH_ENABLED && defined(TUP_USBIP_DWC2) && !CFG_TUH_MAX3421 - -#if !(CFG_TUH_DWC2_SLAVE_ENABLE || CFG_TUH_DWC2_DMA_ENABLE) -#error DWC2 require either CFG_TUH_DWC2_SLAVE_ENABLE or CFG_TUH_DWC2_DMA_ENABLE to be enabled -#endif - -// Debug level for DWC2 -#define DWC2_DEBUG 2 - -#include "socfpga_rst_mngr.h" -#include "host/hcd.h" -#include "host/usbh.h" -#include "dwc2_common.h" - -// Max number of endpoints application can open, can be larger than DWC2_CHANNEL_COUNT_MAX -#ifndef CFG_TUH_DWC2_ENDPOINT_MAX -#define CFG_TUH_DWC2_ENDPOINT_MAX 16 -#endif - -#define DWC2_CHANNEL_COUNT_MAX 16 // absolute max channel count -TU_VERIFY_STATIC(CFG_TUH_DWC2_ENDPOINT_MAX <= 255, "currently only use 8-bit for index"); - -enum { - HPRT_W1_MASK = HPRT_CONN_DETECT | HPRT_ENABLE | HPRT_ENABLE_CHANGE | HPRT_OVER_CURRENT_CHANGE | HPRT_SUSPEND -}; - -enum { - HCD_XFER_ERROR_MAX = 3 -}; - -enum { - HCD_XFER_PERIOD_SPLIT_NYET_MAX = 3 -}; - -//-------------------------------------------------------------------- -// -//-------------------------------------------------------------------- - -// Host driver struct for each opened endpoint -typedef struct { - union { - uint32_t hcchar; - dwc2_channel_char_t hcchar_bm; - }; - union { - uint32_t hcsplt; - dwc2_channel_split_t hcsplt_bm; - }; - - struct TU_ATTR_PACKED { - uint32_t uframe_interval : 18; // micro-frame interval - uint32_t speed : 2; - uint32_t next_pid : 2; // PID for next transfer - uint32_t next_do_ping : 1; // Do PING for next transfer if possible (highspeed OUT) - // uint32_t : 9; - }; - - uint32_t uframe_countdown; // micro-frame count down to transfer for periodic, only need 18-bit - - uint8_t* buffer; - uint32_t buflen; -} hcd_endpoint_t; - -// Additional info for each channel when it is active -typedef struct { - volatile bool allocated; - uint8_t ep_id; - struct TU_ATTR_PACKED { - uint8_t err_count : 3; - uint8_t period_split_nyet_count : 3; - uint8_t halted_nyet : 1; - }; - uint8_t result; - - uint32_t xferred_bytes; // bytes that accumulate transferred though USB bus for the whole hcd_edpt_xfer(), which can - // be composed of multiple channel_xfer_start() (retry with NAK/NYET) - uint16_t fifo_bytes; // bytes written/read from/to FIFO (may not be transferred on USB bus). -} hcd_xfer_t; - -typedef struct { - hcd_xfer_t xfer[DWC2_CHANNEL_COUNT_MAX]; - hcd_endpoint_t edpt[CFG_TUH_DWC2_ENDPOINT_MAX]; -} hcd_data_t; - -hcd_data_t _hcd_data; - -//-------------------------------------------------------------------- -// -//-------------------------------------------------------------------- -TU_ATTR_ALWAYS_INLINE static inline uint8_t dwc2_channel_count(const dwc2_regs_t* dwc2) { - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - return tu_min8(ghwcfg2.num_host_ch + 1, DWC2_CHANNEL_COUNT_MAX); -} - -TU_ATTR_ALWAYS_INLINE static inline tusb_speed_t hprt_speed_get(dwc2_regs_t* dwc2) { - tusb_speed_t speed; - const dwc2_hprt_t hprt = {.value = dwc2->hprt}; - switch(hprt.speed) { - case HPRT_SPEED_HIGH: speed = TUSB_SPEED_HIGH; break; - case HPRT_SPEED_FULL: speed = TUSB_SPEED_FULL; break; - case HPRT_SPEED_LOW : speed = TUSB_SPEED_LOW ; break; - default: - speed = TUSB_SPEED_INVALID; - TU_BREAKPOINT(); - break; - } - return speed; -} - -TU_ATTR_ALWAYS_INLINE static inline bool dma_host_enabled(const dwc2_regs_t* dwc2) { - (void) dwc2; - // Internal DMA only - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - return CFG_TUH_DWC2_DMA_ENABLE && ghwcfg2.arch == GHWCFG2_ARCH_INTERNAL_DMA; -} - -#if CFG_TUH_MEM_DCACHE_ENABLE -bool hcd_dcache_clean(const void* addr, uint32_t data_size) { - TU_VERIFY(addr && data_size); - return dwc2_dcache_clean(addr, data_size); -} - -bool hcd_dcache_invalidate(const void* addr, uint32_t data_size) { - TU_VERIFY(addr && data_size); - return dwc2_dcache_invalidate(addr, data_size); -} - -bool hcd_dcache_clean_invalidate(const void* addr, uint32_t data_size) { - TU_VERIFY(addr && data_size); - return dwc2_dcache_clean_invalidate(addr, data_size); -} -#endif - -// Allocate a channel for new transfer -TU_ATTR_ALWAYS_INLINE static inline uint8_t channel_alloc(dwc2_regs_t* dwc2) { - const uint8_t max_channel = dwc2_channel_count(dwc2); - for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - if (!xfer->allocated) { - tu_memclr(xfer, sizeof(hcd_xfer_t)); - xfer->allocated = true; - return ch_id; - } - } - return TUSB_INDEX_INVALID_8; -} - -// Check if is periodic (interrupt/isochronous) -TU_ATTR_ALWAYS_INLINE static inline bool channel_is_periodic(uint32_t hcchar) { - const dwc2_channel_char_t hcchar_bm = {.value = hcchar}; - return hcchar_bm.ep_type == HCCHAR_EPTYPE_INTERRUPT || hcchar_bm.ep_type == HCCHAR_EPTYPE_ISOCHRONOUS; -} - -TU_ATTR_ALWAYS_INLINE static inline uint8_t req_queue_avail(const dwc2_regs_t* dwc2, bool is_period) { - if (is_period) { - const dwc2_hptxsts_t hptxsts = {.value = dwc2->hptxsts}; - return hptxsts.req_queue_available; - } else { - const dwc2_hnptxsts_t hnptxsts = {.value = dwc2->hnptxsts}; - return hnptxsts.req_queue_available; - } -} - -TU_ATTR_ALWAYS_INLINE static inline void channel_dealloc(dwc2_regs_t* dwc2, uint8_t ch_id) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - xfer->allocated = false; - dwc2->haintmsk &= ~TU_BIT(ch_id); -} - -TU_ATTR_ALWAYS_INLINE static inline bool channel_disable(const dwc2_regs_t* dwc2, dwc2_channel_t* channel) { - // disable also require request queue - TU_ASSERT(req_queue_avail(dwc2, channel_is_periodic(channel->hcchar))); - channel->hcintmsk |= HCINT_HALTED; - channel->hcchar |= HCCHAR_CHDIS | HCCHAR_CHENA; // must set both CHDIS and CHENA - return true; -} - -// attempt to send IN token to receive data -TU_ATTR_ALWAYS_INLINE static inline bool channel_send_in_token(const dwc2_regs_t* dwc2, dwc2_channel_t* channel) { - TU_ASSERT(req_queue_avail(dwc2, channel_is_periodic(channel->hcchar))); - channel->hcchar |= HCCHAR_CHENA; - return true; -} - -// Find currently enabled channel. Note: EP0 is bidirectional -TU_ATTR_ALWAYS_INLINE static inline uint8_t channel_find_enabled(dwc2_regs_t* dwc2, uint8_t dev_addr, uint8_t ep_num, uint8_t ep_dir) { - const uint8_t max_channel = dwc2_channel_count(dwc2); - for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { - if (_hcd_data.xfer[ch_id].allocated) { - const dwc2_channel_char_t hcchar = {.value = dwc2->channel[ch_id].hcchar}; - if (hcchar.dev_addr == dev_addr && hcchar.ep_num == ep_num && (ep_num == 0 || hcchar.ep_dir == ep_dir)) { - return ch_id; - } - } - } - return TUSB_INDEX_INVALID_8; -} - - -// Allocate a new endpoint -TU_ATTR_ALWAYS_INLINE static inline uint8_t edpt_alloc(void) { - for (uint32_t i = 0; i < CFG_TUH_DWC2_ENDPOINT_MAX; i++) { - hcd_endpoint_t* edpt = &_hcd_data.edpt[i]; - if (edpt->hcchar_bm.enable == 0) { - tu_memclr(edpt, sizeof(hcd_endpoint_t)); - edpt->hcchar_bm.enable = 1; - return i; - } - } - return TUSB_INDEX_INVALID_8; -} - -// Find a endpoint that is opened previously with hcd_edpt_open() -// Note: EP0 is bidirectional -TU_ATTR_ALWAYS_INLINE static inline uint8_t edpt_find_opened(uint8_t dev_addr, uint8_t ep_num, uint8_t ep_dir) { - for (uint8_t i = 0; i < (uint8_t)CFG_TUH_DWC2_ENDPOINT_MAX; i++) { - const dwc2_channel_char_t* hcchar_bm = &_hcd_data.edpt[i].hcchar_bm; - if (hcchar_bm->enable && hcchar_bm->dev_addr == dev_addr && - hcchar_bm->ep_num == ep_num && (ep_num == 0 || hcchar_bm->ep_dir == ep_dir)) { - return i; - } - } - return TUSB_INDEX_INVALID_8; -} - -TU_ATTR_ALWAYS_INLINE static inline uint16_t cal_packet_count(uint16_t len, uint16_t ep_size) { - if (len == 0) { - return 1; - } else { - return tu_div_ceil(len, ep_size); - } -} - -TU_ATTR_ALWAYS_INLINE static inline uint8_t cal_next_pid(uint8_t pid, uint8_t packet_count) { - if (packet_count & 0x01) { - return pid ^ 0x02; // toggle DATA0 and DATA1 - } else { - return pid; - } -} - -//-------------------------------------------------------------------- -// -//-------------------------------------------------------------------- - -/* USB Data FIFO Layout - - The FIFO is split up into - - EPInfo: for storing DMA metadata (check dcd_dwc2.c for more details) - - 1 RX FIFO: for receiving data - - 1 TX FIFO for non-periodic (NPTX) - - 1 TX FIFO for periodic (PTX) - - We allocated TX FIFO from top to bottom (using top pointer), this to allow the RX FIFO to grow dynamically which is - possible since the free space is located between the RX and TX FIFOs. - - ----------------- ep_fifo_size - | HCDMAn | - |--------------|-- gdfifocfg.EPINFOBASE (max is ghwcfg3.dfifo_depth) - | Non-Periodic | - | TX FIFO | - |--------------|--- GNPTXFSIZ.addr (fixed size) - | Periodic | - | TX FIFO | - |--------------|--- HPTXFSIZ.addr (expandable downward) - | FREE | - | | - |--------------|-- GRXFSIZ (expandable upward) - | RX FIFO | - ---------------- 0 -*/ - -/* Programming Guide 2.1.2 FIFO RAM allocation - * RX - * - Largest-EPsize/4 + 2 (status info). recommended x2 if high bandwidth or multiple ISO are used. - * - 2 for transfer complete and channel halted status - * - 1 for each Control/Bulk out endpoint to Handle NAK/NYET (i.e max is number of host channel) - * - * TX non-periodic (NPTX) - * - At least largest-EPsize/4, recommended x2 - * - * TX periodic (PTX) - * - At least largest-EPsize*MulCount/4 (MulCount up to 3 for high-bandwidth ISO/interrupt) -*/ -static void dfifo_host_init(uint8_t rhport) { - const dwc2_controller_t* dwc2_controller = &_dwc2_controller[rhport]; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const dwc2_ghwcfg2_t ghwcfg2 = {.value = dwc2->ghwcfg2}; - - // Scatter/Gather DMA mode is not yet supported. Buffer DMA only need 1 words per channel - const bool is_dma = dma_host_enabled(dwc2); - uint16_t dfifo_top = dwc2_controller->ep_fifo_size/4; - if (is_dma) { - dfifo_top -= ghwcfg2.num_host_ch; - } - - // fixed allocation for now, improve later: - // - ptx_largest is limited to 256 for FS since most FS core only has 1024 bytes total - bool is_highspeed = dwc2_core_is_highspeed(dwc2, TUSB_ROLE_HOST); - uint32_t nptx_largest = is_highspeed ? TUSB_EPSIZE_BULK_HS/4 : TUSB_EPSIZE_BULK_FS/4; - uint32_t ptx_largest = is_highspeed ? TUSB_EPSIZE_ISO_HS_MAX/4 : 256/4; - - uint16_t nptxfsiz = 2 * nptx_largest; - uint16_t rxfsiz = 2 * (ptx_largest + 2) + ghwcfg2.num_host_ch; - TU_ASSERT(dfifo_top >= (nptxfsiz + rxfsiz),); - uint16_t ptxfsiz = dfifo_top - (nptxfsiz + rxfsiz); - - dwc2->gdfifocfg = (dfifo_top << GDFIFOCFG_EPINFOBASE_SHIFT) | dfifo_top; - - dfifo_top -= rxfsiz; - dwc2->grxfsiz = rxfsiz; - - dfifo_top -= nptxfsiz; - dwc2->gnptxfsiz = tu_u32_from_u16(nptxfsiz, dfifo_top); - - dfifo_top -= ptxfsiz; - dwc2->hptxfsiz = tu_u32_from_u16(ptxfsiz, dfifo_top); -} - -//--------------------------------------------------------------------+ -// Controller API -//--------------------------------------------------------------------+ - -// optional hcd configuration, called by tuh_configure() -bool hcd_dwc2_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) { - (void) rhport; - (void) cfg_id; - (void) cfg_param; - - return true; -} - -#if( USB_GPIO_TOGGLE == 1 ) -static bool is_pin_gpio(uint8_t pin) -{ - uint32_t val; - val = RD_REG32(PINMUX_REG(pin)); - val &= PINMUX_MASK; - return (val == PINMUX_GPIO); -} - -/* - * @brief Configure the pin as gpio in pinmux - */ -static void config_pinmux(uint8_t pin) -{ - uint32_t reg_val; - if (is_pin_gpio(pin) == false) - { - printf("\n\r Configuring pinmux reg"); - /* Change pin functionality to gpio */ - reg_val = RD_REG32(PINMUX_REG(pin)); - reg_val = (reg_val & ~PINMUX_MASK) | PINMUX_GPIO; - WR_REG32(PINMUX_REG(pin), reg_val); - } -} - -// gpio reset for socfpga usb2 controller -static int usb2_gpio_reset() -{ - #define GPIO_USB_RESET GPIO1_PIN4 - - gpio_handle_t led; - int led_config = GPIO_DIR_OUT; - int ret; - - config_pinmux(GPIO_USB_RESET); - led = gpio_open(GPIO_USB_RESET); - - ret = gpio_ioctl(led, SET_GPIO_DIR, &led_config); - - if( ret != 0 ) - { - ERROR("gpio reset failed"); - gpio_close(led); - return -1; - } - - gpio_write_sync(led, 1); - osal_task_delay(10); - - return 0; -} -#endif - -// Initialize controller to host mode -bool hcd_dwc2_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { - (void) rh_init; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - - tu_memclr(&_hcd_data, sizeof(_hcd_data)); - -#if (CFG_TUSB_MCU == OPT_MCU_SOCFPGA) - -#if ( USB_GPIO_TOGGLE == 1 ) - if( usb2_gpio_reset() != 0 ) - { - return false; - } -#endif - if (rstmgr_assert_reset(RST_USB0) != 0) - { - ERROR("Unable to assert the usb2 reset"); - return false; - } - - if (rstmgr_deassert_reset(RST_USB0) != 0) - { - ERROR("Unable to deassert reset"); - return false; - } - - if (rstmgr_deassert_reset(RST_USB0ECC) != 0) - { - ERROR("Unable to deassert reset"); - return false; - } -#endif - - // Core Initialization - const bool is_highspeed = dwc2_core_is_highspeed(dwc2, TUSB_ROLE_HOST); - const bool is_dma = dma_host_enabled(dwc2); - TU_ASSERT(dwc2_core_init(rhport, is_highspeed, is_dma)); - - //------------- 3.1 Host Initialization -------------// - - // work at max supported speed - dwc2->hcfg &= ~HCFG_FSLS_ONLY; - - // Enable HFIR reload - if (dwc2->gsnpsid >= DWC2_CORE_REV_2_92a) { - dwc2->hfir |= HFIR_RELOAD_CTRL; - } - - // force host mode and wait for mode switch - dwc2->gusbcfg = (dwc2->gusbcfg & ~GUSBCFG_FDMOD) | GUSBCFG_FHMOD; -#if CFG_TUSB_MCU == OPT_MCU_STM32N6 - // No hardware detection of Vbus B-session is available on the STM32N6 - dwc2->stm32_gccfg &= ~STM32_GCCFG_VBVALOVAL; -#endif - while ((dwc2->gintsts & GINTSTS_CMOD) != GINTSTS_CMODE_HOST) {} - - // configure fixed-allocated fifo scheme - dfifo_host_init(rhport); - - dwc2->hprt = HPRT_W1_MASK; // clear all write-1-clear bits - dwc2->hprt = HPRT_POWER; // turn on VBUS - - // Enable required interrupts - dwc2->gintmsk |= GINTSTS_OTGINT | GINTSTS_CONIDSTSCHNG | GINTSTS_HPRTINT | GINTSTS_HCINT | GINTSTS_DISCINT; - - // NPTX can hold at least 2 packet, change interrupt level to half-empty - uint32_t gahbcfg = dwc2->gahbcfg & ~GAHBCFG_TX_FIFO_EPMTY_LVL; - gahbcfg |= GAHBCFG_GINT; // Enable global interrupt - dwc2->gahbcfg = gahbcfg; - return true; -} - -// Enable USB interrupt -void hcd_dwc2_int_enable (uint8_t rhport) { - dwc2_int_set(rhport, TUSB_ROLE_HOST, true); -} - -// Disable USB interrupt -void hcd_dwc2_int_disable(uint8_t rhport) { - dwc2_int_set(rhport, TUSB_ROLE_HOST, false); -} - -// Get frame number (1ms) -uint32_t hcd_dwc2_frame_number(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - return dwc2->hfnum & HFNUM_FRNUM_Msk; -} - -//--------------------------------------------------------------------+ -// Port API -//--------------------------------------------------------------------+ - -// Get the current connect status of roothub port -bool hcd_dwc2_port_connect_status(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - return dwc2->hprt & HPRT_CONN_STATUS; -} - -// Reset USB bus on the port. Return immediately, bus reset sequence may not be complete. -// Some port would require hcd_port_reset_end() to be invoked after 10ms to complete the reset sequence. -void hcd_dwc2_port_reset(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - uint32_t hprt = dwc2->hprt & ~HPRT_W1_MASK; - hprt |= HPRT_RESET; - dwc2->hprt = hprt; -} - -// Complete bus reset sequence, may be required by some controllers -void hcd_dwc2_port_reset_end(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - uint32_t hprt = dwc2->hprt & ~HPRT_W1_MASK; // skip w1c bits - hprt &= ~HPRT_RESET; - dwc2->hprt = hprt; -} - -// Get port link speed -tusb_speed_t hcd_dwc2_port_speed_get(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const tusb_speed_t speed = hprt_speed_get(dwc2); - return speed; -} - -// HCD closes all opened endpoints belong to this device -void hcd_dwc2_device_close(uint8_t rhport, uint8_t dev_addr) { - (void) rhport; - for (uint8_t i = 0; i < (uint8_t) CFG_TUH_DWC2_ENDPOINT_MAX; i++) { - hcd_endpoint_t* edpt = &_hcd_data.edpt[i]; - if (edpt->hcchar_bm.enable && edpt->hcchar_bm.dev_addr == dev_addr) { - tu_memclr(edpt, sizeof(hcd_endpoint_t)); - } - } -} - -//--------------------------------------------------------------------+ -// Endpoints API -//--------------------------------------------------------------------+ - -// Open an endpoint -bool hcd_dwc2_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t* desc_ep) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const tusb_speed_t rh_speed = hprt_speed_get(dwc2); - - tuh_bus_info_t bus_info; - tuh_bus_info_get(dev_addr, &bus_info); - - // find a free endpoint - const uint8_t ep_id = edpt_alloc(); - TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); - hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; - - dwc2_channel_char_t* hcchar_bm = &edpt->hcchar_bm; - hcchar_bm->ep_size = tu_edpt_packet_size(desc_ep); - hcchar_bm->ep_num = tu_edpt_number(desc_ep->bEndpointAddress); - hcchar_bm->ep_dir = tu_edpt_dir(desc_ep->bEndpointAddress); - hcchar_bm->low_speed_dev = (bus_info.speed == TUSB_SPEED_LOW) ? 1 : 0; - hcchar_bm->ep_type = desc_ep->bmAttributes.xfer; // ep_type matches TUSB_XFER_* - hcchar_bm->err_multi_count = 0; - hcchar_bm->dev_addr = dev_addr; - hcchar_bm->odd_frame = 0; - hcchar_bm->disable = 0; - hcchar_bm->enable = 1; - - dwc2_channel_split_t* hcsplt_bm = &edpt->hcsplt_bm; - hcsplt_bm->hub_port = bus_info.hub_port; - hcsplt_bm->hub_addr = bus_info.hub_addr; - hcsplt_bm->xact_pos = 0; - hcsplt_bm->split_compl = 0; - hcsplt_bm->split_en = (rh_speed == TUSB_SPEED_HIGH && bus_info.speed != TUSB_SPEED_HIGH) ? 1 : 0; - - edpt->speed = bus_info.speed; - edpt->next_pid = HCTSIZ_PID_DATA0; - if (desc_ep->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) { - edpt->uframe_interval = 1 << (desc_ep->bInterval - 1); - if (bus_info.speed == TUSB_SPEED_FULL) { - edpt->uframe_interval <<= 3; - } - } else if (desc_ep->bmAttributes.xfer == TUSB_XFER_INTERRUPT) { - if (bus_info.speed == TUSB_SPEED_HIGH) { - edpt->uframe_interval = 1 << (desc_ep->bInterval - 1); - } else { - edpt->uframe_interval = desc_ep->bInterval << 3; - } - } - - return true; -} - -bool hcd_dwc2_edpt_close(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) { - (void) rhport; (void) daddr; (void) ep_addr; - return false; // TODO not implemented yet -} - -// clean up channel after part of transfer is done but the whole urb is not complete -static void channel_xfer_out_wrapup(dwc2_regs_t* dwc2, uint8_t ch_id) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - const dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - - const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; - edpt->next_pid = hctsiz.pid; // save PID - - /* Since hctsiz.xfersize field reflects the number of bytes transferred via the AHB, not the USB) - * For IN: we can use hctsiz.xfersize as remaining bytes. - * For OUT: Must use the hctsiz.pktcnt field to determine how much data has been transferred. This field reflects the - * number of packets that have been transferred via the USB. This is always an integral number of packets if the - * transfer was halted before its normal completion. - */ - const uint16_t remain_packets = hctsiz.packet_count; - const dwc2_channel_char_t hcchar = {.value = channel->hcchar}; - const uint16_t total_packets = cal_packet_count(edpt->buflen, hcchar.ep_size); - const uint16_t actual_bytes = (total_packets - remain_packets) * hcchar.ep_size; - - xfer->fifo_bytes = 0; - xfer->xferred_bytes += actual_bytes; - edpt->buffer += actual_bytes; - edpt->buflen -= actual_bytes; -} - -static bool channel_xfer_start(dwc2_regs_t* dwc2, uint8_t ch_id) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_char_t* hcchar_bm = &edpt->hcchar_bm; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - bool const is_period = channel_is_periodic(edpt->hcchar); - - // clear previous state - xfer->fifo_bytes = 0; - - // hchar: restore but don't enable yet - if (is_period) { - hcchar_bm->odd_frame = 1 - (dwc2->hfnum & 1); // transfer on next frame - } - channel->hcchar = (edpt->hcchar & ~HCCHAR_CHENA); - - // hctsiz: zero length packet still count as 1 - const uint16_t packet_count = cal_packet_count(edpt->buflen, hcchar_bm->ep_size); - dwc2_channel_tsize_t hctsiz = {.value = 0}; - hctsiz.pid = edpt->next_pid; // next PID is set in transfer complete interrupt - hctsiz.packet_count = packet_count; - hctsiz.xfer_size = edpt->buflen; - if (edpt->next_do_ping && edpt->speed == TUSB_SPEED_HIGH && - edpt->next_pid != HCTSIZ_PID_SETUP && hcchar_bm->ep_dir == TUSB_DIR_OUT) { - hctsiz.do_ping = 1; - } - channel->hctsiz = hctsiz.value; - edpt->next_do_ping = 0; - - // pre-calculate next PID based on packet count, adjusted in transfer complete interrupt if short packet - if (hcchar_bm->ep_num == 0) { - edpt->next_pid = HCTSIZ_PID_DATA1; // control data and status stage always start with DATA1 - } else { - edpt->next_pid = cal_next_pid(edpt->next_pid, packet_count); - } - - channel->hcsplt = edpt->hcsplt; - channel->hcint = 0xFFFFFFFFU; // clear all channel interrupts - - if (dma_host_enabled(dwc2)) { - uint32_t hcintmsk = HCINT_HALTED; - channel->hcintmsk = hcintmsk; - dwc2->haintmsk |= TU_BIT(ch_id); - - channel->hcdma = (uint32_t)(uintptr_t) edpt->buffer; - - if (hcchar_bm->ep_dir == TUSB_DIR_IN) { - channel_send_in_token(dwc2, channel); - } else { - hcd_dcache_clean(edpt->buffer, edpt->buflen); - channel->hcchar |= HCCHAR_CHENA; - } - } else { - uint32_t hcintmsk = HCINT_NAK | HCINT_XACT_ERR | HCINT_STALL | HCINT_XFER_COMPLETE | HCINT_DATATOGGLE_ERR; - if (hcchar_bm->ep_dir == TUSB_DIR_IN) { - hcintmsk |= HCINT_BABBLE_ERR | HCINT_DATATOGGLE_ERR | HCINT_ACK; - } else { - hcintmsk |= HCINT_NYET; - if (edpt->hcsplt_bm.split_en || hctsiz.do_ping) { - hcintmsk |= HCINT_ACK; - } - } - channel->hcintmsk = hcintmsk; - dwc2->haintmsk |= TU_BIT(ch_id); - - // enable channel for slave mode: - // - OUT: it will enable corresponding FIFO channel - // - IN : it will write an IN request to the Non-periodic Request Queue, this will have dwc2 trying to send - // IN Token. If we got NAK, we have to re-enable the channel again in the interrupt. Due to the way usbh stack only - // call hcd_edpt_xfer() once, we will need to manage de-allocate/re-allocate IN channel dynamically. - if (hcchar_bm->ep_dir == TUSB_DIR_IN) { - channel_send_in_token(dwc2, channel); - } else { - channel->hcchar |= HCCHAR_CHENA; - if (edpt->buflen > 0) { - // To prevent conflict with other channel, we will enable periodic/non-periodic FIFO empty interrupt accordingly - // And write packet in the interrupt handler - dwc2->gintmsk |= (is_period ? GINTSTS_PTX_FIFO_EMPTY : GINTSTS_NPTX_FIFO_EMPTY); - } - } - } - - return true; -} - -// kick-off transfer with an endpoint -static bool edpt_xfer_kickoff(dwc2_regs_t* dwc2, uint8_t ep_id) { - uint8_t ch_id = channel_alloc(dwc2); - TU_ASSERT(ch_id < 16); // all channel are in used - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - xfer->ep_id = ep_id; - xfer->result = XFER_RESULT_INVALID; - - return channel_xfer_start(dwc2, ch_id); -} - -// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked -bool hcd_dwc2_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint32_t buflen) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint8_t ep_num = tu_edpt_number(ep_addr); - const uint8_t ep_dir = tu_edpt_dir(ep_addr); - - uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir); - TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); - hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; - - edpt->buffer = buffer; - edpt->buflen = buflen; - - if (ep_num == 0) { - // update ep_dir since control endpoint can switch direction - edpt->hcchar_bm.ep_dir = ep_dir; - } - return edpt_xfer_kickoff(dwc2, ep_id); -} - -// Abort a queued transfer. Note: it can only abort transfer that has not been started -// Return true if a queued transfer is aborted, false if there is no transfer to abort -bool hcd_dwc2_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint8_t ep_num = tu_edpt_number(ep_addr); - const uint8_t ep_dir = tu_edpt_dir(ep_addr); - const uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir); - TU_VERIFY(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); - - // hcd_int_disable(rhport); - - // Find enabled channeled and disable it, channel will be de-allocated in the interrupt handler - const uint8_t ch_id = channel_find_enabled(dwc2, dev_addr, ep_num, ep_dir); - if (ch_id < 16) { - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - channel_disable(dwc2, channel); - } - - // hcd_int_enable(rhport); - - return true; -} - -// Submit a special transfer to send 8-byte Setup Packet, when complete hcd_event_xfer_complete() must be invoked -bool hcd_dwc2_setup_send(uint8_t rhport, uint8_t dev_addr, const uint8_t setup_packet[8]) { - uint8_t ep_id = edpt_find_opened(dev_addr, 0, TUSB_DIR_OUT); - TU_ASSERT(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); // no opened endpoint - hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; - edpt->next_pid = HCTSIZ_PID_SETUP; - - return hcd_edpt_xfer(rhport, dev_addr, 0, (uint8_t*)(uintptr_t) setup_packet, 8); -} - -// clear stall, data toggle is also reset to DATA0 -bool hcd_dwc2_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { - (void) rhport; - const uint8_t ep_num = tu_edpt_number(ep_addr); - const uint8_t ep_dir = tu_edpt_dir(ep_addr); - const uint8_t ep_id = edpt_find_opened(dev_addr, ep_num, ep_dir); - TU_VERIFY(ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); - hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; - - edpt->next_pid = HCTSIZ_PID_DATA0; - - return true; -} - -//-------------------------------------------------------------------- -// HCD Event Handler -//-------------------------------------------------------------------- - -// retry an IN transfer, channel must be halted -static void channel_xfer_in_retry(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - dwc2_channel_char_t hcchar = {.value = channel->hcchar}; - - if (channel_is_periodic(hcchar.value)){ - const dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; - // retry immediately for periodic split NYET if we haven't reach max retry - if (hcsplt.split_en && hcsplt.split_compl && (hcint & HCINT_NYET || xfer->halted_nyet)) { - xfer->period_split_nyet_count++; - xfer->halted_nyet = 0; - if (xfer->period_split_nyet_count < HCD_XFER_PERIOD_SPLIT_NYET_MAX) { - hcchar.odd_frame = 1 - (dwc2->hfnum & 1); // transfer on next frame - channel->hcchar = hcchar.value; - channel_send_in_token(dwc2, channel); - return; - } else { - // too many NYET, de-allocate channel with below code - xfer->period_split_nyet_count = 0; - } - } - - const uint32_t ucount = (hprt_speed_get(dwc2) == TUSB_SPEED_HIGH ? 1 : 8); - if (edpt->uframe_interval == ucount) { - // retry on next frame if bInterval is 1 - hcchar.odd_frame = 1 - (dwc2->hfnum & 1); - channel->hcchar = hcchar.value; - channel_send_in_token(dwc2, channel); - } else { - // otherwise, de-allocate channel, enable SOF set frame counter for later transfer - const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; - edpt->next_pid = hctsiz.pid; // save PID - edpt->uframe_countdown = edpt->uframe_interval - ucount; - // enable SOF interrupt if not already enabled - if (!(dwc2->gintmsk & GINTMSK_SOFM)) { - dwc2->gintsts = GINTSTS_SOF; - dwc2->gintmsk |= GINTMSK_SOFM; - } - // already halted, de-allocate channel (called from DMA isr) - channel_dealloc(dwc2, ch_id); - } - } else { - // for control/bulk: retry immediately - channel_send_in_token(dwc2, channel); - } -} - -#if CFG_TUSB_DEBUG -TU_ATTR_ALWAYS_INLINE static inline void print_hcint(uint32_t hcint) { - const char* str[] = { - "XFRC", "HALTED", "AHBERR", "STALL", - "NAK", "ACK", "NYET", "XERR", - "BBLERR", "FRMOR", "DTERR", "BNA", - "XCSERR", "DESC_LST" - }; - - for(uint32_t i=0; i<14; i++) { - if (hcint & TU_BIT(i)) { - TU_LOG1("%s ", str[i]); - } - } - TU_LOG1("\r\n"); -} -#endif - -#if CFG_TUH_DWC2_SLAVE_ENABLE -static void handle_rxflvl_irq(uint8_t rhport) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - - // Pop control word off FIFO - const dwc2_grxstsp_t grxstsp = {.value= dwc2->grxstsp}; - const uint8_t ch_id = grxstsp.ep_ch_num; - - switch (grxstsp.packet_status) { - case GRXSTS_PKTSTS_RX_DATA: { - // In packet received, pop this entry --> ACK interrupt - const uint16_t byte_count = grxstsp.byte_count; - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX,); - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - - if (byte_count) { - dfifo_read_packet(dwc2, edpt->buffer + xfer->xferred_bytes, byte_count); - xfer->xferred_bytes += byte_count; - xfer->fifo_bytes = byte_count; - } - break; - } - - case GRXSTS_PKTSTS_RX_COMPLETE: - // In transfer complete: After this entry is popped from the rx FIFO, dwc2 asserts a Transfer Completed - // interrupt --> handle_channel_irq() - break; - - case GRXSTS_PKTSTS_HOST_DATATOGGLE_ERR: - TU_ASSERT(0, ); // maybe try to change DToggle - break; - - case GRXSTS_PKTSTS_HOST_CHANNEL_HALTED: - // triggered when channel.hcchar_bm.disable is set - // TODO handle later - break; - - default: break; // ignore other status - } -} - -// return true if there is still pending data and need more ISR -static bool handle_txfifo_empty(dwc2_regs_t* dwc2, bool is_periodic) { - // Use period txsts for both p/np to get request queue space available (1-bit difference, it is small enough) - const dwc2_hptxsts_t txsts = {.value = (is_periodic ? dwc2->hptxsts : dwc2->hnptxsts)}; - - const uint8_t max_channel = dwc2_channel_count(dwc2); - for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - const dwc2_channel_char_t hcchar = {.value = channel->hcchar}; - // skip writing to FIFO if channel is expecting halted. - if (!(channel->hcintmsk & HCINT_HALTED) && (hcchar.ep_dir == TUSB_DIR_OUT)) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX); - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; - const uint16_t remain_packets = hctsiz.packet_count; - for (uint16_t i = 0; i < remain_packets; i++) { - const uint16_t remain_bytes = edpt->buflen - xfer->fifo_bytes; - const uint16_t xact_bytes = tu_min16(remain_bytes, hcchar.ep_size); - - // skip if there is not enough space in FIFO and RequestQueue. - // Packet's last word written to FIFO will trigger a request queue - if ((xact_bytes > (txsts.fifo_available << 2)) || (txsts.req_queue_available == 0)) { - return true; - } - - dfifo_write_packet(dwc2, ch_id, edpt->buffer + xfer->fifo_bytes, xact_bytes); - xfer->fifo_bytes += xact_bytes; - } - } - } - - return false; // no channel has pending data -} - -static bool handle_channel_in_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; - const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; - bool is_done = false; - - // if (hcsplt.split_en) { - // if (edpt->hcchar_bm.ep_num == 1) { - // TU_LOG1("Frame %u, ch %u: ep %u, hcint 0x%04lX ", dwc2->hfnum_bm.num, ch_id, hcsplt.ep_num, hcint); - // print_hcint(hcint); - // } - - if (hcint & HCINT_XFER_COMPLETE) { - if (edpt->hcchar_bm.ep_num != 0) { - edpt->next_pid = hctsiz.pid; // save pid (already toggled) - } - - const uint16_t remain_packets = hctsiz.packet_count; - if (hcsplt.split_en && remain_packets && xfer->fifo_bytes == edpt->hcchar_bm.ep_size) { - // Split can only complete 1 transaction (up to 1 packet) at a time, schedule more - hcsplt.split_compl = 0; - channel->hcsplt = hcsplt.value; - } else { - xfer->result = XFER_RESULT_SUCCESS; - } - - channel_disable(dwc2, channel); - } else if (hcint & (HCINT_XACT_ERR | HCINT_BABBLE_ERR | HCINT_STALL)) { - if (hcint & HCINT_STALL) { - xfer->result = XFER_RESULT_STALLED; - } else if (hcint & HCINT_BABBLE_ERR) { - xfer->result = XFER_RESULT_FAILED; - } else if (hcint & HCINT_XACT_ERR) { - xfer->err_count++; - channel->hcintmsk |= HCINT_ACK; - } - - channel_disable(dwc2, channel); - } else if (hcint & HCINT_NYET) { - // restart complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - xfer->halted_nyet = 1; - channel_disable(dwc2, channel); - } else if (hcint & HCINT_NAK) { - // NAK received, disable channel to flush all posted request and try again - if (hcsplt.split_en) { - hcsplt.split_compl = 0; // restart with start-split - channel->hcsplt = hcsplt.value; - } - - channel_disable(dwc2, channel); - } else if (hcint & HCINT_ACK) { - xfer->err_count = 0; - - if (hcsplt.split_en) { - if (!hcsplt.split_compl) { - // start split is ACK --> do complete split - channel->hcintmsk |= HCINT_NYET; - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel_send_in_token(dwc2, channel); - } else { - // do nothing for complete split with DATA, this will trigger XferComplete and handled there - } - } else { - // ACK with data - const uint16_t remain_packets = hctsiz.packet_count; - if (remain_packets) { - // still more packet to receive, also reset to start split - hcsplt.split_compl = 0; - channel->hcsplt = hcsplt.value; - channel_send_in_token(dwc2, channel); - } - } - } else if (hcint & HCINT_HALTED) { - channel->hcintmsk &= ~HCINT_HALTED; - if (xfer->result != XFER_RESULT_INVALID) { - is_done = true; - } else if (xfer->err_count == HCD_XFER_ERROR_MAX) { - xfer->result = XFER_RESULT_FAILED; - is_done = true; - } else { - // got here due to NAK or NYET - channel_xfer_in_retry(dwc2, ch_id, hcint); - } - } else if (hcint & HCINT_DATATOGGLE_ERR) { - xfer->err_count = 0; - TU_ASSERT(false); - } - return is_done; -} - -static bool handle_channel_out_slave(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; - bool is_done = false; - - if (hcint & HCINT_XFER_COMPLETE) { - is_done = true; - xfer->result = XFER_RESULT_SUCCESS; - channel->hcintmsk &= ~HCINT_ACK; - if (hcint & HCINT_NYET) { - // complete transfer with NYET, do ping next time - edpt->next_do_ping = 1; - } - } else if (hcint & HCINT_STALL) { - xfer->result = XFER_RESULT_STALLED; - channel_disable(dwc2, channel); - } else if (hcint & HCINT_NYET) { - xfer->err_count = 0; - if (hcsplt.split_en) { - // retry complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel->hcchar |= HCCHAR_CHENA; - } else { - edpt->next_do_ping = 1; - channel_xfer_out_wrapup(dwc2, ch_id); - channel_disable(dwc2, channel); - } - } else if (hcint & (HCINT_NAK | HCINT_XACT_ERR)) { - // clean up transfer so far, disable and start again later - channel_xfer_out_wrapup(dwc2, ch_id); - channel_disable(dwc2, channel); - if (hcint & HCINT_XACT_ERR) { - xfer->err_count++; - channel->hcintmsk |= HCINT_ACK; - } else { - // NAK disable channel to flush all posted request and try again - edpt->next_do_ping = 1; - xfer->err_count = 0; - } - } else if (hcint & HCINT_HALTED) { - channel->hcintmsk &= ~HCINT_HALTED; - if (xfer->result != XFER_RESULT_INVALID) { - is_done = true; - } else if (xfer->err_count == HCD_XFER_ERROR_MAX) { - xfer->result = XFER_RESULT_FAILED; - is_done = true; - } else { - // Got here due to NAK or NYET - TU_ASSERT(channel_xfer_start(dwc2, ch_id)); - } - } else if (hcint & HCINT_ACK) { - xfer->err_count = 0; - channel->hcintmsk &= ~HCINT_ACK; - if (hcsplt.split_en) { - if (!hcsplt.split_compl) { - // ACK for start split --> do complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel->hcchar |= HCCHAR_CHENA; - } - } else { - // ACK interrupt is only enabled for Split and PING - // ACK for PING, which mean device is ready to receive data - channel->hctsiz &= ~HCTSIZ_DOPING; // HC already cleared PING bit, but we clear anyway - channel->hcchar |= HCCHAR_CHENA; - } - } - - if (is_done) { - xfer->xferred_bytes += xfer->fifo_bytes; - xfer->fifo_bytes = 0; - } - - return is_done; -} -#endif - -#if CFG_TUH_DWC2_DMA_ENABLE -static bool handle_channel_in_dma(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_char_t hcchar = {.value = channel->hcchar}; - dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; - const dwc2_channel_tsize_t hctsiz = {.value = channel->hctsiz}; - - bool is_done = false; - - // TU_LOG1("in hcint = %02lX\r\n", hcint); - - if (hcint & HCINT_HALTED) { - if (hcint & (HCINT_XFER_COMPLETE | HCINT_STALL | HCINT_BABBLE_ERR)) { - const uint16_t remain_bytes = (uint16_t) hctsiz.xfer_size; - const uint16_t remain_packets = hctsiz.packet_count; - const uint16_t actual_len = edpt->buflen - remain_bytes; - xfer->xferred_bytes += actual_len; - - is_done = true; - - if (hcint & HCINT_STALL) { - xfer->result = XFER_RESULT_STALLED; - } else if (hcint & HCINT_BABBLE_ERR) { - xfer->result = XFER_RESULT_FAILED; - } else if (hcsplt.split_en && remain_packets && actual_len == hcchar.ep_size) { - // Split can only complete 1 transaction (up to 1 packet) at a time, schedule more - is_done = false; - edpt->buffer += actual_len; - edpt->buflen -= actual_len; - - hcsplt.split_compl = 0; - channel->hcsplt = hcsplt.value; - channel_xfer_in_retry(dwc2, ch_id, hcint); - } else { - xfer->result = XFER_RESULT_SUCCESS; - } - - xfer->err_count = 0; - channel->hcintmsk &= ~HCINT_ACK; - } else if (hcint & HCINT_XACT_ERR) { - xfer->err_count++; - if (xfer->err_count >= HCD_XFER_ERROR_MAX) { - is_done = true; - xfer->result = XFER_RESULT_FAILED; - } else { - channel->hcintmsk |= HCINT_ACK | HCINT_NAK | HCINT_DATATOGGLE_ERR; - hcsplt.split_compl = 0; - channel->hcsplt = hcsplt.value; - channel_xfer_in_retry(dwc2, ch_id, hcint); - } - } else if (hcint & HCINT_NYET) { - // Must handle nyet before nak or ack. Could get a nyet at the same time as either of those on a BULK/CONTROL - // OUT that started with a PING. The nyet takes precedence. - if (hcsplt.split_en) { - // split not yet mean hub has no data, retry complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel_xfer_in_retry(dwc2, ch_id, hcint); - } - } else if (hcint & HCINT_ACK) { - xfer->err_count = 0; - channel->hcintmsk &= ~HCINT_ACK; - if (hcsplt.split_en) { - // start split is ACK --> do complete split - // TODO: for ISO must use xact_pos to plan complete split based on microframe (up to 187.5 bytes/uframe) - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - if (channel_is_periodic(channel->hcchar)) { - hcchar.odd_frame = 1 - (dwc2->hfnum & 1); // transfer on next frame - channel->hcchar = hcchar.value; - } - channel_send_in_token(dwc2, channel); - } - } else if (hcint & (HCINT_NAK | HCINT_DATATOGGLE_ERR)) { - xfer->err_count = 0; - channel->hcintmsk &= ~(HCINT_NAK | HCINT_DATATOGGLE_ERR); - hcsplt.split_compl = 0; // restart with start-split - channel->hcsplt = hcsplt.value; - channel_xfer_in_retry(dwc2, ch_id, hcint); - } else if (hcint & HCINT_FARME_OVERRUN) { - // retry start-split in next binterval - channel_xfer_in_retry(dwc2, ch_id, hcint); - } - } - - return is_done; -} - -static bool handle_channel_out_dma(dwc2_regs_t* dwc2, uint8_t ch_id, uint32_t hcint) { - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_endpoint_t* edpt = &_hcd_data.edpt[xfer->ep_id]; - dwc2_channel_split_t hcsplt = {.value = channel->hcsplt}; - - bool is_done = false; - - // TU_LOG1("out hcint = %02lX\r\n", hcint); - - if (hcint & HCINT_HALTED) { - if (hcint & (HCINT_XFER_COMPLETE | HCINT_STALL)) { - is_done = true; - xfer->err_count = 0; - if (hcint & HCINT_XFER_COMPLETE) { - xfer->result = XFER_RESULT_SUCCESS; - xfer->xferred_bytes += edpt->buflen; - } else { - xfer->result = XFER_RESULT_STALLED; - channel_xfer_out_wrapup(dwc2, ch_id); - } - channel->hcintmsk &= ~HCINT_ACK; - } else if (hcint & HCINT_XACT_ERR) { - if (hcint & (HCINT_NAK | HCINT_NYET | HCINT_ACK)) { - xfer->err_count = 0; - // clean up transfer so far and start again - channel_xfer_out_wrapup(dwc2, ch_id); - channel_xfer_start(dwc2, ch_id); - } else { - xfer->err_count++; - if (xfer->err_count >= HCD_XFER_ERROR_MAX) { - xfer->result = XFER_RESULT_FAILED; - is_done = true; - } else { - // clean up transfer so far and start again - channel_xfer_out_wrapup(dwc2, ch_id); - channel_xfer_start(dwc2, ch_id); - } - } - } else if (hcint & HCINT_NYET) { - if (hcsplt.split_en && hcsplt.split_compl) { - // split not yet mean hub has no data, retry complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel->hcchar |= HCCHAR_CHENA; - } - } else if (hcint & HCINT_ACK) { - xfer->err_count = 0; - if (hcsplt.split_en && !hcsplt.split_compl) { - // start split is ACK --> do complete split - hcsplt.split_compl = 1; - channel->hcsplt = hcsplt.value; - channel->hcchar |= HCCHAR_CHENA; - } - } - } else if (hcint & HCINT_ACK) { - xfer->err_count = 0; - channel->hcintmsk &= ~HCINT_ACK; - } - - return is_done; -} -#endif - -static void handle_channel_irq(uint8_t rhport, bool in_isr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const bool is_dma = dma_host_enabled(dwc2); - const uint8_t max_channel = dwc2_channel_count(dwc2); - - for (uint8_t ch_id = 0; ch_id < max_channel; ch_id++) { - if (tu_bit_test(dwc2->haint, ch_id)) { - dwc2_channel_t* channel = &dwc2->channel[ch_id]; - hcd_xfer_t* xfer = &_hcd_data.xfer[ch_id]; - TU_ASSERT(xfer->ep_id < CFG_TUH_DWC2_ENDPOINT_MAX,); - dwc2_channel_char_t hcchar = {.value = channel->hcchar}; - - const uint32_t hcint = channel->hcint; - channel->hcint = hcint; // clear interrupt - - bool is_done = false; - if (is_dma) { - #if CFG_TUH_DWC2_DMA_ENABLE - if (hcchar.ep_dir == TUSB_DIR_OUT) { - is_done = handle_channel_out_dma(dwc2, ch_id, hcint); - } else { - is_done = handle_channel_in_dma(dwc2, ch_id, hcint); - if (is_done && (channel->hcdma > xfer->xferred_bytes)) { - // hcdma is increased by word --> need to align4 - hcd_dcache_invalidate((void*)(uintptr_t) tu_align4(channel->hcdma - xfer->xferred_bytes), xfer->xferred_bytes); - } - } - #endif - } else { - #if CFG_TUH_DWC2_SLAVE_ENABLE - if (hcchar.ep_dir == TUSB_DIR_OUT) { - is_done = handle_channel_out_slave(dwc2, ch_id, hcint); - } else { - is_done = handle_channel_in_slave(dwc2, ch_id, hcint); - } - #endif - } - - if (is_done) { - const uint8_t ep_addr = tu_edpt_addr(hcchar.ep_num, hcchar.ep_dir); - hcd_event_xfer_complete(hcchar.dev_addr, ep_addr, xfer->xferred_bytes, (xfer_result_t)xfer->result, in_isr); - channel_dealloc(dwc2, ch_id); - } - } - } -} - -// SOF is enabled for scheduled periodic transfer -static bool handle_sof_irq(uint8_t rhport, bool in_isr) { - (void) in_isr; - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - dwc2->gintsts = GINTSTS_SOF; // Clear the SOF interrupt flag - - bool more_isr = false; - - // If highspeed then SOF is 125us, else 1ms - const uint32_t ucount = (hprt_speed_get(dwc2) == TUSB_SPEED_HIGH ? 1 : 8); - - for(uint8_t ep_id = 0; ep_id < CFG_TUH_DWC2_ENDPOINT_MAX; ep_id++) { - hcd_endpoint_t* edpt = &_hcd_data.edpt[ep_id]; - if (edpt->hcchar_bm.enable && channel_is_periodic(edpt->hcchar) && edpt->uframe_countdown > 0) { - edpt->uframe_countdown -= tu_min32(ucount, edpt->uframe_countdown); - if (edpt->uframe_countdown == 0) { - if (!edpt_xfer_kickoff(dwc2, ep_id)) { - edpt->uframe_countdown = ucount; // failed to start, try again next frame - } - } - - more_isr = true; - } - } - - return more_isr; -} - -// Config HCFG FS/LS clock and HFIR for SOF interval according to link speed (value is in PHY clock unit) -static void port0_enable(dwc2_regs_t* dwc2, tusb_speed_t speed) { - uint32_t hcfg = dwc2->hcfg & ~HCFG_FSLS_PHYCLK_SEL; - - const dwc2_gusbcfg_t gusbcfg = {.value = dwc2->gusbcfg}; - uint32_t phy_clock; - - if (gusbcfg.phy_sel) { - phy_clock = 48; // dedicated FS is 48Mhz - if (speed == TUSB_SPEED_LOW) { - hcfg |= HCFG_FSLS_PHYCLK_SEL_6MHZ; - } else { - hcfg |= HCFG_FSLS_PHYCLK_SEL_48MHZ; - } - } else { - if (gusbcfg.ulpi_utmi_sel) { - phy_clock = 60; // ULPI 8-bit is 60Mhz - } else { - // UTMI+ 16-bit is 30Mhz, 8-bit is 60Mhz - phy_clock = gusbcfg.phy_if16 ? 30 : 60; - - // Enable UTMI+ low power mode 48Mhz external clock if not highspeed - if (speed == TUSB_SPEED_HIGH) { - dwc2->gusbcfg &= ~GUSBCFG_PHYLPCS; - } else { - dwc2->gusbcfg |= GUSBCFG_PHYLPCS; - // may need to reset port - } - } - hcfg |= HCFG_FSLS_PHYCLK_SEL_30_60MHZ; - } - - dwc2->hcfg = hcfg; - - uint32_t hfir = dwc2->hfir & ~HFIR_FRIVL_Msk; - if (speed == TUSB_SPEED_HIGH) { - hfir |= 125*phy_clock - 1; // The "- 1" is the correct value. The Synopsys databook was corrected in 3.30a - } else { - hfir |= 1000*phy_clock - 1; - } - - dwc2->hfir = hfir; -} - -/* Handle Host Port interrupt, possible source are: - - Connection Detection - - Enable Change - - Over Current Change -*/ -static void handle_hprt_irq(uint8_t rhport, bool in_isr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const dwc2_hprt_t hprt_bm = {.value = dwc2->hprt}; - uint32_t hprt = hprt_bm.value & ~HPRT_W1_MASK; - - if (hprt_bm.conn_detected) { - // Port Connect Detect - hprt |= HPRT_CONN_DETECT; - - if (hprt_bm.conn_status) { - hcd_event_device_attach(rhport, in_isr); - } - } - - if (hprt_bm.enable_change) { - // Port enable change - hprt |= HPRT_ENABLE_CHANGE; - - if (hprt_bm.enable) { - // Port enable - const tusb_speed_t speed = hprt_speed_get(dwc2); - port0_enable(dwc2, speed); - } else { - // TU_ASSERT(false, ); - } - } - - dwc2->hprt = hprt; // clear interrupt -} - -/* Interrupt Hierarchy - HCINTn HPRT - | | - HAINT.CHn | - | | - GINTSTS : HCInt | PrtInt | NPTxFEmp | PTxFEmpp | RXFLVL | SOF -*/ -void hcd_dwc2_int_handler(uint8_t rhport, bool in_isr) { - dwc2_regs_t* dwc2 = DWC2_REG(rhport); - const uint32_t gintmsk = dwc2->gintmsk; - const uint32_t gintsts = dwc2->gintsts & gintmsk; - - // TU_LOG1_HEX(gintsts); - - if (gintsts & GINTSTS_CONIDSTSCHNG) { - // Connector ID status change - dwc2->gintsts = GINTSTS_CONIDSTSCHNG; - - //if (dwc2->gotgctl) - // dwc2->hprt = HPRT_POWER; // power on port to turn on VBUS - //dwc2->gintmsk |= GINTMSK_PRTIM; - // TODO wait for SRP if OTG - } - - if (gintsts & GINTSTS_SOF) { - const bool more_sof = handle_sof_irq(rhport, in_isr); - if (!more_sof) { - dwc2->gintmsk &= ~GINTSTS_SOF; - } - } - - if (gintsts & GINTSTS_HPRTINT) { - // Host port interrupt: source is cleared in HPRT register - // TU_LOG1_HEX(dwc2->hprt); - handle_hprt_irq(rhport, in_isr); - } - - if (gintsts & GINTSTS_HCINT) { - // Host Channel interrupt: source is cleared in HCINT register - // must be handled after TX FIFO empty - handle_channel_irq(rhport, in_isr); - } - - if (gintsts & GINTSTS_DISCINT) { - // Device disconnected - dwc2->gintsts = GINTSTS_DISCINT; - - if (!(dwc2->hprt & HPRT_CONN_STATUS)) { - hcd_event_device_remove(rhport, in_isr); - } - } - -#if CFG_TUH_DWC2_SLAVE_ENABLE - // RxFIFO non-empty interrupt handling - if (gintsts & GINTSTS_RXFLVL) { - // RXFLVL bit is read-only - dwc2->gintmsk &= ~GINTSTS_RXFLVL; // disable RXFLVL interrupt while reading - - do { - handle_rxflvl_irq(rhport); // read all packets - } while(dwc2->gintsts & GINTSTS_RXFLVL); - - dwc2->gintmsk |= GINTSTS_RXFLVL; - } - - if (gintsts & GINTSTS_NPTX_FIFO_EMPTY) { - // NPTX FIFO empty interrupt, this is read-only and cleared by hardware when FIFO is written - const bool more_nptxfe = handle_txfifo_empty(dwc2, false); - if (!more_nptxfe) { - // no more pending packet, disable interrupt - dwc2->gintmsk &= ~GINTSTS_NPTX_FIFO_EMPTY; - } - } - - if (gintsts & GINTSTS_PTX_FIFO_EMPTY) { - // PTX FIFO empty interrupt, this is read-only and cleared by hardware when FIFO is written - const bool more_ptxfe = handle_txfifo_empty(dwc2, true); - if (!more_ptxfe) { - // no more pending packet, disable interrupt - dwc2->gintmsk &= ~GINTSTS_PTX_FIFO_EMPTY; - } - } -#endif -} - -#endif diff --git a/src/portable/socfpga/dwc2/hcd_dwc2.h b/src/portable/socfpga/dwc2/hcd_dwc2.h deleted file mode 100644 index 86d7476fe..000000000 --- a/src/portable/socfpga/dwc2/hcd_dwc2.h +++ /dev/null @@ -1,29 +0,0 @@ - -#ifndef __HCD_DWC2_H__ -#define __HCD_DWC2_H__ - -#include -#include -#include - -bool hcd_dwc2_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); -void hcd_dwc2_int_enable (uint8_t rhport); -void hcd_dwc2_int_disable(uint8_t rhport); - -uint32_t hcd_dwc2_frame_number(uint8_t rhport); -bool hcd_dwc2_port_connect_status(uint8_t rhport); -void hcd_dwc2_port_reset(uint8_t rhport); - -void hcd_dwc2_port_reset_end(uint8_t rhport); -tusb_speed_t hcd_dwc2_port_speed_get(uint8_t rhport); -void hcd_dwc2_device_close(uint8_t rhport, uint8_t dev_addr); - -bool hcd_dwc2_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t* desc_ep); -bool hcd_dwc2_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint32_t buflen); -bool hcd_dwc2_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); -bool hcd_dwc2_setup_send(uint8_t rhport, uint8_t dev_addr, const uint8_t setup_packet[8]); -bool hcd_dwc2_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); - -void hcd_dwc2_int_handler(uint8_t rhport, bool in_isr); - -#endif diff --git a/src/portable/socfpga/dwc3/dwc3_common.c b/src/portable/socfpga/dwc3/dwc3_common.c deleted file mode 100644 index 80d3d61b6..000000000 --- a/src/portable/socfpga/dwc3/dwc3_common.c +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2024, Intel Corporation. - * - * SPDX-License-Identifier: MIT - * - * HAL implementation for USB3 - */ -#include -#include -#include -#include "hcd_dwc3.h" -#include "tusb_config.h" -#include "osal_log.h" - -/* tinyusb specific queue initialization method */ -OSAL_QUEUE_DEF(usbh_int_set, xhci_event_params, XHCI_QUEUE_SZ, xcc_event_t); - -static QueueHandle_t xhci_queue; - -void dealloc_usb_port( struct xhci_data *xhci_handle ) -{ - deallocate_xhci_context(xhci_handle); -} - -int init_hcd_params( void ) -{ - xhci_queue = osal_queue_create(&xhci_event_params); - if ( xhci_queue == NULL ) - { - ERROR("Error in creating queue !!!"); - return -ENOMEM; - } - return 0; -} - -int wait_for_command_completion_event( struct xhci_data *xhci_ptr, int type ) -{ - xcc_event_t event = {0}; - while ( true ) - { - if ( osal_queue_receive(xhci_queue, &event, UINT32_MAX) == pdTRUE ) - { - DEBUG("CC event values are"); - DEBUG("pointer : %lx", event.cmd_trb_ptr); - DEBUG("Status field : %x", event.status_field); - DEBUG("Control fields : %x", event.control_field); - break; - } - } - - if ( ((event.status_field & 0xff000000U) >> 24) != 1U ) - { - return -1; - } - - switch (type) - { - case ENABLE_SLOT_CMD: - /* Get slot id from the CC event trb */ - update_device_slot_id(&xhci_ptr->dev_data, - (uint8_t) ((event.control_field & 0xff000000U) >> 24)); - break; - - default: /*do nothing*/ - break; - } - - xhci_ptr->xcr_ring->xcr_dequeue_ptr = (xhci_trb_t*) (event.cmd_trb_ptr); - - return 0; -} - -void xhci_command_event_complete( xcc_event_t event ) -{ - (void) osal_queue_send(xhci_queue, &event); -} - -void reset_usb_port( uint8_t rhport ) -{ - /* USB3 HS port only needs reset */ - if ( rhport == (uint32_t) SOCFPGA_USB3_HS_PORT ) - { - reset_xhci_port(rhport); - } -} - -bool usb_port_reset_end( uint8_t rhport ) -{ - if ( rhport == (uint32_t) SOCFPGA_USB3_HS_PORT ) - { - return is_xhci_port_reset_end(rhport); - } - - return true; -} diff --git a/src/portable/socfpga/dwc3/hcd_dwc3.c b/src/portable/socfpga/dwc3/hcd_dwc3.c deleted file mode 100644 index 67de3816d..000000000 --- a/src/portable/socfpga/dwc3/hcd_dwc3.c +++ /dev/null @@ -1,591 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2021 Koji Kitayama - * Portions copyrighted (c) 2021 Roland Winistoerfer - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#include -#include "tusb.h" -#include "host/hcd.h" -#include "tusb_private.h" - -#if CFG_TUSB_MCU == OPT_MCU_SOCFPGA - #include "socfpga_rst_mngr.h" - #include "dwc3.h" - #include "xhci_commands.h" - #include "xhci_endpoints.h" - #include "xhci_interrupts.h" - #include "xhci_doorbell.h" - #include "hcd_dwc3.h" - #include "osal_log.h" - #include "socfpga_cache.h" -#endif - -typedef struct -{ - uint8_t *buffer; - uint32_t buflen; -} hcd_dwc3_endpoint_t; - -#define XHCI_DCI_MAX 31 -hcd_dwc3_endpoint_t ep_data[XHCI_DCI_MAX]; - -static void hcd_xhci_set_configuration(); -static void hcd_dwc3_update_device_address( uint8_t daddr ); - -struct xhci_data xhci_handle __attribute__((aligned(64))); -static struct xhci_int_desc usb3_int_desc; -static tusb_control_request_t ctrl_req; -static int usb_set_config = 0; -uint8_t device_addr = 0; - -bool hcd_dwc3_init( uint8_t rhport, const tusb_rhport_init_t *rh_init ) -{ - xhci_int_ptr_t usb3_int_ptr = &usb3_int_desc; - (void) rh_init; - int ret; - - if (rhport == SOCFPGA_USB3_SS_PORT) - { - usb3_int_ptr->int_handler = tusb_int_handler; - if (register_usb3ISR(usb3_int_ptr) == false) - { - return false; - } - - if (rstmgr_deassert_reset(RST_USB1) != 0) - { - ERROR("\r\n Unable to deassdert the usb3 reset \r\n"); - return false; - } - - ret = init_hcd_params(); - if (ret != 0) - { - ERROR("hcd error -%d", ret); - return false; - } - - ret = dwc3_init(); - if (ret != 0) - { - ERROR("dwc3 Error -%d!!!", ret); - return false; - } - - //clear xHCI data structure members - tu_memclr(&xhci_handle, sizeof(xhci_handle)); - - if( xhci_init(&xhci_handle) == false ) - { - ERROR("xHCI init failed !!!"); - return false; - } - } - - return true; -} -bool hcd_dwc3_edpt_close(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) -{ - (void)rhport; - (void)daddr; - (void)ep_addr; - return true; -} - -void hcd_dwc3_int_enable( uint8_t rhport ) -{ - switch (rhport) - { - case SOCFPGA_USB3_HS_PORT: - enable_xhci_interrupts(); - break; - - default: /* do nothing */ - break; - } -} - -void hcd_dwc3_int_disable( uint8_t rhport ) -{ - (void) rhport; - /* disable_xhci_interrupts(); */ -} - -/*--------------------------------------------------------------------+ - * Port API - *--------------------------------------------------------------------+*/ -bool hcd_dwc3_port_connect_status( uint8_t rhport ) -{ - bool ret; - - ret = xhci_port_status(rhport); - - return ret; -} - -void hcd_dwc3_port_reset( uint8_t rhport ) -{ - (void) rhport; - reset_usb_port(rhport); -} - -static bool hcd_enable_slot( void ) -{ - enable_slot_command(xhci_handle.xcr_ring); - - if (wait_for_command_completion_event(&xhci_handle, - ENABLE_SLOT_CMD) != 0) - { - return false; - } - - return true; -} - -static bool hcd_send_address_cmd( void ) -{ - int ret; - - update_device_dev_speed(&xhci_handle); - - ret = init_input_device_context(&xhci_handle); - if (ret != 0) - { - ERROR("XHCI Error -%d!!!", ret); - return false; - } - - update_dcbaa_entry(&xhci_handle); - - set_device_address(&xhci_handle); - - if (wait_for_command_completion_event(&xhci_handle, - ADDRESS_DEVICE_CMD) != 0) - { - return false; - } - - update_device_address(&xhci_handle); - - if (xhci_handle.dev_data.dev_addr == 0U) - { - return false; /* device address can not be zero after address command is sent */ - } - - display_xhci_device_params(&xhci_handle.dev_data); - display_ip_context(xhci_handle.ip_ctx); - display_op_context(xhci_handle.op_ctx); - display_event_trbs(&xhci_handle); - - return true; -} - -static void hcd_dwc3_update_device_address( uint8_t daddr ) -{ - device_addr = daddr; -} - -void hcd_dwc3_port_reset_end( uint8_t rhport ) -{ - (void) rhport; - TU_ASSERT(usb_port_reset_end(rhport),); - - hcd_enable_slot(); - - hcd_send_address_cmd(); -} - -tusb_speed_t hcd_dwc3_port_speed_get( uint8_t rhport ) -{ - uint8_t dev_speed; - tusb_speed_t ret; - - dev_speed = get_xhc_port_speed(rhport); - switch (dev_speed) - { - case 4: - ret = TUSB_SPEED_SS; - break; - case 3: - ret = TUSB_SPEED_HIGH; - break; - case 2: - ret = TUSB_SPEED_FULL; - break; - case 1: - ret = TUSB_SPEED_LOW; - break; - default: - ret = TUSB_SPEED_INVALID; - break; - } - return ret; -} - -void hcd_dwc3_device_close( uint8_t rhport ) -{ - uint32_t slotid; - - if (rhport == SOCFPGA_USB3_SS_PORT) - { - /* Issue WR for usb3 ports only */ - xhci_warm_reset(rhport); - } - - slotid = xhci_handle.dev_data.slot_id; - - if (slotid != 0U) - { - disable_slot_command(xhci_handle.xcr_ring, slotid); - - if (wait_for_command_completion_event(&xhci_handle, - DISABLE_SLOT_CMD) != 0) - { - ERROR("xHCI command failed"); - return; - } - - dealloc_usb_port(&xhci_handle); - device_addr = 0U; - usb_set_config = 0; - } -} - -/*--------------------------------------------------------------------+ - * Endpoints API - *--------------------------------------------------------------------+*/ -static void hcd_xhci_set_configuration() -{ - update_xhc_slot_context(&xhci_handle); - - init_xhc_endpoint_context(&xhci_handle, BULK_OUT); - - init_xhc_endpoint_context(&xhci_handle, BULK_IN); - - configure_endpoint(&xhci_handle); - - if (wait_for_command_completion_event(&xhci_handle, - CONFIGURE_ENDPOINT_CMD) != 0) - { - return; - } -} - -bool hcd_dwc3_setup_send( uint8_t rhport, uint8_t daddr, uint8_t const setup_packet[ 8 ] ) -{ - (void)rhport; - memcpy(&ctrl_req, &setup_packet[0], sizeof(ctrl_req)); - - if ((tusb_request_code_t) setup_packet[ 1 ] == TUSB_REQ_SET_CONFIGURATION) - { - hcd_xhci_set_configuration(); - usb_set_config = 1; - } - - if ((tusb_request_code_t) setup_packet[ 1 ] == TUSB_REQ_SET_ADDRESS) - { - hcd_dwc3_update_device_address(ctrl_req.wValue); - } - hcd_event_xfer_complete(daddr, 0, 8, XFER_RESULT_SUCCESS, true); - - return true; -} - -bool hcd_dwc3_edpt_open( uint8_t rhport, uint8_t daddr, tusb_desc_endpoint_t const *ep_desc ) -{ - (void) rhport; - (void) daddr; - (void) ep_desc; - - return true; -} - -bool hcd_dwc3_edpt_xfer(uint8_t rhport, uint8_t daddr, uint8_t ep_addr, uint8_t * buffer, uint32_t buflen) -{ - const uint8_t ep_num = tu_edpt_number(ep_addr); - const unsigned dir = (uint32_t) tu_edpt_dir(ep_addr); - const uint8_t ep_dci = get_ep_dci(ep_addr); - - (void)rhport; - // There is no separate data stage for xHCI controller. Hence skip the tinyusb enumeration step for data stage - if( buffer == NULL && (buflen == 0) && (usb_set_config == 0)) - { - if( usb_set_config == 1 ) - { - usb_set_config = 0; - } - hcd_event_xfer_complete(daddr, ep_num, 8, XFER_RESULT_SUCCESS, true); - return true; - } - - ep_data[ep_dci].buffer = buffer; - ep_data[ep_dci].buflen = buflen; - - if( ep_num == 0 ) - { - configure_setup_stage(&xhci_handle, buffer, (usb_control_request_t *)&ctrl_req); - ring_xhci_ep0_db(&xhci_handle.op_regs); - } - else - { - if( dir == TUSB_DIR_OUT ) - { - cache_force_write_back(buffer, buflen); - } - endpoint_transfer(&xhci_handle, (int) ep_num, (uint8_t) dir, buffer, buflen); - } - - return true; -} - -bool hcd_dwc3_edpt_abort_xfer( uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr ) -{ - (void) rhport; - (void) dev_addr; - (void) ep_addr; - - return false; -} - -static void handle_endpoint_transfer(uint8_t ep_dci, uint8_t ep_addr) -{ - uint8_t *buffer = ep_data[ep_dci].buffer; - uint32_t buflen = ep_data[ep_dci].buflen; - const unsigned dir = (uint32_t) tu_edpt_dir(ep_addr); - const uint8_t ep_num = tu_edpt_number(ep_addr); - - if(ep_num == 0 && buflen != 0) - { - cache_force_invalidate(buffer, buflen); - } - - if( dir == TUSB_DIR_IN ) - { - cache_force_invalidate(buffer, buflen); - } - -} - -void hcd_dwc3_int_handler( uint8_t rhport, bool in_isr ) -{ - (void) rhport; - /* - * array to convert XHCI DCI to corresponding endpoint address for the - * tinyusb stack - */ - const uint8_t DCI2EP[ 30 ] = - { - 0x00, 0x01, 0x81, 0x02, 0x82, 0x3, 0x83, - 0x04, 0x84, 0x05, 0x85, 0x06, 0x86 - }; - uint8_t ep_num; - int ep_dci; - - xhci_event_trb_type_t trb_id; - - xpsc_event_t psc_event; - xtc_event_t tr_event; - xcc_event_t cc_event; - xhci_psceg_params_t rh_params; - - xhci_event_trb_t event_data; - - event_data = get_xhc_event(&xhci_handle); - - trb_id = - (xhci_event_trb_type_t) event_data.event_trb.trb_control_field. - trb_type; - - switch (trb_id) - { - case TRANSFER_EVENT: - tr_event = event_data.tr_event; - if (tr_event.tc_status_params.compl_code == (uint32_t)EVENT_SUCCESS) - { - uint32_t xfer_bytes = tr_event.tc_status_params.transfer_len; - ep_dci = (int) event_data.tr_event.tc_ctrl_params.ep_dci; - ep_num = DCI2EP[ ep_dci - 1 ]; - handle_endpoint_transfer(ep_dci, ep_num); - hcd_event_xfer_complete(device_addr, ep_num, xfer_bytes, XFER_RESULT_SUCCESS, - true); - } - break; - - case PORT_STATUS_CHANGE_EVENT: - psc_event = event_data.psc_event; - rh_params = handle_psceg_event(psc_event); - - /* RH port id should be always less than maximum supported port */ - if ((rh_params.rhport < 1U) || (rh_params.rhport > - xhci_handle.xhc_cap_ptr->hcsparams1_params.max_ports)) - { - break; - } - if (rh_params.dev_attach_flag == 1) - { - hcd_event_device_attach(rh_params.rhport, in_isr); - update_device_rh_params(&xhci_handle, rh_params); - } - else if (rh_params.dev_attach_flag == -1) - { - hcd_event_device_remove(rh_params.rhport, in_isr); - } - else - { - /* Nothing to be handled for tinyusb stack */ - } - break; - - case COMMAND_COMPLETION_EVENT: - cc_event = event_data.cc_event; - xhci_command_event_complete(cc_event); - break; - - default: /* do nothing */ - break; - } - -} - -bool hcd_evaluate_xhci_context( void ) -{ - tusb_desc_device_t usb_desc; - TU_ASSERT(tuh_descriptor_get_device_local(device_addr, &usb_desc)); - const uint16_t bcd_usb = usb_desc.bcdUSB; - uint16_t desc_max_pkt_size; - const uint16_t ep0_pkt_size = - (xhci_handle.ip_ctx->xe_context[ 0 ].xec_info & - ~EP_CTX_MAX_PKT_SIZE_MSK) >> EP_CTX_MAX_PKT_SIZE_POS; - - if (bcd_usb >= 0x300U) - { - desc_max_pkt_size = (uint16_t) pow(2, usb_desc.bMaxPacketSize0); - } - else - { - desc_max_pkt_size = usb_desc.bMaxPacketSize0; - } - - if (ep0_pkt_size != desc_max_pkt_size) - { - update_endpoint_packetsize(xhci_handle.ip_ctx, desc_max_pkt_size); - - evaluate_endpoint(&xhci_handle); - - if (wait_for_command_completion_event(&xhci_handle, EVALUATE_CONTEXT_CMD) != 0) - { - return false; - } - - return true; - } - - return true; -} -bool hcd_dwc3_parse_full_conf_descriptor( tusb_desc_configuration_t *desc_cfg ) -{ - const uint8_t usb_speed = xhci_handle.dev_data.dev_speed; - - uint16_t const total_len = tu_le16toh(desc_cfg->wTotalLength); - uint8_t const *desc_end = ((uint8_t const*) desc_cfg) + total_len; - uint8_t const *p_desc = tu_desc_next(desc_cfg); - uint8_t assoc_itf_count = 1; - uint32_t err_flag = 0U; - - usb_endpoint_descriptor_t xhci_ep_desc; - - DEBUG("Parsing Complete Configuration Descriptors"); - - while (p_desc < desc_end) - { - TU_ASSERT(TUSB_DESC_INTERFACE == tu_desc_type(p_desc)); - - tusb_desc_interface_t const *desc_itf = - (tusb_desc_interface_t const*) (uintptr_t) p_desc; - - /* Check if the device belongs to MSC */ - if (desc_itf->bInterfaceClass != 8) - { - PRINT("Device does not support MSC"); - PRINT("Enumeration process completed"); - return false; - } - - uint16_t const drv_len = tu_desc_get_interface_total_len(desc_itf, - assoc_itf_count, (uint16_t) (desc_end - p_desc)); - - tusb_desc_endpoint_t const *ep_desc = - (tusb_desc_endpoint_t const*) (uintptr_t) tu_desc_next( - desc_itf); - - for (int i = 0; i < 2; i++) - { - TU_ASSERT( TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType && - TUSB_XFER_BULK == ep_desc->bmAttributes.xfer); - - xhci_ep_desc.bLength = ep_desc->bLength; - xhci_ep_desc.bDescriptorType = ep_desc->bDescriptorType; - xhci_ep_desc.bEndpointAddress = ep_desc->bEndpointAddress; - (void) memcpy(&xhci_ep_desc.bmAttributes, &ep_desc->bmAttributes, - sizeof(xhci_ep_desc.bmAttributes)); - xhci_ep_desc.wMaxPacketSize = ep_desc->wMaxPacketSize; - xhci_ep_desc.bInterval = ep_desc->bInterval; - - /* USB3.0 Mode */ - if (usb_speed == XHCI_SPEED_SS) - { - ep_desc = - (tusb_desc_endpoint_t const*) (uintptr_t) tu_desc_next( - ep_desc); - - ep_desc = - (tusb_desc_endpoint_t const*) (uintptr_t) tu_desc_next( - ep_desc); - } - else - { - ep_desc = - (tusb_desc_endpoint_t const*) (uintptr_t) tu_desc_next( - ep_desc); - } - - if (xhci_parse_endpoint_descriptor(&xhci_handle, &xhci_ep_desc) != 0) - { - ERROR("Failed to parse endpoint descriptor"); - return false; - } - err_flag = 1U; - } - - p_desc += drv_len; - } - - if (err_flag == 0U) - { - return false; - } - - return true; -} diff --git a/src/portable/socfpga/dwc3/hcd_dwc3.h b/src/portable/socfpga/dwc3/hcd_dwc3.h deleted file mode 100644 index 55ad2ef83..000000000 --- a/src/portable/socfpga/dwc3/hcd_dwc3.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation - * - * SPDX-License-Identifier: MIT-0 - * - * Header file for xHCI implementation - */ - -#ifndef __HCD_SOCFPGA_H__ -#define __HCD_SOCFPGA_H__ - -#include -#include "xhci.h" -#include "xhci_events.h" -#include - -#define XHCI_SPEED_SS (4) -#define XHCI_QUEUE_SZ (10U) - -/* - * @brief deallocate all the usb3 port memory - * @param[in] handle usb3 port reference handle - */ -void dealloc_usb_port(struct xhci_data *xhci_handle); - -/* - * @brief api to check whether the reset process has completed or not - * @param[in] rhport portid of the correspondinf port - * @return - * - true, if operation is successul, - * - false, if the operation fails - */ -bool usb_port_reset_end(uint8_t rhport); - -/* - * @brief common usb api to reset the port - * @param[in] rhport RH port number - */ -void reset_usb_port(uint8_t rhport); - -/* - * @brief initialize the HCD queue - * @return - * 0, if initalization is successful, - * errno, incase of any failure - */ -int init_hcd_params(void); - -/* - * @brief wait for the command completio event - * @param[in] xhci_ptr reference to xhci context data structure - * @param[in[ type to specify the type of command completed by xHCI - * @return - * - NO_ERROR, if command is executed succssfully - * - -1, if command completion event reports failure - */ -int wait_for_command_completion_event(struct xhci_data *xhci_ptr, int type); - -/* - * @brief notify about the completion of command ring operation - * @param[in] command completion event params - */ -void xhci_command_event_complete(xcc_event_t event); - -bool hcd_dwc3_init(uint8_t rhport, const tusb_rhport_init_t* rh_init); -void hcd_dwc3_int_enable (uint8_t rhport); -void hcd_dwc3_int_disable(uint8_t rhport); - -uint32_t hcd_dwc3_frame_number(uint8_t rhport); -bool hcd_dwc3_port_connect_status(uint8_t rhport); -void hcd_dwc3_port_reset(uint8_t rhport); - -void hcd_dwc3_port_reset_end(uint8_t rhport); -tusb_speed_t hcd_dwc3_port_speed_get(uint8_t rhport); - -bool hcd_dwc3_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t* desc_ep); -bool hcd_dwc3_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint32_t buflen); -bool hcd_dwc3_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); -bool hcd_dwc3_setup_send(uint8_t rhport, uint8_t dev_addr, const uint8_t setup_packet[8]); -bool hcd_dwc3_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr); -bool hcd_dwc3_parse_full_conf_descriptor( tusb_desc_configuration_t *desc_cfg ); -void hcd_dwc3_device_close( uint8_t rhport ); - -void hcd_dwc3_int_handler(uint8_t rhport, bool in_isr); - -#endif /* __HCD_SOCFPGA_H__ */ diff --git a/src/portable/socfpga/hcd_socfpga.c b/src/portable/socfpga/hcd_socfpga.c deleted file mode 100644 index 9800b0cde..000000000 --- a/src/portable/socfpga/hcd_socfpga.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - * The MIT License (MIT) - * - * Copyright (c) 2024 Ha Thach (tinyusb.org) - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - * This file is part of the TinyUSB stack. - */ - -#include "tusb_option.h" -#include "hcd_dwc2.h" -#include "hcd_dwc3.h" - -//--------------------------------------------------------------------+ -// Controller API -//--------------------------------------------------------------------+ - -// optional hcd configuration, called by tuh_configure() -// Since this api has no valid definition in both controllers, we keep it untouched -bool hcd_configure(uint8_t rhport, uint32_t cfg_id, const void* cfg_param) { - (void) rhport; - (void) cfg_id; - (void) cfg_param; - - return true; -} - -// Initialize controller to host mode -bool hcd_init(uint8_t rhport, const tusb_rhport_init_t* rh_init) { - (void) rh_init; - bool ret; - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - //USB2.0 dwc2 controller initialization - return hcd_dwc2_init(rhport, rh_init); - } - else - { - //USB3.1 controller initialization - ret = hcd_dwc3_init(rhport, rh_init); - - } - - return ret; -} - -// Enable USB interrupt -void hcd_int_enable (uint8_t rhport) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - hcd_dwc2_int_enable(rhport); - } - else - { - hcd_dwc3_int_enable(rhport); - } -} - -// Disable USB interrupt -void hcd_int_disable(uint8_t rhport) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - hcd_dwc2_int_disable(rhport); - } - else - { - hcd_dwc3_int_disable(rhport); - } -} - -// Get frame number (1ms) -uint32_t hcd_frame_number(uint8_t rhport) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - return hcd_dwc2_frame_number(rhport); - } - else - { - } - return 0; -} - -//--------------------------------------------------------------------+ -// Port API -//--------------------------------------------------------------------+ - -// Get the current connect status of roothub port -bool hcd_port_connect_status(uint8_t rhport) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - return hcd_dwc2_port_connect_status(rhport); - } - else - { - return hcd_dwc3_port_connect_status(rhport); - } - - return true; -} - -// Reset USB bus on the port. Return immediately, bus reset sequence may not be complete. -// Some port would require hcd_port_reset_end() to be invoked after 10ms to complete the reset sequence. -void hcd_port_reset(uint8_t rhport) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - hcd_dwc2_port_reset(rhport); - } - else - { - hcd_dwc3_port_reset(rhport); - } -} - -// Complete bus reset sequence, may be required by some controllers -void hcd_port_reset_end(uint8_t rhport) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - hcd_dwc2_port_reset_end(rhport); - } - else - { - hcd_dwc3_port_reset_end(rhport); - } -} - -// Get port link speed -tusb_speed_t hcd_port_speed_get(uint8_t rhport) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - return hcd_dwc2_port_speed_get(rhport); - } - else - { - return hcd_dwc3_port_speed_get(rhport); - } - return 0; -} - -// HCD closes all opened endpoints belong to this device -void hcd_device_close(uint8_t rhport, uint8_t dev_addr) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - hcd_dwc2_device_close(rhport, dev_addr); - } - else - { - } -} - -//--------------------------------------------------------------------+ -// Endpoints API -//--------------------------------------------------------------------+ - -// Open an endpoint -bool hcd_edpt_open(uint8_t rhport, uint8_t dev_addr, const tusb_desc_endpoint_t* desc_ep) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - return hcd_dwc2_edpt_open(rhport, dev_addr, desc_ep); - } - else - { - } - - return true; -} - -// No definition present in both controller porting layer -bool hcd_edpt_close(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) { - (void) rhport; (void) daddr; (void) ep_addr; - return false; // TODO not implemented yet -} - - -// Submit a transfer, when complete hcd_event_xfer_complete() must be invoked -bool hcd_edpt_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint32_t buflen) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - return hcd_dwc2_edpt_xfer(rhport, dev_addr, ep_addr, buffer, buflen); - } - else - { - return hcd_dwc3_edpt_xfer(rhport, dev_addr, ep_addr, buffer, buflen); - } - return true; -} - -// Abort a queued transfer. Note: it can only abort transfer that has not been started -// Return true if a queued transfer is aborted, false if there is no transfer to abort -bool hcd_edpt_abort_xfer(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - return hcd_dwc2_edpt_abort_xfer(rhport, dev_addr, ep_addr); - } - else - { - } - return true; -} - -// Submit a special transfer to send 8-byte Setup Packet, when complete hcd_event_xfer_complete() must be invoked -bool hcd_setup_send(uint8_t rhport, uint8_t dev_addr, const uint8_t setup_packet[8]) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - return hcd_dwc2_setup_send(rhport, dev_addr, setup_packet); - } - else - { - return hcd_dwc3_setup_send(rhport, dev_addr, setup_packet); - } - return true; -} - -// clear stall, data toggle is also reset to DATA0 -bool hcd_edpt_clear_stall(uint8_t rhport, uint8_t dev_addr, uint8_t ep_addr) { - (void) rhport; - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - return hcd_dwc2_edpt_clear_stall(rhport, dev_addr, ep_addr); - } - else - { - } - - return true; -} - -bool hcd_parse_full_conf_descriptor( tusb_desc_configuration_t *desc_cfg, uint8_t rhport ) -{ - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - return true; - } - else - { - return hcd_dwc3_parse_full_conf_descriptor(desc_cfg); - } - - return true; -} - -void hcd_int_handler(uint8_t rhport, bool in_isr) { - if( rhport == SOCFPGA_USB2_OTG_PORT ) - { - hcd_dwc2_int_handler(rhport, in_isr); - } - else - { - hcd_dwc3_int_handler(rhport, in_isr); - } - -} - From bbef669125fe2f012faebb41f9f4b4956773a4e3 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Thu, 19 Nov 2026 14:01:40 +0530 Subject: [PATCH 08/17] src: portable: xhci: update xhci register map Signed-off-by: Sourav Raj K K --- src/portable/xhci/xhci_type.h | 2945 +++++++++++++++++++++++++++++++++ 1 file changed, 2945 insertions(+) create mode 100644 src/portable/xhci/xhci_type.h diff --git a/src/portable/xhci/xhci_type.h b/src/portable/xhci/xhci_type.h new file mode 100644 index 000000000..76fcf716e --- /dev/null +++ b/src/portable/xhci/xhci_type.h @@ -0,0 +1,2945 @@ +/* + * SPDX-FileCopyrightText: Copyright (C) 2026-2027 Altera Corporation + * + * SPDX-License-Identifier: MIT-0 + * + * Agilex 5 xHCI register bitfields and register map. + * Field positions follow the Agilex 5 HPS register map. + */ + +#ifndef SOCFPGA_XHCI_TYPE_H_ +#define SOCFPGA_XHCI_TYPE_H_ + +#include +#include +#include "tusb_compiler.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Bit fields of CAPLENGTH register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t caplength : 8; // 0..7 + uint32_t reserved_15_8 : 8; // 8..15 + uint32_t hciversion : 16; // 16..31 + }; +} xhci_caplength_t; +TU_VERIFY_STATIC(sizeof(xhci_caplength_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of HCSPARAMS1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t maxslots : 8; // 0..7 + uint32_t maxintrs : 11; // 8..18 + uint32_t reserved_23_19 : 5; // 19..23 + uint32_t maxports : 8; // 24..31 + }; +} xhci_hcsparams1_t; +TU_VERIFY_STATIC(sizeof(xhci_hcsparams1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of HCSPARAMS2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ist : 4; // 0..3 + uint32_t erstmax : 4; // 4..7 + uint32_t reserved_20_8 : 13; // 8..20 + uint32_t maxscratchpadbufs_hi : 5; // 21..25 + uint32_t spr : 1; // 26 + uint32_t maxscratchpadbufs : 5; // 27..31 + }; +} xhci_hcsparams2_t; +TU_VERIFY_STATIC(sizeof(xhci_hcsparams2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of HCSPARAMS3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t u1_device_exit_lat : 8; // 0..7 + uint32_t reserved_15_8 : 8; // 8..15 + uint32_t u2_device_exit_lat : 16; // 16..31 + }; +} xhci_hcsparams3_t; +TU_VERIFY_STATIC(sizeof(xhci_hcsparams3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of HCCPARAMS1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ac64 : 1; // 0 + uint32_t bnc : 1; // 1 + uint32_t csz : 1; // 2 + uint32_t ppc : 1; // 3 + uint32_t pind : 1; // 4 + uint32_t lhrc : 1; // 5 + uint32_t ltc : 1; // 6 + uint32_t nss : 1; // 7 + uint32_t pae : 1; // 8 + uint32_t spc : 1; // 9 + uint32_t sec : 1; // 10 + uint32_t cfc : 1; // 11 + uint32_t maxpsasize : 4; // 12..15 + uint32_t xecp : 16; // 16..31 + }; +} xhci_hccparams1_t; +TU_VERIFY_STATIC(sizeof(xhci_hccparams1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DBOFF register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_1_0 : 2; // 0..1 + uint32_t doorbell_array_offset : 30; // 2..31 + }; +} xhci_dboff_t; +TU_VERIFY_STATIC(sizeof(xhci_dboff_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of RTSOFF register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_4_0 : 5; // 0..4 + uint32_t runtime_reg_space_offset : 27; // 5..31 + }; +} xhci_rtsoff_t; +TU_VERIFY_STATIC(sizeof(xhci_rtsoff_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of HCCPARAMS2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t u3c : 1; // 0 + uint32_t cmc : 1; // 1 + uint32_t fsc : 1; // 2 + uint32_t ctc : 1; // 3 + uint32_t lec : 1; // 4 + uint32_t cic : 1; // 5 + uint32_t etc : 1; // 6 + uint32_t etc_tsc : 1; // 7 + uint32_t reserved_31_8 : 24; // 8..31 + }; +} xhci_hccparams2_t; +TU_VERIFY_STATIC(sizeof(xhci_hccparams2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of USBCMD register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t r_s : 1; // 0 + uint32_t hcrst : 1; // 1 + uint32_t inte : 1; // 2 + uint32_t hsee : 1; // 3 + uint32_t reserved_6_4 : 3; // 4..6 + uint32_t lhcrst : 1; // 7 + uint32_t css : 1; // 8 + uint32_t crs : 1; // 9 + uint32_t ewe : 1; // 10 + uint32_t eu3s : 1; // 11 + uint32_t reserved_12 : 1; // 12 + uint32_t cme : 1; // 13 + uint32_t ete : 1; // 14 + uint32_t reserved_31_15 : 17; // 15..31 + }; +} xhci_usbcmd_t; +TU_VERIFY_STATIC(sizeof(xhci_usbcmd_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of USBSTS register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t hch : 1; // 0 + uint32_t reserved_1 : 1; // 1 + uint32_t hse : 1; // 2 + uint32_t eint : 1; // 3 + uint32_t pcd : 1; // 4 + uint32_t reserved_7_5 : 3; // 5..7 + uint32_t sss : 1; // 8 + uint32_t rss : 1; // 9 + uint32_t sre : 1; // 10 + uint32_t cnr : 1; // 11 + uint32_t hce : 1; // 12 + uint32_t reserved_31_13 : 19; // 13..31 + }; +} xhci_usbsts_t; +TU_VERIFY_STATIC(sizeof(xhci_usbsts_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of PAGESIZE register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t page_size : 16; // 0..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_pagesize_t; +TU_VERIFY_STATIC(sizeof(xhci_pagesize_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DNCTRL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t n0_n15 : 16; // 0..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_dnctrl_t; +TU_VERIFY_STATIC(sizeof(xhci_dnctrl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of CRCR_LO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rcs : 1; // 0 + uint32_t cs : 1; // 1 + uint32_t ca : 1; // 2 + uint32_t crr : 1; // 3 + uint32_t reserved_5_4 : 2; // 4..5 + uint32_t cmd_ring_pntr : 26; // 6..31 + }; +} xhci_crcr_lo_t; +TU_VERIFY_STATIC(sizeof(xhci_crcr_lo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of CRCR_HI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t cmd_ring_pntr : 32; // 0..31 + }; +} xhci_crcr_hi_t; +TU_VERIFY_STATIC(sizeof(xhci_crcr_hi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCBAAP_LO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_5_0 : 6; // 0..5 + uint32_t device_context_baap : 26; // 6..31 + }; +} xhci_dcbaap_lo_t; +TU_VERIFY_STATIC(sizeof(xhci_dcbaap_lo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCBAAP_HI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t device_context_baap : 32; // 0..31 + }; +} xhci_dcbaap_hi_t; +TU_VERIFY_STATIC(sizeof(xhci_dcbaap_hi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of CONFIG register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t maxslotsen : 8; // 0..7 + uint32_t u3e : 1; // 8 + uint32_t cie : 1; // 9 + uint32_t reserved_31_10 : 22; // 10..31 + }; +} xhci_config_t; +TU_VERIFY_STATIC(sizeof(xhci_config_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of PORTSC_20 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ccs : 1; // 0 + uint32_t ped : 1; // 1 + uint32_t reserved_2 : 1; // 2 + uint32_t oca : 1; // 3 + uint32_t pr : 1; // 4 + uint32_t pls : 4; // 5..8 + uint32_t pp : 1; // 9 + uint32_t portspeed : 4; // 10..13 + uint32_t pic : 2; // 14..15 + uint32_t lws : 1; // 16 + uint32_t csc : 1; // 17 + uint32_t pec : 1; // 18 + uint32_t reserved_19 : 1; // 19 + uint32_t occ : 1; // 20 + uint32_t prc : 1; // 21 + uint32_t plc : 1; // 22 + uint32_t reserved_23 : 1; // 23 + uint32_t cas : 1; // 24 + uint32_t wce : 1; // 25 + uint32_t wde : 1; // 26 + uint32_t woe : 1; // 27 + uint32_t reserved_29_28 : 2; // 28..29 + uint32_t dr : 1; // 30 + uint32_t reserved_31 : 1; // 31 + }; +} xhci_portsc_20_t; +TU_VERIFY_STATIC(sizeof(xhci_portsc_20_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of PORTPMSC_20 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t l1s : 3; // 0..2 + uint32_t rwe : 1; // 3 + uint32_t besl : 4; // 4..7 + uint32_t l1dslot : 8; // 8..15 + uint32_t hle : 1; // 16 + uint32_t reserved_27_17 : 11; // 17..27 + uint32_t prttstctrl : 4; // 28..31 + }; +} xhci_portpmsc_20_t; +TU_VERIFY_STATIC(sizeof(xhci_portpmsc_20_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of PORTLI_20 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_portli_20_t; +TU_VERIFY_STATIC(sizeof(xhci_portli_20_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of PORTHLPMC_20 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t hirdm : 2; // 0..1 + uint32_t l1_timeout : 8; // 2..9 + uint32_t besld : 4; // 10..13 + uint32_t reserved_31_14 : 18; // 14..31 + }; +} xhci_porthlpmc_20_t; +TU_VERIFY_STATIC(sizeof(xhci_porthlpmc_20_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of PORTSC_30 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ccs : 1; // 0 + uint32_t ped : 1; // 1 + uint32_t reserved_2 : 1; // 2 + uint32_t oca : 1; // 3 + uint32_t pr : 1; // 4 + uint32_t pls : 4; // 5..8 + uint32_t pp : 1; // 9 + uint32_t portspeed : 4; // 10..13 + uint32_t pic : 2; // 14..15 + uint32_t lws : 1; // 16 + uint32_t csc : 1; // 17 + uint32_t pec : 1; // 18 + uint32_t wrc : 1; // 19 + uint32_t occ : 1; // 20 + uint32_t prc : 1; // 21 + uint32_t plc : 1; // 22 + uint32_t cec : 1; // 23 + uint32_t cas : 1; // 24 + uint32_t wce : 1; // 25 + uint32_t wde : 1; // 26 + uint32_t woe : 1; // 27 + uint32_t reserved_29_28 : 2; // 28..29 + uint32_t dr : 1; // 30 + uint32_t wpr : 1; // 31 + }; +} xhci_portsc_30_t; +TU_VERIFY_STATIC(sizeof(xhci_portsc_30_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of PORTPMSC_30 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t u1_timeout : 8; // 0..7 + uint32_t u2_timeout : 8; // 8..15 + uint32_t fla : 1; // 16 + uint32_t reserved_31_17 : 15; // 17..31 + }; +} xhci_portpmsc_30_t; +TU_VERIFY_STATIC(sizeof(xhci_portpmsc_30_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of PORTLI_30 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t link_error_count : 16; // 0..15 + uint32_t rlc : 4; // 16..19 + uint32_t tlc : 4; // 20..23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} xhci_portli_30_t; +TU_VERIFY_STATIC(sizeof(xhci_portli_30_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of PORTHLPMC_30 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_porthlpmc_30_t; +TU_VERIFY_STATIC(sizeof(xhci_porthlpmc_30_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of USBLEGSUP register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t capability_id : 8; // 0..7 + uint32_t next_capability_pointer : 8; // 8..15 + uint32_t hc_bios_owned : 1; // 16 + uint32_t reserved_23_17 : 7; // 17..23 + uint32_t hc_os_owned : 1; // 24 + uint32_t reserved_31_25 : 7; // 25..31 + }; +} xhci_usblegsup_t; +TU_VERIFY_STATIC(sizeof(xhci_usblegsup_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of USBLEGCTLSTS register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t usb_smi_enable : 1; // 0 + uint32_t reserved_3_1 : 3; // 1..3 + uint32_t smi_on_host_e : 1; // 4 + uint32_t reserved_12_5 : 8; // 5..12 + uint32_t smi_on_os_e : 1; // 13 + uint32_t smi_on_pci_e : 1; // 14 + uint32_t smi_on_bar_e : 1; // 15 + uint32_t smi_on_event : 1; // 16 + uint32_t reserved_19_17 : 3; // 17..19 + uint32_t smi_on_host : 1; // 20 + uint32_t reserved_28_21 : 8; // 21..28 + uint32_t smi_on_os : 1; // 29 + uint32_t smi_on_pci : 1; // 30 + uint32_t smi_on_bar : 1; // 31 + }; +} xhci_usblegctlsts_t; +TU_VERIFY_STATIC(sizeof(xhci_usblegctlsts_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT2_DW0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t capability_id : 8; // 0..7 + uint32_t next_capability_pointer : 8; // 8..15 + uint32_t minor_revision : 8; // 16..23 + uint32_t major_revision : 8; // 24..31 + }; +} xhci_suptprt2_dw0_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt2_dw0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT2_DW1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t name_string : 32; // 0..31 + }; +} xhci_suptprt2_dw1_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt2_dw1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT2_DW2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t compatible_port_offset : 8; // 0..7 + uint32_t compatible_port_count : 8; // 8..15 + uint32_t l1c : 1; // 16 + uint32_t hso : 1; // 17 + uint32_t ihi : 1; // 18 + uint32_t hlc : 1; // 19 + uint32_t blc : 1; // 20 + uint32_t reserved_24_21 : 4; // 21..24 + uint32_t mhd : 3; // 25..27 + uint32_t psic : 4; // 28..31 + }; +} xhci_suptprt2_dw2_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt2_dw2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT2_DW3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t protcl_slt_ty : 5; // 0..4 + uint32_t reserved_31_5 : 27; // 5..31 + }; +} xhci_suptprt2_dw3_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt2_dw3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT3_DW0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t capability_id : 8; // 0..7 + uint32_t next_capability_pointer : 8; // 8..15 + uint32_t minor_revision : 8; // 16..23 + uint32_t major_revision : 8; // 24..31 + }; +} xhci_suptprt3_dw0_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt3_dw0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT3_DW1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t name_string : 32; // 0..31 + }; +} xhci_suptprt3_dw1_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt3_dw1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT3_DW2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t compatible_port_offset : 8; // 0..7 + uint32_t compatible_port_count : 8; // 8..15 + uint32_t reserved_27_16 : 12; // 16..27 + uint32_t psic : 4; // 28..31 + }; +} xhci_suptprt3_dw2_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt3_dw2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT3_DW3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t protcl_slt_ty : 5; // 0..4 + uint32_t reserved_31_5 : 27; // 5..31 + }; +} xhci_suptprt3_dw3_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt3_dw3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT3_DW4 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t psiv : 4; // 0..3 + uint32_t psie : 2; // 4..5 + uint32_t plt : 2; // 6..7 + uint32_t pfd : 1; // 8 + uint32_t reserved_13_9 : 5; // 9..13 + uint32_t lp : 2; // 14..15 + uint32_t psim : 16; // 16..31 + }; +} xhci_suptprt3_dw4_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt3_dw4_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT3_DW5 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t psiv : 4; // 0..3 + uint32_t psie : 2; // 4..5 + uint32_t plt : 2; // 6..7 + uint32_t pfd : 1; // 8 + uint32_t reserved_13_9 : 5; // 9..13 + uint32_t lp : 2; // 14..15 + uint32_t psim : 16; // 16..31 + }; +} xhci_suptprt3_dw5_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt3_dw5_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT3_DW6 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_suptprt3_dw6_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt3_dw6_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of SUPTPRT3_DW7 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_suptprt3_dw7_t; +TU_VERIFY_STATIC(sizeof(xhci_suptprt3_dw7_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCID register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t capability_id : 8; // 0..7 + uint32_t next_capability_pointer : 8; // 8..15 + uint32_t dcerstmax : 5; // 16..20 + uint32_t reserved_31_21 : 11; // 21..31 + }; +} xhci_dcid_t; +TU_VERIFY_STATIC(sizeof(xhci_dcid_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCDB register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_7_0 : 8; // 0..7 + uint32_t dbtarget : 8; // 8..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_dcdb_t; +TU_VERIFY_STATIC(sizeof(xhci_dcdb_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCERSTSZ register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ers_table_size : 16; // 0..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_dcerstsz_t; +TU_VERIFY_STATIC(sizeof(xhci_dcerstsz_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of RSVD0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_rsvd0_t; +TU_VERIFY_STATIC(sizeof(xhci_rsvd0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCERSTBA_LO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_3_0 : 4; // 0..3 + uint32_t ers_table_bar : 28; // 4..31 + }; +} xhci_dcerstba_lo_t; +TU_VERIFY_STATIC(sizeof(xhci_dcerstba_lo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCERSTBA_HI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ers_table_bar : 32; // 0..31 + }; +} xhci_dcerstba_hi_t; +TU_VERIFY_STATIC(sizeof(xhci_dcerstba_hi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCERDP_LO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t desi : 3; // 0..2 + uint32_t reserved_3 : 1; // 3 + uint32_t dequeue_pointer : 28; // 4..31 + }; +} xhci_dcerdp_lo_t; +TU_VERIFY_STATIC(sizeof(xhci_dcerdp_lo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCERDP_HI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t dequeue_pointer : 32; // 0..31 + }; +} xhci_dcerdp_hi_t; +TU_VERIFY_STATIC(sizeof(xhci_dcerdp_hi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCCTRL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t dcr : 1; // 0 + uint32_t lse : 1; // 1 + uint32_t hot : 1; // 2 + uint32_t hit : 1; // 3 + uint32_t drc : 1; // 4 + uint32_t reserved_15_5 : 11; // 5..15 + uint32_t debug_max_burst_size : 8; // 16..23 + uint32_t device_address : 7; // 24..30 + uint32_t dce : 1; // 31 + }; +} xhci_dcctrl_t; +TU_VERIFY_STATIC(sizeof(xhci_dcctrl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCST register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t er : 1; // 0 + uint32_t sbr : 1; // 1 + uint32_t reserved_23_2 : 22; // 2..23 + uint32_t debug_port_number : 8; // 24..31 + }; +} xhci_dcst_t; +TU_VERIFY_STATIC(sizeof(xhci_dcst_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCPORTSC register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ccs : 1; // 0 + uint32_t ped : 1; // 1 + uint32_t reserved_3_2 : 2; // 2..3 + uint32_t pr : 1; // 4 + uint32_t pls : 4; // 5..8 + uint32_t reserved_9 : 1; // 9 + uint32_t portspeed : 4; // 10..13 + uint32_t reserved_16_14 : 3; // 14..16 + uint32_t csc : 1; // 17 + uint32_t reserved_20_18 : 3; // 18..20 + uint32_t prc : 1; // 21 + uint32_t plc : 1; // 22 + uint32_t cec : 1; // 23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} xhci_dcportsc_t; +TU_VERIFY_STATIC(sizeof(xhci_dcportsc_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of RSVD1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_rsvd1_t; +TU_VERIFY_STATIC(sizeof(xhci_rsvd1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCCP_LO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_3_0 : 4; // 0..3 + uint32_t dccpr : 28; // 4..31 + }; +} xhci_dccp_lo_t; +TU_VERIFY_STATIC(sizeof(xhci_dccp_lo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCCP_HI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t dccpr : 32; // 0..31 + }; +} xhci_dccp_hi_t; +TU_VERIFY_STATIC(sizeof(xhci_dccp_hi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCDDI1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t dbcprotocol : 8; // 0..7 + uint32_t reserved_15_8 : 8; // 8..15 + uint32_t vendorid : 16; // 16..31 + }; +} xhci_dcddi1_t; +TU_VERIFY_STATIC(sizeof(xhci_dcddi1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCDDI2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t productid : 16; // 0..15 + uint32_t devicerev : 16; // 16..31 + }; +} xhci_dcddi2_t; +TU_VERIFY_STATIC(sizeof(xhci_dcddi2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of MFINDEX register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t microframe_index : 14; // 0..13 + uint32_t reserved_31_14 : 18; // 14..31 + }; +} xhci_mfindex_t; +TU_VERIFY_STATIC(sizeof(xhci_mfindex_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of RsvdZ register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_rsvdz_t; +TU_VERIFY_STATIC(sizeof(xhci_rsvdz_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of IMAN register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ip : 1; // 0 + uint32_t ie : 1; // 1 + uint32_t reserved_31_2 : 30; // 2..31 + }; +} xhci_iman_t; +TU_VERIFY_STATIC(sizeof(xhci_iman_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of IMOD register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t imodi : 16; // 0..15 + uint32_t imodc : 16; // 16..31 + }; +} xhci_imod_t; +TU_VERIFY_STATIC(sizeof(xhci_imod_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of ERSTSZ register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ers_table_size : 16; // 0..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_erstsz_t; +TU_VERIFY_STATIC(sizeof(xhci_erstsz_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of RsvdP register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_rsvdp_t; +TU_VERIFY_STATIC(sizeof(xhci_rsvdp_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of ERSTBA_LO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_5_0 : 6; // 0..5 + uint32_t ers_table_bar : 26; // 6..31 + }; +} xhci_erstba_lo_t; +TU_VERIFY_STATIC(sizeof(xhci_erstba_lo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of ERSTBA_HI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ers_table_bar : 32; // 0..31 + }; +} xhci_erstba_hi_t; +TU_VERIFY_STATIC(sizeof(xhci_erstba_hi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of ERDP_LO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t desi : 3; // 0..2 + uint32_t ehb : 1; // 3 + uint32_t erd_pntr : 28; // 4..31 + }; +} xhci_erdp_lo_t; +TU_VERIFY_STATIC(sizeof(xhci_erdp_lo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of ERDP_HI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t erd_pntr : 32; // 0..31 + }; +} xhci_erdp_hi_t; +TU_VERIFY_STATIC(sizeof(xhci_erdp_hi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DB register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t db_target : 8; // 0..7 + uint32_t reserved_15_8 : 8; // 8..15 + uint32_t db_stream_id : 16; // 16..31 + }; +} xhci_db_t; +TU_VERIFY_STATIC(sizeof(xhci_db_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GSBUSCFG0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t incrbrstena : 1; // 0 + uint32_t incr4brstena : 1; // 1 + uint32_t incr8brstena : 1; // 2 + uint32_t incr16brstena : 1; // 3 + uint32_t incr32brstena : 1; // 4 + uint32_t incr64brstena : 1; // 5 + uint32_t incr128brstena : 1; // 6 + uint32_t incr256brstena : 1; // 7 + uint32_t reserved_9_8 : 2; // 8..9 + uint32_t desbigend : 1; // 10 + uint32_t datbigend : 1; // 11 + uint32_t reserved_15_12 : 4; // 12..15 + uint32_t deswrreqinfo : 4; // 16..19 + uint32_t datwrreqinfo : 4; // 20..23 + uint32_t desrdreqinfo : 4; // 24..27 + uint32_t datrdreqinfo : 4; // 28..31 + }; +} xhci_gsbuscfg0_t; +TU_VERIFY_STATIC(sizeof(xhci_gsbuscfg0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GSBUSCFG1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_7_0 : 8; // 0..7 + uint32_t pipetranslimit : 4; // 8..11 + uint32_t en1kpage : 1; // 12 + uint32_t extdpipetranslimit : 4; // 13..16 + uint32_t reserved_31_17 : 15; // 17..31 + }; +} xhci_gsbuscfg1_t; +TU_VERIFY_STATIC(sizeof(xhci_gsbuscfg1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXTHRCFG register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t usbmaxtxburstsize_prd : 5; // 0..4 + uint32_t usbtxthrnumpkt_prd : 5; // 5..9 + uint32_t usbtxthrnumpktsel_prd : 1; // 10 + uint32_t reserved_12_11 : 2; // 11..12 + uint32_t usbtxthrnumpkt_hs_prd : 2; // 13..14 + uint32_t usbtxthrnumpktsel_hs_prd : 1; // 15 + uint32_t usbmaxtxburstsize : 5; // 16..20 + uint32_t usbtxpktcnt : 5; // 21..25 + uint32_t usbtxpktcntsel : 1; // 26 + uint32_t reserved_31_27 : 5; // 27..31 + }; +} xhci_gtxthrcfg_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxthrcfg_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GRXTHRCFG register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t usbmaxrxburstsize_prd : 5; // 0..4 + uint32_t usbrxthrnumpkt_prd : 5; // 5..9 + uint32_t usbrxthrnumpktsel_prd : 1; // 10 + uint32_t reserved_12_11 : 2; // 11..12 + uint32_t usbrxthrnumpkt_hs_prd : 2; // 13..14 + uint32_t usbrxthrnumpktsel_hs_prd : 1; // 15 + uint32_t usbmaxrxburstsize : 5; // 16..20 + uint32_t usbrxpktcnt : 5; // 21..25 + uint32_t usbrxpktcntsel : 1; // 26 + uint32_t reserved_31_27 : 5; // 27..31 + }; +} xhci_grxthrcfg_t; +TU_VERIFY_STATIC(sizeof(xhci_grxthrcfg_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GCTL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t dsblclkgtng : 1; // 0 + uint32_t gblhibernationen : 1; // 1 + uint32_t u2exit_lfps : 1; // 2 + uint32_t disscramble : 1; // 3 + uint32_t scaledown : 2; // 4..5 + uint32_t ramclksel : 2; // 6..7 + uint32_t debugattach : 1; // 8 + uint32_t u1u2timerscale : 1; // 9 + uint32_t reserved_10 : 1; // 10 + uint32_t coresoftreset : 1; // 11 + uint32_t prtcapdir : 2; // 12..13 + uint32_t frmscldwn : 2; // 14..15 + uint32_t u2rstecn : 1; // 16 + uint32_t bypssetaddr : 1; // 17 + uint32_t masterfiltbypass : 1; // 18 + uint32_t pwrdnscale : 13; // 19..31 + }; +} xhci_gctl_t; +TU_VERIFY_STATIC(sizeof(xhci_gctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GPMSTS register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t u2wakeup : 10; // 0..9 + uint32_t reserved_11_10 : 2; // 10..11 + uint32_t u3wakeup : 5; // 12..16 + uint32_t reserved_27_17 : 11; // 17..27 + uint32_t portsel : 4; // 28..31 + }; +} xhci_gpmsts_t; +TU_VERIFY_STATIC(sizeof(xhci_gpmsts_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GSTS register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t curmod : 2; // 0..1 + uint32_t reserved_3_2 : 2; // 2..3 + uint32_t buserraddrvld : 1; // 4 + uint32_t csrtimeout : 1; // 5 + uint32_t device_ip : 1; // 6 + uint32_t host_ip : 1; // 7 + uint32_t reserved_19_8 : 12; // 8..19 + uint32_t cbelt : 12; // 20..31 + }; +} xhci_gsts_t; +TU_VERIFY_STATIC(sizeof(xhci_gsts_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUCTL1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t loa_filter_en : 1; // 0 + uint32_t reserved_1 : 1; // 1 + uint32_t hc_parchk_disable : 1; // 2 + uint32_t hc_errata_enable : 1; // 3 + uint32_t l1_susp_thrld_for_host : 4; // 4..7 + uint32_t l1_susp_thrld_en_for_host : 1; // 8 + uint32_t reserved_9 : 1; // 9 + uint32_t resume_opmode_hs_host : 1; // 10 + uint32_t disrefclkgtng : 1; // 11 + uint32_t disusb2refclkgtng : 1; // 12 + uint32_t hw_lpm_hle_disable : 1; // 13 + uint32_t hw_lpm_cap_disable : 1; // 14 + uint32_t reserved_20_15 : 6; // 15..20 + uint32_t ip_gap_add_on : 3; // 21..23 + uint32_t dev_l1_exit_by_hw : 1; // 24 + uint32_t reserved_26_25 : 2; // 25..26 + uint32_t dev_trb_out_spr_ind : 1; // 27 + uint32_t tx_ipgap_linecheck_dis : 1; // 28 + uint32_t filter_se0_fsls_eop : 1; // 29 + uint32_t ds_rxdet_max_tout_ctrl : 1; // 30 + uint32_t dev_decouple_l1l2_evt : 1; // 31 + }; +} xhci_guctl1_t; +TU_VERIFY_STATIC(sizeof(xhci_guctl1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of USB31_IP_NAME register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t synopsysip : 32; // 0..31 + }; +} xhci_usb31_ip_name_t; +TU_VERIFY_STATIC(sizeof(xhci_usb31_ip_name_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GGPIO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gpi : 16; // 0..15 + uint32_t gpo : 16; // 16..31 + }; +} xhci_ggpio_t; +TU_VERIFY_STATIC(sizeof(xhci_ggpio_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUID register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t userid : 32; // 0..31 + }; +} xhci_guid_t; +TU_VERIFY_STATIC(sizeof(xhci_guid_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUCTL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t dtout : 11; // 0..10 + uint32_t insrtextrfsbodi : 1; // 11 + uint32_t extcapsuppten : 1; // 12 + uint32_t reserved_13 : 1; // 13 + uint32_t usbhstinimmretryen : 1; // 14 + uint32_t reserved_15 : 1; // 15 + uint32_t resbwhseps : 1; // 16 + uint32_t sprsctrltransen : 1; // 17 + uint32_t en_extd_tbc_cap : 1; // 18 + uint32_t ignorehcetimeout : 1; // 19 + uint32_t dmaignorehce : 1; // 20 + uint32_t noextrdl : 1; // 21 + uint32_t refclkper : 10; // 22..31 + }; +} xhci_guctl_t; +TU_VERIFY_STATIC(sizeof(xhci_guctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GBUSERRADDRLO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t buserraddr : 32; // 0..31 + }; +} xhci_gbuserraddrlo_t; +TU_VERIFY_STATIC(sizeof(xhci_gbuserraddrlo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GBUSERRADDRHI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t buserraddr : 32; // 0..31 + }; +} xhci_gbuserraddrhi_t; +TU_VERIFY_STATIC(sizeof(xhci_gbuserraddrhi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GPRTBIMAPLO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum1 : 4; // 0..3 + uint32_t binum2 : 4; // 4..7 + uint32_t binum3 : 4; // 8..11 + uint32_t binum4 : 4; // 12..15 + uint32_t binum5 : 4; // 16..19 + uint32_t binum6 : 4; // 20..23 + uint32_t binum7 : 4; // 24..27 + uint32_t binum8 : 4; // 28..31 + }; +} xhci_gprtbimaplo_t; +TU_VERIFY_STATIC(sizeof(xhci_gprtbimaplo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GPRTBIMAPHI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum9 : 4; // 0..3 + uint32_t binum10 : 4; // 4..7 + uint32_t binum11 : 4; // 8..11 + uint32_t binum12 : 4; // 12..15 + uint32_t binum13 : 4; // 16..19 + uint32_t binum14 : 4; // 20..23 + uint32_t binum15 : 4; // 24..27 + uint32_t reserved_31_28 : 4; // 28..31 + }; +} xhci_gprtbimaphi_t; +TU_VERIFY_STATIC(sizeof(xhci_gprtbimaphi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GHWPARAMS0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams0_2_0 : 3; // 0..2 + uint32_t ghwparams0_5_3 : 3; // 3..5 + uint32_t ghwparams0_7_6 : 2; // 6..7 + uint32_t ghwparams0_15_8 : 8; // 8..15 + uint32_t ghwparams0_23_16 : 8; // 16..23 + uint32_t ghwparams0_31_24 : 8; // 24..31 + }; +} xhci_ghwparams0_t; +TU_VERIFY_STATIC(sizeof(xhci_ghwparams0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GHWPARAMS1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams1_3_0 : 4; // 0..3 + uint32_t ghwparams1_7_4 : 4; // 4..7 + uint32_t ghwparams1_10_8 : 3; // 8..10 + uint32_t ghwparams1_13_11 : 3; // 11..13 + uint32_t ghwparams1_16_14 : 3; // 14..16 + uint32_t ghwparams1_22_17 : 6; // 17..22 + uint32_t ghwparams1_23 : 1; // 23 + uint32_t ghwparams1_25_24 : 2; // 24..25 + uint32_t ghwparams1_26 : 1; // 26 + uint32_t ghwparams1_27 : 1; // 27 + uint32_t ghwparams1_28 : 1; // 28 + uint32_t ghwparams1_29 : 1; // 29 + uint32_t ghwparams1_30 : 1; // 30 + uint32_t ghwparams1_31 : 1; // 31 + }; +} xhci_ghwparams1_t; +TU_VERIFY_STATIC(sizeof(xhci_ghwparams1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GHWPARAMS2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams2_31_0 : 32; // 0..31 + }; +} xhci_ghwparams2_t; +TU_VERIFY_STATIC(sizeof(xhci_ghwparams2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GHWPARAMS3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams3_1_0 : 2; // 0..1 + uint32_t ghwparams3_3_2 : 2; // 2..3 + uint32_t ghwparams3_5_4 : 2; // 4..5 + uint32_t ghwparams3_7_6 : 2; // 6..7 + uint32_t ghwparams3_9_8 : 2; // 8..9 + uint32_t ghwparams3_10 : 1; // 10 + uint32_t ghwparams3_11 : 1; // 11 + uint32_t ghwparams3_17_12 : 6; // 12..17 + uint32_t ghwparams3_22_18 : 5; // 18..22 + uint32_t ghwparams3_30_23 : 8; // 23..30 + uint32_t ghwparams3_31 : 1; // 31 + }; +} xhci_ghwparams3_t; +TU_VERIFY_STATIC(sizeof(xhci_ghwparams3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GHWPARAMS4 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams4_5_0 : 6; // 0..5 + uint32_t ghwparams4_12_6 : 7; // 6..12 + uint32_t ghwparams4_16_13 : 4; // 13..16 + uint32_t ghwparams4_20_17 : 4; // 17..20 + uint32_t ghwparams4_21 : 1; // 21 + uint32_t ghwparams4_22 : 1; // 22 + uint32_t ghwparams4_27_23 : 5; // 23..27 + uint32_t ghwparams4_31_28 : 4; // 28..31 + }; +} xhci_ghwparams4_t; +TU_VERIFY_STATIC(sizeof(xhci_ghwparams4_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GHWPARAMS5 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams5_4_0 : 5; // 0..4 + uint32_t ghwparams5_10_5 : 6; // 5..10 + uint32_t ghwparams5_16_11 : 6; // 11..16 + uint32_t ghwparams5_22_17 : 6; // 17..22 + uint32_t ghwparams5_28_23 : 6; // 23..28 + uint32_t ghwparams5_31_29 : 3; // 29..31 + }; +} xhci_ghwparams5_t; +TU_VERIFY_STATIC(sizeof(xhci_ghwparams5_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GHWPARAMS6 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams6_5_0 : 6; // 0..5 + uint32_t ghwparams6_6 : 1; // 6 + uint32_t ghwparams6_7 : 1; // 7 + uint32_t ghwparams6_9_8 : 2; // 8..9 + uint32_t ghwparams6_14_10 : 5; // 10..14 + uint32_t busfltrssupport : 1; // 15 + uint32_t ghwparams6_31_16 : 16; // 16..31 + }; +} xhci_ghwparams6_t; +TU_VERIFY_STATIC(sizeof(xhci_ghwparams6_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GHWPARAMS7 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams7_15_0 : 16; // 0..15 + uint32_t ghwparams7_31_16 : 16; // 16..31 + }; +} xhci_ghwparams7_t; +TU_VERIFY_STATIC(sizeof(xhci_ghwparams7_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GDBGFIFOSPACE register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t fifo_queue_select : 9; // 0..8 + uint32_t reserved_15_9 : 7; // 9..15 + uint32_t space_available : 16; // 16..31 + }; +} xhci_gdbgfifospace_t; +TU_VERIFY_STATIC(sizeof(xhci_gdbgfifospace_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GBMUCTL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_0 : 1; // 0 + uint32_t active_id_en : 1; // 1 + uint32_t axi_storder_en : 1; // 2 + uint32_t reserved_4_3 : 2; // 3..4 + uint32_t separate_psq_en : 1; // 5 + uint32_t reserved_31_6 : 26; // 6..31 + }; +} xhci_gbmuctl_t; +TU_VERIFY_STATIC(sizeof(xhci_gbmuctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GDBGBMU register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t bmu_ccu : 4; // 0..3 + uint32_t bmu_dcu : 4; // 4..7 + uint32_t bmu_bcu : 24; // 8..31 + }; +} xhci_gdbgbmu_t; +TU_VERIFY_STATIC(sizeof(xhci_gdbgbmu_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GDBGLSPMUX register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lspselect : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t logic_analyzer_trace : 8; // 16..23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} xhci_gdbglspmux_t; +TU_VERIFY_STATIC(sizeof(xhci_gdbglspmux_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GDBGLSP register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lspdebug : 32; // 0..31 + }; +} xhci_gdbglsp_t; +TU_VERIFY_STATIC(sizeof(xhci_gdbglsp_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GDBGEPINFO0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t epdebug : 32; // 0..31 + }; +} xhci_gdbgepinfo0_t; +TU_VERIFY_STATIC(sizeof(xhci_gdbgepinfo0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GDBGEPINFO1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t epdebug : 32; // 0..31 + }; +} xhci_gdbgepinfo1_t; +TU_VERIFY_STATIC(sizeof(xhci_gdbgepinfo1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GPRTBIMAP_HSLO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum1 : 4; // 0..3 + uint32_t binum2 : 4; // 4..7 + uint32_t binum3 : 4; // 8..11 + uint32_t binum4 : 4; // 12..15 + uint32_t binum5 : 4; // 16..19 + uint32_t binum6 : 4; // 20..23 + uint32_t binum7 : 4; // 24..27 + uint32_t binum8 : 4; // 28..31 + }; +} xhci_gprtbimap_hslo_t; +TU_VERIFY_STATIC(sizeof(xhci_gprtbimap_hslo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GPRTBIMAP_HSHI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum9 : 4; // 0..3 + uint32_t binum10 : 4; // 4..7 + uint32_t binum11 : 4; // 8..11 + uint32_t binum12 : 4; // 12..15 + uint32_t binum13 : 4; // 16..19 + uint32_t binum14 : 4; // 20..23 + uint32_t binum15 : 4; // 24..27 + uint32_t reserved_31_28 : 4; // 28..31 + }; +} xhci_gprtbimap_hshi_t; +TU_VERIFY_STATIC(sizeof(xhci_gprtbimap_hshi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GPRTBIMAP_FSLO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum1 : 4; // 0..3 + uint32_t binum2 : 4; // 4..7 + uint32_t binum3 : 4; // 8..11 + uint32_t binum4 : 4; // 12..15 + uint32_t binum5 : 4; // 16..19 + uint32_t binum6 : 4; // 20..23 + uint32_t binum7 : 4; // 24..27 + uint32_t binum8 : 4; // 28..31 + }; +} xhci_gprtbimap_fslo_t; +TU_VERIFY_STATIC(sizeof(xhci_gprtbimap_fslo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GPRTBIMAP_FSHI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t binum9 : 4; // 0..3 + uint32_t binum10 : 4; // 4..7 + uint32_t binum11 : 4; // 8..11 + uint32_t binum12 : 4; // 12..15 + uint32_t binum13 : 4; // 16..19 + uint32_t binum14 : 4; // 20..23 + uint32_t binum15 : 4; // 24..27 + uint32_t reserved_31_28 : 4; // 28..31 + }; +} xhci_gprtbimap_fshi_t; +TU_VERIFY_STATIC(sizeof(xhci_gprtbimap_fshi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GHMSOCBWOR register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ovrd_soc_rd_uf_kb_bandwidth : 15; // 0..14 + uint32_t ovrd_soc_wr_uf_kb_bandwidth : 15; // 15..29 + uint32_t ovrd_common_soc_rd_wr : 1; // 30 + uint32_t ovrd_port_soc_bw : 1; // 31 + }; +} xhci_ghmsocbwor_t; +TU_VERIFY_STATIC(sizeof(xhci_ghmsocbwor_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of USB31_VER_NUMBER register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t version_num : 32; // 0..31 + }; +} xhci_usb31_ver_number_t; +TU_VERIFY_STATIC(sizeof(xhci_usb31_ver_number_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of USB31_VER_TYPE register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t versiontype : 32; // 0..31 + }; +} xhci_usb31_ver_type_t; +TU_VERIFY_STATIC(sizeof(xhci_usb31_ver_type_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GSYSBLKWINCTRL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t beginining_no_blocking_time : 8; // 0..7 + uint32_t end_no_blocking_time : 8; // 8..15 + uint32_t reserved_23_16 : 8; // 16..23 + uint32_t erst_prefetching_watermark : 5; // 24..28 + uint32_t erst_prefetching_en : 1; // 29 + uint32_t disable_no_blocking_window : 1; // 30 + uint32_t sys_blocking_ok_all_the_time : 1; // 31 + }; +} xhci_gsysblkwinctrl_t; +TU_VERIFY_STATIC(sizeof(xhci_gsysblkwinctrl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GPCIEL1EXTLAT register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t pcie_l1_exit_latency : 12; // 0..11 + uint32_t reserved_29_12 : 18; // 12..29 + uint32_t pcie_l1_exit_mode_ctrl : 2; // 30..31 + }; +} xhci_gpciel1extlat_t; +TU_VERIFY_STATIC(sizeof(xhci_gpciel1extlat_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUSB2PHYCFG register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t toutcal : 3; // 0..2 + uint32_t phyif : 1; // 3 + uint32_t ulpi_utmi_sel : 1; // 4 + uint32_t fsintf : 1; // 5 + uint32_t suspendusb20 : 1; // 6 + uint32_t physel : 1; // 7 + uint32_t enblslpm : 1; // 8 + uint32_t xcvrdly : 1; // 9 + uint32_t usbtrdtim : 4; // 10..13 + uint32_t eusb2opmode : 1; // 14 + uint32_t ulpiautores : 1; // 15 + uint32_t reserved_16 : 1; // 16 + uint32_t ulpiextvbusdrv : 1; // 17 + uint32_t ulpiextvbusindiactor : 1; // 18 + uint32_t lsipd : 3; // 19..21 + uint32_t lstrd : 3; // 22..24 + uint32_t ovrd_fsls_disc_time : 1; // 25 + uint32_t inv_sel_hsic : 1; // 26 + uint32_t hsic_con_width_adj : 2; // 27..28 + uint32_t ulpi_lpm_with_opmode_chk : 1; // 29 + uint32_t reserved_30 : 1; // 30 + uint32_t physoftrst : 1; // 31 + }; +} xhci_gusb2phycfg_t; +TU_VERIFY_STATIC(sizeof(xhci_gusb2phycfg_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUSB2PHYACC_ULPI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t regdata : 8; // 0..7 + uint32_t extregaddr : 8; // 8..15 + uint32_t regaddr : 6; // 16..21 + uint32_t regwr : 1; // 22 + uint32_t vstsbsy : 1; // 23 + uint32_t vstsdone : 1; // 24 + uint32_t newregreq : 1; // 25 + uint32_t disuipidrvr : 1; // 26 + uint32_t reserved_31_27 : 5; // 27..31 + }; +} xhci_gusb2phyacc_ulpi_t; +TU_VERIFY_STATIC(sizeof(xhci_gusb2phyacc_ulpi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUSB3PIPECTL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t elastic_buffer_mode : 1; // 0 + uint32_t ss_tx_de_emphasis : 2; // 1..2 + uint32_t tx_margin : 3; // 3..5 + uint32_t tx_swing : 1; // 6 + uint32_t reserved_7 : 1; // 7 + uint32_t rx_detect_to_polling_lfps_control : 1; // 8 + uint32_t lfpsfilter : 1; // 9 + uint32_t p3exsigp2 : 1; // 10 + uint32_t p3p2tranok : 1; // 11 + uint32_t lfpsp0algn : 1; // 12 + uint32_t skiprxdet : 1; // 13 + uint32_t abortrxdetinu2 : 1; // 14 + uint32_t datwidth : 2; // 15..16 + uint32_t suspendenable : 1; // 17 + uint32_t delayp1trans : 1; // 18 + uint32_t delayp1p2p3 : 3; // 19..21 + uint32_t disrxdetu3rxdet : 1; // 22 + uint32_t startrxdetu3rxdet : 1; // 23 + uint32_t request_p1p2p3 : 1; // 24 + uint32_t u1u2exitfail_to_recov : 1; // 25 + uint32_t ping_enhancement_en : 1; // 26 + uint32_t ux_exit_in_px : 1; // 27 + uint32_t disrxdetp3 : 1; // 28 + uint32_t u2p3ok : 1; // 29 + uint32_t hstprtcmpl : 1; // 30 + uint32_t physoftrst : 1; // 31 + }; +} xhci_gusb3pipectl_t; +TU_VERIFY_STATIC(sizeof(xhci_gusb3pipectl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz0_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz1_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz2_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz3_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ4 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz4_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz4_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ5 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz5_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz5_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ6 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz6_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz6_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ7 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz7_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz7_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ8 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz8_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz8_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ9 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz9_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz9_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ10 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz10_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz10_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ11 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz11_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz11_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ12 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz12_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz12_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ13 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz13_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz13_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ14 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz14_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz14_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOSIZ15 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t txfstaddr_n : 16; // 16..31 + }; +} xhci_gtxfifosiz15_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifosiz15_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GRXFIFOSIZ0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} xhci_grxfifosiz0_t; +TU_VERIFY_STATIC(sizeof(xhci_grxfifosiz0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GRXFIFOSIZ1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} xhci_grxfifosiz1_t; +TU_VERIFY_STATIC(sizeof(xhci_grxfifosiz1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GRXFIFOSIZ2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} xhci_grxfifosiz2_t; +TU_VERIFY_STATIC(sizeof(xhci_grxfifosiz2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GRXFIFOSIZ3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} xhci_grxfifosiz3_t; +TU_VERIFY_STATIC(sizeof(xhci_grxfifosiz3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GRXFIFOSIZ4 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} xhci_grxfifosiz4_t; +TU_VERIFY_STATIC(sizeof(xhci_grxfifosiz4_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GRXFIFOSIZ5 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rxfdep_n : 15; // 0..14 + uint32_t reserved_15 : 1; // 15 + uint32_t rxfstaddr_n : 16; // 16..31 + }; +} xhci_grxfifosiz5_t; +TU_VERIFY_STATIC(sizeof(xhci_grxfifosiz5_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GEVNTADRLO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t evntadrlo : 32; // 0..31 + }; +} xhci_gevntadrlo_t; +TU_VERIFY_STATIC(sizeof(xhci_gevntadrlo_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GEVNTADRHI register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t evntadrhi : 32; // 0..31 + }; +} xhci_gevntadrhi_t; +TU_VERIFY_STATIC(sizeof(xhci_gevntadrhi_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GEVNTSIZ register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t eventsiz : 16; // 0..15 + uint32_t reserved_30_16 : 15; // 16..30 + uint32_t evntintrptmask : 1; // 31 + }; +} xhci_gevntsiz_t; +TU_VERIFY_STATIC(sizeof(xhci_gevntsiz_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GEVNTCOUNT register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t evntcount : 16; // 0..15 + uint32_t reserved_30_16 : 15; // 16..30 + uint32_t evnt_handler_busy : 1; // 31 + }; +} xhci_gevntcount_t; +TU_VERIFY_STATIC(sizeof(xhci_gevntcount_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GHWPARAMS8 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ghwparams8_32_0 : 32; // 0..31 + }; +} xhci_ghwparams8_t; +TU_VERIFY_STATIC(sizeof(xhci_ghwparams8_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GSMACCTL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t single_tbt_req : 1; // 0 + uint32_t ignore_babble : 1; // 1 + uint32_t host_mask_nump0 : 1; // 2 + uint32_t single_psqdir_en : 1; // 3 + uint32_t reserved_15_4 : 12; // 4..15 + uint32_t hostout_single_en : 1; // 16 + uint32_t hostin_signle_en : 1; // 17 + uint32_t reserved_25_18 : 8; // 18..25 + uint32_t dbg_ptl_addr : 4; // 26..29 + uint32_t dbg_tis_index : 2; // 30..31 + }; +} xhci_gsmacctl_t; +TU_VERIFY_STATIC(sizeof(xhci_gsmacctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUCTL2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t scheddule_lt_thr : 1; // 0 + uint32_t max_reisu_cnt : 2; // 1..2 + uint32_t svc_opp_per_fsls : 2; // 3..4 + uint32_t svc_opp_per_hs : 2; // 5..6 + uint32_t svc_opp_per_ss : 2; // 7..8 + uint32_t svc_opp_per_ssp : 2; // 9..10 + uint32_t periodic_txdma_uf_thr : 7; // 11..17 + uint32_t async_uf_thr : 7; // 18..24 + uint32_t periodic_uf_thr : 7; // 25..31 + }; +} xhci_guctl2_t; +TU_VERIFY_STATIC(sizeof(xhci_guctl2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUCTL3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t periodic_uf_thr_fsls : 7; // 0..6 + uint32_t intr_ep_ping_enable : 1; // 7 + uint32_t barb_burst_enable : 1; // 8 + uint32_t svc_opp_per_hs_sep : 4; // 9..12 + uint32_t reserved_15_13 : 3; // 13..15 + uint32_t usb20_retry_disable : 1; // 16 + uint32_t reserved_17 : 1; // 17 + uint32_t disextbusclkgt : 1; // 18 + uint32_t disextbusclkgt_u1u2l1 : 1; // 19 + uint32_t ssbi_single_ep_mode_disable : 1; // 20 + uint32_t block_concurrent_in_ctrl_xfers : 1; // 21 + uint32_t cfgep_cmd_switching_time_ctrl : 3; // 22..24 + uint32_t reserved_31_25 : 7; // 25..31 + }; +} xhci_guctl3_t; +TU_VERIFY_STATIC(sizeof(xhci_guctl3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOPRIDEV register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gtxfifopridev : 16; // 0..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_gtxfifopridev_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifopridev_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GTXFIFOPRIHST register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gtxfifoprihst : 7; // 0..6 + uint32_t reserved_31_7 : 25; // 7..31 + }; +} xhci_gtxfifoprihst_t; +TU_VERIFY_STATIC(sizeof(xhci_gtxfifoprihst_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GRXFIFOPRIHST register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t grxfifoprihst : 6; // 0..5 + uint32_t reserved_31_6 : 26; // 6..31 + }; +} xhci_grxfifoprihst_t; +TU_VERIFY_STATIC(sizeof(xhci_grxfifoprihst_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GFIFOPRIDBC register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gfifopridbc : 2; // 0..1 + uint32_t reserved_31_2 : 30; // 2..31 + }; +} xhci_gfifopridbc_t; +TU_VERIFY_STATIC(sizeof(xhci_gfifopridbc_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GDMAHLRATIO register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t hsttxfifo_dma : 5; // 0..4 + uint32_t reserved_7_5 : 3; // 5..7 + uint32_t hstrxfifo_dma : 5; // 8..12 + uint32_t reserved_15_13 : 3; // 13..15 + uint32_t hsttxfifo_mac : 5; // 16..20 + uint32_t reserved_23_21 : 3; // 21..23 + uint32_t hstrxfifo_mac : 5; // 24..28 + uint32_t reserved_31_29 : 3; // 29..31 + }; +} xhci_gdmahlratio_t; +TU_VERIFY_STATIC(sizeof(xhci_gdmahlratio_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GOSTDDMA_ASYNC register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ostdtx_async : 8; // 0..7 + uint32_t ostdtx_async_inactive : 8; // 8..15 + uint32_t ostdtx_async_active : 8; // 16..23 + uint32_t ostdrx_async : 8; // 24..31 + }; +} xhci_gostddma_async_t; +TU_VERIFY_STATIC(sizeof(xhci_gostddma_async_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GOSTDDMA_PRD register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ostdtx_prd : 8; // 0..7 + uint32_t ostdtx_prd_inactive : 8; // 8..15 + uint32_t ostdtx_prd_active : 8; // 16..23 + uint32_t ostdrx_prd : 8; // 24..31 + }; +} xhci_gostddma_prd_t; +TU_VERIFY_STATIC(sizeof(xhci_gostddma_prd_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GFLADJ register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gfladj_30mhz : 6; // 0..5 + uint32_t reserved_6 : 1; // 6 + uint32_t gfladj_30mhz_sdbnd_sel : 1; // 7 + uint32_t gfladj_refclk_fladj : 14; // 8..21 + uint32_t reserved_22 : 1; // 22 + uint32_t gfladj_refclk_lpm_sel : 1; // 23 + uint32_t gfladj_refclk_240mhz_decr : 7; // 24..30 + uint32_t gfladj_refclk_240mhzdecr_pls1 : 1; // 31 + }; +} xhci_gfladj_t; +TU_VERIFY_STATIC(sizeof(xhci_gfladj_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUCTL4 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t csr_timeout_vl : 17; // 0..16 + uint32_t loa_eop_check_clks_byte : 2; // 17..18 + uint32_t loa_eop_check_clks_word : 2; // 19..20 + uint32_t reserved_25_21 : 5; // 21..25 + uint32_t ssp_bwd_ovhd_adj : 5; // 26..30 + uint32_t reserved_31 : 1; // 31 + }; +} xhci_guctl4_t; +TU_VERIFY_STATIC(sizeof(xhci_guctl4_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUCTL5 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_guctl5_t; +TU_VERIFY_STATIC(sizeof(xhci_guctl5_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GUSB2RHBCTL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ovrd_l1timeout : 4; // 0..3 + uint32_t ovrd_hs_int_pkt_del : 8; // 4..11 + uint32_t ovrd_fs_int_pkt_del : 8; // 12..19 + uint32_t reserved_31_20 : 12; // 20..31 + }; +} xhci_gusb2rhbctl_t; +TU_VERIFY_STATIC(sizeof(xhci_gusb2rhbctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCFG register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t devspd : 3; // 0..2 + uint32_t devaddr : 7; // 3..9 + uint32_t reserved_11_10 : 2; // 10..11 + uint32_t intrnum : 5; // 12..16 + uint32_t nump : 5; // 17..21 + uint32_t lpmcap : 1; // 22 + uint32_t ignstrmpp : 1; // 23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} xhci_dcfg_t; +TU_VERIFY_STATIC(sizeof(xhci_dcfg_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCTL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_0 : 1; // 0 + uint32_t tstctl : 4; // 1..4 + uint32_t ulstchngreq : 4; // 5..8 + uint32_t acceptu1ena : 1; // 9 + uint32_t initu1ena : 1; // 10 + uint32_t acceptu2ena : 1; // 11 + uint32_t initu2ena : 1; // 12 + uint32_t reserved_15_13 : 3; // 13..15 + uint32_t css : 1; // 16 + uint32_t crs : 1; // 17 + uint32_t l1hibernationen : 1; // 18 + uint32_t keepconnect : 1; // 19 + uint32_t lpm_nyet_thres : 4; // 20..23 + uint32_t hirdthres : 5; // 24..28 + uint32_t reserved_29 : 1; // 29 + uint32_t csftrst : 1; // 30 + uint32_t run_stop : 1; // 31 + }; +} xhci_dctl_t; +TU_VERIFY_STATIC(sizeof(xhci_dctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DEVTEN register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t dissconnevten : 1; // 0 + uint32_t usbrstevten : 1; // 1 + uint32_t connectdoneevten : 1; // 2 + uint32_t ulstcngen : 1; // 3 + uint32_t wkupevten : 1; // 4 + uint32_t hibernationreqevten : 1; // 5 + uint32_t u3l2l1suspen : 1; // 6 + uint32_t softevten : 1; // 7 + uint32_t l1suspen : 1; // 8 + uint32_t errticerrevten : 1; // 9 + uint32_t reserved_11_10 : 2; // 10..11 + uint32_t vendevtstrcvden : 1; // 12 + uint32_t reserved_13 : 1; // 13 + uint32_t l1wkupevten : 1; // 14 + uint32_t ldmevten : 1; // 15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_devten_t; +TU_VERIFY_STATIC(sizeof(xhci_devten_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DSTS register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t connectspd : 3; // 0..2 + uint32_t soffn : 14; // 3..16 + uint32_t rxfifoempty : 1; // 17 + uint32_t usblnkst : 4; // 18..21 + uint32_t devctrlhlt : 1; // 22 + uint32_t coreidle : 1; // 23 + uint32_t sss : 1; // 24 + uint32_t rss : 1; // 25 + uint32_t reserved_27_26 : 2; // 26..27 + uint32_t sre : 1; // 28 + uint32_t dcnrd : 1; // 29 + uint32_t reserved_31_30 : 2; // 30..31 + }; +} xhci_dsts_t; +TU_VERIFY_STATIC(sizeof(xhci_dsts_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DGCMDPAR register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t parameter : 32; // 0..31 + }; +} xhci_dgcmdpar_t; +TU_VERIFY_STATIC(sizeof(xhci_dgcmdpar_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DGCMD register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t cmdtyp : 8; // 0..7 + uint32_t cmdioc : 1; // 8 + uint32_t reserved_9 : 1; // 9 + uint32_t cmdact : 1; // 10 + uint32_t reserved_11 : 1; // 11 + uint32_t cmdstatus : 4; // 12..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_dgcmd_t; +TU_VERIFY_STATIC(sizeof(xhci_dgcmd_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DCTL1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_0 : 1; // 0 + uint32_t dis_clrspr_sxfer : 1; // 1 + uint32_t en_endxfer_on_rjct_strm : 1; // 2 + uint32_t reserved_31_3 : 29; // 3..31 + }; +} xhci_dctl1_t; +TU_VERIFY_STATIC(sizeof(xhci_dctl1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DALEPENA register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t usbactep : 32; // 0..31 + }; +} xhci_dalepena_t; +TU_VERIFY_STATIC(sizeof(xhci_dalepena_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DLDMENA register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ldmena : 1; // 0 + uint32_t ldmrqs : 3; // 1..3 + uint32_t nolowpwrdur : 4; // 4..7 + uint32_t ldmdur : 8; // 8..15 + uint32_t ldmadj : 16; // 16..31 + }; +} xhci_dldmena_t; +TU_VERIFY_STATIC(sizeof(xhci_dldmena_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of Rsvd register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_rsvd_t; +TU_VERIFY_STATIC(sizeof(xhci_rsvd_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DEPCMDPAR2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t parameter : 32; // 0..31 + }; +} xhci_depcmdpar2_t; +TU_VERIFY_STATIC(sizeof(xhci_depcmdpar2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DEPCMDPAR1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t parameter : 32; // 0..31 + }; +} xhci_depcmdpar1_t; +TU_VERIFY_STATIC(sizeof(xhci_depcmdpar1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DEPCMDPAR0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t parameter : 32; // 0..31 + }; +} xhci_depcmdpar0_t; +TU_VERIFY_STATIC(sizeof(xhci_depcmdpar0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DEPCMD register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t cmdtyp : 4; // 0..3 + uint32_t reserved_7_4 : 4; // 4..7 + uint32_t cmdioc : 1; // 8 + uint32_t reserved_9 : 1; // 9 + uint32_t cmdact : 1; // 10 + uint32_t hipri_forcerm : 1; // 11 + uint32_t cmdstatus : 4; // 12..15 + uint32_t commandparam : 16; // 16..31 + }; +} xhci_depcmd_t; +TU_VERIFY_STATIC(sizeof(xhci_depcmd_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of DEV_IMOD register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t device_imodi : 16; // 0..15 + uint32_t device_imodc : 16; // 16..31 + }; +} xhci_dev_imod_t; +TU_VERIFY_STATIC(sizeof(xhci_dev_imod_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of rsvd0_reg register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_rsvd0_reg_t; +TU_VERIFY_STATIC(sizeof(xhci_rsvd0_reg_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LU1LFPSRXTIM register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gen1_u1_exit_rsp_rx_clk : 8; // 0..7 + uint32_t gen1_u1_lfps_exit_rx_clk : 8; // 8..15 + uint32_t gen2_u1_exit_rsp_rx_clk : 8; // 16..23 + uint32_t gen2_u1_lfps_exit_rx_clk : 8; // 24..31 + }; +} xhci_lu1lfpsrxtim_t; +TU_VERIFY_STATIC(sizeof(xhci_lu1lfpsrxtim_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LU1LFPSTXTIM register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gen1_u1_exit_rsp_tx_clk : 14; // 0..13 + uint32_t reserved_15_14 : 2; // 14..15 + uint32_t gen2_u1_exit_resp_tx_clk : 14; // 16..29 + uint32_t reserved_31_30 : 2; // 30..31 + }; +} xhci_lu1lfpstxtim_t; +TU_VERIFY_STATIC(sizeof(xhci_lu1lfpstxtim_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LU2LFPSRXTIM register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gen1_u2_exit_rsp_rx_clk : 8; // 0..7 + uint32_t gen1_u2_lfps_exit_rx_clk : 8; // 8..15 + uint32_t gen2_u2_exit_rsp_rx_clk : 8; // 16..23 + uint32_t gen2_u2_lfps_exit_rx_clk : 8; // 24..31 + }; +} xhci_lu2lfpsrxtim_t; +TU_VERIFY_STATIC(sizeof(xhci_lu2lfpsrxtim_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LU2LFPSTXTIM register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t u2_exit_rsp_tx_us : 14; // 0..13 + uint32_t reserved_31_14 : 18; // 14..31 + }; +} xhci_lu2lfpstxtim_t; +TU_VERIFY_STATIC(sizeof(xhci_lu2lfpstxtim_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LU3LFPSRXTIM register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gen1_u3_exit_rsp_rx_clk : 8; // 0..7 + uint32_t gen1_u3_lfps_exit_rx_clk : 8; // 8..15 + uint32_t gen2_u3_exit_rsp_rx_clk : 8; // 16..23 + uint32_t gen2_u3_lfps_exit_rx_clk : 8; // 24..31 + }; +} xhci_lu3lfpsrxtim_t; +TU_VERIFY_STATIC(sizeof(xhci_lu3lfpsrxtim_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LU3LFPSTXTIM register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gen1_u3_exit_rsp_tx_clk : 14; // 0..13 + uint32_t reserved_15_14 : 2; // 14..15 + uint32_t gen2_u3_exit_tx_clk : 14; // 16..29 + uint32_t reserved_31_30 : 2; // 30..31 + }; +} xhci_lu3lfpstxtim_t; +TU_VERIFY_STATIC(sizeof(xhci_lu3lfpstxtim_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LPINGLFPSTIM register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gen1_lfps_ping_min_clk : 4; // 0..3 + uint32_t gen1_lfps_ping_max_clk : 6; // 4..9 + uint32_t gen1_lfps_ping_burst_clk : 6; // 10..15 + uint32_t gen2_lfps_ping_min_clk : 4; // 16..19 + uint32_t gen2_lfps_ping_max_clk : 6; // 20..25 + uint32_t gen2_lfps_ping_burst_clk : 6; // 26..31 + }; +} xhci_lpinglfpstim_t; +TU_VERIFY_STATIC(sizeof(xhci_lpinglfpstim_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LPOLLLFPSTXTIM register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lfps_poll_burst_clk : 11; // 0..10 + uint32_t lfps_poll_space_clk : 11; // 11..21 + uint32_t reserved_31_22 : 10; // 22..31 + }; +} xhci_lpolllfpstxtim_t; +TU_VERIFY_STATIC(sizeof(xhci_lpolllfpstxtim_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LSKIPFREQ register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t gen1_skp_freq : 12; // 0..11 + uint32_t gen2_skp_freq : 8; // 12..19 + uint32_t pm_entry_timer_us : 4; // 20..23 + uint32_t pm_lc_timer_us : 3; // 24..26 + uint32_t en_pm_timer_us : 1; // 27 + uint32_t u1_resid_timer_us : 3; // 28..30 + uint32_t reserved_31 : 1; // 31 + }; +} xhci_lskipfreq_t; +TU_VERIFY_STATIC(sizeof(xhci_lskipfreq_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LLUCTL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t tx_ts1_cnt : 5; // 0..4 + uint32_t no_ux_exit_p0_trans : 1; // 5 + uint32_t delay_ux_after_lpma : 1; // 6 + uint32_t mask_pipe_reset : 1; // 7 + uint32_t gen1_loopback_entry_mode : 1; // 8 + uint32_t gen2_loopback_entry_mode : 1; // 9 + uint32_t force_gen1 : 1; // 10 + uint32_t en_reset_pipe_after_phy_mux : 1; // 11 + uint32_t u2p3cpmok : 1; // 12 + uint32_t ring_buf_d_delay : 2; // 13..14 + uint32_t en_us_hp_timer : 1; // 15 + uint32_t pending_hp_timer_us : 5; // 16..20 + uint32_t en_dpp_truncate : 1; // 21 + uint32_t force_dpp_truncate : 1; // 22 + uint32_t disrxdet_ltssm_timer_ovrrd : 1; // 23 + uint32_t delay_tx_gen1_dp : 4; // 24..27 + uint32_t support_p4 : 1; // 28 + uint32_t support_p4_pg : 1; // 29 + uint32_t inverse_sync_header : 1; // 30 + uint32_t reserved_31 : 1; // 31 + }; +} xhci_lluctl_t; +TU_VERIFY_STATIC(sizeof(xhci_lluctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LPTMDPDELAY register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t tx_path_delay : 5; // 0..4 + uint32_t rx_path_delay : 5; // 5..9 + uint32_t p3cpmp4_residency : 12; // 10..21 + uint32_t tx_path_delay_gen2 : 5; // 22..26 + uint32_t rx_path_delay_gen2 : 5; // 27..31 + }; +} xhci_lptmdpdelay_t; +TU_VERIFY_STATIC(sizeof(xhci_lptmdpdelay_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LSCDTIM1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t cd_bit0_rpt_min_clk : 12; // 0..11 + uint32_t scd_bit0_rpt_max_clk : 12; // 12..23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} xhci_lscdtim1_t; +TU_VERIFY_STATIC(sizeof(xhci_lscdtim1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LSCDTIM2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t cd_bit1_rpt_min_clk : 12; // 0..11 + uint32_t scd_bit1_rpt_max_clk : 12; // 12..23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} xhci_lscdtim2_t; +TU_VERIFY_STATIC(sizeof(xhci_lscdtim2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LSCDTIM3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lfps_scd_burst_clk : 8; // 0..7 + uint32_t lfps_scd_space0_clk : 12; // 8..19 + uint32_t lfps_scd_space1_clk : 12; // 20..31 + }; +} xhci_lscdtim3_t; +TU_VERIFY_STATIC(sizeof(xhci_lscdtim3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LSCDTIM4 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lfps_scd_last_space : 12; // 0..11 + uint32_t reserved_31_12 : 20; // 12..31 + }; +} xhci_lscdtim4_t; +TU_VERIFY_STATIC(sizeof(xhci_lscdtim4_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LLPBMTIM1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lfps_lbps0_burst_min_clk : 8; // 0..7 + uint32_t lfps_lbps0_burst_max_clk : 8; // 8..15 + uint32_t lfps_lbps1_burst_min_clk : 8; // 16..23 + uint32_t lfps_lbps1_burst_max_clk : 8; // 24..31 + }; +} xhci_llpbmtim1_t; +TU_VERIFY_STATIC(sizeof(xhci_llpbmtim1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LLPBMTIM2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lfps_lbpm_tpwm_min_clk : 9; // 0..8 + uint32_t lfps_lbpm_tpwm_max_clk : 9; // 9..17 + uint32_t reserved_31_18 : 14; // 18..31 + }; +} xhci_llpbmtim2_t; +TU_VERIFY_STATIC(sizeof(xhci_llpbmtim2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LLPBMTXTIM register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lfps_lbps_burst0_clk : 8; // 0..7 + uint32_t lfps_lbps_burst1_clk : 10; // 8..17 + uint32_t reserved_19_18 : 2; // 18..19 + uint32_t lfps_lpbs_tpwm_clk : 10; // 20..29 + uint32_t reserved_31_30 : 2; // 30..31 + }; +} xhci_llpbmtxtim_t; +TU_VERIFY_STATIC(sizeof(xhci_llpbmtxtim_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LLINKERRINJ register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rx_crc5 : 1; // 0 + uint32_t rx_crc16 : 1; // 1 + uint32_t rx_crc32 : 1; // 2 + uint32_t rx_one_frame_sybl : 1; // 3 + uint32_t rx_all_frame_sybl : 1; // 4 + uint32_t rx_one_end_frame_sybl : 1; // 5 + uint32_t rx_all_end_frame_sybl : 1; // 6 + uint32_t rx_one_srt_frame_sybl : 1; // 7 + uint32_t rx_all_start_frame_sybl : 1; // 8 + uint32_t rx_lfr : 1; // 9 + uint32_t rx_tseq : 1; // 10 + uint32_t rx_ts1 : 1; // 11 + uint32_t rx_ts2 : 1; // 12 + uint32_t rx_insert_delay : 1; // 13 + uint32_t rx_insert_defer : 1; // 14 + uint32_t rx_pipe_rxdata : 1; // 15 + uint32_t tx_crc5 : 1; // 16 + uint32_t tx_crc16 : 1; // 17 + uint32_t tx_crc32 : 1; // 18 + uint32_t tx_one_frame_sybl : 1; // 19 + uint32_t tx_all_frame_sybl : 1; // 20 + uint32_t tx_one_end_frame_sybl : 1; // 21 + uint32_t tx_all_end_frame_sybl : 1; // 22 + uint32_t tx_one_srt_frame_sybl : 1; // 23 + uint32_t tx_delay_credit_rl : 1; // 24 + uint32_t tx_lfr : 1; // 25 + uint32_t tx_tseq : 1; // 26 + uint32_t tx_ts1 : 1; // 27 + uint32_t tx_ts2 : 1; // 28 + uint32_t tx_insert_delay : 1; // 29 + uint32_t tx_insert_defer : 1; // 30 + uint32_t pipe_txdata : 1; // 31 + }; +} xhci_llinkerrinj_t; +TU_VERIFY_STATIC(sizeof(xhci_llinkerrinj_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LLINKERRINJEN register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t b2b_err_cnt : 16; // 0..15 + uint32_t disable_inj_err_cnt : 16; // 16..31 + }; +} xhci_llinkerrinjen_t; +TU_VERIFY_STATIC(sizeof(xhci_llinkerrinjen_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GDBGLTSSM register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txoneszeros : 1; // 0 + uint32_t rxtermination : 1; // 1 + uint32_t txswing : 1; // 2 + uint32_t ltdbclkstate : 3; // 3..5 + uint32_t txdeemphasis : 2; // 6..7 + uint32_t rxeqtrain : 1; // 8 + uint32_t powerdown : 2; // 9..10 + uint32_t ltdbphycmdstate : 3; // 11..13 + uint32_t txdetrxloopback : 1; // 14 + uint32_t rxpolarity : 1; // 15 + uint32_t txelecldle : 1; // 16 + uint32_t elasticbuffermode : 1; // 17 + uint32_t ltdbsubstate : 4; // 18..21 + uint32_t ltdblinkstate : 4; // 22..25 + uint32_t ltdbtimeout : 1; // 26 + uint32_t reserved_29_27 : 3; // 27..29 + uint32_t rxelecidle : 1; // 30 + uint32_t reserved_31 : 1; // 31 + }; +} xhci_gdbgltssm_t; +TU_VERIFY_STATIC(sizeof(xhci_gdbgltssm_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of GDBGLNMCC register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t lnmcc_berc : 9; // 0..8 + uint32_t reserved_15_9 : 7; // 9..15 + uint32_t lnmcc_lserc : 16; // 16..31 + }; +} xhci_gdbglnmcc_t; +TU_VERIFY_STATIC(sizeof(xhci_gdbglnmcc_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LLINKDBGCTRL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t txfifo_number : 4; // 0..3 + uint32_t rxfifo_number : 4; // 4..7 + uint32_t peri_rsc_txfifo_number : 4; // 8..11 + uint32_t peri_rsc_rxfifo_number : 4; // 12..15 + uint32_t link_state_trigger : 4; // 16..19 + uint32_t sub_state_trigger : 4; // 20..23 + uint32_t pipe_phystatus_trigger : 1; // 24 + uint32_t pipe_rxlecidle_trigger : 1; // 25 + uint32_t pipe_txdetectrxlb_trigger : 1; // 26 + uint32_t link_state_trigger_scrambled : 1; // 27 + uint32_t link_state_trigger_descrambled : 1; // 28 + uint32_t trigger_start_sts : 1; // 29 + uint32_t trigger_end_sts : 1; // 30 + uint32_t retry_dp : 1; // 31 + }; +} xhci_llinkdbgctrl_t; +TU_VERIFY_STATIC(sizeof(xhci_llinkdbgctrl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LLINKDBGCNTTRIG register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t srt_cnt : 16; // 0..15 + uint32_t stp_cnt : 16; // 16..31 + }; +} xhci_llinkdbgcnttrig_t; +TU_VERIFY_STATIC(sizeof(xhci_llinkdbgcnttrig_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LCSR_TX_DEEMPH register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t csr_tx_deemph_field_1 : 18; // 0..17 + uint32_t reserved_31_18 : 14; // 18..31 + }; +} xhci_lcsr_tx_deemph_t; +TU_VERIFY_STATIC(sizeof(xhci_lcsr_tx_deemph_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LCSR_TX_DEEMPH_1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t csr_tx_deemph_1_field_1 : 18; // 0..17 + uint32_t reserved_31_18 : 14; // 18..31 + }; +} xhci_lcsr_tx_deemph_1_t; +TU_VERIFY_STATIC(sizeof(xhci_lcsr_tx_deemph_1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LCSR_TX_DEEMPH_2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t csr_tx_deemph_2_field_1 : 18; // 0..17 + uint32_t reserved_31_18 : 14; // 18..31 + }; +} xhci_lcsr_tx_deemph_2_t; +TU_VERIFY_STATIC(sizeof(xhci_lcsr_tx_deemph_2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LCSR_TX_DEEMPH_3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t csr_tx_deemph_3_field_1 : 18; // 0..17 + uint32_t reserved_31_18 : 14; // 18..31 + }; +} xhci_lcsr_tx_deemph_3_t; +TU_VERIFY_STATIC(sizeof(xhci_lcsr_tx_deemph_3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LCSRPTMDEBUG1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ldm_t1 : 17; // 0..16 + uint32_t ldm_t32 : 13; // 17..29 + uint32_t reserved_31_30 : 2; // 30..31 + }; +} xhci_lcsrptmdebug1_t; +TU_VERIFY_STATIC(sizeof(xhci_lcsrptmdebug1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LCSRPTMDEBUG2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ldm_t4 : 17; // 0..16 + uint32_t reserved_31_17 : 15; // 17..31 + }; +} xhci_lcsrptmdebug2_t; +TU_VERIFY_STATIC(sizeof(xhci_lcsrptmdebug2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of LPTMDPDELAY2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t link_tx_delay_gen1 : 5; // 0..4 + uint32_t link_rx_delay_gen1 : 5; // 5..9 + uint32_t link_tx_delay_gen2 : 5; // 10..14 + uint32_t link_rx_delay_gen2 : 5; // 15..19 + uint32_t reserved_31_20 : 12; // 20..31 + }; +} xhci_lptmdpdelay2_t; +TU_VERIFY_STATIC(sizeof(xhci_lptmdpdelay2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BU31RHBDBG register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ovrcur : 1; // 0 + uint32_t pcap : 2; // 1..2 + uint32_t tpcfg_tout_ctrl : 1; // 3 + uint32_t reserved_31_4 : 28; // 4..31 + }; +} xhci_bu31rhbdbg_t; +TU_VERIFY_STATIC(sizeof(xhci_bu31rhbdbg_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BRAMHIADDR register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_11_0 : 12; // 0..11 + uint32_t ramhiaddr : 6; // 12..17 + uint32_t ram_select : 3; // 18..20 + uint32_t reserved_31_21 : 11; // 21..31 + }; +} xhci_bramhiaddr_t; +TU_VERIFY_STATIC(sizeof(xhci_bramhiaddr_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BRSERRCNT register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ram0serrcnt : 6; // 0..5 + uint32_t ram1serrcnt : 6; // 6..11 + uint32_t ram2serrcnt : 6; // 12..17 + uint32_t ram3serrcnt : 6; // 18..23 + uint32_t ram4serrcnt : 6; // 24..29 + uint32_t reserved_31_30 : 2; // 30..31 + }; +} xhci_brserrcnt_t; +TU_VERIFY_STATIC(sizeof(xhci_brserrcnt_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BRMERRCNT register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ram0merrcnt : 6; // 0..5 + uint32_t ram1merrcnt : 6; // 6..11 + uint32_t ram2merrcnt : 6; // 12..17 + uint32_t ram3merrcnt : 6; // 18..23 + uint32_t ram4merrcnt : 6; // 24..29 + uint32_t reserved_31_30 : 2; // 30..31 + }; +} xhci_brmerrcnt_t; +TU_VERIFY_STATIC(sizeof(xhci_brmerrcnt_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BRAMECCERR register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rammerrvec : 5; // 0..4 + uint32_t ramserrvec : 5; // 5..9 + uint32_t rammerr : 1; // 10 + uint32_t ramserr : 1; // 11 + uint32_t reserved_31_12 : 20; // 12..31 + }; +} xhci_brameccerr_t; +TU_VERIFY_STATIC(sizeof(xhci_brameccerr_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BRERRCTL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t rmerrclr : 1; // 0 + uint32_t rserrclr : 1; // 1 + uint32_t reserved_31_2 : 30; // 2..31 + }; +} xhci_brerrctl_t; +TU_VERIFY_STATIC(sizeof(xhci_brerrctl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BRAM0ADDRERR register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ram0errloc : 16; // 0..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_bram0addrerr_t; +TU_VERIFY_STATIC(sizeof(xhci_bram0addrerr_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BRAM1ADDRERR register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ram1errloc : 16; // 0..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_bram1addrerr_t; +TU_VERIFY_STATIC(sizeof(xhci_bram1addrerr_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BRAM2ADDRERR register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ram2errloc : 16; // 0..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_bram2addrerr_t; +TU_VERIFY_STATIC(sizeof(xhci_bram2addrerr_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BRAM3ADDRERR register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ram3errloc : 16; // 0..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_bram3addrerr_t; +TU_VERIFY_STATIC(sizeof(xhci_bram3addrerr_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BRAM4ADDRERR register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t ram4errloc : 16; // 0..15 + uint32_t reserved_31_16 : 16; // 16..31 + }; +} xhci_bram4addrerr_t; +TU_VERIFY_STATIC(sizeof(xhci_bram4addrerr_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BLOOPBCKCTRL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t loopback_mode_en : 1; // 0 + uint32_t loopback_mode : 1; // 1 + uint32_t loopback_level : 2; // 2..3 + uint32_t loopback_prtnum : 4; // 4..7 + uint32_t reserved_31_8 : 24; // 8..31 + }; +} xhci_bloopbckctrl_t; +TU_VERIFY_STATIC(sizeof(xhci_bloopbckctrl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BLOOPBCKTFERSZ register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t loopback_xfer_sz : 24; // 0..23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} xhci_bloopbcktfersz_t; +TU_VERIFY_STATIC(sizeof(xhci_bloopbcktfersz_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTDATAPATSEED register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t bist_pattern_seed : 32; // 0..31 + }; +} xhci_bbistdatapatseed_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistdatapatseed_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTCTRL register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t bist_iteration_cnt : 24; // 0..23 + uint32_t bist_pattern : 3; // 24..26 + uint32_t reserved_28_27 : 2; // 27..28 + uint32_t fail : 1; // 29 + uint32_t bist_test_type : 1; // 30 + uint32_t start_bist_test : 1; // 31 + }; +} xhci_bbistctrl_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistctrl_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTXFERSTS0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t bist_pending_trans_size : 24; // 0..23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} xhci_bbistxfersts0_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistxfersts0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTXFERSTS1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t failed_pending_trans_size : 24; // 0..23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} xhci_bbistxfersts1_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistxfersts1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTXFERSTS2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t failed_iteration : 24; // 0..23 + uint32_t reserved_31_24 : 8; // 24..31 + }; +} xhci_bbistxfersts2_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistxfersts2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTXFERSTS3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t loopback_statemachine : 4; // 0..3 + uint32_t reserved_31_4 : 28; // 4..31 + }; +} xhci_bbistxfersts3_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistxfersts3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTEXPDATASTS0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t exp_data : 32; // 0..31 + }; +} xhci_bbistexpdatasts0_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistexpdatasts0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTEXPDATASTS1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t exp_data : 32; // 0..31 + }; +} xhci_bbistexpdatasts1_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistexpdatasts1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTEXPDATASTS2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t exp_data : 32; // 0..31 + }; +} xhci_bbistexpdatasts2_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistexpdatasts2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTEXPDATASTS3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t exp_data : 32; // 0..31 + }; +} xhci_bbistexpdatasts3_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistexpdatasts3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTRCVDDATASTS0 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t received_data : 32; // 0..31 + }; +} xhci_bbistrcvddatasts0_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistrcvddatasts0_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTRCVDDATASTS1 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t received_data : 32; // 0..31 + }; +} xhci_bbistrcvddatasts1_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistrcvddatasts1_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTRCVDDATASTS2 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t received_data : 32; // 0..31 + }; +} xhci_bbistrcvddatasts2_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistrcvddatasts2_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of BBISTRCVDDATASTS3 register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t received_data : 32; // 0..31 + }; +} xhci_bbistrcvddatasts3_t; +TU_VERIFY_STATIC(sizeof(xhci_bbistrcvddatasts3_t) == sizeof(uint32_t), "incorrect size"); + +/* Bit fields of rsvd_reg register. */ +typedef union { + uint32_t value; + struct TU_ATTR_PACKED { + uint32_t reserved_31_0 : 32; // 0..31 + }; +} xhci_rsvd_reg_t; +TU_VERIFY_STATIC(sizeof(xhci_rsvd_reg_t) == sizeof(uint32_t), "incorrect size"); + +/* xHCI capability and operational register map. */ +typedef struct TU_ATTR_PACKED { + xhci_caplength_t caplength; // 0x0000 + xhci_hcsparams1_t hcsparams1; // 0x0004 + xhci_hcsparams2_t hcsparams2; // 0x0008 + xhci_hcsparams3_t hcsparams3; // 0x000c + xhci_hccparams1_t hccparams1; // 0x0010 + xhci_dboff_t dboff; // 0x0014 + xhci_rtsoff_t rtsoff; // 0x0018 + xhci_hccparams2_t hccparams2; // 0x001c + xhci_usbcmd_t usbcmd; // 0x0020 + xhci_usbsts_t usbsts; // 0x0024 + xhci_pagesize_t pagesize; // 0x0028 + uint32_t reserved_2c_30[2]; // 0x002c..0x0030 + xhci_dnctrl_t dnctrl; // 0x0034 + xhci_crcr_lo_t crcr_lo; // 0x0038 + xhci_crcr_hi_t crcr_hi; // 0x003c + uint32_t reserved_40_4c[4]; // 0x0040..0x004c + xhci_dcbaap_lo_t dcbaap_lo; // 0x0050 + xhci_dcbaap_hi_t dcbaap_hi; // 0x0054 + xhci_config_t config; // 0x0058 +} xhci_regs_t; +TU_VERIFY_STATIC(offsetof(xhci_regs_t, caplength) == 0x0000, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, hcsparams1) == 0x0004, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, hcsparams2) == 0x0008, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, hcsparams3) == 0x000c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, hccparams1) == 0x0010, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, dboff) == 0x0014, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, rtsoff) == 0x0018, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, hccparams2) == 0x001c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, usbcmd) == 0x0020, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, usbsts) == 0x0024, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, pagesize) == 0x0028, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, dnctrl) == 0x0034, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, crcr_lo) == 0x0038, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, crcr_hi) == 0x003c, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, dcbaap_lo) == 0x0050, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, dcbaap_hi) == 0x0054, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_regs_t, config) == 0x0058, "incorrect register offset"); +TU_VERIFY_STATIC(sizeof(xhci_regs_t) == 0x5c, "incorrect register map size"); + +#ifdef __cplusplus +} +#endif + +#endif /* SOCFPGA_XHCI_TYPE_H_ */ From e52f9936795374bb52981ae2e5b3a691738e9972 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Thu, 19 Nov 2026 15:10:39 +0530 Subject: [PATCH 09/17] src: portable: xhci: restructure xhci register operations * Use xhci bitfield structures from xhci_type.h to make it compatible with tinyusb Signed-off-by: Sourav Raj K K --- src/portable/xhci/xhci.c | 46 ++++++------- src/portable/xhci/xhci.h | 1 + src/portable/xhci/xhci_cap.c | 49 +++++++------ src/portable/xhci/xhci_commands.c | 14 ++-- src/portable/xhci/xhci_context.c | 8 ++- src/portable/xhci/xhci_doorbell.c | 21 +++--- src/portable/xhci/xhci_events.c | 102 ++++++++++++++-------------- src/portable/xhci/xhci_interrupts.c | 52 ++++++-------- src/portable/xhci/xhci_rings.c | 42 ++++++------ src/portable/xhci/xhci_type.h | 55 ++++++++++----- 10 files changed, 202 insertions(+), 188 deletions(-) diff --git a/src/portable/xhci/xhci.c b/src/portable/xhci/xhci.c index 897bdb48e..5250f21a7 100644 --- a/src/portable/xhci/xhci.c +++ b/src/portable/xhci/xhci.c @@ -48,7 +48,6 @@ #include "xhci_common.h" #if CFG_TUSB_MCU == OPT_MCU_SOCFPGA - #include "socfpga_defines.h" #include "xhci_events.h" #include "xhci_commands.h" #include "xhci_endpoints.h" @@ -137,22 +136,19 @@ int is_ptr_mem_aligned(uint64_t addr, uint32_t byte) static int configure_xhci_max_slots(void) { - volatile uint32_t config_reg_val; - uint32_t hcsparams1; - uint32_t max_slots; - - hcsparams1 = RD_REG32((USBBASE + USB3_HCSPARAMS1)); - max_slots = (hcsparams1 & USB3_HCSPARAMS1_MAXSLOTS_MASK) - >> USB3_HCSPARAMS1_MAXSLOTS_POS; + volatile xhci_regs_t *xhci = + (volatile xhci_regs_t *)(uintptr_t) USBBASE; + uint32_t max_slots = + (xhci->hcsparams1.value & USB3_HCSPARAMS1_MAXSLOTS_MASK) >> + USB3_HCSPARAMS1_MAXSLOTS_POS; DEBUG("MaxSlots is : %x", max_slots); - config_reg_val = RD_REG32((USBBASE + USB3_CONFIG)); - max_slots |= (config_reg_val & (~USB3_CONFIG_MAXSLOTSEN_MASK)); - WR_REG32((USBBASE + USB3_CONFIG), max_slots); + xhci->config.value = + (xhci->config.value & ~USB3_CONFIG_MAXSLOTSEN_MASK) | + max_slots; - config_reg_val = RD_REG32((USBBASE + USB3_CONFIG)); - if ((config_reg_val & USB3_CONFIG_MAXSLOTSEN_MASK) == 0U) + if ((xhci->config.value & USB3_CONFIG_MAXSLOTSEN_MASK) == 0U) { ERROR("Max Slot Enable Bit Not configurred Correctly"); return -EIO; @@ -162,11 +158,10 @@ static int configure_xhci_max_slots(void) void start_xhci_controller(void) { - uint32_t reg_val; + volatile xhci_regs_t *xhci = + (volatile xhci_regs_t *)(uintptr_t) USBBASE; - reg_val = RD_REG32((USBBASE + USB3_USBCMD)); - reg_val |= (START_XHCI << USB3_USBCMD_R_S_POS); - WR_REG32((USBBASE + USB3_USBCMD), reg_val); + xhci->usbcmd.r_s = START_XHCI; } /* @@ -174,14 +169,14 @@ void start_xhci_controller(void) */ static int wait_for_controller_ready(void) { - uint32_t reg_val; + volatile xhci_regs_t *xhci = + (volatile xhci_regs_t *)(uintptr_t) USBBASE; volatile uint16_t loop = 100; do { - reg_val = RD_REG32((USBBASE + USB3_USBSTS)); /* check for CNR flag */ - if ((reg_val & USB3_USBSTS_CNR_MASK) == 0U) + if (xhci->usbsts.cnr == 0U) { break; } @@ -202,18 +197,17 @@ static int wait_for_controller_ready(void) int xhci_reset(void) { - volatile uint32_t reg_val, err_flag = 0U, loop = 1000U; + volatile xhci_regs_t *xhci = + (volatile xhci_regs_t *)(uintptr_t) USBBASE; + volatile uint32_t err_flag = 0U, loop = 1000U; - reg_val = RD_REG32((USBBASE + USB3_USBCMD)); /* Reset the Host Controller */ - reg_val |= (USB3_USBCMD_HCRST_MASK); - WR_REG32((USBBASE + USB3_USBCMD), reg_val); + xhci->usbcmd.hcrst = 1U; INFO("Initiating Controller Reset"); do { - reg_val = RD_REG32((USBBASE + USB3_USBCMD)); - if ((reg_val & USB3_USBCMD_HCRST_MASK) == 0U) + if (xhci->usbcmd.hcrst == 0U) { err_flag = 1U; break; diff --git a/src/portable/xhci/xhci.h b/src/portable/xhci/xhci.h index addc40728..a868cb1d6 100644 --- a/src/portable/xhci/xhci.h +++ b/src/portable/xhci/xhci.h @@ -11,6 +11,7 @@ #include #include +#include "xhci_type.h" #include "xhci_context.h" #include "xhci_rings.h" diff --git a/src/portable/xhci/xhci_cap.c b/src/portable/xhci/xhci_cap.c index ef8c32900..8d68ffa6c 100644 --- a/src/portable/xhci/xhci_cap.c +++ b/src/portable/xhci/xhci_cap.c @@ -18,35 +18,39 @@ */ int get_xhc_cap_params(struct xhci_data *xhci) { - uint32_t caplength = RD_REG32(USBBASE + USB3_CAPLENGTH); - uint32_t dboff = RD_REG32(USBBASE + USB3_DBOFF); - uint32_t rtsoff = RD_REG32(USBBASE + USB3_RTSOFF); + volatile xhci_regs_t *regs = + (volatile xhci_regs_t *)(uintptr_t) USBBASE; xhci->xhc_cap_ptr = (xhci_cap_reg_t *)USBBASE; DEBUG("CAPLENGTH : %x", - (caplength & USB3_CAPLENGTH_CAPLENGTH_MASK)); + (regs->caplength.value & USB3_CAPLENGTH_CAPLENGTH_MASK)); DEBUG("HCSPARAMS1 : %x", - RD_REG32(USBBASE + USB3_HCSPARAMS1)); + regs->hcsparams1.value); DEBUG("HCSPARAMS2 : %x", - RD_REG32(USBBASE + USB3_HCSPARAMS2)); + regs->hcsparams2.value); DEBUG("HCSPARAMS3 : %x", - RD_REG32(USBBASE + USB3_HCSPARAMS3)); + regs->hcsparams3.value); DEBUG("HCCPARAMS1 : %x", - RD_REG32(USBBASE + USB3_HCCPARAMS1)); + regs->hccparams1.value); DEBUG("DBOFF : %x", - (dboff & USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK)); + (regs->dboff.value & + USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK)); DEBUG("RTOFF : %x", - (rtsoff & USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK)); + (regs->rtsoff.value & + USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK)); DEBUG("HCCPARAMS2 : %x", - RD_REG32(USBBASE + USB3_HCCPARAMS2)); + regs->hccparams2.value); xhci->op_regs.xhci_op_base = (uint64_t)USBBASE + - (uint64_t)(caplength & USB3_CAPLENGTH_CAPLENGTH_MASK); + (uint64_t)(regs->caplength.value & + USB3_CAPLENGTH_CAPLENGTH_MASK); xhci->op_regs.xhci_runtime_base = (uint64_t)USBBASE + - (uint64_t)(rtsoff & USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK); + (uint64_t)(regs->rtsoff.value & + USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK); xhci->op_regs.xhci_db_base = (uint64_t)USBBASE + - (uint64_t)(dboff & USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK); + (uint64_t)(regs->dboff.value & + USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK); DEBUG("Operational base : %lx ", xhci->op_regs.xhci_op_base); @@ -61,14 +65,19 @@ int get_xhc_cap_params(struct xhci_data *xhci) xhci_oper_reg_params_t get_xhci_op_registers(void) { xhci_oper_reg_params_t op_reg = {0}; - uint32_t cap = RD_REG32(USBBASE + offsetof(xhci_cap_reg_t, caplength)); - uint32_t dboff = RD_REG32(USBBASE + offsetof(xhci_cap_reg_t, dboff)); - uint32_t rtsoff = RD_REG32(USBBASE + offsetof(xhci_cap_reg_t, rtsoff)); + volatile xhci_regs_t *regs = + (volatile xhci_regs_t *)(uintptr_t) USBBASE; /* CAPLENGTH[7:0] */ - op_reg.xhci_op_base = (uint64_t)USBBASE + (uint64_t)(cap & 0xFFU); + op_reg.xhci_op_base = (uint64_t)USBBASE + + (uint64_t)(regs->caplength.value & + USB3_CAPLENGTH_CAPLENGTH_MASK); /* DBOFF[31:2] */ - op_reg.xhci_db_base = (uint64_t)USBBASE + (uint64_t)(dboff & ~0x3U); + op_reg.xhci_db_base = (uint64_t)USBBASE + + (uint64_t)(regs->dboff.value & + USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK); /* RSTOFF[31:5] */ - op_reg.xhci_runtime_base = (uint64_t)USBBASE + (uint64_t)(rtsoff & ~0x1FU); + op_reg.xhci_runtime_base = (uint64_t)USBBASE + + (uint64_t)(regs->rtsoff.value & + USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK); return op_reg; } diff --git a/src/portable/xhci/xhci_commands.c b/src/portable/xhci/xhci_commands.c index d3c28d128..7ac479899 100644 --- a/src/portable/xhci/xhci_commands.c +++ b/src/portable/xhci/xhci_commands.c @@ -10,7 +10,6 @@ #include "xhci_commands.h" #include "xhci_doorbell.h" #include "socfpga_cache.h" -#include "socfpga_defines.h" #include "osal_log.h" xhci_trb_t *get_cmdring_enq_ptr(xcr_command_ring_t *cmd_ring) @@ -68,17 +67,18 @@ void set_device_address(struct xhci_data *xhci_ptr) void reset_command_ring(xcr_command_ring_t *xcr_ring) { - uint32_t crcr_reg; + volatile xhci_regs_t *xhci = + (volatile xhci_regs_t *)(uintptr_t) USBBASE; uint32_t crcr_addr; /* first stop the command ring operation */ - crcr_reg = RD_REG32((USBBASE + USB3_CRCR_LO)); - crcr_reg |= (0x2U); - WR_REG32((USBBASE + USB3_CRCR_LO), crcr_reg); + xhci->crcr_lo.cs = 1U; - crcr_addr = ((uint32_t)(uintptr_t) (&xcr_ring->xcr_dequeue_ptr) & + crcr_addr = ((uint32_t)(uintptr_t) xcr_ring->xcr_dequeue_ptr & 0xffffffffU); - WR_REG32((USBBASE + USB3_CRCR_LO), crcr_addr); + xhci->crcr_lo.value = crcr_addr; + xhci->crcr_hi.value = + (uint32_t) ((uintptr_t) xcr_ring->xcr_dequeue_ptr >> 32); } void enable_slot_command(xcr_command_ring_t *xcr_ring) diff --git a/src/portable/xhci/xhci_context.c b/src/portable/xhci/xhci_context.c index 28123d0ca..6920ee94d 100644 --- a/src/portable/xhci/xhci_context.c +++ b/src/portable/xhci/xhci_context.c @@ -45,7 +45,6 @@ #include "xhci.h" #include "socfpga_cache.h" -#include "socfpga_defines.h" #include "xhci_endpoints.h" #include "xhci_context.h" #include "xhci_events.h" @@ -340,7 +339,12 @@ int alloc_dcbaa(struct xhci_data *xhci_ptr) xhci_ptr->dcbaa->dev_context_ptrs[i] = 0UL; } - WR_REG64((USBBASE + USB3_DCBAAP_LO), (uint64_t)xhci_ptr->dcbaa); + volatile xhci_regs_t *xhci = + (volatile xhci_regs_t *)(uintptr_t) USBBASE; + const uint64_t dcbaa = (uint64_t)(uintptr_t) xhci_ptr->dcbaa; + + xhci->dcbaap_lo.value = (uint32_t) dcbaa; + xhci->dcbaap_hi.value = (uint32_t) (dcbaa >> 32); DEBUG("xHCI DCBAA register updated"); return 0; diff --git a/src/portable/xhci/xhci_doorbell.c b/src/portable/xhci/xhci_doorbell.c index 111b8a082..44b838bcb 100644 --- a/src/portable/xhci/xhci_doorbell.c +++ b/src/portable/xhci/xhci_doorbell.c @@ -8,33 +8,30 @@ */ #include "xhci_doorbell.h" -#include "socfpga_defines.h" void ring_xhci_host_db(void) { xhci_oper_reg_params_t op_regs; + volatile xhci_db_t *doorbells; op_regs = get_xhci_op_registers(); - WR_REG32((op_regs.xhci_db_base + USB3_DB), XHCI_COMMAND_DOORBELL); + doorbells = (volatile xhci_db_t *)(uintptr_t) op_regs.xhci_db_base; + doorbells[0].value = XHCI_COMMAND_DOORBELL; } void ring_xhci_ep0_db(xhci_oper_reg_params_t *op_regs) { - uint64_t db_reg; + volatile xhci_db_t *doorbells; uint32_t slot_id = 1U; - db_reg = (op_regs->xhci_db_base + USB3_DB) + - (XHCI_DB_REG_SIZE * (uint64_t) slot_id); - - WR_REG32((uint32_t) db_reg, XHCI_DB_EP0_TARGET); + doorbells = (volatile xhci_db_t *)(uintptr_t) op_regs->xhci_db_base; + doorbells[slot_id].value = XHCI_DB_EP0_TARGET; } void ring_xhci_ep_doorbell(xhci_oper_reg_params_t *op_regs, uint8_t db_target) { - uint64_t db_reg; + volatile xhci_db_t *doorbells; uint32_t slot_id = 1U; - db_reg = (op_regs->xhci_db_base + USB3_DB) + - (XHCI_DB_REG_SIZE * (uint64_t) slot_id); - - WR_REG32((uint32_t) db_reg, db_target); + doorbells = (volatile xhci_db_t *)(uintptr_t) op_regs->xhci_db_base; + doorbells[slot_id].value = db_target; } diff --git a/src/portable/xhci/xhci_events.c b/src/portable/xhci/xhci_events.c index c9551db73..976f5c004 100644 --- a/src/portable/xhci/xhci_events.c +++ b/src/portable/xhci/xhci_events.c @@ -9,11 +9,11 @@ #include #include "xhci_events.h" -#include "socfpga_defines.h" #include "socfpga_cache.h" #include "osal_log.h" -static void erdp_register_update(); +static void erdp_register_update(xer_event_ring_t *xer_ring, + volatile xhci_runtime_regs_t *runtime); void display_event_trbs(struct xhci_data *xhci) { @@ -33,18 +33,14 @@ void display_event_trbs(struct xhci_data *xhci) uint8_t get_xhc_port_speed(uint8_t rhport) { - uint32_t portsc_reg_val, portsc_reg; - uint8_t port_speed; - xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); - portsc_reg = (uint32_t) ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + - (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + volatile xhci_portsc_20_t *portsc = + (volatile xhci_portsc_20_t *)(uintptr_t) + (op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))); - portsc_reg_val = RD_REG32(portsc_reg); - port_speed = (uint8_t) ((portsc_reg_val & USB3_PORTSC_20_PORTSPEED_MASK) >> + return (uint8_t) ((portsc->value & USB3_PORTSC_20_PORTSPEED_MASK) >> USB3_PORTSC_20_PORTSPEED_POS); - - return port_speed; } /* @@ -53,16 +49,14 @@ uint8_t get_xhc_port_speed(uint8_t rhport) */ bool xhci_port_status(uint8_t rhport) { - uint32_t reg_val; - uint32_t portsc_reg; - xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); - portsc_reg = (uint32_t) ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + - (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + volatile xhci_portsc_20_t *portsc = + (volatile xhci_portsc_20_t *)(uintptr_t) + (op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))); /*Bit 0 gives attach/detach status */ - reg_val = RD_REG32(portsc_reg); - if ((reg_val & 1U) != 0U) + if ((portsc->value & USB3_PORTSC_20_CCS_MASK) != 0U) { return true; } @@ -72,29 +66,28 @@ bool xhci_port_status(uint8_t rhport) /* reset the RH port */ void reset_xhci_port(uint8_t rhport) { - uint32_t reg_val; xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); - uint32_t portsc_reg = (uint32_t) ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + - (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + volatile xhci_portsc_20_t *portsc = + (volatile xhci_portsc_20_t *)(uintptr_t) + (op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))); - reg_val = RD_REG32(portsc_reg); - reg_val |= (USB3_PORTSC_20_PR_MASK); - WR_REG32(portsc_reg, reg_val); + portsc->value |= USB3_PORTSC_20_PR_MASK; INFO("xHCI port reset initiated on port : %d", rhport); } bool is_xhci_port_reset_end(uint8_t rhport) { - volatile uint32_t reg_val, portsc_reg; + volatile xhci_portsc_20_t *portsc; uint32_t loop = 100U; xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); - portsc_reg = ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + - (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + portsc = (volatile xhci_portsc_20_t *)(uintptr_t) + (op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))); do { - reg_val = RD_REG32(portsc_reg); - if ((reg_val & (1U << 4)) == 0U) + if ((portsc->value & USB3_PORTSC_20_PR_MASK) == 0U) { break; } @@ -116,13 +109,17 @@ bool is_xhci_port_reset_end(uint8_t rhport) xhci_event_trb_t get_xhc_event(struct xhci_data *xhci_ptr) { uint64_t erdp_addr; + volatile xhci_runtime_regs_t *runtime; xhci_event_trb_type_t trb_id; xhci_event_trb_t event = {0}; /* decrement the event ring trb count */ xhci_ptr->xer_ring.trb_count -= 1U; - erdp_addr = RD_REG32(ERDP); + runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) + xhci_ptr->op_regs.xhci_runtime_base; + erdp_addr = ((uint64_t) runtime->erdp_hi.value << 32) | + runtime->erdp_lo.value; erdp_addr &= 0xfffffff0UL; cache_force_invalidate((void *)erdp_addr, sizeof(xhci_trb_t)); @@ -154,11 +151,12 @@ xhci_event_trb_t get_xhc_event(struct xhci_data *xhci_ptr) /* error TRB type */ configASSERT(trb_id >= 0); } - erdp_register_update(&xhci_ptr->xer_ring); + erdp_register_update(&xhci_ptr->xer_ring, runtime); return event; } -static void erdp_register_update(xer_event_ring_t *xer_ring) +static void erdp_register_update(xer_event_ring_t *xer_ring, + volatile xhci_runtime_regs_t *runtime) { uint32_t trb_count; uint64_t erdp_addr; @@ -167,7 +165,6 @@ static void erdp_register_update(xer_event_ring_t *xer_ring) if (trb_count == 0U) { - erdp_addr = RD_REG32(ERDP); erdp_addr = (uint64_t)xer_ring->xer_enqueue_ptr; /* EHB flag */ erdp_addr |= 8UL; @@ -176,28 +173,32 @@ static void erdp_register_update(xer_event_ring_t *xer_ring) } else { - erdp_addr = RD_REG32(ERDP); + erdp_addr = ((uint64_t) runtime->erdp_hi.value << 32) | + runtime->erdp_lo.value; erdp_addr += 0x10U; } - WR_REG64(ERDP, erdp_addr); + runtime->erdp_lo.value = (uint32_t) erdp_addr; + runtime->erdp_hi.value = (uint32_t) (erdp_addr >> 32); } xhci_psceg_params_t handle_psceg_event(xpsc_event_t psc_event) { - uint32_t portsc_reg, portsc_register, temp = 0U; + uint32_t temp = 0U; xhci_psceg_params_t port_params = { 0 }; + volatile xhci_portsc_20_t *portsc; uint8_t rhport = (uint8_t) ((psc_event.buf & 0xff000000UL) >> 24); xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); - portsc_register = (uint32_t) ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + - (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); - portsc_reg = RD_REG32(portsc_register); + portsc = (volatile xhci_portsc_20_t *)(uintptr_t) + (op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))); - if ((portsc_reg & USB3_PORTSC_20_CSC_MASK) > 0U) + if ((portsc->value & USB3_PORTSC_20_CSC_MASK) != 0U) { /* device connected to RH PORT */ - if ((portsc_reg & USB3_PORTSC_20_CCS_MASK) == 1U) + if ((portsc->value & USB3_PORTSC_20_CCS_MASK) == + USB3_PORTSC_20_CCS_MASK) { /* acknowledge the status bit change */ temp |= (USB3_PORTSC_20_CSC_MASK); @@ -213,33 +214,30 @@ xhci_psceg_params_t handle_psceg_event(xpsc_event_t psc_event) port_params.dev_attach_flag = -1; } } - if ((portsc_reg & USB3_PORTSC_20_PRC_MASK) > 0U) + if ((portsc->value & USB3_PORTSC_20_PRC_MASK) != 0U) { /*Port Reset Event */ temp |= USB3_PORTSC_20_PRC_MASK; } - if ((portsc_reg & USB3_PORTSC_30_WRC_MASK) > 0U) + if ((portsc->value & USB3_PORTSC_30_WRC_MASK) != 0U) { /*Warm PR Event */ temp |= USB3_PORTSC_30_WRC_MASK; } - portsc_reg &= ~PORTSC_CLEAR_FLAGS; - portsc_reg |= temp; - WR_REG32(portsc_register, portsc_reg); + portsc->value = (portsc->value & ~PORTSC_CLEAR_FLAGS) | temp; return port_params; } void xhci_warm_reset(uint8_t rhport) { - uint32_t reg_val, portsc_register; xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); + volatile xhci_portsc_30_t *portsc; - portsc_register = (uint32_t) ((op_reg.xhci_op_base + PORTSC_REG_OFFSET + - (0x10U * ((uint64_t) rhport - 1UL))) & 0x00000000ffffffffUL); + portsc = (volatile xhci_portsc_30_t *)(uintptr_t) + (op_reg.xhci_op_base + PORTSC_REG_OFFSET + + (0x10U * ((uint64_t) rhport - 1UL))); - reg_val = RD_REG32(portsc_register); - reg_val |= USB3_PORTSC_30_WPR_MASK; - WR_REG32(portsc_register, reg_val); + portsc->value |= USB3_PORTSC_30_WPR_MASK; } diff --git a/src/portable/xhci/xhci_interrupts.c b/src/portable/xhci/xhci_interrupts.c index b472d3f76..62af71b45 100644 --- a/src/portable/xhci/xhci_interrupts.c +++ b/src/portable/xhci/xhci_interrupts.c @@ -11,7 +11,6 @@ #include "xhci_interrupts.h" #include "socfpga_interrupt.h" #include "socfpga_usb3_reg.h" -#include "socfpga_defines.h" #include "socfpga_interrupt_priority.h" #include "osal_log.h" @@ -19,39 +18,32 @@ void socfpga_usb3_handler(void *handler); void enable_xhci_interrupts(void) { - volatile uint32_t reg_val; struct xhci_oper_reg_params op_regs; + volatile xhci_runtime_regs_t *runtime; + volatile xhci_regs_t *xhci; op_regs = get_xhci_op_registers(); + runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) op_regs.xhci_runtime_base; + xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; - reg_val = RD_REG32((op_regs.xhci_runtime_base + USB3_IMAN)); - reg_val |= USB3_IMAN_IE_MASK; - WR_REG32((op_regs.xhci_runtime_base + USB3_IMAN), reg_val); - - reg_val = RD_REG32((USBBASE + USB3_USBCMD)); - reg_val |= USB3_USBCMD_INTE_MASK; - WR_REG32((USBBASE + USB3_USBCMD), reg_val); + runtime->iman.ie = 1U; + xhci->usbcmd.inte = 1U; } void disable_xhci_interrupts(void) { - volatile uint32_t reg_val; struct xhci_oper_reg_params op_regs; + volatile xhci_runtime_regs_t *runtime; + volatile xhci_regs_t *xhci; op_regs = get_xhci_op_registers(); + runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) op_regs.xhci_runtime_base; + xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; - reg_val = RD_REG32((op_regs.xhci_runtime_base + USB3_IMAN)); - reg_val &= ~(USB3_IMAN_IE_MASK); - WR_REG32((op_regs.xhci_runtime_base + USB3_IMAN), reg_val); - - reg_val = RD_REG32((op_regs.xhci_runtime_base + USB3_IMAN)); - reg_val &= ~(USB3_IMAN_IP_MASK); - WR_REG32((op_regs.xhci_runtime_base + USB3_IMAN), reg_val); - - reg_val = RD_REG32((USBBASE + USB3_USBCMD)); - reg_val &= ~(USB3_USBCMD_INTE_MASK); - WR_REG32((USBBASE + USB3_USBCMD), reg_val); + runtime->iman.ie = 0U; + runtime->iman.ip = 0U; + xhci->usbcmd.inte = 0U; } bool register_usb3ISR(xhci_int_ptr_t int_handler) @@ -79,29 +71,25 @@ bool register_usb3ISR(xhci_int_ptr_t int_handler) void socfpga_usb3_handler(void *handler) { xhci_int_ptr_t usb3_int_handler; - uint32_t reg_val; struct xhci_oper_reg_params op_regs; + volatile xhci_runtime_regs_t *runtime; + volatile xhci_regs_t *xhci; op_regs = get_xhci_op_registers(); + runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) op_regs.xhci_runtime_base; + xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; usb3_int_handler = (xhci_int_ptr_t) handler; - reg_val = RD_REG32((USBBASE + USB3_USBSTS)); - - if (((reg_val & USB3_USBSTS_HSE_MASK) != 0U) || ((reg_val & - USB3_USBSTS_HCE_MASK) != 0U)) + if ((xhci->usbsts.hse != 0U) || (xhci->usbsts.hce != 0U)) { (void) xhci_reset(); start_xhci_controller(); return; } - reg_val |= (USB3_USBSTS_EINT_MASK); - WR_REG32((USBBASE + USB3_USBSTS), reg_val); - - reg_val = RD_REG32((op_regs.xhci_runtime_base + USB3_IMAN)); - reg_val |= USB3_IMAN_IP_MASK; - WR_REG32((op_regs.xhci_runtime_base + USB3_IMAN), reg_val); + xhci->usbsts.eint = 1U; + runtime->iman.ip = 1U; /* rh_port = 1 -> RH port number as per tinyusb stack */ /* in_isr = true, ISR flag for tinyusb stack */ diff --git a/src/portable/xhci/xhci_rings.c b/src/portable/xhci/xhci_rings.c index 274c12d44..418b7b3e7 100644 --- a/src/portable/xhci/xhci_rings.c +++ b/src/portable/xhci/xhci_rings.c @@ -9,10 +9,11 @@ #include #include "socfpga_cache.h" -#include "socfpga_defines.h" #include "osal_log.h" #include "xhci.h" +#define XHCI_REG_BASE (0x11000000) + /*************************************************************************************************/ /* xHCI Rings */ /*************************************************************************************************/ @@ -36,7 +37,8 @@ int xhci_crcr_init(xcr_command_ring_t *xcr_ring) { - uint32_t crcr_write_val; + volatile xhci_regs_t *xhci = (volatile xhci_regs_t *)(uintptr_t) XHCI_REG_BASE; + int ret; xcr_ring->xcr_dequeue_ptr = allocate_ring_segment(64, XHCI_CR_TRB_LEN); @@ -59,12 +61,11 @@ int xhci_crcr_init(xcr_command_ring_t *xcr_ring) xcr_ring->xcr_enqueue_ptr = xcr_ring->xcr_dequeue_ptr; xcr_ring->xcr_ccs_flag = XHCI_CR_CCS_FLAG; - crcr_write_val = (((uint32_t)(uintptr_t) xcr_ring->xcr_dequeue_ptr) & - USB3_CRCR_LO_CMD_RING_PNTR_MASK); - crcr_write_val |= (xcr_ring->xcr_ccs_flag); - - WR_REG32((USBBASE + USB3_CRCR_LO), crcr_write_val); - INFO("Command Ring Register updated"); + xhci->crcr_lo.value = + (((uint32_t)(uintptr_t)xcr_ring->xcr_dequeue_ptr) & + USB3_CRCR_LO_CMD_RING_PNTR_MASK) | + (uint32_t) xcr_ring->xcr_ccs_flag; + xhci->crcr_hi.value = (uint32_t)((uintptr_t) xcr_ring->xcr_dequeue_ptr >> 32); return 0; } @@ -76,17 +77,17 @@ int init_xhc_event_ring(struct xhci_data *xhci_ptr) uint64_t erdp_reg_val; uint64_t rt_base_addr; - uint32_t reg_val; + volatile xhci_runtime_regs_t *runtime; xer_event_ring_t *xer_ring; xer_ring = &xhci_ptr->xer_ring; - rt_base_addr = xhci_ptr->op_regs.xhci_runtime_base; + rt_base_addr = xhci_ptr->op_regs.xhci_runtime_base; + runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) rt_base_addr; - reg_val = RD_REG32((rt_base_addr + USB3_ERSTSZ)); - reg_val &= ~(USB3_ERSTSZ_ERS_TABLE_SIZE_MASK); - reg_val |= XHCI_EVENT_RING_TABLE_SZ; - WR_REG32((rt_base_addr + USB3_ERSTSZ), reg_val); + runtime->erstsz.value = + (runtime->erstsz.value & ~(USB3_ERSTSZ_ERS_TABLE_SIZE_MASK)) | + XHCI_EVENT_RING_TABLE_SZ; xer_ring->erst_ptr = (xhci_erst_entry_t *)(uintptr_t) pvPortAlignedAlloc(64, 1U * sizeof(xhci_erst_entry_t)); @@ -140,15 +141,16 @@ int init_xhc_event_ring(struct xhci_data *xhci_ptr) xer_ring->erst_ptr->rsvd = 0U; ring_addr = (uint64_t)xer_ring->erst_ptr; - reg_val = RD_REG32((rt_base_addr + USB3_ERSTBA_LO)); - reg_val |= (uint32_t) (ring_addr & ~(0x3fUL)); - WR_REG64((rt_base_addr + USB3_ERSTBA_LO), reg_val); + runtime->erstba_lo.value = + (uint32_t) (ring_addr & ~(0x3fUL)); + runtime->erstba_hi.value = (uint32_t) (ring_addr >> 32); ring_addr = (uint64_t) (xer_ring->xer_enqueue_ptr); - erdp_reg_val = RD_REG32((rt_base_addr + USB3_ERDP_LO)); - erdp_reg_val &= ~(USB3_ERDP_LO_ERD_PNTR_MASK); + erdp_reg_val = runtime->erdp_lo.value & + ~(uint64_t) USB3_ERDP_LO_ERD_PNTR_MASK; erdp_reg_val |= ring_addr; - WR_REG64((rt_base_addr + USB3_ERDP_LO), erdp_reg_val); + runtime->erdp_lo.value = (uint32_t) erdp_reg_val; + runtime->erdp_hi.value = (uint32_t) (ring_addr >> 32); cache_force_write_back((void *)(uintptr_t) xer_ring->erst_ptr, sizeof(xhci_erst_entry_t)); diff --git a/src/portable/xhci/xhci_type.h b/src/portable/xhci/xhci_type.h index 76fcf716e..6446cab74 100644 --- a/src/portable/xhci/xhci_type.h +++ b/src/portable/xhci/xhci_type.h @@ -2899,25 +2899,25 @@ TU_VERIFY_STATIC(sizeof(xhci_rsvd_reg_t) == sizeof(uint32_t), "incorrect size"); /* xHCI capability and operational register map. */ typedef struct TU_ATTR_PACKED { - xhci_caplength_t caplength; // 0x0000 - xhci_hcsparams1_t hcsparams1; // 0x0004 - xhci_hcsparams2_t hcsparams2; // 0x0008 - xhci_hcsparams3_t hcsparams3; // 0x000c - xhci_hccparams1_t hccparams1; // 0x0010 - xhci_dboff_t dboff; // 0x0014 - xhci_rtsoff_t rtsoff; // 0x0018 - xhci_hccparams2_t hccparams2; // 0x001c - xhci_usbcmd_t usbcmd; // 0x0020 - xhci_usbsts_t usbsts; // 0x0024 - xhci_pagesize_t pagesize; // 0x0028 + volatile xhci_caplength_t caplength; // 0x0000 + volatile xhci_hcsparams1_t hcsparams1; // 0x0004 + volatile xhci_hcsparams2_t hcsparams2; // 0x0008 + volatile xhci_hcsparams3_t hcsparams3; // 0x000c + volatile xhci_hccparams1_t hccparams1; // 0x0010 + volatile xhci_dboff_t dboff; // 0x0014 + volatile xhci_rtsoff_t rtsoff; // 0x0018 + volatile xhci_hccparams2_t hccparams2; // 0x001c + volatile xhci_usbcmd_t usbcmd; // 0x0020 + volatile xhci_usbsts_t usbsts; // 0x0024 + volatile xhci_pagesize_t pagesize; // 0x0028 uint32_t reserved_2c_30[2]; // 0x002c..0x0030 - xhci_dnctrl_t dnctrl; // 0x0034 - xhci_crcr_lo_t crcr_lo; // 0x0038 - xhci_crcr_hi_t crcr_hi; // 0x003c + volatile xhci_dnctrl_t dnctrl; // 0x0034 + volatile xhci_crcr_lo_t crcr_lo; // 0x0038 + volatile xhci_crcr_hi_t crcr_hi; // 0x003c uint32_t reserved_40_4c[4]; // 0x0040..0x004c - xhci_dcbaap_lo_t dcbaap_lo; // 0x0050 - xhci_dcbaap_hi_t dcbaap_hi; // 0x0054 - xhci_config_t config; // 0x0058 + volatile xhci_dcbaap_lo_t dcbaap_lo; // 0x0050 + volatile xhci_dcbaap_hi_t dcbaap_hi; // 0x0054 + volatile xhci_config_t config; // 0x0058 } xhci_regs_t; TU_VERIFY_STATIC(offsetof(xhci_regs_t, caplength) == 0x0000, "incorrect register offset"); TU_VERIFY_STATIC(offsetof(xhci_regs_t, hcsparams1) == 0x0004, "incorrect register offset"); @@ -2938,6 +2938,27 @@ TU_VERIFY_STATIC(offsetof(xhci_regs_t, dcbaap_hi) == 0x0054, "incorrect register TU_VERIFY_STATIC(offsetof(xhci_regs_t, config) == 0x0058, "incorrect register offset"); TU_VERIFY_STATIC(sizeof(xhci_regs_t) == 0x5c, "incorrect register map size"); +/* xHCI interrupter runtime register map. */ +typedef struct TU_ATTR_PACKED { + uint32_t reserved_00_1c[8]; // 0x0000..0x001c + xhci_iman_t iman; // 0x0020 + xhci_imod_t imod; // 0x0024 + xhci_erstsz_t erstsz; // 0x0028 + uint32_t reserved_2c; // 0x002c + xhci_erstba_lo_t erstba_lo; // 0x0030 + xhci_erstba_hi_t erstba_hi; // 0x0034 + xhci_erdp_lo_t erdp_lo; // 0x0038 + xhci_erdp_hi_t erdp_hi; // 0x003c +} xhci_runtime_regs_t; +TU_VERIFY_STATIC(offsetof(xhci_runtime_regs_t, iman) == 0x0020, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_runtime_regs_t, imod) == 0x0024, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_runtime_regs_t, erstsz) == 0x0028, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_runtime_regs_t, erstba_lo) == 0x0030, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_runtime_regs_t, erstba_hi) == 0x0034, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_runtime_regs_t, erdp_lo) == 0x0038, "incorrect register offset"); +TU_VERIFY_STATIC(offsetof(xhci_runtime_regs_t, erdp_hi) == 0x003c, "incorrect register offset"); +TU_VERIFY_STATIC(sizeof(xhci_runtime_regs_t) == 0x40, "incorrect register map size"); + #ifdef __cplusplus } #endif From 8a62b16cfeb3dba58414cdff0065803bd6444498 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Fri, 20 Nov 2026 12:25:39 +0530 Subject: [PATCH 10/17] perform all register operations using xhci_type.h Signed-off-by: Sourav Raj K K --- src/portable/synopsys/dwc3/socfpga_usb3_reg.h | 2660 ----------------- src/portable/xhci/xhci_context.h | 2 +- src/portable/xhci/xhci_interrupts.c | 1 - src/portable/xhci/xhci_type.h | 22 + 4 files changed, 23 insertions(+), 2662 deletions(-) delete mode 100644 src/portable/synopsys/dwc3/socfpga_usb3_reg.h diff --git a/src/portable/synopsys/dwc3/socfpga_usb3_reg.h b/src/portable/synopsys/dwc3/socfpga_usb3_reg.h deleted file mode 100644 index d39c52544..000000000 --- a/src/portable/synopsys/dwc3/socfpga_usb3_reg.h +++ /dev/null @@ -1,2660 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation - * - * SPDX-License-Identifier: MIT-0 - * - * This contains the register defintions for Agilex5 USB3.1 controller - */ - -#ifndef __SOCFPGA_USB3_REG_H__ -#define __SOCFPGA_USB3_REG_H__ - -/* USB 3.1 controller base address */ -#define USBBASE (0x11000000U) - -/* CAPLENGTH */ -#define USB3_CAPLENGTH 0x0000U -/* HCSPARAMS1 */ -#define USB3_HCSPARAMS1 0x0004U -/* HCSPARAMS2 */ -#define USB3_HCSPARAMS2 0x0008U -/* HCSPARAMS3 */ -#define USB3_HCSPARAMS3 0x000CU -/* HCCPARAMS1 */ -#define USB3_HCCPARAMS1 0x0010U -/* DBOFF */ -#define USB3_DBOFF 0x0014U -/* RTSOFF */ -#define USB3_RTSOFF 0x0018U -/* HCCPARAMS2 */ -#define USB3_HCCPARAMS2 0x001CU -/* USBCMD */ -#define USB3_USBCMD 0x0020U -/* USBSTS */ -#define USB3_USBSTS 0x0024U -/* PAGESIZE */ -#define USB3_PAGESIZE 0x0028U -/* DNCTRL */ -#define USB3_DNCTRL 0x0034U -/* CRCR_LO */ -#define USB3_CRCR_LO 0x0038U -/* CRCR_HI */ -#define USB3_CRCR_HI 0x003CU -/* DCBAAP_LO */ -#define USB3_DCBAAP_LO 0x0050U -/* DCBAAP_HI */ -#define USB3_DCBAAP_HI 0x0054U -/* CONFIG */ -#define USB3_CONFIG 0x0058U -/* PORTSC_20 */ -#define USB3_PORTSC_20 0x0000U -/* PORTPMSC_20 */ -#define USB3_PORTPMSC_20 0x0004U -/* PORTLI_20 */ -#define USB3_PORTLI_20 0x0008U -/* PORTHLPMC_20 */ -#define USB3_PORTHLPMC_20 0x000CU -/* PORTSC_30 */ -#define USB3_PORTSC_30 0x0000U -/* PORTPMSC_30 */ -#define USB3_PORTPMSC_30 0x0004U -/* PORTLI_30 */ -#define USB3_PORTLI_30 0x0008U -/* PORTHLPMC_30 */ -#define USB3_PORTHLPMC_30 0x000CU -/* USBLEGSUP */ -#define USB3_USBLEGSUP 0x0440U -/* USBLEGCTLSTS */ -#define USB3_USBLEGCTLSTS 0x0444U -/* SUPTPRT2_DW0 */ -#define USB3_SUPTPRT2_DW0 0x0450U -/* SUPTPRT2_DW1 */ -#define USB3_SUPTPRT2_DW1 0x0454U -/* SUPTPRT2_DW2 */ -#define USB3_SUPTPRT2_DW2 0x0458U -/* SUPTPRT2_DW3 */ -#define USB3_SUPTPRT2_DW3 0x045CU -/* SUPTPRT3_DW0 */ -#define USB3_SUPTPRT3_DW0 0x0000U -/* SUPTPRT3_DW1 */ -#define USB3_SUPTPRT3_DW1 0x0004U -/* SUPTPRT3_DW2 */ -#define USB3_SUPTPRT3_DW2 0x0008U -/* SUPTPRT3_DW3 */ -#define USB3_SUPTPRT3_DW3 0x000CU -/* SUPTPRT3_DW4 */ -#define USB3_SUPTPRT3_DW4 0x0010U -/* SUPTPRT3_DW5 */ -#define USB3_SUPTPRT3_DW5 0x0014U -/* SUPTPRT3_DW6 */ -#define USB3_SUPTPRT3_DW6 0x0018U -/* SUPTPRT3_DW7 */ -#define USB3_SUPTPRT3_DW7 0x001CU -/* DCID */ -#define USB3_DCID 0x0480U -/* DCDB */ -#define USB3_DCDB 0x0484U -/* DCERSTSZ */ -#define USB3_DCERSTSZ 0x0488U -/* RSVD0 */ -#define USB3_RSVD0 0x048CU -/* DCERSTBA_LO */ -#define USB3_DCERSTBA_LO 0x0490U -/* DCERSTBA_HI */ -#define USB3_DCERSTBA_HI 0x0494U -/* DCERDP_LO */ -#define USB3_DCERDP_LO 0x0498U -/* DCERDP_HI */ -#define USB3_DCERDP_HI 0x049CU -/* DCCTRL */ -#define USB3_DCCTRL 0x04A0U -/* DCST */ -#define USB3_DCST 0x04A4U -/* DCPORTSC */ -#define USB3_DCPORTSC 0x04A8U -/* RSVD1 */ -#define USB3_RSVD1 0x04ACU -/* DCCP_LO */ -#define USB3_DCCP_LO 0x04B0U -/* DCCP_HI */ -#define USB3_DCCP_HI 0x04B4U -/* DCDDI1 */ -#define USB3_DCDDI1 0x04B8U -/* DCDDI2 */ -#define USB3_DCDDI2 0x04BCU -/* MFINDEX */ -#define USB3_MFINDEX 0x1000U -/* RsvdZ */ -#define USB3_RSVDZ 0x1004U -/* IMAN */ -#define USB3_IMAN 0x0020U -/* IMOD */ -#define USB3_IMOD 0x0004U -/* ERSTSZ */ -#define USB3_ERSTSZ 0x0028U -/* RsvdP */ -#define USB3_RSVDP 0x000CU -/* ERSTBA_LO */ -#define USB3_ERSTBA_LO 0x0030U -/* ERSTBA_HI */ -#define USB3_ERSTBA_HI 0x0014U -/* ERDP_LO */ -#define USB3_ERDP_LO 0x0038U -/* ERDP_HI */ -#define USB3_ERDP_HI 0x001CU -/* DB */ -#define USB3_DB 0x0000U -/* GSBUSCFG0 */ -#define USB3_GSBUSCFG0 0xC100U -/* GSBUSCFG1 */ -#define USB3_GSBUSCFG1 0xC104U -/* GTXTHRCFG */ -#define USB3_GTXTHRCFG 0xC108U -/* GRXTHRCFG */ -#define USB3_GRXTHRCFG 0xC10CU -/* GCTL */ -#define USB3_GCTL 0xC110U -/* GPMSTS */ -#define USB3_GPMSTS 0xC114U -/* GSTS */ -#define USB3_GSTS 0xC118U -/* GUCTL1 */ -#define USB3_GUCTL1 0xC11CU -/* USB31_IP_NAME */ -#define USB3_USB31_IP_NAME 0xC120U -/* GGPIO */ -#define USB3_GGPIO 0xC124U -/* GUID */ -#define USB3_GUID 0xC128U -/* GUCTL */ -#define USB3_GUCTL 0xC12CU -/* GBUSERRADDRLO */ -#define USB3_GBUSERRADDRLO 0xC130U -/* GBUSERRADDRHI */ -#define USB3_GBUSERRADDRHI 0xC134U -/* GPRTBIMAPLO */ -#define USB3_GPRTBIMAPLO 0xC138U -/* GPRTBIMAPHI */ -#define USB3_GPRTBIMAPHI 0xC13CU -/* GHWPARAMS0 */ -#define USB3_GHWPARAMS0 0xC140U -/* GHWPARAMS1 */ -#define USB3_GHWPARAMS1 0xC144U -/* GHWPARAMS2 */ -#define USB3_GHWPARAMS2 0xC148U -/* GHWPARAMS3 */ -#define USB3_GHWPARAMS3 0xC14CU -/* GHWPARAMS4 */ -#define USB3_GHWPARAMS4 0xC150U -/* GHWPARAMS5 */ -#define USB3_GHWPARAMS5 0xC154U -/* GHWPARAMS6 */ -#define USB3_GHWPARAMS6 0xC158U -/* GHWPARAMS7 */ -#define USB3_GHWPARAMS7 0xC15CU -/* GDBGFIFOSPACE */ -#define USB3_GDBGFIFOSPACE 0xC160U -/* GBMUCTL */ -#define USB3_GBMUCTL 0xC164U -/* GDBGBMU */ -#define USB3_GDBGBMU 0xC16CU -/* GDBGLSPMUX */ -#define USB3_GDBGLSPMUX 0xC170U -/* GDBGLSP */ -#define USB3_GDBGLSP 0xC174U -/* GDBGEPINFO0 */ -#define USB3_GDBGEPINFO0 0xC178U -/* GDBGEPINFO1 */ -#define USB3_GDBGEPINFO1 0xC17CU -/* GPRTBIMAP_HSLO */ -#define USB3_GPRTBIMAP_HSLO 0xC180U -/* GPRTBIMAP_HSHI */ -#define USB3_GPRTBIMAP_HSHI 0xC184U -/* GPRTBIMAP_FSLO */ -#define USB3_GPRTBIMAP_FSLO 0xC188U -/* GPRTBIMAP_FSHI */ -#define USB3_GPRTBIMAP_FSHI 0xC18CU -/* GHMSOCBWOR */ -#define USB3_GHMSOCBWOR 0xC190U -/* USB31_VER_NUMBER */ -#define USB3_USB31_VER_NUMBER 0xC1A0U -/* USB31_VER_TYPE */ -#define USB3_USB31_VER_TYPE 0xC1A4U -/* GSYSBLKWINCTRL */ -#define USB3_GSYSBLKWINCTRL 0xC1B0U -/* GPCIEL1EXTLAT */ -#define USB3_GPCIEL1EXTLAT 0xC1B4U -/* GUSB2PHYCFG */ -#define USB3_GUSB2PHYCFG 0xC200U -/* GUSB2PHYACC_ULPI */ -#define USB3_GUSB2PHYACC_ULPI 0x0000U -/* GUSB3PIPECTL */ -#define USB3_GUSB3PIPECTL 0xC2C0U -/* GTXFIFOSIZ0 */ -#define USB3_GTXFIFOSIZ0 0x0000U -/* GTXFIFOSIZ1 */ -#define USB3_GTXFIFOSIZ1 0x0004U -/* GTXFIFOSIZ2 */ -#define USB3_GTXFIFOSIZ2 0x0008U -/* GTXFIFOSIZ3 */ -#define USB3_GTXFIFOSIZ3 0x000CU -/* GTXFIFOSIZ4 */ -#define USB3_GTXFIFOSIZ4 0x0010U -/* GTXFIFOSIZ5 */ -#define USB3_GTXFIFOSIZ5 0x0014U -/* GTXFIFOSIZ6 */ -#define USB3_GTXFIFOSIZ6 0x0018U -/* GTXFIFOSIZ7 */ -#define USB3_GTXFIFOSIZ7 0x001CU -/* GTXFIFOSIZ8 */ -#define USB3_GTXFIFOSIZ8 0x0020U -/* GTXFIFOSIZ9 */ -#define USB3_GTXFIFOSIZ9 0x0024U -/* GTXFIFOSIZ10 */ -#define USB3_GTXFIFOSIZ10 0x0028U -/* GTXFIFOSIZ11 */ -#define USB3_GTXFIFOSIZ11 0x002CU -/* GTXFIFOSIZ12 */ -#define USB3_GTXFIFOSIZ12 0x0030U -/* GTXFIFOSIZ13 */ -#define USB3_GTXFIFOSIZ13 0x0034U -/* GTXFIFOSIZ14 */ -#define USB3_GTXFIFOSIZ14 0x0038U -/* GTXFIFOSIZ15 */ -#define USB3_GTXFIFOSIZ15 0x003CU -/* GRXFIFOSIZ0 */ -#define USB3_GRXFIFOSIZ0 0x0000U -/* GRXFIFOSIZ1 */ -#define USB3_GRXFIFOSIZ1 0x0004U -/* GRXFIFOSIZ2 */ -#define USB3_GRXFIFOSIZ2 0x0008U -/* GRXFIFOSIZ3 */ -#define USB3_GRXFIFOSIZ3 0x000CU -/* GRXFIFOSIZ4 */ -#define USB3_GRXFIFOSIZ4 0x0010U -/* GRXFIFOSIZ5 */ -#define USB3_GRXFIFOSIZ5 0x0014U -/* GEVNTADRLO */ -#define USB3_GEVNTADRLO 0x0000U -/* GEVNTADRHI */ -#define USB3_GEVNTADRHI 0x0004U -/* GEVNTSIZ */ -#define USB3_GEVNTSIZ 0x0008U -/* GEVNTCOUNT */ -#define USB3_GEVNTCOUNT 0x000CU -/* GHWPARAMS8 */ -#define USB3_GHWPARAMS8 0xC600U -/* GSMACCTL */ -#define USB3_GSMACCTL 0xC604U -/* GUCTL2 */ -#define USB3_GUCTL2 0xC608U -/* GUCTL3 */ -#define USB3_GUCTL3 0xC60CU -/* GTXFIFOPRIDEV */ -#define USB3_GTXFIFOPRIDEV 0xC610U -/* GTXFIFOPRIHST */ -#define USB3_GTXFIFOPRIHST 0xC618U -/* GRXFIFOPRIHST */ -#define USB3_GRXFIFOPRIHST 0xC61CU -/* GFIFOPRIDBC */ -#define USB3_GFIFOPRIDBC 0xC620U -/* GDMAHLRATIO */ -#define USB3_GDMAHLRATIO 0xC624U -/* GOSTDDMA_ASYNC */ -#define USB3_GOSTDDMA_ASYNC 0xC628U -/* GOSTDDMA_PRD */ -#define USB3_GOSTDDMA_PRD 0xC62CU -/* GFLADJ */ -#define USB3_GFLADJ 0xC630U -/* GUCTL4 */ -#define USB3_GUCTL4 0xC634U -/* GUCTL5 */ -#define USB3_GUCTL5 0xC638U -/* GUSB2RHBCTL */ -#define USB3_GUSB2RHBCTL 0x0000U -/* DCFG */ -#define USB3_DCFG 0xC700U -/* DCTL */ -#define USB3_DCTL 0xC704U -/* DEVTEN */ -#define USB3_DEVTEN 0xC708U -/* DSTS */ -#define USB3_DSTS 0xC70CU -/* DGCMDPAR */ -#define USB3_DGCMDPAR 0xC710U -/* DGCMD */ -#define USB3_DGCMD 0xC714U -/* DCTL1 */ -#define USB3_DCTL1 0xC718U -/* DALEPENA */ -#define USB3_DALEPENA 0xC720U -/* DLDMENA */ -#define USB3_DLDMENA 0xC724U -/* Rsvd */ -#define USB3_RSVD 0x0000U -/* DEPCMDPAR2 */ -#define USB3_DEPCMDPAR2 0x0000U -/* DEPCMDPAR1 */ -#define USB3_DEPCMDPAR1 0x0004U -/* DEPCMDPAR0 */ -#define USB3_DEPCMDPAR0 0x0008U -/* DEPCMD */ -#define USB3_DEPCMD 0x000CU -/* DEV_IMOD */ -#define USB3_DEV_IMOD 0x0000U -/* rsvd0_reg */ -#define USB3_RSVD0_REG 0xCC00U -/* LU1LFPSRXTIM */ -#define USB3_LU1LFPSRXTIM 0x0000U -/* LU1LFPSTXTIM */ -#define USB3_LU1LFPSTXTIM 0x0004U -/* LU2LFPSRXTIM */ -#define USB3_LU2LFPSRXTIM 0x0008U -/* LU2LFPSTXTIM */ -#define USB3_LU2LFPSTXTIM 0x000CU -/* LU3LFPSRXTIM */ -#define USB3_LU3LFPSRXTIM 0x0010U -/* LU3LFPSTXTIM */ -#define USB3_LU3LFPSTXTIM 0x0014U -/* LPINGLFPSTIM */ -#define USB3_LPINGLFPSTIM 0x0018U -/* LPOLLLFPSTXTIM */ -#define USB3_LPOLLLFPSTXTIM 0x001CU -/* LSKIPFREQ */ -#define USB3_LSKIPFREQ 0x0020U -/* LLUCTL */ -#define USB3_LLUCTL 0x0024U -/* LPTMDPDELAY */ -#define USB3_LPTMDPDELAY 0x0028U -/* LSCDTIM1 */ -#define USB3_LSCDTIM1 0x002CU -/* LSCDTIM2 */ -#define USB3_LSCDTIM2 0x0030U -/* LSCDTIM3 */ -#define USB3_LSCDTIM3 0x0034U -/* LSCDTIM4 */ -#define USB3_LSCDTIM4 0x0038U -/* LLPBMTIM1 */ -#define USB3_LLPBMTIM1 0x003CU -/* LLPBMTIM2 */ -#define USB3_LLPBMTIM2 0x0040U -/* LLPBMTXTIM */ -#define USB3_LLPBMTXTIM 0x0044U -/* LLINKERRINJ */ -#define USB3_LLINKERRINJ 0x0048U -/* LLINKERRINJEN */ -#define USB3_LLINKERRINJEN 0x004CU -/* GDBGLTSSM */ -#define USB3_GDBGLTSSM 0x0050U -/* GDBGLNMCC */ -#define USB3_GDBGLNMCC 0x0054U -/* LLINKDBGCTRL */ -#define USB3_LLINKDBGCTRL 0x0058U -/* LLINKDBGCNTTRIG */ -#define USB3_LLINKDBGCNTTRIG 0x005CU -/* LCSR_TX_DEEMPH */ -#define USB3_LCSR_TX_DEEMPH 0x0060U -/* LCSR_TX_DEEMPH_1 */ -#define USB3_LCSR_TX_DEEMPH_1 0x0064U -/* LCSR_TX_DEEMPH_2 */ -#define USB3_LCSR_TX_DEEMPH_2 0x0068U -/* LCSR_TX_DEEMPH_3 */ -#define USB3_LCSR_TX_DEEMPH_3 0x006CU -/* LCSRPTMDEBUG1 */ -#define USB3_LCSRPTMDEBUG1 0x0070U -/* LCSRPTMDEBUG2 */ -#define USB3_LCSRPTMDEBUG2 0x0074U -/* LPTMDPDELAY2 */ -#define USB3_LPTMDPDELAY2 0x0078U -/* BU31RHBDBG */ -#define USB3_BU31RHBDBG 0x0000U -/* BRAMHIADDR */ -#define USB3_BRAMHIADDR 0xD84CU -/* BRSERRCNT */ -#define USB3_BRSERRCNT 0xD850U -/* BRMERRCNT */ -#define USB3_BRMERRCNT 0xD854U -/* BRAMECCERR */ -#define USB3_BRAMECCERR 0xD858U -/* BRERRCTL */ -#define USB3_BRERRCTL 0xD85CU -/* BRAM0ADDRERR */ -#define USB3_BRAM0ADDRERR 0xD860U -/* BRAM1ADDRERR */ -#define USB3_BRAM1ADDRERR 0xD864U -/* BRAM2ADDRERR */ -#define USB3_BRAM2ADDRERR 0xD868U -/* BRAM3ADDRERR */ -#define USB3_BRAM3ADDRERR 0xD86CU -/* BRAM4ADDRERR */ -#define USB3_BRAM4ADDRERR 0xD870U -/* BLOOPBCKCTRL */ -#define USB3_BLOOPBCKCTRL 0xD900U -/* BLOOPBCKTFERSZ */ -#define USB3_BLOOPBCKTFERSZ 0xD904U -/* BBISTDATAPATSEED */ -#define USB3_BBISTDATAPATSEED 0xD908U -/* BBISTCTRL */ -#define USB3_BBISTCTRL 0xD90CU -/* BBISTXFERSTS0 */ -#define USB3_BBISTXFERSTS0 0xD910U -/* BBISTXFERSTS1 */ -#define USB3_BBISTXFERSTS1 0xD914U -/* BBISTXFERSTS2 */ -#define USB3_BBISTXFERSTS2 0xD918U -/* BBISTXFERSTS3 */ -#define USB3_BBISTXFERSTS3 0xD91CU -/* BBISTEXPDATASTS0 */ -#define USB3_BBISTEXPDATASTS0 0xD920U -/* BBISTEXPDATASTS1 */ -#define USB3_BBISTEXPDATASTS1 0xD924U -/* BBISTEXPDATASTS2 */ -#define USB3_BBISTEXPDATASTS2 0xD928U -/* BBISTEXPDATASTS3 */ -#define USB3_BBISTEXPDATASTS3 0xD92CU -/* BBISTRCVDDATASTS0 */ -#define USB3_BBISTRCVDDATASTS0 0xD930U -/* BBISTRCVDDATASTS1 */ -#define USB3_BBISTRCVDDATASTS1 0xD934U -/* BBISTRCVDDATASTS2 */ -#define USB3_BBISTRCVDDATASTS2 0xD938U -/* BBISTRCVDDATASTS3 */ -#define USB3_BBISTRCVDDATASTS3 0xD93CU -/* rsvd_reg */ -#define USB3_RSVD_REG 0xDA00U - -/* Bit fields of CAPLENGTH register */ -#define USB3_CAPLENGTH_HCIVERSION_MASK 0xFFFF0000U -#define USB3_CAPLENGTH_HCIVERSION_POS 16U -#define USB3_CAPLENGTH_CAPLENGTH_MASK 0x000000FFU -#define USB3_CAPLENGTH_CAPLENGTH_POS 0U - -/* Bit fields of HCSPARAMS1 register */ -#define USB3_HCSPARAMS1_MAXPORTS_MASK 0xFF000000U -#define USB3_HCSPARAMS1_MAXPORTS_POS 24U -#define USB3_HCSPARAMS1_MAXINTRS_MASK 0x0007FF00U -#define USB3_HCSPARAMS1_MAXINTRS_POS 8U -#define USB3_HCSPARAMS1_MAXSLOTS_MASK 0x000000FFU -#define USB3_HCSPARAMS1_MAXSLOTS_POS 0U - -/* Bit fields of HCSPARAMS2 register */ -#define USB3_HCSPARAMS2_MAXSCRATCHPADBUFS_MASK 0xF8000000U -#define USB3_HCSPARAMS2_MAXSCRATCHPADBUFS_POS 27U -#define USB3_HCSPARAMS2_SPR_MASK 0x04000000U -#define USB3_HCSPARAMS2_SPR_POS 26U -#define USB3_HCSPARAMS2_MAXSCRATCHPADBUFS_HI_MASK 0x03E00000U -#define USB3_HCSPARAMS2_MAXSCRATCHPADBUFS_HI_POS 21U -#define USB3_HCSPARAMS2_ERSTMAX_MASK 0x000000F0U -#define USB3_HCSPARAMS2_ERSTMAX_POS 4U -#define USB3_HCSPARAMS2_IST_MASK 0x0000000FU -#define USB3_HCSPARAMS2_IST_POS 0U - -/* Bit fields of HCSPARAMS3 register */ -#define USB3_HCSPARAMS3_U2_DEVICE_EXIT_LAT_MASK 0xFFFF0000U -#define USB3_HCSPARAMS3_U2_DEVICE_EXIT_LAT_POS 16U -#define USB3_HCSPARAMS3_U1_DEVICE_EXIT_LAT_MASK 0x000000FFU -#define USB3_HCSPARAMS3_U1_DEVICE_EXIT_LAT_POS 0U - -/* Bit fields of HCCPARAMS1 register */ -#define USB3_HCCPARAMS1_XECP_MASK 0xFFFF0000U -#define USB3_HCCPARAMS1_XECP_POS 16U -#define USB3_HCCPARAMS1_MAXPSASIZE_MASK 0x0000F000U -#define USB3_HCCPARAMS1_MAXPSASIZE_POS 12U -#define USB3_HCCPARAMS1_CFC_MASK 0x00000800U -#define USB3_HCCPARAMS1_CFC_POS 11U -#define USB3_HCCPARAMS1_SEC_MASK 0x00000400U -#define USB3_HCCPARAMS1_SEC_POS 10U -#define USB3_HCCPARAMS1_SPC_MASK 0x00000200U -#define USB3_HCCPARAMS1_SPC_POS 9U -#define USB3_HCCPARAMS1_PAE_MASK 0x00000100U -#define USB3_HCCPARAMS1_PAE_POS 8U -#define USB3_HCCPARAMS1_NSS_MASK 0x00000080U -#define USB3_HCCPARAMS1_NSS_POS 7U -#define USB3_HCCPARAMS1_LTC_MASK 0x00000040U -#define USB3_HCCPARAMS1_LTC_POS 6U -#define USB3_HCCPARAMS1_LHRC_MASK 0x00000020U -#define USB3_HCCPARAMS1_LHRC_POS 5U -#define USB3_HCCPARAMS1_PIND_MASK 0x00000010U -#define USB3_HCCPARAMS1_PIND_POS 4U -#define USB3_HCCPARAMS1_PPC_MASK 0x00000008U -#define USB3_HCCPARAMS1_PPC_POS 3U -#define USB3_HCCPARAMS1_CSZ_MASK 0x00000004U -#define USB3_HCCPARAMS1_CSZ_POS 2U -#define USB3_HCCPARAMS1_BNC_MASK 0x00000002U -#define USB3_HCCPARAMS1_BNC_POS 1U -#define USB3_HCCPARAMS1_AC64_MASK 0x00000001U -#define USB3_HCCPARAMS1_AC64_POS 0U - -/* Bit fields of DBOFF register */ -#define USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK 0xFFFFFFFCU -#define USB3_DBOFF_DOORBELL_ARRAY_OFFSET_POS 2U - -/* Bit fields of RTSOFF register */ -#define USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK 0xFFFFFFE0U -#define USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_POS 5U - -/* Bit fields of HCCPARAMS2 register */ -#define USB3_HCCPARAMS2_ETC_TSC_MASK 0x00000080U -#define USB3_HCCPARAMS2_ETC_TSC_POS 7U -#define USB3_HCCPARAMS2_ETC_MASK 0x00000040U -#define USB3_HCCPARAMS2_ETC_POS 6U -#define USB3_HCCPARAMS2_CIC_MASK 0x00000020U -#define USB3_HCCPARAMS2_CIC_POS 5U -#define USB3_HCCPARAMS2_LEC_MASK 0x00000010U -#define USB3_HCCPARAMS2_LEC_POS 4U -#define USB3_HCCPARAMS2_CTC_MASK 0x00000008U -#define USB3_HCCPARAMS2_CTC_POS 3U -#define USB3_HCCPARAMS2_FSC_MASK 0x00000004U -#define USB3_HCCPARAMS2_FSC_POS 2U -#define USB3_HCCPARAMS2_CMC_MASK 0x00000002U -#define USB3_HCCPARAMS2_CMC_POS 1U -#define USB3_HCCPARAMS2_U3C_MASK 0x00000001U -#define USB3_HCCPARAMS2_U3C_POS 0U - -/* Bit fields of USBCMD register */ -#define USB3_USBCMD_ETE_MASK 0x00004000U -#define USB3_USBCMD_ETE_POS 14U -#define USB3_USBCMD_CME_MASK 0x00002000U -#define USB3_USBCMD_CME_POS 13U -#define USB3_USBCMD_EU3S_MASK 0x00000800U -#define USB3_USBCMD_EU3S_POS 11U -#define USB3_USBCMD_EWE_MASK 0x00000400U -#define USB3_USBCMD_EWE_POS 10U -#define USB3_USBCMD_CRS_MASK 0x00000200U -#define USB3_USBCMD_CRS_POS 9U -#define USB3_USBCMD_CSS_MASK 0x00000100U -#define USB3_USBCMD_CSS_POS 8U -#define USB3_USBCMD_LHCRST_MASK 0x00000080U -#define USB3_USBCMD_LHCRST_POS 7U -#define USB3_USBCMD_HSEE_MASK 0x00000008U -#define USB3_USBCMD_HSEE_POS 3U -#define USB3_USBCMD_INTE_MASK 0x00000004U -#define USB3_USBCMD_INTE_POS 2U -#define USB3_USBCMD_HCRST_MASK 0x00000002U -#define USB3_USBCMD_HCRST_POS 1U -#define USB3_USBCMD_R_S_MASK 0x00000001U -#define USB3_USBCMD_R_S_POS 0U - -/* Bit fields of USBSTS register */ -#define USB3_USBSTS_HCE_MASK 0x00001000U -#define USB3_USBSTS_HCE_POS 12U -#define USB3_USBSTS_CNR_MASK 0x00000800U -#define USB3_USBSTS_CNR_POS 11U -#define USB3_USBSTS_SRE_MASK 0x00000400U -#define USB3_USBSTS_SRE_POS 10U -#define USB3_USBSTS_RSS_MASK 0x00000200U -#define USB3_USBSTS_RSS_POS 9U -#define USB3_USBSTS_SSS_MASK 0x00000100U -#define USB3_USBSTS_SSS_POS 8U -#define USB3_USBSTS_PCD_MASK 0x00000010U -#define USB3_USBSTS_PCD_POS 4U -#define USB3_USBSTS_EINT_MASK 0x00000008U -#define USB3_USBSTS_EINT_POS 3U -#define USB3_USBSTS_HSE_MASK 0x00000004U -#define USB3_USBSTS_HSE_POS 2U -#define USB3_USBSTS_HCH_MASK 0x00000001U -#define USB3_USBSTS_HCH_POS 0U - -/* Bit fields of PAGESIZE register */ -#define USB3_PAGESIZE_PAGE_SIZE_MASK 0x0000FFFFU -#define USB3_PAGESIZE_PAGE_SIZE_POS 0U - -/* Bit fields of DNCTRL register */ -#define USB3_DNCTRL_N0_N15_MASK 0x0000FFFFU -#define USB3_DNCTRL_N0_N15_POS 0U - -/* Bit fields of CRCR_LO register */ -#define USB3_CRCR_LO_CMD_RING_PNTR_MASK 0xFFFFFFC0U -#define USB3_CRCR_LO_CMD_RING_PNTR_POS 6U -#define USB3_CRCR_LO_CRR_MASK 0x00000008U -#define USB3_CRCR_LO_CRR_POS 3U -#define USB3_CRCR_LO_CA_MASK 0x00000004U -#define USB3_CRCR_LO_CA_POS 2U -#define USB3_CRCR_LO_CS_MASK 0x00000002U -#define USB3_CRCR_LO_CS_POS 1U -#define USB3_CRCR_LO_RCS_MASK 0x00000001U -#define USB3_CRCR_LO_RCS_POS 0U - -/* Bit fields of CRCR_HI register */ -#define USB3_CRCR_HI_CMD_RING_PNTR_MASK 0xFFFFFFFFU -#define USB3_CRCR_HI_CMD_RING_PNTR_POS 0U - -/* Bit fields of DCBAAP_LO register */ -#define USB3_DCBAAP_LO_DEVICE_CONTEXT_BAAP_MASK 0xFFFFFFC0U -#define USB3_DCBAAP_LO_DEVICE_CONTEXT_BAAP_POS 6U - -/* Bit fields of DCBAAP_HI register */ -#define USB3_DCBAAP_HI_DEVICE_CONTEXT_BAAP_MASK 0xFFFFFFFFU -#define USB3_DCBAAP_HI_DEVICE_CONTEXT_BAAP_POS 0U - -/* Bit fields of CONFIG register */ -#define USB3_CONFIG_CIE_MASK 0x00000200U -#define USB3_CONFIG_CIE_POS 9U -#define USB3_CONFIG_U3E_MASK 0x00000100U -#define USB3_CONFIG_U3E_POS 8U -#define USB3_CONFIG_MAXSLOTSEN_MASK 0x000000FFU -#define USB3_CONFIG_MAXSLOTSEN_POS 0U - -/* Bit fields of PORTSC_20 register */ -#define USB3_PORTSC_20_DR_MASK 0x40000000U -#define USB3_PORTSC_20_DR_POS 30U -#define USB3_PORTSC_20_WOE_MASK 0x08000000U -#define USB3_PORTSC_20_WOE_POS 27U -#define USB3_PORTSC_20_WDE_MASK 0x04000000U -#define USB3_PORTSC_20_WDE_POS 26U -#define USB3_PORTSC_20_WCE_MASK 0x02000000U -#define USB3_PORTSC_20_WCE_POS 25U -#define USB3_PORTSC_20_CAS_MASK 0x01000000U -#define USB3_PORTSC_20_CAS_POS 24U -#define USB3_PORTSC_20_PLC_MASK 0x00400000U -#define USB3_PORTSC_20_PLC_POS 22U -#define USB3_PORTSC_20_PRC_MASK 0x00200000U -#define USB3_PORTSC_20_PRC_POS 21U -#define USB3_PORTSC_20_OCC_MASK 0x00100000U -#define USB3_PORTSC_20_OCC_POS 20U -#define USB3_PORTSC_20_PEC_MASK 0x00040000U -#define USB3_PORTSC_20_PEC_POS 18U -#define USB3_PORTSC_20_CSC_MASK 0x00020000U -#define USB3_PORTSC_20_CSC_POS 17U -#define USB3_PORTSC_20_LWS_MASK 0x00010000U -#define USB3_PORTSC_20_LWS_POS 16U -#define USB3_PORTSC_20_PIC_MASK 0x0000C000U -#define USB3_PORTSC_20_PIC_POS 14U -#define USB3_PORTSC_20_PORTSPEED_MASK 0x00003C00U -#define USB3_PORTSC_20_PORTSPEED_POS 10U -#define USB3_PORTSC_20_PP_MASK 0x00000200U -#define USB3_PORTSC_20_PP_POS 9U -#define USB3_PORTSC_20_PLS_MASK 0x000001E0U -#define USB3_PORTSC_20_PLS_POS 5U -#define USB3_PORTSC_20_PR_MASK 0x00000010U -#define USB3_PORTSC_20_PR_POS 4U -#define USB3_PORTSC_20_OCA_MASK 0x00000008U -#define USB3_PORTSC_20_OCA_POS 3U -#define USB3_PORTSC_20_PED_MASK 0x00000002U -#define USB3_PORTSC_20_PED_POS 1U -#define USB3_PORTSC_20_CCS_MASK 0x00000001U -#define USB3_PORTSC_20_CCS_POS 0U - -/* Bit fields of PORTPMSC_20 register */ -#define USB3_PORTPMSC_20_PRTTSTCTRL_MASK 0xF0000000U -#define USB3_PORTPMSC_20_PRTTSTCTRL_POS 28U -#define USB3_PORTPMSC_20_HLE_MASK 0x00010000U -#define USB3_PORTPMSC_20_HLE_POS 16U -#define USB3_PORTPMSC_20_L1DSLOT_MASK 0x0000FF00U -#define USB3_PORTPMSC_20_L1DSLOT_POS 8U -#define USB3_PORTPMSC_20_BESL_MASK 0x000000F0U -#define USB3_PORTPMSC_20_BESL_POS 4U -#define USB3_PORTPMSC_20_RWE_MASK 0x00000008U -#define USB3_PORTPMSC_20_RWE_POS 3U -#define USB3_PORTPMSC_20_L1S_MASK 0x00000007U -#define USB3_PORTPMSC_20_L1S_POS 0U - -/* Bit fields of PORTLI_20 register */ - -/* Bit fields of PORTHLPMC_20 register */ -#define USB3_PORTHLPMC_20_BESLD_MASK 0x00003C00U -#define USB3_PORTHLPMC_20_BESLD_POS 10U -#define USB3_PORTHLPMC_20_L1_TIMEOUT_MASK 0x000003FCU -#define USB3_PORTHLPMC_20_L1_TIMEOUT_POS 2U -#define USB3_PORTHLPMC_20_HIRDM_MASK 0x00000003U -#define USB3_PORTHLPMC_20_HIRDM_POS 0U - -/* Bit fields of PORTSC_30 register */ -#define USB3_PORTSC_30_WPR_MASK 0x80000000U -#define USB3_PORTSC_30_WPR_POS 31U -#define USB3_PORTSC_30_DR_MASK 0x40000000U -#define USB3_PORTSC_30_DR_POS 30U -#define USB3_PORTSC_30_WOE_MASK 0x08000000U -#define USB3_PORTSC_30_WOE_POS 27U -#define USB3_PORTSC_30_WDE_MASK 0x04000000U -#define USB3_PORTSC_30_WDE_POS 26U -#define USB3_PORTSC_30_WCE_MASK 0x02000000U -#define USB3_PORTSC_30_WCE_POS 25U -#define USB3_PORTSC_30_CAS_MASK 0x01000000U -#define USB3_PORTSC_30_CAS_POS 24U -#define USB3_PORTSC_30_CEC_MASK 0x00800000U -#define USB3_PORTSC_30_CEC_POS 23U -#define USB3_PORTSC_30_PLC_MASK 0x00400000U -#define USB3_PORTSC_30_PLC_POS 22U -#define USB3_PORTSC_30_PRC_MASK 0x00200000U -#define USB3_PORTSC_30_PRC_POS 21U -#define USB3_PORTSC_30_OCC_MASK 0x00100000U -#define USB3_PORTSC_30_OCC_POS 20U -#define USB3_PORTSC_30_WRC_MASK 0x00080000U -#define USB3_PORTSC_30_WRC_POS 19U -#define USB3_PORTSC_30_PEC_MASK 0x00040000U -#define USB3_PORTSC_30_PEC_POS 18U -#define USB3_PORTSC_30_CSC_MASK 0x00020000U -#define USB3_PORTSC_30_CSC_POS 17U -#define USB3_PORTSC_30_LWS_MASK 0x00010000U -#define USB3_PORTSC_30_LWS_POS 16U -#define USB3_PORTSC_30_PIC_MASK 0x0000C000U -#define USB3_PORTSC_30_PIC_POS 14U -#define USB3_PORTSC_30_PORTSPEED_MASK 0x00003C00U -#define USB3_PORTSC_30_PORTSPEED_POS 10U -#define USB3_PORTSC_30_PP_MASK 0x00000200U -#define USB3_PORTSC_30_PP_POS 9U -#define USB3_PORTSC_30_PLS_MASK 0x000001E0U -#define USB3_PORTSC_30_PLS_POS 5U -#define USB3_PORTSC_30_PR_MASK 0x00000010U -#define USB3_PORTSC_30_PR_POS 4U -#define USB3_PORTSC_30_OCA_MASK 0x00000008U -#define USB3_PORTSC_30_OCA_POS 3U -#define USB3_PORTSC_30_PED_MASK 0x00000002U -#define USB3_PORTSC_30_PED_POS 1U -#define USB3_PORTSC_30_CCS_MASK 0x00000001U -#define USB3_PORTSC_30_CCS_POS 0U - -/* Bit fields of PORTPMSC_30 register */ -#define USB3_PORTPMSC_30_FLA_MASK 0x00010000U -#define USB3_PORTPMSC_30_FLA_POS 16U -#define USB3_PORTPMSC_30_U2_TIMEOUT_MASK 0x0000FF00U -#define USB3_PORTPMSC_30_U2_TIMEOUT_POS 8U -#define USB3_PORTPMSC_30_U1_TIMEOUT_MASK 0x000000FFU -#define USB3_PORTPMSC_30_U1_TIMEOUT_POS 0U - -/* Bit fields of PORTLI_30 register */ -#define USB3_PORTLI_30_TLC_MASK 0x00F00000U -#define USB3_PORTLI_30_TLC_POS 20U -#define USB3_PORTLI_30_RLC_MASK 0x000F0000U -#define USB3_PORTLI_30_RLC_POS 16U -#define USB3_PORTLI_30_LINK_ERROR_COUNT_MASK 0x0000FFFFU -#define USB3_PORTLI_30_LINK_ERROR_COUNT_POS 0U - -/* Bit fields of PORTHLPMC_30 register */ - -/* Bit fields of USBLEGSUP register */ -#define USB3_USBLEGSUP_HC_OS_OWNED_MASK 0x01000000U -#define USB3_USBLEGSUP_HC_OS_OWNED_POS 24U -#define USB3_USBLEGSUP_HC_BIOS_OWNED_MASK 0x00010000U -#define USB3_USBLEGSUP_HC_BIOS_OWNED_POS 16U -#define USB3_USBLEGSUP_NEXT_CAPABILITY_POINTER_MASK 0x0000FF00U -#define USB3_USBLEGSUP_NEXT_CAPABILITY_POINTER_POS 8U -#define USB3_USBLEGSUP_CAPABILITY_ID_MASK 0x000000FFU -#define USB3_USBLEGSUP_CAPABILITY_ID_POS 0U - -/* Bit fields of USBLEGCTLSTS register */ -#define USB3_USBLEGCTLSTS_SMI_ON_BAR_MASK 0x80000000U -#define USB3_USBLEGCTLSTS_SMI_ON_BAR_POS 31U -#define USB3_USBLEGCTLSTS_SMI_ON_PCI_MASK 0x40000000U -#define USB3_USBLEGCTLSTS_SMI_ON_PCI_POS 30U -#define USB3_USBLEGCTLSTS_SMI_ON_OS_MASK 0x20000000U -#define USB3_USBLEGCTLSTS_SMI_ON_OS_POS 29U -#define USB3_USBLEGCTLSTS_SMI_ON_HOST_MASK 0x00100000U -#define USB3_USBLEGCTLSTS_SMI_ON_HOST_POS 20U -#define USB3_USBLEGCTLSTS_SMI_ON_EVENT_MASK 0x00010000U -#define USB3_USBLEGCTLSTS_SMI_ON_EVENT_POS 16U -#define USB3_USBLEGCTLSTS_SMI_ON_BAR_E_MASK 0x00008000U -#define USB3_USBLEGCTLSTS_SMI_ON_BAR_E_POS 15U -#define USB3_USBLEGCTLSTS_SMI_ON_PCI_E_MASK 0x00004000U -#define USB3_USBLEGCTLSTS_SMI_ON_PCI_E_POS 14U -#define USB3_USBLEGCTLSTS_SMI_ON_OS_E_MASK 0x00002000U -#define USB3_USBLEGCTLSTS_SMI_ON_OS_E_POS 13U -#define USB3_USBLEGCTLSTS_SMI_ON_HOST_E_MASK 0x00000010U -#define USB3_USBLEGCTLSTS_SMI_ON_HOST_E_POS 4U -#define USB3_USBLEGCTLSTS_USB_SMI_ENABLE_MASK 0x00000001U -#define USB3_USBLEGCTLSTS_USB_SMI_ENABLE_POS 0U - -/* Bit fields of SUPTPRT2_DW0 register */ -#define USB3_SUPTPRT2_DW0_MAJOR_REVISION_MASK 0xFF000000U -#define USB3_SUPTPRT2_DW0_MAJOR_REVISION_POS 24U -#define USB3_SUPTPRT2_DW0_MINOR_REVISION_MASK 0x00FF0000U -#define USB3_SUPTPRT2_DW0_MINOR_REVISION_POS 16U -#define USB3_SUPTPRT2_DW0_NEXT_CAPABILITY_POINTER_MASK 0x0000FF00U -#define USB3_SUPTPRT2_DW0_NEXT_CAPABILITY_POINTER_POS 8U -#define USB3_SUPTPRT2_DW0_CAPABILITY_ID_MASK 0x000000FFU -#define USB3_SUPTPRT2_DW0_CAPABILITY_ID_POS 0U - -/* Bit fields of SUPTPRT2_DW1 register */ -#define USB3_SUPTPRT2_DW1_NAME_STRING_MASK 0xFFFFFFFFU -#define USB3_SUPTPRT2_DW1_NAME_STRING_POS 0U - -/* Bit fields of SUPTPRT2_DW2 register */ -#define USB3_SUPTPRT2_DW2_PSIC_MASK 0xF0000000U -#define USB3_SUPTPRT2_DW2_PSIC_POS 28U -#define USB3_SUPTPRT2_DW2_MHD_MASK 0x0E000000U -#define USB3_SUPTPRT2_DW2_MHD_POS 25U -#define USB3_SUPTPRT2_DW2_BLC_MASK 0x00100000U -#define USB3_SUPTPRT2_DW2_BLC_POS 20U -#define USB3_SUPTPRT2_DW2_HLC_MASK 0x00080000U -#define USB3_SUPTPRT2_DW2_HLC_POS 19U -#define USB3_SUPTPRT2_DW2_IHI_MASK 0x00040000U -#define USB3_SUPTPRT2_DW2_IHI_POS 18U -#define USB3_SUPTPRT2_DW2_HSO_MASK 0x00020000U -#define USB3_SUPTPRT2_DW2_HSO_POS 17U -#define USB3_SUPTPRT2_DW2_L1C_MASK 0x00010000U -#define USB3_SUPTPRT2_DW2_L1C_POS 16U -#define USB3_SUPTPRT2_DW2_COMPATIBLE_PORT_COUNT_MASK 0x0000FF00U -#define USB3_SUPTPRT2_DW2_COMPATIBLE_PORT_COUNT_POS 8U -#define USB3_SUPTPRT2_DW2_COMPATIBLE_PORT_OFFSET_MASK 0x000000FFU -#define USB3_SUPTPRT2_DW2_COMPATIBLE_PORT_OFFSET_POS 0U - -/* Bit fields of SUPTPRT2_DW3 register */ -#define USB3_SUPTPRT2_DW3_PROTCL_SLT_TY_MASK 0x0000001FU -#define USB3_SUPTPRT2_DW3_PROTCL_SLT_TY_POS 0U - -/* Bit fields of SUPTPRT3_DW0 register */ -#define USB3_SUPTPRT3_DW0_MAJOR_REVISION_MASK 0xFF000000U -#define USB3_SUPTPRT3_DW0_MAJOR_REVISION_POS 24U -#define USB3_SUPTPRT3_DW0_MINOR_REVISION_MASK 0x00FF0000U -#define USB3_SUPTPRT3_DW0_MINOR_REVISION_POS 16U -#define USB3_SUPTPRT3_DW0_NEXT_CAPABILITY_POINTER_MASK 0x0000FF00U -#define USB3_SUPTPRT3_DW0_NEXT_CAPABILITY_POINTER_POS 8U -#define USB3_SUPTPRT3_DW0_CAPABILITY_ID_MASK 0x000000FFU -#define USB3_SUPTPRT3_DW0_CAPABILITY_ID_POS 0U - -/* Bit fields of SUPTPRT3_DW1 register */ -#define USB3_SUPTPRT3_DW1_NAME_STRING_MASK 0xFFFFFFFFU -#define USB3_SUPTPRT3_DW1_NAME_STRING_POS 0U - -/* Bit fields of SUPTPRT3_DW2 register */ -#define USB3_SUPTPRT3_DW2_PSIC_MASK 0xF0000000U -#define USB3_SUPTPRT3_DW2_PSIC_POS 28U -#define USB3_SUPTPRT3_DW2_COMPATIBLE_PORT_COUNT_MASK 0x0000FF00U -#define USB3_SUPTPRT3_DW2_COMPATIBLE_PORT_COUNT_POS 8U -#define USB3_SUPTPRT3_DW2_COMPATIBLE_PORT_OFFSET_MASK 0x000000FFU -#define USB3_SUPTPRT3_DW2_COMPATIBLE_PORT_OFFSET_POS 0U - -/* Bit fields of SUPTPRT3_DW3 register */ -#define USB3_SUPTPRT3_DW3_PROTCL_SLT_TY_MASK 0x0000001FU -#define USB3_SUPTPRT3_DW3_PROTCL_SLT_TY_POS 0U - -/* Bit fields of SUPTPRT3_DW4 register */ -#define USB3_SUPTPRT3_DW4_PSIM_MASK 0xFFFF0000U -#define USB3_SUPTPRT3_DW4_PSIM_POS 16U -#define USB3_SUPTPRT3_DW4_LP_MASK 0x0000C000U -#define USB3_SUPTPRT3_DW4_LP_POS 14U -#define USB3_SUPTPRT3_DW4_PFD_MASK 0x00000100U -#define USB3_SUPTPRT3_DW4_PFD_POS 8U -#define USB3_SUPTPRT3_DW4_PLT_MASK 0x000000C0U -#define USB3_SUPTPRT3_DW4_PLT_POS 6U -#define USB3_SUPTPRT3_DW4_PSIE_MASK 0x00000030U -#define USB3_SUPTPRT3_DW4_PSIE_POS 4U -#define USB3_SUPTPRT3_DW4_PSIV_MASK 0x0000000FU -#define USB3_SUPTPRT3_DW4_PSIV_POS 0U - -/* Bit fields of SUPTPRT3_DW5 register */ -#define USB3_SUPTPRT3_DW5_PSIM_MASK 0xFFFF0000U -#define USB3_SUPTPRT3_DW5_PSIM_POS 16U -#define USB3_SUPTPRT3_DW5_LP_MASK 0x0000C000U -#define USB3_SUPTPRT3_DW5_LP_POS 14U -#define USB3_SUPTPRT3_DW5_PFD_MASK 0x00000100U -#define USB3_SUPTPRT3_DW5_PFD_POS 8U -#define USB3_SUPTPRT3_DW5_PLT_MASK 0x000000C0U -#define USB3_SUPTPRT3_DW5_PLT_POS 6U -#define USB3_SUPTPRT3_DW5_PSIE_MASK 0x00000030U -#define USB3_SUPTPRT3_DW5_PSIE_POS 4U -#define USB3_SUPTPRT3_DW5_PSIV_MASK 0x0000000FU -#define USB3_SUPTPRT3_DW5_PSIV_POS 0U - -/* Bit fields of SUPTPRT3_DW6 register */ - -/* Bit fields of SUPTPRT3_DW7 register */ - -/* Bit fields of DCID register */ -#define USB3_DCID_DCERSTMAX_MASK 0x001F0000U -#define USB3_DCID_DCERSTMAX_POS 16U -#define USB3_DCID_NEXT_CAPABILITY_POINTER_MASK 0x0000FF00U -#define USB3_DCID_NEXT_CAPABILITY_POINTER_POS 8U -#define USB3_DCID_CAPABILITY_ID_MASK 0x000000FFU -#define USB3_DCID_CAPABILITY_ID_POS 0U - -/* Bit fields of DCDB register */ -#define USB3_DCDB_DBTARGET_MASK 0x0000FF00U -#define USB3_DCDB_DBTARGET_POS 8U - -/* Bit fields of DCERSTSZ register */ -#define USB3_DCERSTSZ_ERS_TABLE_SIZE_MASK 0x0000FFFFU -#define USB3_DCERSTSZ_ERS_TABLE_SIZE_POS 0U - -/* Bit fields of RSVD0 register */ - -/* Bit fields of DCERSTBA_LO register */ -#define USB3_DCERSTBA_LO_ERS_TABLE_BAR_MASK 0xFFFFFFF0U -#define USB3_DCERSTBA_LO_ERS_TABLE_BAR_POS 4U - -/* Bit fields of DCERSTBA_HI register */ -#define USB3_DCERSTBA_HI_ERS_TABLE_BAR_MASK 0xFFFFFFFFU -#define USB3_DCERSTBA_HI_ERS_TABLE_BAR_POS 0U - -/* Bit fields of DCERDP_LO register */ -#define USB3_DCERDP_LO_DEQUEUE_POINTER_MASK 0xFFFFFFF0U -#define USB3_DCERDP_LO_DEQUEUE_POINTER_POS 4U -#define USB3_DCERDP_LO_DESI_MASK 0x00000007U -#define USB3_DCERDP_LO_DESI_POS 0U - -/* Bit fields of DCERDP_HI register */ -#define USB3_DCERDP_HI_DEQUEUE_POINTER_MASK 0xFFFFFFFFU -#define USB3_DCERDP_HI_DEQUEUE_POINTER_POS 0U - -/* Bit fields of DCCTRL register */ -#define USB3_DCCTRL_DCE_MASK 0x80000000U -#define USB3_DCCTRL_DCE_POS 31U -#define USB3_DCCTRL_DEVICE_ADDRESS_MASK 0x7F000000U -#define USB3_DCCTRL_DEVICE_ADDRESS_POS 24U -#define USB3_DCCTRL_DEBUG_MAX_BURST_SIZE_MASK 0x00FF0000U -#define USB3_DCCTRL_DEBUG_MAX_BURST_SIZE_POS 16U -#define USB3_DCCTRL_DRC_MASK 0x00000010U -#define USB3_DCCTRL_DRC_POS 4U -#define USB3_DCCTRL_HIT_MASK 0x00000008U -#define USB3_DCCTRL_HIT_POS 3U -#define USB3_DCCTRL_HOT_MASK 0x00000004U -#define USB3_DCCTRL_HOT_POS 2U -#define USB3_DCCTRL_LSE_MASK 0x00000002U -#define USB3_DCCTRL_LSE_POS 1U -#define USB3_DCCTRL_DCR_MASK 0x00000001U -#define USB3_DCCTRL_DCR_POS 0U - -/* Bit fields of DCST register */ -#define USB3_DCST_DEBUG_PORT_NUMBER_MASK 0xFF000000U -#define USB3_DCST_DEBUG_PORT_NUMBER_POS 24U -#define USB3_DCST_SBR_MASK 0x00000002U -#define USB3_DCST_SBR_POS 1U -#define USB3_DCST_ER_MASK 0x00000001U -#define USB3_DCST_ER_POS 0U - -/* Bit fields of DCPORTSC register */ -#define USB3_DCPORTSC_CEC_MASK 0x00800000U -#define USB3_DCPORTSC_CEC_POS 23U -#define USB3_DCPORTSC_PLC_MASK 0x00400000U -#define USB3_DCPORTSC_PLC_POS 22U -#define USB3_DCPORTSC_PRC_MASK 0x00200000U -#define USB3_DCPORTSC_PRC_POS 21U -#define USB3_DCPORTSC_CSC_MASK 0x00020000U -#define USB3_DCPORTSC_CSC_POS 17U -#define USB3_DCPORTSC_PORTSPEED_MASK 0x00003C00U -#define USB3_DCPORTSC_PORTSPEED_POS 10U -#define USB3_DCPORTSC_PLS_MASK 0x000001E0U -#define USB3_DCPORTSC_PLS_POS 5U -#define USB3_DCPORTSC_PR_MASK 0x00000010U -#define USB3_DCPORTSC_PR_POS 4U -#define USB3_DCPORTSC_PED_MASK 0x00000002U -#define USB3_DCPORTSC_PED_POS 1U -#define USB3_DCPORTSC_CCS_MASK 0x00000001U -#define USB3_DCPORTSC_CCS_POS 0U - -/* Bit fields of RSVD1 register */ - -/* Bit fields of DCCP_LO register */ -#define USB3_DCCP_LO_DCCPR_MASK 0xFFFFFFF0U -#define USB3_DCCP_LO_DCCPR_POS 4U - -/* Bit fields of DCCP_HI register */ -#define USB3_DCCP_HI_DCCPR_MASK 0xFFFFFFFFU -#define USB3_DCCP_HI_DCCPR_POS 0U - -/* Bit fields of DCDDI1 register */ -#define USB3_DCDDI1_VENDORID_MASK 0xFFFF0000U -#define USB3_DCDDI1_VENDORID_POS 16U -#define USB3_DCDDI1_DBCPROTOCOL_MASK 0x000000FFU -#define USB3_DCDDI1_DBCPROTOCOL_POS 0U - -/* Bit fields of DCDDI2 register */ -#define USB3_DCDDI2_DEVICEREV_MASK 0xFFFF0000U -#define USB3_DCDDI2_DEVICEREV_POS 16U -#define USB3_DCDDI2_PRODUCTID_MASK 0x0000FFFFU -#define USB3_DCDDI2_PRODUCTID_POS 0U - -/* Bit fields of MFINDEX register */ -#define USB3_MFINDEX_MICROFRAME_INDEX_MASK 0x00003FFFU -#define USB3_MFINDEX_MICROFRAME_INDEX_POS 0U - -/* Bit fields of RsvdZ register */ - -/* Bit fields of IMAN register */ -#define USB3_IMAN_IE_MASK 0x00000002U -#define USB3_IMAN_IE_POS 1U -#define USB3_IMAN_IP_MASK 0x00000001U -#define USB3_IMAN_IP_POS 0U - -/* Bit fields of IMOD register */ -#define USB3_IMOD_IMODC_MASK 0xFFFF0000U -#define USB3_IMOD_IMODC_POS 16U -#define USB3_IMOD_IMODI_MASK 0x0000FFFFU -#define USB3_IMOD_IMODI_POS 0U - -/* Bit fields of ERSTSZ register */ -#define USB3_ERSTSZ_ERS_TABLE_SIZE_MASK 0x0000FFFFU -#define USB3_ERSTSZ_ERS_TABLE_SIZE_POS 0U - -/* Bit fields of RsvdP register */ - -/* Bit fields of ERSTBA_LO register */ -#define USB3_ERSTBA_LO_ERS_TABLE_BAR_MASK 0xFFFFFFC0U -#define USB3_ERSTBA_LO_ERS_TABLE_BAR_POS 6U - -/* Bit fields of ERSTBA_HI register */ -#define USB3_ERSTBA_HI_ERS_TABLE_BAR_MASK 0xFFFFFFFFU -#define USB3_ERSTBA_HI_ERS_TABLE_BAR_POS 0U - -/* Bit fields of ERDP_LO register */ -#define USB3_ERDP_LO_ERD_PNTR_MASK 0xFFFFFFF0U -#define USB3_ERDP_LO_ERD_PNTR_POS 4U -#define USB3_ERDP_LO_EHB_MASK 0x00000008U -#define USB3_ERDP_LO_EHB_POS 3U -#define USB3_ERDP_LO_DESI_MASK 0x00000007U -#define USB3_ERDP_LO_DESI_POS 0U - -/* Bit fields of ERDP_HI register */ -#define USB3_ERDP_HI_ERD_PNTR_MASK 0xFFFFFFFFU -#define USB3_ERDP_HI_ERD_PNTR_POS 0U - -/* Bit fields of DB register */ -#define USB3_DB_DB_STREAM_ID_MASK 0xFFFF0000U -#define USB3_DB_DB_STREAM_ID_POS 16U -#define USB3_DB_DB_TARGET_MASK 0x000000FFU -#define USB3_DB_DB_TARGET_POS 0U - -/* Bit fields of GSBUSCFG0 register */ -#define USB3_GSBUSCFG0_DATRDREQINFO_MASK 0xF0000000U -#define USB3_GSBUSCFG0_DATRDREQINFO_POS 28U -#define USB3_GSBUSCFG0_DESRDREQINFO_MASK 0x0F000000U -#define USB3_GSBUSCFG0_DESRDREQINFO_POS 24U -#define USB3_GSBUSCFG0_DATWRREQINFO_MASK 0x00F00000U -#define USB3_GSBUSCFG0_DATWRREQINFO_POS 20U -#define USB3_GSBUSCFG0_DESWRREQINFO_MASK 0x000F0000U -#define USB3_GSBUSCFG0_DESWRREQINFO_POS 16U -#define USB3_GSBUSCFG0_DATBIGEND_MASK 0x00000800U -#define USB3_GSBUSCFG0_DATBIGEND_POS 11U -#define USB3_GSBUSCFG0_DESBIGEND_MASK 0x00000400U -#define USB3_GSBUSCFG0_DESBIGEND_POS 10U -#define USB3_GSBUSCFG0_INCR256BRSTENA_MASK 0x00000080U -#define USB3_GSBUSCFG0_INCR256BRSTENA_POS 7U -#define USB3_GSBUSCFG0_INCR128BRSTENA_MASK 0x00000040U -#define USB3_GSBUSCFG0_INCR128BRSTENA_POS 6U -#define USB3_GSBUSCFG0_INCR64BRSTENA_MASK 0x00000020U -#define USB3_GSBUSCFG0_INCR64BRSTENA_POS 5U -#define USB3_GSBUSCFG0_INCR32BRSTENA_MASK 0x00000010U -#define USB3_GSBUSCFG0_INCR32BRSTENA_POS 4U -#define USB3_GSBUSCFG0_INCR16BRSTENA_MASK 0x00000008U -#define USB3_GSBUSCFG0_INCR16BRSTENA_POS 3U -#define USB3_GSBUSCFG0_INCR8BRSTENA_MASK 0x00000004U -#define USB3_GSBUSCFG0_INCR8BRSTENA_POS 2U -#define USB3_GSBUSCFG0_INCR4BRSTENA_MASK 0x00000002U -#define USB3_GSBUSCFG0_INCR4BRSTENA_POS 1U -#define USB3_GSBUSCFG0_INCRBRSTENA_MASK 0x00000001U -#define USB3_GSBUSCFG0_INCRBRSTENA_POS 0U - -/* Bit fields of GSBUSCFG1 register */ -#define USB3_GSBUSCFG1_EXTDPIPETRANSLIMIT_MASK 0x0001E000U -#define USB3_GSBUSCFG1_EXTDPIPETRANSLIMIT_POS 13U -#define USB3_GSBUSCFG1_EN1KPAGE_MASK 0x00001000U -#define USB3_GSBUSCFG1_EN1KPAGE_POS 12U -#define USB3_GSBUSCFG1_PIPETRANSLIMIT_MASK 0x00000F00U -#define USB3_GSBUSCFG1_PIPETRANSLIMIT_POS 8U - -/* Bit fields of GTXTHRCFG register */ -#define USB3_GTXTHRCFG_USBTXPKTCNTSEL_MASK 0x04000000U -#define USB3_GTXTHRCFG_USBTXPKTCNTSEL_POS 26U -#define USB3_GTXTHRCFG_USBTXPKTCNT_MASK 0x03E00000U -#define USB3_GTXTHRCFG_USBTXPKTCNT_POS 21U -#define USB3_GTXTHRCFG_USBMAXTXBURSTSIZE_MASK 0x001F0000U -#define USB3_GTXTHRCFG_USBMAXTXBURSTSIZE_POS 16U -#define USB3_GTXTHRCFG_USBTXTHRNUMPKTSEL_HS_PRD_MASK 0x00008000U -#define USB3_GTXTHRCFG_USBTXTHRNUMPKTSEL_HS_PRD_POS 15U -#define USB3_GTXTHRCFG_USBTXTHRNUMPKT_HS_PRD_MASK 0x00006000U -#define USB3_GTXTHRCFG_USBTXTHRNUMPKT_HS_PRD_POS 13U -#define USB3_GTXTHRCFG_USBTXTHRNUMPKTSEL_PRD_MASK 0x00000400U -#define USB3_GTXTHRCFG_USBTXTHRNUMPKTSEL_PRD_POS 10U -#define USB3_GTXTHRCFG_USBTXTHRNUMPKT_PRD_MASK 0x000003E0U -#define USB3_GTXTHRCFG_USBTXTHRNUMPKT_PRD_POS 5U -#define USB3_GTXTHRCFG_USBMAXTXBURSTSIZE_PRD_MASK 0x0000001FU -#define USB3_GTXTHRCFG_USBMAXTXBURSTSIZE_PRD_POS 0U - -/* Bit fields of GRXTHRCFG register */ -#define USB3_GRXTHRCFG_USBRXPKTCNTSEL_MASK 0x04000000U -#define USB3_GRXTHRCFG_USBRXPKTCNTSEL_POS 26U -#define USB3_GRXTHRCFG_USBRXPKTCNT_MASK 0x03E00000U -#define USB3_GRXTHRCFG_USBRXPKTCNT_POS 21U -#define USB3_GRXTHRCFG_USBMAXRXBURSTSIZE_MASK 0x001F0000U -#define USB3_GRXTHRCFG_USBMAXRXBURSTSIZE_POS 16U -#define USB3_GRXTHRCFG_USBRXTHRNUMPKTSEL_HS_PRD_MASK 0x00008000U -#define USB3_GRXTHRCFG_USBRXTHRNUMPKTSEL_HS_PRD_POS 15U -#define USB3_GRXTHRCFG_USBRXTHRNUMPKT_HS_PRD_MASK 0x00006000U -#define USB3_GRXTHRCFG_USBRXTHRNUMPKT_HS_PRD_POS 13U -#define USB3_GRXTHRCFG_USBRXTHRNUMPKTSEL_PRD_MASK 0x00000400U -#define USB3_GRXTHRCFG_USBRXTHRNUMPKTSEL_PRD_POS 10U -#define USB3_GRXTHRCFG_USBRXTHRNUMPKT_PRD_MASK 0x000003E0U -#define USB3_GRXTHRCFG_USBRXTHRNUMPKT_PRD_POS 5U -#define USB3_GRXTHRCFG_USBMAXRXBURSTSIZE_PRD_MASK 0x0000001FU -#define USB3_GRXTHRCFG_USBMAXRXBURSTSIZE_PRD_POS 0U - -/* Bit fields of GCTL register */ -#define USB3_GCTL_PWRDNSCALE_MASK 0xFFF80000U -#define USB3_GCTL_PWRDNSCALE_POS 19U -#define USB3_GCTL_MASTERFILTBYPASS_MASK 0x00040000U -#define USB3_GCTL_MASTERFILTBYPASS_POS 18U -#define USB3_GCTL_BYPSSETADDR_MASK 0x00020000U -#define USB3_GCTL_BYPSSETADDR_POS 17U -#define USB3_GCTL_U2RSTECN_MASK 0x00010000U -#define USB3_GCTL_U2RSTECN_POS 16U -#define USB3_GCTL_FRMSCLDWN_MASK 0x0000C000U -#define USB3_GCTL_FRMSCLDWN_POS 14U -#define USB3_GCTL_PRTCAPDIR_MASK 0x00003000U -#define USB3_GCTL_PRTCAPDIR_POS 12U -#define USB3_GCTL_CORESOFTRESET_MASK 0x00000800U -#define USB3_GCTL_CORESOFTRESET_POS 11U -#define USB3_GCTL_U1U2TIMERSCALE_MASK 0x00000200U -#define USB3_GCTL_U1U2TIMERSCALE_POS 9U -#define USB3_GCTL_DEBUGATTACH_MASK 0x00000100U -#define USB3_GCTL_DEBUGATTACH_POS 8U -#define USB3_GCTL_RAMCLKSEL_MASK 0x000000C0U -#define USB3_GCTL_RAMCLKSEL_POS 6U -#define USB3_GCTL_SCALEDOWN_MASK 0x00000030U -#define USB3_GCTL_SCALEDOWN_POS 4U -#define USB3_GCTL_DISSCRAMBLE_MASK 0x00000008U -#define USB3_GCTL_DISSCRAMBLE_POS 3U -#define USB3_GCTL_U2EXIT_LFPS_MASK 0x00000004U -#define USB3_GCTL_U2EXIT_LFPS_POS 2U -#define USB3_GCTL_GBLHIBERNATIONEN_MASK 0x00000002U -#define USB3_GCTL_GBLHIBERNATIONEN_POS 1U -#define USB3_GCTL_DSBLCLKGTNG_MASK 0x00000001U -#define USB3_GCTL_DSBLCLKGTNG_POS 0U - -/* Bit fields of GPMSTS register */ -#define USB3_GPMSTS_PORTSEL_MASK 0xF0000000U -#define USB3_GPMSTS_PORTSEL_POS 28U -#define USB3_GPMSTS_U3WAKEUP_MASK 0x0001F000U -#define USB3_GPMSTS_U3WAKEUP_POS 12U -#define USB3_GPMSTS_U2WAKEUP_MASK 0x000003FFU -#define USB3_GPMSTS_U2WAKEUP_POS 0U - -/* Bit fields of GSTS register */ -#define USB3_GSTS_CBELT_MASK 0xFFF00000U -#define USB3_GSTS_CBELT_POS 20U -#define USB3_GSTS_HOST_IP_MASK 0x00000080U -#define USB3_GSTS_HOST_IP_POS 7U -#define USB3_GSTS_DEVICE_IP_MASK 0x00000040U -#define USB3_GSTS_DEVICE_IP_POS 6U -#define USB3_GSTS_CSRTIMEOUT_MASK 0x00000020U -#define USB3_GSTS_CSRTIMEOUT_POS 5U -#define USB3_GSTS_BUSERRADDRVLD_MASK 0x00000010U -#define USB3_GSTS_BUSERRADDRVLD_POS 4U -#define USB3_GSTS_CURMOD_MASK 0x00000003U -#define USB3_GSTS_CURMOD_POS 0U - -/* Bit fields of GUCTL1 register */ -#define USB3_GUCTL1_DEV_DECOUPLE_L1L2_EVT_MASK 0x80000000U -#define USB3_GUCTL1_DEV_DECOUPLE_L1L2_EVT_POS 31U -#define USB3_GUCTL1_DS_RXDET_MAX_TOUT_CTRL_MASK 0x40000000U -#define USB3_GUCTL1_DS_RXDET_MAX_TOUT_CTRL_POS 30U -#define USB3_GUCTL1_FILTER_SE0_FSLS_EOP_MASK 0x20000000U -#define USB3_GUCTL1_FILTER_SE0_FSLS_EOP_POS 29U -#define USB3_GUCTL1_TX_IPGAP_LINECHECK_DIS_MASK 0x10000000U -#define USB3_GUCTL1_TX_IPGAP_LINECHECK_DIS_POS 28U -#define USB3_GUCTL1_DEV_TRB_OUT_SPR_IND_MASK 0x08000000U -#define USB3_GUCTL1_DEV_TRB_OUT_SPR_IND_POS 27U -#define USB3_GUCTL1_DEV_L1_EXIT_BY_HW_MASK 0x01000000U -#define USB3_GUCTL1_DEV_L1_EXIT_BY_HW_POS 24U -#define USB3_GUCTL1_IP_GAP_ADD_ON_MASK 0x00E00000U -#define USB3_GUCTL1_IP_GAP_ADD_ON_POS 21U -#define USB3_GUCTL1_HW_LPM_CAP_DISABLE_MASK 0x00004000U -#define USB3_GUCTL1_HW_LPM_CAP_DISABLE_POS 14U -#define USB3_GUCTL1_HW_LPM_HLE_DISABLE_MASK 0x00002000U -#define USB3_GUCTL1_HW_LPM_HLE_DISABLE_POS 13U -#define USB3_GUCTL1_DISUSB2REFCLKGTNG_MASK 0x00001000U -#define USB3_GUCTL1_DISUSB2REFCLKGTNG_POS 12U -#define USB3_GUCTL1_DISREFCLKGTNG_MASK 0x00000800U -#define USB3_GUCTL1_DISREFCLKGTNG_POS 11U -#define USB3_GUCTL1_RESUME_OPMODE_HS_HOST_MASK 0x00000400U -#define USB3_GUCTL1_RESUME_OPMODE_HS_HOST_POS 10U -#define USB3_GUCTL1_L1_SUSP_THRLD_EN_FOR_HOST_MASK 0x00000100U -#define USB3_GUCTL1_L1_SUSP_THRLD_EN_FOR_HOST_POS 8U -#define USB3_GUCTL1_L1_SUSP_THRLD_FOR_HOST_MASK 0x000000F0U -#define USB3_GUCTL1_L1_SUSP_THRLD_FOR_HOST_POS 4U -#define USB3_GUCTL1_HC_ERRATA_ENABLE_MASK 0x00000008U -#define USB3_GUCTL1_HC_ERRATA_ENABLE_POS 3U -#define USB3_GUCTL1_HC_PARCHK_DISABLE_MASK 0x00000004U -#define USB3_GUCTL1_HC_PARCHK_DISABLE_POS 2U -#define USB3_GUCTL1_LOA_FILTER_EN_MASK 0x00000001U -#define USB3_GUCTL1_LOA_FILTER_EN_POS 0U - -/* Bit fields of USB31_IP_NAME register */ -#define USB3_USB31_IP_NAME_SYNOPSYSIP_MASK 0xFFFFFFFFU -#define USB3_USB31_IP_NAME_SYNOPSYSIP_POS 0U - -/* Bit fields of GGPIO register */ -#define USB3_GGPIO_GPO_MASK 0xFFFF0000U -#define USB3_GGPIO_GPO_POS 16U -#define USB3_GGPIO_GPI_MASK 0x0000FFFFU -#define USB3_GGPIO_GPI_POS 0U - -/* Bit fields of GUID register */ -#define USB3_GUID_USERID_MASK 0xFFFFFFFFU -#define USB3_GUID_USERID_POS 0U - -/* Bit fields of GUCTL register */ -#define USB3_GUCTL_REFCLKPER_MASK 0xFFC00000U -#define USB3_GUCTL_REFCLKPER_POS 22U -#define USB3_GUCTL_NOEXTRDL_MASK 0x00200000U -#define USB3_GUCTL_NOEXTRDL_POS 21U -#define USB3_GUCTL_DMAIGNOREHCE_MASK 0x00100000U -#define USB3_GUCTL_DMAIGNOREHCE_POS 20U -#define USB3_GUCTL_IGNOREHCETIMEOUT_MASK 0x00080000U -#define USB3_GUCTL_IGNOREHCETIMEOUT_POS 19U -#define USB3_GUCTL_EN_EXTD_TBC_CAP_MASK 0x00040000U -#define USB3_GUCTL_EN_EXTD_TBC_CAP_POS 18U -#define USB3_GUCTL_SPRSCTRLTRANSEN_MASK 0x00020000U -#define USB3_GUCTL_SPRSCTRLTRANSEN_POS 17U -#define USB3_GUCTL_RESBWHSEPS_MASK 0x00010000U -#define USB3_GUCTL_RESBWHSEPS_POS 16U -#define USB3_GUCTL_USBHSTINIMMRETRYEN_MASK 0x00004000U -#define USB3_GUCTL_USBHSTINIMMRETRYEN_POS 14U -#define USB3_GUCTL_EXTCAPSUPPTEN_MASK 0x00001000U -#define USB3_GUCTL_EXTCAPSUPPTEN_POS 12U -#define USB3_GUCTL_INSRTEXTRFSBODI_MASK 0x00000800U -#define USB3_GUCTL_INSRTEXTRFSBODI_POS 11U -#define USB3_GUCTL_DTOUT_MASK 0x000007FFU -#define USB3_GUCTL_DTOUT_POS 0U - -/* Bit fields of GBUSERRADDRLO register */ -#define USB3_GBUSERRADDRLO_BUSERRADDR_MASK 0xFFFFFFFFU -#define USB3_GBUSERRADDRLO_BUSERRADDR_POS 0U - -/* Bit fields of GBUSERRADDRHI register */ -#define USB3_GBUSERRADDRHI_BUSERRADDR_MASK 0xFFFFFFFFU -#define USB3_GBUSERRADDRHI_BUSERRADDR_POS 0U - -/* Bit fields of GPRTBIMAPLO register */ -#define USB3_GPRTBIMAPLO_BINUM8_MASK 0xF0000000U -#define USB3_GPRTBIMAPLO_BINUM8_POS 28U -#define USB3_GPRTBIMAPLO_BINUM7_MASK 0x0F000000U -#define USB3_GPRTBIMAPLO_BINUM7_POS 24U -#define USB3_GPRTBIMAPLO_BINUM6_MASK 0x00F00000U -#define USB3_GPRTBIMAPLO_BINUM6_POS 20U -#define USB3_GPRTBIMAPLO_BINUM5_MASK 0x000F0000U -#define USB3_GPRTBIMAPLO_BINUM5_POS 16U -#define USB3_GPRTBIMAPLO_BINUM4_MASK 0x0000F000U -#define USB3_GPRTBIMAPLO_BINUM4_POS 12U -#define USB3_GPRTBIMAPLO_BINUM3_MASK 0x00000F00U -#define USB3_GPRTBIMAPLO_BINUM3_POS 8U -#define USB3_GPRTBIMAPLO_BINUM2_MASK 0x000000F0U -#define USB3_GPRTBIMAPLO_BINUM2_POS 4U -#define USB3_GPRTBIMAPLO_BINUM1_MASK 0x0000000FU -#define USB3_GPRTBIMAPLO_BINUM1_POS 0U - -/* Bit fields of GPRTBIMAPHI register */ -#define USB3_GPRTBIMAPHI_BINUM15_MASK 0x0F000000U -#define USB3_GPRTBIMAPHI_BINUM15_POS 24U -#define USB3_GPRTBIMAPHI_BINUM14_MASK 0x00F00000U -#define USB3_GPRTBIMAPHI_BINUM14_POS 20U -#define USB3_GPRTBIMAPHI_BINUM13_MASK 0x000F0000U -#define USB3_GPRTBIMAPHI_BINUM13_POS 16U -#define USB3_GPRTBIMAPHI_BINUM12_MASK 0x0000F000U -#define USB3_GPRTBIMAPHI_BINUM12_POS 12U -#define USB3_GPRTBIMAPHI_BINUM11_MASK 0x00000F00U -#define USB3_GPRTBIMAPHI_BINUM11_POS 8U -#define USB3_GPRTBIMAPHI_BINUM10_MASK 0x000000F0U -#define USB3_GPRTBIMAPHI_BINUM10_POS 4U -#define USB3_GPRTBIMAPHI_BINUM9_MASK 0x0000000FU -#define USB3_GPRTBIMAPHI_BINUM9_POS 0U - -/* Bit fields of GHWPARAMS0 register */ -#define USB3_GHWPARAMS0_GHWPARAMS0_31_24_MASK 0xFF000000U -#define USB3_GHWPARAMS0_GHWPARAMS0_31_24_POS 24U -#define USB3_GHWPARAMS0_GHWPARAMS0_23_16_MASK 0x00FF0000U -#define USB3_GHWPARAMS0_GHWPARAMS0_23_16_POS 16U -#define USB3_GHWPARAMS0_GHWPARAMS0_15_8_MASK 0x0000FF00U -#define USB3_GHWPARAMS0_GHWPARAMS0_15_8_POS 8U -#define USB3_GHWPARAMS0_GHWPARAMS0_7_6_MASK 0x000000C0U -#define USB3_GHWPARAMS0_GHWPARAMS0_7_6_POS 6U -#define USB3_GHWPARAMS0_GHWPARAMS0_5_3_MASK 0x00000038U -#define USB3_GHWPARAMS0_GHWPARAMS0_5_3_POS 3U -#define USB3_GHWPARAMS0_GHWPARAMS0_2_0_MASK 0x00000007U -#define USB3_GHWPARAMS0_GHWPARAMS0_2_0_POS 0U - -/* Bit fields of GHWPARAMS1 register */ -#define USB3_GHWPARAMS1_GHWPARAMS1_31_MASK 0x80000000U -#define USB3_GHWPARAMS1_GHWPARAMS1_31_POS 31U -#define USB3_GHWPARAMS1_GHWPARAMS1_30_MASK 0x40000000U -#define USB3_GHWPARAMS1_GHWPARAMS1_30_POS 30U -#define USB3_GHWPARAMS1_GHWPARAMS1_29_MASK 0x20000000U -#define USB3_GHWPARAMS1_GHWPARAMS1_29_POS 29U -#define USB3_GHWPARAMS1_GHWPARAMS1_28_MASK 0x10000000U -#define USB3_GHWPARAMS1_GHWPARAMS1_28_POS 28U -#define USB3_GHWPARAMS1_GHWPARAMS1_27_MASK 0x08000000U -#define USB3_GHWPARAMS1_GHWPARAMS1_27_POS 27U -#define USB3_GHWPARAMS1_GHWPARAMS1_26_MASK 0x04000000U -#define USB3_GHWPARAMS1_GHWPARAMS1_26_POS 26U -#define USB3_GHWPARAMS1_GHWPARAMS1_25_24_MASK 0x03000000U -#define USB3_GHWPARAMS1_GHWPARAMS1_25_24_POS 24U -#define USB3_GHWPARAMS1_GHWPARAMS1_23_MASK 0x00800000U -#define USB3_GHWPARAMS1_GHWPARAMS1_23_POS 23U -#define USB3_GHWPARAMS1_GHWPARAMS1_22_17_MASK 0x007E0000U -#define USB3_GHWPARAMS1_GHWPARAMS1_22_17_POS 17U -#define USB3_GHWPARAMS1_GHWPARAMS1_16_14_MASK 0x0001C000U -#define USB3_GHWPARAMS1_GHWPARAMS1_16_14_POS 14U -#define USB3_GHWPARAMS1_GHWPARAMS1_13_11_MASK 0x00003800U -#define USB3_GHWPARAMS1_GHWPARAMS1_13_11_POS 11U -#define USB3_GHWPARAMS1_GHWPARAMS1_10_8_MASK 0x00000700U -#define USB3_GHWPARAMS1_GHWPARAMS1_10_8_POS 8U -#define USB3_GHWPARAMS1_GHWPARAMS1_7_4_MASK 0x000000F0U -#define USB3_GHWPARAMS1_GHWPARAMS1_7_4_POS 4U -#define USB3_GHWPARAMS1_GHWPARAMS1_3_0_MASK 0x0000000FU -#define USB3_GHWPARAMS1_GHWPARAMS1_3_0_POS 0U - -/* Bit fields of GHWPARAMS2 register */ -#define USB3_GHWPARAMS2_GHWPARAMS2_31_0_MASK 0xFFFFFFFFU -#define USB3_GHWPARAMS2_GHWPARAMS2_31_0_POS 0U - -/* Bit fields of GHWPARAMS3 register */ -#define USB3_GHWPARAMS3_GHWPARAMS3_31_MASK 0x80000000U -#define USB3_GHWPARAMS3_GHWPARAMS3_31_POS 31U -#define USB3_GHWPARAMS3_GHWPARAMS3_30_23_MASK 0x7F800000U -#define USB3_GHWPARAMS3_GHWPARAMS3_30_23_POS 23U -#define USB3_GHWPARAMS3_GHWPARAMS3_22_18_MASK 0x007C0000U -#define USB3_GHWPARAMS3_GHWPARAMS3_22_18_POS 18U -#define USB3_GHWPARAMS3_GHWPARAMS3_17_12_MASK 0x0003F000U -#define USB3_GHWPARAMS3_GHWPARAMS3_17_12_POS 12U -#define USB3_GHWPARAMS3_GHWPARAMS3_11_MASK 0x00000800U -#define USB3_GHWPARAMS3_GHWPARAMS3_11_POS 11U -#define USB3_GHWPARAMS3_GHWPARAMS3_10_MASK 0x00000400U -#define USB3_GHWPARAMS3_GHWPARAMS3_10_POS 10U -#define USB3_GHWPARAMS3_GHWPARAMS3_9_8_MASK 0x00000300U -#define USB3_GHWPARAMS3_GHWPARAMS3_9_8_POS 8U -#define USB3_GHWPARAMS3_GHWPARAMS3_7_6_MASK 0x000000C0U -#define USB3_GHWPARAMS3_GHWPARAMS3_7_6_POS 6U -#define USB3_GHWPARAMS3_GHWPARAMS3_5_4_MASK 0x00000030U -#define USB3_GHWPARAMS3_GHWPARAMS3_5_4_POS 4U -#define USB3_GHWPARAMS3_GHWPARAMS3_3_2_MASK 0x0000000CU -#define USB3_GHWPARAMS3_GHWPARAMS3_3_2_POS 2U -#define USB3_GHWPARAMS3_GHWPARAMS3_1_0_MASK 0x00000003U -#define USB3_GHWPARAMS3_GHWPARAMS3_1_0_POS 0U - -/* Bit fields of GHWPARAMS4 register */ -#define USB3_GHWPARAMS4_GHWPARAMS4_31_28_MASK 0xF0000000U -#define USB3_GHWPARAMS4_GHWPARAMS4_31_28_POS 28U -#define USB3_GHWPARAMS4_GHWPARAMS4_27_23_MASK 0x0F800000U -#define USB3_GHWPARAMS4_GHWPARAMS4_27_23_POS 23U -#define USB3_GHWPARAMS4_GHWPARAMS4_22_MASK 0x00400000U -#define USB3_GHWPARAMS4_GHWPARAMS4_22_POS 22U -#define USB3_GHWPARAMS4_GHWPARAMS4_21_MASK 0x00200000U -#define USB3_GHWPARAMS4_GHWPARAMS4_21_POS 21U -#define USB3_GHWPARAMS4_GHWPARAMS4_20_17_MASK 0x001E0000U -#define USB3_GHWPARAMS4_GHWPARAMS4_20_17_POS 17U -#define USB3_GHWPARAMS4_GHWPARAMS4_16_13_MASK 0x0001E000U -#define USB3_GHWPARAMS4_GHWPARAMS4_16_13_POS 13U -#define USB3_GHWPARAMS4_GHWPARAMS4_12_6_MASK 0x00001FC0U -#define USB3_GHWPARAMS4_GHWPARAMS4_12_6_POS 6U -#define USB3_GHWPARAMS4_GHWPARAMS4_5_0_MASK 0x0000003FU -#define USB3_GHWPARAMS4_GHWPARAMS4_5_0_POS 0U - -/* Bit fields of GHWPARAMS5 register */ -#define USB3_GHWPARAMS5_GHWPARAMS5_31_29_MASK 0xE0000000U -#define USB3_GHWPARAMS5_GHWPARAMS5_31_29_POS 29U -#define USB3_GHWPARAMS5_GHWPARAMS5_28_23_MASK 0x1F800000U -#define USB3_GHWPARAMS5_GHWPARAMS5_28_23_POS 23U -#define USB3_GHWPARAMS5_GHWPARAMS5_22_17_MASK 0x007E0000U -#define USB3_GHWPARAMS5_GHWPARAMS5_22_17_POS 17U -#define USB3_GHWPARAMS5_GHWPARAMS5_16_11_MASK 0x0001F800U -#define USB3_GHWPARAMS5_GHWPARAMS5_16_11_POS 11U -#define USB3_GHWPARAMS5_GHWPARAMS5_10_5_MASK 0x000007E0U -#define USB3_GHWPARAMS5_GHWPARAMS5_10_5_POS 5U -#define USB3_GHWPARAMS5_GHWPARAMS5_4_0_MASK 0x0000001FU -#define USB3_GHWPARAMS5_GHWPARAMS5_4_0_POS 0U - -/* Bit fields of GHWPARAMS6 register */ -#define USB3_GHWPARAMS6_GHWPARAMS6_31_16_MASK 0xFFFF0000U -#define USB3_GHWPARAMS6_GHWPARAMS6_31_16_POS 16U -#define USB3_GHWPARAMS6_BUSFLTRSSUPPORT_MASK 0x00008000U -#define USB3_GHWPARAMS6_BUSFLTRSSUPPORT_POS 15U -#define USB3_GHWPARAMS6_GHWPARAMS6_14_10_MASK 0x00007C00U -#define USB3_GHWPARAMS6_GHWPARAMS6_14_10_POS 10U -#define USB3_GHWPARAMS6_GHWPARAMS6_9_8_MASK 0x00000300U -#define USB3_GHWPARAMS6_GHWPARAMS6_9_8_POS 8U -#define USB3_GHWPARAMS6_GHWPARAMS6_7_MASK 0x00000080U -#define USB3_GHWPARAMS6_GHWPARAMS6_7_POS 7U -#define USB3_GHWPARAMS6_GHWPARAMS6_6_MASK 0x00000040U -#define USB3_GHWPARAMS6_GHWPARAMS6_6_POS 6U -#define USB3_GHWPARAMS6_GHWPARAMS6_5_0_MASK 0x0000003FU -#define USB3_GHWPARAMS6_GHWPARAMS6_5_0_POS 0U - -/* Bit fields of GHWPARAMS7 register */ -#define USB3_GHWPARAMS7_GHWPARAMS7_31_16_MASK 0xFFFF0000U -#define USB3_GHWPARAMS7_GHWPARAMS7_31_16_POS 16U -#define USB3_GHWPARAMS7_GHWPARAMS7_15_0_MASK 0x0000FFFFU -#define USB3_GHWPARAMS7_GHWPARAMS7_15_0_POS 0U - -/* Bit fields of GDBGFIFOSPACE register */ -#define USB3_GDBGFIFOSPACE_SPACE_AVAILABLE_MASK 0xFFFF0000U -#define USB3_GDBGFIFOSPACE_SPACE_AVAILABLE_POS 16U -#define USB3_GDBGFIFOSPACE_FIFO_QUEUE_SELECT_MASK 0x000001FFU -#define USB3_GDBGFIFOSPACE_FIFO_QUEUE_SELECT_POS 0U - -/* Bit fields of GBMUCTL register */ -#define USB3_GBMUCTL_SEPARATE_PSQ_EN_MASK 0x00000020U -#define USB3_GBMUCTL_SEPARATE_PSQ_EN_POS 5U -#define USB3_GBMUCTL_AXI_STORDER_EN_MASK 0x00000004U -#define USB3_GBMUCTL_AXI_STORDER_EN_POS 2U -#define USB3_GBMUCTL_ACTIVE_ID_EN_MASK 0x00000002U -#define USB3_GBMUCTL_ACTIVE_ID_EN_POS 1U - -/* Bit fields of GDBGBMU register */ -#define USB3_GDBGBMU_BMU_BCU_MASK 0xFFFFFF00U -#define USB3_GDBGBMU_BMU_BCU_POS 8U -#define USB3_GDBGBMU_BMU_DCU_MASK 0x000000F0U -#define USB3_GDBGBMU_BMU_DCU_POS 4U -#define USB3_GDBGBMU_BMU_CCU_MASK 0x0000000FU -#define USB3_GDBGBMU_BMU_CCU_POS 0U - -/* Bit fields of GDBGLSPMUX register */ -#define USB3_GDBGLSPMUX_LOGIC_ANALYZER_TRACE_MASK 0x00FF0000U -#define USB3_GDBGLSPMUX_LOGIC_ANALYZER_TRACE_POS 16U -#define USB3_GDBGLSPMUX_LSPSELECT_MASK 0x00007FFFU -#define USB3_GDBGLSPMUX_LSPSELECT_POS 0U - -/* Bit fields of GDBGLSP register */ -#define USB3_GDBGLSP_LSPDEBUG_MASK 0xFFFFFFFFU -#define USB3_GDBGLSP_LSPDEBUG_POS 0U - -/* Bit fields of GDBGEPINFO0 register */ -#define USB3_GDBGEPINFO0_EPDEBUG_MASK 0xFFFFFFFFU -#define USB3_GDBGEPINFO0_EPDEBUG_POS 0U - -/* Bit fields of GDBGEPINFO1 register */ -#define USB3_GDBGEPINFO1_EPDEBUG_MASK 0xFFFFFFFFU -#define USB3_GDBGEPINFO1_EPDEBUG_POS 0U - -/* Bit fields of GPRTBIMAP_HSLO register */ -#define USB3_GPRTBIMAP_HSLO_BINUM8_MASK 0xF0000000U -#define USB3_GPRTBIMAP_HSLO_BINUM8_POS 28U -#define USB3_GPRTBIMAP_HSLO_BINUM7_MASK 0x0F000000U -#define USB3_GPRTBIMAP_HSLO_BINUM7_POS 24U -#define USB3_GPRTBIMAP_HSLO_BINUM6_MASK 0x00F00000U -#define USB3_GPRTBIMAP_HSLO_BINUM6_POS 20U -#define USB3_GPRTBIMAP_HSLO_BINUM5_MASK 0x000F0000U -#define USB3_GPRTBIMAP_HSLO_BINUM5_POS 16U -#define USB3_GPRTBIMAP_HSLO_BINUM4_MASK 0x0000F000U -#define USB3_GPRTBIMAP_HSLO_BINUM4_POS 12U -#define USB3_GPRTBIMAP_HSLO_BINUM3_MASK 0x00000F00U -#define USB3_GPRTBIMAP_HSLO_BINUM3_POS 8U -#define USB3_GPRTBIMAP_HSLO_BINUM2_MASK 0x000000F0U -#define USB3_GPRTBIMAP_HSLO_BINUM2_POS 4U -#define USB3_GPRTBIMAP_HSLO_BINUM1_MASK 0x0000000FU -#define USB3_GPRTBIMAP_HSLO_BINUM1_POS 0U - -/* Bit fields of GPRTBIMAP_HSHI register */ -#define USB3_GPRTBIMAP_HSHI_BINUM15_MASK 0x0F000000U -#define USB3_GPRTBIMAP_HSHI_BINUM15_POS 24U -#define USB3_GPRTBIMAP_HSHI_BINUM14_MASK 0x00F00000U -#define USB3_GPRTBIMAP_HSHI_BINUM14_POS 20U -#define USB3_GPRTBIMAP_HSHI_BINUM13_MASK 0x000F0000U -#define USB3_GPRTBIMAP_HSHI_BINUM13_POS 16U -#define USB3_GPRTBIMAP_HSHI_BINUM12_MASK 0x0000F000U -#define USB3_GPRTBIMAP_HSHI_BINUM12_POS 12U -#define USB3_GPRTBIMAP_HSHI_BINUM11_MASK 0x00000F00U -#define USB3_GPRTBIMAP_HSHI_BINUM11_POS 8U -#define USB3_GPRTBIMAP_HSHI_BINUM10_MASK 0x000000F0U -#define USB3_GPRTBIMAP_HSHI_BINUM10_POS 4U -#define USB3_GPRTBIMAP_HSHI_BINUM9_MASK 0x0000000FU -#define USB3_GPRTBIMAP_HSHI_BINUM9_POS 0U - -/* Bit fields of GPRTBIMAP_FSLO register */ -#define USB3_GPRTBIMAP_FSLO_BINUM8_MASK 0xF0000000U -#define USB3_GPRTBIMAP_FSLO_BINUM8_POS 28U -#define USB3_GPRTBIMAP_FSLO_BINUM7_MASK 0x0F000000U -#define USB3_GPRTBIMAP_FSLO_BINUM7_POS 24U -#define USB3_GPRTBIMAP_FSLO_BINUM6_MASK 0x00F00000U -#define USB3_GPRTBIMAP_FSLO_BINUM6_POS 20U -#define USB3_GPRTBIMAP_FSLO_BINUM5_MASK 0x000F0000U -#define USB3_GPRTBIMAP_FSLO_BINUM5_POS 16U -#define USB3_GPRTBIMAP_FSLO_BINUM4_MASK 0x0000F000U -#define USB3_GPRTBIMAP_FSLO_BINUM4_POS 12U -#define USB3_GPRTBIMAP_FSLO_BINUM3_MASK 0x00000F00U -#define USB3_GPRTBIMAP_FSLO_BINUM3_POS 8U -#define USB3_GPRTBIMAP_FSLO_BINUM2_MASK 0x000000F0U -#define USB3_GPRTBIMAP_FSLO_BINUM2_POS 4U -#define USB3_GPRTBIMAP_FSLO_BINUM1_MASK 0x0000000FU -#define USB3_GPRTBIMAP_FSLO_BINUM1_POS 0U - -/* Bit fields of GPRTBIMAP_FSHI register */ -#define USB3_GPRTBIMAP_FSHI_BINUM15_MASK 0x0F000000U -#define USB3_GPRTBIMAP_FSHI_BINUM15_POS 24U -#define USB3_GPRTBIMAP_FSHI_BINUM14_MASK 0x00F00000U -#define USB3_GPRTBIMAP_FSHI_BINUM14_POS 20U -#define USB3_GPRTBIMAP_FSHI_BINUM13_MASK 0x000F0000U -#define USB3_GPRTBIMAP_FSHI_BINUM13_POS 16U -#define USB3_GPRTBIMAP_FSHI_BINUM12_MASK 0x0000F000U -#define USB3_GPRTBIMAP_FSHI_BINUM12_POS 12U -#define USB3_GPRTBIMAP_FSHI_BINUM11_MASK 0x00000F00U -#define USB3_GPRTBIMAP_FSHI_BINUM11_POS 8U -#define USB3_GPRTBIMAP_FSHI_BINUM10_MASK 0x000000F0U -#define USB3_GPRTBIMAP_FSHI_BINUM10_POS 4U -#define USB3_GPRTBIMAP_FSHI_BINUM9_MASK 0x0000000FU -#define USB3_GPRTBIMAP_FSHI_BINUM9_POS 0U - -/* Bit fields of GHMSOCBWOR register */ -#define USB3_GHMSOCBWOR_OVRD_PORT_SOC_BW_MASK 0x80000000U -#define USB3_GHMSOCBWOR_OVRD_PORT_SOC_BW_POS 31U -#define USB3_GHMSOCBWOR_OVRD_COMMON_SOC_RD_WR_MASK 0x40000000U -#define USB3_GHMSOCBWOR_OVRD_COMMON_SOC_RD_WR_POS 30U -#define USB3_GHMSOCBWOR_OVRD_SOC_WR_UF_KB_BANDWIDTH_MASK 0x3FFF8000U -#define USB3_GHMSOCBWOR_OVRD_SOC_WR_UF_KB_BANDWIDTH_POS 15U -#define USB3_GHMSOCBWOR_OVRD_SOC_RD_UF_KB_BANDWIDTH_MASK 0x00007FFFU -#define USB3_GHMSOCBWOR_OVRD_SOC_RD_UF_KB_BANDWIDTH_POS 0U - -/* Bit fields of USB31_VER_NUMBER register */ -#define USB3_USB31_VER_NUMBER_VERSION_NUM_MASK 0xFFFFFFFFU -#define USB3_USB31_VER_NUMBER_VERSION_NUM_POS 0U - -/* Bit fields of USB31_VER_TYPE register */ -#define USB3_USB31_VER_TYPE_VERSIONTYPE_MASK 0xFFFFFFFFU -#define USB3_USB31_VER_TYPE_VERSIONTYPE_POS 0U - -/* Bit fields of GSYSBLKWINCTRL register */ -#define USB3_GSYSBLKWINCTRL_SYS_BLOCKING_OK_ALL_THE_TIME_MASK 0x80000000U -#define USB3_GSYSBLKWINCTRL_SYS_BLOCKING_OK_ALL_THE_TIME_POS 31U -#define USB3_GSYSBLKWINCTRL_DISABLE_NO_BLOCKING_WINDOW_MASK 0x40000000U -#define USB3_GSYSBLKWINCTRL_DISABLE_NO_BLOCKING_WINDOW_POS 30U -#define USB3_GSYSBLKWINCTRL_ERST_PREFETCHING_EN_MASK 0x20000000U -#define USB3_GSYSBLKWINCTRL_ERST_PREFETCHING_EN_POS 29U -#define USB3_GSYSBLKWINCTRL_ERST_PREFETCHING_WATERMARK_MASK 0x1F000000U -#define USB3_GSYSBLKWINCTRL_ERST_PREFETCHING_WATERMARK_POS 24U -#define USB3_GSYSBLKWINCTRL_END_NO_BLOCKING_TIME_MASK 0x0000FF00U -#define USB3_GSYSBLKWINCTRL_END_NO_BLOCKING_TIME_POS 8U -#define USB3_GSYSBLKWINCTRL_BEGININING_NO_BLOCKING_TIME_MASK 0x000000FFU -#define USB3_GSYSBLKWINCTRL_BEGININING_NO_BLOCKING_TIME_POS 0U - -/* Bit fields of GPCIEL1EXTLAT register */ -#define USB3_GPCIEL1EXTLAT_PCIE_L1_EXIT_MODE_CTRL_MASK 0xC0000000U -#define USB3_GPCIEL1EXTLAT_PCIE_L1_EXIT_MODE_CTRL_POS 30U -#define USB3_GPCIEL1EXTLAT_PCIE_L1_EXIT_LATENCY_MASK 0x00000FFFU -#define USB3_GPCIEL1EXTLAT_PCIE_L1_EXIT_LATENCY_POS 0U - -/* Bit fields of GUSB2PHYCFG register */ -#define USB3_GUSB2PHYCFG_PHYSOFTRST_MASK 0x80000000U -#define USB3_GUSB2PHYCFG_PHYSOFTRST_POS 31U -#define USB3_GUSB2PHYCFG_ULPI_LPM_WITH_OPMODE_CHK_MASK 0x20000000U -#define USB3_GUSB2PHYCFG_ULPI_LPM_WITH_OPMODE_CHK_POS 29U -#define USB3_GUSB2PHYCFG_HSIC_CON_WIDTH_ADJ_MASK 0x18000000U -#define USB3_GUSB2PHYCFG_HSIC_CON_WIDTH_ADJ_POS 27U -#define USB3_GUSB2PHYCFG_INV_SEL_HSIC_MASK 0x04000000U -#define USB3_GUSB2PHYCFG_INV_SEL_HSIC_POS 26U -#define USB3_GUSB2PHYCFG_OVRD_FSLS_DISC_TIME_MASK 0x02000000U -#define USB3_GUSB2PHYCFG_OVRD_FSLS_DISC_TIME_POS 25U -#define USB3_GUSB2PHYCFG_LSTRD_MASK 0x01C00000U -#define USB3_GUSB2PHYCFG_LSTRD_POS 22U -#define USB3_GUSB2PHYCFG_LSIPD_MASK 0x00380000U -#define USB3_GUSB2PHYCFG_LSIPD_POS 19U -#define USB3_GUSB2PHYCFG_ULPIEXTVBUSINDIACTOR_MASK 0x00040000U -#define USB3_GUSB2PHYCFG_ULPIEXTVBUSINDIACTOR_POS 18U -#define USB3_GUSB2PHYCFG_ULPIEXTVBUSDRV_MASK 0x00020000U -#define USB3_GUSB2PHYCFG_ULPIEXTVBUSDRV_POS 17U -#define USB3_GUSB2PHYCFG_ULPIAUTORES_MASK 0x00008000U -#define USB3_GUSB2PHYCFG_ULPIAUTORES_POS 15U -#define USB3_GUSB2PHYCFG_EUSB2OPMODE_MASK 0x00004000U -#define USB3_GUSB2PHYCFG_EUSB2OPMODE_POS 14U -#define USB3_GUSB2PHYCFG_USBTRDTIM_MASK 0x00003C00U -#define USB3_GUSB2PHYCFG_USBTRDTIM_POS 10U -#define USB3_GUSB2PHYCFG_XCVRDLY_MASK 0x00000200U -#define USB3_GUSB2PHYCFG_XCVRDLY_POS 9U -#define USB3_GUSB2PHYCFG_ENBLSLPM_MASK 0x00000100U -#define USB3_GUSB2PHYCFG_ENBLSLPM_POS 8U -#define USB3_GUSB2PHYCFG_PHYSEL_MASK 0x00000080U -#define USB3_GUSB2PHYCFG_PHYSEL_POS 7U -#define USB3_GUSB2PHYCFG_SUSPENDUSB20_MASK 0x00000040U -#define USB3_GUSB2PHYCFG_SUSPENDUSB20_POS 6U -#define USB3_GUSB2PHYCFG_FSINTF_MASK 0x00000020U -#define USB3_GUSB2PHYCFG_FSINTF_POS 5U -#define USB3_GUSB2PHYCFG_ULPI_UTMI_SEL_MASK 0x00000010U -#define USB3_GUSB2PHYCFG_ULPI_UTMI_SEL_POS 4U -#define USB3_GUSB2PHYCFG_PHYIF_MASK 0x00000008U -#define USB3_GUSB2PHYCFG_PHYIF_POS 3U -#define USB3_GUSB2PHYCFG_TOUTCAL_MASK 0x00000007U -#define USB3_GUSB2PHYCFG_TOUTCAL_POS 0U - -/* Bit fields of GUSB2PHYACC_ULPI register */ -#define USB3_GUSB2PHYACC_ULPI_DISUIPIDRVR_MASK 0x04000000U -#define USB3_GUSB2PHYACC_ULPI_DISUIPIDRVR_POS 26U -#define USB3_GUSB2PHYACC_ULPI_NEWREGREQ_MASK 0x02000000U -#define USB3_GUSB2PHYACC_ULPI_NEWREGREQ_POS 25U -#define USB3_GUSB2PHYACC_ULPI_VSTSDONE_MASK 0x01000000U -#define USB3_GUSB2PHYACC_ULPI_VSTSDONE_POS 24U -#define USB3_GUSB2PHYACC_ULPI_VSTSBSY_MASK 0x00800000U -#define USB3_GUSB2PHYACC_ULPI_VSTSBSY_POS 23U -#define USB3_GUSB2PHYACC_ULPI_REGWR_MASK 0x00400000U -#define USB3_GUSB2PHYACC_ULPI_REGWR_POS 22U -#define USB3_GUSB2PHYACC_ULPI_REGADDR_MASK 0x003F0000U -#define USB3_GUSB2PHYACC_ULPI_REGADDR_POS 16U -#define USB3_GUSB2PHYACC_ULPI_EXTREGADDR_MASK 0x0000FF00U -#define USB3_GUSB2PHYACC_ULPI_EXTREGADDR_POS 8U -#define USB3_GUSB2PHYACC_ULPI_REGDATA_MASK 0x000000FFU -#define USB3_GUSB2PHYACC_ULPI_REGDATA_POS 0U - -/* Bit fields of GUSB3PIPECTL register */ -#define USB3_GUSB3PIPECTL_PHYSOFTRST_MASK 0x80000000U -#define USB3_GUSB3PIPECTL_PHYSOFTRST_POS 31U -#define USB3_GUSB3PIPECTL_HSTPRTCMPL_MASK 0x40000000U -#define USB3_GUSB3PIPECTL_HSTPRTCMPL_POS 30U -#define USB3_GUSB3PIPECTL_U2P3OK_MASK 0x20000000U -#define USB3_GUSB3PIPECTL_U2P3OK_POS 29U -#define USB3_GUSB3PIPECTL_DISRXDETP3_MASK 0x10000000U -#define USB3_GUSB3PIPECTL_DISRXDETP3_POS 28U -#define USB3_GUSB3PIPECTL_UX_EXIT_IN_PX_MASK 0x08000000U -#define USB3_GUSB3PIPECTL_UX_EXIT_IN_PX_POS 27U -#define USB3_GUSB3PIPECTL_PING_ENHANCEMENT_EN_MASK 0x04000000U -#define USB3_GUSB3PIPECTL_PING_ENHANCEMENT_EN_POS 26U -#define USB3_GUSB3PIPECTL_U1U2EXITFAIL_TO_RECOV_MASK 0x02000000U -#define USB3_GUSB3PIPECTL_U1U2EXITFAIL_TO_RECOV_POS 25U -#define USB3_GUSB3PIPECTL_REQUEST_P1P2P3_MASK 0x01000000U -#define USB3_GUSB3PIPECTL_REQUEST_P1P2P3_POS 24U -#define USB3_GUSB3PIPECTL_STARTRXDETU3RXDET_MASK 0x00800000U -#define USB3_GUSB3PIPECTL_STARTRXDETU3RXDET_POS 23U -#define USB3_GUSB3PIPECTL_DISRXDETU3RXDET_MASK 0x00400000U -#define USB3_GUSB3PIPECTL_DISRXDETU3RXDET_POS 22U -#define USB3_GUSB3PIPECTL_DELAYP1P2P3_MASK 0x00380000U -#define USB3_GUSB3PIPECTL_DELAYP1P2P3_POS 19U -#define USB3_GUSB3PIPECTL_DELAYP1TRANS_MASK 0x00040000U -#define USB3_GUSB3PIPECTL_DELAYP1TRANS_POS 18U -#define USB3_GUSB3PIPECTL_SUSPENDENABLE_MASK 0x00020000U -#define USB3_GUSB3PIPECTL_SUSPENDENABLE_POS 17U -#define USB3_GUSB3PIPECTL_DATWIDTH_MASK 0x00018000U -#define USB3_GUSB3PIPECTL_DATWIDTH_POS 15U -#define USB3_GUSB3PIPECTL_ABORTRXDETINU2_MASK 0x00004000U -#define USB3_GUSB3PIPECTL_ABORTRXDETINU2_POS 14U -#define USB3_GUSB3PIPECTL_SKIPRXDET_MASK 0x00002000U -#define USB3_GUSB3PIPECTL_SKIPRXDET_POS 13U -#define USB3_GUSB3PIPECTL_LFPSP0ALGN_MASK 0x00001000U -#define USB3_GUSB3PIPECTL_LFPSP0ALGN_POS 12U -#define USB3_GUSB3PIPECTL_P3P2TRANOK_MASK 0x00000800U -#define USB3_GUSB3PIPECTL_P3P2TRANOK_POS 11U -#define USB3_GUSB3PIPECTL_P3EXSIGP2_MASK 0x00000400U -#define USB3_GUSB3PIPECTL_P3EXSIGP2_POS 10U -#define USB3_GUSB3PIPECTL_LFPSFILTER_MASK 0x00000200U -#define USB3_GUSB3PIPECTL_LFPSFILTER_POS 9U -#define USB3_GUSB3PIPECTL_RX_DETECT_TO_POLLING_LFPS_CONTROL_MASK 0x00000100U -#define USB3_GUSB3PIPECTL_RX_DETECT_TO_POLLING_LFPS_CONTROL_POS 8U -#define USB3_GUSB3PIPECTL_TX_SWING_MASK 0x00000040U -#define USB3_GUSB3PIPECTL_TX_SWING_POS 6U -#define USB3_GUSB3PIPECTL_TX_MARGIN_MASK 0x00000038U -#define USB3_GUSB3PIPECTL_TX_MARGIN_POS 3U -#define USB3_GUSB3PIPECTL_SS_TX_DE_EMPHASIS_MASK 0x00000006U -#define USB3_GUSB3PIPECTL_SS_TX_DE_EMPHASIS_POS 1U -#define USB3_GUSB3PIPECTL_ELASTIC_BUFFER_MODE_MASK 0x00000001U -#define USB3_GUSB3PIPECTL_ELASTIC_BUFFER_MODE_POS 0U - -/* Bit fields of GTXFIFOSIZ0 register */ -#define USB3_GTXFIFOSIZ0_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ0_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ0_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ0_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ1 register */ -#define USB3_GTXFIFOSIZ1_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ1_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ1_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ1_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ2 register */ -#define USB3_GTXFIFOSIZ2_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ2_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ2_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ2_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ3 register */ -#define USB3_GTXFIFOSIZ3_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ3_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ3_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ3_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ4 register */ -#define USB3_GTXFIFOSIZ4_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ4_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ4_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ4_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ5 register */ -#define USB3_GTXFIFOSIZ5_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ5_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ5_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ5_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ6 register */ -#define USB3_GTXFIFOSIZ6_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ6_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ6_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ6_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ7 register */ -#define USB3_GTXFIFOSIZ7_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ7_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ7_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ7_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ8 register */ -#define USB3_GTXFIFOSIZ8_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ8_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ8_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ8_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ9 register */ -#define USB3_GTXFIFOSIZ9_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ9_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ9_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ9_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ10 register */ -#define USB3_GTXFIFOSIZ10_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ10_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ10_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ10_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ11 register */ -#define USB3_GTXFIFOSIZ11_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ11_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ11_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ11_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ12 register */ -#define USB3_GTXFIFOSIZ12_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ12_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ12_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ12_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ13 register */ -#define USB3_GTXFIFOSIZ13_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ13_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ13_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ13_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ14 register */ -#define USB3_GTXFIFOSIZ14_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ14_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ14_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ14_TXFDEP_N_POS 0U - -/* Bit fields of GTXFIFOSIZ15 register */ -#define USB3_GTXFIFOSIZ15_TXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GTXFIFOSIZ15_TXFSTADDR_N_POS 16U -#define USB3_GTXFIFOSIZ15_TXFDEP_N_MASK 0x00007FFFU -#define USB3_GTXFIFOSIZ15_TXFDEP_N_POS 0U - -/* Bit fields of GRXFIFOSIZ0 register */ -#define USB3_GRXFIFOSIZ0_RXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GRXFIFOSIZ0_RXFSTADDR_N_POS 16U -#define USB3_GRXFIFOSIZ0_RXFDEP_N_MASK 0x00007FFFU -#define USB3_GRXFIFOSIZ0_RXFDEP_N_POS 0U - -/* Bit fields of GRXFIFOSIZ1 register */ -#define USB3_GRXFIFOSIZ1_RXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GRXFIFOSIZ1_RXFSTADDR_N_POS 16U -#define USB3_GRXFIFOSIZ1_RXFDEP_N_MASK 0x00007FFFU -#define USB3_GRXFIFOSIZ1_RXFDEP_N_POS 0U - -/* Bit fields of GRXFIFOSIZ2 register */ -#define USB3_GRXFIFOSIZ2_RXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GRXFIFOSIZ2_RXFSTADDR_N_POS 16U -#define USB3_GRXFIFOSIZ2_RXFDEP_N_MASK 0x00007FFFU -#define USB3_GRXFIFOSIZ2_RXFDEP_N_POS 0U - -/* Bit fields of GRXFIFOSIZ3 register */ -#define USB3_GRXFIFOSIZ3_RXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GRXFIFOSIZ3_RXFSTADDR_N_POS 16U -#define USB3_GRXFIFOSIZ3_RXFDEP_N_MASK 0x00007FFFU -#define USB3_GRXFIFOSIZ3_RXFDEP_N_POS 0U - -/* Bit fields of GRXFIFOSIZ4 register */ -#define USB3_GRXFIFOSIZ4_RXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GRXFIFOSIZ4_RXFSTADDR_N_POS 16U -#define USB3_GRXFIFOSIZ4_RXFDEP_N_MASK 0x00007FFFU -#define USB3_GRXFIFOSIZ4_RXFDEP_N_POS 0U - -/* Bit fields of GRXFIFOSIZ5 register */ -#define USB3_GRXFIFOSIZ5_RXFSTADDR_N_MASK 0xFFFF0000U -#define USB3_GRXFIFOSIZ5_RXFSTADDR_N_POS 16U -#define USB3_GRXFIFOSIZ5_RXFDEP_N_MASK 0x00007FFFU -#define USB3_GRXFIFOSIZ5_RXFDEP_N_POS 0U - -/* Bit fields of GEVNTADRLO register */ -#define USB3_GEVNTADRLO_EVNTADRLO_MASK 0xFFFFFFFFU -#define USB3_GEVNTADRLO_EVNTADRLO_POS 0U - -/* Bit fields of GEVNTADRHI register */ -#define USB3_GEVNTADRHI_EVNTADRHI_MASK 0xFFFFFFFFU -#define USB3_GEVNTADRHI_EVNTADRHI_POS 0U - -/* Bit fields of GEVNTSIZ register */ -#define USB3_GEVNTSIZ_EVNTINTRPTMASK_MASK 0x80000000U -#define USB3_GEVNTSIZ_EVNTINTRPTMASK_POS 31U -#define USB3_GEVNTSIZ_EVENTSIZ_MASK 0x0000FFFFU -#define USB3_GEVNTSIZ_EVENTSIZ_POS 0U - -/* Bit fields of GEVNTCOUNT register */ -#define USB3_GEVNTCOUNT_EVNT_HANDLER_BUSY_MASK 0x80000000U -#define USB3_GEVNTCOUNT_EVNT_HANDLER_BUSY_POS 31U -#define USB3_GEVNTCOUNT_EVNTCOUNT_MASK 0x0000FFFFU -#define USB3_GEVNTCOUNT_EVNTCOUNT_POS 0U - -/* Bit fields of GHWPARAMS8 register */ -#define USB3_GHWPARAMS8_GHWPARAMS8_32_0_MASK 0xFFFFFFFFU -#define USB3_GHWPARAMS8_GHWPARAMS8_32_0_POS 0U - -/* Bit fields of GSMACCTL register */ -#define USB3_GSMACCTL_DBG_TIS_INDEX_MASK 0xC0000000U -#define USB3_GSMACCTL_DBG_TIS_INDEX_POS 30U -#define USB3_GSMACCTL_DBG_PTL_ADDR_MASK 0x3C000000U -#define USB3_GSMACCTL_DBG_PTL_ADDR_POS 26U -#define USB3_GSMACCTL_HOSTIN_SIGNLE_EN_MASK 0x00020000U -#define USB3_GSMACCTL_HOSTIN_SIGNLE_EN_POS 17U -#define USB3_GSMACCTL_HOSTOUT_SINGLE_EN_MASK 0x00010000U -#define USB3_GSMACCTL_HOSTOUT_SINGLE_EN_POS 16U -#define USB3_GSMACCTL_SINGLE_PSQDIR_EN_MASK 0x00000008U -#define USB3_GSMACCTL_SINGLE_PSQDIR_EN_POS 3U -#define USB3_GSMACCTL_HOST_MASK_NUMP0_MASK 0x00000004U -#define USB3_GSMACCTL_HOST_MASK_NUMP0_POS 2U -#define USB3_GSMACCTL_IGNORE_BABBLE_MASK 0x00000002U -#define USB3_GSMACCTL_IGNORE_BABBLE_POS 1U -#define USB3_GSMACCTL_SINGLE_TBT_REQ_MASK 0x00000001U -#define USB3_GSMACCTL_SINGLE_TBT_REQ_POS 0U - -/* Bit fields of GUCTL2 register */ -#define USB3_GUCTL2_PERIODIC_UF_THR_MASK 0xFE000000U -#define USB3_GUCTL2_PERIODIC_UF_THR_POS 25U -#define USB3_GUCTL2_ASYNC_UF_THR_MASK 0x01FC0000U -#define USB3_GUCTL2_ASYNC_UF_THR_POS 18U -#define USB3_GUCTL2_PERIODIC_TXDMA_UF_THR_MASK 0x0003F800U -#define USB3_GUCTL2_PERIODIC_TXDMA_UF_THR_POS 11U -#define USB3_GUCTL2_SVC_OPP_PER_SSP_MASK 0x00000600U -#define USB3_GUCTL2_SVC_OPP_PER_SSP_POS 9U -#define USB3_GUCTL2_SVC_OPP_PER_SS_MASK 0x00000180U -#define USB3_GUCTL2_SVC_OPP_PER_SS_POS 7U -#define USB3_GUCTL2_SVC_OPP_PER_HS_MASK 0x00000060U -#define USB3_GUCTL2_SVC_OPP_PER_HS_POS 5U -#define USB3_GUCTL2_SVC_OPP_PER_FSLS_MASK 0x00000018U -#define USB3_GUCTL2_SVC_OPP_PER_FSLS_POS 3U -#define USB3_GUCTL2_MAX_REISU_CNT_MASK 0x00000006U -#define USB3_GUCTL2_MAX_REISU_CNT_POS 1U -#define USB3_GUCTL2_SCHEDDULE_LT_THR_MASK 0x00000001U -#define USB3_GUCTL2_SCHEDDULE_LT_THR_POS 0U - -/* Bit fields of GUCTL3 register */ -#define USB3_GUCTL3_CFGEP_CMD_SWITCHING_TIME_CTRL_MASK 0x01C00000U -#define USB3_GUCTL3_CFGEP_CMD_SWITCHING_TIME_CTRL_POS 22U -#define USB3_GUCTL3_BLOCK_CONCURRENT_IN_CTRL_XFERS_MASK 0x00200000U -#define USB3_GUCTL3_BLOCK_CONCURRENT_IN_CTRL_XFERS_POS 21U -#define USB3_GUCTL3_SSBI_SINGLE_EP_MODE_DISABLE_MASK 0x00100000U -#define USB3_GUCTL3_SSBI_SINGLE_EP_MODE_DISABLE_POS 20U -#define USB3_GUCTL3_DISEXTBUSCLKGT_U1U2L1_MASK 0x00080000U -#define USB3_GUCTL3_DISEXTBUSCLKGT_U1U2L1_POS 19U -#define USB3_GUCTL3_DISEXTBUSCLKGT_MASK 0x00040000U -#define USB3_GUCTL3_DISEXTBUSCLKGT_POS 18U -#define USB3_GUCTL3_USB20_RETRY_DISABLE_MASK 0x00010000U -#define USB3_GUCTL3_USB20_RETRY_DISABLE_POS 16U -#define USB3_GUCTL3_SVC_OPP_PER_HS_SEP_MASK 0x00001E00U -#define USB3_GUCTL3_SVC_OPP_PER_HS_SEP_POS 9U -#define USB3_GUCTL3_BARB_BURST_ENABLE_MASK 0x00000100U -#define USB3_GUCTL3_BARB_BURST_ENABLE_POS 8U -#define USB3_GUCTL3_INTR_EP_PING_ENABLE_MASK 0x00000080U -#define USB3_GUCTL3_INTR_EP_PING_ENABLE_POS 7U -#define USB3_GUCTL3_PERIODIC_UF_THR_FSLS_MASK 0x0000007FU -#define USB3_GUCTL3_PERIODIC_UF_THR_FSLS_POS 0U - -/* Bit fields of GTXFIFOPRIDEV register */ -#define USB3_GTXFIFOPRIDEV_GTXFIFOPRIDEV_MASK 0x0000FFFFU -#define USB3_GTXFIFOPRIDEV_GTXFIFOPRIDEV_POS 0U - -/* Bit fields of GTXFIFOPRIHST register */ -#define USB3_GTXFIFOPRIHST_GTXFIFOPRIHST_MASK 0x0000007FU -#define USB3_GTXFIFOPRIHST_GTXFIFOPRIHST_POS 0U - -/* Bit fields of GRXFIFOPRIHST register */ -#define USB3_GRXFIFOPRIHST_GRXFIFOPRIHST_MASK 0x0000003FU -#define USB3_GRXFIFOPRIHST_GRXFIFOPRIHST_POS 0U - -/* Bit fields of GFIFOPRIDBC register */ -#define USB3_GFIFOPRIDBC_GFIFOPRIDBC_MASK 0x00000003U -#define USB3_GFIFOPRIDBC_GFIFOPRIDBC_POS 0U - -/* Bit fields of GDMAHLRATIO register */ -#define USB3_GDMAHLRATIO_HSTRXFIFO_MAC_MASK 0x1F000000U -#define USB3_GDMAHLRATIO_HSTRXFIFO_MAC_POS 24U -#define USB3_GDMAHLRATIO_HSTTXFIFO_MAC_MASK 0x001F0000U -#define USB3_GDMAHLRATIO_HSTTXFIFO_MAC_POS 16U -#define USB3_GDMAHLRATIO_HSTRXFIFO_DMA_MASK 0x00001F00U -#define USB3_GDMAHLRATIO_HSTRXFIFO_DMA_POS 8U -#define USB3_GDMAHLRATIO_HSTTXFIFO_DMA_MASK 0x0000001FU -#define USB3_GDMAHLRATIO_HSTTXFIFO_DMA_POS 0U - -/* Bit fields of GOSTDDMA_ASYNC register */ -#define USB3_GOSTDDMA_ASYNC_OSTDRX_ASYNC_MASK 0xFF000000U -#define USB3_GOSTDDMA_ASYNC_OSTDRX_ASYNC_POS 24U -#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_ACTIVE_MASK 0x00FF0000U -#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_ACTIVE_POS 16U -#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_INACTIVE_MASK 0x0000FF00U -#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_INACTIVE_POS 8U -#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_MASK 0x000000FFU -#define USB3_GOSTDDMA_ASYNC_OSTDTX_ASYNC_POS 0U - -/* Bit fields of GOSTDDMA_PRD register */ -#define USB3_GOSTDDMA_PRD_OSTDRX_PRD_MASK 0xFF000000U -#define USB3_GOSTDDMA_PRD_OSTDRX_PRD_POS 24U -#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_ACTIVE_MASK 0x00FF0000U -#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_ACTIVE_POS 16U -#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_INACTIVE_MASK 0x0000FF00U -#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_INACTIVE_POS 8U -#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_MASK 0x000000FFU -#define USB3_GOSTDDMA_PRD_OSTDTX_PRD_POS 0U - -/* Bit fields of GFLADJ register */ -#define USB3_GFLADJ_GFLADJ_REFCLK_240MHZDECR_PLS1_MASK 0x80000000U -#define USB3_GFLADJ_GFLADJ_REFCLK_240MHZDECR_PLS1_POS 31U -#define USB3_GFLADJ_GFLADJ_REFCLK_240MHZ_DECR_MASK 0x7F000000U -#define USB3_GFLADJ_GFLADJ_REFCLK_240MHZ_DECR_POS 24U -#define USB3_GFLADJ_GFLADJ_REFCLK_LPM_SEL_MASK 0x00800000U -#define USB3_GFLADJ_GFLADJ_REFCLK_LPM_SEL_POS 23U -#define USB3_GFLADJ_GFLADJ_REFCLK_FLADJ_MASK 0x003FFF00U -#define USB3_GFLADJ_GFLADJ_REFCLK_FLADJ_POS 8U -#define USB3_GFLADJ_GFLADJ_30MHZ_SDBND_SEL_MASK 0x00000080U -#define USB3_GFLADJ_GFLADJ_30MHZ_SDBND_SEL_POS 7U -#define USB3_GFLADJ_GFLADJ_30MHZ_MASK 0x0000003FU -#define USB3_GFLADJ_GFLADJ_30MHZ_POS 0U - -/* Bit fields of GUCTL4 register */ -#define USB3_GUCTL4_SSP_BWD_OVHD_ADJ_MASK 0x7C000000U -#define USB3_GUCTL4_SSP_BWD_OVHD_ADJ_POS 26U -#define USB3_GUCTL4_LOA_EOP_CHECK_CLKS_WORD_MASK 0x00180000U -#define USB3_GUCTL4_LOA_EOP_CHECK_CLKS_WORD_POS 19U -#define USB3_GUCTL4_LOA_EOP_CHECK_CLKS_BYTE_MASK 0x00060000U -#define USB3_GUCTL4_LOA_EOP_CHECK_CLKS_BYTE_POS 17U -#define USB3_GUCTL4_CSR_TIMEOUT_VL_MASK 0x0001FFFFU -#define USB3_GUCTL4_CSR_TIMEOUT_VL_POS 0U - -/* Bit fields of GUCTL5 register */ - -/* Bit fields of GUSB2RHBCTL register */ -#define USB3_GUSB2RHBCTL_OVRD_FS_INT_PKT_DEL_MASK 0x000FF000U -#define USB3_GUSB2RHBCTL_OVRD_FS_INT_PKT_DEL_POS 12U -#define USB3_GUSB2RHBCTL_OVRD_HS_INT_PKT_DEL_MASK 0x00000FF0U -#define USB3_GUSB2RHBCTL_OVRD_HS_INT_PKT_DEL_POS 4U -#define USB3_GUSB2RHBCTL_OVRD_L1TIMEOUT_MASK 0x0000000FU -#define USB3_GUSB2RHBCTL_OVRD_L1TIMEOUT_POS 0U - -/* Bit fields of DCFG register */ -#define USB3_DCFG_IGNSTRMPP_MASK 0x00800000U -#define USB3_DCFG_IGNSTRMPP_POS 23U -#define USB3_DCFG_LPMCAP_MASK 0x00400000U -#define USB3_DCFG_LPMCAP_POS 22U -#define USB3_DCFG_NUMP_MASK 0x003E0000U -#define USB3_DCFG_NUMP_POS 17U -#define USB3_DCFG_INTRNUM_MASK 0x0001F000U -#define USB3_DCFG_INTRNUM_POS 12U -#define USB3_DCFG_DEVADDR_MASK 0x000003F8U -#define USB3_DCFG_DEVADDR_POS 3U -#define USB3_DCFG_DEVSPD_MASK 0x00000007U -#define USB3_DCFG_DEVSPD_POS 0U - -/* Bit fields of DCTL register */ -#define USB3_DCTL_RUN_STOP_MASK 0x80000000U -#define USB3_DCTL_RUN_STOP_POS 31U -#define USB3_DCTL_CSFTRST_MASK 0x40000000U -#define USB3_DCTL_CSFTRST_POS 30U -#define USB3_DCTL_HIRDTHRES_MASK 0x1F000000U -#define USB3_DCTL_HIRDTHRES_POS 24U -#define USB3_DCTL_LPM_NYET_THRES_MASK 0x00F00000U -#define USB3_DCTL_LPM_NYET_THRES_POS 20U -#define USB3_DCTL_KEEPCONNECT_MASK 0x00080000U -#define USB3_DCTL_KEEPCONNECT_POS 19U -#define USB3_DCTL_L1HIBERNATIONEN_MASK 0x00040000U -#define USB3_DCTL_L1HIBERNATIONEN_POS 18U -#define USB3_DCTL_CRS_MASK 0x00020000U -#define USB3_DCTL_CRS_POS 17U -#define USB3_DCTL_CSS_MASK 0x00010000U -#define USB3_DCTL_CSS_POS 16U -#define USB3_DCTL_INITU2ENA_MASK 0x00001000U -#define USB3_DCTL_INITU2ENA_POS 12U -#define USB3_DCTL_ACCEPTU2ENA_MASK 0x00000800U -#define USB3_DCTL_ACCEPTU2ENA_POS 11U -#define USB3_DCTL_INITU1ENA_MASK 0x00000400U -#define USB3_DCTL_INITU1ENA_POS 10U -#define USB3_DCTL_ACCEPTU1ENA_MASK 0x00000200U -#define USB3_DCTL_ACCEPTU1ENA_POS 9U -#define USB3_DCTL_ULSTCHNGREQ_MASK 0x000001E0U -#define USB3_DCTL_ULSTCHNGREQ_POS 5U -#define USB3_DCTL_TSTCTL_MASK 0x0000001EU -#define USB3_DCTL_TSTCTL_POS 1U - -/* Bit fields of DEVTEN register */ -#define USB3_DEVTEN_LDMEVTEN_MASK 0x00008000U -#define USB3_DEVTEN_LDMEVTEN_POS 15U -#define USB3_DEVTEN_L1WKUPEVTEN_MASK 0x00004000U -#define USB3_DEVTEN_L1WKUPEVTEN_POS 14U -#define USB3_DEVTEN_VENDEVTSTRCVDEN_MASK 0x00001000U -#define USB3_DEVTEN_VENDEVTSTRCVDEN_POS 12U -#define USB3_DEVTEN_ERRTICERREVTEN_MASK 0x00000200U -#define USB3_DEVTEN_ERRTICERREVTEN_POS 9U -#define USB3_DEVTEN_L1SUSPEN_MASK 0x00000100U -#define USB3_DEVTEN_L1SUSPEN_POS 8U -#define USB3_DEVTEN_SOFTEVTEN_MASK 0x00000080U -#define USB3_DEVTEN_SOFTEVTEN_POS 7U -#define USB3_DEVTEN_U3L2L1SUSPEN_MASK 0x00000040U -#define USB3_DEVTEN_U3L2L1SUSPEN_POS 6U -#define USB3_DEVTEN_HIBERNATIONREQEVTEN_MASK 0x00000020U -#define USB3_DEVTEN_HIBERNATIONREQEVTEN_POS 5U -#define USB3_DEVTEN_WKUPEVTEN_MASK 0x00000010U -#define USB3_DEVTEN_WKUPEVTEN_POS 4U -#define USB3_DEVTEN_ULSTCNGEN_MASK 0x00000008U -#define USB3_DEVTEN_ULSTCNGEN_POS 3U -#define USB3_DEVTEN_CONNECTDONEEVTEN_MASK 0x00000004U -#define USB3_DEVTEN_CONNECTDONEEVTEN_POS 2U -#define USB3_DEVTEN_USBRSTEVTEN_MASK 0x00000002U -#define USB3_DEVTEN_USBRSTEVTEN_POS 1U -#define USB3_DEVTEN_DISSCONNEVTEN_MASK 0x00000001U -#define USB3_DEVTEN_DISSCONNEVTEN_POS 0U - -/* Bit fields of DSTS register */ -#define USB3_DSTS_DCNRD_MASK 0x20000000U -#define USB3_DSTS_DCNRD_POS 29U -#define USB3_DSTS_SRE_MASK 0x10000000U -#define USB3_DSTS_SRE_POS 28U -#define USB3_DSTS_RSS_MASK 0x02000000U -#define USB3_DSTS_RSS_POS 25U -#define USB3_DSTS_SSS_MASK 0x01000000U -#define USB3_DSTS_SSS_POS 24U -#define USB3_DSTS_COREIDLE_MASK 0x00800000U -#define USB3_DSTS_COREIDLE_POS 23U -#define USB3_DSTS_DEVCTRLHLT_MASK 0x00400000U -#define USB3_DSTS_DEVCTRLHLT_POS 22U -#define USB3_DSTS_USBLNKST_MASK 0x003C0000U -#define USB3_DSTS_USBLNKST_POS 18U -#define USB3_DSTS_RXFIFOEMPTY_MASK 0x00020000U -#define USB3_DSTS_RXFIFOEMPTY_POS 17U -#define USB3_DSTS_SOFFN_MASK 0x0001FFF8U -#define USB3_DSTS_SOFFN_POS 3U -#define USB3_DSTS_CONNECTSPD_MASK 0x00000007U -#define USB3_DSTS_CONNECTSPD_POS 0U - -/* Bit fields of DGCMDPAR register */ -#define USB3_DGCMDPAR_PARAMETER_MASK 0xFFFFFFFFU -#define USB3_DGCMDPAR_PARAMETER_POS 0U - -/* Bit fields of DGCMD register */ -#define USB3_DGCMD_CMDSTATUS_MASK 0x0000F000U -#define USB3_DGCMD_CMDSTATUS_POS 12U -#define USB3_DGCMD_CMDACT_MASK 0x00000400U -#define USB3_DGCMD_CMDACT_POS 10U -#define USB3_DGCMD_CMDIOC_MASK 0x00000100U -#define USB3_DGCMD_CMDIOC_POS 8U -#define USB3_DGCMD_CMDTYP_MASK 0x000000FFU -#define USB3_DGCMD_CMDTYP_POS 0U - -/* Bit fields of DCTL1 register */ -#define USB3_DCTL1_EN_ENDXFER_ON_RJCT_STRM_MASK 0x00000004U -#define USB3_DCTL1_EN_ENDXFER_ON_RJCT_STRM_POS 2U -#define USB3_DCTL1_DIS_CLRSPR_SXFER_MASK 0x00000002U -#define USB3_DCTL1_DIS_CLRSPR_SXFER_POS 1U - -/* Bit fields of DALEPENA register */ -#define USB3_DALEPENA_USBACTEP_MASK 0xFFFFFFFFU -#define USB3_DALEPENA_USBACTEP_POS 0U - -/* Bit fields of DLDMENA register */ -#define USB3_DLDMENA_LDMADJ_MASK 0xFFFF0000U -#define USB3_DLDMENA_LDMADJ_POS 16U -#define USB3_DLDMENA_LDMDUR_MASK 0x0000FF00U -#define USB3_DLDMENA_LDMDUR_POS 8U -#define USB3_DLDMENA_NOLOWPWRDUR_MASK 0x000000F0U -#define USB3_DLDMENA_NOLOWPWRDUR_POS 4U -#define USB3_DLDMENA_LDMRQS_MASK 0x0000000EU -#define USB3_DLDMENA_LDMRQS_POS 1U -#define USB3_DLDMENA_LDMENA_MASK 0x00000001U -#define USB3_DLDMENA_LDMENA_POS 0U - -/* Bit fields of Rsvd register */ - -/* Bit fields of DEPCMDPAR2 register */ -#define USB3_DEPCMDPAR2_PARAMETER_MASK 0xFFFFFFFFU -#define USB3_DEPCMDPAR2_PARAMETER_POS 0U - -/* Bit fields of DEPCMDPAR1 register */ -#define USB3_DEPCMDPAR1_PARAMETER_MASK 0xFFFFFFFFU -#define USB3_DEPCMDPAR1_PARAMETER_POS 0U - -/* Bit fields of DEPCMDPAR0 register */ -#define USB3_DEPCMDPAR0_PARAMETER_MASK 0xFFFFFFFFU -#define USB3_DEPCMDPAR0_PARAMETER_POS 0U - -/* Bit fields of DEPCMD register */ -#define USB3_DEPCMD_COMMANDPARAM_MASK 0xFFFF0000U -#define USB3_DEPCMD_COMMANDPARAM_POS 16U -#define USB3_DEPCMD_CMDSTATUS_MASK 0x0000F000U -#define USB3_DEPCMD_CMDSTATUS_POS 12U -#define USB3_DEPCMD_HIPRI_FORCERM_MASK 0x00000800U -#define USB3_DEPCMD_HIPRI_FORCERM_POS 11U -#define USB3_DEPCMD_CMDACT_MASK 0x00000400U -#define USB3_DEPCMD_CMDACT_POS 10U -#define USB3_DEPCMD_CMDIOC_MASK 0x00000100U -#define USB3_DEPCMD_CMDIOC_POS 8U -#define USB3_DEPCMD_CMDTYP_MASK 0x0000000FU -#define USB3_DEPCMD_CMDTYP_POS 0U - -/* Bit fields of DEV_IMOD register */ -#define USB3_DEV_IMOD_DEVICE_IMODC_MASK 0xFFFF0000U -#define USB3_DEV_IMOD_DEVICE_IMODC_POS 16U -#define USB3_DEV_IMOD_DEVICE_IMODI_MASK 0x0000FFFFU -#define USB3_DEV_IMOD_DEVICE_IMODI_POS 0U - -/* Bit fields of rsvd0_reg register */ -#define USB3_RSVD0_REG_RSVD_FIELD_MASK 0xFFFFFFFFU -#define USB3_RSVD0_REG_RSVD_FIELD_POS 0U - -/* Bit fields of LU1LFPSRXTIM register */ -#define USB3_LU1LFPSRXTIM_GEN2_U1_LFPS_EXIT_RX_CLK_MASK 0xFF000000U -#define USB3_LU1LFPSRXTIM_GEN2_U1_LFPS_EXIT_RX_CLK_POS 24U -#define USB3_LU1LFPSRXTIM_GEN2_U1_EXIT_RSP_RX_CLK_MASK 0x00FF0000U -#define USB3_LU1LFPSRXTIM_GEN2_U1_EXIT_RSP_RX_CLK_POS 16U -#define USB3_LU1LFPSRXTIM_GEN1_U1_LFPS_EXIT_RX_CLK_MASK 0x0000FF00U -#define USB3_LU1LFPSRXTIM_GEN1_U1_LFPS_EXIT_RX_CLK_POS 8U -#define USB3_LU1LFPSRXTIM_GEN1_U1_EXIT_RSP_RX_CLK_MASK 0x000000FFU -#define USB3_LU1LFPSRXTIM_GEN1_U1_EXIT_RSP_RX_CLK_POS 0U - -/* Bit fields of LU1LFPSTXTIM register */ -#define USB3_LU1LFPSTXTIM_GEN2_U1_EXIT_RESP_TX_CLK_MASK 0x3FFF0000U -#define USB3_LU1LFPSTXTIM_GEN2_U1_EXIT_RESP_TX_CLK_POS 16U -#define USB3_LU1LFPSTXTIM_GEN1_U1_EXIT_RSP_TX_CLK_MASK 0x00003FFFU -#define USB3_LU1LFPSTXTIM_GEN1_U1_EXIT_RSP_TX_CLK_POS 0U - -/* Bit fields of LU2LFPSRXTIM register */ -#define USB3_LU2LFPSRXTIM_GEN2_U2_LFPS_EXIT_RX_CLK_MASK 0xFF000000U -#define USB3_LU2LFPSRXTIM_GEN2_U2_LFPS_EXIT_RX_CLK_POS 24U -#define USB3_LU2LFPSRXTIM_GEN2_U2_EXIT_RSP_RX_CLK_MASK 0x00FF0000U -#define USB3_LU2LFPSRXTIM_GEN2_U2_EXIT_RSP_RX_CLK_POS 16U -#define USB3_LU2LFPSRXTIM_GEN1_U2_LFPS_EXIT_RX_CLK_MASK 0x0000FF00U -#define USB3_LU2LFPSRXTIM_GEN1_U2_LFPS_EXIT_RX_CLK_POS 8U -#define USB3_LU2LFPSRXTIM_GEN1_U2_EXIT_RSP_RX_CLK_MASK 0x000000FFU -#define USB3_LU2LFPSRXTIM_GEN1_U2_EXIT_RSP_RX_CLK_POS 0U - -/* Bit fields of LU2LFPSTXTIM register */ -#define USB3_LU2LFPSTXTIM_U2_EXIT_RSP_TX_US_MASK 0x00003FFFU -#define USB3_LU2LFPSTXTIM_U2_EXIT_RSP_TX_US_POS 0U - -/* Bit fields of LU3LFPSRXTIM register */ -#define USB3_LU3LFPSRXTIM_GEN2_U3_LFPS_EXIT_RX_CLK_MASK 0xFF000000U -#define USB3_LU3LFPSRXTIM_GEN2_U3_LFPS_EXIT_RX_CLK_POS 24U -#define USB3_LU3LFPSRXTIM_GEN2_U3_EXIT_RSP_RX_CLK_MASK 0x00FF0000U -#define USB3_LU3LFPSRXTIM_GEN2_U3_EXIT_RSP_RX_CLK_POS 16U -#define USB3_LU3LFPSRXTIM_GEN1_U3_LFPS_EXIT_RX_CLK_MASK 0x0000FF00U -#define USB3_LU3LFPSRXTIM_GEN1_U3_LFPS_EXIT_RX_CLK_POS 8U -#define USB3_LU3LFPSRXTIM_GEN1_U3_EXIT_RSP_RX_CLK_MASK 0x000000FFU -#define USB3_LU3LFPSRXTIM_GEN1_U3_EXIT_RSP_RX_CLK_POS 0U - -/* Bit fields of LU3LFPSTXTIM register */ -#define USB3_LU3LFPSTXTIM_GEN2_U3_EXIT_TX_CLK_MASK 0x3FFF0000U -#define USB3_LU3LFPSTXTIM_GEN2_U3_EXIT_TX_CLK_POS 16U -#define USB3_LU3LFPSTXTIM_GEN1_U3_EXIT_RSP_TX_CLK_MASK 0x00003FFFU -#define USB3_LU3LFPSTXTIM_GEN1_U3_EXIT_RSP_TX_CLK_POS 0U - -/* Bit fields of LPINGLFPSTIM register */ -#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_BURST_CLK_MASK 0xFC000000U -#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_BURST_CLK_POS 26U -#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_MAX_CLK_MASK 0x03F00000U -#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_MAX_CLK_POS 20U -#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_MIN_CLK_MASK 0x000F0000U -#define USB3_LPINGLFPSTIM_GEN2_LFPS_PING_MIN_CLK_POS 16U -#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_BURST_CLK_MASK 0x0000FC00U -#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_BURST_CLK_POS 10U -#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_MAX_CLK_MASK 0x000003F0U -#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_MAX_CLK_POS 4U -#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_MIN_CLK_MASK 0x0000000FU -#define USB3_LPINGLFPSTIM_GEN1_LFPS_PING_MIN_CLK_POS 0U - -/* Bit fields of LPOLLLFPSTXTIM register */ -#define USB3_LPOLLLFPSTXTIM_LFPS_POLL_SPACE_CLK_MASK 0x003FF800U -#define USB3_LPOLLLFPSTXTIM_LFPS_POLL_SPACE_CLK_POS 11U -#define USB3_LPOLLLFPSTXTIM_LFPS_POLL_BURST_CLK_MASK 0x000007FFU -#define USB3_LPOLLLFPSTXTIM_LFPS_POLL_BURST_CLK_POS 0U - -/* Bit fields of LSKIPFREQ register */ -#define USB3_LSKIPFREQ_U1_RESID_TIMER_US_MASK 0x70000000U -#define USB3_LSKIPFREQ_U1_RESID_TIMER_US_POS 28U -#define USB3_LSKIPFREQ_EN_PM_TIMER_US_MASK 0x08000000U -#define USB3_LSKIPFREQ_EN_PM_TIMER_US_POS 27U -#define USB3_LSKIPFREQ_PM_LC_TIMER_US_MASK 0x07000000U -#define USB3_LSKIPFREQ_PM_LC_TIMER_US_POS 24U -#define USB3_LSKIPFREQ_PM_ENTRY_TIMER_US_MASK 0x00F00000U -#define USB3_LSKIPFREQ_PM_ENTRY_TIMER_US_POS 20U -#define USB3_LSKIPFREQ_GEN2_SKP_FREQ_MASK 0x000FF000U -#define USB3_LSKIPFREQ_GEN2_SKP_FREQ_POS 12U -#define USB3_LSKIPFREQ_GEN1_SKP_FREQ_MASK 0x00000FFFU -#define USB3_LSKIPFREQ_GEN1_SKP_FREQ_POS 0U - -/* Bit fields of LLUCTL register */ -#define USB3_LLUCTL_INVERSE_SYNC_HEADER_MASK 0x40000000U -#define USB3_LLUCTL_INVERSE_SYNC_HEADER_POS 30U -#define USB3_LLUCTL_SUPPORT_P4_PG_MASK 0x20000000U -#define USB3_LLUCTL_SUPPORT_P4_PG_POS 29U -#define USB3_LLUCTL_SUPPORT_P4_MASK 0x10000000U -#define USB3_LLUCTL_SUPPORT_P4_POS 28U -#define USB3_LLUCTL_DELAY_TX_GEN1_DP_MASK 0x0F000000U -#define USB3_LLUCTL_DELAY_TX_GEN1_DP_POS 24U -#define USB3_LLUCTL_DISRXDET_LTSSM_TIMER_OVRRD_MASK 0x00800000U -#define USB3_LLUCTL_DISRXDET_LTSSM_TIMER_OVRRD_POS 23U -#define USB3_LLUCTL_FORCE_DPP_TRUNCATE_MASK 0x00400000U -#define USB3_LLUCTL_FORCE_DPP_TRUNCATE_POS 22U -#define USB3_LLUCTL_EN_DPP_TRUNCATE_MASK 0x00200000U -#define USB3_LLUCTL_EN_DPP_TRUNCATE_POS 21U -#define USB3_LLUCTL_PENDING_HP_TIMER_US_MASK 0x001F0000U -#define USB3_LLUCTL_PENDING_HP_TIMER_US_POS 16U -#define USB3_LLUCTL_EN_US_HP_TIMER_MASK 0x00008000U -#define USB3_LLUCTL_EN_US_HP_TIMER_POS 15U -#define USB3_LLUCTL_RING_BUF_D_DELAY_MASK 0x00006000U -#define USB3_LLUCTL_RING_BUF_D_DELAY_POS 13U -#define USB3_LLUCTL_U2P3CPMOK_MASK 0x00001000U -#define USB3_LLUCTL_U2P3CPMOK_POS 12U -#define USB3_LLUCTL_EN_RESET_PIPE_AFTER_PHY_MUX_MASK 0x00000800U -#define USB3_LLUCTL_EN_RESET_PIPE_AFTER_PHY_MUX_POS 11U -#define USB3_LLUCTL_FORCE_GEN1_MASK 0x00000400U -#define USB3_LLUCTL_FORCE_GEN1_POS 10U -#define USB3_LLUCTL_GEN2_LOOPBACK_ENTRY_MODE_MASK 0x00000200U -#define USB3_LLUCTL_GEN2_LOOPBACK_ENTRY_MODE_POS 9U -#define USB3_LLUCTL_GEN1_LOOPBACK_ENTRY_MODE_MASK 0x00000100U -#define USB3_LLUCTL_GEN1_LOOPBACK_ENTRY_MODE_POS 8U -#define USB3_LLUCTL_MASK_PIPE_RESET_MASK 0x00000080U -#define USB3_LLUCTL_MASK_PIPE_RESET_POS 7U -#define USB3_LLUCTL_DELAY_UX_AFTER_LPMA_MASK 0x00000040U -#define USB3_LLUCTL_DELAY_UX_AFTER_LPMA_POS 6U -#define USB3_LLUCTL_NO_UX_EXIT_P0_TRANS_MASK 0x00000020U -#define USB3_LLUCTL_NO_UX_EXIT_P0_TRANS_POS 5U -#define USB3_LLUCTL_TX_TS1_CNT_MASK 0x0000001FU -#define USB3_LLUCTL_TX_TS1_CNT_POS 0U - -/* Bit fields of LPTMDPDELAY register */ -#define USB3_LPTMDPDELAY_RX_PATH_DELAY_GEN2_MASK 0xF8000000U -#define USB3_LPTMDPDELAY_RX_PATH_DELAY_GEN2_POS 27U -#define USB3_LPTMDPDELAY_TX_PATH_DELAY_GEN2_MASK 0x07C00000U -#define USB3_LPTMDPDELAY_TX_PATH_DELAY_GEN2_POS 22U -#define USB3_LPTMDPDELAY_P3CPMP4_RESIDENCY_MASK 0x003FFC00U -#define USB3_LPTMDPDELAY_P3CPMP4_RESIDENCY_POS 10U -#define USB3_LPTMDPDELAY_RX_PATH_DELAY_MASK 0x000003E0U -#define USB3_LPTMDPDELAY_RX_PATH_DELAY_POS 5U -#define USB3_LPTMDPDELAY_TX_PATH_DELAY_MASK 0x0000001FU -#define USB3_LPTMDPDELAY_TX_PATH_DELAY_POS 0U - -/* Bit fields of LSCDTIM1 register */ -#define USB3_LSCDTIM1_SCD_BIT0_RPT_MAX_CLK_MASK 0x00FFF000U -#define USB3_LSCDTIM1_SCD_BIT0_RPT_MAX_CLK_POS 12U -#define USB3_LSCDTIM1_CD_BIT0_RPT_MIN_CLK_MASK 0x00000FFFU -#define USB3_LSCDTIM1_CD_BIT0_RPT_MIN_CLK_POS 0U - -/* Bit fields of LSCDTIM2 register */ -#define USB3_LSCDTIM2_SCD_BIT1_RPT_MAX_CLK_MASK 0x00FFF000U -#define USB3_LSCDTIM2_SCD_BIT1_RPT_MAX_CLK_POS 12U -#define USB3_LSCDTIM2_CD_BIT1_RPT_MIN_CLK_MASK 0x00000FFFU -#define USB3_LSCDTIM2_CD_BIT1_RPT_MIN_CLK_POS 0U - -/* Bit fields of LSCDTIM3 register */ -#define USB3_LSCDTIM3_LFPS_SCD_SPACE1_CLK_MASK 0xFFF00000U -#define USB3_LSCDTIM3_LFPS_SCD_SPACE1_CLK_POS 20U -#define USB3_LSCDTIM3_LFPS_SCD_SPACE0_CLK_MASK 0x000FFF00U -#define USB3_LSCDTIM3_LFPS_SCD_SPACE0_CLK_POS 8U -#define USB3_LSCDTIM3_LFPS_SCD_BURST_CLK_MASK 0x000000FFU -#define USB3_LSCDTIM3_LFPS_SCD_BURST_CLK_POS 0U - -/* Bit fields of LSCDTIM4 register */ -#define USB3_LSCDTIM4_LFPS_SCD_LAST_SPACE_MASK 0x00000FFFU -#define USB3_LSCDTIM4_LFPS_SCD_LAST_SPACE_POS 0U - -/* Bit fields of LLPBMTIM1 register */ -#define USB3_LLPBMTIM1_LFPS_LBPS1_BURST_MAX_CLK_MASK 0xFF000000U -#define USB3_LLPBMTIM1_LFPS_LBPS1_BURST_MAX_CLK_POS 24U -#define USB3_LLPBMTIM1_LFPS_LBPS1_BURST_MIN_CLK_MASK 0x00FF0000U -#define USB3_LLPBMTIM1_LFPS_LBPS1_BURST_MIN_CLK_POS 16U -#define USB3_LLPBMTIM1_LFPS_LBPS0_BURST_MAX_CLK_MASK 0x0000FF00U -#define USB3_LLPBMTIM1_LFPS_LBPS0_BURST_MAX_CLK_POS 8U -#define USB3_LLPBMTIM1_LFPS_LBPS0_BURST_MIN_CLK_MASK 0x000000FFU -#define USB3_LLPBMTIM1_LFPS_LBPS0_BURST_MIN_CLK_POS 0U - -/* Bit fields of LLPBMTIM2 register */ -#define USB3_LLPBMTIM2_LFPS_LBPM_TPWM_MAX_CLK_MASK 0x0003FE00U -#define USB3_LLPBMTIM2_LFPS_LBPM_TPWM_MAX_CLK_POS 9U -#define USB3_LLPBMTIM2_LFPS_LBPM_TPWM_MIN_CLK_MASK 0x000001FFU -#define USB3_LLPBMTIM2_LFPS_LBPM_TPWM_MIN_CLK_POS 0U - -/* Bit fields of LLPBMTXTIM register */ -#define USB3_LLPBMTXTIM_LFPS_LPBS_TPWM_CLK_MASK 0x3FF00000U -#define USB3_LLPBMTXTIM_LFPS_LPBS_TPWM_CLK_POS 20U -#define USB3_LLPBMTXTIM_LFPS_LBPS_BURST1_CLK_MASK 0x0003FF00U -#define USB3_LLPBMTXTIM_LFPS_LBPS_BURST1_CLK_POS 8U -#define USB3_LLPBMTXTIM_LFPS_LBPS_BURST0_CLK_MASK 0x000000FFU -#define USB3_LLPBMTXTIM_LFPS_LBPS_BURST0_CLK_POS 0U - -/* Bit fields of LLINKERRINJ register */ -#define USB3_LLINKERRINJ_PIPE_TXDATA_MASK 0x80000000U -#define USB3_LLINKERRINJ_PIPE_TXDATA_POS 31U -#define USB3_LLINKERRINJ_TX_INSERT_DEFER_MASK 0x40000000U -#define USB3_LLINKERRINJ_TX_INSERT_DEFER_POS 30U -#define USB3_LLINKERRINJ_TX_INSERT_DELAY_MASK 0x20000000U -#define USB3_LLINKERRINJ_TX_INSERT_DELAY_POS 29U -#define USB3_LLINKERRINJ_TX_TS2_MASK 0x10000000U -#define USB3_LLINKERRINJ_TX_TS2_POS 28U -#define USB3_LLINKERRINJ_TX_TS1_MASK 0x08000000U -#define USB3_LLINKERRINJ_TX_TS1_POS 27U -#define USB3_LLINKERRINJ_TX_TSEQ_MASK 0x04000000U -#define USB3_LLINKERRINJ_TX_TSEQ_POS 26U -#define USB3_LLINKERRINJ_TX_LFR_MASK 0x02000000U -#define USB3_LLINKERRINJ_TX_LFR_POS 25U -#define USB3_LLINKERRINJ_TX_DELAY_CREDIT_RL_MASK 0x01000000U -#define USB3_LLINKERRINJ_TX_DELAY_CREDIT_RL_POS 24U -#define USB3_LLINKERRINJ_TX_ONE_SRT_FRAME_SYBL_MASK 0x00800000U -#define USB3_LLINKERRINJ_TX_ONE_SRT_FRAME_SYBL_POS 23U -#define USB3_LLINKERRINJ_TX_ALL_END_FRAME_SYBL_MASK 0x00400000U -#define USB3_LLINKERRINJ_TX_ALL_END_FRAME_SYBL_POS 22U -#define USB3_LLINKERRINJ_TX_ONE_END_FRAME_SYBL_MASK 0x00200000U -#define USB3_LLINKERRINJ_TX_ONE_END_FRAME_SYBL_POS 21U -#define USB3_LLINKERRINJ_TX_ALL_FRAME_SYBL_MASK 0x00100000U -#define USB3_LLINKERRINJ_TX_ALL_FRAME_SYBL_POS 20U -#define USB3_LLINKERRINJ_TX_ONE_FRAME_SYBL_MASK 0x00080000U -#define USB3_LLINKERRINJ_TX_ONE_FRAME_SYBL_POS 19U -#define USB3_LLINKERRINJ_TX_CRC32_MASK 0x00040000U -#define USB3_LLINKERRINJ_TX_CRC32_POS 18U -#define USB3_LLINKERRINJ_TX_CRC16_MASK 0x00020000U -#define USB3_LLINKERRINJ_TX_CRC16_POS 17U -#define USB3_LLINKERRINJ_TX_CRC5_MASK 0x00010000U -#define USB3_LLINKERRINJ_TX_CRC5_POS 16U -#define USB3_LLINKERRINJ_RX_PIPE_RXDATA_MASK 0x00008000U -#define USB3_LLINKERRINJ_RX_PIPE_RXDATA_POS 15U -#define USB3_LLINKERRINJ_RX_INSERT_DEFER_MASK 0x00004000U -#define USB3_LLINKERRINJ_RX_INSERT_DEFER_POS 14U -#define USB3_LLINKERRINJ_RX_INSERT_DELAY_MASK 0x00002000U -#define USB3_LLINKERRINJ_RX_INSERT_DELAY_POS 13U -#define USB3_LLINKERRINJ_RX_TS2_MASK 0x00001000U -#define USB3_LLINKERRINJ_RX_TS2_POS 12U -#define USB3_LLINKERRINJ_RX_TS1_MASK 0x00000800U -#define USB3_LLINKERRINJ_RX_TS1_POS 11U -#define USB3_LLINKERRINJ_RX_TSEQ_MASK 0x00000400U -#define USB3_LLINKERRINJ_RX_TSEQ_POS 10U -#define USB3_LLINKERRINJ_RX_LFR_MASK 0x00000200U -#define USB3_LLINKERRINJ_RX_LFR_POS 9U -#define USB3_LLINKERRINJ_RX_ALL_START_FRAME_SYBL_MASK 0x00000100U -#define USB3_LLINKERRINJ_RX_ALL_START_FRAME_SYBL_POS 8U -#define USB3_LLINKERRINJ_RX_ONE_SRT_FRAME_SYBL_MASK 0x00000080U -#define USB3_LLINKERRINJ_RX_ONE_SRT_FRAME_SYBL_POS 7U -#define USB3_LLINKERRINJ_RX_ALL_END_FRAME_SYBL_MASK 0x00000040U -#define USB3_LLINKERRINJ_RX_ALL_END_FRAME_SYBL_POS 6U -#define USB3_LLINKERRINJ_RX_ONE_END_FRAME_SYBL_MASK 0x00000020U -#define USB3_LLINKERRINJ_RX_ONE_END_FRAME_SYBL_POS 5U -#define USB3_LLINKERRINJ_RX_ALL_FRAME_SYBL_MASK 0x00000010U -#define USB3_LLINKERRINJ_RX_ALL_FRAME_SYBL_POS 4U -#define USB3_LLINKERRINJ_RX_ONE_FRAME_SYBL_MASK 0x00000008U -#define USB3_LLINKERRINJ_RX_ONE_FRAME_SYBL_POS 3U -#define USB3_LLINKERRINJ_RX_CRC32_MASK 0x00000004U -#define USB3_LLINKERRINJ_RX_CRC32_POS 2U -#define USB3_LLINKERRINJ_RX_CRC16_MASK 0x00000002U -#define USB3_LLINKERRINJ_RX_CRC16_POS 1U -#define USB3_LLINKERRINJ_RX_CRC5_MASK 0x00000001U -#define USB3_LLINKERRINJ_RX_CRC5_POS 0U - -/* Bit fields of LLINKERRINJEN register */ -#define USB3_LLINKERRINJEN_DISABLE_INJ_ERR_CNT_MASK 0xFFFF0000U -#define USB3_LLINKERRINJEN_DISABLE_INJ_ERR_CNT_POS 16U -#define USB3_LLINKERRINJEN_B2B_ERR_CNT_MASK 0x0000FFFFU -#define USB3_LLINKERRINJEN_B2B_ERR_CNT_POS 0U - -/* Bit fields of GDBGLTSSM register */ -#define USB3_GDBGLTSSM_RXELECIDLE_MASK 0x40000000U -#define USB3_GDBGLTSSM_RXELECIDLE_POS 30U -#define USB3_GDBGLTSSM_LTDBTIMEOUT_MASK 0x04000000U -#define USB3_GDBGLTSSM_LTDBTIMEOUT_POS 26U -#define USB3_GDBGLTSSM_LTDBLINKSTATE_MASK 0x03C00000U -#define USB3_GDBGLTSSM_LTDBLINKSTATE_POS 22U -#define USB3_GDBGLTSSM_LTDBSUBSTATE_MASK 0x003C0000U -#define USB3_GDBGLTSSM_LTDBSUBSTATE_POS 18U -#define USB3_GDBGLTSSM_ELASTICBUFFERMODE_MASK 0x00020000U -#define USB3_GDBGLTSSM_ELASTICBUFFERMODE_POS 17U -#define USB3_GDBGLTSSM_TXELECLDLE_MASK 0x00010000U -#define USB3_GDBGLTSSM_TXELECLDLE_POS 16U -#define USB3_GDBGLTSSM_RXPOLARITY_MASK 0x00008000U -#define USB3_GDBGLTSSM_RXPOLARITY_POS 15U -#define USB3_GDBGLTSSM_TXDETRXLOOPBACK_MASK 0x00004000U -#define USB3_GDBGLTSSM_TXDETRXLOOPBACK_POS 14U -#define USB3_GDBGLTSSM_LTDBPHYCMDSTATE_MASK 0x00003800U -#define USB3_GDBGLTSSM_LTDBPHYCMDSTATE_POS 11U -#define USB3_GDBGLTSSM_POWERDOWN_MASK 0x00000600U -#define USB3_GDBGLTSSM_POWERDOWN_POS 9U -#define USB3_GDBGLTSSM_RXEQTRAIN_MASK 0x00000100U -#define USB3_GDBGLTSSM_RXEQTRAIN_POS 8U -#define USB3_GDBGLTSSM_TXDEEMPHASIS_MASK 0x000000C0U -#define USB3_GDBGLTSSM_TXDEEMPHASIS_POS 6U -#define USB3_GDBGLTSSM_LTDBCLKSTATE_MASK 0x00000038U -#define USB3_GDBGLTSSM_LTDBCLKSTATE_POS 3U -#define USB3_GDBGLTSSM_TXSWING_MASK 0x00000004U -#define USB3_GDBGLTSSM_TXSWING_POS 2U -#define USB3_GDBGLTSSM_RXTERMINATION_MASK 0x00000002U -#define USB3_GDBGLTSSM_RXTERMINATION_POS 1U -#define USB3_GDBGLTSSM_TXONESZEROS_MASK 0x00000001U -#define USB3_GDBGLTSSM_TXONESZEROS_POS 0U - -/* Bit fields of GDBGLNMCC register */ -#define USB3_GDBGLNMCC_LNMCC_LSERC_MASK 0xFFFF0000U -#define USB3_GDBGLNMCC_LNMCC_LSERC_POS 16U -#define USB3_GDBGLNMCC_LNMCC_BERC_MASK 0x000001FFU -#define USB3_GDBGLNMCC_LNMCC_BERC_POS 0U - -/* Bit fields of LLINKDBGCTRL register */ -#define USB3_LLINKDBGCTRL_RETRY_DP_MASK 0x80000000U -#define USB3_LLINKDBGCTRL_RETRY_DP_POS 31U -#define USB3_LLINKDBGCTRL_TRIGGER_END_STS_MASK 0x40000000U -#define USB3_LLINKDBGCTRL_TRIGGER_END_STS_POS 30U -#define USB3_LLINKDBGCTRL_TRIGGER_START_STS_MASK 0x20000000U -#define USB3_LLINKDBGCTRL_TRIGGER_START_STS_POS 29U -#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_DESCRAMBLED_MASK 0x10000000U -#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_DESCRAMBLED_POS 28U -#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_SCRAMBLED_MASK 0x08000000U -#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_SCRAMBLED_POS 27U -#define USB3_LLINKDBGCTRL_PIPE_TXDETECTRXLB_TRIGGER_MASK 0x04000000U -#define USB3_LLINKDBGCTRL_PIPE_TXDETECTRXLB_TRIGGER_POS 26U -#define USB3_LLINKDBGCTRL_PIPE_RXLECIDLE_TRIGGER_MASK 0x02000000U -#define USB3_LLINKDBGCTRL_PIPE_RXLECIDLE_TRIGGER_POS 25U -#define USB3_LLINKDBGCTRL_PIPE_PHYSTATUS_TRIGGER_MASK 0x01000000U -#define USB3_LLINKDBGCTRL_PIPE_PHYSTATUS_TRIGGER_POS 24U -#define USB3_LLINKDBGCTRL_SUB_STATE_TRIGGER_MASK 0x00F00000U -#define USB3_LLINKDBGCTRL_SUB_STATE_TRIGGER_POS 20U -#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_MASK 0x000F0000U -#define USB3_LLINKDBGCTRL_LINK_STATE_TRIGGER_POS 16U -#define USB3_LLINKDBGCTRL_PERI_RSC_RXFIFO_NUMBER_MASK 0x0000F000U -#define USB3_LLINKDBGCTRL_PERI_RSC_RXFIFO_NUMBER_POS 12U -#define USB3_LLINKDBGCTRL_PERI_RSC_TXFIFO_NUMBER_MASK 0x00000F00U -#define USB3_LLINKDBGCTRL_PERI_RSC_TXFIFO_NUMBER_POS 8U -#define USB3_LLINKDBGCTRL_RXFIFO_NUMBER_MASK 0x000000F0U -#define USB3_LLINKDBGCTRL_RXFIFO_NUMBER_POS 4U -#define USB3_LLINKDBGCTRL_TXFIFO_NUMBER_MASK 0x0000000FU -#define USB3_LLINKDBGCTRL_TXFIFO_NUMBER_POS 0U - -/* Bit fields of LLINKDBGCNTTRIG register */ -#define USB3_LLINKDBGCNTTRIG_STP_CNT_MASK 0xFFFF0000U -#define USB3_LLINKDBGCNTTRIG_STP_CNT_POS 16U -#define USB3_LLINKDBGCNTTRIG_SRT_CNT_MASK 0x0000FFFFU -#define USB3_LLINKDBGCNTTRIG_SRT_CNT_POS 0U - -/* Bit fields of LCSR_TX_DEEMPH register */ -#define USB3_LCSR_TX_DEEMPH_CSR_TX_DEEMPH_FIELD_1_MASK 0x0003FFFFU -#define USB3_LCSR_TX_DEEMPH_CSR_TX_DEEMPH_FIELD_1_POS 0U - -/* Bit fields of LCSR_TX_DEEMPH_1 register */ -#define USB3_LCSR_TX_DEEMPH_1_CSR_TX_DEEMPH_1_FIELD_1_MASK 0x0003FFFFU -#define USB3_LCSR_TX_DEEMPH_1_CSR_TX_DEEMPH_1_FIELD_1_POS 0U - -/* Bit fields of LCSR_TX_DEEMPH_2 register */ -#define USB3_LCSR_TX_DEEMPH_2_CSR_TX_DEEMPH_2_FIELD_1_MASK 0x0003FFFFU -#define USB3_LCSR_TX_DEEMPH_2_CSR_TX_DEEMPH_2_FIELD_1_POS 0U - -/* Bit fields of LCSR_TX_DEEMPH_3 register */ -#define USB3_LCSR_TX_DEEMPH_3_CSR_TX_DEEMPH_3_FIELD_1_MASK 0x0003FFFFU -#define USB3_LCSR_TX_DEEMPH_3_CSR_TX_DEEMPH_3_FIELD_1_POS 0U - -/* Bit fields of LCSRPTMDEBUG1 register */ -#define USB3_LCSRPTMDEBUG1_LDM_T32_MASK 0x3FFE0000U -#define USB3_LCSRPTMDEBUG1_LDM_T32_POS 17U -#define USB3_LCSRPTMDEBUG1_LDM_T1_MASK 0x0001FFFFU -#define USB3_LCSRPTMDEBUG1_LDM_T1_POS 0U - -/* Bit fields of LCSRPTMDEBUG2 register */ -#define USB3_LCSRPTMDEBUG2_LDM_T4_MASK 0x0001FFFFU -#define USB3_LCSRPTMDEBUG2_LDM_T4_POS 0U - -/* Bit fields of LPTMDPDELAY2 register */ -#define USB3_LPTMDPDELAY2_LINK_RX_DELAY_GEN2_MASK 0x000F8000U -#define USB3_LPTMDPDELAY2_LINK_RX_DELAY_GEN2_POS 15U -#define USB3_LPTMDPDELAY2_LINK_TX_DELAY_GEN2_MASK 0x00007C00U -#define USB3_LPTMDPDELAY2_LINK_TX_DELAY_GEN2_POS 10U -#define USB3_LPTMDPDELAY2_LINK_RX_DELAY_GEN1_MASK 0x000003E0U -#define USB3_LPTMDPDELAY2_LINK_RX_DELAY_GEN1_POS 5U -#define USB3_LPTMDPDELAY2_LINK_TX_DELAY_GEN1_MASK 0x0000001FU -#define USB3_LPTMDPDELAY2_LINK_TX_DELAY_GEN1_POS 0U - -/* Bit fields of BU31RHBDBG register */ -#define USB3_BU31RHBDBG_TPCFG_TOUT_CTRL_MASK 0x00000008U -#define USB3_BU31RHBDBG_TPCFG_TOUT_CTRL_POS 3U -#define USB3_BU31RHBDBG_PCAP_MASK 0x00000006U -#define USB3_BU31RHBDBG_PCAP_POS 1U -#define USB3_BU31RHBDBG_OVRCUR_MASK 0x00000001U -#define USB3_BU31RHBDBG_OVRCUR_POS 0U - -/* Bit fields of BRAMHIADDR register */ -#define USB3_BRAMHIADDR_RAM_SELECT_MASK 0x001C0000U -#define USB3_BRAMHIADDR_RAM_SELECT_POS 18U -#define USB3_BRAMHIADDR_RAMHIADDR_MASK 0x0003F000U -#define USB3_BRAMHIADDR_RAMHIADDR_POS 12U - -/* Bit fields of BRSERRCNT register */ -#define USB3_BRSERRCNT_RAM4SERRCNT_MASK 0x3F000000U -#define USB3_BRSERRCNT_RAM4SERRCNT_POS 24U -#define USB3_BRSERRCNT_RAM3SERRCNT_MASK 0x00FC0000U -#define USB3_BRSERRCNT_RAM3SERRCNT_POS 18U -#define USB3_BRSERRCNT_RAM2SERRCNT_MASK 0x0003F000U -#define USB3_BRSERRCNT_RAM2SERRCNT_POS 12U -#define USB3_BRSERRCNT_RAM1SERRCNT_MASK 0x00000FC0U -#define USB3_BRSERRCNT_RAM1SERRCNT_POS 6U -#define USB3_BRSERRCNT_RAM0SERRCNT_MASK 0x0000003FU -#define USB3_BRSERRCNT_RAM0SERRCNT_POS 0U - -/* Bit fields of BRMERRCNT register */ -#define USB3_BRMERRCNT_RAM4MERRCNT_MASK 0x3F000000U -#define USB3_BRMERRCNT_RAM4MERRCNT_POS 24U -#define USB3_BRMERRCNT_RAM3MERRCNT_MASK 0x00FC0000U -#define USB3_BRMERRCNT_RAM3MERRCNT_POS 18U -#define USB3_BRMERRCNT_RAM2MERRCNT_MASK 0x0003F000U -#define USB3_BRMERRCNT_RAM2MERRCNT_POS 12U -#define USB3_BRMERRCNT_RAM1MERRCNT_MASK 0x00000FC0U -#define USB3_BRMERRCNT_RAM1MERRCNT_POS 6U -#define USB3_BRMERRCNT_RAM0MERRCNT_MASK 0x0000003FU -#define USB3_BRMERRCNT_RAM0MERRCNT_POS 0U - -/* Bit fields of BRAMECCERR register */ -#define USB3_BRAMECCERR_RAMSERR_MASK 0x00000800U -#define USB3_BRAMECCERR_RAMSERR_POS 11U -#define USB3_BRAMECCERR_RAMMERR_MASK 0x00000400U -#define USB3_BRAMECCERR_RAMMERR_POS 10U -#define USB3_BRAMECCERR_RAMSERRVEC_MASK 0x000003E0U -#define USB3_BRAMECCERR_RAMSERRVEC_POS 5U -#define USB3_BRAMECCERR_RAMMERRVEC_MASK 0x0000001FU -#define USB3_BRAMECCERR_RAMMERRVEC_POS 0U - -/* Bit fields of BRERRCTL register */ -#define USB3_BRERRCTL_RSERRCLR_MASK 0x00000002U -#define USB3_BRERRCTL_RSERRCLR_POS 1U -#define USB3_BRERRCTL_RMERRCLR_MASK 0x00000001U -#define USB3_BRERRCTL_RMERRCLR_POS 0U - -/* Bit fields of BRAM0ADDRERR register */ -#define USB3_BRAM0ADDRERR_RAM0ERRLOC_MASK 0x0000FFFFU -#define USB3_BRAM0ADDRERR_RAM0ERRLOC_POS 0U - -/* Bit fields of BRAM1ADDRERR register */ -#define USB3_BRAM1ADDRERR_RAM1ERRLOC_MASK 0x0000FFFFU -#define USB3_BRAM1ADDRERR_RAM1ERRLOC_POS 0U - -/* Bit fields of BRAM2ADDRERR register */ -#define USB3_BRAM2ADDRERR_RAM2ERRLOC_MASK 0x0000FFFFU -#define USB3_BRAM2ADDRERR_RAM2ERRLOC_POS 0U - -/* Bit fields of BRAM3ADDRERR register */ -#define USB3_BRAM3ADDRERR_RAM3ERRLOC_MASK 0x0000FFFFU -#define USB3_BRAM3ADDRERR_RAM3ERRLOC_POS 0U - -/* Bit fields of BRAM4ADDRERR register */ -#define USB3_BRAM4ADDRERR_RAM4ERRLOC_MASK 0x0000FFFFU -#define USB3_BRAM4ADDRERR_RAM4ERRLOC_POS 0U - -/* Bit fields of BLOOPBCKCTRL register */ -#define USB3_BLOOPBCKCTRL_LOOPBACK_PRTNUM_MASK 0x000000F0U -#define USB3_BLOOPBCKCTRL_LOOPBACK_PRTNUM_POS 4U -#define USB3_BLOOPBCKCTRL_LOOPBACK_LEVEL_MASK 0x0000000CU -#define USB3_BLOOPBCKCTRL_LOOPBACK_LEVEL_POS 2U -#define USB3_BLOOPBCKCTRL_LOOPBACK_MODE_MASK 0x00000002U -#define USB3_BLOOPBCKCTRL_LOOPBACK_MODE_POS 1U -#define USB3_BLOOPBCKCTRL_LOOPBACK_MODE_EN_MASK 0x00000001U -#define USB3_BLOOPBCKCTRL_LOOPBACK_MODE_EN_POS 0U - -/* Bit fields of BLOOPBCKTFERSZ register */ -#define USB3_BLOOPBCKTFERSZ_LOOPBACK_XFER_SZ_MASK 0x00FFFFFFU -#define USB3_BLOOPBCKTFERSZ_LOOPBACK_XFER_SZ_POS 0U - -/* Bit fields of BBISTDATAPATSEED register */ -#define USB3_BBISTDATAPATSEED_BIST_PATTERN_SEED_MASK 0xFFFFFFFFU -#define USB3_BBISTDATAPATSEED_BIST_PATTERN_SEED_POS 0U - -/* Bit fields of BBISTCTRL register */ -#define USB3_BBISTCTRL_START_BIST_TEST_MASK 0x80000000U -#define USB3_BBISTCTRL_START_BIST_TEST_POS 31U -#define USB3_BBISTCTRL_BIST_TEST_TYPE_MASK 0x40000000U -#define USB3_BBISTCTRL_BIST_TEST_TYPE_POS 30U -#define USB3_BBISTCTRL_FAIL_MASK 0x20000000U -#define USB3_BBISTCTRL_FAIL_POS 29U -#define USB3_BBISTCTRL_BIST_PATTERN_MASK 0x07000000U -#define USB3_BBISTCTRL_BIST_PATTERN_POS 24U -#define USB3_BBISTCTRL_BIST_ITERATION_CNT_MASK 0x00FFFFFFU -#define USB3_BBISTCTRL_BIST_ITERATION_CNT_POS 0U - -/* Bit fields of BBISTXFERSTS0 register */ -#define USB3_BBISTXFERSTS0_BIST_PENDING_TRANS_SIZE_MASK 0x00FFFFFFU -#define USB3_BBISTXFERSTS0_BIST_PENDING_TRANS_SIZE_POS 0U - -/* Bit fields of BBISTXFERSTS1 register */ -#define USB3_BBISTXFERSTS1_FAILED_PENDING_TRANS_SIZE_MASK 0x00FFFFFFU -#define USB3_BBISTXFERSTS1_FAILED_PENDING_TRANS_SIZE_POS 0U - -/* Bit fields of BBISTXFERSTS2 register */ -#define USB3_BBISTXFERSTS2_FAILED_ITERATION_MASK 0x00FFFFFFU -#define USB3_BBISTXFERSTS2_FAILED_ITERATION_POS 0U - -/* Bit fields of BBISTXFERSTS3 register */ -#define USB3_BBISTXFERSTS3_LOOPBACK_STATEMACHINE_MASK 0x0000000FU -#define USB3_BBISTXFERSTS3_LOOPBACK_STATEMACHINE_POS 0U - -/* Bit fields of BBISTEXPDATASTS0 register */ -#define USB3_BBISTEXPDATASTS0_EXP_DATA_MASK 0xFFFFFFFFU -#define USB3_BBISTEXPDATASTS0_EXP_DATA_POS 0U - -/* Bit fields of BBISTEXPDATASTS1 register */ -#define USB3_BBISTEXPDATASTS1_EXP_DATA_MASK 0xFFFFFFFFU -#define USB3_BBISTEXPDATASTS1_EXP_DATA_POS 0U - -/* Bit fields of BBISTEXPDATASTS2 register */ -#define USB3_BBISTEXPDATASTS2_EXP_DATA_MASK 0xFFFFFFFFU -#define USB3_BBISTEXPDATASTS2_EXP_DATA_POS 0U - -/* Bit fields of BBISTEXPDATASTS3 register */ -#define USB3_BBISTEXPDATASTS3_EXP_DATA_MASK 0xFFFFFFFFU -#define USB3_BBISTEXPDATASTS3_EXP_DATA_POS 0U - -/* Bit fields of BBISTRCVDDATASTS0 register */ -#define USB3_BBISTRCVDDATASTS0_RECEIVED_DATA_MASK 0xFFFFFFFFU -#define USB3_BBISTRCVDDATASTS0_RECEIVED_DATA_POS 0U - -/* Bit fields of BBISTRCVDDATASTS1 register */ -#define USB3_BBISTRCVDDATASTS1_RECEIVED_DATA_MASK 0xFFFFFFFFU -#define USB3_BBISTRCVDDATASTS1_RECEIVED_DATA_POS 0U - -/* Bit fields of BBISTRCVDDATASTS2 register */ -#define USB3_BBISTRCVDDATASTS2_RECEIVED_DATA_MASK 0xFFFFFFFFU -#define USB3_BBISTRCVDDATASTS2_RECEIVED_DATA_POS 0U - -/* Bit fields of BBISTRCVDDATASTS3 register */ -#define USB3_BBISTRCVDDATASTS3_RECEIVED_DATA_MASK 0xFFFFFFFFU -#define USB3_BBISTRCVDDATASTS3_RECEIVED_DATA_POS 0U - -/* Bit fields of rsvd_reg register */ -#define USB3_RSVD_REG_RSVD_FIELD_MASK 0xFFFFFFFFU -#define USB3_RSVD_REG_RSVD_FIELD_POS 0U - -#endif diff --git a/src/portable/xhci/xhci_context.h b/src/portable/xhci/xhci_context.h index 2973c78a1..2481138ae 100644 --- a/src/portable/xhci/xhci_context.h +++ b/src/portable/xhci/xhci_context.h @@ -9,7 +9,7 @@ #ifndef __XCHI_CONTEXT_H__ #define __XCHI_CONTEXT_H__ -#include "socfpga_usb3_reg.h" +#include "xhci_type.h" #include "socfpga_defines.h" /* MASK and POS for Input control context */ diff --git a/src/portable/xhci/xhci_interrupts.c b/src/portable/xhci/xhci_interrupts.c index 62af71b45..8118d0b5e 100644 --- a/src/portable/xhci/xhci_interrupts.c +++ b/src/portable/xhci/xhci_interrupts.c @@ -10,7 +10,6 @@ #include "xhci.h" #include "xhci_interrupts.h" #include "socfpga_interrupt.h" -#include "socfpga_usb3_reg.h" #include "socfpga_interrupt_priority.h" #include "osal_log.h" diff --git a/src/portable/xhci/xhci_type.h b/src/portable/xhci/xhci_type.h index 6446cab74..14e21faa7 100644 --- a/src/portable/xhci/xhci_type.h +++ b/src/portable/xhci/xhci_type.h @@ -18,6 +18,28 @@ extern "C" { #endif + +/* xHCI register macros moved from socfpga_usb3_reg.h. */ +#define USBBASE (0x11000000U) +#define USB3_CAPLENGTH_CAPLENGTH_MASK 0x000000FFU +#define USB3_HCSPARAMS1_MAXSLOTS_MASK 0x000000FFU +#define USB3_HCSPARAMS1_MAXSLOTS_POS 0U +#define USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK 0xFFFFFFFCU +#define USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK 0xFFFFFFE0U +#define USB3_CRCR_LO_CMD_RING_PNTR_MASK 0xFFFFFFC0U +#define USB3_CONFIG_MAXSLOTSEN_MASK 0x000000FFU +#define USB3_PORTSC_20_PRC_MASK 0x00200000U +#define USB3_PORTSC_20_CSC_MASK 0x00020000U +#define USB3_PORTSC_20_PORTSPEED_MASK 0x00003C00U +#define USB3_PORTSC_20_PORTSPEED_POS 10U +#define USB3_PORTSC_20_PR_MASK 0x00000010U +#define USB3_PORTSC_20_CCS_MASK 0x00000001U +#define USB3_PORTSC_30_WPR_MASK 0x80000000U +#define USB3_PORTSC_30_WRC_MASK 0x00080000U +#define USB3_ERSTSZ_ERS_TABLE_SIZE_MASK 0x0000FFFFU +#define USB3_ERDP_LO_ERD_PNTR_MASK 0xFFFFFFF0U +#define USB3_DB_DB_TARGET_POS 0U + /* Bit fields of CAPLENGTH register. */ typedef union { uint32_t value; From 50b3860965b261700f6a8ee849f270b5efd7811a Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Fri, 20 Nov 2026 15:18:11 +0530 Subject: [PATCH 11/17] src: portable: xhci: replace logs with tinyusb log macros * Replace board specific log macros and cache APIs with tinyusb apis Signed-off-by: Sourav Raj K K --- apps/msc_app.c | 2 +- apps/tusb_config.h | 4 +- src/portable/synopsys/dwc3/dwc3_socfpga.h | 81 +++++++++++++++++++ src/portable/synopsys/dwc3/hcd_dwc3.c | 14 ++++ src/portable/xhci/xhci.c | 45 ++++++----- src/portable/xhci/xhci_cap.c | 24 +++--- src/portable/xhci/xhci_commands.c | 30 +++---- src/portable/xhci/xhci_common.c | 16 ++-- src/portable/xhci/xhci_context.c | 96 +++++++++++------------ src/portable/xhci/xhci_context.h | 2 +- src/portable/xhci/xhci_endpoints.c | 20 ++--- src/portable/xhci/xhci_events.c | 25 +++--- src/portable/xhci/xhci_interrupts.c | 6 +- src/portable/xhci/xhci_rings.c | 12 +-- 14 files changed, 240 insertions(+), 137 deletions(-) diff --git a/apps/msc_app.c b/apps/msc_app.c index 278d46a2f..082965030 100644 --- a/apps/msc_app.c +++ b/apps/msc_app.c @@ -83,7 +83,7 @@ bool msc_inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * c void tuh_msc_mount_cb(uint8_t dev_addr) { - PRINT("A MassStorage device mounted"); + PRINT("\r\nA MassStorage device mounted"); uint8_t const lun = 0; tuh_msc_inquiry(dev_addr, lun, &inquiry_resp, msc_inquiry_complete_cb, 0); diff --git a/apps/tusb_config.h b/apps/tusb_config.h index 0b7130d73..c957faaa3 100644 --- a/apps/tusb_config.h +++ b/apps/tusb_config.h @@ -51,9 +51,11 @@ #endif #ifndef CFG_TUSB_DEBUG -#define CFG_TUSB_DEBUG 0 +#define CFG_TUSB_DEBUG 1 #endif +#define CFG_TUH_LOG_LEVEL 2 + /* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. * Tinyusb use follows macros to declare transferring memory so that they can be put * into those specific section. diff --git a/src/portable/synopsys/dwc3/dwc3_socfpga.h b/src/portable/synopsys/dwc3/dwc3_socfpga.h index 2c7371fb8..7653912a1 100644 --- a/src/portable/synopsys/dwc3/dwc3_socfpga.h +++ b/src/portable/synopsys/dwc3/dwc3_socfpga.h @@ -27,6 +27,8 @@ #ifndef DWC3_SOCFPGA_H_ #define DWC3_SOCFPGA_H_ +#include + #ifdef __cplusplus extern "C" { #endif @@ -37,6 +39,7 @@ extern "C" { #include "socfpga_interrupt.h" #include "socfpga_interrupt_priority.h" #include "socfpga_rst_mngr.h" + #include "socfpga_cache.h" #else #error "Unsupported MCUs" #endif @@ -47,6 +50,84 @@ static const dwc3_controller_t _dwc3_controller[] = { { .reg_base = SOCFPGA_USB3_REG_BASE, .irqnum = OTG_HS_IRQn, }, }; +//------------- DCache -------------// +#if CFG_TUH_MEM_DCACHE_ENABLE + +TU_ATTR_ALWAYS_INLINE static inline bool dwc3_dcache_aligned_range(void const* addr, uint32_t data_size, + uint32_t** aligned_addr, int32_t* aligned_size) { + const uintptr_t line_size = CFG_TUSB_MEM_DCACHE_LINE_SIZE_DEFAULT; + const uintptr_t line_mask = line_size - 1U; + const uintptr_t start = (uintptr_t) addr; + + if ((line_size == 0U) || ((line_size & line_mask) != 0U) || + (addr == NULL) || (data_size == 0U) || (start > UINTPTR_MAX - data_size)) { + return false; + } + + const uintptr_t aligned_start = start & ~line_mask; + const uintptr_t end = start + data_size; + if (end > UINTPTR_MAX - line_mask) { + return false; + } + + const uintptr_t aligned_end = (end + line_mask) & ~line_mask; + const uintptr_t range_size = aligned_end - aligned_start; + if (range_size > INT32_MAX) { + return false; + } + + *aligned_addr = (uint32_t*) aligned_start; + *aligned_size = (int32_t) range_size; + return true; +} + +TU_ATTR_ALWAYS_INLINE static inline bool dwc3_dcache_clean(void const* addr, uint32_t data_size) { + if (data_size == 0U) { + return true; + } + + uint32_t* aligned_addr; + int32_t aligned_size; + if (!dwc3_dcache_aligned_range(addr, data_size, &aligned_addr, &aligned_size)) { + return false; + } + + cache_force_write_back(aligned_addr, aligned_size); + return true; +} + +TU_ATTR_ALWAYS_INLINE static inline bool dwc3_dcache_invalidate(void const* addr, uint32_t data_size) { + if (data_size == 0U) { + return true; + } + + uint32_t* aligned_addr; + int32_t aligned_size; + if (!dwc3_dcache_aligned_range(addr, data_size, &aligned_addr, &aligned_size)) { + return false; + } + + cache_force_invalidate(aligned_addr, aligned_size); + return true; +} + +TU_ATTR_ALWAYS_INLINE static inline bool dwc3_dcache_clean_invalidate(void const* addr, uint32_t data_size) { + if (data_size == 0U) { + return true; + } + + uint32_t* aligned_addr; + int32_t aligned_size; + if (!dwc3_dcache_aligned_range(addr, data_size, &aligned_addr, &aligned_size)) { + return false; + } + + cache_force_write_back(aligned_addr, aligned_size); + cache_force_invalidate(aligned_addr, aligned_size); + return true; +} +#endif + //--------------------------------------------------------------------+ // Controller bring-up //--------------------------------------------------------------------+ diff --git a/src/portable/synopsys/dwc3/hcd_dwc3.c b/src/portable/synopsys/dwc3/hcd_dwc3.c index 3e9887db6..b13b044f7 100644 --- a/src/portable/synopsys/dwc3/hcd_dwc3.c +++ b/src/portable/synopsys/dwc3/hcd_dwc3.c @@ -33,6 +33,20 @@ #include "dwc3_common.h" #include "xhci_api.h" +#if CFG_TUH_MEM_DCACHE_ENABLE +bool hcd_dcache_clean(void const* addr, uint32_t data_size) { + return dwc3_dcache_clean(addr, data_size); +} + +bool hcd_dcache_invalidate(void const* addr, uint32_t data_size) { + return dwc3_dcache_invalidate(addr, data_size); +} + +bool hcd_dcache_clean_invalidate(void const* addr, uint32_t data_size) { + return dwc3_dcache_clean_invalidate(addr, data_size); +} +#endif + //--------------------------------------------------------------------+ // Controller API //--------------------------------------------------------------------+ diff --git a/src/portable/xhci/xhci.c b/src/portable/xhci/xhci.c index 5250f21a7..5f4dcfbd8 100644 --- a/src/portable/xhci/xhci.c +++ b/src/portable/xhci/xhci.c @@ -53,7 +53,6 @@ #include "xhci_endpoints.h" #include "xhci_interrupts.h" #include "xhci_doorbell.h" - #include "socfpga_cache.h" #endif typedef struct @@ -142,7 +141,7 @@ static int configure_xhci_max_slots(void) (xhci->hcsparams1.value & USB3_HCSPARAMS1_MAXSLOTS_MASK) >> USB3_HCSPARAMS1_MAXSLOTS_POS; - DEBUG("MaxSlots is : %x", max_slots); + TU_LOG2("MaxSlots is : %x", max_slots); xhci->config.value = (xhci->config.value & ~USB3_CONFIG_MAXSLOTSEN_MASK) | @@ -188,7 +187,7 @@ static int wait_for_controller_ready(void) if(loop > 0) { - INFO("xHCI Controller Ready"); + TU_LOG3("xHCI Controller Ready"); return 0; } @@ -204,7 +203,7 @@ int xhci_reset(void) /* Reset the Host Controller */ xhci->usbcmd.hcrst = 1U; - INFO("Initiating Controller Reset"); + TU_LOG3("Initiating Controller Reset"); do { if (xhci->usbcmd.hcrst == 0U) @@ -219,11 +218,11 @@ int xhci_reset(void) if (err_flag == 0U) { - INFO("Timeout Occurred"); + TU_LOG3("Timeout Occurred"); return -ETIMEDOUT; } - INFO("xHCI controller reset successful"); + TU_LOG3("xHCI controller reset successful"); return 0; } @@ -510,6 +509,18 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t daddr, uint8_t ep_addr, uint8_t * buf ep_data[ep_dci].buffer = buffer; ep_data[ep_dci].buflen = buflen; + if( buflen != 0 ) + { + if( dir == TUSB_DIR_IN ) + { + (void) hcd_dcache_invalidate(buffer, buflen); + } + else + { + (void) hcd_dcache_clean(buffer, buflen); + } + } + if( ep_num == 0 ) { configure_setup_stage(&xhci_handle, buffer, (usb_control_request_t *)&ctrl_req); @@ -517,10 +528,6 @@ bool hcd_edpt_xfer(uint8_t rhport, uint8_t daddr, uint8_t ep_addr, uint8_t * buf } else { - if( dir == TUSB_DIR_OUT ) - { - cache_force_write_back(buffer, buflen); - } endpoint_transfer(&xhci_handle, (int) ep_num, (uint8_t) dir, buffer, buflen); } @@ -542,15 +549,13 @@ static void handle_endpoint_transfer(uint8_t ep_dci, uint8_t ep_addr) uint32_t buflen = ep_data[ep_dci].buflen; const unsigned dir = (uint32_t) tu_edpt_dir(ep_addr); const uint8_t ep_num = tu_edpt_number(ep_addr); + const bool data_in = (ep_num == 0) ? + ((ctrl_req.bmRequestType & TUSB_DIR_IN_MASK) != 0U) : + (dir == TUSB_DIR_IN); - if(ep_num == 0 && buflen != 0) - { - cache_force_invalidate(buffer, buflen); - } - - if( dir == TUSB_DIR_IN ) + if( buflen != 0 && data_in ) { - cache_force_invalidate(buffer, buflen); + (void) hcd_dcache_invalidate(buffer, buflen); } } @@ -685,7 +690,7 @@ bool hcd_parse_full_conf_descriptor(tusb_desc_configuration_t *desc_cfg, uint8_t usb_endpoint_descriptor_t xhci_ep_desc; - DEBUG("Parsing Complete Configuration Descriptors"); + TU_LOG2("Parsing Complete Configuration Descriptors"); while (p_desc < desc_end) { @@ -697,8 +702,8 @@ bool hcd_parse_full_conf_descriptor(tusb_desc_configuration_t *desc_cfg, uint8_t /* Check if the device belongs to MSC */ if (desc_itf->bInterfaceClass != 8) { - PRINT("Device does not support MSC"); - PRINT("Enumeration process completed"); + TU_LOG1("Device does not support MSC"); + TU_LOG1("Enumeration process completed"); return false; } diff --git a/src/portable/xhci/xhci_cap.c b/src/portable/xhci/xhci_cap.c index 8d68ffa6c..7769b59d9 100644 --- a/src/portable/xhci/xhci_cap.c +++ b/src/portable/xhci/xhci_cap.c @@ -11,7 +11,7 @@ #include #include #include "xhci.h" -#include "osal_log.h" +#include "host/hcd.h" /* * @brief read the host controller capability registers @@ -23,23 +23,23 @@ int get_xhc_cap_params(struct xhci_data *xhci) xhci->xhc_cap_ptr = (xhci_cap_reg_t *)USBBASE; - DEBUG("CAPLENGTH : %x", + TU_LOG2("CAPLENGTH : %x", (regs->caplength.value & USB3_CAPLENGTH_CAPLENGTH_MASK)); - DEBUG("HCSPARAMS1 : %x", + TU_LOG2("HCSPARAMS1 : %x", regs->hcsparams1.value); - DEBUG("HCSPARAMS2 : %x", + TU_LOG2("HCSPARAMS2 : %x", regs->hcsparams2.value); - DEBUG("HCSPARAMS3 : %x", + TU_LOG2("HCSPARAMS3 : %x", regs->hcsparams3.value); - DEBUG("HCCPARAMS1 : %x", + TU_LOG2("HCCPARAMS1 : %x", regs->hccparams1.value); - DEBUG("DBOFF : %x", + TU_LOG2("DBOFF : %x", (regs->dboff.value & USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK)); - DEBUG("RTOFF : %x", + TU_LOG2("RTOFF : %x", (regs->rtsoff.value & USB3_RTSOFF_RUNTIME_REG_SPACE_OFFSET_MASK)); - DEBUG("HCCPARAMS2 : %x", + TU_LOG2("HCCPARAMS2 : %x", regs->hccparams2.value); xhci->op_regs.xhci_op_base = (uint64_t)USBBASE + @@ -52,11 +52,11 @@ int get_xhc_cap_params(struct xhci_data *xhci) (uint64_t)(regs->dboff.value & USB3_DBOFF_DOORBELL_ARRAY_OFFSET_MASK); - DEBUG("Operational base : %lx ", + TU_LOG2("Operational base : %lx ", xhci->op_regs.xhci_op_base); - DEBUG("Runtime base : %lx ", + TU_LOG2("Runtime base : %lx ", xhci->op_regs.xhci_runtime_base); - DEBUG("Doorbell base : %lx ", + TU_LOG2("Doorbell base : %lx ", xhci->op_regs.xhci_db_base); return 0; diff --git a/src/portable/xhci/xhci_commands.c b/src/portable/xhci/xhci_commands.c index 7ac479899..5469ded9b 100644 --- a/src/portable/xhci/xhci_commands.c +++ b/src/portable/xhci/xhci_commands.c @@ -9,7 +9,7 @@ #include "xhci_commands.h" #include "xhci_doorbell.h" -#include "socfpga_cache.h" +#include "host/hcd.h" #include "osal_log.h" xhci_trb_t *get_cmdring_enq_ptr(xcr_command_ring_t *cmd_ring) @@ -59,8 +59,8 @@ void set_device_address(struct xhci_data *xhci_ptr) cmd_ctrl_flags |= xhci_ptr->xcr_ring->xcr_ccs_flag; enq_ptr->control = cmd_ctrl_flags; - cache_force_write_back((void *) xhci_ptr->xcr_ring->xcr_enqueue_ptr, - (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + hcd_dcache_clean(xhci_ptr->xcr_ring->xcr_enqueue_ptr, + (uint32_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); ring_xhci_host_db(); } @@ -97,8 +97,8 @@ void enable_slot_command(xcr_command_ring_t *xcr_ring) enq_ptr->control = cmd_ctrl_flags; - cache_force_write_back((void *) xcr_ring->xcr_enqueue_ptr, - (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + hcd_dcache_clean(xcr_ring->xcr_enqueue_ptr, + (uint32_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); /* call doorbell register */ ring_xhci_host_db(); @@ -121,8 +121,8 @@ void disable_slot_command(xcr_command_ring_t *xcr_ring, uint32_t slotid) enq_ptr->control = cmd_ctrl_flags; - cache_force_write_back((void *) xcr_ring->xcr_enqueue_ptr, - (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + hcd_dcache_clean(xcr_ring->xcr_enqueue_ptr, + (uint32_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); /* call doorbell register */ ring_xhci_host_db(); @@ -149,8 +149,8 @@ void configure_endpoint(struct xhci_data *xhci_ptr) enq_ptr->control = cmd_ctrl_flags; - cache_force_write_back((void *) xhci_ptr->xcr_ring->xcr_enqueue_ptr, - XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + hcd_dcache_clean(xhci_ptr->xcr_ring->xcr_enqueue_ptr, + (uint32_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); ring_xhci_host_db(); } @@ -178,8 +178,8 @@ static void stop_endpoint_command(xcr_command_ring_t *xcr_ring) enq_ptr->control = cmd_ctrl_flags; - cache_force_write_back((void *) xcr_ring->xcr_enqueue_ptr, - (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + hcd_dcache_clean(xcr_ring->xcr_enqueue_ptr, + (uint32_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); ring_xhci_host_db(); } @@ -211,8 +211,8 @@ void update_ep_transfer_ring(xcr_command_ring_t *xcr_ring, xhci_trb_t *xtr_ring) enq_ptr->control = cmd_ctrl_flags; - cache_force_write_back((void *) xcr_ring->xcr_enqueue_ptr, - (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + hcd_dcache_clean(xcr_ring->xcr_enqueue_ptr, + (uint32_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); ring_xhci_host_db(); } @@ -238,8 +238,8 @@ void evaluate_endpoint(struct xhci_data *xhci_ptr) cmd_ctrl_flags |= xhci_ptr->xcr_ring->xcr_ccs_flag; enq_ptr->control = cmd_ctrl_flags; - cache_force_write_back((void *) xhci_ptr->xcr_ring->xcr_enqueue_ptr, - (size_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); + hcd_dcache_clean(xhci_ptr->xcr_ring->xcr_enqueue_ptr, + (uint32_t) XHCI_CR_TRB_LEN * sizeof(xhci_trb_t)); ring_xhci_host_db(); } diff --git a/src/portable/xhci/xhci_common.c b/src/portable/xhci/xhci_common.c index 2e5496659..4c7b27faa 100644 --- a/src/portable/xhci/xhci_common.c +++ b/src/portable/xhci/xhci_common.c @@ -10,11 +10,10 @@ #include #include #include "tusb_config.h" -#include "osal_log.h" -#include "osal.h" #include "xhci_commands.h" #include "xhci_events.h" #include "xhci_common.h" +#include "host/hcd.h" #define XHCI_SPEED_SS (4) #define XHCI_QUEUE_SZ (10U) @@ -34,7 +33,7 @@ int init_hcd_params( void ) xhci_queue = osal_queue_create(&xhci_event_params); if ( xhci_queue == NULL ) { - ERROR("Error in creating queue !!!"); + TU_LOG1("Error in creating queue !!!"); return -ENOMEM; } return 0; @@ -47,10 +46,10 @@ int wait_for_command_completion_event( struct xhci_data *xhci_ptr, int type ) { if ( osal_queue_receive(xhci_queue, &event, UINT32_MAX) == pdTRUE ) { - DEBUG("CC event values are"); - DEBUG("pointer : %lx", event.cmd_trb_ptr); - DEBUG("Status field : %x", event.status_field); - DEBUG("Control fields : %x", event.control_field); + TU_LOG2("CC event values are"); + TU_LOG2("pointer : %lx", event.cmd_trb_ptr); + TU_LOG2("Status field : %x", event.status_field); + TU_LOG2("Control fields : %x", event.control_field); break; } } @@ -79,5 +78,6 @@ int wait_for_command_completion_event( struct xhci_data *xhci_ptr, int type ) void xhci_command_event_complete( xcc_event_t event ) { - (void) osal_queue_send(xhci_queue, &event); + // isr flag is 0 + (void) osal_queue_send(xhci_queue, &event, 1); } diff --git a/src/portable/xhci/xhci_context.c b/src/portable/xhci/xhci_context.c index 6920ee94d..03d76be7b 100644 --- a/src/portable/xhci/xhci_context.c +++ b/src/portable/xhci/xhci_context.c @@ -43,12 +43,12 @@ * +------------------+ +---------------+ */ +#include #include "xhci.h" -#include "socfpga_cache.h" #include "xhci_endpoints.h" #include "xhci_context.h" #include "xhci_events.h" -#include "osal_log.h" +#include "host/hcd.h" int alloc_xhci_contexts(struct xhci_data *xhci_ptr) { @@ -56,19 +56,19 @@ int alloc_xhci_contexts(struct xhci_data *xhci_ptr) xhci_ptr->xcr_ring = alloc_command_ring(); if (xhci_ptr->xcr_ring == NULL) { - ERROR("Cannot allocate memory!!!"); + TU_LOG1("Cannot allocate memory!!!"); ret = -ENOMEM; } if (alloc_input_device_context(xhci_ptr) != 0) { - ERROR("Cannot allocate memory!!!"); + TU_LOG1("Cannot allocate memory!!!"); ret = -ENOMEM; } if (alloc_output_device_context(xhci_ptr) != 0) { - ERROR("Cannot allocate memory!!!"); + TU_LOG1("Cannot allocate memory!!!"); ret = -ENOMEM; } @@ -87,7 +87,7 @@ int alloc_xhci_contexts(struct xhci_data *xhci_ptr) vPortFree((void *)xhci_ptr->op_ctx); } } - INFO("xHCI contexts allocated successfully"); + TU_LOG3("xHCI contexts allocated successfully"); return ret; } @@ -120,7 +120,7 @@ void deallocate_xhci_context(struct xhci_data *xhci_ptr) xhci_ptr->dev_data.slot_id = 0U; xhci_ptr->dev_data.rh_port = 0U; - INFO("xHCI contexts deallocated successfully"); + TU_LOG3("xHCI contexts deallocated successfully"); } int init_xhci_context_params(struct xhci_data *xhci_ptr) @@ -158,7 +158,7 @@ int alloc_input_device_context(struct xhci_data *xhci_ptr) sizeof(xhci_ip_device_context_t)); if (xhci_ptr->ip_ctx == NULL) { - ERROR("Cannot allocate memory!!!"); + TU_LOG1("Cannot allocate memory!!!"); return -ENOMEM; } @@ -198,24 +198,24 @@ int init_input_device_context(struct xhci_data *xhci_ptr) switch (dev_speed) { case 4: - PRINT("xHCI - SS device attached"); + TU_LOG1("xHCI - SS device attached"); ep0_max_pkt_size = EP0_MAX_PKT_SIZE_SS; break; case 3: - PRINT("xHCI - HS device attached"); + TU_LOG1("xHCI - HS device attached"); ep0_max_pkt_size = EP0_MAX_PKT_SIZE_HS; break; case 2: - PRINT("xHCI - LS device attached"); + TU_LOG1("xHCI - LS device attached"); ep0_max_pkt_size = EP0_MAX_PKT_SIZE_FS; break; case 1: - PRINT("xHCI - FS device attached"); + TU_LOG1("xHCI - FS device attached"); ep0_max_pkt_size = EP0_MAX_PKT_SIZE_LS; break; default: /* resource unavalable, try again */ - PRINT("XHCI - Device enumeration failed"); + TU_LOG1("XHCI - Device enumeration failed"); ret = -EAGAIN; break; } @@ -247,7 +247,7 @@ int init_input_device_context(struct xhci_data *xhci_ptr) EP_TRB_SEG_LENGTH); if (xep0_tr_ptr == NULL) { - ERROR("Cannot allocate memory!!!"); + TU_LOG1("Cannot allocate memory!!!"); return -ENOMEM; } @@ -276,7 +276,7 @@ int alloc_output_device_context(struct xhci_data *xhci_ptr) sizeof(xhci_op_device_context_t)); if (xhci_ptr->op_ctx == NULL) { - ERROR("Canot allocate memory!!!"); + TU_LOG1("Canot allocate memory!!!"); return -ENOMEM; } @@ -345,7 +345,7 @@ int alloc_dcbaa(struct xhci_data *xhci_ptr) xhci->dcbaap_lo.value = (uint32_t) dcbaa; xhci->dcbaap_hi.value = (uint32_t) (dcbaa >> 32); - DEBUG("xHCI DCBAA register updated"); + TU_LOG2("xHCI DCBAA register updated"); return 0; } @@ -379,12 +379,12 @@ void display_xhci_device_params(struct xhci_device_data *dev_data) { char const *dev_speed[] = {"Null", "Low Speed", "Full Speed", "High Speed"}; - DEBUG("Device address : %d", dev_data->dev_addr); - DEBUG("Device Slot: %d", dev_data->slot_id); - DEBUG("Device rh port: %d", dev_data->rh_port); - DEBUG("Device speed : %s", dev_speed[dev_data->dev_speed]); + TU_LOG2("Device address : %d", dev_data->dev_addr); + TU_LOG2("Device Slot: %d", dev_data->slot_id); + TU_LOG2("Device rh port: %d", dev_data->rh_port); + TU_LOG2("Device speed : %s", dev_speed[dev_data->dev_speed]); - /* Suppressing unused variable warning when not using DEBUG logs. */ + /* Suppressing unused variable warning when not using TU_LOG2 logs. */ (void)dev_data; (void)dev_speed; } @@ -431,41 +431,41 @@ void update_endpoint_packetsize(xhci_ip_device_context_t *ip_ctx, void display_ip_context(xhci_ip_device_context_t *ip_ctx) { - DEBUG(" Input control Contexts "); - DEBUG(" Field 1 : %lx", ip_ctx->xi_context.xic_context_flags); + TU_LOG2(" Input control Contexts "); + TU_LOG2(" Field 1 : %lx", ip_ctx->xi_context.xic_context_flags); - DEBUG(" Slot Contexts "); - DEBUG(" Field 1 : %lx", ip_ctx->xs_context.xsc_info1); - DEBUG(" Field 2 : %lx", ip_ctx->xs_context.xsc_info2); + TU_LOG2(" Slot Contexts "); + TU_LOG2(" Field 1 : %lx", ip_ctx->xs_context.xsc_info1); + TU_LOG2(" Field 2 : %lx", ip_ctx->xs_context.xsc_info2); - DEBUG(" Endpoint 0 Contexts "); - DEBUG(" Field 1 : %lx", ip_ctx->xe_context[0].xec_info); - DEBUG(" Field 2 : %lx", ip_ctx->xe_context[0].xec_dequeue); - DEBUG(" Field 3 : %lx", ip_ctx->xe_context[0].xec_info2); + TU_LOG2(" Endpoint 0 Contexts "); + TU_LOG2(" Field 1 : %lx", ip_ctx->xe_context[0].xec_info); + TU_LOG2(" Field 2 : %lx", ip_ctx->xe_context[0].xec_dequeue); + TU_LOG2(" Field 3 : %lx", ip_ctx->xe_context[0].xec_info2); (void)ip_ctx; } void display_op_context(xhci_op_device_context_t *op_ctx) { - DEBUG(" Slot Contexts "); - DEBUG(" Field 1 : %lx", op_ctx->slot_context.xsc_info1); - DEBUG(" Field 2 : %lx", op_ctx->slot_context.xsc_info2); - - DEBUG(" Endpoint 0 Contexts "); - DEBUG(" Field 1 : %lx", op_ctx->EP_0.xec_info); - DEBUG(" Field 2 : %lx", op_ctx->EP_0.xec_dequeue); - DEBUG(" Field 3 : %lx", op_ctx->EP_0.xec_info2); - - DEBUG(" Endpoint 1 OUT Contexts "); - DEBUG(" Field 1 : %lx", op_ctx->EP[0].xec_info); - DEBUG(" Field 2 : %lx", op_ctx->EP[0].xec_dequeue); - DEBUG(" Field 3 : %lx", op_ctx->EP[0].xec_info2); - - DEBUG(" Endpoint 2 IN Contexts "); - DEBUG(" Field 1 : %lx", op_ctx->EP[3].xec_info); - DEBUG(" Field 2 : %lx", op_ctx->EP[3].xec_dequeue); - DEBUG(" Field 3 : %lx \r\n", op_ctx->EP[3].xec_info2); + TU_LOG2(" Slot Contexts "); + TU_LOG2(" Field 1 : %lx", op_ctx->slot_context.xsc_info1); + TU_LOG2(" Field 2 : %lx", op_ctx->slot_context.xsc_info2); + + TU_LOG2(" Endpoint 0 Contexts "); + TU_LOG2(" Field 1 : %lx", op_ctx->EP_0.xec_info); + TU_LOG2(" Field 2 : %lx", op_ctx->EP_0.xec_dequeue); + TU_LOG2(" Field 3 : %lx", op_ctx->EP_0.xec_info2); + + TU_LOG2(" Endpoint 1 OUT Contexts "); + TU_LOG2(" Field 1 : %lx", op_ctx->EP[0].xec_info); + TU_LOG2(" Field 2 : %lx", op_ctx->EP[0].xec_dequeue); + TU_LOG2(" Field 3 : %lx", op_ctx->EP[0].xec_info2); + + TU_LOG2(" Endpoint 2 IN Contexts "); + TU_LOG2(" Field 1 : %lx", op_ctx->EP[3].xec_info); + TU_LOG2(" Field 2 : %lx", op_ctx->EP[3].xec_dequeue); + TU_LOG2(" Field 3 : %lx \r\n", op_ctx->EP[3].xec_info2); (void)op_ctx; } diff --git a/src/portable/xhci/xhci_context.h b/src/portable/xhci/xhci_context.h index 2481138ae..940ffd80a 100644 --- a/src/portable/xhci/xhci_context.h +++ b/src/portable/xhci/xhci_context.h @@ -10,7 +10,7 @@ #define __XCHI_CONTEXT_H__ #include "xhci_type.h" -#include "socfpga_defines.h" +#include "stdbool.h" /* MASK and POS for Input control context */ #define DCI_SLOT_CONTEXT (1UL) /* !< Select slot context in Input control context */ diff --git a/src/portable/xhci/xhci_endpoints.c b/src/portable/xhci/xhci_endpoints.c index e4fb2c605..6fb9b9260 100644 --- a/src/portable/xhci/xhci_endpoints.c +++ b/src/portable/xhci/xhci_endpoints.c @@ -11,8 +11,7 @@ #include "xhci.h" #include "xhci_endpoints.h" #include "xhci_rings.h" -#include "osal_log.h" -#include "socfpga_cache.h" +#include "host/hcd.h" /** * @brief Setup the TRB with the control transfer data. For xHCI, control transfer consists of 3 stages. @@ -78,7 +77,10 @@ void configure_setup_stage(struct xhci_data *xhci, void *buffer, /* TRB TYPE = 3 */ end_ctrl_flags |= ((uint32_t) DATA_STAGE_TRB << 10); - end_ctrl_flags |= ((uint32_t) DATA_STAGE_DIR_IN << 16); + if ((setup_req->bmRequestType & TUSB_DIR_IN_MASK) != 0U) + { + end_ctrl_flags |= ((uint32_t) DATA_STAGE_DIR_IN << 16); + } end_ctrl_flags |= xhci->ep0.pcs_flag; ptr->control = end_ctrl_flags; @@ -104,7 +106,7 @@ void configure_setup_stage(struct xhci_data *xhci, void *buffer, ptr->control = end_ctrl_flags; - cache_force_write_back((void *) xhci->ep0.ep_tr_enq_ptr, + hcd_dcache_clean(xhci->ep0.ep_tr_enq_ptr, EP_TRB_SEG_LENGTH * sizeof(xhci_trb_t)); } @@ -285,7 +287,7 @@ static void fill_endpoint_transfer_ring(struct ep_priv *ep_ctx, void *buffer, end_ctrl_flags |= (ep_ctx->pcs_flag); ptr->control = end_ctrl_flags; - cache_force_write_back((void *) ep_ctx->ep_tr_enq_ptr, + hcd_dcache_clean(ep_ctx->ep_tr_enq_ptr, EP_TRB_SEG_LENGTH * sizeof(xhci_trb_t)); } @@ -302,7 +304,7 @@ bool endpoint_transfer(struct xhci_data *xhci, int ep_num, uint8_t dir, /* Out transfer */ if (dir == 0U) { - INFO("Endpoint OUT transfer on endpoint - %d with bytes - %d ", ep_num, + TU_LOG3("Endpoint OUT transfer on endpoint - %d with bytes - %d ", ep_num, buflen); fill_endpoint_transfer_ring(&xhci->msc_eps.ep_out, buffer, buflen); ring_xhci_ep_doorbell(&xhci->op_regs, db_target); @@ -310,7 +312,7 @@ bool endpoint_transfer(struct xhci_data *xhci, int ep_num, uint8_t dir, /* In Transfer */ else if (dir == 1U) { - INFO("Endpoint IN transfer on endpoint - %d with bytes - %d ", ep_num, + TU_LOG3("Endpoint IN transfer on endpoint - %d with bytes - %d ", ep_num, buflen); fill_endpoint_transfer_ring(&xhci->msc_eps.ep_in, buffer, buflen); ring_xhci_ep_doorbell(&xhci->op_regs, db_target); @@ -357,7 +359,7 @@ int xhci_parse_endpoint_descriptor(struct xhci_data *xhci_ptr, EP_TRB_SEG_LENGTH); if (enq_ptr == NULL) { - ERROR("Canot allocate memory!!!"); + TU_LOG1("Canot allocate memory!!!"); return -ENOMEM; } @@ -398,7 +400,7 @@ int xhci_parse_endpoint_descriptor(struct xhci_data *xhci_ptr, EP_TRB_SEG_LENGTH); if (enq_ptr == NULL) { - ERROR("Cannot allocate memory!!!"); + TU_LOG1("Cannot allocate memory!!!"); return -ENOMEM; } xhci_ptr->msc_eps.ep_out.ep_tr_enq_ptr = enq_ptr; diff --git a/src/portable/xhci/xhci_events.c b/src/portable/xhci/xhci_events.c index 976f5c004..3663b66df 100644 --- a/src/portable/xhci/xhci_events.c +++ b/src/portable/xhci/xhci_events.c @@ -9,24 +9,23 @@ #include #include "xhci_events.h" -#include "socfpga_cache.h" -#include "osal_log.h" +#include "host/hcd.h" static void erdp_register_update(xer_event_ring_t *xer_ring, volatile xhci_runtime_regs_t *runtime); void display_event_trbs(struct xhci_data *xhci) { - cache_force_invalidate((void *) xhci->xer_ring.xer_enqueue_ptr, + hcd_dcache_invalidate(xhci->xer_ring.xer_enqueue_ptr, (size_t) (XHCI_EVENT_RING_SEG_LENGTH * sizeof(xhci_trb_t))); for (int i = 0; i < 10; i++) { - DEBUG(" ID --> %d", i); - DEBUG(" Address : %p", &xhci->xer_ring.xer_enqueue_ptr[i]); - DEBUG(" Buffer : %lx", xhci->xer_ring.xer_enqueue_ptr[i].buffer); - DEBUG(" Status : %x", xhci->xer_ring.xer_enqueue_ptr[i].status); - DEBUG(" Control : %x", xhci->xer_ring.xer_enqueue_ptr[i].control); - DEBUG(" TRB Value is : %d", + TU_LOG3(" ID --> %d", i); + TU_LOG3(" Address : %p", &xhci->xer_ring.xer_enqueue_ptr[i]); + TU_LOG3(" Buffer : %lx", xhci->xer_ring.xer_enqueue_ptr[i].buffer); + TU_LOG3(" Status : %x", xhci->xer_ring.xer_enqueue_ptr[i].status); + TU_LOG3(" Control : %x", xhci->xer_ring.xer_enqueue_ptr[i].control); + TU_LOG3(" TRB Value is : %d", ((xhci->xer_ring.xer_enqueue_ptr[i].control) & 0xfc00U) >> 10); } } @@ -73,7 +72,7 @@ void reset_xhci_port(uint8_t rhport) (0x10U * ((uint64_t) rhport - 1UL))); portsc->value |= USB3_PORTSC_20_PR_MASK; - INFO("xHCI port reset initiated on port : %d", rhport); + TU_LOG3("xHCI port reset initiated on port : %d", rhport); } bool is_xhci_port_reset_end(uint8_t rhport) @@ -98,11 +97,11 @@ bool is_xhci_port_reset_end(uint8_t rhport) if (loop == 0U) { - ERROR("usb3 port reset failure"); + TU_LOG1("usb3 port reset failure"); return false; } - INFO("xHCI port reset completede on port : %d", rhport); + TU_LOG3("xHCI port reset completede on port : %d", rhport); return true; } @@ -122,7 +121,7 @@ xhci_event_trb_t get_xhc_event(struct xhci_data *xhci_ptr) runtime->erdp_lo.value; erdp_addr &= 0xfffffff0UL; - cache_force_invalidate((void *)erdp_addr, sizeof(xhci_trb_t)); + hcd_dcache_invalidate((void *) erdp_addr, sizeof(xhci_trb_t)); xhci_trb_t *event_trb = (xhci_trb_t *)(uint64_t)erdp_addr; diff --git a/src/portable/xhci/xhci_interrupts.c b/src/portable/xhci/xhci_interrupts.c index 8118d0b5e..8e53171ca 100644 --- a/src/portable/xhci/xhci_interrupts.c +++ b/src/portable/xhci/xhci_interrupts.c @@ -11,7 +11,7 @@ #include "xhci_interrupts.h" #include "socfpga_interrupt.h" #include "socfpga_interrupt_priority.h" -#include "osal_log.h" +#include "host/hcd.h" void socfpga_usb3_handler(void *handler); @@ -59,11 +59,11 @@ bool register_usb3ISR(xhci_int_ptr_t int_handler) err = interrupt_enable(USB1IRQ, GIC_INTERRUPT_PRIORITY_USB3); if (err != 0) { - ERROR("Failed to enable interrupt"); + TU_LOG1("Failed to enable interrupt"); return false; } - INFO("Interrupt handler registered successfully"); + TU_LOG3("Interrupt handler registered successfully"); return true; } diff --git a/src/portable/xhci/xhci_rings.c b/src/portable/xhci/xhci_rings.c index 418b7b3e7..8e49936be 100644 --- a/src/portable/xhci/xhci_rings.c +++ b/src/portable/xhci/xhci_rings.c @@ -8,7 +8,7 @@ */ #include -#include "socfpga_cache.h" +#include "host/hcd.h" #include "osal_log.h" #include "xhci.h" @@ -152,12 +152,12 @@ int init_xhc_event_ring(struct xhci_data *xhci_ptr) runtime->erdp_lo.value = (uint32_t) erdp_reg_val; runtime->erdp_hi.value = (uint32_t) (ring_addr >> 32); - cache_force_write_back((void *)(uintptr_t) xer_ring->erst_ptr, + hcd_dcache_clean(xer_ring->erst_ptr, sizeof(xhci_erst_entry_t)); - cache_force_write_back((void *)(uintptr_t) xer_ring->xer_enqueue_ptr, + hcd_dcache_clean(xer_ring->xer_enqueue_ptr, XHCI_EVENT_RING_SEG_LENGTH * sizeof(xhci_trb_t)); - INFO("Event Ring configured successfully"); + TU_LOG3("Event Ring configured successfully"); return 0; } @@ -200,7 +200,7 @@ xhci_trb_t *allocate_ring_segment(int req_byte_align, int req_trb_len) ring_ctrl_flags |= ((uint32_t) LINK_TRB << 10); link_trb->control = ring_ctrl_flags; - cache_force_write_back(xtr, (size_t) req_trb_len * sizeof(xhci_trb_t)); + hcd_dcache_clean(xtr, (uint32_t) req_trb_len * sizeof(xhci_trb_t)); return xtr; } @@ -243,7 +243,7 @@ xhci_trb_t *get_next_trb_segment(xhci_trb_t *ptr, uint8_t *pcs_flag) link_ctrl |= (*pcs_flag); link_trb->control = link_ctrl; - cache_force_write_back((void *)(uintptr_t) link_trb, sizeof(xhci_trb_t)); + hcd_dcache_clean(link_trb, sizeof(xhci_trb_t)); if ((link_trb->control & 0x00000002U) != 0U) { From 3b6e87713ddf375f6c4b3657addc73a43fb383e4 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Mon, 23 Nov 2026 10:36:34 +0530 Subject: [PATCH 12/17] src: portable: xhci: code clean-up Signed-off-by: Sourav Raj K K --- src/portable/xhci/xhci.c | 31 ++++++------------------------- src/portable/xhci/xhci_cap.c | 3 --- src/portable/xhci/xhci_commands.c | 1 - src/portable/xhci/xhci_context.c | 13 ------------- src/portable/xhci/xhci_events.c | 13 ++++++++++++- 5 files changed, 18 insertions(+), 43 deletions(-) diff --git a/src/portable/xhci/xhci.c b/src/portable/xhci/xhci.c index 5f4dcfbd8..4499f5b35 100644 --- a/src/portable/xhci/xhci.c +++ b/src/portable/xhci/xhci.c @@ -32,15 +32,11 @@ //--------------------------------------------------------------------+ // INCLUDE //--------------------------------------------------------------------+ -#include "osal/osal.h" - #include "host/hcd.h" #include "host/usbh.h" #include "host/usbh_pvt.h" #include "xhci.h" -#include "osal.h" -#include "osal_log.h" #include #include "tusb.h" @@ -73,21 +69,6 @@ static tusb_control_request_t ctrl_req; static int usb_set_config = 0; uint8_t device_addr = 0; - -//--------------------------------------------------------------------+ -// INCLUDE -//--------------------------------------------------------------------+ -#include "osal/osal.h" - -#include "host/hcd.h" -#include "host/usbh.h" -#include "host/usbh_pvt.h" - -#include "xhci.h" -#include "socfpga_defines.h" -#include "osal.h" -#include "osal_log.h" - int is_ptr_mem_aligned(uint64_t addr, uint32_t byte) { uint64_t fact = 0UL; @@ -149,7 +130,7 @@ static int configure_xhci_max_slots(void) if ((xhci->config.value & USB3_CONFIG_MAXSLOTSEN_MASK) == 0U) { - ERROR("Max Slot Enable Bit Not configurred Correctly"); + TU_LOG1("Max Slot Enable Bit Not configurred Correctly"); return -EIO; } return 0; @@ -241,7 +222,7 @@ bool xhci_init() ret = init_hcd_params(); if (ret != 0) { - ERROR("hcd error -%d", ret); + TU_LOG1("hcd error -%d", ret); return false; } @@ -258,7 +239,7 @@ bool xhci_init() ret = xhci_reset(); if( ret != 0 ) { - ERROR("xhci reset failed"); + TU_LOG1("xhci reset failed"); return false; } @@ -333,7 +314,7 @@ static bool hcd_send_address_cmd( void ) ret = init_input_device_context(&xhci_handle); if (ret != 0) { - ERROR("XHCI Error -%d!!!", ret); + TU_LOG1("XHCI Error -%d!!!", ret); return false; } @@ -429,7 +410,7 @@ void hcd_device_close(uint8_t rhport, uint8_t dev_addr) if (wait_for_command_completion_event(&xhci_handle, DISABLE_SLOT_CMD) != 0) { - ERROR("xHCI command failed"); + TU_LOG1("xHCI command failed"); return; } @@ -747,7 +728,7 @@ bool hcd_parse_full_conf_descriptor(tusb_desc_configuration_t *desc_cfg, uint8_t if (xhci_parse_endpoint_descriptor(&xhci_handle, &xhci_ep_desc) != 0) { - ERROR("Failed to parse endpoint descriptor"); + TU_LOG1("Failed to parse endpoint descriptor"); return false; } err_flag = 1U; diff --git a/src/portable/xhci/xhci_cap.c b/src/portable/xhci/xhci_cap.c index 7769b59d9..53f431261 100644 --- a/src/portable/xhci/xhci_cap.c +++ b/src/portable/xhci/xhci_cap.c @@ -7,9 +7,6 @@ * Capabilities sub-module */ -#include -#include -#include #include "xhci.h" #include "host/hcd.h" diff --git a/src/portable/xhci/xhci_commands.c b/src/portable/xhci/xhci_commands.c index 5469ded9b..26d7f94c3 100644 --- a/src/portable/xhci/xhci_commands.c +++ b/src/portable/xhci/xhci_commands.c @@ -10,7 +10,6 @@ #include "xhci_commands.h" #include "xhci_doorbell.h" #include "host/hcd.h" -#include "osal_log.h" xhci_trb_t *get_cmdring_enq_ptr(xcr_command_ring_t *cmd_ring) { diff --git a/src/portable/xhci/xhci_context.c b/src/portable/xhci/xhci_context.c index 03d76be7b..01ef50d35 100644 --- a/src/portable/xhci/xhci_context.c +++ b/src/portable/xhci/xhci_context.c @@ -47,7 +47,6 @@ #include "xhci.h" #include "xhci_endpoints.h" #include "xhci_context.h" -#include "xhci_events.h" #include "host/hcd.h" int alloc_xhci_contexts(struct xhci_data *xhci_ptr) @@ -389,23 +388,11 @@ void display_xhci_device_params(struct xhci_device_data *dev_data) (void)dev_speed; } -void update_device_dev_speed(struct xhci_data *xhci_ptr) -{ - xhci_ptr->dev_data.dev_speed = get_xhc_port_speed( - xhci_ptr->dev_data.rh_port); -} - void update_device_slot_id(struct xhci_device_data *dev_data, uint8_t slot_id) { dev_data->slot_id = slot_id; } -void update_device_rh_params(struct xhci_data *xhci_ptr, - xhci_psceg_params_t rh_params) -{ - xhci_ptr->dev_data.rh_port = (uint8_t) rh_params.rhport; -} - void update_device_address(struct xhci_data *xhci_ptr) { xhci_ptr->dev_data.dev_addr = get_xhc_device_address(xhci_ptr); diff --git a/src/portable/xhci/xhci_events.c b/src/portable/xhci/xhci_events.c index 3663b66df..34599708f 100644 --- a/src/portable/xhci/xhci_events.c +++ b/src/portable/xhci/xhci_events.c @@ -7,7 +7,6 @@ * Events sub-module */ -#include #include "xhci_events.h" #include "host/hcd.h" @@ -30,6 +29,18 @@ void display_event_trbs(struct xhci_data *xhci) } } +void update_device_rh_params(struct xhci_data *xhci_ptr, + xhci_psceg_params_t rh_params) +{ + xhci_ptr->dev_data.rh_port = (uint8_t) rh_params.rhport; +} + +void update_device_dev_speed(struct xhci_data *xhci_ptr) +{ + xhci_ptr->dev_data.dev_speed = get_xhc_port_speed( + xhci_ptr->dev_data.rh_port); +} + uint8_t get_xhc_port_speed(uint8_t rhport) { xhci_oper_reg_params_t op_reg = get_xhci_op_registers(); From 602a92c0d8f9a300a1e8cb8028a95b446930f5ad Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Mon, 23 Nov 2026 15:26:12 +0530 Subject: [PATCH 13/17] code restrucutre * Consolidate the interrupt handling implementation by moving the contents of xhci_interrupt.c into xhci.c. Signed-off-by: Sourav Raj K K --- hw/bsp/socfpga/family.cmake | 1 - src/portable/synopsys/dwc3/dwc3_socfpga.h | 6 +- src/portable/xhci/xhci.c | 151 ++++++++-------------- src/portable/xhci/xhci.h | 18 --- src/portable/xhci/xhci_common.h | 1 + src/portable/xhci/xhci_interrupts.c | 96 -------------- src/portable/xhci/xhci_interrupts.h | 40 ------ src/portable/xhci/xhci_rings.c | 45 +++++++ src/portable/xhci/xhci_socfpga.h | 48 +++++++ 9 files changed, 148 insertions(+), 258 deletions(-) delete mode 100644 src/portable/xhci/xhci_interrupts.c delete mode 100644 src/portable/xhci/xhci_interrupts.h create mode 100644 src/portable/xhci/xhci_socfpga.h diff --git a/hw/bsp/socfpga/family.cmake b/hw/bsp/socfpga/family.cmake index 1b03f6750..17b4e89b1 100644 --- a/hw/bsp/socfpga/family.cmake +++ b/hw/bsp/socfpga/family.cmake @@ -78,7 +78,6 @@ set(SOCFPGA_DWC3_SRCS ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_doorbell.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_endpoints.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_events.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_interrupts.c ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_rings.c ) diff --git a/src/portable/synopsys/dwc3/dwc3_socfpga.h b/src/portable/synopsys/dwc3/dwc3_socfpga.h index 7653912a1..7290eea03 100644 --- a/src/portable/synopsys/dwc3/dwc3_socfpga.h +++ b/src/portable/synopsys/dwc3/dwc3_socfpga.h @@ -34,10 +34,8 @@ extern "C" { #endif #if CFG_TUSB_MCU == OPT_MCU_SOCFPGA - #define SOCFPGA_USB3_REG_BASE (0x1100C100U) + #define SOCFPGA_DWC3_REG_BASE (0x1100C100U) #define OTG_HS_IRQn 126 // IRQ num for USB1 = 126 - #include "socfpga_interrupt.h" - #include "socfpga_interrupt_priority.h" #include "socfpga_rst_mngr.h" #include "socfpga_cache.h" #else @@ -47,7 +45,7 @@ extern "C" { // On STM32 for consistency we associate // - Port0 to OTG_FS, and Port1 to OTG_HS static const dwc3_controller_t _dwc3_controller[] = { - { .reg_base = SOCFPGA_USB3_REG_BASE, .irqnum = OTG_HS_IRQn, }, + { .reg_base = SOCFPGA_DWC3_REG_BASE, .irqnum = OTG_HS_IRQn, }, }; //------------- DCache -------------// diff --git a/src/portable/xhci/xhci.c b/src/portable/xhci/xhci.c index 4499f5b35..8901cf5bc 100644 --- a/src/portable/xhci/xhci.c +++ b/src/portable/xhci/xhci.c @@ -43,14 +43,6 @@ #include "tusb_private.h" #include "xhci_common.h" -#if CFG_TUSB_MCU == OPT_MCU_SOCFPGA - #include "xhci_events.h" - #include "xhci_commands.h" - #include "xhci_endpoints.h" - #include "xhci_interrupts.h" - #include "xhci_doorbell.h" -#endif - typedef struct { uint8_t *buffer; @@ -60,60 +52,11 @@ typedef struct #define XHCI_DCI_MAX 31 hcd_dwc3_endpoint_t ep_data[XHCI_DCI_MAX]; -static void hcd_xhci_set_configuration(); -static void hcd_dwc3_update_device_address( uint8_t daddr ); - -struct xhci_data xhci_handle __attribute__((aligned(64))); -static struct xhci_int_desc usb3_int_desc; +static struct xhci_data xhci_handle TU_ATTR_ALIGNED(64); static tusb_control_request_t ctrl_req; static int usb_set_config = 0; uint8_t device_addr = 0; -int is_ptr_mem_aligned(uint64_t addr, uint32_t byte) -{ - uint64_t fact = 0UL; - - /* Check if the address is byte aligned or not */ - switch (byte) - { - case 8U: - fact = 0x7UL; - break; - - case 16U: - fact = 0xFUL; - break; - - case 32U: - fact = 0x1FUL; - break; - - case 64U: - fact = 0x3FUL; - break; - - case 128U: - fact = 0x7FUL; - break; - - default: - fact = 0xFFUL; - break; - } - - if (fact == 0xFFUL) - { - return ENOMEM; - } - - if ((addr & fact) == 0UL) - { - return 0; - } - - return -EIO; -} - static int configure_xhci_max_slots(void) { volatile xhci_regs_t *xhci = @@ -175,7 +118,7 @@ static int wait_for_controller_ready(void) return -ETIMEDOUT; } -int xhci_reset(void) +static int xhci_reset(void) { volatile xhci_regs_t *xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; @@ -211,10 +154,7 @@ bool xhci_init() { int ret; - xhci_int_ptr_t usb3_int_ptr = &usb3_int_desc; - - usb3_int_ptr->int_handler = tusb_int_handler; - if (register_usb3ISR(usb3_int_ptr) == false) + if (register_usb3ISR() == false) { return false; } @@ -262,6 +202,36 @@ bool hcd_edpt_close(uint8_t rhport, uint8_t daddr, uint8_t ep_addr) return true; } +static void enable_xhci_interrupts(void) +{ + struct xhci_oper_reg_params op_regs; + volatile xhci_runtime_regs_t *runtime; + volatile xhci_regs_t *xhci; + + op_regs = get_xhci_op_registers(); + runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) op_regs.xhci_runtime_base; + xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; + + runtime->iman.ie = 1U; + xhci->usbcmd.inte = 1U; +} + +static void disable_xhci_interrupts(void) +{ + + struct xhci_oper_reg_params op_regs; + volatile xhci_runtime_regs_t *runtime; + volatile xhci_regs_t *xhci; + + op_regs = get_xhci_op_registers(); + runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) op_regs.xhci_runtime_base; + xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; + + runtime->iman.ie = 0U; + runtime->iman.ip = 0U; + xhci->usbcmd.inte = 0U; +} + void hcd_int_enable( uint8_t rhport ) { if(rhport == 1) @@ -541,6 +511,10 @@ static void handle_endpoint_transfer(uint8_t ep_dci, uint8_t ep_addr) } +//-------------------------------------------------------------------- +// HCD Event Handler +//-------------------------------------------------------------------- + void hcd_int_handler( uint8_t rhport, bool in_isr ) { (void) rhport; @@ -565,6 +539,21 @@ void hcd_int_handler( uint8_t rhport, bool in_isr ) xhci_event_trb_t event_data; + volatile xhci_regs_t *xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; + struct xhci_oper_reg_params op_regs = get_xhci_op_registers(); + volatile xhci_runtime_regs_t *runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) op_regs.xhci_runtime_base; + + if ((xhci->usbsts.hse != 0U) || (xhci->usbsts.hce != 0U)) + { + (void) xhci_reset(); + start_xhci_controller(); + return; + } + + // clear interrupt flags + xhci->usbsts.eint = 1U; + runtime->iman.ip = 1U; + event_data = get_xhc_event(&xhci_handle); trb_id = @@ -622,42 +611,6 @@ void hcd_int_handler( uint8_t rhport, bool in_isr ) } -bool hcd_evaluate_xhci_context( void ) -{ - tusb_desc_device_t usb_desc; - TU_ASSERT(tuh_descriptor_get_device_local(device_addr, &usb_desc)); - const uint16_t bcd_usb = usb_desc.bcdUSB; - uint16_t desc_max_pkt_size; - const uint16_t ep0_pkt_size = - (xhci_handle.ip_ctx->xe_context[ 0 ].xec_info & - ~EP_CTX_MAX_PKT_SIZE_MSK) >> EP_CTX_MAX_PKT_SIZE_POS; - - if (bcd_usb >= 0x300U) - { - desc_max_pkt_size = (uint16_t) pow(2, usb_desc.bMaxPacketSize0); - } - else - { - desc_max_pkt_size = usb_desc.bMaxPacketSize0; - } - - if (ep0_pkt_size != desc_max_pkt_size) - { - update_endpoint_packetsize(xhci_handle.ip_ctx, desc_max_pkt_size); - - evaluate_endpoint(&xhci_handle); - - if (wait_for_command_completion_event(&xhci_handle, EVALUATE_CONTEXT_CMD) != 0) - { - return false; - } - - return true; - } - - return true; -} - bool hcd_parse_full_conf_descriptor(tusb_desc_configuration_t *desc_cfg, uint8_t rhport) { (void) rhport; diff --git a/src/portable/xhci/xhci.h b/src/portable/xhci/xhci.h index a868cb1d6..13b965b8c 100644 --- a/src/portable/xhci/xhci.h +++ b/src/portable/xhci/xhci.h @@ -310,16 +310,6 @@ int init_xhci_context_params(struct xhci_data *xhci_ptr); /* Generic xhci APIS */ -/** - * @brief function to check if the pointer address passed is byte aligned - * @param[in] ptr - pointer to be checked byte aligned or not - * @param[in] byte - pointer byte alignment size - * @return - * 0 on successful allocation - * errno, incase of failure - */ -int is_ptr_mem_aligned(uint64_t addr, uint32_t byte); - /** * @brief parse the endpoint descriptors * @param[in] xhci_ptr reference to xhci hcd structure @@ -337,14 +327,6 @@ int xhci_parse_endpoint_descriptor(struct xhci_data *xhci_ptr, */ void display_xhci_device_params(struct xhci_device_data *dev_data); -/** - * @brief reset the xHCI controller - * @return - * 0, on success - * errno, on failure - */ -int xhci_reset(void); - /** * @brief start the xHCI controller */ diff --git a/src/portable/xhci/xhci_common.h b/src/portable/xhci/xhci_common.h index 043cd8d83..afa19fde4 100644 --- a/src/portable/xhci/xhci_common.h +++ b/src/portable/xhci/xhci_common.h @@ -10,6 +10,7 @@ #define __HCD_SOCFPGA_H__ #include +#include "xhci_socfpga.h" #include "xhci.h" #include "xhci_events.h" #include diff --git a/src/portable/xhci/xhci_interrupts.c b/src/portable/xhci/xhci_interrupts.c deleted file mode 100644 index 8e53171ca..000000000 --- a/src/portable/xhci/xhci_interrupts.c +++ /dev/null @@ -1,96 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation - * - * SPDX-License-Identifier: MIT-0 - * - * Low level driver implementation for SoC FPGA USB3.1 XHCI controller. - * Interrupt sub-module. - */ - -#include "xhci.h" -#include "xhci_interrupts.h" -#include "socfpga_interrupt.h" -#include "socfpga_interrupt_priority.h" -#include "host/hcd.h" - -void socfpga_usb3_handler(void *handler); - -void enable_xhci_interrupts(void) -{ - struct xhci_oper_reg_params op_regs; - volatile xhci_runtime_regs_t *runtime; - volatile xhci_regs_t *xhci; - - op_regs = get_xhci_op_registers(); - runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) op_regs.xhci_runtime_base; - xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; - - runtime->iman.ie = 1U; - xhci->usbcmd.inte = 1U; -} - -void disable_xhci_interrupts(void) -{ - - struct xhci_oper_reg_params op_regs; - volatile xhci_runtime_regs_t *runtime; - volatile xhci_regs_t *xhci; - - op_regs = get_xhci_op_registers(); - runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) op_regs.xhci_runtime_base; - xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; - - runtime->iman.ie = 0U; - runtime->iman.ip = 0U; - xhci->usbcmd.inte = 0U; -} - -bool register_usb3ISR(xhci_int_ptr_t int_handler) -{ - int err; - - err = interrupt_register_isr(USB1IRQ, socfpga_usb3_handler, - int_handler); - if (err != 0) - { - return false; - } - - err = interrupt_enable(USB1IRQ, GIC_INTERRUPT_PRIORITY_USB3); - if (err != 0) - { - TU_LOG1("Failed to enable interrupt"); - return false; - } - - TU_LOG3("Interrupt handler registered successfully"); - return true; -} - -void socfpga_usb3_handler(void *handler) -{ - xhci_int_ptr_t usb3_int_handler; - struct xhci_oper_reg_params op_regs; - volatile xhci_runtime_regs_t *runtime; - volatile xhci_regs_t *xhci; - - op_regs = get_xhci_op_registers(); - runtime = (volatile xhci_runtime_regs_t *)(uintptr_t) op_regs.xhci_runtime_base; - xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; - - usb3_int_handler = (xhci_int_ptr_t) handler; - - if ((xhci->usbsts.hse != 0U) || (xhci->usbsts.hce != 0U)) - { - (void) xhci_reset(); - start_xhci_controller(); - return; - } - - xhci->usbsts.eint = 1U; - runtime->iman.ip = 1U; - - /* rh_port = 1 -> RH port number as per tinyusb stack */ - /* in_isr = true, ISR flag for tinyusb stack */ - usb3_int_handler->int_handler(1, true); -} diff --git a/src/portable/xhci/xhci_interrupts.h b/src/portable/xhci/xhci_interrupts.h deleted file mode 100644 index 154f3aab5..000000000 --- a/src/portable/xhci/xhci_interrupts.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * SPDX-FileCopyrightText: Copyright (C) 2025 Altera Corporation - * - * SPDX-License-Identifier: MIT-0 - * - * Header file for Interrupts sub-module of SoC FPGA USB3.1 XHCI low level driver - */ - -#ifndef __XHCI_INTERRUPTS_H__ -#define __XHCI_INTERRUPTS_H__ - -#include - -/* Function pointer for tinyusb interrupt handler */ -typedef void (*tusb_int_ptr)(uint8_t rhport, bool in_isr); - -/* descriptor to pass to interrupt handler */ -struct xhci_int_desc -{ - tusb_int_ptr int_handler; /* !< pointer to tinyusb interrupt handler */ -}; - -typedef struct xhci_int_desc *xhci_int_ptr_t; -/* - * @brief enable xhci interrupts - */ -void enable_xhci_interrupts(void); - -/* - * @brief disable the xhci interrupts - */ -void disable_xhci_interrupts(void); - -/* - * @brief register USB3 ISR - * @param[in] int_handler - pointer to tinyusb interrupt handler - */ -bool register_usb3ISR(xhci_int_ptr_t int_handler); - -#endif /* __XHCI_INTERRUPTS_H__ */ diff --git a/src/portable/xhci/xhci_rings.c b/src/portable/xhci/xhci_rings.c index 8e49936be..f2bc1d269 100644 --- a/src/portable/xhci/xhci_rings.c +++ b/src/portable/xhci/xhci_rings.c @@ -35,6 +35,51 @@ * Transfer rings are associated with endpoints to carry out transfers. */ +static int is_ptr_mem_aligned(uint64_t addr, uint32_t byte) +{ + uint64_t fact = 0UL; + + /* Check if the address is byte aligned or not */ + switch (byte) + { + case 8U: + fact = 0x7UL; + break; + + case 16U: + fact = 0xFUL; + break; + + case 32U: + fact = 0x1FUL; + break; + + case 64U: + fact = 0x3FUL; + break; + + case 128U: + fact = 0x7FUL; + break; + + default: + fact = 0xFFUL; + break; + } + + if (fact == 0xFFUL) + { + return ENOMEM; + } + + if ((addr & fact) == 0UL) + { + return 0; + } + + return -EIO; +} + int xhci_crcr_init(xcr_command_ring_t *xcr_ring) { volatile xhci_regs_t *xhci = (volatile xhci_regs_t *)(uintptr_t) XHCI_REG_BASE; diff --git a/src/portable/xhci/xhci_socfpga.h b/src/portable/xhci/xhci_socfpga.h new file mode 100644 index 000000000..c346288a5 --- /dev/null +++ b/src/portable/xhci/xhci_socfpga.h @@ -0,0 +1,48 @@ +#ifndef XHCI_SOCFGPA_H_ +#define XHCI_SOCFPGA_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#if CFG_TUSB_MCU == OPT_MCU_SOCFPGA + #define USB3_IRQn 126 // IRQ num for USB1 = 126 + #include "tusb.h" + #include "socfpga_interrupt.h" + #include "socfpga_interrupt_priority.h" + #include "xhci_events.h" + #include "xhci_commands.h" + #include "xhci_endpoints.h" + #include "xhci_doorbell.h" +#endif + +static void usb3_isr(void *arg) +{ + (void) arg; + tusb_int_handler(1, true); +} + +TU_ATTR_ALWAYS_INLINE static bool inline register_usb3ISR() +{ + int err; + + err = interrupt_register_isr(USB3_IRQn, usb3_isr, NULL); + if (err != 0) + { + return false; + } + + err = interrupt_enable(USB3_IRQn, GIC_INTERRUPT_PRIORITY_USB3); + if (err != 0) + { + return false; + } + + return true; +} + +#ifdef __cplusplus +} +#endif + +#endif From dedd5edc658d859a7477fdace672b230c476a432 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Tue, 24 Nov 2026 13:58:15 +0530 Subject: [PATCH 14/17] code clean-up Signed-off-by: Sourav Raj K K --- src/portable/xhci/xhci.c | 28 +++++----------------------- src/portable/xhci/xhci.h | 13 ------------- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/src/portable/xhci/xhci.c b/src/portable/xhci/xhci.c index 8901cf5bc..6be97b6d3 100644 --- a/src/portable/xhci/xhci.c +++ b/src/portable/xhci/xhci.c @@ -36,8 +36,6 @@ #include "host/usbh.h" #include "host/usbh_pvt.h" -#include "xhci.h" - #include #include "tusb.h" #include "tusb_private.h" @@ -79,7 +77,7 @@ static int configure_xhci_max_slots(void) return 0; } -void start_xhci_controller(void) +static void start_xhci_controller(void) { volatile xhci_regs_t *xhci = (volatile xhci_regs_t *)(uintptr_t) USBBASE; @@ -154,34 +152,18 @@ bool xhci_init() { int ret; - if (register_usb3ISR() == false) - { - return false; - } + TU_ASSERT((register_usb3ISR() == true)); - ret = init_hcd_params(); - if (ret != 0) - { - TU_LOG1("hcd error -%d", ret); - return false; - } + TU_ASSERT((init_hcd_params() == 0)); //clear xHCI data structure members tu_memclr(&xhci_handle, sizeof(xhci_handle)); get_xhc_cap_params(&xhci_handle); - if(wait_for_controller_ready() != 0) - { - return false; - } + TU_ASSERT((wait_for_controller_ready() == 0)); - ret = xhci_reset(); - if( ret != 0 ) - { - TU_LOG1("xhci reset failed"); - return false; - } + TU_ASSERT((xhci_reset() == 0)); configure_xhci_max_slots(); diff --git a/src/portable/xhci/xhci.h b/src/portable/xhci/xhci.h index 13b965b8c..be07d1886 100644 --- a/src/portable/xhci/xhci.h +++ b/src/portable/xhci/xhci.h @@ -327,17 +327,4 @@ int xhci_parse_endpoint_descriptor(struct xhci_data *xhci_ptr, */ void display_xhci_device_params(struct xhci_device_data *dev_data); -/** - * @brief start the xHCI controller - */ -void start_xhci_controller(void); - -/** - * @brief Initialize the xHCI registers - * @return - * true on successful initialization - * false incase of failure - */ -bool xhci_init(); - #endif /*__XHCI_H__ */ From 4c00ee01b15695c92cdabd7bd053dacdcce4b555 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Tue, 24 Nov 2026 16:37:21 +0530 Subject: [PATCH 15/17] add Agilex5 board support in tinyusb Signed-off-by: Sourav Raj K K --- examples/host/msc_file_explorer/only.txt | 2 + hw/bsp/socfpga/boards/agilex5/agilex5.ld | 262 ++++++++++++++++++++++ hw/bsp/socfpga/boards/agilex5/board.cmake | 10 + hw/bsp/socfpga/boards/agilex5/board.h | 136 +++++++++++ hw/bsp/socfpga/family.c | 62 +++++ hw/bsp/socfpga/family.cmake | 248 ++++++++++++++------ hw/bsp/socfpga/socfpga_sdk_import.cmake | 28 +++ 7 files changed, 679 insertions(+), 69 deletions(-) create mode 100644 hw/bsp/socfpga/boards/agilex5/agilex5.ld create mode 100644 hw/bsp/socfpga/boards/agilex5/board.cmake create mode 100644 hw/bsp/socfpga/boards/agilex5/board.h create mode 100644 hw/bsp/socfpga/family.c create mode 100644 hw/bsp/socfpga/socfpga_sdk_import.cmake diff --git a/examples/host/msc_file_explorer/only.txt b/examples/host/msc_file_explorer/only.txt index cba58f8e8..a400b2332 100644 --- a/examples/host/msc_file_explorer/only.txt +++ b/examples/host/msc_file_explorer/only.txt @@ -20,3 +20,5 @@ mcu:STM32H7RS mcu:STM32N6 family:samd21 family:samd5x_e5x +family:agilex5 +family:socfpga diff --git a/hw/bsp/socfpga/boards/agilex5/agilex5.ld b/hw/bsp/socfpga/boards/agilex5/agilex5.ld new file mode 100644 index 000000000..a84255a84 --- /dev/null +++ b/hw/bsp/socfpga/boards/agilex5/agilex5.ld @@ -0,0 +1,262 @@ + +_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x2000; +_HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x2000; + +_EL0_STACK_SIZE = DEFINED(_EL0_STACK_SIZE) ? _EL0_STACK_SIZE : _STACK_SIZE; +_EL1_STACK_SIZE = DEFINED(_EL1_STACK_SIZE) ? _EL1_STACK_SIZE : _STACK_SIZE; +_EL2_STACK_SIZE = DEFINED(_EL2_STACK_SIZE) ? _EL2_STACK_SIZE : _STACK_SIZE; +_NUM_CORE = DEFINED(_NUM_CORE) ? _NUM_CORE : 1; + +_STACK_EL012 = ALIGN(_EL0_STACK_SIZE, 64) + + ALIGN(_EL1_STACK_SIZE, 64) + ALIGN(_EL2_STACK_SIZE, 64); +_STACK_MAX = _STACK_EL012 * _NUM_CORE; + +MEMORY +{ + SRAM_RO (rx): ORIGIN = 0x82000000, LENGTH = 0x100000 + SRAM (rw): ORIGIN = 0x82100000, LENGTH = 0x7DF00000 +} + +/* Specify the default entry point to the program */ + +ENTRY(_vector_table) +PROVIDE(end = _heap_end); /*Symbol for stdlib heap*/ +PROVIDE(__stack = __stdlib_stack); /*Symbol for stdlib stack*/ +/* Define the sections, and where they are mapped in memory */ + +SECTIONS +{ + .text (READONLY) : { + KEEP (*(.vectors)) + *(.boot) + *(.text) + *(.text.*) + *(.gnu.linkonce.t.*) + *(.plt) + *(.gnu_warning) + *(.gcc_execpt_table) + *(.glue_7) + *(.glue_7t) + *(.ARM.extab) + *(.gnu.linkonce.armextab.*) + } > SRAM_RO + + .init (ALIGN(64)) (READONLY) : { + KEEP (*(.init)) + } > SRAM_RO + + .fini (ALIGN(64)) (READONLY) : { + KEEP (*(.fini)) + } > SRAM_RO + + .interp (READONLY) : { + KEEP (*(.interp)) + } > SRAM_RO + + .note-ABI-tag (READONLY) : { + KEEP (*(.note-ABI-tag)) + } > SRAM_RO + + .rodata (READONLY) : { + . = ALIGN(64); + __rodata_start = .; + *(.rodata) + *(.rodata.*) + *(.gnu.linkonce.r.*) + __rodata_end = .; + } > SRAM_RO + + .rodata1 (READONLY) : { + . = ALIGN(64); + __rodata1_start = .; + *(.rodata1) + *(.rodata1.*) + __rodata1_end = .; + } > SRAM_RO + + .sdata2 : { + . = ALIGN(64); + __sdata2_start = .; + *(.sdata2) + *(.sdata2.*) + *(.gnu.linkonce.s2.*) + __sdata2_end = .; + } > SRAM + + .sbss2 : { + . = ALIGN(64); + __sbss2_start = .; + *(.sbss2) + *(.sbss2.*) + *(.gnu.linkonce.sb2.*) + __sbss2_end = .; + } > SRAM + + .data : { + . = ALIGN(64); + __data_start = .; + *(.data) + *(.data.*) + *(.gnu.linkonce.d.*) + *(.jcr) + *(.got) + *(.got.plt) + __data_end = .; + } > SRAM + + .data1 : { + . = ALIGN(64); + __data1_start = .; + *(.data1) + *(.data1.*) + __data1_end = .; + } > SRAM + + .got : { + *(.got) + } > SRAM + + .got1 : { + *(.got1) + } > SRAM + + .got2 : { + *(.got2) + } > SRAM + + .ctors : { + . = ALIGN(64); + __CTOR_LIST__ = .; + ___CTORS_LIST___ = .; + KEEP (*crtbegin.o(.ctors)) + KEEP (*(EXCLUDE_FILE(*crtend.o) .ctors)) + KEEP (*(SORT(.ctors.*))) + KEEP (*(.ctors)) + __CTOR_END__ = .; + ___CTORS_END___ = .; + } > SRAM + + .dtors : { + . = ALIGN(64); + __DTOR_LIST__ = .; + ___DTORS_LIST___ = .; + KEEP (*crtbegin.o(.dtors)) + KEEP (*(EXCLUDE_FILE(*crtend.o) .dtors)) + KEEP (*(SORT(.dtors.*))) + KEEP (*(.dtors)) + __DTOR_END__ = .; + ___DTORS_END___ = .; + } > SRAM + + .fixup : { + __fixup_start = .; + *(.fixup) + __fixup_end = .; + } > SRAM + + .eh_frame : { + *(.eh_frame) + } > SRAM + + .eh_framehdr : { + __eh_framehdr_start = .; + *(.eh_framehdr) + __eh_framehdr_end = .; + } > SRAM + + .gcc_except_table : { + *(.gcc_except_table) + } > SRAM + + .ARM.exidx : { + __exidx_start = .; + *(.ARM.exidx*) + *(.gnu.linkonce.armexidix.*.*) + __exidx_end = .; + } > SRAM + + .preinit_array : { + . = ALIGN(64); + __preinit_array_start = .; + KEEP (*(SORT(.preinit_array.*))) + KEEP (*(.preinit_array)) + __preinit_array_end = .; + } > SRAM + + .init_array : { + . = ALIGN(64); + __init_array_start = .; + KEEP (*(SORT(.init_array.*))) + KEEP (*(.init_array)) + __init_array_end = .; + } > SRAM + + .fini_array : { + . = ALIGN(64); + __fini_array_start = .; + KEEP (*(SORT(.fini_array.*))) + KEEP (*(.fini_array)) + __fini_array_end = .; + } > SRAM + + .ARM.attributes : { + __ARM.attributes_start = .; + *(.ARM.attributes) + __ARM.attributes_end = .; + } > SRAM + + .sbss (NOLOAD) : { + . = ALIGN(64); + __sbss_start = .; + *(.sbss) + *(.sbss.*) + *(.gnu.linkonce.sb.*) + . = ALIGN(64); + __sbss_end = .; + } > SRAM + + .tdata : { + . = ALIGN(64); + __tdata_start = .; + *(.tdata) + *(.tdata.*) + *(.gnu.linkonce.td.*) + __tdata_end = .; + } > SRAM + + .tbss : { + . = ALIGN(64); + __tbss_start = .; + *(.tbss) + *(.tbss.*) + *(.gnu.linkonce.tb.*) + __tbss_end = .; + } > SRAM + + .bss (NOLOAD) : { + . = ALIGN(64); + __bss_start__ = .; + *(.bss) + *(.bss.*) + *(.gnu.linkonce.b.*) + *(COMMON) + . = ALIGN(64); + __bss_end__ = .; + } > SRAM + + /*Leave 4K space for saftey (if any input section are to be put in .section)*/ + .stack (NOLOAD) : { + __stack_end = .; + . = ALIGN(64); + . += _STACK_EL012; + . = ALIGN(64); + __stdlib_stack = .; + . += _STACK_MAX; + . = ALIGN(64); + __stack_top = .; + } > SRAM + + _end = .; PROVIDE (end = .); + _heap_end = 0xFFEFEFF0; + +} diff --git a/hw/bsp/socfpga/boards/agilex5/board.cmake b/hw/bsp/socfpga/boards/agilex5/board.cmake new file mode 100644 index 000000000..267b7f0a4 --- /dev/null +++ b/hw/bsp/socfpga/boards/agilex5/board.cmake @@ -0,0 +1,10 @@ +set(MCU_VARIANT agilex5) +#set(JLINK_DEVICE ) + +set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/agilex5.ld) + +function(update_board TARGET) + target_compile_definitions(${TARGET} PUBLIC + AGILEX5 + ) +endfunction() diff --git a/hw/bsp/socfpga/boards/agilex5/board.h b/hw/bsp/socfpga/boards/agilex5/board.h new file mode 100644 index 000000000..19a029768 --- /dev/null +++ b/hw/bsp/socfpga/boards/agilex5/board.h @@ -0,0 +1,136 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2020, Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * This file is part of the TinyUSB stack. + */ + +/* metadata: + name: STM32 F407 Discovery + url: https://www.st.com/en/evaluation-tools/stm32f4discovery.html +*/ + +#ifndef BOARD_H_ +#define BOARD_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +// Enable PA2 as the debug log UART +// It is not routed to the ST/Link on the Discovery board. +#define UART_DEV USART2 + +#define PINID_LED 0 +#define PINID_BUTTON 1 +#define PINID_UART_TX 2 +#define PINID_UART_RX 3 +#define PINID_VBUS0_EN 4 + +static board_pindef_t board_pindef[] = { + { // LED + .port = GPIOD, + .pin_init = { .Pin = GPIO_PIN_14, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 }, + .active_state = 1 + }, + { // BUTTON + .port = GPIOA, + .pin_init = { .Pin = GPIO_PIN_0, .Mode = GPIO_MODE_INPUT, .Pull = GPIO_PULLDOWN, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 }, + .active_state = 1 + }, + { // UART TX + .port = GPIOA, + .pin_init = { .Pin = GPIO_PIN_2, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART2 }, + .active_state = 0 + }, + { // UART RX + .port = GPIOA, + .pin_init = { .Pin = GPIO_PIN_3, .Mode = GPIO_MODE_AF_PP, .Pull = GPIO_PULLUP, .Speed = GPIO_SPEED_HIGH, .Alternate = GPIO_AF7_USART2 }, + .active_state = 0 + }, + { // VBUS0 EN + .port = GPIOC, + .pin_init = { .Pin = GPIO_PIN_0, .Mode = GPIO_MODE_OUTPUT_PP, .Pull = GPIO_NOPULL, .Speed = GPIO_SPEED_HIGH, .Alternate = 0 }, + .active_state = 0 + } +}; + +//--------------------------------------------------------------------+ +// RCC Clock +//--------------------------------------------------------------------+ +static inline void board_clock_init(void) +{ + RCC_ClkInitTypeDef RCC_ClkInitStruct; + RCC_OscInitTypeDef RCC_OscInitStruct; + + /* Enable Power Control clock */ + __HAL_RCC_PWR_CLK_ENABLE(); + + /* The voltage scaling allows optimizing the power consumption when the device is + clocked below the maximum system frequency, to update the voltage scaling value + regarding system frequency refer to product datasheet. */ + __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1); + + /* Enable HSE Oscillator and activate PLL with HSE as source */ + RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; + RCC_OscInitStruct.HSEState = RCC_HSE_ON; + RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; + RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; + RCC_OscInitStruct.PLL.PLLM = HSE_VALUE/1000000; + RCC_OscInitStruct.PLL.PLLN = 336; + RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; + RCC_OscInitStruct.PLL.PLLQ = 7; + HAL_RCC_OscConfig(&RCC_OscInitStruct); + + /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 + clocks dividers */ + RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); + RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; + RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; + RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; + RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; + HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5); + + // Enable clocks Uart + __HAL_RCC_USART2_CLK_ENABLE(); +} + +static inline void board_vbus_sense_init(uint8_t rhport) { + if (rhport == 0) { + // Enable VBUS sense (B device) via pin PA9 + USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS; + USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; + } +} + +static inline void board_vbus_set(uint8_t rhport, bool state) { + if (rhport == 0) { + board_pindef_t* pindef = &board_pindef[PINID_VBUS0_EN]; + HAL_GPIO_WritePin(pindef->port, pindef->pin_init.Pin, state == pindef->active_state ? GPIO_PIN_SET : GPIO_PIN_RESET); + } +} + +#ifdef __cplusplus + } +#endif + +#endif /* BOARD_H_ */ diff --git a/hw/bsp/socfpga/family.c b/hw/bsp/socfpga/family.c new file mode 100644 index 000000000..3ad95eced --- /dev/null +++ b/hw/bsp/socfpga/family.c @@ -0,0 +1,62 @@ +#include "bsp/board_api.h" +#include "socfpga_console.h" +#include "socfpga_interrupt.h" + +#include "FreeRTOSConfig.h" + +void board_init(void) { + interrupt_init_gic(); + (void) console_init(configCONSOLE_UART_ID, "115200-8N1"); +} + +void board_init_after_tusb(void) {} + +void board_led_write(bool state) { + (void) state; +} + +uint32_t board_button_read(void) { + return 0; +} + +int board_uart_read(uint8_t *buf, int len) { + int result = console_read(buf, len); + return result > 0 ? result : 0; +} + +int board_uart_write(void const *buf, int len) { + return console_write((unsigned char *)(uintptr_t) buf, len); +} + +int board_getchar(void) { + uint8_t ch; + return board_uart_read(&ch, 1) == 1 ? ch : -1; +} + +void board_putchar(int c) { + uint8_t ch = (uint8_t) c; + (void) board_uart_write(&ch, 1); +} + +uint32_t tusb_time_millis_api(void) { + return board_millis(); +} + +void vApplicationMallocFailedHook(void) { + taskDISABLE_INTERRUPTS(); + for (;;) {} +} + +void vApplicationIdleHook(void) {} + +void vApplicationTickHook(void) {} + +#if CFG_TUSB_OS == OPT_OS_NONE +uint32_t board_millis(void) { + uint64_t counter; + uint64_t frequency; + __asm volatile("mrs %0, cntpct_el0" : "=r"(counter)); + __asm volatile("mrs %0, cntfrq_el0" : "=r"(frequency)); + return frequency ? (uint32_t) ((counter * 1000U) / frequency) : 0; +} +#endif diff --git a/hw/bsp/socfpga/family.cmake b/hw/bsp/socfpga/family.cmake index 17b4e89b1..0a4a9e687 100644 --- a/hw/bsp/socfpga/family.cmake +++ b/hw/bsp/socfpga/family.cmake @@ -1,8 +1,37 @@ -include_guard() +include_guard(GLOBAL) + +if (NOT BOARD) + set(BOARD agilex5) +endif () + +include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake) +include(${CMAKE_CURRENT_LIST_DIR}/socfpga_sdk_import.cmake) + +if (SOCFPGA_SDK_FETCHED) + if (NOT DEFINED SOC) + set(SOC AGILEX5) + endif () + if (NOT DEFINED CORE) + set(CORE A55) + endif () + include(${SOCFPGA_SDK_SOURCE_DIR}/tools/target_socfpga.cmake) + set(FREERTOS_CONFIG_HEADER_PATH + ${SOCFPGA_SDK_SOURCE_DIR}/FreeRTOS/Demo/SOCFPGA) + + foreach(LANGUAGE C CXX ASM) + find_program(SOCFPGA_${LANGUAGE}_COMPILER_PATH + NAMES ${CMAKE_${LANGUAGE}_COMPILER}) + if (NOT SOCFPGA_${LANGUAGE}_COMPILER_PATH) + message(FATAL_ERROR + "Could not find SoCFPGA ${LANGUAGE} compiler: ${CMAKE_${LANGUAGE}_COMPILER}") + endif () + set(CMAKE_${LANGUAGE}_COMPILER "${SOCFPGA_${LANGUAGE}_COMPILER_PATH}" + CACHE FILEPATH "" FORCE) + endforeach () +endif () + +set(FAMILY_MCUS AGILEX5) -# ---------------------- -# Port & Speed Selection -# ---------------------- if (NOT DEFINED RHPORT_DEVICE) set(RHPORT_DEVICE 0) endif () @@ -10,22 +39,17 @@ if (NOT DEFINED RHPORT_HOST) set(RHPORT_HOST 0) endif () -set(RHPORT_DEVICE_SPEED OPT_MODE_HIGH_SPEED) +if (NOT DEFINED RHPORT_DEVICE_SPEED) + set(RHPORT_DEVICE_SPEED OPT_MODE_HIGH_SPEED) +endif () +if (NOT DEFINED RHPORT_HOST_SPEED) + set(RHPORT_HOST_SPEED OPT_MODE_HIGH_SPEED) +endif () -# ---------------------- -# Host controller selection -# dwc2 : USB2.0 OTG (DWC2), rhport 0 -# dwc3 : USB3.1 (DWC3 in xHCI host mode), rhports 1 (USB2 port) and 2 (USB3 port) -# both : both controllers in one image (CFG_TUH_HCD_MULTI), routed per rhport by -# hw/bsp/socfpga/hcd_socfpga_multi.c -# dwc2/dwc3 build exactly one standard TinyUSB HCD. -# ---------------------- set(SOCFPGA_HCD "both" CACHE STRING "SoC FPGA host controller driver: dwc2, dwc3 or both") set_property(CACHE SOCFPGA_HCD PROPERTY STRINGS dwc2 dwc3 both) option(SOCFPGA_HCD_WERROR "Build the TinyUSB library with -Wall -Wextra -Werror" OFF) -set(TUSB_SRC ${FREERTOS_TOP_DIR}/tinyusb/src) - if (SOCFPGA_HCD STREQUAL "dwc2") set(SOCFPGA_HCD_DWC2 1) set(SOCFPGA_HCD_DWC3 0) @@ -38,68 +62,154 @@ elseif (SOCFPGA_HCD STREQUAL "both") else () message(FATAL_ERROR "SOCFPGA_HCD must be dwc2, dwc3 or both (got '${SOCFPGA_HCD}')") endif () -message(STATUS "SoC FPGA TinyUSB HCD : ${SOCFPGA_HCD}") - -add_subdirectory(${FREERTOS_TOP_DIR}/tinyusb/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb) +message(STATUS "SoC FPGA TinyUSB HCD: ${SOCFPGA_HCD}") -add_library(agilex5-tinyusb STATIC) +get_filename_component(TINYUSB_TOP "${CMAKE_CURRENT_LIST_DIR}/../../.." ABSOLUTE) -target_compile_definitions(agilex5-tinyusb PUBLIC CFG_TUSB_MCU=OPT_MCU_SOCFPGA CFG_TUSB_OS=OPT_OS_FREERTOS BOARD_TUH_MAX_SPEED=${RHPORT_DEVICE_SPEED} - SOCFPGA_HCD_DWC2=${SOCFPGA_HCD_DWC2} SOCFPGA_HCD_DWC3=${SOCFPGA_HCD_DWC3}) +function(socfpga_add_hcd_sources TARGET) + target_compile_definitions(${TARGET} PUBLIC + BOARD_TUD_MAX_SPEED=${RHPORT_DEVICE_SPEED} + BOARD_TUH_MAX_SPEED=${RHPORT_HOST_SPEED} + SOCFPGA_HCD_DWC2=${SOCFPGA_HCD_DWC2} + SOCFPGA_HCD_DWC3=${SOCFPGA_HCD_DWC3} + ) -target_include_directories(agilex5-tinyusb PUBLIC - ${FREERTOS_TOP_DIR}/drivers/usb_otg - ${FREERTOS_TOP_DIR}/tinyusb/src/class/msc - ${FREERTOS_TOP_DIR}/tinyusb/src/common - ${FREERTOS_TOP_DIR}/tinyusb/apps/ - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/ - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc2/ - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci + set(SOCFPGA_DWC2_SRCS + ${TINYUSB_TOP}/src/portable/synopsys/dwc2/hcd_dwc2.c + ${TINYUSB_TOP}/src/portable/synopsys/dwc2/dwc2_common.c ) -# Add TinyUSB target and port source -tinyusb_target_add(agilex5-tinyusb) + set(SOCFPGA_DWC3_SRCS + ${TINYUSB_TOP}/src/portable/synopsys/dwc3/hcd_dwc3.c + ${TINYUSB_TOP}/src/portable/xhci/xhci_common.c + ${TINYUSB_TOP}/src/portable/xhci/xhci.c + ${TINYUSB_TOP}/src/portable/xhci/xhci_cap.c + ${TINYUSB_TOP}/src/portable/xhci/xhci_commands.c + ${TINYUSB_TOP}/src/portable/xhci/xhci_context.c + ${TINYUSB_TOP}/src/portable/xhci/xhci_doorbell.c + ${TINYUSB_TOP}/src/portable/xhci/xhci_endpoints.c + ${TINYUSB_TOP}/src/portable/xhci/xhci_events.c + ${TINYUSB_TOP}/src/portable/xhci/xhci_rings.c + ) -set(SOCFPGA_DWC2_SRCS - # Synopsys dwc2 controller - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc2/hcd_dwc2.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc2/dwc2_common.c + if (SOCFPGA_HCD STREQUAL "both") + target_compile_definitions(${TARGET} PUBLIC + CFG_TUH_HCD_MULTI=1 + CFG_TUH_HCD_MULTI_COUNT=3 ) - -set(SOCFPGA_DWC3_SRCS - # Synopsys dwc3 controller - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/synopsys/dwc3/hcd_dwc3.c - - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_common.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_cap.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_commands.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_context.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_doorbell.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_endpoints.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_events.c - ${FREERTOS_TOP_DIR}/tinyusb/src/portable/xhci/xhci_rings.c -) - -if (SOCFPGA_HCD STREQUAL "both") - # Both unmodified drivers, each with its hcd_* API renamed; hcd_multi.c (added by - # tinyusb_target_add) dispatches per rhport through the BSP table. - target_compile_definitions(agilex5-tinyusb PUBLIC CFG_TUH_HCD_MULTI=1 CFG_TUH_HCD_MULTI_COUNT=3) - tinyusb_hcd_multi_add(agilex5-tinyusb dwc2 ${SOCFPGA_DWC2_SRCS}) - tinyusb_hcd_multi_add(agilex5-tinyusb dwc3 ${SOCFPGA_DWC3_SRCS}) - target_sources(agilex5-tinyusb PRIVATE - ${CMAKE_CURRENT_LIST_DIR}/hcd_socfpga_multi.c - ${FREERTOS_TOP_DIR}/tinyusb/src/host/hcd_multi.c - ) -elseif (SOCFPGA_HCD_DWC2) - target_sources(agilex5-tinyusb PRIVATE ${SOCFPGA_DWC2_SRCS}) -else () - target_sources(agilex5-tinyusb PRIVATE ${SOCFPGA_DWC3_SRCS}) + tinyusb_hcd_multi_add(${TARGET} dwc2 ${SOCFPGA_DWC2_SRCS}) + tinyusb_hcd_multi_add(${TARGET} dwc3 ${SOCFPGA_DWC3_SRCS}) + target_sources(${TARGET} PRIVATE + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/hcd_socfpga_multi.c + ${TINYUSB_TOP}/src/host/hcd_multi.c + ) + elseif (SOCFPGA_HCD STREQUAL "dwc2") + target_sources(${TARGET} PRIVATE ${SOCFPGA_DWC2_SRCS}) + else () + target_sources(${TARGET} PRIVATE ${SOCFPGA_DWC3_SRCS}) + endif () + + if (SOCFPGA_HCD_WERROR) + target_compile_options(${TARGET} PRIVATE -Wall -Wextra -Werror) + endif () +endfunction() + +function(socfpga_add_sdk) + if (TARGET socfpga_drivers) + return() + endif () + + if (NOT SOCFPGA_SDK_FETCHED) + message(FATAL_ERROR + "The Agilex 5 TinyUSB target requires the SoCFPGA SDK build " + "(socfpga_drivers target).") + endif () + + if (NOT SOF_PATH) + set(SOF_PATH "${SOCFPGA_SDK_SOURCE_DIR}/agilex5.sof") + endif () + set(FREERTOS_FATFS OFF) + + add_library(freertos_socfpga STATIC + ${SOCFPGA_SDK_SOURCE_DIR}/FreeRTOS/portable/GCC/ARM_AARCH64/portStandardLib.c) + if (CMAKE_BUILD_TYPE STREQUAL "Debug") + target_compile_options(freertos_socfpga PRIVATE ${DEFAULT_C_FLAGS_DEBUG}) + else () + target_compile_options(freertos_socfpga PRIVATE ${DEFAULT_C_FLAGS_RELEASE}) + endif () + + add_subdirectory(${SOCFPGA_SDK_SOURCE_DIR}/FreeRTOS + ${CMAKE_BINARY_DIR}/socfpga-sdk/FreeRTOS) + add_subdirectory(${SOCFPGA_SDK_SOURCE_DIR}/drivers + ${CMAKE_BINARY_DIR}/socfpga-sdk/drivers) + + get_property(SOCFPGA_DRIVER_INCLUDE_DIRS + TARGET socfpga_drivers PROPERTY INCLUDE_DIRECTORIES) + target_include_directories(freertos_socfpga PUBLIC + ${SOCFPGA_DRIVER_INCLUDE_DIRS}) + target_sources(freertos_socfpga PRIVATE + $) + target_link_libraries(freertos_socfpga PUBLIC freertos_kernel) +endfunction() + +if (TARGET socfpga_drivers) + add_subdirectory(${TINYUSB_TOP}/src ${CMAKE_CURRENT_BINARY_DIR}/tinyusb) + add_library(agilex5-tinyusb STATIC) + target_compile_definitions(agilex5-tinyusb PUBLIC + CFG_TUSB_MCU=OPT_MCU_SOCFPGA + CFG_TUSB_OS=OPT_OS_FREERTOS + ) + target_include_directories(agilex5-tinyusb PUBLIC + ${FREERTOS_TOP_DIR}/drivers/usb_otg + ${TINYUSB_TOP}/src + ${TINYUSB_TOP}/src/class/msc + ${TINYUSB_TOP}/src/common + ${TINYUSB_TOP}/apps + ${TINYUSB_TOP}/src/portable/synopsys/dwc3 + ${TINYUSB_TOP}/src/portable/synopsys/dwc2 + ${TINYUSB_TOP}/src/portable/xhci + ) + tinyusb_target_add(agilex5-tinyusb) + socfpga_add_hcd_sources(agilex5-tinyusb) + target_link_libraries(agilex5-tinyusb PRIVATE socfpga_drivers m) endif () -if (SOCFPGA_HCD_WERROR) - target_compile_options(agilex5-tinyusb PRIVATE -Wall -Wextra -Werror) -endif () +function(family_configure_host_example TARGET RTOS) + socfpga_add_sdk() + family_configure_common(${TARGET} ${RTOS}) + target_sources(${TARGET} PRIVATE + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c + ${SOCFPGA_SDK_SOURCE_DIR}/FreeRTOS/portable/GCC/ARM_AARCH64/portStandardLib.c + ) + target_include_directories(${TARGET} PUBLIC + ${TINYUSB_TOP}/hw + ${TINYUSB_TOP}/src/common + ${TINYUSB_TOP}/src/class/msc + ${TINYUSB_TOP}/apps + ${TINYUSB_TOP}/src/portable/xhci + ${CMAKE_CURRENT_FUNCTION_LIST_DIR} + ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD} + ) + target_compile_definitions(${TARGET} PUBLIC + CFG_TUSB_MCU=OPT_MCU_SOCFPGA + CFG_TUSB_OS=OPT_OS_FREERTOS + BOARD_TUH_RHPORT=${RHPORT_HOST} + SOCFPGA_USB3_HS_PORT=1 + SOCFPGA_USB3_SS_PORT=2 + ) + + family_add_tinyusb(${TARGET} OPT_MCU_SOCFPGA) + socfpga_add_hcd_sources(${TARGET}) + target_link_libraries(${TARGET} PUBLIC + freertos_socfpga + freertos_kernel + socfpga_drivers + m + ) + target_link_options(${TARGET} PRIVATE + "LINKER:--script=${LD_FILE_GNU}" + ) -target_link_libraries(agilex5-tinyusb PRIVATE socfpga_drivers m) + family_add_bin_hex(${TARGET}) +endfunction() diff --git a/hw/bsp/socfpga/socfpga_sdk_import.cmake b/hw/bsp/socfpga/socfpga_sdk_import.cmake new file mode 100644 index 000000000..74a07e545 --- /dev/null +++ b/hw/bsp/socfpga/socfpga_sdk_import.cmake @@ -0,0 +1,28 @@ +include_guard(GLOBAL) + +if (DEFINED FREERTOS_TOP_DIR AND + EXISTS "${FREERTOS_TOP_DIR}/tools/target_socfpga.cmake") + set(SOCFPGA_SDK_SOURCE_DIR "${FREERTOS_TOP_DIR}") +else () + include(FetchContent) + + FetchContent_Declare( + socfpga_sdk + GIT_REPOSITORY https://github.com/Ignitarium-Software/freertos-socfpga.git + GIT_TAG v26.1.1 + ) + + FetchContent_GetProperties(socfpga_sdk) + if (NOT socfpga_sdk_POPULATED) + FetchContent_Populate(socfpga_sdk) + endif () + + set(SOCFPGA_SDK_SOURCE_DIR "${socfpga_sdk_SOURCE_DIR}") + set(SOCFPGA_SDK_FETCHED TRUE) +endif () + +if (NOT DEFINED FREERTOS_TOP_DIR) + set(FREERTOS_TOP_DIR "${SOCFPGA_SDK_SOURCE_DIR}") +endif () + +set(LINKER_SCRIPT "${SOCFPGA_SDK_SOURCE_DIR}/lscript.ld") From 8f72c8c6b5623512d3f987e8ddfa161f151c4365 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Fri, 27 Nov 2026 10:42:23 +0530 Subject: [PATCH 16/17] examples: add msc_file explorer freertos * samlple freertos application for msc Signed-off-by: Sourav Raj K K --- .../msc_file_explorer_freertos/CMakeLists.txt | 47 ++ .../CMakePresets.json | 6 + .../host/msc_file_explorer_freertos/Makefile | 27 + .../host/msc_file_explorer_freertos/only.txt | 24 + .../msc_file_explorer_freertos/src/main.c | 148 ++++ .../msc_file_explorer_freertos/src/msc_app.c | 644 ++++++++++++++++++ .../msc_file_explorer_freertos/src/msc_app.h | 35 + .../src/tusb_config.h | 128 ++++ 8 files changed, 1059 insertions(+) create mode 100644 examples/host/msc_file_explorer_freertos/CMakeLists.txt create mode 100644 examples/host/msc_file_explorer_freertos/CMakePresets.json create mode 100644 examples/host/msc_file_explorer_freertos/Makefile create mode 100644 examples/host/msc_file_explorer_freertos/only.txt create mode 100644 examples/host/msc_file_explorer_freertos/src/main.c create mode 100644 examples/host/msc_file_explorer_freertos/src/msc_app.c create mode 100644 examples/host/msc_file_explorer_freertos/src/msc_app.h create mode 100644 examples/host/msc_file_explorer_freertos/src/tusb_config.h diff --git a/examples/host/msc_file_explorer_freertos/CMakeLists.txt b/examples/host/msc_file_explorer_freertos/CMakeLists.txt new file mode 100644 index 000000000..75fe13005 --- /dev/null +++ b/examples/host/msc_file_explorer_freertos/CMakeLists.txt @@ -0,0 +1,47 @@ +cmake_minimum_required(VERSION 3.20) + +include(${CMAKE_CURRENT_SOURCE_DIR}/../../../hw/bsp/family_support.cmake) + +# gets PROJECT name for the example (e.g. -) +family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) + +project(${PROJECT} C CXX ASM) + +# Checks this example is valid for the family and initializes the project +family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) + +# Espressif has its own cmake build system +if(FAMILY STREQUAL "espressif") + return() +endif() + +add_executable(${PROJECT}) + +# Example source +target_sources(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src/main.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/msc_app.c + ${TOP}/lib/fatfs/source/ff.c + ${TOP}/lib/fatfs/source/ffsystem.c + ${TOP}/lib/fatfs/source/ffunicode.c + ) + +# Suppress warnings on fatfs +if (CMAKE_C_COMPILER_ID STREQUAL "GNU") + set_source_files_properties( + ${TOP}/lib/fatfs/source/ff.c + PROPERTIES + COMPILE_FLAGS "-Wno-conversion -Wno-cast-qual" + ) +endif () + +# Example include +target_include_directories(${PROJECT} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/src + ${TOP}/lib/fatfs/source + ${TOP}/lib/embedded-cli + ) + +# Configure compilation flags and libraries for the example without RTOS. +# See the corresponding function in hw/bsp/FAMILY/family.cmake for details. +family_configure_host_example(${PROJECT} freertos) diff --git a/examples/host/msc_file_explorer_freertos/CMakePresets.json b/examples/host/msc_file_explorer_freertos/CMakePresets.json new file mode 100644 index 000000000..5cd8971e9 --- /dev/null +++ b/examples/host/msc_file_explorer_freertos/CMakePresets.json @@ -0,0 +1,6 @@ +{ + "version": 6, + "include": [ + "../../../hw/bsp/BoardPresets.json" + ] +} diff --git a/examples/host/msc_file_explorer_freertos/Makefile b/examples/host/msc_file_explorer_freertos/Makefile new file mode 100644 index 000000000..f0872376f --- /dev/null +++ b/examples/host/msc_file_explorer_freertos/Makefile @@ -0,0 +1,27 @@ +include ../../build_system/make/make.mk + +FATFS_PATH = lib/fatfs/source + +INC += \ + src \ + $(TOP)/hw \ + $(TOP)/$(FATFS_PATH) \ + $(TOP)/lib/embedded-cli \ + +# Example source +EXAMPLE_SOURCE = \ + src/main.c \ + src/msc_app.c \ + +SRC_C += $(addprefix $(CURRENT_PATH)/, $(EXAMPLE_SOURCE)) + +# FatFS source +SRC_C += \ + $(FATFS_PATH)/ff.c \ + $(FATFS_PATH)/ffsystem.c \ + $(FATFS_PATH)/ffunicode.c \ + +# suppress warning caused by fatfs +CFLAGS_GCC += -Wno-error=cast-qual + +include ../../build_system/make/rules.mk diff --git a/examples/host/msc_file_explorer_freertos/only.txt b/examples/host/msc_file_explorer_freertos/only.txt new file mode 100644 index 000000000..a400b2332 --- /dev/null +++ b/examples/host/msc_file_explorer_freertos/only.txt @@ -0,0 +1,24 @@ +mcu:CH32V20X +mcu:KINETIS_KL +mcu:LPC175X_6X +mcu:LPC177X_8X +mcu:LPC18XX +mcu:LPC40XX +mcu:LPC43XX +mcu:MIMXRT1XXX +mcu:MIMXRT10XX +mcu:MIMXRT11XX +mcu:RP2040 +mcu:MSP432E4 +mcu:RX65X +mcu:RAXXX +mcu:MAX3421 +mcu:STM32F4 +mcu:STM32F7 +mcu:STM32H7 +mcu:STM32H7RS +mcu:STM32N6 +family:samd21 +family:samd5x_e5x +family:agilex5 +family:socfpga diff --git a/examples/host/msc_file_explorer_freertos/src/main.c b/examples/host/msc_file_explorer_freertos/src/main.c new file mode 100644 index 000000000..b13b0602e --- /dev/null +++ b/examples/host/msc_file_explorer_freertos/src/main.c @@ -0,0 +1,148 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +/* Example to show how to navigate mass storage device with built-in command line. + * Type help for list of supported commands and syntax (mostly linux commands) + + > help + * help + Print list of commands + * cat + Usage: cat [FILE]... + Concatenate FILE(s) to standard output.. + * cd + Usage: cd [DIR]... + Change the current directory to DIR. + * cp + Usage: cp SOURCE DEST + Copy SOURCE to DEST. + * ls + Usage: ls [DIR]... + List information about the FILEs (the current directory by default). + * pwd + Usage: pwd + Print the name of the current working directory. + * mkdir + Usage: mkdir DIR... + Create the DIRECTORY(ies), if they do not already exist.. + * mv + Usage: mv SOURCE DEST... + Rename SOURCE to DEST. + * rm + Usage: rm [FILE]... + Remove (unlink) the FILE(s). + */ + +#include +#include +#include + +#include "bsp/board_api.h" +#include "tusb.h" + +#include "msc_app.h" + +//--------------------------------------------------------------------+ +// MACRO CONSTANT TYPEDEF PROTYPES +//--------------------------------------------------------------------+ + +#define USBH_STACK_SIZE (3*configMINIMAL_STACK_SIZE/2) * (CFG_TUSB_DEBUG ? 2 : 1) + +void led_blinking_task(void); + +static void usb_host_task(void *param); + +/*------------- MAIN -------------*/ +int main(void) { + board_init(); + + printf("TinyUSB Host MassStorage Explorer Example\r\n"); + + xTaskCreate(usb_host_task, "usbd", USBH_STACK_SIZE, NULL, configMAX_PRIORITIES-1, NULL); + + vTaskStartScheduler(); + + return 0; +} + +// USB Host task +// This top level thread process all usb events and invoke callbacks +static void usb_host_task(void *param) { + (void) param; + + // init host stack on configured roothub port + tusb_rhport_init_t host_init = { + .role = TUSB_ROLE_HOST, + .speed = TUSB_SPEED_AUTO + }; + + if (!tusb_init(BOARD_TUH_RHPORT, &host_init)) { + printf("Failed to init USB Host Stack\r\n"); + vTaskSuspend(NULL); + } + + board_init_after_tusb(); + + msc_app_init(); + + // RTOS forever loop + while (1) { + // put this thread to waiting state until there is new events + tuh_task(); + + msc_app_task(); + + osal_task_delay(10); + } +} + +//--------------------------------------------------------------------+ +// TinyUSB Callbacks +//--------------------------------------------------------------------+ + +void tuh_mount_cb(uint8_t dev_addr) { + (void) dev_addr; +} + +void tuh_umount_cb(uint8_t dev_addr) { + (void) dev_addr; +} + +//--------------------------------------------------------------------+ +// Blinking Task +//--------------------------------------------------------------------+ +void led_blinking_task(void) { + const uint32_t interval_ms = 1000; + static uint32_t start_ms = 0; + + static bool led_state = false; + + // Blink every interval ms + if (board_millis() - start_ms < interval_ms) return; // not enough time + start_ms += interval_ms; + + board_led_write(led_state); + led_state = 1 - led_state; // toggle +} diff --git a/examples/host/msc_file_explorer_freertos/src/msc_app.c b/examples/host/msc_file_explorer_freertos/src/msc_app.c new file mode 100644 index 000000000..40a9ef57e --- /dev/null +++ b/examples/host/msc_file_explorer_freertos/src/msc_app.c @@ -0,0 +1,644 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#include +#include "tusb.h" +#include "bsp/board_api.h" + +#include "ff.h" +#include "diskio.h" + +// lib/embedded-cli +#define EMBEDDED_CLI_IMPL +#include "embedded_cli.h" + +#include "msc_app.h" + + +//--------------------------------------------------------------------+ +// MACRO TYPEDEF CONSTANT ENUM DECLARATION +//--------------------------------------------------------------------+ + +//------------- embedded-cli -------------// +#define CLI_BUFFER_SIZE 512 +#define CLI_RX_BUFFER_SIZE 16 +#define CLI_CMD_BUFFER_SIZE 64 +#define CLI_HISTORY_SIZE 32 +#define CLI_BINDING_COUNT 8 + +static EmbeddedCli *_cli; +static CLI_UINT cli_buffer[BYTES_TO_CLI_UINTS(CLI_BUFFER_SIZE)]; + +//------------- Elm Chan FatFS -------------// +static FATFS fatfs[CFG_TUH_DEVICE_MAX]; // for simplicity only support 1 LUN per device +static volatile bool _disk_busy[CFG_TUH_DEVICE_MAX]; + +// define the buffer to be place in USB/DMA memory with correct alignment/cache line size +CFG_TUH_MEM_SECTION static struct { + TUH_EPBUF_TYPE_DEF(scsi_inquiry_resp_t, inquiry); +} scsi_resp; + + +//--------------------------------------------------------------------+ +// +//--------------------------------------------------------------------+ + +bool cli_init(void); + +bool msc_app_init(void) +{ + for(size_t i=0; i 0 ) + { + while( ch > 0 ) + { + embeddedCliReceiveChar(_cli, (char) ch); + ch = board_getchar(); + } + embeddedCliProcess(_cli); + } +} + +//--------------------------------------------------------------------+ +// +//--------------------------------------------------------------------+ + +static bool inquiry_complete_cb(uint8_t dev_addr, tuh_msc_complete_data_t const * cb_data) { + msc_cbw_t const* cbw = cb_data->cbw; + msc_csw_t const* csw = cb_data->csw; + + if (csw->status != 0) + { + printf("Inquiry failed\r\n"); + return false; + } + + // Print out Vendor ID, Product ID and Rev + printf("%.8s %.16s rev %.4s\r\n", scsi_resp.inquiry.vendor_id, scsi_resp.inquiry.product_id, scsi_resp.inquiry.product_rev); + + // Get capacity of device + uint32_t const block_count = tuh_msc_get_block_count(dev_addr, cbw->lun); + uint32_t const block_size = tuh_msc_get_block_size(dev_addr, cbw->lun); + + printf("Disk Size: %" PRIu32 " MB\r\n", block_count / ((1024*1024)/block_size)); + // printf("Block Count = %lu, Block Size: %lu\r\n", block_count, block_size); + + // For simplicity: we only mount 1 LUN per device + uint8_t const drive_num = dev_addr-1; + char drive_path[3] = "0:"; + drive_path[0] += drive_num; + + if ( f_mount(&fatfs[drive_num], drive_path, 1) != FR_OK ) + { + puts("mount failed"); + } + + // change to newly mounted drive + f_chdir(drive_path); + + // print the drive label +// char label[34]; +// if ( FR_OK == f_getlabel(drive_path, label, NULL) ) +// { +// puts(label); +// } + + return true; +} + +//------------- IMPLEMENTATION -------------// +void tuh_msc_mount_cb(uint8_t dev_addr) +{ + printf("A MassStorage device is mounted\r\n"); + + uint8_t const lun = 0; + tuh_msc_inquiry(dev_addr, lun, &scsi_resp.inquiry, inquiry_complete_cb, 0); +} + +void tuh_msc_umount_cb(uint8_t dev_addr) +{ + printf("A MassStorage device is unmounted\r\n"); + + uint8_t const drive_num = dev_addr-1; + char drive_path[3] = "0:"; + drive_path[0] += drive_num; + + f_unmount(drive_path); + +// if ( phy_disk == f_get_current_drive() ) +// { // active drive is unplugged --> change to other drive +// for(uint8_t i=0; icliBuffer = cli_buffer; + config->cliBufferSize = CLI_BUFFER_SIZE; + config->rxBufferSize = CLI_RX_BUFFER_SIZE; + config->cmdBufferSize = CLI_CMD_BUFFER_SIZE; + config->historyBufferSize = CLI_HISTORY_SIZE; + config->maxBindingCount = CLI_BINDING_COUNT; + + TU_ASSERT(embeddedCliRequiredSize(config) <= CLI_BUFFER_SIZE); + + _cli = embeddedCliNew(config); + TU_ASSERT(_cli != NULL); + + _cli->writeChar = cli_write_char; + + embeddedCliAddBinding(_cli, (CliCommandBinding) { + "cat", + "Usage: cat [FILE]...\r\n\tConcatenate FILE(s) to standard output..", + true, + NULL, + cli_cmd_cat + }); + + embeddedCliAddBinding(_cli, (CliCommandBinding) { + "cd", + "Usage: cd [DIR]...\r\n\tChange the current directory to DIR.", + true, + NULL, + cli_cmd_cd + }); + + embeddedCliAddBinding(_cli, (CliCommandBinding) { + "cp", + "Usage: cp SOURCE DEST\r\n\tCopy SOURCE to DEST.", + true, + NULL, + cli_cmd_cp + }); + + embeddedCliAddBinding(_cli, (CliCommandBinding) { + "ls", + "Usage: ls [DIR]...\r\n\tList information about the FILEs (the current directory by default).", + true, + NULL, + cli_cmd_ls + }); + + embeddedCliAddBinding(_cli, (CliCommandBinding) { + "pwd", + "Usage: pwd\r\n\tPrint the name of the current working directory.", + true, + NULL, + cli_cmd_pwd + }); + + embeddedCliAddBinding(_cli, (CliCommandBinding) { + "mkdir", + "Usage: mkdir DIR...\r\n\tCreate the DIRECTORY(ies), if they do not already exist..", + true, + NULL, + cli_cmd_mkdir + }); + + embeddedCliAddBinding(_cli, (CliCommandBinding) { + "mv", + "Usage: mv SOURCE DEST...\r\n\tRename SOURCE to DEST.", + true, + NULL, + cli_cmd_mv + }); + + embeddedCliAddBinding(_cli, (CliCommandBinding) { + "rm", + "Usage: rm [FILE]...\r\n\tRemove (unlink) the FILE(s).", + true, + NULL, + cli_cmd_rm + }); + + return true; +} + +void cli_cmd_cat(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + + uint16_t argc = embeddedCliGetTokenCount(args); + + // need at least 1 argument + if ( argc == 0 ) + { + printf("invalid arguments\r\n"); + return; + } + + for(uint16_t i=0; i 0) ) + { + for(UINT c = 0; c < count; c++) + { + const uint8_t ch = buf[c]; + if (isprint(ch) || iscntrl(ch)) + { + putchar(ch); + }else + { + putchar('.'); + } + } + } + } + + f_close(&fi); + } +} + +void cli_cmd_cd(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + + uint16_t argc = embeddedCliGetTokenCount(args); + + // only support 1 argument + if ( argc != 1 ) + { + printf("invalid arguments\r\n"); + return; + } + + // default is current directory + const char* dpath = args; + + if ( FR_OK != f_chdir(dpath) ) + { + printf("%s: No such file or directory\r\n", dpath); + return; + } +} + +void cli_cmd_cp(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + + uint16_t argc = embeddedCliGetTokenCount(args); + if ( argc != 2 ) + { + printf("invalid arguments\r\n"); + return; + } + + // default is current directory + const char* src = embeddedCliGetToken(args, 1); + const char* dst = embeddedCliGetToken(args, 2); + + FIL f_src; + FIL f_dst; + + if ( FR_OK != f_open(&f_src, src, FA_READ) ) + { + printf("cannot stat '%s': No such file or directory\r\n", src); + return; + } + + if ( FR_OK != f_open(&f_dst, dst, FA_WRITE | FA_CREATE_ALWAYS) ) + { + printf("cannot create '%s'\r\n", dst); + return; + }else + { + uint8_t buf[512]; + UINT rd_count = 0; + while ( (FR_OK == f_read(&f_src, buf, sizeof(buf), &rd_count)) && (rd_count > 0) ) + { + UINT wr_count = 0; + + if ( FR_OK != f_write(&f_dst, buf, rd_count, &wr_count) ) + { + printf("cannot write to '%s'\r\n", dst); + break; + } + } + } + + f_close(&f_src); + f_close(&f_dst); +} + +void cli_cmd_ls(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + + uint16_t argc = embeddedCliGetTokenCount(args); + + // only support 1 argument + if ( argc > 1 ) + { + printf("invalid arguments\r\n"); + return; + } + + // default is current directory + const char* dpath = "."; + if (argc) dpath = args; + + DIR dir; + if ( FR_OK != f_opendir(&dir, dpath) ) + { + printf("cannot access '%s': No such file or directory\r\n", dpath); + return; + } + + FILINFO fno; + while( (f_readdir(&dir, &fno) == FR_OK) && (fno.fname[0] != 0) ) + { + if ( fno.fname[0] != '.' ) // ignore . and .. entry + { + if ( fno.fattrib & AM_DIR ) + { + // directory + printf("/%s\r\n", fno.fname); + }else + { + printf("%-40s", fno.fname); + if (fno.fsize < 1024) + { + printf("%" PRIu32 " B\r\n", fno.fsize); + }else + { + printf("%" PRIu32 " KB\r\n", fno.fsize / 1024); + } + } + } + } + + f_closedir(&dir); +} + +void cli_cmd_pwd(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + uint16_t argc = embeddedCliGetTokenCount(args); + + if (argc != 0) + { + printf("invalid arguments\r\n"); + return; + } + + char path[256]; + if (FR_OK != f_getcwd(path, sizeof(path))) + { + printf("cannot get current working directory\r\n"); + } + + puts(path); +} + +void cli_cmd_mkdir(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + + uint16_t argc = embeddedCliGetTokenCount(args); + + // only support 1 argument + if ( argc != 1 ) + { + printf("invalid arguments\r\n"); + return; + } + + // default is current directory + const char* dpath = args; + + if ( FR_OK != f_mkdir(dpath) ) + { + printf("%s: cannot create this directory\r\n", dpath); + return; + } +} + +void cli_cmd_mv(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + + uint16_t argc = embeddedCliGetTokenCount(args); + if ( argc != 2 ) + { + printf("invalid arguments\r\n"); + return; + } + + // default is current directory + const char* src = embeddedCliGetToken(args, 1); + const char* dst = embeddedCliGetToken(args, 2); + + if ( FR_OK != f_rename(src, dst) ) + { + printf("cannot mv %s to %s\r\n", src, dst); + return; + } +} + +void cli_cmd_rm(EmbeddedCli *cli, char *args, void *context) +{ + (void) cli; (void) context; + + uint16_t argc = embeddedCliGetTokenCount(args); + + // need at least 1 argument + if ( argc == 0 ) + { + printf("invalid arguments\r\n"); + return; + } + + for(uint16_t i=0; i + +bool msc_app_init(void); +void msc_app_task(void); + + +#endif diff --git a/examples/host/msc_file_explorer_freertos/src/tusb_config.h b/examples/host/msc_file_explorer_freertos/src/tusb_config.h new file mode 100644 index 000000000..d128ec052 --- /dev/null +++ b/examples/host/msc_file_explorer_freertos/src/tusb_config.h @@ -0,0 +1,128 @@ +/* + * The MIT License (MIT) + * + * Copyright (c) 2019 Ha Thach (tinyusb.org) + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + */ + +#ifndef _TUSB_CONFIG_H_ +#define _TUSB_CONFIG_H_ + +#ifdef __cplusplus + extern "C" { +#endif + +//-------------------------------------------------------------------- +// USB ports in socfpga is configured as below +//-------------------------------------------------------------------- +#define SOCFPGA_USB2_OTG_PORT (0) +#define SOCFPGA_USB3_HS_PORT (1) +#define SOCFPGA_USB3_SS_PORT (2) + +//-------------------------------------------------------------------- +// Common Configuration +//-------------------------------------------------------------------- + +// defined by compiler flags for flexibility +#ifndef CFG_TUSB_MCU +#error CFG_TUSB_MCU must be defined +#endif + +#ifndef CFG_TUSB_OS +#define CFG_TUSB_OS OPT_OS_FREERTOS +#endif + +#ifndef CFG_TUSB_DEBUG +#define CFG_TUSB_DEBUG 0 +#endif + +/* USB DMA on some MCUs can only access a specific SRAM region with restriction on alignment. + * Tinyusb use follows macros to declare transferring memory so that they can be put + * into those specific section. + * e.g + * - CFG_TUSB_MEM SECTION : __attribute__ (( section(".usb_ram") )) + * - CFG_TUSB_MEM_ALIGN : __attribute__ ((aligned(4))) + */ +#ifndef CFG_TUH_MEM_SECTION +#define CFG_TUH_MEM_SECTION +#endif + +#ifndef CFG_TUH_MEM_ALIGN +#define CFG_TUH_MEM_ALIGN __attribute__ ((aligned(4))) +#endif + +//-------------------------------------------------------------------- +// Host Configuration +//-------------------------------------------------------------------- + +// Enable Host stack +#define CFG_TUH_ENABLED 1 + +// #define CFG_TUH_MAX3421 1 // use max3421 as host controller + +#if CFG_TUSB_MCU == OPT_MCU_RP2040 + // #define CFG_TUH_RPI_PIO_USB 1 // use pio-usb as host controller + + // host roothub port is 1 if using either pio-usb or max3421 + #if (defined(CFG_TUH_RPI_PIO_USB) && CFG_TUH_RPI_PIO_USB) || (defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421) + #define BOARD_TUH_RHPORT 1 + #endif +#endif + +// Default is max speed that hardware controller could support with on-chip PHY +#define CFG_TUH_MAX_SPEED BOARD_TUH_MAX_SPEED + +//------------------------- Board Specific -------------------------- + +// RHPort number used for host can be defined by board.mk, default to port 0 +#ifndef BOARD_TUH_RHPORT +#define BOARD_TUH_RHPORT 0 +#endif + +// RHPort max operational speed can defined by board.mk +#ifndef BOARD_TUH_MAX_SPEED +#define BOARD_TUH_MAX_SPEED OPT_MODE_DEFAULT_SPEED +#endif + +//-------------------------------------------------------------------- +// Driver Configuration +//-------------------------------------------------------------------- + +// Size of buffer to hold descriptors and other data used for enumeration +#define CFG_TUH_ENUMERATION_BUFSIZE 256 + +#define CFG_TUH_HUB 1 // number of supported hubs +#define CFG_TUH_MSC 1 +#define CFG_TUH_CDC 0 +#define CFG_TUH_HID 0 // typical keyboard + mouse device can have 3-4 HID interfaces +#define CFG_TUH_VENDOR 0 + +// max device support (excluding hub device): 1 hub typically has 4 ports +#define CFG_TUH_DEVICE_MAX (3*CFG_TUH_HUB + 1) + +//------------- MSC -------------// +#define CFG_TUH_MSC_MAXLUN 4 // typical for most card reader + +#ifdef __cplusplus + } +#endif + +#endif /* _TUSB_CONFIG_H_ */ From cbbca355c393e5c1423238266d393e6ea173d016 Mon Sep 17 00:00:00 2001 From: Sourav Raj K K Date: Fri, 27 Nov 2026 16:29:55 +0530 Subject: [PATCH 17/17] fix Cmake compilation warinings Signed-off-by: Sourav Raj K K --- hw/bsp/socfpga/family.cmake | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hw/bsp/socfpga/family.cmake b/hw/bsp/socfpga/family.cmake index 0a4a9e687..7262cae0b 100644 --- a/hw/bsp/socfpga/family.cmake +++ b/hw/bsp/socfpga/family.cmake @@ -174,13 +174,14 @@ if (TARGET socfpga_drivers) target_link_libraries(agilex5-tinyusb PRIVATE socfpga_drivers m) endif () +set(TINYUSB_WARNS -Wno-unused-function -Wno-missing-prototypes -Wno-strict-prototypes -Wno-old-style-declaration -Wno-undef -Wno-unused-variable -Wno-redundant-decls) + function(family_configure_host_example TARGET RTOS) socfpga_add_sdk() family_configure_common(${TARGET} ${RTOS}) target_sources(${TARGET} PRIVATE ${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c - ${SOCFPGA_SDK_SOURCE_DIR}/FreeRTOS/portable/GCC/ARM_AARCH64/portStandardLib.c ) target_include_directories(${TARGET} PUBLIC ${TINYUSB_TOP}/hw @@ -199,6 +200,8 @@ function(family_configure_host_example TARGET RTOS) SOCFPGA_USB3_SS_PORT=2 ) + target_compile_options(${TARGET} PUBLIC ${DEFAULT_C_FLAGS_DEBUG} ${TINYUSB_WARNS}) + family_add_tinyusb(${TARGET} OPT_MCU_SOCFPGA) socfpga_add_hcd_sources(${TARGET}) target_link_libraries(${TARGET} PUBLIC