OSDN Git Service

ASoC: soc-component: add soc_component_pin() and share code
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Thu, 4 Jun 2020 08:06:11 +0000 (17:06 +0900)
committerMark Brown <broonie@kernel.org>
Mon, 15 Jun 2020 17:21:18 +0000 (18:21 +0100)
soc-component has too many snd_soc_component_xxx_pin_xxx() functions.
The difference between these functions are used function name and
enable/disable.
This patch adds common soc_component_pin() and share code.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Reviewed-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Link: https://lore.kernel.org/r/87tuzrw8zw.wl-kuninori.morimoto.gx@renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/soc-component.c

index 785a038..76f4b95 100644 (file)
@@ -77,8 +77,10 @@ int snd_soc_component_set_bias_level(struct snd_soc_component *component,
        return 0;
 }
 
-int snd_soc_component_enable_pin(struct snd_soc_component *component,
-                                const char *pin)
+static int soc_component_pin(struct snd_soc_component *component,
+                            const char *pin,
+                            int (*pin_func)(struct snd_soc_dapm_context *dapm,
+                                            const char *pin))
 {
        struct snd_soc_dapm_context *dapm =
                snd_soc_component_get_dapm(component);
@@ -86,170 +88,71 @@ int snd_soc_component_enable_pin(struct snd_soc_component *component,
        int ret;
 
        if (!component->name_prefix)
-               return snd_soc_dapm_enable_pin(dapm, pin);
+               return pin_func(dapm, pin);
 
        full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
        if (!full_name)
                return -ENOMEM;
 
-       ret = snd_soc_dapm_enable_pin(dapm, full_name);
+       ret = pin_func(dapm, full_name);
        kfree(full_name);
 
        return ret;
 }
+
+int snd_soc_component_enable_pin(struct snd_soc_component *component,
+                                const char *pin)
+{
+       return soc_component_pin(component, pin, snd_soc_dapm_enable_pin);
+}
 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin);
 
 int snd_soc_component_enable_pin_unlocked(struct snd_soc_component *component,
                                          const char *pin)
 {
-       struct snd_soc_dapm_context *dapm =
-               snd_soc_component_get_dapm(component);
-       char *full_name;
-       int ret;
-
-       if (!component->name_prefix)
-               return snd_soc_dapm_enable_pin_unlocked(dapm, pin);
-
-       full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
-       if (!full_name)
-               return -ENOMEM;
-
-       ret = snd_soc_dapm_enable_pin_unlocked(dapm, full_name);
-       kfree(full_name);
-
-       return ret;
+       return soc_component_pin(component, pin, snd_soc_dapm_enable_pin_unlocked);
 }
 EXPORT_SYMBOL_GPL(snd_soc_component_enable_pin_unlocked);
 
 int snd_soc_component_disable_pin(struct snd_soc_component *component,
                                  const char *pin)
 {
-       struct snd_soc_dapm_context *dapm =
-               snd_soc_component_get_dapm(component);
-       char *full_name;
-       int ret;
-
-       if (!component->name_prefix)
-               return snd_soc_dapm_disable_pin(dapm, pin);
-
-       full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
-       if (!full_name)
-               return -ENOMEM;
-
-       ret = snd_soc_dapm_disable_pin(dapm, full_name);
-       kfree(full_name);
-
-       return ret;
+       return soc_component_pin(component, pin, snd_soc_dapm_disable_pin);
 }
 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin);
 
 int snd_soc_component_disable_pin_unlocked(struct snd_soc_component *component,
                                           const char *pin)
 {
-       struct snd_soc_dapm_context *dapm =
-               snd_soc_component_get_dapm(component);
-       char *full_name;
-       int ret;
-
-       if (!component->name_prefix)
-               return snd_soc_dapm_disable_pin_unlocked(dapm, pin);
-
-       full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
-       if (!full_name)
-               return -ENOMEM;
-
-       ret = snd_soc_dapm_disable_pin_unlocked(dapm, full_name);
-       kfree(full_name);
-
-       return ret;
+       return soc_component_pin(component, pin, snd_soc_dapm_disable_pin_unlocked);
 }
 EXPORT_SYMBOL_GPL(snd_soc_component_disable_pin_unlocked);
 
 int snd_soc_component_nc_pin(struct snd_soc_component *component,
                             const char *pin)
 {
-       struct snd_soc_dapm_context *dapm =
-               snd_soc_component_get_dapm(component);
-       char *full_name;
-       int ret;
-
-       if (!component->name_prefix)
-               return snd_soc_dapm_nc_pin(dapm, pin);
-
-       full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
-       if (!full_name)
-               return -ENOMEM;
-
-       ret = snd_soc_dapm_nc_pin(dapm, full_name);
-       kfree(full_name);
-
-       return ret;
+       return soc_component_pin(component, pin, snd_soc_dapm_nc_pin);
 }
 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin);
 
 int snd_soc_component_nc_pin_unlocked(struct snd_soc_component *component,
                                      const char *pin)
 {
-       struct snd_soc_dapm_context *dapm =
-               snd_soc_component_get_dapm(component);
-       char *full_name;
-       int ret;
-
-       if (!component->name_prefix)
-               return snd_soc_dapm_nc_pin_unlocked(dapm, pin);
-
-       full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
-       if (!full_name)
-               return -ENOMEM;
-
-       ret = snd_soc_dapm_nc_pin_unlocked(dapm, full_name);
-       kfree(full_name);
-
-       return ret;
+       return soc_component_pin(component, pin, snd_soc_dapm_nc_pin_unlocked);
 }
 EXPORT_SYMBOL_GPL(snd_soc_component_nc_pin_unlocked);
 
 int snd_soc_component_get_pin_status(struct snd_soc_component *component,
                                     const char *pin)
 {
-       struct snd_soc_dapm_context *dapm =
-               snd_soc_component_get_dapm(component);
-       char *full_name;
-       int ret;
-
-       if (!component->name_prefix)
-               return snd_soc_dapm_get_pin_status(dapm, pin);
-
-       full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
-       if (!full_name)
-               return -ENOMEM;
-
-       ret = snd_soc_dapm_get_pin_status(dapm, full_name);
-       kfree(full_name);
-
-       return ret;
+       return soc_component_pin(component, pin, snd_soc_dapm_get_pin_status);
 }
 EXPORT_SYMBOL_GPL(snd_soc_component_get_pin_status);
 
 int snd_soc_component_force_enable_pin(struct snd_soc_component *component,
                                       const char *pin)
 {
-       struct snd_soc_dapm_context *dapm =
-               snd_soc_component_get_dapm(component);
-       char *full_name;
-       int ret;
-
-       if (!component->name_prefix)
-               return snd_soc_dapm_force_enable_pin(dapm, pin);
-
-       full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
-       if (!full_name)
-               return -ENOMEM;
-
-       ret = snd_soc_dapm_force_enable_pin(dapm, full_name);
-       kfree(full_name);
-
-       return ret;
+       return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin);
 }
 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin);
 
@@ -257,22 +160,7 @@ int snd_soc_component_force_enable_pin_unlocked(
        struct snd_soc_component *component,
        const char *pin)
 {
-       struct snd_soc_dapm_context *dapm =
-               snd_soc_component_get_dapm(component);
-       char *full_name;
-       int ret;
-
-       if (!component->name_prefix)
-               return snd_soc_dapm_force_enable_pin_unlocked(dapm, pin);
-
-       full_name = kasprintf(GFP_KERNEL, "%s %s", component->name_prefix, pin);
-       if (!full_name)
-               return -ENOMEM;
-
-       ret = snd_soc_dapm_force_enable_pin_unlocked(dapm, full_name);
-       kfree(full_name);
-
-       return ret;
+       return soc_component_pin(component, pin, snd_soc_dapm_force_enable_pin_unlocked);
 }
 EXPORT_SYMBOL_GPL(snd_soc_component_force_enable_pin_unlocked);