2021-08-19 08:28:28 -04:00
|
|
|
/*
|
2024-03-14 14:37:26 -04:00
|
|
|
* SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD
|
2021-08-19 08:28:28 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2024-03-14 09:20:33 -04:00
|
|
|
#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"
|
2021-08-19 08:28:28 -04:00
|
|
|
|
2023-12-26 12:32:06 -05:00
|
|
|
void usb_fsls_phy_hal_init(usb_fsls_phy_hal_context_t *hal)
|
2021-08-19 08:28:28 -04:00
|
|
|
{
|
|
|
|
hal->wrap_dev = &USB_WRAP;
|
|
|
|
#if SOC_USB_SERIAL_JTAG_SUPPORTED
|
|
|
|
hal->jtag_dev = &USB_SERIAL_JTAG;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-12-26 12:32:06 -05:00
|
|
|
void usb_fsls_phy_hal_otg_conf(usb_fsls_phy_hal_context_t *hal, usb_phy_target_t phy_target)
|
2021-08-19 08:28:28 -04:00
|
|
|
{
|
|
|
|
if (phy_target == USB_PHY_TARGET_EXT) {
|
2024-03-14 14:37:26 -04:00
|
|
|
usb_wrap_ll_phy_enable_external(hal->wrap_dev, true);
|
2021-08-19 08:28:28 -04:00
|
|
|
} else if (phy_target == USB_PHY_TARGET_INT) {
|
2024-03-14 14:37:26 -04:00
|
|
|
usb_wrap_ll_phy_enable_external(hal->wrap_dev, false);
|
|
|
|
usb_wrap_ll_phy_enable_pad(hal->wrap_dev, true);
|
2021-08-19 08:28:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if SOC_USB_SERIAL_JTAG_SUPPORTED
|
2023-12-26 12:32:06 -05:00
|
|
|
void usb_fsls_phy_hal_jtag_conf(usb_fsls_phy_hal_context_t *hal, usb_phy_target_t phy_target)
|
2021-08-19 08:28:28 -04:00
|
|
|
{
|
|
|
|
if (phy_target == USB_PHY_TARGET_EXT) {
|
2024-03-14 09:20:33 -04:00
|
|
|
usb_serial_jtag_ll_phy_enable_external(true); // USJ uses external PHY
|
2021-08-19 08:28:28 -04:00
|
|
|
} else if (phy_target == USB_PHY_TARGET_INT) {
|
2024-03-14 14:37:26 -04:00
|
|
|
usb_serial_jtag_ll_phy_enable_external(false); // USJ uses internal PHY
|
2024-03-14 09:20:33 -04:00
|
|
|
usb_serial_jtag_ll_phy_enable_pad(true); // Enable USB PHY pads
|
2021-08-19 08:28:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-12-26 12:32:06 -05:00
|
|
|
void usb_fsls_phy_hal_int_load_conf_host(usb_fsls_phy_hal_context_t *hal)
|
2021-08-19 08:28:28 -04:00
|
|
|
{
|
|
|
|
// HOST - upstream: dp_pd = 1, dm_pd = 1
|
2024-03-14 14:37:26 -04:00
|
|
|
usb_wrap_ll_phy_enable_pull_override(hal->wrap_dev, false, false, true, true);
|
2021-08-19 08:28:28 -04:00
|
|
|
}
|
|
|
|
|
2023-12-26 12:32:06 -05:00
|
|
|
void usb_fsls_phy_hal_int_load_conf_dev(usb_fsls_phy_hal_context_t *hal, usb_phy_speed_t speed)
|
2021-08-19 08:28:28 -04:00
|
|
|
{
|
|
|
|
// DEVICE - downstream
|
2023-11-29 03:30:04 -05:00
|
|
|
if (speed == USB_PHY_SPEED_LOW) {
|
2021-08-19 08:28:28 -04:00
|
|
|
// LS: dm_pu = 1
|
2024-03-14 14:37:26 -04:00
|
|
|
usb_wrap_ll_phy_enable_pull_override(hal->wrap_dev, false, true, false, false);
|
2021-08-19 08:28:28 -04:00
|
|
|
} else {
|
|
|
|
// FS: dp_pu = 1
|
2024-03-14 14:37:26 -04:00
|
|
|
usb_wrap_ll_phy_enable_pull_override(hal->wrap_dev, true, false, false, false);
|
2021-08-19 08:28:28 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-26 12:32:06 -05:00
|
|
|
void usb_fsls_phy_hal_int_mimick_disconn(usb_fsls_phy_hal_context_t *hal, bool disconn)
|
2021-08-19 08:28:28 -04:00
|
|
|
{
|
2024-03-14 14:37:26 -04:00
|
|
|
if (disconn) {
|
|
|
|
/*
|
|
|
|
We mimick a disconnect by enabling the internal PHY's test mode, then forcing the output_enable to HIGH. This will:
|
|
|
|
A HIGH output_enable will cause the received VP and VM to be zero, thus mimicking a disconnection.
|
|
|
|
*/
|
|
|
|
usb_wrap_ll_phy_test_mode_set_signals(hal->wrap_dev,
|
|
|
|
true, // OEN
|
|
|
|
false, // TX D+
|
|
|
|
false, // TX D-
|
|
|
|
false, // RX D+
|
|
|
|
false, // RX D-
|
|
|
|
false); // RX RCv
|
|
|
|
usb_wrap_ll_phy_enable_test_mode(hal->wrap_dev, true);
|
|
|
|
} else {
|
|
|
|
usb_wrap_ll_phy_enable_test_mode(hal->wrap_dev, false);
|
|
|
|
}
|
2021-08-19 08:28:28 -04:00
|
|
|
}
|