1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2019-2021, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include <mod_n1sdp_sensor.h>
9 #include <mod_sensor.h>
10 #include <mod_timer.h>
11 
12 #include <fwk_element.h>
13 #include <fwk_id.h>
14 #include <fwk_module.h>
15 #include <fwk_module_idx.h>
16 
17 #include <stddef.h>
18 
19 /*
20  * N1SDP sensor driver config
21  */
22 
23 static struct mod_sensor_info info_temp_sensor = {
24     .type = MOD_SENSOR_TYPE_DEGREES_C,
25     .update_interval = 0,
26     .update_interval_multiplier = 0,
27     .unit_multiplier = 0,
28 };
29 
30 static struct mod_sensor_info info_volt_sensor = {
31     .type = MOD_SENSOR_TYPE_VOLTS,
32     .update_interval = 0,
33     .update_interval_multiplier = 0,
34     .unit_multiplier = 0,
35 };
36 
37 static const struct fwk_element n1sdp_sensor_element_table[] = {
38     [MOD_N1SDP_TEMP_SENSOR_IDX_CLUSTER0] = {
39         .name = "CLUS0 Temperature",
40         .data = &((struct mod_n1sdp_temp_sensor_config) {
41             .alarm_threshold = 70,
42             .shutdown_threshold = 80,
43             .info = &info_temp_sensor,
44         }),
45     },
46     [MOD_N1SDP_TEMP_SENSOR_IDX_CLUSTER1] = {
47         .name = "CLUS1 Temperature",
48         .data = &((struct mod_n1sdp_temp_sensor_config) {
49             .alarm_threshold = 70,
50             .shutdown_threshold = 80,
51             .info = &info_temp_sensor,
52         }),
53     },
54     [MOD_N1SDP_TEMP_SENSOR_IDX_SYSTEM] = {
55         .name = "SYS Temperature",
56         .data = &((struct mod_n1sdp_temp_sensor_config) {
57             .alarm_threshold = 70,
58             .shutdown_threshold = 80,
59             .info = &info_temp_sensor,
60         }),
61     },
62     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS0CORE0] = {
63         .name = "CLUS0CORE0 Voltage",
64         .data = &((struct mod_n1sdp_volt_sensor_config) {
65             .info = &info_volt_sensor,
66         }),
67     },
68     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS0CORE1] = {
69         .name = "CLUS0CORE1 Voltage",
70         .data = &((struct mod_n1sdp_volt_sensor_config) {
71             .info = &info_volt_sensor,
72         }),
73     },
74     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS1CORE0] = {
75         .name = "CLUS1CORE0 Voltage",
76         .data = &((struct mod_n1sdp_volt_sensor_config) {
77             .info = &info_volt_sensor,
78         }),
79     },
80     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS1CORE1] = {
81         .name = "CLUS1CORE1 Voltage",
82         .data = &((struct mod_n1sdp_volt_sensor_config) {
83             .info = &info_volt_sensor,
84         }),
85     },
86     [MOD_N1SDP_VOLT_SENSOR_IDX_SYSTEM] = {
87         .name = "SYS Voltage",
88         .data = &((struct mod_n1sdp_volt_sensor_config) {
89             .info = &info_volt_sensor,
90         }),
91     },
92     [MOD_N1SDP_VOLT_SENSOR_COUNT] = { 0 },
93 };
94 
get_n1sdp_sensor_element_table(fwk_id_t id)95 static const struct fwk_element *get_n1sdp_sensor_element_table(fwk_id_t id)
96 {
97     return n1sdp_sensor_element_table;
98 }
99 
100 struct fwk_module_config config_n1sdp_sensor = {
101     .data =
102         &(struct mod_n1sdp_sensor_config){
103             .alarm_id = FWK_ID_SUB_ELEMENT_INIT(FWK_MODULE_IDX_TIMER, 0, 0),
104             .alarm_api =
105                 FWK_ID_API_INIT(FWK_MODULE_IDX_TIMER, MOD_TIMER_API_IDX_ALARM),
106             .t_sensor_count = 3,
107             .v_sensor_count = 5,
108         },
109 
110     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(get_n1sdp_sensor_element_table),
111 };
112 
113 /*
114  * Sensor module config
115  */
116 static const struct fwk_element sensor_element_table[] = {
117     [MOD_N1SDP_TEMP_SENSOR_IDX_CLUSTER0] = {
118         .name = "CLUS0 Temperature",
119         .data = &((struct mod_sensor_dev_config) {
120             .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_N1SDP_SENSOR,
121                              MOD_N1SDP_TEMP_SENSOR_IDX_CLUSTER0),
122             .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_N1SDP_SENSOR, 0),
123         }),
124     },
125     [MOD_N1SDP_TEMP_SENSOR_IDX_CLUSTER1] = {
126         .name = "CLUS1 Temperature",
127         .data = &((struct mod_sensor_dev_config) {
128             .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_N1SDP_SENSOR,
129                              MOD_N1SDP_TEMP_SENSOR_IDX_CLUSTER1),
130             .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_N1SDP_SENSOR, 0),
131         }),
132     },
133     [MOD_N1SDP_TEMP_SENSOR_IDX_SYSTEM] = {
134         .name = "SYS Temperature",
135         .data = &((struct mod_sensor_dev_config) {
136             .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_N1SDP_SENSOR,
137                              MOD_N1SDP_TEMP_SENSOR_IDX_SYSTEM),
138             .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_N1SDP_SENSOR, 0),
139         }),
140     },
141     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS0CORE0] = {
142         .name = "CLUS0CORE0 Voltage",
143         .data = &((struct mod_sensor_dev_config) {
144             .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_N1SDP_SENSOR,
145                              MOD_N1SDP_VOLT_SENSOR_IDX_CLUS0CORE0),
146             .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_N1SDP_SENSOR, 0),
147         }),
148     },
149     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS0CORE1] = {
150         .name = "CLUS0CORE1 Voltage",
151         .data = &((struct mod_sensor_dev_config) {
152             .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_N1SDP_SENSOR,
153                              MOD_N1SDP_VOLT_SENSOR_IDX_CLUS0CORE1),
154             .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_N1SDP_SENSOR, 0),
155         }),
156     },
157     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS1CORE0] = {
158         .name = "CLUS1CORE0 Voltage",
159         .data = &((struct mod_sensor_dev_config) {
160             .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_N1SDP_SENSOR,
161                              MOD_N1SDP_VOLT_SENSOR_IDX_CLUS1CORE0),
162             .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_N1SDP_SENSOR, 0),
163         }),
164     },
165     [MOD_N1SDP_VOLT_SENSOR_IDX_CLUS1CORE1] = {
166         .name = "CLUS1CORE1 Voltage",
167         .data = &((struct mod_sensor_dev_config) {
168             .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_N1SDP_SENSOR,
169                              MOD_N1SDP_VOLT_SENSOR_IDX_CLUS1CORE1),
170             .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_N1SDP_SENSOR, 0),
171         }),
172     },
173     [MOD_N1SDP_VOLT_SENSOR_IDX_SYSTEM] = {
174         .name = "SYS Voltage",
175         .data = &((struct mod_sensor_dev_config) {
176             .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_N1SDP_SENSOR,
177                              MOD_N1SDP_VOLT_SENSOR_IDX_SYSTEM),
178             .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_N1SDP_SENSOR, 0),
179         }),
180     },
181     [MOD_N1SDP_VOLT_SENSOR_COUNT] = { 0 },
182 };
183 
get_sensor_element_table(fwk_id_t module_id)184 static const struct fwk_element *get_sensor_element_table(fwk_id_t module_id)
185 {
186     return sensor_element_table;
187 }
188 
189 struct fwk_module_config config_sensor = {
190     .elements = FWK_MODULE_DYNAMIC_ELEMENTS(get_sensor_element_table),
191 };
192