]> git.hungrycats.org Git - linux/commitdiff
ASoC: tas2781: Refactor calibration start kcontrol creation to separate helper
authorShenghao Ding <shenghao-ding@ti.com>
Thu, 13 Aug 2026 08:05:40 +0000 (16:05 +0800)
committerMark Brown <broonie@kernel.org>
Thu, 13 Aug 2026 18:19:12 +0000 (19:19 +0100)
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>
sound/soc/codecs/tas2781-i2c.c

index c029345b4644421be863f53ea1e73d475d5e0ae4..6ea4d6488f4e02181ba2fbe7c16199be48846bd3 100644 (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,