ASoC: wm9081: Use snd_soc_update_bits for read-modify-write
Subsystems (3)
PATCH v3 1/1 ASoC: wm9081: Use snd_soc_update_bits for read-modify-write
Use snd_soc_update_bits for read-modify-write register access instead of open-coding it using snd_soc_read and snd_soc_write
--- sound/soc/codecs/wm9081.c | 82 ++++++++++++++++++++------------------------- 1 files changed, 36 insertions(+), 46 deletions(-)
sound/soc/codecs/wm9081.c +36 -46
@@ -826,84 +826,75 @@ 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 | +WM9081_VMID_SEL_MASK , +WM9081_VMID_RAMP |0x6 );mdelay (100 );/* Normal bias enable & soft start off */ - 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 ,0 );/* 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_VMID_CONTROL ); - reg &= ~WM9081_VMID_SEL_MASK ; - reg |=0x04 ; -snd_soc_write (codec,WM9081_VMID_CONTROL , reg); +snd_soc_update_bits (codec,WM9081_VMID_CONTROL , +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 and disable bias */ - reg =snd_soc_read (codec,WM9081_BIAS_CONTROL_1 ); - reg |=WM9081_BIAS_SRC ; - reg &= ~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 );/* Disable VMID with soft ramping */ - reg =snd_soc_read (codec,WM9081_VMID_CONTROL ); - reg &= ~WM9081_VMID_SEL_MASK ; - 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_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 ; }
@@ -1291,11 +1282,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 );if (!wm9081->pdata.num_retune_configs) { dev_dbg(codec->dev,
Signature · 1 line
1.7.5.4
Quoted 9 lines
/* 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|
+WM9081_VMID_SEL_MASK,
+WM9081_VMID_RAMP|0x6);
Quoted 9 lines
mdelay(100);
/* Normal bias enable & soft start off */
- 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, 0);
It's probably not trival why we need to clear WM9081_VMID_SEL_MASK bits here by looking at the patch. Looking at original code, you will know current code indeed clear WM9081_VMID_SEL_MASK bit here.
What current code does:
1. read WM9081_VMID_CONTROL register
2. write to WM9081_VMID_CONTROL register with setting WM9081_VMID_RAMP bit and setting WM9081_VMID_SEL_MASK bits to 0x6 (VMID
2*4k; Soft VMID
ramp enable)
3. mdelay(100)
4. write to WM9081_VMID_CONTROL register with clearingWM9081_VMID_RAMP bit.
Note: In this write, we do also clear WM9081_VMID_SEL_MASK
bits because the register
value of WM9081_VMID_SEL_MASK bits are clear when we read
in "step1".
In this case, the WM9081_VMID_SEL_MASK bits are clear because we clear WM9081_VMID_SEL_MASK bits in SND_SOC_BIAS_OFF. ( The default value is also zero for WM9081_VMID_SEL_MASK bits. )
While converting to snd_soc_update_bits here we actually do one more read. For the second call of snd_soc_update_bits, we need to explictly clear WM9081_VMID_SEL_MASK bits.
Regards,
Axel
2011/11/9 Axel Lin <[email protected]>:
Quoted 9 lines
Quoted 9 lines
/* 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|
+WM9081_VMID_SEL_MASK,
+WM9081_VMID_RAMP|0x6);
Quoted 4 lines
Quoted 4 lines
mdelay(100);
/* Normal bias enable & soft start off */
- reg &= ~WM9081_VMID_RAMP;
oh.. wait. so original code does not clear WM9081_VMID_SEL_MASK bits here. My bad. Don't know why I always think WM9081_VMID_SEL_MASK bits are cleared here.
Will send a new version soon.
Quoted 5 lines
Quoted 5 lines
-
snd_soc_write(codec, WM9081_VMID_CONTROL, reg);
+ snd_soc_update_bits(codec,WM9081_VMID_CONTROL,
+WM9081_VMID_RAMP|
+WM9081_VMID_SEL_MASK, 0);