1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2019-2022, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef SENSOR_H
9 #define SENSOR_H
10 
11 #include <mod_sensor.h>
12 
13 #include <fwk_id.h>
14 
15 #include <stdint.h>
16 
17 /*!
18  * \cond
19  */
20 
21 /*
22  * Sensor concurrency readings max pending requests.
23  */
24 #define SENSOR_MAX_PENDING_REQUESTS 3
25 
26 /*
27  * Sensor trip point element context
28  */
29 struct sensor_trip_point_ctx {
30     /* Structure that describes the trip point configuration */
31     struct mod_sensor_trip_point_params params;
32 
33     /* This flag is used to latch status if the trip point were triggered */
34     bool above_threshold;
35 
36     /* This flag describes if this feature is enabled or not */
37     bool enabled;
38 };
39 
40 /*
41  * Sensor element context
42  */
43 struct sensor_dev_ctx {
44     struct mod_sensor_dev_config *config;
45 
46     struct mod_sensor_driver_api *driver_api;
47 
48     struct sensor_trip_point_ctx *trip_point_ctx;
49     uint32_t cookie;
50 
51     struct {
52         uint32_t pending_requests;
53         bool dequeuing;
54     } concurrency_readings;
55 
56     struct mod_sensor_data last_read;
57 
58     unsigned int axis_count;
59 
60 #ifdef BUILD_HAS_SENSOR_TIMESTAMP
61     struct mod_sensor_timestamp_info timestamp;
62 #endif
63 
64 #ifdef BUILD_HAS_SENSOR_EXT_ATTRIBS
65     bool mod_extended_attrib;
66 
67     struct mod_sensor_ext_properties sensor_property_values;
68 #endif
69 };
70 
71 struct mod_sensor_ctx {
72     struct mod_sensor_config *config;
73     struct mod_sensor_trip_point_api *sensor_trip_point_api;
74 };
75 
76 struct sensor_dev_ctx *sensor_get_ctx(fwk_id_t id);
77 
78 /*
79  * Sensor event indexes
80  */
81 enum mod_sensor_event_idx {
82     SENSOR_EVENT_IDX_READ_REQUEST = MOD_SENSOR_EVENT_IDX_READ_REQUEST,
83     SENSOR_EVENT_IDX_READ_COMPLETE,
84     SENSOR_EVENT_IDX_COUNT
85 };
86 
87 /*
88  * Event identifiers
89  */
90 static const fwk_id_t mod_sensor_event_id_read_complete =
91     FWK_ID_EVENT_INIT(FWK_MODULE_IDX_SENSOR,
92                       SENSOR_EVENT_IDX_READ_COMPLETE);
93 
94 #ifdef BUILD_HAS_SENSOR_TIMESTAMP
95 
96 int sensor_timestamp_dev_init(fwk_id_t id, struct sensor_dev_ctx *ctx);
97 
98 int sensor_set_timestamp_config(
99     fwk_id_t id,
100     const struct mod_sensor_timestamp_info *config);
101 
102 int sensor_get_timestamp_config(
103     fwk_id_t id,
104     struct mod_sensor_timestamp_info *config);
105 
106 uint64_t sensor_get_timestamp(fwk_id_t id);
107 #endif
108 
109 #ifdef BUILD_HAS_SENSOR_MULTI_AXIS
110 
111 int sensor_axis_start(fwk_id_t id);
112 
113 int sensor_get_axis_info(
114     fwk_id_t id,
115     uint32_t axis,
116     struct mod_sensor_axis_info *info);
117 #endif
118 
119 /*!
120  * \endcond
121  */
122 
123 #endif /* SENSOR_H */
124