Jacky Bai | d1806aa | 2023-09-21 11:06:34 +0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: BSD-3-Clause */ |
| 2 | /* |
| 3 | * Copyright 2023-2024 NXP |
| 4 | */ |
| 5 | |
| 6 | #ifndef SCMI_MSG_SENSOR_H |
| 7 | #define SCMI_MSG_SENSOR_H |
| 8 | |
| 9 | #include <stdint.h> |
| 10 | |
| 11 | #include <lib/utils_def.h> |
| 12 | |
| 13 | #define SCMI_PROTOCOL_VERSION_SENSOR 0x20000U |
| 14 | |
| 15 | /* |
| 16 | * Identifiers of the SCMI SENSOR Protocol commands |
| 17 | */ |
| 18 | enum scmi_sensor_command_id { |
| 19 | SCMI_SENSOR_DESCRIPTION_GET = 0x003, |
| 20 | SCMI_SENSOR_TRIP_POINT_NOTIFY = 0x004, |
| 21 | SCMI_SENSOR_TRIP_POINT_CONFIG = 0x005, |
| 22 | SCMI_SENSOR_READING_GET = 0x006, |
| 23 | SCMI_SENSOR_AXIS_DESCRIPTION_GET = 0x007, |
| 24 | SCMI_SENSOR_LIST_UPDATE_INTERVALS = 0x008, |
| 25 | SCMI_SENSOR_CONFIG_GET = 0x009, |
| 26 | SCMI_SENSOR_CONFIG_SET = 0x00A, |
| 27 | SCMI_SENSOR_CONTINUOUS_UPDATE_NOTIFY = 0x00B, |
| 28 | SCMI_SENSOR_MAX = 0x00C, |
| 29 | }; |
| 30 | |
| 31 | /* Protocol attributes */ |
| 32 | struct scmi_protocol_attributes_p2a_sensor { |
| 33 | int32_t status; |
| 34 | int16_t num_sensors; |
| 35 | uint8_t max_reqs; |
| 36 | uint8_t res; |
| 37 | uint32_t sensor_reg_low; |
| 38 | uint32_t sensor_reg_high; |
| 39 | uint32_t sensor_reg_len; |
| 40 | }; |
| 41 | |
| 42 | #define SCMI_SENSOR_NAME_LENGTH_MAX 16U |
| 43 | |
| 44 | struct scmi_sensor_desc { |
| 45 | uint32_t id; |
| 46 | uint32_t attr_low; |
| 47 | uint32_t attr_high; |
| 48 | uint8_t name[SCMI_SENSOR_NAME_LENGTH_MAX]; |
| 49 | uint32_t power; |
| 50 | uint32_t resolution; |
| 51 | int32_t min_range_low; |
| 52 | int32_t min_range_high; |
| 53 | int32_t max_range_low; |
| 54 | int32_t max_range_high; |
| 55 | }; |
| 56 | |
| 57 | struct scmi_sensor_description_get_a2p { |
| 58 | uint32_t desc_index; |
| 59 | }; |
| 60 | |
| 61 | struct scmi_sensor_description_get_p2a { |
| 62 | int32_t status; |
| 63 | uint32_t num_sensor_flags; |
| 64 | }; |
| 65 | |
| 66 | struct scmi_sensor_config_get_a2p { |
| 67 | uint32_t sensor_id; |
| 68 | }; |
| 69 | |
| 70 | struct scmi_sensor_config_get_p2a { |
| 71 | int32_t status; |
| 72 | uint32_t sensor_config; |
| 73 | }; |
| 74 | |
| 75 | /* |
| 76 | * Sensor Reading Get |
| 77 | */ |
| 78 | struct scmi_sensor_reading_get_a2p { |
| 79 | uint32_t sensor_id; |
| 80 | uint32_t flags; |
| 81 | }; |
| 82 | |
| 83 | struct scmi_sensor_val { |
| 84 | uint32_t value_low; |
| 85 | uint32_t value_high; |
| 86 | uint32_t timestap_low; |
| 87 | uint32_t timestap_high; |
| 88 | }; |
| 89 | |
| 90 | struct scmi_sensor_reading_get_p2a { |
| 91 | int32_t status; |
| 92 | struct scmi_sensor_val val; |
| 93 | }; |
| 94 | |
| 95 | typedef struct { |
| 96 | uint16_t (*sensor_count)(unsigned int agent_id); |
| 97 | uint8_t (*sensor_max_request)(unsigned int agent_id); |
| 98 | uint32_t (*get_sensor_req)(unsigned int agent_id, unsigned int *addr); |
| 99 | int32_t (*sensor_reading_get)(uint32_t agent_id, uint16_t sensor_id, |
| 100 | uint32_t *val); |
| 101 | uint32_t (*sensor_description_get)(unsigned int agent_id, uint16_t sensor_id, |
| 102 | struct scmi_sensor_desc *desc); |
| 103 | uint32_t (*sensor_update_interval)(uint32_t agent_id, uint16_t sensor_id); |
| 104 | uint32_t (*sensor_state)(uint32_t agent_id, uint16_t sensor_id); |
| 105 | uint16_t (*sensor_timestamped)(uint32_t agent_id, uint16_t sensor_id); |
| 106 | } plat_scmi_sensor_ops_t; |
| 107 | |
| 108 | #define REGISTER_SCMI_SENSOR_OPS(_sensor_count, _sensor_max_request, \ |
| 109 | _get_sensor_req, _sensor_reading_get, \ |
| 110 | _sensor_description_get, _sensor_update_interval, \ |
| 111 | _sensor_state, _sensor_timestamped) \ |
| 112 | const plat_scmi_sensor_ops_t sensor_ops = { \ |
| 113 | .sensor_count = _sensor_count, \ |
| 114 | .sensor_max_request = _sensor_max_request, \ |
| 115 | .get_sensor_req = _get_sensor_req, \ |
| 116 | .sensor_reading_get = _sensor_reading_get, \ |
| 117 | .sensor_description_get = _sensor_description_get, \ |
| 118 | .sensor_update_interval = _sensor_update_interval, \ |
| 119 | .sensor_state = _sensor_state, \ |
| 120 | .sensor_timestamped = _sensor_timestamped, \ |
| 121 | } |
| 122 | |
| 123 | extern const plat_scmi_sensor_ops_t sensor_ops; |
| 124 | |
| 125 | #endif /* SCMI_MSG_SENSOR_H */ |