From 4043ecf9ee6949b43a81bef20aa97de72f9a8718 Mon Sep 17 00:00:00 2001 From: Bard liao Date: Mon, 25 Mar 2019 09:57:41 +0800 Subject: [PATCH 1/3] ASoC: intel: sof_rt5682: use modern representation in dailinks Use .codecs and .num_codecs instead of .codec_name and .codec_dai_name Signed-off-by: Bard liao --- sound/soc/intel/boards/sof_rt5682.c | 38 +++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/sound/soc/intel/boards/sof_rt5682.c b/sound/soc/intel/boards/sof_rt5682.c index 99735cc247c02f..0454741807bcfa 100644 --- a/sound/soc/intel/boards/sof_rt5682.c +++ b/sound/soc/intel/boards/sof_rt5682.c @@ -285,11 +285,26 @@ static const struct x86_cpu_id legacy_cpi_ids[] = { {} }; +static struct snd_soc_dai_link_component rt5682_component[] = { + { + .name = "i2c-10EC5682:00", + .dai_name = "rt5682-aif1", + } +}; + +static struct snd_soc_dai_link_component dmic_component[] = { + { + .name = "dmic-codec", + .dai_name = "dmic-hifi", + } +}; + static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, int ssp_port, int dmic_num, int hdmi_num) { + struct snd_soc_dai_link_component *idisp_components; struct snd_soc_dai_link *links; int i, id = 0; @@ -299,8 +314,8 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port); links[id].id = id; - links[id].codec_name = "i2c-10EC5682:00"; - links[id].codec_dai_name = "rt5682-aif1"; + links[id].codecs = rt5682_component; + links[id].num_codecs = ARRAY_SIZE(rt5682_component); links[id].platforms = platform_component; links[id].num_platforms = ARRAY_SIZE(platform_component); links[id].init = sof_rt5682_codec_init; @@ -325,8 +340,8 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, links[id].id = id; links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "DMIC%02d Pin", i); - links[id].codec_name = "dmic-codec"; - links[id].codec_dai_name = "dmic-hifi"; + links[id].codecs = dmic_component; + links[id].num_codecs = ARRAY_SIZE(dmic_component); links[id].platforms = platform_component; links[id].num_platforms = ARRAY_SIZE(platform_component); links[id].ignore_suspend = 1; @@ -336,16 +351,23 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, } /* HDMI */ + if (hdmi_num > 0) { + idisp_components = devm_kzalloc(dev, + sizeof(struct snd_soc_dai_link_component) * + hdmi_num, GFP_KERNEL); + } for (i = 1; i <= hdmi_num; i++) { links[id].name = devm_kasprintf(dev, GFP_KERNEL, "iDisp%d", i); links[id].id = id; links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "iDisp%d Pin", i); - links[id].codec_name = "ehdaudio0D2"; - links[id].codec_dai_name = devm_kasprintf(dev, GFP_KERNEL, - "intel-hdmi-hifi%d", - i); + idisp_components[i-1].name = "ehdaudio0D2"; + idisp_components[i-1].dai_name = devm_kasprintf(dev, GFP_KERNEL, + "intel-hdmi-" + "hifi%d", i); + links[id].codecs = &idisp_components[i-1]; + links[id].num_codecs = 1; links[id].platforms = platform_component; links[id].num_platforms = ARRAY_SIZE(platform_component); links[id].init = sof_hdmi_init; From 7a4c4ae5a58317f592ed3af48813b0988d4249a5 Mon Sep 17 00:00:00 2001 From: Bard liao Date: Mon, 25 Mar 2019 10:26:57 +0800 Subject: [PATCH 2/3] ASoC: intel: sof_rt5682: set ignore_pmdown_time to rt5682 dai link Currently, On CKL+ platforms MCLK will be turned off in sof runtime suspended, and it will go into runtime suspended right after playback is stop. However, rt5682 will output static noise if sysclk turns off during playback. Set ignore_pmdown_time to power down rt5682 immediately and avoid the noise. It can be removed once we can control MCLK by driver. Signed-off-by: Bard liao --- sound/soc/intel/boards/sof_rt5682.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sound/soc/intel/boards/sof_rt5682.c b/sound/soc/intel/boards/sof_rt5682.c index 0454741807bcfa..da7e6f69e98b69 100644 --- a/sound/soc/intel/boards/sof_rt5682.c +++ b/sound/soc/intel/boards/sof_rt5682.c @@ -328,6 +328,16 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "ssp%d-port", ssp_port); } else { + /* + * Currently, On SKL+ platforms MCLK will be turned off in sof + * runtime suspended, and it will go into runtime suspended + * right after playback is stop. However, rt5682 will output + * static noise if sysclk turns off during playback. Set + * ignore_pmdown_time to power down rt5682 immediately and + * avoid the noise. + * It can be removed once we can control MCLK by driver. + */ + links[id].ignore_pmdown_time = 1; links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port); } From 0eeaa9541ceb79577df838f5e1381387db474cdd Mon Sep 17 00:00:00 2001 From: Bard liao Date: Tue, 26 Mar 2019 09:30:54 +0800 Subject: [PATCH 3/3] ASoC: Intel: sof_rt5682: test devm_ and return -ENOMEM test all devm_ based memory allocation function and return -ENOMEM if it is failed. Signed-off-by: Bard liao --- sound/soc/intel/boards/sof_rt5682.c | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sound/soc/intel/boards/sof_rt5682.c b/sound/soc/intel/boards/sof_rt5682.c index da7e6f69e98b69..007cf94c0d5d73 100644 --- a/sound/soc/intel/boards/sof_rt5682.c +++ b/sound/soc/intel/boards/sof_rt5682.c @@ -310,9 +310,15 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) * (1 + dmic_num + hdmi_num), GFP_KERNEL); + if (!links) + goto devm_err; + /* SSP */ links[id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_port); + if (!links[id].name) + goto devm_err; + links[id].id = id; links[id].codecs = rt5682_component; links[id].num_codecs = ARRAY_SIZE(rt5682_component); @@ -327,6 +333,8 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, if (is_legacy_cpu) { links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "ssp%d-port", ssp_port); + if (!links[id].cpu_dai_name) + goto devm_err; } else { /* * Currently, On SKL+ platforms MCLK will be turned off in sof @@ -340,6 +348,8 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, links[id].ignore_pmdown_time = 1; links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_port); + if (!links[id].cpu_dai_name) + goto devm_err; } id++; @@ -347,9 +357,15 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, for (i = 1; i <= dmic_num; i++) { links[id].name = devm_kasprintf(dev, GFP_KERNEL, "dmic%02d", i); + if (!links[id].name) + goto devm_err; + links[id].id = id; links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "DMIC%02d Pin", i); + if (!links[id].cpu_dai_name) + goto devm_err; + links[id].codecs = dmic_component; links[id].num_codecs = ARRAY_SIZE(dmic_component); links[id].platforms = platform_component; @@ -365,17 +381,28 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, idisp_components = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component) * hdmi_num, GFP_KERNEL); + if (!idisp_components) + goto devm_err; } for (i = 1; i <= hdmi_num; i++) { links[id].name = devm_kasprintf(dev, GFP_KERNEL, "iDisp%d", i); + if (!links[id].name) + goto devm_err; + links[id].id = id; links[id].cpu_dai_name = devm_kasprintf(dev, GFP_KERNEL, "iDisp%d Pin", i); + if (!links[id].cpu_dai_name) + goto devm_err; + idisp_components[i-1].name = "ehdaudio0D2"; idisp_components[i-1].dai_name = devm_kasprintf(dev, GFP_KERNEL, "intel-hdmi-" "hifi%d", i); + if (!idisp_components[i-1].dai_name) + goto devm_err; + links[id].codecs = &idisp_components[i-1]; links[id].num_codecs = 1; links[id].platforms = platform_component; @@ -387,6 +414,9 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev, } return links; + +devm_err: + return NULL; } static int sof_audio_probe(struct platform_device *pdev) @@ -420,6 +450,9 @@ static int sof_audio_probe(struct platform_device *pdev) dai_links = sof_card_dai_links_create(&pdev->dev, sof_rt5682_quirk & SOF_RT5682_SSP_MASK, dmic_num, hdmi_num); + if (!dai_links) + return -ENOMEM; + sof_audio_card_rt5682.dai_link = dai_links; sof_audio_card_rt5682.num_links = 1 + dmic_num + hdmi_num;