1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * SCMI Message Protocol driver header 4 * 5 * Copyright (C) 2018 ARM Ltd. 6 */ 7 8 #ifndef _LINUX_SCMI_PROTOCOL_H 9 #define _LINUX_SCMI_PROTOCOL_H 10 11 #include <linux/device.h> 12 #include <linux/types.h> 13 14 #define SCMI_MAX_STR_SIZE 16 15 #define SCMI_MAX_NUM_RATES 16 16 17 /** 18 * struct scmi_revision_info - version information structure 19 * 20 * @major_ver: Major ABI version. Change here implies risk of backward 21 * compatibility break. 22 * @minor_ver: Minor ABI version. Change here implies new feature addition, 23 * or compatible change in ABI. 24 * @num_protocols: Number of protocols that are implemented, excluding the 25 * base protocol. 26 * @num_agents: Number of agents in the system. 27 * @impl_ver: A vendor-specific implementation version. 28 * @vendor_id: A vendor identifier(Null terminated ASCII string) 29 * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string) 30 */ 31 struct scmi_revision_info { 32 u16 major_ver; 33 u16 minor_ver; 34 u8 num_protocols; 35 u8 num_agents; 36 u32 impl_ver; 37 char vendor_id[SCMI_MAX_STR_SIZE]; 38 char sub_vendor_id[SCMI_MAX_STR_SIZE]; 39 }; 40 41 struct scmi_clock_info { 42 char name[SCMI_MAX_STR_SIZE]; 43 bool rate_discrete; 44 union { 45 struct { 46 int num_rates; 47 u64 rates[SCMI_MAX_NUM_RATES]; 48 } list; 49 struct { 50 u64 min_rate; 51 u64 max_rate; 52 u64 step_size; 53 } range; 54 }; 55 }; 56 57 struct scmi_handle; 58 59 /** 60 * struct scmi_clk_ops - represents the various operations provided 61 * by SCMI Clock Protocol 62 * 63 * @count_get: get the count of clocks provided by SCMI 64 * @info_get: get the information of the specified clock 65 * @rate_get: request the current clock rate of a clock 66 * @rate_set: set the clock rate of a clock 67 * @enable: enables the specified clock 68 * @disable: disables the specified clock 69 */ 70 struct scmi_clk_ops { 71 int (*count_get)(const struct scmi_handle *handle); 72 73 const struct scmi_clock_info *(*info_get) 74 (const struct scmi_handle *handle, u32 clk_id); 75 int (*rate_get)(const struct scmi_handle *handle, u32 clk_id, 76 u64 *rate); 77 int (*rate_set)(const struct scmi_handle *handle, u32 clk_id, 78 u64 rate); 79 int (*enable)(const struct scmi_handle *handle, u32 clk_id); 80 int (*disable)(const struct scmi_handle *handle, u32 clk_id); 81 }; 82 83 /** 84 * struct scmi_perf_ops - represents the various operations provided 85 * by SCMI Performance Protocol 86 * 87 * @limits_set: sets limits on the performance level of a domain 88 * @limits_get: gets limits on the performance level of a domain 89 * @level_set: sets the performance level of a domain 90 * @level_get: gets the performance level of a domain 91 * @device_domain_id: gets the scmi domain id for a given device 92 * @transition_latency_get: gets the DVFS transition latency for a given device 93 * @device_opps_add: adds all the OPPs for a given device 94 * @freq_set: sets the frequency for a given device using sustained frequency 95 * to sustained performance level mapping 96 * @freq_get: gets the frequency for a given device using sustained frequency 97 * to sustained performance level mapping 98 * @est_power_get: gets the estimated power cost for a given performance domain 99 * at a given frequency 100 */ 101 struct scmi_perf_ops { 102 int (*limits_set)(const struct scmi_handle *handle, u32 domain, 103 u32 max_perf, u32 min_perf); 104 int (*limits_get)(const struct scmi_handle *handle, u32 domain, 105 u32 *max_perf, u32 *min_perf); 106 int (*level_set)(const struct scmi_handle *handle, u32 domain, 107 u32 level, bool poll); 108 int (*level_get)(const struct scmi_handle *handle, u32 domain, 109 u32 *level, bool poll); 110 int (*device_domain_id)(struct device *dev); 111 int (*transition_latency_get)(const struct scmi_handle *handle, 112 struct device *dev); 113 int (*device_opps_add)(const struct scmi_handle *handle, 114 struct device *dev); 115 int (*freq_set)(const struct scmi_handle *handle, u32 domain, 116 unsigned long rate, bool poll); 117 int (*freq_get)(const struct scmi_handle *handle, u32 domain, 118 unsigned long *rate, bool poll); 119 int (*est_power_get)(const struct scmi_handle *handle, u32 domain, 120 unsigned long *rate, unsigned long *power); 121 }; 122 123 /** 124 * struct scmi_power_ops - represents the various operations provided 125 * by SCMI Power Protocol 126 * 127 * @num_domains_get: get the count of power domains provided by SCMI 128 * @name_get: gets the name of a power domain 129 * @state_set: sets the power state of a power domain 130 * @state_get: gets the power state of a power domain 131 */ 132 struct scmi_power_ops { 133 int (*num_domains_get)(const struct scmi_handle *handle); 134 char *(*name_get)(const struct scmi_handle *handle, u32 domain); 135 #define SCMI_POWER_STATE_TYPE_SHIFT 30 136 #define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1) 137 #define SCMI_POWER_STATE_PARAM(type, id) \ 138 ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \ 139 ((id) & SCMI_POWER_STATE_ID_MASK)) 140 #define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0) 141 #define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0) 142 int (*state_set)(const struct scmi_handle *handle, u32 domain, 143 u32 state); 144 int (*state_get)(const struct scmi_handle *handle, u32 domain, 145 u32 *state); 146 }; 147 148 struct scmi_sensor_info { 149 u32 id; 150 u8 type; 151 s8 scale; 152 u8 num_trip_points; 153 bool async; 154 char name[SCMI_MAX_STR_SIZE]; 155 }; 156 157 /* 158 * Partial list from Distributed Management Task Force (DMTF) specification: 159 * DSP0249 (Platform Level Data Model specification) 160 */ 161 enum scmi_sensor_class { 162 NONE = 0x0, 163 TEMPERATURE_C = 0x2, 164 VOLTAGE = 0x5, 165 CURRENT = 0x6, 166 POWER = 0x7, 167 ENERGY = 0x8, 168 }; 169 170 /** 171 * struct scmi_sensor_ops - represents the various operations provided 172 * by SCMI Sensor Protocol 173 * 174 * @count_get: get the count of sensors provided by SCMI 175 * @info_get: get the information of the specified sensor 176 * @trip_point_notify: control notifications on cross-over events for 177 * the trip-points 178 * @trip_point_config: selects and configures a trip-point of interest 179 * @reading_get: gets the current value of the sensor 180 */ 181 struct scmi_sensor_ops { 182 int (*count_get)(const struct scmi_handle *handle); 183 184 const struct scmi_sensor_info *(*info_get) 185 (const struct scmi_handle *handle, u32 sensor_id); 186 int (*trip_point_notify)(const struct scmi_handle *handle, 187 u32 sensor_id, bool enable); 188 int (*trip_point_config)(const struct scmi_handle *handle, 189 u32 sensor_id, u8 trip_id, u64 trip_value); 190 int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id, 191 u64 *value); 192 }; 193 194 /** 195 * struct scmi_reset_ops - represents the various operations provided 196 * by SCMI Reset Protocol 197 * 198 * @num_domains_get: get the count of reset domains provided by SCMI 199 * @name_get: gets the name of a reset domain 200 * @latency_get: gets the reset latency for the specified reset domain 201 * @reset: resets the specified reset domain 202 * @assert: explicitly assert reset signal of the specified reset domain 203 * @deassert: explicitly deassert reset signal of the specified reset domain 204 */ 205 struct scmi_reset_ops { 206 int (*num_domains_get)(const struct scmi_handle *handle); 207 char *(*name_get)(const struct scmi_handle *handle, u32 domain); 208 int (*latency_get)(const struct scmi_handle *handle, u32 domain); 209 int (*reset)(const struct scmi_handle *handle, u32 domain); 210 int (*assert)(const struct scmi_handle *handle, u32 domain); 211 int (*deassert)(const struct scmi_handle *handle, u32 domain); 212 }; 213 214 /** 215 * struct scmi_handle - Handle returned to ARM SCMI clients for usage. 216 * 217 * @dev: pointer to the SCMI device 218 * @version: pointer to the structure containing SCMI version information 219 * @power_ops: pointer to set of power protocol operations 220 * @perf_ops: pointer to set of performance protocol operations 221 * @clk_ops: pointer to set of clock protocol operations 222 * @sensor_ops: pointer to set of sensor protocol operations 223 * @reset_ops: pointer to set of reset protocol operations 224 * @perf_priv: pointer to private data structure specific to performance 225 * protocol(for internal use only) 226 * @clk_priv: pointer to private data structure specific to clock 227 * protocol(for internal use only) 228 * @power_priv: pointer to private data structure specific to power 229 * protocol(for internal use only) 230 * @sensor_priv: pointer to private data structure specific to sensors 231 * protocol(for internal use only) 232 * @reset_priv: pointer to private data structure specific to reset 233 * protocol(for internal use only) 234 */ 235 struct scmi_handle { 236 struct device *dev; 237 struct scmi_revision_info *version; 238 struct scmi_perf_ops *perf_ops; 239 struct scmi_clk_ops *clk_ops; 240 struct scmi_power_ops *power_ops; 241 struct scmi_sensor_ops *sensor_ops; 242 struct scmi_reset_ops *reset_ops; 243 /* for protocol internal use */ 244 void *perf_priv; 245 void *clk_priv; 246 void *power_priv; 247 void *sensor_priv; 248 void *reset_priv; 249 }; 250 251 enum scmi_std_protocol { 252 SCMI_PROTOCOL_BASE = 0x10, 253 SCMI_PROTOCOL_POWER = 0x11, 254 SCMI_PROTOCOL_SYSTEM = 0x12, 255 SCMI_PROTOCOL_PERF = 0x13, 256 SCMI_PROTOCOL_CLOCK = 0x14, 257 SCMI_PROTOCOL_SENSOR = 0x15, 258 SCMI_PROTOCOL_RESET = 0x16, 259 }; 260 261 struct scmi_device { 262 u32 id; 263 u8 protocol_id; 264 const char *name; 265 struct device dev; 266 struct scmi_handle *handle; 267 }; 268 269 #define to_scmi_dev(d) container_of(d, struct scmi_device, dev) 270 271 struct scmi_device * 272 scmi_device_create(struct device_node *np, struct device *parent, int protocol, 273 const char *name); 274 void scmi_device_destroy(struct scmi_device *scmi_dev); 275 276 struct scmi_device_id { 277 u8 protocol_id; 278 const char *name; 279 }; 280 281 struct scmi_driver { 282 const char *name; 283 int (*probe)(struct scmi_device *sdev); 284 void (*remove)(struct scmi_device *sdev); 285 const struct scmi_device_id *id_table; 286 287 struct device_driver driver; 288 }; 289 290 #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver) 291 292 #ifdef CONFIG_ARM_SCMI_PROTOCOL 293 int scmi_driver_register(struct scmi_driver *driver, 294 struct module *owner, const char *mod_name); 295 void scmi_driver_unregister(struct scmi_driver *driver); 296 #else 297 static inline int 298 scmi_driver_register(struct scmi_driver *driver, struct module *owner, 299 const char *mod_name) 300 { 301 return -EINVAL; 302 } 303 304 static inline void scmi_driver_unregister(struct scmi_driver *driver) {} 305 #endif /* CONFIG_ARM_SCMI_PROTOCOL */ 306 307 #define scmi_register(driver) \ 308 scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) 309 #define scmi_unregister(driver) \ 310 scmi_driver_unregister(driver) 311 312 /** 313 * module_scmi_driver() - Helper macro for registering a scmi driver 314 * @__scmi_driver: scmi_driver structure 315 * 316 * Helper macro for scmi drivers to set up proper module init / exit 317 * functions. Replaces module_init() and module_exit() and keeps people from 318 * printing pointless things to the kernel log when their driver is loaded. 319 */ 320 #define module_scmi_driver(__scmi_driver) \ 321 module_driver(__scmi_driver, scmi_register, scmi_unregister) 322 323 typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *); 324 int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn); 325 void scmi_protocol_unregister(int protocol_id); 326 327 #endif /* _LINUX_SCMI_PROTOCOL_H */ 328