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 
115 #define BUFFER_PACKAGE              "BufferPackage.bin"
116 #define BUFFER_CONFIG_OSLO_VAL      "BufferConfigValOslo.bin"
117 #define BUFFER_CONFIG_VAL_MULTI_SEC "BufferConfigVal.bin"
118 #define BUFFER_CONFIG_VAL_2_SEC     "BufferConfigVal2Sec.bin"
119 #define BUFFER_CONFIG_VAL_CHRE      "BufferConfigValCHRE.bin"
120 #define OK_GOOGLE_PACKAGE           "OkGooglePackage.bin"
121 #define AMBIENT_EC_PACKAGE          "AmbientECPackage.bin"
122 #define AMBIENT_DA_PACKAGE          "AmbientDAPackage.bin"
123 #define SENSOR_PACKAGE              "OsloSensorPackage.bin"
124 #define SENSOR_CONFIG_VAL           "OsloSensorConfig.bin"
125 #define ECHOCANCELLER_PACKAGE       "EchoCancellerPackage.bin"
126 #define MIXER_PACKAGE               "AScalarSimpleMixerPackage.bin"
127 #define SRC_PACKAGE                 "SampleRateConverterPackage.bin"
128 #define SRC_CONFIG                  "SampleRateConverterCreateCfgBlkGen.bin"
129 
130 /* The routing definition depend on the platform
131    and the features plugin.
132  */
133 enum {
134     ST_ROUTE_MIN = 0,
135 
136 /* Input Port routing definition */
137     ST_MIC_ROUTE_INT_CLK = ST_ROUTE_MIN,
138     ST_MIC_ROUTE_EXT_CLK,
139     ST_BARGEIN_AMP_REF,
140     ST_BARGEIN_AMP_REF_48K,
141 
142 /* Plugin routing definition */
143     ST_HOTWORD_WITHOUT_BARGEIN,
144     ST_HOTWORD_WITH_BARGEIN,
145     ST_HOTWORD_BUFFER_WITHOUT_BARGEIN,
146     ST_HOTWORD_BUFFER_WITH_BARGEIN,
147     ST_AMBIENT_WITHOUT_BARGEIN,
148     ST_AMBIENT_WITH_BARGEIN,
149     ST_AMBIENT_BUFFER_WITHOUT_BARGEIN,
150     ST_AMBIENT_BUFFER_WITH_BARGEIN,
151     ST_BARGEIN_ROUTE,
152     ST_CHRE_WITHOUT_BARGEIN,
153     ST_CHRE_WITH_BARGEIN,
154     ST_SRC_ROUTE_MIC,
155     ST_SRC_ROUTE_AMP_REF,
156     ST_SENSOR_ROUTE,
157     ST_ROUTE_MAX,
158 };
159 
160 enum clock_type {
161     INTERNAL_OSCILLATOR,
162     EXTERNAL_OSCILLATOR
163 };
164 
165 enum src_type {
166     SRC_MIC,
167     SRC_AMP_REF
168 };
169 
170 enum strm_type {
171     STRM_16K,
172     STRM_48K
173 };
174 
175 enum sthal_mode {
176     IN_CALL,
177     CON_DISABLED_ST,
178     CON_DISABLED_CAPTURE,
179     CON_ENABLED_ST,
180     CON_ENABLED_CAPTURE_ST
181 };
182 
183 typedef enum {
184     TRANSIT_NONE,
185     TRANSIT_SETUP_AEC
186 } transit_case_t;
187 
188 #define PLUGIN_DEF_CONFIG_ID    0
189 
190 int write_model(struct iaxxx_odsp_hw *odsp_hdl, unsigned char *data,
191                 int length, int kw_type);
192 int get_model_state(struct iaxxx_odsp_hw *odsp_hdl, const uint32_t inst_id,
193                     const uint32_t param_val);
194 int get_event(struct iaxxx_odsp_hw *odsp_hdl,
195             struct iaxxx_get_event_info *ge);
196 int setup_chip(struct iaxxx_odsp_hw *odsp_hdl);
197 int setup_buffer_package(struct iaxxx_odsp_hw *odsp_hdl);
198 int destroy_buffer_package(struct iaxxx_odsp_hw *odsp_hdl);
199 int setup_hotword_package(struct iaxxx_odsp_hw *odsp_hdl);
200 int destroy_hotword_package(struct iaxxx_odsp_hw *odsp_hdl);
201 int setup_ambient_package(struct iaxxx_odsp_hw *odsp_hdl);
202 int destroy_ambient_package(struct iaxxx_odsp_hw *odsp_hdl);
203 int setup_aec_package(struct iaxxx_odsp_hw *odsp_hdl);
204 int destroy_aec_package(struct iaxxx_odsp_hw *odsp_hdl);
205 int setup_chre_package(struct iaxxx_odsp_hw *odsp_hdl);
206 int destroy_chre_package(struct iaxxx_odsp_hw *odsp_hdl);
207 int setup_sensor_package(struct iaxxx_odsp_hw *odsp_hdl);
208 int destroy_sensor_package(struct iaxxx_odsp_hw *odsp_hdl);
209 int setup_mixer_package(struct iaxxx_odsp_hw *odsp_hdl);
210 int destroy_mixer_package(struct iaxxx_odsp_hw *odsp_hdl);
211 int setup_src_package(struct iaxxx_odsp_hw *odsp_hdl);
212 int destroy_src_package(struct iaxxx_odsp_hw *odsp_hdl);
213 
214 int setup_music_buffer(struct iaxxx_odsp_hw *odsp_hdl);
215 int destroy_music_buffer(struct iaxxx_odsp_hw *odsp_hdl);
216 int setup_howord_buffer(struct iaxxx_odsp_hw *odsp_hdl);
217 int destroy_howord_buffer(struct iaxxx_odsp_hw *odsp_hdl);
218 int setup_src_plugin(struct iaxxx_odsp_hw *odsp_hdl, enum src_type st);
219 int destroy_src_plugin(struct iaxxx_odsp_hw *odsp_hdl, enum src_type st);
220 int set_hotword_buffer_route(struct audio_route *route_hdl, bool bargein);
221 int tear_hotword_buffer_route(struct audio_route *route_hdl, bool bargein);
222 int enable_mic_route(struct audio_route *route_hdl, bool enable,
223                     enum clock_type ct);
224 int enable_amp_ref_route(struct audio_route *route_hdl, bool enable,
225                          enum strm_type strmt);
226 int enable_src_route(struct audio_route *route_hdl, bool enable, enum src_type st);
227 int set_sensor_route(struct audio_route *route_hdl, bool enable);
228 int set_ambient_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current);
229 int tear_ambient_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current);
230 int set_ambient_route(struct audio_route *route_hdl, bool bargein);
231 int tear_ambient_route(struct audio_route *route_hdl, bool bargein);
232 int set_hotword_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current);
233 int tear_hotword_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current);
234 int set_hotword_route(struct audio_route *route_hdl, bool bargein);
235 int tear_hotword_route(struct audio_route *route_hdl, bool bargein);
236 int set_chre_audio_route(struct audio_route *route_hdl, bool bargein);
237 int tear_chre_audio_route(struct audio_route *route_hdl, bool bargein);
238 int reset_ambient_plugin(struct iaxxx_odsp_hw *odsp_hdl);
239 int enable_bargein_route(struct audio_route *route_hdl, bool enable);
240 int set_music_buffer_route(struct audio_route *route_hdl, bool downlink);
241 int tear_music_buffer_route(struct audio_route *route_hdl, bool downlink);
242 
243 int flush_model(struct iaxxx_odsp_hw *odsp_hdl, int kw_type);
244 int get_entity_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload, unsigned int payload_size);
245 int get_wakeup_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload, unsigned int payload_size);
246 int set_default_apll_clk(struct mixer *mixer);
247 int get_fw_status(struct iaxxx_odsp_hw *odsp_hdl, unsigned int *status);
248 int reset_fw(struct iaxxx_odsp_hw *odsp_hdl);
249 int reset_all_route(struct audio_route *route_hdl);
250 int trigger_sensor_destroy_event(struct iaxxx_odsp_hw *odsp_hdl);
251 int trigger_chre_destroy_event(struct iaxxx_odsp_hw *odsp_hdl);
252 int setup_slpi_wakeup_event(struct iaxxx_odsp_hw *odsp_hdl, bool enabled);
253 #endif /* _CVQ_IOCTL_H */
254