Re: [PATCH v2 RESEND] ASoC: wm9081: Use snd_soc_update_bits for read-modify-write

From: Girdwood, Liam
Date: Wed Oct 19 2011 - 04:10:19 EST


On 19 October 2011 04:06, Axel Lin <axel.lin@xxxxxxxxx> wrote:
> Use snd_soc_update_bits for read-modify-write register access instead of
> open-coding it using snd_soc_read and snd_soc_write
>
> Signed-off-by: Axel Lin <axel.lin@xxxxxxxxx>
> ---
> RESEND:
> I just found I doesn't set my mail client properly to show correct sender,
> so here is a resend.
>
> v2:
> For Initial cold start ( change bias level from SND_SOC_BIAS_OFF to
> SND_SOC_BIAS_STANDBY ), the v1 does not set VMID_SEL[1:0] bits
> correctly for Normal bias enable & soft start off.
> In v2 we also clear VMID_SEL[1:0] bits for Normal bias enable & soft start off.
> We did clear VMID_SEL[1:0] bits in SND_SOC_BIAS_OFF,
> thus we know the VMID_SEL[1:0] bits status is 0b00 in this case.
>

The mechanics look OK, but best for Mark to check with the hardware.

Acked-by: Liam Girdwood <lrg@xxxxxx>

> Âsound/soc/codecs/wm9081.c | Â 82 +++++++++++++++++++-------------------------
> Â1 files changed, 35 insertions(+), 47 deletions(-)
>
> diff --git a/sound/soc/codecs/wm9081.c b/sound/soc/codecs/wm9081.c
> index 66092ef..9c38ddb 100644
> --- a/sound/soc/codecs/wm9081.c
> +++ b/sound/soc/codecs/wm9081.c
> @@ -766,84 +766,73 @@ static const struct snd_soc_dapm_route wm9081_audio_paths[] = {
> Âstatic int wm9081_set_bias_level(struct snd_soc_codec *codec,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â enum snd_soc_bias_level level)
> Â{
> - Â Â Â u16 reg;
> -
> Â Â Â Âswitch (level) {
> Â Â Â Âcase SND_SOC_BIAS_ON:
> Â Â Â Â Â Â Â Âbreak;
>
> Â Â Â Âcase SND_SOC_BIAS_PREPARE:
> Â Â Â Â Â Â Â Â/* VMID=2*40k */
> - Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_VMID_CONTROL);
> - Â Â Â Â Â Â Â reg &= ~WM9081_VMID_SEL_MASK;
> - Â Â Â Â Â Â Â reg |= 0x2;
> - Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_VMID_CONTROL, reg);
> + Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_VMID_CONTROL,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_VMID_SEL_MASK, 0x2);
>
> Â Â Â Â Â Â Â Â/* Normal bias current */
> - Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1);
> - Â Â Â Â Â Â Â reg &= ~WM9081_STBY_BIAS_ENA;
> - Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_BIAS_CONTROL_1, reg);
> + Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_BIAS_CONTROL_1,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_STBY_BIAS_ENA, 0);
> Â Â Â Â Â Â Â Âbreak;
>
> Â Â Â Âcase SND_SOC_BIAS_STANDBY:
> Â Â Â Â Â Â Â Â/* Initial cold start */
> Â Â Â Â Â Â Â Âif (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
> Â Â Â Â Â Â Â Â Â Â Â Â/* Disable LINEOUT discharge */
> - Â Â Â Â Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_ANTI_POP_CONTROL);
> - Â Â Â Â Â Â Â Â Â Â Â reg &= ~WM9081_LINEOUT_DISCH;
> - Â Â Â Â Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_ANTI_POP_CONTROL, reg);
> + Â Â Â Â Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_ANTI_POP_CONTROL,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_LINEOUT_DISCH, 0);
>
> Â Â Â Â Â Â Â Â Â Â Â Â/* Select startup bias source */
> - Â Â Â Â Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1);
> - Â Â Â Â Â Â Â Â Â Â Â reg |= WM9081_BIAS_SRC | WM9081_BIAS_ENA;
> - Â Â Â Â Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_BIAS_CONTROL_1, reg);
> + Â Â Â Â Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_BIAS_CONTROL_1,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_BIAS_SRC | WM9081_BIAS_ENA,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_BIAS_SRC | WM9081_BIAS_ENA);
>
> Â Â Â Â Â Â Â Â Â Â Â Â/* VMID 2*4k; Soft VMID ramp enable */
> - Â Â Â Â Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_VMID_CONTROL);
> - Â Â Â Â Â Â Â Â Â Â Â reg |= WM9081_VMID_RAMP | 0x6;
> - Â Â Â Â Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_VMID_CONTROL, reg);
> -
> + Â Â Â Â Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_VMID_CONTROL,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_VMID_RAMP | 0x6,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_VMID_RAMP | 0x6);
> Â Â Â Â Â Â Â Â Â Â Â Âmdelay(100);
>
> Â Â Â Â Â Â Â Â Â Â Â Â/* Normal bias enable & soft start off */
> - Â Â Â Â Â Â Â Â Â Â Â reg |= WM9081_BIAS_ENA;
> - Â Â Â Â Â Â Â Â Â Â Â reg &= ~WM9081_VMID_RAMP;
> - Â Â Â Â Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_VMID_CONTROL, reg);
> + Â Â Â Â Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_VMID_CONTROL,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_VMID_RAMP | WM9081_BIAS_ENA |
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_VMID_SEL_MASK,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_BIAS_ENA);
>
> Â Â Â Â Â Â Â Â Â Â Â Â/* Standard bias source */
> - Â Â Â Â Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1);
> - Â Â Â Â Â Â Â Â Â Â Â reg &= ~WM9081_BIAS_SRC;
> - Â Â Â Â Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_BIAS_CONTROL_1, reg);
> + Â Â Â Â Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_BIAS_CONTROL_1,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_BIAS_SRC, 0);
> Â Â Â Â Â Â Â Â}
>
> Â Â Â Â Â Â Â Â/* VMID 2*240k */
> - Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1);
> - Â Â Â Â Â Â Â reg &= ~WM9081_VMID_SEL_MASK;
> - Â Â Â Â Â Â Â reg |= 0x04;
> - Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_VMID_CONTROL, reg);
> + Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_BIAS_CONTROL_1,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_VMID_SEL_MASK, 0x04);
>
> Â Â Â Â Â Â Â Â/* Standby bias current on */
> - Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1);
> - Â Â Â Â Â Â Â reg |= WM9081_STBY_BIAS_ENA;
> - Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_BIAS_CONTROL_1, reg);
> + Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_BIAS_CONTROL_1,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_STBY_BIAS_ENA,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_STBY_BIAS_ENA);
> Â Â Â Â Â Â Â Âbreak;
>
> Â Â Â Âcase SND_SOC_BIAS_OFF:
> Â Â Â Â Â Â Â Â/* Startup bias source */
> - Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_BIAS_CONTROL_1);
> - Â Â Â Â Â Â Â reg |= WM9081_BIAS_SRC;
> - Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_BIAS_CONTROL_1, reg);
> + Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_BIAS_CONTROL_1,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_BIAS_SRC, WM9081_BIAS_SRC);
>
> Â Â Â Â Â Â Â Â/* Disable VMID and biases with soft ramping */
> - Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_VMID_CONTROL);
> - Â Â Â Â Â Â Â reg &= ~(WM9081_VMID_SEL_MASK | WM9081_BIAS_ENA);
> - Â Â Â Â Â Â Â reg |= WM9081_VMID_RAMP;
> - Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_VMID_CONTROL, reg);
> + Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_VMID_CONTROL,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_VMID_RAMP | WM9081_VMID_SEL_MASK |
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_BIAS_ENA, WM9081_VMID_RAMP);
>
> Â Â Â Â Â Â Â Â/* Actively discharge LINEOUT */
> - Â Â Â Â Â Â Â reg = snd_soc_read(codec, WM9081_ANTI_POP_CONTROL);
> - Â Â Â Â Â Â Â reg |= WM9081_LINEOUT_DISCH;
> - Â Â Â Â Â Â Â snd_soc_write(codec, WM9081_ANTI_POP_CONTROL, reg);
> + Â Â Â Â Â Â Â snd_soc_update_bits(codec, WM9081_ANTI_POP_CONTROL,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_LINEOUT_DISCH,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_LINEOUT_DISCH);
> Â Â Â Â Â Â Â Âbreak;
> Â Â Â Â}
>
> @@ -1242,11 +1231,10 @@ static int wm9081_probe(struct snd_soc_codec *codec)
> Â Â Â Âwm9081_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
>
> Â Â Â Â/* Enable zero cross by default */
> - Â Â Â reg = snd_soc_read(codec, WM9081_ANALOGUE_LINEOUT);
> - Â Â Â snd_soc_write(codec, WM9081_ANALOGUE_LINEOUT, reg | WM9081_LINEOUTZC);
> - Â Â Â reg = snd_soc_read(codec, WM9081_ANALOGUE_SPEAKER_PGA);
> - Â Â Â snd_soc_write(codec, WM9081_ANALOGUE_SPEAKER_PGA,
> - Â Â Â Â Â Â Â Â Â Âreg | WM9081_SPKPGAZC);
> + Â Â Â snd_soc_update_bits(codec, WM9081_ANALOGUE_LINEOUT,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_LINEOUTZC, WM9081_LINEOUTZC);
> + Â Â Â snd_soc_update_bits(codec, WM9081_ANALOGUE_SPEAKER_PGA,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â WM9081_SPKPGAZC, WM9081_SPKPGAZC);
>
> Â Â Â Âsnd_soc_add_controls(codec, wm9081_snd_controls,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â ARRAY_SIZE(wm9081_snd_controls));
> --
> 1.7.5.4
>
>
>
>
èº{.nÇ+‰·Ÿ®‰­†+%ŠËlzwm…ébëæìr¸›zX§»®w¥Š{ayºÊÚë,j­¢f£¢·hš‹àz¹®w¥¢¸ ¢·¦j:+v‰¨ŠwèjØm¶Ÿÿ¾«‘êçzZ+ƒùšŽŠÝj"ú!¶iO•æ¬z·švØ^¶m§ÿðà nÆàþY&—