4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jonghyuk Choi <jhchoi.choi@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
24 #include <sys/types.h>
30 #include <linux/input.h>
31 #include <iniparser.h>
33 #include "avsys-audio-shm.h"
34 #include "avsys-audio-sync.h"
35 #include "avsys-audio-path.h"
36 #include "avsys-audio-shm.h"
37 #include "avsys-debug.h"
38 #include "avsys-common.h"
39 #include "avsys-audio-handle.h"
40 #include "avsys-audio-logical-volume.h"
42 #ifndef MURPHY_SUPPORT
43 #include "avsys-audio-alsa.h"
44 #include "avsys-audio-ascenario.h"
47 #define EXPORT_API __attribute__((__visibility__("default")))
49 #define RET_IO_CTL_ERR_IF_FAIL(SECTION) { if(AVSYS_FAIL(SECTION)) { \
50 avsys_error_r(AVAUDIO,"%s %d\n",__func__,__LINE__); \
51 return AVSYS_STATE_ERR_IO_CONTROL; \
54 static int g_playback_path_select_data[AVSYS_AUDIO_PLAYBACK_GAIN_MAX][AVSYS_AUDIO_PATH_EX_OUTMAX] = {
55 { /* AVSYS_AUDIO_PLAYBACK_GAIN_AP */
56 /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI DOCK USBAUDIO */
57 0, 1, 0, 1, 0, 0, 0, 1, 1, 0
59 { /* AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO */
60 /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI */
61 1, 1, 0, 1, 0, 1, 0, 0, 0, 0
63 { /* AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL */
64 /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI */
65 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
67 { /* AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL */
68 /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI */
69 1, 1, 1, 1, 1, 0, 0, 0, 0, 0
71 { /* AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT */
72 /* NONE SPK RECV HEADSET BTHEADSET A2DP HANDSFREE HDMI */
73 0, 1, 1, 1, 1, 0, 0, 0, 0, 0
77 static int g_capture_path_select_data[AVSYS_AUDIO_CAPTURE_GAIN_MAX][AVSYS_AUDIO_PATH_EX_INMAX] = {
78 { /* AVSYS_AUDIO_CAPTURE_GAIN_AP */
79 /* NONE MIC HMIC BMIC FMIN HFREE */
82 { /* AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO */
83 /* NONE MIC HMIC BMIC FMIN HFREE */
86 { /* AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL */
87 /* NONE MIC HMIC BMIC FMIN HFREE */
90 { /* AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL */
91 /* NONE MIC HMIC BMIC FMIN HFREE */
96 static int g_playback_gain_select_data[AVSYS_AUDIO_PLAYBACK_GAIN_MAX][AVSYS_AUDIO_PLAYBACK_GAIN_MAX] = {
97 { /* AVSYS_AUDIO_PLAYBACK_GAIN_AP */
98 AVSYS_AUDIO_PLAYBACK_GAIN_AP, /* AVSYS_AUDIO_PLAYBACK_GAIN_AP */
99 AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO, /* AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO */
100 AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL */
101 AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL */
102 AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT, /* AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT */
104 { /* AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO */
105 AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO, /* AVSYS_AUDIO_PLAYBACK_GAIN_AP */
106 AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO, /* AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO */
107 AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL */
108 AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL */
109 AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO, /* AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT */
111 { /* AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL */
112 AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_AP */
113 AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO */
114 AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL */
115 AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL */
116 AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT, /* AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT */
118 { /* AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL */
119 AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_AP */
120 AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO */
121 AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL */
122 AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL */
123 AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT, /* AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT */
125 { /* AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT */
126 AVSYS_AUDIO_PLAYBACK_GAIN_AP, /* AVSYS_AUDIO_PLAYBACK_GAIN_AP */
127 AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO, /* AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO */
128 AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL */
129 AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL, /* AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL */
130 AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT, /* AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT */
134 static int g_capture_gain_select_data[AVSYS_AUDIO_CAPTURE_GAIN_MAX][AVSYS_AUDIO_CAPTURE_GAIN_MAX] = {
135 { /* AVSYS_AUDIO_CAPTURE_GAIN_AP */
136 AVSYS_AUDIO_CAPTURE_GAIN_AP, /* AVSYS_AUDIO_CAPTURE_GAIN_AP */
137 AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO, /* AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO */
138 AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL, /* AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL */
139 AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL, /* AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL */
141 { /* AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO */
142 AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO, /* AVSYS_AUDIO_CAPTURE_GAIN_AP */
143 AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO, /* AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO */
144 AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL, /* AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL */
145 AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL, /* AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL */
147 { /* AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL */
148 AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL, /* AVSYS_AUDIO_CAPTURE_GAIN_AP */
149 AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL, /* AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO */
150 AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL, /* AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL */
151 AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL, /* AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL */
153 { /* AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL */
154 AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL, /* AVSYS_AUDIO_CAPTURE_GAIN_AP */
155 AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL, /* AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO */
156 AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL, /* AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL */
157 AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL, /* AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL */
162 char headset_detection;
163 char headset_node_number;
167 #ifndef MURPHY_SUPPORT
169 static int __avsys_audio_path_set_ascn_ap_playback(avsys_audio_path_ex_info_t *control);
170 static int __avsys_audio_path_set_ascn_voicecall(avsys_audio_path_ex_info_t *control);
171 static int __avsys_audio_path_set_ascn_videocall(avsys_audio_path_ex_info_t *control);
172 static int __avsys_audio_path_set_ascn_fmradio(avsys_audio_path_ex_info_t *control);
173 static int __avsys_audio_path_set_ascn_ap_capture(avsys_audio_path_ex_info_t *control);
174 static int __avsys_audio_path_set_hw_controls(avsys_audio_path_ex_info_t *control);
175 static int __avsys_audio_path_get_earjack_type(void);
177 #define AUDIOSYSTEM_CONF "/opt/etc/audio_system.conf"
178 #define CONF_ITEM_COUNT 2
179 #define INPUT_DEV_MAX 20
181 #define EARJACK_EVENT_PATH "/dev/input/event"
183 #define AVSYS_AUDIO_INI_DEFAULT_PATH "/usr/etc/mmfw_avsystem.ini"
184 #define AVSYS_AUDIO_DEFAULT_CONTROL_AIF_BEFORE_PATH_SET 0
185 #define AVSYS_AUDIO_DEFAULT_GAIN_DEBUG_MODE 0
187 #define CP_STATUS "/sys/class/audio/caps/cp_caps"
188 #define CP_WB_STRING "wb"
190 static char *conf_string[] = {
196 char headset_detection;
197 char headset_node_number;
198 bool control_aif_before_path_set;
199 bool gain_debug_mode;
202 static int __load_conf(avsys_audio_conf *data)
204 dictionary *dict = NULL;
206 #if defined(_MMFW_I386_ALL_SIMULATOR)
208 return AVSYS_STATE_ERR_NULL_POINTER;
210 data->headset_detection = 1;
211 data->headset_node_number = 4;
215 char buffer[64] = { 0, };
216 char conf_data[CONF_ITEM_COUNT] = { 1, 0 };
219 return AVSYS_STATE_ERR_NULL_POINTER;
221 fp = fopen(AUDIOSYSTEM_CONF, "r");
223 char filename[128] = { 0, };
224 char readBuffer[32] = { 0, };
225 char headset_find = 0;
226 int num = 0, headset_num = -1;
228 for (num = 0; num < INPUT_DEV_MAX; num++) {
230 memset(filename, '\0', sizeof(filename));
231 snprintf(filename, sizeof(filename), "/sys/class/input/input%01d/name", num);
232 if (NULL == (sfp = fopen(filename, "r")))
234 memset(readBuffer, '\0', sizeof(readBuffer));
235 if (NULL == fgets(readBuffer, sizeof(readBuffer) - 1, sfp)) {
239 if (strstr(readBuffer, "Headset")) {
245 if (headset_num != -1) {
249 if (headset_num == -1)
250 return AVSYS_STATE_ERR_INTERNAL;
252 if (NULL == (fp = fopen(AUDIOSYSTEM_CONF, "w"))) {
253 return AVSYS_STATE_ERR_INTERNAL;
256 fprintf(fp, "%s:1\n", conf_string[0]);
257 fprintf(fp, "%s:%d\n", conf_string[1], headset_num);
262 data->headset_detection = 1;
263 data->headset_node_number = headset_num;
264 return AVSYS_STATE_SUCCESS;
267 while (fgets(buffer, sizeof(buffer) - 1, fp) != NULL) {
268 if ((strlen(buffer) < 3) || (buffer[0] == '#') || (buffer[0] == '!'))
270 if (buffer[strlen(buffer) - 1] == '\n')
271 buffer[strlen(buffer) - 1] = '\0';
272 for (i = 0; i < CONF_ITEM_COUNT; i++) {
273 if (0 == strncmp(buffer, conf_string[i], strlen(conf_string[i]))) {
275 if (NULL == (ptr = strstr(buffer, ":")))
277 conf_data[i] = atoi(ptr + 1);
278 avsys_warning(AVAUDIO, "%s[%d]\n", buffer, conf_data[i]);
283 data->headset_detection = conf_data[0];
284 data->headset_node_number = conf_data[1];
287 /* first, try to load existing ini file */
288 dict = iniparser_load(AVSYS_AUDIO_INI_DEFAULT_PATH);
289 if (dict) { /* if dict is available */
290 data->control_aif_before_path_set = iniparser_getboolean(dict, "aif:control aif before path set", AVSYS_AUDIO_DEFAULT_CONTROL_AIF_BEFORE_PATH_SET);
291 data->gain_debug_mode = iniparser_getboolean(dict, "debug:gain debug mode", AVSYS_AUDIO_DEFAULT_GAIN_DEBUG_MODE);
293 /* free dict as we got our own structure */
294 iniparser_freedict (dict);
295 } else { /* if no file exists. create one with set of default values */
296 data->control_aif_before_path_set = AVSYS_AUDIO_DEFAULT_CONTROL_AIF_BEFORE_PATH_SET;
297 data->gain_debug_mode = AVSYS_AUDIO_DEFAULT_GAIN_DEBUG_MODE;
300 return AVSYS_STATE_SUCCESS;
303 static bool __is_cp_wb ()
306 char str[10] = { 0, };
309 avsys_info(AVAUDIO, "Checking [%s] for WB capability...\n", CP_STATUS);
310 fp = fopen (CP_STATUS, "r");
312 if (fgets (str, sizeof(str)-1, fp)) {
313 if (strstr (str, CP_WB_STRING)) {
319 avsys_warning (AVAUDIO, "failed to open [%s]...errno=[%d]\n", CP_STATUS, errno);
322 avsys_info(AVAUDIO, "Result [%d] : [%s] capability!!!\n", ret, (ret)? "WB" : "NB");
325 #endif /* MURPHY_SUPPORT */
328 int avsys_audio_path_ex_init(void)
330 avsys_audio_path_ex_info_t *control = NULL;
331 avsys_audio_path_ex_info_t **temp = NULL;
332 gain_info_t default_gain = { AVSYS_AUDIO_PLAYBACK_GAIN_AP, AVSYS_AUDIO_CAPTURE_GAIN_AP };
333 path_info_t default_path = { AVSYS_AUDIO_PATH_EX_SPK, AVSYS_AUDIO_PATH_EX_MIC };
334 option_info_t default_option = { AVSYS_AUDIO_PATH_OPTION_NONE, AVSYS_AUDIO_PATH_OPTION_NONE };
336 int err = AVSYS_STATE_SUCCESS;
337 avsys_audio_conf conf = { 0, };
339 /* Check root user */
340 err = avsys_check_root_privilege();
341 if (AVSYS_FAIL(err)) {
346 avsys_assert(AVSYS_SUCCESS(avsys_audio_create_sync(AVSYS_AUDIO_SYNC_IDEN_PATH)));
347 avsys_assert(AVSYS_SUCCESS(avsys_audio_create_shm(AVSYS_AUDIO_SHM_IDEN_PATH)));
349 avsys_assert(AVSYS_SUCCESS(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp)));
351 return AVSYS_STATE_ERR_NULL_POINTER;
354 control->pregain = default_gain;
355 control->gain = default_gain;
356 control->reqgain = default_gain;
357 control->path = default_path;
358 control->backup_gain = default_gain;
359 control->backup_path = default_path;
360 control->option = default_option;
362 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
363 control->inserted = AVSYS_AUDIO_INSERTED_NONE;
365 #ifdef MURPHY_SUPPORT
366 control->gain_debug_mode = 0;
367 #else /* MURPHY_SUPPORT */
369 if (AVSYS_FAIL(__load_conf(&conf)))
370 avsys_error_r(AVAUDIO, "Can not load audio system configuration file\n");
372 if (conf.headset_detection) {
373 control->inserted = __avsys_audio_path_get_earjack_type();
374 if (control->inserted == AVSYS_AUDIO_INSERTED_NONE)
375 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
377 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET;
379 avsys_warning(AVAUDIO, "Ignore headset detection. Use speaker device\n");
380 control->inserted = AVSYS_AUDIO_INSERTED_NONE;
381 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
384 avsys_error_r(AVAUDIO, "Earjack init value is %d\n", control->inserted);
386 control->control_aif_before_path_set = conf.control_aif_before_path_set;
387 control->wb_enabled = __is_cp_wb();
388 control->gain_debug_mode = conf.gain_debug_mode;
390 #endif /* MURPHY_SUPPORT */
392 control->mute = AVSYS_AUDIO_UNMUTE;
393 control->path_fixed = PATH_FIXED_NONE;
397 control->pathlock_pid[index] = -1;
399 } while (index < AVSYS_AUDIO_LOCK_SLOT_MAX);
403 control->path_fixed_pid[index] = -1;
405 } while (index < PATH_FIXED_TYPE_MAX);
408 #ifdef MURPHY_SUPPORT
409 err = AVSYS_STATE_SUCCESS;
411 /* call path control */
412 err = __avsys_audio_path_set_ascn_ap_playback(control);
413 if (AVSYS_SUCCESS(err))
414 err = __avsys_audio_path_set_hw_controls(control);
416 if (AVSYS_SUCCESS(err))
417 err = __avsys_audio_path_set_ascn_ap_capture(control);
424 int avsys_audio_path_ex_fini(void)
426 if (AVSYS_FAIL(avsys_audio_remove_shm(AVSYS_AUDIO_SHM_IDEN_PATH))) {
427 avsys_error_r(AVAUDIO, "avsys_audio_remove_shm() failed in %s\n", __func__);
428 return AVSYS_STATE_ERR_INTERNAL;
430 if (AVSYS_FAIL(avsys_audio_remove_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
431 avsys_error_r(AVAUDIO, "avsys_audio_remove_sync() failed in %s\n", __func__);
432 return AVSYS_STATE_ERR_INTERNAL;
434 return AVSYS_STATE_SUCCESS;
438 int avsys_audio_path_ex_reset(int forced)
440 #ifdef MURPHY_SUPPORT
442 return AVSYS_STATE_SUCCESS;
444 avsys_audio_path_ex_info_t *control = NULL;
445 avsys_audio_path_ex_info_t **temp = NULL;
446 gain_info_t default_gain = { AVSYS_AUDIO_PLAYBACK_GAIN_AP, AVSYS_AUDIO_CAPTURE_GAIN_AP };
447 path_info_t default_path = { AVSYS_AUDIO_PATH_EX_SPK, AVSYS_AUDIO_PATH_EX_MIC };
448 option_info_t default_option = { AVSYS_AUDIO_PATH_OPTION_NONE, AVSYS_AUDIO_PATH_OPTION_NONE };
450 int err = AVSYS_STATE_SUCCESS;
451 int backup_debug = 0;
452 avsys_audio_conf conf = { 0, };
454 /* Check root user */
455 err = avsys_check_root_privilege();
456 if (AVSYS_FAIL(err)) {
461 if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))) {
462 avsys_error_r(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
463 return AVSYS_STATE_ERR_INTERNAL;
466 return AVSYS_STATE_ERR_NULL_POINTER;
468 if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
469 avsys_error_r(AVAUDIO, "avsys_audio_lock_sync() failed in %s\n", __func__);
470 return AVSYS_STATE_ERR_INTERNAL;
474 control->pregain = default_gain;
475 control->gain = default_gain;
476 control->reqgain = default_gain;
477 control->path = default_path;
478 control->backup_gain = default_gain;
479 control->backup_path = default_path;
480 control->option = default_option;
482 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
483 control->inserted = AVSYS_AUDIO_INSERTED_NONE;
485 if (AVSYS_FAIL(__load_conf(&conf)))
486 avsys_error_r(AVAUDIO, "Can not load audio system configuration file\n");
488 if (conf.headset_detection) {
489 control->inserted = __avsys_audio_path_get_earjack_type();
490 if (control->inserted == AVSYS_AUDIO_INSERTED_NONE)
491 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
493 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET;
494 control->path.playback = AVSYS_AUDIO_PATH_EX_HEADSET;
496 if (control->inserted == AVSYS_AUDIO_INSERTED_4)
497 control->path.capture = AVSYS_AUDIO_PATH_EX_HEADSETMIC;
500 avsys_warning(AVAUDIO, "Ignore headset detection. Use speaker device\n");
501 control->inserted = AVSYS_AUDIO_INSERTED_NONE;
502 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
505 avsys_error_r(AVAUDIO, "Earjack init value is %d\n", control->inserted);
507 control->control_aif_before_path_set = conf.control_aif_before_path_set;
508 control->gain_debug_mode = conf.gain_debug_mode;
510 control->mute = AVSYS_AUDIO_UNMUTE;
511 control->path_fixed = PATH_FIXED_NONE;
515 control->pathlock_pid[index] = -1;
517 } while (index < AVSYS_AUDIO_LOCK_SLOT_MAX);
521 control->path_fixed_pid[index] = -1;
523 } while (index < PATH_FIXED_TYPE_MAX);
526 backup_debug = control->gain_debug_mode;
527 control->gain_debug_mode = 1;
529 /* call path control */
530 err = __avsys_audio_path_set_ascn_ap_playback(control);
531 if (AVSYS_SUCCESS(err))
532 err = __avsys_audio_path_set_hw_controls(control);
534 if (AVSYS_SUCCESS(err))
535 err = __avsys_audio_path_set_ascn_ap_capture(control);
538 control->gain_debug_mode = backup_debug;
541 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
542 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__);
543 return AVSYS_STATE_ERR_INTERNAL;
547 #endif /* MURPHY_SUPPORT */
551 int avsys_audio_path_ex_dump(void)
553 avsys_audio_path_ex_info_t *control = NULL;
554 avsys_audio_path_ex_info_t **temp = NULL;
555 const static char *str_earType[] = { "None", "EarOnly", "EarMic", "TVout" };
556 const static char *str_yn[] = { "NO", "YES" };
557 const static char *str_ear[] = { "MANUAL", "AUTO_MUTE", "AUTO_NOMUTE" };
558 const static char *str_out[AVSYS_AUDIO_PATH_EX_OUTMAX] = {
559 "NONE", "SPK", "RECV", "HEADSET", "BTHEADSET", "A2DP", "HANSFREE", "HDMI", "DOCK", "USBAUDIO"
561 const static char *str_in[AVSYS_AUDIO_PATH_EX_INMAX] = {
562 "NONE", "MIC", "HEADMIC", "BTMIC", "FMINPUT", "HANSFREEMIC"
564 const static char *str_route[AVSYS_AUDIO_ROUTE_POLICY_MAX] = {
565 "DEFAULT", "IGN_A2DP", "HANDSET"
568 const static char *str_gain[AVSYS_AUDIO_GAIN_EX_MAX] = {
569 "KEYTONE", "RINGTONE", "ALARMTONE", "CALLTONE", "AUDIOPLAYER", "VIDEOPLAYER",
570 "VOICECALL", "VIDEOCALL", "FMRADIO", "VOICEREC", "CAMCORDER", "CAMERA", "GAME"};
572 const static char *str_playback_gain[AVSYS_AUDIO_PLAYBACK_GAIN_MAX] = {
573 "AP", "FMRADIO", "VOICECALL", "VIDEOCALL", "CALLALERT",
575 const static char *str_capture_gain[AVSYS_AUDIO_CAPTURE_GAIN_MAX] = {
576 "AP", "FMRADIO", "VOICECALL", "VIDEOCALL",
583 if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))) {
584 avsys_error_r(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
585 return AVSYS_STATE_ERR_INTERNAL;
588 return AVSYS_STATE_ERR_NULL_POINTER;
590 fprintf(stdout, "======================================================================\n");
591 fprintf(stdout, " Avsystem Audio Path Control Information \n");
592 fprintf(stdout, "======================================================================\n");
593 #if defined(_MMFW_I386_ALL_SIMULATOR)
594 fprintf(stdout, " In simulator, follow informations don`t have means.\n");
595 #elif defined(MURPHY_SUPPORT)
596 fprintf(stdout, " Murphy support is enabled. module-murphy-ivi is routing in pulseaudio.\n"
597 " The information below does not make much sense ...\n");
600 fprintf(stdout, " GAIN : P (%-s / %-s) - R (%-s / %-s) - C (%-s / %-s)\n",
601 str_playback_gain[control->pregain.playback], str_capture_gain[control->pregain.capture],
602 str_playback_gain[control->reqgain.playback], str_capture_gain[control->reqgain.capture],
603 str_playback_gain[control->gain.playback], str_capture_gain[control->gain.capture]);
604 fprintf(stdout, " Current Out / In : %-s / %-s\n", str_out[control->path.playback], str_in[control->path.capture] );
605 fprintf(stdout, " Gain debug mode : 0x%-x\n", control->gain_debug_mode);
606 fprintf(stdout, " Auto EarJack Control : %-s\n", str_ear[control->ear_auto]);
607 fprintf(stdout, " Physical Earjack? [type] : %-s [%-s]\n", str_yn[control->inserted != AVSYS_AUDIO_INSERTED_NONE], str_earType[control->inserted]);
608 fprintf(stdout, " Path Fixed State : 0x%-x\n", control->path_fixed);
609 fprintf(stdout, " Mute status : %d\n", control->mute);
610 if (control->path_fixed_pid[PATH_FIXED_TYPE_FMRADIO] != -1)
611 fprintf(stdout, " FM Radio path pid : %d\n", control->path_fixed_pid[PATH_FIXED_TYPE_FMRADIO]);
612 if (control->path_fixed_pid[PATH_FIXED_TYPE_CALL] != -1)
613 fprintf(stdout, " Call path pid : %d\n", control->path_fixed_pid[PATH_FIXED_TYPE_CALL]);
617 if (control->pathlock_pid[index] != -1)
618 fprintf(stdout, " Path sync lock required PIDs : %d\n", control->pathlock_pid[index]);
620 } while (index < AVSYS_AUDIO_LOCK_SLOT_MAX);
621 fprintf(stdout, " Option Dual out : %-s\n", str_yn[(control->option.playback & AVSYS_AUDIO_PATH_OPTION_DUAL_OUT) ? 1 : 0]);
622 fprintf(stdout, " Option Forced : %-s\n", str_yn[(control->option.playback & AVSYS_AUDIO_PATH_OPTION_FORCED) ? 1 : 0]);
624 return AVSYS_STATE_SUCCESS;
627 #ifndef MURPHY_SUPPORT
628 static int __avsys_audio_path_get_earjack_type (void)
631 char readval = AVSYS_AUDIO_INSERTED_NONE;
632 fd = open("/sys/devices/platform/jack/earjack_online", O_RDONLY);
635 avsys_error_r(AVAUDIO, "Can not get initial jack type\n");
636 return AVSYS_AUDIO_INSERTED_NONE;
638 read(fd, &readval, sizeof(readval));
641 readval = AVSYS_AUDIO_INSERTED_NONE;
644 readval = AVSYS_AUDIO_INSERTED_3;
647 readval = AVSYS_AUDIO_INSERTED_4;
650 readval = AVSYS_AUDIO_INSERTED_AV;
653 if (1 == read(fd, &readval, sizeof(readval))) {
654 if (readval == '0') {
655 readval = AVSYS_AUDIO_INSERTED_AV;
657 avsys_error(AVAUDIO, "Unknown jack type value...2%d\n", readval);
658 readval = AVSYS_AUDIO_INSERTED_NONE;
661 avsys_error(AVAUDIO, "jack type read error...\n");
662 readval = AVSYS_AUDIO_INSERTED_NONE;
666 avsys_error(AVAUDIO, "jack type unknown value...%c\n", readval);
667 readval = AVSYS_AUDIO_INSERTED_NONE;
674 #endif /* MURPHY_SUPPORT */
676 int avsys_audio_path_earjack_init(int *init_type, int *outfd)
678 #if !defined(_MMFW_I386_ALL_SIMULATOR) && !defined(MURPHY_SUPPORT)
679 char eventnode_filename[32] = { 0, };
681 avsys_audio_conf conf = { 0, };
683 if (outfd == NULL || init_type == NULL) {
684 avsys_error(AVAUDIO, "input parameter is null\n");
685 return AVSYS_STATE_ERR_NULL_POINTER;
688 if (AVSYS_FAIL(__load_conf(&conf))) {
689 avsys_error_r(AVAUDIO, "Can not load audio system configuration file\n");
692 if (!conf.headset_detection) {
693 avsys_error(AVAUDIO, "Earjack control daemon will be closed by user option...\n");
694 return AVSYS_STATE_ERR_DEVICE_NOT_SUPPORT;
697 snprintf(eventnode_filename, sizeof(eventnode_filename), "%s%01d", EARJACK_EVENT_PATH, conf.headset_node_number);
699 fd = open(eventnode_filename, O_RDONLY);
701 avsys_error_r(AVAUDIO, "Device file open error\n");
702 return AVSYS_STATE_ERR_INTERNAL;
704 avsys_audio_path_ex_info_t *control = NULL;
705 avsys_audio_path_ex_info_t **temp = NULL;
706 void *vol_data = NULL;
707 void *handle_data = NULL;
710 if(AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_LVOLUME, &vol_data))) {
711 avsys_error(AVAUDIO,"attach logical volume shared memory failed\n");
713 return AVSYS_STATE_ERR_ALLOCATION;
715 if(AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_HANDLE, &handle_data))) {
716 avsys_error(AVAUDIO,"attach handle shared memory failed\n");
718 return AVSYS_STATE_ERR_ALLOCATION;
720 if(AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void**)temp))) {
721 avsys_error_r(AVAUDIO,"avsys_audio_get_shm() failed in %s\n", __func__);
723 return AVSYS_STATE_ERR_INTERNAL;
726 *init_type = control->inserted;
728 return AVSYS_STATE_SUCCESS;
731 return AVSYS_STATE_ERR_DEVICE_NOT_SUPPORT;
735 int avsys_audio_path_earjack_wait(int fd, int *current_type, int *new_type, int *is_auto_mute)
737 #if !defined(_MMFW_I386_ALL_SIMULATOR) && !defined(MURPHY_SUPPORT)
741 struct input_event jevent;
742 int res = AVSYS_STATE_SUCCESS;
745 if (new_type == NULL || is_auto_mute == NULL)
746 return AVSYS_STATE_ERR_NULL_POINTER;
751 cur_type = *current_type;
753 select_ret = select(fd + 1, &set, NULL, NULL, NULL);
754 avsys_info(AVAUDIO, "SELECT returns......\n");
756 if (select_ret != 1) {
757 if (select_ret == 0) {
758 avsys_error_r(AVAUDIO, "Earjack timeout in autocontrol\n");
759 } else if (select_ret == -1) {
760 avsys_error_r(AVAUDIO, "Earjack detect unknown error: %d\n", errno);
762 return AVSYS_STATE_WAR_INVALID_VALUE;
764 #ifdef EARJACK_LOCK /* currently this is disabled to avoid semapore value increase */
765 if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
766 avsys_error_r(AVAUDIO, "avsys_audio_lock_sync() failed in %s\n", __func__);
767 return AVSYS_STATE_ERR_INTERNAL;
770 if (read(fd, &jevent, sizeof(jevent)) < 0) {
771 avsys_error(AVAUDIO, "read fd failed with 0x%x\n", errno);
772 return AVSYS_STATE_WAR_INVALID_MODE;
774 avsys_info(AVAUDIO, "*** JEVENT : code=%d, value=%d\n", jevent.code, jevent.value);
775 if (jevent.type != TYPE_EVENT_SWITCH) {
776 avsys_info(AVAUDIO, "Not a switch event\n");
777 return AVSYS_STATE_WAR_INVALID_MODE;
780 switch (jevent.code) {
781 case CODE_HEADPHONE_INSERT:
782 case CODE_LINEOUT_INSERT:
783 case CODE_JACK_PHYSICAL_INSERT:
784 if (jevent.value == 1) {
785 readtemp = __avsys_audio_path_get_earjack_type();
791 readtemp = cur_type; /* same value */
795 *new_type = readtemp;
797 avsys_audio_path_ex_info_t *control = NULL;
798 avsys_audio_path_ex_info_t **temp = NULL;
801 if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))) {
802 avsys_error_r(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
803 return AVSYS_STATE_ERR_INTERNAL;
806 avsys_info(AVAUDIO, "control->ear_auto = %d\n", control->ear_auto);
807 if (control->ear_auto == AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE) {
808 *current_type = control->inserted;
810 res = AVSYS_STATE_SUCCESS;
811 } else if (control->ear_auto == AVSYS_AUDIO_EAR_SWITCH_AUTO_WITHOUT_MUTE) {
812 *current_type = control->inserted;
814 res = AVSYS_STATE_SUCCESS;
820 return AVSYS_STATE_ERR_DEVICE_NOT_SUPPORT;
824 int avsys_audio_path_earjack_process(int new_type)
826 #if !defined(_MMFW_I386_ALL_SIMULATOR) && !defined(MURPHY_SUPPORT)
827 avsys_audio_path_ex_info_t *control = NULL;
828 avsys_audio_path_ex_info_t **temp = NULL;
829 int err = AVSYS_STATE_SUCCESS;
832 avsys_info(AVAUDIO, "new_type = %d\n", new_type);
833 if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))) {
834 avsys_error_r(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
835 return AVSYS_STATE_ERR_INTERNAL;
838 control->inserted = new_type;
842 return AVSYS_STATE_ERR_DEVICE_NOT_SUPPORT;
846 int avsys_audio_path_earjack_deinit(int fd)
848 #if !defined(_MMFW_I386_ALL_SIMULATOR) && !defined(MURPHY_SUPPORT)
850 return AVSYS_STATE_SUCCESS;
852 return AVSYS_STATE_ERR_DEVICE_NOT_SUPPORT;
856 int avsys_audio_path_earjack_unlock()
858 #if defined(EARJACK_LOCK) && !defined(MURPHY_SUPPORT) /* currently EARJACK_LOCK is disabled to avoid semapore value increase */
859 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
860 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__);
861 return AVSYS_STATE_ERR_INTERNAL;
864 return AVSYS_STATE_SUCCESS;
867 #define DO_IF_VALID(c, p) { if(c > -1) p; }
868 #define DO_IF_INVALID(c, p) { if(c == -1) p; }
869 #define CHECK_VALID(c) (c>-1 ? 1 : 0)
874 CMD_DEVICE_CLOSE, /* Not used */
878 #ifndef MURPHY_SUPPORT
879 avsys_audio_alsa_aif_handle_t *g_hAIF[AIF_DEVICE_MAX] = { NULL, NULL, NULL, NULL, NULL };
880 char *strAIF[AIF_DEVICE_MAX] = { "AIF CP Capture", "AIF CP Playback", "AIF BT Capture", "AIF BT Playback", "AIF RADIO Playback" };
882 #define SET_AIF(index) do { AIF_control[index] = CMD_DEVICE_OPEN; } while (0)
884 static int __is_cp_aif (int type)
886 return ((type == AIF_CP_PLAYBACK || type == AIF_CP_CAPTURE));
889 static int __avsys_open_aif(char AIF_control[], bool wb_enabled)
892 int err = AVSYS_STATE_SUCCESS;
896 /* Check If BT is enabled */
897 for (iAIF = 0; iAIF < AIF_DEVICE_MAX; iAIF++) {
898 if (AIF_control[iAIF] == CMD_DEVICE_OPEN && (iAIF == AIF_BT_PLAYBACK || iAIF== AIF_BT_CAPTURE)) {
904 /* Iterate control command */
905 avsys_info(AVAUDIO, "================== Close if reopen is needed (bt[%d] wb[%d]) ================== \n", bt_enabled, wb_enabled);
906 for (iAIF = 0; iAIF < AIF_DEVICE_MAX; iAIF++) {
908 if (AIF_control[iAIF] != CMD_DEVICE_OPEN)
911 avsys_info(AVAUDIO, "%d. [%s]\n", iAIF, strAIF[iAIF]);
913 /* check handle exists */
915 /* Handle is already opened.
916 * Check if WB is supported and CP handle case */
917 if (wb_enabled && __is_cp_aif(g_hAIF[iAIF]->type)) {
918 /* CP Handle is already opened with WB enabled .
919 * Determine whether re-open is needed */
920 if ((bt_enabled && g_hAIF[iAIF]->rate != AIF_NB_RATE) ||
921 (!bt_enabled && g_hAIF[iAIF]->rate == AIF_NB_RATE)) {
922 /* CP handle exists and BT enabled with not NB opened => close for reopen
923 CP handle exists and BT disabled with NB opened => close for reopen */
924 avsys_info(AVAUDIO, "=> Close device for reopen :: %s\n", strAIF[iAIF]);
925 if (AVSYS_FAIL(avsys_audio_alsa_close_AIF_device(g_hAIF[iAIF]))) {
926 avsys_error_r(AVAUDIO, "close %s device failed\n", strAIF[iAIF]);
931 /* CP handle exists and BT enabled with NB opened ||
932 CP handle exists and BT disabled with not NB opened */
933 avsys_info(AVAUDIO, "=> Skip device :: %s\n", strAIF[iAIF]);
938 /* Not CP case or WB is disabled. No need to reopen */
939 avsys_info(AVAUDIO, "=> Skip device :: %s\n", strAIF[iAIF]);
945 avsys_info(AVAUDIO, "================== Open & Set Param ================== \n");
946 /* Iterate control command */
947 for (iAIF = 0; iAIF < AIF_DEVICE_MAX; iAIF++) {
949 if (AIF_control[iAIF] != CMD_DEVICE_OPEN)
952 avsys_info(AVAUDIO, "%d. [%s]\n", iAIF, strAIF[iAIF]);
954 /* check handle exists */
956 /* Not CP case or WB is disabled. No need to reopen */
957 avsys_info(AVAUDIO, "=> Skip device Already opened!!! :: %s\n", strAIF[iAIF]);
961 /* memory allocation for handle */
962 avsys_warning(AVAUDIO, "=> [%s] handle alloc", strAIF[iAIF]);
963 g_hAIF[iAIF] = calloc(sizeof(avsys_audio_handle_t), 1);
965 avsys_error_r(AVAUDIO, "=> Can not alloc memory for [%s] device handle", strAIF[iAIF]);
966 err = AVSYS_STATE_ERR_ALLOCATION;
970 if (AVSYS_FAIL(avsys_audio_alsa_open_AIF_device(iAIF, g_hAIF[iAIF]))) {
971 avsys_error_r(AVAUDIO, "=> open [%s] device failed\n", strAIF[iAIF]);
972 err = AVSYS_STATE_ERR_INVALID_HANDLE;
974 avsys_warning(AVAUDIO, "=> open [%s] device success\n", strAIF[iAIF]);
977 if (__is_cp_aif(g_hAIF[iAIF]->type)) {
978 rate = (wb_enabled && !bt_enabled)? AIF_WB_RATE : AIF_NB_RATE;
980 rate = AIF_CONF_RATE;
983 if (AVSYS_FAIL(avsys_audio_alsa_set_AIF_params(g_hAIF[iAIF],rate))) {
984 avsys_error_r(AVAUDIO, "=> [%s] device set parameter failed\n", strAIF[iAIF]);
985 err = AVSYS_STATE_ERR_INVALID_PARAMETER;
987 avsys_warning(AVAUDIO, "=> [%s] device set parameter success\n", strAIF[iAIF]);
994 static void __avsys_close_aif ()
998 for (iAIF = 0; iAIF < AIF_DEVICE_MAX; iAIF++) {
1000 avsys_info(AVAUDIO, "close device :: %s\n", strAIF[iAIF]);
1001 if (AVSYS_FAIL(avsys_audio_alsa_close_AIF_device(g_hAIF[iAIF]))) {
1002 avsys_error_r(AVAUDIO, "close %s device failed\n", strAIF[iAIF]);
1005 g_hAIF[iAIF] = NULL;
1006 avsys_warning(AVAUDIO, "%s device handle free\n", strAIF[iAIF]);
1008 avsys_info(AVAUDIO, "skip closing device :: %s\n", strAIF[iAIF]);
1013 #endif /* MURPHY_SUPPORT */
1016 static int __avsys_audio_release_path (gain_info_t local_gain, avsys_audio_path_ex_info_t *control)
1018 int err = AVSYS_STATE_SUCCESS;
1020 bool close_aif_later = false;
1022 avsys_warning(AVAUDIO, "Release path for %d %d\n", local_gain.playback, local_gain.capture);
1024 switch (local_gain.playback) {
1025 case AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL:
1026 case AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL:
1027 if (getpid() == control->path_fixed_pid[PATH_FIXED_TYPE_CALL]) {
1028 #ifndef MURPHY_SUPPORT
1029 if (!control->control_aif_before_path_set) {
1030 __avsys_close_aif();
1032 close_aif_later = true;
1035 if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_CODEC_DISABLE_ON_SUSPEND))) {
1036 avsys_error_r(AVAUDIO, "[%s] failed to set codec_disable_on_suspend\n", __func__);
1038 #endif /* MURPHY_SUPPORT */
1040 if (control->path_fixed_pid[PATH_FIXED_TYPE_CALL] < 0) {
1041 avsys_warning(AVAUDIO, "Sound path for call released already\n");
1043 avsys_warning(AVAUDIO, "Try to close call path from other process.. original pid[%d]\n", control->path_fixed_pid[PATH_FIXED_TYPE_CALL]);
1044 avsys_warning(AVAUDIO, "Just mark handle as off\n");
1048 if ((control->path_fixed & PATH_FIXED_WITH_CALL) == 0) {
1049 avsys_error(AVAUDIO, "Call path release without call path request\n");
1051 control->path_fixed &= ~PATH_FIXED_WITH_CALL;
1052 control->path_fixed_pid[PATH_FIXED_TYPE_CALL] = -1;
1056 case AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO:
1057 /* TODO: Reset & Codec disable on suspend script */
1058 #ifdef MURPHY_SUPPORT
1059 control->p_path_status.playback = PS_PATH_NONE;
1061 if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_CODEC_DISABLE_ON_SUSPEND))) {
1062 avsys_error_r(AVAUDIO, "[%s] failed to set codec_disable_on_suspend\n", __func__);
1065 if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET_CAPTURE))) {
1066 avsys_error_r(AVAUDIO, "[%s] failed to set reset\n", __func__);
1073 avsys_warning(AVAUDIO, "unexpected path release\n");
1077 if (control->path_fixed != PATH_FIXED_NONE) {
1078 avsys_error(AVAUDIO, "Still remain another path_fixed request : 0x%08X\n", control->path_fixed);
1079 avsys_error(AVAUDIO, "This is not expected condition\n");
1081 avsys_warning(AVAUDIO, "Path Release to default condition....\n");
1082 control->gain.playback = AVSYS_AUDIO_PLAYBACK_GAIN_AP;
1083 control->gain.capture = AVSYS_AUDIO_CAPTURE_GAIN_AP;
1084 control->path.playback = AVSYS_AUDIO_PATH_EX_SPK;
1085 control->path.capture = AVSYS_AUDIO_PATH_EX_MIC;
1086 if (control->inserted != AVSYS_AUDIO_INSERTED_NONE) {
1087 control->path.playback = AVSYS_AUDIO_PATH_EX_HEADSET;
1088 if (control->inserted == AVSYS_AUDIO_INSERTED_4)
1089 control->path.capture = AVSYS_AUDIO_PATH_EX_HEADSETMIC;
1092 #ifndef MURPHY_SUPPORT
1094 err = __avsys_audio_path_set_ascn_ap_playback(control);
1095 if (AVSYS_SUCCESS(err)) {
1096 err = __avsys_audio_path_set_hw_controls(control);
1097 if (AVSYS_FAIL(err)) {
1098 avsys_error(AVAUDIO, "Update logical volume failure\n");
1101 avsys_error(AVAUDIO, "Set ap playback failure\n");
1105 err = __avsys_audio_path_set_ascn_ap_capture(control);
1106 if (AVSYS_FAIL(err)) {
1107 avsys_error(AVAUDIO, "Set ap capture failure\n");
1112 #ifndef MURPHY_SUPPORT
1113 if (close_aif_later == true) {
1114 __avsys_close_aif();
1120 int avsys_audio_path_earjack_get_type()
1122 avsys_audio_path_ex_info_t *control = NULL;
1123 avsys_audio_path_ex_info_t **temp = NULL;
1124 int err = AVSYS_STATE_SUCCESS;
1128 if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))) {
1129 avsys_error_r(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
1130 return AVSYS_STATE_ERR_INTERNAL;
1132 if (control == NULL)
1133 return AVSYS_STATE_ERR_NULL_POINTER;
1135 if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1136 avsys_error_r(AVAUDIO, "avsys_audio_lock_sync() failed in %s\n", __func__);
1137 return AVSYS_STATE_ERR_INTERNAL;
1140 ret = control->inserted;
1142 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1143 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__);
1144 return AVSYS_STATE_ERR_INTERNAL;
1150 int avsys_audio_path_ex_set_path(int gain, int out, int in, int option)
1152 avsys_audio_path_ex_info_t *control = NULL;
1153 avsys_audio_path_ex_info_t **temp = NULL;
1154 gain_info_t local_gain = { -1, -1 };
1155 gain_info_t req_gain = { -1, -1 };
1157 int err = AVSYS_STATE_SUCCESS;
1158 char req_release_path = 0;
1159 #ifndef MURPHY_SUPPORT
1160 char AIF_control[AIF_DEVICE_MAX] = { CMD_DEVICE_NONE, CMD_DEVICE_NONE, CMD_DEVICE_NONE, CMD_DEVICE_NONE, CMD_DEVICE_NONE };
1164 avsys_warning(AVAUDIO, "=================== [Input Param] gain %d, out %d, in %d, opt 0x%x ====================\n", gain, out, in, option);
1166 /* Determine REQUESTs */
1168 case AVSYS_AUDIO_GAIN_EX_KEYTONE:
1169 case AVSYS_AUDIO_GAIN_EX_ALARMTONE:
1170 case AVSYS_AUDIO_GAIN_EX_AUDIOPLAYER:
1171 case AVSYS_AUDIO_GAIN_EX_VIDEOPLAYER:
1172 case AVSYS_AUDIO_GAIN_EX_CAMERA:
1173 case AVSYS_AUDIO_GAIN_EX_GAME:
1174 req_gain.playback = AVSYS_AUDIO_PLAYBACK_GAIN_AP;
1175 req_gain.capture = AVSYS_AUDIO_CAPTURE_GAIN_AP;
1178 case AVSYS_AUDIO_GAIN_EX_RINGTONE:
1179 case AVSYS_AUDIO_GAIN_EX_CALLTONE:
1180 req_gain.playback = AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT;
1183 case AVSYS_AUDIO_GAIN_EX_VOICEREC:
1184 case AVSYS_AUDIO_GAIN_EX_CAMCORDER:
1185 req_gain.capture = AVSYS_AUDIO_CAPTURE_GAIN_AP;
1188 case AVSYS_AUDIO_GAIN_EX_VOICECALL:
1189 req_gain.playback = AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL;
1190 req_gain.capture = AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL;
1191 if (out == AVSYS_AUDIO_PATH_EX_NONE && in == AVSYS_AUDIO_PATH_EX_NONE)
1192 req_release_path = 1;
1195 case AVSYS_AUDIO_GAIN_EX_VIDEOCALL:
1196 req_gain.playback = AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL;
1197 req_gain.capture = AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL;
1198 if (out == AVSYS_AUDIO_PATH_EX_NONE && in == AVSYS_AUDIO_PATH_EX_NONE)
1199 req_release_path = 1;
1202 case AVSYS_AUDIO_GAIN_EX_FMRADIO:
1203 req_gain.playback = AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO;
1204 req_gain.capture = AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO;
1205 if (out == AVSYS_AUDIO_PATH_EX_NONE && in == AVSYS_AUDIO_PATH_EX_NONE)
1206 req_release_path = 1;
1210 /* Get avsys shared memeory */
1212 if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))) {
1213 avsys_error_r(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
1214 return AVSYS_STATE_ERR_INTERNAL;
1217 if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1218 avsys_error_r(AVAUDIO, "avsys_audio_lock_sync() failed in %s\n", __func__);
1219 return AVSYS_STATE_ERR_INTERNAL;
1222 current_pid = getpid(); /* moved from below */
1224 /* Check FORCED option */
1225 if (option & AVSYS_AUDIO_PATH_OPTION_FORCED) {
1226 DO_IF_VALID(req_gain.playback, local_gain.playback = req_gain.playback)
1227 DO_IF_VALID(req_gain.capture, local_gain.capture = req_gain.capture)
1229 DO_IF_VALID(req_gain.playback, local_gain.playback = g_playback_gain_select_data[control->gain.playback][req_gain.playback])
1230 DO_IF_VALID(req_gain.capture, local_gain.capture = g_capture_gain_select_data[control->gain.capture][req_gain.capture])
1233 avsys_info(AVAUDIO, "Gain : req(%d,%d) local(%d,%d)\n", req_gain.playback, req_gain.capture, local_gain.playback, local_gain.capture);
1235 /* Check path fixed process alive. */
1236 if (control->path_fixed & PATH_FIXED_WITH_CALL) {
1237 if (AVSYS_FAIL(avsys_check_process(control->path_fixed_pid[PATH_FIXED_TYPE_CALL]))) {
1238 control->path_fixed &= ~PATH_FIXED_WITH_CALL;
1241 if (control->path_fixed == PATH_FIXED_NONE) {
1242 /* forced gain setting when path fixed by dead process */
1243 if (req_gain.playback != local_gain.playback) {
1244 local_gain.playback = req_gain.playback;
1246 if (req_gain.capture != local_gain.capture) {
1247 local_gain.capture = req_gain.capture;
1251 if (CHECK_VALID(local_gain.playback)) {
1252 if (g_playback_path_select_data[local_gain.playback][out] == 0) {
1253 avsys_error(AVAUDIO, "[PLAYBACK] Does not support request sound path : conv gain %d, out path %d\n", local_gain.playback, out);
1254 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1255 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__);
1256 return AVSYS_STATE_ERR_INTERNAL;
1258 return AVSYS_STATE_ERR_INVALID_STATE;
1261 if (CHECK_VALID(local_gain.capture)) {
1262 if (g_capture_path_select_data[local_gain.capture][in] == 0) {
1263 avsys_error(AVAUDIO, "[CAPTURE] Does not support request sound path : conv gain %d, in path %d\n", local_gain.capture, in);
1264 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1265 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__);
1266 return AVSYS_STATE_ERR_INTERNAL;
1268 return AVSYS_STATE_ERR_INVALID_STATE;
1271 /* overwrite local_gain with current gain if it is simplex sound path */
1272 DO_IF_INVALID(local_gain.playback, local_gain.playback = control->gain.playback)
1273 DO_IF_INVALID(local_gain.capture, local_gain.capture = control->gain.capture)
1274 control->pregain = control->gain;
1275 control->gain = local_gain;
1277 DO_IF_VALID(req_gain.playback, control->reqgain.playback = req_gain.playback)
1278 DO_IF_VALID(req_gain.capture, control->reqgain.capture = req_gain.capture)
1279 DO_IF_VALID(local_gain.playback, control->option.playback = option)
1280 DO_IF_VALID(local_gain.capture, control->option.capture = option)
1282 /* Check for Release PATH */
1283 if (req_release_path && (req_gain.playback == local_gain.playback) && (req_gain.capture == local_gain.capture)) {
1284 avsys_warning(AVAUDIO,"Release path for %d %d\n", local_gain.playback, local_gain.capture);
1286 #ifdef MURPHY_SUPPORT
1287 err = AVSYS_STATE_SUCCESS;
1289 err = __avsys_audio_release_path(local_gain, control);
1293 if (CHECK_VALID(req_gain.playback)) {
1294 if(req_gain.playback != local_gain.playback) {
1295 avsys_warning(AVAUDIO, "Sound Path is protected. use current configuration (playback_gain %d, out %d, opt 0x%x)\n",
1296 local_gain.playback, control->path.playback, control->option.playback);
1297 if (req_gain.playback == AVSYS_AUDIO_PLAYBACK_GAIN_AP) {
1298 control->backup_gain.playback = control->reqgain.playback;
1299 control->backup_path.playback = out;
1302 control->path.playback = out;
1303 control->backup_gain.playback = local_gain.playback;
1304 control->backup_path.playback = out;
1306 switch (local_gain.playback) {
1307 case AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT:
1308 #ifndef MURPHY_SUPPORT
1309 if (control->path.playback == AVSYS_AUDIO_PATH_EX_BTHEADSET) {
1310 SET_AIF(AIF_BT_PLAYBACK);
1311 SET_AIF(AIF_BT_CAPTURE);
1316 case AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL:
1317 case AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL:
1318 #ifndef MURPHY_SUPPORT
1319 /* Set CP only for voicecall */
1320 if (local_gain.capture == AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL) {
1321 SET_AIF(AIF_CP_PLAYBACK);
1323 control->path_fixed_pid[PATH_FIXED_TYPE_CALL] = current_pid;
1324 SET_AIF(AIF2_PLAYBACK);
1326 /* Voicecall / Videocall Common setting */
1327 control->path_fixed_pid[PATH_FIXED_TYPE_CALL] = current_pid;
1328 if (control->path.playback == AVSYS_AUDIO_PATH_EX_BTHEADSET) {
1329 SET_AIF(AIF_BT_PLAYBACK);
1334 case AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO:
1335 control->path_fixed_pid[PATH_FIXED_TYPE_FMRADIO] = current_pid;
1336 SET_AIF(AIF_RADIO_PLAYBACK);
1342 if (CHECK_VALID(req_gain.capture)) {
1343 if (req_gain.capture != local_gain.capture) {
1344 avsys_warning(AVAUDIO, "Sound Path is protected. use current configuration (capture_gain %d, in %d, opt 0x%x)\n",
1345 local_gain.capture, control->path.capture, control->option.capture);
1346 if (req_gain.capture == AVSYS_AUDIO_CAPTURE_GAIN_AP) {
1347 control->backup_gain.capture = control->reqgain.capture;
1348 control->backup_path.capture = in;
1351 control->path.capture = in;
1352 control->backup_gain.capture = local_gain.capture;
1353 control->backup_path.capture = in;
1355 switch (local_gain.capture) {
1356 case AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL:
1357 case AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL:
1358 /* Voicecall / Videocall Common setting */
1359 control->path_fixed_pid[PATH_FIXED_TYPE_CALL] = current_pid;
1360 #ifndef MURPHY_SUPPORT
1361 /* Set CP only for voicecall */
1362 if (local_gain.capture == AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL) {
1363 SET_AIF(AIF_CP_CAPTURE);
1365 control->path_fixed_pid[PATH_FIXED_TYPE_CALL] = current_pid;
1366 if (control->path.capture == AVSYS_AUDIO_PATH_EX_BTMIC) {
1367 SET_AIF(AIF3_CAPTURE);
1370 SET_AIF(AIF2_CAPTURE);
1372 if (control->path.capture == AVSYS_AUDIO_PATH_EX_BTMIC) {
1373 SET_AIF(AIF_BT_CAPTURE);
1378 case AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO:
1379 control->path_fixed_pid[PATH_FIXED_TYPE_FMRADIO] = current_pid;
1386 if (control->control_aif_before_path_set) {
1387 #if !defined(MURPHY_SUPPORT)
1388 err = __avsys_open_aif(AIF_control, control->wb_enabled);
1390 err = AVSYS_STATE_SUCCESS;
1394 /* Do ALSA scenario control based on gain */
1396 if (local_gain.playback == AVSYS_AUDIO_PLAYBACK_GAIN_AP) {
1397 avsys_warning(AVAUDIO, "playback gain : ap\n");
1398 #ifndef MURPHY_SUPPORT
1399 err = __avsys_audio_path_set_ascn_ap_playback(control);
1400 if (AVSYS_SUCCESS(err)) {
1401 err = __avsys_audio_path_set_hw_controls(control);
1404 } else if(local_gain.playback == AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT) {
1405 avsys_warning(AVAUDIO,"playback gain : callalert\n");
1406 #ifndef MURPHY_SUPPORT
1407 err = __avsys_audio_path_set_ascn_ap_playback(control);
1408 if (AVSYS_SUCCESS(err)) {
1409 err = __avsys_audio_path_set_hw_controls(control);
1412 } else if (local_gain.playback == AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO &&
1413 local_gain.capture == AVSYS_AUDIO_CAPTURE_GAIN_FMRADIO) {
1414 avsys_warning(AVAUDIO, "fmradio gain\n");
1415 #ifndef MURPHY_SUPPORT
1416 err = __avsys_audio_path_set_ascn_fmradio(control);
1418 } else if (local_gain.playback == AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL &&
1419 local_gain.capture == AVSYS_AUDIO_CAPTURE_GAIN_VOICECALL) {
1420 avsys_warning(AVAUDIO, "voicecall gain\n");
1421 #ifndef MURPHY_SUPPORT
1422 err = __avsys_audio_path_set_ascn_voicecall(control);
1424 } else if (local_gain.playback == AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL &&
1425 local_gain.capture == AVSYS_AUDIO_CAPTURE_GAIN_VIDEOCALL) {
1426 avsys_warning(AVAUDIO, "videocall gain\n");
1427 #ifndef MURPHY_SUPPORT
1428 err = __avsys_audio_path_set_ascn_videocall(control);
1432 if (local_gain.capture == AVSYS_AUDIO_CAPTURE_GAIN_AP) {
1433 avsys_warning(AVAUDIO, "capture gain : ap\n");
1434 #ifndef MURPHY_SUPPORT
1435 err = __avsys_audio_path_set_ascn_ap_capture(control);
1439 if (!control->control_aif_before_path_set) {
1440 #if !defined(MURPHY_SUPPORT)
1441 err = __avsys_open_aif(AIF_control, control->wb_enabled);
1443 err = AVSYS_STATE_SUCCESS;
1449 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1450 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__);
1451 return AVSYS_STATE_ERR_INTERNAL;
1453 avsys_info(AVAUDIO, "------------------------------------------------\n");
1457 int avsys_audio_path_ex_get_path(int *gain, int *out, int *in, int *option)
1459 avsys_audio_path_ex_info_t *control = NULL;
1460 avsys_audio_path_ex_info_t ** temp = NULL;
1462 if(gain == NULL || out == NULL || in == NULL || option == NULL) {
1463 avsys_error(AVAUDIO,"Invalid parameter\n");
1464 return AVSYS_STATE_ERR_NULL_POINTER;
1469 if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))) {
1470 avsys_error_r(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
1471 return AVSYS_STATE_ERR_INTERNAL;
1473 if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1474 avsys_error_r(AVAUDIO, "avsys_audio_lock_sync() failed in %s\n", __func__);
1475 return AVSYS_STATE_ERR_INTERNAL;
1478 switch (control->gain.playback) {
1479 case AVSYS_AUDIO_PLAYBACK_GAIN_AP:
1480 *gain = AVSYS_AUDIO_GAIN_EX_KEYTONE;
1481 *out = control->path.playback;
1482 *in = AVSYS_AUDIO_PATH_EX_NONE;
1483 *option = control->option.playback;
1485 case AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT:
1486 *gain = AVSYS_AUDIO_GAIN_EX_RINGTONE;
1487 *out = control->path.playback;
1488 *in = AVSYS_AUDIO_PATH_EX_NONE;
1489 *option = control->option.playback;
1491 case AVSYS_AUDIO_PLAYBACK_GAIN_VOICECALL:
1492 *gain = AVSYS_AUDIO_GAIN_EX_VOICECALL;
1493 *out = control->path.playback;
1494 *in = control->path.capture;
1495 *option = control->option.playback;
1497 case AVSYS_AUDIO_PLAYBACK_GAIN_VIDEOCALL:
1498 *gain = AVSYS_AUDIO_GAIN_EX_VIDEOCALL;
1499 *out = control->path.playback;
1500 *in = control->path.capture;
1501 *option = control->option.playback;
1503 case AVSYS_AUDIO_PLAYBACK_GAIN_FMRADIO:
1504 *gain = AVSYS_AUDIO_GAIN_EX_FMRADIO;
1505 *out = control->path.playback;
1506 *in = control->path.capture;
1507 *option = control->option.playback;
1511 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1512 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__);
1513 return AVSYS_STATE_ERR_INTERNAL;
1516 return AVSYS_STATE_SUCCESS;
1519 int avsys_audio_path_ex_set_amp(const int onoff)
1521 //not yet implemented.
1522 return AVSYS_STATE_SUCCESS;
1525 int avsys_audio_path_ex_set_mute(const int mute)
1527 avsys_audio_path_ex_info_t *control = NULL;
1528 avsys_audio_path_ex_info_t **temp = NULL;
1532 if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))) {
1533 avsys_error_r(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
1534 return AVSYS_STATE_ERR_INTERNAL;
1537 if (control == NULL) {
1538 return AVSYS_STATE_ERR_NULL_POINTER;
1541 if (mute == AVSYS_AUDIO_UNMUTE || mute == AVSYS_AUDIO_MUTE) {
1542 if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1543 avsys_error_r(AVAUDIO, "avsys_audio_lock_sync() failed in %s\n", __func__);
1544 return AVSYS_STATE_ERR_INTERNAL;
1547 if (control->mute == mute) {
1548 avsys_info(AVAUDIO, "[Path Mute] skip mute ctrl op: %d\n", mute);
1549 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1550 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() 2 failed in %s\n", __func__);
1551 return AVSYS_STATE_ERR_INTERNAL;
1553 return AVSYS_STATE_SUCCESS;
1555 control->mute = mute;
1556 avsys_warning(AVAUDIO, "[Path Mute] run mute ctrl op: %d\n", mute);
1559 #ifndef MURPHY_SUPPORT
1560 if (control->mute) {
1561 if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_STR_PLAYBACK_MUTE))) {
1562 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1563 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() 1 failed in %s\n", __func__);
1564 return AVSYS_STATE_ERR_INTERNAL;
1566 avsys_error(AVAUDIO, "Mute fail %s\n", __func__);
1567 return AVSYS_STATE_ERR_IO_CONTROL;
1570 if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_STR_PLAYBACK_UNMUTE))) {
1571 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1572 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() 1 failed in %s\n", __func__);
1573 return AVSYS_STATE_ERR_INTERNAL;
1575 avsys_error(AVAUDIO, "Unmute fail %s\n", __func__);
1576 return AVSYS_STATE_ERR_IO_CONTROL;
1581 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1582 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() 2 failed in %s\n", __func__);
1583 return AVSYS_STATE_ERR_INTERNAL;
1587 if (mute == AVSYS_AUDIO_UNMUTE_NOLOCK) /* set nomalize */
1588 mute_nolock = AVSYS_AUDIO_UNMUTE;
1590 mute_nolock = AVSYS_AUDIO_MUTE;
1592 if (control->mute == mute_nolock) {
1593 avsys_info(AVAUDIO, "[Path Mute] skip mute ctrl op: %d\n", mute);
1594 return AVSYS_STATE_SUCCESS;
1596 control->mute = mute_nolock;
1597 avsys_warning(AVAUDIO, "[Path Mute] run mute ctrl op: %d\n", mute);
1600 #ifndef MURPHY_SUPPORT
1601 if (control->mute) {
1602 if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_STR_PLAYBACK_MUTE))) {
1603 avsys_error(AVAUDIO, "Mute fail %s\n", __func__);
1604 return AVSYS_STATE_ERR_IO_CONTROL;
1607 if (AVSYS_FAIL(avsys_audio_ascn_single_set(ASCN_STR_PLAYBACK_UNMUTE))) {
1608 avsys_error(AVAUDIO, "Unmute fail %s\n", __func__);
1609 return AVSYS_STATE_ERR_IO_CONTROL;
1615 if (mute == AVSYS_AUDIO_UNMUTE || mute == AVSYS_AUDIO_UNMUTE_NOLOCK)
1616 avsys_info_r(AVAUDIO, "Global Mute Disabled\n");
1617 else if (mute == AVSYS_AUDIO_MUTE || mute == AVSYS_AUDIO_MUTE_NOLOCK)
1618 avsys_info_r(AVAUDIO, "Global Mute Enabled\n");
1619 return AVSYS_STATE_SUCCESS;
1622 int avsys_audio_path_ex_get_mute(int *mute)
1624 avsys_audio_path_ex_info_t *control = NULL;
1625 avsys_audio_path_ex_info_t **temp = NULL;
1629 if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp))) {
1630 avsys_error_r(AVAUDIO, "avsys_audio_get_shm() failed in %s\n", __func__);
1631 return AVSYS_STATE_ERR_INTERNAL;
1634 if (control == NULL) {
1635 return AVSYS_STATE_ERR_NULL_POINTER;
1638 if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1639 avsys_error_r(AVAUDIO, "avsys_audio_lock_sync() failed in %s\n", __func__);
1640 return AVSYS_STATE_ERR_INTERNAL;
1643 *mute = control->mute;
1645 if (AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH))) {
1646 avsys_error_r(AVAUDIO, "avsys_audio_unlock_sync() failed in %s\n", __func__);
1647 return AVSYS_STATE_ERR_INTERNAL;
1650 return AVSYS_STATE_SUCCESS;
1653 #ifndef MURPHY_SUPPORT
1654 static int __avsys_audio_path_set_ascn_ap_playback(avsys_audio_path_ex_info_t *control)
1656 int cmd_gain[2] = { 0, 0 };
1657 int cmd_path[3] = { 0, 0, 0 };
1658 char callalert_mode = 0;
1660 avsys_info(AVAUDIO, "<< path.playback = %d, option = %x, gain.playback = %d, inserted = %d\n",
1661 control->path.playback, control->option.playback, control->gain.playback, control->inserted);
1663 callalert_mode = (control->gain.playback == AVSYS_AUDIO_PLAYBACK_GAIN_CALLALERT) ? 1 : 0;
1664 control->path_fixed = PATH_FIXED_NONE;
1666 switch (control->path.playback) {
1667 case AVSYS_AUDIO_PATH_EX_SPK:
1668 if (control->option.playback & AVSYS_AUDIO_PATH_OPTION_DUAL_OUT) {
1669 if (callalert_mode) {
1670 cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_CALLALERT;
1671 cmd_gain[1] = INPUT_AP | OUTPUT_HEADSET | GAIN_CALLALERT;
1673 cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE;
1674 cmd_gain[1] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE;
1677 cmd_path[0] = INPUT_AP | OUTPUT_STEREO_SPK;
1678 cmd_path[1] = INPUT_AP | OUTPUT_HEADSET;
1680 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
1682 if (callalert_mode) {
1683 cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_CALLALERT;
1685 cmd_gain[0] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE;
1687 control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITHOUT_MUTE;
1688 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
1690 cmd_path[0] = INPUT_AP | OUTPUT_STEREO_SPK;
1694 case AVSYS_AUDIO_PATH_EX_RECV:
1695 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
1696 cmd_gain[0] = INPUT_AP | OUTPUT_RECV | GAIN_MODE;
1697 cmd_path[0] = INPUT_AP | OUTPUT_RECV;
1700 case AVSYS_AUDIO_PATH_EX_HEADSET:
1701 if (callalert_mode) {
1702 cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_CALLALERT;
1704 cmd_gain[0] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE;
1706 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET;
1707 cmd_path[0] = INPUT_AP | OUTPUT_HEADSET;
1710 case AVSYS_AUDIO_PATH_EX_HDMI:
1711 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
1712 cmd_gain[0] = INPUT_AP | OUTPUT_HDMI | GAIN_MODE;
1713 cmd_path[0] = INPUT_AP | OUTPUT_HDMI;
1716 case AVSYS_AUDIO_PATH_EX_DOCK:
1717 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
1718 cmd_gain[0] = INPUT_AP | OUTPUT_DOCK | GAIN_MODE;
1719 cmd_path[0] = INPUT_AP | OUTPUT_DOCK;
1722 case AVSYS_AUDIO_PATH_EX_BTHEADSET:
1723 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET;
1724 cmd_gain[0] = INPUT_AP | OUTPUT_BT_HEADSET | GAIN_MODE;
1725 cmd_path[0] = INPUT_AP | OUTPUT_BT_HEADSET;
1727 case AVSYS_AUDIO_PATH_EX_HANDSFREE:
1728 default: /* DEFAULT PATH CONTROL TO NONE */
1729 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
1733 avsys_warning(AVAUDIO, "Run Alsa Scenario Script\n");
1734 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 2, ASCN_RESET_PLAYBACK))
1735 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 2, ASCN_RESET_NONE))
1737 avsys_info(AVAUDIO, ">> leave");
1738 return AVSYS_STATE_SUCCESS;
1741 static int __avsys_audio_path_set_ascn_voicecall(avsys_audio_path_ex_info_t *control)
1743 int cmd_gain[6] = { 0, 0, 0, 0, 0, 0 };
1744 int cmd_path[6] = { 0, 0, 0, 0, 0, 0 };
1747 control->path_fixed = PATH_FIXED_WITH_CALL;
1749 avsys_info(AVAUDIO, "<< path.playback = %d, option = %x, gain.playback = %d, inserted = %d\n",
1750 control->path.playback, control->option.playback, control->gain.playback, control->inserted);
1753 switch (control->path.playback) {
1754 case AVSYS_AUDIO_PATH_EX_NONE:
1755 avsys_warning(AVAUDIO, "[SZ] playback AVSYS_AUDIO_PATH_EX_NONE\n");
1758 case AVSYS_AUDIO_PATH_EX_SPK:
1759 if (control->reqgain.playback == control->gain.playback) {
1760 cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE;
1761 cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK;
1762 cmd_gain[gain_idx++] = INPUT_CP | OUTPUT_STEREO_SPK | GAIN_VOICE_CALL;
1763 cmd_path[path_idx++] = INPUT_CP | OUTPUT_STEREO_SPK;
1765 avsys_warning(AVAUDIO, "Ignore another path setting request during voicecall\n");
1769 case AVSYS_AUDIO_PATH_EX_RECV:
1770 if (control->gain.playback == control->reqgain.playback) {
1771 cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_RECV | GAIN_MODE;
1772 cmd_path[path_idx++] = INPUT_AP | OUTPUT_RECV;
1773 cmd_gain[gain_idx++] = INPUT_CP | OUTPUT_RECV | GAIN_VOICE_CALL;
1774 cmd_path[path_idx++] = INPUT_CP | OUTPUT_RECV;
1776 avsys_warning(AVAUDIO, "Ignore another path setting request during voicecall\n");
1780 case AVSYS_AUDIO_PATH_EX_HEADSET:
1781 if (control->reqgain.playback == control->gain.playback) {
1782 cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE;
1783 cmd_path[path_idx++] = INPUT_AP | OUTPUT_HEADSET;
1784 cmd_gain[gain_idx++] = INPUT_CP | OUTPUT_HEADSET | GAIN_VOICE_CALL;
1785 cmd_path[path_idx++] = INPUT_CP | OUTPUT_HEADSET;
1787 avsys_warning(AVAUDIO, "Ignore another path setting request during voicecall\n");
1791 case AVSYS_AUDIO_PATH_EX_BTHEADSET:
1793 if (control->reqgain.playback == control->gain.playback) {
1794 control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITH_MUTE;
1795 cmd_gain[gain_idx++] = INPUT_CP | OUTPUT_BT_HEADSET | GAIN_MODE;
1796 cmd_path[path_idx++] = INPUT_AP | OUTPUT_BT_HEADSET;
1797 cmd_path[path_idx++] = INPUT_CP | OUTPUT_BT_HEADSET;
1799 avsys_warning(AVAUDIO, "Ignore another path setting request during voicecall\n");
1803 case AVSYS_AUDIO_PATH_EX_HANDSFREE:
1805 if (control->reqgain.playback == control->gain.playback) {
1806 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
1812 /* Add sound path CP to AP (Rx recording) */
1813 if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC) {
1814 avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC\n");
1815 //cmd_path[path_idx++] = INPUT_CP | OUTPUT_AP;
1820 switch (control->path.capture) {
1821 case AVSYS_AUDIO_PATH_EX_NONE:
1822 avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_EX_NONE\n");
1825 case AVSYS_AUDIO_PATH_EX_MIC:
1826 if (control->reqgain.capture == control->gain.capture) {
1827 if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC) {
1828 cmd_gain[gain_idx++] = INPUT_SUB_MIC | OUTPUT_CP | GAIN_MODE;
1829 cmd_path[path_idx++] = INPUT_SUB_MIC | OUTPUT_CP;
1830 if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC) {
1831 avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC\n");
1832 //cmd_path[path_idx++] = INPUT_SUB_MIC | OUTPUT_AP;
1835 cmd_gain[gain_idx++] = INPUT_MAIN_MIC | OUTPUT_CP | GAIN_MODE;
1836 cmd_path[path_idx++] = INPUT_MAIN_MIC | OUTPUT_CP;
1837 if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC) {
1838 avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC\n");
1839 //cmd_path[path_idx++] = INPUT_MAIN_MIC | OUTPUT_AP;
1845 case AVSYS_AUDIO_PATH_EX_HEADSETMIC:
1846 if (control->reqgain.capture == control->gain.capture) {
1847 cmd_gain[gain_idx++] = INPUT_EAR_MIC | OUTPUT_CP | GAIN_MODE;
1848 cmd_path[path_idx++] = INPUT_EAR_MIC | OUTPUT_CP;
1849 if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC) {
1850 avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC\n");
1851 //cmd_path[path_idx++] = INPUT_EAR_MIC | OUTPUT_AP;
1856 case AVSYS_AUDIO_PATH_EX_BTMIC:
1857 if (control->reqgain.capture == control->gain.capture) {
1858 cmd_gain[gain_idx++] = INPUT_BT_MIC | OUTPUT_CP | GAIN_MODE;
1859 cmd_path[path_idx++] = INPUT_BT_MIC | OUTPUT_CP;
1860 if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC) {
1861 avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_OPTION_VOICECALL_REC\n");
1862 //avsys_error(AVAUDIO, "BT Call recording is not supported");
1866 case AVSYS_AUDIO_PATH_EX_HANDSFREE:
1871 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET));
1872 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 6, ASCN_RESET_NONE));
1873 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 6, ASCN_RESET_NONE));
1875 avsys_info(AVAUDIO, ">> leave");
1876 return AVSYS_STATE_SUCCESS;
1879 static int __avsys_audio_path_set_ascn_videocall(avsys_audio_path_ex_info_t *control)
1881 int cmd_gain[2] = { 0, 0 };
1882 int cmd_path[3] = { 0, 0, 0 };
1886 control->path_fixed = PATH_FIXED_WITH_CALL;
1887 switch (control->path.playback) {
1888 case AVSYS_AUDIO_PATH_EX_NONE:
1889 avsys_warning(AVAUDIO, "[SZ] playback AVSYS_AUDIO_PATH_EX_NONE\n");
1892 case AVSYS_AUDIO_PATH_EX_SPK:
1893 if (control->reqgain.playback == control->gain.playback) {
1894 cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE;
1895 cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK;
1896 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
1898 avsys_warning(AVAUDIO, "Sound Path request during VT call ignored.");
1902 case AVSYS_AUDIO_PATH_EX_RECV:
1903 if (control->gain.playback == control->reqgain.playback) {
1904 cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_RECV | GAIN_MODE;
1905 cmd_path[path_idx++] = INPUT_AP | OUTPUT_RECV;
1906 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
1908 avsys_warning(AVAUDIO, "Sound Path request during VT call ignored.");
1912 case AVSYS_AUDIO_PATH_EX_HEADSET:
1913 if (control->reqgain.playback == control->gain.playback) {
1914 cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE;
1915 cmd_path[path_idx++] = INPUT_AP | OUTPUT_HEADSET;
1916 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET;
1918 avsys_warning(AVAUDIO, "Sound Path request during VT call ignored.");
1922 case AVSYS_AUDIO_PATH_EX_BTHEADSET:
1923 if (control->reqgain.playback == control->gain.playback) {
1924 cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_BT_HEADSET | GAIN_MODE;
1925 cmd_path[path_idx++] = INPUT_AP | OUTPUT_BT_HEADSET;
1926 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET;
1928 avsys_warning(AVAUDIO, "Sound Path request during VT call ignored.");
1932 case AVSYS_AUDIO_PATH_EX_HANDSFREE:
1934 if (control->reqgain.playback == control->gain.playback) {
1935 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
1940 switch (control->path.capture) {
1941 case AVSYS_AUDIO_PATH_EX_NONE:
1942 avsys_warning(AVAUDIO, "[SZ] capture AVSYS_AUDIO_PATH_EX_NONE\n");
1945 case AVSYS_AUDIO_PATH_EX_MIC:
1946 if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC) {
1947 cmd_gain[gain_idx++] = INPUT_SUB_MIC | OUTPUT_AP | GAIN_MODE;
1948 cmd_path[path_idx++] = INPUT_SUB_MIC | OUTPUT_AP;
1950 cmd_gain[gain_idx++] = INPUT_MAIN_MIC | OUTPUT_AP | GAIN_MODE;
1951 cmd_path[path_idx++] = INPUT_MAIN_MIC | OUTPUT_AP;
1955 case AVSYS_AUDIO_PATH_EX_HEADSETMIC:
1956 cmd_gain[gain_idx++] = INPUT_EAR_MIC | OUTPUT_AP | GAIN_MODE;
1957 cmd_path[path_idx++] = INPUT_EAR_MIC | OUTPUT_AP;
1960 case AVSYS_AUDIO_PATH_EX_BTMIC:
1961 cmd_gain[gain_idx++] = INPUT_BT_MIC | OUTPUT_AP | GAIN_MODE;
1962 cmd_path[path_idx++] = INPUT_BT_MIC | OUTPUT_AP;
1965 case AVSYS_AUDIO_PATH_EX_HANDSFREE:
1970 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET));
1971 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 2, ASCN_RESET_NONE));
1972 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 2, ASCN_RESET_NONE));
1974 return AVSYS_STATE_SUCCESS;
1978 static int __avsys_audio_path_set_ascn_fmradio(avsys_audio_path_ex_info_t *control)
1980 int cmd_gain[2] = { 0, 0 };
1981 int cmd_path[3] = { 0, 0, 0 };
1983 int skip_clear_record = 0;
1987 avsys_warning(AVAUDIO, "req gain playback [%x], control gain playback [%x]\n",
1988 control->reqgain.playback, control->gain.playback);
1989 avsys_warning(AVAUDIO, "req gain capture [%x], control gain capture [%x]\n",
1990 control->reqgain.capture, control->gain.capture);
1992 switch (control->path.playback) {
1993 case AVSYS_AUDIO_PATH_EX_NONE:
1994 avsys_warning(AVAUDIO, "[SZ] playback AVSYS_AUDIO_PATH_EX_NONE\n");
1997 case AVSYS_AUDIO_PATH_EX_SPK:
1998 if (control->reqgain.playback == control->gain.playback) {
1999 avsys_warning(AVAUDIO, "req gain playback == control gain playback\n");
2000 cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_STEREO_SPK | GAIN_MODE;
2001 cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK;
2003 avsys_warning(AVAUDIO, "req gain playback != control gain playback\n");
2004 /* append ap playback sound path */
2005 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
2006 cmd_path[path_idx++] = INPUT_AP | OUTPUT_STEREO_SPK;
2011 case AVSYS_AUDIO_PATH_EX_HEADSET:
2012 if (control->reqgain.playback == control->gain.playback) {
2013 avsys_warning(AVAUDIO, "req gain playback == control gain playback\n");
2014 cmd_gain[gain_idx++] = INPUT_AP | OUTPUT_HEADSET | GAIN_MODE;
2015 cmd_path[path_idx++] = INPUT_AP | OUTPUT_HEADSET;
2017 //append ap playback
2018 avsys_warning(AVAUDIO, "req gain playback != control gain playback\n");
2019 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_HEADSET;
2020 cmd_path[path_idx++] = INPUT_AP | OUTPUT_HEADSET;
2025 case AVSYS_AUDIO_PATH_EX_A2DP:
2026 if (control->reqgain.playback == control->gain.playback) {
2027 avsys_warning(AVAUDIO, "req gain playback == control gain playback\n");
2028 //control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_MANUAL;
2030 avsys_warning(AVAUDIO, "req gain playback != control gain playback\n");
2031 control->lvol_dev_type = AVSYS_AUDIO_LVOL_DEV_TYPE_BTHEADSET;
2040 switch (control->path.capture) {
2041 case AVSYS_AUDIO_PATH_EX_FMINPUT:
2042 if (control->reqgain.capture == control->gain.capture) {
2043 avsys_warning(AVAUDIO, "req gain capture == control gain capture\n");
2044 cmd_path[path_idx++] = INPUT_FMRADIO | OUTPUT_AP | GAIN_MODE;
2045 cmd_path[path_idx++] = INPUT_FMRADIO | OUTPUT_AP;
2046 if (control->reqgain.capture == control->pregain.capture) {
2047 avsys_warning(AVAUDIO, "req gain capture == control pregain capture\n");
2048 skip_clear_record = 1;
2056 if (skip_clear_record) {
2057 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET_PLAYBACK))
2058 } else if (!skip_clear) {
2059 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(ASCN_STR_RESET))
2061 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, gain_idx, ASCN_RESET_NONE))
2062 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, path_idx, ASCN_RESET_NONE))
2064 return AVSYS_STATE_SUCCESS;
2067 static int __avsys_audio_path_set_ascn_ap_capture(avsys_audio_path_ex_info_t *control)
2069 int cmd_gain[2] = { 0, 0 };
2070 int cmd_path[3] = { 0, 0, 0 };
2072 avsys_info(AVAUDIO, "<< path.capture = %d, option = %x, gain.capture = %d, inserted = %d\n",
2073 control->path.capture, control->option.capture, control->gain.capture, control->inserted);
2074 switch(control->path.capture) {
2075 case AVSYS_AUDIO_PATH_EX_MIC:
2076 control->ear_auto = AVSYS_AUDIO_EAR_SWITCH_AUTO_WITHOUT_MUTE;
2077 if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_SUBMIC) {
2078 cmd_gain[0] = INPUT_SUB_MIC | OUTPUT_AP | GAIN_MODE;
2079 cmd_path[0] = INPUT_SUB_MIC | OUTPUT_AP;
2080 } else if (control->option.capture & AVSYS_AUDIO_PATH_OPTION_USE_STEREOMIC) {
2081 cmd_gain[0] = INPUT_STEREO_MIC | OUTPUT_AP | GAIN_MODE;
2082 cmd_path[0] = INPUT_STEREO_MIC | OUTPUT_AP;
2084 cmd_gain[0] = INPUT_MAIN_MIC | OUTPUT_AP | GAIN_MODE;
2085 cmd_path[0] = INPUT_MAIN_MIC | OUTPUT_AP;
2089 case AVSYS_AUDIO_PATH_EX_HEADSETMIC:
2090 cmd_gain[0] = INPUT_EAR_MIC | OUTPUT_AP | GAIN_MODE;
2091 cmd_path[0] = INPUT_EAR_MIC | OUTPUT_AP;
2098 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_gain, 2, ASCN_RESET_CAPTURE))
2099 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_bulk_set(cmd_path, 2, ASCN_RESET_NONE))
2101 avsys_info (AVAUDIO, ">> leave");
2103 return AVSYS_STATE_SUCCESS;
2107 static int __avsys_audio_path_set_hw_controls(avsys_audio_path_ex_info_t *control)
2109 avsys_audio_handle_info_t *handle_control = NULL;
2110 avsys_audio_handle_info_t **temp = NULL;
2111 int ret = AVSYS_STATE_SUCCESS;
2112 avsys_info(AVAUDIO, "global mute %d\n", control->mute);
2113 avsys_info(AVAUDIO, "path_fixed mute %d\n", control->path_fixed);
2115 /* update logical volume table - about output device - information for open handles */
2116 avsys_info(AVAUDIO, "Control handle informations\n");
2118 avsys_audio_handle_t *ptr = NULL;
2120 int out_device = AVSYS_AUDIO_LVOL_DEV_TYPE_SPK;
2122 temp = &handle_control;
2123 if (AVSYS_FAIL(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_HANDLE, (void**)temp))) {
2124 avsys_error(AVAUDIO, "avsys_audio_get_shm() failed in %s\n",__func__);
2125 return AVSYS_STATE_ERR_INTERNAL;
2128 if (AVSYS_FAIL(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_HANDLE))) {
2129 avsys_error(AVAUDIO, "avsys_audio_lock_sync() failed in %s\n",__func__);
2130 return AVSYS_STATE_ERR_INTERNAL;
2133 while (++handle < AVSYS_AUDIO_HANDLE_MAX) {
2134 long long int flag = 0x01;
2137 if (handle_control->allocated & flag)
2139 ptr = &(handle_control->handles[handle]);
2141 if (ptr->mode != AVSYS_AUDIO_MODE_OUTPUT && ptr->mode != AVSYS_AUDIO_MODE_OUTPUT_CLOCK
2142 && ptr->mode != AVSYS_AUDIO_MODE_OUTPUT_LOW_LATENCY && ptr->mode != AVSYS_AUDIO_MODE_OUTPUT_AP_CALL) {
2146 out_device = control->lvol_dev_type;
2147 avsys_audio_logical_volume_update_table(out_device, &ptr->gain_setting);
2148 avsys_audio_logical_volume_convert(&ptr->setting_vol, &ptr->working_vol, &ptr->gain_setting);
2152 if(AVSYS_FAIL(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_HANDLE))) {
2153 avsys_error(AVAUDIO,"avsys_audio_unlock_sync() failed in %s\n",__func__);
2154 return AVSYS_STATE_ERR_INTERNAL;
2157 return AVSYS_STATE_SUCCESS;
2160 #endif /* MURPHY_SUPPORT */
2162 static bool __avsys_audio_path_check_cp_audio(int gain)
2164 /*If video call uses CP audio, add AVSYS_AUDIO_GAIN_EX_VIDEOCALL to following code. */
2165 if (gain == AVSYS_AUDIO_GAIN_EX_VOICECALL)
2171 int avsys_audio_path_set_volume(int handle)
2173 avsys_audio_path_ex_info_t *control = NULL;
2174 avsys_audio_path_ex_info_t **temp = NULL;
2175 avsys_audio_handle_t *ptr = NULL;
2177 int vol_conf, vol_conf_type;
2178 int out_device = AVSYS_AUDIO_DEVICE_TYPE_SPK;
2180 err = avsys_audio_handle_get_ptr(handle, &ptr, HANDLE_PTR_MODE_NORMAL);
2181 if (AVSYS_FAIL(err)) {
2182 avsys_error(AVAUDIO, "Handle is not allocated\n");
2183 avsys_audio_handle_release_ptr(handle, HANDLE_PTR_MODE_NORMAL);
2184 return AVSYS_STATE_ERR_INVALID_PARAMETER;
2188 avsys_assert(AVSYS_SUCCESS(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp)));
2189 avsys_assert(control != NULL);
2190 avsys_assert(AVSYS_SUCCESS(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH)));
2192 if (__avsys_audio_path_check_cp_audio(control->gain.playback))
2193 ptr->during_cp_audio = 1;
2195 ptr->during_cp_audio = 0;
2197 vol_conf = ptr->gain_setting.volume_config;
2198 vol_conf_type = AVSYS_AUDIO_VOLUME_CONFIG_TYPE(vol_conf);
2199 out_device = control->lvol_dev_type;
2200 avsys_assert(AVSYS_SUCCESS(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH)));
2201 avsys_warning(AVAUDIO, "set path volume : gain(%d), out_dev(%d)\n", vol_conf_type, out_device);
2202 err = avsys_audio_logical_volume_set_table(vol_conf, out_device, &ptr->gain_setting);
2203 avsys_audio_handle_release_ptr(handle, HANDLE_PTR_MODE_NORMAL);
2207 int avsys_audio_path_set_route_policy(avsys_audio_route_policy_t route)
2213 int avsys_audio_path_get_route_policy(avsys_audio_route_policy_t *route)
2219 int avsys_audio_path_check_cp_audio(bool *cpaudio, bool *btpath)
2221 avsys_audio_path_ex_info_t *control = NULL;
2222 avsys_audio_path_ex_info_t **temp = NULL;
2224 if (!cpaudio || !btpath)
2225 return AVSYS_STATE_ERR_INVALID_PARAMETER;
2228 avsys_assert(AVSYS_SUCCESS(avsys_audio_get_shm(AVSYS_AUDIO_SHM_IDEN_PATH, (void **)temp)));
2229 avsys_assert(control != NULL);
2230 avsys_assert(AVSYS_SUCCESS(avsys_audio_lock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH)));
2232 if (__avsys_audio_path_check_cp_audio(control->gain.playback))
2237 if (control->path.playback == AVSYS_AUDIO_PATH_EX_BTHEADSET)
2242 avsys_assert(AVSYS_SUCCESS(avsys_audio_unlock_sync(AVSYS_AUDIO_SYNC_IDEN_PATH)));
2243 return AVSYS_STATE_SUCCESS;
2246 int avsys_audio_path_set_single_ascn(char *str)
2249 return AVSYS_STATE_ERR_INVALID_PARAMETER;
2251 #ifndef MURPHY_SUPPORT
2252 RET_IO_CTL_ERR_IF_FAIL(avsys_audio_ascn_single_set(str))
2255 return AVSYS_STATE_SUCCESS;