ASoC: tas2781: Add Calibration Kcontrols for Chromebook
Subsystems (3)
Shenghao Ding
maintainerPATCH v2 1/1 ASoC: tas2781: Add Calibration Kcontrols for Chromebook
Add calibration related kcontrol for speaker impedance calibration and speaker leakage check for Chromebook
---
v2:
- Add channel no into the log for error debug
- | Reported-by: kernel test robot <[email protected]>
| Closes: https://urldefense.com/v3/__https://lore.kernel.org/oe-kbuild-all/[email protected]/__;!!G3vK!QyZeGtz-H
- renamae tasdevice_chn_switch to put it in a single line
- With inverted check this entire function becomes neater in
tasdev_chn_switch.
- Add registers for TAS2563 and TAS2781 calibration.
- Add cali_data_backup 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.
- 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.
- Define tas2781_cali_control and tas2563_cali_control for calibration
--- include/sound/tas2781.h | 68 +++ sound/soc/codecs/tas2781-comlib.c | 26 + sound/soc/codecs/tas2781-fmwlib.c | 60 +- sound/soc/codecs/tas2781-i2c.c | 961 +++++++++++++++++++++++++++++- 4 files changed, 1104 insertions(+), 11 deletions(-)
include/sound/tas2781.h +68 -0
@@ -49,12 +49,59 @@/*I2C Checksum */ #define TASDEVICE_I2CChecksum TASDEVICE_REG(0x0, 0x0, 0x7E) +/* XM_340 */ +#define TASDEVICE_XM_A1_REG TASDEVICE_REG(0x64, 0x02, 0x4c) +/* XM_341 */ +#define TASDEVICE_XM_A2_REG TASDEVICE_REG(0x64, 0x02, 0x64) +/* Volume control */ #define TAS2563_DVC_LVL TASDEVICE_REG(0x00, 0x02, 0x0C)#define TAS2781_DVC_LVL TASDEVICE_REG(0x0, 0x0, 0x1A)#define TAS2781_AMP_LEVEL TASDEVICE_REG(0x0, 0x0, 0x03)#define TAS2781_AMP_LEVEL_MASK GENMASK(5, 1) +#define TAS2563_IDLE TASDEVICE_REG(0x00, 0x00, 0x3e) +#define TAS2563_PRM_R0_REG TASDEVICE_REG(0x00, 0x0f, 0x34) + +#define TAS2563_RUNTIME_RE_REG_TF TASDEVICE_REG(0x64, 0x02, 0x70) +#define TAS2563_RUNTIME_RE_REG TASDEVICE_REG(0x64, 0x02, 0x48) + +#define TAS2563_PRM_ENFF_REG TASDEVICE_REG(0x00, 0x0d, 0x54) +#define TAS2563_PRM_DISTCK_REG TASDEVICE_REG(0x00, 0x0d, 0x58) +#define TAS2563_PRM_TE_SCTHR_REG TASDEVICE_REG(0x00, 0x0f, 0x60) +#define TAS2563_PRM_PLT_FLAG_REG TASDEVICE_REG(0x00, 0x0d, 0x74) +#define TAS2563_PRM_SINEGAIN_REG TASDEVICE_REG(0x00, 0x0d, 0x7c) +/* prm_Int_B0 */ +#define TAS2563_TE_TA1_REG TASDEVICE_REG(0x00, 0x10, 0x0c) +/* prm_Int_A1 */ +#define TAS2563_TE_TA1_AT_REG TASDEVICE_REG(0x00, 0x10, 0x10) +/* prm_TE_Beta */ +#define TAS2563_TE_TA2_REG TASDEVICE_REG(0x00, 0x0f, 0x64) +/* prm_TE_Beta1 */ +#define TAS2563_TE_AT_REG TASDEVICE_REG(0x00, 0x0f, 0x68) +/* prm_TE_1_Beta1 */ +#define TAS2563_TE_DT_REG TASDEVICE_REG(0x00, 0x0f, 0x70) + +#define TAS2781_PRM_INT_MASK_REG TASDEVICE_REG(0x00, 0x00, 0x3b) +#define TAS2781_PRM_CLK_CFG_REG TASDEVICE_REG(0x00, 0x00, 0x5c) +#define TAS2781_PRM_RSVD_REG TASDEVICE_REG(0x00, 0x01, 0x19) +#define TAS2781_PRM_TEST_57_REG TASDEVICE_REG(0x00, 0xfd, 0x39) +#define TAS2781_PRM_TEST_62_REG TASDEVICE_REG(0x00, 0xfd, 0x3e) +#define TAS2781_PRM_PVDD_UVLO_REG TASDEVICE_REG(0x00, 0x00, 0x71) +#define TAS2781_PRM_CHNL_0_REG TASDEVICE_REG(0x00, 0x00, 0x03) +#define TAS2781_PRM_NG_CFG0_REG TASDEVICE_REG(0x00, 0x00, 0x35) +#define TAS2781_PRM_IDLE_CH_DET_REG TASDEVICE_REG(0x00, 0x00, 0x66) +#define TAS2781_PRM_PLT_FLAG_REG TASDEVICE_REG(0x00, 0x14, 0x38) +#define TAS2781_PRM_SINEGAIN_REG TASDEVICE_REG(0x00, 0x14, 0x40) +#define TAS2781_PRM_SINEGAIN2_REG TASDEVICE_REG(0x00, 0x14, 0x44) + +#define TAS2781_TEST_UNLOCK_REG TASDEVICE_REG(0x00, 0xFD, 0x0D) +#define TAS2781_TEST_PAGE_UNLOCK 0x0D + +#define TAS2781_RUNTIME_LATCH_RE_REG TASDEVICE_REG(0x00, 0x00, 0x49) +#define TAS2781_RUNTIME_RE_REG_TF TASDEVICE_REG(0x64, 0x62, 0x48) +#define TAS2781_RUNTIME_RE_REG TASDEVICE_REG(0x64, 0x63, 0x44) +#define TASDEVICE_CMD_SING_W 0x1#define TASDEVICE_CMD_BURST 0x2#define TASDEVICE_CMD_DELAY 0x3
@@ -70,7 +117,15 @@ enum device_catlog_id {OTHERS }; +struct bulk_reg_val { +int reg; +unsigned char val[4 ]; +unsigned char val_len; +bool is_locked; +}; +struct tasdevice { +struct bulk_reg_val *cali_data_backup;struct tasdevice_fw *cali_data_fmw;unsigned int dev_addr;unsigned int err_code;
@@ -81,9 +136,19 @@ struct tasdevice {bool is_loaderr; }; +struct cali_reg { +unsigned int r0_reg; +unsigned int r0_low_reg; +unsigned int invr0_reg; +unsigned int pow_reg; +unsigned int tlimit_reg; +}; +struct calidata {unsigned char *data;unsigned long total_sz; +struct cali_reg cali_reg_array; +unsigned int cali_dat_sz_per_dev; };struct tasdevice_priv {
@@ -119,6 +184,7 @@ struct tasdevice_priv {bool force_fwload_status;bool playback_started;bool isacpi; +bool is_user_space_calidata;unsigned int global_addr; int (*fw_parse_variable_header)(struct tasdevice_priv *tas_priv,
@@ -145,6 +211,8 @@ int tasdevice_init(struct tasdevice_priv *tas_priv);void tasdevice_remove (struct tasdevice_priv *tas_priv);int tasdevice_save_calibration (struct tasdevice_priv *tas_priv);void tasdevice_apply_calibration (struct tasdevice_priv *tas_priv); +int tasdev_chn_switch (struct tasdevice_priv *tas_priv, +unsigned short chn);int tasdevice_dev_read (struct tasdevice_priv *tas_priv,unsigned short chn,unsigned int reg,unsigned int *value); int tasdevice_dev_write(struct tasdevice_priv *tas_priv,
sound/soc/codecs/tas2781-comlib.c +26 -0
@@ -88,6 +88,32 @@ static int tasdevice_change_chn_book(struct tasdevice_priv *tas_priv,return ret; } +int tasdev_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 (tasdev_chn_switch); +int tasdevice_dev_read (struct tasdevice_priv *tas_priv,unsigned short chn,unsigned int reg,unsigned int *val) {
sound/soc/codecs/tas2781-fmwlib.c +51 -9
80 lines not on this page · raw message
sound/soc/codecs/tas2781-i2c.c +959 -2
1,036 lines not on this page · raw message
Signature · 1 line
2.35.7
Quoted 2 lines · Shenghao Ding
Add calibration related kcontrol for speaker impedance calibration and speaker leakage check for Chromebook
Missing grammatical period at the end.
...
It's possible to create a macro and reduce the below _a lot_.
Look at the include/linux/propery.h on how to have a similar one.
Quoted 1 line
+static const struct
bulk_reg_valtas2563_cali_start_reg[] = {
...
sound/soc/codecs/tas2781-i2c.c line 99
Quoted 6 lines
sound/soc/codecs/tas2781-i2c.c +6
-0+static const struct bulk_reg_val tas2781_cali_start_reg[] = { + { + .reg =TAS2781_PRM_INT_MASK_REG , + .val = {0xfe }, + .val_len =1 , + .is_locked = false
Please, mind the trailing comma in these cases.
Quoted 3 lines
include/sound/tas2781.h +2
-0+ }, +};
...
sound/soc/codecs/tas2781-i2c.c static int tasdev_force_fwload_put(struct snd_kcontrol *kcontrol, · line 418
Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2
-0+ rc =tasdevice_dev_bulk_read (tas_priv, i, reg, &dst[1 ], +4 );
This reads much better in a single line.
...
Quoted 4 lines
sound/soc/codecs/tas2781-i2c.c +4
-0+static int tasdevice_active_num_put (struct snd_kcontrol *kcontrol, +struct snd_ctl_elem_value *ucontrol) +{ +struct snd_soc_component *codec =snd_soc_kcontrol_component (kcontrol);
sound/soc/codecs/tas2781-i2c.c static int tasdevice_configuration_put( · line 1198
Quoted 10 lines
sound/soc/codecs/tas2781-i2c.c +10
-0+struct tasdevice_priv *tas_priv =snd_soc_component_get_drvdata (codec); +int dev_id = ucontrol->value.integer.value[0 ]; +int max = tas_priv->ndev -1 , rc; + + dev_id =clamp (dev_id,0 , max); + +guard (mutex)(&tas_priv->codec_lock); + rc =tasdev_chn_switch (tas_priv, dev_id); + +return rc;
int dev_id; dev_id = clamp(ucontrol->value.integer.value[0], 0, tas_priv->ndev - 1); guard(mutex)(&tas_priv->codec_lock); return tasdev_chn_switch(tas_priv, dev_id);
Quoted 1 line
+}
...
sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls(struct tasdevice_priv *tas_priv) · line 1319
Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2
-0+ rc =snd_soc_add_component_controls (tas_priv->codec, cali_ctrls, + num_controls);
Single line?
...
sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls(struct tasdevice_priv *tas_priv) · line 1334
Quoted 2 lines
sound/soc/codecs/tas2781-i2c.c +2
-0+/* +* Alloc kcontrol via devm_kzalloc, which don't manually
devm_kzalloc()
sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls(struct tasdevice_priv *tas_priv) · line 1335
Quoted 1 line
sound/soc/codecs/tas2781-i2c.c +1
-0+* free the kcontrol
Missing period.
Quoted 1 line
(quoted diff) +1
-0+ */
...
Review
Quoted 2 lines
(quoted diff) +2
-0+ /* + * package structure for tas2781 ftc start:
Package
Quoted 9 lines
sound/soc/codecs/tas2781-i2c.c +9
-0+* Pkg len (1 byte) +* Reg id (1 byte, constant 'r') +* book, page, register for pilot threshold, pilot tone +* and sine gain (12 bytes) +* for (i = 0; i < Device-Sum; i++) { +* Device #i index_info (1 byte) +* Sine gain for Device #i (8 bytes) +* } +*/
...
sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls(struct tasdevice_priv *tas_priv) · line 1419
Quoted 4 lines
sound/soc/codecs/tas2781-i2c.c +4
-0+ rc =snd_soc_add_component_controls (tas_priv->codec, cali_ctrls, + num_controls < i ? num_controls : i); + +return rc;
return snd_soc_add_component_controls(tas_priv->codec, cali_ctrls, num_controls < i ? num_controls : i);
Can num_controls ever be bigger than i?
Quoted 1 line
+}
Signature · 2 lines
With Best Regards, Andy Shevchenko
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Shenghao,
kernel test robot noticed the following build warnings:
[auto build test WARNING on broonie-sound/for-next]
[also build test WARNING on next-20240902]
[cannot apply to tiwai-sound/for-next tiwai-sound/for-linus linus/master v6.11-rc6] [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-for-Chromebook/20240902-142152 base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next patch link: https://lore.kernel.org/r/20240902062029.983-1-shenghao-ding%40ti.com patch subject: [PATCH v2] ASoC: tas2781: Add Calibration Kcontrols for Chromebook config: alpha-randconfig-r073-20240902 (https://download.01.org/0day-ci/archive/20240903/[email protected]/config) compiler: alpha-linux-gcc (GCC) 13.3.0
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]/
smatch warnings:sound/soc/codecs/tas2781-i2c.c:452 sngl_calib_start() warn: inconsistent indenting
vim +452 sound/soc/codecs/tas2781-i2c.c
425
426 static void sngl_calib_start(struct tasdevice_priv *tas_priv, int i,
427 int *reg, unsigned char *dat)
428 {
429 struct tasdevice *tasdev = tas_priv->tasdevice;
430 struct bulk_reg_val *p = tasdev[i].cali_data_backup;
431 const int sum = ARRAY_SIZE(tas2781_cali_start_reg);
432 int j;
433
434 if (p == NULL)
435 return;
436
437 /* Store the current setting from the chip */
438 for (j = 0; j < sum; j++) {
439 if (p[j].val_len == 1) {
440 if (p[j].is_locked)
441 tasdevice_dev_write(tas_priv, i,
442 TAS2781_TEST_UNLOCK_REG,
443 TAS2781_TEST_PAGE_UNLOCK);
444 tasdevice_dev_read(tas_priv, i, p[j].reg,
445 (int *)&p[j].val[0]);
446 } else {
447 switch (p[j].reg) {
448 case 0:
449 if (!reg[0])
450 continue;
451 p[j].reg = reg[0];
> 452 break;
453 case TAS2781_PRM_PLT_FLAG_REG:
454 p[j].reg = reg[1];
455 break;
456 case TAS2781_PRM_SINEGAIN_REG:
457 p[j].reg = reg[2];
458 break;
459 case TAS2781_PRM_SINEGAIN2_REG:
460 p[j].reg = reg[3];
461 break;
462 }
463 tasdevice_dev_bulk_read(tas_priv, i, p[j].reg,
464 p[j].val, 4);
465 }
466 }
467
468 /* Update the setting for calibration */
469 for (j = 0; j < sum - 2; j++) {
470 if (p[j].val_len == 1) {
471 if (p[j].is_locked)
472 tasdevice_dev_write(tas_priv, i,
473 TAS2781_TEST_UNLOCK_REG,
474 TAS2781_TEST_PAGE_UNLOCK);
475 tasdevice_dev_write(tas_priv, i, p[j].reg,
476 tas2781_cali_start_reg[j].val[0]);
477 } else {
478 if (!p[j].reg)
479 continue;
480 tasdevice_dev_bulk_write(tas_priv, i, p[j].reg,
481 (unsigned char *)
482 tas2781_cali_start_reg[j].val, 4);
483 }
484 }
485
486 tasdevice_dev_bulk_write(tas_priv, i, p[j].reg, &dat[1], 4);
487 tasdevice_dev_bulk_write(tas_priv, i, p[j + 1].reg, &dat[5], 4);
488 }
489
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki