Commit 54e49a3c authored by Mark Brown's avatar Mark Brown

ASoC: fsl-asoc-card: add S/PDIF controller support

Merge series from Elinor Montmasson <elinor.montmasson@savoirfairelinux.com>:

This is a series of patches aiming to make the machine driver
`fsl-asoc-card` compatible with S/PDIF controllers on imx boards.  The
main goal is to allow the use of S/PDIF controllers with ASRC modules.

The `imx-spdif` machine driver already has specific support for S/PDIF
controllers but doesn't support using an ASRC with it. However, the
`fsl-asoc-card` machine driver has the necessary code to create a sound
card which can use an ASRC module.
It is then possible to extend the support for S/PDIF audio cards by
merging the `imx-spdif` driver into `fsl-asoc-card`.

The first three patches adapt the `fsl-asoc-card` driver to support
multiple codec use cases.
The driver can get 2 codec phandles from the device tree, and
codec-related variables are doubled.
`for_each_codecs` macros are also used when possible to ease adding
other multi-codec use cases in the future.
It makes possible to use the two S/PDIF dummy codec drivers
`spdif_receiver` and `spdif_transmitter` instead of `snd-soc-dummy`,
which was used in `imx-spdif`.

The fourth patch merges the S/PDIF support from `imx-spdif` to
`fsl-asoc-card`.
`fsl-asoc-card` offers the same functionalities as `imx-spdif` did, but
this merge also extends the S/PDIF support with the possibility of using
an ASRC.
Compatible "fsl,imx-audio-spdif" is kept, but `fsl-asoc-card` uses
different DT properties compared to `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 S/PDIF, 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".
Backward compatibility is therefore implemented in `fsl-asoc-card`.
However, it is recommended to use the new properties when needed.
Especially, declaring and using S/PDIF transmitter and/or receiver nodes
is better than using the dummy codec.

The last three patches update the device tree bindings of
`fsl-asoc-card` and update all in-tree device trees to use the
`fsl-asoc-card` properties.
Note that as the old properties are still supported:
* previous versions of in-tree device trees are still supported.
* out-of-tree device trees are still supported.

This series of patches was successfully built for arm64 and x86 on top
of the latest "for-next" branch of the ASoC git tree on the 26th of June
2024.
These modifications have also been tested on an i.MX8MN evaluation board
with a linux kernel RT v6.1.26-rt8.
parents 0c6c6511 4359caad
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
%YAML 1.2
---
$id: http://devicetree.org/schemas/sound/fsl,imx-audio-spdif.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
title: Freescale i.MX audio complex with S/PDIF transceiver
maintainers:
- Shengjiu Wang <shengjiu.wang@nxp.com>
properties:
compatible:
oneOf:
- items:
- enum:
- fsl,imx-sabreauto-spdif
- fsl,imx6sx-sdb-spdif
- const: fsl,imx-audio-spdif
- enum:
- fsl,imx-audio-spdif
model:
$ref: /schemas/types.yaml#/definitions/string
description: User specified audio sound card name
spdif-controller:
$ref: /schemas/types.yaml#/definitions/phandle
description: The phandle of the i.MX S/PDIF controller
spdif-out:
type: boolean
description:
If present, the transmitting function of S/PDIF will be enabled,
indicating there's a physical S/PDIF out connector or jack on the
board or it's connecting to some other IP block, such as an HDMI
encoder or display-controller.
spdif-in:
type: boolean
description:
If present, the receiving function of S/PDIF will be enabled,
indicating there is a physical S/PDIF in connector/jack on the board.
required:
- compatible
- model
- spdif-controller
anyOf:
- required:
- spdif-in
- required:
- spdif-out
additionalProperties: false
examples:
- |
sound-spdif {
compatible = "fsl,imx-audio-spdif";
model = "imx-spdif";
spdif-controller = <&spdif>;
spdif-out;
spdif-in;
};
...@@ -65,6 +65,11 @@ properties: ...@@ -65,6 +65,11 @@ properties:
- fsl,imx-audio-sgtl5000 - fsl,imx-audio-sgtl5000
- fsl,imx-audio-wm8960 - fsl,imx-audio-wm8960
- fsl,imx-audio-wm8962 - fsl,imx-audio-wm8962
- items:
- enum:
- fsl,imx-sabreauto-spdif
- fsl,imx6sx-sdb-spdif
- const: fsl,imx-audio-spdif
- items: - items:
- enum: - enum:
- fsl,imx-audio-ac97 - fsl,imx-audio-ac97
...@@ -81,6 +86,7 @@ properties: ...@@ -81,6 +86,7 @@ properties:
- fsl,imx-audio-wm8960 - fsl,imx-audio-wm8960
- fsl,imx-audio-wm8962 - fsl,imx-audio-wm8962
- fsl,imx-audio-wm8958 - fsl,imx-audio-wm8958
- fsl,imx-audio-spdif
model: model:
$ref: /schemas/types.yaml#/definitions/string $ref: /schemas/types.yaml#/definitions/string
...@@ -93,8 +99,15 @@ properties: ...@@ -93,8 +99,15 @@ properties:
need to add ASRC support via DPCM. need to add ASRC support via DPCM.
audio-codec: audio-codec:
$ref: /schemas/types.yaml#/definitions/phandle $ref: /schemas/types.yaml#/definitions/phandle-array
description: The phandle of an audio codec description: |
The phandle of an audio codec.
With "fsl,imx-audio-spdif", either SPDIF audio codec spdif_transmitter,
spdif_receiver or both.
minItems: 1
maxItems: 2
items:
maxItems: 1
audio-cpu: audio-cpu:
$ref: /schemas/types.yaml#/definitions/phandle $ref: /schemas/types.yaml#/definitions/phandle
...@@ -150,8 +163,10 @@ properties: ...@@ -150,8 +163,10 @@ properties:
description: dai-link uses bit clock inversion. description: dai-link uses bit clock inversion.
mclk-id: mclk-id:
$ref: /schemas/types.yaml#/definitions/uint32 $ref: /schemas/types.yaml#/definitions/uint32-array
description: main clock id, specific for each card configuration. description: Main clock id for each codec, specific for each card configuration.
minItems: 1
maxItems: 2
mux-int-port: mux-int-port:
$ref: /schemas/types.yaml#/definitions/uint32 $ref: /schemas/types.yaml#/definitions/uint32
...@@ -167,6 +182,27 @@ properties: ...@@ -167,6 +182,27 @@ properties:
$ref: /schemas/types.yaml#/definitions/phandle $ref: /schemas/types.yaml#/definitions/phandle
description: The phandle of an CPU DAI controller description: The phandle of an CPU DAI controller
spdif-controller:
$ref: /schemas/types.yaml#/definitions/phandle
deprecated: true
description: The phandle of an S/PDIF CPU DAI controller.
spdif-out:
type: boolean
deprecated: true
description: |
If present, the transmitting function of S/PDIF will be enabled,
indicating there's a physical S/PDIF out connector or jack on the
board or it's connecting to some other IP block, such as an HDMI
encoder or display-controller.
spdif-in:
type: boolean
deprecated: true
description: |
If present, the receiving function of S/PDIF will be enabled,
indicating there is a physical S/PDIF in connector/jack on the board.
required: required:
- compatible - compatible
- model - model
...@@ -195,3 +231,12 @@ examples: ...@@ -195,3 +231,12 @@ examples:
"AIN2L", "Line In Jack", "AIN2L", "Line In Jack",
"AIN2R", "Line In Jack"; "AIN2R", "Line In Jack";
}; };
- |
sound-spdif-asrc {
compatible = "fsl,imx-audio-spdif";
model = "spdif-asrc-audio";
audio-cpu = <&spdif>;
audio-asrc = <&easrc>;
audio-codec = <&spdifdit>, <&spdifdir>;
};
...@@ -311,7 +311,6 @@ CONFIG_SND_IMX_SOC=y ...@@ -311,7 +311,6 @@ CONFIG_SND_IMX_SOC=y
CONFIG_SND_SOC_EUKREA_TLV320=y CONFIG_SND_SOC_EUKREA_TLV320=y
CONFIG_SND_SOC_IMX_ES8328=y CONFIG_SND_SOC_IMX_ES8328=y
CONFIG_SND_SOC_IMX_SGTL5000=y CONFIG_SND_SOC_IMX_SGTL5000=y
CONFIG_SND_SOC_IMX_SPDIF=y
CONFIG_SND_SOC_FSL_ASOC_CARD=y CONFIG_SND_SOC_FSL_ASOC_CARD=y
CONFIG_SND_SOC_AC97_CODEC=y CONFIG_SND_SOC_AC97_CODEC=y
CONFIG_SND_SOC_CS42XX8_I2C=y CONFIG_SND_SOC_CS42XX8_I2C=y
......
...@@ -940,7 +940,6 @@ CONFIG_SND_SOC_FSL_MICFIL=m ...@@ -940,7 +940,6 @@ CONFIG_SND_SOC_FSL_MICFIL=m
CONFIG_SND_SOC_FSL_EASRC=m CONFIG_SND_SOC_FSL_EASRC=m
CONFIG_SND_IMX_SOC=m CONFIG_SND_IMX_SOC=m
CONFIG_SND_SOC_IMX_SGTL5000=m CONFIG_SND_SOC_IMX_SGTL5000=m
CONFIG_SND_SOC_IMX_SPDIF=m
CONFIG_SND_SOC_FSL_ASOC_CARD=m CONFIG_SND_SOC_FSL_ASOC_CARD=m
CONFIG_SND_SOC_IMX_AUDMIX=m CONFIG_SND_SOC_IMX_AUDMIX=m
CONFIG_SND_SOC_MT8183=m CONFIG_SND_SOC_MT8183=m
......
...@@ -303,15 +303,6 @@ config SND_SOC_IMX_SGTL5000 ...@@ -303,15 +303,6 @@ config SND_SOC_IMX_SGTL5000
SND_SOC_FSL_ASOC_CARD and SND_SOC_SGTL5000 to use the newer SND_SOC_FSL_ASOC_CARD and SND_SOC_SGTL5000 to use the newer
driver. driver.
config SND_SOC_IMX_SPDIF
tristate "SoC Audio support for i.MX boards with S/PDIF"
select SND_SOC_IMX_PCM_DMA
select SND_SOC_FSL_SPDIF
help
SoC Audio support for i.MX boards with S/PDIF
Say Y if you want to add support for SoC audio on an i.MX board with
a S/DPDIF.
config SND_SOC_FSL_ASOC_CARD config SND_SOC_FSL_ASOC_CARD
tristate "Generic ASoC Sound Card with ASRC support" tristate "Generic ASoC Sound Card with ASRC support"
depends on OF && I2C depends on OF && I2C
...@@ -323,6 +314,7 @@ config SND_SOC_FSL_ASOC_CARD ...@@ -323,6 +314,7 @@ config SND_SOC_FSL_ASOC_CARD
select SND_SOC_FSL_ESAI select SND_SOC_FSL_ESAI
select SND_SOC_FSL_SAI select SND_SOC_FSL_SAI
select SND_SOC_FSL_SSI select SND_SOC_FSL_SSI
select SND_SOC_FSL_SPDIF
select SND_SOC_TLV320AIC31XX select SND_SOC_TLV320AIC31XX
select SND_SOC_WM8994 select SND_SOC_WM8994
select MFD_WM8994 select MFD_WM8994
......
...@@ -67,7 +67,6 @@ obj-$(CONFIG_SND_SOC_IMX_PCM_RPMSG) += imx-pcm-rpmsg.o ...@@ -67,7 +67,6 @@ obj-$(CONFIG_SND_SOC_IMX_PCM_RPMSG) += imx-pcm-rpmsg.o
snd-soc-eukrea-tlv320-y := eukrea-tlv320.o snd-soc-eukrea-tlv320-y := eukrea-tlv320.o
snd-soc-imx-es8328-y := imx-es8328.o snd-soc-imx-es8328-y := imx-es8328.o
snd-soc-imx-sgtl5000-y := imx-sgtl5000.o snd-soc-imx-sgtl5000-y := imx-sgtl5000.o
snd-soc-imx-spdif-y := imx-spdif.o
snd-soc-imx-audmix-y := imx-audmix.o snd-soc-imx-audmix-y := imx-audmix.o
snd-soc-imx-hdmi-y := imx-hdmi.o snd-soc-imx-hdmi-y := imx-hdmi.o
snd-soc-imx-rpmsg-y := imx-rpmsg.o snd-soc-imx-rpmsg-y := imx-rpmsg.o
...@@ -76,7 +75,6 @@ snd-soc-imx-card-y := imx-card.o ...@@ -76,7 +75,6 @@ snd-soc-imx-card-y := imx-card.o
obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o obj-$(CONFIG_SND_SOC_EUKREA_TLV320) += snd-soc-eukrea-tlv320.o
obj-$(CONFIG_SND_SOC_IMX_ES8328) += snd-soc-imx-es8328.o obj-$(CONFIG_SND_SOC_IMX_ES8328) += snd-soc-imx-es8328.o
obj-$(CONFIG_SND_SOC_IMX_SGTL5000) += snd-soc-imx-sgtl5000.o obj-$(CONFIG_SND_SOC_IMX_SGTL5000) += snd-soc-imx-sgtl5000.o
obj-$(CONFIG_SND_SOC_IMX_SPDIF) += snd-soc-imx-spdif.o
obj-$(CONFIG_SND_SOC_IMX_AUDMIX) += snd-soc-imx-audmix.o obj-$(CONFIG_SND_SOC_IMX_AUDMIX) += snd-soc-imx-audmix.o
obj-$(CONFIG_SND_SOC_IMX_HDMI) += snd-soc-imx-hdmi.o obj-$(CONFIG_SND_SOC_IMX_HDMI) += snd-soc-imx-hdmi.o
obj-$(CONFIG_SND_SOC_IMX_RPMSG) += snd-soc-imx-rpmsg.o obj-$(CONFIG_SND_SOC_IMX_RPMSG) += snd-soc-imx-rpmsg.o
......
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0+
//
// Copyright (C) 2013 Freescale Semiconductor, Inc.
#include <linux/module.h>
#include <linux/of_platform.h>
#include <sound/soc.h>
struct imx_spdif_data {
struct snd_soc_dai_link dai;
struct snd_soc_card card;
};
static int imx_spdif_audio_probe(struct platform_device *pdev)
{
struct device_node *spdif_np, *np = pdev->dev.of_node;
struct imx_spdif_data *data;
struct snd_soc_dai_link_component *comp;
int ret = 0;
spdif_np = of_parse_phandle(np, "spdif-controller", 0);
if (!spdif_np) {
dev_err(&pdev->dev, "failed to find spdif-controller\n");
ret = -EINVAL;
goto end;
}
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
comp = devm_kzalloc(&pdev->dev, sizeof(*comp), GFP_KERNEL);
if (!data || !comp) {
ret = -ENOMEM;
goto end;
}
/*
* CPU == Platform
* platform is using soc-generic-dmaengine-pcm
*/
data->dai.cpus =
data->dai.platforms = comp;
data->dai.codecs = &snd_soc_dummy_dlc;
data->dai.num_cpus = 1;
data->dai.num_codecs = 1;
data->dai.num_platforms = 1;
data->dai.name = "S/PDIF PCM";
data->dai.stream_name = "S/PDIF PCM";
data->dai.cpus->of_node = spdif_np;
data->dai.playback_only = true;
data->dai.capture_only = true;
if (of_property_read_bool(np, "spdif-out"))
data->dai.capture_only = false;
if (of_property_read_bool(np, "spdif-in"))
data->dai.playback_only = false;
if (data->dai.playback_only && data->dai.capture_only) {
dev_err(&pdev->dev, "no enabled S/PDIF DAI link\n");
goto end;
}
data->card.dev = &pdev->dev;
data->card.dai_link = &data->dai;
data->card.num_links = 1;
data->card.owner = THIS_MODULE;
ret = snd_soc_of_parse_card_name(&data->card, "model");
if (ret)
goto end;
ret = devm_snd_soc_register_card(&pdev->dev, &data->card);
if (ret)
dev_err_probe(&pdev->dev, ret, "snd_soc_register_card failed\n");
end:
of_node_put(spdif_np);
return ret;
}
static const struct of_device_id imx_spdif_dt_ids[] = {
{ .compatible = "fsl,imx-audio-spdif", },
{ /* sentinel */ }
};
MODULE_DEVICE_TABLE(of, imx_spdif_dt_ids);
static struct platform_driver imx_spdif_driver = {
.driver = {
.name = "imx-spdif",
.pm = &snd_soc_pm_ops,
.of_match_table = imx_spdif_dt_ids,
},
.probe = imx_spdif_audio_probe,
};
module_platform_driver(imx_spdif_driver);
MODULE_AUTHOR("Freescale Semiconductor, Inc.");
MODULE_DESCRIPTION("Freescale i.MX S/PDIF machine driver");
MODULE_LICENSE("GPL v2");
MODULE_ALIAS("platform:imx-spdif");
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment