Skip to contentSkip to conversation

ASoC: cs35l56: Replace open-coded SoundWire regmap with generic regmap-sdw

PATCH Superseded Richard Fitzgerald 2 participants 5 messages May 19 – May 22

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Richard Fitzgerald

author maintainer
#0 lore raw

v3 cover ASoC: cs35l56: Replace open-coded SoundWire regmap with generic regmap-sdw

This series replaces the entirely custom SoundWire regmap with the generic regmap-sdw. The reasons for doing this are:

- Avoid code duplication
- Avoid effort of keeping custom implementation up-to-date
- Prepare for supporting BRA

Changes in V3:
- Change cs35l56-shared-test KUnit test to handle the offset addresses passed into its mock regmap bus.

Changes in V2:
- Select REGMAP_SOUNDWIRE

Richard Fitzgerald (3):
ASoC: cs35l56-shared-test: Subtract reg_base offset in dummy regmap
ASoC: cs35l56: Use reg_base to offset addresses on SoundWire
ASoC: cs35l56: Use standard SoundWire regmap implementation

 sound/soc/codecs/Kconfig               |   2 +-
 sound/soc/codecs/cs35l56-sdw.c         | 137 +++++++++----------------
 sound/soc/codecs/cs35l56-shared-test.c |   6 ++
 sound/soc/codecs/cs35l56-shared.c      |   2 +
 sound/soc/codecs/cs35l56.h             |   1 +
 5 files changed, 59 insertions(+), 89 deletions(-)
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH v3 1/3 ASoC: cs35l56-shared-test: Subtract reg_base offset in dummy regmap

Subtract the value of cs35l56 regmap_config->reg_base from addresses passed into the mock regmap bus.

Chip register addresses transferred over SoundWire are offset by 0x8000 to move them after the address range reserved in the SoundWire spec.

This commit prepares for changing the cs35l56-sdw driver to use regmap_config->reg_base to add this offset. When that is done the addresses passed into the mock regmap_bus will include this offset.

---
New in V3

 sound/soc/codecs/cs35l56-shared-test.c | 6 ++++++
 1 file changed, 6 insertions(+)
sound/soc/codecs/cs35l56-shared-test.c +6 -0
index cfe7938065f9..8060a275d32b 100644
@@ -29,6 +29,7 @@ struct cs35l56_shared_test_priv {
 	struct faux_device *gpio_dev;
 	struct cs35l56_shared_test_mock_gpio *gpio_priv;
 	struct regmap *registers;
+	unsigned int reg_offset;
 	struct cs35l56_base *cs35l56_base;
 	u8 applied_pad_pull_state[CS35L56_MAX_GPIO];
 };
@@ -194,6 +195,8 @@ static int cs35l56_shared_test_reg_read(void *context, unsigned int reg, unsigne
 {
 	struct cs35l56_shared_test_priv *priv = context;
 
+	reg -= priv->reg_offset;
+
 	switch (reg) {
 	case CS35L56_SYNC_GPIO1_CFG ... CS35L56_ASP2_DIO_GPIO13_CFG:
 	case CS35L56_GPIO1_CTRL1 ... CS35L56_GPIO13_CTRL1:
@@ -214,6 +217,8 @@ static int cs35l56_shared_test_reg_write(void *context, unsigned int reg, unsign
 {
 	struct cs35l56_shared_test_priv *priv = context;
 
+	reg -= priv->reg_offset;
+
 	switch (reg) {
 	case CS35L56_UPDATE_REGS:
 		return cs35l56_shared_test_updt_gpio_pres(priv, reg, val);
@@ -657,6 +662,7 @@ static int cs35l56_shared_test_case_base_init(struct kunit *test, u8 type, u8 re
 
 	test->priv = priv;
 	priv->test = test;
+	priv->reg_offset = regmap_config->reg_base;
 
 	/* Create dummy amp driver dev */
 	priv->amp_dev = faux_device_create("cs35l56_shared_test_drv", NULL, NULL);
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH v3 2/3 ASoC: cs35l56: Use reg_base to offset addresses on SoundWire

In reply to Richard Fitzgerald

Set the reg_base member of regmap_config for SoundWire so that the regmap core will apply the 0x8000 offset to addresses, instead of doing it within our low-level regmap read/write callbacks.

---
No changes in V3
No changes in V2

 sound/soc/codecs/cs35l56-sdw.c    | 7 +------
 sound/soc/codecs/cs35l56-shared.c | 2 ++
 2 files changed, 3 insertions(+), 6 deletions(-)
sound/soc/codecs/cs35l56-sdw.c +1 -6
index d5b9e5f71de2..d9dcca1e952f 100644
@@ -59,8 +59,6 @@ static int cs35l56_sdw_slow_read(struct sdw_slave *peripheral, unsigned int reg,
 {
 	int ret, i;
 
-	reg += CS35L56_SDW_ADDR_OFFSET;
-
 	for (i = 0; i < val_size; i += sizeof(u32)) {
 		/* Poll for bus bridge idle */
 		ret = cs35l56_sdw_poll_mem_status(peripheral,
@@ -123,11 +121,9 @@ static int cs35l56_sdw_read(void *context, const void *reg_buf,
 
 	reg = le32_to_cpu(*(const __le32 *)reg_buf);
 
-	if (cs35l56_is_otp_register(reg))
+	if (cs35l56_is_otp_register(reg - CS35L56_SDW_ADDR_OFFSET))
 		return cs35l56_sdw_slow_read(peripheral, reg, buf8, val_size);
 
-	reg += CS35L56_SDW_ADDR_OFFSET;
-
 	if (val_size == 4)
 		return cs35l56_sdw_read_one(peripheral, reg, val_buf);
 
@@ -186,7 +182,6 @@ static int cs35l56_sdw_gather_write(void *context,
 	int ret;
 
 	reg = le32_to_cpu(*(const __le32 *)reg_buf);
-	reg += CS35L56_SDW_ADDR_OFFSET;
 
 	if (val_size == 4)
 		return cs35l56_sdw_write_one(peripheral, reg, src_be);
sound/soc/codecs/cs35l56-shared.c +2 -0
index 795e2764d67e..8e3538e28fad 100644
@@ -1880,6 +1880,7 @@ EXPORT_SYMBOL_NS_GPL(cs35l56_regmap_spi, "SND_SOC_CS35L56_SHARED");
 
 const struct regmap_config cs35l56_regmap_sdw = {
 	.reg_bits = 32,
+	.reg_base = 0x8000,
 	.val_bits = 32,
 	.reg_stride = 4,
 	.reg_format_endian = REGMAP_ENDIAN_LITTLE,
@@ -1915,6 +1916,7 @@ const struct regmap_config cs35l63_regmap_sdw = {
 	.reg_bits = 32,
 	.val_bits = 32,
 	.reg_stride = 4,
+	.reg_base = 0x8000,
 	.reg_format_endian = REGMAP_ENDIAN_LITTLE,
 	.val_format_endian = REGMAP_ENDIAN_BIG,
 	.max_register = CS35L56_DSP1_PMEM_5114,
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH v3 3/3 ASoC: cs35l56: Use standard SoundWire regmap implementation

In reply to Richard Fitzgerald

Use the regmap_sdw implementation for SoundWire instead of re-implementing the low-level bus transactions in cs35l56-sdw.c

The cs35l56 registers are big-endian on I2C and SPI but little-endian over SoundWire. The firmware files are all big-endian and contain opaque blobs in big-endian order. So these must be endian-swapped to transfer over SoundWire. A custom regmap bus implementation is used to do this endian-swapping.

The original implementation of this custom regmap bus was a complete bus backend, performing the endian swapping and low-level SoundWire bus read/write.

This commit changes the custom regmap bus to only perform the endian-swap. It uses an underlying simple uncached regmap_sdw bus to deal with transferring the 32-bit registers over the SoundWire bus. Although this adds a small amount of overhead, from passing through the regmap APIs twice, it avoids having a local duplicate implementation of what regmap_sdw already does.

The slow-read handling for OTP registers must access 8-bit SoundWire registers so it still uses low-level SoundWire bus reads.

---
No changes in V3

Changed in V2:
- Select REGMAP_SOUNDWIRE

 sound/soc/codecs/Kconfig       |   2 +-
 sound/soc/codecs/cs35l56-sdw.c | 132 ++++++++++++---------------------
 sound/soc/codecs/cs35l56.h     |   1 +
 3 files changed, 51 insertions(+), 84 deletions(-)
sound/soc/codecs/Kconfig +1 -1
index 5fdd0334c355..a7c61f7c7f4c 100644
@@ -887,7 +887,7 @@ config SND_SOC_CS35L56_SPI
 config SND_SOC_CS35L56_SDW
 	tristate "Cirrus Logic CS35L56 CODEC (SDW)"
 	depends on SOUNDWIRE
-	select REGMAP
+	select REGMAP_SOUNDWIRE
 	select SND_SOC_CS35L56
 	select SND_SOC_CS35L56_SHARED
 	help
sound/soc/codecs/cs35l56-sdw.c +49 -83

188 lines not on this page · raw message

sound/soc/codecs/cs35l56.h +1 -0
index cd71b23b2a3a..d029fa3f8656 100644
@@ -37,6 +37,7 @@ struct cs35l56_private {
 	struct snd_soc_component *component;
 	struct regulator_bulk_data supplies[CS35L56_NUM_BULK_SUPPLIES];
 	struct sdw_slave *sdw_peripheral;
+	struct regmap *sdw_bus_regmap;
 	const char *fallback_fw_suffix;
 	struct work_struct sdw_irq_work;
 	bool sdw_irq_no_unmask;
Signature · 1 line
2.47.3
maintainer
#4 lore raw
In reply to Richard Fitzgerald
Quoted 10 lines · Richard Fitzgerald

ASoC: cs35l56: Replace open-coded SoundWire regmap with generic regmap-sdw

This series replaces the entirely custom SoundWire regmap with the generic regmap-sdw. The reasons for doing this are:

- Avoid code duplication
- Avoid effort of keeping custom implementation up-to-date
- Prepare for supporting BRA

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2

Thanks!

[1/3] ASoC: cs35l56-shared-test: Subtract reg_base offset in dummy regmap

      https://git.kernel.org/broonie/sound/c/a6f7c21accb5
[2/3] ASoC: cs35l56: Use reg_base to offset addresses on SoundWire
      https://git.kernel.org/broonie/sound/c/7f9ae6d20525
[3/3] ASoC: cs35l56: Use standard SoundWire regmap implementation
      https://git.kernel.org/broonie/sound/c/eb65b5ad9324

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark