From 039d56b817071a326574fdbfe7758ebdaf9cc49e Mon Sep 17 00:00:00 2001
From: Shengjiu Wang <shengjiu.wang@nxp.com>
Date: Thu, 11 Oct 2018 18:00:08 +0800
Subject: [PATCH] MLK-19854-1: ASoC: imx-wm8960: fix error when m4 image is not
 loaded

With rpmsg sound, when the m4 image is not loaded. There is error log

[ 46.275223] imx-wm8960 sound-rpmsg-wm8960: ASoC: CODEC DAI rpmsg-wm8960-hifi not registered
[ 46.284543] imx-wm8960 sound-rpmsg-wm8960: snd_soc_register_card failed (-517)

The issue is caused by that codec is not registered, the sound
card registration will fail

So add check in probe function for codec dai is ready or not.

Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
(cherry picked from commit 6fab38509647529c165bb610b8a7996d6ad16307)
Signed-off-by: Vipul Kumar <vipul_kumar@mentor.com>
Signed-off-by: Srikanth Krishnakar <Srikanth_Krishnakar@mentor.com>
---
 sound/soc/fsl/imx-wm8960.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sound/soc/fsl/imx-wm8960.c b/sound/soc/fsl/imx-wm8960.c
index 39f69085f802d6..6b354c7e16dc37 100644
--- a/sound/soc/fsl/imx-wm8960.c
+++ b/sound/soc/fsl/imx-wm8960.c
@@ -448,6 +448,8 @@ static int imx_wm8960_probe(struct platform_device *pdev)
 	struct imx_wm8960_data *data;
 	struct platform_device *asrc_pdev = NULL;
 	struct device_node *asrc_np;
+	struct snd_soc_dai_link_component dlc = { 0 };
+	struct snd_soc_dai *codec_dai;
 	u32 width;
 	int ret;
 
@@ -537,6 +539,12 @@ static int imx_wm8960_probe(struct platform_device *pdev)
 	if (data->is_codec_rpmsg) {
 		imx_wm8960_dai[0].codec_name     = "rpmsg-audio-codec-wm8960";
 		imx_wm8960_dai[0].codec_dai_name = "rpmsg-wm8960-hifi";
+
+		dlc.name = "rpmsg-audio-codec-wm8960";
+		dlc.dai_name = "rpmsg-wm8960-hifi";
+		codec_dai = snd_soc_find_dai(&dlc);
+		if (!codec_dai)
+			return -ENODEV;
 	} else
 		imx_wm8960_dai[0].codec_of_node	= codec_np;
 
-- 
GitLab