[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251015092619.52952-8-vitalyr@opensource.cirrus.com>
Date: Wed, 15 Oct 2025 10:26:10 +0100
From: Vitaly Rodionov <vitalyr@...nsource.cirrus.com>
To: Mark Brown <broonie@...nel.org>
Cc: Liam Girdwood <lgirdwood@...il.com>, Takashi Iwai <tiwai@...e.com>,
Jaroslav Kysela <perex@...ex.cz>, linux-sound@...r.kernel.org,
linux-kernel@...r.kernel.org, patches@...nsource.cirrus.com,
Vitaly Rodionov <vitalyr@...nsource.cirrus.com>
Subject: [PATCH 7/8] ASoC: cs530x: Add SPI bus support for cs530x parts
cs530x family has 2 control buses I2C and SPI
This patch adds SPI support.
Signed-off-by: Vitaly Rodionov <vitalyr@...nsource.cirrus.com>
---
sound/soc/codecs/Kconfig | 10 ++++
sound/soc/codecs/Makefile | 2 +
sound/soc/codecs/cs530x-spi.c | 92 +++++++++++++++++++++++++++++++++++
sound/soc/codecs/cs530x.c | 21 ++++++++
sound/soc/codecs/cs530x.h | 1 +
5 files changed, 126 insertions(+)
create mode 100644 sound/soc/codecs/cs530x-spi.c
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 160c07699a8b..ef49f71e8b34 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -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
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index bd95a7c911d5..39138d96a720 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -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
index 000000000000..dbf1e7bbec19
--- /dev/null
+++ b/sound/soc/codecs/cs530x-spi.c
@@ -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@...nsource.cirrus.com>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs530x.c b/sound/soc/codecs/cs530x.c
index 027d936c0912..6df1b37fc6c4 100644
--- a/sound/soc/codecs/cs530x.c
+++ b/sound/soc/codecs/cs530x.c
@@ -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;
diff --git a/sound/soc/codecs/cs530x.h b/sound/soc/codecs/cs530x.h
index 8675a86d7d95..8af7921b3c3e 100644
--- a/sound/soc/codecs/cs530x.h
+++ b/sound/soc/codecs/cs530x.h
@@ -221,6 +221,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
--
2.43.0
Powered by blists - more mailing lists