From: Yixun Lan <dlan@gentoo.org>
To: Stephen Boyd <sboyd@kernel.org>,
Michael Turquette <mturquette@baylibre.com>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>
Cc: Haylen Chu <heylenay@4d2.org>, Guodong Xu <guodong@riscstar.com>,
Inochi Amaoto <inochiama@gmail.com>, Yao Zi <me@ziyao.cc>,
linux-clk@vger.kernel.org, devicetree@vger.kernel.org,
linux-riscv@lists.infradead.org, spacemit@lists.linux.dev,
linux-kernel@vger.kernel.org, Yixun Lan <dlan@gentoo.org>
Subject: [PATCH v4 2/5] clk: spacemit: ccu_mix: add inverted enable gate clock
Date: Sat, 03 Jan 2026 15:44:17 +0800 [thread overview]
Message-ID: <20260103-k3-clk-v4-2-4cccba2360f0@gentoo.org> (raw)
In-Reply-To: <20260103-k3-clk-v4-0-4cccba2360f0@gentoo.org>
K3 SoC has the clock IP which support to write value 0 for enabling the
clock, while write 1 for disabling it, thus the enable BIT is inverted.
So, introduce a flag to support the inverted gate clock.
Signed-off-by: Yixun Lan <dlan@gentoo.org>
---
drivers/clk/spacemit/ccu_mix.c | 12 ++++++++----
drivers/clk/spacemit/ccu_mix.h | 12 ++++++++++++
2 files changed, 20 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/spacemit/ccu_mix.c b/drivers/clk/spacemit/ccu_mix.c
index 67f8b12b4f5b..9578366e9746 100644
--- a/drivers/clk/spacemit/ccu_mix.c
+++ b/drivers/clk/spacemit/ccu_mix.c
@@ -16,17 +16,19 @@
static void ccu_gate_disable(struct clk_hw *hw)
{
struct ccu_mix *mix = hw_to_ccu_mix(hw);
+ struct ccu_gate_config *gate = &mix->gate;
+ u32 val = gate->inverted ? gate->mask : 0;
- ccu_update(&mix->common, ctrl, mix->gate.mask, 0);
+ ccu_update(&mix->common, ctrl, gate->mask, val);
}
static int ccu_gate_enable(struct clk_hw *hw)
{
struct ccu_mix *mix = hw_to_ccu_mix(hw);
struct ccu_gate_config *gate = &mix->gate;
+ u32 val = gate->inverted ? 0 : gate->mask;
- ccu_update(&mix->common, ctrl, gate->mask, gate->mask);
-
+ ccu_update(&mix->common, ctrl, gate->mask, val);
return 0;
}
@@ -34,8 +36,10 @@ static int ccu_gate_is_enabled(struct clk_hw *hw)
{
struct ccu_mix *mix = hw_to_ccu_mix(hw);
struct ccu_gate_config *gate = &mix->gate;
+ u32 tmp = ccu_read(&mix->common, ctrl) & gate->mask;
+ u32 val = gate->inverted ? 0 : gate->mask;
- return (ccu_read(&mix->common, ctrl) & gate->mask) == gate->mask;
+ return !!(tmp == val);
}
static unsigned long ccu_factor_recalc_rate(struct clk_hw *hw,
diff --git a/drivers/clk/spacemit/ccu_mix.h b/drivers/clk/spacemit/ccu_mix.h
index c406508e3504..dbba9bf49b3b 100644
--- a/drivers/clk/spacemit/ccu_mix.h
+++ b/drivers/clk/spacemit/ccu_mix.h
@@ -16,9 +16,11 @@
*
* @mask: Mask to enable the gate. Some clocks may have more than one bit
* set in this field.
+ * @inverted: Enable bit is inverted, 1 - disable clock, 0 - enable clock
*/
struct ccu_gate_config {
u32 mask;
+ bool inverted;
};
struct ccu_factor_config {
@@ -48,6 +50,7 @@ struct ccu_mix {
#define CCU_FACTOR_INIT(_div, _mul) { .div = _div, .mul = _mul }
#define CCU_MUX_INIT(_shift, _width) { .shift = _shift, .width = _width }
#define CCU_DIV_INIT(_shift, _width) { .shift = _shift, .width = _width }
+#define CCU_GATE_FLAGS_INIT(_mask, _inverted) { .mask = _mask, .inverted = _inverted }
#define CCU_PARENT_HW(_parent) { .hw = &_parent.common.hw }
#define CCU_PARENT_NAME(_name) { .fw_name = #_name }
@@ -101,6 +104,15 @@ static struct ccu_mix _name = { \
} \
}
+#define CCU_GATE_FLAGS_DEFINE(_name, _parent, _reg_ctrl, _mask_gate, _inverted, _flags) \
+static struct ccu_mix _name = { \
+ .gate = CCU_GATE_FLAGS_INIT(_mask_gate, _inverted), \
+ .common = { \
+ .reg_ctrl = _reg_ctrl, \
+ CCU_MIX_INITHW(_name, _parent, spacemit_ccu_gate_ops, _flags), \
+ } \
+}
+
#define CCU_FACTOR_GATE_FLAGS_DEFINE(_name, _parent, _reg_ctrl, _mask_gate, _div, \
_mul, _flags) \
static struct ccu_mix _name = { \
--
2.52.0
next prev parent reply other threads:[~2026-01-03 7:45 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-03 7:44 [PATCH v4 0/5] Add clock support for SpacemiT K3 SoC Yixun Lan
2026-01-03 7:44 ` [PATCH v4 1/5] dt-bindings: soc: spacemit: k3: add clock support Yixun Lan
2026-01-05 7:48 ` Krzysztof Kozlowski
2026-01-05 7:55 ` Yixun Lan
2026-01-03 7:44 ` Yixun Lan [this message]
2026-01-03 7:44 ` [PATCH v4 3/5] clk: spacemit: ccu_pll: add plla type clock Yixun Lan
2026-01-03 7:44 ` [PATCH v4 4/5] clk: spacemit: k3: extract common header Yixun Lan
2026-01-03 7:44 ` [PATCH v4 5/5] clk: spacemit: k3: add the clock tree Yixun Lan
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=20260103-k3-clk-v4-2-4cccba2360f0@gentoo.org \
--to=dlan@gentoo.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=guodong@riscstar.com \
--cc=heylenay@4d2.org \
--cc=inochiama@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=me@ziyao.cc \
--cc=mturquette@baylibre.com \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=spacemit@lists.linux.dev \
/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®