ASoC: tas2781: Refactor calibration start kcontrol creation to separate helper

Move the tas2781-specific calibration start kcontrol initialization logic
out of tasdevice_create_cali_ctrls() into a new dedicated helper function
create_tas2781_cali_start_ktrl().

This change eliminates duplicate inline code in the main calibration
control registration routine, improves code readability, and makes further
extension for custom calibration parameters much easier. No functional
behavior changes.

Signed-off-by: Shenghao Ding <shenghao-ding@ti.com>
Link: https://patch.msgid.link/20260813080540.1030-1-shenghao-ding@ti.com
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Shenghao Ding 2026-08-13 16:05:40 +08:00 committed by Mark Brown
parent bc34c37ed8
commit ba5401135a
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0

View File

@ -1456,6 +1456,43 @@ static void alpa_cali_update(struct bulk_reg_val *p,
p->val_len = 4;
}
static int create_tas2781_cali_start_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(priv->dev,
sizeof(*ext_cali_start), GFP_KERNEL);
if (!ext_cali_start)
return -ENOMEM;
cali_start_name = devm_kstrdup(priv->dev,
"Calibration Start", GFP_KERNEL);
if (!cali_start_name)
return -ENOMEM;
/*
* package structure for tas2781 ftc start:
* 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)
* }
*/
ext_cali_start->max = 14 + priv->ndev * 9;
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 = tas2781_calib_start_put;
cali_ctrl->get = tasdev_nop_get;
cali_ctrl->private_value = (unsigned long)ext_cali_start;
return 0;
}
static int tasdevice_create_cali_ctrls(struct tasdevice_priv *priv)
{
struct calidata *cali_data = &priv->cali_data;
@ -1574,37 +1611,11 @@ static int tasdevice_create_cali_ctrls(struct tasdevice_priv *priv)
*/
cali_data->data[0] = 0xff;
if (priv->chip_id == TAS2781) {
struct soc_bytes_ext *ext_cali_start;
char *cali_start_name;
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,
"Calibration Start", GFP_KERNEL);
if (!cali_start_name)
return -ENOMEM;
/*
* package structure for tas2781 ftc start:
* 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)
* }
*/
ext_cali_start->max = 14 + priv->ndev * 9;
cali_ctrls[i].name = cali_start_name;
cali_ctrls[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER;
cali_ctrls[i].info = snd_soc_bytes_info_ext;
cali_ctrls[i].put = tas2781_calib_start_put;
cali_ctrls[i].get = tasdev_nop_get;
cali_ctrls[i].private_value = (unsigned long)ext_cali_start;
rc = create_tas2781_cali_start_ktrl(priv, &cali_ctrls[i]);
if (rc != 0)
return rc;
i++;
}
return snd_soc_add_component_controls(priv->codec, cali_ctrls,