From a77e5cc718de7c582f29e8fde5e8019e24046f4e Mon Sep 17 00:00:00 2001 From: Darian Leung Date: Thu, 14 Mar 2024 21:20:33 +0800 Subject: [PATCH] refactor(hal/usb): Remove usb_fsls_phy_ll.h For targets that only contain a USJ peripheral (and not a DWC OTG), their 'usb_fsls_phy_ll.h' headers only contain a single function ('usb_fsls_phy_ll_int_jtag_enable()') whose feature is already covered by functions in 'usb_serial_jtag_ll.h'. Thus, this header is redundant. This commit does the following: - Remove 'usb_fsls_phy_ll.h' for targets that only contain a USJ peripheral - Rename 'usb_fsls_phy_[hal|ll].[h|c]' to `usb_wrap_[hal|ll].[h|c]` for targets that contain a DWC OTG peripheral. This better reflects the underlying peripheral that the LL header accesses. --- .../src/bootloader_console.c | 5 +- .../src/usb_serial_jtag.c | 4 +- components/esp_system/port/soc/esp32c3/clk.c | 3 +- components/esp_system/port/soc/esp32c6/clk.c | 3 +- components/esp_system/port/soc/esp32h2/clk.c | 3 +- components/esp_system/port/soc/esp32s3/clk.c | 3 +- components/hal/CMakeLists.txt | 2 +- .../hal/esp32c3/include/hal/usb_fsls_phy_ll.h | 47 ------------------- .../hal/esp32c6/include/hal/usb_fsls_phy_ll.h | 47 ------------------- .../hal/esp32h2/include/hal/usb_fsls_phy_ll.h | 47 ------------------- .../hal/{usb_fsls_phy_ll.h => usb_wrap_ll.h} | 0 .../hal/{usb_fsls_phy_ll.h => usb_wrap_ll.h} | 0 .../{usb_fsls_phy_hal.h => usb_wrap_hal.h} | 0 .../{usb_fsls_phy_hal.c => usb_wrap_hal.c} | 22 +++++++-- components/usb/usb_phy.c | 4 +- 15 files changed, 30 insertions(+), 160 deletions(-) delete mode 100644 components/hal/esp32c3/include/hal/usb_fsls_phy_ll.h delete mode 100644 components/hal/esp32c6/include/hal/usb_fsls_phy_ll.h delete mode 100644 components/hal/esp32h2/include/hal/usb_fsls_phy_ll.h rename components/hal/esp32s2/include/hal/{usb_fsls_phy_ll.h => usb_wrap_ll.h} (100%) rename components/hal/esp32s3/include/hal/{usb_fsls_phy_ll.h => usb_wrap_ll.h} (100%) rename components/hal/include/hal/{usb_fsls_phy_hal.h => usb_wrap_hal.h} (100%) rename components/hal/{usb_fsls_phy_hal.c => usb_wrap_hal.c} (68%) diff --git a/components/bootloader_support/src/bootloader_console.c b/components/bootloader_support/src/bootloader_console.c index da047055a9..066eac3114 100644 --- a/components/bootloader_support/src/bootloader_console.c +++ b/components/bootloader_support/src/bootloader_console.c @@ -6,6 +6,7 @@ #include "sdkconfig.h" #include "bootloader_console.h" +#include "soc/soc_caps.h" #include "soc/uart_periph.h" #include "soc/uart_channel.h" #include "soc/io_mux_reg.h" @@ -18,8 +19,8 @@ #include "esp32s2/rom/usb/cdc_acm.h" #include "esp32s2/rom/usb/usb_common.h" #endif -#if SOC_USB_SERIAL_JTAG_SUPPORTED -#include "hal/usb_fsls_phy_ll.h" +#if CONFIG_ESP_CONSOLE_USB_CDC && SOC_USB_SERIAL_JTAG_SUPPORTED +#include "hal/usb_wrap_ll.h" #endif #include "esp_rom_gpio.h" #include "esp_rom_uart.h" diff --git a/components/esp_driver_usb_serial_jtag/src/usb_serial_jtag.c b/components/esp_driver_usb_serial_jtag/src/usb_serial_jtag.c index 06130db5b3..c2427b0c5a 100644 --- a/components/esp_driver_usb_serial_jtag/src/usb_serial_jtag.c +++ b/components/esp_driver_usb_serial_jtag/src/usb_serial_jtag.c @@ -9,7 +9,6 @@ #include #include "esp_log.h" #include "hal/usb_serial_jtag_ll.h" -#include "hal/usb_fsls_phy_ll.h" #include "freertos/FreeRTOS.h" #include "freertos/semphr.h" #include "freertos/ringbuf.h" @@ -187,7 +186,8 @@ esp_err_t usb_serial_jtag_driver_install(usb_serial_jtag_driver_config_t *usb_se atomic_store(&p_usb_serial_jtag_obj->fifo_status, FIFO_IDLE); // Configure PHY - usb_fsls_phy_ll_int_jtag_enable(&USB_SERIAL_JTAG); + usb_serial_jtag_ll_phy_enable_external(false); // Use internal PHY + usb_serial_jtag_ll_phy_enable_pad(true); // Enable USB PHY pads usb_serial_jtag_ll_clr_intsts_mask(USB_SERIAL_JTAG_INTR_SERIAL_IN_EMPTY | USB_SERIAL_JTAG_INTR_SERIAL_OUT_RECV_PKT); diff --git a/components/esp_system/port/soc/esp32c3/clk.c b/components/esp_system/port/soc/esp32c3/clk.c index 1ab7f7bd87..e9914ae17b 100644 --- a/components/esp_system/port/soc/esp32c3/clk.c +++ b/components/esp_system/port/soc/esp32c3/clk.c @@ -22,7 +22,6 @@ #include "soc/i2s_reg.h" #include "hal/wdt_hal.h" #include "hal/usb_serial_jtag_ll.h" -#include "hal/usb_fsls_phy_ll.h" #include "esp_private/periph_ctrl.h" #include "esp_private/esp_clk.h" #include "soc/syscon_reg.h" @@ -246,7 +245,7 @@ __attribute__((weak)) void esp_perip_clk_init(void) #if !CONFIG_USJ_ENABLE_USB_SERIAL_JTAG && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED // Disable USB-Serial-JTAG clock and it's pad if not used - usb_fsls_phy_ll_int_jtag_disable(&USB_SERIAL_JTAG); + usb_serial_jtag_ll_phy_enable_pad(false); _usb_serial_jtag_ll_enable_bus_clock(false); #endif } diff --git a/components/esp_system/port/soc/esp32c6/clk.c b/components/esp_system/port/soc/esp32c6/clk.c index 19d87dfcd1..81ca7becae 100644 --- a/components/esp_system/port/soc/esp32c6/clk.c +++ b/components/esp_system/port/soc/esp32c6/clk.c @@ -40,7 +40,6 @@ #include "hal/lp_core_ll.h" #include "hal/temperature_sensor_ll.h" #include "hal/usb_serial_jtag_ll.h" -#include "hal/usb_fsls_phy_ll.h" #include "esp_private/esp_modem_clock.h" #include "esp_private/periph_ctrl.h" #include "esp_private/esp_clk.h" @@ -282,7 +281,7 @@ __attribute__((weak)) void esp_perip_clk_init(void) #if !CONFIG_USJ_ENABLE_USB_SERIAL_JTAG && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED // Disable USB-Serial-JTAG clock and it's pad if not used - usb_fsls_phy_ll_int_jtag_disable(&USB_SERIAL_JTAG); + usb_serial_jtag_ll_phy_enable_pad(false); usb_serial_jtag_ll_enable_bus_clock(false); #endif } diff --git a/components/esp_system/port/soc/esp32h2/clk.c b/components/esp_system/port/soc/esp32h2/clk.c index e78a701b26..20c4df2f5a 100644 --- a/components/esp_system/port/soc/esp32h2/clk.c +++ b/components/esp_system/port/soc/esp32h2/clk.c @@ -41,7 +41,6 @@ #include "hal/clk_gate_ll.h" #include "hal/temperature_sensor_ll.h" #include "hal/usb_serial_jtag_ll.h" -#include "hal/usb_fsls_phy_ll.h" #include "esp_private/periph_ctrl.h" #include "esp_private/esp_clk.h" #include "esp_private/esp_pmu.h" @@ -273,7 +272,7 @@ __attribute__((weak)) void esp_perip_clk_init(void) #if !CONFIG_USJ_ENABLE_USB_SERIAL_JTAG && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED // Disable USB-Serial-JTAG clock and it's pad if not used - usb_fsls_phy_ll_int_jtag_disable(&USB_SERIAL_JTAG); + usb_serial_jtag_ll_phy_enable_pad(false); usb_serial_jtag_ll_enable_bus_clock(false); #endif } diff --git a/components/esp_system/port/soc/esp32s3/clk.c b/components/esp_system/port/soc/esp32s3/clk.c index 16c8986b96..f1c55204c8 100644 --- a/components/esp_system/port/soc/esp32s3/clk.c +++ b/components/esp_system/port/soc/esp32s3/clk.c @@ -22,7 +22,6 @@ #include "soc/i2s_reg.h" #include "hal/wdt_hal.h" #include "hal/usb_serial_jtag_ll.h" -#include "hal/usb_fsls_phy_ll.h" #include "esp_private/periph_ctrl.h" #include "esp_private/esp_clk.h" #include "bootloader_clock.h" @@ -265,7 +264,7 @@ __attribute__((weak)) void esp_perip_clk_init(void) #if !CONFIG_USJ_ENABLE_USB_SERIAL_JTAG && !CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG_ENABLED // Disable USB-Serial-JTAG clock and it's pad if not used - usb_fsls_phy_ll_int_jtag_disable(&USB_SERIAL_JTAG); + usb_serial_jtag_ll_phy_enable_pad(false); usb_serial_jtag_ll_enable_bus_clock(false); #endif } diff --git a/components/hal/CMakeLists.txt b/components/hal/CMakeLists.txt index 28e1766909..eb01d3307d 100644 --- a/components/hal/CMakeLists.txt +++ b/components/hal/CMakeLists.txt @@ -258,7 +258,7 @@ if(NOT BOOTLOADER_BUILD) if(CONFIG_SOC_USB_OTG_SUPPORTED) list(APPEND srcs "usb_dwc_hal.c") if(NOT ${target} STREQUAL "esp32p4") - list(APPEND srcs "usb_fsls_phy_hal.c") + list(APPEND srcs "usb_wrap_hal.c") endif() endif() diff --git a/components/hal/esp32c3/include/hal/usb_fsls_phy_ll.h b/components/hal/esp32c3/include/hal/usb_fsls_phy_ll.h deleted file mode 100644 index f20cc684a7..0000000000 --- a/components/hal/esp32c3/include/hal/usb_fsls_phy_ll.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include "soc/usb_serial_jtag_struct.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Configures the internal PHY for USB_Serial_JTAG - * - * @param hw Start address of the USB Serial_JTAG registers - */ -static inline void usb_fsls_phy_ll_int_jtag_enable(usb_serial_jtag_dev_t *hw) -{ - // USB_Serial_JTAG use internal PHY - hw->conf0.phy_sel = 0; - // Disable software control USB D+ D- pullup pulldown (Device FS: dp_pullup = 1) - hw->conf0.pad_pull_override = 0; - // Enable USB D+ pullup - hw->conf0.dp_pullup = 1; - // Enable USB pad function - hw->conf0.usb_pad_enable = 1; -} - -/** - * @brief Disable the internal PHY for USB_Serial_JTAG - * - * @param hw Start address of the USB Serial_JTAG registers - */ -static inline void usb_fsls_phy_ll_int_jtag_disable(usb_serial_jtag_dev_t *hw) -{ - // Disable USB D+ pullup - hw->conf0.dp_pullup = 0; - // Disable USB pad function - hw->conf0.usb_pad_enable = 0; -} - -#ifdef __cplusplus -} -#endif diff --git a/components/hal/esp32c6/include/hal/usb_fsls_phy_ll.h b/components/hal/esp32c6/include/hal/usb_fsls_phy_ll.h deleted file mode 100644 index d6f0f8c883..0000000000 --- a/components/hal/esp32c6/include/hal/usb_fsls_phy_ll.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include "soc/usb_serial_jtag_struct.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Configures the internal PHY for USB_Serial_JTAG - * - * @param hw Start address of the USB Serial_JTAG registers - */ -static inline void usb_fsls_phy_ll_int_jtag_enable(usb_serial_jtag_dev_t *hw) -{ - // USB_Serial_JTAG use internal PHY - hw->conf0.phy_sel = 0; - // Disable software control USB D+ D- pullup pulldown (Device FS: dp_pullup = 1) - hw->conf0.pad_pull_override = 0; - // Enable USB D+ pullup - hw->conf0.dp_pullup = 1; - // Enable USB pad function - hw->conf0.usb_pad_enable = 1; -} - -/** - * @brief Disable the internal PHY for USB_Serial_JTAG - * - * @param hw Start address of the USB Serial_JTAG registers - */ -static inline void usb_fsls_phy_ll_int_jtag_disable(usb_serial_jtag_dev_t *hw) -{ - // Disable USB D+ pullup - hw->conf0.dp_pullup = 0; - // Disable USB pad function - hw->conf0.usb_pad_enable = 0; -} - -#ifdef __cplusplus -} -#endif diff --git a/components/hal/esp32h2/include/hal/usb_fsls_phy_ll.h b/components/hal/esp32h2/include/hal/usb_fsls_phy_ll.h deleted file mode 100644 index d6f0f8c883..0000000000 --- a/components/hal/esp32h2/include/hal/usb_fsls_phy_ll.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include "soc/usb_serial_jtag_struct.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Configures the internal PHY for USB_Serial_JTAG - * - * @param hw Start address of the USB Serial_JTAG registers - */ -static inline void usb_fsls_phy_ll_int_jtag_enable(usb_serial_jtag_dev_t *hw) -{ - // USB_Serial_JTAG use internal PHY - hw->conf0.phy_sel = 0; - // Disable software control USB D+ D- pullup pulldown (Device FS: dp_pullup = 1) - hw->conf0.pad_pull_override = 0; - // Enable USB D+ pullup - hw->conf0.dp_pullup = 1; - // Enable USB pad function - hw->conf0.usb_pad_enable = 1; -} - -/** - * @brief Disable the internal PHY for USB_Serial_JTAG - * - * @param hw Start address of the USB Serial_JTAG registers - */ -static inline void usb_fsls_phy_ll_int_jtag_disable(usb_serial_jtag_dev_t *hw) -{ - // Disable USB D+ pullup - hw->conf0.dp_pullup = 0; - // Disable USB pad function - hw->conf0.usb_pad_enable = 0; -} - -#ifdef __cplusplus -} -#endif diff --git a/components/hal/esp32s2/include/hal/usb_fsls_phy_ll.h b/components/hal/esp32s2/include/hal/usb_wrap_ll.h similarity index 100% rename from components/hal/esp32s2/include/hal/usb_fsls_phy_ll.h rename to components/hal/esp32s2/include/hal/usb_wrap_ll.h diff --git a/components/hal/esp32s3/include/hal/usb_fsls_phy_ll.h b/components/hal/esp32s3/include/hal/usb_wrap_ll.h similarity index 100% rename from components/hal/esp32s3/include/hal/usb_fsls_phy_ll.h rename to components/hal/esp32s3/include/hal/usb_wrap_ll.h diff --git a/components/hal/include/hal/usb_fsls_phy_hal.h b/components/hal/include/hal/usb_wrap_hal.h similarity index 100% rename from components/hal/include/hal/usb_fsls_phy_hal.h rename to components/hal/include/hal/usb_wrap_hal.h diff --git a/components/hal/usb_fsls_phy_hal.c b/components/hal/usb_wrap_hal.c similarity index 68% rename from components/hal/usb_fsls_phy_hal.c rename to components/hal/usb_wrap_hal.c index 7bceb8c364..58b77bba23 100644 --- a/components/hal/usb_fsls_phy_hal.c +++ b/components/hal/usb_wrap_hal.c @@ -4,8 +4,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "hal/usb_fsls_phy_ll.h" -#include "hal/usb_fsls_phy_hal.h" +#include "soc/soc_caps.h" +#include "soc/rtc_cntl_struct.h" +#if SOC_USB_SERIAL_JTAG_SUPPORTED +#include "hal/usb_serial_jtag_ll.h" +#endif +#include "hal/usb_wrap_ll.h" +#include "hal/usb_wrap_hal.h" void usb_fsls_phy_hal_init(usb_fsls_phy_hal_context_t *hal) { @@ -29,9 +34,18 @@ void usb_fsls_phy_hal_otg_conf(usb_fsls_phy_hal_context_t *hal, usb_phy_target_t void usb_fsls_phy_hal_jtag_conf(usb_fsls_phy_hal_context_t *hal, usb_phy_target_t phy_target) { if (phy_target == USB_PHY_TARGET_EXT) { - usb_fsls_phy_ll_ext_jtag_enable(hal->jtag_dev); + usb_serial_jtag_ll_phy_enable_external(true); // USJ uses external PHY + // Enable SW control of muxing USB OTG vs USJ to the internal USB FSLS PHY + RTCCNTL.usb_conf.sw_hw_usb_phy_sel = 1; + // Internal USB FSLS PHY is mapped to the USJ + RTCCNTL.usb_conf.sw_usb_phy_sel = 1; } else if (phy_target == USB_PHY_TARGET_INT) { - usb_fsls_phy_ll_int_jtag_enable(hal->jtag_dev); + usb_serial_jtag_ll_phy_enable_external(true); // USJ uses internal PHY + usb_serial_jtag_ll_phy_enable_pad(true); // Enable USB PHY pads + // Enable SW control of muxing USB OTG vs USJ to the internal USB FSLS PHY + RTCCNTL.usb_conf.sw_hw_usb_phy_sel = 1; + // Internal USB FSLS PHY is mapped to the USJ + RTCCNTL.usb_conf.sw_usb_phy_sel = 0; } } #endif diff --git a/components/usb/usb_phy.c b/components/usb/usb_phy.c index 4e1707441a..c687c21782 100644 --- a/components/usb/usb_phy.c +++ b/components/usb/usb_phy.c @@ -12,8 +12,8 @@ #include "esp_private/periph_ctrl.h" #include "esp_private/usb_phy.h" #include "soc/usb_dwc_periph.h" -#include "hal/usb_fsls_phy_hal.h" -#include "hal/usb_fsls_phy_ll.h" +#include "hal/usb_wrap_hal.h" +#include "hal/usb_wrap_ll.h" #include "esp_rom_gpio.h" #include "driver/gpio.h" #include "hal/gpio_ll.h"