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 #define LOG_TAG "SoundTriggerHALUtil"
18 #define LOG_NDEBUG 0
19
20 #include <stdio.h>
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <stdbool.h>
24 #include <string.h>
25 #include <signal.h>
26 #include <sys/stat.h>
27 #include <log/log.h>
28
29 #include <errno.h>
30 #include <linux/errno.h>
31 #include <sys/ioctl.h>
32
33 #include "cvq_ioctl.h"
34
35 /* Array for ST route */
36 static const char * const route_table[ST_ROUTE_MAX] = {
37
38 /* Input Port routing definition */
39 [ST_MIC_ROUTE_INT_CLK] = "mic-route-internal-clock",
40 [ST_MIC_ROUTE_EXT_CLK] = "mic-route-external-clock",
41 [ST_BARGEIN_AMP_REF] = "bargein-amp-ref",
42 [ST_BARGEIN_AMP_REF_48K] = "bargein-amp-ref-48k",
43
44 /* Plugin routing definition */
45 [ST_HOTWORD_WITHOUT_BARGEIN] = "hotword-route-without-bargein",
46 [ST_HOTWORD_WITH_BARGEIN] = "hotword-route-with-bargein",
47 [ST_HOTWORD_BUFFER_WITHOUT_BARGEIN] = "buffer-route-without-bargein",
48 [ST_HOTWORD_BUFFER_WITH_BARGEIN] = "buffer-route-with-bargein",
49 [ST_AMBIENT_WITHOUT_BARGEIN] = "ambient-route-without-bargein",
50 [ST_AMBIENT_WITH_BARGEIN] = "ambient-route-with-bargein",
51 [ST_AMBIENT_BUFFER_WITHOUT_BARGEIN] = "downlink-audio-route",
52 [ST_AMBIENT_BUFFER_WITH_BARGEIN] = "music-audio-route",
53 [ST_BARGEIN_ROUTE] = "bargein-route",
54 [ST_CHRE_WITHOUT_BARGEIN] = "chre-route-without-bargein",
55 [ST_CHRE_WITH_BARGEIN] = "chre-route-with-bargein",
56 [ST_SRC_ROUTE_MIC] = "src-route-mic",
57 [ST_SRC_ROUTE_AMP_REF] = "src-route-amp-ref",
58 [ST_SENSOR_ROUTE] = "oslo-route",
59 };
60
write_model(struct iaxxx_odsp_hw * odsp_hdl,unsigned char * data,int length,int kw_type)61 int write_model(struct iaxxx_odsp_hw *odsp_hdl, unsigned char *data,
62 int length, int kw_type)
63 {
64 int err = 0;
65
66 switch(kw_type)
67 {
68 case 0: //HOTWORD
69 ALOGV("+%s+ OK_GOOGLE_KW_ID", __func__);
70
71 err = iaxxx_odsp_plugin_set_parameter_blk(odsp_hdl,
72 HOTWORD_INSTANCE_ID, HOTWORD_SLOT_ID,
73 IAXXX_HMD_BLOCK_ID, data, length);
74 break;
75 case 1: //AMBIENT
76 ALOGV("+%s+ AMBIENT_KW_ID", __func__);
77
78 err = iaxxx_odsp_plugin_set_parameter_blk(odsp_hdl,
79 AMBIENT_INSTANCE_ID, AMBIENT_SLOT_ID,
80 IAXXX_HMD_BLOCK_ID, data, length);
81 break;
82 case 2: //ENTITY
83 ALOGV("+%s+ Entity_KW_ID", __func__);
84
85 err = iaxxx_odsp_plugin_set_parameter_blk(odsp_hdl,
86 AMBIENT_INSTANCE_ID, ENTITY_SLOT_ID,
87 IAXXX_HMD_BLOCK_ID, data, length);
88 break;
89 case 3: //WAKEUP
90 ALOGV("+%s+ WAKEUP_KW_ID", __func__);
91
92 err = iaxxx_odsp_plugin_set_parameter_blk(odsp_hdl,
93 HOTWORD_INSTANCE_ID, WAKEUP_SLOT_ID,
94 IAXXX_HMD_BLOCK_ID, data, length);
95 break;
96 default:
97 ALOGE("%s: Unknown KW_ID\n", __func__);
98 err = -EINVAL;
99 goto exit;
100 }
101
102 if (err < 0) {
103 ALOGE("%s: Failed to load the keyword with error %s\n",
104 __func__, strerror(errno));
105 goto exit;
106 }
107
108 ALOGV("-%s-", __func__);
109 exit:
110 return err;
111 }
112
get_model_state(struct iaxxx_odsp_hw * odsp_hdl,const uint32_t inst_id,const uint32_t param_val)113 int get_model_state(struct iaxxx_odsp_hw *odsp_hdl, const uint32_t inst_id,
114 const uint32_t param_val)
115 {
116 int err = 0;
117 const uint32_t param_id = AMBIENT_GET_MODEL_STATE_PARAM_ID;
118 const uint32_t block_id = IAXXX_HMD_BLOCK_ID;
119
120 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, inst_id, param_id,
121 param_val, block_id);
122 if (err != 0) {
123 ALOGE("%s: ERROR: Failed to get the model state", __func__);
124 }
125
126 return err;
127 }
128
get_event(struct iaxxx_odsp_hw * odsp_hdl,struct iaxxx_get_event_info * ge)129 int get_event(struct iaxxx_odsp_hw *odsp_hdl, struct iaxxx_get_event_info *ge)
130 {
131 int err = 0;
132
133 ALOGV("+%s+", __func__);
134 err = iaxxx_odsp_evt_getevent(odsp_hdl, ge);
135 if (err != 0) {
136 ALOGE("%s: ERROR Failed to get event with error %d(%s)",
137 __func__, errno, strerror(errno));
138 }
139
140 ALOGV("-%s-", __func__);
141 return err;
142 }
143
reset_ambient_plugin(struct iaxxx_odsp_hw * odsp_hdl)144 int reset_ambient_plugin(struct iaxxx_odsp_hw *odsp_hdl)
145 {
146 int err = 0;
147
148 ALOGV("+%s+", __func__);
149 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl,
150 AMBIENT_INSTANCE_ID,
151 AMBIENT_RESET_PARAM_ID,
152 AMBIENT_SLOT_ID,
153 IAXXX_HMD_BLOCK_ID);
154 if (err != 0) {
155 ALOGE("%s: ERROR: Set param for ambient lib reset failed %d(%s)",
156 __func__, errno, strerror(errno));
157 }
158
159 ALOGV("-%s-", __func__);
160 return err;
161 }
162
set_sensor_route(struct audio_route * route_hdl,bool enable)163 int set_sensor_route(struct audio_route *route_hdl, bool enable)
164 {
165 int err = 0;
166
167 ALOGV("+%s+", __func__);
168 if (enable)
169 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_SENSOR_ROUTE]);
170 else
171 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_SENSOR_ROUTE]);
172 if (err)
173 ALOGE("%s: route fail %d", __func__, err);
174
175 ALOGV("-%s-", __func__);
176 return err;
177 }
178
set_ambient_state(struct iaxxx_odsp_hw * odsp_hdl,unsigned int current)179 int set_ambient_state(struct iaxxx_odsp_hw *odsp_hdl,
180 unsigned int current)
181 {
182 int err = 0;
183 ALOGV("+%s+ enable models %x", __func__, current & PLUGIN2_MASK);
184
185 err = iaxxx_odsp_plugin_setevent(odsp_hdl, AMBIENT_INSTANCE_ID,
186 current & PLUGIN2_MASK, IAXXX_HMD_BLOCK_ID);
187 if (err < 0) {
188 ALOGE("%s: ERROR: ambient set event failed with error %d(%s)",
189 __func__, errno, strerror(errno));
190 goto exit;
191 }
192 if (current & AMBIENT_MASK) {
193 err = iaxxx_odsp_evt_subscribe(odsp_hdl, AMBIENT_EVT_SRC_ID,
194 AMBIENT_DETECTION, IAXXX_SYSID_HOST, 0);
195 if (err < 0) {
196 ALOGE("%s: ERROR: Ambient subscribe event failed"
197 " with error %d(%s)", __func__,
198 errno, strerror(errno));
199 goto exit;
200 }
201
202 }
203 if (current & ENTITY_MASK) {
204 err = iaxxx_odsp_evt_subscribe(odsp_hdl, AMBIENT_EVT_SRC_ID,
205 ENTITY_DETECTION, IAXXX_SYSID_HOST, 0);
206 if (err < 0) {
207 ALOGE("%s: ERROR: Entity subscribe event failed"
208 " with error %d(%s)", __func__,
209 errno, strerror(errno));
210 goto exit;
211 }
212 }
213
214 exit:
215 ALOGV("-%s-", __func__);
216 return err;
217 }
218
tear_ambient_state(struct iaxxx_odsp_hw * odsp_hdl,unsigned int current)219 int tear_ambient_state(struct iaxxx_odsp_hw *odsp_hdl,
220 unsigned int current)
221 {
222 int err = 0;
223 ALOGV("+%s+ current %x", __func__, current & PLUGIN2_MASK);
224 if (current & AMBIENT_MASK) {
225 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, AMBIENT_EVT_SRC_ID,
226 AMBIENT_DETECTION, IAXXX_SYSID_HOST);
227 if (err < 0) {
228 ALOGE("%s: ERROR: Ambient unsubscribe event failed"
229 " with error %d(%s)", __func__,
230 errno, strerror(errno));
231 goto exit;
232 }
233 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl,
234 AMBIENT_INSTANCE_ID,
235 AMBIENT_UNLOAD_PARAM_ID,
236 AMBIENT_SLOT_ID,
237 IAXXX_HMD_BLOCK_ID);
238 if (err < 0) {
239 ALOGE("%s: ERROR: Ambient model unload failed with error %d(%s)",
240 __func__, errno, strerror(errno));
241 goto exit;
242 }
243 }
244 if (current & ENTITY_MASK) {
245 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, AMBIENT_EVT_SRC_ID,
246 ENTITY_DETECTION, IAXXX_SYSID_HOST);
247 if (err < 0) {
248 ALOGE("%s: ERROR: Entity unsubscribe event failed"
249 " with error %d(%s)", __func__,
250 errno, strerror(errno));
251 goto exit;
252 }
253 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl,
254 AMBIENT_INSTANCE_ID,
255 AMBIENT_UNLOAD_PARAM_ID,
256 ENTITY_SLOT_ID,
257 IAXXX_HMD_BLOCK_ID);
258 if (err < 0) {
259 ALOGE("%s: ERROR: Entity model unload failed with error %d(%s)",
260 __func__, errno, strerror(errno));
261 goto exit;
262 }
263 }
264
265 exit:
266 ALOGV("-%s-", __func__);
267 return err;
268 }
269
set_ambient_route(struct audio_route * route_hdl,bool bargein)270 int set_ambient_route(struct audio_route *route_hdl, bool bargein)
271 {
272 int err = 0;
273
274 ALOGV("+%s bargein %d+", __func__, bargein);
275
276 if (bargein == true)
277 err = audio_route_apply_and_update_path(route_hdl,
278 route_table[ST_AMBIENT_WITH_BARGEIN]);
279 else
280 err = audio_route_apply_and_update_path(route_hdl,
281 route_table[ST_AMBIENT_WITHOUT_BARGEIN]);
282 if (err)
283 ALOGE("%s: route apply fail %d", __func__, err);
284
285 ALOGV("-%s-", __func__);
286 return err;
287 }
288
tear_ambient_route(struct audio_route * route_hdl,bool bargein)289 int tear_ambient_route(struct audio_route *route_hdl, bool bargein)
290 {
291 int err = 0;
292
293 ALOGV("+%s bargein %d+", __func__, bargein);
294 /* check cvq node to send ioctl */
295 if (bargein == true)
296 err = audio_route_reset_and_update_path(route_hdl,
297 route_table[ST_AMBIENT_WITH_BARGEIN]);
298 else
299 err = audio_route_reset_and_update_path(route_hdl,
300 route_table[ST_AMBIENT_WITHOUT_BARGEIN]);
301 if (err)
302 ALOGE("%s: route reset fail %d", __func__, err);
303
304 ALOGV("-%s-", __func__);
305 return err;
306 }
307
set_hotword_state(struct iaxxx_odsp_hw * odsp_hdl,unsigned int current)308 int set_hotword_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current)
309 {
310 int err = 0;
311
312 ALOGV("+%s+ current %x", __func__, current & PLUGIN1_MASK);
313 // Set the events and params
314 err = iaxxx_odsp_plugin_setevent(odsp_hdl, HOTWORD_INSTANCE_ID,
315 current & PLUGIN1_MASK, IAXXX_HMD_BLOCK_ID);
316 if (err != 0) {
317 ALOGE("%s: ERROR: Hotword set event failed with error %d(%s)",
318 __func__, errno, strerror(errno));
319 goto exit;
320 }
321
322 if (current & HOTWORD_MASK) {
323 ALOGD("Registering for Hotword event\n");
324 err = iaxxx_odsp_evt_subscribe(odsp_hdl, HOTWORD_EVT_SRC_ID,
325 HOTWORD_DETECTION, IAXXX_SYSID_HOST, 0);
326 if (err < 0) {
327 ALOGE("%s: ERROR: HOTWORD subscribe event failed"
328 " with error %d(%s)", __func__,
329 errno, strerror(errno));
330 goto exit;
331 }
332
333 }
334 if (current & WAKEUP_MASK) {
335 ALOGD("Registering for Wakeup event\n");
336 err = iaxxx_odsp_evt_subscribe(odsp_hdl, HOTWORD_EVT_SRC_ID,
337 WAKEUP_DETECTION, IAXXX_SYSID_HOST, 0);
338 if (err < 0) {
339 ALOGE("%s: ERROR: WAKEUP subscribe event failed"
340 " with error %d(%s)", __func__,
341 errno, strerror(errno));
342 goto exit;
343 }
344 }
345
346 ALOGV("-%s-", __func__);
347 exit:
348 return err;
349 }
350
tear_hotword_state(struct iaxxx_odsp_hw * odsp_hdl,unsigned int current)351 int tear_hotword_state(struct iaxxx_odsp_hw *odsp_hdl, unsigned int current)
352 {
353 int err = 0;
354
355 ALOGV("+%s+ current %x", __func__, current & PLUGIN1_MASK);
356 if (current & HOTWORD_MASK) {
357 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, HOTWORD_EVT_SRC_ID,
358 HOTWORD_DETECTION, IAXXX_SYSID_HOST);
359 if (err < 0) {
360 ALOGE("%s: ERROR: Hotword unsubscribe event failed"
361 " with error %d(%s)", __func__,
362 errno, strerror(errno));
363 goto exit;
364 }
365 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl,
366 HOTWORD_INSTANCE_ID,
367 HOTWORD_UNLOAD_PARAM_ID,
368 HOTWORD_SLOT_ID,
369 IAXXX_HMD_BLOCK_ID);
370
371 if (err < 0) {
372 ALOGE("%s: ERROR: Ambient model unload failed with error %d(%s)",
373 __func__, errno, strerror(errno));
374 goto exit;
375 }
376 }
377 if (current & WAKEUP_MASK) {
378 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, HOTWORD_EVT_SRC_ID,
379 WAKEUP_DETECTION, IAXXX_SYSID_HOST);
380 if (err < 0) {
381 ALOGE("%s: ERROR: WAKEUP unsubscribe event failed"
382 " with error %d(%s)", __func__,
383 errno, strerror(errno));
384 goto exit;
385 }
386 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl,
387 HOTWORD_INSTANCE_ID,
388 HOTWORD_UNLOAD_PARAM_ID,
389 WAKEUP_SLOT_ID,
390 IAXXX_HMD_BLOCK_ID);
391 if (err < 0) {
392 ALOGE("%s: ERROR: WAKEUP model unload failed with error %d(%s)",
393 __func__, errno, strerror(errno));
394 goto exit;
395 }
396 }
397
398 ALOGV("-%s-", __func__);
399 exit:
400 return err;
401 }
402
set_hotword_route(struct audio_route * route_hdl,bool bargein)403 int set_hotword_route(struct audio_route *route_hdl, bool bargein)
404 {
405 int err = 0;
406
407 ALOGV("+%s bargein %d+", __func__, bargein);
408
409 if (bargein == true)
410 err = audio_route_apply_and_update_path(route_hdl,
411 route_table[ST_HOTWORD_WITH_BARGEIN]);
412 else
413 err = audio_route_apply_and_update_path(route_hdl,
414 route_table[ST_HOTWORD_WITHOUT_BARGEIN]);
415 if (err)
416 ALOGE("%s: route apply fail %d", __func__, err);
417
418 ALOGV("-%s-", __func__);
419 return err;
420 }
421
tear_hotword_route(struct audio_route * route_hdl,bool bargein)422 int tear_hotword_route(struct audio_route *route_hdl, bool bargein)
423 {
424 int err = 0;
425
426 ALOGV("+%s bargein %d+", __func__, bargein);
427 /* check cvq node to send ioctl */
428 if (bargein == true)
429 err = audio_route_reset_and_update_path(route_hdl,
430 route_table[ST_HOTWORD_WITH_BARGEIN]);
431 else
432 err = audio_route_reset_and_update_path(route_hdl,
433 route_table[ST_HOTWORD_WITHOUT_BARGEIN]);
434 if (err)
435 ALOGE("%s: route reset fail %d", __func__, err);
436
437 ALOGV("-%s-", __func__);
438 return err;
439 }
440
set_chre_audio_route(struct audio_route * route_hdl,bool bargein)441 int set_chre_audio_route(struct audio_route *route_hdl, bool bargein)
442 {
443 int err = 0;
444
445 ALOGV("+%s+", __func__);
446 if (bargein)
447 err = audio_route_apply_and_update_path(route_hdl,
448 route_table[ST_CHRE_WITH_BARGEIN]);
449 else
450 err = audio_route_apply_and_update_path(route_hdl,
451 route_table[ST_CHRE_WITHOUT_BARGEIN]);
452 if (err)
453 ALOGE("%s: route apply fail %d", __func__, err);
454
455 ALOGV("-%s-", __func__);
456 return err;
457 }
458
tear_chre_audio_route(struct audio_route * route_hdl,bool bargein)459 int tear_chre_audio_route(struct audio_route *route_hdl, bool bargein)
460 {
461 int err = 0;
462
463 ALOGV("+%s+", __func__);
464 if (bargein == true)
465 err = audio_route_reset_and_update_path(route_hdl,
466 route_table[ST_CHRE_WITH_BARGEIN]);
467 else
468 err = audio_route_reset_and_update_path(route_hdl,
469 route_table[ST_CHRE_WITHOUT_BARGEIN]);
470 if (err)
471 ALOGE("%s: route reset fail %d", __func__, err);
472
473 ALOGV("-%s-", __func__);
474 return err;
475 }
476
sensor_event_init_params(struct iaxxx_odsp_hw * odsp_hdl)477 int sensor_event_init_params(struct iaxxx_odsp_hw *odsp_hdl)
478 {
479 int err = 0;
480
481 ALOGV("+%s+", __func__);
482 // Set the events and params
483 err = iaxxx_odsp_plugin_setevent(odsp_hdl, SENSOR_INSTANCE_ID, 0x1F,
484 IAXXX_HMD_BLOCK_ID);
485 if (err != 0) {
486 ALOGE("%s: ERROR: Sensor set event with error %d(%s)",
487 __func__, errno, strerror(errno));
488 goto exit;
489 }
490
491 ALOGD("Registering for 3 sensor mode switch events\n");
492
493 // Subscribe for events
494 err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID,
495 SENSOR_PRESENCE_MODE, IAXXX_SYSID_SCRIPT_MGR,
496 0x1201);
497 if (err != 0) {
498 ALOGE("%s: ERROR: Sensor subscribe (presence mode) failed %d(%s)",
499 __func__, errno, strerror(errno));
500 goto exit;
501 }
502
503 // Subscribe for events
504 err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID,
505 SENSOR_DETECTED_MODE, IAXXX_SYSID_SCRIPT_MGR,
506 0x1202);
507 if (err != 0) {
508 ALOGE("%s: ERROR: Sensor subscribe (detection mode) failed %d(%s)",
509 __func__, errno, strerror(errno));
510 goto exit;
511 }
512
513 // Subscribe for events
514 err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID,
515 SENSOR_MAX_MODE, IAXXX_SYSID_HOST, 0);
516 if (err != 0) {
517 ALOGE("%s: ERROR: Sensor subscribe (max mode) failed %d(%s)",
518 __func__, errno, strerror(errno));
519 goto exit;
520 }
521
522 err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID,
523 OSLO_DATA_EVENT_ID, IAXXX_SYSID_HOST_1, 0);
524 if (err != 0) {
525 ALOGE("%s: ERROR: Sensor subscribe (oslo data event) failed %d(%s)",
526 __func__, errno, strerror(errno));
527 goto exit;
528 }
529
530 err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID,
531 OSLO_CONFIGURED, IAXXX_SYSID_HOST_1, 0);
532 if (err != 0) {
533 ALOGE("%s: ERROR: Sensor subscribe (oslo configured) failed %d(%s)",
534 __func__, errno, strerror(errno));
535 goto exit;
536 }
537
538 err = iaxxx_odsp_evt_subscribe(odsp_hdl, OSLO_EVT_SRC_ID,
539 OSLO_DESTROYED, IAXXX_SYSID_HOST_1, 0);
540 if (err != 0) {
541 ALOGE("%s: ERROR: Sensor subscribe (oslo destroyed) %d(%s)",
542 __func__, errno, strerror(errno));
543 goto exit;
544 }
545
546 err = iaxxx_odsp_evt_subscribe(odsp_hdl, IAXXX_SYSID_HOST_1,
547 OSLO_EP_DISCONNECT, IAXXX_SYSID_HOST_0, 0);
548 if (err == -1) {
549 ALOGE("%s: ERROR: oslo event subscription (oslo ep disconnect) failed with"
550 " error %d(%s)", __func__, errno, strerror(errno));
551 goto exit;
552 }
553
554 err = iaxxx_odsp_evt_trigger(odsp_hdl, OSLO_EVT_SRC_ID, OSLO_CONFIGURED, 0);
555 if (err != 0) {
556 ALOGE("%s: ERROR: olso event trigger (oslo configured) failed %d(%s)",
557 __func__, errno, strerror(errno));
558 goto exit;
559 }
560
561 ALOGV("-%s-", __func__);
562
563 exit:
564 return err;
565 }
566
sensor_event_deinit_params(struct iaxxx_odsp_hw * odsp_hdl)567 static int sensor_event_deinit_params(struct iaxxx_odsp_hw *odsp_hdl)
568 {
569 int err = 0;
570
571 ALOGD("+%s+", __func__);
572
573 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID, SENSOR_MAX_MODE,
574 IAXXX_SYSID_HOST);
575 if (err != 0) {
576 ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)"
577 " error %d(%s)", __func__, OSLO_EVT_SRC_ID,
578 SENSOR_MAX_MODE, errno, strerror(errno));
579 goto exit;
580 }
581
582 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID,
583 SENSOR_DETECTED_MODE, IAXXX_SYSID_SCRIPT_MGR);
584 if (err != 0) {
585 ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)"
586 " error %d(%s)", __func__, OSLO_EVT_SRC_ID,
587 SENSOR_DETECTED_MODE, errno, strerror(errno));
588 goto exit;
589 }
590
591 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID,
592 SENSOR_PRESENCE_MODE, IAXXX_SYSID_SCRIPT_MGR);
593 if (err != 0) {
594 ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)"
595 " error %d(%s)", __func__, OSLO_EVT_SRC_ID,
596 SENSOR_PRESENCE_MODE, errno, strerror(errno));
597 goto exit;
598 }
599
600 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID,
601 OSLO_DATA_EVENT_ID, IAXXX_SYSID_HOST_1);
602 if (err != 0) {
603 ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)"
604 " from host %d error %d(%s)", __func__, OSLO_EVT_SRC_ID,
605 OSLO_DATA_EVENT_ID, IAXXX_SYSID_HOST_1, errno, strerror(errno));
606 goto exit;
607 }
608
609 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID,
610 OSLO_CONFIGURED, IAXXX_SYSID_HOST_1);
611 if (err != 0) {
612 ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)"
613 " from host %d error %d(%s)", __func__, OSLO_EVT_SRC_ID,
614 OSLO_CONFIGURED, IAXXX_SYSID_HOST_1, errno, strerror(errno));
615 goto exit;
616 }
617
618 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, OSLO_EVT_SRC_ID,
619 OSLO_DESTROYED, IAXXX_SYSID_HOST_1);
620 if (err != 0) {
621 ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)"
622 " from host %d error %d(%s)", __func__, OSLO_EVT_SRC_ID,
623 OSLO_DESTROYED, IAXXX_SYSID_HOST_1, errno, strerror(errno));
624 goto exit;
625 }
626
627 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, IAXXX_SYSID_HOST_1,
628 OSLO_EP_DISCONNECT, IAXXX_SYSID_HOST_0);
629 if (err != 0) {
630 ALOGE("%s: Failed to unsubscribe sensor event (src id %d event id %d)"
631 " from host %d with the error %d(%s)", __func__, IAXXX_SYSID_HOST_1,
632 OSLO_EP_DISCONNECT, IAXXX_SYSID_HOST_0, errno, strerror(errno));
633 goto exit;
634 }
635
636 ALOGD("-%s-", __func__);
637
638 exit:
639 return err;
640 }
641
flush_model(struct iaxxx_odsp_hw * odsp_hdl,int kw_type)642 int flush_model(struct iaxxx_odsp_hw *odsp_hdl, int kw_type)
643 {
644 int err = 0;
645
646 ALOGV("+%s+", __func__);
647
648 switch(kw_type)
649 {
650 case 0: //HOTWORD
651 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl,
652 HOTWORD_INSTANCE_ID,
653 HOTWORD_UNLOAD_PARAM_ID,
654 HOTWORD_SLOT_ID,
655 IAXXX_HMD_BLOCK_ID);
656 break;
657 case 1: //AMBIENT
658 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl,
659 AMBIENT_INSTANCE_ID,
660 AMBIENT_UNLOAD_PARAM_ID,
661 AMBIENT_SLOT_ID,
662 IAXXX_HMD_BLOCK_ID);
663 break;
664 case 2: //ENTITY
665 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl,
666 AMBIENT_INSTANCE_ID,
667 AMBIENT_UNLOAD_PARAM_ID,
668 ENTITY_SLOT_ID,
669 IAXXX_HMD_BLOCK_ID);
670 break;
671 case 3: //WAKEUP
672 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl,
673 HOTWORD_INSTANCE_ID,
674 HOTWORD_UNLOAD_PARAM_ID,
675 WAKEUP_SLOT_ID,
676 IAXXX_HMD_BLOCK_ID);
677 break;
678 default:
679 ALOGE("%s: Unknown KW_ID\n", __func__);
680 err = -1;
681 errno = -EINVAL;
682 break;
683 }
684
685 if (err < 0) {
686 ALOGE("%s: ERROR: model unload set param failed with error %d(%s)",
687 __func__, errno, strerror(errno));
688 }
689
690 ALOGV("-%s-", __func__);
691 return err;
692 }
693
setup_buffer_package(struct iaxxx_odsp_hw * odsp_hdl)694 int setup_buffer_package(struct iaxxx_odsp_hw *odsp_hdl)
695 {
696 int err = 0;
697
698 ALOGD("+%s+", __func__);
699
700 err = iaxxx_odsp_package_load(odsp_hdl, BUFFER_PACKAGE, BUF_PKG_ID);
701 if (err != 0) {
702 ALOGE("%s: ERROR: Failed to load Buffer package %d(%s)",
703 __func__, errno, strerror(errno));
704 goto exit;
705 }
706
707 ALOGD("-%s-", __func__);
708
709 exit:
710 return err;
711 }
712
destroy_buffer_package(struct iaxxx_odsp_hw * odsp_hdl)713 int destroy_buffer_package(struct iaxxx_odsp_hw *odsp_hdl)
714 {
715 int err = 0;
716
717 ALOGD("+%s+", __func__);
718
719 err = iaxxx_odsp_package_unload(odsp_hdl, BUF_PKG_ID);
720 if (err != 0) {
721 ALOGE("%s: ERROR: Failed to unload Buffer package %d(%s)",
722 __func__, errno, strerror(errno));
723 goto exit;
724 }
725
726 ALOGD("-%s-", __func__);
727
728 exit:
729 return err;
730 }
731
setup_hotword_package(struct iaxxx_odsp_hw * odsp_hdl)732 int setup_hotword_package(struct iaxxx_odsp_hw *odsp_hdl)
733 {
734 int err = 0;
735
736 ALOGD("+%s+", __func__);
737
738 // Download packages for ok google
739 err = iaxxx_odsp_package_load(odsp_hdl, AMBIENT_EC_PACKAGE,
740 HOTWORD_PKG_ID);
741 if (err != 0) {
742 ALOGE("%s: ERROR: Failed to load Hotword package %d(%s)",
743 __func__, errno, strerror(errno));
744 goto exit;
745 }
746
747 // Create Hotword plugin
748 err = iaxxx_odsp_plugin_create(odsp_hdl, HOTWORD_INSTANCE_ID, HOTWORD_PRIORITY,
749 HOTWORD_PKG_ID, HOTWORD_PLUGIN_IDX,
750 IAXXX_HMD_BLOCK_ID, PLUGIN_DEF_CONFIG_ID);
751 if (err != 0) {
752 ALOGE("%s: ERROR: Failed to create Hotword plugin %d(%s)",
753 __func__, errno, strerror(errno));
754 goto exit;
755 }
756
757 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, HOTWORD_INSTANCE_ID, 0,
758 0, IAXXX_HMD_BLOCK_ID);
759 if (err != 0) {
760 ALOGE("%s: ERROR: Hotword init frontend failed %d(%s)",
761 __func__, errno, strerror(errno));
762 goto exit;
763 }
764
765 ALOGD("-%s-", __func__);
766
767 exit:
768 return err;
769 }
770
destroy_hotword_package(struct iaxxx_odsp_hw * odsp_hdl)771 int destroy_hotword_package(struct iaxxx_odsp_hw *odsp_hdl)
772 {
773 int err = 0;
774
775 ALOGD("+%s+", __func__);
776
777 err = iaxxx_odsp_plugin_destroy(odsp_hdl, HOTWORD_INSTANCE_ID,
778 IAXXX_HMD_BLOCK_ID);
779 if (err != 0) {
780 ALOGE("%s: ERROR: Failed to destroy Hotword plugin %d(%s)",
781 __func__, errno, strerror(errno));
782 goto exit;
783 }
784
785 // Unload hotword package
786 err = iaxxx_odsp_package_unload(odsp_hdl, HOTWORD_PKG_ID);
787 if (err != 0) {
788 ALOGE("%s: ERROR: Failed to unload Hotword package %d(%s)",
789 __func__, errno, strerror(errno));
790 goto exit;
791 }
792
793 ALOGD("-%s-", __func__);
794
795 exit:
796 return err;
797 }
798
get_hotword_info(struct iaxxx_odsp_hw * odsp_hdl,unsigned int * hotword_version,void * supported_model_arch)799 int get_hotword_info(struct iaxxx_odsp_hw *odsp_hdl,
800 unsigned int *hotword_version, void *supported_model_arch)
801 {
802 int err = 0;
803 const uint32_t inst_id = HOTWORD_INSTANCE_ID;
804 const uint32_t param_id = HOTWORD_GET_VERSION_PARAM_ID;
805 const uint32_t block_id = IAXXX_HMD_BLOCK_ID;
806 unsigned int param_val = HOTWORD_DEFAULT_VER;
807
808 err = setup_hotword_package(odsp_hdl);
809 if (err != 0) {
810 if (errno == EEXIST) {
811 ALOGW("%s: WARN: Hotword package existed already", __func__);
812 err = iaxxx_odsp_plugin_get_parameter(odsp_hdl, inst_id, param_id,
813 block_id, ¶m_val);
814 if (err != 0) {
815 ALOGE("%s: Failed to get parameter for id %u with error %d: %s",
816 __func__, param_id, err, strerror(errno));
817 } else {
818 ALOGD("%s: Value of parameter id %u is %u", __func__, param_id,
819 param_val);
820 }
821 *hotword_version = param_val;
822 err = iaxxx_odsp_plugin_get_parameter_blk(odsp_hdl, inst_id, block_id,
823 PARAM_BLOCK_GET_DSP_IDENTIFIER,
824 supported_model_arch,
825 PAYLOAD_MAX_STRING_LEN);
826 if (err != 0) {
827 ALOGE("%s: Failed to get dsp identifier with error %d: %s",
828 __func__, err, strerror(errno));
829 }
830 } else {
831 ALOGE("%s: ERROR: setup hotword package failed", __func__);
832 }
833 } else {
834 err = iaxxx_odsp_plugin_get_parameter(odsp_hdl, inst_id, param_id,
835 block_id, ¶m_val);
836 if (err != 0) {
837 ALOGE("%s: Failed to get parameter for id %u with error %d: %s",
838 __func__, param_id, err, strerror(errno));
839 } else {
840 ALOGD("%s: Value of parameter id %u is %u", __func__, param_id,
841 param_val);
842 }
843 *hotword_version = param_val;
844 err = iaxxx_odsp_plugin_get_parameter_blk(odsp_hdl, inst_id, block_id,
845 PARAM_BLOCK_GET_DSP_IDENTIFIER,
846 supported_model_arch,
847 PAYLOAD_MAX_STRING_LEN);
848 if (err != 0) {
849 ALOGE("%s: Failed to get dsp identifier with error %d: %s",
850 __func__, err, strerror(errno));
851 }
852 err = destroy_hotword_package(odsp_hdl);
853 if (err != 0)
854 ALOGE("%s: ERROR: destroy hotword package failed", __func__);
855 }
856
857 return err;
858 }
859
setup_ambient_package(struct iaxxx_odsp_hw * odsp_hdl)860 int setup_ambient_package(struct iaxxx_odsp_hw *odsp_hdl)
861 {
862 int err = 0;
863
864 ALOGD("+%s+", __func__);
865
866 // Download packages for ambient
867 err = iaxxx_odsp_package_load(odsp_hdl, AMBIENT_DA_PACKAGE,
868 AMBIENT_PKG_ID);
869 if (err != 0) {
870 ALOGE("%s: ERROR: Failed to load Ambient package %d(%s)",
871 __func__, errno, strerror(errno));
872 goto exit;
873 }
874
875 // Create Ambient plugin
876 err = iaxxx_odsp_plugin_create(odsp_hdl, AMBIENT_INSTANCE_ID,
877 AMBIENT_PRIORITY, AMBIENT_PKG_ID,
878 AMBIENT_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
879 PLUGIN_DEF_CONFIG_ID);
880 if (err != 0) {
881 ALOGE("%s: ERROR: Failed to create Ambient plugin %d(%s)",
882 __func__, errno, strerror(errno));
883 goto exit;
884 }
885
886 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, AMBIENT_INSTANCE_ID,
887 0, 0, IAXXX_HMD_BLOCK_ID);
888 if (err != 0) {
889 ALOGE("%s: ERROR: Ambient init frontend failed %d(%s)",
890 __func__, errno, strerror(errno));
891 goto exit;
892 }
893
894 ALOGD("-%s-", __func__);
895
896 exit:
897 return err;
898 }
899
destroy_ambient_package(struct iaxxx_odsp_hw * odsp_hdl)900 int destroy_ambient_package(struct iaxxx_odsp_hw *odsp_hdl)
901 {
902 int err = 0;
903
904 ALOGD("+%s+", __func__);
905
906 err = iaxxx_odsp_plugin_destroy(odsp_hdl, AMBIENT_INSTANCE_ID,
907 IAXXX_HMD_BLOCK_ID);
908 if (err != 0) {
909 ALOGE("%s: ERROR: Failed to destroy Ambient plugin %d(%s)",
910 __func__, errno, strerror(errno));
911 goto exit;
912 }
913
914 err = iaxxx_odsp_package_unload(odsp_hdl, AMBIENT_PKG_ID);
915 if (err != 0) {
916 ALOGE("%s: ERROR: Failed to unload Ambient package %d(%s)",
917 __func__, errno, strerror(errno));
918 goto exit;
919 }
920
921 ALOGD("-%s-", __func__);
922
923 exit:
924 return err;
925 }
926
get_ambient_info(struct iaxxx_odsp_hw * odsp_hdl,unsigned int * ambient_version,void * supported_model_arch)927 int get_ambient_info(struct iaxxx_odsp_hw *odsp_hdl,
928 unsigned int *ambient_version, void *supported_model_arch)
929 {
930 int err = 0;
931 const uint32_t inst_id = AMBIENT_INSTANCE_ID;
932 const uint32_t param_id = AMBIENT_GET_VERSION_PARAM_ID;
933 const uint32_t block_id = IAXXX_HMD_BLOCK_ID;
934 unsigned int param_val = AMBIENT_DEFAULT_VER;
935
936 err = setup_ambient_package(odsp_hdl);
937 if (err != 0) {
938 if (errno == EEXIST) {
939 ALOGW("%s: WARN: Ambient package existed already", __func__);
940 err = iaxxx_odsp_plugin_get_parameter(odsp_hdl, inst_id, param_id,
941 block_id, ¶m_val);
942 if (err != 0) {
943 ALOGE("%s: Failed to get parameter for id %u with error %d: %s",
944 __func__, param_id, err, strerror(errno));
945 } else {
946 ALOGD("%s: Value of parameter id %u is %u", __func__, param_id,
947 param_val);
948 }
949 *ambient_version = param_val;
950 err = iaxxx_odsp_plugin_get_parameter_blk(odsp_hdl, inst_id, block_id,
951 PARAM_BLOCK_GET_DSP_IDENTIFIER,
952 supported_model_arch,
953 PAYLOAD_MAX_STRING_LEN);
954 if (err != 0) {
955 ALOGE("%s: Failed to get dsp identifier with error %d: %s",
956 __func__, err, strerror(errno));
957 }
958 } else {
959 ALOGE("%s: ERROR: setup Ambient package failed", __func__);
960 }
961 } else {
962 err = iaxxx_odsp_plugin_get_parameter(odsp_hdl, inst_id, param_id,
963 block_id, ¶m_val);
964 if (err != 0) {
965 ALOGE("%s: Failed to get parameter for id %u with error %d: %s",
966 __func__, param_id, err, strerror(errno));
967 } else {
968 ALOGD("%s: Value of parameter id %u is %u", __func__, param_id,
969 param_val);
970 }
971 *ambient_version = param_val;
972 err = iaxxx_odsp_plugin_get_parameter_blk(odsp_hdl, inst_id, block_id,
973 PARAM_BLOCK_GET_DSP_IDENTIFIER,
974 supported_model_arch,
975 PAYLOAD_MAX_STRING_LEN);
976 if (err != 0) {
977 ALOGE("%s: Failed to get dsp identifier with error %d: %s",
978 __func__, err, strerror(errno));
979 }
980 err = destroy_ambient_package(odsp_hdl);
981 if (err != 0)
982 ALOGE("%s: ERROR: destroy Ambient package failed", __func__);
983 }
984
985 return err;
986 }
987
setup_aec_package(struct iaxxx_odsp_hw * odsp_hdl)988 int setup_aec_package(struct iaxxx_odsp_hw *odsp_hdl)
989 {
990 int err = 0;
991
992 ALOGD("+%s+", __func__);
993
994 err = iaxxx_odsp_package_load(odsp_hdl, ECHOCANCELLER_PACKAGE,
995 AEC_PKG_ID);
996 if (err != 0) {
997 ALOGE("%s: ERROR: Failed to load AEC passthrough package %d(%s)",
998 __func__, errno, strerror(errno));
999 goto exit;
1000 }
1001
1002 // AEC PT Plugin Create
1003 err = iaxxx_odsp_plugin_create(odsp_hdl, AEC_INSTANCE_ID, AEC_PRIORITY,
1004 AEC_PKG_ID, AEC_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
1005 PLUGIN_DEF_CONFIG_ID);
1006 if (err != 0) {
1007 ALOGE("%s: ERROR: Failed to create AEC plugin %d(%s)",
1008 __func__, errno, strerror(errno));
1009 goto exit;
1010 }
1011
1012 ALOGD("-%s-", __func__);
1013
1014 exit:
1015 return err;
1016 }
1017
destroy_aec_package(struct iaxxx_odsp_hw * odsp_hdl)1018 int destroy_aec_package(struct iaxxx_odsp_hw *odsp_hdl)
1019 {
1020 int err = 0;
1021
1022 ALOGD("+%s+", __func__);
1023
1024 err = iaxxx_odsp_plugin_destroy(odsp_hdl, AEC_INSTANCE_ID,
1025 IAXXX_HMD_BLOCK_ID);
1026 if (err != 0) {
1027 ALOGE("%s: ERROR: Failed to destroy AEC plugin %d(%s)",
1028 __func__, errno, strerror(errno));
1029 goto exit;
1030 }
1031
1032 err = iaxxx_odsp_package_unload(odsp_hdl, AEC_PKG_ID);
1033 if (err != 0) {
1034 ALOGE("%s: ERROR: Failed to unload AEC package %d(%s)",
1035 __func__, errno, strerror(errno));
1036 goto exit;
1037 }
1038
1039 ALOGD("-%s-", __func__);
1040
1041 exit:
1042 return err;
1043 }
1044
setup_chre_package(struct iaxxx_odsp_hw * odsp_hdl)1045 int setup_chre_package(struct iaxxx_odsp_hw *odsp_hdl)
1046 {
1047 int err = 0;
1048 struct iaxxx_create_config_data cdata;
1049
1050 ALOGD("+%s+", __func__);
1051
1052 /* Create CHRE plugins */
1053 cdata.type = CONFIG_FILE;
1054 cdata.data.fdata.filename = BUFFER_CONFIG_VAL_CHRE;
1055 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1056 CHRE_INSTANCE_ID,
1057 IAXXX_HMD_BLOCK_ID,
1058 cdata);
1059 if (err != 0) {
1060 ALOGE("%s: ERROR: CHRE Buffer configuration failed %d(%s)",
1061 __func__, errno, strerror(errno));
1062 goto exit;
1063 }
1064
1065 // Create CHRE Buffer plugin
1066 err = iaxxx_odsp_plugin_create(odsp_hdl, CHRE_INSTANCE_ID, BUF_PRIORITY,
1067 BUF_PKG_ID, CHRE_PLUGIN_IDX,
1068 IAXXX_HMD_BLOCK_ID, PLUGIN_DEF_CONFIG_ID);
1069 if (err != 0) {
1070 ALOGE("%s: ERROR: Failed to create CHRE buffer %d(%s)",
1071 __func__, errno, strerror(errno));
1072 goto exit;
1073 }
1074
1075 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, CHRE_INSTANCE_ID,
1076 CHRE_EVT_PARAM_ID, CHRE_BUF_SIZE,
1077 IAXXX_HMD_BLOCK_ID);
1078 if (err != 0) {
1079 ALOGE("%s: ERROR: CHRE buffer set param failed %d(%s)",
1080 __func__, errno, strerror(errno));
1081 goto exit;
1082 }
1083
1084 err = iaxxx_odsp_plugin_setevent(odsp_hdl, CHRE_INSTANCE_ID,
1085 CHRE_EVT_MASK, IAXXX_HMD_BLOCK_ID);
1086 if (err != 0) {
1087 ALOGE("%s: ERROR: CHRE set event failed %d(%s)",
1088 __func__, errno, strerror(errno));
1089 goto exit;
1090 }
1091
1092 // Subscribe for events
1093 err = iaxxx_odsp_evt_subscribe(odsp_hdl, CHRE_EVT_SRC_ID,
1094 CHRE_EVT_ID, IAXXX_SYSID_HOST_1, 0);
1095 if (err != 0) {
1096 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)"
1097 " IOCTL failed %d(%s)", __func__, CHRE_EVT_ID, CHRE_EVT_SRC_ID,
1098 errno, strerror(errno));
1099 goto exit;
1100 }
1101
1102 err = iaxxx_odsp_evt_subscribe(odsp_hdl, CHRE_EVT_SRC_ID,
1103 CHRE_CONFIGURED, IAXXX_SYSID_HOST_1, 0);
1104 if (err != 0) {
1105 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)"
1106 " IOCTL failed %d(%s)", __func__, CHRE_CONFIGURED, CHRE_EVT_SRC_ID,
1107 errno, strerror(errno));
1108 goto exit;
1109 }
1110
1111 err = iaxxx_odsp_evt_subscribe(odsp_hdl, CHRE_EVT_SRC_ID,
1112 CHRE_DESTROYED, IAXXX_SYSID_HOST_1, 0);
1113 if (err != 0) {
1114 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)"
1115 " IOCTL failed %d(%s)", __func__, CHRE_DESTROYED, CHRE_EVT_SRC_ID,
1116 errno, strerror(errno));
1117 goto exit;
1118 }
1119
1120 err = iaxxx_odsp_evt_subscribe(odsp_hdl, IAXXX_SYSID_HOST_1,
1121 CHRE_EP_DISCONNECT, IAXXX_SYSID_HOST_0, 0);
1122 if (err == -1) {
1123 ALOGE("%s: ERROR: CHRE event subscription (CHRE EP disconnect) failed "
1124 " with error %d(%s)", __func__, errno, strerror(errno));
1125 goto exit;
1126 }
1127
1128 err = iaxxx_odsp_evt_trigger(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_CONFIGURED, 0);
1129 if (err != 0) {
1130 ALOGE("%s: ERROR: CHRE event trigger (chre configured) failed %d(%s)",
1131 __func__, errno, strerror(errno));
1132 goto exit;
1133 }
1134
1135 ALOGD("-%s-", __func__);
1136
1137 exit:
1138 return err;
1139 }
1140
destroy_chre_package(struct iaxxx_odsp_hw * odsp_hdl)1141 int destroy_chre_package(struct iaxxx_odsp_hw *odsp_hdl)
1142 {
1143 int err = 0;
1144
1145 ALOGD("+%s+", __func__);
1146
1147 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_EVT_ID,
1148 IAXXX_SYSID_HOST_1);
1149 if (err != 0) {
1150 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)"
1151 " IOCTL failed %d(%s)", __func__, CHRE_EVT_ID, CHRE_EVT_SRC_ID,
1152 errno, strerror(errno));
1153 goto exit;
1154 }
1155
1156 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_CONFIGURED,
1157 IAXXX_SYSID_HOST_1);
1158 if (err != 0) {
1159 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)"
1160 " IOCTL failed %d(%s)", __func__, CHRE_CONFIGURED, CHRE_EVT_SRC_ID,
1161 errno, strerror(errno));
1162 goto exit;
1163 }
1164
1165 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_DESTROYED,
1166 IAXXX_SYSID_HOST_1);
1167 if (err != 0) {
1168 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)"
1169 " IOCTL failed %d(%s)", __func__, CHRE_DESTROYED, CHRE_EVT_SRC_ID,
1170 errno, strerror(errno));
1171 goto exit;
1172 }
1173
1174 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, IAXXX_SYSID_HOST_1,
1175 CHRE_EP_DISCONNECT, IAXXX_SYSID_HOST_0);
1176 if (err == -1) {
1177 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)"
1178 " IOCTL failed with error %d(%s)", __func__, CHRE_EP_DISCONNECT,
1179 IAXXX_SYSID_HOST_1, errno, strerror(errno));
1180 goto exit;
1181 }
1182
1183 err = iaxxx_odsp_plugin_destroy(odsp_hdl, CHRE_INSTANCE_ID,
1184 IAXXX_HMD_BLOCK_ID);
1185 if (err != 0) {
1186 ALOGE("%s: ERROR: Failed to destroy buffer plugin for CHRE %d(%s)",
1187 __func__, errno, strerror(errno));
1188 goto exit;
1189 }
1190
1191 ALOGD("-%s-", __func__);
1192
1193 exit:
1194 return err;
1195 }
1196
trigger_chre_destroy_event(struct iaxxx_odsp_hw * odsp_hdl)1197 int trigger_chre_destroy_event(struct iaxxx_odsp_hw *odsp_hdl) {
1198 int err = 0;
1199
1200 ALOGD("+%s+", __func__);
1201
1202 err = iaxxx_odsp_evt_trigger(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_DESTROYED, 0);
1203 if (err == -1) {
1204 ALOGE("%s: ERROR: CHRE event trigger (chre destroyed) failed with "
1205 "error %d(%s)", __func__, errno, strerror(errno));
1206 goto exit;
1207 }
1208
1209 exit:
1210 ALOGD("-%s-", __func__);
1211 return err;
1212 }
1213
setup_sensor_package(struct iaxxx_odsp_hw * odsp_hdl)1214 int setup_sensor_package(struct iaxxx_odsp_hw *odsp_hdl)
1215 {
1216 int err = 0;
1217 struct iaxxx_create_config_data cdata;
1218
1219 ALOGD("+%s+", __func__);
1220
1221 // Download sensor packages
1222 err = iaxxx_odsp_package_load(odsp_hdl, SENSOR_PACKAGE, SENSOR_PKG_ID);
1223 if (err != 0) {
1224 ALOGE("%s: ERROR: Failed to load Sensor package %d(%s)",
1225 __func__, errno, strerror(errno));
1226 goto exit;
1227 }
1228
1229 /* Create plugins */
1230 cdata.type = CONFIG_FILE;
1231 cdata.data.fdata.filename = BUFFER_CONFIG_OSLO_VAL;
1232 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1233 OSLO_BUF_INSTANCE_ID,
1234 IAXXX_HMD_BLOCK_ID,
1235 cdata);
1236 if (err != 0) {
1237 ALOGE("%s: ERROR: Sensor buffer configuration failed %d(%s)",
1238 __func__, errno, strerror(errno));
1239 goto exit;
1240 }
1241
1242 // Create Buffer plugin
1243 err = iaxxx_odsp_plugin_create(odsp_hdl, OSLO_BUF_INSTANCE_ID,
1244 OSLO_BUF_PRIORITY, BUF_PKG_ID,
1245 BUF_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
1246 PLUGIN_DEF_CONFIG_ID);
1247 if (err != 0) {
1248 ALOGE("%s: ERROR: Failed to create Sensor Buffer %d(%s)",
1249 __func__, errno, strerror(errno));
1250 goto exit;
1251 }
1252
1253 cdata.type = CONFIG_FILE;
1254 cdata.data.fdata.filename = SENSOR_CONFIG_VAL;
1255 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1256 SENSOR_INSTANCE_ID,
1257 IAXXX_HMD_BLOCK_ID,
1258 cdata);
1259 if (err == -1) {
1260 ALOGE("%s: ERROR: Sensor configuration %d(%s)",
1261 __func__, errno, strerror(errno));
1262 return err;
1263 }
1264
1265 // Create placeholder sensor plugin
1266 err = iaxxx_odsp_plugin_create(odsp_hdl, SENSOR_INSTANCE_ID,
1267 SENSOR_PRIORITY, SENSOR_PKG_ID,
1268 SENSOR_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
1269 PLUGIN_DEF_CONFIG_ID);
1270 if (err != 0) {
1271 ALOGE("%s: ERROR: Failed to create Sensor plugin %d(%s)",
1272 __func__, errno, strerror(errno));
1273 goto exit;
1274 }
1275
1276 err = sensor_event_init_params(odsp_hdl);
1277 if (err) {
1278 ALOGE("%s: ERROR: Sensor event init failed %d", __func__, err);
1279 goto exit;
1280 }
1281
1282 ALOGD("-%s-", __func__);
1283
1284 exit:
1285 return err;
1286 }
1287
destroy_sensor_package(struct iaxxx_odsp_hw * odsp_hdl)1288 int destroy_sensor_package(struct iaxxx_odsp_hw *odsp_hdl)
1289 {
1290 int err = 0;
1291
1292 ALOGD("+%s+", __func__);
1293
1294 err = sensor_event_deinit_params(odsp_hdl);
1295 if (err != 0) {
1296 ALOGE("%s: ERROR: Sensor event uninit failed %d", __func__, err);
1297 goto exit;
1298 }
1299
1300 err = iaxxx_odsp_plugin_destroy(odsp_hdl, SENSOR_INSTANCE_ID,
1301 IAXXX_HMD_BLOCK_ID);
1302 if (err != 0) {
1303 ALOGE("%s: ERROR: Failed to destroy sensor plugin %d(%s)",
1304 __func__, errno, strerror(errno));
1305 goto exit;
1306 }
1307
1308 err = iaxxx_odsp_plugin_destroy(odsp_hdl, OSLO_BUF_INSTANCE_ID,
1309 IAXXX_HMD_BLOCK_ID);
1310 if (err != 0) {
1311 ALOGE("%s: ERROR: Failed to destroy sensor buffer plugin %d(%s)",
1312 __func__, errno, strerror(errno));
1313 goto exit;
1314 }
1315
1316 err = iaxxx_odsp_package_unload(odsp_hdl, SENSOR_PKG_ID);
1317 if (err != 0) {
1318 ALOGE("%s: ERROR: Failed to unload sensor package %d(%s)",
1319 __func__, errno, strerror(errno));
1320 goto exit;
1321 }
1322
1323 ALOGD("-%s-", __func__);
1324
1325 exit:
1326 return err;
1327 }
1328
trigger_sensor_destroy_event(struct iaxxx_odsp_hw * odsp_hdl)1329 int trigger_sensor_destroy_event(struct iaxxx_odsp_hw *odsp_hdl)
1330 {
1331 int err = 0;
1332
1333 ALOGD("+%s+", __func__);
1334
1335 err = iaxxx_odsp_evt_trigger(odsp_hdl, OSLO_EVT_SRC_ID, OSLO_DESTROYED, 0);
1336 if (err == -1)
1337 ALOGE("%s: ERROR: oslo event trigger (oslo destroyed) failed with "
1338 "error %d(%s)", __func__, errno, strerror(errno));
1339
1340 ALOGD("-%s-", __func__);
1341 return err;
1342 }
1343
setup_mixer_package(struct iaxxx_odsp_hw * odsp_hdl)1344 int setup_mixer_package(struct iaxxx_odsp_hw *odsp_hdl)
1345 {
1346 int err = 0;
1347
1348 ALOGD("+%s+", __func__);
1349
1350 // Load package for Mixer
1351 err = iaxxx_odsp_package_load(odsp_hdl, MIXER_PACKAGE, MIXER_PKG_ID);
1352 if (err != 0) {
1353 ALOGE("%s: ERROR: Failed to load Mixer package %d(%s)",
1354 __func__, errno, strerror(errno));
1355 goto exit;
1356 }
1357
1358 // Create Mixer Plugin
1359 err = iaxxx_odsp_plugin_create(odsp_hdl, MIXER_INSTANCE_ID,
1360 MIXER_PRIORITY, MIXER_PKG_ID,
1361 MIXER_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
1362 PLUGIN_DEF_CONFIG_ID);
1363 if (err != 0) {
1364 ALOGE("%s: ERROR: Failed to create Mixer plugin %d(%s)",
1365 __func__, errno, strerror(errno));
1366 goto exit;
1367 }
1368
1369 ALOGD("-%s-", __func__);
1370
1371 exit:
1372 return err;
1373
1374 }
1375
destroy_mixer_package(struct iaxxx_odsp_hw * odsp_hdl)1376 int destroy_mixer_package(struct iaxxx_odsp_hw *odsp_hdl)
1377 {
1378 int err = 0;
1379
1380 ALOGD("+%s+", __func__);
1381
1382 // Destroy Mixer Plugin
1383 err = iaxxx_odsp_plugin_destroy(odsp_hdl, MIXER_INSTANCE_ID,
1384 IAXXX_HMD_BLOCK_ID);
1385 if (err != 0) {
1386 ALOGE("%s: ERROR: Failed to destroy Mixer buffer plugin %d(%s)",
1387 __func__, errno, strerror(errno));
1388 goto exit;
1389 }
1390
1391 // Unload package for Mixer
1392 err = iaxxx_odsp_package_unload(odsp_hdl, MIXER_PKG_ID);
1393 if (err != 0) {
1394 ALOGE("%s: ERROR: Failed to unload sensor package error %d(%s)",
1395 __func__, errno, strerror(errno));
1396 goto exit;
1397 }
1398
1399 ALOGD("-%s-", __func__);
1400
1401 exit:
1402 return err;
1403 }
1404
setup_src_package(struct iaxxx_odsp_hw * odsp_hdl)1405 int setup_src_package(struct iaxxx_odsp_hw *odsp_hdl)
1406 {
1407 int err = 0;
1408
1409 ALOGD("+%s+", __func__);
1410
1411 err = iaxxx_odsp_package_load(odsp_hdl, SRC_PACKAGE, SRC_PKG_ID);
1412 if (err != 0) {
1413 ALOGE("%s: ERROR: Failed to load SRC package %d(%s)",
1414 __func__, errno, strerror(errno));
1415 goto exit;
1416 }
1417
1418 ALOGD("-%s-", __func__);
1419
1420 exit:
1421 return err;
1422
1423 }
1424
destroy_src_package(struct iaxxx_odsp_hw * odsp_hdl)1425 int destroy_src_package(struct iaxxx_odsp_hw *odsp_hdl)
1426 {
1427 int err = 0;
1428
1429 ALOGD("+%s+", __func__);
1430
1431 err = iaxxx_odsp_package_unload(odsp_hdl, SRC_PKG_ID);
1432 if (err != 0) {
1433 ALOGE("%s: ERROR: Failed to unload SRC package error %d(%s)",
1434 __func__, errno, strerror(errno));
1435 goto exit;
1436 }
1437
1438 ALOGD("-%s-", __func__);
1439
1440 exit:
1441 return err;
1442 }
1443
setup_music_buffer(struct iaxxx_odsp_hw * odsp_hdl)1444 int setup_music_buffer(struct iaxxx_odsp_hw *odsp_hdl)
1445 {
1446 int err = 0;
1447 struct iaxxx_create_config_data cdata;
1448
1449 ALOGD("+%s+", __func__);
1450
1451 // Create the 8 seconds Buffer plugin for Downlink Audio
1452 cdata.type = CONFIG_FILE;
1453 cdata.data.fdata.filename = BUFFER_CONFIG_VAL_MULTI_SEC;
1454 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1455 DA_BUF_INSTANCE_ID,
1456 IAXXX_HMD_BLOCK_ID,
1457 cdata);
1458 if (err != 0) {
1459 ALOGE("%s: ERROR: DA buffer configuration failed %d(%s)",
1460 __func__, errno, strerror(errno));
1461 goto exit;
1462 }
1463
1464 // Create Buffer plugin
1465 err = iaxxx_odsp_plugin_create(odsp_hdl,
1466 DA_BUF_INSTANCE_ID,
1467 BUF_PRIORITY, BUF_PKG_ID,
1468 BUF_PLUGIN_IDX,
1469 IAXXX_HMD_BLOCK_ID,
1470 PLUGIN_DEF_CONFIG_ID);
1471 if (err != 0) {
1472 ALOGE("%s: ERROR: Failed to create DA Buffer error %d(%s)",
1473 __func__, errno, strerror(errno));
1474 goto exit;
1475 }
1476 ALOGD("-%s-", __func__);
1477
1478 exit:
1479 return err;
1480 }
1481
destroy_music_buffer(struct iaxxx_odsp_hw * odsp_hdl)1482 int destroy_music_buffer(struct iaxxx_odsp_hw *odsp_hdl)
1483 {
1484 int err = 0;
1485
1486 ALOGD("+%s+", __func__);
1487 err = iaxxx_odsp_plugin_destroy(odsp_hdl,
1488 DA_BUF_INSTANCE_ID,
1489 IAXXX_HMD_BLOCK_ID);
1490 if (err == -1) {
1491 ALOGE("%s: ERROR: Failed to destroy DA buffer plugin %d(%s)",
1492 __func__, errno, strerror(errno));
1493 goto exit;
1494 }
1495
1496 ALOGD("-%s-", __func__);
1497
1498 exit:
1499 return err;
1500 }
1501
setup_howord_buffer(struct iaxxx_odsp_hw * odsp_hdl)1502 int setup_howord_buffer(struct iaxxx_odsp_hw *odsp_hdl)
1503 {
1504 struct iaxxx_create_config_data cdata;
1505 int err = 0;
1506
1507 ALOGD("+%s+", __func__);
1508
1509 cdata.type = CONFIG_FILE;
1510 cdata.data.fdata.filename = BUFFER_CONFIG_VAL_2_SEC;
1511 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1512 BUF_INSTANCE_ID,
1513 IAXXX_HMD_BLOCK_ID,
1514 cdata);
1515 if (err != 0) {
1516 ALOGE("%s: ERROR: 8 sec buffer configuration failed %d(%s)",
1517 __func__, errno, strerror(errno));
1518 goto exit;
1519 }
1520
1521 // Create Buffer plugin
1522 err = iaxxx_odsp_plugin_create(odsp_hdl, BUF_INSTANCE_ID,
1523 BUF_PRIORITY, BUF_PKG_ID, BUF_PLUGIN_IDX,
1524 IAXXX_HMD_BLOCK_ID, PLUGIN_DEF_CONFIG_ID);
1525 if (err != 0) {
1526 ALOGE("%s: ERROR: Failed to create Buffer Plugin %d(%s)",
1527 __func__, errno, strerror(errno));
1528 goto exit;
1529 }
1530
1531 ALOGD("-%s-", __func__);
1532
1533 exit:
1534 return err;
1535 }
1536
destroy_howord_buffer(struct iaxxx_odsp_hw * odsp_hdl)1537 int destroy_howord_buffer(struct iaxxx_odsp_hw *odsp_hdl)
1538 {
1539 int err = 0;
1540
1541 ALOGD("+%s+", __func__);
1542
1543 // Destroy Buffer plugin
1544 err = iaxxx_odsp_plugin_destroy(odsp_hdl, BUF_INSTANCE_ID,
1545 IAXXX_HMD_BLOCK_ID);
1546 if (err != 0) {
1547 ALOGE("%s: ERROR: Failed to destroy 8 sec buffer %d(%s)",
1548 __func__, errno, strerror(errno));
1549 goto exit;
1550 }
1551
1552 ALOGD("-%s-", __func__);
1553
1554 exit:
1555 return err;
1556 }
1557
setup_src_plugin(struct iaxxx_odsp_hw * odsp_hdl,enum src_type st)1558 int setup_src_plugin(struct iaxxx_odsp_hw *odsp_hdl, enum src_type st)
1559 {
1560 int err = 0;
1561 int plugin_instant_id = 0;
1562 struct iaxxx_create_config_data cdata;
1563
1564 if (st == SRC_MIC) {
1565 plugin_instant_id = SRC_MIC_INSTANCE_ID;
1566 } else if (st == SRC_AMP_REF) {
1567 plugin_instant_id = SRC_AMP_INSTANCE_ID;
1568 } else {
1569 ALOGE("%s: Invalid src type %d", __func__, st);
1570 err = -EINVAL;
1571 goto exit;
1572 }
1573
1574 ALOGD("+%s+ src type %d", __func__, st);
1575
1576 // set src config
1577 cdata.type = CONFIG_FILE;
1578 cdata.data.fdata.filename = SRC_CONFIG;
1579 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1580 plugin_instant_id,
1581 IAXXX_HMD_BLOCK_ID,
1582 cdata);
1583 if (err != 0) {
1584 ALOGE("%s: ERROR: SRC-%d configuration failed %d(%s)",
1585 __func__, st, errno, strerror(errno));
1586 goto exit;
1587 }
1588
1589 err = iaxxx_odsp_plugin_create(odsp_hdl, plugin_instant_id,
1590 SRC_PRIORITY, SRC_PKG_ID,
1591 SRC_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
1592 PLUGIN_DEF_CONFIG_ID);
1593 if (err != 0) {
1594 ALOGE("%s: ERROR: Failed to create SRC-%d plugin %d(%s)",
1595 __func__, st, errno, strerror(errno));
1596 goto exit;
1597 }
1598
1599 ALOGD("-%s-", __func__);
1600
1601 exit:
1602 return err;
1603 }
1604
destroy_src_plugin(struct iaxxx_odsp_hw * odsp_hdl,enum src_type st)1605 int destroy_src_plugin(struct iaxxx_odsp_hw *odsp_hdl, enum src_type st)
1606 {
1607 int err = 0;
1608 int plugin_instant_id = 0;
1609
1610 if (st == SRC_MIC) {
1611 plugin_instant_id = SRC_MIC_INSTANCE_ID;
1612 } else if (st == SRC_AMP_REF) {
1613 plugin_instant_id = SRC_AMP_INSTANCE_ID;
1614 } else {
1615 ALOGE("%s: Invalid src type %d", __func__, st);
1616 err = -EINVAL;
1617 goto exit;
1618 }
1619 ALOGD("+%s+ src type %d", __func__, st);
1620
1621 err = iaxxx_odsp_plugin_destroy(odsp_hdl, plugin_instant_id,
1622 IAXXX_HMD_BLOCK_ID);
1623 if (err != 0) {
1624 ALOGE("%s: ERROR: Failed to destroy SRC plugin %d(%s)",
1625 __func__, errno, strerror(errno));
1626 goto exit;
1627 }
1628
1629 ALOGD("-%s-", __func__);
1630
1631 exit:
1632 return err;
1633 }
1634
set_hotword_buffer_route(struct audio_route * route_hdl,bool bargein)1635 int set_hotword_buffer_route(struct audio_route *route_hdl, bool bargein)
1636 {
1637 int err = 0;
1638
1639 ALOGD("+%s %d+", __func__, bargein);
1640
1641 if (bargein == true)
1642 err = audio_route_apply_and_update_path(route_hdl,
1643 route_table[ST_HOTWORD_BUFFER_WITH_BARGEIN]);
1644 else
1645 err = audio_route_apply_and_update_path(route_hdl,
1646 route_table[ST_HOTWORD_BUFFER_WITHOUT_BARGEIN]);
1647 if (err)
1648 ALOGE("%s: route fail %d", __func__, err);
1649
1650 ALOGD("-%s-", __func__);
1651 return err;
1652 }
1653
tear_hotword_buffer_route(struct audio_route * route_hdl,bool bargein)1654 int tear_hotword_buffer_route(struct audio_route *route_hdl, bool bargein)
1655 {
1656 int err = 0;
1657
1658 ALOGD("+%s %d+", __func__, bargein);
1659
1660 if (bargein == true)
1661 err = audio_route_reset_and_update_path(route_hdl,
1662 route_table[ST_HOTWORD_BUFFER_WITH_BARGEIN]);
1663 else
1664 err = audio_route_reset_and_update_path(route_hdl,
1665 route_table[ST_HOTWORD_BUFFER_WITHOUT_BARGEIN]);
1666 if (err)
1667 ALOGE("%s: route fail %d", __func__, err);
1668
1669 ALOGD("-%s-", __func__);
1670 return err;
1671 }
1672
enable_bargein_route(struct audio_route * route_hdl,bool enable)1673 int enable_bargein_route(struct audio_route *route_hdl, bool enable)
1674 {
1675 int err = 0;
1676
1677 ALOGV("+%s+ %d", __func__, enable);
1678 if (enable)
1679 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_BARGEIN_ROUTE]);
1680 else
1681 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_BARGEIN_ROUTE]);
1682 if (err)
1683 ALOGE("%s: route fail %d", __func__, err);
1684
1685 ALOGD("-%s-", __func__);
1686 return err;
1687 }
1688
enable_amp_ref_route(struct audio_route * route_hdl,bool enable,enum strm_type strmt)1689 int enable_amp_ref_route(struct audio_route *route_hdl, bool enable,
1690 enum strm_type strmt)
1691 {
1692 int err = 0;
1693
1694 ALOGV("+%s+ %d strm type %d", __func__, enable, strmt);
1695 if (strmt == STRM_16K) {
1696 if (enable)
1697 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF]);
1698 else
1699 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF]);
1700 } else if (strmt == STRM_48K) {
1701 if (enable)
1702 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF_48K]);
1703 else
1704 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF_48K]);
1705 } else {
1706 ALOGE("%s: ERROR: Invalid strm type", __func__);
1707 err = -EINVAL;
1708 }
1709
1710 if (err)
1711 ALOGE("%s: route fail %d", __func__, err);
1712
1713 ALOGD("-%s-", __func__);
1714 return err;
1715 }
1716
set_music_buffer_route(struct audio_route * route_hdl,bool downlink)1717 int set_music_buffer_route(struct audio_route *route_hdl, bool downlink)
1718 {
1719 int err = 0;
1720
1721 ALOGD("+%s+ %d", __func__, downlink);
1722 if (downlink)
1723 err = audio_route_apply_and_update_path(route_hdl,
1724 route_table[ST_AMBIENT_BUFFER_WITHOUT_BARGEIN]);
1725 else
1726 err = audio_route_apply_and_update_path(route_hdl,
1727 route_table[ST_AMBIENT_BUFFER_WITH_BARGEIN]);
1728 if (err)
1729 ALOGE("%s: route fail %d", __func__, err);
1730
1731 ALOGD("-%s-", __func__);
1732 return err;
1733 }
1734
tear_music_buffer_route(struct audio_route * route_hdl,bool downlink)1735 int tear_music_buffer_route(struct audio_route *route_hdl, bool downlink)
1736 {
1737 int err = 0;
1738
1739 ALOGD("+%s+ %d", __func__, downlink);
1740 if (downlink)
1741 err = audio_route_reset_and_update_path(route_hdl,
1742 route_table[ST_AMBIENT_BUFFER_WITHOUT_BARGEIN]);
1743 else
1744 err = audio_route_reset_and_update_path(route_hdl,
1745 route_table[ST_AMBIENT_BUFFER_WITH_BARGEIN]);
1746 if (err)
1747 ALOGE("%s: route fail %d", __func__, err);
1748
1749 ALOGD("-%s-", __func__);
1750 return err;
1751 }
1752
enable_src_route(struct audio_route * route_hdl,bool enable,enum src_type st)1753 int enable_src_route(struct audio_route *route_hdl, bool enable, enum src_type st)
1754 {
1755 int err = 0;
1756
1757 ALOGV("+%s+ %d src type %d", __func__, enable, st);
1758
1759 if (st == SRC_MIC) {
1760 if (enable)
1761 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_MIC]);
1762 else
1763 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_MIC]);
1764 } else if (st == SRC_AMP_REF) {
1765 if (enable)
1766 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_AMP_REF]);
1767 else
1768 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_AMP_REF]);
1769
1770 } else {
1771 ALOGE("%s: ERROR: Invalid src type", __func__);
1772 err = -EINVAL;
1773 }
1774
1775 if (err)
1776 ALOGE("%s: route fail %d", __func__, err);
1777
1778 ALOGD("-%s-", __func__);
1779 return err;
1780 }
1781
enable_mic_route(struct audio_route * route_hdl,bool enable,enum clock_type ct)1782 int enable_mic_route(struct audio_route *route_hdl, bool enable,
1783 enum clock_type ct)
1784 {
1785 int err = 0;
1786
1787 ALOGD("+%s+ %d clock type %d", __func__, enable, ct);
1788
1789 if (ct == EXTERNAL_OSCILLATOR) {
1790 if (enable) {
1791 err = audio_route_apply_and_update_path(route_hdl,
1792 route_table[ST_MIC_ROUTE_EXT_CLK]);
1793 } else {
1794 err = audio_route_reset_and_update_path(route_hdl,
1795 route_table[ST_MIC_ROUTE_EXT_CLK]);
1796 }
1797 } else if (ct == INTERNAL_OSCILLATOR) {
1798 if (enable) {
1799 err = audio_route_apply_and_update_path(route_hdl,
1800 route_table[ST_MIC_ROUTE_INT_CLK]);
1801 } else {
1802 err = audio_route_reset_and_update_path(route_hdl,
1803 route_table[ST_MIC_ROUTE_INT_CLK]);
1804 }
1805 } else {
1806 ALOGE("%s: ERROR: Invalid clock type", __func__);
1807 err = -EINVAL;
1808 }
1809
1810 if (err)
1811 ALOGE("%s: route fail %d", __func__, err);
1812
1813 ALOGD("-%s-", __func__);
1814 return err;
1815 }
1816
get_entity_param_blk(struct iaxxx_odsp_hw * odsp_hdl,void * payload,unsigned int payload_size)1817 int get_entity_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload,
1818 unsigned int payload_size)
1819 {
1820 int err = 0;
1821 err = iaxxx_odsp_plugin_get_parameter_blk(odsp_hdl,
1822 AMBIENT_INSTANCE_ID,
1823 IAXXX_HMD_BLOCK_ID,
1824 PARAM_BLOCK_GET_RECOGNITION_PAYLOAD,
1825 payload, payload_size);
1826
1827 if (err < 0) {
1828 ALOGE("%s: Failed to get param blk error %s\n",
1829 __func__, strerror(errno));
1830 }
1831 return err;
1832 }
1833
get_wakeup_param_blk(struct iaxxx_odsp_hw * odsp_hdl,void * payload,unsigned int payload_size)1834 int get_wakeup_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload,
1835 unsigned int payload_size)
1836 {
1837 int err = 0;
1838 err = iaxxx_odsp_plugin_get_parameter_blk(odsp_hdl,
1839 HOTWORD_INSTANCE_ID,
1840 IAXXX_HMD_BLOCK_ID,
1841 PARAM_BLOCK_GET_RECOGNITION_PAYLOAD,
1842 payload, payload_size);
1843
1844 if (err < 0) {
1845 ALOGE("%s: Failed to get param blk error %s\n",
1846 __func__, strerror(errno));
1847 }
1848 return err;
1849 }
1850
set_default_apll_clk(struct mixer * mixer)1851 int set_default_apll_clk(struct mixer *mixer) {
1852
1853 int ret = 0;
1854 struct mixer_ctl* ctl;
1855
1856 ALOGD("+Entering %s+", __func__);
1857
1858 if (!mixer) {
1859 ALOGE("%s mixer is NULL", __func__);
1860 return -EINVAL;
1861 }
1862
1863 ctl = mixer_get_ctl_by_name(mixer, "Port ApllCLK");
1864 if (ctl) {
1865 ret = mixer_ctl_set_enum_by_string(ctl, "IAXXX_ACLK_FREQ_24576");
1866 if (ret)
1867 ALOGE("%s: update ApllCLK fail! ret = %d", __func__, ret);
1868 } else {
1869 ALOGE("%s: get Port ApllCL control fail", __func__);
1870 ret = -ENODEV;
1871 }
1872
1873 ALOGD("-Exiting %s-", __func__);
1874 return ret;
1875 }
1876
get_fw_status(struct iaxxx_odsp_hw * odsp_hdl,unsigned int * status)1877 int get_fw_status(struct iaxxx_odsp_hw *odsp_hdl, unsigned int *status)
1878 {
1879 int err;
1880
1881 ALOGD("+%s+", __func__);
1882
1883 err = iaxxx_odsp_get_fw_status(odsp_hdl,
1884 status);
1885 if (err == -1) {
1886 ALOGE("%s: ERROR: Failed to get fw status with error %d(%s)",
1887 __func__, errno, strerror(errno));
1888 goto exit;
1889 }
1890
1891 ALOGE("Firmware status is %d", *status);
1892
1893 exit:
1894 ALOGD("-%s-", __func__);
1895 return err;
1896 }
1897
reset_fw(struct iaxxx_odsp_hw * odsp_hdl)1898 int reset_fw(struct iaxxx_odsp_hw *odsp_hdl)
1899 {
1900 int err;
1901
1902 ALOGD("+%s+", __func__);
1903 err = iaxxx_odsp_reset_fw(odsp_hdl);
1904 if (err == -1) {
1905 ALOGE("%s: ERROR: Failed to reset fw with error %d(%s)",
1906 __func__, errno, strerror(errno));
1907 goto exit;
1908 }
1909
1910 exit:
1911 ALOGD("-%s-", __func__);
1912 return err;
1913 }
1914
reset_all_route(struct audio_route * route_hdl)1915 int reset_all_route(struct audio_route *route_hdl)
1916 {
1917 int err = 0;
1918
1919 ALOGD("+%s+", __func__);
1920 for (int i = ST_ROUTE_MIN; i < ST_ROUTE_MAX; i++) {
1921 audio_route_force_reset_and_update_path(route_hdl, route_table[i]);
1922 }
1923 ALOGD("-%s-", __func__);
1924 return err;
1925 }
1926
setup_slpi_wakeup_event(struct iaxxx_odsp_hw * odsp_hdl,bool enabled)1927 int setup_slpi_wakeup_event(struct iaxxx_odsp_hw *odsp_hdl, bool enabled)
1928 {
1929 int err;
1930
1931 ALOGD("+%s+", __func__);
1932
1933 if (enabled) {
1934 err = iaxxx_odsp_evt_subscribe(odsp_hdl, IAXXX_SYSID_CTRL_MGR_CM4,
1935 IAXXX_HOST1_WAKEUP_EVENT_ID,
1936 IAXXX_SYSID_HOST_1, 0);
1937 if (err != 0) {
1938 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)"
1939 " IOCTL failed %d(%s)", __func__, IAXXX_HOST1_WAKEUP_EVENT_ID,
1940 IAXXX_SYSID_CTRL_MGR_CM4, errno, strerror(errno));
1941 goto exit;
1942 }
1943 } else {
1944 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, IAXXX_SYSID_CTRL_MGR_CM4,
1945 IAXXX_HOST1_WAKEUP_EVENT_ID,
1946 IAXXX_SYSID_HOST_1);
1947 if (err != 0) {
1948 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)"
1949 " IOCTL failed %d(%s)", __func__, IAXXX_HOST1_WAKEUP_EVENT_ID,
1950 IAXXX_SYSID_CTRL_MGR_CM4, errno, strerror(errno));
1951 goto exit;
1952 }
1953 }
1954 exit:
1955 ALOGD("-%s-", __func__);
1956 return err;
1957 }
1958