ASoC: dapm: Fix return value of snd_soc_dapm_put_{volsw, enum_virt}()
Subsystems (3)
PATCH 1/5 ASoC: dapm: Fix return value of snd_soc_dapm_put_{volsw, enum_virt}()
The ALSA core expect the put callback of a control to return 1 if the value of the control changed and 0 if it did not. Both snd_soc_dapm_put_volsw() and snd_soc_dapm_put_enum_virt() currently always returns 0. For both functions we already have a 'change' variable which either contains 1 or 0 depending on whether the value has changed or not, so just return that.
--- sound/soc/soc-dapm.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
sound/soc/soc-dapm.c +2 -3
@@ -2703,7 +2703,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol, }mutex_unlock (&card->dapm_mutex); -return 0 ; +return change; }EXPORT_SYMBOL_GPL (snd_soc_dapm_put_volsw);
@@ -2831,7 +2831,6 @@ int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;int change; -int ret =0 ;int wi;if (ucontrol->value.enumerated.item[0 ] >= e->max)
@@ -2851,7 +2850,7 @@ int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol, }mutex_unlock (&card->dapm_mutex); -return ret; +return change; }EXPORT_SYMBOL_GPL (snd_soc_dapm_put_enum_virt);
Signature · 1 line
1.8.0
PATCH 2/5 ASoC: dapm: Pass snd_soc_card directly to soc_dpcm_runtime_update()
soc_dpcm_runtime_update() operates on a ASoC card as a whole. Currently it takes a snd_soc_dapm_widget as its only parameter though. The widget is then used to look up the card and is otherwise unused. This patch changes the function to take a pointer to the card directly. This makes it possible to to call soc_dpcm_runtime_update() for updates which are not related to one specific widget.
--- include/sound/soc-dpcm.h | 2 +- sound/soc/soc-dapm.c | 4 ++-- sound/soc/soc-pcm.c | 10 +--------- 3 files changed, 4 insertions(+), 12 deletions(-)
include/sound/soc-dpcm.h +1 -1
@@ -133,6 +133,6 @@ void snd_soc_dpcm_be_set_state(struct snd_soc_pcm_runtime *be, int stream,/* internal use only */ int soc_dpcm_be_digital_mute (struct snd_soc_pcm_runtime *fe,int mute);int soc_dpcm_debugfs_add (struct snd_soc_pcm_runtime *rtd); -int soc_dpcm_runtime_update (struct snd_soc_dapm_widget *); +int soc_dpcm_runtime_update (struct snd_soc_card *);#endif
sound/soc/soc-dapm.c +2 -2
@@ -1956,7 +1956,7 @@ int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget, ret =soc_dapm_mux_update_power (widget, kcontrol, mux, e);mutex_unlock (&card->dapm_mutex);if (ret >0 ) -soc_dpcm_runtime_update (widget); +soc_dpcm_runtime_update (card);return ret; }EXPORT_SYMBOL_GPL (snd_soc_dapm_mux_update_power);
@@ -2002,7 +2002,7 @@ int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget, ret =soc_dapm_mixer_update_power (widget, kcontrol, connect);mutex_unlock (&card->dapm_mutex);if (ret >0 ) -soc_dpcm_runtime_update (widget); +soc_dpcm_runtime_update (card);return ret; }EXPORT_SYMBOL_GPL (snd_soc_dapm_mixer_update_power);
sound/soc/soc-pcm.c +1 -9
@@ -1833,18 +1833,10 @@ static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream)/* Called by DAPM mixer/mux changes to update audio routing between PCMs and * any DAI links. */ -int soc_dpcm_runtime_update (struct snd_soc_dapm_widget *widget) +int soc_dpcm_runtime_update (struct snd_soc_card *card) { -struct snd_soc_card *card;int i, old, new, paths; -if (widget->codec) - card = widget->codec->card; -else if (widget->platform) - card = widget->platform->card; -else -return -EINVAL ; -mutex_lock_nested (&card->mutex,SND_SOC_CARD_CLASS_RUNTIME );for (i =0 ; i < card->num_rtd; i++) {struct snd_soc_dapm_widget_list *list;
Signature · 1 line
1.8.0
PATCH 3/5 ASoC: dapm: Run widget updates for shared controls at the same time
In reply to Lars-Peter ClausenCurrently when updating a control that is shared between multiple widgets the whole power-up/power-down sequence is being run once for each widget. The control register is updated during the first run, which means the CODEC internal routing is also updated for all widgets during this first run. The input and output paths for each widgets are only updated though during the respective run for that widget. This leads to a slight inconsistency between the CODEC's internal state and ASoC's state, which causes non optimal behavior in regard to click and pop avoidance.
E.g. consider the following setup where two MUXs share the same control.
+------+
A1 ------| |
| MUX1 |----- C1
B1 ------| |
+------+
|
control ---+
|
+------+
A2 ------| |
| MUX2 |----- C2
B2 ------| |
+------+If the control is updated to switch the MUXs from input A to input B with the current code the power-up/power-down sequence will look like this:
Run soc_dapm_mux_update_power for MUX1
Power-down A1
Update MUXing
Power-up B1
Run soc_dapm_mux_update_power for MUX2
Power-down A2
(Update MUXing)
Power-up B2
Note that the second 'Update Muxing' is a no-op, since the register was already updated.
While the preferred order for avoiding pops and clicks should be:
Run soc_dapm_mux_update_power for control
Power-down A1
Power-down A2
Update MUXing
Power-up B1
Power-up B2
This patch changes the behavior to the later by running the updates for all widgets that the control is attached to at the same time.
The new code is also a bit simpler since callers of soc_dapm_{mux,muxer}_update_power don't have to loop over each widget anymore and neither do we need to keep track for which of the kcontrol's widgets the current update is.
--- include/sound/soc-dapm.h | 7 +- sound/soc/soc-dapm.c | 162 ++++++++++++++++++++--------------------------- 2 files changed, 71 insertions(+), 98 deletions(-)
include/sound/soc-dapm.h +3 -4
@@ -391,10 +391,10 @@ void snd_soc_dapm_stream_event(struct snd_soc_pcm_runtime *rtd, int stream,void snd_soc_dapm_shutdown (struct snd_soc_card *card);/* external DAPM widget events */ -int snd_soc_dapm_mixer_update_power (struct snd_soc_dapm_widget *widget, +int snd_soc_dapm_mixer_update_power (struct snd_soc_dapm_context *dapm,struct snd_kcontrol *kcontrol,int connect); -int snd_soc_dapm_mux_update_power (struct snd_soc_dapm_widget *widget, -struct snd_kcontrol *kcontrol,int mux,struct soc_enum *e); +int snd_soc_dapm_mux_update_power (struct snd_soc_dapm_context *dapm, +struct snd_kcontrol *kcontrol,int mux,struct soc_enum *e);/* dapm sys fs - used by the core */ int snd_soc_dapm_sys_add (struct device *dev);
@@ -559,7 +559,6 @@ struct snd_soc_dapm_widget { };struct snd_soc_dapm_update { -struct snd_soc_dapm_widget *widget;struct snd_kcontrol *kcontrol;int reg;int mask;
sound/soc/soc-dapm.c +68 -94
295 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH 4/5 ASoC: dapm: Add a update parameter to snd_soc_dapm_{mux, mixer}_update_power
In reply to Lars-Peter ClausenIn order to avoid race conditions the assignment of dapm->update should happen while card->dapm_mutex is being held. To allow CODEC drivers to run a register update when using snd_soc_dapm_mux_update_power() or snd_soc_dapm_mixer_update_power() add a update parameter to these two functions. The update parameter will be assigned to dapm->update while card->dapm_mutex is locked.
--- include/sound/soc-dapm.h | 7 +++++-- sound/soc/soc-dapm.c | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-)
include/sound/soc-dapm.h +5 -2
@@ -333,6 +333,7 @@ struct snd_soc_dapm_route;struct snd_soc_dapm_context ;struct regulator ;struct snd_soc_dapm_widget_list ; +struct snd_soc_dapm_update ;int dapm_reg_event (struct snd_soc_dapm_widget *w,struct snd_kcontrol *kcontrol,int event);
@@ -392,9 +393,11 @@ void snd_soc_dapm_shutdown(struct snd_soc_card *card);/* external DAPM widget events */ int snd_soc_dapm_mixer_update_power (struct snd_soc_dapm_context *dapm, -struct snd_kcontrol *kcontrol,int connect); +struct snd_kcontrol *kcontrol,int connect, +struct snd_soc_dapm_update *update);int snd_soc_dapm_mux_update_power (struct snd_soc_dapm_context *dapm, -struct snd_kcontrol *kcontrol,int mux,struct soc_enum *e); +struct snd_kcontrol *kcontrol,int mux,struct soc_enum *e, +struct snd_soc_dapm_update *update);/* dapm sys fs - used by the core */ int snd_soc_dapm_sys_add (struct device *dev);
sound/soc/soc-dapm.c +8 -2
@@ -1952,13 +1952,16 @@ static int soc_dapm_mux_update_power(struct snd_soc_dapm_context *dapm, }int snd_soc_dapm_mux_update_power (struct snd_soc_dapm_context *dapm, -struct snd_kcontrol *kcontrol,int mux,struct soc_enum *e) +struct snd_kcontrol *kcontrol,int mux,struct soc_enum *e, +struct snd_soc_dapm_update *update) {struct snd_soc_card *card = dapm->card;int ret;mutex_lock_nested (&card->dapm_mutex,SND_SOC_DAPM_CLASS_RUNTIME ); + dapm->update = update; ret =soc_dapm_mux_update_power (dapm, kcontrol, mux, e); + dapm->update =NULL ;mutex_unlock (&card->dapm_mutex);if (ret >0 )soc_dpcm_runtime_update (card);
@@ -1992,13 +1995,16 @@ static int soc_dapm_mixer_update_power(struct snd_soc_dapm_context *dapm, }int snd_soc_dapm_mixer_update_power (struct snd_soc_dapm_context *dapm, -struct snd_kcontrol *kcontrol,int connect) +struct snd_kcontrol *kcontrol,int connect, +struct snd_soc_dapm_update *update) {struct snd_soc_card *card = dapm->card;int ret;mutex_lock_nested (&card->dapm_mutex,SND_SOC_DAPM_CLASS_RUNTIME ); + dapm->update = update; ret =soc_dapm_mixer_update_power (dapm, kcontrol, connect); + dapm->update =NULL ;mutex_unlock (&card->dapm_mutex);if (ret >0 )soc_dpcm_runtime_update (card);
Signature · 1 line
1.8.0
PATCH 5/5 ASoC: tlv320aic3x: Use snd_soc_dapm_mixer_update_power
In reply to Lars-Peter ClausenUse snd_soc_dapm_mixer_update_power() instead of reimplementing its functionality.
--- sound/soc/codecs/tlv320aic3x.c | 49 ++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 33 deletions(-)
sound/soc/codecs/tlv320aic3x.c +16 -33
@@ -147,10 +147,9 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,int max = mc->max;unsigned int mask = (1 <<fls (max)) -1 ;unsigned int invert = mc->invert; -unsigned short val, val_mask; -int ret; -struct snd_soc_dapm_path *path; -int found =0 ; +unsigned short val; +struct snd_soc_dapm_update update; +int connect, change; val = (ucontrol->value.integer.value[0 ] & mask);
@@ -158,42 +157,26 @@ static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,if (val) val = mask; + connect = !!val; +if (invert) val = mask - val; - val_mask = mask << shift; - val = val << shift; - -mutex_lock (&widget->codec->mutex); -if (snd_soc_test_bits (widget->codec, reg, val_mask, val)) { -/* find dapm widget path assoc with kcontrol */ -list_for_each_entry (path, &widget->dapm->card->paths, list) { -if (path->kcontrol != kcontrol) -continue ; + mask <<= shift; + val <<= shift; -/* found, now check type */ - found =1 ; -if (val) -/* new connection */ - path->connect = invert ?0 :1 ; -else -/* old connection must be powered down */ - path->connect = invert ?1 :0 ; + change =snd_soc_test_bits (widget->codec, val, mask, reg); +if (change) { + update.kcontrol = kcontrol; + update.reg = reg; + update.mask = mask; + update.val = val; -dapm_mark_dirty (path->source,"tlv320aic3x source" ); -dapm_mark_dirty (path->sink,"tlv320aic3x sink" ); - -break ; - } +snd_soc_dapm_mixer_update_power (widget->dapm, kcontrol, connect, + &update); } -mutex_unlock (&widget->codec->mutex); - -if (found) -snd_soc_dapm_sync (widget->dapm); - - ret =snd_soc_update_bits_locked (widget->codec, reg, val_mask, val); -return ret; +return change; }/*
Signature · 1 line
1.8.0
Quoted 5 lines · Lars-Peter Clausen
The ALSA core expect the put callback of a control to return 1 if the value of the control changed and 0 if it did not. Both
snd_soc_dapm_put_volsw()andsnd_soc_dapm_put_enum_virt()currently always returns 0. For both functions we already have a 'change' variable which either contains 1 or 0 depending on whether the value has changed or not, so just return that.
Applied, thanks.