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