Commit bb4b894a authored by Srinivas Kandagatla's avatar Srinivas Kandagatla Committed by Mark Brown

ASoC: core: add support to card re-bind using component framework

This patch aims at achieving dynamic behaviour of audio card when
the dependent components disappear and reappear.

With this patch the card is removed if any of the dependent component
is removed and card is added back if the dependent component comes back.
All this is done using component framework and matching based on
component name.
Signed-off-by: default avatarSrinivas Kandagatla <srinivas.kandagatla@linaro.org>
Reviewed-by: default avatarVinod Koul <vkoul@kernel.org>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 19e023e3
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/component.h>
#include <linux/regmap.h> #include <linux/regmap.h>
#include <linux/log2.h> #include <linux/log2.h>
#include <sound/core.h> #include <sound/core.h>
...@@ -1090,6 +1091,12 @@ struct snd_soc_card { ...@@ -1090,6 +1091,12 @@ struct snd_soc_card {
struct work_struct deferred_resume_work; struct work_struct deferred_resume_work;
/* component framework related */
bool components_added;
/* set in machine driver to enable/disable auto re-binding */
bool auto_bind;
struct component_match *match;
/* lists of probed devices belonging to this card */ /* lists of probed devices belonging to this card */
struct list_head component_dev_list; struct list_head component_dev_list;
......
...@@ -279,11 +279,28 @@ static inline void snd_soc_debugfs_exit(void) ...@@ -279,11 +279,28 @@ static inline void snd_soc_debugfs_exit(void)
#endif #endif
static int snd_soc_card_comp_compare(struct device *dev, void *data)
{
struct snd_soc_component *component;
lockdep_assert_held(&client_mutex);
list_for_each_entry(component, &component_list, list) {
if (dev == component->dev) {
if (!strcmp(component->name, data))
return 1;
break;
}
}
return 0;
}
static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd, static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd,
struct snd_soc_component *component) struct snd_soc_component *component)
{ {
struct snd_soc_rtdcom_list *rtdcom; struct snd_soc_rtdcom_list *rtdcom;
struct snd_soc_rtdcom_list *new_rtdcom; struct snd_soc_rtdcom_list *new_rtdcom;
char *cname;
for_each_rtdcom(rtd, rtdcom) { for_each_rtdcom(rtd, rtdcom) {
/* already connected */ /* already connected */
...@@ -300,6 +317,13 @@ static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd, ...@@ -300,6 +317,13 @@ static int snd_soc_rtdcom_add(struct snd_soc_pcm_runtime *rtd,
list_add_tail(&new_rtdcom->list, &rtd->component_list); list_add_tail(&new_rtdcom->list, &rtd->component_list);
if (rtd->card->auto_bind && !rtd->card->components_added) {
cname = devm_kasprintf(rtd->card->dev, GFP_KERNEL,
"%s", component->name);
component_match_add(rtd->card->dev, &rtd->card->match,
snd_soc_card_comp_compare, cname);
}
return 0; return 0;
} }
...@@ -835,6 +859,25 @@ static bool soc_is_dai_link_bound(struct snd_soc_card *card, ...@@ -835,6 +859,25 @@ static bool soc_is_dai_link_bound(struct snd_soc_card *card,
return false; return false;
} }
static int snd_soc_card_comp_bind(struct device *dev)
{
struct snd_soc_card *card = dev_get_drvdata(dev);
if (card->instantiated)
return 0;
return snd_soc_register_card(card);
}
static void snd_soc_card_comp_unbind(struct device *dev)
{
}
static const struct component_master_ops snd_soc_card_comp_ops = {
.bind = snd_soc_card_comp_bind,
.unbind = snd_soc_card_comp_unbind,
};
static int soc_bind_dai_link(struct snd_soc_card *card, static int soc_bind_dai_link(struct snd_soc_card *card,
struct snd_soc_dai_link *dai_link) struct snd_soc_dai_link *dai_link)
{ {
...@@ -2126,6 +2169,12 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card) ...@@ -2126,6 +2169,12 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
card->instantiated = 1; card->instantiated = 1;
snd_soc_dapm_sync(&card->dapm); snd_soc_dapm_sync(&card->dapm);
if (card->auto_bind && !card->components_added) {
component_master_add_with_match(card->dev,
&snd_soc_card_comp_ops,
card->match);
card->components_added = true;
}
mutex_unlock(&card->mutex); mutex_unlock(&card->mutex);
mutex_unlock(&client_mutex); mutex_unlock(&client_mutex);
...@@ -2749,6 +2798,9 @@ int snd_soc_unregister_card(struct snd_soc_card *card) ...@@ -2749,6 +2798,9 @@ int snd_soc_unregister_card(struct snd_soc_card *card)
dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name); dev_dbg(card->dev, "ASoC: Unregistered card '%s'\n", card->name);
} }
if (!card->auto_bind && card->components_added)
component_master_del(card->dev, &snd_soc_card_comp_ops);
return 0; return 0;
} }
EXPORT_SYMBOL_GPL(snd_soc_unregister_card); EXPORT_SYMBOL_GPL(snd_soc_unregister_card);
...@@ -3161,8 +3213,17 @@ int snd_soc_add_component(struct device *dev, ...@@ -3161,8 +3213,17 @@ int snd_soc_add_component(struct device *dev,
snd_soc_component_add(component); snd_soc_component_add(component);
ret = component_add(dev, NULL);
if (ret < 0) {
dev_err(dev, "ASoC: Failed to add Component: %d\n", ret);
goto err_comp;
}
return 0; return 0;
err_comp:
soc_remove_component(component);
snd_soc_unregister_dais(component);
err_cleanup: err_cleanup:
snd_soc_component_cleanup(component); snd_soc_component_cleanup(component);
err_free: err_free:
...@@ -3210,6 +3271,7 @@ static int __snd_soc_unregister_component(struct device *dev) ...@@ -3210,6 +3271,7 @@ static int __snd_soc_unregister_component(struct device *dev)
mutex_unlock(&client_mutex); mutex_unlock(&client_mutex);
if (found) { if (found) {
component_del(dev, NULL);
snd_soc_component_cleanup(component); snd_soc_component_cleanup(component);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment