1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * SCMI Message Protocol driver header
5 * Copyright (C) 2018 ARM Ltd.
8 #ifndef _LINUX_SCMI_PROTOCOL_H
9 #define _LINUX_SCMI_PROTOCOL_H
11 #include <linux/device.h>
12 #include <linux/types.h>
14 #define SCMI_MAX_STR_SIZE 16
15 #define SCMI_MAX_NUM_RATES 16
18 * struct scmi_revision_info - version information structure
20 * @major_ver: Major ABI version. Change here implies risk of backward
21 * compatibility break.
22 * @minor_ver: Minor ABI version. Change here implies new feature addition,
23 * or compatible change in ABI.
24 * @num_protocols: Number of protocols that are implemented, excluding the
26 * @num_agents: Number of agents in the system.
27 * @impl_ver: A vendor-specific implementation version.
28 * @vendor_id: A vendor identifier(Null terminated ASCII string)
29 * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string)
31 struct scmi_revision_info {
37 char vendor_id[SCMI_MAX_STR_SIZE];
38 char sub_vendor_id[SCMI_MAX_STR_SIZE];
41 struct scmi_clock_info {
42 char name[SCMI_MAX_STR_SIZE];
47 u64 rates[SCMI_MAX_NUM_RATES];
60 * struct scmi_clk_ops - represents the various operations provided
61 * by SCMI Clock Protocol
63 * @count_get: get the count of clocks provided by SCMI
64 * @info_get: get the information of the specified clock
65 * @rate_get: request the current clock rate of a clock
66 * @rate_set: set the clock rate of a clock
67 * @enable: enables the specified clock
68 * @disable: disables the specified clock
71 int (*count_get)(const struct scmi_handle *handle);
73 const struct scmi_clock_info *(*info_get)
74 (const struct scmi_handle *handle, u32 clk_id);
75 int (*rate_get)(const struct scmi_handle *handle, u32 clk_id,
77 int (*rate_set)(const struct scmi_handle *handle, u32 clk_id,
79 int (*enable)(const struct scmi_handle *handle, u32 clk_id);
80 int (*disable)(const struct scmi_handle *handle, u32 clk_id);
84 * struct scmi_perf_ops - represents the various operations provided
85 * by SCMI Performance Protocol
87 * @limits_set: sets limits on the performance level of a domain
88 * @limits_get: gets limits on the performance level of a domain
89 * @level_set: sets the performance level of a domain
90 * @level_get: gets the performance level of a domain
91 * @device_domain_id: gets the scmi domain id for a given device
92 * @transition_latency_get: gets the DVFS transition latency for a given device
93 * @device_opps_add: adds all the OPPs for a given device
94 * @freq_set: sets the frequency for a given device using sustained frequency
95 * to sustained performance level mapping
96 * @freq_get: gets the frequency for a given device using sustained frequency
97 * to sustained performance level mapping
98 * @est_power_get: gets the estimated power cost for a given performance domain
99 * at a given frequency
101 struct scmi_perf_ops {
102 int (*limits_set)(const struct scmi_handle *handle, u32 domain,
103 u32 max_perf, u32 min_perf);
104 int (*limits_get)(const struct scmi_handle *handle, u32 domain,
105 u32 *max_perf, u32 *min_perf);
106 int (*level_set)(const struct scmi_handle *handle, u32 domain,
107 u32 level, bool poll);
108 int (*level_get)(const struct scmi_handle *handle, u32 domain,
109 u32 *level, bool poll);
110 int (*device_domain_id)(struct device *dev);
111 int (*transition_latency_get)(const struct scmi_handle *handle,
113 int (*device_opps_add)(const struct scmi_handle *handle,
115 int (*freq_set)(const struct scmi_handle *handle, u32 domain,
116 unsigned long rate, bool poll);
117 int (*freq_get)(const struct scmi_handle *handle, u32 domain,
118 unsigned long *rate, bool poll);
119 int (*est_power_get)(const struct scmi_handle *handle, u32 domain,
120 unsigned long *rate, unsigned long *power);
124 * struct scmi_power_ops - represents the various operations provided
125 * by SCMI Power Protocol
127 * @num_domains_get: get the count of power domains provided by SCMI
128 * @name_get: gets the name of a power domain
129 * @state_set: sets the power state of a power domain
130 * @state_get: gets the power state of a power domain
132 struct scmi_power_ops {
133 int (*num_domains_get)(const struct scmi_handle *handle);
134 char *(*name_get)(const struct scmi_handle *handle, u32 domain);
135 #define SCMI_POWER_STATE_TYPE_SHIFT 30
136 #define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1)
137 #define SCMI_POWER_STATE_PARAM(type, id) \
138 ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
139 ((id) & SCMI_POWER_STATE_ID_MASK))
140 #define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0)
141 #define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0)
142 int (*state_set)(const struct scmi_handle *handle, u32 domain,
144 int (*state_get)(const struct scmi_handle *handle, u32 domain,
148 struct scmi_sensor_info {
154 char name[SCMI_MAX_STR_SIZE];
158 * Partial list from Distributed Management Task Force (DMTF) specification:
159 * DSP0249 (Platform Level Data Model specification)
161 enum scmi_sensor_class {
171 * struct scmi_sensor_ops - represents the various operations provided
172 * by SCMI Sensor Protocol
174 * @count_get: get the count of sensors provided by SCMI
175 * @info_get: get the information of the specified sensor
176 * @trip_point_notify: control notifications on cross-over events for
178 * @trip_point_config: selects and configures a trip-point of interest
179 * @reading_get: gets the current value of the sensor
181 struct scmi_sensor_ops {
182 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_notify)(const struct scmi_handle *handle,
187 u32 sensor_id, bool enable);
188 int (*trip_point_config)(const struct scmi_handle *handle,
189 u32 sensor_id, u8 trip_id, u64 trip_value);
190 int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id,
195 * struct scmi_reset_ops - represents the various operations provided
196 * by SCMI Reset Protocol
198 * @num_domains_get: get the count of reset domains provided by SCMI
199 * @name_get: gets the name of a reset domain
200 * @latency_get: gets the reset latency for the specified reset domain
201 * @reset: resets the specified reset domain
202 * @assert: explicitly assert reset signal of the specified reset domain
203 * @deassert: explicitly deassert reset signal of the specified reset domain
205 struct scmi_reset_ops {
206 int (*num_domains_get)(const struct scmi_handle *handle);
207 char *(*name_get)(const struct scmi_handle *handle, u32 domain);
208 int (*latency_get)(const struct scmi_handle *handle, u32 domain);
209 int (*reset)(const struct scmi_handle *handle, u32 domain);
210 int (*assert)(const struct scmi_handle *handle, u32 domain);
211 int (*deassert)(const struct scmi_handle *handle, u32 domain);
215 * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
217 * @dev: pointer to the SCMI device
218 * @version: pointer to the structure containing SCMI version information
219 * @power_ops: pointer to set of power protocol operations
220 * @perf_ops: pointer to set of performance protocol operations
221 * @clk_ops: pointer to set of clock protocol operations
222 * @sensor_ops: pointer to set of sensor protocol operations
223 * @reset_ops: pointer to set of reset protocol operations
224 * @perf_priv: pointer to private data structure specific to performance
225 * protocol(for internal use only)
226 * @clk_priv: pointer to private data structure specific to clock
227 * protocol(for internal use only)
228 * @power_priv: pointer to private data structure specific to power
229 * protocol(for internal use only)
230 * @sensor_priv: pointer to private data structure specific to sensors
231 * protocol(for internal use only)
232 * @reset_priv: pointer to private data structure specific to reset
233 * protocol(for internal use only)
237 struct scmi_revision_info *version;
238 struct scmi_perf_ops *perf_ops;
239 struct scmi_clk_ops *clk_ops;
240 struct scmi_power_ops *power_ops;
241 struct scmi_sensor_ops *sensor_ops;
242 struct scmi_reset_ops *reset_ops;
243 /* for protocol internal use */
251 enum scmi_std_protocol {
252 SCMI_PROTOCOL_BASE = 0x10,
253 SCMI_PROTOCOL_POWER = 0x11,
254 SCMI_PROTOCOL_SYSTEM = 0x12,
255 SCMI_PROTOCOL_PERF = 0x13,
256 SCMI_PROTOCOL_CLOCK = 0x14,
257 SCMI_PROTOCOL_SENSOR = 0x15,
258 SCMI_PROTOCOL_RESET = 0x16,
266 struct scmi_handle *handle;
269 #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
272 scmi_device_create(struct device_node *np, struct device *parent, int protocol,
274 void scmi_device_destroy(struct scmi_device *scmi_dev);
276 struct scmi_device_id {
283 int (*probe)(struct scmi_device *sdev);
284 void (*remove)(struct scmi_device *sdev);
285 const struct scmi_device_id *id_table;
287 struct device_driver driver;
290 #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
292 #ifdef CONFIG_ARM_SCMI_PROTOCOL
293 int scmi_driver_register(struct scmi_driver *driver,
294 struct module *owner, const char *mod_name);
295 void scmi_driver_unregister(struct scmi_driver *driver);
298 scmi_driver_register(struct scmi_driver *driver, struct module *owner,
299 const char *mod_name)
304 static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
305 #endif /* CONFIG_ARM_SCMI_PROTOCOL */
307 #define scmi_register(driver) \
308 scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
309 #define scmi_unregister(driver) \
310 scmi_driver_unregister(driver)
313 * module_scmi_driver() - Helper macro for registering a scmi driver
314 * @__scmi_driver: scmi_driver structure
316 * Helper macro for scmi drivers to set up proper module init / exit
317 * functions. Replaces module_init() and module_exit() and keeps people from
318 * printing pointless things to the kernel log when their driver is loaded.
320 #define module_scmi_driver(__scmi_driver) \
321 module_driver(__scmi_driver, scmi_register, scmi_unregister)
323 typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *);
324 int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn);
325 void scmi_protocol_unregister(int protocol_id);
327 #endif /* _LINUX_SCMI_PROTOCOL_H */