From nobody Mon Feb 9 17:04:58 2026 Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BDFD2BEC5E; Sat, 3 Jan 2026 07:45:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=140.211.166.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767426340; cv=none; b=SsL0gFsVQr8DIKswRgPyXhlDfdUIReTKOqcZG7te0ZBf4Lyw6qTYZsytO+NQOYpi7M4ACcByPUb6jh+qFIUypW0fN27rbVUteLeBLuLOT48IcfJFJ1AXOnDwNVnqcRhqg1cvA4NjuwrtRwVBxhJODEb07GgFxfcANElIyW499hA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767426340; c=relaxed/simple; bh=ipL2B/NzInRqtMt2AU3bNhpY6GimKKXFXudISgvQy5c=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=laIJ6ANpmrx+bAcKmyI7L2w7YkF1r+RX5pviJNjKU66DhBOBLTpgEtN5vYHgGcRTj8Pm7bIznZ4fnvvDSnPf8aT8z8XF+zNp3fB9FYeFwEVHH/plUH8EtztK8QKoEiJaHv3DCe0vbWG1wK2pgDNeNv7KDyXirN0W79RdpWN2lEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gentoo.org; spf=pass smtp.mailfrom=gentoo.org; arc=none smtp.client-ip=140.211.166.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gentoo.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gentoo.org Received: from [127.0.0.1] (unknown [116.232.18.222]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: dlan) by smtp.gentoo.org (Postfix) with ESMTPSA id 744C93410B9; Sat, 03 Jan 2026 07:45:31 +0000 (UTC) From: Yixun Lan Date: Sat, 03 Jan 2026 15:44:17 +0800 Subject: [PATCH v4 2/5] clk: spacemit: ccu_mix: add inverted enable gate clock Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260103-k3-clk-v4-2-4cccba2360f0@gentoo.org> References: <20260103-k3-clk-v4-0-4cccba2360f0@gentoo.org> In-Reply-To: <20260103-k3-clk-v4-0-4cccba2360f0@gentoo.org> To: Stephen Boyd , Michael Turquette , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Haylen Chu , Guodong Xu , Inochi Amaoto , Yao Zi , 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 X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=3259; i=dlan@gentoo.org; h=from:subject:message-id; bh=ipL2B/NzInRqtMt2AU3bNhpY6GimKKXFXudISgvQy5c=; b=owEB6QIW/ZANAwAKATGq6kdZTbvtAcsmYgBpWMkCC51BegXxeL4pfgn0B+4VTkn1GAXxLCDyv QI+vaPL+DeJAq8EAAEKAJkWIQS1urjJwxtxFWcCI9wxqupHWU277QUCaVjJAhsUgAAAAAAEAA5t YW51MiwyLjUrMS4xMSwyLDJfFIAAAAAALgAoaXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5 maWZ0aGhvcnNlbWFuLm5ldEI1QkFCOEM5QzMxQjcxMTU2NzAyMjNEQzMxQUFFQTQ3NTk0REJCRU QACgkQMarqR1lNu+2QWw//Zq1tgDWX0cyN1zVp+4+M3qAN3sjCpEM66y1aBwL3XspW0Y44yJKA+ 7eRKq4baIX1nNFJotTknmt2gEWeSl4UpOfBRGR4HU0sZms2Fg7+fZ36fyR9znOjs9mO4zkkPCLr Kg9eO8kLxtQ8ViqrOLTqX/B0VWP2jWZSvBbLef+4fM9j6doPKRxNsqKvkfkD3NAQJI1fE7iArvs sE8x2NQxgtj8D2vY7f76oPx4XMrPLehQEr5eD69KojQHkv08ABFSl9UBTlaPg/hwQjj02f57m1y TYgy2glJ6i1nU0Hk1C+YHCWWyqibuC3j3BYvijETwQBlOcP+bDMH4ZdEvQ0O8/Iy/A4vk56GMaP Af582JlzjYVTJAzBbPIGzD2ifUt4Q0Hutp+rshQsuzHSiVyx6MqRBpRvYtfVYaOZ9SSTvio68uM Q402KHklwgIQ7UiqiHwcd83aOwYmIUf0yLF+4zk7Yvl04CvdAo7tg9tpmGH4QnVE5Q79rH7giCH Pqr0DPerjd0UZJ2ruvFJiL+bppO46ObffCsRSJDOGgDX+WiTKPGZ4XzrOP5VStTRWMic613OpED 4YcmdPNt2p/tbEKy3slof/tOtr/2eT0b9WeKncSsCovlgjUDEOWWROEqNSQfBycGVLL1QqKpqQj AMLyAfQXpSP6DiFkpaJZ7zovj1H4/U= X-Developer-Key: i=dlan@gentoo.org; a=openpgp; fpr=50B03A1A5CBCD33576EF8CD7920C0DBCAABEFD55 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 --- 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 =3D hw_to_ccu_mix(hw); + struct ccu_gate_config *gate =3D &mix->gate; + u32 val =3D gate->inverted ? gate->mask : 0; =20 - ccu_update(&mix->common, ctrl, mix->gate.mask, 0); + ccu_update(&mix->common, ctrl, gate->mask, val); } =20 static int ccu_gate_enable(struct clk_hw *hw) { struct ccu_mix *mix =3D hw_to_ccu_mix(hw); struct ccu_gate_config *gate =3D &mix->gate; + u32 val =3D gate->inverted ? 0 : gate->mask; =20 - ccu_update(&mix->common, ctrl, gate->mask, gate->mask); - + ccu_update(&mix->common, ctrl, gate->mask, val); return 0; } =20 @@ -34,8 +36,10 @@ static int ccu_gate_is_enabled(struct clk_hw *hw) { struct ccu_mix *mix =3D hw_to_ccu_mix(hw); struct ccu_gate_config *gate =3D &mix->gate; + u32 tmp =3D ccu_read(&mix->common, ctrl) & gate->mask; + u32 val =3D gate->inverted ? 0 : gate->mask; =20 - return (ccu_read(&mix->common, ctrl) & gate->mask) =3D=3D gate->mask; + return !!(tmp =3D=3D val); } =20 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; }; =20 struct ccu_factor_config { @@ -48,6 +50,7 @@ struct ccu_mix { #define CCU_FACTOR_INIT(_div, _mul) { .div =3D _div, .mul =3D _mul } #define CCU_MUX_INIT(_shift, _width) { .shift =3D _shift, .width =3D _widt= h } #define CCU_DIV_INIT(_shift, _width) { .shift =3D _shift, .width =3D _widt= h } +#define CCU_GATE_FLAGS_INIT(_mask, _inverted) { .mask =3D _mask, .inverted= =3D _inverted } =20 #define CCU_PARENT_HW(_parent) { .hw =3D &_parent.common.hw } #define CCU_PARENT_NAME(_name) { .fw_name =3D #_name } @@ -101,6 +104,15 @@ static struct ccu_mix _name =3D { \ } \ } =20 +#define CCU_GATE_FLAGS_DEFINE(_name, _parent, _reg_ctrl, _mask_gate, _inve= rted, _flags) \ +static struct ccu_mix _name =3D { \ + .gate =3D CCU_GATE_FLAGS_INIT(_mask_gate, _inverted), \ + .common =3D { \ + .reg_ctrl =3D _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 =3D { \ --=20 2.52.0