Commit b43fccf4 authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

ASoC: ml26124: Remove duplicate code

Current code has duplicate code for 16000, 32000 and 48000 sample rates.
get_srate() returns negative error code for unsupported rate, so we can
remove the duplicate code in the swith cases by calling get_srate() first.
Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent b787f68c
...@@ -341,6 +341,7 @@ static int ml26124_hw_params(struct snd_pcm_substream *substream, ...@@ -341,6 +341,7 @@ static int ml26124_hw_params(struct snd_pcm_substream *substream,
struct snd_soc_codec *codec = dai->codec; struct snd_soc_codec *codec = dai->codec;
struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec); struct ml26124_priv *priv = snd_soc_codec_get_drvdata(codec);
int i = get_coeff(priv->mclk, params_rate(hw_params)); int i = get_coeff(priv->mclk, params_rate(hw_params));
int srate;
if (i < 0) if (i < 0)
return i; return i;
...@@ -370,53 +371,16 @@ static int ml26124_hw_params(struct snd_pcm_substream *substream, ...@@ -370,53 +371,16 @@ static int ml26124_hw_params(struct snd_pcm_substream *substream,
BIT(0) | BIT(1), 0); BIT(0) | BIT(1), 0);
} }
switch (params_rate(hw_params)) { srate = get_srate(params_rate(hw_params));
case 16000: if (srate < 0)
snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf, return srate;
get_srate(params_rate(hw_params)));
snd_soc_update_bits(codec, ML26124_PLLNL, 0xff, snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf, srate);
coeff_div[i].pllnl); snd_soc_update_bits(codec, ML26124_PLLNL, 0xff, coeff_div[i].pllnl);
snd_soc_update_bits(codec, ML26124_PLLNH, 0x1, snd_soc_update_bits(codec, ML26124_PLLNH, 0x1, coeff_div[i].pllnh);
coeff_div[i].pllnh); snd_soc_update_bits(codec, ML26124_PLLML, 0xff, coeff_div[i].pllml);
snd_soc_update_bits(codec, ML26124_PLLML, 0xff, snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f, coeff_div[i].pllmh);
coeff_div[i].pllml); snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f, coeff_div[i].plldiv);
snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f,
coeff_div[i].pllmh);
snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f,
coeff_div[i].plldiv);
break;
case 32000:
snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf,
get_srate(params_rate(hw_params)));
snd_soc_update_bits(codec, ML26124_PLLNL, 0xff,
coeff_div[i].pllnl);
snd_soc_update_bits(codec, ML26124_PLLNH, 0x1,
coeff_div[i].pllnh);
snd_soc_update_bits(codec, ML26124_PLLML, 0xff,
coeff_div[i].pllml);
snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f,
coeff_div[i].pllmh);
snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f,
coeff_div[i].plldiv);
break;
case 48000:
snd_soc_update_bits(codec, ML26124_SMPLING_RATE, 0xf,
get_srate(params_rate(hw_params)));
snd_soc_update_bits(codec, ML26124_PLLNL, 0xff,
coeff_div[i].pllnl);
snd_soc_update_bits(codec, ML26124_PLLNH, 0x1,
coeff_div[i].pllnh);
snd_soc_update_bits(codec, ML26124_PLLML, 0xff,
coeff_div[i].pllml);
snd_soc_update_bits(codec, ML26124_PLLMH, 0x3f,
coeff_div[i].pllmh);
snd_soc_update_bits(codec, ML26124_PLLDIV, 0x1f,
coeff_div[i].plldiv);
break;
default:
pr_err("%s:this rate is no support for ml26124\n", __func__);
return -EINVAL;
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment