hal: update logic to identify primary sound card
Check if the sound card name contains the hw codec name
to validate the primary sound card name before initializing
the audio route library.
Bug: 21731989
Change-Id: I2a14201e8774c07a922c87d3fc08f55a389a56e6
diff --git a/hal/msm8960/platform.c b/hal/msm8960/platform.c
index acfa991..2f596ba 100644
--- a/hal/msm8960/platform.c
+++ b/hal/msm8960/platform.c
@@ -958,6 +958,13 @@
return -ENOSYS;
}
+int platform_set_parameters(void *platform __unused,
+ struct str_parms *parms __unused)
+{
+ ALOGE("%s: Not implemented", __func__);
+ return -ENOSYS;
+}
+
/* Delay in Us */
int64_t platform_render_latency(audio_usecase_t usecase)
{
diff --git a/hal/msm8974/platform.c b/hal/msm8974/platform.c
index c6b84a8..77611b8 100644
--- a/hal/msm8974/platform.c
+++ b/hal/msm8974/platform.c
@@ -55,6 +55,8 @@
#define RETRY_US 500000
#define MAX_SND_CARD 8
+#define MAX_SND_CARD_NAME_LEN 31
+
#define DEFAULT_APP_TYPE_RX_PATH 0x11130
struct audio_block_header
@@ -100,6 +102,8 @@
acdb_send_gain_dep_cal_t acdb_send_gain_dep_cal;
struct csd_data *csd;
char ec_ref_mixer_path[64];
+
+ char *snd_card_name;
};
static int pcm_device_table[AUDIO_USECASE_MAX][2] = {
@@ -747,6 +751,15 @@
int retry_num = 0, snd_card_num = 0;
const char *snd_card_name;
+ my_data = calloc(1, sizeof(struct platform_data));
+
+ my_data->adev = adev;
+
+ set_platform_defaults(my_data);
+
+ /* Initialize platform specific ids and/or backends*/
+ platform_info_init(my_data);
+
while (snd_card_num < MAX_SND_CARD) {
adev->mixer = mixer_open(snd_card_num);
@@ -765,12 +778,23 @@
}
snd_card_name = mixer_get_name(adev->mixer);
+
+ /* validate the sound card name */
+ if (my_data->snd_card_name != NULL &&
+ strncmp(snd_card_name, my_data->snd_card_name, MAX_SND_CARD_NAME_LEN) != 0) {
+ ALOGI("%s: found valid sound card %s, but not primary sound card %s",
+ __func__, snd_card_name, my_data->snd_card_name);
+ retry_num = 0;
+ snd_card_num++;
+ continue;
+ }
+
ALOGD("%s: snd_card_name: %s", __func__, snd_card_name);
adev->audio_route = audio_route_init(snd_card_num, MIXER_XML_PATH);
if (!adev->audio_route) {
ALOGE("%s: Failed to init audio route controls, aborting.", __func__);
- return NULL;
+ goto init_failed;
}
adev->snd_card = snd_card_num;
ALOGD("%s: Opened sound card:%d", __func__, snd_card_num);
@@ -779,12 +803,9 @@
if (snd_card_num >= MAX_SND_CARD) {
ALOGE("%s: Unable to find correct sound card, aborting.", __func__);
- return NULL;
+ goto init_failed;
}
- my_data = calloc(1, sizeof(struct platform_data));
-
- my_data->adev = adev;
my_data->dualmic_config = DUALMIC_CONFIG_NONE;
my_data->fluence_in_spkr_mode = false;
my_data->fluence_in_voice_call = false;
@@ -873,11 +894,6 @@
}
- set_platform_defaults(my_data);
-
- /* Initialize platform specific ids and/or backends*/
- platform_info_init();
-
audio_extn_spkr_prot_init(adev);
audio_extn_hwdep_cal_send(adev->snd_card, my_data->acdb_handle);
@@ -886,12 +902,30 @@
platform_csd_init(my_data);
return my_data;
+
+init_failed:
+ if (my_data)
+ free(my_data);
+ return NULL;
}
void platform_deinit(void *platform)
{
+ int32_t dev;
+
struct platform_data *my_data = (struct platform_data *)platform;
close_csd_client(my_data->csd);
+
+ for (dev = 0; dev < SND_DEVICE_MAX; dev++) {
+ if (backend_tag_table[dev])
+ free(backend_tag_table[dev]);
+ if (hw_interface_table[dev])
+ free(hw_interface_table[dev]);
+ }
+
+ if (my_data->snd_card_name)
+ free(my_data->snd_card_name);
+
free(platform);
}
@@ -1855,6 +1889,37 @@
return ret;
}
+int platform_set_parameters(void *platform, struct str_parms *parms)
+{
+ struct platform_data *my_data = (struct platform_data *)platform;
+ char value[64];
+ char *kv_pairs = str_parms_to_str(parms);
+ int ret = 0, err;
+
+ if (kv_pairs == NULL) {
+ ret = -EINVAL;
+ ALOGE("%s: key-value pair is NULL",__func__);
+ goto done;
+ }
+
+ ALOGV("%s: enter: %s", __func__, kv_pairs);
+
+ err = str_parms_get_str(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME,
+ value, sizeof(value));
+ if (err >= 0) {
+ str_parms_del(parms, PLATFORM_CONFIG_KEY_SOUNDCARD_NAME);
+ my_data->snd_card_name = strdup(value);
+ ALOGV("%s: sound card name %s", __func__, my_data->snd_card_name);
+ }
+
+done:
+ ALOGV("%s: exit with code(%d)", __func__, ret);
+ if (kv_pairs != NULL)
+ free(kv_pairs);
+
+ return ret;
+}
+
/* Delay in Us */
int64_t platform_render_latency(audio_usecase_t usecase)
{
diff --git a/hal/msm8974/platform.h b/hal/msm8974/platform.h
index ca75b8f..63c1357 100644
--- a/hal/msm8974/platform.h
+++ b/hal/msm8974/platform.h
@@ -203,6 +203,8 @@
#define LIB_CSD_CLIENT "libcsd-client.so"
#define LIB_MDM_DETECT "libmdmdetect.so"
+#define PLATFORM_CONFIG_KEY_SOUNDCARD_NAME "snd_card_name"
+
/* CSD-CLIENT related functions */
typedef int (*init_t)(bool);
typedef int (*deinit_t)();
diff --git a/hal/platform_api.h b/hal/platform_api.h
index 8b2b09c..61bb92f 100644
--- a/hal/platform_api.h
+++ b/hal/platform_api.h
@@ -61,8 +61,8 @@
int platform_set_snd_device_backend(snd_device_t snd_device, const char * backend,
const char * hw_interface);
-/* From platform_info_parser.c */
-int platform_info_init(void);
+/* From platform_info.c */
+int platform_info_init(void *);
int platform_get_usecase_index(const char * usecase);
int platform_set_usecase_pcm_id(audio_usecase_t usecase, int32_t type, int32_t pcm_id);
@@ -75,4 +75,6 @@
bool platform_check_backends_match(snd_device_t snd_device1, snd_device_t snd_device2);
+int platform_set_parameters(void *platform, struct str_parms *parms);
+
#endif // AUDIO_PLATFORM_API_H
diff --git a/hal/platform_info.c b/hal/platform_info.c
index e1ff361..c0527b4 100644
--- a/hal/platform_info.c
+++ b/hal/platform_info.c
@@ -32,6 +32,7 @@
ACDB,
PCM_ID,
BACKEND_NAME,
+ CONFIG_PARAMS,
} section_t;
typedef void (* section_process_fn)(const XML_Char **attr);
@@ -39,6 +40,7 @@
static void process_acdb_id(const XML_Char **attr);
static void process_pcm_id(const XML_Char **attr);
static void process_backend_name(const XML_Char **attr);
+static void process_config_params(const XML_Char **attr);
static void process_root(const XML_Char **attr);
static section_process_fn section_table[] = {
@@ -46,10 +48,18 @@
[ACDB] = process_acdb_id,
[PCM_ID] = process_pcm_id,
[BACKEND_NAME] = process_backend_name,
+ [CONFIG_PARAMS] = process_config_params,
};
static section_t section;
+struct platform_info {
+ void *platform;
+ struct str_parms *kvpairs;
+};
+
+static struct platform_info my_data;
+
/*
* <audio_platform_info>
* <acdb_ids>
@@ -67,6 +77,12 @@
* ...
* ...
* </pcm_ids>
+ * <config_params>
+ * <param key="snd_card_name" value="msm8994-tomtom-mtp-snd-card"/>
+ * ...
+ * ...
+ * </config_params>
+ *
* </audio_platform_info>
*/
@@ -80,7 +96,7 @@
int index;
if (strcmp(attr[0], "name") != 0) {
- ALOGE("%s: 'name' not found, no ACDB ID set!", __func__);
+ ALOGE("%s: 'name' not found, no pcm_id set!", __func__);
goto done;
}
@@ -198,6 +214,24 @@
return;
}
+/* platform specific configuration key-value pairs */
+static void process_config_params(const XML_Char **attr)
+{
+ if (strcmp(attr[0], "key") != 0) {
+ ALOGE("%s: 'key' not found", __func__);
+ goto done;
+ }
+
+ if (strcmp(attr[2], "value") != 0) {
+ ALOGE("%s: 'value' not found", __func__);
+ goto done;
+ }
+
+ str_parms_add_str(my_data.kvpairs, (char*)attr[1], (char*)attr[3]);
+done:
+ return;
+}
+
static void start_tag(void *userdata __unused, const XML_Char *tag_name,
const XML_Char **attr)
{
@@ -211,6 +245,8 @@
section = PCM_ID;
} else if (strcmp(tag_name, "backend_names") == 0) {
section = BACKEND_NAME;
+ } else if (strcmp(tag_name, "config_params") == 0) {
+ section = CONFIG_PARAMS;
} else if (strcmp(tag_name, "device") == 0) {
if ((section != ACDB) && (section != BACKEND_NAME)) {
ALOGE("device tag only supported for acdb/backend names");
@@ -228,6 +264,14 @@
section_process_fn fn = section_table[PCM_ID];
fn(attr);
+ } else if (strcmp(tag_name, "param") == 0) {
+ if (section != CONFIG_PARAMS) {
+ ALOGE("param tag only supported with CONFIG_PARAMS section");
+ return;
+ }
+
+ section_process_fn fn = section_table[section];
+ fn(attr);
}
return;
@@ -241,10 +285,13 @@
section = ROOT;
} else if (strcmp(tag_name, "backend_names") == 0) {
section = ROOT;
+ } else if (strcmp(tag_name, "config_params") == 0) {
+ section = ROOT;
+ platform_set_parameters(my_data.platform, my_data.kvpairs);
}
}
-int platform_info_init(void)
+int platform_info_init(void *platform)
{
XML_Parser parser;
FILE *file;
@@ -270,6 +317,9 @@
goto err_close_file;
}
+ my_data.platform = platform;
+ my_data.kvpairs = str_parms_create();
+
XML_SetElementHandler(parser, start_tag, end_tag);
while (1) {