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:
Gerard Marull-Paretas 2023-08-08 10:29:38 +02:00 committed by Martí Bolívar
commit 3118a8c05c
13 changed files with 60 additions and 31 deletions

View file

@ -10,6 +10,7 @@ zephyr_sources(
) )
zephyr_library_sources_ifdef(CONFIG_PM power.c) zephyr_library_sources_ifdef(CONFIG_PM power.c)
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
# get code-partition slot0 address # get code-partition slot0 address
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition") dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")

View file

@ -16,5 +16,6 @@ config SOC_SERIES_ESP32C3
select SOC_FAMILY_ESP32 select SOC_FAMILY_ESP32
select XIP if !MCUBOOT select XIP if !MCUBOOT
select HAS_PM select HAS_PM
select HAS_POWEROFF
help help
Enable support for Espressif ESP32-C3 Enable support for Espressif ESP32-C3

View file

@ -17,11 +17,6 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
ARG_UNUSED(substate_id); ARG_UNUSED(substate_id);
switch (state) { 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: case PM_STATE_STANDBY:
/* Nothing to do. */ /* Nothing to do. */
break; break;
@ -37,9 +32,6 @@ void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id)
ARG_UNUSED(substate_id); ARG_UNUSED(substate_id);
switch (state) { switch (state) {
case PM_STATE_SOFT_OFF:
/* Nothing to do. */
break;
case PM_STATE_STANDBY: case PM_STATE_STANDBY:
irq_unlock(MSTATUS_IEN); irq_unlock(MSTATUS_IEN);
__asm__ volatile("wfi"); __asm__ volatile("wfi");

View 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();
}

View file

@ -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_GDBSTUB gdbstub.c)
zephyr_library_sources_ifdef(CONFIG_PM power.c) zephyr_library_sources_ifdef(CONFIG_PM power.c)
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
# get code-partition slot0 address # get code-partition slot0 address
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition") dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")

View file

@ -14,5 +14,6 @@ config SOC_SERIES_ESP32
select HAS_ESPRESSIF_HAL select HAS_ESPRESSIF_HAL
select CPU_HAS_FPU select CPU_HAS_FPU
select HAS_PM select HAS_PM
select HAS_POWEROFF
help help
Enable support for Espressif ESP32 Enable support for Espressif ESP32

View file

@ -21,17 +21,6 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
ARG_UNUSED(substate_id); ARG_UNUSED(substate_id);
switch (state) { 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: case PM_STATE_STANDBY:
intenable = XTENSA_RSR("INTENABLE"); intenable = XTENSA_RSR("INTENABLE");
__asm__ volatile ("waiti 0"); __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); ARG_UNUSED(substate_id);
switch (state) { switch (state) {
case PM_STATE_SOFT_OFF:
/* Nothing to do. */
break;
case PM_STATE_STANDBY: case PM_STATE_STANDBY:
z_xt_ints_on(intenable); z_xt_ints_on(intenable);
esp_light_sleep_start(); esp_light_sleep_start();

View 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();
}

View file

@ -9,6 +9,7 @@ zephyr_sources(
zephyr_library_sources_ifdef(CONFIG_NEWLIB_LIBC newlib_fix.c) zephyr_library_sources_ifdef(CONFIG_NEWLIB_LIBC newlib_fix.c)
zephyr_library_sources_ifdef(CONFIG_PM power.c) zephyr_library_sources_ifdef(CONFIG_PM power.c)
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
# get code-partition slot0 address # get code-partition slot0 address
dt_nodelabel(dts_partition_path NODELABEL "slot0_partition") dt_nodelabel(dts_partition_path NODELABEL "slot0_partition")

View file

@ -13,5 +13,6 @@ config SOC_SERIES_ESP32S2
select HAS_ESPRESSIF_HAL select HAS_ESPRESSIF_HAL
select ARCH_SUPPORTS_COREDUMP select ARCH_SUPPORTS_COREDUMP
select HAS_PM select HAS_PM
select HAS_POWEROFF
help help
Enable support for Espressif ESP32-S2 Enable support for Espressif ESP32-S2

View file

@ -19,11 +19,6 @@ void pm_state_set(enum pm_state state, uint8_t substate_id)
ARG_UNUSED(substate_id); ARG_UNUSED(substate_id);
switch (state) { 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: case PM_STATE_STANDBY:
intenable = XTENSA_RSR("INTENABLE"); intenable = XTENSA_RSR("INTENABLE");
__asm__ volatile ("waiti 0"); __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); ARG_UNUSED(substate_id);
switch (state) { switch (state) {
case PM_STATE_SOFT_OFF:
/* Nothing to do. */
break;
case PM_STATE_STANDBY: case PM_STATE_STANDBY:
z_xt_ints_on(intenable); z_xt_ints_on(intenable);
esp_light_sleep_start(); esp_light_sleep_start();

View 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();
}

View file

@ -152,7 +152,7 @@ manifest:
groups: groups:
- hal - hal
- name: hal_espressif - name: hal_espressif
revision: ae1bd648a1ac701672c46b6ff4eadfa716937ce3 revision: ec90f3c49e3826ef2c56c5381aa068c4f482b31f
path: modules/hal/espressif path: modules/hal/espressif
west-commands: west/west-commands.yml west-commands: west/west-commands.yml
groups: groups: