Linux Sound subsystem development
 help / color / mirror / Atom feed
* [PATCH v1] ASoC: tas2781: read TAS2573 status registers by entry length
@ 2026-11-27  4:28 Shenghao Ding
  2026-11-27  4:38 ` sashiko-bot
  0 siblings, 1 reply; 2+ messages in thread
From: Shenghao Ding @ 2026-11-27  4:28 UTC (permalink / raw)
  To: broonie
  Cc: tiwai, 13916275206, perex, lgirdwood, linux-sound, baojun.xu,
	k-lu, Shenghao Ding

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.

Signed-off-by: Shenghao Ding <shenghao-ding@ti.com>
---
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(-)

diff --git a/include/sound/tas2573-reg.h b/include/sound/tas2573-reg.h
index 6f8411c695eb..b23d14b93319 100644
--- a/include/sound/tas2573-reg.h
+++ b/include/sound/tas2573-reg.h
@@ -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(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
diff --git a/sound/soc/codecs/tas2781-i2c.c b/sound/soc/codecs/tas2781-i2c.c
index 2dbbd13f5e81..f59be9d7ac31 100644
--- a/sound/soc/codecs/tas2781-i2c.c
+++ b/sound/soc/codecs/tas2781-i2c.c
@@ -1549,7 +1549,8 @@ static int create_tas2781_cali_start_ktrl(struct tasdevice_priv
  * pack the results into a report.
  */
 static int tas2573_status_get_common(struct snd_kcontrol *kcontrol,
-	struct snd_ctl_elem_value *ucontrol, const struct tasdev_reg_map *map)
+	struct snd_ctl_elem_value *ucontrol,
+	const struct tasdev_reg_table *map)
 {
 	struct snd_soc_component *comp = snd_kcontrol_chip(kcontrol);
 	struct tasdevice_priv *priv = snd_soc_component_get_drvdata(comp);
@@ -1565,40 +1566,45 @@ static int tas2573_status_get_common(struct snd_kcontrol *kcontrol,
 	dst[i++] = 'r';
 
 	/* Emit book/page/reg triplets for every register in the map */
-	for (j = 0; j < map->nregs; j++) {
-		dst[i++] = TASDEVICE_BOOK_ID(map->regs[j]);
-		dst[i++] = TASDEVICE_PAGE_ID(map->regs[j]);
-		dst[i++] = TASDEVICE_PAGE_REG(map->regs[j]);
+	for (j = 0; j < map->nentries; j++) {
+		dst[i++] = TASDEVICE_BOOK_ID(map->entries[j].reg);
+		dst[i++] = TASDEVICE_PAGE_ID(map->entries[j].reg);
+		dst[i++] = TASDEVICE_PAGE_REG(map->entries[j].reg);
 	}
 	dst[i++] = 'D';
 
 	guard(mutex)(&priv->codec_lock);
 
 	/*
-	 * Read each channel: first register via single read, the rest
-	 * via bulk read (4 bytes each).
+	 * Dump per-channel status to dst: channel index followed by one
+	 * 4-byte slot per entry, bulk read when val_len is 4, single-byte
+	 * read otherwise.
 	 */
 	for (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,
+					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;
+				else
+					dev_err(priv->dev,
+						"chn %d %s rd err = %d\n", j,
+						map->tag, rc);
+			}
 		}
 	}
 
@@ -1638,8 +1644,8 @@ static int create_tas2573_cali_status_ktrl(struct tasdevice_priv
 	 *		Sine gain for Device #i (48 bytes)
 	 *	}
 	 */
-	ext_cali_start->max = calib_status_map.nregs * 3 + 3 +
-		priv->ndev * (calib_status_map.nregs * 4 + 1);
+	ext_cali_start->max = calib_status_map.nentries * 3 + 3 +
+		priv->ndev * (calib_status_map.nentries * 4 + 1);
 	cali_ctrl->name = cali_start_name;
 	cali_ctrl->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
 	cali_ctrl->info = snd_soc_bytes_info_ext;
@@ -1685,8 +1691,8 @@ static int create_tas2573_rt_spk_data_ktrl(struct tasdevice_priv
 	 *		real-time spk data for Device #i (28 bytes)
 	 *	}
 	 */
-	ext_cali_start->max = tas2573_rt_data_map.nregs * 3 + 3 +
-		priv->ndev * (tas2573_rt_data_map.nregs * 4 + 1);
+	ext_cali_start->max = tas2573_rt_data_map.nentries * 3 + 3 +
+		priv->ndev * (tas2573_rt_data_map.nentries * 4 + 1);
 	cali_ctrl->name = cali_start_name;
 	cali_ctrl->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
 	cali_ctrl->info = snd_soc_bytes_info_ext;
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-11-27  4:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27  4:28 [PATCH v1] ASoC: tas2781: read TAS2573 status registers by entry length Shenghao Ding
2026-11-27  4:38 ` sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox