From 3cea7c80002f8ef8ebb67f243a8f3180ab877cca Mon Sep 17 00:00:00 2001 From: Sreeram Tatapudi Date: Wed, 4 Sep 2024 14:15:52 -0700 Subject: [PATCH] soc: infineon: Support for power management on 20829 - Initial changes in board, dts, and soc files to support system power management Signed-off-by: Sreeram Tatapudi --- .../cyw920829m2evk_02/cyw920829m2evk_02.dts | 4 + .../cyw920829m2evk_02_defconfig | 1 - dts/arm/infineon/cat1b/cyw20829/cyw20829.dtsi | 15 ++++ .../hal_infineon/mtb-pdl-cat1/CMakeLists.txt | 2 + soc/infineon/cat1b/cyw20829/CMakeLists.txt | 2 + soc/infineon/cat1b/cyw20829/Kconfig | 1 + soc/infineon/cat1b/cyw20829/Kconfig.defconfig | 6 ++ soc/infineon/cat1b/cyw20829/power.c | 73 +++++++++++++++++++ soc/infineon/cat1b/cyw20829/soc.c | 10 +++ 9 files changed, 113 insertions(+), 1 deletion(-) create mode 100644 soc/infineon/cat1b/cyw20829/power.c diff --git a/boards/infineon/cyw920829m2evk_02/cyw920829m2evk_02.dts b/boards/infineon/cyw920829m2evk_02/cyw920829m2evk_02.dts index 83825dd8693ce2..927b1f865f4bd0 100644 --- a/boards/infineon/cyw920829m2evk_02/cyw920829m2evk_02.dts +++ b/boards/infineon/cyw920829m2evk_02/cyw920829m2evk_02.dts @@ -81,6 +81,10 @@ uart2: &scb2 { status = "okay"; }; +&mcwdt0 { + status = "okay"; +}; + &bluetooth { status = "okay"; }; diff --git a/boards/infineon/cyw920829m2evk_02/cyw920829m2evk_02_defconfig b/boards/infineon/cyw920829m2evk_02/cyw920829m2evk_02_defconfig index 426cd85d30f371..e50b5462babe15 100644 --- a/boards/infineon/cyw920829m2evk_02/cyw920829m2evk_02_defconfig +++ b/boards/infineon/cyw920829m2evk_02/cyw920829m2evk_02_defconfig @@ -4,7 +4,6 @@ # # General configuration -CONFIG_CORTEX_M_SYSTICK=y CONFIG_BUILD_OUTPUT_HEX=y CONFIG_BUILD_OUTPUT_BIN=y diff --git a/dts/arm/infineon/cat1b/cyw20829/cyw20829.dtsi b/dts/arm/infineon/cat1b/cyw20829/cyw20829.dtsi index 1b90d91b578425..aca60b622c5c65 100644 --- a/dts/arm/infineon/cat1b/cyw20829/cyw20829.dtsi +++ b/dts/arm/infineon/cat1b/cyw20829/cyw20829.dtsi @@ -16,6 +16,21 @@ device_type = "cpu"; compatible = "arm,cortex-m33"; reg = <0>; + cpu-power-states = <&idle &suspend_to_ram>; + }; + + power-states { + idle: idle { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-idle"; + min-residency-us = <1000000>; + }; + + suspend_to_ram: suspend_to_ram { + compatible = "zephyr,power-state"; + power-state-name = "suspend-to-ram"; + min-residency-us = <2000000>; + }; }; }; diff --git a/modules/hal_infineon/mtb-pdl-cat1/CMakeLists.txt b/modules/hal_infineon/mtb-pdl-cat1/CMakeLists.txt index ed33a73bfcd912..ab39f70a8c031e 100644 --- a/modules/hal_infineon/mtb-pdl-cat1/CMakeLists.txt +++ b/modules/hal_infineon/mtb-pdl-cat1/CMakeLists.txt @@ -84,6 +84,8 @@ if(CONFIG_SOC_FAMILY_INFINEON_CAT1B) zephyr_library_sources(${pdl_drv_dir}/source/cy_systick_v2.c) zephyr_library_sources(${pdl_drv_dir}/source/cy_syspm_v2.c) zephyr_library_sources(${pdl_drv_dir}/source/cy_syspm_btss.c) + zephyr_library_sources(${pdl_drv_dir}/source/cy_syspm_ppu.c) + zephyr_library_sources(${pdl_drv_dir}/source/ppu_v1.c) endif() zephyr_library_sources(${pdl_drv_dir}/source/cy_syslib.c) zephyr_library_sources(${pdl_drv_dir}/source/cy_syspm.c) diff --git a/soc/infineon/cat1b/cyw20829/CMakeLists.txt b/soc/infineon/cat1b/cyw20829/CMakeLists.txt index 8532a44108aea5..464a3f44a3067d 100644 --- a/soc/infineon/cat1b/cyw20829/CMakeLists.txt +++ b/soc/infineon/cat1b/cyw20829/CMakeLists.txt @@ -5,6 +5,8 @@ zephyr_sources(soc.c) zephyr_sources(app_header.c) zephyr_include_directories(.) +zephyr_sources_ifdef(CONFIG_PM power.c) + # CAT1B family defines zephyr_compile_definitions_ifdef(CONFIG_SOC_FAMILY_INFINEON_CAT1 CY_USING_HAL) zephyr_compile_definitions_ifdef(CONFIG_SOC_FAMILY_INFINEON_CAT1B COMPONENT_CAT1B) diff --git a/soc/infineon/cat1b/cyw20829/Kconfig b/soc/infineon/cat1b/cyw20829/Kconfig index 242a3569018805..85ec200be8e9d0 100644 --- a/soc/infineon/cat1b/cyw20829/Kconfig +++ b/soc/infineon/cat1b/cyw20829/Kconfig @@ -12,3 +12,4 @@ config SOC_SERIES_CYW20829 select CPU_HAS_FPU select DYNAMIC_INTERRUPTS select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE + select HAS_PM diff --git a/soc/infineon/cat1b/cyw20829/Kconfig.defconfig b/soc/infineon/cat1b/cyw20829/Kconfig.defconfig index 896abd9475c558..78b2cdd8956f20 100644 --- a/soc/infineon/cat1b/cyw20829/Kconfig.defconfig +++ b/soc/infineon/cat1b/cyw20829/Kconfig.defconfig @@ -6,6 +6,12 @@ if SOC_DIE_CYW20829 +config INFINEON_CAT1_LP_TIMER + bool + +config CORTEX_M_SYSTICK + default n if INFINEON_CAT1_LP_TIMER + config NUM_IRQS default 70 diff --git a/soc/infineon/cat1b/cyw20829/power.c b/soc/infineon/cat1b/cyw20829/power.c new file mode 100644 index 00000000000000..f5d6e272fc48d5 --- /dev/null +++ b/soc/infineon/cat1b/cyw20829/power.c @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2021 Cypress Semiconductor Corporation (an Infineon company) or + * an affiliate of Cypress Semiconductor Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#include +#include + +LOG_MODULE_REGISTER(soc_power, CONFIG_SOC_LOG_LEVEL); + +/* + * Called from pm_system_suspend(int32_t ticks) in subsys/power.c + * For deep sleep pm_system_suspend has executed all the driver + * power management call backs. + */ +void pm_state_set(enum pm_state state, uint8_t substate_id) +{ + ARG_UNUSED(substate_id); + + /* Set BASEPRI to 0 */ + irq_unlock(0); + + switch (state) { + case PM_STATE_SUSPEND_TO_IDLE: + LOG_DBG("Entering PM state suspend to idle"); + cyhal_syspm_sleep(); + break; + case PM_STATE_SUSPEND_TO_RAM: + LOG_DBG("Entering PM state suspend to RAM"); + cyhal_syspm_deepsleep(); + + /* + * The HAL function doesn't clear this bit. It is a problem + * if the Zephyr idle function executes the wfi instruction + * with this bit set. We will always clear it here to avoid + * that situation. + */ + SCB_SCR &= (uint32_t)~SCB_SCR_SLEEPDEEP_Msk; + break; + default: + LOG_DBG("Unsupported power state %u", state); + break; + } +} + +void pm_state_exit_post_ops(enum pm_state state, uint8_t substate_id) +{ + ARG_UNUSED(substate_id); + + switch (state) { + case PM_STATE_SUSPEND_TO_IDLE: + case PM_STATE_SUSPEND_TO_RAM: + break; + + default: + break; + } +} + +int ifx_pm_init(void) +{ + /* System Domain Idle Power Mode Configuration */ + Cy_SysPm_SetDeepSleepMode(CY_SYSPM_MODE_DEEPSLEEP); + + return cyhal_syspm_init(); +} diff --git a/soc/infineon/cat1b/cyw20829/soc.c b/soc/infineon/cat1b/cyw20829/soc.c index 5e87a400841b4c..3a55e035c7940d 100644 --- a/soc/infineon/cat1b/cyw20829/soc.c +++ b/soc/infineon/cat1b/cyw20829/soc.c @@ -11,10 +11,13 @@ #include #include #include + #include #include #include "cy_pdl.h" +extern int ifx_pm_init(void); + cy_en_sysint_status_t Cy_SysInt_Init(const cy_stc_sysint_t *config, cy_israddress userIsr) { CY_ASSERT_L3(CY_SYSINT_IS_PRIORITY_VALID(config->intrPriority)); @@ -94,3 +97,10 @@ static int init_cycfg_platform_wrapper(void) } SYS_INIT(init_cycfg_platform_wrapper, PRE_KERNEL_1, 0); + +#ifdef CONFIG_PM +void soc_early_init_hook(void) +{ + ifx_pm_init(); +} +#endif