Skip to content

Commit 7c57fec

Browse files
yangbolu1991kartben
authored andcommitted
drivers: firmware: scmi: add power domain protocol
Added helpers for ARM SCMI power dmomain protocol. Signed-off-by: Yangbo Lu <[email protected]>
1 parent db70391 commit 7c57fec

File tree

6 files changed

+204
-0
lines changed

6 files changed

+204
-0
lines changed

doc/hardware/arch/arm-scmi.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,22 @@ Protocols
135135

136136
Currently, Zephyr has support for the following standard protocols:
137137

138+
#. **Power domain management**
138139
#. **Clock management**
139140
#. **Pin Control**
140141

141142

143+
Power domain management
144+
***********************
145+
146+
This protocol is intended for management of power states of power domains.
147+
This is done via a set of functions implementing various commands, for
148+
example, ``POWER_STATE_GET`` and ``POWER_STATE_SET``.
149+
150+
.. note::
151+
This driver is vendor-agnostic. As such, it may be used on any
152+
system that uses SCMI for power domain management operations.
153+
142154
Clock management protocol
143155
*************************
144156

drivers/firmware/scmi/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ zephyr_library_sources_ifdef(CONFIG_ARM_SCMI_SHMEM shmem.c)
1010
# SCMI protocol helper files
1111
zephyr_library_sources_ifdef(CONFIG_ARM_SCMI_CLK_HELPERS clk.c)
1212
zephyr_library_sources_ifdef(CONFIG_ARM_SCMI_PINCTRL_HELPERS pinctrl.c)
13+
zephyr_library_sources_ifdef(CONFIG_ARM_SCMI_POWER_DOMAIN_HELPERS power.c)

drivers/firmware/scmi/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ config ARM_SCMI_PINCTRL_HELPERS
2828
help
2929
Enable support for SCMI pinctrl protocol helper functions.
3030

31+
config ARM_SCMI_POWER_DOMAIN_HELPERS
32+
bool "Helper functions for SCMI power domain protocol"
33+
default y
34+
depends on DT_HAS_ARM_SCMI_POWER_ENABLED
35+
help
36+
Enable support for SCMI power domain protocol helper functions.
37+
3138
config ARM_SCMI_SHMEM
3239
bool "SCMI shared memory (SHMEM) driver"
3340
default y

drivers/firmware/scmi/power.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright 2024 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/drivers/firmware/scmi/power.h>
8+
#include <string.h>
9+
10+
DT_SCMI_PROTOCOL_DEFINE_NODEV(DT_INST(0, arm_scmi_power), NULL);
11+
12+
struct scmi_power_state_get_reply {
13+
int32_t status;
14+
uint32_t power_state;
15+
};
16+
17+
int scmi_power_state_get(uint32_t domain_id, uint32_t *power_state)
18+
{
19+
struct scmi_protocol *proto = &SCMI_PROTOCOL_NAME(SCMI_PROTOCOL_POWER_DOMAIN);
20+
struct scmi_power_state_get_reply reply_buffer;
21+
struct scmi_message msg, reply;
22+
int ret;
23+
24+
/* sanity checks */
25+
if (!proto || !power_state) {
26+
return -EINVAL;
27+
}
28+
29+
if (proto->id != SCMI_PROTOCOL_POWER_DOMAIN) {
30+
return -EINVAL;
31+
}
32+
33+
msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_POWER_DOMAIN_MSG_POWER_STATE_GET, SCMI_COMMAND,
34+
proto->id, 0x0);
35+
msg.len = sizeof(domain_id);
36+
msg.content = &domain_id;
37+
38+
reply.hdr = msg.hdr;
39+
reply.len = sizeof(reply_buffer);
40+
reply.content = &reply_buffer;
41+
42+
ret = scmi_send_message(proto, &msg, &reply);
43+
if (ret < 0) {
44+
return ret;
45+
}
46+
47+
if (reply_buffer.status != SCMI_SUCCESS) {
48+
return scmi_status_to_errno(reply_buffer.status);
49+
}
50+
51+
*power_state = reply_buffer.power_state;
52+
53+
return 0;
54+
}
55+
56+
int scmi_power_state_set(struct scmi_power_state_config *cfg)
57+
{
58+
struct scmi_protocol *proto = &SCMI_PROTOCOL_NAME(SCMI_PROTOCOL_POWER_DOMAIN);
59+
struct scmi_message msg, reply;
60+
int status, ret;
61+
62+
/* sanity checks */
63+
if (!proto || !cfg) {
64+
return -EINVAL;
65+
}
66+
67+
if (proto->id != SCMI_PROTOCOL_POWER_DOMAIN) {
68+
return -EINVAL;
69+
}
70+
71+
/* Currently ASYNC flag is not supported. */
72+
if (cfg->flags & SCMI_POWER_STATE_SET_FLAGS_ASYNC) {
73+
return -ENOTSUP;
74+
}
75+
76+
msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_POWER_DOMAIN_MSG_POWER_STATE_SET, SCMI_COMMAND,
77+
proto->id, 0x0);
78+
msg.len = sizeof(*cfg);
79+
msg.content = cfg;
80+
81+
reply.hdr = msg.hdr;
82+
reply.len = sizeof(status);
83+
reply.content = &status;
84+
85+
ret = scmi_send_message(proto, &msg, &reply);
86+
if (ret < 0) {
87+
return ret;
88+
}
89+
90+
if (status != SCMI_SUCCESS) {
91+
return scmi_status_to_errno(status);
92+
}
93+
94+
return 0;
95+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2024 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: System Control and Management Interface (SCMI) power domain protocol
5+
6+
compatible: "arm,scmi-power"
7+
8+
include: [base.yaml]
9+
10+
properties:
11+
reg:
12+
required: true
13+
const: [0x11]
14+
15+
"#power-domain-cells":
16+
type: int
17+
required: true
18+
const: 1
19+
20+
power-domain-cells:
21+
- name
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2024 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_POWER_H_
13+
#define _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_POWER_H_
14+
15+
#include <zephyr/drivers/firmware/scmi/protocol.h>
16+
17+
#define SCMI_POWER_STATE_SET_FLAGS_ASYNC BIT(0)
18+
19+
/**
20+
* @struct scmi_power_state_config
21+
*
22+
* @brief Describes the parameters for the POWER_STATE_SET
23+
* command
24+
*/
25+
struct scmi_power_state_config {
26+
uint32_t flags;
27+
uint32_t domain_id;
28+
uint32_t power_state;
29+
};
30+
31+
/**
32+
* @brief Power domain protocol command message IDs
33+
*/
34+
enum scmi_power_domain_message {
35+
SCMI_POWER_DOMAIN_MSG_PROTOCOL_VERSION = 0x0,
36+
SCMI_POWER_DOMAIN_MSG_PROTOCOL_ATTRIBUTES = 0x1,
37+
SCMI_POWER_DOMAIN_MSG_PROTOCOL_MESSAGE_ATTRIBUTES = 0x2,
38+
SCMI_POWER_DOMAIN_MSG_POWER_DOMAIN_ATTRIBUTES = 0x3,
39+
SCMI_POWER_DOMAIN_MSG_POWER_STATE_SET = 0x4,
40+
SCMI_POWER_DOMAIN_MSG_POWER_STATE_GET = 0x5,
41+
SCMI_POWER_DOMAIN_MSG_POWER_STATE_NOTIFY = 0x6,
42+
SCMI_POWER_DOMAIN_MSG_POWER_STATE_CHANGE_REQEUSTED_NOTIFY = 0x7,
43+
SCMI_POWER_DOMAIN_MSG_POWER_DOMAIN_NAME_GET = 0x8,
44+
SCMI_POWER_DOMAIN_MSG_NEGOTIATE_PROTOCOL_VERSION = 0x10,
45+
};
46+
47+
/**
48+
* @brief Send the POWER_STATE_SET command and get its reply
49+
*
50+
* @param cfg pointer to structure containing configuration
51+
* to be set
52+
*
53+
* @retval 0 if successful
54+
* @retval negative errno if failure
55+
*/
56+
int scmi_power_state_set(struct scmi_power_state_config *cfg);
57+
/**
58+
* @brief Query the power domain state
59+
*
60+
* @param domain_id ID of the power domain for which the query is done
61+
* @param power_state pointer to be set via this command
62+
*
63+
* @retval 0 if successful
64+
* @retval negative errno if failure
65+
*/
66+
int scmi_power_state_get(uint32_t domain_id, uint32_t *power_state);
67+
68+
#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_POWER_H_ */

0 commit comments

Comments
 (0)