summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChancel Liu <chancel.liu@nxp.com>2026-06-03 12:50:41 +0300
committerMark Brown <broonie@kernel.org>2026-06-03 14:56:57 +0300
commit3158f585f4f25cb88415bf39786aaced87c98ee1 (patch)
treea13667deb08915cac6b759cb76656d4103c45314
parent596f8d6494449d5bac7bb7b4e613bfe47d0a965b (diff)
downloadlinux-3158f585f4f25cb88415bf39786aaced87c98ee1.tar.xz
ASoC: cs42xx8: Add SPI bus support for CS42448/CS42888 codec
The existing cs42xx8 driver only supported I2C control interface. Add SPI bus support for the Cirrus Logic CS42448/CS42888 Audio CODEC. Signed-off-by: Chancel Liu <chancel.liu@nxp.com> Reviewed-by: Charles Keepax <ckeepax@opensource.cirrus.com> Link: https://patch.msgid.link/20260603095041.3906558-3-chancel.liu@oss.nxp.com Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r--sound/soc/codecs/Kconfig7
-rw-r--r--sound/soc/codecs/Makefile2
-rw-r--r--sound/soc/codecs/cs42xx8-spi.c104
-rw-r--r--sound/soc/codecs/cs42xx8.c3
4 files changed, 116 insertions, 0 deletions
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 269c31ce0814..4822007aa0bc 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -93,6 +93,7 @@ config SND_SOC_ALL_CODECS
imply SND_SOC_CS4271_I2C
imply SND_SOC_CS4271_SPI
imply SND_SOC_CS42XX8_I2C
+ imply SND_SOC_CS42XX8_SPI
imply SND_SOC_CS43130
imply SND_SOC_CS4341
imply SND_SOC_CS4349
@@ -1074,6 +1075,12 @@ config SND_SOC_CS4271_SPI
config SND_SOC_CS42XX8
tristate
+config SND_SOC_CS42XX8_SPI
+ tristate "Cirrus Logic CS42448/CS42888 CODEC (SPI)"
+ depends on SPI_MASTER
+ select SND_SOC_CS42XX8
+ select REGMAP_SPI
+
config SND_SOC_CS42XX8_I2C
tristate "Cirrus Logic CS42448/CS42888 CODEC (I2C)"
depends on I2C
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index 172861d17cfd..3187cceddd8e 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -103,6 +103,7 @@ snd-soc-cs4271-i2c-y := cs4271-i2c.o
snd-soc-cs4271-spi-y := cs4271-spi.o
snd-soc-cs42xx8-y := cs42xx8.o
snd-soc-cs42xx8-i2c-y := cs42xx8-i2c.o
+snd-soc-cs42xx8-spi-y := cs42xx8-spi.o
snd-soc-cs43130-y := cs43130.o
snd-soc-cs4341-y := cs4341.o
snd-soc-cs4349-y := cs4349.o
@@ -540,6 +541,7 @@ obj-$(CONFIG_SND_SOC_CS4271_I2C) += snd-soc-cs4271-i2c.o
obj-$(CONFIG_SND_SOC_CS4271_SPI) += snd-soc-cs4271-spi.o
obj-$(CONFIG_SND_SOC_CS42XX8) += snd-soc-cs42xx8.o
obj-$(CONFIG_SND_SOC_CS42XX8_I2C) += snd-soc-cs42xx8-i2c.o
+obj-$(CONFIG_SND_SOC_CS42XX8_SPI) += snd-soc-cs42xx8-spi.o
obj-$(CONFIG_SND_SOC_CS43130) += snd-soc-cs43130.o
obj-$(CONFIG_SND_SOC_CS4341) += snd-soc-cs4341.o
obj-$(CONFIG_SND_SOC_CS4349) += snd-soc-cs4349.o
diff --git a/sound/soc/codecs/cs42xx8-spi.c b/sound/soc/codecs/cs42xx8-spi.c
new file mode 100644
index 000000000000..b86fe2fe771e
--- /dev/null
+++ b/sound/soc/codecs/cs42xx8-spi.c
@@ -0,0 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Cirrus Logic CS42448/CS42888 Audio CODEC DAI SPI driver
+ *
+ * Copyright 2026 NXP
+ *
+ */
+
+#include <linux/mod_devicetable.h>
+#include <linux/module.h>
+#include <linux/pm_runtime.h>
+#include <linux/regmap.h>
+#include <linux/spi/spi.h>
+#include <sound/soc.h>
+
+#include "cs42xx8.h"
+
+/*
+ * CS42448/CS42888 SPI register access (from datasheet Figure 23):
+ *
+ * The SPI frame is 3 bytes:
+ * Byte 0: chip address [7:1] = 1001111, bit[0] = R/W (0=write, 1=read)
+ * Write: 0x9E, Read: 0x9F
+ * Byte 1: MAP - Memory Address Pointer
+ * bit[7] = INCR (auto-increment for burst), bits[6:0] = address
+ * Byte 2: data byte
+ *
+ * We configure reg_bits=16 so that regmap treats the address field as 2 bytes
+ * (big-endian). The chip address byte (0x9E/0x9F) is placed in the high byte
+ * via write_flag_mask / read_flag_mask, and the MAP register address occupies
+ * the low byte. Currently INCR (MAP bit[7]) is not set and use_single_read/write
+ * are enabled. This produces the correct 3-byte on-wire frame without any
+ * custom bus implementation:
+ *
+ * write: [0x9E, MAP_addr, data]
+ * read: [0x9F, MAP_addr] -> [data]
+ */
+
+static int cs42xx8_spi_probe(struct spi_device *spi)
+{
+ struct cs42xx8_driver_data *drvdata;
+ struct regmap_config config;
+ int ret;
+
+ drvdata = (struct cs42xx8_driver_data *)spi_get_device_match_data(spi);
+ if (!drvdata)
+ return dev_err_probe(&spi->dev, -EINVAL,
+ "failed to find driver data\n");
+
+ config = cs42xx8_regmap_config;
+ /*
+ * reg_bits=16 makes regmap send a 2-byte address field (big-endian).
+ * write_flag_mask/read_flag_mask are OR'd into that address field:
+ */
+ config.reg_bits = 16;
+ config.write_flag_mask = 0x9E;
+ config.read_flag_mask = 0x9F;
+
+ ret = cs42xx8_probe(&spi->dev,
+ devm_regmap_init_spi(spi, &config), drvdata);
+ if (ret)
+ return ret;
+
+ pm_runtime_enable(&spi->dev);
+ pm_request_idle(&spi->dev);
+
+ return 0;
+}
+
+static void cs42xx8_spi_remove(struct spi_device *spi)
+{
+ pm_runtime_disable(&spi->dev);
+}
+
+static const struct of_device_id cs42xx8_of_match[] = {
+ { .compatible = "cirrus,cs42448", .data = &cs42448_data, },
+ { .compatible = "cirrus,cs42888", .data = &cs42888_data, },
+ { /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, cs42xx8_of_match);
+
+static const struct spi_device_id cs42xx8_spi_id[] = {
+ { .name = "cs42448", .driver_data = (kernel_ulong_t)&cs42448_data },
+ { .name = "cs42888", .driver_data = (kernel_ulong_t)&cs42888_data },
+ { }
+};
+MODULE_DEVICE_TABLE(spi, cs42xx8_spi_id);
+
+static struct spi_driver cs42xx8_spi_driver = {
+ .driver = {
+ .name = "cs42xx8",
+ .pm = pm_ptr(&cs42xx8_pm),
+ .of_match_table = cs42xx8_of_match,
+ },
+ .probe = cs42xx8_spi_probe,
+ .remove = cs42xx8_spi_remove,
+ .id_table = cs42xx8_spi_id,
+};
+
+module_spi_driver(cs42xx8_spi_driver);
+
+MODULE_DESCRIPTION("Cirrus Logic CS42448/CS42888 ALSA SoC Codec SPI Driver");
+MODULE_AUTHOR("Chancel Liu <chancel.liu@nxp.com>");
+MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/cs42xx8.c b/sound/soc/codecs/cs42xx8.c
index 12fe9b3e2525..5b689549c74e 100644
--- a/sound/soc/codecs/cs42xx8.c
+++ b/sound/soc/codecs/cs42xx8.c
@@ -478,6 +478,9 @@ const struct regmap_config cs42xx8_regmap_config = {
.volatile_reg = cs42xx8_volatile_register,
.writeable_reg = cs42xx8_writeable_register,
.cache_type = REGCACHE_MAPLE,
+ .reg_format_endian = REGMAP_ENDIAN_BIG,
+ .use_single_read = true,
+ .use_single_write = true,
};
EXPORT_SYMBOL_GPL(cs42xx8_regmap_config);