Commit 0445bdf4 authored by Liam Girdwood's avatar Liam Girdwood Committed by Mark Brown

ASoC: dapm - Refactor widget IO functions in preparation for platform widgets.

This time with soc_widget_update_bits reflecting recent soc_update_bits changes.

Currently widget IO is tightly coupled to the CODEC drivers. Future platform DSP
devices have mixer components that can alter power usage and hence require full
DAPM support.

This provides a generic widget IO operation wrapper in preparation for
future patches that implement platform driver DAPM.
Signed-off-by: default avatarLiam Girdwood <lrg@ti.com>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 169d5a83
...@@ -124,6 +124,43 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget( ...@@ -124,6 +124,43 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL); return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
} }
static int soc_widget_read(struct snd_soc_dapm_widget *w, int reg)
{
if (w->codec)
return snd_soc_read(w->codec, reg);
return 0;
}
static int soc_widget_write(struct snd_soc_dapm_widget *w, int reg, int val)
{
if (w->codec)
return snd_soc_write(w->codec, reg, val);
return 0;
}
static int soc_widget_update_bits(struct snd_soc_dapm_widget *w,
unsigned short reg, unsigned int mask, unsigned int value)
{
int change;
unsigned int old, new;
int ret;
ret = soc_widget_read(w, reg);
if (ret < 0)
return ret;
old = ret;
new = (old & ~mask) | (value & mask);
change = old != new;
if (change) {
ret = soc_widget_write(w, reg, new);
if (ret < 0)
return ret;
}
return change;
}
/** /**
* snd_soc_dapm_set_bias_level - set the bias level for the system * snd_soc_dapm_set_bias_level - set the bias level for the system
* @dapm: DAPM context * @dapm: DAPM context
...@@ -181,7 +218,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w, ...@@ -181,7 +218,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
unsigned int mask = (1 << fls(max)) - 1; unsigned int mask = (1 << fls(max)) - 1;
unsigned int invert = mc->invert; unsigned int invert = mc->invert;
val = snd_soc_read(w->codec, reg); val = soc_widget_read(w, reg);
val = (val >> shift) & mask; val = (val >> shift) & mask;
if ((invert && !val) || (!invert && val)) if ((invert && !val) || (!invert && val))
...@@ -197,7 +234,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w, ...@@ -197,7 +234,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
for (bitmask = 1; bitmask < e->max; bitmask <<= 1) for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
; ;
val = snd_soc_read(w->codec, e->reg); val = soc_widget_read(w, e->reg);
item = (val >> e->shift_l) & (bitmask - 1); item = (val >> e->shift_l) & (bitmask - 1);
p->connect = 0; p->connect = 0;
...@@ -227,7 +264,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w, ...@@ -227,7 +264,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
w->kcontrol_news[i].private_value; w->kcontrol_news[i].private_value;
int val, item; int val, item;
val = snd_soc_read(w->codec, e->reg); val = soc_widget_read(w, e->reg);
val = (val >> e->shift_l) & e->mask; val = (val >> e->shift_l) & e->mask;
for (item = 0; item < e->max; item++) { for (item = 0; item < e->max; item++) {
if (val == e->values[item]) if (val == e->values[item])
...@@ -674,7 +711,7 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w, ...@@ -674,7 +711,7 @@ int dapm_reg_event(struct snd_soc_dapm_widget *w,
else else
val = w->off_val; val = w->off_val;
snd_soc_update_bits(w->codec, -(w->reg + 1), soc_widget_update_bits(w, -(w->reg + 1),
w->mask << w->shift, val << w->shift); w->mask << w->shift, val << w->shift);
return 0; return 0;
...@@ -885,7 +922,7 @@ static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm, ...@@ -885,7 +922,7 @@ static void dapm_seq_run_coalesced(struct snd_soc_dapm_context *dapm,
"pop test : Applying 0x%x/0x%x to %x in %dms\n", "pop test : Applying 0x%x/0x%x to %x in %dms\n",
value, mask, reg, card->pop_time); value, mask, reg, card->pop_time);
pop_wait(card->pop_time); pop_wait(card->pop_time);
snd_soc_update_bits(dapm->codec, reg, mask, value); soc_widget_update_bits(w, reg, mask, value);
} }
list_for_each_entry(w, pending, power_list) { list_for_each_entry(w, pending, power_list) {
...@@ -1964,7 +2001,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm) ...@@ -1964,7 +2001,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_dapm_context *dapm)
/* Read the initial power state from the device */ /* Read the initial power state from the device */
if (w->reg >= 0) { if (w->reg >= 0) {
val = snd_soc_read(w->codec, w->reg); val = soc_widget_read(w, w->reg);
val &= 1 << w->shift; val &= 1 << w->shift;
if (w->invert) if (w->invert)
val = !val; val = !val;
......
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