1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef MOD_N1SDP_SENSOR_DRIVER_H
9 #define MOD_N1SDP_SENSOR_DRIVER_H
10 
11 #include <mod_n1sdp_sensor.h>
12 
13 #define PVT_HISTORY_LEN 64
14 
15 /* Temperature sensor context */
16 struct n1sdp_temp_sensor_ctx {
17     /* Pointer to temperature sensor config */
18     struct mod_n1sdp_temp_sensor_config *config;
19 
20     /* Pointer to history of temperature sensor values */
21     int32_t *sensor_data_buffer;
22 
23     /* Buffer index pointing to latest temperature value */
24     uint8_t buf_index;
25 };
26 
27 /* Voltage sensor context */
28 struct n1sdp_volt_sensor_ctx {
29     /* Pointer to voltage sensor config */
30     struct mod_n1sdp_volt_sensor_config *config;
31 
32     /* Pointer to history of voltage sensor values */
33     int32_t *sensor_data_buffer;
34 
35     /* Buffer index pointing to latest voltage value */
36     uint8_t buf_index;
37 };
38 
39 /* N1SDP Sensor module context */
40 struct n1sdp_sensor_ctx {
41     /* Pointer to module configuration data */
42     struct mod_n1sdp_sensor_config *module_config;
43 
44     /* Table of temperature sensor contexts */
45     struct n1sdp_temp_sensor_ctx *t_dev_ctx_table;
46 
47     /* Table of voltage sensor contexts */
48     struct n1sdp_volt_sensor_ctx *v_dev_ctx_table;
49 
50     /* Pointer to timer alarm API */
51     struct mod_timer_alarm_api *timer_alarm_api;
52 
53     /* Pointer to SCP2PCC API */
54     struct mod_n1sdp_scp2pcc_api *scp2pcc_api;
55 };
56 
57 static const char *const sensor_type_name[] = {
58     [MOD_N1SDP_TEMP_SENSOR_IDX_CLUSTER0] = "T-CLUS0",
59     [MOD_N1SDP_TEMP_SENSOR_IDX_CLUSTER1] = "T-CLUS1",
60     [MOD_N1SDP_TEMP_SENSOR_IDX_SYSTEM] = "T-SYS",
61     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS0CORE0] = "V-CLUS0CORE0",
62     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS0CORE1] = "V-CLUS0CORE1",
63     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS1CORE0] = "V-CLUS1CORE0",
64     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS1CORE1] = "V-CLUS1CORE1",
65     [MOD_N1SDP_VOLT_SENSOR_IDX_SYSTEM] = "V-SYS",
66 };
67 
68 int n1sdp_sensor_lib_sample(int32_t *value, int sensor_type, int offset);
69 void n1sdp_sensor_lib_trigger_sample(int sensor_type);
70 int n1sdp_sensor_lib_init(uint32_t *msg);
71 
72 #endif
73