Skip to content

Commit 5025487

Browse files
cyliangtwfabiobaltieri
authored andcommitted
soc: nuvoton: numaker: add poweroff for m2l31x
Add support of sys_poweroff API on m2l31x series. It could support SPD0~2 standby or DPD0~1 deep power down mode. Signed-off-by: cyliang tw <[email protected]>
1 parent f3dcaae commit 5025487

File tree

6 files changed

+51
-0
lines changed

6 files changed

+51
-0
lines changed

dts/arm/nuvoton/m2l31x.dtsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
clk-pclkdiv = <(NUMAKER_CLK_PCLKDIV_APB0DIV_DIV2 |
4949
NUMAKER_CLK_PCLKDIV_APB1DIV_DIV2)>;
5050
core-clock = <DT_FREQ_M(72)>;
51+
powerdown-mode = <NUMAKER_CLK_PMUCTL_PDMSEL_DPD0>;
5152

5253
pcc: peripheral-clock-controller {
5354
compatible = "nuvoton,numaker-pcc";

include/zephyr/dt-bindings/clock/numaker_m2l31x_clock.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,4 +271,17 @@
271271
#define NUMAKER_LPADC0_MODULE 0xB5431218
272272
#define NUMAKER_OPA_MODULE 0xA000001B
273273

274+
#define NUMAKER_CLK_PMUCTL_PDMSEL_PD 0x00000000
275+
#define NUMAKER_CLK_PMUCTL_PDMSEL_NPD0 0x00000000
276+
#define NUMAKER_CLK_PMUCTL_PDMSEL_NPD1 0x00000001
277+
#define NUMAKER_CLK_PMUCTL_PDMSEL_NPD2 0x00000002
278+
#define NUMAKER_CLK_PMUCTL_PDMSEL_NPD3 0x00000003
279+
#define NUMAKER_CLK_PMUCTL_PDMSEL_NPD4 0x00000004
280+
#define NUMAKER_CLK_PMUCTL_PDMSEL_NPD5 0x00000005
281+
#define NUMAKER_CLK_PMUCTL_PDMSEL_SPD0 0x00000008
282+
#define NUMAKER_CLK_PMUCTL_PDMSEL_SPD1 0x00000009
283+
#define NUMAKER_CLK_PMUCTL_PDMSEL_SPD2 0x0000000A
284+
#define NUMAKER_CLK_PMUCTL_PDMSEL_DPD0 0x0000000C
285+
#define NUMAKER_CLK_PMUCTL_PDMSEL_DPD1 0x0000000D
286+
274287
#endif

soc/nuvoton/numaker/m2l31x/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ zephyr_sources(soc.c)
66

77
zephyr_include_directories(.)
88

9+
zephyr_library_sources_ifdef(CONFIG_POWEROFF poweroff.c)
10+
911
set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "")

soc/nuvoton/numaker/m2l31x/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config SOC_SERIES_M2L31X
88
select CPU_CORTEX_M_HAS_SYSTICK
99
select CPU_CORTEX_M_HAS_VTOR
1010
select CPU_HAS_ARM_MPU
11+
select HAS_POWEROFF
1112

1213
config SOC_M2L31XXX
1314
select HAS_NUMAKER_HAL

soc/nuvoton/numaker/m2l31x/poweroff.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2024 Nuvoton Technology Corporation.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/devicetree.h>
9+
#include <zephyr/sys/poweroff.h>
10+
#include <NuMicro.h>
11+
12+
void z_sys_poweroff(void)
13+
{
14+
SYS_UnlockReg();
15+
16+
/* Clear all wake-up flag */
17+
CLK->PMUSTS |= CLK_PMUSTS_CLRWK_Msk;
18+
19+
/* Select Power-down mode */
20+
CLK_SetPowerDownMode(DT_PROP_OR(DT_NODELABEL(scc), powerdown_mode, CLK_PMUCTL_PDMSEL_SPD0));
21+
22+
/* Enable RTC wake-up */
23+
CLK_ENABLE_RTCWK();
24+
25+
/* Enter to Power-down mode */
26+
CLK_PowerDown();
27+
28+
k_cpu_idle();
29+
30+
CODE_UNREACHABLE;
31+
}

soc/nuvoton/numaker/m2l31x/soc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ void z_arm_platform_init(void)
1616
/* Unlock protected registers */
1717
SYS_UnlockReg();
1818

19+
/* Release I/O hold status */
20+
CLK->IOPDCTL = 1;
21+
1922
/*
2023
* -------------------
2124
* Init System Clock

0 commit comments

Comments
 (0)