1 /*
2  * Copyright (C) 2018 Knowles Electronics
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 _CVQ_IOCTL_H
18 #define _CVQ_IOCTL_H
19 
20 #include "iaxxx_odsp_hw.h"
21 #include <audio_route/audio_route.h>
22 #include <tinyalsa/asoundlib.h>
23 
24 #define HOTWORD_MASK 0x1
25 #define AMBIENT_MASK 0x2
26 #define ENTITY_MASK  0x4
27 #define PLUGIN1_MASK (HOTWORD_MASK | WAKEUP_MASK)
28 #define PLUGIN2_MASK (AMBIENT_MASK | ENTITY_MASK)
29 #define WAKEUP_MASK  0x8
30 #define OSLO_MASK  0x10
31 #define CHRE_MASK  0x20
32 
33 #define HOTWORD_EVT_SRC_ID            IAXXX_SYSID_PLUGIN_INSTANCE_0
34 #define AMBIENT_EVT_SRC_ID            IAXXX_SYSID_PLUGIN_INSTANCE_2
35 #define CHRE_EVT_SRC_ID               IAXXX_SYSID_PLUGIN_INSTANCE_5
36 // HOST1 Plugin instances start from 8 to 15
37 // plugin 8 is assigned for Oslo buffer and 9 for Oslo plugin
38 #define OSLO_EVT_SRC_ID               IAXXX_SYSID_PLUGIN_INSTANCE_9
39 
40 #define HOTWORD_PKG_ID      11
41 #define HOTWORD_PLUGIN_IDX  0
42 #define HOTWORD_INSTANCE_ID 0
43 #define HOTWORD_PRIORITY    1
44 
45 #define AMBIENT_PKG_ID          12
46 #define AMBIENT_PLUGIN_IDX      0
47 #define AMBIENT_INSTANCE_ID     2
48 #define AMBIENT_PRIORITY        1
49 
50 #define SENSOR_PKG_ID           0
51 #define SENSOR_PLUGIN_IDX       0
52 #define SENSOR_INSTANCE_ID      9
53 #define SENSOR_PRIORITY         2
54 #define SENSOR_PRESENCE_MODE    0
55 #define SENSOR_DETECTED_MODE    1
56 #define SENSOR_MAX_MODE         2
57 #define OSLO_DATA_EVENT_ID      1
58 #define OSLO_CONFIGURED         (0x201)
59 #define OSLO_DESTROYED          (0x202)
60 #define OSLO_EP_DISCONNECT      (0x205)
61 #define CHRE_EP_DISCONNECT      (0x206)
62 #define OSLO_BUF_INSTANCE_ID    8
63 #define OSLO_BUF_PRIORITY       2
64 
65 #define AEC_PKG_ID       7
66 #define AEC_PLUGIN_IDX   0
67 #define AEC_INSTANCE_ID  4
68 #define AEC_PRIORITY     1
69 
70 #define CHRE_PLUGIN_IDX      0
71 #define CHRE_INSTANCE_ID     5
72 #define CHRE_EVT_ID          3
73 #define CHRE_EVT_PARAM_ID    8
74 #define CHRE_BUF_SIZE        64000 // 320B (160 samples) per 10ms -> 64000B per 2s
75 #define CHRE_CONFIGURED      (0x203)
76 #define CHRE_DESTROYED       (0x204)
77 #define CHRE_EVT_MASK        (0x1f)
78 
79 #define IAXXX_SYSID_CTRL_MGR_CM4 0x2610
80 #define IAXXX_HOST1_WAKEUP_EVENT_ID 4
81 
82 #define MIXER_PKG_ID       5
83 #define MIXER_PLUGIN_IDX   0
84 #define MIXER_INSTANCE_ID  7
85 #define MIXER_PRIORITY     1
86 
87 #define SRC_PKG_ID       3
88 #define SRC_PLUGIN_IDX   0
89 #define SRC_PRIORITY     1
90 #define SRC_MIC_INSTANCE_ID  6
91 #define SRC_AMP_INSTANCE_ID  7
92 
93 #define BUF_PKG_ID          4
94 #define BUF_PLUGIN_IDX      0
95 #define BUF_INSTANCE_ID     1
96 #define BUF_PRIORITY        1
97 
98 #define DA_BUF_INSTANCE_ID    3
99 
100 #define HOTWORD_DETECTION   0
101 #define AMBIENT_DETECTION   1
102 #define ENTITY_DETECTION    2
103 #define WAKEUP_DETECTION    3
104 
105 #define HOTWORD_SLOT_ID     1
106 #define AMBIENT_SLOT_ID     3
107 #define ENTITY_SLOT_ID      5
108 #define WAKEUP_SLOT_ID      6
109 
110 #define HOTWORD_UNLOAD_PARAM_ID          1
111 #define AMBIENT_UNLOAD_PARAM_ID          1
112 #define AMBIENT_RESET_PARAM_ID           2
113 #define AMBIENT_GET_MODEL_STATE_PARAM_ID 7
114 #define HOTWORD_GET_VERSION_PARAM_ID     8
115 #define AMBIENT_GET_VERSION_PARAM_ID     8
116 #define HOTWORD_DEFAULT_VER              0
117 #define AMBIENT_DEFAULT_VER              0
118 
119 enum {
120     PARAM_BLOCK_GET_MIN = 0,
121     PARAM_BLOCK_GET_RECOGNITION_PAYLOAD = 100,
122     PARAM_BLOCK_GET_DSP_IDENTIFIER,
123     PARAM_BLOCK_GET_MAX,
124 };
125 
126 #define BUFFER_PACKAGE              "BufferPackage.bin"
127 #define BUFFER_CONFIG_OSLO_VAL      "BufferConfigValOslo.bin"
128 #define BUFFER_CONFIG_VAL_MULTI_SEC "BufferConfigVal.bin"
129 #define BUFFER_CONFIG_VAL_2_SEC     "BufferConfigVal2Sec.bin"
130 #define BUFFER_CONFIG_VAL_CHRE      "BufferConfigValCHRE.bin"
131 #define OK_GOOGLE_PACKAGE           "OkGooglePackage.bin"
132 #define AMBIENT_EC_PACKAGE          "AmbientECPackage.bin"
133 #define AMBIENT_DA_PACKAGE          "AmbientDAPackage.bin"
134 #define SENSOR_PACKAGE              "OsloSensorPackage.bin"
135 #define SENSOR_CONFIG_VAL           "OsloSensorConfig.bin"
136 #define ECHOCANCELLER_PACKAGE       "EchoCancellerPackage.bin"
137 #define MIXER_PACKAGE               "AScalarSimpleMixerPackage.bin"
138 #define SRC_PACKAGE                 "SampleRateConverterPackage.bin"
139 #define SRC_CONFIG                  "SampleRateConverterCreateCfgBlkGen.bin"
140 
141 #define PAYLOAD_MAX_STRING_LEN 64
142 
143 /* The routing definition depend on the platform
144    and the features plugin.
145  */
146 enum {
147     ST_ROUTE_MIN = 0,
148 
149 /* Input Port routing definition */
150     ST_MIC_ROUTE_INT_CLK = ST_ROUTE_MIN,
151     ST_MIC_ROUTE_EXT_CLK,
152     ST_BARGEIN_AMP_REF,
153     ST_BARGEIN_AMP_REF_48K,
154 
155 /* Plugin routing definition */
156     ST_HOTWORD_WITHOUT_BARGEIN,
157     ST_HOTWORD_WITH_BARGEIN,
158     ST_HOTWORD_BUFFER_WITHOUT_BARGEIN,
159     ST_HOTWORD_BUFFER_WITH_BARGEIN,
160     ST_AMBIENT_WITHOUT_BARGEIN,
161     ST_AMBIENT_WITH_BARGEIN,
162     ST_AMBIENT_BUFFER_WITHOUT_BARGEIN,
163     ST_AMBIENT_BUFFER_WITH_BARGEIN,
164     ST_BARGEIN_ROUTE,
165     ST_CHRE_WITHOUT_BARGEIN,
166     ST_CHRE_WITH_BARGEIN,
167     ST_SRC_ROUTE_MIC,
168     ST_SRC_ROUTE_AMP_REF,
169     ST_SENSOR_ROUTE,
170     ST_ROUTE_MAX,
171 };
172 
173 enum clock_type {
174     INTERNAL_OSCILLATOR,
175     EXTERNAL_OSCILLATOR
176 };
177 
178 enum src_type {
179     SRC_MIC,
180     SRC_AMP_REF
181 };
182 
183 enum strm_type {
184     STRM_16K,
185     STRM_48K
186 };
187 
188 enum sthal_mode {
189     IN_CALL,
190     CON_DISABLED_ST,
191     CON_DISABLED_CAPTURE,
192     CON_ENABLED_ST,
193     CON_ENABLED_CAPTURE_ST
194 };
195 
196 typedef enum {
197     TRANSIT_NONE,
198     TRANSIT_SETUP_AEC
199 } transit_case_t;
200 
201 #define PLUGIN_DEF_CONFIG_ID    0
202 
203 int write_model(struct iaxxx_odsp_hw *odsp_hdl, unsigned char *data,
204                 int length, int kw_type);
205 int get_model_state(struct iaxxx_odsp_hw *odsp_hdl, const uint32_t inst_id,
206                     const uint32_t param_val);
207 int get_event(struct iaxxx_odsp_hw *odsp_hdl,
208             struct iaxxx_get_event_info *ge);
209 int setup_chip(struct iaxxx_odsp_hw *odsp_hdl);
210 int setup_buffer_package(struct iaxxx_odsp_hw *odsp_hdl);
211 int destroy_buffer_package(struct iaxxx_odsp_hw *odsp_hdl);
212 int setup_hotword_package(struct iaxxx_odsp_hw *odsp_hdl);
213 int destroy_hotword_package(struct iaxxx_odsp_hw *odsp_hdl);
214 int get_hotword_info(struct iaxxx_odsp_hw *odsp_hdl,
215                      unsigned int *hotword_version, void *supported_model_arch);
216 int setup_ambient_package(struct iaxxx_odsp_hw *odsp_hdl);
217 int destroy_ambient_package(struct iaxxx_odsp_hw *odsp_hdl);
218 int get_ambient_info(struct iaxxx_odsp_hw *odsp_hdl,
219                      unsigned int *ambient_version, void *supported_model_arch);
220 int setup_aec_package(struct iaxxx_odsp_hw *odsp_hdl);
221 int destroy_aec_package(struct iaxxx_odsp_hw *odsp_hdl);
222 int setup_chre_package(struct iaxxx_odsp_hw *odsp_hdl);
223 int destroy_chre_package(struct iaxxx_odsp_hw *odsp_hdl);
224 int setup_sensor_package(struct iaxxx_odsp_hw *odsp_hdl);
225 int destroy_sensor_package(struct iaxxx_odsp_hw *odsp_hdl);
226 int setup_mixer_package(struct iaxxx_odsp_hw *odsp_hdl);
227 int destroy_mixer_package(struct iaxxx_odsp_hw *odsp_hdl);
228 int setup_src_package(struct iaxxx_odsp_hw *odsp_hdl);
229 int destroy_src_package(struct iaxxx_odsp_hw *odsp_hdl);
230 
231 int setup_music_buffer(struct iaxxx_odsp_hw *odsp_hdl);
232 int destroy_music_buffer(struct iaxxx_odsp_hw *odsp_hdl);
233 int setup_howord_buffer(struct iaxxx_odsp_hw *odsp_hdl);
234 int destroy_howord_buffer(struct iaxxx_odsp_hw *odsp_hdl);
235 int setup_src_plugin(struct iaxxx_odsp_hw *odsp_hdl, enum src_type st);
236 int destroy_src_plugin(struct iaxxx_odsp_hw *odsp_hdl, enum src_type st);
237 int set_hotword_buffer_route(struct audio_route *route_hdl, bool bargein);
238 int tear_hotword_buffer_route(struct audio_route *route_hdl, bool bargein);
239 int enable_mic_route(struct audio_route *route_hdl, bool enable,
240                     enum clock_type ct);
241 int enable_amp_ref_route(struct audio_route *route_hdl, bool enable,
242                          enum strm_type strmt);
243 int enable_src_route(struct audio_route *route_hdl, bool enable, enum src_type st);
244 int set_sensor_route(struct audio_route *route_hdl, bool enable);
245 int set_ambient_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current);
246 int tear_ambient_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current);
247 int set_ambient_route(struct audio_route *route_hdl, bool bargein);
248 int tear_ambient_route(struct audio_route *route_hdl, bool bargein);
249 int set_hotword_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current);
250 int tear_hotword_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current);
251 int set_hotword_route(struct audio_route *route_hdl, bool bargein);
252 int tear_hotword_route(struct audio_route *route_hdl, bool bargein);
253 int set_chre_audio_route(struct audio_route *route_hdl, bool bargein);
254 int tear_chre_audio_route(struct audio_route *route_hdl, bool bargein);
255 int reset_ambient_plugin(struct iaxxx_odsp_hw *odsp_hdl);
256 int enable_bargein_route(struct audio_route *route_hdl, bool enable);
257 int set_music_buffer_route(struct audio_route *route_hdl, bool downlink);
258 int tear_music_buffer_route(struct audio_route *route_hdl, bool downlink);
259 
260 int flush_model(struct iaxxx_odsp_hw *odsp_hdl, int kw_type);
261 int get_entity_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload, unsigned int payload_size);
262 int get_wakeup_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload, unsigned int payload_size);
263 int set_default_apll_clk(struct mixer *mixer);
264 int get_fw_status(struct iaxxx_odsp_hw *odsp_hdl, unsigned int *status);
265 int reset_fw(struct iaxxx_odsp_hw *odsp_hdl);
266 int reset_all_route(struct audio_route *route_hdl);
267 int trigger_sensor_destroy_event(struct iaxxx_odsp_hw *odsp_hdl);
268 int trigger_chre_destroy_event(struct iaxxx_odsp_hw *odsp_hdl);
269 int setup_slpi_wakeup_event(struct iaxxx_odsp_hw *odsp_hdl, bool enabled);
270 #endif /* _CVQ_IOCTL_H */
271