From: Jon Mason <jonmason@broadcom.com>
To: Michael Turquette <mturquette@baylibre.com>,
Stephen Boyd <sboyd@codeaurora.org>
Cc: devicetree@vger.kernel.org,
Florian Fainelli <f.fainelli@gmail.com>,
Scott Branden <sbranden@broadcom.com>,
Hauke Mehrtens <hauke@hauke-m.de>,
linux-kernel@vger.kernel.org,
bcm-kernel-feedback-list@broadcom.com,
Ray Jui <rjui@broadcom.com>,
linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 05/10] clk: iproc: Add PLL base write function
Date: Thu, 15 Oct 2015 15:48:28 -0400 [thread overview]
Message-ID: <1444938513-10758-6-git-send-email-jonmason@broadcom.com> (raw)
In-Reply-To: <1444938513-10758-1-git-send-email-jonmason@broadcom.com>
All writes to the PLL base address must be flushed if the
IPROC_CLK_NEEDS_READ_BACK flag is set. If we add a function to make the
necessary write and reads, we can make sure that any future code which
makes PLL base writes will do the correct thing.
Signed-off-by: Jon Mason <jonmason@broadcom.com>
---
drivers/clk/bcm/clk-iproc-pll.c | 80 +++++++++++++++++------------------------
1 file changed, 33 insertions(+), 47 deletions(-)
diff --git a/drivers/clk/bcm/clk-iproc-pll.c b/drivers/clk/bcm/clk-iproc-pll.c
index e029ab3..74cdd66 100644
--- a/drivers/clk/bcm/clk-iproc-pll.c
+++ b/drivers/clk/bcm/clk-iproc-pll.c
@@ -137,6 +137,18 @@ static int pll_wait_for_lock(struct iproc_pll *pll)
return -EIO;
}
+static void iproc_pll_write(const struct iproc_pll *pll, void __iomem *base,
+ const u32 offset, u32 val)
+{
+ const struct iproc_pll_ctrl *ctrl = pll->ctrl;
+
+ writel(val, base + offset);
+
+ if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK &&
+ base == pll->pll_base))
+ val = readl(base + offset);
+}
+
static void __pll_disable(struct iproc_pll *pll)
{
const struct iproc_pll_ctrl *ctrl = pll->ctrl;
@@ -145,27 +157,24 @@ static void __pll_disable(struct iproc_pll *pll)
if (ctrl->flags & IPROC_CLK_PLL_ASIU) {
val = readl(pll->asiu_base + ctrl->asiu.offset);
val &= ~(1 << ctrl->asiu.en_shift);
- writel(val, pll->asiu_base + ctrl->asiu.offset);
+ iproc_pll_write(pll, pll->asiu_base, ctrl->asiu.offset, val);
}
if (ctrl->flags & IPROC_CLK_EMBED_PWRCTRL) {
val = readl(pll->pll_base + ctrl->aon.offset);
val |= (bit_mask(ctrl->aon.pwr_width) << ctrl->aon.pwr_shift);
- writel(val, pll->pll_base + ctrl->aon.offset);
-
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->aon.offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->aon.offset, val);
}
if (pll->pwr_base) {
/* latch input value so core power can be shut down */
val = readl(pll->pwr_base + ctrl->aon.offset);
val |= (1 << ctrl->aon.iso_shift);
- writel(val, pll->pwr_base + ctrl->aon.offset);
+ iproc_pll_write(pll, pll->pwr_base, ctrl->aon.offset, val);
/* power down the core */
val &= ~(bit_mask(ctrl->aon.pwr_width) << ctrl->aon.pwr_shift);
- writel(val, pll->pwr_base + ctrl->aon.offset);
+ iproc_pll_write(pll, pll->pwr_base, ctrl->aon.offset, val);
}
}
@@ -177,10 +186,7 @@ static int __pll_enable(struct iproc_pll *pll)
if (ctrl->flags & IPROC_CLK_EMBED_PWRCTRL) {
val = readl(pll->pll_base + ctrl->aon.offset);
val &= ~(bit_mask(ctrl->aon.pwr_width) << ctrl->aon.pwr_shift);
- writel(val, pll->pll_base + ctrl->aon.offset);
-
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->aon.offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->aon.offset, val);
}
if (pll->pwr_base) {
@@ -188,14 +194,14 @@ static int __pll_enable(struct iproc_pll *pll)
val = readl(pll->pwr_base + ctrl->aon.offset);
val |= bit_mask(ctrl->aon.pwr_width) << ctrl->aon.pwr_shift;
val &= ~(1 << ctrl->aon.iso_shift);
- writel(val, pll->pwr_base + ctrl->aon.offset);
+ iproc_pll_write(pll, pll->pwr_base, ctrl->aon.offset, val);
}
/* certain PLLs also need to be ungated from the ASIU top level */
if (ctrl->flags & IPROC_CLK_PLL_ASIU) {
val = readl(pll->asiu_base + ctrl->asiu.offset);
val |= (1 << ctrl->asiu.en_shift);
- writel(val, pll->asiu_base + ctrl->asiu.offset);
+ iproc_pll_write(pll, pll->asiu_base, ctrl->asiu.offset, val);
}
return 0;
@@ -209,9 +215,7 @@ static void __pll_put_in_reset(struct iproc_pll *pll)
val = readl(pll->pll_base + reset->offset);
val &= ~(1 << reset->reset_shift | 1 << reset->p_reset_shift);
- writel(val, pll->pll_base + reset->offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + reset->offset);
+ iproc_pll_write(pll, pll->pll_base, reset->offset, val);
}
static void __pll_bring_out_reset(struct iproc_pll *pll, unsigned int kp,
@@ -228,9 +232,7 @@ static void __pll_bring_out_reset(struct iproc_pll *pll, unsigned int kp,
val |= ki << reset->ki_shift | kp << reset->kp_shift |
ka << reset->ka_shift;
val |= 1 << reset->reset_shift | 1 << reset->p_reset_shift;
- writel(val, pll->pll_base + reset->offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + reset->offset);
+ iproc_pll_write(pll, pll->pll_base, reset->offset, val);
}
static int pll_set_rate(struct iproc_clk *clk, unsigned int rate_index,
@@ -285,9 +287,8 @@ static int pll_set_rate(struct iproc_clk *clk, unsigned int rate_index,
/* put PLL in reset */
__pll_put_in_reset(pll);
- writel(0, pll->pll_base + ctrl->vco_ctrl.u_offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->vco_ctrl.u_offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->vco_ctrl.u_offset, 0);
+
val = readl(pll->pll_base + ctrl->vco_ctrl.l_offset);
if (rate >= VCO_LOW && rate < VCO_MID)
@@ -298,17 +299,13 @@ static int pll_set_rate(struct iproc_clk *clk, unsigned int rate_index,
else
val |= (1 << PLL_VCO_HIGH_SHIFT);
- writel(val, pll->pll_base + ctrl->vco_ctrl.l_offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->vco_ctrl.l_offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->vco_ctrl.l_offset, val);
/* program integer part of NDIV */
val = readl(pll->pll_base + ctrl->ndiv_int.offset);
val &= ~(bit_mask(ctrl->ndiv_int.width) << ctrl->ndiv_int.shift);
val |= vco->ndiv_int << ctrl->ndiv_int.shift;
- writel(val, pll->pll_base + ctrl->ndiv_int.offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->ndiv_int.offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->ndiv_int.offset, val);
/* program fractional part of NDIV */
if (ctrl->flags & IPROC_CLK_PLL_HAS_NDIV_FRAC) {
@@ -316,18 +313,15 @@ static int pll_set_rate(struct iproc_clk *clk, unsigned int rate_index,
val &= ~(bit_mask(ctrl->ndiv_frac.width) <<
ctrl->ndiv_frac.shift);
val |= vco->ndiv_frac << ctrl->ndiv_frac.shift;
- writel(val, pll->pll_base + ctrl->ndiv_frac.offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->ndiv_frac.offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->ndiv_frac.offset,
+ val);
}
/* program PDIV */
val = readl(pll->pll_base + ctrl->pdiv.offset);
val &= ~(bit_mask(ctrl->pdiv.width) << ctrl->pdiv.shift);
val |= vco->pdiv << ctrl->pdiv.shift;
- writel(val, pll->pll_base + ctrl->pdiv.offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->pdiv.offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->pdiv.offset, val);
__pll_bring_out_reset(pll, kp, ka, ki);
@@ -467,14 +461,12 @@ static int iproc_clk_enable(struct clk_hw *hw)
/* channel enable is active low */
val = readl(pll->pll_base + ctrl->enable.offset);
val &= ~(1 << ctrl->enable.enable_shift);
- writel(val, pll->pll_base + ctrl->enable.offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->enable.offset, val);
/* also make sure channel is not held */
val = readl(pll->pll_base + ctrl->enable.offset);
val &= ~(1 << ctrl->enable.hold_shift);
- writel(val, pll->pll_base + ctrl->enable.offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->enable.offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->enable.offset, val);
return 0;
}
@@ -491,9 +483,7 @@ static void iproc_clk_disable(struct clk_hw *hw)
val = readl(pll->pll_base + ctrl->enable.offset);
val |= 1 << ctrl->enable.enable_shift;
- writel(val, pll->pll_base + ctrl->enable.offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->enable.offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->enable.offset, val);
}
static unsigned long iproc_clk_recalc_rate(struct clk_hw *hw,
@@ -562,9 +552,7 @@ static int iproc_clk_set_rate(struct clk_hw *hw, unsigned long rate,
val &= ~(bit_mask(ctrl->mdiv.width) << ctrl->mdiv.shift);
val |= div << ctrl->mdiv.shift;
}
- writel(val, pll->pll_base + ctrl->mdiv.offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->mdiv.offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->mdiv.offset, val);
clk->rate = parent_rate / div;
return 0;
@@ -591,9 +579,7 @@ static void iproc_pll_sw_cfg(struct iproc_pll *pll)
val = readl(pll->pll_base + ctrl->sw_ctrl.offset);
val |= BIT(ctrl->sw_ctrl.shift);
- writel(val, pll->pll_base + ctrl->sw_ctrl.offset);
- if (unlikely(ctrl->flags & IPROC_CLK_NEEDS_READ_BACK))
- readl(pll->pll_base + ctrl->sw_ctrl.offset);
+ iproc_pll_write(pll, pll->pll_base, ctrl->sw_ctrl.offset, val);
}
}
--
1.9.1
next prev parent reply other threads:[~2015-10-15 19:48 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-15 19:48 [PATCH v3 0/10] clk: iproc: add support for BCM NS, NSP, and NS2 Jon Mason
2015-10-15 19:48 ` [PATCH v3 01/10] ARM: cygnus: fix link failures when CONFIG_COMMON_CLK_IPROC is disabled Jon Mason
2015-10-15 20:28 ` Scott Branden
2015-10-15 21:08 ` Jon Mason
2015-10-15 21:17 ` Hauke Mehrtens
2015-10-21 23:40 ` Stephen Boyd
2015-10-15 19:48 ` [PATCH v3 02/10] clk: cygnus: Convert all macros to all caps Jon Mason
[not found] ` <1444938513-10758-3-git-send-email-jonmason-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
2015-10-21 23:44 ` Stephen Boyd
2015-10-15 19:48 ` [PATCH v3 03/10] clk: iproc: Add PWRCTRL support Jon Mason
2015-10-21 23:48 ` Stephen Boyd
2015-10-15 19:48 ` [PATCH v3 04/10] clk: nsp: add clock support for Broadcom Northstar Plus SoC Jon Mason
2015-10-15 20:41 ` Scott Branden
2015-10-15 21:04 ` Jon Mason
2015-10-21 23:54 ` Stephen Boyd
2015-10-15 19:48 ` Jon Mason [this message]
2015-10-22 0:02 ` [PATCH v3 05/10] clk: iproc: Add PLL base write function spamassassin system account
2015-10-15 19:48 ` [PATCH v3 06/10] clk: iproc: Split off dig_filter Jon Mason
2015-10-22 0:04 ` Stephen Boyd
2015-10-15 19:48 ` [PATCH v3 07/10] clk: iproc: Separate status and control variables Jon Mason
2015-10-22 0:04 ` Stephen Boyd
2015-10-15 19:48 ` [PATCH v3 08/10] clk: ns2: add clock support for Broadcom Northstar 2 SoC Jon Mason
2015-10-15 20:40 ` Scott Branden
2015-10-15 20:55 ` Ray Jui
[not found] ` <562012A8.8050707-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
2015-10-15 21:04 ` Scott Branden
2015-10-15 21:10 ` Jon Mason
2015-10-15 21:15 ` Ray Jui
2015-10-15 21:25 ` Scott Branden
[not found] ` <562019DD.3000206-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
2015-10-22 0:22 ` Stephen Boyd
2015-10-22 14:18 ` Jon Mason
2015-10-22 0:25 ` Stephen Boyd
[not found] ` <1444938513-10758-1-git-send-email-jonmason-dY08KVG/lbpWk0Htik3J/w@public.gmane.org>
2015-10-15 19:48 ` [PATCH v3 09/10] clk: iproc: define Broadcom NSP iProc clock binding Jon Mason
2015-10-22 0:25 ` Stephen Boyd
2015-10-15 19:48 ` [PATCH v3 10/10] clk: iproc: define Broadcom NS2 " Jon Mason
2015-10-22 0:25 ` Stephen Boyd
2015-10-21 23:51 ` [PATCH v3 0/10] clk: iproc: add support for BCM NS, NSP, and NS2 Stephen Boyd
[not found] ` <20151021235144.GQ19782-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
2015-10-22 14:16 ` Jon Mason
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=1444938513-10758-6-git-send-email-jonmason@broadcom.com \
--to=jonmason@broadcom.com \
--cc=bcm-kernel-feedback-list@broadcom.com \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=hauke@hauke-m.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mturquette@baylibre.com \
--cc=rjui@broadcom.com \
--cc=sboyd@codeaurora.org \
--cc=sbranden@broadcom.com \
/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;
as well as URLs for NNTP newsgroup(s).