Commit 6ea31b9f authored by Mark Brown's avatar Mark Brown

ASoC: Factor out DAPM power checks for DACs and ADCs

This also switches us to using a switch statement for the widget type
in dapm_power_widget().
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent cd0f2d47
...@@ -594,6 +594,34 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) ...@@ -594,6 +594,34 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
return out != 0 && in != 0; return out != 0 && in != 0;
} }
/* Check to see if an ADC has power */
static int dapm_adc_check_power(struct snd_soc_dapm_widget *w)
{
int in;
if (w->active) {
in = is_connected_input_ep(w);
dapm_clear_walk(w->codec);
return in != 0;
} else {
return dapm_generic_check_power(w);
}
}
/* Check to see if a DAC has power */
static int dapm_dac_check_power(struct snd_soc_dapm_widget *w)
{
int out;
if (w->active) {
out = is_connected_output_ep(w);
dapm_clear_walk(w->codec);
return out != 0;
} else {
return dapm_generic_check_power(w);
}
}
/* /*
* Scan a single DAPM widget for a complete audio path and update the * Scan a single DAPM widget for a complete audio path and update the
* power status appropriately. * power status appropriately.
...@@ -601,36 +629,23 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) ...@@ -601,36 +629,23 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w)
static int dapm_power_widget(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, power_change, power, ret; int power, ret;
/* vmid - no action */ /* Work out the new power state */
if (w->id == snd_soc_dapm_vmid) switch (w->id) {
case snd_soc_dapm_vmid:
/* No action required */
return 0; return 0;
/* active ADC */ case snd_soc_dapm_adc:
if (w->id == snd_soc_dapm_adc && w->active) { power = dapm_adc_check_power(w);
in = is_connected_input_ep(w); break;
dapm_clear_walk(w->codec);
power = (in != 0) ? 1 : 0;
if (power == w->power)
return 0;
w->power = power;
return dapm_generic_apply_power(w);
}
/* active DAC */ case snd_soc_dapm_dac:
if (w->id == snd_soc_dapm_dac && w->active) { power = dapm_dac_check_power(w);
out = is_connected_output_ep(w); break;
dapm_clear_walk(w->codec);
power = (out != 0) ? 1 : 0;
if (power == w->power)
return 0;
w->power = power;
return dapm_generic_apply_power(w);
}
/* pre and post event widgets */ case snd_soc_dapm_pre:
if (w->id == snd_soc_dapm_pre) {
if (!w->event) if (!w->event)
return 0; return 0;
...@@ -646,8 +661,8 @@ static int dapm_power_widget(struct snd_soc_codec *codec, int event, ...@@ -646,8 +661,8 @@ static int dapm_power_widget(struct snd_soc_codec *codec, int event,
return ret; return ret;
} }
return 0; return 0;
}
if (w->id == snd_soc_dapm_post) { case snd_soc_dapm_post:
if (!w->event) if (!w->event)
return 0; return 0;
...@@ -663,15 +678,15 @@ static int dapm_power_widget(struct snd_soc_codec *codec, int event, ...@@ -663,15 +678,15 @@ static int dapm_power_widget(struct snd_soc_codec *codec, int event,
return ret; return ret;
} }
return 0; return 0;
}
/* all other widgets */ default:
power = dapm_generic_check_power(w); power = dapm_generic_check_power(w);
power_change = (w->power == power) ? 0 : 1; break;
w->power = power; }
if (!power_change) if (w->power == power)
return 0; return 0;
w->power = power;
return dapm_generic_apply_power(w); return dapm_generic_apply_power(w);
} }
......
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