1 /* 2 * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <stdbool.h> 8 #include "soc/soc_caps.h" 9 #include "esp_private/sleep_console.h" 10 #include "esp_attr.h" 11 12 #if SOC_USB_SERIAL_JTAG_SUPPORTED 13 #include "hal/usb_serial_jtag_ll.h" 14 15 static sleep_console_usj_enable_state_t s_usj_state = {0}; 16 sleep_console_usj_pad_backup_and_disable(void)17void sleep_console_usj_pad_backup_and_disable(void) 18 { 19 s_usj_state.usj_clock_enabled = usb_serial_jtag_ll_module_is_enabled(); 20 if (!s_usj_state.usj_clock_enabled) { 21 // Enable USJ clock and clear reset 22 usb_serial_jtag_ll_enable_bus_clock(true); 23 usb_serial_jtag_ll_reset_register(); 24 } 25 s_usj_state.usj_pad_enabled = usb_serial_jtag_ll_phy_is_pad_enabled(); 26 usb_serial_jtag_ll_phy_enable_pad(false); 27 // Disable USJ clock 28 usb_serial_jtag_ll_enable_bus_clock(false); 29 } 30 sleep_console_usj_pad_restore(void)31void sleep_console_usj_pad_restore(void) 32 { 33 usb_serial_jtag_ll_enable_bus_clock(true); 34 usb_serial_jtag_ll_phy_enable_pad(s_usj_state.usj_pad_enabled); 35 if (!s_usj_state.usj_clock_enabled) { 36 usb_serial_jtag_ll_enable_bus_clock(false); 37 } 38 } 39 #endif 40