Skip to content

Commit 6d174cc

Browse files
Revaliolibroonie
authored andcommitted
ASoC: fsl-asoc-card: merge spdif support from imx-spdif.c
The imx-spdif machine driver creates audio card to directly use an S/PDIF device. However, it doesn't support interacting with an ASRC. fsl-asoc-card already has the support to create audio card which can use the ASRC. Merge the S/PDIF support from imx-spdif into driver fsl-asoc-card to extend the support of S/PDIF audio card with the use of ASRC devices. fsl-asoc-card uses slightly different DT properties than imx-spdif: * the "spdif-controller" property from imx-spdif is named "audio-cpu" in fsl-asoc-card. * fsl-asoc-card uses codecs explicitly declared in DT with "audio-codec". With an SPDIF, codec drivers spdif_transmitter and spdif_receiver should be used. Driver imx-spdif used instead the dummy codec and a pair of boolean properties, "spdif-in" and "spdif-out". To keep backward compatibility, support for "spdif-controller", "spdif-in" and "spdif-out" is also added to fsl-asoc-card. However, it is recommended to use the new properties if possible. It is better to declare transmitter and/or receiver in DT than using the dummy codec. DTs using compatible "fsl,imx-audio-spdif" are still compatible, and fsl-asoc-card will behave the same as imx-spdif for these DTs. Signed-off-by: Elinor Montmasson <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent fcc6ace commit 6d174cc

File tree

6 files changed

+84
-118
lines changed

6 files changed

+84
-118
lines changed

arch/arm/configs/imx_v6_v7_defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,6 @@ CONFIG_SND_IMX_SOC=y
311311
CONFIG_SND_SOC_EUKREA_TLV320=y
312312
CONFIG_SND_SOC_IMX_ES8328=y
313313
CONFIG_SND_SOC_IMX_SGTL5000=y
314-
CONFIG_SND_SOC_IMX_SPDIF=y
315314
CONFIG_SND_SOC_FSL_ASOC_CARD=y
316315
CONFIG_SND_SOC_AC97_CODEC=y
317316
CONFIG_SND_SOC_CS42XX8_I2C=y

arch/arm64/configs/defconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,6 @@ CONFIG_SND_SOC_FSL_MICFIL=m
940940
CONFIG_SND_SOC_FSL_EASRC=m
941941
CONFIG_SND_IMX_SOC=m
942942
CONFIG_SND_SOC_IMX_SGTL5000=m
943-
CONFIG_SND_SOC_IMX_SPDIF=m
944943
CONFIG_SND_SOC_FSL_ASOC_CARD=m
945944
CONFIG_SND_SOC_IMX_AUDMIX=m
946945
CONFIG_SND_SOC_MT8183=m

sound/soc/fsl/Kconfig

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,6 @@ config SND_SOC_IMX_SGTL5000
303303
SND_SOC_FSL_ASOC_CARD and SND_SOC_SGTL5000 to use the newer
304304
driver.
305305

306-
config SND_SOC_IMX_SPDIF
307-
tristate "SoC Audio support for i.MX boards with S/PDIF"
308-
select SND_SOC_IMX_PCM_DMA
309-
select SND_SOC_FSL_SPDIF
310-
help
311-
SoC Audio support for i.MX boards with S/PDIF
312-
Say Y if you want to add support for SoC audio on an i.MX board with
313-
a S/DPDIF.
314-
315306
config SND_SOC_FSL_ASOC_CARD
316307
tristate "Generic ASoC Sound Card with ASRC support"
317308
depends on OF && I2C
@@ -323,6 +314,7 @@ config SND_SOC_FSL_ASOC_CARD
323314
select SND_SOC_FSL_ESAI
324315
select SND_SOC_FSL_SAI
325316
select SND_SOC_FSL_SSI
317+
select SND_SOC_FSL_SPDIF
326318
select SND_SOC_TLV320AIC31XX
327319
select SND_SOC_WM8994
328320
select MFD_WM8994

sound/soc/fsl/Makefile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ obj-$(CONFIG_SND_SOC_IMX_PCM_RPMSG) += imx-pcm-rpmsg.o
6767
snd-soc-eukrea-tlv320-y := eukrea-tlv320.o
6868
snd-soc-imx-es8328-y := imx-es8328.o
6969
snd-soc-imx-sgtl5000-y := imx-sgtl5000.o
70-
snd-soc-imx-spdif-y := imx-spdif.o
7170
snd-soc-imx-audmix-y := imx-audmix.o
7271
snd-soc-imx-hdmi-y := imx-hdmi.o
7372
snd-soc-imx-rpmsg-y := imx-rpmsg.o
@@ -76,7 +75,6 @@ snd-soc-imx-card-y := imx-card.o
7675
obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o
7776
obj-$(CONFIG_SND_SOC_IMX_ES8328) += snd-soc-imx-es8328.o
7877
obj-$(CONFIG_SND_SOC_IMX_SGTL5000) += snd-soc-imx-sgtl5000.o
79-
obj-$(CONFIG_SND_SOC_IMX_SPDIF) += snd-soc-imx-spdif.o
8078
obj-$(CONFIG_SND_SOC_IMX_AUDMIX) += snd-soc-imx-audmix.o
8179
obj-$(CONFIG_SND_SOC_IMX_HDMI) += snd-soc-imx-hdmi.o
8280
obj-$(CONFIG_SND_SOC_IMX_RPMSG) += snd-soc-imx-rpmsg.o

sound/soc/fsl/fsl-asoc-card.c

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,75 @@ static int fsl_asoc_card_audmux_init(struct device_node *np,
477477
return 0;
478478
}
479479

480+
static int fsl_asoc_card_spdif_init(struct device_node *codec_np[],
481+
struct device_node *cpu_np,
482+
const char *codec_dai_name[],
483+
struct fsl_asoc_card_priv *priv)
484+
{
485+
struct device *dev = &priv->pdev->dev;
486+
struct device_node *np = dev->of_node;
487+
488+
if (!of_node_name_eq(cpu_np, "spdif")) {
489+
dev_err(dev, "CPU phandle invalid, should be an SPDIF device\n");
490+
return -EINVAL;
491+
}
492+
493+
priv->dai_link[0].playback_only = true;
494+
priv->dai_link[0].capture_only = true;
495+
496+
for (int i = 0; i < 2; i++) {
497+
if (!codec_np[i])
498+
break;
499+
500+
if (of_device_is_compatible(codec_np[i], "linux,spdif-dit")) {
501+
priv->dai_link[0].capture_only = false;
502+
codec_dai_name[i] = "dit-hifi";
503+
} else if (of_device_is_compatible(codec_np[i], "linux,spdif-dir")) {
504+
priv->dai_link[0].playback_only = false;
505+
codec_dai_name[i] = "dir-hifi";
506+
}
507+
}
508+
509+
// Old SPDIF DT binding
510+
if (!codec_np[0]) {
511+
codec_dai_name[0] = snd_soc_dummy_dlc.dai_name;
512+
if (of_property_read_bool(np, "spdif-out"))
513+
priv->dai_link[0].capture_only = false;
514+
if (of_property_read_bool(np, "spdif-in"))
515+
priv->dai_link[0].playback_only = false;
516+
}
517+
518+
if (priv->dai_link[0].playback_only && priv->dai_link[0].capture_only) {
519+
dev_err(dev, "no enabled S/PDIF DAI link\n");
520+
return -EINVAL;
521+
}
522+
523+
if (priv->dai_link[0].playback_only) {
524+
priv->dai_link[1].dpcm_capture = false;
525+
priv->dai_link[2].dpcm_capture = false;
526+
priv->card.dapm_routes = audio_map_tx;
527+
priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_tx);
528+
} else if (priv->dai_link[0].capture_only) {
529+
priv->dai_link[1].dpcm_playback = false;
530+
priv->dai_link[2].dpcm_playback = false;
531+
priv->card.dapm_routes = audio_map_rx;
532+
priv->card.num_dapm_routes = ARRAY_SIZE(audio_map_rx);
533+
}
534+
535+
// No DAPM routes with old bindings and dummy codec
536+
if (!codec_np[0]) {
537+
priv->card.dapm_routes = NULL;
538+
priv->card.num_dapm_routes = 0;
539+
}
540+
541+
if (codec_np[0] && codec_np[1]) {
542+
priv->dai_link[0].num_codecs = 2;
543+
priv->dai_link[2].num_codecs = 2;
544+
}
545+
546+
return 0;
547+
}
548+
480549
static int hp_jack_event(struct notifier_block *nb, unsigned long event,
481550
void *data)
482551
{
@@ -582,9 +651,11 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
582651
priv->pdev = pdev;
583652

584653
cpu_np = of_parse_phandle(np, "audio-cpu", 0);
585-
/* Give a chance to old DT binding */
654+
/* Give a chance to old DT bindings */
586655
if (!cpu_np)
587656
cpu_np = of_parse_phandle(np, "ssi-controller", 0);
657+
if (!cpu_np)
658+
cpu_np = of_parse_phandle(np, "spdif-controller", 0);
588659
if (!cpu_np) {
589660
dev_err(&pdev->dev, "CPU phandle missing or invalid\n");
590661
ret = -EINVAL;
@@ -748,6 +819,10 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
748819
priv->codec_priv[0].fll_id = WM8904_CLK_FLL;
749820
priv->codec_priv[0].pll_id = WM8904_FLL_MCLK;
750821
priv->dai_fmt |= SND_SOC_DAIFMT_CBP_CFP;
822+
} else if (of_device_is_compatible(np, "fsl,imx-audio-spdif")) {
823+
ret = fsl_asoc_card_spdif_init(codec_np, cpu_np, codec_dai_name, priv);
824+
if (ret)
825+
goto asrc_fail;
751826
} else {
752827
dev_err(&pdev->dev, "unknown Device Tree compatible\n");
753828
ret = -EINVAL;
@@ -797,7 +872,8 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
797872
of_node_put(bitclkprovider);
798873
of_node_put(frameprovider);
799874

800-
if (!fsl_asoc_card_is_ac97(priv) && !codec_dev[0]) {
875+
if (!fsl_asoc_card_is_ac97(priv) && !codec_dev[0]
876+
&& codec_dai_name[0] != snd_soc_dummy_dlc.dai_name) {
801877
dev_dbg(&pdev->dev, "failed to find codec device\n");
802878
ret = -EPROBE_DEFER;
803879
goto asrc_fail;
@@ -862,6 +938,10 @@ static int fsl_asoc_card_probe(struct platform_device *pdev)
862938
codec_comp->dai_name = codec_dai_name[codec_idx];
863939
}
864940

941+
// Old SPDIF DT binding support
942+
if (codec_dai_name[0] == snd_soc_dummy_dlc.dai_name)
943+
priv->dai_link[0].codecs[0].name = snd_soc_dummy_dlc.name;
944+
865945
if (!fsl_asoc_card_is_ac97(priv)) {
866946
for_each_link_codecs((&(priv->dai_link[0])), codec_idx, codec_comp) {
867947
codec_comp->of_node = codec_np[codec_idx];
@@ -992,6 +1072,7 @@ static const struct of_device_id fsl_asoc_card_dt_ids[] = {
9921072
{ .compatible = "fsl,imx-audio-wm8958", },
9931073
{ .compatible = "fsl,imx-audio-nau8822", },
9941074
{ .compatible = "fsl,imx-audio-wm8904", },
1075+
{ .compatible = "fsl,imx-audio-spdif", },
9951076
{}
9961077
};
9971078
MODULE_DEVICE_TABLE(of, fsl_asoc_card_dt_ids);

sound/soc/fsl/imx-spdif.c

Lines changed: 0 additions & 103 deletions
This file was deleted.

0 commit comments

Comments
 (0)