xref: /openbmc/linux/include/linux/scmi_protocol.h (revision 82894c1d)
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_config: selects and configures a trip-point of interest
1805179c523SSudeep Holla  * @reading_get: gets the current value of the sensor
1815179c523SSudeep Holla  */
1825179c523SSudeep Holla struct scmi_sensor_ops {
1835179c523SSudeep Holla 	int (*count_get)(const struct scmi_handle *handle);
1845179c523SSudeep Holla 	const struct scmi_sensor_info *(*info_get)
1855179c523SSudeep Holla 		(const struct scmi_handle *handle, u32 sensor_id);
1869eefa43aSSudeep Holla 	int (*trip_point_config)(const struct scmi_handle *handle,
1879eefa43aSSudeep Holla 				 u32 sensor_id, u8 trip_id, u64 trip_value);
1885179c523SSudeep Holla 	int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id,
1896a55331cSSudeep Holla 			   u64 *value);
1905179c523SSudeep Holla };
1915179c523SSudeep Holla 
19276a65509SSudeep Holla /**
19395a15d80SSudeep Holla  * struct scmi_reset_ops - represents the various operations provided
19495a15d80SSudeep Holla  *	by SCMI Reset Protocol
19595a15d80SSudeep Holla  *
19695a15d80SSudeep Holla  * @num_domains_get: get the count of reset domains provided by SCMI
19795a15d80SSudeep Holla  * @name_get: gets the name of a reset domain
19895a15d80SSudeep Holla  * @latency_get: gets the reset latency for the specified reset domain
19995a15d80SSudeep Holla  * @reset: resets the specified reset domain
20095a15d80SSudeep Holla  * @assert: explicitly assert reset signal of the specified reset domain
20195a15d80SSudeep Holla  * @deassert: explicitly deassert reset signal of the specified reset domain
20295a15d80SSudeep Holla  */
20395a15d80SSudeep Holla struct scmi_reset_ops {
20495a15d80SSudeep Holla 	int (*num_domains_get)(const struct scmi_handle *handle);
20595a15d80SSudeep Holla 	char *(*name_get)(const struct scmi_handle *handle, u32 domain);
20695a15d80SSudeep Holla 	int (*latency_get)(const struct scmi_handle *handle, u32 domain);
20795a15d80SSudeep Holla 	int (*reset)(const struct scmi_handle *handle, u32 domain);
20895a15d80SSudeep Holla 	int (*assert)(const struct scmi_handle *handle, u32 domain);
20995a15d80SSudeep Holla 	int (*deassert)(const struct scmi_handle *handle, u32 domain);
21095a15d80SSudeep Holla };
21195a15d80SSudeep Holla 
21295a15d80SSudeep Holla /**
213e7c215f3SCristian Marussi  * struct scmi_notify_ops  - represents notifications' operations provided by
214e7c215f3SCristian Marussi  * SCMI core
215e7c215f3SCristian Marussi  * @register_event_notifier: Register a notifier_block for the requested event
216e7c215f3SCristian Marussi  * @unregister_event_notifier: Unregister a notifier_block for the requested
217e7c215f3SCristian Marussi  *			       event
218e7c215f3SCristian Marussi  *
219e7c215f3SCristian Marussi  * A user can register/unregister its own notifier_block against the wanted
220e7c215f3SCristian Marussi  * platform instance regarding the desired event identified by the
221e7c215f3SCristian Marussi  * tuple: (proto_id, evt_id, src_id) using the provided register/unregister
222e7c215f3SCristian Marussi  * interface where:
223e7c215f3SCristian Marussi  *
224e7c215f3SCristian Marussi  * @handle: The handle identifying the platform instance to use
225e7c215f3SCristian Marussi  * @proto_id: The protocol ID as in SCMI Specification
226e7c215f3SCristian Marussi  * @evt_id: The message ID of the desired event as in SCMI Specification
227e7c215f3SCristian Marussi  * @src_id: A pointer to the desired source ID if different sources are
228e7c215f3SCristian Marussi  *	    possible for the protocol (like domain_id, sensor_id...etc)
229e7c215f3SCristian Marussi  *
230e7c215f3SCristian Marussi  * @src_id can be provided as NULL if it simply does NOT make sense for
231e7c215f3SCristian Marussi  * the protocol at hand, OR if the user is explicitly interested in
232e7c215f3SCristian Marussi  * receiving notifications from ANY existent source associated to the
233e7c215f3SCristian Marussi  * specified proto_id / evt_id.
234e7c215f3SCristian Marussi  *
235e7c215f3SCristian Marussi  * Received notifications are finally delivered to the registered users,
236e7c215f3SCristian Marussi  * invoking the callback provided with the notifier_block *nb as follows:
237e7c215f3SCristian Marussi  *
238e7c215f3SCristian Marussi  *	int user_cb(nb, evt_id, report)
239e7c215f3SCristian Marussi  *
240e7c215f3SCristian Marussi  * with:
241e7c215f3SCristian Marussi  *
242e7c215f3SCristian Marussi  * @nb: The notifier block provided by the user
243e7c215f3SCristian Marussi  * @evt_id: The message ID of the delivered event
244e7c215f3SCristian Marussi  * @report: A custom struct describing the specific event delivered
245e7c215f3SCristian Marussi  */
246e7c215f3SCristian Marussi struct scmi_notify_ops {
247e7c215f3SCristian Marussi 	int (*register_event_notifier)(const struct scmi_handle *handle,
248e7c215f3SCristian Marussi 				       u8 proto_id, u8 evt_id, u32 *src_id,
249e7c215f3SCristian Marussi 				       struct notifier_block *nb);
250e7c215f3SCristian Marussi 	int (*unregister_event_notifier)(const struct scmi_handle *handle,
251e7c215f3SCristian Marussi 					 u8 proto_id, u8 evt_id, u32 *src_id,
252e7c215f3SCristian Marussi 					 struct notifier_block *nb);
253e7c215f3SCristian Marussi };
254e7c215f3SCristian Marussi 
255e7c215f3SCristian Marussi /**
256aa4f886fSSudeep Holla  * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
257aa4f886fSSudeep Holla  *
258aa4f886fSSudeep Holla  * @dev: pointer to the SCMI device
259b6f20ff8SSudeep Holla  * @version: pointer to the structure containing SCMI version information
26076a65509SSudeep Holla  * @power_ops: pointer to set of power protocol operations
261a9e3fbfaSSudeep Holla  * @perf_ops: pointer to set of performance protocol operations
2625f6c6430SSudeep Holla  * @clk_ops: pointer to set of clock protocol operations
2635179c523SSudeep Holla  * @sensor_ops: pointer to set of sensor protocol operations
26495a15d80SSudeep Holla  * @reset_ops: pointer to set of reset protocol operations
265e7c215f3SCristian Marussi  * @notify_ops: pointer to set of notifications related operations
2661baf47c2SSudeep Holla  * @perf_priv: pointer to private data structure specific to performance
2671baf47c2SSudeep Holla  *	protocol(for internal use only)
2681baf47c2SSudeep Holla  * @clk_priv: pointer to private data structure specific to clock
2691baf47c2SSudeep Holla  *	protocol(for internal use only)
2701baf47c2SSudeep Holla  * @power_priv: pointer to private data structure specific to power
2711baf47c2SSudeep Holla  *	protocol(for internal use only)
2721baf47c2SSudeep Holla  * @sensor_priv: pointer to private data structure specific to sensors
2731baf47c2SSudeep Holla  *	protocol(for internal use only)
27495a15d80SSudeep Holla  * @reset_priv: pointer to private data structure specific to reset
27595a15d80SSudeep Holla  *	protocol(for internal use only)
2761fc2dd18SCristian Marussi  * @notify_priv: pointer to private data structure specific to notifications
2771fc2dd18SCristian Marussi  *	(for internal use only)
278aa4f886fSSudeep Holla  */
279aa4f886fSSudeep Holla struct scmi_handle {
280aa4f886fSSudeep Holla 	struct device *dev;
281b6f20ff8SSudeep Holla 	struct scmi_revision_info *version;
28282894c1dSRikard Falkeborn 	const struct scmi_perf_ops *perf_ops;
28382894c1dSRikard Falkeborn 	const struct scmi_clk_ops *clk_ops;
28482894c1dSRikard Falkeborn 	const struct scmi_power_ops *power_ops;
28582894c1dSRikard Falkeborn 	const struct scmi_sensor_ops *sensor_ops;
28682894c1dSRikard Falkeborn 	const struct scmi_reset_ops *reset_ops;
28782894c1dSRikard Falkeborn 	const struct scmi_notify_ops *notify_ops;
288a9e3fbfaSSudeep Holla 	/* for protocol internal use */
289a9e3fbfaSSudeep Holla 	void *perf_priv;
2905f6c6430SSudeep Holla 	void *clk_priv;
29176a65509SSudeep Holla 	void *power_priv;
2925179c523SSudeep Holla 	void *sensor_priv;
29395a15d80SSudeep Holla 	void *reset_priv;
2941fc2dd18SCristian Marussi 	void *notify_priv;
295b6f20ff8SSudeep Holla };
296b6f20ff8SSudeep Holla 
297b6f20ff8SSudeep Holla enum scmi_std_protocol {
298b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_BASE = 0x10,
299b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_POWER = 0x11,
300b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_SYSTEM = 0x12,
301b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_PERF = 0x13,
302b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_CLOCK = 0x14,
303b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_SENSOR = 0x15,
30495a15d80SSudeep Holla 	SCMI_PROTOCOL_RESET = 0x16,
305aa4f886fSSudeep Holla };
306933c5044SSudeep Holla 
307933c5044SSudeep Holla struct scmi_device {
308933c5044SSudeep Holla 	u32 id;
309933c5044SSudeep Holla 	u8 protocol_id;
310ee7a9c9fSSudeep Holla 	const char *name;
311933c5044SSudeep Holla 	struct device dev;
312933c5044SSudeep Holla 	struct scmi_handle *handle;
313933c5044SSudeep Holla };
314933c5044SSudeep Holla 
315933c5044SSudeep Holla #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
316933c5044SSudeep Holla 
317933c5044SSudeep Holla struct scmi_device *
318ee7a9c9fSSudeep Holla scmi_device_create(struct device_node *np, struct device *parent, int protocol,
319ee7a9c9fSSudeep Holla 		   const char *name);
320933c5044SSudeep Holla void scmi_device_destroy(struct scmi_device *scmi_dev);
321933c5044SSudeep Holla 
322933c5044SSudeep Holla struct scmi_device_id {
323933c5044SSudeep Holla 	u8 protocol_id;
324ee7a9c9fSSudeep Holla 	const char *name;
325933c5044SSudeep Holla };
326933c5044SSudeep Holla 
327933c5044SSudeep Holla struct scmi_driver {
328933c5044SSudeep Holla 	const char *name;
329933c5044SSudeep Holla 	int (*probe)(struct scmi_device *sdev);
330933c5044SSudeep Holla 	void (*remove)(struct scmi_device *sdev);
331933c5044SSudeep Holla 	const struct scmi_device_id *id_table;
332933c5044SSudeep Holla 
333933c5044SSudeep Holla 	struct device_driver driver;
334933c5044SSudeep Holla };
335933c5044SSudeep Holla 
336933c5044SSudeep Holla #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
337933c5044SSudeep Holla 
338933c5044SSudeep Holla #ifdef CONFIG_ARM_SCMI_PROTOCOL
339933c5044SSudeep Holla int scmi_driver_register(struct scmi_driver *driver,
340933c5044SSudeep Holla 			 struct module *owner, const char *mod_name);
341933c5044SSudeep Holla void scmi_driver_unregister(struct scmi_driver *driver);
342933c5044SSudeep Holla #else
343933c5044SSudeep Holla static inline int
344933c5044SSudeep Holla scmi_driver_register(struct scmi_driver *driver, struct module *owner,
345933c5044SSudeep Holla 		     const char *mod_name)
346933c5044SSudeep Holla {
347933c5044SSudeep Holla 	return -EINVAL;
348933c5044SSudeep Holla }
349933c5044SSudeep Holla 
350933c5044SSudeep Holla static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
351933c5044SSudeep Holla #endif /* CONFIG_ARM_SCMI_PROTOCOL */
352933c5044SSudeep Holla 
353933c5044SSudeep Holla #define scmi_register(driver) \
354933c5044SSudeep Holla 	scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
355933c5044SSudeep Holla #define scmi_unregister(driver) \
356933c5044SSudeep Holla 	scmi_driver_unregister(driver)
357933c5044SSudeep Holla 
358933c5044SSudeep Holla /**
359933c5044SSudeep Holla  * module_scmi_driver() - Helper macro for registering a scmi driver
360933c5044SSudeep Holla  * @__scmi_driver: scmi_driver structure
361933c5044SSudeep Holla  *
362933c5044SSudeep Holla  * Helper macro for scmi drivers to set up proper module init / exit
363933c5044SSudeep Holla  * functions.  Replaces module_init() and module_exit() and keeps people from
364933c5044SSudeep Holla  * printing pointless things to the kernel log when their driver is loaded.
365933c5044SSudeep Holla  */
366933c5044SSudeep Holla #define module_scmi_driver(__scmi_driver)	\
367933c5044SSudeep Holla 	module_driver(__scmi_driver, scmi_register, scmi_unregister)
368933c5044SSudeep Holla 
369933c5044SSudeep Holla typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *);
370933c5044SSudeep Holla int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn);
371933c5044SSudeep Holla void scmi_protocol_unregister(int protocol_id);
37270771c69SSudeep Holla 
373e27077bcSCristian Marussi /* SCMI Notification API - Custom Event Reports */
374e27077bcSCristian Marussi enum scmi_notification_events {
375e27077bcSCristian Marussi 	SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
376fb5086dcSCristian Marussi 	SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
377fb5086dcSCristian Marussi 	SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
378128e3e93SCristian Marussi 	SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
379469ca182SCristian Marussi 	SCMI_EVENT_RESET_ISSUED = 0x0,
380585dfab3SCristian Marussi 	SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
381e27077bcSCristian Marussi };
382e27077bcSCristian Marussi 
383e27077bcSCristian Marussi struct scmi_power_state_changed_report {
38472a5eb9dSCristian Marussi 	ktime_t		timestamp;
38572a5eb9dSCristian Marussi 	unsigned int	agent_id;
38672a5eb9dSCristian Marussi 	unsigned int	domain_id;
38772a5eb9dSCristian Marussi 	unsigned int	power_state;
388e27077bcSCristian Marussi };
389e27077bcSCristian Marussi 
390fb5086dcSCristian Marussi struct scmi_perf_limits_report {
39172a5eb9dSCristian Marussi 	ktime_t		timestamp;
39272a5eb9dSCristian Marussi 	unsigned int	agent_id;
39372a5eb9dSCristian Marussi 	unsigned int	domain_id;
39472a5eb9dSCristian Marussi 	unsigned int	range_max;
39572a5eb9dSCristian Marussi 	unsigned int	range_min;
396fb5086dcSCristian Marussi };
397fb5086dcSCristian Marussi 
398fb5086dcSCristian Marussi struct scmi_perf_level_report {
39972a5eb9dSCristian Marussi 	ktime_t		timestamp;
40072a5eb9dSCristian Marussi 	unsigned int	agent_id;
40172a5eb9dSCristian Marussi 	unsigned int	domain_id;
40272a5eb9dSCristian Marussi 	unsigned int	performance_level;
403fb5086dcSCristian Marussi };
404fb5086dcSCristian Marussi 
405128e3e93SCristian Marussi struct scmi_sensor_trip_point_report {
40672a5eb9dSCristian Marussi 	ktime_t		timestamp;
40772a5eb9dSCristian Marussi 	unsigned int	agent_id;
40872a5eb9dSCristian Marussi 	unsigned int	sensor_id;
40972a5eb9dSCristian Marussi 	unsigned int	trip_point_desc;
410128e3e93SCristian Marussi };
411128e3e93SCristian Marussi 
412469ca182SCristian Marussi struct scmi_reset_issued_report {
41372a5eb9dSCristian Marussi 	ktime_t		timestamp;
41472a5eb9dSCristian Marussi 	unsigned int	agent_id;
41572a5eb9dSCristian Marussi 	unsigned int	domain_id;
41672a5eb9dSCristian Marussi 	unsigned int	reset_state;
417469ca182SCristian Marussi };
418469ca182SCristian Marussi 
419585dfab3SCristian Marussi struct scmi_base_error_report {
42072a5eb9dSCristian Marussi 	ktime_t			timestamp;
42172a5eb9dSCristian Marussi 	unsigned int		agent_id;
422585dfab3SCristian Marussi 	bool			fatal;
42372a5eb9dSCristian Marussi 	unsigned int		cmd_count;
42472a5eb9dSCristian Marussi 	unsigned long long	reports[];
425585dfab3SCristian Marussi };
426585dfab3SCristian Marussi 
42770771c69SSudeep Holla #endif /* _LINUX_SCMI_PROTOCOL_H */
428