]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ASoC: topology: Create kcontrols based on their type
authorCezary Rojewski <cezary.rojewski@intel.com>
Mon, 17 Feb 2025 10:21:06 +0000 (11:21 +0100)
committerMark Brown <broonie@kernel.org>
Mon, 24 Feb 2025 16:01:51 +0000 (16:01 +0000)
Fields ->ops.info and ->type of struct snd_soc_tplg_ctl_hdr denote
info-operation type and control type respectively. These are two
different pieces of information. The info type is represented by
SND_SOC_TPLG_CTL_xxx and SND_SOC_TPLG_DAPM_CTL_xxx on UAPI side whereas
for control type it is SND_SOC_TPLG_TYPE_xxx (mixer, bytes or enum).

The type of the kcontrol to be created is currently guessed based on the
value of the ->ops.info. Use the ->type instead to correct and simplify
the code. With this change ops.info() can be customized by sound drivers
utilizing the ASoC-topology just like ops.get() and ops.put() can be.

Signed-off-by: Cezary Rojewski <cezary.rojewski@intel.com>
Link: https://patch.msgid.link/20250217102115.3539427-2-cezary.rojewski@intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-topology.c

index 9f4da061eff9e8769da8370cf8c590621f5b049f..921521a84e29728e8a6f865fe616c553edae9193 100644 (file)
@@ -220,15 +220,6 @@ static int get_widget_id(int tplg_type)
        return -EINVAL;
 }
 
-static inline void soc_bind_err(struct soc_tplg *tplg,
-       struct snd_soc_tplg_ctl_hdr *hdr, int index)
-{
-       dev_err(tplg->dev,
-               "ASoC: invalid control type (g,p,i) %d:%d:%d index %d at 0x%lx\n",
-               hdr->ops.get, hdr->ops.put, hdr->ops.info, index,
-               soc_tplg_get_offset(tplg));
-}
-
 static inline void soc_control_err(struct soc_tplg *tplg,
        struct snd_soc_tplg_ctl_hdr *hdr, const char *name)
 {
@@ -992,35 +983,26 @@ static int soc_tplg_kcontrol_elems_load(struct soc_tplg *tplg,
                        return -EINVAL;
                }
 
-               switch (le32_to_cpu(control_hdr->ops.info)) {
-               case SND_SOC_TPLG_CTL_VOLSW:
-               case SND_SOC_TPLG_CTL_STROBE:
-               case SND_SOC_TPLG_CTL_VOLSW_SX:
-               case SND_SOC_TPLG_CTL_VOLSW_XR_SX:
-               case SND_SOC_TPLG_CTL_RANGE:
-               case SND_SOC_TPLG_DAPM_CTL_VOLSW:
-               case SND_SOC_TPLG_DAPM_CTL_PIN:
+               switch (le32_to_cpu(control_hdr->type)) {
+               case SND_SOC_TPLG_TYPE_MIXER:
                        ret = soc_tplg_dmixer_create(tplg, le32_to_cpu(hdr->payload_size));
                        break;
-               case SND_SOC_TPLG_CTL_ENUM:
-               case SND_SOC_TPLG_CTL_ENUM_VALUE:
-               case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE:
-               case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT:
-               case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE:
+               case SND_SOC_TPLG_TYPE_ENUM:
                        ret = soc_tplg_denum_create(tplg, le32_to_cpu(hdr->payload_size));
                        break;
-               case SND_SOC_TPLG_CTL_BYTES:
+               case SND_SOC_TPLG_TYPE_BYTES:
                        ret = soc_tplg_dbytes_create(tplg, le32_to_cpu(hdr->payload_size));
                        break;
                default:
-                       soc_bind_err(tplg, control_hdr, i);
-                       return -EINVAL;
+                       ret = -EINVAL;
+                       break;
                }
+
                if (ret < 0) {
-                       dev_err(tplg->dev, "ASoC: invalid control\n");
+                       dev_err(tplg->dev, "ASoC: invalid control type: %d, index: %d at 0x%lx\n",
+                               control_hdr->type, i, soc_tplg_get_offset(tplg));
                        return ret;
                }
-
        }
 
        return 0;
@@ -1184,13 +1166,9 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
 
        for (i = 0; i < le32_to_cpu(w->num_kcontrols); i++) {
                control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos;
-               switch (le32_to_cpu(control_hdr->ops.info)) {
-               case SND_SOC_TPLG_CTL_VOLSW:
-               case SND_SOC_TPLG_CTL_STROBE:
-               case SND_SOC_TPLG_CTL_VOLSW_SX:
-               case SND_SOC_TPLG_CTL_VOLSW_XR_SX:
-               case SND_SOC_TPLG_CTL_RANGE:
-               case SND_SOC_TPLG_DAPM_CTL_VOLSW:
+
+               switch (le32_to_cpu(control_hdr->type)) {
+               case SND_SOC_TPLG_TYPE_MIXER:
                        /* volume mixer */
                        kc[i].index = mixer_count;
                        kcontrol_type[i] = SND_SOC_TPLG_TYPE_MIXER;
@@ -1199,11 +1177,7 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
                        if (ret < 0)
                                goto hdr_err;
                        break;
-               case SND_SOC_TPLG_CTL_ENUM:
-               case SND_SOC_TPLG_CTL_ENUM_VALUE:
-               case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE:
-               case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT:
-               case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE:
+               case SND_SOC_TPLG_TYPE_ENUM:
                        /* enumerated mixer */
                        kc[i].index = enum_count;
                        kcontrol_type[i] = SND_SOC_TPLG_TYPE_ENUM;
@@ -1212,7 +1186,7 @@ static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg,
                        if (ret < 0)
                                goto hdr_err;
                        break;
-               case SND_SOC_TPLG_CTL_BYTES:
+               case SND_SOC_TPLG_TYPE_BYTES:
                        /* bytes control */
                        kc[i].index = bytes_count;
                        kcontrol_type[i] = SND_SOC_TPLG_TYPE_BYTES;