ASoC: tas2781: Support dsp firmware Alpha and Beta seaies
Subsystems (3)
Shenghao Ding
maintainerPATCH v4 1/1 ASoC: tas2781: Support dsp firmware Alpha and Beta seaies
For calibration, basic version does not contain any calibration addresses, it depends on calibration tool to convey the addresses to the driver. Since Alpha and Beta firmware, all the calibration addresses are saved into the firmware.
---
v4:
- drop unnecceary "unsigned short size;" and "char *data;" in struct fct_param_address
- replace strstr() with strncmp() in fct_param_address_parser()
- replace hex_parse_u8() with memcpy()
- replace hex_parse_u24() with direct assignment
- drop hex_parse_u8() & hex_parse_u24()
- Just return directly and use proper error codes and drop "goto out" and "out:" label in fw_parse_fct_param_address
- fixed indentation issues in cali_reg_update
- fixed the logical splits in tas2781_calib_stop_put()
- return -ENOMEM if kmemdup fails in fw_parse_fct_param_address()
- remove unnecessary "out:" label
v3:
- Merge the 4 patches into one patch
v2:
- | Reported-by: kernel test robot <[email protected]> | Closes: | https://urldefense.com/v3/__https://lore.kernel.org/oe-kbuild-all/2025 | [email protected]/__;!!G3vK!WriwhtbQGlg6p00bcWutlhb-y9vS | pDrSu5_g9oOzzGOoABdirEARTntFzyX6Ss3UPRDxi_E-IA$ - | Reported-by: kernel test robot <[email protected]> | Closes: | https://urldefense.com/v3/__https://lore.kernel.org/oe-kbuild-all/2025 | [email protected]/__;!!G3vK!VtEdfur3fZklvPVfHFFfFP60Ub2E | JYvmjSUZ65lJ6BsQPJDl1fjYRDqh3c6Q5y6sA70ssXDG5g$
v1:
- update the year from 2024 to 2025 in the files.
- Add dspbin_type to distinguish different dspbin types, such as TASDEV_BASIC, TASDEV_ALPHA, and TASDEV_BETA.
- Add struct bulk_reg_val alp_cali_bckp to store the value of pilot tone threshold only for TASDEV_ALPHA & TASDEV_BETA firmware.
- Add the declaration of (*fw_parse_fct_param_address)() to parse the addresses of calibration params.
- Add the minimum version of TASDEV_ALPHA and TASDEV_BETA firmware.
- Add the definition of struct fct_param_address.
- update the year from 2024 to 2025.
- release the memory to save calibration addresses in tasdevice_dsp_remove().
- Add TASDEV_ALPHA and TASDEV_BETA firmware checking code.
- Add fct_param_address_parser for Alpha and Beta firmware.
- Add an extra branch to handle calibration address for TASDEV_ALPHA and TASDEV_BETA firmware.
--- include/sound/tas2781-dsp.h | 30 ++++- include/sound/tas2781.h | 11 ++ sound/pci/hda/tas2781_spi_fwlib.c | 8 +- sound/soc/codecs/tas2781-fmwlib.c | 214 +++++++++++++++++++++++++---- sound/soc/codecs/tas2781-i2c.c | 216 +++++++++++++++++++++++------- 5 files changed, 395 insertions(+), 84 deletions(-)
include/sound/tas2781-dsp.h +27 -3
@@ -2,7 +2,7 @@// // ALSA SoC Texas Instruments TAS2781 Audio Smart Amplifier // -// Copyright (C) 2022 - 2024 Texas Instruments Incorporated +// Copyright (C) 2022 - 2025 Texas Instruments Incorporated // https://www.ti.com // // The TAS2781 driver implements a flexible and configurable
@@ -30,8 +30,10 @@#define PRE_DEVICE_C 0x12#define PRE_DEVICE_D 0x16 -#define PPC3_VERSION 0x4100 -#define PPC3_VERSION_TAS2781 0x14600 +#define PPC3_VERSION_BASE 0x4100 +#define PPC3_VERSION_TAS2781_BASIC_MIN 0x14600 +#define PPC3_VERSION_TAS2781_ALPHA_MIN 0x4a00 +#define PPC3_VERSION_TAS2781_BETA_MIN 0x19400#define TASDEVICE_DEVICE_SUM 8#define TASDEVICE_CONFIG_SUM 64
@@ -106,6 +108,27 @@ struct tasdevice_calibration {struct tasdevice_data dev_data; }; +struct fct_param_address { +/* Thermal data for PG 1.0 device */ +unsigned char thr[3 ]; +/* Thermal data for PG 2.0 device */ +unsigned char thr2[3 ]; +/* Pilot tone enable flag, usually the sine wave */ +unsigned char plt_flg[3 ]; +/* Pilot tone gain for calibration */ +unsigned char sin_gn[3 ]; +/* Pilot tone gain for calibration */ +unsigned char sin_gn2[3 ]; +/* high 32-bit of real-time spk impedance */ +unsigned char r0_reg[3 ]; +/* check spk connection */ +unsigned char tf_reg[3 ]; +/* check spk resonant frequency */ +unsigned char a1_reg[3 ]; +/* check spk resonant frequency */ +unsigned char a2_reg[3 ]; +}; +struct tasdevice_fw {struct tasdevice_dspfw_hdr fw_hdr;unsigned short nr_programs;
@@ -114,6 +137,7 @@ struct tasdevice_fw {struct tasdevice_config *configs;unsigned short nr_calibrations;struct tasdevice_calibration *calibrations; +struct fct_param_address fct_par_addr;struct device *dev; };
include/sound/tas2781.h +11 -0
@@ -113,6 +113,12 @@ enum audio_device { TAS2781, }; +enum dspbin_type { +TASDEV_BASIC , +TASDEV_ALPHA , +TASDEV_BETA , +}; +enum device_catlog_id {LENOVO =0 ,OTHERS
@@ -127,6 +133,7 @@ struct bulk_reg_val {struct tasdevice {struct bulk_reg_val *cali_data_backup; +struct bulk_reg_val alp_cali_bckp;struct tasdevice_fw *cali_data_fmw;unsigned int dev_addr;unsigned int err_code;
@@ -171,6 +178,7 @@ struct tasdevice_priv {unsigned char dev_name[32 ];const char *name_prefix;unsigned char ndev; +unsigned int dspbin_typ;unsigned int magic_num;unsigned int chip_id;unsigned int sysclk;
@@ -196,6 +204,9 @@ struct tasdevice_priv {int (*fw_parse_configuration_data)(struct tasdevice_priv *tas_priv,struct tasdevice_fw *tas_fmw,const struct firmware *fmw,int offset); +int (*fw_parse_fct_param_address)(struct tasdevice_priv *tas_priv, +struct tasdevice_fw *tas_fmw, +const struct firmware *fmw,int offset);int (*tasdevice_load_block)(struct tasdevice_priv *tas_priv,struct tasdev_blk *block);
sound/pci/hda/tas2781_spi_fwlib.c +4 -4
@@ -2,7 +2,7 @@// // TAS2781 HDA SPI driver // -// Copyright 2024 Texas Instruments, Inc. +// Copyright 2024 - 2025 Texas Instruments, Inc. // // Author: Baojun Xu <[email protected]>
@@ -370,10 +370,10 @@ static unsigned char map_dev_idx(struct tasdevice_fw *tas_fmw,int i, n =ARRAY_SIZE (non_ppc3_mapping_table);unsigned char dev_idx =0 ; -if (fw_fixed_hdr->ppcver >=PPC3_VERSION_TAS2781 ) { +if (fw_fixed_hdr->ppcver >=PPC3_VERSION_TAS2781_BASIC_MIN ) { p = (struct blktyp_devidx_map *)ppc3_tas2781_mapping_table; n =ARRAY_SIZE (ppc3_tas2781_mapping_table); - }else if (fw_fixed_hdr->ppcver >=PPC3_VERSION ) { + }else if (fw_fixed_hdr->ppcver >=PPC3_VERSION_BASE ) { p = (struct blktyp_devidx_map *)ppc3_mapping_table; n =ARRAY_SIZE (ppc3_mapping_table); }
@@ -1605,7 +1605,7 @@ static int dspfw_default_callback(struct tasdevice_priv *tas_priv,int rc =0 ;if (drv_ver ==0x100 ) { -if (ppcver >=PPC3_VERSION ) { +if (ppcver >=PPC3_VERSION_BASE ) { tas_priv->fw_parse_variable_header = fw_parse_variable_header_kernel; tas_priv->fw_parse_program_data =
sound/soc/codecs/tas2781-fmwlib.c +189 -25
281 lines not on this page · raw message
sound/soc/codecs/tas2781-i2c.c +164 -52
342 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 4 lines · Shenghao Ding
For calibration, basic version does not contain any calibration addresses, it depends on calibration tool to convey the addresses to the driver. Since Alpha and Beta firmware, all the calibration addresses are saved into the firmware.
...
Quoted 4 lines
sound/soc/codecs/tas2781-fmwlib.c +4
-0+for (i =0 ; i <20 ; i++) { +const unsigned char *dat = &data[24 * i]; + +/*
sound/soc/codecs/tas2781-fmwlib.c static int fw_parse_configuration_data_kernel( · line 615
Quoted 10 lines
sound/soc/codecs/tas2781-fmwlib.c +9
-0+* check whether current fct param is empty. +*/ +if (dat[23 ] !=1 ) +break ; + +if (!strncmp (dat,"umg_SsmKEGCye" ,20 )) { + r->pow_reg =TASDEVICE_REG (dat[20 ], dat[21 ], dat[22 ]); +continue ; + }
Instead of this lengthy approach, just replace the chain with
if (foo) ... else if ... ...
It will reduce this by 2/3 of LoCs.
Quoted 70 lines
sound/soc/codecs/tas2781-fmwlib.c +70
-0+/* high 32-bit of real-time spk impedance */ +if (!strncmp (dat,"iks_E0" ,20 )) { + r->r0_reg =TASDEVICE_REG (dat[20 ], dat[21 ], dat[22 ]); +continue ; + } +/* inverse of real-time spk impedance */ +if (!strncmp (dat,"yep_LsqM0" ,20 )) { + r->invr0_reg = +TASDEVICE_REG (dat[20 ], dat[21 ], dat[22 ]); +continue ; + } +/* low 32-bit of real-time spk impedance */ +if (!strncmp (dat,"oyz_U0_ujx" ,20 )) { + r->r0_low_reg = +TASDEVICE_REG (dat[20 ], dat[21 ], dat[22 ]); +continue ; + } +/* Delta Thermal Limit */ +if (!strncmp (dat,"iks_GC_GMgq" ,20 )) { + r->tlimit_reg = +TASDEVICE_REG (dat[20 ], dat[21 ], dat[22 ]); +continue ; + } +/* Thermal data for PG 1.0 device */ +if (!strncmp (dat,"gou_Yao" ,20 )) { +memcpy (p->thr, &dat[20 ],3 ); +continue ; + } +/* Pilot tone enable flag, usually the sine wave */ +if (!strncmp (dat,"kgd_Wsc_Qsbp" ,20 )) { +memcpy (p->plt_flg, &dat[20 ],3 ); +continue ; + } +/* Pilot tone gain for calibration */ +if (!strncmp (dat,"yec_CqseSsqs" ,20 )) { +memcpy (p->sin_gn, &dat[20 ],3 ); +continue ; + } +/* Pilot tone gain for calibration, useless in PG 2.0 */ +if (!strncmp (dat,"iks_SogkGgog2" ,20 )) { +memcpy (p->sin_gn2, &dat[20 ],3 ); +continue ; + } +/* Thermal data for PG 2.0 device */ +if (!strncmp (dat,"yec_Sae_Y" ,20 )) { +memcpy (p->thr2, &dat[20 ],3 ); +continue ; + } +/* Spk Equivalent Resistance in fixed-point format */ +if (!strncmp (dat,"Re_Int" ,20 )) { +memcpy (p->r0_reg, &dat[20 ],3 ); +continue ; + } +/* Check whether the spk connection is open */ +if (!strncmp (dat,"SigFlag" ,20 )) { +memcpy (p->tf_reg, &dat[20 ],3 ); +continue ; + } +/* check spk resonant frequency */ +if (!strncmp (dat,"a1_Int" ,20 )) { +memcpy (p->a1_reg, &dat[20 ],3 ); +continue ; + } +/* check spk resonant frequency */ +if (!strncmp (dat,"a2_Int" ,20 )) { +memcpy (p->a2_reg, &dat[20 ],3 ); +continue ; + } + } +}
...
sound/soc/codecs/tas2781-fmwlib.c static int fw_parse_configuration_data_kernel( · line 696
Quoted 10 lines
sound/soc/codecs/tas2781-fmwlib.c +10
-0+static int fw_parse_fct_param_address (struct tasdevice_priv *tas_priv, +struct tasdevice_fw *tas_fmw,const struct firmware *fmw,int offset) +{ +struct calidata *cali_data = &tas_priv->cali_data; +struct cali_reg *r = &cali_data->cali_reg_array; +const unsigned char *data = fmw->data; + +if (offset +520 > fmw->size) { +dev_err (tas_priv->dev,"%s: File Size error\n" , __func__); +return -1 ;
Use proper error code here. Check include/uapi/asm-generic/errno.h.
Quoted 11 lines
sound/soc/codecs/tas2781-fmwlib.c +11
-0+ } + +/* skip reserved part */ + offset +=40 ; + +fct_param_address_parser (r, tas_fmw, &data[offset]); + + offset +=480 ; + +return offset; +}
...
Quoted 12 lines
sound/soc/codecs/tas2781-fmwlib.c +3
-6offset = tas_priv->fw_parse_variable_header (tas_priv, fmw, offset); -if (offset <0 ) { - ret = offset; - goto out; - } +if (offset <0 ) +return offset; + offset = tas_priv->fw_parse_program_data (tas_priv, tas_fmw, fmw, offset); -if (offset <0 ) { - ret = offset;
sound/soc/codecs/tas2781-fmwlib.c static int tasdevice_dspfw_ready(const struct firmware *fmw, · line 2186
Quoted 10 lines
sound/soc/codecs/tas2781-fmwlib.c +4
-3- goto out; - } +if (offset <0 ) +return offset; + offset = tas_priv->fw_parse_configuration_data (tas_priv, tas_fmw, fmw, offset);if (offset <0 ) - ret = offset; +return offset;
The below...
sound/soc/codecs/tas2781-fmwlib.c static int tasdevice_dspfw_ready(const struct firmware *fmw, · line 2195
Quoted 9 lines
sound/soc/codecs/tas2781-fmwlib.c +6
-1+if (tas_priv->fw_parse_fct_param_address) { + offset = tas_priv->fw_parse_fct_param_address (tas_priv, + tas_fmw, fmw, offset); +if (offset <0 ) + ret = offset; + } -out:return ret;
...can be written in this form:
if (tas_priv->fw_parse_fct_param_address) {
offset = tas_priv->fw_parse_fct_param_address(tas_priv,
tas_fmw, fmw, offset);
if (offset < 0)
return offset;
}
return 0;...
sound/soc/codecs/tas2781-i2c.c static int tasdevice_dsp_create_ctrls(struct tasdevice_priv *tas_priv) · line 1238
Quoted 6 lines
sound/soc/codecs/tas2781-i2c.c +5
-0+static void cali_reg_update (struct bulk_reg_val *p, +struct fct_param_address *t) +{ +const int sum =ARRAY_SIZE (tas2781_cali_start_reg); +int reg =0 ;
Unneeded assignment.
Quoted 27 lines
sound/soc/codecs/tas2781-i2c.c +27
-0+int j; + +for (j =0 ; j < sum; j++) { +switch (tas2781_cali_start_reg[j].reg) { +case 0 : + reg =TASDEVICE_REG (t->thr[0 ], t->thr[1 ], t->thr[2 ]); +break ; +case TAS2781_PRM_PLT_FLAG_REG : + reg =TASDEVICE_REG (t->plt_flg[0 ], t->plt_flg[1 ], + t->plt_flg[2 ]); +break ; +case TAS2781_PRM_SINEGAIN_REG : + reg =TASDEVICE_REG (t->sin_gn[0 ], t->sin_gn[1 ], + t->sin_gn[2 ]); +break ; +case TAS2781_PRM_SINEGAIN2_REG : + reg =TASDEVICE_REG (t->sin_gn[0 ], t->sin_gn[1 ], + t->sin_gn[2 ]); +break ; +default : + reg =0 ; +break ; + } +if (reg) + p[j].reg = reg; + } +}
Signature · 2 lines
With Best Regards, Andy Shevchenko