]>
Commit | Line | Data |
---|---|---|
4752544a | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
aa4f886f SH |
2 | /* |
3 | * SCMI Message Protocol driver header | |
4 | * | |
5 | * Copyright (C) 2018 ARM Ltd. | |
6 | */ | |
933c5044 | 7 | #include <linux/device.h> |
aa4f886f SH |
8 | #include <linux/types.h> |
9 | ||
b6f20ff8 | 10 | #define SCMI_MAX_STR_SIZE 16 |
5f6c6430 | 11 | #define SCMI_MAX_NUM_RATES 16 |
b6f20ff8 SH |
12 | |
13 | /** | |
14 | * struct scmi_revision_info - version information structure | |
15 | * | |
16 | * @major_ver: Major ABI version. Change here implies risk of backward | |
17 | * compatibility break. | |
18 | * @minor_ver: Minor ABI version. Change here implies new feature addition, | |
19 | * or compatible change in ABI. | |
20 | * @num_protocols: Number of protocols that are implemented, excluding the | |
21 | * base protocol. | |
22 | * @num_agents: Number of agents in the system. | |
23 | * @impl_ver: A vendor-specific implementation version. | |
24 | * @vendor_id: A vendor identifier(Null terminated ASCII string) | |
25 | * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string) | |
26 | */ | |
27 | struct scmi_revision_info { | |
28 | u16 major_ver; | |
29 | u16 minor_ver; | |
30 | u8 num_protocols; | |
31 | u8 num_agents; | |
32 | u32 impl_ver; | |
33 | char vendor_id[SCMI_MAX_STR_SIZE]; | |
34 | char sub_vendor_id[SCMI_MAX_STR_SIZE]; | |
35 | }; | |
36 | ||
5f6c6430 SH |
37 | struct scmi_clock_info { |
38 | char name[SCMI_MAX_STR_SIZE]; | |
39 | bool rate_discrete; | |
40 | union { | |
41 | struct { | |
42 | int num_rates; | |
43 | u64 rates[SCMI_MAX_NUM_RATES]; | |
44 | } list; | |
45 | struct { | |
46 | u64 min_rate; | |
47 | u64 max_rate; | |
48 | u64 step_size; | |
49 | } range; | |
50 | }; | |
51 | }; | |
52 | ||
a9e3fbfa SH |
53 | struct scmi_handle; |
54 | ||
5f6c6430 SH |
55 | /** |
56 | * struct scmi_clk_ops - represents the various operations provided | |
57 | * by SCMI Clock Protocol | |
58 | * | |
59 | * @count_get: get the count of clocks provided by SCMI | |
60 | * @info_get: get the information of the specified clock | |
61 | * @rate_get: request the current clock rate of a clock | |
62 | * @rate_set: set the clock rate of a clock | |
63 | * @enable: enables the specified clock | |
64 | * @disable: disables the specified clock | |
65 | */ | |
66 | struct scmi_clk_ops { | |
67 | int (*count_get)(const struct scmi_handle *handle); | |
68 | ||
69 | const struct scmi_clock_info *(*info_get) | |
70 | (const struct scmi_handle *handle, u32 clk_id); | |
71 | int (*rate_get)(const struct scmi_handle *handle, u32 clk_id, | |
72 | u64 *rate); | |
73 | int (*rate_set)(const struct scmi_handle *handle, u32 clk_id, | |
d0aba116 | 74 | u64 rate); |
5f6c6430 SH |
75 | int (*enable)(const struct scmi_handle *handle, u32 clk_id); |
76 | int (*disable)(const struct scmi_handle *handle, u32 clk_id); | |
77 | }; | |
78 | ||
a9e3fbfa SH |
79 | /** |
80 | * struct scmi_perf_ops - represents the various operations provided | |
81 | * by SCMI Performance Protocol | |
82 | * | |
83 | * @limits_set: sets limits on the performance level of a domain | |
84 | * @limits_get: gets limits on the performance level of a domain | |
85 | * @level_set: sets the performance level of a domain | |
86 | * @level_get: gets the performance level of a domain | |
87 | * @device_domain_id: gets the scmi domain id for a given device | |
7859e08c SH |
88 | * @transition_latency_get: gets the DVFS transition latency for a given device |
89 | * @device_opps_add: adds all the OPPs for a given device | |
a9e3fbfa SH |
90 | * @freq_set: sets the frequency for a given device using sustained frequency |
91 | * to sustained performance level mapping | |
92 | * @freq_get: gets the frequency for a given device using sustained frequency | |
93 | * to sustained performance level mapping | |
1a63fe9a QP |
94 | * @est_power_get: gets the estimated power cost for a given performance domain |
95 | * at a given frequency | |
a9e3fbfa SH |
96 | */ |
97 | struct scmi_perf_ops { | |
98 | int (*limits_set)(const struct scmi_handle *handle, u32 domain, | |
99 | u32 max_perf, u32 min_perf); | |
100 | int (*limits_get)(const struct scmi_handle *handle, u32 domain, | |
101 | u32 *max_perf, u32 *min_perf); | |
102 | int (*level_set)(const struct scmi_handle *handle, u32 domain, | |
5c4ba3cc | 103 | u32 level, bool poll); |
a9e3fbfa | 104 | int (*level_get)(const struct scmi_handle *handle, u32 domain, |
5c4ba3cc | 105 | u32 *level, bool poll); |
a9e3fbfa | 106 | int (*device_domain_id)(struct device *dev); |
7859e08c | 107 | int (*transition_latency_get)(const struct scmi_handle *handle, |
a9e3fbfa | 108 | struct device *dev); |
7859e08c SH |
109 | int (*device_opps_add)(const struct scmi_handle *handle, |
110 | struct device *dev); | |
a9e3fbfa | 111 | int (*freq_set)(const struct scmi_handle *handle, u32 domain, |
5c4ba3cc | 112 | unsigned long rate, bool poll); |
a9e3fbfa | 113 | int (*freq_get)(const struct scmi_handle *handle, u32 domain, |
5c4ba3cc | 114 | unsigned long *rate, bool poll); |
1a63fe9a QP |
115 | int (*est_power_get)(const struct scmi_handle *handle, u32 domain, |
116 | unsigned long *rate, unsigned long *power); | |
a9e3fbfa SH |
117 | }; |
118 | ||
76a65509 SH |
119 | /** |
120 | * struct scmi_power_ops - represents the various operations provided | |
121 | * by SCMI Power Protocol | |
122 | * | |
123 | * @num_domains_get: get the count of power domains provided by SCMI | |
124 | * @name_get: gets the name of a power domain | |
125 | * @state_set: sets the power state of a power domain | |
126 | * @state_get: gets the power state of a power domain | |
127 | */ | |
128 | struct scmi_power_ops { | |
129 | int (*num_domains_get)(const struct scmi_handle *handle); | |
130 | char *(*name_get)(const struct scmi_handle *handle, u32 domain); | |
131 | #define SCMI_POWER_STATE_TYPE_SHIFT 30 | |
132 | #define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1) | |
133 | #define SCMI_POWER_STATE_PARAM(type, id) \ | |
134 | ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \ | |
135 | ((id) & SCMI_POWER_STATE_ID_MASK)) | |
136 | #define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0) | |
137 | #define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0) | |
138 | int (*state_set)(const struct scmi_handle *handle, u32 domain, | |
139 | u32 state); | |
140 | int (*state_get)(const struct scmi_handle *handle, u32 domain, | |
141 | u32 *state); | |
142 | }; | |
143 | ||
5179c523 SH |
144 | struct scmi_sensor_info { |
145 | u32 id; | |
146 | u8 type; | |
0b673b64 | 147 | s8 scale; |
d09aac0e SH |
148 | u8 num_trip_points; |
149 | bool async; | |
5179c523 SH |
150 | char name[SCMI_MAX_STR_SIZE]; |
151 | }; | |
152 | ||
153 | /* | |
154 | * Partial list from Distributed Management Task Force (DMTF) specification: | |
155 | * DSP0249 (Platform Level Data Model specification) | |
156 | */ | |
157 | enum scmi_sensor_class { | |
158 | NONE = 0x0, | |
159 | TEMPERATURE_C = 0x2, | |
160 | VOLTAGE = 0x5, | |
161 | CURRENT = 0x6, | |
162 | POWER = 0x7, | |
163 | ENERGY = 0x8, | |
164 | }; | |
165 | ||
166 | /** | |
167 | * struct scmi_sensor_ops - represents the various operations provided | |
168 | * by SCMI Sensor Protocol | |
169 | * | |
170 | * @count_get: get the count of sensors provided by SCMI | |
171 | * @info_get: get the information of the specified sensor | |
9eefa43a | 172 | * @trip_point_notify: control notifications on cross-over events for |
5179c523 | 173 | * the trip-points |
9eefa43a | 174 | * @trip_point_config: selects and configures a trip-point of interest |
5179c523 SH |
175 | * @reading_get: gets the current value of the sensor |
176 | */ | |
177 | struct scmi_sensor_ops { | |
178 | int (*count_get)(const struct scmi_handle *handle); | |
179 | ||
180 | const struct scmi_sensor_info *(*info_get) | |
181 | (const struct scmi_handle *handle, u32 sensor_id); | |
9eefa43a SH |
182 | int (*trip_point_notify)(const struct scmi_handle *handle, |
183 | u32 sensor_id, bool enable); | |
184 | int (*trip_point_config)(const struct scmi_handle *handle, | |
185 | u32 sensor_id, u8 trip_id, u64 trip_value); | |
5179c523 | 186 | int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id, |
6a55331c | 187 | u64 *value); |
5179c523 SH |
188 | }; |
189 | ||
aa4f886f SH |
190 | /** |
191 | * struct scmi_handle - Handle returned to ARM SCMI clients for usage. | |
192 | * | |
193 | * @dev: pointer to the SCMI device | |
b6f20ff8 | 194 | * @version: pointer to the structure containing SCMI version information |
76a65509 | 195 | * @power_ops: pointer to set of power protocol operations |
a9e3fbfa | 196 | * @perf_ops: pointer to set of performance protocol operations |
5f6c6430 | 197 | * @clk_ops: pointer to set of clock protocol operations |
5179c523 | 198 | * @sensor_ops: pointer to set of sensor protocol operations |
1baf47c2 SH |
199 | * @perf_priv: pointer to private data structure specific to performance |
200 | * protocol(for internal use only) | |
201 | * @clk_priv: pointer to private data structure specific to clock | |
202 | * protocol(for internal use only) | |
203 | * @power_priv: pointer to private data structure specific to power | |
204 | * protocol(for internal use only) | |
205 | * @sensor_priv: pointer to private data structure specific to sensors | |
206 | * protocol(for internal use only) | |
aa4f886f SH |
207 | */ |
208 | struct scmi_handle { | |
209 | struct device *dev; | |
b6f20ff8 | 210 | struct scmi_revision_info *version; |
a9e3fbfa | 211 | struct scmi_perf_ops *perf_ops; |
5f6c6430 | 212 | struct scmi_clk_ops *clk_ops; |
76a65509 | 213 | struct scmi_power_ops *power_ops; |
5179c523 | 214 | struct scmi_sensor_ops *sensor_ops; |
a9e3fbfa SH |
215 | /* for protocol internal use */ |
216 | void *perf_priv; | |
5f6c6430 | 217 | void *clk_priv; |
76a65509 | 218 | void *power_priv; |
5179c523 | 219 | void *sensor_priv; |
b6f20ff8 SH |
220 | }; |
221 | ||
222 | enum scmi_std_protocol { | |
223 | SCMI_PROTOCOL_BASE = 0x10, | |
224 | SCMI_PROTOCOL_POWER = 0x11, | |
225 | SCMI_PROTOCOL_SYSTEM = 0x12, | |
226 | SCMI_PROTOCOL_PERF = 0x13, | |
227 | SCMI_PROTOCOL_CLOCK = 0x14, | |
228 | SCMI_PROTOCOL_SENSOR = 0x15, | |
aa4f886f | 229 | }; |
933c5044 SH |
230 | |
231 | struct scmi_device { | |
232 | u32 id; | |
233 | u8 protocol_id; | |
234 | struct device dev; | |
235 | struct scmi_handle *handle; | |
236 | }; | |
237 | ||
238 | #define to_scmi_dev(d) container_of(d, struct scmi_device, dev) | |
239 | ||
240 | struct scmi_device * | |
241 | scmi_device_create(struct device_node *np, struct device *parent, int protocol); | |
242 | void scmi_device_destroy(struct scmi_device *scmi_dev); | |
243 | ||
244 | struct scmi_device_id { | |
245 | u8 protocol_id; | |
246 | }; | |
247 | ||
248 | struct scmi_driver { | |
249 | const char *name; | |
250 | int (*probe)(struct scmi_device *sdev); | |
251 | void (*remove)(struct scmi_device *sdev); | |
252 | const struct scmi_device_id *id_table; | |
253 | ||
254 | struct device_driver driver; | |
255 | }; | |
256 | ||
257 | #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver) | |
258 | ||
259 | #ifdef CONFIG_ARM_SCMI_PROTOCOL | |
260 | int scmi_driver_register(struct scmi_driver *driver, | |
261 | struct module *owner, const char *mod_name); | |
262 | void scmi_driver_unregister(struct scmi_driver *driver); | |
263 | #else | |
264 | static inline int | |
265 | scmi_driver_register(struct scmi_driver *driver, struct module *owner, | |
266 | const char *mod_name) | |
267 | { | |
268 | return -EINVAL; | |
269 | } | |
270 | ||
271 | static inline void scmi_driver_unregister(struct scmi_driver *driver) {} | |
272 | #endif /* CONFIG_ARM_SCMI_PROTOCOL */ | |
273 | ||
274 | #define scmi_register(driver) \ | |
275 | scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) | |
276 | #define scmi_unregister(driver) \ | |
277 | scmi_driver_unregister(driver) | |
278 | ||
279 | /** | |
280 | * module_scmi_driver() - Helper macro for registering a scmi driver | |
281 | * @__scmi_driver: scmi_driver structure | |
282 | * | |
283 | * Helper macro for scmi drivers to set up proper module init / exit | |
284 | * functions. Replaces module_init() and module_exit() and keeps people from | |
285 | * printing pointless things to the kernel log when their driver is loaded. | |
286 | */ | |
287 | #define module_scmi_driver(__scmi_driver) \ | |
288 | module_driver(__scmi_driver, scmi_register, scmi_unregister) | |
289 | ||
290 | typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *); | |
291 | int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn); | |
292 | void scmi_protocol_unregister(int protocol_id); |