Skip to content

Commit

Permalink
ASoC: codecs: dmic: Make number of channels configurable
Browse files Browse the repository at this point in the history
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@chromium.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Acked-by: Arnaud Pouliquen <arnaud.pouliquen@st.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Matthias Kaehlcke authored and Mark Brown committed Jan 9, 2018
1 parent 4fbd8d1 commit 7fb59e9
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Documentation/devicetree/bindings/sound/dmic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
};
24 changes: 23 additions & 1 deletion sound/soc/codecs/dmic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7fb59e9

Please sign in to comment.