14752544aSSudeep Holla /* SPDX-License-Identifier: GPL-2.0-only */ 2aa4f886fSSudeep Holla /* 3aa4f886fSSudeep Holla * SCMI Message Protocol driver header 4aa4f886fSSudeep Holla * 5aa4f886fSSudeep Holla * Copyright (C) 2018 ARM Ltd. 6aa4f886fSSudeep Holla */ 770771c69SSudeep Holla 870771c69SSudeep Holla #ifndef _LINUX_SCMI_PROTOCOL_H 970771c69SSudeep Holla #define _LINUX_SCMI_PROTOCOL_H 1070771c69SSudeep Holla 11933c5044SSudeep Holla #include <linux/device.h> 12aa4f886fSSudeep Holla #include <linux/types.h> 13aa4f886fSSudeep Holla 14b6f20ff8SSudeep Holla #define SCMI_MAX_STR_SIZE 16 155f6c6430SSudeep Holla #define SCMI_MAX_NUM_RATES 16 16b6f20ff8SSudeep Holla 17b6f20ff8SSudeep Holla /** 18b6f20ff8SSudeep Holla * struct scmi_revision_info - version information structure 19b6f20ff8SSudeep Holla * 20b6f20ff8SSudeep Holla * @major_ver: Major ABI version. Change here implies risk of backward 21b6f20ff8SSudeep Holla * compatibility break. 22b6f20ff8SSudeep Holla * @minor_ver: Minor ABI version. Change here implies new feature addition, 23b6f20ff8SSudeep Holla * or compatible change in ABI. 24b6f20ff8SSudeep Holla * @num_protocols: Number of protocols that are implemented, excluding the 25b6f20ff8SSudeep Holla * base protocol. 26b6f20ff8SSudeep Holla * @num_agents: Number of agents in the system. 27b6f20ff8SSudeep Holla * @impl_ver: A vendor-specific implementation version. 28b6f20ff8SSudeep Holla * @vendor_id: A vendor identifier(Null terminated ASCII string) 29b6f20ff8SSudeep Holla * @sub_vendor_id: A sub-vendor identifier(Null terminated ASCII string) 30b6f20ff8SSudeep Holla */ 31b6f20ff8SSudeep Holla struct scmi_revision_info { 32b6f20ff8SSudeep Holla u16 major_ver; 33b6f20ff8SSudeep Holla u16 minor_ver; 34b6f20ff8SSudeep Holla u8 num_protocols; 35b6f20ff8SSudeep Holla u8 num_agents; 36b6f20ff8SSudeep Holla u32 impl_ver; 37b6f20ff8SSudeep Holla char vendor_id[SCMI_MAX_STR_SIZE]; 38b6f20ff8SSudeep Holla char sub_vendor_id[SCMI_MAX_STR_SIZE]; 39b6f20ff8SSudeep Holla }; 40b6f20ff8SSudeep Holla 415f6c6430SSudeep Holla struct scmi_clock_info { 425f6c6430SSudeep Holla char name[SCMI_MAX_STR_SIZE]; 435f6c6430SSudeep Holla bool rate_discrete; 445f6c6430SSudeep Holla union { 455f6c6430SSudeep Holla struct { 465f6c6430SSudeep Holla int num_rates; 475f6c6430SSudeep Holla u64 rates[SCMI_MAX_NUM_RATES]; 485f6c6430SSudeep Holla } list; 495f6c6430SSudeep Holla struct { 505f6c6430SSudeep Holla u64 min_rate; 515f6c6430SSudeep Holla u64 max_rate; 525f6c6430SSudeep Holla u64 step_size; 535f6c6430SSudeep Holla } range; 545f6c6430SSudeep Holla }; 555f6c6430SSudeep Holla }; 565f6c6430SSudeep Holla 57a9e3fbfaSSudeep Holla struct scmi_handle; 58a9e3fbfaSSudeep Holla 59a9e3fbfaSSudeep Holla /** 605f6c6430SSudeep Holla * struct scmi_clk_ops - represents the various operations provided 615f6c6430SSudeep Holla * by SCMI Clock Protocol 625f6c6430SSudeep Holla * 635f6c6430SSudeep Holla * @count_get: get the count of clocks provided by SCMI 645f6c6430SSudeep Holla * @info_get: get the information of the specified clock 655f6c6430SSudeep Holla * @rate_get: request the current clock rate of a clock 665f6c6430SSudeep Holla * @rate_set: set the clock rate of a clock 675f6c6430SSudeep Holla * @enable: enables the specified clock 685f6c6430SSudeep Holla * @disable: disables the specified clock 695f6c6430SSudeep Holla */ 705f6c6430SSudeep Holla struct scmi_clk_ops { 715f6c6430SSudeep Holla int (*count_get)(const struct scmi_handle *handle); 725f6c6430SSudeep Holla 735f6c6430SSudeep Holla const struct scmi_clock_info *(*info_get) 745f6c6430SSudeep Holla (const struct scmi_handle *handle, u32 clk_id); 755f6c6430SSudeep Holla int (*rate_get)(const struct scmi_handle *handle, u32 clk_id, 765f6c6430SSudeep Holla u64 *rate); 775f6c6430SSudeep Holla int (*rate_set)(const struct scmi_handle *handle, u32 clk_id, 78d0aba116SSudeep Holla u64 rate); 795f6c6430SSudeep Holla int (*enable)(const struct scmi_handle *handle, u32 clk_id); 805f6c6430SSudeep Holla int (*disable)(const struct scmi_handle *handle, u32 clk_id); 815f6c6430SSudeep Holla }; 825f6c6430SSudeep Holla 835f6c6430SSudeep Holla /** 84a9e3fbfaSSudeep Holla * struct scmi_perf_ops - represents the various operations provided 85a9e3fbfaSSudeep Holla * by SCMI Performance Protocol 86a9e3fbfaSSudeep Holla * 87a9e3fbfaSSudeep Holla * @limits_set: sets limits on the performance level of a domain 88a9e3fbfaSSudeep Holla * @limits_get: gets limits on the performance level of a domain 89a9e3fbfaSSudeep Holla * @level_set: sets the performance level of a domain 90a9e3fbfaSSudeep Holla * @level_get: gets the performance level of a domain 91a9e3fbfaSSudeep Holla * @device_domain_id: gets the scmi domain id for a given device 927859e08cSSudeep Holla * @transition_latency_get: gets the DVFS transition latency for a given device 937859e08cSSudeep Holla * @device_opps_add: adds all the OPPs for a given device 94a9e3fbfaSSudeep Holla * @freq_set: sets the frequency for a given device using sustained frequency 95a9e3fbfaSSudeep Holla * to sustained performance level mapping 96a9e3fbfaSSudeep Holla * @freq_get: gets the frequency for a given device using sustained frequency 97a9e3fbfaSSudeep Holla * to sustained performance level mapping 981a63fe9aSQuentin Perret * @est_power_get: gets the estimated power cost for a given performance domain 991a63fe9aSQuentin Perret * at a given frequency 100a9e3fbfaSSudeep Holla */ 101a9e3fbfaSSudeep Holla struct scmi_perf_ops { 102a9e3fbfaSSudeep Holla int (*limits_set)(const struct scmi_handle *handle, u32 domain, 103a9e3fbfaSSudeep Holla u32 max_perf, u32 min_perf); 104a9e3fbfaSSudeep Holla int (*limits_get)(const struct scmi_handle *handle, u32 domain, 105a9e3fbfaSSudeep Holla u32 *max_perf, u32 *min_perf); 106a9e3fbfaSSudeep Holla int (*level_set)(const struct scmi_handle *handle, u32 domain, 1075c4ba3ccSSudeep Holla u32 level, bool poll); 108a9e3fbfaSSudeep Holla int (*level_get)(const struct scmi_handle *handle, u32 domain, 1095c4ba3ccSSudeep Holla u32 *level, bool poll); 110a9e3fbfaSSudeep Holla int (*device_domain_id)(struct device *dev); 1117859e08cSSudeep Holla int (*transition_latency_get)(const struct scmi_handle *handle, 112a9e3fbfaSSudeep Holla struct device *dev); 1137859e08cSSudeep Holla int (*device_opps_add)(const struct scmi_handle *handle, 114a9e3fbfaSSudeep Holla struct device *dev); 115a9e3fbfaSSudeep Holla int (*freq_set)(const struct scmi_handle *handle, u32 domain, 1165c4ba3ccSSudeep Holla unsigned long rate, bool poll); 117a9e3fbfaSSudeep Holla int (*freq_get)(const struct scmi_handle *handle, u32 domain, 1185c4ba3ccSSudeep Holla unsigned long *rate, bool poll); 1191a63fe9aSQuentin Perret int (*est_power_get)(const struct scmi_handle *handle, u32 domain, 1201a63fe9aSQuentin Perret unsigned long *rate, unsigned long *power); 1211909872fSNicola Mazzucato bool (*fast_switch_possible)(const struct scmi_handle *handle, 1221909872fSNicola Mazzucato struct device *dev); 123a9e3fbfaSSudeep Holla }; 124a9e3fbfaSSudeep Holla 125aa4f886fSSudeep Holla /** 12676a65509SSudeep Holla * struct scmi_power_ops - represents the various operations provided 12776a65509SSudeep Holla * by SCMI Power Protocol 12876a65509SSudeep Holla * 12976a65509SSudeep Holla * @num_domains_get: get the count of power domains provided by SCMI 13076a65509SSudeep Holla * @name_get: gets the name of a power domain 13176a65509SSudeep Holla * @state_set: sets the power state of a power domain 13276a65509SSudeep Holla * @state_get: gets the power state of a power domain 13376a65509SSudeep Holla */ 13476a65509SSudeep Holla struct scmi_power_ops { 13576a65509SSudeep Holla int (*num_domains_get)(const struct scmi_handle *handle); 13676a65509SSudeep Holla char *(*name_get)(const struct scmi_handle *handle, u32 domain); 13776a65509SSudeep Holla #define SCMI_POWER_STATE_TYPE_SHIFT 30 13876a65509SSudeep Holla #define SCMI_POWER_STATE_ID_MASK (BIT(28) - 1) 13976a65509SSudeep Holla #define SCMI_POWER_STATE_PARAM(type, id) \ 14076a65509SSudeep Holla ((((type) & BIT(0)) << SCMI_POWER_STATE_TYPE_SHIFT) | \ 14176a65509SSudeep Holla ((id) & SCMI_POWER_STATE_ID_MASK)) 14276a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_ON SCMI_POWER_STATE_PARAM(0, 0) 14376a65509SSudeep Holla #define SCMI_POWER_STATE_GENERIC_OFF SCMI_POWER_STATE_PARAM(1, 0) 14476a65509SSudeep Holla int (*state_set)(const struct scmi_handle *handle, u32 domain, 14576a65509SSudeep Holla u32 state); 14676a65509SSudeep Holla int (*state_get)(const struct scmi_handle *handle, u32 domain, 14776a65509SSudeep Holla u32 *state); 14876a65509SSudeep Holla }; 14976a65509SSudeep Holla 1505179c523SSudeep Holla struct scmi_sensor_info { 1515179c523SSudeep Holla u32 id; 1525179c523SSudeep Holla u8 type; 1530b673b64SFlorian Fainelli s8 scale; 154d09aac0eSSudeep Holla u8 num_trip_points; 155d09aac0eSSudeep Holla bool async; 1565179c523SSudeep Holla char name[SCMI_MAX_STR_SIZE]; 1575179c523SSudeep Holla }; 1585179c523SSudeep Holla 1595179c523SSudeep Holla /* 1605179c523SSudeep Holla * Partial list from Distributed Management Task Force (DMTF) specification: 1615179c523SSudeep Holla * DSP0249 (Platform Level Data Model specification) 1625179c523SSudeep Holla */ 1635179c523SSudeep Holla enum scmi_sensor_class { 1645179c523SSudeep Holla NONE = 0x0, 1655179c523SSudeep Holla TEMPERATURE_C = 0x2, 1665179c523SSudeep Holla VOLTAGE = 0x5, 1675179c523SSudeep Holla CURRENT = 0x6, 1685179c523SSudeep Holla POWER = 0x7, 1695179c523SSudeep Holla ENERGY = 0x8, 1705179c523SSudeep Holla }; 1715179c523SSudeep Holla 1725179c523SSudeep Holla /** 1735179c523SSudeep Holla * struct scmi_sensor_ops - represents the various operations provided 1745179c523SSudeep Holla * by SCMI Sensor Protocol 1755179c523SSudeep Holla * 1765179c523SSudeep Holla * @count_get: get the count of sensors provided by SCMI 1775179c523SSudeep Holla * @info_get: get the information of the specified sensor 1789eefa43aSSudeep Holla * @trip_point_notify: control notifications on cross-over events for 1795179c523SSudeep Holla * the trip-points 1809eefa43aSSudeep Holla * @trip_point_config: selects and configures a trip-point of interest 1815179c523SSudeep Holla * @reading_get: gets the current value of the sensor 1825179c523SSudeep Holla */ 1835179c523SSudeep Holla struct scmi_sensor_ops { 1845179c523SSudeep Holla int (*count_get)(const struct scmi_handle *handle); 1855179c523SSudeep Holla 1865179c523SSudeep Holla const struct scmi_sensor_info *(*info_get) 1875179c523SSudeep Holla (const struct scmi_handle *handle, u32 sensor_id); 1889eefa43aSSudeep Holla int (*trip_point_notify)(const struct scmi_handle *handle, 1899eefa43aSSudeep Holla u32 sensor_id, bool enable); 1909eefa43aSSudeep Holla int (*trip_point_config)(const struct scmi_handle *handle, 1919eefa43aSSudeep Holla u32 sensor_id, u8 trip_id, u64 trip_value); 1925179c523SSudeep Holla int (*reading_get)(const struct scmi_handle *handle, u32 sensor_id, 1936a55331cSSudeep Holla u64 *value); 1945179c523SSudeep Holla }; 1955179c523SSudeep Holla 19676a65509SSudeep Holla /** 19795a15d80SSudeep Holla * struct scmi_reset_ops - represents the various operations provided 19895a15d80SSudeep Holla * by SCMI Reset Protocol 19995a15d80SSudeep Holla * 20095a15d80SSudeep Holla * @num_domains_get: get the count of reset domains provided by SCMI 20195a15d80SSudeep Holla * @name_get: gets the name of a reset domain 20295a15d80SSudeep Holla * @latency_get: gets the reset latency for the specified reset domain 20395a15d80SSudeep Holla * @reset: resets the specified reset domain 20495a15d80SSudeep Holla * @assert: explicitly assert reset signal of the specified reset domain 20595a15d80SSudeep Holla * @deassert: explicitly deassert reset signal of the specified reset domain 20695a15d80SSudeep Holla */ 20795a15d80SSudeep Holla struct scmi_reset_ops { 20895a15d80SSudeep Holla int (*num_domains_get)(const struct scmi_handle *handle); 20995a15d80SSudeep Holla char *(*name_get)(const struct scmi_handle *handle, u32 domain); 21095a15d80SSudeep Holla int (*latency_get)(const struct scmi_handle *handle, u32 domain); 21195a15d80SSudeep Holla int (*reset)(const struct scmi_handle *handle, u32 domain); 21295a15d80SSudeep Holla int (*assert)(const struct scmi_handle *handle, u32 domain); 21395a15d80SSudeep Holla int (*deassert)(const struct scmi_handle *handle, u32 domain); 21495a15d80SSudeep Holla }; 21595a15d80SSudeep Holla 21695a15d80SSudeep Holla /** 217aa4f886fSSudeep Holla * struct scmi_handle - Handle returned to ARM SCMI clients for usage. 218aa4f886fSSudeep Holla * 219aa4f886fSSudeep Holla * @dev: pointer to the SCMI device 220b6f20ff8SSudeep Holla * @version: pointer to the structure containing SCMI version information 22176a65509SSudeep Holla * @power_ops: pointer to set of power protocol operations 222a9e3fbfaSSudeep Holla * @perf_ops: pointer to set of performance protocol operations 2235f6c6430SSudeep Holla * @clk_ops: pointer to set of clock protocol operations 2245179c523SSudeep Holla * @sensor_ops: pointer to set of sensor protocol operations 22595a15d80SSudeep Holla * @reset_ops: pointer to set of reset protocol operations 2261baf47c2SSudeep Holla * @perf_priv: pointer to private data structure specific to performance 2271baf47c2SSudeep Holla * protocol(for internal use only) 2281baf47c2SSudeep Holla * @clk_priv: pointer to private data structure specific to clock 2291baf47c2SSudeep Holla * protocol(for internal use only) 2301baf47c2SSudeep Holla * @power_priv: pointer to private data structure specific to power 2311baf47c2SSudeep Holla * protocol(for internal use only) 2321baf47c2SSudeep Holla * @sensor_priv: pointer to private data structure specific to sensors 2331baf47c2SSudeep Holla * protocol(for internal use only) 23495a15d80SSudeep Holla * @reset_priv: pointer to private data structure specific to reset 23595a15d80SSudeep Holla * protocol(for internal use only) 2361fc2dd18SCristian Marussi * @notify_priv: pointer to private data structure specific to notifications 2371fc2dd18SCristian Marussi * (for internal use only) 238aa4f886fSSudeep Holla */ 239aa4f886fSSudeep Holla struct scmi_handle { 240aa4f886fSSudeep Holla struct device *dev; 241b6f20ff8SSudeep Holla struct scmi_revision_info *version; 242a9e3fbfaSSudeep Holla struct scmi_perf_ops *perf_ops; 2435f6c6430SSudeep Holla struct scmi_clk_ops *clk_ops; 24476a65509SSudeep Holla struct scmi_power_ops *power_ops; 2455179c523SSudeep Holla struct scmi_sensor_ops *sensor_ops; 24695a15d80SSudeep Holla struct scmi_reset_ops *reset_ops; 247a9e3fbfaSSudeep Holla /* for protocol internal use */ 248a9e3fbfaSSudeep Holla void *perf_priv; 2495f6c6430SSudeep Holla void *clk_priv; 25076a65509SSudeep Holla void *power_priv; 2515179c523SSudeep Holla void *sensor_priv; 25295a15d80SSudeep Holla void *reset_priv; 2531fc2dd18SCristian Marussi void *notify_priv; 254b6f20ff8SSudeep Holla }; 255b6f20ff8SSudeep Holla 256b6f20ff8SSudeep Holla enum scmi_std_protocol { 257b6f20ff8SSudeep Holla SCMI_PROTOCOL_BASE = 0x10, 258b6f20ff8SSudeep Holla SCMI_PROTOCOL_POWER = 0x11, 259b6f20ff8SSudeep Holla SCMI_PROTOCOL_SYSTEM = 0x12, 260b6f20ff8SSudeep Holla SCMI_PROTOCOL_PERF = 0x13, 261b6f20ff8SSudeep Holla SCMI_PROTOCOL_CLOCK = 0x14, 262b6f20ff8SSudeep Holla SCMI_PROTOCOL_SENSOR = 0x15, 26395a15d80SSudeep Holla SCMI_PROTOCOL_RESET = 0x16, 264aa4f886fSSudeep Holla }; 265933c5044SSudeep Holla 266933c5044SSudeep Holla struct scmi_device { 267933c5044SSudeep Holla u32 id; 268933c5044SSudeep Holla u8 protocol_id; 269ee7a9c9fSSudeep Holla const char *name; 270933c5044SSudeep Holla struct device dev; 271933c5044SSudeep Holla struct scmi_handle *handle; 272933c5044SSudeep Holla }; 273933c5044SSudeep Holla 274933c5044SSudeep Holla #define to_scmi_dev(d) container_of(d, struct scmi_device, dev) 275933c5044SSudeep Holla 276933c5044SSudeep Holla struct scmi_device * 277ee7a9c9fSSudeep Holla scmi_device_create(struct device_node *np, struct device *parent, int protocol, 278ee7a9c9fSSudeep Holla const char *name); 279933c5044SSudeep Holla void scmi_device_destroy(struct scmi_device *scmi_dev); 280933c5044SSudeep Holla 281933c5044SSudeep Holla struct scmi_device_id { 282933c5044SSudeep Holla u8 protocol_id; 283ee7a9c9fSSudeep Holla const char *name; 284933c5044SSudeep Holla }; 285933c5044SSudeep Holla 286933c5044SSudeep Holla struct scmi_driver { 287933c5044SSudeep Holla const char *name; 288933c5044SSudeep Holla int (*probe)(struct scmi_device *sdev); 289933c5044SSudeep Holla void (*remove)(struct scmi_device *sdev); 290933c5044SSudeep Holla const struct scmi_device_id *id_table; 291933c5044SSudeep Holla 292933c5044SSudeep Holla struct device_driver driver; 293933c5044SSudeep Holla }; 294933c5044SSudeep Holla 295933c5044SSudeep Holla #define to_scmi_driver(d) container_of(d, struct scmi_driver, driver) 296933c5044SSudeep Holla 297933c5044SSudeep Holla #ifdef CONFIG_ARM_SCMI_PROTOCOL 298933c5044SSudeep Holla int scmi_driver_register(struct scmi_driver *driver, 299933c5044SSudeep Holla struct module *owner, const char *mod_name); 300933c5044SSudeep Holla void scmi_driver_unregister(struct scmi_driver *driver); 301933c5044SSudeep Holla #else 302933c5044SSudeep Holla static inline int 303933c5044SSudeep Holla scmi_driver_register(struct scmi_driver *driver, struct module *owner, 304933c5044SSudeep Holla const char *mod_name) 305933c5044SSudeep Holla { 306933c5044SSudeep Holla return -EINVAL; 307933c5044SSudeep Holla } 308933c5044SSudeep Holla 309933c5044SSudeep Holla static inline void scmi_driver_unregister(struct scmi_driver *driver) {} 310933c5044SSudeep Holla #endif /* CONFIG_ARM_SCMI_PROTOCOL */ 311933c5044SSudeep Holla 312933c5044SSudeep Holla #define scmi_register(driver) \ 313933c5044SSudeep Holla scmi_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) 314933c5044SSudeep Holla #define scmi_unregister(driver) \ 315933c5044SSudeep Holla scmi_driver_unregister(driver) 316933c5044SSudeep Holla 317933c5044SSudeep Holla /** 318933c5044SSudeep Holla * module_scmi_driver() - Helper macro for registering a scmi driver 319933c5044SSudeep Holla * @__scmi_driver: scmi_driver structure 320933c5044SSudeep Holla * 321933c5044SSudeep Holla * Helper macro for scmi drivers to set up proper module init / exit 322933c5044SSudeep Holla * functions. Replaces module_init() and module_exit() and keeps people from 323933c5044SSudeep Holla * printing pointless things to the kernel log when their driver is loaded. 324933c5044SSudeep Holla */ 325933c5044SSudeep Holla #define module_scmi_driver(__scmi_driver) \ 326933c5044SSudeep Holla module_driver(__scmi_driver, scmi_register, scmi_unregister) 327933c5044SSudeep Holla 328933c5044SSudeep Holla typedef int (*scmi_prot_init_fn_t)(struct scmi_handle *); 329933c5044SSudeep Holla int scmi_protocol_register(int protocol_id, scmi_prot_init_fn_t fn); 330933c5044SSudeep Holla void scmi_protocol_unregister(int protocol_id); 33170771c69SSudeep Holla 33270771c69SSudeep Holla #endif /* _LINUX_SCMI_PROTOCOL_H */ 333