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 16b6f20ff8SSudeep Holla #define SCMI_MAX_STR_SIZE 16 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]; 455f6c6430SSudeep Holla bool rate_discrete; 465f6c6430SSudeep Holla union { 475f6c6430SSudeep Holla struct { 485f6c6430SSudeep Holla int num_rates; 495f6c6430SSudeep Holla u64 rates[SCMI_MAX_NUM_RATES]; 505f6c6430SSudeep Holla } list; 515f6c6430SSudeep Holla struct { 525f6c6430SSudeep Holla u64 min_rate; 535f6c6430SSudeep Holla u64 max_rate; 545f6c6430SSudeep Holla u64 step_size; 555f6c6430SSudeep Holla } range; 565f6c6430SSudeep Holla }; 575f6c6430SSudeep Holla }; 585f6c6430SSudeep Holla 59a9e3fbfaSSudeep Holla struct scmi_handle; 6023934efeSCristian Marussi struct scmi_device; 6123934efeSCristian Marussi struct scmi_protocol_handle; 62a9e3fbfaSSudeep Holla 63a9e3fbfaSSudeep Holla /** 645f6c6430SSudeep Holla * struct scmi_clk_ops - represents the various operations provided 655f6c6430SSudeep Holla * by SCMI Clock Protocol 665f6c6430SSudeep Holla * 675f6c6430SSudeep Holla * @count_get: get the count of clocks provided by SCMI 685f6c6430SSudeep Holla * @info_get: get the information of the specified clock 695f6c6430SSudeep Holla * @rate_get: request the current clock rate of a clock 705f6c6430SSudeep Holla * @rate_set: set the clock rate of a clock 715f6c6430SSudeep Holla * @enable: enables the specified clock 725f6c6430SSudeep Holla * @disable: disables the specified clock 735f6c6430SSudeep Holla */ 745f6c6430SSudeep Holla struct scmi_clk_ops { 755f6c6430SSudeep Holla int (*count_get)(const struct scmi_handle *handle); 765f6c6430SSudeep Holla 775f6c6430SSudeep Holla const struct scmi_clock_info *(*info_get) 785f6c6430SSudeep Holla (const struct scmi_handle *handle, u32 clk_id); 795f6c6430SSudeep Holla int (*rate_get)(const struct scmi_handle *handle, u32 clk_id, 805f6c6430SSudeep Holla u64 *rate); 815f6c6430SSudeep Holla int (*rate_set)(const struct scmi_handle *handle, u32 clk_id, 82d0aba116SSudeep Holla u64 rate); 835f6c6430SSudeep Holla int (*enable)(const struct scmi_handle *handle, u32 clk_id); 845f6c6430SSudeep Holla int (*disable)(const struct scmi_handle *handle, u32 clk_id); 855f6c6430SSudeep Holla }; 865f6c6430SSudeep Holla 875f6c6430SSudeep Holla /** 88*1fec5e6bSCristian Marussi * struct scmi_perf_proto_ops - represents the various operations provided 89a9e3fbfaSSudeep Holla * by SCMI Performance Protocol 90a9e3fbfaSSudeep Holla * 91a9e3fbfaSSudeep Holla * @limits_set: sets limits on the performance level of a domain 92a9e3fbfaSSudeep Holla * @limits_get: gets limits on the performance level of a domain 93a9e3fbfaSSudeep Holla * @level_set: sets the performance level of a domain 94a9e3fbfaSSudeep Holla * @level_get: gets the performance level of a domain 95a9e3fbfaSSudeep Holla * @device_domain_id: gets the scmi domain id for a given device 967859e08cSSudeep Holla * @transition_latency_get: gets the DVFS transition latency for a given device 977859e08cSSudeep Holla * @device_opps_add: adds all the OPPs for a given device 98a9e3fbfaSSudeep Holla * @freq_set: sets the frequency for a given device using sustained frequency 99a9e3fbfaSSudeep Holla * to sustained performance level mapping 100a9e3fbfaSSudeep Holla * @freq_get: gets the frequency for a given device using sustained frequency 101a9e3fbfaSSudeep Holla * to sustained performance level mapping 1021a63fe9aSQuentin Perret * @est_power_get: gets the estimated power cost for a given performance domain 1031a63fe9aSQuentin Perret * at a given frequency 104a9e3fbfaSSudeep Holla */ 105*1fec5e6bSCristian Marussi struct scmi_perf_proto_ops { 106*1fec5e6bSCristian Marussi int (*limits_set)(const struct scmi_protocol_handle *ph, u32 domain, 107*1fec5e6bSCristian Marussi u32 max_perf, u32 min_perf); 108*1fec5e6bSCristian Marussi int (*limits_get)(const struct scmi_protocol_handle *ph, u32 domain, 109*1fec5e6bSCristian Marussi u32 *max_perf, u32 *min_perf); 110*1fec5e6bSCristian Marussi int (*level_set)(const struct scmi_protocol_handle *ph, u32 domain, 111*1fec5e6bSCristian Marussi u32 level, bool poll); 112*1fec5e6bSCristian Marussi int (*level_get)(const struct scmi_protocol_handle *ph, u32 domain, 113*1fec5e6bSCristian Marussi u32 *level, bool poll); 114*1fec5e6bSCristian Marussi int (*device_domain_id)(struct device *dev); 115*1fec5e6bSCristian Marussi int (*transition_latency_get)(const struct scmi_protocol_handle *ph, 116*1fec5e6bSCristian Marussi struct device *dev); 117*1fec5e6bSCristian Marussi int (*device_opps_add)(const struct scmi_protocol_handle *ph, 118*1fec5e6bSCristian Marussi struct device *dev); 119*1fec5e6bSCristian Marussi int (*freq_set)(const struct scmi_protocol_handle *ph, u32 domain, 120*1fec5e6bSCristian Marussi unsigned long rate, bool poll); 121*1fec5e6bSCristian Marussi int (*freq_get)(const struct scmi_protocol_handle *ph, u32 domain, 122*1fec5e6bSCristian Marussi unsigned long *rate, bool poll); 123*1fec5e6bSCristian Marussi int (*est_power_get)(const struct scmi_protocol_handle *ph, u32 domain, 124*1fec5e6bSCristian Marussi unsigned long *rate, unsigned long *power); 125*1fec5e6bSCristian Marussi bool (*fast_switch_possible)(const struct scmi_protocol_handle *ph, 126*1fec5e6bSCristian Marussi struct device *dev); 127*1fec5e6bSCristian Marussi bool (*power_scale_mw_get)(const struct scmi_protocol_handle *ph); 128*1fec5e6bSCristian Marussi }; 129*1fec5e6bSCristian Marussi 130a9e3fbfaSSudeep Holla struct scmi_perf_ops { 131a9e3fbfaSSudeep Holla int (*limits_set)(const struct scmi_handle *handle, u32 domain, 132a9e3fbfaSSudeep Holla u32 max_perf, u32 min_perf); 133a9e3fbfaSSudeep Holla int (*limits_get)(const struct scmi_handle *handle, u32 domain, 134a9e3fbfaSSudeep Holla u32 *max_perf, u32 *min_perf); 135a9e3fbfaSSudeep Holla int (*level_set)(const struct scmi_handle *handle, u32 domain, 1365c4ba3ccSSudeep Holla u32 level, bool poll); 137a9e3fbfaSSudeep Holla int (*level_get)(const struct scmi_handle *handle, u32 domain, 1385c4ba3ccSSudeep Holla u32 *level, bool poll); 139a9e3fbfaSSudeep Holla int (*device_domain_id)(struct device *dev); 1407859e08cSSudeep Holla int (*transition_latency_get)(const struct scmi_handle *handle, 141a9e3fbfaSSudeep Holla struct device *dev); 1427859e08cSSudeep Holla int (*device_opps_add)(const struct scmi_handle *handle, 143a9e3fbfaSSudeep Holla struct device *dev); 144a9e3fbfaSSudeep Holla int (*freq_set)(const struct scmi_handle *handle, u32 domain, 1455c4ba3ccSSudeep Holla unsigned long rate, bool poll); 146a9e3fbfaSSudeep Holla int (*freq_get)(const struct scmi_handle *handle, u32 domain, 1475c4ba3ccSSudeep Holla unsigned long *rate, bool poll); 1481a63fe9aSQuentin Perret int (*est_power_get)(const struct scmi_handle *handle, u32 domain, 1491a63fe9aSQuentin Perret unsigned long *rate, unsigned long *power); 1501909872fSNicola Mazzucato bool (*fast_switch_possible)(const struct scmi_handle *handle, 1511909872fSNicola Mazzucato struct device *dev); 15276ea4d8eSLukasz Luba bool (*power_scale_mw_get)(const struct scmi_handle *handle); 153a9e3fbfaSSudeep Holla }; 154a9e3fbfaSSudeep Holla 155aa4f886fSSudeep Holla /** 15676a65509SSudeep Holla * struct scmi_power_ops - represents the various operations provided 15776a65509SSudeep Holla * by SCMI Power Protocol 15876a65509SSudeep Holla * 15976a65509SSudeep Holla * @num_domains_get: get the count of power domains provided by SCMI 16076a65509SSudeep Holla * @name_get: gets the name of a power domain 16176a65509SSudeep Holla * @state_set: sets the power state of a power domain 16276a65509SSudeep Holla * @state_get: gets the power state of a power domain 16376a65509SSudeep Holla */ 16476a65509SSudeep Holla struct scmi_power_ops { 16576a65509SSudeep Holla int (*num_domains_get)(const struct scmi_handle *handle); 16676a65509SSudeep Holla char *(*name_get)(const struct scmi_handle *handle, u32 domain); 16776a65509SSudeep Holla #define SCMI_POWER_STATE_TYPE_SHIFT 30 16876a65509SSudeep Holla #define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1) 16976a65509SSudeep Holla #define SCMI_POWER_STATE_PARAM(type, id) \ 17076a65509SSudeep Holla ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \ 17176a65509SSudeep Holla ((id) & SCMI_POWER_STATE_ID_MASK)) 17276a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0) 17376a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0) 17476a65509SSudeep Holla int (*state_set)(const struct scmi_handle *handle, u32 domain, 17576a65509SSudeep Holla u32 state); 17676a65509SSudeep Holla int (*state_get)(const struct scmi_handle *handle, u32 domain, 17776a65509SSudeep Holla u32 *state); 17876a65509SSudeep Holla }; 17976a65509SSudeep Holla 1801fe00b8bSCristian Marussi /** 181e2083d36SCristian Marussi * scmi_sensor_reading - represent a timestamped read 182e2083d36SCristian Marussi * 183e2083d36SCristian Marussi * Used by @reading_get_timestamped method. 184e2083d36SCristian Marussi * 185e2083d36SCristian Marussi * @value: The signed value sensor read. 186e2083d36SCristian Marussi * @timestamp: An unsigned timestamp for the sensor read, as provided by 187e2083d36SCristian Marussi * SCMI platform. Set to zero when not available. 188e2083d36SCristian Marussi */ 189e2083d36SCristian Marussi struct scmi_sensor_reading { 190e2083d36SCristian Marussi long long value; 191e2083d36SCristian Marussi unsigned long long timestamp; 192e2083d36SCristian Marussi }; 193e2083d36SCristian Marussi 194e2083d36SCristian Marussi /** 1951fe00b8bSCristian Marussi * scmi_range_attrs - specifies a sensor or axis values' range 1961fe00b8bSCristian Marussi * @min_range: The minimum value which can be represented by the sensor/axis. 1971fe00b8bSCristian Marussi * @max_range: The maximum value which can be represented by the sensor/axis. 1981fe00b8bSCristian Marussi */ 1991fe00b8bSCristian Marussi struct scmi_range_attrs { 2001fe00b8bSCristian Marussi long long min_range; 2011fe00b8bSCristian Marussi long long max_range; 2021fe00b8bSCristian Marussi }; 2031fe00b8bSCristian Marussi 2041fe00b8bSCristian Marussi /** 2051fe00b8bSCristian Marussi * scmi_sensor_axis_info - describes one sensor axes 2061fe00b8bSCristian Marussi * @id: The axes ID. 2071fe00b8bSCristian Marussi * @type: Axes type. Chosen amongst one of @enum scmi_sensor_class. 2081fe00b8bSCristian Marussi * @scale: Power-of-10 multiplier applied to the axis unit. 2091fe00b8bSCristian Marussi * @name: NULL-terminated string representing axes name as advertised by 2101fe00b8bSCristian Marussi * SCMI platform. 2111fe00b8bSCristian Marussi * @extended_attrs: Flag to indicate the presence of additional extended 2121fe00b8bSCristian Marussi * attributes for this axes. 2131fe00b8bSCristian Marussi * @resolution: Extended attribute representing the resolution of the axes. 2141fe00b8bSCristian Marussi * Set to 0 if not reported by this axes. 2151fe00b8bSCristian Marussi * @exponent: Extended attribute representing the power-of-10 multiplier that 2161fe00b8bSCristian Marussi * is applied to the resolution field. Set to 0 if not reported by 2171fe00b8bSCristian Marussi * this axes. 2181fe00b8bSCristian Marussi * @attrs: Extended attributes representing minimum and maximum values 2191fe00b8bSCristian Marussi * measurable by this axes. Set to 0 if not reported by this sensor. 2201fe00b8bSCristian Marussi */ 2211fe00b8bSCristian Marussi struct scmi_sensor_axis_info { 2221fe00b8bSCristian Marussi unsigned int id; 2231fe00b8bSCristian Marussi unsigned int type; 2241fe00b8bSCristian Marussi int scale; 2255179c523SSudeep Holla char name[SCMI_MAX_STR_SIZE]; 2261fe00b8bSCristian Marussi bool extended_attrs; 2271fe00b8bSCristian Marussi unsigned int resolution; 2281fe00b8bSCristian Marussi int exponent; 2291fe00b8bSCristian Marussi struct scmi_range_attrs attrs; 2301fe00b8bSCristian Marussi }; 2311fe00b8bSCristian Marussi 2321fe00b8bSCristian Marussi /** 2331fe00b8bSCristian Marussi * scmi_sensor_intervals_info - describes number and type of available update 2341fe00b8bSCristian Marussi * intervals 2351fe00b8bSCristian Marussi * @segmented: Flag for segmented intervals' representation. When True there 2361fe00b8bSCristian Marussi * will be exactly 3 intervals in @desc, with each entry 2371fe00b8bSCristian Marussi * representing a member of a segment in this order: 2381fe00b8bSCristian Marussi * {lowest update interval, highest update interval, step size} 2391fe00b8bSCristian Marussi * @count: Number of intervals described in @desc. 2401fe00b8bSCristian Marussi * @desc: Array of @count interval descriptor bitmask represented as detailed in 2411fe00b8bSCristian Marussi * the SCMI specification: it can be accessed using the accompanying 2421fe00b8bSCristian Marussi * macros. 2431fe00b8bSCristian Marussi * @prealloc_pool: A minimal preallocated pool of desc entries used to avoid 2441fe00b8bSCristian Marussi * lesser-than-64-bytes dynamic allocation for small @count 2451fe00b8bSCristian Marussi * values. 2461fe00b8bSCristian Marussi */ 2471fe00b8bSCristian Marussi struct scmi_sensor_intervals_info { 2481fe00b8bSCristian Marussi bool segmented; 2491fe00b8bSCristian Marussi unsigned int count; 2501fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_SEGMENT_LOW 0 2511fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_SEGMENT_HIGH 1 2521fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_SEGMENT_STEP 2 2531fe00b8bSCristian Marussi unsigned int *desc; 2541fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_GET_SECS(x) FIELD_GET(GENMASK(20, 5), (x)) 2551fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_GET_EXP(x) \ 2561fe00b8bSCristian Marussi ({ \ 2571fe00b8bSCristian Marussi int __signed_exp = FIELD_GET(GENMASK(4, 0), (x)); \ 2581fe00b8bSCristian Marussi \ 2591fe00b8bSCristian Marussi if (__signed_exp & BIT(4)) \ 2601fe00b8bSCristian Marussi __signed_exp |= GENMASK(31, 5); \ 2611fe00b8bSCristian Marussi __signed_exp; \ 2621fe00b8bSCristian Marussi }) 2631fe00b8bSCristian Marussi #define SCMI_MAX_PREALLOC_POOL 16 2641fe00b8bSCristian Marussi unsigned int prealloc_pool[SCMI_MAX_PREALLOC_POOL]; 2651fe00b8bSCristian Marussi }; 2661fe00b8bSCristian Marussi 2671fe00b8bSCristian Marussi /** 2681fe00b8bSCristian Marussi * struct scmi_sensor_info - represents information related to one of the 2691fe00b8bSCristian Marussi * available sensors. 2701fe00b8bSCristian Marussi * @id: Sensor ID. 2711fe00b8bSCristian Marussi * @type: Sensor type. Chosen amongst one of @enum scmi_sensor_class. 2721fe00b8bSCristian Marussi * @scale: Power-of-10 multiplier applied to the sensor unit. 2731fe00b8bSCristian Marussi * @num_trip_points: Number of maximum configurable trip points. 2741fe00b8bSCristian Marussi * @async: Flag for asynchronous read support. 2751fe00b8bSCristian Marussi * @update: Flag for continuouos update notification support. 2761fe00b8bSCristian Marussi * @timestamped: Flag for timestamped read support. 2771fe00b8bSCristian Marussi * @tstamp_scale: Power-of-10 multiplier applied to the sensor timestamps to 2781fe00b8bSCristian Marussi * represent it in seconds. 2791fe00b8bSCristian Marussi * @num_axis: Number of supported axis if any. Reported as 0 for scalar sensors. 2801fe00b8bSCristian Marussi * @axis: Pointer to an array of @num_axis descriptors. 2811fe00b8bSCristian Marussi * @intervals: Descriptor of available update intervals. 2821fe00b8bSCristian Marussi * @sensor_config: A bitmask reporting the current sensor configuration as 2831fe00b8bSCristian Marussi * detailed in the SCMI specification: it can accessed and 2841fe00b8bSCristian Marussi * modified through the accompanying macros. 2851fe00b8bSCristian Marussi * @name: NULL-terminated string representing sensor name as advertised by 2861fe00b8bSCristian Marussi * SCMI platform. 2871fe00b8bSCristian Marussi * @extended_scalar_attrs: Flag to indicate the presence of additional extended 2881fe00b8bSCristian Marussi * attributes for this sensor. 2891fe00b8bSCristian Marussi * @sensor_power: Extended attribute representing the average power 2901fe00b8bSCristian Marussi * consumed by the sensor in microwatts (uW) when it is active. 2911fe00b8bSCristian Marussi * Reported here only for scalar sensors. 2921fe00b8bSCristian Marussi * Set to 0 if not reported by this sensor. 2931fe00b8bSCristian Marussi * @resolution: Extended attribute representing the resolution of the sensor. 2941fe00b8bSCristian Marussi * Reported here only for scalar sensors. 2951fe00b8bSCristian Marussi * Set to 0 if not reported by this sensor. 2961fe00b8bSCristian Marussi * @exponent: Extended attribute representing the power-of-10 multiplier that is 2971fe00b8bSCristian Marussi * applied to the resolution field. 2981fe00b8bSCristian Marussi * Reported here only for scalar sensors. 2991fe00b8bSCristian Marussi * Set to 0 if not reported by this sensor. 3001fe00b8bSCristian Marussi * @scalar_attrs: Extended attributes representing minimum and maximum 3011fe00b8bSCristian Marussi * measurable values by this sensor. 3021fe00b8bSCristian Marussi * Reported here only for scalar sensors. 3031fe00b8bSCristian Marussi * Set to 0 if not reported by this sensor. 3041fe00b8bSCristian Marussi */ 3051fe00b8bSCristian Marussi struct scmi_sensor_info { 3061fe00b8bSCristian Marussi unsigned int id; 3071fe00b8bSCristian Marussi unsigned int type; 3081fe00b8bSCristian Marussi int scale; 3091fe00b8bSCristian Marussi unsigned int num_trip_points; 3101fe00b8bSCristian Marussi bool async; 3111fe00b8bSCristian Marussi bool update; 3121fe00b8bSCristian Marussi bool timestamped; 3131fe00b8bSCristian Marussi int tstamp_scale; 3141fe00b8bSCristian Marussi unsigned int num_axis; 3151fe00b8bSCristian Marussi struct scmi_sensor_axis_info *axis; 3161fe00b8bSCristian Marussi struct scmi_sensor_intervals_info intervals; 3177b83c5f4SCristian Marussi unsigned int sensor_config; 3187b83c5f4SCristian Marussi #define SCMI_SENS_CFG_UPDATE_SECS_MASK GENMASK(31, 16) 3197b83c5f4SCristian Marussi #define SCMI_SENS_CFG_GET_UPDATE_SECS(x) \ 3207b83c5f4SCristian Marussi FIELD_GET(SCMI_SENS_CFG_UPDATE_SECS_MASK, (x)) 3217b83c5f4SCristian Marussi 3227b83c5f4SCristian Marussi #define SCMI_SENS_CFG_UPDATE_EXP_MASK GENMASK(15, 11) 3237b83c5f4SCristian Marussi #define SCMI_SENS_CFG_GET_UPDATE_EXP(x) \ 3247b83c5f4SCristian Marussi ({ \ 3257b83c5f4SCristian Marussi int __signed_exp = \ 3267b83c5f4SCristian Marussi FIELD_GET(SCMI_SENS_CFG_UPDATE_EXP_MASK, (x)); \ 3277b83c5f4SCristian Marussi \ 3287b83c5f4SCristian Marussi if (__signed_exp & BIT(4)) \ 3297b83c5f4SCristian Marussi __signed_exp |= GENMASK(31, 5); \ 3307b83c5f4SCristian Marussi __signed_exp; \ 3317b83c5f4SCristian Marussi }) 3327b83c5f4SCristian Marussi 3337b83c5f4SCristian Marussi #define SCMI_SENS_CFG_ROUND_MASK GENMASK(10, 9) 3347b83c5f4SCristian Marussi #define SCMI_SENS_CFG_ROUND_AUTO 2 3357b83c5f4SCristian Marussi #define SCMI_SENS_CFG_ROUND_UP 1 3367b83c5f4SCristian Marussi #define SCMI_SENS_CFG_ROUND_DOWN 0 3377b83c5f4SCristian Marussi 3387b83c5f4SCristian Marussi #define SCMI_SENS_CFG_TSTAMP_ENABLED_MASK BIT(1) 3397b83c5f4SCristian Marussi #define SCMI_SENS_CFG_TSTAMP_ENABLE 1 3407b83c5f4SCristian Marussi #define SCMI_SENS_CFG_TSTAMP_DISABLE 0 3417b83c5f4SCristian Marussi #define SCMI_SENS_CFG_IS_TSTAMP_ENABLED(x) \ 3427b83c5f4SCristian Marussi FIELD_GET(SCMI_SENS_CFG_TSTAMP_ENABLED_MASK, (x)) 3437b83c5f4SCristian Marussi 3447b83c5f4SCristian Marussi #define SCMI_SENS_CFG_SENSOR_ENABLED_MASK BIT(0) 3457b83c5f4SCristian Marussi #define SCMI_SENS_CFG_SENSOR_ENABLE 1 3467b83c5f4SCristian Marussi #define SCMI_SENS_CFG_SENSOR_DISABLE 0 3471fe00b8bSCristian Marussi char name[SCMI_MAX_STR_SIZE]; 3487b83c5f4SCristian Marussi #define SCMI_SENS_CFG_IS_ENABLED(x) FIELD_GET(BIT(0), (x)) 3491fe00b8bSCristian Marussi bool extended_scalar_attrs; 3501fe00b8bSCristian Marussi unsigned int sensor_power; 3511fe00b8bSCristian Marussi unsigned int resolution; 3521fe00b8bSCristian Marussi int exponent; 3531fe00b8bSCristian Marussi struct scmi_range_attrs scalar_attrs; 3545179c523SSudeep Holla }; 3555179c523SSudeep Holla 3565179c523SSudeep Holla /* 3575179c523SSudeep Holla * Partial list from Distributed Management Task Force (DMTF) specification: 3585179c523SSudeep Holla * DSP0249 (Platform Level Data Model specification) 3595179c523SSudeep Holla */ 3605179c523SSudeep Holla enum scmi_sensor_class { 3615179c523SSudeep Holla NONE = 0x0, 362607a4672SSudeep Holla UNSPEC = 0x1, 3635179c523SSudeep Holla TEMPERATURE_C = 0x2, 364607a4672SSudeep Holla TEMPERATURE_F = 0x3, 365607a4672SSudeep Holla TEMPERATURE_K = 0x4, 3665179c523SSudeep Holla VOLTAGE = 0x5, 3675179c523SSudeep Holla CURRENT = 0x6, 3685179c523SSudeep Holla POWER = 0x7, 3695179c523SSudeep Holla ENERGY = 0x8, 370607a4672SSudeep Holla CHARGE = 0x9, 371607a4672SSudeep Holla VOLTAMPERE = 0xA, 372607a4672SSudeep Holla NITS = 0xB, 373607a4672SSudeep Holla LUMENS = 0xC, 374607a4672SSudeep Holla LUX = 0xD, 375607a4672SSudeep Holla CANDELAS = 0xE, 376607a4672SSudeep Holla KPA = 0xF, 377607a4672SSudeep Holla PSI = 0x10, 378607a4672SSudeep Holla NEWTON = 0x11, 379607a4672SSudeep Holla CFM = 0x12, 380607a4672SSudeep Holla RPM = 0x13, 381607a4672SSudeep Holla HERTZ = 0x14, 382607a4672SSudeep Holla SECS = 0x15, 383607a4672SSudeep Holla MINS = 0x16, 384607a4672SSudeep Holla HOURS = 0x17, 385607a4672SSudeep Holla DAYS = 0x18, 386607a4672SSudeep Holla WEEKS = 0x19, 387607a4672SSudeep Holla MILS = 0x1A, 388607a4672SSudeep Holla INCHES = 0x1B, 389607a4672SSudeep Holla FEET = 0x1C, 390607a4672SSudeep Holla CUBIC_INCHES = 0x1D, 391607a4672SSudeep Holla CUBIC_FEET = 0x1E, 392607a4672SSudeep Holla METERS = 0x1F, 393607a4672SSudeep Holla CUBIC_CM = 0x20, 394607a4672SSudeep Holla CUBIC_METERS = 0x21, 395607a4672SSudeep Holla LITERS = 0x22, 396607a4672SSudeep Holla FLUID_OUNCES = 0x23, 397607a4672SSudeep Holla RADIANS = 0x24, 398607a4672SSudeep Holla STERADIANS = 0x25, 399607a4672SSudeep Holla REVOLUTIONS = 0x26, 400607a4672SSudeep Holla CYCLES = 0x27, 401607a4672SSudeep Holla GRAVITIES = 0x28, 402607a4672SSudeep Holla OUNCES = 0x29, 403607a4672SSudeep Holla POUNDS = 0x2A, 404607a4672SSudeep Holla FOOT_POUNDS = 0x2B, 405607a4672SSudeep Holla OUNCE_INCHES = 0x2C, 406607a4672SSudeep Holla GAUSS = 0x2D, 407607a4672SSudeep Holla GILBERTS = 0x2E, 408607a4672SSudeep Holla HENRIES = 0x2F, 409607a4672SSudeep Holla FARADS = 0x30, 410607a4672SSudeep Holla OHMS = 0x31, 411607a4672SSudeep Holla SIEMENS = 0x32, 412607a4672SSudeep Holla MOLES = 0x33, 413607a4672SSudeep Holla BECQUERELS = 0x34, 414607a4672SSudeep Holla PPM = 0x35, 415607a4672SSudeep Holla DECIBELS = 0x36, 416607a4672SSudeep Holla DBA = 0x37, 417607a4672SSudeep Holla DBC = 0x38, 418607a4672SSudeep Holla GRAYS = 0x39, 419607a4672SSudeep Holla SIEVERTS = 0x3A, 420607a4672SSudeep Holla COLOR_TEMP_K = 0x3B, 421607a4672SSudeep Holla BITS = 0x3C, 422607a4672SSudeep Holla BYTES = 0x3D, 423607a4672SSudeep Holla WORDS = 0x3E, 424607a4672SSudeep Holla DWORDS = 0x3F, 425607a4672SSudeep Holla QWORDS = 0x40, 426607a4672SSudeep Holla PERCENTAGE = 0x41, 427607a4672SSudeep Holla PASCALS = 0x42, 428607a4672SSudeep Holla COUNTS = 0x43, 429607a4672SSudeep Holla GRAMS = 0x44, 430607a4672SSudeep Holla NEWTON_METERS = 0x45, 431607a4672SSudeep Holla HITS = 0x46, 432607a4672SSudeep Holla MISSES = 0x47, 433607a4672SSudeep Holla RETRIES = 0x48, 434607a4672SSudeep Holla OVERRUNS = 0x49, 435607a4672SSudeep Holla UNDERRUNS = 0x4A, 436607a4672SSudeep Holla COLLISIONS = 0x4B, 437607a4672SSudeep Holla PACKETS = 0x4C, 438607a4672SSudeep Holla MESSAGES = 0x4D, 439607a4672SSudeep Holla CHARS = 0x4E, 440607a4672SSudeep Holla ERRORS = 0x4F, 441607a4672SSudeep Holla CORRECTED_ERRS = 0x50, 442607a4672SSudeep Holla UNCORRECTABLE_ERRS = 0x51, 443607a4672SSudeep Holla SQ_MILS = 0x52, 444607a4672SSudeep Holla SQ_INCHES = 0x53, 445607a4672SSudeep Holla SQ_FEET = 0x54, 446607a4672SSudeep Holla SQ_CM = 0x55, 447607a4672SSudeep Holla SQ_METERS = 0x56, 4481fe00b8bSCristian Marussi RADIANS_SEC = 0x57, 4491fe00b8bSCristian Marussi BPM = 0x58, 4501fe00b8bSCristian Marussi METERS_SEC_SQUARED = 0x59, 4511fe00b8bSCristian Marussi METERS_SEC = 0x5A, 4521fe00b8bSCristian Marussi CUBIC_METERS_SEC = 0x5B, 4531fe00b8bSCristian Marussi MM_MERCURY = 0x5C, 4541fe00b8bSCristian Marussi RADIANS_SEC_SQUARED = 0x5D, 4551fe00b8bSCristian Marussi OEM_UNIT = 0xFF 4565179c523SSudeep Holla }; 4575179c523SSudeep Holla 4585179c523SSudeep Holla /** 4595179c523SSudeep Holla * struct scmi_sensor_ops - represents the various operations provided 4605179c523SSudeep Holla * by SCMI Sensor Protocol 4615179c523SSudeep Holla * 4625179c523SSudeep Holla * @count_get: get the count of sensors provided by SCMI 4635179c523SSudeep Holla * @info_get: get the information of the specified sensor 4649eefa43aSSudeep Holla * @trip_point_config: selects and configures a trip-point of interest 4655179c523SSudeep Holla * @reading_get: gets the current value of the sensor 466e2083d36SCristian Marussi * @reading_get_timestamped: gets the current value and timestamp, when 467e2083d36SCristian Marussi * available, of the sensor. (as of v3.0 spec) 468e2083d36SCristian Marussi * Supports multi-axis sensors for sensors which 469e2083d36SCristian Marussi * supports it and if the @reading array size of 470e2083d36SCristian Marussi * @count entry equals the sensor num_axis 4717b83c5f4SCristian Marussi * @config_get: Get sensor current configuration 4727b83c5f4SCristian Marussi * @config_set: Set sensor current configuration 4735179c523SSudeep Holla */ 4745179c523SSudeep Holla struct scmi_sensor_ops { 4755179c523SSudeep Holla int (*count_get)(const struct scmi_handle *handle); 4765179c523SSudeep Holla const struct scmi_sensor_info *(*info_get) 4775179c523SSudeep Holla (const struct scmi_handle *handle, u32 sensor_id); 4789eefa43aSSudeep Holla int (*trip_point_config)(const struct scmi_handle *handle, 4799eefa43aSSudeep Holla u32 sensor_id, u8 trip_id, u64 trip_value); 4805179c523SSudeep Holla int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id, 4816a55331cSSudeep Holla u64 *value); 482e2083d36SCristian Marussi int (*reading_get_timestamped)(const struct scmi_handle *handle, 483e2083d36SCristian Marussi u32 sensor_id, u8 count, 484e2083d36SCristian Marussi struct scmi_sensor_reading *readings); 4857b83c5f4SCristian Marussi int (*config_get)(const struct scmi_handle *handle, 4867b83c5f4SCristian Marussi u32 sensor_id, u32 *sensor_config); 4877b83c5f4SCristian Marussi int (*config_set)(const struct scmi_handle *handle, 4887b83c5f4SCristian Marussi u32 sensor_id, u32 sensor_config); 4895179c523SSudeep Holla }; 4905179c523SSudeep Holla 49176a65509SSudeep Holla /** 49295a15d80SSudeep Holla * struct scmi_reset_ops - represents the various operations provided 49395a15d80SSudeep Holla * by SCMI Reset Protocol 49495a15d80SSudeep Holla * 49595a15d80SSudeep Holla * @num_domains_get: get the count of reset domains provided by SCMI 49695a15d80SSudeep Holla * @name_get: gets the name of a reset domain 49795a15d80SSudeep Holla * @latency_get: gets the reset latency for the specified reset domain 49895a15d80SSudeep Holla * @reset: resets the specified reset domain 49995a15d80SSudeep Holla * @assert: explicitly assert reset signal of the specified reset domain 50095a15d80SSudeep Holla * @deassert: explicitly deassert reset signal of the specified reset domain 50195a15d80SSudeep Holla */ 50295a15d80SSudeep Holla struct scmi_reset_ops { 50395a15d80SSudeep Holla int (*num_domains_get)(const struct scmi_handle *handle); 50495a15d80SSudeep Holla char *(*name_get)(const struct scmi_handle *handle, u32 domain); 50595a15d80SSudeep Holla int (*latency_get)(const struct scmi_handle *handle, u32 domain); 50695a15d80SSudeep Holla int (*reset)(const struct scmi_handle *handle, u32 domain); 50795a15d80SSudeep Holla int (*assert)(const struct scmi_handle *handle, u32 domain); 50895a15d80SSudeep Holla int (*deassert)(const struct scmi_handle *handle, u32 domain); 50995a15d80SSudeep Holla }; 51095a15d80SSudeep Holla 51195a15d80SSudeep Holla /** 5122add5cacSCristian Marussi * struct scmi_voltage_info - describe one available SCMI Voltage Domain 5132add5cacSCristian Marussi * 5142add5cacSCristian Marussi * @id: the domain ID as advertised by the platform 5152add5cacSCristian Marussi * @segmented: defines the layout of the entries of array @levels_uv. 5162add5cacSCristian Marussi * - when True the entries are to be interpreted as triplets, 5172add5cacSCristian Marussi * each defining a segment representing a range of equally 5182add5cacSCristian Marussi * space voltages: <lowest_volts>, <highest_volt>, <step_uV> 5192add5cacSCristian Marussi * - when False the entries simply represent a single discrete 5202add5cacSCristian Marussi * supported voltage level 5212add5cacSCristian Marussi * @negative_volts_allowed: True if any of the entries of @levels_uv represent 5222add5cacSCristian Marussi * a negative voltage. 5232add5cacSCristian Marussi * @attributes: represents Voltage Domain advertised attributes 5242add5cacSCristian Marussi * @name: name assigned to the Voltage Domain by platform 5252add5cacSCristian Marussi * @num_levels: number of total entries in @levels_uv. 5262add5cacSCristian Marussi * @levels_uv: array of entries describing the available voltage levels for 5272add5cacSCristian Marussi * this domain. 5282add5cacSCristian Marussi */ 5292add5cacSCristian Marussi struct scmi_voltage_info { 5302add5cacSCristian Marussi unsigned int id; 5312add5cacSCristian Marussi bool segmented; 5322add5cacSCristian Marussi bool negative_volts_allowed; 5332add5cacSCristian Marussi unsigned int attributes; 5342add5cacSCristian Marussi char name[SCMI_MAX_STR_SIZE]; 5352add5cacSCristian Marussi unsigned int num_levels; 5362add5cacSCristian Marussi #define SCMI_VOLTAGE_SEGMENT_LOW 0 5372add5cacSCristian Marussi #define SCMI_VOLTAGE_SEGMENT_HIGH 1 5382add5cacSCristian Marussi #define SCMI_VOLTAGE_SEGMENT_STEP 2 5392add5cacSCristian Marussi int *levels_uv; 5402add5cacSCristian Marussi }; 5412add5cacSCristian Marussi 5422add5cacSCristian Marussi /** 5432add5cacSCristian Marussi * struct scmi_voltage_ops - represents the various operations provided 5442add5cacSCristian Marussi * by SCMI Voltage Protocol 5452add5cacSCristian Marussi * 5462add5cacSCristian Marussi * @num_domains_get: get the count of voltage domains provided by SCMI 5472add5cacSCristian Marussi * @info_get: get the information of the specified domain 5482add5cacSCristian Marussi * @config_set: set the config for the specified domain 5492add5cacSCristian Marussi * @config_get: get the config of the specified domain 5502add5cacSCristian Marussi * @level_set: set the voltage level for the specified domain 5512add5cacSCristian Marussi * @level_get: get the voltage level of the specified domain 5522add5cacSCristian Marussi */ 5532add5cacSCristian Marussi struct scmi_voltage_ops { 5542add5cacSCristian Marussi int (*num_domains_get)(const struct scmi_handle *handle); 5552add5cacSCristian Marussi const struct scmi_voltage_info __must_check *(*info_get) 5562add5cacSCristian Marussi (const struct scmi_handle *handle, u32 domain_id); 5572add5cacSCristian Marussi int (*config_set)(const struct scmi_handle *handle, u32 domain_id, 5582add5cacSCristian Marussi u32 config); 5592add5cacSCristian Marussi #define SCMI_VOLTAGE_ARCH_STATE_OFF 0x0 5602add5cacSCristian Marussi #define SCMI_VOLTAGE_ARCH_STATE_ON 0x7 5612add5cacSCristian Marussi int (*config_get)(const struct scmi_handle *handle, u32 domain_id, 5622add5cacSCristian Marussi u32 *config); 5632add5cacSCristian Marussi int (*level_set)(const struct scmi_handle *handle, u32 domain_id, 5642add5cacSCristian Marussi u32 flags, s32 volt_uV); 5652add5cacSCristian Marussi int (*level_get)(const struct scmi_handle *handle, u32 domain_id, 5662add5cacSCristian Marussi s32 *volt_uV); 5672add5cacSCristian Marussi }; 5682add5cacSCristian Marussi 5692add5cacSCristian Marussi /** 570e7c215f3SCristian Marussi * struct scmi_notify_ops - represents notifications' operations provided by 571e7c215f3SCristian Marussi * SCMI core 5725ad3d1cfSCristian Marussi * @devm_event_notifier_register: Managed registration of a notifier_block for 5735ad3d1cfSCristian Marussi * the requested event 5745ad3d1cfSCristian Marussi * @devm_event_notifier_unregister: Managed unregistration of a notifier_block 5755ad3d1cfSCristian Marussi * for the requested event 576e7c215f3SCristian Marussi * @register_event_notifier: Register a notifier_block for the requested event 577e7c215f3SCristian Marussi * @unregister_event_notifier: Unregister a notifier_block for the requested 578e7c215f3SCristian Marussi * event 579e7c215f3SCristian Marussi * 580e7c215f3SCristian Marussi * A user can register/unregister its own notifier_block against the wanted 581e7c215f3SCristian Marussi * platform instance regarding the desired event identified by the 582e7c215f3SCristian Marussi * tuple: (proto_id, evt_id, src_id) using the provided register/unregister 583e7c215f3SCristian Marussi * interface where: 584e7c215f3SCristian Marussi * 5855ad3d1cfSCristian Marussi * @sdev: The scmi_device to use when calling the devres managed ops devm_ 5865ad3d1cfSCristian Marussi * @handle: The handle identifying the platform instance to use, when not 5875ad3d1cfSCristian Marussi * calling the managed ops devm_ 588e7c215f3SCristian Marussi * @proto_id: The protocol ID as in SCMI Specification 589e7c215f3SCristian Marussi * @evt_id: The message ID of the desired event as in SCMI Specification 590e7c215f3SCristian Marussi * @src_id: A pointer to the desired source ID if different sources are 591e7c215f3SCristian Marussi * possible for the protocol (like domain_id, sensor_id...etc) 592e7c215f3SCristian Marussi * 593e7c215f3SCristian Marussi * @src_id can be provided as NULL if it simply does NOT make sense for 594e7c215f3SCristian Marussi * the protocol at hand, OR if the user is explicitly interested in 595e7c215f3SCristian Marussi * receiving notifications from ANY existent source associated to the 596e7c215f3SCristian Marussi * specified proto_id / evt_id. 597e7c215f3SCristian Marussi * 598e7c215f3SCristian Marussi * Received notifications are finally delivered to the registered users, 599e7c215f3SCristian Marussi * invoking the callback provided with the notifier_block *nb as follows: 600e7c215f3SCristian Marussi * 601e7c215f3SCristian Marussi * int user_cb(nb, evt_id, report) 602e7c215f3SCristian Marussi * 603e7c215f3SCristian Marussi * with: 604e7c215f3SCristian Marussi * 605e7c215f3SCristian Marussi * @nb: The notifier block provided by the user 606e7c215f3SCristian Marussi * @evt_id: The message ID of the delivered event 607e7c215f3SCristian Marussi * @report: A custom struct describing the specific event delivered 608e7c215f3SCristian Marussi */ 609e7c215f3SCristian Marussi struct scmi_notify_ops { 6105ad3d1cfSCristian Marussi int (*devm_event_notifier_register)(struct scmi_device *sdev, 6115ad3d1cfSCristian Marussi u8 proto_id, u8 evt_id, 6125ad3d1cfSCristian Marussi const u32 *src_id, 6135ad3d1cfSCristian Marussi struct notifier_block *nb); 6145ad3d1cfSCristian Marussi int (*devm_event_notifier_unregister)(struct scmi_device *sdev, 6155ad3d1cfSCristian Marussi u8 proto_id, u8 evt_id, 6165ad3d1cfSCristian Marussi const u32 *src_id, 6175ad3d1cfSCristian Marussi struct notifier_block *nb); 618e7c215f3SCristian Marussi int (*register_event_notifier)(const struct scmi_handle *handle, 6195ad3d1cfSCristian Marussi u8 proto_id, u8 evt_id, 6205ad3d1cfSCristian Marussi const u32 *src_id, 621e7c215f3SCristian Marussi struct notifier_block *nb); 622e7c215f3SCristian Marussi int (*unregister_event_notifier)(const struct scmi_handle *handle, 6235ad3d1cfSCristian Marussi u8 proto_id, u8 evt_id, 6245ad3d1cfSCristian Marussi const u32 *src_id, 625e7c215f3SCristian Marussi struct notifier_block *nb); 626e7c215f3SCristian Marussi }; 627e7c215f3SCristian Marussi 628e7c215f3SCristian Marussi /** 629aa4f886fSSudeep Holla * struct scmi_handle - Handle returned to ARM SCMI clients for usage. 630aa4f886fSSudeep Holla * 631aa4f886fSSudeep Holla * @dev: pointer to the SCMI device 632b6f20ff8SSudeep Holla * @version: pointer to the structure containing SCMI version information 63376a65509SSudeep Holla * @power_ops: pointer to set of power protocol operations 634a9e3fbfaSSudeep Holla * @perf_ops: pointer to set of performance protocol operations 6355f6c6430SSudeep Holla * @clk_ops: pointer to set of clock protocol operations 6365179c523SSudeep Holla * @sensor_ops: pointer to set of sensor protocol operations 63795a15d80SSudeep Holla * @reset_ops: pointer to set of reset protocol operations 6382add5cacSCristian Marussi * @voltage_ops: pointer to set of voltage protocol operations 63923934efeSCristian Marussi * @devm_protocol_get: devres managed method to acquire a protocol and get specific 64023934efeSCristian Marussi * operations and a dedicated protocol handler 64123934efeSCristian Marussi * @devm_protocol_put: devres managed method to release a protocol 642e7c215f3SCristian Marussi * @notify_ops: pointer to set of notifications related operations 6431baf47c2SSudeep Holla * @clk_priv: pointer to private data structure specific to clock 6441baf47c2SSudeep Holla * protocol(for internal use only) 6451baf47c2SSudeep Holla * @power_priv: pointer to private data structure specific to power 6461baf47c2SSudeep Holla * protocol(for internal use only) 6471baf47c2SSudeep Holla * @sensor_priv: pointer to private data structure specific to sensors 6481baf47c2SSudeep Holla * protocol(for internal use only) 64995a15d80SSudeep Holla * @reset_priv: pointer to private data structure specific to reset 65095a15d80SSudeep Holla * protocol(for internal use only) 6512add5cacSCristian Marussi * @voltage_priv: pointer to private data structure specific to voltage 6522add5cacSCristian Marussi * protocol(for internal use only) 6531fc2dd18SCristian Marussi * @notify_priv: pointer to private data structure specific to notifications 6541fc2dd18SCristian Marussi * (for internal use only) 655aa4f886fSSudeep Holla */ 656aa4f886fSSudeep Holla struct scmi_handle { 657aa4f886fSSudeep Holla struct device *dev; 658b6f20ff8SSudeep Holla struct scmi_revision_info *version; 65982894c1dSRikard Falkeborn const struct scmi_perf_ops *perf_ops; 66082894c1dSRikard Falkeborn const struct scmi_clk_ops *clk_ops; 66182894c1dSRikard Falkeborn const struct scmi_power_ops *power_ops; 66282894c1dSRikard Falkeborn const struct scmi_sensor_ops *sensor_ops; 66382894c1dSRikard Falkeborn const struct scmi_reset_ops *reset_ops; 6642add5cacSCristian Marussi const struct scmi_voltage_ops *voltage_ops; 66523934efeSCristian Marussi 66623934efeSCristian Marussi const void __must_check * 66723934efeSCristian Marussi (*devm_protocol_get)(struct scmi_device *sdev, u8 proto, 66823934efeSCristian Marussi struct scmi_protocol_handle **ph); 66923934efeSCristian Marussi void (*devm_protocol_put)(struct scmi_device *sdev, u8 proto); 67023934efeSCristian Marussi 67182894c1dSRikard Falkeborn const struct scmi_notify_ops *notify_ops; 672a9e3fbfaSSudeep Holla /* for protocol internal use */ 6735f6c6430SSudeep Holla void *clk_priv; 67476a65509SSudeep Holla void *power_priv; 6755179c523SSudeep Holla void *sensor_priv; 67695a15d80SSudeep Holla void *reset_priv; 6772add5cacSCristian Marussi void *voltage_priv; 6781fc2dd18SCristian Marussi void *notify_priv; 679a8803055SCristian Marussi void *system_priv; 680b6f20ff8SSudeep Holla }; 681b6f20ff8SSudeep Holla 682b6f20ff8SSudeep Holla enum scmi_std_protocol { 683b6f20ff8SSudeep Holla SCMI_PROTOCOL_BASE = 0x10, 684b6f20ff8SSudeep Holla SCMI_PROTOCOL_POWER = 0x11, 685b6f20ff8SSudeep Holla SCMI_PROTOCOL_SYSTEM = 0x12, 686b6f20ff8SSudeep Holla SCMI_PROTOCOL_PERF = 0x13, 687b6f20ff8SSudeep Holla SCMI_PROTOCOL_CLOCK = 0x14, 688b6f20ff8SSudeep Holla SCMI_PROTOCOL_SENSOR = 0x15, 68995a15d80SSudeep Holla SCMI_PROTOCOL_RESET = 0x16, 6902add5cacSCristian Marussi SCMI_PROTOCOL_VOLTAGE = 0x17, 691aa4f886fSSudeep Holla }; 692933c5044SSudeep Holla 693a8803055SCristian Marussi enum scmi_system_events { 694a8803055SCristian Marussi SCMI_SYSTEM_SHUTDOWN, 695a8803055SCristian Marussi SCMI_SYSTEM_COLDRESET, 696a8803055SCristian Marussi SCMI_SYSTEM_WARMRESET, 697a8803055SCristian Marussi SCMI_SYSTEM_POWERUP, 698a8803055SCristian Marussi SCMI_SYSTEM_SUSPEND, 699a8803055SCristian Marussi SCMI_SYSTEM_MAX 700a8803055SCristian Marussi }; 701a8803055SCristian Marussi 702933c5044SSudeep Holla struct scmi_device { 703933c5044SSudeep Holla u32 id; 704933c5044SSudeep Holla u8 protocol_id; 705ee7a9c9fSSudeep Holla const char *name; 706933c5044SSudeep Holla struct device dev; 707933c5044SSudeep Holla struct scmi_handle *handle; 708933c5044SSudeep Holla }; 709933c5044SSudeep Holla 710933c5044SSudeep Holla #define to_scmi_dev(d) container_of(d, struct scmi_device, dev) 711933c5044SSudeep Holla 712933c5044SSudeep Holla struct scmi_device * 713ee7a9c9fSSudeep Holla scmi_device_create(struct device_node *np, struct device *parent, int protocol, 714ee7a9c9fSSudeep Holla const char *name); 715933c5044SSudeep Holla void scmi_device_destroy(struct scmi_device *scmi_dev); 716933c5044SSudeep Holla 717933c5044SSudeep Holla struct scmi_device_id { 718933c5044SSudeep Holla u8 protocol_id; 719ee7a9c9fSSudeep Holla const char *name; 720933c5044SSudeep Holla }; 721933c5044SSudeep Holla 722933c5044SSudeep Holla struct scmi_driver { 723933c5044SSudeep Holla const char *name; 724933c5044SSudeep Holla int (*probe)(struct scmi_device *sdev); 725933c5044SSudeep Holla void (*remove)(struct scmi_device *sdev); 726933c5044SSudeep Holla const struct scmi_device_id *id_table; 727933c5044SSudeep Holla 728933c5044SSudeep Holla struct device_driver driver; 729933c5044SSudeep Holla }; 730933c5044SSudeep Holla 731933c5044SSudeep Holla #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver) 732933c5044SSudeep Holla 73366d90f6eSSudeep Holla #if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL) 734933c5044SSudeep Holla int scmi_driver_register(struct scmi_driver *driver, 735933c5044SSudeep Holla struct module *owner, const char *mod_name); 736933c5044SSudeep Holla void scmi_driver_unregister(struct scmi_driver *driver); 737933c5044SSudeep Holla #else 738933c5044SSudeep Holla static inline int 739933c5044SSudeep Holla scmi_driver_register(struct scmi_driver *driver, struct module *owner, 740933c5044SSudeep Holla const char *mod_name) 741933c5044SSudeep Holla { 742933c5044SSudeep Holla return -EINVAL; 743933c5044SSudeep Holla } 744933c5044SSudeep Holla 745933c5044SSudeep Holla static inline void scmi_driver_unregister(struct scmi_driver *driver) {} 746933c5044SSudeep Holla #endif /* CONFIG_ARM_SCMI_PROTOCOL */ 747933c5044SSudeep Holla 748933c5044SSudeep Holla #define scmi_register(driver) \ 749933c5044SSudeep Holla scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) 750933c5044SSudeep Holla #define scmi_unregister(driver) \ 751933c5044SSudeep Holla scmi_driver_unregister(driver) 752933c5044SSudeep Holla 753933c5044SSudeep Holla /** 754933c5044SSudeep Holla * module_scmi_driver() - Helper macro for registering a scmi driver 755933c5044SSudeep Holla * @__scmi_driver: scmi_driver structure 756933c5044SSudeep Holla * 757933c5044SSudeep Holla * Helper macro for scmi drivers to set up proper module init / exit 758933c5044SSudeep Holla * functions. Replaces module_init() and module_exit() and keeps people from 759933c5044SSudeep Holla * printing pointless things to the kernel log when their driver is loaded. 760933c5044SSudeep Holla */ 761933c5044SSudeep Holla #define module_scmi_driver(__scmi_driver) \ 762933c5044SSudeep Holla module_driver(__scmi_driver, scmi_register, scmi_unregister) 763933c5044SSudeep Holla 76448dc16e2SCristian Marussi struct scmi_protocol; 76548dc16e2SCristian Marussi int scmi_protocol_register(const struct scmi_protocol *proto); 76648dc16e2SCristian Marussi void scmi_protocol_unregister(const struct scmi_protocol *proto); 76770771c69SSudeep Holla 768e27077bcSCristian Marussi /* SCMI Notification API - Custom Event Reports */ 769e27077bcSCristian Marussi enum scmi_notification_events { 770e27077bcSCristian Marussi SCMI_EVENT_POWER_STATE_CHANGED = 0x0, 771fb5086dcSCristian Marussi SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0, 772fb5086dcSCristian Marussi SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1, 773128e3e93SCristian Marussi SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0, 774e3811190SCristian Marussi SCMI_EVENT_SENSOR_UPDATE = 0x1, 775469ca182SCristian Marussi SCMI_EVENT_RESET_ISSUED = 0x0, 776585dfab3SCristian Marussi SCMI_EVENT_BASE_ERROR_EVENT = 0x0, 777a8803055SCristian Marussi SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0, 778e27077bcSCristian Marussi }; 779e27077bcSCristian Marussi 780e27077bcSCristian Marussi struct scmi_power_state_changed_report { 78172a5eb9dSCristian Marussi ktime_t timestamp; 78272a5eb9dSCristian Marussi unsigned int agent_id; 78372a5eb9dSCristian Marussi unsigned int domain_id; 78472a5eb9dSCristian Marussi unsigned int power_state; 785e27077bcSCristian Marussi }; 786e27077bcSCristian Marussi 787a8803055SCristian Marussi struct scmi_system_power_state_notifier_report { 788a8803055SCristian Marussi ktime_t timestamp; 789a8803055SCristian Marussi unsigned int agent_id; 790a8803055SCristian Marussi unsigned int flags; 791a8803055SCristian Marussi unsigned int system_state; 792a8803055SCristian Marussi }; 793a8803055SCristian Marussi 794fb5086dcSCristian Marussi struct scmi_perf_limits_report { 79572a5eb9dSCristian Marussi ktime_t timestamp; 79672a5eb9dSCristian Marussi unsigned int agent_id; 79772a5eb9dSCristian Marussi unsigned int domain_id; 79872a5eb9dSCristian Marussi unsigned int range_max; 79972a5eb9dSCristian Marussi unsigned int range_min; 800fb5086dcSCristian Marussi }; 801fb5086dcSCristian Marussi 802fb5086dcSCristian Marussi struct scmi_perf_level_report { 80372a5eb9dSCristian Marussi ktime_t timestamp; 80472a5eb9dSCristian Marussi unsigned int agent_id; 80572a5eb9dSCristian Marussi unsigned int domain_id; 80672a5eb9dSCristian Marussi unsigned int performance_level; 807fb5086dcSCristian Marussi }; 808fb5086dcSCristian Marussi 809128e3e93SCristian Marussi struct scmi_sensor_trip_point_report { 81072a5eb9dSCristian Marussi ktime_t timestamp; 81172a5eb9dSCristian Marussi unsigned int agent_id; 81272a5eb9dSCristian Marussi unsigned int sensor_id; 81372a5eb9dSCristian Marussi unsigned int trip_point_desc; 814128e3e93SCristian Marussi }; 815128e3e93SCristian Marussi 816e3811190SCristian Marussi struct scmi_sensor_update_report { 817e3811190SCristian Marussi ktime_t timestamp; 818e3811190SCristian Marussi unsigned int agent_id; 819e3811190SCristian Marussi unsigned int sensor_id; 820e3811190SCristian Marussi unsigned int readings_count; 821e3811190SCristian Marussi struct scmi_sensor_reading readings[]; 822e3811190SCristian Marussi }; 823e3811190SCristian Marussi 824469ca182SCristian Marussi struct scmi_reset_issued_report { 82572a5eb9dSCristian Marussi ktime_t timestamp; 82672a5eb9dSCristian Marussi unsigned int agent_id; 82772a5eb9dSCristian Marussi unsigned int domain_id; 82872a5eb9dSCristian Marussi unsigned int reset_state; 829469ca182SCristian Marussi }; 830469ca182SCristian Marussi 831585dfab3SCristian Marussi struct scmi_base_error_report { 83272a5eb9dSCristian Marussi ktime_t timestamp; 83372a5eb9dSCristian Marussi unsigned int agent_id; 834585dfab3SCristian Marussi bool fatal; 83572a5eb9dSCristian Marussi unsigned int cmd_count; 83672a5eb9dSCristian Marussi unsigned long long reports[]; 837585dfab3SCristian Marussi }; 838585dfab3SCristian Marussi 83970771c69SSudeep Holla #endif /* _LINUX_SCMI_PROTOCOL_H */ 840