Skip to content

Commit 7704d4e

Browse files
manuarguedleach02
authored andcommitted
soc: nxp: s32: convert power mng to native drivers
Convert power management to native drivers retaining existing functionalities. Presently only SoC reset support and power control initialization is supported, but these drivers will be extended to support power management as well. MC_ME and MC_RGM peripherals are common enough to be reused by other NXP S32 devices, whereas PMC has specific implementations for each SoC series. Signed-off-by: Manuel Argüelles <[email protected]>
1 parent c449684 commit 7704d4e

File tree

14 files changed

+527
-140
lines changed

14 files changed

+527
-140
lines changed

boards/nxp/mr_canhubk3/mr_canhubk3.dts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@
201201
};
202202
};
203203

204+
&pmc {
205+
lm-reg;
206+
};
207+
204208
&flash0 {
205209
partitions {
206210
compatible = "fixed-partitions";

dts/arm/nxp/nxp_s32k344_m7.dtsi

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,23 @@
857857
reg = <0x40080000 0x4000>;
858858
status = "disabled";
859859
};
860+
861+
pmc: pmc@402e8000 {
862+
compatible = "nxp,s32k3-pmc";
863+
reg = <0x402e8000 0x4000>;
864+
};
865+
866+
mc_me: mc_me@402dc000 {
867+
compatible = "nxp,s32-mc-me";
868+
reg = <0x402dc000 0x4000>;
869+
};
870+
871+
mc_rgm: mc_rgm@4028c000 {
872+
compatible = "nxp,s32-mc-rgm";
873+
reg = <0x4028c000 0x4000>;
874+
func-reset-threshold = <0>;
875+
dest-reset-threshold = <0>;
876+
};
860877
};
861878
};
862879

dts/bindings/power/nxp,s32-mc-me.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: NXP S32 Module Entry (MC_ME)
5+
6+
compatible: "nxp,s32-mc-me"
7+
8+
include: base.yaml
9+
10+
properties:
11+
reg:
12+
required: true
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: NXP S32 Module Reset Generation (MC_RGM)
5+
6+
compatible: "nxp,s32-mc-rgm"
7+
8+
include: base.yaml
9+
10+
properties:
11+
reg:
12+
required: true
13+
14+
func-reset-threshold:
15+
type: int
16+
enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
17+
default: 15
18+
description: |
19+
Functional Reset Escalation threshold.
20+
If the value of this property is 0, the Functional reset escalation
21+
function is disabled. Any other value is the number of Functional
22+
resets that causes a Destructive reset, if the FRET register isn't
23+
written to beforehand.
24+
Default to maximum threshold (hardware reset value).
25+
26+
dest-reset-threshold:
27+
type: int
28+
enum: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
29+
default: 0
30+
description: |
31+
Destructive Reset Escalation threshold.
32+
If the value of this property is 0, the Destructive reset escalation
33+
function is disabled. Any other value is the number of Destructive
34+
resets which keeps the chip in the reset state until the next power-on
35+
reset triggers a new reset sequence, if the DRET register isn't
36+
written to beforehand.
37+
Default to disabled (hardware reset value).

dts/bindings/power/nxp,s32k3-pmc.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: NXP S32K3xx Power Management Controller (PMC)
5+
6+
compatible: "nxp,s32k3-pmc"
7+
8+
include: base.yaml
9+
10+
properties:
11+
reg:
12+
required: true
13+
14+
lm-reg:
15+
type: boolean
16+
description: |
17+
Enables the Last Mile regulator, which regulates an external 1.5V
18+
voltage on V15 down to the core and logic supply (V11 power domain),
19+
which is typically 1.1V.
20+
When enabling PLL as system clock, the PMC Last Mile regulator should
21+
be enabled.
22+
23+
lm-reg-auto:
24+
type: boolean
25+
description: |
26+
Enables to turn over automatically from Boot Regulator Mode to Last Mile
27+
regulator mode and vice versa, depending on the V15 voltage status.
28+
When configuring system clocks higher than FIRC clock frequency,
29+
lm-reg should be also enabled.
30+
31+
lm-reg-base-control:
32+
type: boolean
33+
description: |
34+
Enable this if an external BJT between VDD_HV_A and V15 is used on the
35+
PCB. The base of this BJT must be connected to the VRC_CTRL pin and is
36+
controlled by the PMC to regulate a voltage of 1.5V on V15 pin.

soc/nxp/s32/Kconfig

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,6 @@
33

44
if SOC_FAMILY_NXP_S32
55

6-
config NXP_S32_FUNC_RESET_THRESHOLD
7-
int "Functional Reset Escalation threshold"
8-
default 15
9-
range 0 15
10-
help
11-
If the value of this option is 0, the Functional reset escalation
12-
function is disabled. Any other value is the number of Functional
13-
resets that causes a Destructive reset, if the FRET register isn't
14-
written to beforehand.
15-
Default to maximum threshold (hardware reset value).
16-
17-
config NXP_S32_DEST_RESET_THRESHOLD
18-
int "Destructive Reset Escalation threshold"
19-
default 0
20-
range 0 15
21-
help
22-
If the value of this field is 0, the Destructive reset escalation
23-
function is disabled. Any other value is the number of Destructive
24-
resets which keeps the chip in the reset state until the next power-on
25-
reset triggers a new reset sequence, if the DRET register isn't
26-
written to beforehand.
27-
Default to disabled (hardware reset value).
28-
296
rsource "*/Kconfig"
307

318
endif # SOC_FAMILY_NXP_S32

soc/nxp/s32/common/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@
33

44
zephyr_include_directories(.)
55
zephyr_sources(osif.c)
6-
zephyr_sources_ifdef(CONFIG_SOC_SERIES_S32K3 power_soc.c)
6+
zephyr_library_sources_ifdef(CONFIG_DT_HAS_NXP_S32_MC_RGM_ENABLED mc_rgm.c)
7+
zephyr_library_sources_ifdef(CONFIG_DT_HAS_NXP_S32_MC_ME_ENABLED mc_me.c)

soc/nxp/s32/common/mc_me.c

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT nxp_s32_mc_me
8+
9+
#include <zephyr/kernel.h>
10+
#if defined(CONFIG_REBOOT)
11+
#include <zephyr/sys/reboot.h>
12+
#endif /* CONFIG_REBOOT */
13+
14+
/* Control Key Register */
15+
#define MC_ME_CTL_KEY 0x0
16+
#define MC_ME_CTL_KEY_KEY_MASK GENMASK(15, 0)
17+
#define MC_ME_CTL_KEY_KEY(v) FIELD_PREP(MC_ME_CTL_KEY_KEY_MASK, (v))
18+
/* Mode Configuration Register */
19+
#define MC_ME_MODE_CONF 0x4
20+
#define MC_ME_MODE_CONF_DEST_RST_MASK BIT(0)
21+
#define MC_ME_MODE_CONF_DEST_RST(v) FIELD_PREP(MC_ME_MODE_CONF_DEST_RST_MASK, (v))
22+
#define MC_ME_MODE_CONF_FUNC_RST_MASK BIT(1)
23+
#define MC_ME_MODE_CONF_FUNC_RST(v) FIELD_PREP(MC_ME_MODE_CONF_FUNC_RST_MASK, (v))
24+
#define MC_ME_MODE_CONF_STANDBY_MASK BIT(15)
25+
#define MC_ME_MODE_CONF_STANDBY(v) FIELD_PREP(MC_ME_MODE_CONF_STANDBY_MASK, (v))
26+
/* Mode Update Register */
27+
#define MC_ME_MODE_UPD 0x8
28+
#define MC_ME_MODE_UPD_MODE_UPD_MASK BIT(0)
29+
#define MC_ME_MODE_UPD_MODE_UPD(v) FIELD_PREP(MC_ME_MODE_UPD_MODE_UPD_MASK, (v))
30+
/* Mode Status Register */
31+
#define MC_ME_MODE_STAT 0xc
32+
#define MC_ME_MODE_STAT_PREV_MODE_MASK BIT(0)
33+
#define MC_ME_MODE_STAT_PREV_MODE(v) FIELD_PREP(MC_ME_MODE_STAT_PREV_MODE_MASK, (v))
34+
/* Main Core ID Register */
35+
#define MC_ME_MAIN_COREID 0x10
36+
#define MC_ME_MAIN_COREID_CIDX_MASK GENMASK(2, 0)
37+
#define MC_ME_MAIN_COREID_CIDX(v) FIELD_PREP(MC_ME_MAIN_COREID_CIDX_MASK, (v))
38+
#define MC_ME_MAIN_COREID_PIDX_MASK GENMASK(12, 8)
39+
#define MC_ME_MAIN_COREID_PIDX(v) FIELD_PREP(MC_ME_MAIN_COREID_PIDX_MASK, (v))
40+
/* Partition p Process Configuration Register */
41+
#define MC_ME_PRTN_PCONF(p) (0x100 + 0x200 * (p))
42+
#define MC_ME_PRTN_PCONF_PCE_MASK BIT(0)
43+
#define MC_ME_PRTN_PCONF_PCE(v) FIELD_PREP(MC_ME_PRTN_PCONF_PCE_MASK, (v))
44+
/* Partition p Process Update Register */
45+
#define MC_ME_PRTN_PUPD(p) (0x104 + 0x200 * (p))
46+
#define MC_ME_PRTN_PUPD_PCUD_MASK BIT(0)
47+
#define MC_ME_PRTN_PUPD_PCUD(v) FIELD_PREP(MC_ME_PRTN_PUPD_PCUD_MASK, (v))
48+
/* Partition p Status Register */
49+
#define MC_ME_PRTN_STAT(p) (0x108 + 0x200 * (p))
50+
#define MC_ME_PRTN_STAT_PCS_MASK BIT(0)
51+
#define MC_ME_PRTN_STAT_PCS(v) FIELD_PREP(MC_ME_PRTN_STAT_PCS_MASK, (v))
52+
/* Partition p COFB c Clock Status Register */
53+
#define MC_ME_PRTN_COFB_STAT(p, c) (0x110 + 0x200 * (p) + 0x4 * (c))
54+
/* Partition p COFB c Clock Enable Register */
55+
#define MC_ME_PRTN_COFB_CLKEN(p, c) (0x130 + 0x200 * (p) + 0x4 * (c))
56+
/* Partition p Core c Process Configuration Register */
57+
#define MC_ME_PRTN_CORE_PCONF(p, c) (0x140 + 0x200 * (p) + 0x20 * (c))
58+
#define MC_ME_PRTN_CORE_PCONF_CCE_MASK BIT(0)
59+
#define MC_ME_PRTN_CORE_PCONF_CCE(v) FIELD_PREP(MC_ME_PRTN_CORE_PCONF_CCE_MASK, (v))
60+
/* Partition n Core c Process Update Register */
61+
#define MC_ME_PRTN_CORE_PUPD(p, c) (0x144 + 0x200 * (p) + 0x20 * (c))
62+
#define MC_ME_PRTN_CORE_PUPD_CCUPD_MASK BIT(0)
63+
#define MC_ME_PRTN_CORE_PUPD_CCUPD(v) FIELD_PREP(MC_ME_PRTN_CORE_PUPD_CCUPD_MASK, (v))
64+
/* Partition n Core c Status Register */
65+
#define MC_ME_PRTN_CORE_STAT(p, c) (0x148 + 0x200 * (p) + 0x20 * (c))
66+
#define MC_ME_PRTN_CORE_STAT_CCS_MASK BIT(0)
67+
#define MC_ME_PRTN_CORE_STAT_CCS(v) FIELD_PREP(MC_ME_PRTN_CORE_STAT_CCS_MASK, (v))
68+
#define MC_ME_PRTN_CORE_STAT_WFI_MASK BIT(31)
69+
#define MC_ME_PRTN_CORE_STAT_WFI(v) FIELD_PREP(MC_ME_PRTN_CORE_STAT_WFI_MASK, (v))
70+
/* Partition n Core c Address Register */
71+
#define MC_ME_PRTN_CORE_ADDR(p, c) (0x14c + 0x200 * (p) + 0x20 * (c))
72+
#define MC_ME_PRTN_CORE_ADDR_ADDR_MASK GENMASK(31, 2)
73+
#define MC_ME_PRTN_CORE_ADDR_ADDR(v) FIELD_PREP(MC_ME_PRTN_CORE_ADDR_ADDR_MASK, (v))
74+
75+
#define MC_ME_CTL_KEY_DIRECT_KEY 0x00005af0U
76+
#define MC_ME_CTL_KEY_INVERTED_KEY 0x0000a50fU
77+
78+
/* Handy accessors */
79+
#define REG_READ(r) sys_read32((mem_addr_t)(DT_INST_REG_ADDR(0) + (r)))
80+
#define REG_WRITE(r, v) sys_write32((v), (mem_addr_t)(DT_INST_REG_ADDR(0) + (r)))
81+
82+
/** MC_ME power mode */
83+
enum mc_me_power_mode {
84+
/** Destructive Reset Mode */
85+
MC_ME_DEST_RESET_MODE,
86+
/** Functional Reset Mode */
87+
MC_ME_FUNC_RESET_MODE,
88+
};
89+
90+
#if defined(CONFIG_REBOOT)
91+
static inline void mc_me_write_ctl_key(void)
92+
{
93+
REG_WRITE(MC_ME_CTL_KEY, MC_ME_CTL_KEY_KEY(MC_ME_CTL_KEY_DIRECT_KEY));
94+
REG_WRITE(MC_ME_CTL_KEY, MC_ME_CTL_KEY_KEY(MC_ME_CTL_KEY_INVERTED_KEY));
95+
}
96+
97+
static inline void mc_me_trigger_mode_update(void)
98+
{
99+
REG_WRITE(MC_ME_MODE_UPD, MC_ME_MODE_UPD_MODE_UPD(1U));
100+
mc_me_write_ctl_key();
101+
}
102+
103+
static int mc_me_set_mode(enum mc_me_power_mode mode)
104+
{
105+
int err = 0;
106+
107+
switch (mode) {
108+
case MC_ME_DEST_RESET_MODE:
109+
REG_WRITE(MC_ME_MODE_CONF, MC_ME_MODE_CONF_DEST_RST(1U));
110+
mc_me_trigger_mode_update();
111+
break;
112+
case MC_ME_FUNC_RESET_MODE:
113+
REG_WRITE(MC_ME_MODE_CONF, MC_ME_MODE_CONF_FUNC_RST(1U));
114+
mc_me_trigger_mode_update();
115+
break;
116+
default:
117+
err = -ENOTSUP;
118+
break;
119+
}
120+
121+
return err;
122+
}
123+
124+
/*
125+
* Overrides default weak implementation of system reboot.
126+
*
127+
* SYS_REBOOT_COLD (Destructive Reset):
128+
* - Leads most parts of the chip, except a few modules, to reset. SRAM content
129+
* is lost after this reset event.
130+
* - Flash is always reset, so an updated value of the option bits is reloaded
131+
* in volatile registers outside of the Flash array.
132+
* - Trimming is lost.
133+
* - STCU is reset and configured BISTs are executed.
134+
*
135+
* SYS_REBOOT_WARM (Functional Reset):
136+
* - Leads all the communication peripherals and cores to reset. The communication
137+
* protocols' sanity is not guaranteed and they are assumed to be reinitialized
138+
* after reset. The SRAM content, and the functionality of certain modules, is
139+
* preserved across functional reset.
140+
* - The volatile registers are not reset; in case of a reset event, the
141+
* trimming is maintained.
142+
* - No BISTs are executed after functional reset.
143+
*/
144+
void sys_arch_reboot(int type)
145+
{
146+
switch (type) {
147+
case SYS_REBOOT_COLD:
148+
mc_me_set_mode(MC_ME_DEST_RESET_MODE);
149+
break;
150+
case SYS_REBOOT_WARM:
151+
mc_me_set_mode(MC_ME_FUNC_RESET_MODE);
152+
break;
153+
default:
154+
/* Do nothing */
155+
break;
156+
}
157+
}
158+
#endif /* CONFIG_REBOOT */

0 commit comments

Comments
 (0)