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