* [PATCH v1] ASoC: tas2781: add realtime speaker protection data control for TAS2573
@ 2026-11-19 1:11 Shenghao Ding
2026-11-19 1:23 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Shenghao Ding @ 2026-11-19 1:11 UTC (permalink / raw)
To: broonie
Cc: tiwai, 13916275206, perex, lgirdwood, linux-sound, baojun.xu,
k-lu, Shenghao Ding
The existing "Real-time Speaker Impedance" control only reports the
re output of each device. Customers need more realtime speaker
protection data, so extend the control to a group of registers
(TDM detection, coil temperature, Re/A1/A2 output, excursion gain
and thermal gain) and rename it to "Real-time Speaker Protection
Data". No functional change for the reported registers, only more data
is exposed.
Signed-off-by: Shenghao Ding <shenghao-ding@ti.com>
---
v1:
- Introduce struct tasdev_reg_map to bind a register table with its
length and a log tag, and refactor the register-reading logic into
tas2573_status_get_common() so other controls can reuse it.
- Extend the control to a group of registers (TDM detection, coil
temperature, Re/A1/A2 output, excursion gain and thermal gain)
and rename it to "Real-time Speaker Protection Data".
---
include/sound/tas2573-reg.h | 25 +++++++++++
sound/soc/codecs/tas2781-i2c.c | 80 ++++++++++++++++++++++++----------
2 files changed, 83 insertions(+), 22 deletions(-)
diff --git a/include/sound/tas2573-reg.h b/include/sound/tas2573-reg.h
index 02c9a2fcccfa..4fedc8a3329e 100644
--- a/include/sound/tas2573-reg.h
+++ b/include/sound/tas2573-reg.h
@@ -14,6 +14,16 @@
#ifndef __TAS2573_REG_H__
#define __TAS2573_REG_H__
+/*
+ * Register map descriptor: binds the register table, its length, and the log
+ * tag together into a single argument.
+ */
+struct tasdev_reg_map {
+ const unsigned int *regs;
+ unsigned int nregs;
+ const char *tag;
+};
+
#define TAS2573_TDM_DET_REG TASDEVICE_REG(0x00, 0x00, 0x14)
#define TAS2573_FCT_INT_LATCH TASDEVICE_REG(0x00, 0x00, 0x67)
/* YM57 */
@@ -49,4 +59,19 @@
/* YM955 */
#define TAS2573_SHORTCKT TASDEVICE_REG(0x00, 0x83, 0x6C)
+/* 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,
+};
+static const __maybe_unused struct tasdev_reg_map tas2573_rt_data_map = {
+ .regs = tas2573_rt_data_regs,
+ .nregs = 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 984cb67476a5..e44a1d460c70 100644
--- a/sound/soc/codecs/tas2781-i2c.c
+++ b/sound/soc/codecs/tas2781-i2c.c
@@ -1544,37 +1544,62 @@ static int create_tas2781_cali_start_ktrl(struct tasdevice_priv
return 0;
}
-static int tas2573_re_get(struct snd_kcontrol *kcontrol,
- struct snd_ctl_elem_value *ucontrol)
+/*
+ * Common helper: shared by all controls that read a group of registers and
+ * 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_soc_component *comp = snd_kcontrol_chip(kcontrol);
struct tasdevice_priv *priv = snd_soc_component_get_drvdata(comp);
unsigned char *dst = ucontrol->value.bytes.data;
struct soc_bytes_ext *bytes_ext =
- (struct soc_bytes_ext *) kcontrol->private_value;
+ (struct soc_bytes_ext *)kcontrol->private_value;
+ unsigned int j, k, val;
unsigned int i = 0;
- unsigned int j;
int rc;
- guard(mutex)(&priv->codec_lock);
+ /* Report header: max size and 'r' marker */
dst[i++] = bytes_ext->max;
dst[i++] = 'r';
- dst[i++] = TASDEVICE_BOOK_ID(TAS2573_RE_OUT);
- dst[i++] = TASDEVICE_PAGE_ID(TAS2573_RE_OUT);
- dst[i++] = TASDEVICE_PAGE_REG(TAS2573_RE_OUT);
-
+ /* 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]);
+ }
dst[i++] = 'D';
+ guard(mutex)(&priv->codec_lock);
+
+ /*
+ * Read each channel: first register via single read, the rest
+ * via bulk read (4 bytes each).
+ */
for (j = 0; j < priv->ndev; j++) {
dst[i++] = j;
+ dst[i++] = 0;
+ dst[i++] = 0;
+ dst[i++] = 0;
- rc = tasdevice_dev_bulk_read(priv, j, TAS2573_RE_OUT,
- &dst[i], 4);
+ rc = tasdevice_dev_read(priv, j, map->regs[0], &val);
if (rc < 0)
- dev_err(priv->dev, "chn %d bulk_rd err = %d\n", j, rc);
+ dev_err(priv->dev,
+ "chn %d %s[0] rd err = %d\n",
+ j, map->tag, rc);
+ else
+ dst[i++] = val;
- i += 4;
+ 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);
+ }
}
return 0;
@@ -1682,37 +1707,48 @@ static int create_tas2573_cali_status_ktrl(struct tasdevice_priv
return 0;
}
-static int create_tas2573_cali_re_ktrl(struct tasdevice_priv
+/* Realtime sp data control */
+static int tas2573_rt_get(struct snd_kcontrol *kcontrol,
+ struct snd_ctl_elem_value *ucontrol)
+{
+ return tas2573_status_get_common(kcontrol, ucontrol,
+ &tas2573_rt_data_map);
+}
+
+static int create_tas2573_rt_spk_data_ktrl(struct tasdevice_priv
*priv, struct snd_kcontrol_new *cali_ctrl)
{
struct soc_bytes_ext *ext_cali_start;
char *cali_start_name;
- ext_cali_start = devm_kzalloc_obj(priv->dev, *ext_cali_start);
+ ext_cali_start = devm_kzalloc(priv->dev,
+ sizeof(*ext_cali_start), GFP_KERNEL);
if (!ext_cali_start)
return -ENOMEM;
cali_start_name = devm_kstrdup(priv->dev,
- "Real-time Speaker Impedance", GFP_KERNEL);
+ "Real-time Speaker Protection Data", GFP_KERNEL);
if (!cali_start_name)
return -ENOMEM;
/*
- * package structure for tas2573 real-time spk impedance:
+ * package structure for tas2573 real-time spk protection data:
* Pkg len (1 byte)
* Reg id (1 byte, constant 'r')
- * book, page, register for fct status (total 3 bytes)
+ * 7 groups of book, page, register for real-time spk_data
+ * (21 bytes)
* Data Start Flag (1 byte, constant 'D')
* for (i = 0; i < Device-Sum; i++) {
* Device #i index_info (1 byte)
- * Sine gain for Device #i (4 bytes)
+ * real-time spk data for Device #i (28 bytes)
* }
*/
- ext_cali_start->max = 6 + priv->ndev * 5;
+ ext_cali_start->max = tas2573_rt_data_map.nregs * 3 + 3 +
+ priv->ndev * (tas2573_rt_data_map.nregs * 4 + 1);
cali_ctrl->name = cali_start_name;
cali_ctrl->iface = SNDRV_CTL_ELEM_IFACE_MIXER;
cali_ctrl->info = snd_soc_bytes_info_ext;
cali_ctrl->put = NULL;
- cali_ctrl->get = tas2573_re_get;
+ cali_ctrl->get = tas2573_rt_get;
cali_ctrl->private_value = (unsigned long)ext_cali_start;
return 0;
@@ -1869,7 +1905,7 @@ static int tasdevice_create_cali_ctrls(struct tasdevice_priv *priv)
if (rc != 0)
return rc;
i++;
- rc = create_tas2573_cali_re_ktrl(priv, &cali_ctrls[i]);
+ rc = create_tas2573_rt_spk_data_ktrl(priv, &cali_ctrls[i]);
if (rc != 0)
return rc;
i++;
--
2.53.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] ASoC: tas2781: add realtime speaker protection data control for TAS2573
2026-11-19 1:11 [PATCH v1] ASoC: tas2781: add realtime speaker protection data control for TAS2573 Shenghao Ding
@ 2026-11-19 1:23 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-19 1:23 UTC (permalink / raw)
To: Shenghao Ding; +Cc: linux-sound
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] ASoC: tas2781: buffer offset shift on error in
tas2573_status_get_common()
- [Low] ASoC: tas2781: duplicate report logic in
tas2573_calib_status_get()
- [Low] ASoC: tas2781: use devm_kzalloc_obj() in
create_tas2573_rt_spk_data_ktrl()
--
commit ab506d198e775a76f5fde0b4b1d45d99fc376412
Author: Shenghao Ding <shenghao-ding@ti.com>
ASoC: tas2781: add realtime speaker protection data control for TAS2573
This commit introduces a common register-map report helper for TAS2573 and
extends the "Real-time Speaker Impedance" control into "Real-time Speaker
Protection Data" covering seven protection registers.
> diff --git a/sound/soc/codecs/tas2781-i2c.c b/sound/soc/codecs/tas2781-i2c.c
> index 984cb67476a53..e44a1d460c703 100644
> --- a/sound/soc/codecs/tas2781-i2c.c
> +++ b/sound/soc/codecs/tas2781-i2c.c
> @@ -1544,37 +1544,62 @@ static int create_tas2781_cali_start_ktrl(struct tasdevice_priv
> return 0;
> }
>
> -static int tas2573_re_get(struct snd_kcontrol *kcontrol,
> - struct snd_ctl_elem_value *ucontrol)
> +/*
> + * Common helper: shared by all controls that read a group of registers and
> + * 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_soc_component *comp = snd_kcontrol_chip(kcontrol);
> struct tasdevice_priv *priv = snd_soc_component_get_drvdata(comp);
> unsigned char *dst = ucontrol->value.bytes.data;
> struct soc_bytes_ext *bytes_ext =
> - (struct soc_bytes_ext *) kcontrol->private_value;
> + (struct soc_bytes_ext *)kcontrol->private_value;
> + unsigned int j, k, val;
> unsigned int i = 0;
> - unsigned int j;
> int rc;
>
> - guard(mutex)(&priv->codec_lock);
> + /* Report header: max size and 'r' marker */
> dst[i++] = bytes_ext->max;
> dst[i++] = 'r';
>
> - dst[i++] = TASDEVICE_BOOK_ID(TAS2573_RE_OUT);
> - dst[i++] = TASDEVICE_PAGE_ID(TAS2573_RE_OUT);
> - dst[i++] = TASDEVICE_PAGE_REG(TAS2573_RE_OUT);
> -
> + /* 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]);
> + }
> dst[i++] = 'D';
>
> + guard(mutex)(&priv->codec_lock);
> +
> + /*
> + * Read each channel: first register via single read, the rest
> + * via bulk read (4 bytes each).
> + */
> for (j = 0; j < priv->ndev; j++) {
> dst[i++] = j;
> + dst[i++] = 0;
> + dst[i++] = 0;
> + dst[i++] = 0;
>
> - rc = tasdevice_dev_bulk_read(priv, j, TAS2573_RE_OUT,
> - &dst[i], 4);
> + rc = tasdevice_dev_read(priv, j, map->regs[0], &val);
> if (rc < 0)
> - dev_err(priv->dev, "chn %d bulk_rd err = %d\n", j, rc);
> + dev_err(priv->dev,
> + "chn %d %s[0] rd err = %d\n",
> + j, map->tag, rc);
> + else
> + dst[i++] = val;
>
> - i += 4;
> + 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);
> + }
> }
>
> return 0;
[Severity: Medium]
Does an error from tasdevice_dev_read() leave i misaligned by one byte in
dst[]?
Unlike the pre-patch tas2573_re_get() and the bulk-read loop below it, the
rc < 0 branch skips incrementing i for the fourth byte of map->regs[0], so
the remaining registers for channel j and all subsequent channels are
written shifted left by one byte in the fixed-layout report buffer.
[Severity: Low]
This isn't a bug, but tas2573_calib_status_get() right below
tas2573_status_get_common() still open-codes an identical copy of this
report-packing and register-reading loop over fct_status_regs[] instead of
using tas2573_status_get_common().
> @@ -1682,37 +1707,48 @@ static int create_tas2573_cali_status_ktrl(struct tasdevice_priv
> return 0;
> }
>
> -static int create_tas2573_cali_re_ktrl(struct tasdevice_priv
> +/* Realtime sp data control */
> +static int tas2573_rt_get(struct snd_kcontrol *kcontrol,
> + struct snd_ctl_elem_value *ucontrol)
> +{
> + return tas2573_status_get_common(kcontrol, ucontrol,
> + &tas2573_rt_data_map);
> +}
> +
> +static int create_tas2573_rt_spk_data_ktrl(struct tasdevice_priv
> *priv, struct snd_kcontrol_new *cali_ctrl)
> {
> struct soc_bytes_ext *ext_cali_start;
> char *cali_start_name;
>
> - ext_cali_start = devm_kzalloc_obj(priv->dev, *ext_cali_start);
> + ext_cali_start = devm_kzalloc(priv->dev,
> + sizeof(*ext_cali_start), GFP_KERNEL);
[Severity: Low]
This reverts the devm_kzalloc_obj() conversion from 4dd10fbbeb9c
("treewide: Convert devm_kmalloc() family to the devm_kmalloc_obj()
family"), diverging from the neighboring kcontrol helpers in this file.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119011102.1790-1-shenghao-ding@ti.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-19 1:23 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 1:11 [PATCH v1] ASoC: tas2781: add realtime speaker protection data control for TAS2573 Shenghao Ding
2026-11-19 1:23 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox