From 9e31a8a6e38c7b95b79e35132d0629c9d5abd4f1 Mon Sep 17 00:00:00 2001 From: Banajit Goswami Date: Thu, 16 Nov 2017 18:40:14 -0800 Subject: [PATCH] asoc: sdm845: check sound card status before sending AFE config WCD codec must be enumerated before AFE configuration for some of the features can be sent to DSP. This is because as part of setting up this configuration, DSP tries to access some codec register. These register accesses will fail if codec is not enumerated already. Add a check for Sound Card online state to confirm that WCD codec has already enumerated before sending AFE configs. Change-Id: I0b7e5eb49e4f6c6aee9cb142054e57eae592602b Signed-off-by: Banajit Goswami --- asoc/sdm845.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/asoc/sdm845.c b/asoc/sdm845.c index d75174c3d9ca..3eb20a2d4969 100644 --- a/asoc/sdm845.c +++ b/asoc/sdm845.c @@ -3618,31 +3618,44 @@ static void msm_afe_clear_config(void) afe_clear_config(AFE_SLIMBUS_SLAVE_CONFIG); } -static int msm_adsp_power_up_config(struct snd_soc_codec *codec) +static int msm_adsp_power_up_config(struct snd_soc_codec *codec, + struct snd_card *card) { int ret = 0; unsigned long timeout; int adsp_ready = 0; + bool snd_card_online = 0; timeout = jiffies + msecs_to_jiffies(ADSP_STATE_READY_TIMEOUT_MS); do { - if (q6core_is_adsp_ready()) { - pr_debug("%s: ADSP Audio is ready\n", __func__); - adsp_ready = 1; - break; + if (!snd_card_online) { + snd_card_online = snd_card_is_online_state(card); + pr_debug("%s: Sound card is %s\n", __func__, + snd_card_online ? "Online" : "Offline"); } + if (!adsp_ready) { + adsp_ready = q6core_is_adsp_ready(); + pr_debug("%s: ADSP Audio is %s\n", __func__, + adsp_ready ? "ready" : "not ready"); + } + if (snd_card_online && adsp_ready) + break; + /* - * ADSP will be coming up after subsystem restart and + * Sound card/ADSP will be coming up after subsystem restart and * it might not be fully up when the control reaches * here. So, wait for 50msec before checking ADSP state */ msleep(50); } while (time_after(timeout, jiffies)); - if (!adsp_ready) { - pr_err("%s: timed out waiting for ADSP Audio\n", __func__); + if (!snd_card_online || !adsp_ready) { + pr_err("%s: Timeout. Sound card is %s, ADSP Audio is %s\n", + __func__, + snd_card_online ? "Online" : "Offline", + adsp_ready ? "ready" : "not ready"); ret = -ETIMEDOUT; goto err; } @@ -3700,7 +3713,7 @@ static int sdm845_notifier_service_cb(struct notifier_block *this, } codec = rtd->codec; - ret = msm_adsp_power_up_config(codec); + ret = msm_adsp_power_up_config(codec, card->snd_card); if (ret < 0) { dev_err(card->dev, "%s: msm_adsp_power_up_config failed ret = %d!\n", @@ -3798,7 +3811,7 @@ static int msm_audrx_init(struct snd_soc_pcm_runtime *rtd) msm_codec_fn.get_afe_config_fn = tavil_get_afe_config; - ret = msm_adsp_power_up_config(codec); + ret = msm_adsp_power_up_config(codec, rtd->card->snd_card); if (ret) { pr_err("%s: Failed to set AFE config %d\n", __func__, ret); goto err; @@ -7046,6 +7059,7 @@ static int msm_asoc_machine_remove(struct platform_device *pdev) struct msm_asoc_mach_data *pdata = snd_soc_card_get_drvdata(card); + audio_notifier_deregister("sdm845"); if (pdata->us_euro_gpio > 0) { gpio_free(pdata->us_euro_gpio); pdata->us_euro_gpio = 0; @@ -7054,7 +7068,6 @@ static int msm_asoc_machine_remove(struct platform_device *pdev) msm_release_pinctrl(pdev); snd_soc_unregister_card(card); - audio_notifier_deregister("sdm845"); return 0; }