Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: Add function "rl6231_get_pre_div" to correct the dmic clock calculation

Signed-off-by: Bard Liao <bardliao@realtek.com>
Signed-off-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Oder Chiou and committed by
Mark Brown
00a6d6e5 213213d9

+68 -13
+47
sound/soc/codecs/rl6231.c
··· 11 11 */ 12 12 13 13 #include <linux/module.h> 14 + #include <linux/regmap.h> 14 15 15 16 #include "rl6231.h" 17 + 18 + /** 19 + * rl6231_get_pre_div - Return the value of pre divider. 20 + * 21 + * @map: map for setting. 22 + * @reg: register. 23 + * @sft: shift. 24 + * 25 + * Return the value of pre divider from given register value. 26 + * Return negative error code for unexpected register value. 27 + */ 28 + int rl6231_get_pre_div(struct regmap *map, unsigned int reg, int sft) 29 + { 30 + int pd, val; 31 + 32 + regmap_read(map, reg, &val); 33 + 34 + val = (val >> sft) & 0x7; 35 + 36 + switch (val) { 37 + case 0: 38 + case 1: 39 + case 2: 40 + case 3: 41 + pd = val + 1; 42 + break; 43 + case 4: 44 + pd = 6; 45 + break; 46 + case 5: 47 + pd = 8; 48 + break; 49 + case 6: 50 + pd = 12; 51 + break; 52 + case 7: 53 + pd = 16; 54 + break; 55 + default: 56 + pd = -EINVAL; 57 + break; 58 + } 59 + 60 + return pd; 61 + } 62 + EXPORT_SYMBOL_GPL(rl6231_get_pre_div); 16 63 17 64 /** 18 65 * rl6231_calc_dmic_clk - Calculate the parameter of dmic.
+1
sound/soc/codecs/rl6231.h
··· 30 30 int rl6231_pll_calc(const unsigned int freq_in, 31 31 const unsigned int freq_out, struct rl6231_pll_code *pll_code); 32 32 int rl6231_get_clk_info(int sclk, int rate); 33 + int rl6231_get_pre_div(struct regmap *map, unsigned int reg, int sft); 33 34 34 35 #endif /* __RL6231_H__ */
+4 -3
sound/soc/codecs/rt5640.c
··· 459 459 { 460 460 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 461 461 struct rt5640_priv *rt5640 = snd_soc_codec_get_drvdata(codec); 462 - int idx = -EINVAL; 462 + int idx, rate; 463 463 464 - idx = rl6231_calc_dmic_clk(rt5640->sysclk); 465 - 464 + rate = rt5640->sysclk / rl6231_get_pre_div(rt5640->regmap, 465 + RT5640_ADDA_CLK1, RT5640_I2S_PD1_SFT); 466 + idx = rl6231_calc_dmic_clk(rate); 466 467 if (idx < 0) 467 468 dev_err(codec->dev, "Failed to set DMIC clock\n"); 468 469 else
+4 -3
sound/soc/codecs/rt5645.c
··· 510 510 { 511 511 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 512 512 struct rt5645_priv *rt5645 = snd_soc_codec_get_drvdata(codec); 513 - int idx = -EINVAL; 513 + int idx, rate; 514 514 515 - idx = rl6231_calc_dmic_clk(rt5645->sysclk); 516 - 515 + rate = rt5645->sysclk / rl6231_get_pre_div(rt5645->regmap, 516 + RT5645_ADDA_CLK1, RT5645_I2S_PD1_SFT); 517 + idx = rl6231_calc_dmic_clk(rate); 517 518 if (idx < 0) 518 519 dev_err(codec->dev, "Failed to set DMIC clock\n"); 519 520 else
+4 -3
sound/soc/codecs/rt5651.c
··· 378 378 { 379 379 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 380 380 struct rt5651_priv *rt5651 = snd_soc_codec_get_drvdata(codec); 381 - int idx = -EINVAL; 381 + int idx, rate; 382 382 383 - idx = rl6231_calc_dmic_clk(rt5651->sysclk); 384 - 383 + rate = rt5651->sysclk / rl6231_get_pre_div(rt5651->regmap, 384 + RT5651_ADDA_CLK1, RT5651_I2S_PD1_SFT); 385 + idx = rl6231_calc_dmic_clk(rate); 385 386 if (idx < 0) 386 387 dev_err(codec->dev, "Failed to set DMIC clock\n"); 387 388 else
+4 -3
sound/soc/codecs/rt5670.c
··· 683 683 { 684 684 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 685 685 struct rt5670_priv *rt5670 = snd_soc_codec_get_drvdata(codec); 686 - int idx = -EINVAL; 686 + int idx, rate; 687 687 688 - idx = rl6231_calc_dmic_clk(rt5670->sysclk); 689 - 688 + rate = rt5670->sysclk / rl6231_get_pre_div(rt5670->regmap, 689 + RT5670_ADDA_CLK1, RT5670_I2S_PD1_SFT); 690 + idx = rl6231_calc_dmic_clk(rate); 690 691 if (idx < 0) 691 692 dev_err(codec->dev, "Failed to set DMIC clock\n"); 692 693 else
+4 -1
sound/soc/codecs/rt5677.c
··· 917 917 { 918 918 struct snd_soc_codec *codec = snd_soc_dapm_to_codec(w->dapm); 919 919 struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); 920 - int idx = rl6231_calc_dmic_clk(rt5677->lrck[RT5677_AIF1] << 8); 920 + int idx, rate; 921 921 922 + rate = rt5677->sysclk / rl6231_get_pre_div(rt5677->regmap, 923 + RT5677_CLK_TREE_CTRL1, RT5677_I2S_PD1_SFT); 924 + idx = rl6231_calc_dmic_clk(rate); 922 925 if (idx < 0) 923 926 dev_err(codec->dev, "Failed to set DMIC clock\n"); 924 927 else