Re: [PATCH] ASoC: tlv320aic3x: Use snd_soc_update_bits for read-modify-write

From: Girdwood, Liam
Date: Thu Oct 27 2011 - 05:18:19 EST


On 26 October 2011 15:13, 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>
> ---
> Âsound/soc/codecs/tlv320aic3x.c | Â 41 +++++++++++++--------------------------
> Â1 files changed, 14 insertions(+), 27 deletions(-)
>
> diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
> index 7a49390..a77f6ea 100644
> --- a/sound/soc/codecs/tlv320aic3x.c
> +++ b/sound/soc/codecs/tlv320aic3x.c
> @@ -833,7 +833,6 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,
> Â Â Â Âint codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
> Â Â Â Âu8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
> Â Â Â Âu16 d, pll_d = 1;
> - Â Â Â u8 reg;
> Â Â Â Âint clk;
>
> Â Â Â Â/* select data word length */
> @@ -869,14 +868,13 @@ static int aic3x_hw_params(struct snd_pcm_substream *substream,
> Â Â Â Â Â Â Â Âsnd_soc_write(codec, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT);
> Â Â Â Â Â Â Â Âsnd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV);
> Â Â Â Â Â Â Â Â/* disable PLL if it is bypassed */
> - Â Â Â Â Â Â Â reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
> - Â Â Â Â Â Â Â snd_soc_write(codec, AIC3X_PLL_PROGA_REG, reg & ~PLL_ENABLE);
> + Â Â Â Â Â Â Â snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG, PLL_ENABLE, 0);
>
> Â Â Â Â} else {
> Â Â Â Â Â Â Â Âsnd_soc_write(codec, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV);
> Â Â Â Â Â Â Â Â/* enable PLL when it is used */
> - Â Â Â Â Â Â Â reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
> - Â Â Â Â Â Â Â snd_soc_write(codec, AIC3X_PLL_PROGA_REG, reg | PLL_ENABLE);
> + Â Â Â Â Â Â Â snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â PLL_ENABLE, PLL_ENABLE);
> Â Â Â Â}
>
> Â Â Â Â/* Route Left DAC to left channel input and
> @@ -1155,7 +1153,6 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
> Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Âenum snd_soc_bias_level level)
> Â{
> Â Â Â Âstruct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
> - Â Â Â u8 reg;
>
> Â Â Â Âswitch (level) {
> Â Â Â Âcase SND_SOC_BIAS_ON:
> @@ -1164,9 +1161,8 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
> Â Â Â Â Â Â Â Âif (codec->dapm.bias_level == SND_SOC_BIAS_STANDBY &&
> Â Â Â Â Â Â Â Â Â Âaic3x->master) {
> Â Â Â Â Â Â Â Â Â Â Â Â/* enable pll */
> - Â Â Â Â Â Â Â Â Â Â Â reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
> - Â Â Â Â Â Â Â Â Â Â Â snd_soc_write(codec, AIC3X_PLL_PROGA_REG,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â reg | PLL_ENABLE);
> + Â Â Â Â Â Â Â Â Â Â Â snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â PLL_ENABLE, PLL_ENABLE);
> Â Â Â Â Â Â Â Â}
> Â Â Â Â Â Â Â Âbreak;
> Â Â Â Âcase SND_SOC_BIAS_STANDBY:
> @@ -1175,9 +1171,8 @@ static int aic3x_set_bias_level(struct snd_soc_codec *codec,
> Â Â Â Â Â Â Â Âif (codec->dapm.bias_level == SND_SOC_BIAS_PREPARE &&
> Â Â Â Â Â Â Â Â Â Âaic3x->master) {
> Â Â Â Â Â Â Â Â Â Â Â Â/* disable pll */
> - Â Â Â Â Â Â Â Â Â Â Â reg = snd_soc_read(codec, AIC3X_PLL_PROGA_REG);
> - Â Â Â Â Â Â Â Â Â Â Â snd_soc_write(codec, AIC3X_PLL_PROGA_REG,
> - Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â reg & ~PLL_ENABLE);
> + Â Â Â Â Â Â Â Â Â Â Â snd_soc_update_bits(codec, AIC3X_PLL_PROGA_REG,
> + Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â PLL_ENABLE, 0);
> Â Â Â Â Â Â Â Â}
> Â Â Â Â Â Â Â Âbreak;
> Â Â Â Âcase SND_SOC_BIAS_OFF:
> @@ -1294,7 +1289,6 @@ static int aic3x_resume(struct snd_soc_codec *codec)
> Âstatic int aic3x_init(struct snd_soc_codec *codec)
> Â{
> Â Â Â Âstruct aic3x_priv *aic3x = snd_soc_codec_get_drvdata(codec);
> - Â Â Â int reg;
>
> Â Â Â Âsnd_soc_write(codec, AIC3X_PAGE_SELECT, PAGE0_SELECT);
> Â Â Â Âsnd_soc_write(codec, AIC3X_RESET, SOFT_RESET);
> @@ -1316,20 +1310,13 @@ static int aic3x_init(struct snd_soc_codec *codec)
> Â Â Â Âsnd_soc_write(codec, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
>
> Â Â Â Â/* unmute all outputs */
> - Â Â Â reg = snd_soc_read(codec, LLOPM_CTRL);
> - Â Â Â snd_soc_write(codec, LLOPM_CTRL, reg | UNMUTE);
> - Â Â Â reg = snd_soc_read(codec, RLOPM_CTRL);
> - Â Â Â snd_soc_write(codec, RLOPM_CTRL, reg | UNMUTE);
> - Â Â Â reg = snd_soc_read(codec, MONOLOPM_CTRL);
> - Â Â Â snd_soc_write(codec, MONOLOPM_CTRL, reg | UNMUTE);
> - Â Â Â reg = snd_soc_read(codec, HPLOUT_CTRL);
> - Â Â Â snd_soc_write(codec, HPLOUT_CTRL, reg | UNMUTE);
> - Â Â Â reg = snd_soc_read(codec, HPROUT_CTRL);
> - Â Â Â snd_soc_write(codec, HPROUT_CTRL, reg | UNMUTE);
> - Â Â Â reg = snd_soc_read(codec, HPLCOM_CTRL);
> - Â Â Â snd_soc_write(codec, HPLCOM_CTRL, reg | UNMUTE);
> - Â Â Â reg = snd_soc_read(codec, HPRCOM_CTRL);
> - Â Â Â snd_soc_write(codec, HPRCOM_CTRL, reg | UNMUTE);
> + Â Â Â snd_soc_update_bits(codec, LLOPM_CTRL, UNMUTE, UNMUTE);
> + Â Â Â snd_soc_update_bits(codec, RLOPM_CTRL, UNMUTE, UNMUTE);
> + Â Â Â snd_soc_update_bits(codec, MONOLOPM_CTRL, UNMUTE, UNMUTE);
> + Â Â Â snd_soc_update_bits(codec, HPLOUT_CTRL, UNMUTE, UNMUTE);
> + Â Â Â snd_soc_update_bits(codec, HPROUT_CTRL, UNMUTE, UNMUTE);
> + Â Â Â snd_soc_update_bits(codec, HPLCOM_CTRL, UNMUTE, UNMUTE);
> + Â Â Â snd_soc_update_bits(codec, HPRCOM_CTRL, UNMUTE, UNMUTE);
>
> Â Â Â Â/* ADC default volume and unmute */
> Â Â Â Âsnd_soc_write(codec, LADC_VOL, DEFAULT_GAIN);
> --
> 1.7.5.4
>
>
>
>

Acked-by: Liam Girdwood <lrg@xxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/