Skip to content

Commit

Permalink
drivers: firmware: scmi: add more APIs of clock management protocol
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
yangbolu1991 authored and kartben committed Jan 15, 2025
1 parent 7537a14 commit db70391
Show file tree
Hide file tree
Showing 2 changed files with 177 additions and 0 deletions.
123 changes: 123 additions & 0 deletions drivers/firmware/scmi/clk.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ struct scmi_clock_rate_set_reply {
uint32_t rate[2];
};

struct scmi_clock_parent_get_reply {
int32_t status;
uint32_t parent_id;
};

struct scmi_clock_parent_config {
uint32_t clk_id;
uint32_t parent_id;
};

int scmi_clock_rate_get(struct scmi_protocol *proto,
uint32_t clk_id, uint32_t *rate)
{
Expand Down Expand Up @@ -61,6 +71,119 @@ int scmi_clock_rate_get(struct scmi_protocol *proto,
return 0;
}

int scmi_clock_rate_set(struct scmi_protocol *proto, struct scmi_clock_rate_config *cfg)
{
struct scmi_message msg, reply;
int status, ret;

/* sanity checks */
if (!proto || !cfg) {
return -EINVAL;
}

if (proto->id != SCMI_PROTOCOL_CLOCK) {
return -EINVAL;
}

/* Currently ASYNC flag is not supported. */
if (cfg->flags & SCMI_CLK_RATE_SET_FLAGS_ASYNC) {
return -ENOTSUP;
}

msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_CLK_MSG_CLOCK_RATE_SET, SCMI_COMMAND, proto->id, 0x0);
msg.len = sizeof(*cfg);
msg.content = cfg;

reply.hdr = msg.hdr;
reply.len = sizeof(status);
reply.content = &status;

ret = scmi_send_message(proto, &msg, &reply);
if (ret < 0) {
return ret;
}

if (status != SCMI_SUCCESS) {
return scmi_status_to_errno(status);
}

return 0;
}

int scmi_clock_parent_get(struct scmi_protocol *proto, uint32_t clk_id, uint32_t *parent_id)
{
struct scmi_message msg, reply;
int ret;
struct scmi_clock_parent_get_reply reply_buffer;

/* sanity checks */
if (!proto || !parent_id) {
return -EINVAL;
}

if (proto->id != SCMI_PROTOCOL_CLOCK) {
return -EINVAL;
}

msg.hdr =
SCMI_MESSAGE_HDR_MAKE(SCMI_CLK_MSG_CLOCK_PARENT_GET, SCMI_COMMAND, proto->id, 0x0);
msg.len = sizeof(clk_id);
msg.content = &clk_id;

reply.hdr = msg.hdr;
reply.len = sizeof(reply_buffer);
reply.content = &reply_buffer;

ret = scmi_send_message(proto, &msg, &reply);
if (ret < 0) {
return ret;
}

if (reply_buffer.status != SCMI_SUCCESS) {
return scmi_status_to_errno(reply_buffer.status);
}

*parent_id = reply_buffer.parent_id;

return 0;
}

int scmi_clock_parent_set(struct scmi_protocol *proto, uint32_t clk_id, uint32_t parent_id)
{
struct scmi_clock_parent_config cfg = {.clk_id = clk_id, .parent_id = parent_id};
struct scmi_message msg, reply;
int status, ret;

/* sanity checks */
if (!proto) {
return -EINVAL;
}

if (proto->id != SCMI_PROTOCOL_CLOCK) {
return -EINVAL;
}

msg.hdr =
SCMI_MESSAGE_HDR_MAKE(SCMI_CLK_MSG_CLOCK_PARENT_SET, SCMI_COMMAND, proto->id, 0x0);
msg.len = sizeof(cfg);
msg.content = &cfg;

reply.hdr = msg.hdr;
reply.len = sizeof(status);
reply.content = &status;

ret = scmi_send_message(proto, &msg, &reply);
if (ret < 0) {
return ret;
}

if (status != SCMI_SUCCESS) {
return scmi_status_to_errno(status);
}

return 0;
}

int scmi_clock_config_set(struct scmi_protocol *proto,
struct scmi_clock_config *cfg)
{
Expand Down
54 changes: 54 additions & 0 deletions include/zephyr/drivers/firmware/scmi/clk.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@

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

#define SCMI_CLK_RATE_SET_FLAGS_ASYNC BIT(0)
#define SCMI_CLK_RATE_SET_FLAGS_IGNORE_DELEAYED_RESP BIT(1)
#define SCMI_CLK_RATE_SET_FLAGS_ROUNDS_UP_DOWN BIT(2)
#define SCMI_CLK_RATE_SET_FLAGS_ROUNDS_AUTO BIT(3)

/**
* @struct scmi_clock_config
*
Expand All @@ -32,6 +37,18 @@ struct scmi_clock_config {
uint32_t extended_cfg_val;
};

/**
* @struct scmi_clock_rate_config
*
* @brief Describes the parameters for the CLOCK_RATE_SET
* command
*/
struct scmi_clock_rate_config {
uint32_t flags;
uint32_t clk_id;
uint32_t rate[2];
};

/**
* @brief Clock protocol command message IDs
*/
Expand Down Expand Up @@ -93,4 +110,41 @@ int scmi_clock_config_set(struct scmi_protocol *proto,
int scmi_clock_rate_get(struct scmi_protocol *proto,
uint32_t clk_id, uint32_t *rate);

/**
* @brief Send the CLOCK_RATE_SET command and get its reply
*
* @param proto pointer to SCMI clock protocol data
* @param cfg pointer to structure containing configuration
* to be set
*
* @retval 0 if successful
* @retval negative errno if failure
*/
int scmi_clock_rate_set(struct scmi_protocol *proto, struct scmi_clock_rate_config *cfg);

/**
* @brief Query the parent of a clock
*
* @param proto pointer to SCMI clock protocol data
* @param clk_id ID of the clock for which the query is done
* @param parent_id pointer to be set via this command
*
* @retval 0 if successful
* @retval negative errno if failure
*/
int scmi_clock_parent_get(struct scmi_protocol *proto, uint32_t clk_id, uint32_t *parent_id);

/**
* @brief Send the CLOCK_PARENT_SET command and get its reply
*
* @param proto pointer to SCMI clock protocol data
* @param clk_id ID of the clock for which the query is done
* @param parent_id to be set via this command
* to be set
*
* @retval 0 if successful
* @retval negative errno if failure
*/
int scmi_clock_parent_set(struct scmi_protocol *proto, uint32_t clk_id, uint32_t parent_id);

#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_CLK_H_ */

0 comments on commit db70391

Please sign in to comment.