Re: [PATCH] ASoC: codecs: dmic: Make number of channels configurable

From: Arnaud Pouliquen
Date: Tue Jan 09 2018 - 04:06:36 EST


Hello Mathias,

Next time could you add patch version in your mail subject ( [PATCH vX])
easier to follow versions :-).

otherwise,

Acked-by: Arnaud Pouliquen <arnaud.pouliquen@xxxxxx>

Regards,
Arnaud

On 01/05/2018 09:39 PM, Matthias Kaehlcke wrote:
> The DMIC DAI driver specifies a number of 1 to 8 channels for each DAI.
> The actual number of mics can currently not be configured in the device
> tree or audio glue, but is derived from the min/max channels of the CPU
> and codec DAI. A typical CPU DAI has two or more channels, in consequence
> a single mic is treated as a stereo/multi channel device, even though
> only one channel carries audio data.
>
> This change adds the option to specify the number of used DMIC channels
> in the device tree. When specified this value overwrites the default
> channels_max value of 8 in the snd_soc_dai_driver struct of the codec.
>
> Signed-off-by: Matthias Kaehlcke <mka@xxxxxxxxxxxx>
> ---
> ÂDocumentation/devicetree/bindings/sound/dmic.txt |Â 2 ++
> Âsound/soc/codecs/dmic.cÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ | 24
> +++++++++++++++++++++++-
> Â2 files changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/Documentation/devicetree/bindings/sound/dmic.txt
> b/Documentation/devicetree/bindings/sound/dmic.txt
> index 54c8ef6498a8..f7bf65611453 100644
> --- a/Documentation/devicetree/bindings/sound/dmic.txt
> +++ b/Documentation/devicetree/bindings/sound/dmic.txt
> @@ -7,10 +7,12 @@ Required properties:
> Â
> ÂOptional properties:
> ÂÂÂÂÂÂÂÂ - dmicen-gpios: GPIO specifier for dmic to control start and stop
> +ÂÂÂÂÂÂ - num-channels: Number of microphones on this DAI
> Â
> ÂExample node:
> Â
> ÂÂÂÂÂÂÂÂ dmic_codec: dmic@0 {
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ compatible = "dmic-codec";
> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dmicen-gpios = <&gpio4 3 GPIO_ACTIVE_HIGH>;
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ num-channels = <1>;
> ÂÂÂÂÂÂÂÂ };
> diff --git a/sound/soc/codecs/dmic.c b/sound/soc/codecs/dmic.c
> index b88a1ee66f80..c88f974ebe3e 100644
> --- a/sound/soc/codecs/dmic.c
> +++ b/sound/soc/codecs/dmic.c
> @@ -107,8 +107,30 @@ static const struct snd_soc_codec_driver soc_dmic = {
> Â
> Âstatic int dmic_dev_probe(struct platform_device *pdev)
> Â{
> +ÂÂÂÂÂÂ int err;
> +ÂÂÂÂÂÂ u32 chans;
> +ÂÂÂÂÂÂ struct snd_soc_dai_driver *dai_drv = &dmic_dai;
> +
> +ÂÂÂÂÂÂ if (pdev->dev.of_node) {
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ err = of_property_read_u32(pdev->dev.of_node,
> "num-channels", &chans);
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (err && (err != -ENOENT))
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return err;
> +
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (!err) {
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (chans < 1 || chans > 8)
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return -EINVAL;
> +
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dai_drv = devm_kzalloc(&pdev->dev,
> sizeof(*dai_drv), GFP_KERNEL);
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ if (!dai_drv)
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ return -ENOMEM;
> +
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ memcpy(dai_drv, &dmic_dai, sizeof(*dai_drv));
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ dai_drv->capture.channels_max = chans;
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂ }
> +ÂÂÂÂÂÂ }
> +

> ÂÂÂÂÂÂÂÂ return snd_soc_register_codec(&pdev->dev,
> -ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &soc_dmic, &dmic_dai, 1);
> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &soc_dmic, dai_drv, 1);
> Â}
> Â
> Âstatic int dmic_dev_remove(struct platform_device *pdev)
> --
> 2.16.0.rc0.223.g4a4ac83678-goog
>