Skip to content

Commit 2efb4fc

Browse files
committed
max32: cpu_freq: Add CPU freq support to MAX32655
Define P-states for Max32 and add cpu_freq driver for MAX32655. Signed-off-by: Sean Kyer <[email protected]>
1 parent 76d4976 commit 2efb4fc

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed

boards/adi/max32655fthr/max32655fthr_max32655_m4.dts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@
9696
<1 0 &gpio2 1 0>, /* AIN1 */
9797
<0 0 &gpio2 0 0>; /* AIN0 */
9898
};
99+
100+
performance-states {
101+
pstate_0: pstate_0 {
102+
compatible = "adi,max32-pstate";
103+
load-threshold = <50>;
104+
pstate-id = <0>;
105+
};
106+
pstate_1: pstate_1 {
107+
compatible = "adi,max32-pstate";
108+
load-threshold = <20>;
109+
pstate-id = <1>;
110+
};
111+
pstate_2: pstate_2 {
112+
compatible = "adi,max32-pstate";
113+
load-threshold = <0>;
114+
pstate-id = <2>;
115+
};
116+
};
99117
};
100118

101119
&uart0 {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2025 Analog Devices, Inc.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
description: Max32 custom properties for performance state (pstate)
6+
7+
compatible: "adi,max32-pstate"
8+
9+
include: "zephyr,pstate.yaml"
10+
11+
properties:
12+
pstate-id:
13+
type: int
14+
required: true
15+
description: |
16+
Identifier of performance state which maps to a divider setting.

samples/subsys/cpu_freq/on_demand/sample.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ sample:
44
tests:
55
sample.cpu_freq:
66
tags: cpu_freq
7+
platform_allow:
8+
- max32655fthr/max32655/m4

soc/adi/max32/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,8 @@ if(CONFIG_SOC_MAX78000 OR CONFIG_SOC_MAX78002)
1414
endif()
1515

1616
set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/arm/cortex_m/scripts/linker.ld CACHE INTERNAL "")
17+
18+
if(CONFIG_SOC_MAX32655)
19+
zephyr_library_sources_ifdef(CONFIG_CPU_FREQ max32655/cpu_freq.c)
20+
zephyr_include_directories(max32655)
21+
endif()

soc/adi/max32/max32655/cpu_freq.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2025 Analog Devices, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/devicetree.h>
9+
#include <zephyr/cpu_freq/cpu_freq.h>
10+
#include <zephyr/cpu_freq/pstate.h>
11+
#include <zephyr/logging/log.h>
12+
13+
#include "mxc_sys.h"
14+
15+
LOG_MODULE_REGISTER(max32655_cpu_freq, CONFIG_CPU_FREQ_LOG_LEVEL);
16+
17+
struct max32_config {
18+
int state_id;
19+
};
20+
21+
int32_t cpu_freq_pstate_set(struct pstate state)
22+
{
23+
int state_id = ((const struct max32_config *)state.config)->state_id;
24+
25+
LOG_DBG("Setting performance state: %d", state_id);
26+
27+
switch (state_id) {
28+
case 0:
29+
LOG_DBG("Setting P-state 0: Nominal Mode");
30+
break;
31+
case 1:
32+
LOG_DBG("Setting P-state 1: Low Power Mode");
33+
break;
34+
case 2:
35+
LOG_DBG("Setting P-state 2: Ultra-low Power Mode");
36+
break;
37+
default:
38+
LOG_ERR("Unsupported P-state: %d", state_id);
39+
return -1;
40+
}
41+
42+
return 0;
43+
}
44+
45+
#define DEFINE_MAX32_CONFIG(node_id) \
46+
static const struct max32_config _CONCAT(max32_config_, node_id) = { \
47+
.state_id = DT_PROP(node_id, pstate_id), \
48+
}; \
49+
PSTATE_DT_DEFINE(node_id, &_CONCAT(max32_config_, node_id))
50+
51+
DT_FOREACH_CHILD(DT_PATH(performance_states), DEFINE_MAX32_CONFIG)

soc/adi/max32/max32655/cpu_freq_soc.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2025 Analog Devices, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_CPU_FREQ_SOC_H__
8+
#define ZEPHYR_CPU_FREQ_SOC_H__
9+
10+
#include <zephyr/cpu_freq/pstate.h>
11+
12+
/* Define performance-states as extern to be picked up by CPU Freq policy */
13+
#define DECLARE_PSTATE_EXTERN(node_id) \
14+
extern const struct pstate _CONCAT(pstate_, DEVICE_DT_NAME_GET(node_id));
15+
16+
DT_FOREACH_CHILD(DT_PATH(performance_states), DECLARE_PSTATE_EXTERN)
17+
18+
#endif /* ZEPHYR_CPU_FREQ_SOC_H__ */

0 commit comments

Comments
 (0)