xref: /openbmc/linux/include/linux/scmi_protocol.h (revision 76ea4d8e)
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);
124*76ea4d8eSLukasz Luba 	bool (*power_scale_mw_get)(const struct scmi_handle *handle);
125a9e3fbfaSSudeep Holla };
126a9e3fbfaSSudeep Holla 
127aa4f886fSSudeep Holla /**
12876a65509SSudeep Holla  * struct scmi_power_ops - represents the various operations provided
12976a65509SSudeep Holla  *	by SCMI Power Protocol
13076a65509SSudeep Holla  *
13176a65509SSudeep Holla  * @num_domains_get: get the count of power domains provided by SCMI
13276a65509SSudeep Holla  * @name_get: gets the name of a power domain
13376a65509SSudeep Holla  * @state_set: sets the power state of a power domain
13476a65509SSudeep Holla  * @state_get: gets the power state of a power domain
13576a65509SSudeep Holla  */
13676a65509SSudeep Holla struct scmi_power_ops {
13776a65509SSudeep Holla 	int (*num_domains_get)(const struct scmi_handle *handle);
13876a65509SSudeep Holla 	char *(*name_get)(const struct scmi_handle *handle, u32 domain);
13976a65509SSudeep Holla #define SCMI_POWER_STATE_TYPE_SHIFT	30
14076a65509SSudeep Holla #define SCMI_POWER_STATE_ID_MASK	(BIT(28) - 1)
14176a65509SSudeep Holla #define SCMI_POWER_STATE_PARAM(type, id) \
14276a65509SSudeep Holla 	((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
14376a65509SSudeep Holla 		((id) & SCMI_POWER_STATE_ID_MASK))
14476a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_ON	SCMI_POWER_STATE_PARAM(0, 0)
14576a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_OFF	SCMI_POWER_STATE_PARAM(1, 0)
14676a65509SSudeep Holla 	int (*state_set)(const struct scmi_handle *handle, u32 domain,
14776a65509SSudeep Holla 			 u32 state);
14876a65509SSudeep Holla 	int (*state_get)(const struct scmi_handle *handle, u32 domain,
14976a65509SSudeep Holla 			 u32 *state);
15076a65509SSudeep Holla };
15176a65509SSudeep Holla 
1525179c523SSudeep Holla struct scmi_sensor_info {
1535179c523SSudeep Holla 	u32 id;
1545179c523SSudeep Holla 	u8 type;
1550b673b64SFlorian Fainelli 	s8 scale;
156d09aac0eSSudeep Holla 	u8 num_trip_points;
157d09aac0eSSudeep Holla 	bool async;
1585179c523SSudeep Holla 	char name[SCMI_MAX_STR_SIZE];
1595179c523SSudeep Holla };
1605179c523SSudeep Holla 
1615179c523SSudeep Holla /*
1625179c523SSudeep Holla  * Partial list from Distributed Management Task Force (DMTF) specification:
1635179c523SSudeep Holla  * DSP0249 (Platform Level Data Model specification)
1645179c523SSudeep Holla  */
1655179c523SSudeep Holla enum scmi_sensor_class {
1665179c523SSudeep Holla 	NONE = 0x0,
1675179c523SSudeep Holla 	TEMPERATURE_C = 0x2,
1685179c523SSudeep Holla 	VOLTAGE = 0x5,
1695179c523SSudeep Holla 	CURRENT = 0x6,
1705179c523SSudeep Holla 	POWER = 0x7,
1715179c523SSudeep Holla 	ENERGY = 0x8,
1725179c523SSudeep Holla };
1735179c523SSudeep Holla 
1745179c523SSudeep Holla /**
1755179c523SSudeep Holla  * struct scmi_sensor_ops - represents the various operations provided
1765179c523SSudeep Holla  *	by SCMI Sensor Protocol
1775179c523SSudeep Holla  *
1785179c523SSudeep Holla  * @count_get: get the count of sensors provided by SCMI
1795179c523SSudeep Holla  * @info_get: get the information of the specified sensor
1809eefa43aSSudeep Holla  * @trip_point_config: selects and configures a trip-point of interest
1815179c523SSudeep Holla  * @reading_get: gets the current value of the sensor
1825179c523SSudeep Holla  */
1835179c523SSudeep Holla struct scmi_sensor_ops {
1845179c523SSudeep Holla 	int (*count_get)(const struct scmi_handle *handle);
1855179c523SSudeep Holla 	const struct scmi_sensor_info *(*info_get)
1865179c523SSudeep Holla 		(const struct scmi_handle *handle, u32 sensor_id);
1879eefa43aSSudeep Holla 	int (*trip_point_config)(const struct scmi_handle *handle,
1889eefa43aSSudeep Holla 				 u32 sensor_id, u8 trip_id, u64 trip_value);
1895179c523SSudeep Holla 	int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id,
1906a55331cSSudeep Holla 			   u64 *value);
1915179c523SSudeep Holla };
1925179c523SSudeep Holla 
19376a65509SSudeep Holla /**
19495a15d80SSudeep Holla  * struct scmi_reset_ops - represents the various operations provided
19595a15d80SSudeep Holla  *	by SCMI Reset Protocol
19695a15d80SSudeep Holla  *
19795a15d80SSudeep Holla  * @num_domains_get: get the count of reset domains provided by SCMI
19895a15d80SSudeep Holla  * @name_get: gets the name of a reset domain
19995a15d80SSudeep Holla  * @latency_get: gets the reset latency for the specified reset domain
20095a15d80SSudeep Holla  * @reset: resets the specified reset domain
20195a15d80SSudeep Holla  * @assert: explicitly assert reset signal of the specified reset domain
20295a15d80SSudeep Holla  * @deassert: explicitly deassert reset signal of the specified reset domain
20395a15d80SSudeep Holla  */
20495a15d80SSudeep Holla struct scmi_reset_ops {
20595a15d80SSudeep Holla 	int (*num_domains_get)(const struct scmi_handle *handle);
20695a15d80SSudeep Holla 	char *(*name_get)(const struct scmi_handle *handle, u32 domain);
20795a15d80SSudeep Holla 	int (*latency_get)(const struct scmi_handle *handle, u32 domain);
20895a15d80SSudeep Holla 	int (*reset)(const struct scmi_handle *handle, u32 domain);
20995a15d80SSudeep Holla 	int (*assert)(const struct scmi_handle *handle, u32 domain);
21095a15d80SSudeep Holla 	int (*deassert)(const struct scmi_handle *handle, u32 domain);
21195a15d80SSudeep Holla };
21295a15d80SSudeep Holla 
21395a15d80SSudeep Holla /**
214e7c215f3SCristian Marussi  * struct scmi_notify_ops  - represents notifications' operations provided by
215e7c215f3SCristian Marussi  * SCMI core
216e7c215f3SCristian Marussi  * @register_event_notifier: Register a notifier_block for the requested event
217e7c215f3SCristian Marussi  * @unregister_event_notifier: Unregister a notifier_block for the requested
218e7c215f3SCristian Marussi  *			       event
219e7c215f3SCristian Marussi  *
220e7c215f3SCristian Marussi  * A user can register/unregister its own notifier_block against the wanted
221e7c215f3SCristian Marussi  * platform instance regarding the desired event identified by the
222e7c215f3SCristian Marussi  * tuple: (proto_id, evt_id, src_id) using the provided register/unregister
223e7c215f3SCristian Marussi  * interface where:
224e7c215f3SCristian Marussi  *
225e7c215f3SCristian Marussi  * @handle: The handle identifying the platform instance to use
226e7c215f3SCristian Marussi  * @proto_id: The protocol ID as in SCMI Specification
227e7c215f3SCristian Marussi  * @evt_id: The message ID of the desired event as in SCMI Specification
228e7c215f3SCristian Marussi  * @src_id: A pointer to the desired source ID if different sources are
229e7c215f3SCristian Marussi  *	    possible for the protocol (like domain_id, sensor_id...etc)
230e7c215f3SCristian Marussi  *
231e7c215f3SCristian Marussi  * @src_id can be provided as NULL if it simply does NOT make sense for
232e7c215f3SCristian Marussi  * the protocol at hand, OR if the user is explicitly interested in
233e7c215f3SCristian Marussi  * receiving notifications from ANY existent source associated to the
234e7c215f3SCristian Marussi  * specified proto_id / evt_id.
235e7c215f3SCristian Marussi  *
236e7c215f3SCristian Marussi  * Received notifications are finally delivered to the registered users,
237e7c215f3SCristian Marussi  * invoking the callback provided with the notifier_block *nb as follows:
238e7c215f3SCristian Marussi  *
239e7c215f3SCristian Marussi  *	int user_cb(nb, evt_id, report)
240e7c215f3SCristian Marussi  *
241e7c215f3SCristian Marussi  * with:
242e7c215f3SCristian Marussi  *
243e7c215f3SCristian Marussi  * @nb: The notifier block provided by the user
244e7c215f3SCristian Marussi  * @evt_id: The message ID of the delivered event
245e7c215f3SCristian Marussi  * @report: A custom struct describing the specific event delivered
246e7c215f3SCristian Marussi  */
247e7c215f3SCristian Marussi struct scmi_notify_ops {
248e7c215f3SCristian Marussi 	int (*register_event_notifier)(const struct scmi_handle *handle,
249e7c215f3SCristian Marussi 				       u8 proto_id, u8 evt_id, u32 *src_id,
250e7c215f3SCristian Marussi 				       struct notifier_block *nb);
251e7c215f3SCristian Marussi 	int (*unregister_event_notifier)(const struct scmi_handle *handle,
252e7c215f3SCristian Marussi 					 u8 proto_id, u8 evt_id, u32 *src_id,
253e7c215f3SCristian Marussi 					 struct notifier_block *nb);
254e7c215f3SCristian Marussi };
255e7c215f3SCristian Marussi 
256e7c215f3SCristian Marussi /**
257aa4f886fSSudeep Holla  * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
258aa4f886fSSudeep Holla  *
259aa4f886fSSudeep Holla  * @dev: pointer to the SCMI device
260b6f20ff8SSudeep Holla  * @version: pointer to the structure containing SCMI version information
26176a65509SSudeep Holla  * @power_ops: pointer to set of power protocol operations
262a9e3fbfaSSudeep Holla  * @perf_ops: pointer to set of performance protocol operations
2635f6c6430SSudeep Holla  * @clk_ops: pointer to set of clock protocol operations
2645179c523SSudeep Holla  * @sensor_ops: pointer to set of sensor protocol operations
26595a15d80SSudeep Holla  * @reset_ops: pointer to set of reset protocol operations
266e7c215f3SCristian Marussi  * @notify_ops: pointer to set of notifications related operations
2671baf47c2SSudeep Holla  * @perf_priv: pointer to private data structure specific to performance
2681baf47c2SSudeep Holla  *	protocol(for internal use only)
2691baf47c2SSudeep Holla  * @clk_priv: pointer to private data structure specific to clock
2701baf47c2SSudeep Holla  *	protocol(for internal use only)
2711baf47c2SSudeep Holla  * @power_priv: pointer to private data structure specific to power
2721baf47c2SSudeep Holla  *	protocol(for internal use only)
2731baf47c2SSudeep Holla  * @sensor_priv: pointer to private data structure specific to sensors
2741baf47c2SSudeep Holla  *	protocol(for internal use only)
27595a15d80SSudeep Holla  * @reset_priv: pointer to private data structure specific to reset
27695a15d80SSudeep Holla  *	protocol(for internal use only)
2771fc2dd18SCristian Marussi  * @notify_priv: pointer to private data structure specific to notifications
2781fc2dd18SCristian Marussi  *	(for internal use only)
279aa4f886fSSudeep Holla  */
280aa4f886fSSudeep Holla struct scmi_handle {
281aa4f886fSSudeep Holla 	struct device *dev;
282b6f20ff8SSudeep Holla 	struct scmi_revision_info *version;
28382894c1dSRikard Falkeborn 	const struct scmi_perf_ops *perf_ops;
28482894c1dSRikard Falkeborn 	const struct scmi_clk_ops *clk_ops;
28582894c1dSRikard Falkeborn 	const struct scmi_power_ops *power_ops;
28682894c1dSRikard Falkeborn 	const struct scmi_sensor_ops *sensor_ops;
28782894c1dSRikard Falkeborn 	const struct scmi_reset_ops *reset_ops;
28882894c1dSRikard Falkeborn 	const struct scmi_notify_ops *notify_ops;
289a9e3fbfaSSudeep Holla 	/* for protocol internal use */
290a9e3fbfaSSudeep Holla 	void *perf_priv;
2915f6c6430SSudeep Holla 	void *clk_priv;
29276a65509SSudeep Holla 	void *power_priv;
2935179c523SSudeep Holla 	void *sensor_priv;
29495a15d80SSudeep Holla 	void *reset_priv;
2951fc2dd18SCristian Marussi 	void *notify_priv;
296a8803055SCristian Marussi 	void *system_priv;
297b6f20ff8SSudeep Holla };
298b6f20ff8SSudeep Holla 
299b6f20ff8SSudeep Holla enum scmi_std_protocol {
300b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_BASE = 0x10,
301b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_POWER = 0x11,
302b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_SYSTEM = 0x12,
303b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_PERF = 0x13,
304b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_CLOCK = 0x14,
305b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_SENSOR = 0x15,
30695a15d80SSudeep Holla 	SCMI_PROTOCOL_RESET = 0x16,
307aa4f886fSSudeep Holla };
308933c5044SSudeep Holla 
309a8803055SCristian Marussi enum scmi_system_events {
310a8803055SCristian Marussi 	SCMI_SYSTEM_SHUTDOWN,
311a8803055SCristian Marussi 	SCMI_SYSTEM_COLDRESET,
312a8803055SCristian Marussi 	SCMI_SYSTEM_WARMRESET,
313a8803055SCristian Marussi 	SCMI_SYSTEM_POWERUP,
314a8803055SCristian Marussi 	SCMI_SYSTEM_SUSPEND,
315a8803055SCristian Marussi 	SCMI_SYSTEM_MAX
316a8803055SCristian Marussi };
317a8803055SCristian Marussi 
318933c5044SSudeep Holla struct scmi_device {
319933c5044SSudeep Holla 	u32 id;
320933c5044SSudeep Holla 	u8 protocol_id;
321ee7a9c9fSSudeep Holla 	const char *name;
322933c5044SSudeep Holla 	struct device dev;
323933c5044SSudeep Holla 	struct scmi_handle *handle;
324933c5044SSudeep Holla };
325933c5044SSudeep Holla 
326933c5044SSudeep Holla #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
327933c5044SSudeep Holla 
328933c5044SSudeep Holla struct scmi_device *
329ee7a9c9fSSudeep Holla scmi_device_create(struct device_node *np, struct device *parent, int protocol,
330ee7a9c9fSSudeep Holla 		   const char *name);
331933c5044SSudeep Holla void scmi_device_destroy(struct scmi_device *scmi_dev);
332933c5044SSudeep Holla 
333933c5044SSudeep Holla struct scmi_device_id {
334933c5044SSudeep Holla 	u8 protocol_id;
335ee7a9c9fSSudeep Holla 	const char *name;
336933c5044SSudeep Holla };
337933c5044SSudeep Holla 
338933c5044SSudeep Holla struct scmi_driver {
339933c5044SSudeep Holla 	const char *name;
340933c5044SSudeep Holla 	int (*probe)(struct scmi_device *sdev);
341933c5044SSudeep Holla 	void (*remove)(struct scmi_device *sdev);
342933c5044SSudeep Holla 	const struct scmi_device_id *id_table;
343933c5044SSudeep Holla 
344933c5044SSudeep Holla 	struct device_driver driver;
345933c5044SSudeep Holla };
346933c5044SSudeep Holla 
347933c5044SSudeep Holla #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
348933c5044SSudeep Holla 
34966d90f6eSSudeep Holla #if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL)
350933c5044SSudeep Holla int scmi_driver_register(struct scmi_driver *driver,
351933c5044SSudeep Holla 			 struct module *owner, const char *mod_name);
352933c5044SSudeep Holla void scmi_driver_unregister(struct scmi_driver *driver);
353933c5044SSudeep Holla #else
354933c5044SSudeep Holla static inline int
355933c5044SSudeep Holla scmi_driver_register(struct scmi_driver *driver, struct module *owner,
356933c5044SSudeep Holla 		     const char *mod_name)
357933c5044SSudeep Holla {
358933c5044SSudeep Holla 	return -EINVAL;
359933c5044SSudeep Holla }
360933c5044SSudeep Holla 
361933c5044SSudeep Holla static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
362933c5044SSudeep Holla #endif /* CONFIG_ARM_SCMI_PROTOCOL */
363933c5044SSudeep Holla 
364933c5044SSudeep Holla #define scmi_register(driver) \
365933c5044SSudeep Holla 	scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
366933c5044SSudeep Holla #define scmi_unregister(driver) \
367933c5044SSudeep Holla 	scmi_driver_unregister(driver)
368933c5044SSudeep Holla 
369933c5044SSudeep Holla /**
370933c5044SSudeep Holla  * module_scmi_driver() - Helper macro for registering a scmi driver
371933c5044SSudeep Holla  * @__scmi_driver: scmi_driver structure
372933c5044SSudeep Holla  *
373933c5044SSudeep Holla  * Helper macro for scmi drivers to set up proper module init / exit
374933c5044SSudeep Holla  * functions.  Replaces module_init() and module_exit() and keeps people from
375933c5044SSudeep Holla  * printing pointless things to the kernel log when their driver is loaded.
376933c5044SSudeep Holla  */
377933c5044SSudeep Holla #define module_scmi_driver(__scmi_driver)	\
378933c5044SSudeep Holla 	module_driver(__scmi_driver, scmi_register, scmi_unregister)
379933c5044SSudeep Holla 
380933c5044SSudeep Holla typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *);
381933c5044SSudeep Holla int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn);
382933c5044SSudeep Holla void scmi_protocol_unregister(int protocol_id);
38370771c69SSudeep Holla 
384e27077bcSCristian Marussi /* SCMI Notification API - Custom Event Reports */
385e27077bcSCristian Marussi enum scmi_notification_events {
386e27077bcSCristian Marussi 	SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
387fb5086dcSCristian Marussi 	SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
388fb5086dcSCristian Marussi 	SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
389128e3e93SCristian Marussi 	SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
390469ca182SCristian Marussi 	SCMI_EVENT_RESET_ISSUED = 0x0,
391585dfab3SCristian Marussi 	SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
392a8803055SCristian Marussi 	SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
393e27077bcSCristian Marussi };
394e27077bcSCristian Marussi 
395e27077bcSCristian Marussi struct scmi_power_state_changed_report {
39672a5eb9dSCristian Marussi 	ktime_t		timestamp;
39772a5eb9dSCristian Marussi 	unsigned int	agent_id;
39872a5eb9dSCristian Marussi 	unsigned int	domain_id;
39972a5eb9dSCristian Marussi 	unsigned int	power_state;
400e27077bcSCristian Marussi };
401e27077bcSCristian Marussi 
402a8803055SCristian Marussi struct scmi_system_power_state_notifier_report {
403a8803055SCristian Marussi 	ktime_t		timestamp;
404a8803055SCristian Marussi 	unsigned int	agent_id;
405a8803055SCristian Marussi 	unsigned int	flags;
406a8803055SCristian Marussi 	unsigned int	system_state;
407a8803055SCristian Marussi };
408a8803055SCristian Marussi 
409fb5086dcSCristian Marussi struct scmi_perf_limits_report {
41072a5eb9dSCristian Marussi 	ktime_t		timestamp;
41172a5eb9dSCristian Marussi 	unsigned int	agent_id;
41272a5eb9dSCristian Marussi 	unsigned int	domain_id;
41372a5eb9dSCristian Marussi 	unsigned int	range_max;
41472a5eb9dSCristian Marussi 	unsigned int	range_min;
415fb5086dcSCristian Marussi };
416fb5086dcSCristian Marussi 
417fb5086dcSCristian Marussi struct scmi_perf_level_report {
41872a5eb9dSCristian Marussi 	ktime_t		timestamp;
41972a5eb9dSCristian Marussi 	unsigned int	agent_id;
42072a5eb9dSCristian Marussi 	unsigned int	domain_id;
42172a5eb9dSCristian Marussi 	unsigned int	performance_level;
422fb5086dcSCristian Marussi };
423fb5086dcSCristian Marussi 
424128e3e93SCristian Marussi struct scmi_sensor_trip_point_report {
42572a5eb9dSCristian Marussi 	ktime_t		timestamp;
42672a5eb9dSCristian Marussi 	unsigned int	agent_id;
42772a5eb9dSCristian Marussi 	unsigned int	sensor_id;
42872a5eb9dSCristian Marussi 	unsigned int	trip_point_desc;
429128e3e93SCristian Marussi };
430128e3e93SCristian Marussi 
431469ca182SCristian Marussi struct scmi_reset_issued_report {
43272a5eb9dSCristian Marussi 	ktime_t		timestamp;
43372a5eb9dSCristian Marussi 	unsigned int	agent_id;
43472a5eb9dSCristian Marussi 	unsigned int	domain_id;
43572a5eb9dSCristian Marussi 	unsigned int	reset_state;
436469ca182SCristian Marussi };
437469ca182SCristian Marussi 
438585dfab3SCristian Marussi struct scmi_base_error_report {
43972a5eb9dSCristian Marussi 	ktime_t			timestamp;
44072a5eb9dSCristian Marussi 	unsigned int		agent_id;
441585dfab3SCristian Marussi 	bool			fatal;
44272a5eb9dSCristian Marussi 	unsigned int		cmd_count;
44372a5eb9dSCristian Marussi 	unsigned long long	reports[];
444585dfab3SCristian Marussi };
445585dfab3SCristian Marussi 
44670771c69SSudeep Holla #endif /* _LINUX_SCMI_PROTOCOL_H */
447