From: "Peng Fan (OSS)" <peng.fan@oss.nxp.com>
To: sboyd@kernel.org, mturquette@baylibre.com
Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, kernel@pengutronix.de,
Peng Fan <peng.fan@nxp.com>
Subject: [PATCH 3/3] clk: gate: support regmap
Date: Fri, 28 May 2021 19:34:03 +0800 [thread overview]
Message-ID: <20210528113403.5374-4-peng.fan@oss.nxp.com> (raw)
In-Reply-To: <20210528113403.5374-1-peng.fan@oss.nxp.com>
From: Peng Fan <peng.fan@nxp.com>
To i.MX8ULP, a PCC register provides clk(mux, gate, divider) and peripheral
reset functionality, so we need make sure the access to the PCC register
be protected to avoid concurrent access from clk and reset subsystem.
So let's use regmap here.
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
drivers/clk/clk-gate.c | 26 +++++++++++++++++++++++---
include/linux/clk-provider.h | 3 +++
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/drivers/clk/clk-gate.c b/drivers/clk/clk-gate.c
index 070dc47e95a1..1acaa2f5a969 100644
--- a/drivers/clk/clk-gate.c
+++ b/drivers/clk/clk-gate.c
@@ -8,6 +8,7 @@
#include <linux/clk-provider.h>
#include <linux/module.h>
+#include <linux/regmap.h>
#include <linux/slab.h>
#include <linux/io.h>
#include <linux/err.h>
@@ -25,18 +26,37 @@
static inline u32 clk_gate_readl(struct clk_gate *gate)
{
- if (gate->flags & CLK_GATE_BIG_ENDIAN)
+ int ret;
+ u32 val;
+
+ if (gate->flags & CLK_GATE_BIG_ENDIAN) {
return ioread32be(gate->reg);
+ } else if (gate->flags & CLK_GATE_REGMAP) {
+ ret = regmap_read(gate->regmap, gate->reg_off, &val);
+ if (ret < 0) {
+ pr_warn("%s: failed %x, %d\n", __func__, gate->reg_off, ret);
+ return ret;
+ } else {
+ return val;
+ }
+ }
return readl(gate->reg);
}
static inline void clk_gate_writel(struct clk_gate *gate, u32 val)
{
- if (gate->flags & CLK_GATE_BIG_ENDIAN)
+ int ret;
+
+ if (gate->flags & CLK_GATE_BIG_ENDIAN) {
iowrite32be(val, gate->reg);
- else
+ } else if (gate->flags & CLK_GATE_REGMAP) {
+ ret = regmap_write(gate->regmap, gate->reg_off, val);
+ if (ret < 0)
+ pr_warn("%s: %x: %d\n", __func__, gate->reg_off, ret);
+ } else {
writel(val, gate->reg);
+ }
}
/*
diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
index 3902f883cdaf..0a4c01a023cc 100644
--- a/include/linux/clk-provider.h
+++ b/include/linux/clk-provider.h
@@ -474,6 +474,8 @@ struct clk_gate {
u8 bit_idx;
u8 flags;
spinlock_t *lock;
+ struct regmap *regmap;
+ u32 reg_off;
};
#define to_clk_gate(_hw) container_of(_hw, struct clk_gate, hw)
@@ -481,6 +483,7 @@ struct clk_gate {
#define CLK_GATE_SET_TO_DISABLE BIT(0)
#define CLK_GATE_HIWORD_MASK BIT(1)
#define CLK_GATE_BIG_ENDIAN BIT(2)
+#define CLK_GATE_REGMAP BIT(3)
extern const struct clk_ops clk_gate_ops;
struct clk_hw *__clk_hw_register_gate(struct device *dev,
--
2.30.0
next prev parent reply other threads:[~2021-05-28 11:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-28 11:34 [PATCH 0/3] clk: " Peng Fan (OSS)
2021-05-28 11:34 ` [PATCH 1/3] clk: mux: " Peng Fan (OSS)
2021-05-28 11:34 ` [PATCH 2/3] clk: fractional-divider: " Peng Fan (OSS)
2021-05-28 11:34 ` Peng Fan (OSS) [this message]
2021-06-02 8:18 ` [PATCH 0/3] clk: " Stephen Boyd
2021-06-02 8:21 ` Marc Kleine-Budde
2021-06-02 8:40 ` Peng Fan
2021-06-02 9:32 ` Jerome Brunet
2021-06-18 14:30 ` Jerome Brunet
2021-07-27 0:47 ` Stephen Boyd
2021-06-02 8:39 ` Peng Fan
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=20210528113403.5374-4-peng.fan@oss.nxp.com \
--to=peng.fan@oss.nxp.com \
--cc=kernel@pengutronix.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=peng.fan@nxp.com \
--cc=sboyd@kernel.org \
/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
all inboxes | Powered by JetHome®