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

ASoC: rl6231: add pll preset table

Currently, rl6231_pll_calc provide a working PLL parameters for
given freq_in and freq_out. However, in some cases it is not the
perfect parameter. For example if freq_in = 19200000 and freq_out
= 24576000, the calculated parameter will gengrate 24.5647 MHz
which is not exactly the same as what we need. But the PLL can
output 24.576 MHz as exactly what we expect if we set the best
PLL parameter.
To improve it, we put the best match parameters in a preset table.
We can search the preset table first, if there is no preset parameter
for the given freq_in and freq_out, we can still calculate a working
PLL parameter.

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

authored by

Bard Liao and committed by
Mark Brown
213213d9 bc0195aa

+26 -1
+26 -1
sound/soc/codecs/rl6231.c
··· 43 43 } 44 44 EXPORT_SYMBOL_GPL(rl6231_calc_dmic_clk); 45 45 46 + struct pll_calc_map { 47 + unsigned int pll_in; 48 + unsigned int pll_out; 49 + int k; 50 + int n; 51 + int m; 52 + bool m_bp; 53 + }; 54 + 55 + static const struct pll_calc_map pll_preset_table[] = { 56 + {19200000, 24576000, 3, 30, 3, false}, 57 + }; 58 + 46 59 /** 47 60 * rl6231_pll_calc - Calcualte PLL M/N/K code. 48 61 * @freq_in: external clock provided to codec. ··· 70 57 const unsigned int freq_out, struct rl6231_pll_code *pll_code) 71 58 { 72 59 int max_n = RL6231_PLL_N_MAX, max_m = RL6231_PLL_M_MAX; 73 - int k, red, n_t, pll_out, in_t, out_t; 60 + int i, k, red, n_t, pll_out, in_t, out_t; 74 61 int n = 0, m = 0, m_t = 0; 75 62 int red_t = abs(freq_out - freq_in); 76 63 bool bypass = false; 77 64 78 65 if (RL6231_PLL_INP_MAX < freq_in || RL6231_PLL_INP_MIN > freq_in) 79 66 return -EINVAL; 67 + 68 + for (i = 0; i < ARRAY_SIZE(pll_preset_table); i++) { 69 + if (freq_in == pll_preset_table[i].pll_in && 70 + freq_out == pll_preset_table[i].pll_out) { 71 + k = pll_preset_table[i].k; 72 + m = pll_preset_table[i].m; 73 + n = pll_preset_table[i].n; 74 + bypass = pll_preset_table[i].m_bp; 75 + pr_debug("Use preset PLL parameter table\n"); 76 + goto code_find; 77 + } 78 + } 80 79 81 80 k = 100000000 / freq_out - 2; 82 81 if (k > RL6231_PLL_K_MAX)