-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drivers: firmware: scmi: add power domain protocol
Added helpers for ARM SCMI power dmomain protocol. Signed-off-by: Yangbo Lu <[email protected]>
- Loading branch information
1 parent
db70391
commit 7c57fec
Showing
6 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright 2024 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include <zephyr/drivers/firmware/scmi/power.h> | ||
#include <string.h> | ||
|
||
DT_SCMI_PROTOCOL_DEFINE_NODEV(DT_INST(0, arm_scmi_power), NULL); | ||
|
||
struct scmi_power_state_get_reply { | ||
int32_t status; | ||
uint32_t power_state; | ||
}; | ||
|
||
int scmi_power_state_get(uint32_t domain_id, uint32_t *power_state) | ||
{ | ||
struct scmi_protocol *proto = &SCMI_PROTOCOL_NAME(SCMI_PROTOCOL_POWER_DOMAIN); | ||
struct scmi_power_state_get_reply reply_buffer; | ||
struct scmi_message msg, reply; | ||
int ret; | ||
|
||
/* sanity checks */ | ||
if (!proto || !power_state) { | ||
return -EINVAL; | ||
} | ||
|
||
if (proto->id != SCMI_PROTOCOL_POWER_DOMAIN) { | ||
return -EINVAL; | ||
} | ||
|
||
msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_POWER_DOMAIN_MSG_POWER_STATE_GET, SCMI_COMMAND, | ||
proto->id, 0x0); | ||
msg.len = sizeof(domain_id); | ||
msg.content = &domain_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); | ||
} | ||
|
||
*power_state = reply_buffer.power_state; | ||
|
||
return 0; | ||
} | ||
|
||
int scmi_power_state_set(struct scmi_power_state_config *cfg) | ||
{ | ||
struct scmi_protocol *proto = &SCMI_PROTOCOL_NAME(SCMI_PROTOCOL_POWER_DOMAIN); | ||
struct scmi_message msg, reply; | ||
int status, ret; | ||
|
||
/* sanity checks */ | ||
if (!proto || !cfg) { | ||
return -EINVAL; | ||
} | ||
|
||
if (proto->id != SCMI_PROTOCOL_POWER_DOMAIN) { | ||
return -EINVAL; | ||
} | ||
|
||
/* Currently ASYNC flag is not supported. */ | ||
if (cfg->flags & SCMI_POWER_STATE_SET_FLAGS_ASYNC) { | ||
return -ENOTSUP; | ||
} | ||
|
||
msg.hdr = SCMI_MESSAGE_HDR_MAKE(SCMI_POWER_DOMAIN_MSG_POWER_STATE_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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2024 NXP | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
description: System Control and Management Interface (SCMI) power domain protocol | ||
|
||
compatible: "arm,scmi-power" | ||
|
||
include: [base.yaml] | ||
|
||
properties: | ||
reg: | ||
required: true | ||
const: [0x11] | ||
|
||
"#power-domain-cells": | ||
type: int | ||
required: true | ||
const: 1 | ||
|
||
power-domain-cells: | ||
- name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2024 NXP | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
/** | ||
* @file | ||
* @brief SCMI power domain protocol helpers | ||
*/ | ||
|
||
#ifndef _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_POWER_H_ | ||
#define _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_POWER_H_ | ||
|
||
#include <zephyr/drivers/firmware/scmi/protocol.h> | ||
|
||
#define SCMI_POWER_STATE_SET_FLAGS_ASYNC BIT(0) | ||
|
||
/** | ||
* @struct scmi_power_state_config | ||
* | ||
* @brief Describes the parameters for the POWER_STATE_SET | ||
* command | ||
*/ | ||
struct scmi_power_state_config { | ||
uint32_t flags; | ||
uint32_t domain_id; | ||
uint32_t power_state; | ||
}; | ||
|
||
/** | ||
* @brief Power domain protocol command message IDs | ||
*/ | ||
enum scmi_power_domain_message { | ||
SCMI_POWER_DOMAIN_MSG_PROTOCOL_VERSION = 0x0, | ||
SCMI_POWER_DOMAIN_MSG_PROTOCOL_ATTRIBUTES = 0x1, | ||
SCMI_POWER_DOMAIN_MSG_PROTOCOL_MESSAGE_ATTRIBUTES = 0x2, | ||
SCMI_POWER_DOMAIN_MSG_POWER_DOMAIN_ATTRIBUTES = 0x3, | ||
SCMI_POWER_DOMAIN_MSG_POWER_STATE_SET = 0x4, | ||
SCMI_POWER_DOMAIN_MSG_POWER_STATE_GET = 0x5, | ||
SCMI_POWER_DOMAIN_MSG_POWER_STATE_NOTIFY = 0x6, | ||
SCMI_POWER_DOMAIN_MSG_POWER_STATE_CHANGE_REQEUSTED_NOTIFY = 0x7, | ||
SCMI_POWER_DOMAIN_MSG_POWER_DOMAIN_NAME_GET = 0x8, | ||
SCMI_POWER_DOMAIN_MSG_NEGOTIATE_PROTOCOL_VERSION = 0x10, | ||
}; | ||
|
||
/** | ||
* @brief Send the POWER_STATE_SET command and get its reply | ||
* | ||
* @param cfg pointer to structure containing configuration | ||
* to be set | ||
* | ||
* @retval 0 if successful | ||
* @retval negative errno if failure | ||
*/ | ||
int scmi_power_state_set(struct scmi_power_state_config *cfg); | ||
/** | ||
* @brief Query the power domain state | ||
* | ||
* @param domain_id ID of the power domain for which the query is done | ||
* @param power_state pointer to be set via this command | ||
* | ||
* @retval 0 if successful | ||
* @retval negative errno if failure | ||
*/ | ||
int scmi_power_state_get(uint32_t domain_id, uint32_t *power_state); | ||
|
||
#endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_POWER_H_ */ |