14752544aSSudeep Holla /* SPDX-License-Identifier: GPL-2.0-only */ 2aa4f886fSSudeep Holla /* 3aa4f886fSSudeep Holla * SCMI Message Protocol driver header 4aa4f886fSSudeep Holla * 5aa4f886fSSudeep Holla * Copyright (C) 2018 ARM Ltd. 6aa4f886fSSudeep Holla */ 770771c69SSudeep Holla 870771c69SSudeep Holla #ifndef _LINUX_SCMI_PROTOCOL_H 970771c69SSudeep Holla #define _LINUX_SCMI_PROTOCOL_H 1070771c69SSudeep Holla 11*1fe00b8bSCristian 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; 60a9e3fbfaSSudeep Holla 61a9e3fbfaSSudeep Holla /** 625f6c6430SSudeep Holla * struct scmi_clk_ops - represents the various operations provided 635f6c6430SSudeep Holla * by SCMI Clock Protocol 645f6c6430SSudeep Holla * 655f6c6430SSudeep Holla * @count_get: get the count of clocks provided by SCMI 665f6c6430SSudeep Holla * @info_get: get the information of the specified clock 675f6c6430SSudeep Holla * @rate_get: request the current clock rate of a clock 685f6c6430SSudeep Holla * @rate_set: set the clock rate of a clock 695f6c6430SSudeep Holla * @enable: enables the specified clock 705f6c6430SSudeep Holla * @disable: disables the specified clock 715f6c6430SSudeep Holla */ 725f6c6430SSudeep Holla struct scmi_clk_ops { 735f6c6430SSudeep Holla int (*count_get)(const struct scmi_handle *handle); 745f6c6430SSudeep Holla 755f6c6430SSudeep Holla const struct scmi_clock_info *(*info_get) 765f6c6430SSudeep Holla (const struct scmi_handle *handle, u32 clk_id); 775f6c6430SSudeep Holla int (*rate_get)(const struct scmi_handle *handle, u32 clk_id, 785f6c6430SSudeep Holla u64 *rate); 795f6c6430SSudeep Holla int (*rate_set)(const struct scmi_handle *handle, u32 clk_id, 80d0aba116SSudeep Holla u64 rate); 815f6c6430SSudeep Holla int (*enable)(const struct scmi_handle *handle, u32 clk_id); 825f6c6430SSudeep Holla int (*disable)(const struct scmi_handle *handle, u32 clk_id); 835f6c6430SSudeep Holla }; 845f6c6430SSudeep Holla 855f6c6430SSudeep Holla /** 86a9e3fbfaSSudeep Holla * struct scmi_perf_ops - represents the various operations provided 87a9e3fbfaSSudeep Holla * by SCMI Performance Protocol 88a9e3fbfaSSudeep Holla * 89a9e3fbfaSSudeep Holla * @limits_set: sets limits on the performance level of a domain 90a9e3fbfaSSudeep Holla * @limits_get: gets limits on the performance level of a domain 91a9e3fbfaSSudeep Holla * @level_set: sets the performance level of a domain 92a9e3fbfaSSudeep Holla * @level_get: gets the performance level of a domain 93a9e3fbfaSSudeep Holla * @device_domain_id: gets the scmi domain id for a given device 947859e08cSSudeep Holla * @transition_latency_get: gets the DVFS transition latency for a given device 957859e08cSSudeep Holla * @device_opps_add: adds all the OPPs for a given device 96a9e3fbfaSSudeep Holla * @freq_set: sets the frequency for a given device using sustained frequency 97a9e3fbfaSSudeep Holla * to sustained performance level mapping 98a9e3fbfaSSudeep Holla * @freq_get: gets the frequency for a given device using sustained frequency 99a9e3fbfaSSudeep Holla * to sustained performance level mapping 1001a63fe9aSQuentin Perret * @est_power_get: gets the estimated power cost for a given performance domain 1011a63fe9aSQuentin Perret * at a given frequency 102a9e3fbfaSSudeep Holla */ 103a9e3fbfaSSudeep Holla struct scmi_perf_ops { 104a9e3fbfaSSudeep Holla int (*limits_set)(const struct scmi_handle *handle, u32 domain, 105a9e3fbfaSSudeep Holla u32 max_perf, u32 min_perf); 106a9e3fbfaSSudeep Holla int (*limits_get)(const struct scmi_handle *handle, u32 domain, 107a9e3fbfaSSudeep Holla u32 *max_perf, u32 *min_perf); 108a9e3fbfaSSudeep Holla int (*level_set)(const struct scmi_handle *handle, u32 domain, 1095c4ba3ccSSudeep Holla u32 level, bool poll); 110a9e3fbfaSSudeep Holla int (*level_get)(const struct scmi_handle *handle, u32 domain, 1115c4ba3ccSSudeep Holla u32 *level, bool poll); 112a9e3fbfaSSudeep Holla int (*device_domain_id)(struct device *dev); 1137859e08cSSudeep Holla int (*transition_latency_get)(const struct scmi_handle *handle, 114a9e3fbfaSSudeep Holla struct device *dev); 1157859e08cSSudeep Holla int (*device_opps_add)(const struct scmi_handle *handle, 116a9e3fbfaSSudeep Holla struct device *dev); 117a9e3fbfaSSudeep Holla int (*freq_set)(const struct scmi_handle *handle, u32 domain, 1185c4ba3ccSSudeep Holla unsigned long rate, bool poll); 119a9e3fbfaSSudeep Holla int (*freq_get)(const struct scmi_handle *handle, u32 domain, 1205c4ba3ccSSudeep Holla unsigned long *rate, bool poll); 1211a63fe9aSQuentin Perret int (*est_power_get)(const struct scmi_handle *handle, u32 domain, 1221a63fe9aSQuentin Perret unsigned long *rate, unsigned long *power); 1231909872fSNicola Mazzucato bool (*fast_switch_possible)(const struct scmi_handle *handle, 1241909872fSNicola Mazzucato struct device *dev); 125a9e3fbfaSSudeep Holla }; 126a9e3fbfaSSudeep Holla 127aa4f886fSSudeep Holla /** 12876a65509SSudeep Holla * struct scmi_power_ops - represents the various operations provided 12976a65509SSudeep Holla * by SCMI Power Protocol 13076a65509SSudeep Holla * 13176a65509SSudeep Holla * @num_domains_get: get the count of power domains provided by SCMI 13276a65509SSudeep Holla * @name_get: gets the name of a power domain 13376a65509SSudeep Holla * @state_set: sets the power state of a power domain 13476a65509SSudeep Holla * @state_get: gets the power state of a power domain 13576a65509SSudeep Holla */ 13676a65509SSudeep Holla struct scmi_power_ops { 13776a65509SSudeep Holla int (*num_domains_get)(const struct scmi_handle *handle); 13876a65509SSudeep Holla char *(*name_get)(const struct scmi_handle *handle, u32 domain); 13976a65509SSudeep Holla #define SCMI_POWER_STATE_TYPE_SHIFT 30 14076a65509SSudeep Holla #define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1) 14176a65509SSudeep Holla #define SCMI_POWER_STATE_PARAM(type, id) \ 14276a65509SSudeep Holla ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \ 14376a65509SSudeep Holla ((id) & SCMI_POWER_STATE_ID_MASK)) 14476a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0) 14576a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0) 14676a65509SSudeep Holla int (*state_set)(const struct scmi_handle *handle, u32 domain, 14776a65509SSudeep Holla u32 state); 14876a65509SSudeep Holla int (*state_get)(const struct scmi_handle *handle, u32 domain, 14976a65509SSudeep Holla u32 *state); 15076a65509SSudeep Holla }; 15176a65509SSudeep Holla 152*1fe00b8bSCristian Marussi /** 153*1fe00b8bSCristian Marussi * scmi_range_attrs - specifies a sensor or axis values' range 154*1fe00b8bSCristian Marussi * @min_range: The minimum value which can be represented by the sensor/axis. 155*1fe00b8bSCristian Marussi * @max_range: The maximum value which can be represented by the sensor/axis. 156*1fe00b8bSCristian Marussi */ 157*1fe00b8bSCristian Marussi struct scmi_range_attrs { 158*1fe00b8bSCristian Marussi long long min_range; 159*1fe00b8bSCristian Marussi long long max_range; 160*1fe00b8bSCristian Marussi }; 161*1fe00b8bSCristian Marussi 162*1fe00b8bSCristian Marussi /** 163*1fe00b8bSCristian Marussi * scmi_sensor_axis_info - describes one sensor axes 164*1fe00b8bSCristian Marussi * @id: The axes ID. 165*1fe00b8bSCristian Marussi * @type: Axes type. Chosen amongst one of @enum scmi_sensor_class. 166*1fe00b8bSCristian Marussi * @scale: Power-of-10 multiplier applied to the axis unit. 167*1fe00b8bSCristian Marussi * @name: NULL-terminated string representing axes name as advertised by 168*1fe00b8bSCristian Marussi * SCMI platform. 169*1fe00b8bSCristian Marussi * @extended_attrs: Flag to indicate the presence of additional extended 170*1fe00b8bSCristian Marussi * attributes for this axes. 171*1fe00b8bSCristian Marussi * @resolution: Extended attribute representing the resolution of the axes. 172*1fe00b8bSCristian Marussi * Set to 0 if not reported by this axes. 173*1fe00b8bSCristian Marussi * @exponent: Extended attribute representing the power-of-10 multiplier that 174*1fe00b8bSCristian Marussi * is applied to the resolution field. Set to 0 if not reported by 175*1fe00b8bSCristian Marussi * this axes. 176*1fe00b8bSCristian Marussi * @attrs: Extended attributes representing minimum and maximum values 177*1fe00b8bSCristian Marussi * measurable by this axes. Set to 0 if not reported by this sensor. 178*1fe00b8bSCristian Marussi */ 179*1fe00b8bSCristian Marussi struct scmi_sensor_axis_info { 180*1fe00b8bSCristian Marussi unsigned int id; 181*1fe00b8bSCristian Marussi unsigned int type; 182*1fe00b8bSCristian Marussi int scale; 1835179c523SSudeep Holla char name[SCMI_MAX_STR_SIZE]; 184*1fe00b8bSCristian Marussi bool extended_attrs; 185*1fe00b8bSCristian Marussi unsigned int resolution; 186*1fe00b8bSCristian Marussi int exponent; 187*1fe00b8bSCristian Marussi struct scmi_range_attrs attrs; 188*1fe00b8bSCristian Marussi }; 189*1fe00b8bSCristian Marussi 190*1fe00b8bSCristian Marussi /** 191*1fe00b8bSCristian Marussi * scmi_sensor_intervals_info - describes number and type of available update 192*1fe00b8bSCristian Marussi * intervals 193*1fe00b8bSCristian Marussi * @segmented: Flag for segmented intervals' representation. When True there 194*1fe00b8bSCristian Marussi * will be exactly 3 intervals in @desc, with each entry 195*1fe00b8bSCristian Marussi * representing a member of a segment in this order: 196*1fe00b8bSCristian Marussi * {lowest update interval, highest update interval, step size} 197*1fe00b8bSCristian Marussi * @count: Number of intervals described in @desc. 198*1fe00b8bSCristian Marussi * @desc: Array of @count interval descriptor bitmask represented as detailed in 199*1fe00b8bSCristian Marussi * the SCMI specification: it can be accessed using the accompanying 200*1fe00b8bSCristian Marussi * macros. 201*1fe00b8bSCristian Marussi * @prealloc_pool: A minimal preallocated pool of desc entries used to avoid 202*1fe00b8bSCristian Marussi * lesser-than-64-bytes dynamic allocation for small @count 203*1fe00b8bSCristian Marussi * values. 204*1fe00b8bSCristian Marussi */ 205*1fe00b8bSCristian Marussi struct scmi_sensor_intervals_info { 206*1fe00b8bSCristian Marussi bool segmented; 207*1fe00b8bSCristian Marussi unsigned int count; 208*1fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_SEGMENT_LOW 0 209*1fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_SEGMENT_HIGH 1 210*1fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_SEGMENT_STEP 2 211*1fe00b8bSCristian Marussi unsigned int *desc; 212*1fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_GET_SECS(x) FIELD_GET(GENMASK(20, 5), (x)) 213*1fe00b8bSCristian Marussi #define SCMI_SENS_INTVL_GET_EXP(x) \ 214*1fe00b8bSCristian Marussi ({ \ 215*1fe00b8bSCristian Marussi int __signed_exp = FIELD_GET(GENMASK(4, 0), (x)); \ 216*1fe00b8bSCristian Marussi \ 217*1fe00b8bSCristian Marussi if (__signed_exp & BIT(4)) \ 218*1fe00b8bSCristian Marussi __signed_exp |= GENMASK(31, 5); \ 219*1fe00b8bSCristian Marussi __signed_exp; \ 220*1fe00b8bSCristian Marussi }) 221*1fe00b8bSCristian Marussi #define SCMI_MAX_PREALLOC_POOL 16 222*1fe00b8bSCristian Marussi unsigned int prealloc_pool[SCMI_MAX_PREALLOC_POOL]; 223*1fe00b8bSCristian Marussi }; 224*1fe00b8bSCristian Marussi 225*1fe00b8bSCristian Marussi /** 226*1fe00b8bSCristian Marussi * struct scmi_sensor_info - represents information related to one of the 227*1fe00b8bSCristian Marussi * available sensors. 228*1fe00b8bSCristian Marussi * @id: Sensor ID. 229*1fe00b8bSCristian Marussi * @type: Sensor type. Chosen amongst one of @enum scmi_sensor_class. 230*1fe00b8bSCristian Marussi * @scale: Power-of-10 multiplier applied to the sensor unit. 231*1fe00b8bSCristian Marussi * @num_trip_points: Number of maximum configurable trip points. 232*1fe00b8bSCristian Marussi * @async: Flag for asynchronous read support. 233*1fe00b8bSCristian Marussi * @update: Flag for continuouos update notification support. 234*1fe00b8bSCristian Marussi * @timestamped: Flag for timestamped read support. 235*1fe00b8bSCristian Marussi * @tstamp_scale: Power-of-10 multiplier applied to the sensor timestamps to 236*1fe00b8bSCristian Marussi * represent it in seconds. 237*1fe00b8bSCristian Marussi * @num_axis: Number of supported axis if any. Reported as 0 for scalar sensors. 238*1fe00b8bSCristian Marussi * @axis: Pointer to an array of @num_axis descriptors. 239*1fe00b8bSCristian Marussi * @intervals: Descriptor of available update intervals. 240*1fe00b8bSCristian Marussi * @sensor_config: A bitmask reporting the current sensor configuration as 241*1fe00b8bSCristian Marussi * detailed in the SCMI specification: it can accessed and 242*1fe00b8bSCristian Marussi * modified through the accompanying macros. 243*1fe00b8bSCristian Marussi * @name: NULL-terminated string representing sensor name as advertised by 244*1fe00b8bSCristian Marussi * SCMI platform. 245*1fe00b8bSCristian Marussi * @extended_scalar_attrs: Flag to indicate the presence of additional extended 246*1fe00b8bSCristian Marussi * attributes for this sensor. 247*1fe00b8bSCristian Marussi * @sensor_power: Extended attribute representing the average power 248*1fe00b8bSCristian Marussi * consumed by the sensor in microwatts (uW) when it is active. 249*1fe00b8bSCristian Marussi * Reported here only for scalar sensors. 250*1fe00b8bSCristian Marussi * Set to 0 if not reported by this sensor. 251*1fe00b8bSCristian Marussi * @resolution: Extended attribute representing the resolution of the sensor. 252*1fe00b8bSCristian Marussi * Reported here only for scalar sensors. 253*1fe00b8bSCristian Marussi * Set to 0 if not reported by this sensor. 254*1fe00b8bSCristian Marussi * @exponent: Extended attribute representing the power-of-10 multiplier that is 255*1fe00b8bSCristian Marussi * applied to the resolution field. 256*1fe00b8bSCristian Marussi * Reported here only for scalar sensors. 257*1fe00b8bSCristian Marussi * Set to 0 if not reported by this sensor. 258*1fe00b8bSCristian Marussi * @scalar_attrs: Extended attributes representing minimum and maximum 259*1fe00b8bSCristian Marussi * measurable values by this sensor. 260*1fe00b8bSCristian Marussi * Reported here only for scalar sensors. 261*1fe00b8bSCristian Marussi * Set to 0 if not reported by this sensor. 262*1fe00b8bSCristian Marussi */ 263*1fe00b8bSCristian Marussi struct scmi_sensor_info { 264*1fe00b8bSCristian Marussi unsigned int id; 265*1fe00b8bSCristian Marussi unsigned int type; 266*1fe00b8bSCristian Marussi int scale; 267*1fe00b8bSCristian Marussi unsigned int num_trip_points; 268*1fe00b8bSCristian Marussi bool async; 269*1fe00b8bSCristian Marussi bool update; 270*1fe00b8bSCristian Marussi bool timestamped; 271*1fe00b8bSCristian Marussi int tstamp_scale; 272*1fe00b8bSCristian Marussi unsigned int num_axis; 273*1fe00b8bSCristian Marussi struct scmi_sensor_axis_info *axis; 274*1fe00b8bSCristian Marussi struct scmi_sensor_intervals_info intervals; 275*1fe00b8bSCristian Marussi char name[SCMI_MAX_STR_SIZE]; 276*1fe00b8bSCristian Marussi bool extended_scalar_attrs; 277*1fe00b8bSCristian Marussi unsigned int sensor_power; 278*1fe00b8bSCristian Marussi unsigned int resolution; 279*1fe00b8bSCristian Marussi int exponent; 280*1fe00b8bSCristian Marussi struct scmi_range_attrs scalar_attrs; 2815179c523SSudeep Holla }; 2825179c523SSudeep Holla 2835179c523SSudeep Holla /* 2845179c523SSudeep Holla * Partial list from Distributed Management Task Force (DMTF) specification: 2855179c523SSudeep Holla * DSP0249 (Platform Level Data Model specification) 2865179c523SSudeep Holla */ 2875179c523SSudeep Holla enum scmi_sensor_class { 2885179c523SSudeep Holla NONE = 0x0, 289607a4672SSudeep Holla UNSPEC = 0x1, 2905179c523SSudeep Holla TEMPERATURE_C = 0x2, 291607a4672SSudeep Holla TEMPERATURE_F = 0x3, 292607a4672SSudeep Holla TEMPERATURE_K = 0x4, 2935179c523SSudeep Holla VOLTAGE = 0x5, 2945179c523SSudeep Holla CURRENT = 0x6, 2955179c523SSudeep Holla POWER = 0x7, 2965179c523SSudeep Holla ENERGY = 0x8, 297607a4672SSudeep Holla CHARGE = 0x9, 298607a4672SSudeep Holla VOLTAMPERE = 0xA, 299607a4672SSudeep Holla NITS = 0xB, 300607a4672SSudeep Holla LUMENS = 0xC, 301607a4672SSudeep Holla LUX = 0xD, 302607a4672SSudeep Holla CANDELAS = 0xE, 303607a4672SSudeep Holla KPA = 0xF, 304607a4672SSudeep Holla PSI = 0x10, 305607a4672SSudeep Holla NEWTON = 0x11, 306607a4672SSudeep Holla CFM = 0x12, 307607a4672SSudeep Holla RPM = 0x13, 308607a4672SSudeep Holla HERTZ = 0x14, 309607a4672SSudeep Holla SECS = 0x15, 310607a4672SSudeep Holla MINS = 0x16, 311607a4672SSudeep Holla HOURS = 0x17, 312607a4672SSudeep Holla DAYS = 0x18, 313607a4672SSudeep Holla WEEKS = 0x19, 314607a4672SSudeep Holla MILS = 0x1A, 315607a4672SSudeep Holla INCHES = 0x1B, 316607a4672SSudeep Holla FEET = 0x1C, 317607a4672SSudeep Holla CUBIC_INCHES = 0x1D, 318607a4672SSudeep Holla CUBIC_FEET = 0x1E, 319607a4672SSudeep Holla METERS = 0x1F, 320607a4672SSudeep Holla CUBIC_CM = 0x20, 321607a4672SSudeep Holla CUBIC_METERS = 0x21, 322607a4672SSudeep Holla LITERS = 0x22, 323607a4672SSudeep Holla FLUID_OUNCES = 0x23, 324607a4672SSudeep Holla RADIANS = 0x24, 325607a4672SSudeep Holla STERADIANS = 0x25, 326607a4672SSudeep Holla REVOLUTIONS = 0x26, 327607a4672SSudeep Holla CYCLES = 0x27, 328607a4672SSudeep Holla GRAVITIES = 0x28, 329607a4672SSudeep Holla OUNCES = 0x29, 330607a4672SSudeep Holla POUNDS = 0x2A, 331607a4672SSudeep Holla FOOT_POUNDS = 0x2B, 332607a4672SSudeep Holla OUNCE_INCHES = 0x2C, 333607a4672SSudeep Holla GAUSS = 0x2D, 334607a4672SSudeep Holla GILBERTS = 0x2E, 335607a4672SSudeep Holla HENRIES = 0x2F, 336607a4672SSudeep Holla FARADS = 0x30, 337607a4672SSudeep Holla OHMS = 0x31, 338607a4672SSudeep Holla SIEMENS = 0x32, 339607a4672SSudeep Holla MOLES = 0x33, 340607a4672SSudeep Holla BECQUERELS = 0x34, 341607a4672SSudeep Holla PPM = 0x35, 342607a4672SSudeep Holla DECIBELS = 0x36, 343607a4672SSudeep Holla DBA = 0x37, 344607a4672SSudeep Holla DBC = 0x38, 345607a4672SSudeep Holla GRAYS = 0x39, 346607a4672SSudeep Holla SIEVERTS = 0x3A, 347607a4672SSudeep Holla COLOR_TEMP_K = 0x3B, 348607a4672SSudeep Holla BITS = 0x3C, 349607a4672SSudeep Holla BYTES = 0x3D, 350607a4672SSudeep Holla WORDS = 0x3E, 351607a4672SSudeep Holla DWORDS = 0x3F, 352607a4672SSudeep Holla QWORDS = 0x40, 353607a4672SSudeep Holla PERCENTAGE = 0x41, 354607a4672SSudeep Holla PASCALS = 0x42, 355607a4672SSudeep Holla COUNTS = 0x43, 356607a4672SSudeep Holla GRAMS = 0x44, 357607a4672SSudeep Holla NEWTON_METERS = 0x45, 358607a4672SSudeep Holla HITS = 0x46, 359607a4672SSudeep Holla MISSES = 0x47, 360607a4672SSudeep Holla RETRIES = 0x48, 361607a4672SSudeep Holla OVERRUNS = 0x49, 362607a4672SSudeep Holla UNDERRUNS = 0x4A, 363607a4672SSudeep Holla COLLISIONS = 0x4B, 364607a4672SSudeep Holla PACKETS = 0x4C, 365607a4672SSudeep Holla MESSAGES = 0x4D, 366607a4672SSudeep Holla CHARS = 0x4E, 367607a4672SSudeep Holla ERRORS = 0x4F, 368607a4672SSudeep Holla CORRECTED_ERRS = 0x50, 369607a4672SSudeep Holla UNCORRECTABLE_ERRS = 0x51, 370607a4672SSudeep Holla SQ_MILS = 0x52, 371607a4672SSudeep Holla SQ_INCHES = 0x53, 372607a4672SSudeep Holla SQ_FEET = 0x54, 373607a4672SSudeep Holla SQ_CM = 0x55, 374607a4672SSudeep Holla SQ_METERS = 0x56, 375*1fe00b8bSCristian Marussi RADIANS_SEC = 0x57, 376*1fe00b8bSCristian Marussi BPM = 0x58, 377*1fe00b8bSCristian Marussi METERS_SEC_SQUARED = 0x59, 378*1fe00b8bSCristian Marussi METERS_SEC = 0x5A, 379*1fe00b8bSCristian Marussi CUBIC_METERS_SEC = 0x5B, 380*1fe00b8bSCristian Marussi MM_MERCURY = 0x5C, 381*1fe00b8bSCristian Marussi RADIANS_SEC_SQUARED = 0x5D, 382*1fe00b8bSCristian Marussi OEM_UNIT = 0xFF 3835179c523SSudeep Holla }; 3845179c523SSudeep Holla 3855179c523SSudeep Holla /** 3865179c523SSudeep Holla * struct scmi_sensor_ops - represents the various operations provided 3875179c523SSudeep Holla * by SCMI Sensor Protocol 3885179c523SSudeep Holla * 3895179c523SSudeep Holla * @count_get: get the count of sensors provided by SCMI 3905179c523SSudeep Holla * @info_get: get the information of the specified sensor 3919eefa43aSSudeep Holla * @trip_point_config: selects and configures a trip-point of interest 3925179c523SSudeep Holla * @reading_get: gets the current value of the sensor 3935179c523SSudeep Holla */ 3945179c523SSudeep Holla struct scmi_sensor_ops { 3955179c523SSudeep Holla int (*count_get)(const struct scmi_handle *handle); 3965179c523SSudeep Holla const struct scmi_sensor_info *(*info_get) 3975179c523SSudeep Holla (const struct scmi_handle *handle, u32 sensor_id); 3989eefa43aSSudeep Holla int (*trip_point_config)(const struct scmi_handle *handle, 3999eefa43aSSudeep Holla u32 sensor_id, u8 trip_id, u64 trip_value); 4005179c523SSudeep Holla int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id, 4016a55331cSSudeep Holla u64 *value); 4025179c523SSudeep Holla }; 4035179c523SSudeep Holla 40476a65509SSudeep Holla /** 40595a15d80SSudeep Holla * struct scmi_reset_ops - represents the various operations provided 40695a15d80SSudeep Holla * by SCMI Reset Protocol 40795a15d80SSudeep Holla * 40895a15d80SSudeep Holla * @num_domains_get: get the count of reset domains provided by SCMI 40995a15d80SSudeep Holla * @name_get: gets the name of a reset domain 41095a15d80SSudeep Holla * @latency_get: gets the reset latency for the specified reset domain 41195a15d80SSudeep Holla * @reset: resets the specified reset domain 41295a15d80SSudeep Holla * @assert: explicitly assert reset signal of the specified reset domain 41395a15d80SSudeep Holla * @deassert: explicitly deassert reset signal of the specified reset domain 41495a15d80SSudeep Holla */ 41595a15d80SSudeep Holla struct scmi_reset_ops { 41695a15d80SSudeep Holla int (*num_domains_get)(const struct scmi_handle *handle); 41795a15d80SSudeep Holla char *(*name_get)(const struct scmi_handle *handle, u32 domain); 41895a15d80SSudeep Holla int (*latency_get)(const struct scmi_handle *handle, u32 domain); 41995a15d80SSudeep Holla int (*reset)(const struct scmi_handle *handle, u32 domain); 42095a15d80SSudeep Holla int (*assert)(const struct scmi_handle *handle, u32 domain); 42195a15d80SSudeep Holla int (*deassert)(const struct scmi_handle *handle, u32 domain); 42295a15d80SSudeep Holla }; 42395a15d80SSudeep Holla 42495a15d80SSudeep Holla /** 425e7c215f3SCristian Marussi * struct scmi_notify_ops - represents notifications' operations provided by 426e7c215f3SCristian Marussi * SCMI core 427e7c215f3SCristian Marussi * @register_event_notifier: Register a notifier_block for the requested event 428e7c215f3SCristian Marussi * @unregister_event_notifier: Unregister a notifier_block for the requested 429e7c215f3SCristian Marussi * event 430e7c215f3SCristian Marussi * 431e7c215f3SCristian Marussi * A user can register/unregister its own notifier_block against the wanted 432e7c215f3SCristian Marussi * platform instance regarding the desired event identified by the 433e7c215f3SCristian Marussi * tuple: (proto_id, evt_id, src_id) using the provided register/unregister 434e7c215f3SCristian Marussi * interface where: 435e7c215f3SCristian Marussi * 436e7c215f3SCristian Marussi * @handle: The handle identifying the platform instance to use 437e7c215f3SCristian Marussi * @proto_id: The protocol ID as in SCMI Specification 438e7c215f3SCristian Marussi * @evt_id: The message ID of the desired event as in SCMI Specification 439e7c215f3SCristian Marussi * @src_id: A pointer to the desired source ID if different sources are 440e7c215f3SCristian Marussi * possible for the protocol (like domain_id, sensor_id...etc) 441e7c215f3SCristian Marussi * 442e7c215f3SCristian Marussi * @src_id can be provided as NULL if it simply does NOT make sense for 443e7c215f3SCristian Marussi * the protocol at hand, OR if the user is explicitly interested in 444e7c215f3SCristian Marussi * receiving notifications from ANY existent source associated to the 445e7c215f3SCristian Marussi * specified proto_id / evt_id. 446e7c215f3SCristian Marussi * 447e7c215f3SCristian Marussi * Received notifications are finally delivered to the registered users, 448e7c215f3SCristian Marussi * invoking the callback provided with the notifier_block *nb as follows: 449e7c215f3SCristian Marussi * 450e7c215f3SCristian Marussi * int user_cb(nb, evt_id, report) 451e7c215f3SCristian Marussi * 452e7c215f3SCristian Marussi * with: 453e7c215f3SCristian Marussi * 454e7c215f3SCristian Marussi * @nb: The notifier block provided by the user 455e7c215f3SCristian Marussi * @evt_id: The message ID of the delivered event 456e7c215f3SCristian Marussi * @report: A custom struct describing the specific event delivered 457e7c215f3SCristian Marussi */ 458e7c215f3SCristian Marussi struct scmi_notify_ops { 459e7c215f3SCristian Marussi int (*register_event_notifier)(const struct scmi_handle *handle, 460e7c215f3SCristian Marussi u8 proto_id, u8 evt_id, u32 *src_id, 461e7c215f3SCristian Marussi struct notifier_block *nb); 462e7c215f3SCristian Marussi int (*unregister_event_notifier)(const struct scmi_handle *handle, 463e7c215f3SCristian Marussi u8 proto_id, u8 evt_id, u32 *src_id, 464e7c215f3SCristian Marussi struct notifier_block *nb); 465e7c215f3SCristian Marussi }; 466e7c215f3SCristian Marussi 467e7c215f3SCristian Marussi /** 468aa4f886fSSudeep Holla * struct scmi_handle - Handle returned to ARM SCMI clients for usage. 469aa4f886fSSudeep Holla * 470aa4f886fSSudeep Holla * @dev: pointer to the SCMI device 471b6f20ff8SSudeep Holla * @version: pointer to the structure containing SCMI version information 47276a65509SSudeep Holla * @power_ops: pointer to set of power protocol operations 473a9e3fbfaSSudeep Holla * @perf_ops: pointer to set of performance protocol operations 4745f6c6430SSudeep Holla * @clk_ops: pointer to set of clock protocol operations 4755179c523SSudeep Holla * @sensor_ops: pointer to set of sensor protocol operations 47695a15d80SSudeep Holla * @reset_ops: pointer to set of reset protocol operations 477e7c215f3SCristian Marussi * @notify_ops: pointer to set of notifications related operations 4781baf47c2SSudeep Holla * @perf_priv: pointer to private data structure specific to performance 4791baf47c2SSudeep Holla * protocol(for internal use only) 4801baf47c2SSudeep Holla * @clk_priv: pointer to private data structure specific to clock 4811baf47c2SSudeep Holla * protocol(for internal use only) 4821baf47c2SSudeep Holla * @power_priv: pointer to private data structure specific to power 4831baf47c2SSudeep Holla * protocol(for internal use only) 4841baf47c2SSudeep Holla * @sensor_priv: pointer to private data structure specific to sensors 4851baf47c2SSudeep Holla * protocol(for internal use only) 48695a15d80SSudeep Holla * @reset_priv: pointer to private data structure specific to reset 48795a15d80SSudeep Holla * protocol(for internal use only) 4881fc2dd18SCristian Marussi * @notify_priv: pointer to private data structure specific to notifications 4891fc2dd18SCristian Marussi * (for internal use only) 490aa4f886fSSudeep Holla */ 491aa4f886fSSudeep Holla struct scmi_handle { 492aa4f886fSSudeep Holla struct device *dev; 493b6f20ff8SSudeep Holla struct scmi_revision_info *version; 49482894c1dSRikard Falkeborn const struct scmi_perf_ops *perf_ops; 49582894c1dSRikard Falkeborn const struct scmi_clk_ops *clk_ops; 49682894c1dSRikard Falkeborn const struct scmi_power_ops *power_ops; 49782894c1dSRikard Falkeborn const struct scmi_sensor_ops *sensor_ops; 49882894c1dSRikard Falkeborn const struct scmi_reset_ops *reset_ops; 49982894c1dSRikard Falkeborn const struct scmi_notify_ops *notify_ops; 500a9e3fbfaSSudeep Holla /* for protocol internal use */ 501a9e3fbfaSSudeep Holla void *perf_priv; 5025f6c6430SSudeep Holla void *clk_priv; 50376a65509SSudeep Holla void *power_priv; 5045179c523SSudeep Holla void *sensor_priv; 50595a15d80SSudeep Holla void *reset_priv; 5061fc2dd18SCristian Marussi void *notify_priv; 507a8803055SCristian Marussi void *system_priv; 508b6f20ff8SSudeep Holla }; 509b6f20ff8SSudeep Holla 510b6f20ff8SSudeep Holla enum scmi_std_protocol { 511b6f20ff8SSudeep Holla SCMI_PROTOCOL_BASE = 0x10, 512b6f20ff8SSudeep Holla SCMI_PROTOCOL_POWER = 0x11, 513b6f20ff8SSudeep Holla SCMI_PROTOCOL_SYSTEM = 0x12, 514b6f20ff8SSudeep Holla SCMI_PROTOCOL_PERF = 0x13, 515b6f20ff8SSudeep Holla SCMI_PROTOCOL_CLOCK = 0x14, 516b6f20ff8SSudeep Holla SCMI_PROTOCOL_SENSOR = 0x15, 51795a15d80SSudeep Holla SCMI_PROTOCOL_RESET = 0x16, 518aa4f886fSSudeep Holla }; 519933c5044SSudeep Holla 520a8803055SCristian Marussi enum scmi_system_events { 521a8803055SCristian Marussi SCMI_SYSTEM_SHUTDOWN, 522a8803055SCristian Marussi SCMI_SYSTEM_COLDRESET, 523a8803055SCristian Marussi SCMI_SYSTEM_WARMRESET, 524a8803055SCristian Marussi SCMI_SYSTEM_POWERUP, 525a8803055SCristian Marussi SCMI_SYSTEM_SUSPEND, 526a8803055SCristian Marussi SCMI_SYSTEM_MAX 527a8803055SCristian Marussi }; 528a8803055SCristian Marussi 529933c5044SSudeep Holla struct scmi_device { 530933c5044SSudeep Holla u32 id; 531933c5044SSudeep Holla u8 protocol_id; 532ee7a9c9fSSudeep Holla const char *name; 533933c5044SSudeep Holla struct device dev; 534933c5044SSudeep Holla struct scmi_handle *handle; 535933c5044SSudeep Holla }; 536933c5044SSudeep Holla 537933c5044SSudeep Holla #define to_scmi_dev(d) container_of(d, struct scmi_device, dev) 538933c5044SSudeep Holla 539933c5044SSudeep Holla struct scmi_device * 540ee7a9c9fSSudeep Holla scmi_device_create(struct device_node *np, struct device *parent, int protocol, 541ee7a9c9fSSudeep Holla const char *name); 542933c5044SSudeep Holla void scmi_device_destroy(struct scmi_device *scmi_dev); 543933c5044SSudeep Holla 544933c5044SSudeep Holla struct scmi_device_id { 545933c5044SSudeep Holla u8 protocol_id; 546ee7a9c9fSSudeep Holla const char *name; 547933c5044SSudeep Holla }; 548933c5044SSudeep Holla 549933c5044SSudeep Holla struct scmi_driver { 550933c5044SSudeep Holla const char *name; 551933c5044SSudeep Holla int (*probe)(struct scmi_device *sdev); 552933c5044SSudeep Holla void (*remove)(struct scmi_device *sdev); 553933c5044SSudeep Holla const struct scmi_device_id *id_table; 554933c5044SSudeep Holla 555933c5044SSudeep Holla struct device_driver driver; 556933c5044SSudeep Holla }; 557933c5044SSudeep Holla 558933c5044SSudeep Holla #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver) 559933c5044SSudeep Holla 56066d90f6eSSudeep Holla #if IS_REACHABLE(CONFIG_ARM_SCMI_PROTOCOL) 561933c5044SSudeep Holla int scmi_driver_register(struct scmi_driver *driver, 562933c5044SSudeep Holla struct module *owner, const char *mod_name); 563933c5044SSudeep Holla void scmi_driver_unregister(struct scmi_driver *driver); 564933c5044SSudeep Holla #else 565933c5044SSudeep Holla static inline int 566933c5044SSudeep Holla scmi_driver_register(struct scmi_driver *driver, struct module *owner, 567933c5044SSudeep Holla const char *mod_name) 568933c5044SSudeep Holla { 569933c5044SSudeep Holla return -EINVAL; 570933c5044SSudeep Holla } 571933c5044SSudeep Holla 572933c5044SSudeep Holla static inline void scmi_driver_unregister(struct scmi_driver *driver) {} 573933c5044SSudeep Holla #endif /* CONFIG_ARM_SCMI_PROTOCOL */ 574933c5044SSudeep Holla 575933c5044SSudeep Holla #define scmi_register(driver) \ 576933c5044SSudeep Holla scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) 577933c5044SSudeep Holla #define scmi_unregister(driver) \ 578933c5044SSudeep Holla scmi_driver_unregister(driver) 579933c5044SSudeep Holla 580933c5044SSudeep Holla /** 581933c5044SSudeep Holla * module_scmi_driver() - Helper macro for registering a scmi driver 582933c5044SSudeep Holla * @__scmi_driver: scmi_driver structure 583933c5044SSudeep Holla * 584933c5044SSudeep Holla * Helper macro for scmi drivers to set up proper module init / exit 585933c5044SSudeep Holla * functions. Replaces module_init() and module_exit() and keeps people from 586933c5044SSudeep Holla * printing pointless things to the kernel log when their driver is loaded. 587933c5044SSudeep Holla */ 588933c5044SSudeep Holla #define module_scmi_driver(__scmi_driver) \ 589933c5044SSudeep Holla module_driver(__scmi_driver, scmi_register, scmi_unregister) 590933c5044SSudeep Holla 591933c5044SSudeep Holla typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *); 592933c5044SSudeep Holla int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn); 593933c5044SSudeep Holla void scmi_protocol_unregister(int protocol_id); 59470771c69SSudeep Holla 595e27077bcSCristian Marussi /* SCMI Notification API - Custom Event Reports */ 596e27077bcSCristian Marussi enum scmi_notification_events { 597e27077bcSCristian Marussi SCMI_EVENT_POWER_STATE_CHANGED = 0x0, 598fb5086dcSCristian Marussi SCMI_EVENT_PERFORMANCE_LIMITS_CHANGED = 0x0, 599fb5086dcSCristian Marussi SCMI_EVENT_PERFORMANCE_LEVEL_CHANGED = 0x1, 600128e3e93SCristian Marussi SCMI_EVENT_SENSOR_TRIP_POINT_EVENT = 0x0, 601469ca182SCristian Marussi SCMI_EVENT_RESET_ISSUED = 0x0, 602585dfab3SCristian Marussi SCMI_EVENT_BASE_ERROR_EVENT = 0x0, 603a8803055SCristian Marussi SCMI_EVENT_SYSTEM_POWER_STATE_NOTIFIER = 0x0, 604e27077bcSCristian Marussi }; 605e27077bcSCristian Marussi 606e27077bcSCristian Marussi struct scmi_power_state_changed_report { 60772a5eb9dSCristian Marussi ktime_t timestamp; 60872a5eb9dSCristian Marussi unsigned int agent_id; 60972a5eb9dSCristian Marussi unsigned int domain_id; 61072a5eb9dSCristian Marussi unsigned int power_state; 611e27077bcSCristian Marussi }; 612e27077bcSCristian Marussi 613a8803055SCristian Marussi struct scmi_system_power_state_notifier_report { 614a8803055SCristian Marussi ktime_t timestamp; 615a8803055SCristian Marussi unsigned int agent_id; 616a8803055SCristian Marussi unsigned int flags; 617a8803055SCristian Marussi unsigned int system_state; 618a8803055SCristian Marussi }; 619a8803055SCristian Marussi 620fb5086dcSCristian Marussi struct scmi_perf_limits_report { 62172a5eb9dSCristian Marussi ktime_t timestamp; 62272a5eb9dSCristian Marussi unsigned int agent_id; 62372a5eb9dSCristian Marussi unsigned int domain_id; 62472a5eb9dSCristian Marussi unsigned int range_max; 62572a5eb9dSCristian Marussi unsigned int range_min; 626fb5086dcSCristian Marussi }; 627fb5086dcSCristian Marussi 628fb5086dcSCristian Marussi struct scmi_perf_level_report { 62972a5eb9dSCristian Marussi ktime_t timestamp; 63072a5eb9dSCristian Marussi unsigned int agent_id; 63172a5eb9dSCristian Marussi unsigned int domain_id; 63272a5eb9dSCristian Marussi unsigned int performance_level; 633fb5086dcSCristian Marussi }; 634fb5086dcSCristian Marussi 635128e3e93SCristian Marussi struct scmi_sensor_trip_point_report { 63672a5eb9dSCristian Marussi ktime_t timestamp; 63772a5eb9dSCristian Marussi unsigned int agent_id; 63872a5eb9dSCristian Marussi unsigned int sensor_id; 63972a5eb9dSCristian Marussi unsigned int trip_point_desc; 640128e3e93SCristian Marussi }; 641128e3e93SCristian Marussi 642469ca182SCristian Marussi struct scmi_reset_issued_report { 64372a5eb9dSCristian Marussi ktime_t timestamp; 64472a5eb9dSCristian Marussi unsigned int agent_id; 64572a5eb9dSCristian Marussi unsigned int domain_id; 64672a5eb9dSCristian Marussi unsigned int reset_state; 647469ca182SCristian Marussi }; 648469ca182SCristian Marussi 649585dfab3SCristian Marussi struct scmi_base_error_report { 65072a5eb9dSCristian Marussi ktime_t timestamp; 65172a5eb9dSCristian Marussi unsigned int agent_id; 652585dfab3SCristian Marussi bool fatal; 65372a5eb9dSCristian Marussi unsigned int cmd_count; 65472a5eb9dSCristian Marussi unsigned long long reports[]; 655585dfab3SCristian Marussi }; 656585dfab3SCristian Marussi 65770771c69SSudeep Holla #endif /* _LINUX_SCMI_PROTOCOL_H */ 658