ASoC: tas2781: read TAS2573 status registers by entry length
Subsystems (3)
Shenghao Ding
maintainerPATCH v2 1/1 ASoC: tas2781: read TAS2573 status registers by entry length
The TAS2573 status kcontrols read registers through a shared descriptor that assumes the first register is one byte and all others are four bytes. The assumption is position dependent, so a one-byte register can only be described by moving it to the front of the table.
Make the width explicit by replacing the address array with entries that carry their own access width.
---
v2:
- TAS2573_FCT_INT_LATCH was registered with the wrong entry macro; use TASDEV_REG_ENTRY_B1() since it is a one-byte register.
v1:
- Convert the register descriptor used by the TAS2573 calibration and real-time speaker protection kcontrols from a plain array of register addresses into an explicit table of entries that carry their own access width.
- Two helper macros, TASDEV_REG_ENTRY() and TASDEV_REG_ENTRY_B1(), keep the tables readable for 4-byte and 1-byte entries respectively.
- Now that each register entry knows its access width, drop the implicit "the first register is one byte, all the rest are four bytes" rule in tas2573_status_get_common() and select the access method per entry from val_len.
--- include/sound/tas2573-reg.h | 78 +++++++++++++++++++--------------- sound/soc/codecs/tas2781-i2c.c | 66 +++++++++++++++------------- 2 files changed, 80 insertions(+), 64 deletions(-)
include/sound/tas2573-reg.h +44 -34
@@ -14,16 +14,25 @@#ifndef __TAS2573_REG_H__#define __TAS2573_REG_H__ +/* Descriptor of a single register field: address plus value length. */ +struct tasdev_reg_entry { +const unsigned int reg; +const unsigned char val_len; +}; +/* -* Register map descriptor: binds the register table, its length, and the log -* tag together into a single argument. +* A named group of register fields accessed together. Each entry occupies +* a fixed 4-byte slot in the userspace report, regardless of val_len. */ -struct tasdev_reg_map { -const unsigned int *regs; -unsigned int nregs; +struct tasdev_reg_table { +const struct tasdev_reg_entry *entries; +unsigned int nentries;const char *tag; }; +#define TASDEV_REG_ENTRY (regid) { .reg = (regid), .val_len = 4 } +#define TASDEV_REG_ENTRY_B1 (regid) { .reg = (regid), .val_len = 1 } +#define TAS2573_TDM_DET_REG TASDEVICE_REG(0x00, 0x00, 0x14)#define TAS2573_FCT_INT_LATCH TASDEVICE_REG(0x00, 0x00, 0x67)/* YM57 */
@@ -59,41 +68,42 @@ struct tasdev_reg_map {/* YM955 */ #define TAS2573_SHORTCKT TASDEVICE_REG(0x00, 0x83, 0x6C) -/* Registers for the speaker calibration */ -static const __maybe_unused unsigned int fct_status_regs[] = { -TAS2573_FCT_INT_LATCH , -TAS2573_FCT_STATUS_CTRL , -TAS2573_FCT_STATUS_BINNING , -TAS2573_SILENCE_DETECTED , -TAS2573_OPEN_CIRCUIT , -TAS2573_SHORTCKT , -TAS2573_FCT_OUTPUT_R0 , -TAS2573_FCT_OUTPUT_R0_LOW , -TAS2573_FCT_OUTPUT_INV_R0 , -TAS2573_FCT_OUTPUT_POWERTOT , -TAS2573_FCT_OUTPUT_F0 , -TAS2573_RE_OUT , +/* Register Array for the speaker calibration */ +static const __maybe_unused struct tasdev_reg_entry fct_status_regs[] = { +TASDEV_REG_ENTRY_B1 (TAS2573_FCT_INT_LATCH ), +TASDEV_REG_ENTRY (TAS2573_FCT_STATUS_CTRL ), +TASDEV_REG_ENTRY (TAS2573_FCT_STATUS_BINNING ), +TASDEV_REG_ENTRY (TAS2573_SILENCE_DETECTED ), +TASDEV_REG_ENTRY (TAS2573_OPEN_CIRCUIT ), +TASDEV_REG_ENTRY (TAS2573_SHORTCKT ), +TASDEV_REG_ENTRY (TAS2573_FCT_OUTPUT_R0 ), +TASDEV_REG_ENTRY (TAS2573_FCT_OUTPUT_R0_LOW ), +TASDEV_REG_ENTRY (TAS2573_FCT_OUTPUT_INV_R0 ), +TASDEV_REG_ENTRY (TAS2573_FCT_OUTPUT_POWERTOT ), +TASDEV_REG_ENTRY (TAS2573_FCT_OUTPUT_F0 ), +TASDEV_REG_ENTRY (TAS2573_RE_OUT ), }; -static const __maybe_unused struct tasdev_reg_map calib_status_map = { - .regs = fct_status_regs, - .nregs =ARRAY_SIZE (fct_status_regs), +static const __maybe_unused struct tasdev_reg_table calib_status_map = { + .entries = fct_status_regs, + .nentries =ARRAY_SIZE (fct_status_regs), .tag ="fct_status_regs" , }; -/* Registers for the realtime (RT) speaker protection data */ -static const __maybe_unused unsigned int tas2573_rt_data_regs[] = { -TAS2573_TDM_DET_REG , -TAS2573_SPK_COIL_TEMPERATURE , -TAS2573_RE_OUT , -TAS2573_A1_OUT , -TAS2573_A2_OUT , -TAS2573_EXCURSION_GAIN , -TAS2573_THERMAL_GAIN , +/* Register Array for the realtime (RT) speaker protection data */ +static const __maybe_unused struct tasdev_reg_entry tas2573_rt_data_regs[] = { +TASDEV_REG_ENTRY_B1 (TAS2573_TDM_DET_REG ), +TASDEV_REG_ENTRY (TAS2573_SPK_COIL_TEMPERATURE ), +TASDEV_REG_ENTRY (TAS2573_RE_OUT ), +TASDEV_REG_ENTRY (TAS2573_A1_OUT ), +TASDEV_REG_ENTRY (TAS2573_A2_OUT ), +TASDEV_REG_ENTRY (TAS2573_EXCURSION_GAIN ), +TASDEV_REG_ENTRY (TAS2573_THERMAL_GAIN ), }; -static const __maybe_unused struct tasdev_reg_map tas2573_rt_data_map = { - .regs = tas2573_rt_data_regs, - .nregs =ARRAY_SIZE (tas2573_rt_data_regs), + +static const __maybe_unused struct tasdev_reg_table tas2573_rt_data_map = { + .entries = tas2573_rt_data_regs, + .nentries =ARRAY_SIZE (tas2573_rt_data_regs), .tag ="tas2573_rt_data_regs" , };#endif
sound/soc/codecs/tas2781-i2c.c +36 -30
99 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] ASoC: tas2781: wrong 1-byte value offset in tas2573_status_get_common() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] ASoC: tas2781: wrong 1-byte value offset in tas2573_status_get_common()
--
commit b7312ae4413018d2f0f76879de67e7c18a9d032d
Author: Shenghao Ding <[email protected]>
ASoC: tas2781: read TAS2573 status registers by entry length
This commit replaces the plain register address arrays for TAS2573 status controls with entry descriptors that specify each register's access width.
Quoted 4 lines
sound/soc/codecs/tas2781-i2c.c +0
-0
[ ... ]
Quoted 1 line
sound/soc/codecs/tas2781-i2c.c +0
-0@@ -1565,40 +1566,45 @@ static int tas2573_status_get_common(struct snd_kcontrol *kcontrol,
[ ... ]
Quoted 29 lines
sound/soc/codecs/tas2781-i2c.c +8
-19for (j =0 ; j < priv->ndev; j++) { dst[i++] = j; - dst[i++] =0 ; - dst[i++] =0 ; - dst[i++] =0 ; - - rc =tasdevice_dev_read (priv, j, map->regs[0 ], &val); -if (rc <0 ) -dev_err (priv->dev, -"chn %d %s[0] rd err = %d\n" , - j, map->tag, rc); -else - dst[i++] = val; - -for (k =1 ; k < map->nregs; k++, i +=4 ) { - rc =tasdevice_dev_bulk_read (priv, j, map->regs[k], - &dst[i],4 ); -if (rc <0 ) -dev_err (priv->dev, -"chn %d %s[%u] bulk_rd err = %d\n" , - j, map->tag, k, rc); +for (k =0 ; k < map->nentries; k++, i +=4 ) { + dst[i] =0 ; + dst[i +1 ] =0 ; + dst[i +2 ] =0 ; + dst[i +3 ] =0 ; + +if (map->entries[k].val_len ==4 ) { + rc = tasdevice_dev_bulk_read(priv, j,
sound/soc/codecs/tas2781-i2c.c static int tas2573_status_get_common(struct snd_kcontrol *kcontrol, · line 1602
Quoted 10 lines
sound/soc/codecs/tas2781-i2c.c +10
-0+ map->entries[k].reg, &dst[i], 4); +if (rc <0 ) +dev_err (priv->dev, +"chn %d %s[%u] bulk_read err = %d\n" , + j, map->tag, k, rc); + }else { + rc =tasdevice_dev_read (priv, j, + map->entries[k].reg, &val); +if (!rc) + dst[i] = val;
[Severity: Medium]
Should the single-byte read branch write to dst[i + 3] instead of dst[i]? Previously i was post-incremented three times while zeroing the leading bytes, so val was placed in the fourth byte ({0, 0, 0, val}); writing dst[i] = val changes the 4-byte slot layout returned to userspace to {val, 0, 0, 0}.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Mark Brown
maintainerQuoted 1 line · Shenghao Ding
ASoC: tas2781: read TAS2573 status registers by entry length
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.5
Thanks!
[1/1] ASoC: tas2781: read TAS2573 status registers by entry length
https://git.kernel.org/broonie/sound/c/693643ea8035
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