aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOwen Chen <owen.chen@mediatek.com>2019-03-05 00:05:40 -0500
committerStephen Boyd <sboyd@kernel.org>2019-04-11 16:13:08 -0400
commit9d7e1a82b7d195f901c2a18dd5602a1c11e9eefb (patch)
treec64502c6a88052a8b1857af5516b68af1d461f8d
parenta3ae549917f1634f85c62984617521801505eb1e (diff)
clk: mediatek: Add configurable pcwibits and fmin to mtk_pll_data
1. pcwibits: The integer bits of pcw for PLLs is extend to 8 bits, add a variable to indicate this change and backward-compatible. 2. fmin: The PLL frequency lower-bound is vary from 1GHz to 1.5GHz, add a variable to indicate platform-dependent. Signed-off-by: Owen Chen <owen.chen@mediatek.com> Signed-off-by: Weiyi Lu <weiyi.lu@mediatek.com> Acked-by: Sean Wang <sean.wang@kernel.org> Reviewed-by: James Liao <jamesjj.liao@mediatek.com> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org> Tested-by: Nicolas Boichat <drinkcat@chromium.org> Signed-off-by: Stephen Boyd <sboyd@kernel.org>
-rw-r--r--drivers/clk/mediatek/clk-mtk.h2
-rw-r--r--drivers/clk/mediatek/clk-pll.c15
2 files changed, 13 insertions, 4 deletions
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index fb27b5bf30d9..9d53ee3dffd2 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -227,8 +227,10 @@ struct mtk_pll_data {
227 unsigned int flags; 227 unsigned int flags;
228 const struct clk_ops *ops; 228 const struct clk_ops *ops;
229 u32 rst_bar_mask; 229 u32 rst_bar_mask;
230 unsigned long fmin;
230 unsigned long fmax; 231 unsigned long fmax;
231 int pcwbits; 232 int pcwbits;
233 int pcwibits;
232 uint32_t pcw_reg; 234 uint32_t pcw_reg;
233 int pcw_shift; 235 int pcw_shift;
234 const struct mtk_pll_div_table *div_table; 236 const struct mtk_pll_div_table *div_table;
diff --git a/drivers/clk/mediatek/clk-pll.c b/drivers/clk/mediatek/clk-pll.c
index 18842d660317..67aaa3082d9b 100644
--- a/drivers/clk/mediatek/clk-pll.c
+++ b/drivers/clk/mediatek/clk-pll.c
@@ -32,6 +32,8 @@
32#define AUDPLL_TUNER_EN BIT(31) 32#define AUDPLL_TUNER_EN BIT(31)
33 33
34#define POSTDIV_MASK 0x7 34#define POSTDIV_MASK 0x7
35
36/* default 7 bits integer, can be overridden with pcwibits. */
35#define INTEGER_BITS 7 37#define INTEGER_BITS 7
36 38
37/* 39/*
@@ -68,12 +70,15 @@ static unsigned long __mtk_pll_recalc_rate(struct mtk_clk_pll *pll, u32 fin,
68 u32 pcw, int postdiv) 70 u32 pcw, int postdiv)
69{ 71{
70 int pcwbits = pll->data->pcwbits; 72 int pcwbits = pll->data->pcwbits;
71 int pcwfbits; 73 int pcwfbits = 0;
74 int ibits;
72 u64 vco; 75 u64 vco;
73 u8 c = 0; 76 u8 c = 0;
74 77
75 /* The fractional part of the PLL divider. */ 78 /* The fractional part of the PLL divider. */
76 pcwfbits = pcwbits > INTEGER_BITS ? pcwbits - INTEGER_BITS : 0; 79 ibits = pll->data->pcwibits ? pll->data->pcwibits : INTEGER_BITS;
80 if (pcwbits > ibits)
81 pcwfbits = pcwbits - ibits;
77 82
78 vco = (u64)fin * pcw; 83 vco = (u64)fin * pcw;
79 84
@@ -170,9 +175,10 @@ static void mtk_pll_set_rate_regs(struct mtk_clk_pll *pll, u32 pcw,
170static void mtk_pll_calc_values(struct mtk_clk_pll *pll, u32 *pcw, u32 *postdiv, 175static void mtk_pll_calc_values(struct mtk_clk_pll *pll, u32 *pcw, u32 *postdiv,
171 u32 freq, u32 fin) 176 u32 freq, u32 fin)
172{ 177{
173 unsigned long fmin = 1000 * MHZ; 178 unsigned long fmin = pll->data->fmin ? pll->data->fmin : (1000 * MHZ);
174 const struct mtk_pll_div_table *div_table = pll->data->div_table; 179 const struct mtk_pll_div_table *div_table = pll->data->div_table;
175 u64 _pcw; 180 u64 _pcw;
181 int ibits;
176 u32 val; 182 u32 val;
177 183
178 if (freq > pll->data->fmax) 184 if (freq > pll->data->fmax)
@@ -196,7 +202,8 @@ static void mtk_pll_calc_values(struct mtk_clk_pll *pll, u32 *pcw, u32 *postdiv,
196 } 202 }
197 203
198 /* _pcw = freq * postdiv / fin * 2^pcwfbits */ 204 /* _pcw = freq * postdiv / fin * 2^pcwfbits */
199 _pcw = ((u64)freq << val) << (pll->data->pcwbits - INTEGER_BITS); 205 ibits = pll->data->pcwibits ? pll->data->pcwibits : INTEGER_BITS;
206 _pcw = ((u64)freq << val) << (pll->data->pcwbits - ibits);
200 do_div(_pcw, fin); 207 do_div(_pcw, fin);
201 208
202 *pcw = (u32)_pcw; 209 *pcw = (u32)_pcw;