]> www.infradead.org Git - users/hch/misc.git/commitdiff
ASoC: codecs: pcm1754: add pcm1754 dac driver
authorAlvin Šipraga <alsi@bang-olufsen.dk>
Wed, 10 Sep 2025 09:34:06 +0000 (11:34 +0200)
committerMark Brown <broonie@kernel.org>
Thu, 11 Sep 2025 13:07:24 +0000 (14:07 +0100)
The Texas Instruments PCM1754[1] is a simple stereo DAC without any
digital
management interface but soft mute, PCM input format and 44.1 kHz
digital de-emphasis can be configured via strapping pins. Only soft mute
and PCM input format selection is currently exposed via optional GPIOs
in the driver.

[1]: https://www.ti.com/product/PCM1754

Signed-off-by: Alvin Šipraga <alsi@bang-olufsen.dk>
Co-developed-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
Signed-off-by: Stefan Kerkmann <s.kerkmann@pengutronix.de>
Link: https://patch.msgid.link/20250910-v6-12-topic-pcm1754-v2-2-0917dbe73c65@pengutronix.de
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/Kconfig
sound/soc/codecs/Makefile
sound/soc/codecs/pcm1754.c [new file with mode: 0644]

index 6d7e4725d89cd33647770e4f2c4e81445b8335ce..423cc02f76bce6a2585f684f2d0bd2866356b137 100644 (file)
@@ -177,6 +177,7 @@ config SND_SOC_ALL_CODECS
        imply SND_SOC_NAU8825
        imply SND_SOC_HDMI_CODEC
        imply SND_SOC_PCM1681
+       imply SND_SOC_PCM1754
        imply SND_SOC_PCM1789_I2C
        imply SND_SOC_PCM179X_I2C
        imply SND_SOC_PCM179X_SPI
@@ -1426,6 +1427,10 @@ config SND_SOC_PCM1681
        tristate "Texas Instruments PCM1681 CODEC"
        depends on I2C
 
+config SND_SOC_PCM1754
+       tristate "Texas Instruments PCM1754 CODEC"
+       depends on GPIOLIB
+
 config SND_SOC_PCM1789
        tristate
 
index a68c3d192a1b6ccec513c6bc447c29be532ea70c..af177e271dda8d5f745270d500131e3ac629e0a1 100644 (file)
@@ -201,6 +201,7 @@ snd-soc-ntp8918-y := ntp8918.o
 snd-soc-ntpfw-y := ntpfw.o
 snd-soc-hdmi-codec-y := hdmi-codec.o
 snd-soc-pcm1681-y := pcm1681.o
+snd-soc-pcm1754-y := pcm1754.o
 snd-soc-pcm1789-codec-y := pcm1789.o
 snd-soc-pcm1789-i2c-y := pcm1789-i2c.o
 snd-soc-pcm179x-codec-y := pcm179x.o
@@ -621,6 +622,7 @@ obj-$(CONFIG_SND_SOC_NTP8918)       += snd-soc-ntp8918.o
 obj-$(CONFIG_SND_SOC_NTPFW)    += snd-soc-ntpfw.o
 obj-$(CONFIG_SND_SOC_HDMI_CODEC)       += snd-soc-hdmi-codec.o
 obj-$(CONFIG_SND_SOC_PCM1681)  += snd-soc-pcm1681.o
+obj-$(CONFIG_SND_SOC_PCM1754)  += snd-soc-pcm1754.o
 obj-$(CONFIG_SND_SOC_PCM179X)  += snd-soc-pcm179x-codec.o
 obj-$(CONFIG_SND_SOC_PCM1789_I2C)      += snd-soc-pcm1789-i2c.o
 obj-$(CONFIG_SND_SOC_PCM1789)  += snd-soc-pcm1789-codec.o
diff --git a/sound/soc/codecs/pcm1754.c b/sound/soc/codecs/pcm1754.c
new file mode 100644 (file)
index 0000000..b68a528
--- /dev/null
@@ -0,0 +1,185 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * PCM1754 DAC ASoC codec driver
+ *
+ * Copyright (c) 2022 Alvin Šipraga <alsi@bang-olufsen.dk>
+ * Copyright (c) 2025 Stefan Kerkmann <s.kerkmann@pengutronix.de>
+ */
+
+#include <linux/gpio/consumer.h>
+#include <linux/module.h>
+#include <linux/regulator/consumer.h>
+
+#include <sound/pcm_params.h>
+#include <sound/soc.h>
+
+struct pcm1754_priv {
+       unsigned int format;
+       struct gpio_desc *gpiod_mute;
+       struct gpio_desc *gpiod_format;
+};
+
+static int pcm1754_set_dai_fmt(struct snd_soc_dai *codec_dai,
+                                  unsigned int format)
+{
+       struct snd_soc_component *component = codec_dai->component;
+       struct pcm1754_priv *priv = snd_soc_component_get_drvdata(component);
+
+       priv->format = format;
+
+       return 0;
+}
+
+static int pcm1754_hw_params(struct snd_pcm_substream *substream,
+                                struct snd_pcm_hw_params *params,
+                                struct snd_soc_dai *codec_dai)
+{
+       struct snd_soc_component *component = codec_dai->component;
+       struct pcm1754_priv *priv = snd_soc_component_get_drvdata(component);
+       int format;
+
+       switch (priv->format & SND_SOC_DAIFMT_FORMAT_MASK) {
+       case SND_SOC_DAIFMT_RIGHT_J:
+               switch (params_width(params)) {
+               case 16:
+                       format = 1;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       case SND_SOC_DAIFMT_I2S:
+               switch (params_width(params)) {
+               case 16:
+                       fallthrough;
+               case 24:
+                       format = 0;
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       default:
+               dev_err(component->dev, "Invalid DAI format\n");
+               return -EINVAL;
+       }
+
+       gpiod_set_value_cansleep(priv->gpiod_format, format);
+
+       return 0;
+}
+
+static int pcm1754_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
+{
+       struct pcm1754_priv *priv = snd_soc_component_get_drvdata(dai->component);
+
+       gpiod_set_value_cansleep(priv->gpiod_mute, mute);
+
+       return 0;
+}
+
+static const struct snd_soc_dai_ops pcm1754_dai_ops = {
+       .set_fmt = pcm1754_set_dai_fmt,
+       .hw_params = pcm1754_hw_params,
+       .mute_stream = pcm1754_mute_stream,
+};
+
+static const struct snd_soc_dai_driver pcm1754_dai = {
+       .name = "pcm1754",
+       .playback = {
+               .stream_name    = "Playback",
+               .channels_min   = 2,
+               .channels_max   = 2,
+               .rates          = SNDRV_PCM_RATE_CONTINUOUS,
+               .rate_min       = 5000,
+               .rate_max       = 200000,
+               .formats        = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE
+       },
+       .ops = &pcm1754_dai_ops,
+};
+
+static const struct snd_soc_dapm_widget pcm1754_dapm_widgets[] = {
+       SND_SOC_DAPM_REGULATOR_SUPPLY("VCC", 0, 0),
+
+       SND_SOC_DAPM_DAC("DAC1", "Channel 1 Playback", SND_SOC_NOPM, 0, 0),
+       SND_SOC_DAPM_DAC("DAC2", "Channel 2 Playback", SND_SOC_NOPM, 0, 0),
+
+       SND_SOC_DAPM_OUTPUT("VOUTL"),
+       SND_SOC_DAPM_OUTPUT("VOUTR"),
+};
+
+static const struct snd_soc_dapm_route pcm1754_dapm_routes[] = {
+       { "DAC1", NULL, "Playback" },
+       { "DAC2", NULL, "Playback" },
+
+       { "DAC1", NULL, "VCC" },
+       { "DAC2", NULL, "VCC" },
+
+       { "VOUTL", NULL, "DAC1" },
+       { "VOUTR", NULL, "DAC2" },
+};
+
+static const struct snd_soc_component_driver soc_component_dev_pcm1754 = {
+       .dapm_widgets = pcm1754_dapm_widgets,
+       .num_dapm_widgets = ARRAY_SIZE(pcm1754_dapm_widgets),
+       .dapm_routes = pcm1754_dapm_routes,
+       .num_dapm_routes = ARRAY_SIZE(pcm1754_dapm_routes),
+};
+
+static int pcm1754_probe(struct platform_device *pdev)
+{
+       struct pcm1754_priv *priv;
+       struct device *dev = &pdev->dev;
+       struct snd_soc_dai_driver *dai_drv;
+       int ret;
+
+       dai_drv = devm_kmemdup(dev, &pcm1754_dai, sizeof(*dai_drv), GFP_KERNEL);
+       if (!dai_drv)
+               return -ENOMEM;
+
+       priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
+       if (!priv)
+               return -ENOMEM;
+
+       priv->gpiod_mute = devm_gpiod_get_optional(dev, "mute", GPIOD_OUT_HIGH);
+       if (IS_ERR(priv->gpiod_mute))
+               return dev_err_probe(dev, PTR_ERR(priv->gpiod_mute),
+                                        "failed to get mute gpio");
+
+       priv->gpiod_format = devm_gpiod_get_optional(dev, "format", GPIOD_OUT_LOW);
+       if (IS_ERR(priv->gpiod_format))
+               return dev_err_probe(dev, PTR_ERR(priv->gpiod_format),
+                                        "failed to get format gpio");
+
+       dev_set_drvdata(dev, priv);
+
+       ret = devm_snd_soc_register_component(
+               &pdev->dev, &soc_component_dev_pcm1754, dai_drv, 1);
+       if (ret)
+               return dev_err_probe(dev, ret, "failed to register");
+
+       return 0;
+}
+
+#ifdef CONFIG_OF
+static const struct of_device_id pcm1754_of_match[] = {
+       { .compatible = "ti,pcm1754" },
+       { }
+};
+MODULE_DEVICE_TABLE(of, pcm1754_of_match);
+#endif
+
+static struct platform_driver pcm1754_codec_driver = {
+       .driver = {
+               .name = "pcm1754-codec",
+               .of_match_table = of_match_ptr(pcm1754_of_match),
+       },
+       .probe = pcm1754_probe,
+};
+
+module_platform_driver(pcm1754_codec_driver);
+
+MODULE_DESCRIPTION("ASoC PCM1754 driver");
+MODULE_AUTHOR("Alvin Šipraga <alsi@bang-olufsen.dk>");
+MODULE_AUTHOR("Stefan Kerkmann <s.kerkmann@pengutronix.de>");
+MODULE_LICENSE("GPL");