Skip to contentSkip to conversation

ALSA: hda/tas2781: Fix the order of TAS2781 calibrated-data

PATCH Superseded Shenghao Ding 2 participants 3 messages Sep 6, 2025 – Sep 7, 2025 Sound

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 ALSA: hda/tas2781: Fix the order of TAS2781 calibrated-data

A bug reported by one of my customers that the order of TAS2781 calibrated-data is incorrect, the correct way is to move R0_Low and insert it between R0 and InvR0.

Fixes 4fe238513407 ("ALSA: hda/tas2781: Move and unified the calibrated-data getting function for SPI and I2C into the tas2781_hda lib")

---
v3:
- Take Tiwai's advice on cali_cnv() to make it more simpler.
v2:
- Submit to sound branch maintianed by Tiwai instead of linux-next branch
- Drop other fix

---
 sound/hda/codecs/side-codecs/tas2781_hda.c | 25 +++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
sound/hda/codecs/side-codecs/tas2781_hda.c +20 -5
index f46d2e06c64f..f4a44c6b0234 100644
@@ -33,6 +33,23 @@ const efi_guid_t tasdev_fct_efi_guid[] = {
 };
 EXPORT_SYMBOL_NS_GPL(tasdev_fct_efi_guid, "SND_HDA_SCODEC_TAS2781");
 
+/*
+ * The order of calibrated-data writing function is a bit different from the
+ * order in UEFI. Here is the conversion to match the order of calibrated-data
+ * writing function.
+ */
+static void cali_cnv(unsigned char *data, unsigned int base, int offset)
+{
+	struct cali_reg reg_data;
+
+	memcpy(&reg_data, data, sizeof(reg_data));
+	/* the data order has to be swapped between r0_low_reg and inv0_reg */
+	swap(reg_data.r0_low_reg, reg_data.invr0_reg);
+
+	cpu_to_be32_array((__force __be32 *)(data + offset + 1),
+		(u32 *)&reg_data, TASDEV_CALIB_N);
+}
+
 static void tas2781_apply_calib(struct tasdevice_priv *p)
 {
 	struct calidata *cali_data = &p->cali_data;
@@ -103,8 +120,7 @@ static void tas2781_apply_calib(struct tasdevice_priv *p)
 
 				data[l] = k;
 				oft++;
-				for (i = 0; i < TASDEV_CALIB_N * 4; i++)
-					data[l + i + 1] = data[4 * oft + i];
+				cali_cnv(data, 4 * oft, l);
 				k++;
 			}
 		}
@@ -130,9 +146,8 @@ static void tas2781_apply_calib(struct tasdevice_priv *p)
 
 		for (j = p->ndev - 1; j >= 0; j--) {
 			l = j * (cali_data->cali_dat_sz_per_dev + 1);
-			for (i = TASDEV_CALIB_N * 4; i > 0 ; i--)
-				data[l + i] = data[p->index * 5 + i];
-			data[l+i] = j;
+			cali_cnv(data, cali_data->cali_dat_sz_per_dev * j, l);
+			data[l] = j;
 		}
 	}
 
Signature · 1 line
2.43.0
#1 lore raw

Hi Shenghao,

Quoted 22 lines · Shenghao Ding

A bug reported by one of my customers that the order of TAS2781 calibrated-data is incorrect, the correct way is to move R0_Low and insert it between R0 and InvR0.

Fixes 4fe238513407 ("ALSA: hda/tas2781: Move and unified the calibrated-data getting function for SPI and I2C into the tas2781_hda lib")

---
v3:
- Take Tiwai's advice on cali_cnv() to make it more simpler.
v2:
- Submit to sound branch maintianed by Tiwai instead of linux-next branch
- Drop other fix

---
 sound/hda/codecs/side-codecs/tas2781_hda.c | 25 +++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
sound/hda/codecs/side-codecs/tas2781_hda.c +0 -0
index f46d2e06c64f..f4a44c6b0234 100644

sound/hda/codecs/side-codecs/tas2781_hda.c const efi_guid_t tasdev_fct_efi_guid[] = { · line 41

Quoted 9 lines
sound/hda/codecs/side-codecs/tas2781_hda.c +6 -0
@@ -33,6 +33,23 @@ const efi_guid_t tasdev_fct_efi_guid[] = {
 };
 EXPORT_SYMBOL_NS_GPL(tasdev_fct_efi_guid, "SND_HDA_SCODEC_TAS2781");
 
+/*
+ * The order of calibrated-data writing function is a bit different from the
+ * order in UEFI. Here is the conversion to match the order of calibrated-data
+ * writing function.
+ */
+static void cali_cnv(unsigned char *data, unsigned int base, int offset)

unused base?

sound/hda/codecs/side-codecs/tas2781_hda.c const efi_guid_t tasdev_fct_efi_guid[] = { · line 45

Quoted 4 lines
sound/hda/codecs/side-codecs/tas2781_hda.c +4 -0
+{
+	struct cali_reg reg_data;
+
+	memcpy(&reg_data, data, sizeof(reg_data));

data points to cali_data?

Quoted 22 lines
sound/hda/codecs/side-codecs/tas2781_hda.c +8 -2
+	/* the data order has to be swapped between r0_low_reg and inv0_reg */
+	swap(reg_data.r0_low_reg, reg_data.invr0_reg);
+
+	cpu_to_be32_array((__force __be32 *)(data + offset + 1),
+		(u32 *)&reg_data, TASDEV_CALIB_N);
+}
+
 static void tas2781_apply_calib(struct tasdevice_priv *p)
 {
 	struct calidata *cali_data = &p->cali_data;
@@ -103,8 +120,7 @@ static void tas2781_apply_calib(struct tasdevice_priv *p)
 
 				data[l] = k;
 				oft++;
-				for (i = 0; i < TASDEV_CALIB_N * 4; i++)
-					data[l + i + 1] = data[4 * oft + i];
+				cali_cnv(data, 4 * oft, l);
 				k++;
 			}
 		}
@@ -130,9 +146,8 @@ static void tas2781_apply_calib(struct tasdevice_priv *p)
 

sound/hda/codecs/side-codecs/tas2781_hda.c static void tas2781_apply_calib(struct tasdevice_priv *p) · line 153

Quoted 10 lines
sound/hda/codecs/side-codecs/tas2781_hda.c +2 -3
 		for (j = p->ndev - 1; j >= 0; j--) {
 			l = j * (cali_data->cali_dat_sz_per_dev + 1);
-			for (i = TASDEV_CALIB_N * 4; i > 0 ; i--)
-				data[l + i] = data[p->index * 5 + i];
-			data[l+i] = j;
+			cali_cnv(data, cali_data->cali_dat_sz_per_dev * j, l);
+			data[l] = j;
 		}
 	}
 

Gergo

#2 lore raw

Thanks for your comment, I will prepare a new patch soon.

Quoted 70 lines

-----Original Message-----
From: Gergo Koteles <[email protected]>
Sent: Saturday, September 6, 2025 8:13 PM
To: Ding, Shenghao <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; alsa-devel@alsa- project.org; [email protected]; Xu, Baojun <[email protected]>; [email protected]
Subject: [EXTERNAL] Re: [PATCH v3] ALSA: hda/tas2781: Fix the order of TAS2781 calibrated-data

Hi Shenghao, On Sat, 2025-09-06 at 17: 19 +0800, Shenghao Ding wrote: > A bug reported by one of my customers that the order of TAS2781 > calibrated-data is incorrect, the correct way is to move R0_Low > and insert it between R0 and ZjQcmQRYFpfptBannerStart This message was sent from outside of Texas Instruments.
Do not click links or open attachments unless you recognize the source of this email and know the content is safe.
<https://us-phishalarm-
ewt.proofpoint.com/EWT/v1/G3vK!uldgPTePPA3xaizufNmp9kStdEQS36lcAc9Q wr41j6O4ieidIV-4ba5O3e2zdceeW_86IkqVuODKMJ11ZYqjt- Y4PnTTtX6uNRJ38dLuTVI$>
Report Suspicious

ZjQcmQRYFpfptBannerEnd
Hi Shenghao,

Quoted 27 lines · Shenghao Ding

A bug reported by one of my customers that the order of TAS2781 calibrated-data is incorrect, the correct way is to move R0_Low and insert it between R0 and InvR0.

Fixes 4fe238513407 ("ALSA: hda/tas2781: Move and unified the

calibrated-data getting function for SPI and I2C into the tas2781_hda lib")

---
v3:
- Take Tiwai's advice on cali_cnv() to make it more simpler.
v2:
- Submit to the sound branch maintained by Tiwai instead of linux-next
branch
- Drop other fix

---
 sound/hda/codecs/side-codecs/tas2781_hda.c | 25
+++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
sound/hda/codecs/side-codecs/tas2781_hda.c +0 -0
index f46d2e06c64f..f4a44c6b0234 100644

sound/hda/codecs/side-codecs/tas2781_hda.c const efi_guid_t tasdev_fct_efi_guid[] = { }; · line 33

Quoted 1 line
sound/hda/codecs/side-codecs/tas2781_hda.c +0 -0
@@ -33,6 +33,23 @@ const efi_guid_t tasdev_fct_efi_guid[] = {  };
 EXPORT_SYMBOL_NS_GPL(tasdev_fct_efi_guid,

"SND_HDA_SCODEC_TAS2781");

sound/hda/codecs/side-codecs/tas2781_hda.c const efi_guid_t tasdev_fct_efi_guid[] = { }; · line 42

Quoted 10 lines
sound/hda/codecs/side-codecs/tas2781_hda.c +9 -0
+/*
+ * The order of calibrated-data writing function is a bit different
+from the
+ * order in UEFI. Here is the conversion to match the order of
+calibrated-data
+ * writing function.
+ */
+static void cali_cnv(unsigned char *data, unsigned int base, int
+offset)

unused base?

Quoted 6 lines

sound/hda/codecs/side-codecs/tas2781_hda.c const efi_guid_t tasdev_fct_efi_guid[] = { · line 45

Quoted 4 lines
sound/hda/codecs/side-codecs/tas2781_hda.c +4 -0
+{
+	struct cali_reg reg_data;
+
+	memcpy(&reg_data, data, sizeof(reg_data));

data points to cali_data?

it should add base
memcpy(&reg_data, &data[base], sizeof(reg_data));

Quoted 36 lines

sound/hda/codecs/side-codecs/tas2781_hda.c const efi_guid_t tasdev_fct_efi_guid[] = { }; · line 47

Quoted 2 lines
sound/hda/codecs/side-codecs/tas2781_hda.c +1 -0
+	/* the data order has to be swapped between r0_low_reg and inv0_reg

*/

Quoted 21 lines
sound/hda/codecs/side-codecs/tas2781_hda.c +6 -0
+	swap(reg_data.r0_low_reg, reg_data.invr0_reg);
+
+	cpu_to_be32_array((__force __be32 *)(data + offset + 1),
+		(u32 *)&reg_data, TASDEV_CALIB_N);
+}
+
 static void tas2781_apply_calib(struct tasdevice_priv *p)  {
 	struct calidata *cali_data = &p->cali_data; @@ -103,8 +120,7 @@

static void tas2781_apply_calib(struct tasdevice_priv *p)

sound/hda/codecs/side-codecs/tas2781_hda.c +1 -2
 				data[l] = k;
 				oft++;
-				for (i = 0; i < TASDEV_CALIB_N * 4; i++)
-					data[l + i + 1] = data[4 * oft + i];
+				cali_cnv(data, 4 * oft, l);
 				k++;
 			}
 		}
@@ -130,9 +146,8 @@ static void tas2781_apply_calib(struct
 tasdevice_priv *p)

sound/hda/codecs/side-codecs/tas2781_hda.c static void tas2781_apply_calib(struct · line 153

Quoted 10 lines
sound/hda/codecs/side-codecs/tas2781_hda.c +2 -3
 
 		for (j = p->ndev - 1; j >= 0; j--) {
 			l = j * (cali_data->cali_dat_sz_per_dev + 1);
-			for (i = TASDEV_CALIB_N * 4; i > 0 ; i--)
-				data[l + i] = data[p->index * 5 + i];
-			data[l+i] = j;
+			cali_cnv(data, cali_data->cali_dat_sz_per_dev * j, l);
+			data[l] = j;
 		}
 	}

Gergo