xref: /openbmc/linux/include/linux/scmi_protocol.h (revision 4c74701b)
14752544aSSudeep Holla /* SPDX-License-Identifier: GPL-2.0-only */
2aa4f886fSSudeep Holla /*
3aa4f886fSSudeep Holla  * SCMI Message Protocol driver header
4aa4f886fSSudeep Holla  *
548dc16e2SCristian Marussi  * Copyright (C) 2018-2021 ARM Ltd.
6aa4f886fSSudeep Holla  */
770771c69SSudeep Holla 
870771c69SSudeep Holla #ifndef _LINUX_SCMI_PROTOCOL_H
970771c69SSudeep Holla #define _LINUX_SCMI_PROTOCOL_H
1070771c69SSudeep Holla 
111fe00b8bSCristian Marussi #include <linux/bitfield.h>
12933c5044SSudeep Holla #include <linux/device.h>
13e7c215f3SCristian Marussi #include <linux/notifier.h>
14aa4f886fSSudeep Holla #include <linux/types.h>
15aa4f886fSSudeep Holla 
16b260fccaSCristian Marussi #define SCMI_MAX_STR_SIZE	64
175f6c6430SSudeep Holla #define SCMI_MAX_NUM_RATES	16
18b6f20ff8SSudeep Holla 
19b6f20ff8SSudeep Holla /**
20b6f20ff8SSudeep Holla  * struct scmi_revision_info - version information structure
21b6f20ff8SSudeep Holla  *
22b6f20ff8SSudeep Holla  * @major_ver: Major ABI version. Change here implies risk of backward
23b6f20ff8SSudeep Holla  *	compatibility break.
24b6f20ff8SSudeep Holla  * @minor_ver: Minor ABI version. Change here implies new feature addition,
25b6f20ff8SSudeep Holla  *	or compatible change in ABI.
26b6f20ff8SSudeep Holla  * @num_protocols: Number of protocols that are implemented, excluding the
27b6f20ff8SSudeep Holla  *	base protocol.
28b6f20ff8SSudeep Holla  * @num_agents: Number of agents in the system.
29b6f20ff8SSudeep Holla  * @impl_ver: A vendor-specific implementation version.
30b6f20ff8SSudeep Holla  * @vendor_id: A vendor identifier(Null terminated ASCII string)
31b6f20ff8SSudeep Holla  * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string)
32b6f20ff8SSudeep Holla  */
33b6f20ff8SSudeep Holla struct scmi_revision_info {
34b6f20ff8SSudeep Holla 	u16 major_ver;
35b6f20ff8SSudeep Holla 	u16 minor_ver;
36b6f20ff8SSudeep Holla 	u8 num_protocols;
37b6f20ff8SSudeep Holla 	u8 num_agents;
38b6f20ff8SSudeep Holla 	u32 impl_ver;
39b6f20ff8SSudeep Holla 	char vendor_id[SCMI_MAX_STR_SIZE];
40b6f20ff8SSudeep Holla 	char sub_vendor_id[SCMI_MAX_STR_SIZE];
41b6f20ff8SSudeep Holla };
42b6f20ff8SSudeep Holla 
435f6c6430SSudeep Holla struct scmi_clock_info {
445f6c6430SSudeep Holla 	char name[SCMI_MAX_STR_SIZE];
4518f295b7SCristian Marussi 	unsigned int enable_latency;
465f6c6430SSudeep Holla 	bool rate_discrete;
477aa75496SCristian Marussi 	bool rate_changed_notifications;
487aa75496SCristian Marussi 	bool rate_change_requested_notifications;
495f6c6430SSudeep Holla 	union {
505f6c6430SSudeep Holla 		struct {
515f6c6430SSudeep Holla 			int num_rates;
525f6c6430SSudeep Holla 			u64 rates[SCMI_MAX_NUM_RATES];
535f6c6430SSudeep Holla 		} list;
545f6c6430SSudeep Holla 		struct {
555f6c6430SSudeep Holla 			u64 min_rate;
565f6c6430SSudeep Holla 			u64 max_rate;
575f6c6430SSudeep Holla 			u64 step_size;
585f6c6430SSudeep Holla 		} range;
595f6c6430SSudeep Holla 	};
605f6c6430SSudeep Holla };
615f6c6430SSudeep Holla 
62a9e3fbfaSSudeep Holla struct scmi_handle;
6323934efeSCristian Marussi struct scmi_device;
6423934efeSCristian Marussi struct scmi_protocol_handle;
65a9e3fbfaSSudeep Holla 
66a9e3fbfaSSudeep Holla /**
67887281c7SCristian Marussi  * struct scmi_clk_proto_ops - represents the various operations provided
685f6c6430SSudeep Holla  *	by SCMI Clock Protocol
695f6c6430SSudeep Holla  *
705f6c6430SSudeep Holla  * @count_get: get the count of clocks provided by SCMI
715f6c6430SSudeep Holla  * @info_get: get the information of the specified clock
725f6c6430SSudeep Holla  * @rate_get: request the current clock rate of a clock
735f6c6430SSudeep Holla  * @rate_set: set the clock rate of a clock
745f6c6430SSudeep Holla  * @enable: enables the specified clock
755f6c6430SSudeep Holla  * @disable: disables the specified clock
765f6c6430SSudeep Holla  */
77887281c7SCristian Marussi struct scmi_clk_proto_ops {
78887281c7SCristian Marussi 	int (*count_get)(const struct scmi_protocol_handle *ph);
79887281c7SCristian Marussi 
80887281c7SCristian Marussi 	const struct scmi_clock_info *(*info_get)
81887281c7SCristian Marussi 		(const struct scmi_protocol_handle *ph, u32 clk_id);
82887281c7SCristian Marussi 	int (*rate_get)(const struct scmi_protocol_handle *ph, u32 clk_id,
83887281c7SCristian Marussi 			u64 *rate);
84887281c7SCristian Marussi 	int (*rate_set)(const struct scmi_protocol_handle *ph, u32 clk_id,
85887281c7SCristian Marussi 			u64 rate);
86887281c7SCristian Marussi 	int (*enable)(const struct scmi_protocol_handle *ph, u32 clk_id);
87887281c7SCristian Marussi 	int (*disable)(const struct scmi_protocol_handle *ph, u32 clk_id);
88b7bd36f2SCristian Marussi 	int (*enable_atomic)(const struct scmi_protocol_handle *ph, u32 clk_id);
89b7bd36f2SCristian Marussi 	int (*disable_atomic)(const struct scmi_protocol_handle *ph,
90b7bd36f2SCristian Marussi 			      u32 clk_id);
91887281c7SCristian Marussi };
92887281c7SCristian Marussi 
935f6c6430SSudeep Holla /**
941fec5e6bSCristian Marussi  * struct scmi_perf_proto_ops - represents the various operations provided
95a9e3fbfaSSudeep Holla  *	by SCMI Performance Protocol
96a9e3fbfaSSudeep Holla  *
97a9e3fbfaSSudeep Holla  * @limits_set: sets limits on the performance level of a domain
98a9e3fbfaSSudeep Holla  * @limits_get: gets limits on the performance level of a domain
99a9e3fbfaSSudeep Holla  * @level_set: sets the performance level of a domain
100a9e3fbfaSSudeep Holla  * @level_get: gets the performance level of a domain
101a9e3fbfaSSudeep Holla  * @device_domain_id: gets the scmi domain id for a given device
1027859e08cSSudeep Holla  * @transition_latency_get: gets the DVFS transition latency for a given device
1037859e08cSSudeep Holla  * @device_opps_add: adds all the OPPs for a given device
104a9e3fbfaSSudeep Holla  * @freq_set: sets the frequency for a given device using sustained frequency
105a9e3fbfaSSudeep Holla  *	to sustained performance level mapping
106a9e3fbfaSSudeep Holla  * @freq_get: gets the frequency for a given device using sustained frequency
107a9e3fbfaSSudeep Holla  *	to sustained performance level mapping
1081a63fe9aSQuentin Perret  * @est_power_get: gets the estimated power cost for a given performance domain
1091a63fe9aSQuentin Perret  *	at a given frequency
11052f83955SSudeep Holla  * @fast_switch_possible: indicates if fast DVFS switching is possible or not
11152f83955SSudeep Holla  *	for a given device
11252f83955SSudeep Holla  * @power_scale_mw_get: indicates if the power values provided are in milliWatts
11352f83955SSudeep Holla  *	or in some other (abstract) scale
114a9e3fbfaSSudeep Holla  */
1151fec5e6bSCristian Marussi struct scmi_perf_proto_ops {
1161fec5e6bSCristian Marussi 	int (*limits_set)(const struct scmi_protocol_handle *ph, u32 domain,
1171fec5e6bSCristian Marussi 			  u32 max_perf, u32 min_perf);
1181fec5e6bSCristian Marussi 	int (*limits_get)(const struct scmi_protocol_handle *ph, u32 domain,
1191fec5e6bSCristian Marussi 			  u32 *max_perf, u32 *min_perf);
1201fec5e6bSCristian Marussi 	int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain,
1211fec5e6bSCristian Marussi 			 u32 level, bool poll);
1221fec5e6bSCristian Marussi 	int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain,
1231fec5e6bSCristian Marussi 			 u32 *level, bool poll);
1241fec5e6bSCristian Marussi 	int (*device_domain_id)(struct device *dev);
1251fec5e6bSCristian Marussi 	int (*transition_latency_get)(const struct scmi_protocol_handle *ph,
1261fec5e6bSCristian Marussi 				      struct device *dev);
1271fec5e6bSCristian Marussi 	int (*device_opps_add)(const struct scmi_protocol_handle *ph,
1281fec5e6bSCristian Marussi 			       struct device *dev);
1291fec5e6bSCristian Marussi 	int (*freq_set)(const struct scmi_protocol_handle *ph, u32 domain,
1301fec5e6bSCristian Marussi 			unsigned long rate, bool poll);
1311fec5e6bSCristian Marussi 	int (*freq_get)(const struct scmi_protocol_handle *ph, u32 domain,
1321fec5e6bSCristian Marussi 			unsigned long *rate, bool poll);
1331fec5e6bSCristian Marussi 	int (*est_power_get)(const struct scmi_protocol_handle *ph, u32 domain,
1341fec5e6bSCristian Marussi 			     unsigned long *rate, unsigned long *power);
1351fec5e6bSCristian Marussi 	bool (*fast_switch_possible)(const struct scmi_protocol_handle *ph,
1361fec5e6bSCristian Marussi 				     struct device *dev);
1371fec5e6bSCristian Marussi 	bool (*power_scale_mw_get)(const struct scmi_protocol_handle *ph);
1381fec5e6bSCristian Marussi };
1391fec5e6bSCristian Marussi 
140aa4f886fSSudeep Holla /**
1419bc8069cSCristian Marussi  * struct scmi_power_proto_ops - represents the various operations provided
14276a65509SSudeep Holla  *	by SCMI Power Protocol
14376a65509SSudeep Holla  *
14476a65509SSudeep Holla  * @num_domains_get: get the count of power domains provided by SCMI
14576a65509SSudeep Holla  * @name_get: gets the name of a power domain
14676a65509SSudeep Holla  * @state_set: sets the power state of a power domain
14776a65509SSudeep Holla  * @state_get: gets the power state of a power domain
14876a65509SSudeep Holla  */
1499bc8069cSCristian Marussi struct scmi_power_proto_ops {
1509bc8069cSCristian Marussi 	int (*num_domains_get)(const struct scmi_protocol_handle *ph);
151992be5d3SCristian Marussi 	const char *(*name_get)(const struct scmi_protocol_handle *ph,
152992be5d3SCristian Marussi 				u32 domain);
15376a65509SSudeep Holla #define SCMI_POWER_STATE_TYPE_SHIFT	30
15476a65509SSudeep Holla #define SCMI_POWER_STATE_ID_MASK	(BIT(28) - 1)
15576a65509SSudeep Holla #define SCMI_POWER_STATE_PARAM(type, id) \
15676a65509SSudeep Holla 	((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \
15776a65509SSudeep Holla 		((id) & SCMI_POWER_STATE_ID_MASK))
15876a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_ON	SCMI_POWER_STATE_PARAM(0, 0)
15976a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_OFF	SCMI_POWER_STATE_PARAM(1, 0)
1609bc8069cSCristian Marussi 	int (*state_set)(const struct scmi_protocol_handle *ph, u32 domain,
1619bc8069cSCristian Marussi 			 u32 state);
1629bc8069cSCristian Marussi 	int (*state_get)(const struct scmi_protocol_handle *ph, u32 domain,
1639bc8069cSCristian Marussi 			 u32 *state);
1649bc8069cSCristian Marussi };
1659bc8069cSCristian Marussi 
1661fe00b8bSCristian Marussi /**
16752f83955SSudeep Holla  * struct scmi_sensor_reading  - represent a timestamped read
168e2083d36SCristian Marussi  *
169e2083d36SCristian Marussi  * Used by @reading_get_timestamped method.
170e2083d36SCristian Marussi  *
171e2083d36SCristian Marussi  * @value: The signed value sensor read.
172e2083d36SCristian Marussi  * @timestamp: An unsigned timestamp for the sensor read, as provided by
173e2083d36SCristian Marussi  *	       SCMI platform. Set to zero when not available.
174e2083d36SCristian Marussi  */
175e2083d36SCristian Marussi struct scmi_sensor_reading {
176e2083d36SCristian Marussi 	long long value;
177e2083d36SCristian Marussi 	unsigned long long timestamp;
178e2083d36SCristian Marussi };
179e2083d36SCristian Marussi 
180e2083d36SCristian Marussi /**
18152f83955SSudeep Holla  * struct scmi_range_attrs  - specifies a sensor or axis values' range
1821fe00b8bSCristian Marussi  * @min_range: The minimum value which can be represented by the sensor/axis.
1831fe00b8bSCristian Marussi  * @max_range: The maximum value which can be represented by the sensor/axis.
1841fe00b8bSCristian Marussi  */
1851fe00b8bSCristian Marussi struct scmi_range_attrs {
1861fe00b8bSCristian Marussi 	long long min_range;
1871fe00b8bSCristian Marussi 	long long max_range;
1881fe00b8bSCristian Marussi };
1891fe00b8bSCristian Marussi 
1901fe00b8bSCristian Marussi /**
19152f83955SSudeep Holla  * struct scmi_sensor_axis_info  - describes one sensor axes
1921fe00b8bSCristian Marussi  * @id: The axes ID.
1931fe00b8bSCristian Marussi  * @type: Axes type. Chosen amongst one of @enum scmi_sensor_class.
1941fe00b8bSCristian Marussi  * @scale: Power-of-10 multiplier applied to the axis unit.
1951fe00b8bSCristian Marussi  * @name: NULL-terminated string representing axes name as advertised by
1961fe00b8bSCristian Marussi  *	  SCMI platform.
1971fe00b8bSCristian Marussi  * @extended_attrs: Flag to indicate the presence of additional extended
1981fe00b8bSCristian Marussi  *		    attributes for this axes.
1991fe00b8bSCristian Marussi  * @resolution: Extended attribute representing the resolution of the axes.
2001fe00b8bSCristian Marussi  *		Set to 0 if not reported by this axes.
2011fe00b8bSCristian Marussi  * @exponent: Extended attribute representing the power-of-10 multiplier that
2021fe00b8bSCristian Marussi  *	      is applied to the resolution field. Set to 0 if not reported by
2031fe00b8bSCristian Marussi  *	      this axes.
2041fe00b8bSCristian Marussi  * @attrs: Extended attributes representing minimum and maximum values
2051fe00b8bSCristian Marussi  *	   measurable by this axes. Set to 0 if not reported by this sensor.
2061fe00b8bSCristian Marussi  */
2071fe00b8bSCristian Marussi struct scmi_sensor_axis_info {
2081fe00b8bSCristian Marussi 	unsigned int id;
2091fe00b8bSCristian Marussi 	unsigned int type;
2101fe00b8bSCristian Marussi 	int scale;
2115179c523SSudeep Holla 	char name[SCMI_MAX_STR_SIZE];
2121fe00b8bSCristian Marussi 	bool extended_attrs;
2131fe00b8bSCristian Marussi 	unsigned int resolution;
2141fe00b8bSCristian Marussi 	int exponent;
2151fe00b8bSCristian Marussi 	struct scmi_range_attrs attrs;
2161fe00b8bSCristian Marussi };
2171fe00b8bSCristian Marussi 
2181fe00b8bSCristian Marussi /**
21952f83955SSudeep Holla  * struct scmi_sensor_intervals_info  - describes number and type of available
22052f83955SSudeep Holla  *	update intervals
2211fe00b8bSCristian Marussi  * @segmented: Flag for segmented intervals' representation. When True there
2221fe00b8bSCristian Marussi  *	       will be exactly 3 intervals in @desc, with each entry
2231fe00b8bSCristian Marussi  *	       representing a member of a segment in this order:
2241fe00b8bSCristian Marussi  *	       {lowest update interval, highest update interval, step size}
2251fe00b8bSCristian Marussi  * @count: Number of intervals described in @desc.
2261fe00b8bSCristian Marussi  * @desc: Array of @count interval descriptor bitmask represented as detailed in
2271fe00b8bSCristian Marussi  *	  the SCMI specification: it can be accessed using the accompanying
2281fe00b8bSCristian Marussi  *	  macros.
2291fe00b8bSCristian Marussi  * @prealloc_pool: A minimal preallocated pool of desc entries used to avoid
2301fe00b8bSCristian Marussi  *		   lesser-than-64-bytes dynamic allocation for small @count
2311fe00b8bSCristian Marussi  *		   values.
2321fe00b8bSCristian Marussi  */
2331fe00b8bSCristian Marussi struct scmi_sensor_intervals_info {
2341fe00b8bSCristian Marussi 	bool segmented;
2351fe00b8bSCristian Marussi 	unsigned int count;
2361fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_SEGMENT_LOW	0
2371fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_SEGMENT_HIGH	1
2381fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_SEGMENT_STEP	2
2391fe00b8bSCristian Marussi 	unsigned int *desc;
2401fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_GET_SECS(x)		FIELD_GET(GENMASK(20, 5), (x))
2411fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_GET_EXP(x)					\
2421fe00b8bSCristian Marussi 	({								\
2431fe00b8bSCristian Marussi 		int __signed_exp = FIELD_GET(GENMASK(4, 0), (x));	\
2441fe00b8bSCristian Marussi 									\
2451fe00b8bSCristian Marussi 		if (__signed_exp & BIT(4))				\
2461fe00b8bSCristian Marussi 			__signed_exp |= GENMASK(31, 5);			\
2471fe00b8bSCristian Marussi 		__signed_exp;						\
2481fe00b8bSCristian Marussi 	})
2491fe00b8bSCristian Marussi #define SCMI_MAX_PREALLOC_POOL			16
2501fe00b8bSCristian Marussi 	unsigned int prealloc_pool[SCMI_MAX_PREALLOC_POOL];
2511fe00b8bSCristian Marussi };
2521fe00b8bSCristian Marussi 
2531fe00b8bSCristian Marussi /**
2541fe00b8bSCristian Marussi  * struct scmi_sensor_info - represents information related to one of the
2551fe00b8bSCristian Marussi  * available sensors.
2561fe00b8bSCristian Marussi  * @id: Sensor ID.
2571fe00b8bSCristian Marussi  * @type: Sensor type. Chosen amongst one of @enum scmi_sensor_class.
2581fe00b8bSCristian Marussi  * @scale: Power-of-10 multiplier applied to the sensor unit.
2591fe00b8bSCristian Marussi  * @num_trip_points: Number of maximum configurable trip points.
2601fe00b8bSCristian Marussi  * @async: Flag for asynchronous read support.
2611fe00b8bSCristian Marussi  * @update: Flag for continuouos update notification support.
2621fe00b8bSCristian Marussi  * @timestamped: Flag for timestamped read support.
2631fe00b8bSCristian Marussi  * @tstamp_scale: Power-of-10 multiplier applied to the sensor timestamps to
2641fe00b8bSCristian Marussi  *		  represent it in seconds.
2651fe00b8bSCristian Marussi  * @num_axis: Number of supported axis if any. Reported as 0 for scalar sensors.
2661fe00b8bSCristian Marussi  * @axis: Pointer to an array of @num_axis descriptors.
2671fe00b8bSCristian Marussi  * @intervals: Descriptor of available update intervals.
2681fe00b8bSCristian Marussi  * @sensor_config: A bitmask reporting the current sensor configuration as
2691fe00b8bSCristian Marussi  *		   detailed in the SCMI specification: it can accessed and
2701fe00b8bSCristian Marussi  *		   modified through the accompanying macros.
2711fe00b8bSCristian Marussi  * @name: NULL-terminated string representing sensor name as advertised by
2721fe00b8bSCristian Marussi  *	  SCMI platform.
2731fe00b8bSCristian Marussi  * @extended_scalar_attrs: Flag to indicate the presence of additional extended
2741fe00b8bSCristian Marussi  *			   attributes for this sensor.
2751fe00b8bSCristian Marussi  * @sensor_power: Extended attribute representing the average power
2761fe00b8bSCristian Marussi  *		  consumed by the sensor in microwatts (uW) when it is active.
2771fe00b8bSCristian Marussi  *		  Reported here only for scalar sensors.
2781fe00b8bSCristian Marussi  *		  Set to 0 if not reported by this sensor.
2791fe00b8bSCristian Marussi  * @resolution: Extended attribute representing the resolution of the sensor.
2801fe00b8bSCristian Marussi  *		Reported here only for scalar sensors.
2811fe00b8bSCristian Marussi  *		Set to 0 if not reported by this sensor.
2821fe00b8bSCristian Marussi  * @exponent: Extended attribute representing the power-of-10 multiplier that is
2831fe00b8bSCristian Marussi  *	      applied to the resolution field.
2841fe00b8bSCristian Marussi  *	      Reported here only for scalar sensors.
2851fe00b8bSCristian Marussi  *	      Set to 0 if not reported by this sensor.
2861fe00b8bSCristian Marussi  * @scalar_attrs: Extended attributes representing minimum and maximum
2871fe00b8bSCristian Marussi  *		  measurable values by this sensor.
2881fe00b8bSCristian Marussi  *		  Reported here only for scalar sensors.
2891fe00b8bSCristian Marussi  *		  Set to 0 if not reported by this sensor.
2901fe00b8bSCristian Marussi  */
2911fe00b8bSCristian Marussi struct scmi_sensor_info {
2921fe00b8bSCristian Marussi 	unsigned int id;
2931fe00b8bSCristian Marussi 	unsigned int type;
2941fe00b8bSCristian Marussi 	int scale;
2951fe00b8bSCristian Marussi 	unsigned int num_trip_points;
2961fe00b8bSCristian Marussi 	bool async;
2971fe00b8bSCristian Marussi 	bool update;
2981fe00b8bSCristian Marussi 	bool timestamped;
2991fe00b8bSCristian Marussi 	int tstamp_scale;
3001fe00b8bSCristian Marussi 	unsigned int num_axis;
3011fe00b8bSCristian Marussi 	struct scmi_sensor_axis_info *axis;
3021fe00b8bSCristian Marussi 	struct scmi_sensor_intervals_info intervals;
3037b83c5f4SCristian Marussi 	unsigned int sensor_config;
3047b83c5f4SCristian Marussi #define SCMI_SENS_CFG_UPDATE_SECS_MASK		GENMASK(31, 16)
3057b83c5f4SCristian Marussi #define SCMI_SENS_CFG_GET_UPDATE_SECS(x)				\
3067b83c5f4SCristian Marussi 	FIELD_GET(SCMI_SENS_CFG_UPDATE_SECS_MASK, (x))
3077b83c5f4SCristian Marussi 
3087b83c5f4SCristian Marussi #define SCMI_SENS_CFG_UPDATE_EXP_MASK		GENMASK(15, 11)
3097b83c5f4SCristian Marussi #define SCMI_SENS_CFG_GET_UPDATE_EXP(x)					\
3107b83c5f4SCristian Marussi 	({								\
3117b83c5f4SCristian Marussi 		int __signed_exp =					\
3127b83c5f4SCristian Marussi 			FIELD_GET(SCMI_SENS_CFG_UPDATE_EXP_MASK, (x));	\
3137b83c5f4SCristian Marussi 									\
3147b83c5f4SCristian Marussi 		if (__signed_exp & BIT(4))				\
3157b83c5f4SCristian Marussi 			__signed_exp |= GENMASK(31, 5);			\
3167b83c5f4SCristian Marussi 		__signed_exp;						\
3177b83c5f4SCristian Marussi 	})
3187b83c5f4SCristian Marussi 
3197b83c5f4SCristian Marussi #define SCMI_SENS_CFG_ROUND_MASK		GENMASK(10, 9)
3207b83c5f4SCristian Marussi #define SCMI_SENS_CFG_ROUND_AUTO		2
3217b83c5f4SCristian Marussi #define SCMI_SENS_CFG_ROUND_UP			1
3227b83c5f4SCristian Marussi #define SCMI_SENS_CFG_ROUND_DOWN		0
3237b83c5f4SCristian Marussi 
3247b83c5f4SCristian Marussi #define SCMI_SENS_CFG_TSTAMP_ENABLED_MASK	BIT(1)
3257b83c5f4SCristian Marussi #define SCMI_SENS_CFG_TSTAMP_ENABLE		1
3267b83c5f4SCristian Marussi #define SCMI_SENS_CFG_TSTAMP_DISABLE		0
3277b83c5f4SCristian Marussi #define SCMI_SENS_CFG_IS_TSTAMP_ENABLED(x)				\
3287b83c5f4SCristian Marussi 	FIELD_GET(SCMI_SENS_CFG_TSTAMP_ENABLED_MASK, (x))
3297b83c5f4SCristian Marussi 
3307b83c5f4SCristian Marussi #define SCMI_SENS_CFG_SENSOR_ENABLED_MASK	BIT(0)
3317b83c5f4SCristian Marussi #define SCMI_SENS_CFG_SENSOR_ENABLE		1
3327b83c5f4SCristian Marussi #define SCMI_SENS_CFG_SENSOR_DISABLE		0
3331fe00b8bSCristian Marussi 	char name[SCMI_MAX_STR_SIZE];
3347b83c5f4SCristian Marussi #define SCMI_SENS_CFG_IS_ENABLED(x)		FIELD_GET(BIT(0), (x))
3351fe00b8bSCristian Marussi 	bool extended_scalar_attrs;
3361fe00b8bSCristian Marussi 	unsigned int sensor_power;
3371fe00b8bSCristian Marussi 	unsigned int resolution;
3381fe00b8bSCristian Marussi 	int exponent;
3391fe00b8bSCristian Marussi 	struct scmi_range_attrs scalar_attrs;
3405179c523SSudeep Holla };
3415179c523SSudeep Holla 
3425179c523SSudeep Holla /*
3435179c523SSudeep Holla  * Partial list from Distributed Management Task Force (DMTF) specification:
3445179c523SSudeep Holla  * DSP0249 (Platform Level Data Model specification)
3455179c523SSudeep Holla  */
3465179c523SSudeep Holla enum scmi_sensor_class {
3475179c523SSudeep Holla 	NONE = 0x0,
348607a4672SSudeep Holla 	UNSPEC = 0x1,
3495179c523SSudeep Holla 	TEMPERATURE_C = 0x2,
350607a4672SSudeep Holla 	TEMPERATURE_F = 0x3,
351607a4672SSudeep Holla 	TEMPERATURE_K = 0x4,
3525179c523SSudeep Holla 	VOLTAGE = 0x5,
3535179c523SSudeep Holla 	CURRENT = 0x6,
3545179c523SSudeep Holla 	POWER = 0x7,
3555179c523SSudeep Holla 	ENERGY = 0x8,
356607a4672SSudeep Holla 	CHARGE = 0x9,
357607a4672SSudeep Holla 	VOLTAMPERE = 0xA,
358607a4672SSudeep Holla 	NITS = 0xB,
359607a4672SSudeep Holla 	LUMENS = 0xC,
360607a4672SSudeep Holla 	LUX = 0xD,
361607a4672SSudeep Holla 	CANDELAS = 0xE,
362607a4672SSudeep Holla 	KPA = 0xF,
363607a4672SSudeep Holla 	PSI = 0x10,
364607a4672SSudeep Holla 	NEWTON = 0x11,
365607a4672SSudeep Holla 	CFM = 0x12,
366607a4672SSudeep Holla 	RPM = 0x13,
367607a4672SSudeep Holla 	HERTZ = 0x14,
368607a4672SSudeep Holla 	SECS = 0x15,
369607a4672SSudeep Holla 	MINS = 0x16,
370607a4672SSudeep Holla 	HOURS = 0x17,
371607a4672SSudeep Holla 	DAYS = 0x18,
372607a4672SSudeep Holla 	WEEKS = 0x19,
373607a4672SSudeep Holla 	MILS = 0x1A,
374607a4672SSudeep Holla 	INCHES = 0x1B,
375607a4672SSudeep Holla 	FEET = 0x1C,
376607a4672SSudeep Holla 	CUBIC_INCHES = 0x1D,
377607a4672SSudeep Holla 	CUBIC_FEET = 0x1E,
378607a4672SSudeep Holla 	METERS = 0x1F,
379607a4672SSudeep Holla 	CUBIC_CM = 0x20,
380607a4672SSudeep Holla 	CUBIC_METERS = 0x21,
381607a4672SSudeep Holla 	LITERS = 0x22,
382607a4672SSudeep Holla 	FLUID_OUNCES = 0x23,
383607a4672SSudeep Holla 	RADIANS = 0x24,
384607a4672SSudeep Holla 	STERADIANS = 0x25,
385607a4672SSudeep Holla 	REVOLUTIONS = 0x26,
386607a4672SSudeep Holla 	CYCLES = 0x27,
387607a4672SSudeep Holla 	GRAVITIES = 0x28,
388607a4672SSudeep Holla 	OUNCES = 0x29,
389607a4672SSudeep Holla 	POUNDS = 0x2A,
390607a4672SSudeep Holla 	FOOT_POUNDS = 0x2B,
391607a4672SSudeep Holla 	OUNCE_INCHES = 0x2C,
392607a4672SSudeep Holla 	GAUSS = 0x2D,
393607a4672SSudeep Holla 	GILBERTS = 0x2E,
394607a4672SSudeep Holla 	HENRIES = 0x2F,
395607a4672SSudeep Holla 	FARADS = 0x30,
396607a4672SSudeep Holla 	OHMS = 0x31,
397607a4672SSudeep Holla 	SIEMENS = 0x32,
398607a4672SSudeep Holla 	MOLES = 0x33,
399607a4672SSudeep Holla 	BECQUERELS = 0x34,
400607a4672SSudeep Holla 	PPM = 0x35,
401607a4672SSudeep Holla 	DECIBELS = 0x36,
402607a4672SSudeep Holla 	DBA = 0x37,
403607a4672SSudeep Holla 	DBC = 0x38,
404607a4672SSudeep Holla 	GRAYS = 0x39,
405607a4672SSudeep Holla 	SIEVERTS = 0x3A,
406607a4672SSudeep Holla 	COLOR_TEMP_K = 0x3B,
407607a4672SSudeep Holla 	BITS = 0x3C,
408607a4672SSudeep Holla 	BYTES = 0x3D,
409607a4672SSudeep Holla 	WORDS = 0x3E,
410607a4672SSudeep Holla 	DWORDS = 0x3F,
411607a4672SSudeep Holla 	QWORDS = 0x40,
412607a4672SSudeep Holla 	PERCENTAGE = 0x41,
413607a4672SSudeep Holla 	PASCALS = 0x42,
414607a4672SSudeep Holla 	COUNTS = 0x43,
415607a4672SSudeep Holla 	GRAMS = 0x44,
416607a4672SSudeep Holla 	NEWTON_METERS = 0x45,
417607a4672SSudeep Holla 	HITS = 0x46,
418607a4672SSudeep Holla 	MISSES = 0x47,
419607a4672SSudeep Holla 	RETRIES = 0x48,
420607a4672SSudeep Holla 	OVERRUNS = 0x49,
421607a4672SSudeep Holla 	UNDERRUNS = 0x4A,
422607a4672SSudeep Holla 	COLLISIONS = 0x4B,
423607a4672SSudeep Holla 	PACKETS = 0x4C,
424607a4672SSudeep Holla 	MESSAGES = 0x4D,
425607a4672SSudeep Holla 	CHARS = 0x4E,
426607a4672SSudeep Holla 	ERRORS = 0x4F,
427607a4672SSudeep Holla 	CORRECTED_ERRS = 0x50,
428607a4672SSudeep Holla 	UNCORRECTABLE_ERRS = 0x51,
429607a4672SSudeep Holla 	SQ_MILS = 0x52,
430607a4672SSudeep Holla 	SQ_INCHES = 0x53,
431607a4672SSudeep Holla 	SQ_FEET = 0x54,
432607a4672SSudeep Holla 	SQ_CM = 0x55,
433607a4672SSudeep Holla 	SQ_METERS = 0x56,
4341fe00b8bSCristian Marussi 	RADIANS_SEC = 0x57,
4351fe00b8bSCristian Marussi 	BPM = 0x58,
4361fe00b8bSCristian Marussi 	METERS_SEC_SQUARED = 0x59,
4371fe00b8bSCristian Marussi 	METERS_SEC = 0x5A,
4381fe00b8bSCristian Marussi 	CUBIC_METERS_SEC = 0x5B,
4391fe00b8bSCristian Marussi 	MM_MERCURY = 0x5C,
4401fe00b8bSCristian Marussi 	RADIANS_SEC_SQUARED = 0x5D,
4411fe00b8bSCristian Marussi 	OEM_UNIT = 0xFF
4425179c523SSudeep Holla };
4435179c523SSudeep Holla 
4445179c523SSudeep Holla /**
4459694a7f6SCristian Marussi  * struct scmi_sensor_proto_ops - represents the various operations provided
4465179c523SSudeep Holla  *	by SCMI Sensor Protocol
4475179c523SSudeep Holla  *
4485179c523SSudeep Holla  * @count_get: get the count of sensors provided by SCMI
4495179c523SSudeep Holla  * @info_get: get the information of the specified sensor
4509eefa43aSSudeep Holla  * @trip_point_config: selects and configures a trip-point of interest
4515179c523SSudeep Holla  * @reading_get: gets the current value of the sensor
452e2083d36SCristian Marussi  * @reading_get_timestamped: gets the current value and timestamp, when
453e2083d36SCristian Marussi  *			     available, of the sensor. (as of v3.0 spec)
454e2083d36SCristian Marussi  *			     Supports multi-axis sensors for sensors which
455e2083d36SCristian Marussi  *			     supports it and if the @reading array size of
456e2083d36SCristian Marussi  *			     @count entry equals the sensor num_axis
4577b83c5f4SCristian Marussi  * @config_get: Get sensor current configuration
4587b83c5f4SCristian Marussi  * @config_set: Set sensor current configuration
4595179c523SSudeep Holla  */
4609694a7f6SCristian Marussi struct scmi_sensor_proto_ops {
4619694a7f6SCristian Marussi 	int (*count_get)(const struct scmi_protocol_handle *ph);
4629694a7f6SCristian Marussi 	const struct scmi_sensor_info *(*info_get)
4639694a7f6SCristian Marussi 		(const struct scmi_protocol_handle *ph, u32 sensor_id);
4649694a7f6SCristian Marussi 	int (*trip_point_config)(const struct scmi_protocol_handle *ph,
4659694a7f6SCristian Marussi 				 u32 sensor_id, u8 trip_id, u64 trip_value);
4669694a7f6SCristian Marussi 	int (*reading_get)(const struct scmi_protocol_handle *ph, u32 sensor_id,
4679694a7f6SCristian Marussi 			   u64 *value);
4689694a7f6SCristian Marussi 	int (*reading_get_timestamped)(const struct scmi_protocol_handle *ph,
4699694a7f6SCristian Marussi 				       u32 sensor_id, u8 count,
4709694a7f6SCristian Marussi 				       struct scmi_sensor_reading *readings);
4719694a7f6SCristian Marussi 	int (*config_get)(const struct scmi_protocol_handle *ph,
4729694a7f6SCristian Marussi 			  u32 sensor_id, u32 *sensor_config);
4739694a7f6SCristian Marussi 	int (*config_set)(const struct scmi_protocol_handle *ph,
4749694a7f6SCristian Marussi 			  u32 sensor_id, u32 sensor_config);
4759694a7f6SCristian Marussi };
4769694a7f6SCristian Marussi 
47776a65509SSudeep Holla /**
4787e029344SCristian Marussi  * struct scmi_reset_proto_ops - represents the various operations provided
47995a15d80SSudeep Holla  *	by SCMI Reset Protocol
48095a15d80SSudeep Holla  *
48195a15d80SSudeep Holla  * @num_domains_get: get the count of reset domains provided by SCMI
48295a15d80SSudeep Holla  * @name_get: gets the name of a reset domain
48395a15d80SSudeep Holla  * @latency_get: gets the reset latency for the specified reset domain
48495a15d80SSudeep Holla  * @reset: resets the specified reset domain
48595a15d80SSudeep Holla  * @assert: explicitly assert reset signal of the specified reset domain
48695a15d80SSudeep Holla  * @deassert: explicitly deassert reset signal of the specified reset domain
48795a15d80SSudeep Holla  */
4887e029344SCristian Marussi struct scmi_reset_proto_ops {
4897e029344SCristian Marussi 	int (*num_domains_get)(const struct scmi_protocol_handle *ph);
490992be5d3SCristian Marussi 	const char *(*name_get)(const struct scmi_protocol_handle *ph,
491992be5d3SCristian Marussi 				u32 domain);
4927e029344SCristian Marussi 	int (*latency_get)(const struct scmi_protocol_handle *ph, u32 domain);
4937e029344SCristian Marussi 	int (*reset)(const struct scmi_protocol_handle *ph, u32 domain);
4947e029344SCristian Marussi 	int (*assert)(const struct scmi_protocol_handle *ph, u32 domain);
4957e029344SCristian Marussi 	int (*deassert)(const struct scmi_protocol_handle *ph, u32 domain);
4967e029344SCristian Marussi };
4977e029344SCristian Marussi 
498*4c74701bSCristian Marussi enum scmi_voltage_level_mode {
499*4c74701bSCristian Marussi 	SCMI_VOLTAGE_LEVEL_SET_AUTO,
500*4c74701bSCristian Marussi 	SCMI_VOLTAGE_LEVEL_SET_SYNC,
501*4c74701bSCristian Marussi };
502*4c74701bSCristian Marussi 
50395a15d80SSudeep Holla /**
5042add5cacSCristian Marussi  * struct scmi_voltage_info - describe one available SCMI Voltage Domain
5052add5cacSCristian Marussi  *
5062add5cacSCristian Marussi  * @id: the domain ID as advertised by the platform
5072add5cacSCristian Marussi  * @segmented: defines the layout of the entries of array @levels_uv.
5082add5cacSCristian Marussi  *	       - when True the entries are to be interpreted as triplets,
5092add5cacSCristian Marussi  *	         each defining a segment representing a range of equally
5102add5cacSCristian Marussi  *	         space voltages: <lowest_volts>, <highest_volt>, <step_uV>
5112add5cacSCristian Marussi  *	       - when False the entries simply represent a single discrete
5122add5cacSCristian Marussi  *	         supported voltage level
5132add5cacSCristian Marussi  * @negative_volts_allowed: True if any of the entries of @levels_uv represent
5142add5cacSCristian Marussi  *			    a negative voltage.
515*4c74701bSCristian Marussi  * @async_level_set: True when the voltage domain supports asynchronous level
516*4c74701bSCristian Marussi  *		     set commands.
5172add5cacSCristian Marussi  * @name: name assigned to the Voltage Domain by platform
5182add5cacSCristian Marussi  * @num_levels: number of total entries in @levels_uv.
5192add5cacSCristian Marussi  * @levels_uv: array of entries describing the available voltage levels for
5202add5cacSCristian Marussi  *	       this domain.
5212add5cacSCristian Marussi  */
5222add5cacSCristian Marussi struct scmi_voltage_info {
5232add5cacSCristian Marussi 	unsigned int id;
5242add5cacSCristian Marussi 	bool segmented;
5252add5cacSCristian Marussi 	bool negative_volts_allowed;
526*4c74701bSCristian Marussi 	bool async_level_set;
5272add5cacSCristian Marussi 	char name[SCMI_MAX_STR_SIZE];
5282add5cacSCristian Marussi 	unsigned int num_levels;
5292add5cacSCristian Marussi #define SCMI_VOLTAGE_SEGMENT_LOW	0
5302add5cacSCristian Marussi #define SCMI_VOLTAGE_SEGMENT_HIGH	1
5312add5cacSCristian Marussi #define SCMI_VOLTAGE_SEGMENT_STEP	2
5322add5cacSCristian Marussi 	int *levels_uv;
5332add5cacSCristian Marussi };
5342add5cacSCristian Marussi 
5352add5cacSCristian Marussi /**
536fe4894d9SCristian Marussi  * struct scmi_voltage_proto_ops - represents the various operations provided
5372add5cacSCristian Marussi  * by SCMI Voltage Protocol
5382add5cacSCristian Marussi  *
5392add5cacSCristian Marussi  * @num_domains_get: get the count of voltage domains provided by SCMI
5402add5cacSCristian Marussi  * @info_get: get the information of the specified domain
5412add5cacSCristian Marussi  * @config_set: set the config for the specified domain
5422add5cacSCristian Marussi  * @config_get: get the config of the specified domain
5432add5cacSCristian Marussi  * @level_set: set the voltage level for the specified domain
5442add5cacSCristian Marussi  * @level_get: get the voltage level of the specified domain
5452add5cacSCristian Marussi  */
546fe4894d9SCristian Marussi struct scmi_voltage_proto_ops {
547fe4894d9SCristian Marussi 	int (*num_domains_get)(const struct scmi_protocol_handle *ph);
548fe4894d9SCristian Marussi 	const struct scmi_voltage_info __must_check *(*info_get)
549fe4894d9SCristian Marussi 		(const struct scmi_protocol_handle *ph, u32 domain_id);
550fe4894d9SCristian Marussi 	int (*config_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
551fe4894d9SCristian Marussi 			  u32 config);
552fe4894d9SCristian Marussi #define	SCMI_VOLTAGE_ARCH_STATE_OFF		0x0
553fe4894d9SCristian Marussi #define	SCMI_VOLTAGE_ARCH_STATE_ON		0x7
554fe4894d9SCristian Marussi 	int (*config_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
555fe4894d9SCristian Marussi 			  u32 *config);
556fe4894d9SCristian Marussi 	int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain_id,
557*4c74701bSCristian Marussi 			 enum scmi_voltage_level_mode mode, s32 volt_uV);
558fe4894d9SCristian Marussi 	int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain_id,
559fe4894d9SCristian Marussi 			 s32 *volt_uV);
560fe4894d9SCristian Marussi };
561fe4894d9SCristian Marussi 
5622add5cacSCristian Marussi /**
563e7c215f3SCristian Marussi  * struct scmi_notify_ops  - represents notifications' operations provided by
564e7c215f3SCristian Marussi  * SCMI core
5655ad3d1cfSCristian Marussi  * @devm_event_notifier_register: Managed registration of a notifier_block for
5665ad3d1cfSCristian Marussi  *				  the requested event
5675ad3d1cfSCristian Marussi  * @devm_event_notifier_unregister: Managed unregistration of a notifier_block
5685ad3d1cfSCristian Marussi  *				    for the requested event
569aa1fd3e4SCristian Marussi  * @event_notifier_register: Register a notifier_block for the requested event
570aa1fd3e4SCristian Marussi  * @event_notifier_unregister: Unregister a notifier_block for the requested
571e7c215f3SCristian Marussi  *			       event
572e7c215f3SCristian Marussi  *
573e7c215f3SCristian Marussi  * A user can register/unregister its own notifier_block against the wanted
574e7c215f3SCristian Marussi  * platform instance regarding the desired event identified by the
575e7c215f3SCristian Marussi  * tuple: (proto_id, evt_id, src_id) using the provided register/unregister
576e7c215f3SCristian Marussi  * interface where:
577e7c215f3SCristian Marussi  *
5785ad3d1cfSCristian Marussi  * @sdev: The scmi_device to use when calling the devres managed ops devm_
5795ad3d1cfSCristian Marussi  * @handle: The handle identifying the platform instance to use, when not
5805ad3d1cfSCristian Marussi  *	    calling the managed ops devm_
581e7c215f3SCristian Marussi  * @proto_id: The protocol ID as in SCMI Specification
582e7c215f3SCristian Marussi  * @evt_id: The message ID of the desired event as in SCMI Specification
583e7c215f3SCristian Marussi  * @src_id: A pointer to the desired source ID if different sources are
584e7c215f3SCristian Marussi  *	    possible for the protocol (like domain_id, sensor_id...etc)
585e7c215f3SCristian Marussi  *
586e7c215f3SCristian Marussi  * @src_id can be provided as NULL if it simply does NOT make sense for
587e7c215f3SCristian Marussi  * the protocol at hand, OR if the user is explicitly interested in
588e7c215f3SCristian Marussi  * receiving notifications from ANY existent source associated to the
589e7c215f3SCristian Marussi  * specified proto_id / evt_id.
590e7c215f3SCristian Marussi  *
591e7c215f3SCristian Marussi  * Received notifications are finally delivered to the registered users,
592e7c215f3SCristian Marussi  * invoking the callback provided with the notifier_block *nb as follows:
593e7c215f3SCristian Marussi  *
594e7c215f3SCristian Marussi  *	int user_cb(nb, evt_id, report)
595e7c215f3SCristian Marussi  *
596e7c215f3SCristian Marussi  * with:
597e7c215f3SCristian Marussi  *
598e7c215f3SCristian Marussi  * @nb: The notifier block provided by the user
599e7c215f3SCristian Marussi  * @evt_id: The message ID of the delivered event
600e7c215f3SCristian Marussi  * @report: A custom struct describing the specific event delivered
601e7c215f3SCristian Marussi  */
602e7c215f3SCristian Marussi struct scmi_notify_ops {
6035ad3d1cfSCristian Marussi 	int (*devm_event_notifier_register)(struct scmi_device *sdev,
6045ad3d1cfSCristian Marussi 					    u8 proto_id, u8 evt_id,
6055ad3d1cfSCristian Marussi 					    const u32 *src_id,
6065ad3d1cfSCristian Marussi 					    struct notifier_block *nb);
6075ad3d1cfSCristian Marussi 	int (*devm_event_notifier_unregister)(struct scmi_device *sdev,
6085ad3d1cfSCristian Marussi 					      u8 proto_id, u8 evt_id,
6095ad3d1cfSCristian Marussi 					      const u32 *src_id,
6105ad3d1cfSCristian Marussi 					      struct notifier_block *nb);
611aa1fd3e4SCristian Marussi 	int (*event_notifier_register)(const struct scmi_handle *handle,
6125ad3d1cfSCristian Marussi 				       u8 proto_id, u8 evt_id,
6135ad3d1cfSCristian Marussi 				       const u32 *src_id,
614e7c215f3SCristian Marussi 				       struct notifier_block *nb);
615aa1fd3e4SCristian Marussi 	int (*event_notifier_unregister)(const struct scmi_handle *handle,
6165ad3d1cfSCristian Marussi 					 u8 proto_id, u8 evt_id,
6175ad3d1cfSCristian Marussi 					 const u32 *src_id,
618e7c215f3SCristian Marussi 					 struct notifier_block *nb);
619e7c215f3SCristian Marussi };
620e7c215f3SCristian Marussi 
621e7c215f3SCristian Marussi /**
622aa4f886fSSudeep Holla  * struct scmi_handle - Handle returned to ARM SCMI clients for usage.
623aa4f886fSSudeep Holla  *
624aa4f886fSSudeep Holla  * @dev: pointer to the SCMI device
625b6f20ff8SSudeep Holla  * @version: pointer to the structure containing SCMI version information
62623934efeSCristian Marussi  * @devm_protocol_get: devres managed method to acquire a protocol and get specific
62723934efeSCristian Marussi  *		       operations and a dedicated protocol handler
62823934efeSCristian Marussi  * @devm_protocol_put: devres managed method to release a protocol
62969255e74SCristian Marussi  * @is_transport_atomic: method to check if the underlying transport for this
63069255e74SCristian Marussi  *			 instance handle is configured to support atomic
63169255e74SCristian Marussi  *			 transactions for commands.
63269255e74SCristian Marussi  *			 Some users of the SCMI stack in the upper layers could
63369255e74SCristian Marussi  *			 be interested to know if they can assume SCMI
63469255e74SCristian Marussi  *			 command transactions associated to this handle will
63569255e74SCristian Marussi  *			 never sleep and act accordingly.
63605976c5fSCristian Marussi  *			 An optional atomic threshold value could be returned
63705976c5fSCristian Marussi  *			 where configured.
638e7c215f3SCristian Marussi  * @notify_ops: pointer to set of notifications related operations
639aa4f886fSSudeep Holla  */
640aa4f886fSSudeep Holla struct scmi_handle {
641aa4f886fSSudeep Holla 	struct device *dev;
642b6f20ff8SSudeep Holla 	struct scmi_revision_info *version;
64323934efeSCristian Marussi 
64423934efeSCristian Marussi 	const void __must_check *
64523934efeSCristian Marussi 		(*devm_protocol_get)(struct scmi_device *sdev, u8 proto,
64623934efeSCristian Marussi 				     struct scmi_protocol_handle **ph);
64723934efeSCristian Marussi 	void (*devm_protocol_put)(struct scmi_device *sdev, u8 proto);
64805976c5fSCristian Marussi 	bool (*is_transport_atomic)(const struct scmi_handle *handle,
64905976c5fSCristian Marussi 				    unsigned int *atomic_threshold);
65023934efeSCristian Marussi 
65182894c1dSRikard Falkeborn 	const struct scmi_notify_ops *notify_ops;
652b6f20ff8SSudeep Holla };
653b6f20ff8SSudeep Holla 
654b6f20ff8SSudeep Holla enum scmi_std_protocol {
655b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_BASE = 0x10,
656b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_POWER = 0x11,
657b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_SYSTEM = 0x12,
658b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_PERF = 0x13,
659b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_CLOCK = 0x14,
660b6f20ff8SSudeep Holla 	SCMI_PROTOCOL_SENSOR = 0x15,
66195a15d80SSudeep Holla 	SCMI_PROTOCOL_RESET = 0x16,
6622add5cacSCristian Marussi 	SCMI_PROTOCOL_VOLTAGE = 0x17,
663aa4f886fSSudeep Holla };
664933c5044SSudeep Holla 
665a8803055SCristian Marussi enum scmi_system_events {
666a8803055SCristian Marussi 	SCMI_SYSTEM_SHUTDOWN,
667a8803055SCristian Marussi 	SCMI_SYSTEM_COLDRESET,
668a8803055SCristian Marussi 	SCMI_SYSTEM_WARMRESET,
669a8803055SCristian Marussi 	SCMI_SYSTEM_POWERUP,
670a8803055SCristian Marussi 	SCMI_SYSTEM_SUSPEND,
671a8803055SCristian Marussi 	SCMI_SYSTEM_MAX
672a8803055SCristian Marussi };
673a8803055SCristian Marussi 
674933c5044SSudeep Holla struct scmi_device {
675933c5044SSudeep Holla 	u32 id;
676933c5044SSudeep Holla 	u8 protocol_id;
677ee7a9c9fSSudeep Holla 	const char *name;
678933c5044SSudeep Holla 	struct device dev;
679933c5044SSudeep Holla 	struct scmi_handle *handle;
680933c5044SSudeep Holla };
681933c5044SSudeep Holla 
682933c5044SSudeep Holla #define to_scmi_dev(d) container_of(d, struct scmi_device, dev)
683933c5044SSudeep Holla 
684933c5044SSudeep Holla struct scmi_device *
685ee7a9c9fSSudeep Holla scmi_device_create(struct device_node *np, struct device *parent, int protocol,
686ee7a9c9fSSudeep Holla 		   const char *name);
687933c5044SSudeep Holla void scmi_device_destroy(struct scmi_device *scmi_dev);
688933c5044SSudeep Holla 
689933c5044SSudeep Holla struct scmi_device_id {
690933c5044SSudeep Holla 	u8 protocol_id;
691ee7a9c9fSSudeep Holla 	const char *name;
692933c5044SSudeep Holla };
693933c5044SSudeep Holla 
694933c5044SSudeep Holla struct scmi_driver {
695933c5044SSudeep Holla 	const char *name;
696933c5044SSudeep Holla 	int (*probe)(struct scmi_device *sdev);
697933c5044SSudeep Holla 	void (*remove)(struct scmi_device *sdev);
698933c5044SSudeep Holla 	const struct scmi_device_id *id_table;
699933c5044SSudeep Holla 
700933c5044SSudeep Holla 	struct device_driver driver;
701933c5044SSudeep Holla };
702933c5044SSudeep Holla 
703933c5044SSudeep Holla #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver)
704933c5044SSudeep Holla 
70566d90f6eSSudeep Holla #if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL)
706933c5044SSudeep Holla int scmi_driver_register(struct scmi_driver *driver,
707933c5044SSudeep Holla 			 struct module *owner, const char *mod_name);
708933c5044SSudeep Holla void scmi_driver_unregister(struct scmi_driver *driver);
709933c5044SSudeep Holla #else
710933c5044SSudeep Holla static inline int
711933c5044SSudeep Holla scmi_driver_register(struct scmi_driver *driver, struct module *owner,
712933c5044SSudeep Holla 		     const char *mod_name)
713933c5044SSudeep Holla {
714933c5044SSudeep Holla 	return -EINVAL;
715933c5044SSudeep Holla }
716933c5044SSudeep Holla 
717933c5044SSudeep Holla static inline void scmi_driver_unregister(struct scmi_driver *driver) {}
718933c5044SSudeep Holla #endif /* CONFIG_ARM_SCMI_PROTOCOL */
719933c5044SSudeep Holla 
720933c5044SSudeep Holla #define scmi_register(driver) \
721933c5044SSudeep Holla 	scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
722933c5044SSudeep Holla #define scmi_unregister(driver) \
723933c5044SSudeep Holla 	scmi_driver_unregister(driver)
724933c5044SSudeep Holla 
725933c5044SSudeep Holla /**
726933c5044SSudeep Holla  * module_scmi_driver() - Helper macro for registering a scmi driver
727933c5044SSudeep Holla  * @__scmi_driver: scmi_driver structure
728933c5044SSudeep Holla  *
729933c5044SSudeep Holla  * Helper macro for scmi drivers to set up proper module init / exit
730933c5044SSudeep Holla  * functions.  Replaces module_init() and module_exit() and keeps people from
731933c5044SSudeep Holla  * printing pointless things to the kernel log when their driver is loaded.
732933c5044SSudeep Holla  */
733933c5044SSudeep Holla #define module_scmi_driver(__scmi_driver)	\
734933c5044SSudeep Holla 	module_driver(__scmi_driver, scmi_register, scmi_unregister)
735933c5044SSudeep Holla 
736f5800e0bSCristian Marussi /**
737f5800e0bSCristian Marussi  * module_scmi_protocol() - Helper macro for registering a scmi protocol
738f5800e0bSCristian Marussi  * @__scmi_protocol: scmi_protocol structure
739f5800e0bSCristian Marussi  *
740f5800e0bSCristian Marussi  * Helper macro for scmi drivers to set up proper module init / exit
741f5800e0bSCristian Marussi  * functions.  Replaces module_init() and module_exit() and keeps people from
742f5800e0bSCristian Marussi  * printing pointless things to the kernel log when their driver is loaded.
743f5800e0bSCristian Marussi  */
744f5800e0bSCristian Marussi #define module_scmi_protocol(__scmi_protocol)	\
745f5800e0bSCristian Marussi 	module_driver(__scmi_protocol,		\
746f5800e0bSCristian Marussi 		      scmi_protocol_register, scmi_protocol_unregister)
747f5800e0bSCristian Marussi 
74848dc16e2SCristian Marussi struct scmi_protocol;
74948dc16e2SCristian Marussi int scmi_protocol_register(const struct scmi_protocol *proto);
75048dc16e2SCristian Marussi void scmi_protocol_unregister(const struct scmi_protocol *proto);
75170771c69SSudeep Holla 
752e27077bcSCristian Marussi /* SCMI Notification API - Custom Event Reports */
753e27077bcSCristian Marussi enum scmi_notification_events {
754e27077bcSCristian Marussi 	SCMI_EVENT_POWER_STATE_CHANGED = 0x0,
7557aa75496SCristian Marussi 	SCMI_EVENT_CLOCK_RATE_CHANGED = 0x0,
7567aa75496SCristian Marussi 	SCMI_EVENT_CLOCK_RATE_CHANGE_REQUESTED = 0x1,
757fb5086dcSCristian Marussi 	SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0,
758fb5086dcSCristian Marussi 	SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1,
759128e3e93SCristian Marussi 	SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0,
760e3811190SCristian Marussi 	SCMI_EVENT_SENSOR_UPDATE = 0x1,
761469ca182SCristian Marussi 	SCMI_EVENT_RESET_ISSUED = 0x0,
762585dfab3SCristian Marussi 	SCMI_EVENT_BASE_ERROR_EVENT = 0x0,
763a8803055SCristian Marussi 	SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0,
764e27077bcSCristian Marussi };
765e27077bcSCristian Marussi 
766e27077bcSCristian Marussi struct scmi_power_state_changed_report {
76772a5eb9dSCristian Marussi 	ktime_t		timestamp;
76872a5eb9dSCristian Marussi 	unsigned int	agent_id;
76972a5eb9dSCristian Marussi 	unsigned int	domain_id;
77072a5eb9dSCristian Marussi 	unsigned int	power_state;
771e27077bcSCristian Marussi };
772e27077bcSCristian Marussi 
7737aa75496SCristian Marussi struct scmi_clock_rate_notif_report {
7747aa75496SCristian Marussi 	ktime_t			timestamp;
7757aa75496SCristian Marussi 	unsigned int		agent_id;
7767aa75496SCristian Marussi 	unsigned int		clock_id;
7777aa75496SCristian Marussi 	unsigned long long	rate;
7787aa75496SCristian Marussi };
7797aa75496SCristian Marussi 
780a8803055SCristian Marussi struct scmi_system_power_state_notifier_report {
781a8803055SCristian Marussi 	ktime_t		timestamp;
782a8803055SCristian Marussi 	unsigned int	agent_id;
783a8803055SCristian Marussi 	unsigned int	flags;
784a8803055SCristian Marussi 	unsigned int	system_state;
785a8803055SCristian Marussi };
786a8803055SCristian Marussi 
787fb5086dcSCristian Marussi struct scmi_perf_limits_report {
78872a5eb9dSCristian Marussi 	ktime_t		timestamp;
78972a5eb9dSCristian Marussi 	unsigned int	agent_id;
79072a5eb9dSCristian Marussi 	unsigned int	domain_id;
79172a5eb9dSCristian Marussi 	unsigned int	range_max;
79272a5eb9dSCristian Marussi 	unsigned int	range_min;
793fb5086dcSCristian Marussi };
794fb5086dcSCristian Marussi 
795fb5086dcSCristian Marussi struct scmi_perf_level_report {
79672a5eb9dSCristian Marussi 	ktime_t		timestamp;
79772a5eb9dSCristian Marussi 	unsigned int	agent_id;
79872a5eb9dSCristian Marussi 	unsigned int	domain_id;
79972a5eb9dSCristian Marussi 	unsigned int	performance_level;
800fb5086dcSCristian Marussi };
801fb5086dcSCristian Marussi 
802128e3e93SCristian Marussi struct scmi_sensor_trip_point_report {
80372a5eb9dSCristian Marussi 	ktime_t		timestamp;
80472a5eb9dSCristian Marussi 	unsigned int	agent_id;
80572a5eb9dSCristian Marussi 	unsigned int	sensor_id;
80672a5eb9dSCristian Marussi 	unsigned int	trip_point_desc;
807128e3e93SCristian Marussi };
808128e3e93SCristian Marussi 
809e3811190SCristian Marussi struct scmi_sensor_update_report {
810e3811190SCristian Marussi 	ktime_t				timestamp;
811e3811190SCristian Marussi 	unsigned int			agent_id;
812e3811190SCristian Marussi 	unsigned int			sensor_id;
813e3811190SCristian Marussi 	unsigned int			readings_count;
814e3811190SCristian Marussi 	struct scmi_sensor_reading	readings[];
815e3811190SCristian Marussi };
816e3811190SCristian Marussi 
817469ca182SCristian Marussi struct scmi_reset_issued_report {
81872a5eb9dSCristian Marussi 	ktime_t		timestamp;
81972a5eb9dSCristian Marussi 	unsigned int	agent_id;
82072a5eb9dSCristian Marussi 	unsigned int	domain_id;
82172a5eb9dSCristian Marussi 	unsigned int	reset_state;
822469ca182SCristian Marussi };
823469ca182SCristian Marussi 
824585dfab3SCristian Marussi struct scmi_base_error_report {
82572a5eb9dSCristian Marussi 	ktime_t			timestamp;
82672a5eb9dSCristian Marussi 	unsigned int		agent_id;
827585dfab3SCristian Marussi 	bool			fatal;
82872a5eb9dSCristian Marussi 	unsigned int		cmd_count;
82972a5eb9dSCristian Marussi 	unsigned long long	reports[];
830585dfab3SCristian Marussi };
831585dfab3SCristian Marussi 
83270771c69SSudeep Holla #endif /* _LINUX_SCMI_PROTOCOL_H */
833