ASoC: cs530x: Add SPI bus support for cs530x parts

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>
This commit is contained in:
Vitaly Rodionov
2025-10-23 10:03:20 +01:00
committed by Mark Brown
parent bb65cb96f6
commit e7434adf0c
5 changed files with 126 additions and 0 deletions

View 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

View 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

View File

@@ -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");

View 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;

View 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