soc: riscv|xtensa: esp32: add support for sys_poweroff
Implement the sys_poweroff hook for all ESP32 SoCs based on the previous SOFT_OFF implementation. Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
parent
91450a4358
commit
3118a8c05c
13 changed files with 60 additions and 31 deletions
|
@ -10,6 +10,7 @@ zephyr_sources(
|
|||
)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_PM power.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
|
||||
|
||||
# get code-partition slot0 address
|
||||
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
|
||||
|
|
|
@ -16,5 +16,6 @@ config SOC_SERIES_ESP32C3
|
|||
select SOC_FAMILY_ESP32
|
||||
select XIP if !MCUBOOT
|
||||
select HAS_PM
|
||||
select HAS_POWEROFF
|
||||
help
|
||||
Enable support for Espressif ESP32-C3
|
||||
|
|
|
@ -17,11 +17,6 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
|
|||
ARG_UNUSED(substate_id);
|
||||
|
||||
switch (state) {
|
||||
case PM_STATE_SOFT_OFF:
|
||||
/* Forces RTC domain to be always on */
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
esp_deep_sleep_start();
|
||||
break;
|
||||
case PM_STATE_STANDBY:
|
||||
/* Nothing to do. */
|
||||
break;
|
||||
|
@ -37,9 +32,6 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
|
|||
ARG_UNUSED(substate_id);
|
||||
|
||||
switch (state) {
|
||||
case PM_STATE_SOFT_OFF:
|
||||
/* Nothing to do. */
|
||||
break;
|
||||
case PM_STATE_STANDBY:
|
||||
irq_unlock(MSTATUS_IEN);
|
||||
__asm__ volatile("wfi");
|
||||
|
|
15
soc/riscv/espressif_esp32/esp32c3/poweroff.c
Normal file
15
soc/riscv/espressif_esp32/esp32c3/poweroff.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/sys/poweroff.h>
|
||||
|
||||
#include <esp_sleep.h>
|
||||
|
||||
void z_sys_poweroff(void)
|
||||
{
|
||||
/* Forces RTC domain to be always on */
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
esp_deep_sleep_start();
|
||||
}
|
|
@ -11,6 +11,7 @@ zephyr_library_sources_ifdef(CONFIG_NEWLIB_LIBC newlib_fix.c)
|
|||
zephyr_library_sources_ifdef(CONFIG_GDBSTUB gdbstub.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_PM power.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
|
||||
|
||||
# get code-partition slot0 address
|
||||
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
|
||||
|
|
|
@ -14,5 +14,6 @@ config SOC_SERIES_ESP32
|
|||
select HAS_ESPRESSIF_HAL
|
||||
select CPU_HAS_FPU
|
||||
select HAS_PM
|
||||
select HAS_POWEROFF
|
||||
help
|
||||
Enable support for Espressif ESP32
|
||||
|
|
|
@ -21,17 +21,6 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
|
|||
ARG_UNUSED(substate_id);
|
||||
|
||||
switch (state) {
|
||||
case PM_STATE_SOFT_OFF:
|
||||
/*
|
||||
* Isolate GPIO12 pin from external circuits. This is needed for modules
|
||||
* which have an external pull-up resistor on GPIO12 (such as ESP32-WROVER)
|
||||
* to minimize current consumption.
|
||||
*/
|
||||
rtcio_hal_isolate(RTCIO_GPIO12_CHANNEL);
|
||||
/* Forces RTC domain to be always on */
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
esp_deep_sleep_start();
|
||||
break;
|
||||
case PM_STATE_STANDBY:
|
||||
intenable = XTENSA_RSR("INTENABLE");
|
||||
__asm__ volatile ("waiti 0");
|
||||
|
@ -48,9 +37,6 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
|
|||
ARG_UNUSED(substate_id);
|
||||
|
||||
switch (state) {
|
||||
case PM_STATE_SOFT_OFF:
|
||||
/* Nothing to do. */
|
||||
break;
|
||||
case PM_STATE_STANDBY:
|
||||
z_xt_ints_on(intenable);
|
||||
esp_light_sleep_start();
|
||||
|
|
23
soc/xtensa/espressif_esp32/esp32/poweroff.c
Normal file
23
soc/xtensa/espressif_esp32/esp32/poweroff.c
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/sys/poweroff.h>
|
||||
|
||||
#include <esp_sleep.h>
|
||||
#include <hal/rtc_io_hal.h>
|
||||
#include <soc/rtc_io_channel.h>
|
||||
|
||||
void z_sys_poweroff(void)
|
||||
{
|
||||
/*
|
||||
* Isolate GPIO12 pin from external circuits. This is needed for modules
|
||||
* which have an external pull-up resistor on GPIO12 (such as ESP32-WROVER)
|
||||
* to minimize current consumption.
|
||||
*/
|
||||
rtcio_hal_isolate(RTCIO_GPIO12_CHANNEL);
|
||||
/* Forces RTC domain to be always on */
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
esp_deep_sleep_start();
|
||||
}
|
|
@ -9,6 +9,7 @@ zephyr_sources(
|
|||
zephyr_library_sources_ifdef(CONFIG_NEWLIB_LIBC newlib_fix.c)
|
||||
|
||||
zephyr_library_sources_ifdef(CONFIG_PM power.c)
|
||||
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
|
||||
|
||||
# get code-partition slot0 address
|
||||
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")
|
||||
|
|
|
@ -13,5 +13,6 @@ config SOC_SERIES_ESP32S2
|
|||
select HAS_ESPRESSIF_HAL
|
||||
select ARCH_SUPPORTS_COREDUMP
|
||||
select HAS_PM
|
||||
select HAS_POWEROFF
|
||||
help
|
||||
Enable support for Espressif ESP32-S2
|
||||
|
|
|
@ -19,11 +19,6 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
|
|||
ARG_UNUSED(substate_id);
|
||||
|
||||
switch (state) {
|
||||
case PM_STATE_SOFT_OFF:
|
||||
/* Forces RTC domain to be always on */
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
esp_deep_sleep_start();
|
||||
break;
|
||||
case PM_STATE_STANDBY:
|
||||
intenable = XTENSA_RSR("INTENABLE");
|
||||
__asm__ volatile ("waiti 0");
|
||||
|
@ -40,9 +35,6 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
|
|||
ARG_UNUSED(substate_id);
|
||||
|
||||
switch (state) {
|
||||
case PM_STATE_SOFT_OFF:
|
||||
/* Nothing to do. */
|
||||
break;
|
||||
case PM_STATE_STANDBY:
|
||||
z_xt_ints_on(intenable);
|
||||
esp_light_sleep_start();
|
||||
|
|
15
soc/xtensa/espressif_esp32/esp32s2/poweroff.c
Normal file
15
soc/xtensa/espressif_esp32/esp32s2/poweroff.c
Normal file
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/sys/poweroff.h>
|
||||
|
||||
#include <esp_sleep.h>
|
||||
|
||||
void z_sys_poweroff(void)
|
||||
{
|
||||
/* Forces RTC domain to be always on */
|
||||
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
|
||||
esp_deep_sleep_start();
|
||||
}
|
2
west.yml
2
west.yml
|
@ -152,7 +152,7 @@ manifest:
|
|||
groups:
|
||||
- hal
|
||||
- name: hal_espressif
|
||||
revision: ae1bd648a1ac701672c46b6ff4eadfa716937ce3
|
||||
revision: ec90f3c49e3826ef2c56c5381aa068c4f482b31f
|
||||
path: modules/hal/espressif
|
||||
west-commands: west/west-commands.yml
|
||||
groups:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue