Commit 68f89ad8 authored by Mark Brown's avatar Mark Brown

ASoC: Factor out boiler plate for DAPM event generation

Make the DAPM sequence execution look a bit nicer by factoring out the
code to invoke an event into a single function since it's all the same
pretty much.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
parent 00fb0d98
...@@ -726,13 +726,55 @@ static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget, ...@@ -726,13 +726,55 @@ static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
list_add_tail(&new_widget->power_list, list); list_add_tail(&new_widget->power_list, list);
} }
static void dapm_seq_check_event(struct snd_soc_dapm_context *dapm,
struct snd_soc_dapm_widget *w, int event)
{
struct snd_soc_card *card = dapm->card;
const char *ev_name;
int power, ret;
switch (event) {
case SND_SOC_DAPM_PRE_PMU:
ev_name = "PRE_PMU";
power = 1;
break;
case SND_SOC_DAPM_POST_PMU:
ev_name = "POST_PMU";
power = 1;
break;
case SND_SOC_DAPM_PRE_PMD:
ev_name = "PRE_PMD";
power = 0;
break;
case SND_SOC_DAPM_POST_PMD:
ev_name = "POST_PMD";
power = 0;
break;
default:
BUG();
return;
}
if (w->power != power)
return;
if (w->event && (w->event_flags & event)) {
pop_dbg(dapm->dev, card->pop_time, "pop test : %s %s\n",
w->name, ev_name);
ret = w->event(w, NULL, event);
if (ret < 0)
pr_err("%s: %s event failed: %d\n",
ev_name, w->name, ret);
}
}
/* Apply the coalesced changes from a DAPM sequence */ /* Apply the coalesced changes from a DAPM sequence */
static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm, static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
struct list_head *pending) struct list_head *pending)
{ {
struct snd_soc_dapm_widget *w;
struct snd_soc_card *card = dapm->card; struct snd_soc_card *card = dapm->card;
int reg, power, ret; struct snd_soc_dapm_widget *w;
int reg, power;
unsigned int value = 0; unsigned int value = 0;
unsigned int mask = 0; unsigned int mask = 0;
unsigned int cur_mask; unsigned int cur_mask;
...@@ -757,29 +799,9 @@ static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm, ...@@ -757,29 +799,9 @@ static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
"pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n", "pop test : Queue %s: reg=0x%x, 0x%x/0x%x\n",
w->name, reg, value, mask); w->name, reg, value, mask);
/* power up pre event */ /* Check for events */
if (w->power && w->event && dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMU);
(w->event_flags & SND_SOC_DAPM_PRE_PMU)) { dapm_seq_check_event(dapm, w, SND_SOC_DAPM_PRE_PMD);
pop_dbg(dapm->dev, card->pop_time,
"pop test : %s PRE_PMU\n", w->name);
ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMU);
if (ret < 0)
dev_err(dapm->dev,
"%s: pre event failed: %d\n",
w->name, ret);
}
/* power down pre event */
if (!w->power && w->event &&
(w->event_flags & SND_SOC_DAPM_PRE_PMD)) {
pop_dbg(dapm->dev, card->pop_time,
"pop test : %s PRE_PMD\n", w->name);
ret = w->event(w, NULL, SND_SOC_DAPM_PRE_PMD);
if (ret < 0)
dev_err(dapm->dev,
"%s: pre event failed: %d\n",
w->name, ret);
}
} }
if (reg >= 0) { if (reg >= 0) {
...@@ -791,30 +813,8 @@ static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm, ...@@ -791,30 +813,8 @@ static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
} }
list_for_each_entry(w, pending, power_list) { list_for_each_entry(w, pending, power_list) {
/* power up post event */ dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMU);
if (w->power && w->event && dapm_seq_check_event(dapm, w, SND_SOC_DAPM_POST_PMD);
(w->event_flags & SND_SOC_DAPM_POST_PMU)) {
pop_dbg(dapm->dev, card->pop_time,
"pop test : %s POST_PMU\n", w->name);
ret = w->event(w,
NULL, SND_SOC_DAPM_POST_PMU);
if (ret < 0)
dev_err(dapm->dev,
"%s: post event failed: %d\n",
w->name, ret);
}
/* power down post event */
if (!w->power && w->event &&
(w->event_flags & SND_SOC_DAPM_POST_PMD)) {
pop_dbg(dapm->dev, card->pop_time,
"pop test : %s POST_PMD\n", w->name);
ret = w->event(w, NULL, SND_SOC_DAPM_POST_PMD);
if (ret < 0)
dev_err(dapm->dev,
"%s: post event failed: %d\n",
w->name, ret);
}
} }
} }
......
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