1
2
3
4
5
6
7
8#ifndef _LINUX_SCMI_PROTOCOL_H
9#define _LINUX_SCMI_PROTOCOL_H
10
11#include <linux/device.h>
12#include <linux/notifier.h>
13#include <linux/types.h>
14
15#define SCMI_MAX_STR_SIZE 16
16#define SCMI_MAX_NUM_RATES 16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32struct scmi_revision_info {
33 u16 major_ver;
34 u16 minor_ver;
35 u8 num_protocols;
36 u8 num_agents;
37 u32 impl_ver;
38 char vendor_id[SCMI_MAX_STR_SIZE];
39 char sub_vendor_id[SCMI_MAX_STR_SIZE];
40};
41
42struct scmi_clock_info {
43 char name[SCMI_MAX_STR_SIZE];
44 bool rate_discrete;
45 union {
46 struct {
47 int num_rates;
48 u64 rates[SCMI_MAX_NUM_RATES];
49 } list;
50 struct {
51 u64 min_rate;
52 u64 max_rate;
53 u64 step_size;
54 } range;
55 };
56};
57
58struct scmi_handle;
59
60
61
62
63
64
65
66
67
68
69
70
71struct scmi_clk_ops {
72 int (*count_get)(const struct scmi_handle *handle);
73
74 const struct scmi_clock_info *(*info_get)
75 (const struct scmi_handle *handle, u32 clk_id);
76 int (*rate_get)(const struct scmi_handle *handle, u32 clk_id,
77 u64 *rate);
78 int (*rate_set)(const struct scmi_handle *handle, u32 clk_id,
79 u64 rate);
80 int (*enable)(const struct scmi_handle *handle, u32 clk_id);
81 int (*disable)(const struct scmi_handle *handle, u32 clk_id);
82};
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102struct scmi_perf_ops {
103 int (*limits_set)(const struct scmi_handle *handle, u32 domain,
104 u32 max_perf, u32 min_perf);
105 int (*limits_get)(const struct scmi_handle *handle, u32 domain,
106 u32 *max_perf, u32 *min_perf);
107 int (*level_set)(const struct scmi_handle *handle, u32 domain,
108 u32 level, bool poll);
109 int (*level_get)(const struct scmi_handle *handle, u32 domain,
110 u32 *level, bool poll);
111 int (*device_domain_id)(struct device *dev);
112 int (*transition_latency_get)(const struct scmi_handle *handle,
113 struct device *dev);
114 int (*device_opps_add)(const struct scmi_handle *handle,
115 struct device *dev);
116 int (*freq_set)(const struct scmi_handle *handle, u32 domain,
117 unsigned long rate, bool poll);
118 int (*freq_get)(const struct scmi_handle *handle, u32 domain,
119 unsigned long *rate, bool poll);
120 int (*est_power_get)(const struct scmi_handle *handle, u32 domain,
121 unsigned long *rate, unsigned long *power);
122 bool (*fast_switch_possible)(const struct scmi_handle *handle,
123 struct device *dev);
124};
125
126
127
128
129
130
131
132
133
134
135struct scmi_power_ops {
136 int (*num_domains_get)(const struct scmi_handle *handle);
137 char *(*name_get)(const struct scmi_handle *handle, u32 domain);
138#define SCMI_POWER_STATE_TYPE_SHIFT 30
139#define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1)
140#define SCMI_POWER_STATE_PARAM(type, id) \
141 ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
142 ((id) & SCMI_POWER_STATE_ID_MASK))
143#define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0)
144#define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0)
145 int (*state_set)(const struct scmi_handle *handle, u32 domain,
146 u32 state);
147 int (*state_get)(const struct scmi_handle *handle, u32 domain,
148 u32 *state);
149};
150
151struct scmi_sensor_info {
152 u32 id;
153 u8 type;
154 s8 scale;
155 u8 num_trip_points;
156 bool async;
157 char name[SCMI_MAX_STR_SIZE];
158};
159
160
161
162
163
164enum scmi_sensor_class {
165 NONE = 0x0,
166 TEMPERATURE_C = 0x2,
167 VOLTAGE = 0x5,
168 CURRENT = 0x6,
169 POWER = 0x7,
170 ENERGY = 0x8,
171};
172
173
174
175
176
177
178
179
180
181
182struct scmi_sensor_ops {
183 int (*count_get)(const struct scmi_handle *handle);
184 const struct scmi_sensor_info *(*info_get)
185 (const struct scmi_handle *handle, u32 sensor_id);
186 int (*trip_point_config)(const struct scmi_handle *handle,
187 u32 sensor_id, u8 trip_id, u64 trip_value);
188 int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id,
189 u64 *value);
190};
191
192
193
194
195
196
197
198
199
200
201
202
203struct scmi_reset_ops {
204 int (*num_domains_get)(const struct scmi_handle *handle);
205 char *(*name_get)(const struct scmi_handle *handle, u32 domain);
206 int (*latency_get)(const struct scmi_handle *handle, u32 domain);
207 int (*reset)(const struct scmi_handle *handle, u32 domain);
208 int (*assert)(const struct scmi_handle *handle, u32 domain);
209 int (*deassert)(const struct scmi_handle *handle, u32 domain);
210};
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246struct scmi_notify_ops {
247 int (*register_event_notifier)(const struct scmi_handle *handle,
248 u8 proto_id, u8 evt_id, u32 *src_id,
249 struct notifier_block *nb);
250 int (*unregister_event_notifier)(const struct scmi_handle *handle,
251 u8 proto_id, u8 evt_id, u32 *src_id,
252 struct notifier_block *nb);
253};
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279struct scmi_handle {
280 struct device *dev;
281 struct scmi_revision_info *version;
282 const struct scmi_perf_ops *perf_ops;
283 const struct scmi_clk_ops *clk_ops;
284 const struct scmi_power_ops *power_ops;
285 const struct scmi_sensor_ops *sensor_ops;
286 const struct scmi_reset_ops *reset_ops;
287 const struct scmi_notify_ops *notify_ops;
288
289 void *perf_priv;
290 void *clk_priv;
291 void *power_priv;
292 void *sensor_priv;
293 void *reset_priv;
294 void *notify_priv;
295 void *system_priv;
296};
297
298enum scmi_std_protocol {
299 SCMI_PROTOCOL_BASE = 0x10,
300 SCMI_PROTOCOL_POWER = 0x11,
301 SCMI_PROTOCOL_SYSTEM = 0x12,
302 SCMI_PROTOCOL_PERF = 0x13,
303 SCMI_PROTOCOL_CLOCK = 0x14,
304 SCMI_PROTOCOL_SENSOR = 0x15,
305 SCMI_PROTOCOL_RESET = 0x16,
306};
307
308enum scmi_system_events {
309 SCMI_SYSTEM_SHUTDOWN,
310 SCMI_SYSTEM_COLDRESET,
311 SCMI_SYSTEM_WARMRESET,
312 SCMI_SYSTEM_POWERUP,
313 SCMI_SYSTEM_SUSPEND,
314 SCMI_SYSTEM_MAX
315};
316
317struct scmi_device {
318 u32 id;
319 u8 protocol_id;
320 const char *name;
321 struct device dev;
322 struct scmi_handle *handle;
323};
324
325#define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
326
327struct scmi_device *
328scmi_device_create(struct device_node *np, struct device *parent, int protocol,
329 const char *name);
330void scmi_device_destroy(struct scmi_device *scmi_dev);
331
332struct scmi_device_id {
333 u8 protocol_id;
334 const char *name;
335};
336
337struct scmi_driver {
338 const char *name;
339 int (*probe)(struct scmi_device *sdev);
340 void (*remove)(struct scmi_device *sdev);
341 const struct scmi_device_id *id_table;
342
343 struct device_driver driver;
344};
345
346#define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
347
348#if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL)
349int scmi_driver_register(struct scmi_driver *driver,
350 struct module *owner, const char *mod_name);
351void scmi_driver_unregister(struct scmi_driver *driver);
352#else
353static inline int
354scmi_driver_register(struct scmi_driver *driver, struct module *owner,
355 const char *mod_name)
356{
357 return -EINVAL;
358}
359
360static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
361#endif
362
363#define scmi_register(driver) \
364 scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
365#define scmi_unregister(driver) \
366 scmi_driver_unregister(driver)
367
368
369
370
371
372
373
374
375
376#define module_scmi_driver(__scmi_driver) \
377 module_driver(__scmi_driver, scmi_register, scmi_unregister)
378
379typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *);
380int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn);
381void scmi_protocol_unregister(int protocol_id);
382
383
384enum scmi_notification_events {
385 SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
386 SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
387 SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
388 SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
389 SCMI_EVENT_RESET_ISSUED = 0x0,
390 SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
391 SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
392};
393
394struct scmi_power_state_changed_report {
395 ktime_t timestamp;
396 unsigned int agent_id;
397 unsigned int domain_id;
398 unsigned int power_state;
399};
400
401struct scmi_system_power_state_notifier_report {
402 ktime_t timestamp;
403 unsigned int agent_id;
404 unsigned int flags;
405 unsigned int system_state;
406};
407
408struct scmi_perf_limits_report {
409 ktime_t timestamp;
410 unsigned int agent_id;
411 unsigned int domain_id;
412 unsigned int range_max;
413 unsigned int range_min;
414};
415
416struct scmi_perf_level_report {
417 ktime_t timestamp;
418 unsigned int agent_id;
419 unsigned int domain_id;
420 unsigned int performance_level;
421};
422
423struct scmi_sensor_trip_point_report {
424 ktime_t timestamp;
425 unsigned int agent_id;
426 unsigned int sensor_id;
427 unsigned int trip_point_desc;
428};
429
430struct scmi_reset_issued_report {
431 ktime_t timestamp;
432 unsigned int agent_id;
433 unsigned int domain_id;
434 unsigned int reset_state;
435};
436
437struct scmi_base_error_report {
438 ktime_t timestamp;
439 unsigned int agent_id;
440 bool fatal;
441 unsigned int cmd_count;
442 unsigned long long reports[];
443};
444
445#endif
446