Commit 42aa3418 authored by Mark Brown's avatar Mark Brown

ASoC: Factor out DAPM widget power check into separate function

Essentially simple code motion to facilitate refactoring of the power
decisions.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 20a41eac
......@@ -523,38 +523,17 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w,
EXPORT_SYMBOL_GPL(dapm_reg_event);
/*
* Scan each dapm widget for complete audio path.
* A complete path is a route that has valid endpoints i.e.:-
*
* o DAC to output pin.
* o Input Pin to ADC.
* o Input pin to Output pin (bypass, sidetone)
* o DAC to ADC (loopback).
* Scan a single DAPM widget for a complete audio path and update the
* power status appropriately.
*/
static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
static int dapm_power_widget(struct snd_soc_codec *codec, int event,
struct snd_soc_dapm_widget *w)
{
struct snd_soc_dapm_widget *w;
int in, out, i, c = 1, *seq = NULL, ret = 0, power_change, power;
/* do we have a sequenced stream event */
if (event == SND_SOC_DAPM_STREAM_START) {
c = ARRAY_SIZE(dapm_up_seq);
seq = dapm_up_seq;
} else if (event == SND_SOC_DAPM_STREAM_STOP) {
c = ARRAY_SIZE(dapm_down_seq);
seq = dapm_down_seq;
}
for(i = 0; i < c; i++) {
list_for_each_entry(w, &codec->dapm_widgets, list) {
/* is widget in stream order */
if (seq && seq[i] && w->id != seq[i])
continue;
int in, out, power_change, power, ret;
/* vmid - no action */
if (w->id == snd_soc_dapm_vmid)
continue;
return 0;
/* active ADC */
if (w->id == snd_soc_dapm_adc && w->active) {
......@@ -562,7 +541,7 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
dapm_clear_walk(w->codec);
w->power = (in != 0) ? 1 : 0;
dapm_update_bits(w);
continue;
return 0;
}
/* active DAC */
......@@ -571,13 +550,13 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
dapm_clear_walk(w->codec);
w->power = (out != 0) ? 1 : 0;
dapm_update_bits(w);
continue;
return 0;
}
/* pre and post event widgets */
if (w->id == snd_soc_dapm_pre) {
if (!w->event)
continue;
return 0;
if (event == SND_SOC_DAPM_STREAM_START) {
ret = w->event(w,
......@@ -590,11 +569,11 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
if (ret < 0)
return ret;
}
continue;
return 0;
}
if (w->id == snd_soc_dapm_post) {
if (!w->event)
continue;
return 0;
if (event == SND_SOC_DAPM_STREAM_START) {
ret = w->event(w,
......@@ -607,7 +586,7 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
if (ret < 0)
return ret;
}
continue;
return 0;
}
/* all other widgets */
......@@ -616,11 +595,11 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
out = is_connected_output_ep(w);
dapm_clear_walk(w->codec);
power = (out != 0 && in != 0) ? 1 : 0;
power_change = (w->power == power) ? 0: 1;
power_change = (w->power == power) ? 0 : 1;
w->power = power;
if (!power_change)
continue;
return 0;
/* call any power change event handlers */
if (w->event)
......@@ -670,10 +649,47 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
if (ret < 0)
return ret;
}
return 0;
}
/*
* Scan each dapm widget for complete audio path.
* A complete path is a route that has valid endpoints i.e.:-
*
* o DAC to output pin.
* o Input Pin to ADC.
* o Input pin to Output pin (bypass, sidetone)
* o DAC to ADC (loopback).
*/
static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
{
struct snd_soc_dapm_widget *w;
int i, c = 1, *seq = NULL, ret = 0;
/* do we have a sequenced stream event */
if (event == SND_SOC_DAPM_STREAM_START) {
c = ARRAY_SIZE(dapm_up_seq);
seq = dapm_up_seq;
} else if (event == SND_SOC_DAPM_STREAM_STOP) {
c = ARRAY_SIZE(dapm_down_seq);
seq = dapm_down_seq;
}
}
for (i = 0; i < c; i++) {
list_for_each_entry(w, &codec->dapm_widgets, list) {
/* is widget in stream order */
if (seq && seq[i] && w->id != seq[i])
continue;
ret = dapm_power_widget(codec, event, w);
if (ret != 0)
return ret;
}
}
return 0;
}
#ifdef DEBUG
......
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