1 /* 2 * Copyright 2024 NXP 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 /** 8 * @file 9 * @brief SCMI clock protocol helpers 10 */ 11 12 #ifndef _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_CLK_H_ 13 #define _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_CLK_H_ 14 15 #include <zephyr/drivers/firmware/scmi/protocol.h> 16 17 #define SCMI_CLK_CONFIG_DISABLE_ENABLE_MASK GENMASK(1, 0) 18 #define SCMI_CLK_CONFIG_ENABLE_DISABLE(x)\ 19 ((uint32_t)(x) & SCMI_CLK_CONFIG_DISABLE_ENABLE_MASK) 20 21 #define SCMI_CLK_ATTRIBUTES_CLK_NUM(x) ((x) & GENMASK(15, 0)) 22 23 /** 24 * @struct scmi_clock_config 25 * 26 * @brief Describes the parameters for the CLOCK_CONFIG_SET 27 * command 28 */ 29 struct scmi_clock_config { 30 uint32_t clk_id; 31 uint32_t attributes; 32 uint32_t extended_cfg_val; 33 }; 34 35 /** 36 * @brief Clock protocol command message IDs 37 */ 38 enum scmi_clock_message { 39 SCMI_CLK_MSG_PROTOCOL_VERSION = 0x0, 40 SCMI_CLK_MSG_PROTOCOL_ATTRIBUTES = 0x1, 41 SCMI_CLK_MSG_PROTOCOL_MESSAGE_ATTRIBUTES = 0x2, 42 SCMI_CLK_MSG_CLOCK_ATTRIBUTES = 0x3, 43 SCMI_CLK_MSG_CLOCK_DESCRIBE_RATES = 0x4, 44 SCMI_CLK_MSG_CLOCK_RATE_SET = 0x5, 45 SCMI_CLK_MSG_CLOCK_RATE_GET = 0x6, 46 SCMI_CLK_MSG_CLOCK_CONFIG_SET = 0x7, 47 SCMI_CLK_MSG_CLOCK_NAME_GET = 0x8, 48 SCMI_CLK_MSG_CLOCK_RATE_NOTIFY = 0x9, 49 SCMI_CLK_MSG_CLOCK_RATE_CHANGE_REQUESTED_NOTIFY = 0xa, 50 SCMI_CLK_MSG_CLOCK_CONFIG_GET = 0xb, 51 SCMI_CLK_MSG_CLOCK_POSSIBLE_PARENTS_GET = 0xc, 52 SCMI_CLK_MSG_CLOCK_PARENT_SET = 0xd, 53 SCMI_CLK_MSG_CLOCK_PARENT_GET = 0xe, 54 SCMI_CLK_MSG_CLOCK_GET_PERMISSIONS = 0xf, 55 SCMI_CLK_MSG_NEGOTIATE_PROTOCOL_VERSION = 0x10, 56 }; 57 58 /** 59 * @brief Send the PROTOCOL_ATTRIBUTES command and get its reply 60 * 61 * @param proto pointer to SCMI clock protocol data 62 * @param attributes pointer to attributes to be set via 63 * this command 64 * 65 * @retval 0 if successful 66 * @retval negative errno if failure 67 */ 68 int scmi_clock_protocol_attributes(struct scmi_protocol *proto, 69 uint32_t *attributes); 70 71 /** 72 * @brief Send the CLOCK_CONFIG_SET command and get its reply 73 * 74 * @param proto pointer to SCMI clock protocol data 75 * @param cfg pointer to structure containing configuration 76 * to be set 77 * 78 * @retval 0 if successful 79 * @retval negative errno if failure 80 */ 81 int scmi_clock_config_set(struct scmi_protocol *proto, 82 struct scmi_clock_config *cfg); 83 /** 84 * @brief Query the rate of a clock 85 * 86 * @param proto pointer to SCMI clock protocol data 87 * @param clk_id ID of the clock for which the query is done 88 * @param rate pointer to rate to be set via this command 89 * 90 * @retval 0 if successful 91 * @retval negative errno if failure 92 */ 93 int scmi_clock_rate_get(struct scmi_protocol *proto, 94 uint32_t clk_id, uint32_t *rate); 95 96 #endif /* _INCLUDE_ZEPHYR_DRIVERS_FIRMWARE_SCMI_CLK_H_ */ 97