ASoC: cs35l56: Replace open-coded SoundWire regmap with generic regmap-sdw
Subsystems (3)
Richard Fitzgerald
maintainercover 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
Richard Fitzgerald (2):
ASoC: cs35l56: Use reg_base to offset addresses on SoundWire
ASoC: cs35l56: Use standard SoundWire regmap implementation
sound/soc/codecs/cs35l56-sdw.c | 137 +++++++++++------------------- sound/soc/codecs/cs35l56-shared.c | 2 + sound/soc/codecs/cs35l56.h | 1 + 3 files changed, 52 insertions(+), 88 deletions(-)
Signature · 1 line
2.47.3
Richard Fitzgerald
maintainerPATCH 1/2 ASoC: cs35l56: Use reg_base to offset addresses on SoundWire
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.
--- 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
@@ -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
@@ -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
Richard Fitzgerald
maintainerPATCH 2/2 ASoC: cs35l56: Use standard SoundWire regmap implementation
In reply to Richard FitzgeraldUse 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.
--- sound/soc/codecs/cs35l56-sdw.c | 132 ++++++++++++--------------------- sound/soc/codecs/cs35l56.h | 1 + 2 files changed, 50 insertions(+), 83 deletions(-)
sound/soc/codecs/cs35l56-sdw.c +49 -83
@@ -17,6 +17,7 @@#include <linux/string_choices.h> #include <linux/swab.h> #include <linux/types.h> +#include <linux/unaligned.h> #include <linux/workqueue.h> #include "cs35l56.h"
@@ -95,55 +96,23 @@ static int cs35l56_sdw_slow_read(struct sdw_slave *peripheral, unsigned int reg,return 0 ; } -static int cs35l56_sdw_read_one (struct sdw_slave *peripheral,unsigned int reg,void *buf) -{ -int ret; - - ret =sdw_nread_no_pm (peripheral, reg,4 , (u8 *)buf); -if (ret !=0 ) { -dev_err (&peripheral->dev,"Read failed @%#x:%d\n" , reg, ret); -return ret; - } - -swab32s ((u32 *)buf); - -return 0 ; -} -static int cs35l56_sdw_read (void *context,const void *reg_buf,const size_t reg_size,void *val_buf,size_t val_size) {struct sdw_slave *peripheral = context; -u8 *buf8 = val_buf; -unsigned int reg, bytes; +struct cs35l56_private *cs35l56 =dev_get_drvdata (&peripheral->dev); +unsigned int reg_addr =get_unaligned_le32 (reg_buf);int ret; - reg =le32_to_cpu (*(const __le32 *)reg_buf); +if (cs35l56_is_otp_register (reg_addr -CS35L56_SDW_ADDR_OFFSET )) +return cs35l56_sdw_slow_read (peripheral, reg_addr, (u8 *)val_buf, val_size); -if (cs35l56_is_otp_register (reg -CS35L56_SDW_ADDR_OFFSET )) -return cs35l56_sdw_slow_read (peripheral, reg, buf8, val_size); + ret =regmap_raw_read (cs35l56->sdw_bus_regmap, reg_addr, val_buf, val_size); +if (ret) +return ret; -if (val_size ==4 ) -return cs35l56_sdw_read_one (peripheral, reg, val_buf); - -while (val_size) { - bytes =SDW_REG_NO_PAGE - (reg &SDW_REGADDR );/* to end of page */ -if (bytes > val_size) - bytes = val_size; - - ret =sdw_nread_no_pm (peripheral, reg, bytes, buf8); -if (ret !=0 ) { -dev_err (&peripheral->dev,"Read failed @%#x..%#x:%d\n" , - reg, reg + bytes -1 , ret); -return ret; - } - -swab32_array ((u32 *)buf8, bytes /4 ); - val_size -= bytes; - reg += bytes; - buf8 += bytes; - } +swab32_array ((u32 *)val_buf, val_size /sizeof (u32));return 0 ; }
@@ -157,57 +126,34 @@ static inline void cs35l56_swab_copy(void *dest, const void *src, size_t nbytes) *dest32++ =swab32 (*src32++); } -static int cs35l56_sdw_write_one (struct sdw_slave *peripheral,unsigned int reg,const void *buf) -{ -u32 val_le =swab32 (*(u32 *)buf); -int ret; - - ret =sdw_nwrite_no_pm (peripheral, reg,4 , (u8 *)&val_le); -if (ret !=0 ) { -dev_err (&peripheral->dev,"Write failed @%#x:%d\n" , reg, ret); -return ret; - } - -return 0 ; -} -static int cs35l56_sdw_gather_write (void *context,const void *reg_buf,size_t reg_size,const void *val_buf,size_t val_size) {struct sdw_slave *peripheral = context; -const u8 *src_be = val_buf; -u32 val_le_buf[64 ];/* Define u32 so it is 32-bit aligned */ -unsigned int reg, bytes; +struct cs35l56_private *cs35l56 =dev_get_drvdata (&peripheral->dev); +unsigned int reg_addr =get_unaligned_le32 (reg_buf); +u32 swab_buf[64 ];/* Define u32 so it is 32-bit aligned */ int ret; - reg =le32_to_cpu (*(const __le32 *)reg_buf); - -if (val_size ==4 ) -return cs35l56_sdw_write_one (peripheral, reg, src_be); - -while (val_size) { - bytes =SDW_REG_NO_PAGE - (reg &SDW_REGADDR );/* to end of page */ -if (bytes > val_size) - bytes = val_size; -if (bytes >sizeof (val_le_buf)) - bytes =sizeof (val_le_buf); - -cs35l56_swab_copy (val_le_buf, src_be, bytes); - - ret =sdw_nwrite_no_pm (peripheral, reg, bytes, (u8 *)val_le_buf); -if (ret !=0 ) { -dev_err (&peripheral->dev,"Write failed @%#x..%#x:%d\n" , - reg, reg + bytes -1 , ret); +while (val_size >sizeof (swab_buf)) { +cs35l56_swab_copy (swab_buf, val_buf,sizeof (swab_buf)); + ret =regmap_raw_write (cs35l56->sdw_bus_regmap, reg_addr, + swab_buf,sizeof (swab_buf)); +if (ret)return ret; - } - val_size -= bytes; - reg += bytes; - src_be += bytes; + val_size -=sizeof (swab_buf); + reg_addr +=sizeof (swab_buf); + val_buf +=sizeof (swab_buf); } -return 0 ; +if (val_size ==0 ) +return 0 ; + +cs35l56_swab_copy (swab_buf, val_buf, val_size); + +return regmap_raw_write (cs35l56->sdw_bus_regmap, reg_addr, swab_buf, val_size); }static int cs35l56_sdw_write (void *context,const void *val_buf,size_t val_size)
@@ -226,7 +172,7 @@ static int cs35l56_sdw_write(void *context, const void *val_buf, size_t val_size* byte controls always have the same byte order, and firmware file blobs * can be written verbatim. */ -static const struct regmap_bus cs35l56_regmap_bus_sdw = { +static const struct regmap_bus cs35l56_regmap_swab_bus_sdw = { .read = cs35l56_sdw_read, .write = cs35l56_sdw_write, .gather_write = cs35l56_sdw_gather_write,
@@ -234,6 +180,18 @@ static const struct regmap_bus cs35l56_regmap_bus_sdw = { .val_format_endian_default = REGMAP_ENDIAN_BIG, }; +/* Low-level SoundWire regmap to transfer the data over the bus */ +static const struct regmap_config cs35l56_sdw_bus_regmap = { + .name ="sdw-le32" , + .reg_bits =32 , + .val_bits =32 , + .reg_stride =4 , + .reg_format_endian =REGMAP_ENDIAN_LITTLE , + .val_format_endian =REGMAP_ENDIAN_LITTLE , + .max_register =CS35L56_DSP1_PMEM_5114 +0x8000 , + .cache_type =REGCACHE_NONE , +}; +static int cs35l56_sdw_get_unique_id (struct cs35l56_private *cs35l56) {int ret;
@@ -555,8 +513,16 @@ static int cs35l56_sdw_probe(struct sdw_slave *peripheral, const struct sdw_devi cs35l56->base.type = ((unsigned int )id->driver_data) &0xff ; - cs35l56->base.regmap =devm_regmap_init (dev, &cs35l56_regmap_bus_sdw, - peripheral, regmap_config); +/* Low-level regmap to transfer read/writes over SoundWire bus */ + cs35l56->sdw_bus_regmap =devm_regmap_init_sdw (peripheral, &cs35l56_sdw_bus_regmap); +if (IS_ERR (cs35l56->sdw_bus_regmap)) { + ret =PTR_ERR (cs35l56->sdw_bus_regmap); +return dev_err_probe (dev, ret,"Failed to allocate bus register map\n" ); + } + +/* Wrapper regmap to simulate big-endian ordering */ + cs35l56->base.regmap =devm_regmap_init (dev, &cs35l56_regmap_swab_bus_sdw, + peripheral, regmap_config);if (IS_ERR (cs35l56->base.regmap)) { ret =PTR_ERR (cs35l56->base.regmap);return dev_err_probe (dev, ret,"Failed to allocate register map\n" );
sound/soc/codecs/cs35l56.h +1 -0
@@ -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
Mark Brown
maintainerRe: [PATCH 2/2] ASoC: cs35l56: Use standard SoundWire regmap implementation
sound/soc/codecs/cs35l56-sdw.c static int cs35l56_sdw_probe(struct sdw_slave *peripheral, const struct sdw_devi · line 521
Quoted 11 lines · Richard Fitzgerald
Use the
regmap_sdwimplementation for SoundWire instead of re-implementing the low-level bus transactions incs35l56-sdw.csound/soc/codecs/cs35l56-sdw.c +6
-2- cs35l56->base.regmap =devm_regmap_init (dev, &cs35l56_regmap_bus_sdw, - peripheral, regmap_config); +/* Low-level regmap to transfer read/writes over SoundWire bus */ + cs35l56->sdw_bus_regmap =devm_regmap_init_sdw (peripheral, &cs35l56_sdw_bus_regmap); +if (IS_ERR (cs35l56->sdw_bus_regmap)) { + ret =PTR_ERR (cs35l56->sdw_bus_regmap); +return dev_err_probe (dev, ret,"Failed to allocate bus register map\n" ); + }
This means an update is needed to select REGMAP_SOUNDWIRE instead of REGMAP.