From: mingming lee <mingming.lee@mediatek.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 4/8] clk: mediatek: add configurable pcw_chg_reg/ibits/fmin to mtk_pll
Date: Tue, 31 Dec 2019 11:29:22 +0800 [thread overview]
Message-ID: <20191231032926.2194-5-mingming.lee@mediatek.com> (raw)
In-Reply-To: <20191231032926.2194-1-mingming.lee@mediatek.com>
Add configurable pcw_chg_reg/ibits/fmin to mtk_pll to support mt8512
---
drivers/clk/mediatek/clk-mtk.c | 25 +++++++++++++++++--------
drivers/clk/mediatek/clk-mtk.h | 3 +++
2 files changed, 20 insertions(+), 8 deletions(-)
diff --git a/drivers/clk/mediatek/clk-mtk.c b/drivers/clk/mediatek/clk-mtk.c
index 450de981e9..334559161e 100644
--- a/drivers/clk/mediatek/clk-mtk.c
+++ b/drivers/clk/mediatek/clk-mtk.c
@@ -95,11 +95,13 @@ static unsigned long __mtk_pll_recalc_rate(const struct mtk_pll_data *pll,
{
int pcwbits = pll->pcwbits;
int pcwfbits;
+ int ibits;
u64 vco;
u8 c = 0;
/* The fractional part of the PLL divider. */
- pcwfbits = pcwbits > INTEGER_BITS ? pcwbits - INTEGER_BITS : 0;
+ ibits = pll->pcwibits ? pll->pcwibits : INTEGER_BITS;
+ pcwfbits = pcwbits > ibits ? pcwbits - ibits : 0;
vco = (u64)fin * pcw;
@@ -124,7 +126,7 @@ static void mtk_pll_set_rate_regs(struct clk *clk, u32 pcw, int postdiv)
{
struct mtk_clk_priv *priv = dev_get_priv(clk->dev);
const struct mtk_pll_data *pll = &priv->tree->plls[clk->id];
- u32 val;
+ u32 val, chg;
/* set postdiv */
val = readl(priv->base + pll->pd_reg);
@@ -140,11 +142,16 @@ static void mtk_pll_set_rate_regs(struct clk *clk, u32 pcw, int postdiv)
/* set pcw */
val &= ~GENMASK(pll->pcw_shift + pll->pcwbits - 1, pll->pcw_shift);
val |= pcw << pll->pcw_shift;
- val &= ~CON1_PCW_CHG;
- writel(val, priv->base + pll->pcw_reg);
- val |= CON1_PCW_CHG;
- writel(val, priv->base + pll->pcw_reg);
+ if (pll->pcw_chg_reg) {
+ chg = readl(priv->base + pll->pcw_chg_reg);
+ chg |= CON1_PCW_CHG;
+ writel(val, priv->base + pll->pcw_reg);
+ writel(chg, priv->base + pll->pcw_chg_reg);
+ } else {
+ val |= CON1_PCW_CHG;
+ writel(val, priv->base + pll->pcw_reg);
+ }
udelay(20);
}
@@ -161,8 +168,9 @@ static void mtk_pll_calc_values(struct clk *clk, u32 *pcw, u32 *postdiv,
{
struct mtk_clk_priv *priv = dev_get_priv(clk->dev);
const struct mtk_pll_data *pll = &priv->tree->plls[clk->id];
- unsigned long fmin = 1000 * MHZ;
+ unsigned long fmin = pll->fmin ? pll->fmin : 1000 * MHZ;
u64 _pcw;
+ int ibits;
u32 val;
if (freq > pll->fmax)
@@ -175,7 +183,8 @@ static void mtk_pll_calc_values(struct clk *clk, u32 *pcw, u32 *postdiv,
}
/* _pcw = freq * postdiv / xtal_rate * 2^pcwfbits */
- _pcw = ((u64)freq << val) << (pll->pcwbits - INTEGER_BITS);
+ ibits = pll->pcwibits ? pll->pcwibits : INTEGER_BITS;
+ _pcw = ((u64)freq << val) << (pll->pcwbits - ibits);
do_div(_pcw, priv->tree->xtal2_rate);
*pcw = (u32)_pcw;
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index 7ea0042500..c7dc980861 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -37,9 +37,12 @@ struct mtk_pll_data {
u32 flags;
u32 rst_bar_mask;
u64 fmax;
+ u64 fmin;
int pcwbits;
+ int pcwibits;
u32 pcw_reg;
int pcw_shift;
+ u32 pcw_chg_reg;
};
/**
--
2.24.1
next prev parent reply other threads:[~2019-12-31 3:29 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-12-31 3:29 [PATCH v2 0/8] Add support for MediaTek MT8512 Soc mingming lee
2019-12-31 3:29 ` [PATCH v2 1/8] ARM: MediaTek: Add support for MediaTek MT8512 SoC mingming lee
2020-01-16 14:41 ` Tom Rini
2019-12-31 3:29 ` [PATCH v2 2/8] clk: mediatek: add driver support for MT8512 mingming lee
2020-01-16 14:41 ` Tom Rini
2019-12-31 3:29 ` [PATCH v2 3/8] clk: mediatek: add set_clr_upd mux type flow mingming lee
2020-01-16 14:41 ` Tom Rini
2019-12-31 3:29 ` mingming lee [this message]
2020-01-16 14:41 ` [PATCH v2 4/8] clk: mediatek: add configurable pcw_chg_reg/ibits/fmin to mtk_pll Tom Rini
2020-01-16 14:41 ` Tom Rini
2019-12-31 3:29 ` [PATCH v2 5/8] pinctrl: mediatek: add driver for MT8512 mingming lee
2020-01-16 14:41 ` Tom Rini
2019-12-31 3:29 ` [PATCH v2 6/8] mmc: mtk-sd: add support for MediaTek MT8512/MT8110 SoCs mingming lee
2020-01-16 14:41 ` Tom Rini
2019-12-31 3:29 ` [PATCH v2 7/8] mmc: mtk-sd: fix hang when data read quickly mingming lee
2020-01-16 14:41 ` Tom Rini
2019-12-31 3:29 ` [PATCH v2 8/8] ARM: MediaTek: add basic support for MT8512 boards mingming lee
2020-01-16 14:41 ` Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191231032926.2194-5-mingming.lee@mediatek.com \
--to=mingming.lee@mediatek.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox