diff options
author | Shengjiu Wang <shengjiu.wang@nxp.com> | 2019-06-03 10:32:38 +0800 |
---|---|---|
committer | Dong Aisheng <aisheng.dong@nxp.com> | 2019-11-25 15:50:54 +0800 |
commit | 134471ab8a51ca18f8a1d3b423105b15e3494492 (patch) | |
tree | 2bfd569b44eac52ea306071175b21965754d7162 | |
parent | b455c78216cbb51481ca618dff82b4fc56e6e4de (diff) |
MLK-21940-6: ASoC: imx-wm8524: Support EASRC in this sound card
Support EASRC in this sound card with FE-BE structure
Signed-off-by: Shengjiu Wang <shengjiu.wang@nxp.com>
Reviewed-by: Daniel Baluta <daniel.baluta@nxp.com>
Reviewed-by: Viorel Suman <viorel.suman@nxp.com>
-rw-r--r-- | sound/soc/fsl/imx-wm8524.c | 112 |
1 files changed, 99 insertions, 13 deletions
diff --git a/sound/soc/fsl/imx-wm8524.c b/sound/soc/fsl/imx-wm8524.c index 59978a6a80be..a35b90e94f17 100644 --- a/sound/soc/fsl/imx-wm8524.c +++ b/sound/soc/fsl/imx-wm8524.c @@ -24,10 +24,14 @@ #include <linux/mfd/syscon.h> struct imx_priv { + struct snd_soc_dai_link dai[3]; struct platform_device *pdev; + struct platform_device *asrc_pdev; struct snd_soc_card card; struct clk *codec_clk; unsigned int clk_frequency; + u32 asrc_rate; + u32 asrc_format; }; static const struct snd_soc_dapm_widget imx_wm8524_dapm_widgets[] = { @@ -69,15 +73,35 @@ static struct snd_soc_ops imx_hifi_ops = { .hw_params = imx_hifi_hw_params, }; -static struct snd_soc_dai_link imx_wm8524_dai[] = { - { - .name = "HiFi", - .stream_name = "HiFi", - .codec_dai_name = "wm8524-hifi", - .ops = &imx_hifi_ops, - }, +static const struct snd_soc_dapm_route audio_map[] = { + {"Playback", NULL, "CPU-Playback"}, + {"CPU-Capture", NULL, "Capture"}, + {"CPU-Playback", NULL, "ASRC-Playback"}, + {"ASRC-Capture", NULL, "CPU-Capture"}, }; +static int be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, + struct snd_pcm_hw_params *params) +{ + struct snd_soc_card *card = rtd->card; + struct imx_priv *priv = snd_soc_card_get_drvdata(card); + struct snd_interval *rate; + struct snd_mask *mask; + + if (!priv->asrc_pdev) + return -EINVAL; + + rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); + rate->max = priv->asrc_rate; + rate->min = priv->asrc_rate; + + mask = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); + snd_mask_none(mask); + snd_mask_set(mask, priv->asrc_format); + + return 0; +} + static int imx_wm8524_late_probe(struct snd_soc_card *card) { struct snd_soc_pcm_runtime *rtd = list_first_entry( @@ -97,10 +121,13 @@ static int imx_wm8524_late_probe(struct snd_soc_card *card) static int imx_wm8524_probe(struct platform_device *pdev) { struct device_node *cpu_np, *codec_np = NULL; + struct device_node *asrc_np = NULL; + struct platform_device *asrc_pdev = NULL; struct platform_device *cpu_pdev; struct imx_priv *priv; struct platform_device *codec_pdev = NULL; int ret; + u32 width; priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); if (!priv) @@ -122,6 +149,12 @@ static int imx_wm8524_probe(struct platform_device *pdev) goto fail; } + asrc_np = of_parse_phandle(pdev->dev.of_node, "asrc-controller", 0); + if (asrc_np) { + asrc_pdev = of_find_device_by_node(asrc_np); + priv->asrc_pdev = asrc_pdev; + } + cpu_pdev = of_find_device_by_node(cpu_np); if (!cpu_pdev) { dev_err(&pdev->dev, "failed to find SAI platform device\n"); @@ -143,12 +176,14 @@ static int imx_wm8524_probe(struct platform_device *pdev) goto fail; } - priv->card.dai_link = imx_wm8524_dai; - - imx_wm8524_dai[0].codec_of_node = codec_np; - imx_wm8524_dai[0].cpu_dai_name = dev_name(&cpu_pdev->dev); - imx_wm8524_dai[0].platform_of_node = cpu_np; - imx_wm8524_dai[0].playback_only = 1; + priv->dai[0].name = "HiFi"; + priv->dai[0].stream_name = "HiFi"; + priv->dai[0].codec_dai_name = "wm8524-hifi", + priv->dai[0].ops = &imx_hifi_ops, + priv->dai[0].codec_of_node = codec_np; + priv->dai[0].cpu_dai_name = dev_name(&cpu_pdev->dev); + priv->dai[0].platform_of_node = cpu_np; + priv->dai[0].playback_only = 1; priv->card.late_probe = imx_wm8524_late_probe; priv->card.num_links = 1; @@ -156,6 +191,57 @@ static int imx_wm8524_probe(struct platform_device *pdev) priv->card.owner = THIS_MODULE; priv->card.dapm_widgets = imx_wm8524_dapm_widgets; priv->card.num_dapm_widgets = ARRAY_SIZE(imx_wm8524_dapm_widgets); + priv->card.dai_link = priv->dai; + priv->card.dapm_routes = audio_map; + priv->card.num_dapm_routes = 2; + + /*if there is no asrc controller, we only enable one device*/ + if (asrc_pdev) { + priv->dai[1].name = "HiFi-ASRC-FE"; + priv->dai[1].stream_name = "HiFi-ASRC-FE"; + priv->dai[1].codec_dai_name = "snd-soc-dummy-dai"; + priv->dai[1].codec_name = "snd-soc-dummy"; + priv->dai[1].cpu_of_node = asrc_np; + priv->dai[1].platform_of_node = asrc_np; + priv->dai[1].dynamic = 1; + priv->dai[1].dpcm_playback = 1; + priv->dai[1].dpcm_capture = 0; + + priv->dai[2].name = "HiFi-ASRC-BE"; + priv->dai[2].stream_name = "HiFi-ASRC-BE"; + priv->dai[2].codec_dai_name = "wm8524-hifi"; + priv->dai[2].codec_of_node = codec_np; + priv->dai[2].cpu_of_node = cpu_np; + priv->dai[2].platform_name = "snd-soc-dummy"; + priv->dai[2].no_pcm = 1; + priv->dai[2].dpcm_playback = 1; + priv->dai[2].dpcm_capture = 0; + priv->dai[2].ops = &imx_hifi_ops, + priv->dai[2].be_hw_params_fixup = be_hw_params_fixup, + priv->card.num_links = 3; + priv->card.dai_link = &priv->dai[0]; + priv->card.num_dapm_routes += 2; + + ret = of_property_read_u32(asrc_np, "fsl,asrc-rate", + &priv->asrc_rate); + if (ret) { + dev_err(&pdev->dev, "failed to get output rate\n"); + ret = -EINVAL; + goto fail; + } + + ret = of_property_read_u32(asrc_np, "fsl,asrc-width", &width); + if (ret) { + dev_err(&pdev->dev, "failed to get output rate\n"); + ret = -EINVAL; + goto fail; + } + + if (width == 24) + priv->asrc_format = SNDRV_PCM_FORMAT_S24_LE; + else + priv->asrc_format = SNDRV_PCM_FORMAT_S16_LE; + } ret = snd_soc_of_parse_card_name(&priv->card, "model"); if (ret) |