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_version(struct iaxxx_odsp_hw * odsp_hdl)799 unsigned int get_hotword_version(struct iaxxx_odsp_hw *odsp_hdl)
800 {
801 int err = 0;
802 const uint32_t inst_id = HOTWORD_INSTANCE_ID;
803 const uint32_t param_id = HOTWORD_GET_VERSION_PARAM_ID;
804 const uint32_t block_id = IAXXX_HMD_BLOCK_ID;
805 unsigned int param_val = HOTWORD_DEFAULT_VER;
806
807 err = setup_hotword_package(odsp_hdl);
808 if (err != 0) {
809 if (errno == EEXIST) {
810 ALOGW("%s: WARN: Hotword package existed already", __func__);
811 err = iaxxx_odsp_plugin_get_parameter(odsp_hdl, inst_id, param_id,
812 block_id, ¶m_val);
813 if (err != 0) {
814 ALOGE("%s: Failed to get parameter for id %u with error %d: %s",
815 __func__, param_id, err, strerror(errno));
816 } else {
817 ALOGD("%s: Value of parameter id %u is %u", __func__, param_id,
818 param_val);
819 }
820 } else {
821 ALOGE("%s: ERROR: setup hotword package failed", __func__);
822 }
823 } else {
824 err = iaxxx_odsp_plugin_get_parameter(odsp_hdl, inst_id, param_id,
825 block_id, ¶m_val);
826 if (err != 0) {
827 ALOGE("%s: Failed to get parameter for id %u with error %d: %s",
828 __func__, param_id, err, strerror(errno));
829 } else {
830 ALOGD("%s: Value of parameter id %u is %u", __func__, param_id,
831 param_val);
832 }
833 err = destroy_hotword_package(odsp_hdl);
834 if (err != 0)
835 ALOGE("%s: ERROR: destroy hotword package failed", __func__);
836 }
837
838 return param_val;
839 }
840
setup_ambient_package(struct iaxxx_odsp_hw * odsp_hdl)841 int setup_ambient_package(struct iaxxx_odsp_hw *odsp_hdl)
842 {
843 int err = 0;
844
845 ALOGD("+%s+", __func__);
846
847 // Download packages for ambient
848 err = iaxxx_odsp_package_load(odsp_hdl, AMBIENT_DA_PACKAGE,
849 AMBIENT_PKG_ID);
850 if (err != 0) {
851 ALOGE("%s: ERROR: Failed to load Ambient package %d(%s)",
852 __func__, errno, strerror(errno));
853 goto exit;
854 }
855
856 // Create Ambient plugin
857 err = iaxxx_odsp_plugin_create(odsp_hdl, AMBIENT_INSTANCE_ID,
858 AMBIENT_PRIORITY, AMBIENT_PKG_ID,
859 AMBIENT_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
860 PLUGIN_DEF_CONFIG_ID);
861 if (err != 0) {
862 ALOGE("%s: ERROR: Failed to create Ambient plugin %d(%s)",
863 __func__, errno, strerror(errno));
864 goto exit;
865 }
866
867 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, AMBIENT_INSTANCE_ID,
868 0, 0, IAXXX_HMD_BLOCK_ID);
869 if (err != 0) {
870 ALOGE("%s: ERROR: Ambient init frontend failed %d(%s)",
871 __func__, errno, strerror(errno));
872 goto exit;
873 }
874
875 ALOGD("-%s-", __func__);
876
877 exit:
878 return err;
879 }
880
destroy_ambient_package(struct iaxxx_odsp_hw * odsp_hdl)881 int destroy_ambient_package(struct iaxxx_odsp_hw *odsp_hdl)
882 {
883 int err = 0;
884
885 ALOGD("+%s+", __func__);
886
887 err = iaxxx_odsp_plugin_destroy(odsp_hdl, AMBIENT_INSTANCE_ID,
888 IAXXX_HMD_BLOCK_ID);
889 if (err != 0) {
890 ALOGE("%s: ERROR: Failed to destroy Ambient plugin %d(%s)",
891 __func__, errno, strerror(errno));
892 goto exit;
893 }
894
895 err = iaxxx_odsp_package_unload(odsp_hdl, AMBIENT_PKG_ID);
896 if (err != 0) {
897 ALOGE("%s: ERROR: Failed to unload Ambient package %d(%s)",
898 __func__, errno, strerror(errno));
899 goto exit;
900 }
901
902 ALOGD("-%s-", __func__);
903
904 exit:
905 return err;
906 }
907
get_ambient_version(struct iaxxx_odsp_hw * odsp_hdl)908 unsigned int get_ambient_version(struct iaxxx_odsp_hw *odsp_hdl)
909 {
910 int err = 0;
911 const uint32_t inst_id = AMBIENT_INSTANCE_ID;
912 const uint32_t param_id = AMBIENT_GET_VERSION_PARAM_ID;
913 const uint32_t block_id = IAXXX_HMD_BLOCK_ID;
914 unsigned int param_val = AMBIENT_DEFAULT_VER;
915
916 err = setup_ambient_package(odsp_hdl);
917 if (err != 0) {
918 if (errno == EEXIST) {
919 ALOGW("%s: WARN: Ambient package existed already", __func__);
920 err = iaxxx_odsp_plugin_get_parameter(odsp_hdl, inst_id, param_id,
921 block_id, ¶m_val);
922 if (err != 0) {
923 ALOGE("%s: Failed to get parameter for id %u with error %d: %s",
924 __func__, param_id, err, strerror(errno));
925 } else {
926 ALOGD("%s: Value of parameter id %u is %u", __func__, param_id,
927 param_val);
928 }
929 } else {
930 ALOGE("%s: ERROR: setup Ambient package failed", __func__);
931 }
932 } else {
933 err = iaxxx_odsp_plugin_get_parameter(odsp_hdl, inst_id, param_id,
934 block_id, ¶m_val);
935 if (err != 0) {
936 ALOGE("%s: Failed to get parameter for id %u with error %d: %s",
937 __func__, param_id, err, strerror(errno));
938 } else {
939 ALOGD("%s: Value of parameter id %u is %u", __func__, param_id,
940 param_val);
941 }
942 err = destroy_ambient_package(odsp_hdl);
943 if (err != 0)
944 ALOGE("%s: ERROR: destroy Ambient package failed", __func__);
945 }
946
947 return param_val;
948 }
949
setup_aec_package(struct iaxxx_odsp_hw * odsp_hdl)950 int setup_aec_package(struct iaxxx_odsp_hw *odsp_hdl)
951 {
952 int err = 0;
953
954 ALOGD("+%s+", __func__);
955
956 err = iaxxx_odsp_package_load(odsp_hdl, ECHOCANCELLER_PACKAGE,
957 AEC_PKG_ID);
958 if (err != 0) {
959 ALOGE("%s: ERROR: Failed to load AEC passthrough package %d(%s)",
960 __func__, errno, strerror(errno));
961 goto exit;
962 }
963
964 // AEC PT Plugin Create
965 err = iaxxx_odsp_plugin_create(odsp_hdl, AEC_INSTANCE_ID, AEC_PRIORITY,
966 AEC_PKG_ID, AEC_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
967 PLUGIN_DEF_CONFIG_ID);
968 if (err != 0) {
969 ALOGE("%s: ERROR: Failed to create AEC plugin %d(%s)",
970 __func__, errno, strerror(errno));
971 goto exit;
972 }
973
974 ALOGD("-%s-", __func__);
975
976 exit:
977 return err;
978 }
979
destroy_aec_package(struct iaxxx_odsp_hw * odsp_hdl)980 int destroy_aec_package(struct iaxxx_odsp_hw *odsp_hdl)
981 {
982 int err = 0;
983
984 ALOGD("+%s+", __func__);
985
986 err = iaxxx_odsp_plugin_destroy(odsp_hdl, AEC_INSTANCE_ID,
987 IAXXX_HMD_BLOCK_ID);
988 if (err != 0) {
989 ALOGE("%s: ERROR: Failed to destroy AEC plugin %d(%s)",
990 __func__, errno, strerror(errno));
991 goto exit;
992 }
993
994 err = iaxxx_odsp_package_unload(odsp_hdl, AEC_PKG_ID);
995 if (err != 0) {
996 ALOGE("%s: ERROR: Failed to unload AEC package %d(%s)",
997 __func__, errno, strerror(errno));
998 goto exit;
999 }
1000
1001 ALOGD("-%s-", __func__);
1002
1003 exit:
1004 return err;
1005 }
1006
setup_chre_package(struct iaxxx_odsp_hw * odsp_hdl)1007 int setup_chre_package(struct iaxxx_odsp_hw *odsp_hdl)
1008 {
1009 int err = 0;
1010 struct iaxxx_create_config_data cdata;
1011
1012 ALOGD("+%s+", __func__);
1013
1014 /* Create CHRE plugins */
1015 cdata.type = CONFIG_FILE;
1016 cdata.data.fdata.filename = BUFFER_CONFIG_VAL_CHRE;
1017 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1018 CHRE_INSTANCE_ID,
1019 IAXXX_HMD_BLOCK_ID,
1020 cdata);
1021 if (err != 0) {
1022 ALOGE("%s: ERROR: CHRE Buffer configuration failed %d(%s)",
1023 __func__, errno, strerror(errno));
1024 goto exit;
1025 }
1026
1027 // Create CHRE Buffer plugin
1028 err = iaxxx_odsp_plugin_create(odsp_hdl, CHRE_INSTANCE_ID, BUF_PRIORITY,
1029 BUF_PKG_ID, CHRE_PLUGIN_IDX,
1030 IAXXX_HMD_BLOCK_ID, PLUGIN_DEF_CONFIG_ID);
1031 if (err != 0) {
1032 ALOGE("%s: ERROR: Failed to create CHRE buffer %d(%s)",
1033 __func__, errno, strerror(errno));
1034 goto exit;
1035 }
1036
1037 err = iaxxx_odsp_plugin_set_parameter(odsp_hdl, CHRE_INSTANCE_ID,
1038 CHRE_EVT_PARAM_ID, CHRE_BUF_SIZE,
1039 IAXXX_HMD_BLOCK_ID);
1040 if (err != 0) {
1041 ALOGE("%s: ERROR: CHRE buffer set param failed %d(%s)",
1042 __func__, errno, strerror(errno));
1043 goto exit;
1044 }
1045
1046 err = iaxxx_odsp_plugin_setevent(odsp_hdl, CHRE_INSTANCE_ID,
1047 CHRE_EVT_MASK, IAXXX_HMD_BLOCK_ID);
1048 if (err != 0) {
1049 ALOGE("%s: ERROR: CHRE set event failed %d(%s)",
1050 __func__, errno, strerror(errno));
1051 goto exit;
1052 }
1053
1054 // Subscribe for events
1055 err = iaxxx_odsp_evt_subscribe(odsp_hdl, CHRE_EVT_SRC_ID,
1056 CHRE_EVT_ID, IAXXX_SYSID_HOST_1, 0);
1057 if (err != 0) {
1058 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)"
1059 " IOCTL failed %d(%s)", __func__, CHRE_EVT_ID, CHRE_EVT_SRC_ID,
1060 errno, strerror(errno));
1061 goto exit;
1062 }
1063
1064 err = iaxxx_odsp_evt_subscribe(odsp_hdl, CHRE_EVT_SRC_ID,
1065 CHRE_CONFIGURED, IAXXX_SYSID_HOST_1, 0);
1066 if (err != 0) {
1067 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)"
1068 " IOCTL failed %d(%s)", __func__, CHRE_CONFIGURED, CHRE_EVT_SRC_ID,
1069 errno, strerror(errno));
1070 goto exit;
1071 }
1072
1073 err = iaxxx_odsp_evt_subscribe(odsp_hdl, CHRE_EVT_SRC_ID,
1074 CHRE_DESTROYED, IAXXX_SYSID_HOST_1, 0);
1075 if (err != 0) {
1076 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)"
1077 " IOCTL failed %d(%s)", __func__, CHRE_DESTROYED, CHRE_EVT_SRC_ID,
1078 errno, strerror(errno));
1079 goto exit;
1080 }
1081
1082 err = iaxxx_odsp_evt_subscribe(odsp_hdl, IAXXX_SYSID_HOST_1,
1083 CHRE_EP_DISCONNECT, IAXXX_SYSID_HOST_0, 0);
1084 if (err == -1) {
1085 ALOGE("%s: ERROR: CHRE event subscription (CHRE EP disconnect) failed "
1086 " with error %d(%s)", __func__, errno, strerror(errno));
1087 goto exit;
1088 }
1089
1090 err = iaxxx_odsp_evt_trigger(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_CONFIGURED, 0);
1091 if (err != 0) {
1092 ALOGE("%s: ERROR: CHRE event trigger (chre configured) failed %d(%s)",
1093 __func__, errno, strerror(errno));
1094 goto exit;
1095 }
1096
1097 ALOGD("-%s-", __func__);
1098
1099 exit:
1100 return err;
1101 }
1102
destroy_chre_package(struct iaxxx_odsp_hw * odsp_hdl)1103 int destroy_chre_package(struct iaxxx_odsp_hw *odsp_hdl)
1104 {
1105 int err = 0;
1106
1107 ALOGD("+%s+", __func__);
1108
1109 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_EVT_ID,
1110 IAXXX_SYSID_HOST_1);
1111 if (err != 0) {
1112 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)"
1113 " IOCTL failed %d(%s)", __func__, CHRE_EVT_ID, CHRE_EVT_SRC_ID,
1114 errno, strerror(errno));
1115 goto exit;
1116 }
1117
1118 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_CONFIGURED,
1119 IAXXX_SYSID_HOST_1);
1120 if (err != 0) {
1121 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)"
1122 " IOCTL failed %d(%s)", __func__, CHRE_CONFIGURED, CHRE_EVT_SRC_ID,
1123 errno, strerror(errno));
1124 goto exit;
1125 }
1126
1127 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_DESTROYED,
1128 IAXXX_SYSID_HOST_1);
1129 if (err != 0) {
1130 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)"
1131 " IOCTL failed %d(%s)", __func__, CHRE_DESTROYED, CHRE_EVT_SRC_ID,
1132 errno, strerror(errno));
1133 goto exit;
1134 }
1135
1136 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, IAXXX_SYSID_HOST_1,
1137 CHRE_EP_DISCONNECT, IAXXX_SYSID_HOST_0);
1138 if (err == -1) {
1139 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)"
1140 " IOCTL failed with error %d(%s)", __func__, CHRE_EP_DISCONNECT,
1141 IAXXX_SYSID_HOST_1, errno, strerror(errno));
1142 goto exit;
1143 }
1144
1145 err = iaxxx_odsp_plugin_destroy(odsp_hdl, CHRE_INSTANCE_ID,
1146 IAXXX_HMD_BLOCK_ID);
1147 if (err != 0) {
1148 ALOGE("%s: ERROR: Failed to destroy buffer plugin for CHRE %d(%s)",
1149 __func__, errno, strerror(errno));
1150 goto exit;
1151 }
1152
1153 ALOGD("-%s-", __func__);
1154
1155 exit:
1156 return err;
1157 }
1158
trigger_chre_destroy_event(struct iaxxx_odsp_hw * odsp_hdl)1159 int trigger_chre_destroy_event(struct iaxxx_odsp_hw *odsp_hdl) {
1160 int err = 0;
1161
1162 ALOGD("+%s+", __func__);
1163
1164 err = iaxxx_odsp_evt_trigger(odsp_hdl, CHRE_EVT_SRC_ID, CHRE_DESTROYED, 0);
1165 if (err == -1) {
1166 ALOGE("%s: ERROR: CHRE event trigger (chre destroyed) failed with "
1167 "error %d(%s)", __func__, errno, strerror(errno));
1168 goto exit;
1169 }
1170
1171 exit:
1172 ALOGD("-%s-", __func__);
1173 return err;
1174 }
1175
setup_sensor_package(struct iaxxx_odsp_hw * odsp_hdl)1176 int setup_sensor_package(struct iaxxx_odsp_hw *odsp_hdl)
1177 {
1178 int err = 0;
1179 struct iaxxx_create_config_data cdata;
1180
1181 ALOGD("+%s+", __func__);
1182
1183 // Download sensor packages
1184 err = iaxxx_odsp_package_load(odsp_hdl, SENSOR_PACKAGE, SENSOR_PKG_ID);
1185 if (err != 0) {
1186 ALOGE("%s: ERROR: Failed to load Sensor package %d(%s)",
1187 __func__, errno, strerror(errno));
1188 goto exit;
1189 }
1190
1191 /* Create plugins */
1192 cdata.type = CONFIG_FILE;
1193 cdata.data.fdata.filename = BUFFER_CONFIG_OSLO_VAL;
1194 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1195 OSLO_BUF_INSTANCE_ID,
1196 IAXXX_HMD_BLOCK_ID,
1197 cdata);
1198 if (err != 0) {
1199 ALOGE("%s: ERROR: Sensor buffer configuration failed %d(%s)",
1200 __func__, errno, strerror(errno));
1201 goto exit;
1202 }
1203
1204 // Create Buffer plugin
1205 err = iaxxx_odsp_plugin_create(odsp_hdl, OSLO_BUF_INSTANCE_ID,
1206 OSLO_BUF_PRIORITY, BUF_PKG_ID,
1207 BUF_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
1208 PLUGIN_DEF_CONFIG_ID);
1209 if (err != 0) {
1210 ALOGE("%s: ERROR: Failed to create Sensor Buffer %d(%s)",
1211 __func__, errno, strerror(errno));
1212 goto exit;
1213 }
1214
1215 cdata.type = CONFIG_FILE;
1216 cdata.data.fdata.filename = SENSOR_CONFIG_VAL;
1217 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1218 SENSOR_INSTANCE_ID,
1219 IAXXX_HMD_BLOCK_ID,
1220 cdata);
1221 if (err == -1) {
1222 ALOGE("%s: ERROR: Sensor configuration %d(%s)",
1223 __func__, errno, strerror(errno));
1224 return err;
1225 }
1226
1227 // Create Dummy sensor plugin
1228 err = iaxxx_odsp_plugin_create(odsp_hdl, SENSOR_INSTANCE_ID,
1229 SENSOR_PRIORITY, SENSOR_PKG_ID,
1230 SENSOR_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
1231 PLUGIN_DEF_CONFIG_ID);
1232 if (err != 0) {
1233 ALOGE("%s: ERROR: Failed to create Sensor plugin %d(%s)",
1234 __func__, errno, strerror(errno));
1235 goto exit;
1236 }
1237
1238 err = sensor_event_init_params(odsp_hdl);
1239 if (err) {
1240 ALOGE("%s: ERROR: Sensor event init failed %d", __func__, err);
1241 goto exit;
1242 }
1243
1244 ALOGD("-%s-", __func__);
1245
1246 exit:
1247 return err;
1248 }
1249
destroy_sensor_package(struct iaxxx_odsp_hw * odsp_hdl)1250 int destroy_sensor_package(struct iaxxx_odsp_hw *odsp_hdl)
1251 {
1252 int err = 0;
1253
1254 ALOGD("+%s+", __func__);
1255
1256 err = sensor_event_deinit_params(odsp_hdl);
1257 if (err != 0) {
1258 ALOGE("%s: ERROR: Sensor event uninit failed %d", __func__, err);
1259 goto exit;
1260 }
1261
1262 err = iaxxx_odsp_plugin_destroy(odsp_hdl, SENSOR_INSTANCE_ID,
1263 IAXXX_HMD_BLOCK_ID);
1264 if (err != 0) {
1265 ALOGE("%s: ERROR: Failed to destroy sensor plugin %d(%s)",
1266 __func__, errno, strerror(errno));
1267 goto exit;
1268 }
1269
1270 err = iaxxx_odsp_plugin_destroy(odsp_hdl, OSLO_BUF_INSTANCE_ID,
1271 IAXXX_HMD_BLOCK_ID);
1272 if (err != 0) {
1273 ALOGE("%s: ERROR: Failed to destroy sensor buffer plugin %d(%s)",
1274 __func__, errno, strerror(errno));
1275 goto exit;
1276 }
1277
1278 err = iaxxx_odsp_package_unload(odsp_hdl, SENSOR_PKG_ID);
1279 if (err != 0) {
1280 ALOGE("%s: ERROR: Failed to unload sensor package %d(%s)",
1281 __func__, errno, strerror(errno));
1282 goto exit;
1283 }
1284
1285 ALOGD("-%s-", __func__);
1286
1287 exit:
1288 return err;
1289 }
1290
trigger_sensor_destroy_event(struct iaxxx_odsp_hw * odsp_hdl)1291 int trigger_sensor_destroy_event(struct iaxxx_odsp_hw *odsp_hdl)
1292 {
1293 int err = 0;
1294
1295 ALOGD("+%s+", __func__);
1296
1297 err = iaxxx_odsp_evt_trigger(odsp_hdl, OSLO_EVT_SRC_ID, OSLO_DESTROYED, 0);
1298 if (err == -1)
1299 ALOGE("%s: ERROR: oslo event trigger (oslo destroyed) failed with "
1300 "error %d(%s)", __func__, errno, strerror(errno));
1301
1302 ALOGD("-%s-", __func__);
1303 return err;
1304 }
1305
setup_mixer_package(struct iaxxx_odsp_hw * odsp_hdl)1306 int setup_mixer_package(struct iaxxx_odsp_hw *odsp_hdl)
1307 {
1308 int err = 0;
1309
1310 ALOGD("+%s+", __func__);
1311
1312 // Load package for Mixer
1313 err = iaxxx_odsp_package_load(odsp_hdl, MIXER_PACKAGE, MIXER_PKG_ID);
1314 if (err != 0) {
1315 ALOGE("%s: ERROR: Failed to load Mixer package %d(%s)",
1316 __func__, errno, strerror(errno));
1317 goto exit;
1318 }
1319
1320 // Create Mixer Plugin
1321 err = iaxxx_odsp_plugin_create(odsp_hdl, MIXER_INSTANCE_ID,
1322 MIXER_PRIORITY, MIXER_PKG_ID,
1323 MIXER_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
1324 PLUGIN_DEF_CONFIG_ID);
1325 if (err != 0) {
1326 ALOGE("%s: ERROR: Failed to create Mixer plugin %d(%s)",
1327 __func__, errno, strerror(errno));
1328 goto exit;
1329 }
1330
1331 ALOGD("-%s-", __func__);
1332
1333 exit:
1334 return err;
1335
1336 }
1337
destroy_mixer_package(struct iaxxx_odsp_hw * odsp_hdl)1338 int destroy_mixer_package(struct iaxxx_odsp_hw *odsp_hdl)
1339 {
1340 int err = 0;
1341
1342 ALOGD("+%s+", __func__);
1343
1344 // Destroy Mixer Plugin
1345 err = iaxxx_odsp_plugin_destroy(odsp_hdl, MIXER_INSTANCE_ID,
1346 IAXXX_HMD_BLOCK_ID);
1347 if (err != 0) {
1348 ALOGE("%s: ERROR: Failed to destroy Mixer buffer plugin %d(%s)",
1349 __func__, errno, strerror(errno));
1350 goto exit;
1351 }
1352
1353 // Unload package for Mixer
1354 err = iaxxx_odsp_package_unload(odsp_hdl, MIXER_PKG_ID);
1355 if (err != 0) {
1356 ALOGE("%s: ERROR: Failed to unload sensor package error %d(%s)",
1357 __func__, errno, strerror(errno));
1358 goto exit;
1359 }
1360
1361 ALOGD("-%s-", __func__);
1362
1363 exit:
1364 return err;
1365 }
1366
setup_src_package(struct iaxxx_odsp_hw * odsp_hdl)1367 int setup_src_package(struct iaxxx_odsp_hw *odsp_hdl)
1368 {
1369 int err = 0;
1370
1371 ALOGD("+%s+", __func__);
1372
1373 err = iaxxx_odsp_package_load(odsp_hdl, SRC_PACKAGE, SRC_PKG_ID);
1374 if (err != 0) {
1375 ALOGE("%s: ERROR: Failed to load SRC package %d(%s)",
1376 __func__, errno, strerror(errno));
1377 goto exit;
1378 }
1379
1380 ALOGD("-%s-", __func__);
1381
1382 exit:
1383 return err;
1384
1385 }
1386
destroy_src_package(struct iaxxx_odsp_hw * odsp_hdl)1387 int destroy_src_package(struct iaxxx_odsp_hw *odsp_hdl)
1388 {
1389 int err = 0;
1390
1391 ALOGD("+%s+", __func__);
1392
1393 err = iaxxx_odsp_package_unload(odsp_hdl, SRC_PKG_ID);
1394 if (err != 0) {
1395 ALOGE("%s: ERROR: Failed to unload SRC package error %d(%s)",
1396 __func__, errno, strerror(errno));
1397 goto exit;
1398 }
1399
1400 ALOGD("-%s-", __func__);
1401
1402 exit:
1403 return err;
1404 }
1405
setup_music_buffer(struct iaxxx_odsp_hw * odsp_hdl)1406 int setup_music_buffer(struct iaxxx_odsp_hw *odsp_hdl)
1407 {
1408 int err = 0;
1409 struct iaxxx_create_config_data cdata;
1410
1411 ALOGD("+%s+", __func__);
1412
1413 // Create the 8 seconds Buffer plugin for Downlink Audio
1414 cdata.type = CONFIG_FILE;
1415 cdata.data.fdata.filename = BUFFER_CONFIG_VAL_MULTI_SEC;
1416 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1417 DA_BUF_INSTANCE_ID,
1418 IAXXX_HMD_BLOCK_ID,
1419 cdata);
1420 if (err != 0) {
1421 ALOGE("%s: ERROR: DA buffer configuration failed %d(%s)",
1422 __func__, errno, strerror(errno));
1423 goto exit;
1424 }
1425
1426 // Create Buffer plugin
1427 err = iaxxx_odsp_plugin_create(odsp_hdl,
1428 DA_BUF_INSTANCE_ID,
1429 BUF_PRIORITY, BUF_PKG_ID,
1430 BUF_PLUGIN_IDX,
1431 IAXXX_HMD_BLOCK_ID,
1432 PLUGIN_DEF_CONFIG_ID);
1433 if (err != 0) {
1434 ALOGE("%s: ERROR: Failed to create DA Buffer error %d(%s)",
1435 __func__, errno, strerror(errno));
1436 goto exit;
1437 }
1438 ALOGD("-%s-", __func__);
1439
1440 exit:
1441 return err;
1442 }
1443
destroy_music_buffer(struct iaxxx_odsp_hw * odsp_hdl)1444 int destroy_music_buffer(struct iaxxx_odsp_hw *odsp_hdl)
1445 {
1446 int err = 0;
1447
1448 ALOGD("+%s+", __func__);
1449 err = iaxxx_odsp_plugin_destroy(odsp_hdl,
1450 DA_BUF_INSTANCE_ID,
1451 IAXXX_HMD_BLOCK_ID);
1452 if (err == -1) {
1453 ALOGE("%s: ERROR: Failed to destroy DA buffer plugin %d(%s)",
1454 __func__, errno, strerror(errno));
1455 goto exit;
1456 }
1457
1458 ALOGD("-%s-", __func__);
1459
1460 exit:
1461 return err;
1462 }
1463
setup_howord_buffer(struct iaxxx_odsp_hw * odsp_hdl)1464 int setup_howord_buffer(struct iaxxx_odsp_hw *odsp_hdl)
1465 {
1466 struct iaxxx_create_config_data cdata;
1467 int err = 0;
1468
1469 ALOGD("+%s+", __func__);
1470
1471 cdata.type = CONFIG_FILE;
1472 cdata.data.fdata.filename = BUFFER_CONFIG_VAL_2_SEC;
1473 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1474 BUF_INSTANCE_ID,
1475 IAXXX_HMD_BLOCK_ID,
1476 cdata);
1477 if (err != 0) {
1478 ALOGE("%s: ERROR: 8 sec buffer configuration failed %d(%s)",
1479 __func__, errno, strerror(errno));
1480 goto exit;
1481 }
1482
1483 // Create Buffer plugin
1484 err = iaxxx_odsp_plugin_create(odsp_hdl, BUF_INSTANCE_ID,
1485 BUF_PRIORITY, BUF_PKG_ID, BUF_PLUGIN_IDX,
1486 IAXXX_HMD_BLOCK_ID, PLUGIN_DEF_CONFIG_ID);
1487 if (err != 0) {
1488 ALOGE("%s: ERROR: Failed to create Buffer Plugin %d(%s)",
1489 __func__, errno, strerror(errno));
1490 goto exit;
1491 }
1492
1493 ALOGD("-%s-", __func__);
1494
1495 exit:
1496 return err;
1497 }
1498
destroy_howord_buffer(struct iaxxx_odsp_hw * odsp_hdl)1499 int destroy_howord_buffer(struct iaxxx_odsp_hw *odsp_hdl)
1500 {
1501 int err = 0;
1502
1503 ALOGD("+%s+", __func__);
1504
1505 // Destroy Buffer plugin
1506 err = iaxxx_odsp_plugin_destroy(odsp_hdl, BUF_INSTANCE_ID,
1507 IAXXX_HMD_BLOCK_ID);
1508 if (err != 0) {
1509 ALOGE("%s: ERROR: Failed to destroy 8 sec buffer %d(%s)",
1510 __func__, errno, strerror(errno));
1511 goto exit;
1512 }
1513
1514 ALOGD("-%s-", __func__);
1515
1516 exit:
1517 return err;
1518 }
1519
setup_src_plugin(struct iaxxx_odsp_hw * odsp_hdl,enum src_type st)1520 int setup_src_plugin(struct iaxxx_odsp_hw *odsp_hdl, enum src_type st)
1521 {
1522 int err = 0;
1523 int plugin_instant_id = 0;
1524 struct iaxxx_create_config_data cdata;
1525
1526 if (st == SRC_MIC) {
1527 plugin_instant_id = SRC_MIC_INSTANCE_ID;
1528 } else if (st == SRC_AMP_REF) {
1529 plugin_instant_id = SRC_AMP_INSTANCE_ID;
1530 } else {
1531 ALOGE("%s: Invalid src type %d", __func__, st);
1532 err = -EINVAL;
1533 goto exit;
1534 }
1535
1536 ALOGD("+%s+ src type %d", __func__, st);
1537
1538 // set src config
1539 cdata.type = CONFIG_FILE;
1540 cdata.data.fdata.filename = SRC_CONFIG;
1541 err = iaxxx_odsp_plugin_set_creation_config(odsp_hdl,
1542 plugin_instant_id,
1543 IAXXX_HMD_BLOCK_ID,
1544 cdata);
1545 if (err != 0) {
1546 ALOGE("%s: ERROR: SRC-%d configuration failed %d(%s)",
1547 __func__, st, errno, strerror(errno));
1548 goto exit;
1549 }
1550
1551 err = iaxxx_odsp_plugin_create(odsp_hdl, plugin_instant_id,
1552 SRC_PRIORITY, SRC_PKG_ID,
1553 SRC_PLUGIN_IDX, IAXXX_HMD_BLOCK_ID,
1554 PLUGIN_DEF_CONFIG_ID);
1555 if (err != 0) {
1556 ALOGE("%s: ERROR: Failed to create SRC-%d plugin %d(%s)",
1557 __func__, st, errno, strerror(errno));
1558 goto exit;
1559 }
1560
1561 ALOGD("-%s-", __func__);
1562
1563 exit:
1564 return err;
1565 }
1566
destroy_src_plugin(struct iaxxx_odsp_hw * odsp_hdl,enum src_type st)1567 int destroy_src_plugin(struct iaxxx_odsp_hw *odsp_hdl, enum src_type st)
1568 {
1569 int err = 0;
1570 int plugin_instant_id = 0;
1571
1572 if (st == SRC_MIC) {
1573 plugin_instant_id = SRC_MIC_INSTANCE_ID;
1574 } else if (st == SRC_AMP_REF) {
1575 plugin_instant_id = SRC_AMP_INSTANCE_ID;
1576 } else {
1577 ALOGE("%s: Invalid src type %d", __func__, st);
1578 err = -EINVAL;
1579 goto exit;
1580 }
1581 ALOGD("+%s+ src type %d", __func__, st);
1582
1583 err = iaxxx_odsp_plugin_destroy(odsp_hdl, plugin_instant_id,
1584 IAXXX_HMD_BLOCK_ID);
1585 if (err != 0) {
1586 ALOGE("%s: ERROR: Failed to destroy SRC plugin %d(%s)",
1587 __func__, errno, strerror(errno));
1588 goto exit;
1589 }
1590
1591 ALOGD("-%s-", __func__);
1592
1593 exit:
1594 return err;
1595 }
1596
set_hotword_buffer_route(struct audio_route * route_hdl,bool bargein)1597 int set_hotword_buffer_route(struct audio_route *route_hdl, bool bargein)
1598 {
1599 int err = 0;
1600
1601 ALOGD("+%s %d+", __func__, bargein);
1602
1603 if (bargein == true)
1604 err = audio_route_apply_and_update_path(route_hdl,
1605 route_table[ST_HOTWORD_BUFFER_WITH_BARGEIN]);
1606 else
1607 err = audio_route_apply_and_update_path(route_hdl,
1608 route_table[ST_HOTWORD_BUFFER_WITHOUT_BARGEIN]);
1609 if (err)
1610 ALOGE("%s: route fail %d", __func__, err);
1611
1612 ALOGD("-%s-", __func__);
1613 return err;
1614 }
1615
tear_hotword_buffer_route(struct audio_route * route_hdl,bool bargein)1616 int tear_hotword_buffer_route(struct audio_route *route_hdl, bool bargein)
1617 {
1618 int err = 0;
1619
1620 ALOGD("+%s %d+", __func__, bargein);
1621
1622 if (bargein == true)
1623 err = audio_route_reset_and_update_path(route_hdl,
1624 route_table[ST_HOTWORD_BUFFER_WITH_BARGEIN]);
1625 else
1626 err = audio_route_reset_and_update_path(route_hdl,
1627 route_table[ST_HOTWORD_BUFFER_WITHOUT_BARGEIN]);
1628 if (err)
1629 ALOGE("%s: route fail %d", __func__, err);
1630
1631 ALOGD("-%s-", __func__);
1632 return err;
1633 }
1634
enable_bargein_route(struct audio_route * route_hdl,bool enable)1635 int enable_bargein_route(struct audio_route *route_hdl, bool enable)
1636 {
1637 int err = 0;
1638
1639 ALOGV("+%s+ %d", __func__, enable);
1640 if (enable)
1641 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_BARGEIN_ROUTE]);
1642 else
1643 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_BARGEIN_ROUTE]);
1644 if (err)
1645 ALOGE("%s: route fail %d", __func__, err);
1646
1647 ALOGD("-%s-", __func__);
1648 return err;
1649 }
1650
enable_amp_ref_route(struct audio_route * route_hdl,bool enable,enum strm_type strmt)1651 int enable_amp_ref_route(struct audio_route *route_hdl, bool enable,
1652 enum strm_type strmt)
1653 {
1654 int err = 0;
1655
1656 ALOGV("+%s+ %d strm type %d", __func__, enable, strmt);
1657 if (strmt == STRM_16K) {
1658 if (enable)
1659 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF]);
1660 else
1661 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF]);
1662 } else if (strmt == STRM_48K) {
1663 if (enable)
1664 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF_48K]);
1665 else
1666 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF_48K]);
1667 } else {
1668 ALOGE("%s: ERROR: Invalid strm type", __func__);
1669 err = -EINVAL;
1670 }
1671
1672 if (err)
1673 ALOGE("%s: route fail %d", __func__, err);
1674
1675 ALOGD("-%s-", __func__);
1676 return err;
1677 }
1678
set_music_buffer_route(struct audio_route * route_hdl,bool downlink)1679 int set_music_buffer_route(struct audio_route *route_hdl, bool downlink)
1680 {
1681 int err = 0;
1682
1683 ALOGD("+%s+ %d", __func__, downlink);
1684 if (downlink)
1685 err = audio_route_apply_and_update_path(route_hdl,
1686 route_table[ST_AMBIENT_BUFFER_WITHOUT_BARGEIN]);
1687 else
1688 err = audio_route_apply_and_update_path(route_hdl,
1689 route_table[ST_AMBIENT_BUFFER_WITH_BARGEIN]);
1690 if (err)
1691 ALOGE("%s: route fail %d", __func__, err);
1692
1693 ALOGD("-%s-", __func__);
1694 return err;
1695 }
1696
tear_music_buffer_route(struct audio_route * route_hdl,bool downlink)1697 int tear_music_buffer_route(struct audio_route *route_hdl, bool downlink)
1698 {
1699 int err = 0;
1700
1701 ALOGD("+%s+ %d", __func__, downlink);
1702 if (downlink)
1703 err = audio_route_reset_and_update_path(route_hdl,
1704 route_table[ST_AMBIENT_BUFFER_WITHOUT_BARGEIN]);
1705 else
1706 err = audio_route_reset_and_update_path(route_hdl,
1707 route_table[ST_AMBIENT_BUFFER_WITH_BARGEIN]);
1708 if (err)
1709 ALOGE("%s: route fail %d", __func__, err);
1710
1711 ALOGD("-%s-", __func__);
1712 return err;
1713 }
1714
enable_src_route(struct audio_route * route_hdl,bool enable,enum src_type st)1715 int enable_src_route(struct audio_route *route_hdl, bool enable, enum src_type st)
1716 {
1717 int err = 0;
1718
1719 ALOGV("+%s+ %d src type %d", __func__, enable, st);
1720
1721 if (st == SRC_MIC) {
1722 if (enable)
1723 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_MIC]);
1724 else
1725 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_MIC]);
1726 } else if (st == SRC_AMP_REF) {
1727 if (enable)
1728 err = audio_route_apply_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_AMP_REF]);
1729 else
1730 err = audio_route_reset_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_AMP_REF]);
1731
1732 } else {
1733 ALOGE("%s: ERROR: Invalid src type", __func__);
1734 err = -EINVAL;
1735 }
1736
1737 if (err)
1738 ALOGE("%s: route fail %d", __func__, err);
1739
1740 ALOGD("-%s-", __func__);
1741 return err;
1742 }
1743
enable_mic_route(struct audio_route * route_hdl,bool enable,enum clock_type ct)1744 int enable_mic_route(struct audio_route *route_hdl, bool enable,
1745 enum clock_type ct)
1746 {
1747 int err = 0;
1748
1749 ALOGD("+%s+ %d clock type %d", __func__, enable, ct);
1750
1751 if (ct == EXTERNAL_OSCILLATOR) {
1752 if (enable) {
1753 err = audio_route_apply_and_update_path(route_hdl,
1754 route_table[ST_MIC_ROUTE_EXT_CLK]);
1755 } else {
1756 err = audio_route_reset_and_update_path(route_hdl,
1757 route_table[ST_MIC_ROUTE_EXT_CLK]);
1758 }
1759 } else if (ct == INTERNAL_OSCILLATOR) {
1760 if (enable) {
1761 err = audio_route_apply_and_update_path(route_hdl,
1762 route_table[ST_MIC_ROUTE_INT_CLK]);
1763 } else {
1764 err = audio_route_reset_and_update_path(route_hdl,
1765 route_table[ST_MIC_ROUTE_INT_CLK]);
1766 }
1767 } else {
1768 ALOGE("%s: ERROR: Invalid clock type", __func__);
1769 err = -EINVAL;
1770 }
1771
1772 if (err)
1773 ALOGE("%s: route fail %d", __func__, err);
1774
1775 ALOGD("-%s-", __func__);
1776 return err;
1777 }
1778
get_entity_param_blk(struct iaxxx_odsp_hw * odsp_hdl,void * payload,unsigned int payload_size)1779 int get_entity_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload,
1780 unsigned int payload_size)
1781 {
1782 int err = 0;
1783 err = iaxxx_odsp_plugin_get_parameter_blk(odsp_hdl,
1784 AMBIENT_INSTANCE_ID,
1785 IAXXX_HMD_BLOCK_ID,
1786 100, payload,
1787 payload_size);
1788
1789 if (err < 0) {
1790 ALOGE("%s: Failed to get param blk error %s\n",
1791 __func__, strerror(errno));
1792 }
1793 return err;
1794 }
1795
get_wakeup_param_blk(struct iaxxx_odsp_hw * odsp_hdl,void * payload,unsigned int payload_size)1796 int get_wakeup_param_blk(struct iaxxx_odsp_hw *odsp_hdl, void *payload,
1797 unsigned int payload_size)
1798 {
1799 int err = 0;
1800 err = iaxxx_odsp_plugin_get_parameter_blk(odsp_hdl,
1801 HOTWORD_INSTANCE_ID,
1802 IAXXX_HMD_BLOCK_ID,
1803 100, payload,
1804 payload_size);
1805
1806 if (err < 0) {
1807 ALOGE("%s: Failed to get param blk error %s\n",
1808 __func__, strerror(errno));
1809 }
1810 return err;
1811 }
1812
set_default_apll_clk(struct mixer * mixer)1813 int set_default_apll_clk(struct mixer *mixer) {
1814
1815 int ret = 0;
1816 struct mixer_ctl* ctl;
1817
1818 ALOGD("+Entering %s+", __func__);
1819
1820 if (!mixer) {
1821 ALOGE("%s mixer is NULL", __func__);
1822 return -EINVAL;
1823 }
1824
1825 ctl = mixer_get_ctl_by_name(mixer, "Port ApllCLK");
1826 if (ctl) {
1827 ret = mixer_ctl_set_enum_by_string(ctl, "IAXXX_ACLK_FREQ_24576");
1828 if (ret)
1829 ALOGE("%s: update ApllCLK fail! ret = %d", __func__, ret);
1830 } else {
1831 ALOGE("%s: get Port ApllCL control fail", __func__);
1832 ret = -ENODEV;
1833 }
1834
1835 ALOGD("-Exiting %s-", __func__);
1836 return ret;
1837 }
1838
get_fw_status(struct iaxxx_odsp_hw * odsp_hdl,unsigned int * status)1839 int get_fw_status(struct iaxxx_odsp_hw *odsp_hdl, unsigned int *status)
1840 {
1841 int err;
1842
1843 ALOGD("+%s+", __func__);
1844
1845 err = iaxxx_odsp_get_fw_status(odsp_hdl,
1846 status);
1847 if (err == -1) {
1848 ALOGE("%s: ERROR: Failed to get fw status with error %d(%s)",
1849 __func__, errno, strerror(errno));
1850 goto exit;
1851 }
1852
1853 ALOGE("Firmware status is %d", *status);
1854
1855 exit:
1856 ALOGD("-%s-", __func__);
1857 return err;
1858 }
1859
reset_fw(struct iaxxx_odsp_hw * odsp_hdl)1860 int reset_fw(struct iaxxx_odsp_hw *odsp_hdl)
1861 {
1862 int err;
1863
1864 ALOGD("+%s+", __func__);
1865 err = iaxxx_odsp_reset_fw(odsp_hdl);
1866 if (err == -1) {
1867 ALOGE("%s: ERROR: Failed to reset fw with error %d(%s)",
1868 __func__, errno, strerror(errno));
1869 goto exit;
1870 }
1871
1872 exit:
1873 ALOGD("-%s-", __func__);
1874 return err;
1875 }
1876
reset_all_route(struct audio_route * route_hdl)1877 int reset_all_route(struct audio_route *route_hdl)
1878 {
1879 int err = 0;
1880
1881 ALOGD("+%s+", __func__);
1882 for (int i = ST_ROUTE_MIN; i < ST_ROUTE_MAX; i++) {
1883 audio_route_force_reset_and_update_path(route_hdl, route_table[i]);
1884 }
1885 ALOGD("-%s-", __func__);
1886 return err;
1887 }
1888
setup_slpi_wakeup_event(struct iaxxx_odsp_hw * odsp_hdl,bool enabled)1889 int setup_slpi_wakeup_event(struct iaxxx_odsp_hw *odsp_hdl, bool enabled)
1890 {
1891 int err;
1892
1893 ALOGD("+%s+", __func__);
1894
1895 if (enabled) {
1896 err = iaxxx_odsp_evt_subscribe(odsp_hdl, IAXXX_SYSID_CTRL_MGR_CM4,
1897 IAXXX_HOST1_WAKEUP_EVENT_ID,
1898 IAXXX_SYSID_HOST_1, 0);
1899 if (err != 0) {
1900 ALOGE("%s: ERROR: ODSP_EVENT_SUBSCRIBE (for event_id %d, src_id %d)"
1901 " IOCTL failed %d(%s)", __func__, IAXXX_HOST1_WAKEUP_EVENT_ID,
1902 IAXXX_SYSID_CTRL_MGR_CM4, errno, strerror(errno));
1903 goto exit;
1904 }
1905 } else {
1906 err = iaxxx_odsp_evt_unsubscribe(odsp_hdl, IAXXX_SYSID_CTRL_MGR_CM4,
1907 IAXXX_HOST1_WAKEUP_EVENT_ID,
1908 IAXXX_SYSID_HOST_1);
1909 if (err != 0) {
1910 ALOGE("%s: ERROR: ODSP_EVENT_UNSUBSCRIBE (for event_id %d, src_id %d)"
1911 " IOCTL failed %d(%s)", __func__, IAXXX_HOST1_WAKEUP_EVENT_ID,
1912 IAXXX_SYSID_CTRL_MGR_CM4, errno, strerror(errno));
1913 goto exit;
1914 }
1915 }
1916 exit:
1917 ALOGD("-%s-", __func__);
1918 return err;
1919 }
1920