Skip to content

Commit c412ee4

Browse files
ZhaoQiang-b45475kartben
authored andcommitted
drivers: firmware: scmi: add cpu domain protocol
Added helpers for NXP SCMI cpu dmomain protocol. Signed-off-by: Qiang Zhao <[email protected]>
1 parent 89dd0ef commit c412ee4

File tree

7 files changed

+177
-0
lines changed

7 files changed

+177
-0
lines changed

doc/hardware/arch/arm-scmi.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ Currently, Zephyr has support for the following standard protocols:
139139
#. **Clock management**
140140
#. **Pin Control**
141141

142+
NXP-specific protocols:
143+
#. **CPU domain management**
142144

143145
Power domain management
144146
***********************
@@ -178,6 +180,16 @@ supported command is ``PINCTRL_SETTINGS_CONFIGURE``.
178180
call into the SCMI pin control protocol function implementing the
179181
``PINCTRL_SETTINGS_CONFIGURE`` command.
180182

183+
NXP - CPU domain management
184+
***************************
185+
186+
This protocol is intended for management of cpu states.
187+
This is done via a set of functions implementing various commands, for
188+
example, ``CPU_SLEEP_MODE_SET``.
189+
190+
.. note::
191+
This driver is NXP-specific. As such, it may only be used on NXP
192+
system that uses SCMI for cpu domain management operations.
181193

182194
Enabling the SCMI support
183195
*************************
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
zephyr_library()
34
zephyr_library_sources_ifdef(CONFIG_ARM_SCMI_NXP_VENDOR_EXTENSIONS shmem.c)
5+
zephyr_library_sources_ifdef(CONFIG_NXP_SCMI_CPU_DOMAIN_HELPERS cpu.c)

drivers/firmware/scmi/nxp/Kconfig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,14 @@ config ARM_SCMI_NXP_VENDOR_EXTENSIONS
66
select CRC
77
help
88
When enabled, additional SCMI features specific to NXP will be available
9+
10+
if ARM_SCMI_NXP_VENDOR_EXTENSIONS
11+
12+
config NXP_SCMI_CPU_DOMAIN_HELPERS
13+
bool "Helper functions for SCMI cpu domain protocol"
14+
default y
15+
depends on DT_HAS_NXP_SCMI_CPU_ENABLED
16+
help
17+
Enable support for SCMI cpu domain protocol helper functions.
18+
19+
endif # ARM_SCMI_NXP_VENDOR_EXTENSIONS

drivers/firmware/scmi/nxp/cpu.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <string.h>
8+
#include <zephyr/drivers/firmware/scmi/nxp/cpu.h>
9+
10+
DT_SCMI_PROTOCOL_DEFINE_NODEV(DT_INST(0, nxp_scmi_cpu), NULL);
11+
12+
int scmi_cpu_sleep_mode_set(struct scmi_cpu_sleep_mode_config *cfg)
13+
{
14+
struct scmi_protocol *proto = &SCMI_PROTOCOL_NAME(SCMI_PROTOCOL_CPU_DOMAIN);
15+
struct scmi_message msg, reply;
16+
int status, ret;
17+
18+
/* sanity checks */
19+
if (!proto || !cfg) {
20+
return -EINVAL;
21+
}
22+
23+
if (proto->id != SCMI_PROTOCOL_CPU_DOMAIN) {
24+
return -EINVAL;
25+
}
26+
27+
msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_CPU_DOMAIN_MSG_CPU_SLEEP_MODE_SET, SCMI_COMMAND,
28+
proto->id, 0x0);
29+
msg.len = sizeof(*cfg);
30+
msg.content = cfg;
31+
32+
reply.hdr = msg.hdr;
33+
reply.len = sizeof(status);
34+
reply.content = &status;
35+
36+
ret = scmi_send_message(proto, &msg, &reply);
37+
if (ret < 0) {
38+
return ret;
39+
}
40+
41+
if (status != SCMI_SUCCESS) {
42+
return scmi_status_to_errno(status);
43+
}
44+
45+
return 0;
46+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: System Control and Management Interface (SCMI) cpu domain protocol
5+
6+
compatible: "nxp,scmi-cpu"
7+
8+
include: [base.yaml]
9+
10+
properties:
11+
reg:
12+
required: true
13+
const: [0x82]
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* @brief SCMI power domain protocol helpers
10+
*/
11+
12+
#ifndef _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_CPU_H_
13+
#define _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_CPU_H_
14+
15+
#include <zephyr/drivers/firmware/scmi/protocol.h>
16+
#if __has_include("scmi_cpu_soc.h")
17+
#include <scmi_cpu_soc.h>
18+
#endif
19+
20+
#define SCMI_CPU_SLEEP_FLAG_IRQ_MUX 0x1U
21+
22+
#define SCMI_PROTOCOL_CPU_DOMAIN 130
23+
24+
/**
25+
* @struct scmi_cpu_sleep_mode_config
26+
*
27+
* @brief Describes the parameters for the CPU_STATE_SET
28+
* command
29+
*/
30+
struct scmi_cpu_sleep_mode_config {
31+
uint32_t cpu_id;
32+
uint32_t flags;
33+
uint32_t sleep_mode;
34+
};
35+
36+
/**
37+
* @brief CPU domain protocol command message IDs
38+
*/
39+
enum scmi_cpu_domain_message {
40+
SCMI_CPU_DOMAIN_MSG_PROTOCOL_VERSION = 0x0,
41+
SCMI_CPU_DOMAIN_MSG_PROTOCOL_ATTRIBUTES = 0x1,
42+
SCMI_CPU_DOMAIN_MSG_PROTOCOL_MESSAGE_ATTRIBUTES = 0x2,
43+
SCMI_CPU_DOMAIN_MSG_CPU_DOMAIN_ATTRIBUTES = 0x3,
44+
SCMI_CPU_DOMAIN_MSG_CPU_START = 0x4,
45+
SCMI_CPU_DOMAIN_MSG_CPU_STOP = 0x5,
46+
SCMI_CPU_DOMAIN_MSG_CPU_RESET_VECTOR_SET = 0x6,
47+
SCMI_CPU_DOMAIN_MSG_CPU_SLEEP_MODE_SET = 0x7,
48+
SCMI_CPU_DOMAIN_MSG_CPU_IRQ_WAKE_SET = 0x8,
49+
SCMI_CPU_DOMAIN_MSG_CPU_NON_IRQ_WAKE_SET = 0x9,
50+
SCMI_CPU_DOMAIN_MSG_CPU_PD_LPM_CONFIG_SET = 0xA,
51+
SCMI_CPU_DOMAIN_MSG_CPU_PER_LPM_CONFIG_SET = 0xB,
52+
SCMI_CPU_DOMAIN_MSG_CPU_INFO_GET = 0xC,
53+
SCMI_CPU_DOMAIN_MSG_NEGOTIATE_PROTOCOL_VERSION = 0x10,
54+
};
55+
56+
/**
57+
* @brief Send the CPU_SLEEP_MODE_SET command and get its reply
58+
*
59+
* @param cfg pointer to structure containing configuration
60+
* to be set
61+
*
62+
* @retval 0 if successful
63+
* @retval negative errno if failure
64+
*/
65+
int scmi_cpu_sleep_mode_set(struct scmi_cpu_sleep_mode_config *cfg);
66+
67+
#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_CPU_H_ */

soc/nxp/imx/imx9/imx95/scmi_cpu_soc.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_NXP_IMX95_SCMI_CPU_SOC_H_
8+
#define ZEPHYR_NXP_IMX95_SCMI_CPU_SOC_H_
9+
10+
#define CPU_IDX_M33P 0U
11+
#define CPU_IDX_M7P 1U
12+
#define CPU_IDX_A55C0 2U
13+
#define CPU_IDX_A55C1 3U
14+
#define CPU_IDX_A55C2 4U
15+
#define CPU_IDX_A55C3 5U
16+
#define CPU_IDX_A55C4 6U
17+
#define CPU_IDX_A55C5 7U
18+
#define CPU_IDX_A55P 8U
19+
#define CPU_NUM_IDX 9U
20+
21+
#define CPU_SLEEP_MODE_RUN 0U
22+
#define CPU_SLEEP_MODE_WAIT 1U
23+
#define CPU_SLEEP_MODE_STOP 2U
24+
#define CPU_SLEEP_MODE_SUSPEND 3U
25+
26+
#endif /* ZEPHYR_NXP_IMX95_SCMI_CPU_SOC_H_ */

0 commit comments

Comments
 (0)