Skip to content

Commit

Permalink
ASoC: soc-core: add component lookup functions
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Kuninori Morimoto authored and Mark Brown committed Oct 4, 2017
1 parent 7ba236c commit 7dd5d0d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions include/sound/soc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
26 changes: 26 additions & 0 deletions sound/soc/soc-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7dd5d0d

Please sign in to comment.