Skip to content

Commit

Permalink
ASoC: uda134x: Use regmap_update_bits() were appropriate
Browse files Browse the repository at this point in the history
Instead of doing the read-modify-update cycle by hand when updating a
register use regmap_update_bits().

This also means we can now remove uda134x_read_reg_cache() and
uda134x_write() since they are unused.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Mark Brown <broonie@kernel.org>
  • Loading branch information
Lars-Peter Clausen authored and Mark Brown committed Jul 13, 2015
1 parent f33c340 commit ef3355d
Showing 1 changed file with 14 additions and 43 deletions.
57 changes: 14 additions & 43 deletions sound/soc/codecs/uda134x.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,6 @@ static const struct reg_default uda134x_reg_defaults[] = {
{ UDA134X_DATA1, 0x00 },
};

/*
* The codec has no support for reading its registers except for peak level...
*/
static inline unsigned int uda134x_read_reg_cache(struct snd_soc_codec *codec,
unsigned int reg)
{
struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
unsigned int val;
int ret;

ret = regmap_read(uda134x->regmap, reg, &val);
if (ret)
return -1;

return val;
}

static void uda134x_write(struct snd_soc_codec *codec, unsigned int reg,
unsigned int val)
{
struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);

regmap_write(uda134x->regmap, reg, val);
}

/*
* Write to the uda134x registers
*
Expand Down Expand Up @@ -137,27 +112,28 @@ static int uda134x_regmap_write(void *context, unsigned int reg,

static inline void uda134x_reset(struct snd_soc_codec *codec)
{
u8 reset_reg = uda134x_read_reg_cache(codec, UDA134X_STATUS0);
uda134x_write(codec, UDA134X_STATUS0, reset_reg | (1<<6));
struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
unsigned int mask = 1<<6;

regmap_update_bits(uda134x->regmap, UDA134X_STATUS0, mask, mask);
msleep(1);
uda134x_write(codec, UDA134X_STATUS0, reset_reg & ~(1<<6));
regmap_update_bits(uda134x->regmap, UDA134X_STATUS0, mask, 0);
}

static int uda134x_mute(struct snd_soc_dai *dai, int mute)
{
struct snd_soc_codec *codec = dai->codec;
u8 mute_reg = uda134x_read_reg_cache(codec, UDA134X_DATA010);
struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(dai->codec);
unsigned int mask = 1<<2;
unsigned int val;

pr_debug("%s mute: %d\n", __func__, mute);

if (mute)
mute_reg |= (1<<2);
val = mask;
else
mute_reg &= ~(1<<2);

uda134x_write(codec, UDA134X_DATA010, mute_reg);
val = 0;

return 0;
return regmap_update_bits(uda134x->regmap, UDA134X_DATA010, mask, val);
}

static int uda134x_startup(struct snd_pcm_substream *substream,
Expand Down Expand Up @@ -209,18 +185,14 @@ static int uda134x_hw_params(struct snd_pcm_substream *substream,
{
struct snd_soc_codec *codec = dai->codec;
struct uda134x_priv *uda134x = snd_soc_codec_get_drvdata(codec);
u8 hw_params;
unsigned int hw_params = 0;

if (substream == uda134x->slave_substream) {
pr_debug("%s ignoring hw_params for slave substream\n",
__func__);
return 0;
}

hw_params = uda134x_read_reg_cache(codec, UDA134X_STATUS0);
hw_params &= STATUS0_SYSCLK_MASK;
hw_params &= STATUS0_DAIFMT_MASK;

pr_debug("%s sysclk: %d, rate:%d\n", __func__,
uda134x->sysclk, params_rate(params));

Expand Down Expand Up @@ -271,9 +243,8 @@ static int uda134x_hw_params(struct snd_pcm_substream *substream,
return -EINVAL;
}

uda134x_write(codec, UDA134X_STATUS0, hw_params);

return 0;
return regmap_update_bits(uda134x->regmap, UDA134X_STATUS0,
STATUS0_SYSCLK_MASK | STATUS0_DAIFMT_MASK, hw_params);
}

static int uda134x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
Expand Down

0 comments on commit ef3355d

Please sign in to comment.