1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _OSLO_IAXXX_SENSOR_CONTROL_H_
18 #define _OSLO_IAXXX_SENSOR_CONTROL_H_
19 
20 #if __cplusplus
21 extern "C" {
22 #endif
23 
24 #include <errno.h>
25 #include <getopt.h>
26 #include <inttypes.h>
27 #include <limits.h>
28 #include <math.h>
29 #include <stdbool.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <sys/ioctl.h>
34 #include <sys/param.h>
35 #include <time.h>
36 #include <unistd.h>
37 
38 #include <linux/mfd/adnc/iaxxx-module.h>
39 
40 /* copy of SensorDriver.h from polygon */
41 #define SENSOR_MAX_PARAMBLK_SIZE (1024 * 4)
42 
43 /* copy of oslo.h from polygon */
44 #define OSLO_PRESET_CONFIG_START_INDEX 100
45 #define OSLO_CONTROL_START_INDEX 200
46 #define OSLO_SETTING_START_INDEX 300
47 #define OSLO_REGISTER_RW_START_INDEX 400
48 
49 typedef enum {
50     SENSOR_PARAM_SENSOR_SPEC = 0,
51     SENSOR_PARAM_SAMP_RATE,
52     SENSOR_PARAM_SAMP_SIZE,
53     SENSOR_PARAM_INTF_SPEED,
54     SENSOR_PARAM_DRIVER_STATE,
55     SENSOR_PARAM_FRAMES_PROCESSED,
56     SENSOR_PARAM_WATCHDOG_RECOVERY_COUNT,
57     SENSOR_PARAM_PRESET_RADAR_CONFIG,
58     SENSOR_PARAM_DUMP_STATS,
59 
60     /* oslo preset configurations */
61     OSLO_CONFIG_DEFAULT = OSLO_PRESET_CONFIG_START_INDEX,
62     OSLO_CONFIG_PRESENCE,
63     OSLO_CONFIG_CONTINUOUS,
64     OSLO_CONFIG_PRESENCE_SLOW,
65     OSLO_CONFIG_FACTORY_PRESENCE,
66     OSLO_CONFIG_FACTORY_REACH,
67     OSLO_CONFIG_CW_MODE,
68     OSLO_CONFIG_IDLE,
69     OSLO_CONFIG_FACTORY_PRESENCE_V1,
70     OSLO_CONFIG_FACTORY_REACH_V1,
71     OSLO_CONFIG_REACH,
72     OSLO_CONFIG_PRESENCE_V1,
73     OSLO_CONFIG_REACH_V1,
74     OSLO_CONFIG_OFF,
75 
76     /* oslo control - restart oslo when settings change */
77     OSLO_CONTROL_RESTART = OSLO_CONTROL_START_INDEX,
78     OSLO_CONTROL_STRIP_HEADERS,
79     OSLO_CONTROL_SLPI_INT,
80     OSLO_CONTROL_STOP,
81     OSLO_CONTROL_SIMULATE_RADAR_DATA,
82     OSLO_CONTROL_INJECT_RADAR_DATA,
83     OSLO_CONTROL_INJECT_FRAME_READY,
84     OSLO_CONTROL_ASSERT_RESET,
85 
86     /* oslo settings */
87     OSLO_PARAM_REQUEST_RATE = OSLO_SETTING_START_INDEX,
88     OSLO_PARAM_REQUEST_ANTENNA_MASK,
89     OSLO_PARAM_TX_POWER,
90     OSLO_PARAM_LOWER_FREQ,
91     OSLO_PARAM_UPPER_FREQ,
92     OSLO_PARAM_SAMPLES_PER_CHIRP,
93     OSLO_PARAM_VGA_GAIN_CH1,
94     OSLO_PARAM_VGA_GAIN_CH2,
95     OSLO_PARAM_VGA_GAIN_CH3,
96     OSLO_PARAM_VGA_GAIN_CH4,
97     OSLO_PARAM_BURST_CHIRP_COUNT,
98     OSLO_PARAM_BURST_CHIRP_RATE,
99     OSLO_PARAM_BURST_POWER_MODE,
100     OSLO_PARAM_BURST_INTERCHIRP_POWER_MODE,
101     OSLO_PARAM_STARTUP_TIMING_WAKE_UP_TIME_100NS,
102     OSLO_PARAM_STARTUP_TIMING_PLL_SETTLE_TIME_COARSE_100NS,
103     OSLO_PARAM_STARTUP_TIMING_PLL_SETTLE_TIME_FINE_100NS,
104     OSLO_PARAM_STARTUP_TIMING_OSCILLATOR_USEC,
105     OSLO_PARAM_PRE_CHIRP_DELAY_100NS,
106     OSLO_PARAM_POST_CHIRP_DELAY_100NS,
107     OSLO_PARAM_CHIRP_PA_DELAY_100NS,
108     OSLO_PARAM_CHIRP_ADC_DELAY_100NS,
109     OSLO_PARAM_VISUALIZER_DATA_TYPE,
110     OSLO_PARAM_OSCILLATOR_MODE,
111     OSLO_PARAM_HP_GAIN_CH1,
112     OSLO_PARAM_HP_GAIN_CH2,
113     OSLO_PARAM_HP_GAIN_CH3,
114     OSLO_PARAM_HP_GAIN_CH4,
115     OSLO_PARAM_BASEBAND_RESET_PERIOD_1NS,
116     OSLO_PARAM_HP_CUTOFF_CH1,
117     OSLO_PARAM_HP_CUTOFF_CH2,
118     OSLO_PARAM_HP_CUTOFF_CH3,
119     OSLO_PARAM_HP_CUTOFF_CH4,
120     OSLO_PARAM_PHASE_CONFIG,
121     OSLO_PARAM_IDLE_SETTINGS_ENABLE_PLL,
122     OSLO_PARAM_IDLE_SETTINGS_ENABLE_VCO,
123     OSLO_PARAM_IDLE_SETTINGS_ENABLE_FDIV,
124     OSLO_PARAM_IDLE_SETTINGS_ENABLE_BASEBAND,
125     OSLO_PARAM_IDLE_SETTINGS_ENABLE_RF,
126     OSLO_PARAM_IDLE_SETTINGS_ENABLE_MADC,
127     OSLO_PARAM_IDLE_SETTINGS_ENABLE_MADC_BANDGAP,
128     OSLO_PARAM_IDLE_SETTINGS_ENABLE_SADC,
129     OSLO_PARAM_IDLE_SETTINGS_ENABLE_SADC_BANDGAP,
130     OSLO_PARAM_DEEP_SLEEP_SETTINGS_ENABLE_PLL,
131     OSLO_PARAM_DEEP_SLEEP_SETTINGS_ENABLE_VCO,
132     OSLO_PARAM_DEEP_SLEEP_SETTINGS_ENABLE_FDIV,
133     OSLO_PARAM_DEEP_SLEEP_SETTINGS_ENABLE_BASEBAND,
134     OSLO_PARAM_DEEP_SLEEP_SETTINGS_ENABLE_RF,
135     OSLO_PARAM_DEEP_SLEEP_SETTINGS_ENABLE_MADC,
136     OSLO_PARAM_DEEP_SLEEP_SETTINGS_ENABLE_MADC_BANDGAP,
137     OSLO_PARAM_DEEP_SLEEP_SETTINGS_ENABLE_SADC,
138     OSLO_PARAM_DEEP_SLEEP_SETTINGS_ENABLE_SADC_BANDGAP,
139     OSLO_PARAM_TOSS_COUNT,
140     OSLO_PARAM_CHIRP_DIRECTION,
141     OSLO_PARAM_ADC_SAMPLE_RATE,
142     OSLO_PARAM_CHARGE_PUMP,
143 
144     /* oslo register r/w */
145     OSLO_REGISTER_MIN = OSLO_REGISTER_RW_START_INDEX,
146     OSLO_REGISTER_MAX = OSLO_REGISTER_RW_START_INDEX + 99,
147 
148     SENSOR_PARAM_NUM,
149 
150     /* Force enums to be of size int */
151     SENSOR_PARAM_FORCE_SIZE = INT_MAX,
152 } sensor_param_t;
153 
154 typedef enum {
155     PARAM_BLK_ID_SET_PARAM = 1,
156     PARAM_BLK_ID_FRAME_DATA_INJECTION,
157 } sensor_param_blk_id_t;
158 
159 /* copy of OsloSensorPluginInternal.h from polygon */
160 /* OsloSensor Plugin Param Ids */
161 typedef enum oslo_sensor_param_id_e {
162     OSLO_SENSOR_PARAM_MODE_1_SWITCH_COUNT = 0,
163     OSLO_SENSOR_PARAM_MODE_2_SWITCH_COUNT,
164     OSLO_SENSOR_PARAM_MODE,
165     OSLO_SENSOR_PARAM_SLPY_STATE,
166     OSLO_SENSOR_PARAM_ENABLE_SLPY_RAW,
167     OSLO_SENSOR_PARAM_HOST,
168     OSLO_SENSOR_STATE,
169     OSLO_TESTMODE_RESET,
170     OSLO_TESTMODE_PRESENCE_ON,
171     OSLO_TESTMODE_PRESENCE_OFF,
172     OSLO_TESTMODE_SWIPE,
173     OSLO_TESTMODE_FLICK,
174     OSLO_TESTMODE_REACH_IN,
175     OSLO_TESTMODE_REACH_OUT,
176     OSLO_TESTMODE_REACH_SWIPE,
177     OSLO_TESTMODE_REACH_FLICK,
178     OSLO_TESTMODE_REACH_SWIPE_FLICK,
179     OSLO_SENSOR_CONFIG_RECOVERY_COUNTER,
180 
181     /* Force enums to be of size int */
182     OSLO_SENSOR_PARAM_ID_FORCE_SIZE = INT_MAX,
183 } oslo_sensor_param_id_t;
184 
185 struct ia_sensor_mgr {
186     FILE *dev_node;
187 };
188 
189 struct ia_sensor_mgr *iaxxx_sensor_mgr_init(void);
190 int iaxxx_sensor_mgr_deinit(struct ia_sensor_mgr *smd);
191 void oslo_driver_set_param(struct ia_sensor_mgr *smd, int param_id, float param_val);
192 uint32_t oslo_driver_get_param(struct ia_sensor_mgr *smd, int param_id);
193 size_t oslo_driver_set_param_blk(struct ia_sensor_mgr *smd, uint32_t param_blk_id,
194                                  const void *blk_data, uint32_t blk_size);
195 int oslo_driver_get_stats(struct ia_sensor_mgr *smd, struct iaxxx_sensor_mode_stats stats[]);
196 void oslo_plugin_set_param(int param_id, uint32_t param_val);
197 uint32_t oslo_plugin_get_param(int param_id);
198 
199 #if __cplusplus
200 }  // extern "C"
201 #endif
202 
203 #endif  //_OSLO_IAXXX_SENSOR_CONTROL_H_
204