Skip to content

Commit db70391

Browse files
yangbolu1991kartben
authored andcommitted
drivers: firmware: scmi: add more APIs of clock management protocol
Added more APIs for ARM SCMI clock management protocol. - scmi_clock_rate_set - scmi_clock_parent_get - scmi_clock_parent_set Signed-off-by: Yangbo Lu <[email protected]>
1 parent 7537a14 commit db70391

File tree

2 files changed

+177
-0
lines changed
  • drivers/firmware/scmi
  • include/zephyr/drivers/firmware/scmi

2 files changed

+177
-0
lines changed

drivers/firmware/scmi/clk.c

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ struct scmi_clock_rate_set_reply {
2222
uint32_t rate[2];
2323
};
2424

25+
struct scmi_clock_parent_get_reply {
26+
int32_t status;
27+
uint32_t parent_id;
28+
};
29+
30+
struct scmi_clock_parent_config {
31+
uint32_t clk_id;
32+
uint32_t parent_id;
33+
};
34+
2535
int scmi_clock_rate_get(struct scmi_protocol *proto,
2636
uint32_t clk_id, uint32_t *rate)
2737
{
@@ -61,6 +71,119 @@ int scmi_clock_rate_get(struct scmi_protocol *proto,
6171
return 0;
6272
}
6373

74+
int scmi_clock_rate_set(struct scmi_protocol *proto, struct scmi_clock_rate_config *cfg)
75+
{
76+
struct scmi_message msg, reply;
77+
int status, ret;
78+
79+
/* sanity checks */
80+
if (!proto || !cfg) {
81+
return -EINVAL;
82+
}
83+
84+
if (proto->id != SCMI_PROTOCOL_CLOCK) {
85+
return -EINVAL;
86+
}
87+
88+
/* Currently ASYNC flag is not supported. */
89+
if (cfg->flags & SCMI_CLK_RATE_SET_FLAGS_ASYNC) {
90+
return -ENOTSUP;
91+
}
92+
93+
msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_CLK_MSG_CLOCK_RATE_SET, SCMI_COMMAND, proto->id, 0x0);
94+
msg.len = sizeof(*cfg);
95+
msg.content = cfg;
96+
97+
reply.hdr = msg.hdr;
98+
reply.len = sizeof(status);
99+
reply.content = &status;
100+
101+
ret = scmi_send_message(proto, &msg, &reply);
102+
if (ret < 0) {
103+
return ret;
104+
}
105+
106+
if (status != SCMI_SUCCESS) {
107+
return scmi_status_to_errno(status);
108+
}
109+
110+
return 0;
111+
}
112+
113+
int scmi_clock_parent_get(struct scmi_protocol *proto, uint32_t clk_id, uint32_t *parent_id)
114+
{
115+
struct scmi_message msg, reply;
116+
int ret;
117+
struct scmi_clock_parent_get_reply reply_buffer;
118+
119+
/* sanity checks */
120+
if (!proto || !parent_id) {
121+
return -EINVAL;
122+
}
123+
124+
if (proto->id != SCMI_PROTOCOL_CLOCK) {
125+
return -EINVAL;
126+
}
127+
128+
msg.hdr =
129+
SCMI_MESSAGE_HDR_MAKE(SCMI_CLK_MSG_CLOCK_PARENT_GET, SCMI_COMMAND, proto->id, 0x0);
130+
msg.len = sizeof(clk_id);
131+
msg.content = &clk_id;
132+
133+
reply.hdr = msg.hdr;
134+
reply.len = sizeof(reply_buffer);
135+
reply.content = &reply_buffer;
136+
137+
ret = scmi_send_message(proto, &msg, &reply);
138+
if (ret < 0) {
139+
return ret;
140+
}
141+
142+
if (reply_buffer.status != SCMI_SUCCESS) {
143+
return scmi_status_to_errno(reply_buffer.status);
144+
}
145+
146+
*parent_id = reply_buffer.parent_id;
147+
148+
return 0;
149+
}
150+
151+
int scmi_clock_parent_set(struct scmi_protocol *proto, uint32_t clk_id, uint32_t parent_id)
152+
{
153+
struct scmi_clock_parent_config cfg = {.clk_id = clk_id, .parent_id = parent_id};
154+
struct scmi_message msg, reply;
155+
int status, ret;
156+
157+
/* sanity checks */
158+
if (!proto) {
159+
return -EINVAL;
160+
}
161+
162+
if (proto->id != SCMI_PROTOCOL_CLOCK) {
163+
return -EINVAL;
164+
}
165+
166+
msg.hdr =
167+
SCMI_MESSAGE_HDR_MAKE(SCMI_CLK_MSG_CLOCK_PARENT_SET, SCMI_COMMAND, proto->id, 0x0);
168+
msg.len = sizeof(cfg);
169+
msg.content = &cfg;
170+
171+
reply.hdr = msg.hdr;
172+
reply.len = sizeof(status);
173+
reply.content = &status;
174+
175+
ret = scmi_send_message(proto, &msg, &reply);
176+
if (ret < 0) {
177+
return ret;
178+
}
179+
180+
if (status != SCMI_SUCCESS) {
181+
return scmi_status_to_errno(status);
182+
}
183+
184+
return 0;
185+
}
186+
64187
int scmi_clock_config_set(struct scmi_protocol *proto,
65188
struct scmi_clock_config *cfg)
66189
{

include/zephyr/drivers/firmware/scmi/clk.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020

2121
#define SCMI_CLK_ATTRIBUTES_CLK_NUM(x) ((x) & GENMASK(15, 0))
2222

23+
#define SCMI_CLK_RATE_SET_FLAGS_ASYNC BIT(0)
24+
#define SCMI_CLK_RATE_SET_FLAGS_IGNORE_DELEAYED_RESP BIT(1)
25+
#define SCMI_CLK_RATE_SET_FLAGS_ROUNDS_UP_DOWN BIT(2)
26+
#define SCMI_CLK_RATE_SET_FLAGS_ROUNDS_AUTO BIT(3)
27+
2328
/**
2429
* @struct scmi_clock_config
2530
*
@@ -32,6 +37,18 @@ struct scmi_clock_config {
3237
uint32_t extended_cfg_val;
3338
};
3439

40+
/**
41+
* @struct scmi_clock_rate_config
42+
*
43+
* @brief Describes the parameters for the CLOCK_RATE_SET
44+
* command
45+
*/
46+
struct scmi_clock_rate_config {
47+
uint32_t flags;
48+
uint32_t clk_id;
49+
uint32_t rate[2];
50+
};
51+
3552
/**
3653
* @brief Clock protocol command message IDs
3754
*/
@@ -93,4 +110,41 @@ int scmi_clock_config_set(struct scmi_protocol *proto,
93110
int scmi_clock_rate_get(struct scmi_protocol *proto,
94111
uint32_t clk_id, uint32_t *rate);
95112

113+
/**
114+
* @brief Send the CLOCK_RATE_SET command and get its reply
115+
*
116+
* @param proto pointer to SCMI clock protocol data
117+
* @param cfg pointer to structure containing configuration
118+
* to be set
119+
*
120+
* @retval 0 if successful
121+
* @retval negative errno if failure
122+
*/
123+
int scmi_clock_rate_set(struct scmi_protocol *proto, struct scmi_clock_rate_config *cfg);
124+
125+
/**
126+
* @brief Query the parent of a clock
127+
*
128+
* @param proto pointer to SCMI clock protocol data
129+
* @param clk_id ID of the clock for which the query is done
130+
* @param parent_id pointer to be set via this command
131+
*
132+
* @retval 0 if successful
133+
* @retval negative errno if failure
134+
*/
135+
int scmi_clock_parent_get(struct scmi_protocol *proto, uint32_t clk_id, uint32_t *parent_id);
136+
137+
/**
138+
* @brief Send the CLOCK_PARENT_SET command and get its reply
139+
*
140+
* @param proto pointer to SCMI clock protocol data
141+
* @param clk_id ID of the clock for which the query is done
142+
* @param parent_id to be set via this command
143+
* to be set
144+
*
145+
* @retval 0 if successful
146+
* @retval negative errno if failure
147+
*/
148+
int scmi_clock_parent_set(struct scmi_protocol *proto, uint32_t clk_id, uint32_t parent_id);
149+
96150
#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_CLK_H_ */

0 commit comments

Comments
 (0)