diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-06-17 00:41:31 -0400 |
---|---|---|
committer | Mark Brown <broonie@linaro.org> | 2014-06-30 14:42:47 -0400 |
commit | 099d334e3d5c0b26480dffc44fe6272c90898237 (patch) | |
tree | ac5bc5499c7744ff85bee82481aaefa606b1b87c | |
parent | f58c3b915287af02d192cc8fb64ae8689107ec5f (diff) |
ASoC: rt5677: Convert to use rl6231_pll_calc
The implementation of rt5677_pll_calc() has the same logic of rl6231_pll_calc().
The only difference is the lower boundary checking for freq_in.
This patch calls rl6231_pll_calc() instead of open-coded.
The k_bp of struct rt5677_pll_code is always false, thus also remove the
code to check pll_code.k_bp.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Tested-by: Oder Chiou <oder_chiou@realtek.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
-rw-r--r-- | sound/soc/codecs/rt5677.c | 69 | ||||
-rw-r--r-- | sound/soc/codecs/rt5677.h | 8 |
2 files changed, 8 insertions, 69 deletions
diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c index 8ecfb323b1b2..98370ae3b38d 100644 --- a/sound/soc/codecs/rt5677.c +++ b/sound/soc/codecs/rt5677.c | |||
@@ -2996,62 +2996,12 @@ static int rt5677_set_dai_sysclk(struct snd_soc_dai *dai, | |||
2996 | * Returns 0 for success or negative error code. | 2996 | * Returns 0 for success or negative error code. |
2997 | */ | 2997 | */ |
2998 | static int rt5677_pll_calc(const unsigned int freq_in, | 2998 | static int rt5677_pll_calc(const unsigned int freq_in, |
2999 | const unsigned int freq_out, struct rt5677_pll_code *pll_code) | 2999 | const unsigned int freq_out, struct rl6231_pll_code *pll_code) |
3000 | { | 3000 | { |
3001 | int max_n = RT5677_PLL_N_MAX, max_m = RT5677_PLL_M_MAX; | 3001 | if (RT5677_PLL_INP_MIN > freq_in) |
3002 | int k, red, n_t, pll_out, in_t; | ||
3003 | int n = 0, m = 0, m_t = 0; | ||
3004 | int out_t, red_t = abs(freq_out - freq_in); | ||
3005 | bool m_bp = false, k_bp = false; | ||
3006 | |||
3007 | if (RT5677_PLL_INP_MAX < freq_in || RT5677_PLL_INP_MIN > freq_in) | ||
3008 | return -EINVAL; | 3002 | return -EINVAL; |
3009 | 3003 | ||
3010 | k = 100000000 / freq_out - 2; | 3004 | return rl6231_pll_calc(freq_in, freq_out, pll_code); |
3011 | if (k > RT5677_PLL_K_MAX) | ||
3012 | k = RT5677_PLL_K_MAX; | ||
3013 | for (n_t = 0; n_t <= max_n; n_t++) { | ||
3014 | in_t = freq_in / (k + 2); | ||
3015 | pll_out = freq_out / (n_t + 2); | ||
3016 | if (in_t < 0) | ||
3017 | continue; | ||
3018 | if (in_t == pll_out) { | ||
3019 | m_bp = true; | ||
3020 | n = n_t; | ||
3021 | goto code_find; | ||
3022 | } | ||
3023 | red = abs(in_t - pll_out); | ||
3024 | if (red < red_t) { | ||
3025 | m_bp = true; | ||
3026 | n = n_t; | ||
3027 | m = m_t; | ||
3028 | if (red == 0) | ||
3029 | goto code_find; | ||
3030 | red_t = red; | ||
3031 | } | ||
3032 | for (m_t = 0; m_t <= max_m; m_t++) { | ||
3033 | out_t = in_t / (m_t + 2); | ||
3034 | red = abs(out_t - pll_out); | ||
3035 | if (red < red_t) { | ||
3036 | m_bp = false; | ||
3037 | n = n_t; | ||
3038 | m = m_t; | ||
3039 | if (red == 0) | ||
3040 | goto code_find; | ||
3041 | red_t = red; | ||
3042 | } | ||
3043 | } | ||
3044 | } | ||
3045 | pr_debug("Only get approximation about PLL\n"); | ||
3046 | |||
3047 | code_find: | ||
3048 | |||
3049 | pll_code->m_bp = m_bp; | ||
3050 | pll_code->k_bp = k_bp; | ||
3051 | pll_code->m_code = m; | ||
3052 | pll_code->n_code = n; | ||
3053 | pll_code->k_code = k; | ||
3054 | return 0; | ||
3055 | } | 3005 | } |
3056 | 3006 | ||
3057 | static int rt5677_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, | 3007 | static int rt5677_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, |
@@ -3059,7 +3009,7 @@ static int rt5677_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, | |||
3059 | { | 3009 | { |
3060 | struct snd_soc_codec *codec = dai->codec; | 3010 | struct snd_soc_codec *codec = dai->codec; |
3061 | struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); | 3011 | struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec); |
3062 | struct rt5677_pll_code pll_code; | 3012 | struct rl6231_pll_code pll_code; |
3063 | int ret; | 3013 | int ret; |
3064 | 3014 | ||
3065 | if (source == rt5677->pll_src && freq_in == rt5677->pll_in && | 3015 | if (source == rt5677->pll_src && freq_in == rt5677->pll_in && |
@@ -3117,15 +3067,12 @@ static int rt5677_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, | |||
3117 | return ret; | 3067 | return ret; |
3118 | } | 3068 | } |
3119 | 3069 | ||
3120 | dev_dbg(codec->dev, "m_bypass=%d k_bypass=%d m=%d n=%d k=%d\n", | 3070 | dev_dbg(codec->dev, "m_bypass=%d m=%d n=%d k=%d\n", |
3121 | pll_code.m_bp, pll_code.k_bp, | 3071 | pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code), |
3122 | (pll_code.m_bp ? 0 : pll_code.m_code), pll_code.n_code, | 3072 | pll_code.n_code, pll_code.k_code); |
3123 | (pll_code.k_bp ? 0 : pll_code.k_code)); | ||
3124 | 3073 | ||
3125 | regmap_write(rt5677->regmap, RT5677_PLL1_CTRL1, | 3074 | regmap_write(rt5677->regmap, RT5677_PLL1_CTRL1, |
3126 | pll_code.n_code << RT5677_PLL_N_SFT | | 3075 | pll_code.n_code << RT5677_PLL_N_SFT | pll_code.k_code); |
3127 | pll_code.k_bp << RT5677_PLL_K_BP_SFT | | ||
3128 | (pll_code.k_bp ? 0 : pll_code.k_code)); | ||
3129 | regmap_write(rt5677->regmap, RT5677_PLL1_CTRL2, | 3076 | regmap_write(rt5677->regmap, RT5677_PLL1_CTRL2, |
3130 | (pll_code.m_bp ? 0 : pll_code.m_code) << RT5677_PLL_M_SFT | | 3077 | (pll_code.m_bp ? 0 : pll_code.m_code) << RT5677_PLL_M_SFT | |
3131 | pll_code.m_bp << RT5677_PLL_M_BP_SFT); | 3078 | pll_code.m_bp << RT5677_PLL_M_BP_SFT); |
diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h index af4e9c797408..08252e7c1ab4 100644 --- a/sound/soc/codecs/rt5677.h +++ b/sound/soc/codecs/rt5677.h | |||
@@ -1425,14 +1425,6 @@ enum { | |||
1425 | RT5677_AIFS, | 1425 | RT5677_AIFS, |
1426 | }; | 1426 | }; |
1427 | 1427 | ||
1428 | struct rt5677_pll_code { | ||
1429 | bool m_bp; /* Indicates bypass m code or not. */ | ||
1430 | bool k_bp; /* Indicates bypass k code or not. */ | ||
1431 | int m_code; | ||
1432 | int n_code; | ||
1433 | int k_code; | ||
1434 | }; | ||
1435 | |||
1436 | struct rt5677_priv { | 1428 | struct rt5677_priv { |
1437 | struct snd_soc_codec *codec; | 1429 | struct snd_soc_codec *codec; |
1438 | struct rt5677_platform_data pdata; | 1430 | struct rt5677_platform_data pdata; |