Commit 9949788b authored by Mark Brown's avatar Mark Brown

ASoC: Refactor DAPM suspend handling

Instead of using stream events to handle power down during suspend
integrate the handling with the normal widget path checking by
replacing all cases where we report a connected endpoint in a path
with a function snd_soc_dapm_suspend_check() which looks at the ALSA
power state for the card and reports false if we are in a D3 state.

Since the core moves us into D3 prior to initating the suspend all
power checks during suspend will cause the widgets to be powered
down. In order to ensure that widgets are powered up on resume set
the card to D2 at the start of resume handling (ALSA API calls
require D0 so we are still protected against userspace access).
Tested-by: default avatarPeter Ujfalusi <peter.ujfalusi@nokia.com>
Acked-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 50ae8384
...@@ -963,6 +963,9 @@ static void soc_resume_deferred(struct work_struct *work) ...@@ -963,6 +963,9 @@ static void soc_resume_deferred(struct work_struct *work)
dev_dbg(socdev->dev, "starting resume work\n"); dev_dbg(socdev->dev, "starting resume work\n");
/* Bring us up into D2 so that DAPM starts enabling things */
snd_power_change_state(codec->card, SNDRV_CTL_POWER_D2);
if (card->resume_pre) if (card->resume_pre)
card->resume_pre(pdev); card->resume_pre(pdev);
......
...@@ -430,6 +430,23 @@ static inline void dapm_clear_walk(struct snd_soc_codec *codec) ...@@ -430,6 +430,23 @@ static inline void dapm_clear_walk(struct snd_soc_codec *codec)
p->walked = 0; p->walked = 0;
} }
/* We implement power down on suspend by checking the power state of
* the ALSA card - when we are suspending the ALSA state for the card
* is set to D3.
*/
static int snd_soc_dapm_suspend_check(struct snd_soc_dapm_widget *widget)
{
struct snd_soc_codec *codec = widget->codec;
switch (snd_power_get_state(codec->card)) {
case SNDRV_CTL_POWER_D3hot:
case SNDRV_CTL_POWER_D3cold:
return 0;
default:
return 1;
}
}
/* /*
* Recursively check for a completed path to an active or physically connected * Recursively check for a completed path to an active or physically connected
* output widget. Returns number of complete paths. * output widget. Returns number of complete paths.
...@@ -446,7 +463,7 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) ...@@ -446,7 +463,7 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
case snd_soc_dapm_adc: case snd_soc_dapm_adc:
case snd_soc_dapm_aif_out: case snd_soc_dapm_aif_out:
if (widget->active) if (widget->active)
return 1; return snd_soc_dapm_suspend_check(widget);
default: default:
break; break;
} }
...@@ -454,12 +471,12 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget) ...@@ -454,12 +471,12 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
if (widget->connected) { if (widget->connected) {
/* connected pin ? */ /* connected pin ? */
if (widget->id == snd_soc_dapm_output && !widget->ext) if (widget->id == snd_soc_dapm_output && !widget->ext)
return 1; return snd_soc_dapm_suspend_check(widget);
/* connected jack or spk ? */ /* connected jack or spk ? */
if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk || if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
(widget->id == snd_soc_dapm_line && !list_empty(&widget->sources))) (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
return 1; return snd_soc_dapm_suspend_check(widget);
} }
list_for_each_entry(path, &widget->sinks, list_source) { list_for_each_entry(path, &widget->sinks, list_source) {
...@@ -492,7 +509,7 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) ...@@ -492,7 +509,7 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
case snd_soc_dapm_dac: case snd_soc_dapm_dac:
case snd_soc_dapm_aif_in: case snd_soc_dapm_aif_in:
if (widget->active) if (widget->active)
return 1; return snd_soc_dapm_suspend_check(widget);
default: default:
break; break;
} }
...@@ -500,16 +517,16 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget) ...@@ -500,16 +517,16 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
if (widget->connected) { if (widget->connected) {
/* connected pin ? */ /* connected pin ? */
if (widget->id == snd_soc_dapm_input && !widget->ext) if (widget->id == snd_soc_dapm_input && !widget->ext)
return 1; return snd_soc_dapm_suspend_check(widget);
/* connected VMID/Bias for lower pops */ /* connected VMID/Bias for lower pops */
if (widget->id == snd_soc_dapm_vmid) if (widget->id == snd_soc_dapm_vmid)
return 1; return snd_soc_dapm_suspend_check(widget);
/* connected jack ? */ /* connected jack ? */
if (widget->id == snd_soc_dapm_mic || if (widget->id == snd_soc_dapm_mic ||
(widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks))) (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
return 1; return snd_soc_dapm_suspend_check(widget);
} }
list_for_each_entry(path, &widget->sources, list_sink) { list_for_each_entry(path, &widget->sources, list_sink) {
...@@ -897,22 +914,12 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event) ...@@ -897,22 +914,12 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
if (!w->power_check) if (!w->power_check)
continue; continue;
/* If we're suspending then pull down all the if (!w->force)
* power. */ power = w->power_check(w);
switch (event) { else
case SND_SOC_DAPM_STREAM_SUSPEND: power = 1;
power = 0; if (power)
break; sys_power = 1;
default:
if (!w->force)
power = w->power_check(w);
else
power = 1;
if (power)
sys_power = 1;
break;
}
if (w->power == power) if (w->power == power)
continue; continue;
......
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