1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /*
3  * Copyright (c) 2015-2019, Arm Limited and Contributors. All rights reserved.
4  * Copyright (c) 2019, Linaro Limited
5  */
6 
7 #ifndef SCMI_MSG_CLOCK_H
8 #define SCMI_MSG_CLOCK_H
9 
10 #include <stdint.h>
11 #include <util.h>
12 
13 #include "common.h"
14 
15 #define SCMI_PROTOCOL_VERSION_CLOCK	0x20000
16 
17 /*
18  * Identifiers of the SCMI Clock Management Protocol commands
19  */
20 enum scmi_clock_command_id {
21 	SCMI_CLOCK_ATTRIBUTES = 0x003,
22 	SCMI_CLOCK_DESCRIBE_RATES = 0x004,
23 	SCMI_CLOCK_RATE_SET = 0x005,
24 	SCMI_CLOCK_RATE_GET = 0x006,
25 	SCMI_CLOCK_CONFIG_SET = 0x007,
26 };
27 
28 /* Protocol attributes */
29 #define SCMI_CLOCK_CLOCK_COUNT_MASK			GENMASK_32(15, 0)
30 #define SCMI_CLOCK_MAX_PENDING_TRANSITIONS_MASK		GENMASK_32(23, 16)
31 
32 #define SCMI_CLOCK_PROTOCOL_ATTRIBUTES(_max_pending, _clk_count) \
33 	((((_max_pending) << 16) & SCMI_CLOCK_MAX_PENDING_TRANSITIONS_MASK) | \
34 	 (((_clk_count) & SCMI_CLOCK_CLOCK_COUNT_MASK)))
35 
36 struct scmi_clock_attributes_a2p {
37 	uint32_t clock_id;
38 };
39 
40 #define SCMI_CLOCK_NAME_LENGTH_MAX	16
41 
42 struct scmi_clock_attributes_p2a {
43 	int32_t status;
44 	uint32_t attributes;
45 	char clock_name[SCMI_CLOCK_NAME_LENGTH_MAX];
46 };
47 
48 /*
49  * Clock Rate Get
50  */
51 
52 struct scmi_clock_rate_get_a2p {
53 	uint32_t clock_id;
54 };
55 
56 struct scmi_clock_rate_get_p2a {
57 	int32_t status;
58 	uint32_t rate[2];
59 };
60 
61 /*
62  * Clock Rate Set
63  */
64 
65 /* If set, set the new clock rate asynchronously */
66 #define SCMI_CLOCK_RATE_SET_ASYNC_POS			0
67 /* If set, do not send a delayed asynchronous response */
68 #define SCMI_CLOCK_RATE_SET_NO_DELAYED_RESPONSE_POS	1
69 /* Round up, if set, otherwise round down */
70 #define SCMI_CLOCK_RATE_SET_ROUND_UP_POS		2
71 /* If set, the platform chooses the appropriate rounding mode */
72 #define SCMI_CLOCK_RATE_SET_ROUND_AUTO_POS		3
73 
74 #define SCMI_CLOCK_RATE_SET_ASYNC_MASK \
75 		BIT(SCMI_CLOCK_RATE_SET_ASYNC_POS)
76 #define SCMI_CLOCK_RATE_SET_NO_DELAYED_RESPONSE_MASK \
77 		BIT(SCMI_CLOCK_RATE_SET_NO_DELAYED_RESPONSE_POS)
78 #define SCMI_CLOCK_RATE_SET_ROUND_UP_MASK \
79 		BIT(SCMI_CLOCK_RATE_SET_ROUND_UP_POS)
80 #define SCMI_CLOCK_RATE_SET_ROUND_AUTO_MASK \
81 		BIT(SCMI_CLOCK_RATE_SET_ROUND_AUTO_POS)
82 
83 struct scmi_clock_rate_set_a2p {
84 	uint32_t flags;
85 	uint32_t clock_id;
86 	uint32_t rate[2];
87 };
88 
89 struct scmi_clock_rate_set_p2a {
90 	int32_t status;
91 };
92 
93 /*
94  * Clock Config Set
95  */
96 
97 #define SCMI_CLOCK_CONFIG_SET_ENABLE_POS	0
98 
99 #define SCMI_CLOCK_CONFIG_SET_ENABLE_MASK \
100 	BIT(SCMI_CLOCK_CONFIG_SET_ENABLE_POS)
101 
102 struct scmi_clock_config_set_a2p {
103 	uint32_t clock_id;
104 	uint32_t attributes;
105 };
106 
107 struct scmi_clock_config_set_p2a {
108 	int32_t status;
109 };
110 
111 /*
112  * Clock Describe Rates
113  */
114 
115 #define SCMI_CLOCK_RATE_FORMAT_RANGE 1
116 #define SCMI_CLOCK_RATE_FORMAT_LIST  0
117 
118 #define SCMI_CLOCK_DESCRIBE_RATES_REMAINING_MASK	GENMASK_32(31, 16)
119 #define SCMI_CLOCK_DESCRIBE_RATES_REMAINING_POS		16
120 
121 #define SCMI_CLOCK_DESCRIBE_RATES_FORMAT_MASK		BIT(12)
122 #define SCMI_CLOCK_DESCRIBE_RATES_FORMAT_POS		12
123 
124 #define SCMI_CLOCK_DESCRIBE_RATES_COUNT_MASK		GENMASK_32(11, 0)
125 
126 #define SCMI_CLOCK_DESCRIBE_RATES_NUM_RATES_FLAGS(_count, _fmt, _rem_rates) \
127 	( \
128 		((_count) & SCMI_CLOCK_DESCRIBE_RATES_COUNT_MASK) | \
129 		(((_rem_rates) << SCMI_CLOCK_DESCRIBE_RATES_REMAINING_POS) & \
130 		 SCMI_CLOCK_DESCRIBE_RATES_REMAINING_MASK) | \
131 		(((_fmt) << SCMI_CLOCK_DESCRIBE_RATES_FORMAT_POS) & \
132 		 SCMI_CLOCK_DESCRIBE_RATES_FORMAT_MASK) \
133 	)
134 
135 struct scmi_clock_rate {
136 	uint32_t low;
137 	uint32_t high;
138 };
139 
140 struct scmi_clock_describe_rates_a2p {
141 	uint32_t clock_id;
142 	uint32_t rate_index;
143 };
144 
145 struct scmi_clock_describe_rates_p2a {
146 	int32_t status;
147 	uint32_t num_rates_flags;
148 	struct scmi_clock_rate rates[];
149 };
150 
151 #ifdef CFG_SCMI_MSG_CLOCK
152 /*
153  * scmi_msg_get_clock_handler - Return a handler for a clock message
154  * @msg - message to process
155  * Return a function handler for the message or NULL
156  */
157 scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg);
158 #else
159 static inline
scmi_msg_get_clock_handler(struct scmi_msg * msg __unused)160 scmi_msg_handler_t scmi_msg_get_clock_handler(struct scmi_msg *msg __unused)
161 {
162 	return NULL;
163 }
164 #endif
165 #endif /* SCMI_MSG_CLOCK_H */
166