Add Hifiberry DAC+DSP soundcard driver (#3224)
authorJörg Schambacher <j-schambacher@users.noreply.github.com>
Thu, 12 Sep 2019 12:57:32 +0000 (14:57 +0200)
committerpopcornmix <popcornmix@gmail.com>
Wed, 1 Jul 2020 15:33:05 +0000 (16:33 +0100)
Adds the driver for the Hifiberry DAC+DSP. It supports capture and
playback depending on the DSP firmware.

Signed-off-by: Joerg Schambacher <joerg@i2audio.com>
sound/soc/bcm/Kconfig
sound/soc/bcm/Makefile
sound/soc/bcm/hifiberry_dacplusadcpro.c
sound/soc/bcm/hifiberry_dacplusdsp.c [new file with mode: 0644]
sound/soc/bcm/rpi-simple-soundcard.c

index 4c38298..8d50e52 100644 (file)
@@ -59,6 +59,13 @@ config SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO
         help
          Say Y or M if you want to add support for HifiBerry DAC+ADC PRO.
 
+config SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP
+        tristate "Support for HifiBerry DAC+DSP"
+        depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
+       select SND_RPI_SIMPLE_SOUNDCARD
+        help
+         Say Y or M if you want to add support for HifiBerry DSP-DAC.
+
 config SND_BCM2708_SOC_HIFIBERRY_DIGI
         tristate "Support for HifiBerry Digi"
         depends on SND_BCM2708_SOC_I2S || SND_BCM2835_SOC_I2S
index 0e8b60f..4c0486c 100644 (file)
@@ -16,6 +16,7 @@ snd-soc-googlevoicehat-codec-objs := googlevoicehat-codec.o
 snd-soc-hifiberry-dacplus-objs := hifiberry_dacplus.o
 snd-soc-hifiberry-dacplusadc-objs := hifiberry_dacplusadc.o
 snd-soc-hifiberry-dacplusadcpro-objs := hifiberry_dacplusadcpro.o
+snd-soc-hifiberry-dacplusdsp-objs := hifiberry_dacplusdsp.o
 snd-soc-justboom-dac-objs := justboom-dac.o
 snd-soc-rpi-cirrus-objs := rpi-cirrus.o
 snd-soc-rpi-proto-objs := rpi-proto.o
@@ -41,6 +42,7 @@ obj-$(CONFIG_SND_BCM2708_SOC_GOOGLEVOICEHAT_SOUNDCARD)  += snd-soc-googlevoiceha
 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) += snd-soc-hifiberry-dacplus.o
 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADC) += snd-soc-hifiberry-dacplusadc.o
 obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSADCPRO) += snd-soc-hifiberry-dacplusadcpro.o
+obj-$(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUSDSP) += snd-soc-hifiberry-dacplusdsp.o
 obj-$(CONFIG_SND_BCM2708_SOC_JUSTBOOM_DAC) += snd-soc-justboom-dac.o
 obj-$(CONFIG_SND_BCM2708_SOC_RPI_CIRRUS) += snd-soc-rpi-cirrus.o
 obj-$(CONFIG_SND_BCM2708_SOC_RPI_PROTO) += snd-soc-rpi-proto.o
index ed080b2..cc33d41 100644 (file)
@@ -445,29 +445,21 @@ static struct snd_soc_ops snd_rpi_hifiberry_dacplusadcpro_ops = {
        .shutdown = snd_rpi_hifiberry_dacplusadcpro_shutdown,
 };
 
-static struct snd_soc_dai_link_component snd_rpi_hifiberry_dacplusadcpro_codecs[] = {
-       {
-               .name           = "pcm512x.1-004d",
-               .dai_name       = "pcm512x-hifi",
-       },
-       {
-               .name           = "pcm186x.1-004a",
-               .dai_name       = "pcm1863-aif",
-       },
-};
+SND_SOC_DAILINK_DEFS(hifi,
+       DAILINK_COMP_ARRAY(COMP_CPU("bcm2708-i2s.0")),
+       DAILINK_COMP_ARRAY(COMP_CODEC("pcm512x.1-004d", "pcm512x-hifi"),
+                          COMP_CODEC("pcm186x.1-004a", "pcm1863-aif")),
+       DAILINK_COMP_ARRAY(COMP_PLATFORM("bcm2708-i2s.0")));
 
 static struct snd_soc_dai_link snd_rpi_hifiberry_dacplusadcpro_dai[] = {
 {
        .name           = "HiFiBerry DAC+ADC PRO",
        .stream_name    = "HiFiBerry DAC+ADC PRO HiFi",
-       .cpu_dai_name   = "bcm2708-i2s.0",
-       .platform_name  = "bcm2708-i2s.0",
-       .codecs         = snd_rpi_hifiberry_dacplusadcpro_codecs,
-       .num_codecs     = 2,
        .dai_fmt        = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
                                SND_SOC_DAIFMT_CBS_CFS,
        .ops            = &snd_rpi_hifiberry_dacplusadcpro_ops,
        .init           = snd_rpi_hifiberry_dacplusadcpro_init,
+       SND_SOC_DAILINK_REG(hifi),
 },
 };
 
@@ -495,10 +487,10 @@ static int snd_rpi_hifiberry_dacplusadcpro_probe(struct platform_device *pdev)
                        "i2s-controller", 0);
                if (i2s_node) {
                        for (i = 0; i < card->num_links; i++) {
-                               dai->cpu_dai_name = NULL;
-                               dai->cpu_of_node = i2s_node;
-                               dai->platform_name = NULL;
-                               dai->platform_of_node = i2s_node;
+                               dai->cpus->dai_name = NULL;
+                               dai->cpus->of_node = i2s_node;
+                               dai->platforms->name = NULL;
+                               dai->platforms->of_node = i2s_node;
                        }
                }
        }
diff --git a/sound/soc/bcm/hifiberry_dacplusdsp.c b/sound/soc/bcm/hifiberry_dacplusdsp.c
new file mode 100644 (file)
index 0000000..cda7ee5
--- /dev/null
@@ -0,0 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * ASoC Driver for HiFiBerry DAC + DSP
+ *
+ * Author:     Joerg Schambacher <joscha@schambacher.com>
+ *             Copyright 2018
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * version 2 as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ */
+
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <sound/soc.h>
+
+static struct snd_soc_component_driver dacplusdsp_component_driver;
+
+static struct snd_soc_dai_driver dacplusdsp_dai = {
+       .name = "dacplusdsp-hifi",
+       .capture = {
+               .stream_name = "DAC+DSP Capture",
+               .channels_min = 2,
+               .channels_max = 2,
+               .rates = SNDRV_PCM_RATE_CONTINUOUS,
+               .formats = SNDRV_PCM_FMTBIT_S16_LE |
+                          SNDRV_PCM_FMTBIT_S24_LE |
+                          SNDRV_PCM_FMTBIT_S32_LE,
+       },
+       .playback = {
+               .stream_name = "DACP+DSP Playback",
+               .channels_min = 2,
+               .channels_max = 2,
+               .rates = SNDRV_PCM_RATE_CONTINUOUS,
+               .formats = SNDRV_PCM_FMTBIT_S16_LE |
+                          SNDRV_PCM_FMTBIT_S24_LE |
+                          SNDRV_PCM_FMTBIT_S32_LE,
+       },
+       .symmetric_rates = 1};
+
+#ifdef CONFIG_OF
+static const struct of_device_id dacplusdsp_ids[] = {
+       {
+               .compatible = "hifiberry,dacplusdsp",
+       },
+       {} };
+MODULE_DEVICE_TABLE(of, dacplusdsp_ids);
+#endif
+
+static int dacplusdsp_platform_probe(struct platform_device *pdev)
+{
+       int ret;
+
+       ret = snd_soc_register_component(&pdev->dev,
+                       &dacplusdsp_component_driver, &dacplusdsp_dai, 1);
+       if (ret) {
+               pr_alert("snd_soc_register_component failed\n");
+               return ret;
+       }
+
+       return 0;
+}
+
+static int dacplusdsp_platform_remove(struct platform_device *pdev)
+{
+       snd_soc_unregister_component(&pdev->dev);
+       return 0;
+}
+
+static struct platform_driver dacplusdsp_driver = {
+       .driver = {
+               .name = "hifiberry-dacplusdsp-codec",
+               .of_match_table = of_match_ptr(dacplusdsp_ids),
+               },
+               .probe = dacplusdsp_platform_probe,
+               .remove = dacplusdsp_platform_remove,
+};
+
+module_platform_driver(dacplusdsp_driver);
+
+MODULE_AUTHOR("Joerg Schambacher <joerg@i2audio.com>");
+MODULE_DESCRIPTION("ASoC Driver for HiFiBerry DAC+DSP");
+MODULE_LICENSE("GPL v2");
index 2023b0a..133b6d9 100644 (file)
@@ -144,6 +144,27 @@ static struct snd_rpi_simple_drvdata drvdata_googlevoicehat = {
        .dai       = snd_googlevoicehat_soundcard_dai,
 };
 
+SND_SOC_DAILINK_DEFS(hifiberry_dacplusdsp,
+       DAILINK_COMP_ARRAY(COMP_EMPTY()),
+       DAILINK_COMP_ARRAY(COMP_CODEC("dacplusdsp-codec", "dacplusdsp-hifi")),
+       DAILINK_COMP_ARRAY(COMP_EMPTY()));
+
+static struct snd_soc_dai_link snd_hifiberrydacplusdsp_soundcard_dai[] = {
+{
+       .name           = "Hifiberry DAC+DSP SoundCard",
+       .stream_name    = "Hifiberry DAC+DSP SoundCard HiFi",
+       .dai_fmt        =  SND_SOC_DAIFMT_I2S |
+                          SND_SOC_DAIFMT_NB_NF |
+                          SND_SOC_DAIFMT_CBS_CFS,
+       SND_SOC_DAILINK_REG(hifiberry_dacplusdsp),
+},
+};
+
+static struct snd_rpi_simple_drvdata drvdata_hifiberrydacplusdsp = {
+       .card_name = "snd_rpi_hifiberrydacplusdsp_soundcard",
+       .dai       = snd_hifiberrydacplusdsp_soundcard_dai,
+};
+
 SND_SOC_DAILINK_DEFS(hifiberry_amp,
        DAILINK_COMP_ARRAY(COMP_EMPTY()),
        DAILINK_COMP_ARRAY(COMP_CODEC("tas5713.1-001b", "tas5713-hifi")),
@@ -213,6 +234,8 @@ static const struct of_device_id snd_rpi_simple_of_match[] = {
                .data = (void *) &drvdata_adau1977 },
        { .compatible = "googlevoicehat,googlevoicehat-soundcard",
                .data = (void *) &drvdata_googlevoicehat },
+       { .compatible = "hifiberrydacplusdsp,hifiberrydacplusdsp-soundcard",
+               .data = (void *) &drvdata_hifiberrydacplusdsp },
        { .compatible = "hifiberry,hifiberry-amp",
                .data = (void *) &drvdata_hifiberry_amp },
        { .compatible = "hifiberry,hifiberry-dac",