]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: cs530x: Add SPI bus support for cs530x parts
authorVitaly Rodionov <vitalyr@opensource.cirrus.com>
Thu, 23 Oct 2025 09:03:20 +0000 (10:03 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 27 Oct 2025 11:10:34 +0000 (11:10 +0000)
Cirrus Logic cs530x device family has 2 control buses I2C and SPI.
This patch adds SPI support.

Signed-off-by: Vitaly Rodionov <vitalyr@opensource.cirrus.com>
Link: https://patch.msgid.link/20251023090327.58275-13-vitalyr@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/Kconfig
sound/soc/codecs/Makefile
sound/soc/codecs/cs530x-spi.c [new file with mode: 0644]
sound/soc/codecs/cs530x.c
sound/soc/codecs/cs530x.h

index 160c07699a8b723b24d915dd73944722bf294289..ef49f71e8b3493982ad8db717a5483241b243c49 100644 (file)
@@ -106,6 +106,7 @@ config SND_SOC_ALL_CODECS
        imply SND_SOC_CS48L32
        imply SND_SOC_CS53L30
        imply SND_SOC_CS530X_I2C
+       imply SND_SOC_CS530X_SPI
        imply SND_SOC_CX20442
        imply SND_SOC_CX2072X
        imply SND_SOC_DA7210
@@ -1082,6 +1083,15 @@ config SND_SOC_CS530X_I2C
          Enable support for Cirrus Logic CS530X ADCs
          with I2C control.
 
+config SND_SOC_CS530X_SPI
+       tristate "Cirrus Logic CS530x ADCs (SPI)"
+       depends on SPI_MASTER
+       select REGMAP_SPI
+       select SND_SOC_CS530X
+       help
+         Enable support for Cirrus Logic CS530X ADCs
+         with SPI control.
+
 config SND_SOC_CX20442
        tristate
        depends on TTY
index bd95a7c911d5c19a935cc9b8b1384af11fa268a1..39138d96a7205de3951852db89846404ae053b15 100644 (file)
@@ -115,6 +115,7 @@ snd-soc-cs48l32-y := cs48l32.o cs48l32-tables.o
 snd-soc-cs53l30-y := cs53l30.o
 snd-soc-cs530x-y := cs530x.o
 snd-soc-cs530x-i2c-y := cs530x-i2c.o
+snd-soc-cs530x-spi-y := cs530x-spi.o
 snd-soc-cx20442-y := cx20442.o
 snd-soc-cx2072x-y := cx2072x.o
 snd-soc-da7210-y := da7210.o
@@ -546,6 +547,7 @@ obj-$(CONFIG_SND_SOC_CS48L32)       += snd-soc-cs48l32.o
 obj-$(CONFIG_SND_SOC_CS53L30)  += snd-soc-cs53l30.o
 obj-$(CONFIG_SND_SOC_CS530X)   += snd-soc-cs530x.o
 obj-$(CONFIG_SND_SOC_CS530X_I2C)       += snd-soc-cs530x-i2c.o
+obj-$(CONFIG_SND_SOC_CS530X_SPI)       += snd-soc-cs530x-spi.o
 obj-$(CONFIG_SND_SOC_CX20442)  += snd-soc-cx20442.o
 obj-$(CONFIG_SND_SOC_CX2072X)  += snd-soc-cx2072x.o
 obj-$(CONFIG_SND_SOC_DA7210)   += snd-soc-da7210.o
diff --git a/sound/soc/codecs/cs530x-spi.c b/sound/soc/codecs/cs530x-spi.c
new file mode 100644 (file)
index 0000000..dbf1e7b
--- /dev/null
@@ -0,0 +1,92 @@
+// SPDX-License-Identifier: GPL-2.0
+//
+// CS530x CODEC driver
+//
+// Copyright (C) 2025 Cirrus Logic, Inc. and
+//                    Cirrus Logic International Semiconductor Ltd.
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+
+#include "cs530x.h"
+
+static const struct of_device_id cs530x_of_match[] = {
+       {
+               .compatible = "cirrus,cs4282",
+               .data = (void *)CS4282,
+       }, {
+               .compatible = "cirrus,cs4302",
+               .data = (void *)CS4302,
+       }, {
+               .compatible = "cirrus,cs4304",
+               .data = (void *)CS4304,
+       }, {
+               .compatible = "cirrus,cs4308",
+               .data = (void *)CS4308,
+       }, {
+               .compatible = "cirrus,cs5302",
+               .data = (void *)CS5302,
+       }, {
+               .compatible = "cirrus,cs5304",
+               .data = (void *)CS5304,
+       }, {
+               .compatible = "cirrus,cs5304",
+               .data = (void *)CS5308,
+       },
+       {}
+};
+MODULE_DEVICE_TABLE(of, cs530x_of_match);
+
+static const struct spi_device_id cs530x_spi_id[] = {
+       { "cs4282", CS4282 },
+       { "cs4302", CS4302 },
+       { "cs4304", CS4304 },
+       { "cs4308", CS4308 },
+       { "cs5302", CS5302 },
+       { "cs5304", CS5304 },
+       { "cs5308", CS5308 },
+       { }
+};
+MODULE_DEVICE_TABLE(spi, cs530x_spi_id);
+
+static int cs530x_spi_probe(struct spi_device *spi)
+{
+       struct cs530x_priv *cs530x;
+       struct device *dev = &spi->dev;
+       int ret;
+
+       cs530x = devm_kzalloc(dev, sizeof(struct cs530x_priv), GFP_KERNEL);
+       if (cs530x == NULL)
+               return -ENOMEM;
+
+       spi_set_drvdata(spi, cs530x);
+
+       cs530x->regmap = devm_regmap_init_spi(spi, &cs530x_regmap_spi);
+       if (IS_ERR(cs530x->regmap)) {
+               ret = PTR_ERR(cs530x->regmap);
+               dev_err(dev, "Failed to allocate register map: %d\n", ret);
+               return ret;
+       }
+
+       cs530x->devtype = (unsigned long)spi_get_device_match_data(spi);
+       cs530x->dev = &spi->dev;
+
+       return cs530x_probe(cs530x);
+}
+
+static struct spi_driver cs530x_spi_driver = {
+       .driver = {
+               .name           = "cs530x",
+               .of_match_table = cs530x_of_match,
+       },
+       .id_table       = cs530x_spi_id,
+       .probe          = cs530x_spi_probe,
+};
+
+module_spi_driver(cs530x_spi_driver);
+
+MODULE_DESCRIPTION("SPI CS530X driver");
+MODULE_IMPORT_NS("SND_SOC_CS530X");
+MODULE_AUTHOR("Vitaly Rodionov <vitalyr@opensource.cirrus.com>");
+MODULE_LICENSE("GPL");
index 79f615d5b12100c88a793567321b04ac47f7b0fc..d052fd324143d24c3f21a8bb61133a547ca1f27c 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/pm.h>
 #include <linux/property.h>
 #include <linux/slab.h>
+#include <linux/spi/spi.h>
 #include <sound/core.h>
 #include <sound/initval.h>
 #include <sound/pcm.h>
@@ -1142,6 +1143,26 @@ const struct regmap_config cs530x_regmap_i2c = {
 };
 EXPORT_SYMBOL_NS_GPL(cs530x_regmap_i2c, "SND_SOC_CS530X");
 
+const struct regmap_config cs530x_regmap_spi = {
+       .reg_bits = 16,
+       .pad_bits = 16,
+       .val_bits = 16,
+
+       .reg_stride = 2,
+
+       .reg_format_endian = REGMAP_ENDIAN_BIG,
+       .val_format_endian = REGMAP_ENDIAN_BIG,
+
+       .max_register = CS530X_MAX_REGISTER,
+       .writeable_reg = cs530x_writeable_register,
+       .readable_reg = cs530x_readable_register,
+
+       .cache_type = REGCACHE_MAPLE,
+       .reg_defaults = cs530x_reg_defaults,
+       .num_reg_defaults = ARRAY_SIZE(cs530x_reg_defaults),
+};
+EXPORT_SYMBOL_NS_GPL(cs530x_regmap_spi, "SND_SOC_CS530X");
+
 static int cs530x_check_device_id(struct cs530x_priv *cs530x)
 {
        struct device *dev = cs530x->dev;
index 2a7b7d01ecfbb6c04d301d8c168f7abcb0a9c07e..1e2f6a7a589c1989c5e7bedc88a7afb6df4ac394 100644 (file)
@@ -247,6 +247,7 @@ struct cs530x_priv {
 };
 
 extern const struct regmap_config cs530x_regmap_i2c;
+extern const struct regmap_config cs530x_regmap_spi;
 int cs530x_probe(struct cs530x_priv *cs530x);
 
 #endif