xref: /openbmc/linux/include/linux/scmi_protocol.h (revision e27077bc)
14752544aSSudeep Holla /* SPDX-License-Identifier: GPL-2.0-only */
2aa4f886fSSudeep Holla /*
3aa4f886fSSudeep Holla  * SCMI Message Protocol driver header
4aa4f886fSSudeep Holla  *
5aa4f886fSSudeep Holla  * Copyright (C) 2018 ARM Ltd.
6aa4f886fSSudeep Holla  */
770771c69SSudeep Holla 
870771c69SSudeep Holla #ifndef _LINUX_SCMI_PROTOCOL_H
970771c69SSudeep Holla #define _LINUX_SCMI_PROTOCOL_H
1070771c69SSudeep Holla 
11933c5044SSudeep Holla #include <linux/device.h>
12e7c215f3SCristian Marussi #include <linux/notifier.h>
13aa4f886fSSudeep Holla #include <linux/types.h>
14aa4f886fSSudeep Holla 
15b6f20ff8SSudeep Holla #define SCMI_MAX_STR_SIZE	16
165f6c6430SSudeep Holla #define SCMI_MAX_NUM_RATES	16
17b6f20ff8SSudeep Holla 
18b6f20ff8SSudeep Holla /**
19b6f20ff8SSudeep Holla  * struct scmi_revision_info - version information structure
20b6f20ff8SSudeep Holla  *
21b6f20ff8SSudeep Holla  * @major_ver: Major ABI version. Change here implies risk of backward
22b6f20ff8SSudeep Holla  *	compatibility break.
23b6f20ff8SSudeep Holla  * @minor_ver: Minor ABI version. Change here implies new feature addition,
24b6f20ff8SSudeep Holla  *	or compatible change in ABI.
25b6f20ff8SSudeep Holla  * @num_protocols: Number of protocols that are implemented, excluding the
26b6f20ff8SSudeep Holla  *	base protocol.
27b6f20ff8SSudeep Holla  * @num_agents: Number of agents in the system.
28b6f20ff8SSudeep Holla  * @impl_ver: A vendor-specific implementation version.
29b6f20ff8SSudeep Holla  * @vendor_id: A vendor identifier(Null terminated ASCII string)
30b6f20ff8SSudeep Holla  * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string)
31b6f20ff8SSudeep Holla  */
32b6f20ff8SSudeep Holla struct scmi_revision_info {
33b6f20ff8SSudeep Holla 	u16 major_ver;
34b6f20ff8SSudeep Holla 	u16 minor_ver;
35b6f20ff8SSudeep Holla 	u8 num_protocols;
36b6f20ff8SSudeep Holla 	u8 num_agents;
37b6f20ff8SSudeep Holla 	u32 impl_ver;
38b6f20ff8SSudeep Holla 	char vendor_id[SCMI_MAX_STR_SIZE];
39b6f20ff8SSudeep Holla 	char sub_vendor_id[SCMI_MAX_STR_SIZE];
40b6f20ff8SSudeep Holla };
41b6f20ff8SSudeep Holla 
425f6c6430SSudeep Holla struct scmi_clock_info {
435f6c6430SSudeep Holla 	char name[SCMI_MAX_STR_SIZE];
445f6c6430SSudeep Holla 	bool rate_discrete;
455f6c6430SSudeep Holla 	union {
465f6c6430SSudeep Holla 		struct {
475f6c6430SSudeep Holla 			int num_rates;
485f6c6430SSudeep Holla 			u64 rates[SCMI_MAX_NUM_RATES];
495f6c6430SSudeep Holla 		} list;
505f6c6430SSudeep Holla 		struct {
515f6c6430SSudeep Holla 			u64 min_rate;
525f6c6430SSudeep Holla 			u64 max_rate;
535f6c6430SSudeep Holla 			u64 step_size;
545f6c6430SSudeep Holla 		} range;
555f6c6430SSudeep Holla 	};
565f6c6430SSudeep Holla };
575f6c6430SSudeep Holla 
58a9e3fbfaSSudeep Holla struct scmi_handle;
59a9e3fbfaSSudeep Holla 
60a9e3fbfaSSudeep Holla /**
615f6c6430SSudeep Holla  * struct scmi_clk_ops - represents the various operations provided
625f6c6430SSudeep Holla  *	by SCMI Clock Protocol
635f6c6430SSudeep Holla  *
645f6c6430SSudeep Holla  * @count_get: get the count of clocks provided by SCMI
655f6c6430SSudeep Holla  * @info_get: get the information of the specified clock
665f6c6430SSudeep Holla  * @rate_get: request the current clock rate of a clock
675f6c6430SSudeep Holla  * @rate_set: set the clock rate of a clock
685f6c6430SSudeep Holla  * @enable: enables the specified clock
695f6c6430SSudeep Holla  * @disable: disables the specified clock
705f6c6430SSudeep Holla  */
715f6c6430SSudeep Holla struct scmi_clk_ops {
725f6c6430SSudeep Holla 	int (*count_get)(const struct scmi_handle *handle);
735f6c6430SSudeep Holla 
745f6c6430SSudeep Holla 	const struct scmi_clock_info *(*info_get)
755f6c6430SSudeep Holla 		(const struct scmi_handle *handle, u32 clk_id);
765f6c6430SSudeep Holla 	int (*rate_get)(const struct scmi_handle *handle, u32 clk_id,
775f6c6430SSudeep Holla 			u64 *rate);
785f6c6430SSudeep Holla 	int (*rate_set)(const struct scmi_handle *handle, u32 clk_id,
79d0aba116SSudeep Holla 			u64 rate);
805f6c6430SSudeep Holla 	int (*enable)(const struct scmi_handle *handle, u32 clk_id);
815f6c6430SSudeep Holla 	int (*disable)(const struct scmi_handle *handle, u32 clk_id);
825f6c6430SSudeep Holla };
835f6c6430SSudeep Holla 
845f6c6430SSudeep Holla /**
85a9e3fbfaSSudeep Holla  * struct scmi_perf_ops - represents the various operations provided
86a9e3fbfaSSudeep Holla  *	by SCMI Performance Protocol
87a9e3fbfaSSudeep Holla  *
88a9e3fbfaSSudeep Holla  * @limits_set: sets limits on the performance level of a domain
89a9e3fbfaSSudeep Holla  * @limits_get: gets limits on the performance level of a domain
90a9e3fbfaSSudeep Holla  * @level_set: sets the performance level of a domain
91a9e3fbfaSSudeep Holla  * @level_get: gets the performance level of a domain
92a9e3fbfaSSudeep Holla  * @device_domain_id: gets the scmi domain id for a given device
937859e08cSSudeep Holla  * @transition_latency_get: gets the DVFS transition latency for a given device
947859e08cSSudeep Holla  * @device_opps_add: adds all the OPPs for a given device
95a9e3fbfaSSudeep Holla  * @freq_set: sets the frequency for a given device using sustained frequency
96a9e3fbfaSSudeep Holla  *	to sustained performance level mapping
97a9e3fbfaSSudeep Holla  * @freq_get: gets the frequency for a given device using sustained frequency
98a9e3fbfaSSudeep Holla  *	to sustained performance level mapping
991a63fe9aSQuentin Perret  * @est_power_get: gets the estimated power cost for a given performance domain
1001a63fe9aSQuentin Perret  *	at a given frequency
101a9e3fbfaSSudeep Holla  */
102a9e3fbfaSSudeep Holla struct scmi_perf_ops {
103a9e3fbfaSSudeep Holla 	int (*limits_set)(const struct scmi_handle *handle, u32 domain,
104a9e3fbfaSSudeep Holla 			  u32 max_perf, u32 min_perf);
105a9e3fbfaSSudeep Holla 	int (*limits_get)(const struct scmi_handle *handle, u32 domain,
106a9e3fbfaSSudeep Holla 			  u32 *max_perf, u32 *min_perf);
107a9e3fbfaSSudeep Holla 	int (*level_set)(const struct scmi_handle *handle, u32 domain,
1085c4ba3ccSSudeep Holla 			 u32 level, bool poll);
109a9e3fbfaSSudeep Holla 	int (*level_get)(const struct scmi_handle *handle, u32 domain,
1105c4ba3ccSSudeep Holla 			 u32 *level, bool poll);
111a9e3fbfaSSudeep Holla 	int (*device_domain_id)(struct device *dev);
1127859e08cSSudeep Holla 	int (*transition_latency_get)(const struct scmi_handle *handle,
113a9e3fbfaSSudeep Holla 				      struct device *dev);
1147859e08cSSudeep Holla 	int (*device_opps_add)(const struct scmi_handle *handle,
115a9e3fbfaSSudeep Holla 			       struct device *dev);
116a9e3fbfaSSudeep Holla 	int (*freq_set)(const struct scmi_handle *handle, u32 domain,
1175c4ba3ccSSudeep Holla 			unsigned long rate, bool poll);
118a9e3fbfaSSudeep Holla 	int (*freq_get)(const struct scmi_handle *handle, u32 domain,
1195c4ba3ccSSudeep Holla 			unsigned long *rate, bool poll);
1201a63fe9aSQuentin Perret 	int (*est_power_get)(const struct scmi_handle *handle, u32 domain,
1211a63fe9aSQuentin Perret 			     unsigned long *rate, unsigned long *power);
1221909872fSNicola Mazzucato 	bool (*fast_switch_possible)(const struct scmi_handle *handle,
1231909872fSNicola Mazzucato 				     struct device *dev);
124a9e3fbfaSSudeep Holla };
125a9e3fbfaSSudeep Holla 
126aa4f886fSSudeep Holla /**
12776a65509SSudeep Holla  * struct scmi_power_ops - represents the various operations provided
12876a65509SSudeep Holla  *	by SCMI Power Protocol
12976a65509SSudeep Holla  *
13076a65509SSudeep Holla  * @num_domains_get: get the count of power domains provided by SCMI
13176a65509SSudeep Holla  * @name_get: gets the name of a power domain
13276a65509SSudeep Holla  * @state_set: sets the power state of a power domain
13376a65509SSudeep Holla  * @state_get: gets the power state of a power domain
13476a65509SSudeep Holla  */
13576a65509SSudeep Holla struct scmi_power_ops {
13676a65509SSudeep Holla 	int (*num_domains_get)(const struct scmi_handle *handle);
13776a65509SSudeep Holla 	char *(*name_get)(const struct scmi_handle *handle, u32 domain);
13876a65509SSudeep Holla #define SCMI_POWER_STATE_TYPE_SHIFT	30
13976a65509SSudeep Holla #define SCMI_POWER_STATE_ID_MASK	(BIT(28) - 1)
14076a65509SSudeep Holla #define SCMI_POWER_STATE_PARAM(type, id) \
14176a65509SSudeep Holla 	((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
14276a65509SSudeep Holla 		((id) & SCMI_POWER_STATE_ID_MASK))
14376a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_ON	SCMI_POWER_STATE_PARAM(0, 0)
14476a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_OFF	SCMI_POWER_STATE_PARAM(1, 0)
14576a65509SSudeep Holla 	int (*state_set)(const struct scmi_handle *handle, u32 domain,
14676a65509SSudeep Holla 			 u32 state);
14776a65509SSudeep Holla 	int (*state_get)(const struct scmi_handle *handle, u32 domain,
14876a65509SSudeep Holla 			 u32 *state);
14976a65509SSudeep Holla };
15076a65509SSudeep Holla 
1515179c523SSudeep Holla struct scmi_sensor_info {
1525179c523SSudeep Holla 	u32 id;
1535179c523SSudeep Holla 	u8 type;
1540b673b64SFlorian Fainelli 	s8 scale;
155d09aac0eSSudeep Holla 	u8 num_trip_points;
156d09aac0eSSudeep Holla 	bool async;
1575179c523SSudeep Holla 	char name[SCMI_MAX_STR_SIZE];
1585179c523SSudeep Holla };
1595179c523SSudeep Holla 
1605179c523SSudeep Holla /*
1615179c523SSudeep Holla  * Partial list from Distributed Management Task Force (DMTF) specification:
1625179c523SSudeep Holla  * DSP0249 (Platform Level Data Model specification)
1635179c523SSudeep Holla  */
1645179c523SSudeep Holla enum scmi_sensor_class {
1655179c523SSudeep Holla 	NONE = 0x0,
1665179c523SSudeep Holla 	TEMPERATURE_C = 0x2,
1675179c523SSudeep Holla 	VOLTAGE = 0x5,
1685179c523SSudeep Holla 	CURRENT = 0x6,
1695179c523SSudeep Holla 	POWER = 0x7,
1705179c523SSudeep Holla 	ENERGY = 0x8,
1715179c523SSudeep Holla };
1725179c523SSudeep Holla 
1735179c523SSudeep Holla /**
1745179c523SSudeep Holla  * struct scmi_sensor_ops - represents the various operations provided
1755179c523SSudeep Holla  *	by SCMI Sensor Protocol
1765179c523SSudeep Holla  *
1775179c523SSudeep Holla  * @count_get: get the count of sensors provided by SCMI
1785179c523SSudeep Holla  * @info_get: get the information of the specified sensor
1799eefa43aSSudeep Holla  * @trip_point_notify: control notifications on cross-over events for
1805179c523SSudeep Holla  *	the trip-points
1819eefa43aSSudeep Holla  * @trip_point_config: selects and configures a trip-point of interest
1825179c523SSudeep Holla  * @reading_get: gets the current value of the sensor
1835179c523SSudeep Holla  */
1845179c523SSudeep Holla struct scmi_sensor_ops {
1855179c523SSudeep Holla 	int (*count_get)(const struct scmi_handle *handle);
1865179c523SSudeep Holla 
1875179c523SSudeep Holla 	const struct scmi_sensor_info *(*info_get)
1885179c523SSudeep Holla 		(const struct scmi_handle *handle, u32 sensor_id);
1899eefa43aSSudeep Holla 	int (*trip_point_notify)(const struct scmi_handle *handle,
1909eefa43aSSudeep Holla 				 u32 sensor_id, bool enable);
1919eefa43aSSudeep Holla 	int (*trip_point_config)(const struct scmi_handle *handle,
1929eefa43aSSudeep Holla 				 u32 sensor_id, u8 trip_id, u64 trip_value);
1935179c523SSudeep Holla 	int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id,
1946a55331cSSudeep Holla 			   u64 *value);
1955179c523SSudeep Holla };
1965179c523SSudeep Holla 
19776a65509SSudeep Holla /**
19895a15d80SSudeep Holla  * struct scmi_reset_ops - represents the various operations provided
19995a15d80SSudeep Holla  *	by SCMI Reset Protocol
20095a15d80SSudeep Holla  *
20195a15d80SSudeep Holla  * @num_domains_get: get the count of reset domains provided by SCMI
20295a15d80SSudeep Holla  * @name_get: gets the name of a reset domain
20395a15d80SSudeep Holla  * @latency_get: gets the reset latency for the specified reset domain
20495a15d80SSudeep Holla  * @reset: resets the specified reset domain
20595a15d80SSudeep Holla  * @assert: explicitly assert reset signal of the specified reset domain
20695a15d80SSudeep Holla  * @deassert: explicitly deassert reset signal of the specified reset domain
20795a15d80SSudeep Holla  */
20895a15d80SSudeep Holla struct scmi_reset_ops {
20995a15d80SSudeep Holla 	int (*num_domains_get)(const struct scmi_handle *handle);
21095a15d80SSudeep Holla 	char *(*name_get)(const struct scmi_handle *handle, u32 domain);
21195a15d80SSudeep Holla 	int (*latency_get)(const struct scmi_handle *handle, u32 domain);
21295a15d80SSudeep Holla 	int (*reset)(const struct scmi_handle *handle, u32 domain);
21395a15d80SSudeep Holla 	int (*assert)(const struct scmi_handle *handle, u32 domain);
21495a15d80SSudeep Holla 	int (*deassert)(const struct scmi_handle *handle, u32 domain);
21595a15d80SSudeep Holla };
21695a15d80SSudeep Holla 
21795a15d80SSudeep Holla /**
218e7c215f3SCristian Marussi  * struct scmi_notify_ops  - represents notifications' operations provided by
219e7c215f3SCristian Marussi  * SCMI core
220e7c215f3SCristian Marussi  * @register_event_notifier: Register a notifier_block for the requested event
221e7c215f3SCristian Marussi  * @unregister_event_notifier: Unregister a notifier_block for the requested
222e7c215f3SCristian Marussi  *			       event
223e7c215f3SCristian Marussi  *
224e7c215f3SCristian Marussi  * A user can register/unregister its own notifier_block against the wanted
225e7c215f3SCristian Marussi  * platform instance regarding the desired event identified by the
226e7c215f3SCristian Marussi  * tuple: (proto_id, evt_id, src_id) using the provided register/unregister
227e7c215f3SCristian Marussi  * interface where:
228e7c215f3SCristian Marussi  *
229e7c215f3SCristian Marussi  * @handle: The handle identifying the platform instance to use
230e7c215f3SCristian Marussi  * @proto_id: The protocol ID as in SCMI Specification
231e7c215f3SCristian Marussi  * @evt_id: The message ID of the desired event as in SCMI Specification
232e7c215f3SCristian Marussi  * @src_id: A pointer to the desired source ID if different sources are
233e7c215f3SCristian Marussi  *	    possible for the protocol (like domain_id, sensor_id...etc)
234e7c215f3SCristian Marussi  *
235e7c215f3SCristian Marussi  * @src_id can be provided as NULL if it simply does NOT make sense for
236e7c215f3SCristian Marussi  * the protocol at hand, OR if the user is explicitly interested in
237e7c215f3SCristian Marussi  * receiving notifications from ANY existent source associated to the
238e7c215f3SCristian Marussi  * specified proto_id / evt_id.
239e7c215f3SCristian Marussi  *
240e7c215f3SCristian Marussi  * Received notifications are finally delivered to the registered users,
241e7c215f3SCristian Marussi  * invoking the callback provided with the notifier_block *nb as follows:
242e7c215f3SCristian Marussi  *
243e7c215f3SCristian Marussi  *	int user_cb(nb, evt_id, report)
244e7c215f3SCristian Marussi  *
245e7c215f3SCristian Marussi  * with:
246e7c215f3SCristian Marussi  *
247e7c215f3SCristian Marussi  * @nb: The notifier block provided by the user
248e7c215f3SCristian Marussi  * @evt_id: The message ID of the delivered event
249e7c215f3SCristian Marussi  * @report: A custom struct describing the specific event delivered
250e7c215f3SCristian Marussi  */
251e7c215f3SCristian Marussi struct scmi_notify_ops {
252e7c215f3SCristian Marussi 	int (*register_event_notifier)(const struct scmi_handle *handle,
253e7c215f3SCristian Marussi 				       u8 proto_id, u8 evt_id, u32 *src_id,
254e7c215f3SCristian Marussi 				       struct notifier_block *nb);
255e7c215f3SCristian Marussi 	int (*unregister_event_notifier)(const struct scmi_handle *handle,
256e7c215f3SCristian Marussi 					 u8 proto_id, u8 evt_id, u32 *src_id,
257e7c215f3SCristian Marussi 					 struct notifier_block *nb);
258e7c215f3SCristian Marussi };
259e7c215f3SCristian Marussi 
260e7c215f3SCristian Marussi /**
261aa4f886fSSudeep Holla  * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
262aa4f886fSSudeep Holla  *
263aa4f886fSSudeep Holla  * @dev: pointer to the SCMI device
264b6f20ff8SSudeep Holla  * @version: pointer to the structure containing SCMI version information
26576a65509SSudeep Holla  * @power_ops: pointer to set of power protocol operations
266a9e3fbfaSSudeep Holla  * @perf_ops: pointer to set of performance protocol operations
2675f6c6430SSudeep Holla  * @clk_ops: pointer to set of clock protocol operations
2685179c523SSudeep Holla  * @sensor_ops: pointer to set of sensor protocol operations
26995a15d80SSudeep Holla  * @reset_ops: pointer to set of reset protocol operations
270e7c215f3SCristian Marussi  * @notify_ops: pointer to set of notifications related operations
2711baf47c2SSudeep Holla  * @perf_priv: pointer to private data structure specific to performance
2721baf47c2SSudeep Holla  *	protocol(for internal use only)
2731baf47c2SSudeep Holla  * @clk_priv: pointer to private data structure specific to clock
2741baf47c2SSudeep Holla  *	protocol(for internal use only)
2751baf47c2SSudeep Holla  * @power_priv: pointer to private data structure specific to power
2761baf47c2SSudeep Holla  *	protocol(for internal use only)
2771baf47c2SSudeep Holla  * @sensor_priv: pointer to private data structure specific to sensors
2781baf47c2SSudeep Holla  *	protocol(for internal use only)
27995a15d80SSudeep Holla  * @reset_priv: pointer to private data structure specific to reset
28095a15d80SSudeep Holla  *	protocol(for internal use only)
2811fc2dd18SCristian Marussi  * @notify_priv: pointer to private data structure specific to notifications
2821fc2dd18SCristian Marussi  *	(for internal use only)
283aa4f886fSSudeep Holla  */
284aa4f886fSSudeep Holla struct scmi_handle {
285aa4f886fSSudeep Holla 	struct device *dev;
286b6f20ff8SSudeep Holla 	struct scmi_revision_info *version;
287a9e3fbfaSSudeep Holla 	struct scmi_perf_ops *perf_ops;
2885f6c6430SSudeep Holla 	struct scmi_clk_ops *clk_ops;
28976a65509SSudeep Holla 	struct scmi_power_ops *power_ops;
2905179c523SSudeep Holla 	struct scmi_sensor_ops *sensor_ops;
29195a15d80SSudeep Holla 	struct scmi_reset_ops *reset_ops;
292e7c215f3SCristian Marussi 	struct scmi_notify_ops *notify_ops;
293a9e3fbfaSSudeep Holla 	/* for protocol internal use */
294a9e3fbfaSSudeep Holla 	void *perf_priv;
2955f6c6430SSudeep Holla 	void *clk_priv;
29676a65509SSudeep Holla 	void *power_priv;
2975179c523SSudeep Holla 	void *sensor_priv;
29895a15d80SSudeep Holla 	void *reset_priv;
2991fc2dd18SCristian Marussi 	void *notify_priv;
300b6f20ff8SSudeep Holla };
301b6f20ff8SSudeep Holla 
302b6f20ff8SSudeep Holla enum scmi_std_protocol {
303b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_BASE = 0x10,
304b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_POWER = 0x11,
305b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_SYSTEM = 0x12,
306b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_PERF = 0x13,
307b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_CLOCK = 0x14,
308b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_SENSOR = 0x15,
30995a15d80SSudeep Holla 	SCMI_PROTOCOL_RESET = 0x16,
310aa4f886fSSudeep Holla };
311933c5044SSudeep Holla 
312933c5044SSudeep Holla struct scmi_device {
313933c5044SSudeep Holla 	u32 id;
314933c5044SSudeep Holla 	u8 protocol_id;
315ee7a9c9fSSudeep Holla 	const char *name;
316933c5044SSudeep Holla 	struct device dev;
317933c5044SSudeep Holla 	struct scmi_handle *handle;
318933c5044SSudeep Holla };
319933c5044SSudeep Holla 
320933c5044SSudeep Holla #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
321933c5044SSudeep Holla 
322933c5044SSudeep Holla struct scmi_device *
323ee7a9c9fSSudeep Holla scmi_device_create(struct device_node *np, struct device *parent, int protocol,
324ee7a9c9fSSudeep Holla 		   const char *name);
325933c5044SSudeep Holla void scmi_device_destroy(struct scmi_device *scmi_dev);
326933c5044SSudeep Holla 
327933c5044SSudeep Holla struct scmi_device_id {
328933c5044SSudeep Holla 	u8 protocol_id;
329ee7a9c9fSSudeep Holla 	const char *name;
330933c5044SSudeep Holla };
331933c5044SSudeep Holla 
332933c5044SSudeep Holla struct scmi_driver {
333933c5044SSudeep Holla 	const char *name;
334933c5044SSudeep Holla 	int (*probe)(struct scmi_device *sdev);
335933c5044SSudeep Holla 	void (*remove)(struct scmi_device *sdev);
336933c5044SSudeep Holla 	const struct scmi_device_id *id_table;
337933c5044SSudeep Holla 
338933c5044SSudeep Holla 	struct device_driver driver;
339933c5044SSudeep Holla };
340933c5044SSudeep Holla 
341933c5044SSudeep Holla #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
342933c5044SSudeep Holla 
343933c5044SSudeep Holla #ifdef CONFIG_ARM_SCMI_PROTOCOL
344933c5044SSudeep Holla int scmi_driver_register(struct scmi_driver *driver,
345933c5044SSudeep Holla 			 struct module *owner, const char *mod_name);
346933c5044SSudeep Holla void scmi_driver_unregister(struct scmi_driver *driver);
347933c5044SSudeep Holla #else
348933c5044SSudeep Holla static inline int
349933c5044SSudeep Holla scmi_driver_register(struct scmi_driver *driver, struct module *owner,
350933c5044SSudeep Holla 		     const char *mod_name)
351933c5044SSudeep Holla {
352933c5044SSudeep Holla 	return -EINVAL;
353933c5044SSudeep Holla }
354933c5044SSudeep Holla 
355933c5044SSudeep Holla static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
356933c5044SSudeep Holla #endif /* CONFIG_ARM_SCMI_PROTOCOL */
357933c5044SSudeep Holla 
358933c5044SSudeep Holla #define scmi_register(driver) \
359933c5044SSudeep Holla 	scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
360933c5044SSudeep Holla #define scmi_unregister(driver) \
361933c5044SSudeep Holla 	scmi_driver_unregister(driver)
362933c5044SSudeep Holla 
363933c5044SSudeep Holla /**
364933c5044SSudeep Holla  * module_scmi_driver() - Helper macro for registering a scmi driver
365933c5044SSudeep Holla  * @__scmi_driver: scmi_driver structure
366933c5044SSudeep Holla  *
367933c5044SSudeep Holla  * Helper macro for scmi drivers to set up proper module init / exit
368933c5044SSudeep Holla  * functions.  Replaces module_init() and module_exit() and keeps people from
369933c5044SSudeep Holla  * printing pointless things to the kernel log when their driver is loaded.
370933c5044SSudeep Holla  */
371933c5044SSudeep Holla #define module_scmi_driver(__scmi_driver)	\
372933c5044SSudeep Holla 	module_driver(__scmi_driver, scmi_register, scmi_unregister)
373933c5044SSudeep Holla 
374933c5044SSudeep Holla typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *);
375933c5044SSudeep Holla int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn);
376933c5044SSudeep Holla void scmi_protocol_unregister(int protocol_id);
37770771c69SSudeep Holla 
378*e27077bcSCristian Marussi /* SCMI Notification API - Custom Event Reports */
379*e27077bcSCristian Marussi enum scmi_notification_events {
380*e27077bcSCristian Marussi 	SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
381*e27077bcSCristian Marussi };
382*e27077bcSCristian Marussi 
383*e27077bcSCristian Marussi struct scmi_power_state_changed_report {
384*e27077bcSCristian Marussi 	u64 timestamp;
385*e27077bcSCristian Marussi 	u32 agent_id;
386*e27077bcSCristian Marussi 	u32 domain_id;
387*e27077bcSCristian Marussi 	u32 power_state;
388*e27077bcSCristian Marussi };
389*e27077bcSCristian Marussi 
39070771c69SSudeep Holla #endif /* _LINUX_SCMI_PROTOCOL_H */
391