Commit 7be31be8 authored by Jarkko Nikula's avatar Jarkko Nikula Committed by Mark Brown

ASoC: Extend DAPM to handle power changes on cross-device paths

Power change event like stream start/stop or kcontrol change in a
cross-device path originates from one device but codec bias and widget power
changes must be populated to another devices on that path as well.

This patch modifies the dapm_power_widgets so that all the widgets on a
sound card are checked for a power change, not just those that are specific
to originating device. Also bias management is extended to check all the
devices. Only exception in bias management are widgetless codecs whose bias
state is changed only if power change is originating from that context.

DAPM context test is added to dapm_seq_run to take care of if power sequence
extends to an another device which requires separate register writes.
Signed-off-by: default avatarJarkko Nikula <jhnikula@gmail.com>
Acked-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 97c866de
...@@ -471,6 +471,11 @@ struct snd_soc_dapm_context { ...@@ -471,6 +471,11 @@ struct snd_soc_dapm_context {
struct device *dev; /* from parent - for debug */ struct device *dev; /* from parent - for debug */
struct snd_soc_codec *codec; /* parent codec */ struct snd_soc_codec *codec; /* parent codec */
struct snd_soc_card *card; /* parent card */ struct snd_soc_card *card; /* parent card */
/* used during DAPM updates */
int dev_power;
struct list_head list;
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
struct dentry *debugfs_dapm; struct dentry *debugfs_dapm;
#endif #endif
......
...@@ -663,6 +663,7 @@ struct snd_soc_card { ...@@ -663,6 +663,7 @@ struct snd_soc_card {
struct list_head widgets; struct list_head widgets;
struct list_head paths; struct list_head paths;
struct list_head dapm_list;
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
struct dentry *debugfs_card_root; struct dentry *debugfs_card_root;
......
...@@ -1427,6 +1427,7 @@ static int soc_probe_codec(struct snd_soc_card *card, ...@@ -1427,6 +1427,7 @@ static int soc_probe_codec(struct snd_soc_card *card,
/* mark codec as probed and add to card codec list */ /* mark codec as probed and add to card codec list */
codec->probed = 1; codec->probed = 1;
list_add(&codec->card_list, &card->codec_dev_list); list_add(&codec->card_list, &card->codec_dev_list);
list_add(&codec->dapm.list, &card->dapm_list);
return ret; return ret;
} }
...@@ -1881,6 +1882,7 @@ static int soc_probe(struct platform_device *pdev) ...@@ -1881,6 +1882,7 @@ static int soc_probe(struct platform_device *pdev)
INIT_LIST_HEAD(&card->platform_dev_list); INIT_LIST_HEAD(&card->platform_dev_list);
INIT_LIST_HEAD(&card->widgets); INIT_LIST_HEAD(&card->widgets);
INIT_LIST_HEAD(&card->paths); INIT_LIST_HEAD(&card->paths);
INIT_LIST_HEAD(&card->dapm_list);
soc_init_card_debugfs(card); soc_init_card_debugfs(card);
......
...@@ -847,19 +847,22 @@ static void dapm_seq_run(struct snd_soc_dapm_context *dapm, ...@@ -847,19 +847,22 @@ static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
LIST_HEAD(pending); LIST_HEAD(pending);
int cur_sort = -1; int cur_sort = -1;
int cur_reg = SND_SOC_NOPM; int cur_reg = SND_SOC_NOPM;
struct snd_soc_dapm_context *cur_dapm = NULL;
int ret; int ret;
list_for_each_entry_safe(w, n, list, power_list) { list_for_each_entry_safe(w, n, list, power_list) {
ret = 0; ret = 0;
/* Do we need to apply any queued changes? */ /* Do we need to apply any queued changes? */
if (sort[w->id] != cur_sort || w->reg != cur_reg) { if (sort[w->id] != cur_sort || w->reg != cur_reg ||
w->dapm != cur_dapm) {
if (!list_empty(&pending)) if (!list_empty(&pending))
dapm_seq_run_coalesced(dapm, &pending); dapm_seq_run_coalesced(cur_dapm, &pending);
INIT_LIST_HEAD(&pending); INIT_LIST_HEAD(&pending);
cur_sort = -1; cur_sort = -1;
cur_reg = SND_SOC_NOPM; cur_reg = SND_SOC_NOPM;
cur_dapm = NULL;
} }
switch (w->id) { switch (w->id) {
...@@ -903,6 +906,7 @@ static void dapm_seq_run(struct snd_soc_dapm_context *dapm, ...@@ -903,6 +906,7 @@ static void dapm_seq_run(struct snd_soc_dapm_context *dapm,
/* Queue it up for application */ /* Queue it up for application */
cur_sort = sort[w->id]; cur_sort = sort[w->id];
cur_reg = w->reg; cur_reg = w->reg;
cur_dapm = w->dapm;
list_move(&w->power_list, &pending); list_move(&w->power_list, &pending);
break; break;
} }
...@@ -929,20 +933,22 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) ...@@ -929,20 +933,22 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
{ {
struct snd_soc_card *card = dapm->codec->card; struct snd_soc_card *card = dapm->codec->card;
struct snd_soc_dapm_widget *w; struct snd_soc_dapm_widget *w;
struct snd_soc_dapm_context *d;
LIST_HEAD(up_list); LIST_HEAD(up_list);
LIST_HEAD(down_list); LIST_HEAD(down_list);
int ret = 0; int ret = 0;
int power; int power;
int sys_power = 0;
trace_snd_soc_dapm_start(card); trace_snd_soc_dapm_start(card);
list_for_each_entry(d, &card->dapm_list, list)
if (d->n_widgets)
d->dev_power = 0;
/* Check which widgets we need to power and store them in /* Check which widgets we need to power and store them in
* lists indicating if they should be powered up or down. * lists indicating if they should be powered up or down.
*/ */
list_for_each_entry(w, &card->widgets, list) { list_for_each_entry(w, &card->widgets, list) {
if (w->dapm != dapm)
continue;
switch (w->id) { switch (w->id) {
case snd_soc_dapm_pre: case snd_soc_dapm_pre:
dapm_seq_insert(w, &down_list, dapm_down_seq); dapm_seq_insert(w, &down_list, dapm_down_seq);
...@@ -960,7 +966,7 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) ...@@ -960,7 +966,7 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
else else
power = 1; power = 1;
if (power) if (power)
sys_power = 1; w->dapm->dev_power = 1;
if (w->power == power) if (w->power == power)
continue; continue;
...@@ -984,22 +990,22 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) ...@@ -984,22 +990,22 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
switch (event) { switch (event) {
case SND_SOC_DAPM_STREAM_START: case SND_SOC_DAPM_STREAM_START:
case SND_SOC_DAPM_STREAM_RESUME: case SND_SOC_DAPM_STREAM_RESUME:
sys_power = 1; dapm->dev_power = 1;
break; break;
case SND_SOC_DAPM_STREAM_STOP: case SND_SOC_DAPM_STREAM_STOP:
sys_power = !!dapm->codec->active; dapm->dev_power = !!dapm->codec->active;
break; break;
case SND_SOC_DAPM_STREAM_SUSPEND: case SND_SOC_DAPM_STREAM_SUSPEND:
sys_power = 0; dapm->dev_power = 0;
break; break;
case SND_SOC_DAPM_STREAM_NOP: case SND_SOC_DAPM_STREAM_NOP:
switch (dapm->bias_level) { switch (dapm->bias_level) {
case SND_SOC_BIAS_STANDBY: case SND_SOC_BIAS_STANDBY:
case SND_SOC_BIAS_OFF: case SND_SOC_BIAS_OFF:
sys_power = 0; dapm->dev_power = 0;
break; break;
default: default:
sys_power = 1; dapm->dev_power = 1;
break; break;
} }
break; break;
...@@ -1008,22 +1014,25 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) ...@@ -1008,22 +1014,25 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
} }
} }
if (sys_power && dapm->bias_level == SND_SOC_BIAS_OFF) { list_for_each_entry(d, &dapm->card->dapm_list, list) {
ret = snd_soc_dapm_set_bias_level(card, dapm, if (d->dev_power && d->bias_level == SND_SOC_BIAS_OFF) {
ret = snd_soc_dapm_set_bias_level(card, d,
SND_SOC_BIAS_STANDBY); SND_SOC_BIAS_STANDBY);
if (ret != 0) if (ret != 0)
dev_err(dapm->dev, dev_err(d->dev,
"Failed to turn on bias: %d\n", ret); "Failed to turn on bias: %d\n", ret);
} }
/* If we're changing to all on or all off then prepare */ /* If we're changing to all on or all off then prepare */
if ((sys_power && dapm->bias_level == SND_SOC_BIAS_STANDBY) || if ((d->dev_power && d->bias_level == SND_SOC_BIAS_STANDBY) ||
(!sys_power && dapm->bias_level == SND_SOC_BIAS_ON)) { (!d->dev_power && d->bias_level == SND_SOC_BIAS_ON)) {
ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_PREPARE); ret = snd_soc_dapm_set_bias_level(card, d,
SND_SOC_BIAS_PREPARE);
if (ret != 0) if (ret != 0)
dev_err(dapm->dev, dev_err(d->dev,
"Failed to prepare bias: %d\n", ret); "Failed to prepare bias: %d\n", ret);
} }
}
/* Power down widgets first; try to avoid amplifying pops. */ /* Power down widgets first; try to avoid amplifying pops. */
dapm_seq_run(dapm, &down_list, event, dapm_down_seq); dapm_seq_run(dapm, &down_list, event, dapm_down_seq);
...@@ -1031,29 +1040,36 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event) ...@@ -1031,29 +1040,36 @@ static int dapm_power_widgets(struct snd_soc_dapm_context *dapm, int event)
/* Now power up. */ /* Now power up. */
dapm_seq_run(dapm, &up_list, event, dapm_up_seq); dapm_seq_run(dapm, &up_list, event, dapm_up_seq);
list_for_each_entry(d, &dapm->card->dapm_list, list) {
/* If we just powered the last thing off drop to standby bias */ /* If we just powered the last thing off drop to standby bias */
if (dapm->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) { if (d->bias_level == SND_SOC_BIAS_PREPARE && !d->dev_power) {
ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_STANDBY); ret = snd_soc_dapm_set_bias_level(card, d,
SND_SOC_BIAS_STANDBY);
if (ret != 0) if (ret != 0)
dev_err(dapm->dev, dev_err(d->dev,
"Failed to apply standby bias: %d\n", ret); "Failed to apply standby bias: %d\n",
ret);
} }
/* If we're in standby and can support bias off then do that */ /* If we're in standby and can support bias off then do that */
if (dapm->bias_level == SND_SOC_BIAS_STANDBY && if (d->bias_level == SND_SOC_BIAS_STANDBY &&
dapm->idle_bias_off) { d->idle_bias_off) {
ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_OFF); ret = snd_soc_dapm_set_bias_level(card, d,
SND_SOC_BIAS_OFF);
if (ret != 0) if (ret != 0)
dev_err(dapm->dev, dev_err(d->dev,
"Failed to turn off bias: %d\n", ret); "Failed to turn off bias: %d\n", ret);
} }
/* If we just powered up then move to active bias */ /* If we just powered up then move to active bias */
if (dapm->bias_level == SND_SOC_BIAS_PREPARE && sys_power) { if (d->bias_level == SND_SOC_BIAS_PREPARE && d->dev_power) {
ret = snd_soc_dapm_set_bias_level(card, dapm, SND_SOC_BIAS_ON); ret = snd_soc_dapm_set_bias_level(card, d,
SND_SOC_BIAS_ON);
if (ret != 0) if (ret != 0)
dev_err(dapm->dev, dev_err(d->dev,
"Failed to apply active bias: %d\n", ret); "Failed to apply active bias: %d\n",
ret);
}
} }
pop_dbg(dapm->dev, card->pop_time, pop_dbg(dapm->dev, card->pop_time,
...@@ -2309,6 +2325,7 @@ void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm) ...@@ -2309,6 +2325,7 @@ void snd_soc_dapm_free(struct snd_soc_dapm_context *dapm)
{ {
snd_soc_dapm_sys_remove(dapm->dev); snd_soc_dapm_sys_remove(dapm->dev);
dapm_free_widgets(dapm); dapm_free_widgets(dapm);
list_del(&dapm->list);
} }
EXPORT_SYMBOL_GPL(snd_soc_dapm_free); EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
......
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