Skip to contentSkip to conversation

ASoc: tas2781: Add Calibration Kcontrols and tas2563 digtial gain for Chromebook

PATCH In review Shenghao Ding 4 participants 7 messages May 22, 2024 – Aug 9, 2024

Subsystems (3)
lore
Share & tools
lore

Shenghao Ding

author maintainer
#0 lore raw

PATCH 1/1 ASoc: tas2781: Add Calibration Kcontrols and tas2563 digtial gain for Chromebook

Calibrated data will be set to default after loading DSP config params, which will cause speaker protection work abnormally. Reload calibrated data after loading DSP config params.

---
v1:
- Changed the copyright year to 2024 in the related files.
- Add CAL_DAT_SZ for calibrated data size.
- Add TAS2563_DVC_LVL for digtial gain kcontrol.
- Add registers for TAS2563 and TAS2781 calibration.
- Add cali_data_restore for regsiter restore after calibration.
- Add is_user_space_calidata to store the flag where the calibrated from, user space or bin file from driver parsing.
- Add TASDEVICE_RCA_FW_OK to support only register setting bin in the device.
- Add tas2563_dvc_table for relationship between tas2563 digtial gains and register values.
- Correct the filename in the header comments of tas2781-comlib.c, tas2781-lib.c --> tas2781-comlib.c.
- tasdevice_chn_switch for chip switch among multiple chips(tas2563 or tas2781)
- Add loading the calibrated values from user space in tasdev_load_calibrated_data
- Correct no dsp no work, it can still work in bypass mode.
- Add calibrated register setting for tas2563&tas2781.
- Add mutex into each kcontrol.
- rename tas2781_force_fwload_get, tas2781_force_fwload_put--> tasdev_force_fwload_get, tasdev_force_fwload_put
- rename tas2781_codec --> tasdev_codec
- define tas2781_snd_control and tas2563_snd_control for volume
- define tas2781_cali_control and tas2563_cali_control for calibration

---
 include/sound/tas2781-dsp.h       |   1 +
 include/sound/tas2781.h           |  92 ++-
 sound/soc/codecs/tas2781-comlib.c |  35 +-
 sound/soc/codecs/tas2781-fmwlib.c |  51 +-
 sound/soc/codecs/tas2781-i2c.c    | 941 +++++++++++++++++++++++++++++-
 5 files changed, 1061 insertions(+), 59 deletions(-)
include/sound/tas2781-dsp.h +1 -0
index 7fba7ea26a4b..74ab6f113029 100644
@@ -121,6 +121,7 @@ enum tasdevice_dsp_fw_state {
 	TASDEVICE_DSP_FW_NONE = 0,
 	TASDEVICE_DSP_FW_PENDING,
 	TASDEVICE_DSP_FW_FAIL,
+	TASDEVICE_RCA_FW_OK,
 	TASDEVICE_DSP_FW_ALL_OK,
 };
 
include/sound/tas2781.h +82 -10

147 lines not on this page · raw message

sound/soc/codecs/tas2781-comlib.c +31 -4
index 3aa81514dad7..9d7b56663b6b 100644
@@ -1,8 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
 //
-// tas2781-lib.c -- TAS2781 Common functions for HDA and ASoC Audio drivers
+// tas2781-comlib.c -- TAS2781 Common functions for HDA and ASoC Audio drivers
 //
-// Copyright 2023 Texas Instruments, Inc.
+// Copyright 2023 - 2024 Texas Instruments, Inc.
 //
 // Author: Shenghao Ding <[email protected]>
 
@@ -89,6 +89,33 @@ static int tasdevice_change_chn_book(struct tasdevice_priv *tas_priv,
 	return ret;
 }
 
+int tasdevice_chn_switch(struct tasdevice_priv *tas_priv,
+	unsigned short chn)
+{
+	struct i2c_client *client = (struct i2c_client *)tas_priv->client;
+	struct tasdevice *tasdev = &tas_priv->tasdevice[chn];
+	struct regmap *map = tas_priv->regmap;
+	int ret;
+
+	if (client->addr != tasdev->dev_addr) {
+		client->addr = tasdev->dev_addr;
+		/* All devices share the same regmap, clear the page
+		 * inside regmap once switching to another device.
+		 * Register 0 at any pages and any books inside tas2781
+		 * is the same one for page-switching.
+		 */
+		ret = regmap_write(map, TASDEVICE_PAGE_SELECT, 0);
+		if (ret < 0) {
+			dev_err(tas_priv->dev, "%s, E=%d\n",
+				__func__, ret);
+			return ret;
+		}
+		return 1;
+	}
+	return 0;
+}
+EXPORT_SYMBOL_GPL(tasdevice_chn_switch);
+
 int tasdevice_dev_read(struct tasdevice_priv *tas_priv,
 	unsigned short chn, unsigned int reg, unsigned int *val)
 {
@@ -254,8 +281,8 @@ void tas2781_reset(struct tasdevice_priv *tas_dev)
 	} else {
 		for (i = 0; i < tas_dev->ndev; i++) {
 			ret = tasdevice_dev_write(tas_dev, i,
-				TAS2781_REG_SWRESET,
-				TAS2781_REG_SWRESET_RESET);
+				TASDEVICE_REG_SWRESET,
+				TASDEVICE_REG_SWRESET_RESET);
 			if (ret < 0)
 				dev_err(tas_dev->dev,
 					"dev %d swreset fail, %d\n",
sound/soc/codecs/tas2781-fmwlib.c +37 -14

88 lines not on this page · raw message

sound/soc/codecs/tas2781-i2c.c +910 -31

1,120 lines not on this page · raw message

Signature · 1 line
2.34.1
#1 lore raw
Quoted 3 lines · Shenghao Ding

Calibrated data will be set to default after loading DSP config params, which will cause speaker protection work abnormally. Reload calibrated data after loading DSP config params.

...

sound/soc/codecs/tas2781-comlib.c line 3

Quoted 2 lines
sound/soc/codecs/tas2781-comlib.c +1 -1
-// tas2781-lib.c -- TAS2781 Common functions for HDA and ASoC Audio drivers
+// tas2781-comlib.c -- TAS2781 Common functions for HDA and ASoC Audio drivers

Please, drop the filename from the file completely, this change is exactly the answer to "why having filename in the file is a bad idea in a long-term".

...

sound/soc/codecs/tas2781-comlib.c static int tasdevice_change_chn_book(struct tasdevice_priv *tas_priv, · line 93

Quoted 2 lines
sound/soc/codecs/tas2781-comlib.c +2 -0
+int tasdevice_chn_switch(struct tasdevice_priv *tas_priv,
+	unsigned short chn)

Pretty much can be on a single line.

sound/soc/codecs/tas2781-comlib.c static int tasdevice_change_chn_book(struct tasdevice_priv *tas_priv, · line 100

Quoted 7 lines
sound/soc/codecs/tas2781-comlib.c +6 -0
+{
+	struct i2c_client *client = (struct i2c_client *)tas_priv->client;
+	struct tasdevice *tasdev = &tas_priv->tasdevice[chn];
+	struct regmap *map = tas_priv->regmap;
+	int ret;
 
+	if (client->addr != tasdev->dev_addr) {

With inverted check this entire function becomes neater.

Quoted 7 lines
sound/soc/codecs/tas2781-comlib.c +7 -0
+		client->addr = tasdev->dev_addr;
+		/* All devices share the same regmap, clear the page
+		 * inside regmap once switching to another device.
+		 * Register 0 at any pages and any books inside tas2781
+		 * is the same one for page-switching.
+		 */
+		ret = regmap_write(map, TASDEVICE_PAGE_SELECT, 0);

sound/soc/codecs/tas2781-comlib.c static int tasdevice_change_chn_book(struct tasdevice_priv *tas_priv, · line 117

Quoted 10 lines
sound/soc/codecs/tas2781-comlib.c +10 -0
+		if (ret < 0) {
+			dev_err(tas_priv->dev, "%s, E=%d\n",
+				__func__, ret);
+			return ret;
+		}
+		return 1;
+	}
+	return 0;
+}
+EXPORT_SYMBOL_GPL(tasdevice_chn_switch);

Is it namespaced? If not would be good to make it so. Also I see that other file uses namespaced exports.

...

sound/soc/codecs/tas2781-fmwlib.c static int tasdevice_load_data(struct tasdevice_priv *tas_priv, · line 2164

Quoted 2 lines
sound/soc/codecs/tas2781-fmwlib.c +2 -0
+	if (!priv->is_user_space_calidata &&
+		cal_fmw) {

With all possible restrictions this can be on a single line besides the fact that the second one currently has a broken indentation.

...

sound/soc/codecs/tas2781-fmwlib.c static int tasdevice_load_data(struct tasdevice_priv *tas_priv, · line 2183

Quoted 1 line
sound/soc/codecs/tas2781-fmwlib.c +1 -0
+				&(data[k + 4 * j]), 4);

How parentheses are helpful here?

Quoted 1 line
(quoted diff) +1 -0
+	}

...

Quoted 1 line

+#include <asm/unaligned.h>

linux/* followed by asm/* as the latter is not so generic as the former.

Quoted 3 lines

#include <linux/crc8.h>
#include <linux/firmware.h>
#include <linux/gpio/consumer.h>

...

sound/soc/codecs/tas2781-i2c.c line 101

Quoted 5 lines
sound/soc/codecs/tas2781-i2c.c +5 -0
+	{
+		.reg = TAS2781_PRM_TEST_57_REG,
+		.val = { 0x14 },
+		.val_len = 1,
+		.is_locked = true

Here and everywhere else in cases like this (when it's not a termination line) leave the trailing comma. It will reduce the churn in case this needs to be expanded in the future.

Quoted 1 line
(quoted diff) +1 -0
+	},

...

sound/soc/codecs/tas2781-i2c.c static int tas2781_digital_getvol(struct snd_kcontrol *kcontrol, · line 207

Quoted 8 lines
sound/soc/codecs/tas2781-i2c.c +6 -1
+	int rc;
+
+	mutex_lock(&tas_priv->codec_lock);
+	rc = tasdevice_digital_getvol(tas_priv, ucontrol, mc);
+	mutex_unlock(&tas_priv->codec_lock);
 
-	return tasdevice_digital_getvol(tas_priv, ucontrol, mc);
+	return rc;

Why not converting to use cleanup.h and this will become a oneliner update. Same Q to all these mutex additions.

...

Review

Quoted 2 lines
(quoted diff) +2 -0
+{
+	struct i2c_client *clt = (struct i2c_client *)tas_priv->client;

Hmm... Why explicit casting? Is the client not void * or the same type?

sound/soc/codecs/tas2781-i2c.c static int tas2781_force_fwload_put(struct snd_kcontrol *kcontrol, · line 323

Quoted 3 lines
sound/soc/codecs/tas2781-i2c.c +2 -0
+	struct tasdevice *tasdev = tas_priv->tasdevice;
 
+	int rc = -1;

Use proper error codes.

sound/soc/codecs/tas2781-i2c.c static int tas2781_force_fwload_put(struct snd_kcontrol *kcontrol, · line 334

Quoted 11 lines
sound/soc/codecs/tas2781-i2c.c +11 -0
+	int i;
+
+	if (data_len != 4)
+		return rc;
+
+	for (i = 0; i < tas_priv->ndev; i++) {
+		if (clt->addr == tasdev[i].dev_addr) {
+			/* First byte is the device index. */
+			dst[0] = i;
+			tasdevice_dev_bulk_read(tas_priv, i, reg, &dst[1],
+				4);

On one line this will be better to read.

Review

Quoted 2 lines
(quoted diff) +2 -0
+			rc = 0;
+			break;

Why not simply

			return 0;

?

Quoted 5 lines
sound/soc/codecs/tas2781-i2c.c +5 -0
+		}
+	}
+
+	return rc;
+}

...

sound/soc/codecs/tas2781-i2c.c static int tas2781_force_fwload_put(struct snd_kcontrol *kcontrol, · line 357

Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2 -0
+	if (tas_priv->chip_id != TAS2781 &&
+		bytes_ext->max != 8 * tas_priv->ndev) {

Here and seems in many places you have broken indentation.

Review

Quoted 1 line
(quoted diff) +1 -0
+		rc = -1;

error code?

sound/soc/codecs/tas2781-i2c.c static int tas2781_force_fwload_put(struct snd_kcontrol *kcontrol, · line 370

Quoted 4 lines
sound/soc/codecs/tas2781-i2c.c +3 -0
+		goto out;
+	}
 
+		for (j = 0; j < sum; j++) {

With a temporary variable for p[j]...

sound/soc/codecs/tas2781-i2c.c static int tas2781_force_fwload_put(struct snd_kcontrol *kcontrol, · line 380

Quoted 10 lines
sound/soc/codecs/tas2781-i2c.c +10 -0
+			if (p[j].val_len == 1) {
+				if (p[j].is_locked)
+					tasdevice_dev_write(tas_priv, i,
+						TAS2781_TEST_UNLOCK_REG,
+						TAS2781_TEST_PAGE_UNLOCK);
+				tasdevice_dev_read(tas_priv, i, p[j].reg,
+					(int *)&p[j].val[0]);
+			} else
+				tasdevice_dev_bulk_read(tas_priv, i, p[j].reg,
+					p[j].val, 4);

...all the above can be made more readable.

sound/soc/codecs/tas2781-i2c.c static int tas2781_force_fwload_put(struct snd_kcontrol *kcontrol, · line 383

Quoted 3 lines
sound/soc/codecs/tas2781-i2c.c +3 -0
+		}
+
+		for (j = 0; j < sum - 2; j++) {

Ditto for tas2781_cali_start_reg[j]

Quoted 1 line
(quoted diff) +1 -0
+		}

...

sound/soc/codecs/tas2781-i2c.c static int tas2781_force_fwload_put(struct snd_kcontrol *kcontrol, · line 701

Quoted 8 lines
sound/soc/codecs/tas2781-i2c.c +8 -0
+	while (r > 1 + l) {
+		mid = (l + r) / 2;
+		ar_mid = get_unaligned_be32(tas2563_dvc_table[mid]);
+		if (target < ar_mid)
+			r = mid;
+		else
+			l = mid;
+	}

Hmm... I'm wondering if bsearch() can be utilised here.

...

sound/soc/codecs/tas2781-i2c.c static int tas2781_force_fwload_put(struct snd_kcontrol *kcontrol, · line 707

Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2 -0
+	ucontrol->value.integer.value[0] =
+		abs(target - ar_l) <= abs(target - ar_r) ? l : r;

I don't understand why do you need 'target' to be in this check.

...

sound/soc/codecs/tas2781-i2c.c static int tasdevice_set_profile_id(struct snd_kcontrol *kcontrol, · line 824

Quoted 1 line
sound/soc/codecs/tas2781-i2c.c +1 -0
+	uinfo->value.integer.max = (int)tas_priv->ndev - 1;

Why casting?

...

sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls( · line 1095

Quoted 1 line
sound/soc/codecs/tas2781-i2c.c +1 -0
+	scnprintf(active_dev_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,

Why 'c' variant in use? You are ignoring the returned value. Isn't strscpy() you want or memtostr() (in both cases 2 parameters variant)?

sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls( · line 1096

Quoted 1 line
sound/soc/codecs/tas2781-i2c.c +1 -0
+		"Activate Tasdevice Id");

Same Q to all scnprintf() calls.

...

sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls( · line 1127

Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2 -0
+	cali_data->data = devm_kzalloc(tas_priv->dev, tas_priv->ndev *
+		(cali_data->reg_array_sz * 4 + 1), GFP_KERNEL);

No way. First of all, we have kcalloc(), second, there is an overflow.h that has necessary macros to calculate sizes for memory allocations.

Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2 -0
+	if (!cali_data->data)
+		return -ENOMEM;

...

sound/soc/codecs/tas2781-i2c.c static int tasdevice_startup(struct snd_pcm_substream *substream, · line 1327

Quoted 13 lines
sound/soc/codecs/tas2781-i2c.c +5 -5
-	int ret = 0;
 
-	if (tas_priv->fw_state != TASDEVICE_DSP_FW_ALL_OK) {
-		dev_err(tas_priv->dev, "DSP bin file not loaded\n");
-		ret = -EINVAL;
+	if (!(tas_priv->fw_state == TASDEVICE_DSP_FW_ALL_OK ||
+		tas_priv->fw_state == TASDEVICE_RCA_FW_OK)) {
+		dev_err(tas_priv->dev, "Bin file not loaded\n");
+		return -EINVAL;
 	}
 
-	return ret;
+	return 0;

This patch is a mess. Try to split out the different logical changes into different patches.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
author maintainer
#2 lore raw

Hi Andy
Thanks for your comments. Following are my answers.

Quoted 27 lines

-----Original Message-----
From: Andy Shevchenko <[email protected]>
Sent: Wednesday, May 22, 2024 8:02 PM
To: Ding, Shenghao <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; pierre- [email protected]; [email protected]; [email protected]; [email protected]; Salazar, Ivan <i- [email protected]>; [email protected]; Chadha, Jasjot Singh <j- [email protected]>; [email protected]; [email protected]; yung- [email protected]; Rao, Dipa <[email protected]>; Lu, Kevin <kevin- [email protected]>; [email protected]; [email protected]; Xu, Baojun <[email protected]>; [email protected]; [email protected]; Navada Kanyana, Mukund <[email protected]>; [email protected]; Kutty, Aanya <[email protected]>; Mahmud, Nayeem <[email protected]>
Subject: [EXTERNAL] Re: [PATCH v1] ASoc: tas2781: Add Calibration Kcontrols and tas2563 digtial gain for Chromebook

On Wed, May 22, 2024 at 07: 29: 41PM +0800, Shenghao Ding wrote: > Calibrated data will be set to default after loading DSP config params, > which will cause speaker protection work abnormally. Reload calibrated > data after loading 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. If you wish to report this message to IT Security, please forward the message as an attachment to [email protected]

........................

Quoted 10 lines

sound/soc/codecs/tas2781-i2c.c static int tas2781_force_fwload_put(struct snd_kcontrol *kcontrol, · line 701

Quoted 8 lines
sound/soc/codecs/tas2781-i2c.c +8 -0
+	while (r > 1 + l) {
+		mid = (l + r) / 2;
+		ar_mid = get_unaligned_be32(tas2563_dvc_table[mid]);
+		if (target < ar_mid)
+			r = mid;
+		else
+			l = mid;
+	}

Hmm... I'm wondering if bsearch() can be utilised here.

Bsearch is to find out the value, in this function is to find out the member same as or closer to the input value.

Quoted 25 lines

...

sound/soc/codecs/tas2781-i2c.c static int tas2781_force_fwload_put(struct snd_kcontrol *kcontrol, · line 707

Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2 -0
+	ucontrol->value.integer.value[0] =
+		abs(target - ar_l) <= abs(target - ar_r) ? l : r;

I don't understand why do you need 'target' to be in this check.

...

sound/soc/codecs/tas2781-i2c.c static int tasdevice_set_profile_id(struct snd_kcontrol *kcontrol, · line 824

Quoted 1 line
sound/soc/codecs/tas2781-i2c.c +1 -0
+	uinfo->value.integer.max = (int)tas_priv->ndev - 1;

Why casting?

...

sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls( · line 1095

Quoted 1 line
sound/soc/codecs/tas2781-i2c.c +1 -0
+	scnprintf(active_dev_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN,

Why 'c' variant in use? You are ignoring the returned value. Isn't strscpy() you want or memtostr() (in both cases 2 parameters variant)?

sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls( · line 1096

Quoted 1 line
sound/soc/codecs/tas2781-i2c.c +1 -0
+		"Activate Tasdevice Id");

Same Q to all scnprintf() calls.

Quoted 7 lines

...

sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls( · line 1127

Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2 -0
+	cali_data->data = devm_kzalloc(tas_priv->dev, tas_priv->ndev *
+		(cali_data->reg_array_sz * 4 + 1), GFP_KERNEL);

No way. First of all, we have kcalloc(), second, there is an overflow.h that has necessary macros to calculate sizes for memory allocations.

Memory allocated with devm_kzalloc is automatically freed on driver detach while kcalloc can’t

Quoted 5 lines
Quoted 3 lines
sound/soc/codecs/tas2781-i2c.c +2 -0
+	if (!cali_data->data)
+		return -ENOMEM;

...

BR
Shenghao Ding

#3 lore raw
Quoted 4 lines · Shenghao
Quoted 4 lines

From: Andy Shevchenko <[email protected]>
Sent: Wednesday, May 22, 2024 8:02 PM
To: Ding, Shenghao <[email protected]>
On Wed, May 22, 2024 at 07: 29: 41PM +0800, Shenghao Ding wrote: >

(some comments were not answered, are you agree on all of the points?)

...

Quoted 6 lines
Quoted 5 lines

sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls( · line 1127

Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2 -0
+	cali_data->data = devm_kzalloc(tas_priv->dev, tas_priv->ndev *
+		(cali_data->reg_array_sz * 4 + 1), GFP_KERNEL);

No way. First of all, we have kcalloc(), second, there is an overflow.h that has necessary macros to calculate sizes for memory allocations.

Memory allocated with devm_kzalloc is automatically freed on driver detach while kcalloc can’t

Yes, we have devm variant for kcalloc(), why can it be not utilised?

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2 -0
+	if (!cali_data->data)
+		return -ENOMEM;
Signature · 2 lines
With Best Regards,
Andy Shevchenko
#4 lore raw
In reply to Shenghao Ding
kernel test robot noticed the following build errors:

Hi Shenghao,

kernel test robot noticed the following build errors:

[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on next-20240522]
[cannot apply to tiwai-sound/for-next tiwai-sound/for-linus linus/master v6.9] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Shenghao-Ding/ASoc-tas2781-Add-Calibration-Kcontrols-and-tas2563-digtial-gain-for-Chromebook/20240522-193315
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link:    https://lore.kernel.org/r/20240522112942.994-1-shenghao-ding%40ti.com
patch subject: [PATCH v1] ASoc: tas2781: Add Calibration Kcontrols and tas2563 digtial gain for Chromebook
config: x86_64-buildonly-randconfig-002-20240523 (https://download.01.org/0day-ci/archive/20240523/[email protected]/config)
compiler: gcc-8 (Ubuntu 8.4.0-3ubuntu2) 8.4.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240523/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

sound/soc/codecs/tas2781-i2c.c: In function 'tas2563_digital_gain_get':

>> sound/soc/codecs/tas2781-i2c.c:696:31: error: 'tas2563_dvc_table' undeclared (first use in this function); did you mean 'tasklet_disable'?
      ar_mid = get_unaligned_be32(tas2563_dvc_table[mid]);
                                  ^~~~~~~~~~~~~~~~~
                                  tasklet_disable
   sound/soc/codecs/tas2781-i2c.c:696:31: note: each undeclared identifier is reported only once for each function it appears in
   sound/soc/codecs/tas2781-i2c.c: In function 'tas2563_digital_gain_put':
   sound/soc/codecs/tas2781-i2c.c:737:29: error: 'tas2563_dvc_table' undeclared (first use in this function); did you mean 'tasklet_disable'?
     volwr = get_unaligned_be32(tas2563_dvc_table[vol]);
                                ^~~~~~~~~~~~~~~~~
                                tasklet_disable
   In file included from sound/soc/codecs/tas2781-i2c.c:30:
   sound/soc/codecs/tas2781-i2c.c: At top level:
>> sound/soc/codecs/tas2781-i2c.c:790:3: error: 'tas2563_dvc_tlv' undeclared here (not in a function); did you mean 'tas2563_snd_controls'?
      tas2563_dvc_tlv),
      ^~~~~~~~~~~~~~~
   include/sound/soc.h:293:12: note: in definition of macro 'SOC_SINGLE_RANGE_EXT_TLV'
     .tlv.p = (tlv_array), \
               ^~~~~~~~~
>> sound/soc/codecs/tas2781-i2c.c:788:17: error: 'tas2563_dvc_table' undeclared here (not in a function); did you mean 'tas2563_snd_controls'?
      0, ARRAY_SIZE(tas2563_dvc_table) - 1, 0,
                    ^~~~~~~~~~~~~~~~~
   include/sound/soc.h:298:42: note: in definition of macro 'SOC_SINGLE_RANGE_EXT_TLV'
       .rshift = xshift, .min = xmin, .max = xmax, \
                                             ^~~~
   sound/soc/codecs/tas2781-i2c.c:788:6: note: in expansion of macro 'ARRAY_SIZE'
      0, ARRAY_SIZE(tas2563_dvc_table) - 1, 0,
         ^~~~~~~~~~
   include/linux/build_bug.h:16:51: error: bit-field '<anonymous>' width not an integer constant
    #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); })))
                                                      ^
   include/sound/soc.h:298:42: note: in definition of macro 'SOC_SINGLE_RANGE_EXT_TLV'
       .rshift = xshift, .min = xmin, .max = xmax, \
                                             ^~~~
   include/linux/compiler.h:237:28: note: in expansion of macro 'BUILD_BUG_ON_ZERO'
    #define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
                               ^~~~~~~~~~~~~~~~~
   include/linux/array_size.h:11:59: note: in expansion of macro '__must_be_array'
    #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
                                                              ^~~~~~~~~~~~~~~
   sound/soc/codecs/tas2781-i2c.c:788:6: note: in expansion of macro 'ARRAY_SIZE'
      0, ARRAY_SIZE(tas2563_dvc_table) - 1, 0,
         ^~~~~~~~~~

vim +696 sound/soc/codecs/tas2781-i2c.c

669
670 static int tas2563_digital_gain_get(
671 struct snd_kcontrol *kcontrol,
672 struct snd_ctl_elem_value *ucontrol)
673 {
674 struct soc_mixer_control *mc =
675 (struct soc_mixer_control *)kcontrol->private_value;
676 struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol);
677 struct tasdevice_priv *tas_dev = snd_soc_component_get_drvdata(codec);
678 unsigned int l = 0, r = mc->max;
679 unsigned int target, ar_mid, mid, ar_l, ar_r;
680 unsigned int reg = mc->reg;
681 unsigned char data[4];
682 int ret;
683
684 mutex_lock(&tas_dev->codec_lock);
685 /* Read the primary device */
686 ret = tasdevice_dev_bulk_read(tas_dev, 0, reg, data, 4);
687 if (ret) {
688 dev_err(tas_dev->dev, "%s, get AMP vol error\n", __func__);
689 goto out;
690 }
691
692 target = get_unaligned_be32(&data[0]);
693
694 while (r > 1 + l) {
695 mid = (l + r) / 2;

 > 696			ar_mid = get_unaligned_be32(tas2563_dvc_table[mid]);
   697			if (target < ar_mid)
   698				r = mid;
   699			else
   700				l = mid;
   701		}
   702	
   703		ar_l = get_unaligned_be32(tas2563_dvc_table[l]);
   704		ar_r = get_unaligned_be32(tas2563_dvc_table[r]);
   705	
   706		ucontrol->value.integer.value[0] =
   707			abs(target - ar_l) <= abs(target - ar_r) ? l : r;
   708	out:
   709		mutex_unlock(&tas_dev->codec_lock);
   710		return 0;
   711	}
   712	
   713	static int tas2563_digital_gain_put(
   714		struct snd_kcontrol *kcontrol,
   715		struct snd_ctl_elem_value *ucontrol)
   716	{
   717		struct soc_mixer_control *mc =
   718			(struct soc_mixer_control *)kcontrol->private_value;
   719		struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol);
   720		struct tasdevice_priv *tas_dev = snd_soc_component_get_drvdata(codec);
   721		unsigned int reg = mc->reg;
   722		unsigned int volrd, volwr;
   723		int vol = ucontrol->value.integer.value[0];
   724		int max = mc->max, i, ret = 1;
   725		unsigned char data[4];
   726	
   727		vol = clamp(vol, 0, max);
   728		mutex_lock(&tas_dev->codec_lock);
   729		/* Read the primary device */
   730		ret =  tasdevice_dev_bulk_read(tas_dev, 0, reg, data, 4);
   731		if (ret) {
   732			dev_err(tas_dev->dev, "%s, get AMP vol error\n", __func__);
   733			goto out;
   734		}
   735	
   736		volrd = get_unaligned_be32(&data[0]);
   737		volwr = get_unaligned_be32(tas2563_dvc_table[vol]);
   738	
   739		if (volrd == volwr) {
   740			ret = 0;
   741			goto out;
   742		}
   743	
   744		for (i = 0; i < tas_dev->ndev; i++) {
   745			ret = tasdevice_dev_bulk_write(tas_dev, i, reg,
   746				(unsigned char *)tas2563_dvc_table[vol], 4);
   747			if (ret)
   748				dev_err(tas_dev->dev,
   749					"%s, set digital vol error in device %d\n",
   750					__func__, i);
   751		}
   752	
   753	out:
   754		mutex_unlock(&tas_dev->codec_lock);
   755		return ret;
   756	}
   757	
   758	static const struct snd_kcontrol_new tasdevice_snd_controls[] = {
   759		SOC_SINGLE_BOOL_EXT("Speaker Force Firmware Load", 0,
   760			tasdev_force_fwload_get, tasdev_force_fwload_put),
   761	};
   762	
   763	static const struct snd_kcontrol_new tasdevice_cali_controls[] = {
   764		SOC_SINGLE_EXT("Calibration Stop", SND_SOC_NOPM, 0, 1, 0,
   765			tasdev_nop_get, tasdev_calib_stop_put),
   766		SND_SOC_BYTES_EXT("Amp TF Data", 5, tasdev_tf_data_get, NULL),
   767		SND_SOC_BYTES_EXT("Amp RE Data", 5, tasdev_re_data_get, NULL),
   768		SND_SOC_BYTES_EXT("Amp R0 Data", 5, tasdev_r0_data_get, NULL),
   769		SND_SOC_BYTES_EXT("Amp XMA1 Data", 5, tasdev_XMA1_data_get, NULL),
   770		SND_SOC_BYTES_EXT("Amp XMA2 Data", 5, tasdev_XMA2_data_get, NULL),
   771	};
   772	
   773	static const struct snd_kcontrol_new tas2781_snd_controls[] = {
   774		SOC_SINGLE_RANGE_EXT_TLV("Speaker Analog Gain", TAS2781_AMP_LEVEL,
   775			1, 0, 20, 0, tas2781_amp_getvol,
   776			tas2781_amp_putvol, amp_vol_tlv),
   777		SOC_SINGLE_RANGE_EXT_TLV("Speaker Digital Gain", TAS2781_DVC_LVL,
   778			0, 0, 200, 1, tas2781_digital_getvol,
   779			tas2781_digital_putvol, dvc_tlv),
   780	};
   781	
   782	static const struct snd_kcontrol_new tas2781_cali_controls[] = {
   783		SND_SOC_BYTES_EXT("Amp Latch Data", 2, tas2781_latch_reg_get, NULL),
   784	};
   785	
   786	static const struct snd_kcontrol_new tas2563_snd_controls[] = {
   787		SOC_SINGLE_RANGE_EXT_TLV("Speaker Digital Gain", TAS2563_DVC_LVL, 0,
 > 788			0, ARRAY_SIZE(tas2563_dvc_table) - 1, 0,
   789			tas2563_digital_gain_get, tas2563_digital_gain_put,
 > 790			tas2563_dvc_tlv),

791 };
792

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#5 lore raw
In reply to Shenghao Ding
kernel test robot noticed the following build errors:

Hi Shenghao,

kernel test robot noticed the following build errors:

[auto build test ERROR on broonie-sound/for-next]
[also build test ERROR on next-20240522]
[cannot apply to tiwai-sound/for-next tiwai-sound/for-linus linus/master v6.9] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Shenghao-Ding/ASoc-tas2781-Add-Calibration-Kcontrols-and-tas2563-digtial-gain-for-Chromebook/20240522-193315
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
patch link:    https://lore.kernel.org/r/20240522112942.994-1-shenghao-ding%40ti.com
patch subject: [PATCH v1] ASoc: tas2781: Add Calibration Kcontrols and tas2563 digtial gain for Chromebook
config: mips-randconfig-r081-20240523 (https://download.01.org/0day-ci/archive/20240523/[email protected]/config)
compiler: clang version 16.0.6 (https://github.com/llvm/llvm-project 7cbf1a2591520c2491aa35339f227775f4d3adf6)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240523/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> sound/soc/codecs/tas2781-i2c.c:696:31: error: use of undeclared identifier 'tas2563_dvc_table'
                   ar_mid = get_unaligned_be32(tas2563_dvc_table[mid]);
                                               ^
   sound/soc/codecs/tas2781-i2c.c:703:28: error: use of undeclared identifier 'tas2563_dvc_table'
           ar_l = get_unaligned_be32(tas2563_dvc_table[l]);
                                     ^
   sound/soc/codecs/tas2781-i2c.c:704:28: error: use of undeclared identifier 'tas2563_dvc_table'
           ar_r = get_unaligned_be32(tas2563_dvc_table[r]);
                                     ^
   sound/soc/codecs/tas2781-i2c.c:737:29: error: use of undeclared identifier 'tas2563_dvc_table'
           volwr = get_unaligned_be32(tas2563_dvc_table[vol]);
                                      ^
   sound/soc/codecs/tas2781-i2c.c:746:21: error: use of undeclared identifier 'tas2563_dvc_table'
                           (unsigned char *)tas2563_dvc_table[vol], 4);
                                            ^
>> sound/soc/codecs/tas2781-i2c.c:790:3: error: use of undeclared identifier 'tas2563_dvc_tlv'
                   tas2563_dvc_tlv),
                   ^
   sound/soc/codecs/tas2781-i2c.c:788:17: error: use of undeclared identifier 'tas2563_dvc_table'
                   0, ARRAY_SIZE(tas2563_dvc_table) - 1, 0,
                                 ^
   sound/soc/codecs/tas2781-i2c.c:788:17: error: use of undeclared identifier 'tas2563_dvc_table'
   sound/soc/codecs/tas2781-i2c.c:788:17: error: use of undeclared identifier 'tas2563_dvc_table'
   sound/soc/codecs/tas2781-i2c.c:1433:4: error: invalid application of 'sizeof' to an incomplete type 'const struct snd_kcontrol_new[]'
                           ARRAY_SIZE(tas2563_snd_controls));
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/linux/array_size.h:11:32: note: expanded from macro 'ARRAY_SIZE'
   #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
                                  ^~~~~

10 errors generated.

vim +/tas2563_dvc_table +696 sound/soc/codecs/tas2781-i2c.c

669
670 static int tas2563_digital_gain_get(
671 struct snd_kcontrol *kcontrol,
672 struct snd_ctl_elem_value *ucontrol)
673 {
674 struct soc_mixer_control *mc =
675 (struct soc_mixer_control *)kcontrol->private_value;
676 struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol);
677 struct tasdevice_priv *tas_dev = snd_soc_component_get_drvdata(codec);
678 unsigned int l = 0, r = mc->max;
679 unsigned int target, ar_mid, mid, ar_l, ar_r;
680 unsigned int reg = mc->reg;
681 unsigned char data[4];
682 int ret;
683
684 mutex_lock(&tas_dev->codec_lock);
685 /* Read the primary device */
686 ret = tasdevice_dev_bulk_read(tas_dev, 0, reg, data, 4);
687 if (ret) {
688 dev_err(tas_dev->dev, "%s, get AMP vol error\n", __func__);
689 goto out;
690 }
691
692 target = get_unaligned_be32(&data[0]);
693
694 while (r > 1 + l) {
695 mid = (l + r) / 2;

 > 696			ar_mid = get_unaligned_be32(tas2563_dvc_table[mid]);
   697			if (target < ar_mid)
   698				r = mid;
   699			else
   700				l = mid;
   701		}
   702	
   703		ar_l = get_unaligned_be32(tas2563_dvc_table[l]);
   704		ar_r = get_unaligned_be32(tas2563_dvc_table[r]);
   705	
   706		ucontrol->value.integer.value[0] =
   707			abs(target - ar_l) <= abs(target - ar_r) ? l : r;
   708	out:
   709		mutex_unlock(&tas_dev->codec_lock);
   710		return 0;
   711	}
   712	
   713	static int tas2563_digital_gain_put(
   714		struct snd_kcontrol *kcontrol,
   715		struct snd_ctl_elem_value *ucontrol)
   716	{
   717		struct soc_mixer_control *mc =
   718			(struct soc_mixer_control *)kcontrol->private_value;
   719		struct snd_soc_component *codec = snd_soc_kcontrol_component(kcontrol);
   720		struct tasdevice_priv *tas_dev = snd_soc_component_get_drvdata(codec);
   721		unsigned int reg = mc->reg;
   722		unsigned int volrd, volwr;
   723		int vol = ucontrol->value.integer.value[0];
   724		int max = mc->max, i, ret = 1;
   725		unsigned char data[4];
   726	
   727		vol = clamp(vol, 0, max);
   728		mutex_lock(&tas_dev->codec_lock);
   729		/* Read the primary device */
   730		ret =  tasdevice_dev_bulk_read(tas_dev, 0, reg, data, 4);
   731		if (ret) {
   732			dev_err(tas_dev->dev, "%s, get AMP vol error\n", __func__);
   733			goto out;
   734		}
   735	
   736		volrd = get_unaligned_be32(&data[0]);
   737		volwr = get_unaligned_be32(tas2563_dvc_table[vol]);
   738	
   739		if (volrd == volwr) {
   740			ret = 0;
   741			goto out;
   742		}
   743	
   744		for (i = 0; i < tas_dev->ndev; i++) {
   745			ret = tasdevice_dev_bulk_write(tas_dev, i, reg,
   746				(unsigned char *)tas2563_dvc_table[vol], 4);
   747			if (ret)
   748				dev_err(tas_dev->dev,
   749					"%s, set digital vol error in device %d\n",
   750					__func__, i);
   751		}
   752	
   753	out:
   754		mutex_unlock(&tas_dev->codec_lock);
   755		return ret;
   756	}
   757	
   758	static const struct snd_kcontrol_new tasdevice_snd_controls[] = {
   759		SOC_SINGLE_BOOL_EXT("Speaker Force Firmware Load", 0,
   760			tasdev_force_fwload_get, tasdev_force_fwload_put),
   761	};
   762	
   763	static const struct snd_kcontrol_new tasdevice_cali_controls[] = {
   764		SOC_SINGLE_EXT("Calibration Stop", SND_SOC_NOPM, 0, 1, 0,
   765			tasdev_nop_get, tasdev_calib_stop_put),
   766		SND_SOC_BYTES_EXT("Amp TF Data", 5, tasdev_tf_data_get, NULL),
   767		SND_SOC_BYTES_EXT("Amp RE Data", 5, tasdev_re_data_get, NULL),
   768		SND_SOC_BYTES_EXT("Amp R0 Data", 5, tasdev_r0_data_get, NULL),
   769		SND_SOC_BYTES_EXT("Amp XMA1 Data", 5, tasdev_XMA1_data_get, NULL),
   770		SND_SOC_BYTES_EXT("Amp XMA2 Data", 5, tasdev_XMA2_data_get, NULL),
   771	};
   772	
   773	static const struct snd_kcontrol_new tas2781_snd_controls[] = {
   774		SOC_SINGLE_RANGE_EXT_TLV("Speaker Analog Gain", TAS2781_AMP_LEVEL,
   775			1, 0, 20, 0, tas2781_amp_getvol,
   776			tas2781_amp_putvol, amp_vol_tlv),
   777		SOC_SINGLE_RANGE_EXT_TLV("Speaker Digital Gain", TAS2781_DVC_LVL,
   778			0, 0, 200, 1, tas2781_digital_getvol,
   779			tas2781_digital_putvol, dvc_tlv),
   780	};
   781	
   782	static const struct snd_kcontrol_new tas2781_cali_controls[] = {
   783		SND_SOC_BYTES_EXT("Amp Latch Data", 2, tas2781_latch_reg_get, NULL),
   784	};
   785	
   786	static const struct snd_kcontrol_new tas2563_snd_controls[] = {
   787		SOC_SINGLE_RANGE_EXT_TLV("Speaker Digital Gain", TAS2563_DVC_LVL, 0,
   788			0, ARRAY_SIZE(tas2563_dvc_table) - 1, 0,
   789			tas2563_digital_gain_get, tas2563_digital_gain_put,
 > 790			tas2563_dvc_tlv),

791 };
792

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#6 lore raw
In reply to Shenghao Ding

Could you move this sort of renaming/editing to a first patch?

Quoted 22 lines

/*Software Reset */

include/sound/tas2781.h +6 -6
-#define TAS2781_REG_SWRESET		TASDEVICE_REG(0x0, 0X0, 0x01)
-#define TAS2781_REG_SWRESET_RESET	BIT(0)
+#define TASDEVICE_REG_SWRESET		TASDEVICE_REG(0x00, 0X00, 0x01)
+#define TASDEVICE_REG_SWRESET_RESET	BIT(0)
 
-// tas2781-lib.c -- TAS2781 Common functions for HDA and ASoC Audio drivers
+// tas2781-comlib.c -- TAS2781 Common functions for HDA and ASoC Audio drivers
 //
-// Copyright 2023 Texas Instruments, Inc.
+// Copyright 2023 - 2024 Texas Instruments, Inc.
@@ -254,8 +281,8 @@ void tas2781_reset(struct tasdevice_priv *tas_dev)
 	} else {
 		for (i = 0; i < tas_dev->ndev; i++) {
 			ret = tasdevice_dev_write(tas_dev, i,
-				TAS2781_REG_SWRESET,
-				TAS2781_REG_SWRESET_RESET);
+				TASDEVICE_REG_SWRESET,
+				TASDEVICE_REG_SWRESET_RESET);
 

include/sound/tas2781.h static const struct snd_soc_component_driver · line 1477

Quoted 10 lines
include/sound/tas2781.h +2 -2
@@ -591,8 +1470,8 @@ static const struct snd_soc_component_driver
 	soc_codec_driver_tasdevice = {
 	.probe			= tasdevice_codec_probe,
 	.remove			= tasdevice_codec_remove,
-	.controls		= tas2781_snd_controls,
-	.num_controls		= ARRAY_SIZE(tas2781_snd_controls),
+	.controls		= tasdevice_snd_controls,
+	.num_controls		= ARRAY_SIZE(tasdevice_snd_controls),
 	.dapm_widgets		= tasdevice_dapm_widgets,
 	.num_dapm_widgets	= ARRAY_SIZE(tasdevice_dapm_widgets),
 	.dapm_routes		= tasdevice_audio_map,

And then add functional changes in a second patch? It'd be simpler to review really...