ASoC: soc-core: add component lookup functions
authorKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Mon, 2 Oct 2017 05:09:52 +0000 (05:09 +0000)
committerMark Brown <broonie@kernel.org>
Wed, 4 Oct 2017 11:27:18 +0000 (12:27 +0100)
ALSA SoC platform/codec will be replaced to component soon.
This means 1 device might have multiple components. But current
unregister component function only checks "dev" to find it.
This means, unexpected component might be unregistered by current
function.
But, it is no problem if driver registered only 1 component.

To prepare avoid this issue, this patch adds new component
lookup function. it finds component by "dev" and "driver name".

Here, the reason why it uses "driver name" is that "component name"
was created by fmt_single_name() and difficult to use it from driver.
Driver of course knows its "driver name", thus, using it is more easy.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
include/sound/soc.h
sound/soc/soc-core.c

index d776cdee30d70d99e80a1909c3fb14774d92cfd5..11ca867033bd7d906056c581343f97070bdd4689 100644 (file)
@@ -475,6 +475,8 @@ int devm_snd_soc_register_component(struct device *dev,
                         const struct snd_soc_component_driver *component_driver,
                         struct snd_soc_dai_driver *dai_drv, int num_dai);
 void snd_soc_unregister_component(struct device *dev);
+struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
+                                                  const char *driver_name);
 int snd_soc_cache_init(struct snd_soc_codec *codec);
 int snd_soc_cache_exit(struct snd_soc_codec *codec);
 
index fb3435121172539c6725c117143448d74a1d3c85..6ec127346e9c457df78ba125cb274029ca895fdf 100644 (file)
@@ -3481,6 +3481,32 @@ void snd_soc_unregister_component(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
 
+struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
+                                                  const char *driver_name)
+{
+       struct snd_soc_component *component;
+       struct snd_soc_component *ret;
+
+       ret = NULL;
+       mutex_lock(&client_mutex);
+       list_for_each_entry(component, &component_list, list) {
+               if (dev != component->dev)
+                       continue;
+
+               if (driver_name &&
+                   (driver_name != component->driver->name) &&
+                   (strcmp(component->driver->name, driver_name) != 0))
+                       continue;
+
+               ret = component;
+               break;
+       }
+       mutex_unlock(&client_mutex);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
+
 static int snd_soc_platform_drv_probe(struct snd_soc_component *component)
 {
        struct snd_soc_platform *platform = snd_soc_component_to_platform(component);