diff mbox

[RFC/RFT] ASoC: rt5677: Convert to use rl6231_pll_calc

Message ID 1402980091.13607.1.camel@phoenix (mailing list archive)
State Accepted
Commit 099d334e3d5c0b26480dffc44fe6272c90898237
Headers show

Commit Message

Axel Lin June 17, 2014, 4:41 a.m. UTC
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>
---
Hi Oder,
This patch removes the usage of k_bp from struct rt5677_pll_code because it is
always false. I think if k_bp is necessay in the further development, maybe
it's better to add it to rl6231_pll_code. How do you think?

Regards,
Axel

 sound/soc/codecs/rt5677.c | 69 ++++++-----------------------------------------
 sound/soc/codecs/rt5677.h |  8 ------
 2 files changed, 8 insertions(+), 69 deletions(-)

Comments

Oder Chiou June 23, 2014, 5:32 a.m. UTC | #1
> -----Original Message-----
> From: Axel Lin [mailto:axel.lin@ingics.com]
> Sent: Tuesday, June 17, 2014 12:42 PM
> To: Mark Brown
> Cc: Oder Chiou; Liam Girdwood; alsa-devel@alsa-project.org
> Subject: [PATCH RFC/RFT] 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>

> ---
> Hi Oder,
> This patch removes the usage of k_bp from struct rt5677_pll_code because it is
> always false. I think if k_bp is necessay in the further development, maybe
> it's better to add it to rl6231_pll_code. How do you think?
> 
It is the better way, thanks.
Mark Brown June 30, 2014, 6:42 p.m. UTC | #2
On Tue, Jun 17, 2014 at 12:41:31PM +0800, Axel Lin wrote:
> 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.

Applied, thanks.
diff mbox

Patch

diff --git a/sound/soc/codecs/rt5677.c b/sound/soc/codecs/rt5677.c
index 45f99a8..e7c401f 100644
--- a/sound/soc/codecs/rt5677.c
+++ b/sound/soc/codecs/rt5677.c
@@ -2988,62 +2988,12 @@  static int rt5677_set_dai_sysclk(struct snd_soc_dai *dai,
  * Returns 0 for success or negative error code.
  */
 static int rt5677_pll_calc(const unsigned int freq_in,
-	const unsigned int freq_out, struct rt5677_pll_code *pll_code)
+	const unsigned int freq_out, struct rl6231_pll_code *pll_code)
 {
-	int max_n = RT5677_PLL_N_MAX, max_m = RT5677_PLL_M_MAX;
-	int k, red, n_t, pll_out, in_t;
-	int n = 0, m = 0, m_t = 0;
-	int out_t, red_t = abs(freq_out - freq_in);
-	bool m_bp = false, k_bp = false;
-
-	if (RT5677_PLL_INP_MAX < freq_in || RT5677_PLL_INP_MIN > freq_in)
+	if (RT5677_PLL_INP_MIN > freq_in)
 		return -EINVAL;
 
-	k = 100000000 / freq_out - 2;
-	if (k > RT5677_PLL_K_MAX)
-		k = RT5677_PLL_K_MAX;
-	for (n_t = 0; n_t <= max_n; n_t++) {
-		in_t = freq_in / (k + 2);
-		pll_out = freq_out / (n_t + 2);
-		if (in_t < 0)
-			continue;
-		if (in_t == pll_out) {
-			m_bp = true;
-			n = n_t;
-			goto code_find;
-		}
-		red = abs(in_t - pll_out);
-		if (red < red_t) {
-			m_bp = true;
-			n = n_t;
-			m = m_t;
-			if (red == 0)
-				goto code_find;
-			red_t = red;
-		}
-		for (m_t = 0; m_t <= max_m; m_t++) {
-			out_t = in_t / (m_t + 2);
-			red = abs(out_t - pll_out);
-			if (red < red_t) {
-				m_bp = false;
-				n = n_t;
-				m = m_t;
-				if (red == 0)
-					goto code_find;
-				red_t = red;
-			}
-		}
-	}
-	pr_debug("Only get approximation about PLL\n");
-
-code_find:
-
-	pll_code->m_bp = m_bp;
-	pll_code->k_bp = k_bp;
-	pll_code->m_code = m;
-	pll_code->n_code = n;
-	pll_code->k_code = k;
-	return 0;
+	return rl6231_pll_calc(freq_in, freq_out, pll_code);
 }
 
 static int rt5677_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
@@ -3051,7 +3001,7 @@  static int rt5677_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
 {
 	struct snd_soc_codec *codec = dai->codec;
 	struct rt5677_priv *rt5677 = snd_soc_codec_get_drvdata(codec);
-	struct rt5677_pll_code pll_code;
+	struct rl6231_pll_code pll_code;
 	int ret;
 
 	if (source == rt5677->pll_src && freq_in == rt5677->pll_in &&
@@ -3109,15 +3059,12 @@  static int rt5677_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
 		return ret;
 	}
 
-	dev_dbg(codec->dev, "m_bypass=%d k_bypass=%d m=%d n=%d k=%d\n",
-		pll_code.m_bp, pll_code.k_bp,
-		(pll_code.m_bp ? 0 : pll_code.m_code), pll_code.n_code,
-		(pll_code.k_bp ? 0 : pll_code.k_code));
+	dev_dbg(codec->dev, "m_bypass=%d m=%d n=%d k=%d\n",
+		pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code),
+		pll_code.n_code, pll_code.k_code);
 
 	regmap_write(rt5677->regmap, RT5677_PLL1_CTRL1,
-		pll_code.n_code << RT5677_PLL_N_SFT |
-		pll_code.k_bp << RT5677_PLL_K_BP_SFT |
-		(pll_code.k_bp ? 0 : pll_code.k_code));
+		pll_code.n_code << RT5677_PLL_N_SFT | pll_code.k_code);
 	regmap_write(rt5677->regmap, RT5677_PLL1_CTRL2,
 		(pll_code.m_bp ? 0 : pll_code.m_code) << RT5677_PLL_M_SFT |
 		pll_code.m_bp << RT5677_PLL_M_BP_SFT);
diff --git a/sound/soc/codecs/rt5677.h b/sound/soc/codecs/rt5677.h
index af4e9c7..08252e7 100644
--- a/sound/soc/codecs/rt5677.h
+++ b/sound/soc/codecs/rt5677.h
@@ -1425,14 +1425,6 @@  enum {
 	RT5677_AIFS,
 };
 
-struct rt5677_pll_code {
-	bool m_bp; /* Indicates bypass m code or not. */
-	bool k_bp; /* Indicates bypass k code or not. */
-	int m_code;
-	int n_code;
-	int k_code;
-};
-
 struct rt5677_priv {
 	struct snd_soc_codec *codec;
 	struct rt5677_platform_data pdata;