summaryrefslogtreecommitdiffstats
path: root/sound
diff options
context:
space:
mode:
authorMatthias Kaehlcke2018-01-05 21:39:57 +0100
committerMark Brown2018-01-09 17:46:24 +0100
commit7fb59e940f6225beed0b24cd09e9fad9aebb7565 (patch)
tree715bab6eb9cf55a3a25e642847ef1c13a5adaaad /sound
parentLinux 4.15-rc1 (diff)
downloadkernel-qcow2-linux-7fb59e940f6225beed0b24cd09e9fad9aebb7565.tar.gz
kernel-qcow2-linux-7fb59e940f6225beed0b24cd09e9fad9aebb7565.tar.xz
kernel-qcow2-linux-7fb59e940f6225beed0b24cd09e9fad9aebb7565.zip
ASoC: codecs: dmic: Make number of channels configurable
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>
Diffstat (limited to 'sound')
-rw-r--r--sound/soc/codecs/dmic.c24
1 files changed, 23 insertions, 1 deletions
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)