From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8D85B606A327 for ; Tue, 1 Dec 2026 08:56:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=NR6BF7Q9; dkim=fail reason="signature verification failed" (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=D8u0Zyh0 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References: Message-Id:MIME-Version:Subject:Date:From:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=FWmCf9mJ0VhVhxAOAZd8reQ8wbfHrG1Vok/Dt5hY9bQ=; b=NR6BF7Q9I/p4nULtiwWJFOoFBG u4WCFvLKIVZgroWxN0JchzEUcARwaL7fS23n2sG/wKPWSucEYfUJ6qu7hFQxQMxsVSyatu8hh/7NJ OQivSRrDFLRy2wRWfIg+7iaFsPe4Yr8XvMCDVDHNipHBME9WRN6S+X8rfnw9DGBet2Iq74tBNurq2 3MnHgsKM/KOWIsuBAVuyd6Al7j8/1+of/4bXfYyrTzZl1lWoqUaXxL9z5OwDOdH+kKhlM293dioMb Bj/PuPfx0/1PmmCSepk5VE9sulR9thp5gl+KcLXKXbEvTswxigY3CcFlKCh8JFn2YuDjKPXVoTrns Zp7wnmow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYJfK-000000075lG-3N3l; Tue, 01 Dec 2026 08:56:46 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYJfH-000000075k8-0u9E; Tue, 01 Dec 2026 08:56:45 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 930F1405A9; Tue, 1 Dec 2026 08:56:42 +0000 (UTC) Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796115402; b=3KHcA/3DxPs6W1c9jpU0XhW8xxoSl2QjGk5FbIW4B5Wrc1N+J5Mi4mb5jbQrq0HmDeJi tWGuSuuER6Zr3+Lq4bJoLxYlb1OcsbHi+HmJnEnWFTkcq3FwLVBp0Zd+31VWi/SqRP92E KCTMKa8ixGNm1/iXu96NivCMpXJV15wZEFJAb027EmhicFVhl7GjxZqdBwC8tx95ddasL rRIGfBihnkKrIu28ltmgJl83Bc05+tB938l1axUNyJ45eArFsmoKr1SvhW3/ECD9h/IUn mvzVPdOgHjvi1fbQpMEIYXdR8ZDie9kt9PckPnRxLKBI4V84Mt19OYH/IJLnpxoN5Ag== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796115402; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=A4YQUFDebuJ5HU4ME8XjRhcQu9bYjSa9sSKF6a5pNI0=; b=A5bLFplvw6Y+TB4Na2ANPZOwi4AmZ3H+aZeFCtc4o8fE4q+ooZFYBDkpQ7Qdw17Sm57S /kHgBDVnPkWp2+IW1YFylNjccTp/8qwQubBlZ8xLlsdt8I3L2ZFPZ7pcUHYt6s7FeKneG wRXiynwfCoqRkFdHPPnhTMH2ZbHfj/8GqzvDsh1KdiVWQ1HNO4hGxe/Kv8uZA2wPU2oQa J+2eVfrl4q+nsr7hI542XWnsBc9snUEFYjHMh98xsLvzWfdVmVqOJIZZcGQ2DPJEWVhp/ agpc6EWwnMvOeVxE5wD2TXi/JsKDWrt/6Kf/kfdxGbg/ZPWHXH9n9bSe5YON5/vJAgA== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id B8C5C1F00897; Tue, 1 Dec 2026 08:56:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796115402; bh=A4YQUFDebuJ5HU4ME8XjRhcQu9bYjSa9sSKF6a5pNI0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=D8u0Zyh0FnjxU7jNzTDS2XBhq6Mt1Uz9BKTm4iWvkXI6LxZ/aIr3msQnKdABq+7Lz 0CgOJG5+hKG3NMM3zFHGGDjQoGO9EbW18IftuB+DmYdmpw8HwbHaFiwq83jV1ehbOL dKRXvksSJo3UHEdbGwhaXZMFug/l2cLzKxU59mpYJpdjiK3qvyVIFvu4jl6gtRNLeG F5J5H2P9wZOo8O7L02QVLYZetNZ9st/ScTRy7fMhGNPCGs+EGq6t7Eu1HkML0pyjUV QQtHOiLEfNLMb2KkGQvSPEa2ntc7B0M1YWYi4Sm56/rINmYP4/kFOSnnr9gaSclb6h KVSR1hrsPprfg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 3E5A64EC78; Tue, 1 Dec 2026 08:56:41 +0000 (UTC) From: Jian Hu via B4 Relay Date: Tue, 01 Dec 2026 16:56:14 +0800 Subject: [PATCH RFC RFT v3 01/13] clk: divider: Add CLK_DIVIDER_INVALID_ZERO flag X-Archived-By: MIME-Version: 1.0 Message-Id: <20261201-meson_refactor_n-v3-1-f85a4460fd80@amlogic.com> References: <20261201-meson_refactor_n-v3-0-f85a4460fd80@amlogic.com> In-Reply-To: <20261201-meson_refactor_n-v3-0-f85a4460fd80@amlogic.com> To: Stephen Boyd , Brian Masney , Jerome Brunet , Neil Armstrong , Jerome Brunet , Kevin Hilman , Martin Blumenstingl , Rob Herring , Krzysztof Kozlowski , Conor Dooley Cc: Carlo Caione , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Jian Hu X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796115398; l=2906; i=jian.hu@amlogic.com; s=20260415; h=from:subject:message-id; bh=PMAtGHMcZxOfZFFy/gcoJRVdP8x+dHG4FMw7YGST9FE=; b=G9CBnCYDS65E36h1w4EafnOfWZPLnG+7uKoQcFEV5XM1ujxLTctRJe4R5ZYN+RhHN/sxmYOGQ H+/Ex2xout8A3RyZGyDsYWbXzqbR+z6ZZu0RyhmVAsZ3amh2NbpSJfl X-Developer-Key: i=jian.hu@amlogic.com; a=ed25519; pk=zHUE+rNtH9z+Sb8au1/elWknjFQmy5QDVkBoxleuOIA= X-Endpoint-Received: by B4 Relay for jian.hu@amlogic.com/20260415 with auth_id=735 X-Original-From: Jian Hu X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: jian.hu@amlogic.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-amlogic" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Jian Hu When a divider register reads zero, divider_recalc_rate() currently emits a warning (unless CLK_DIVIDER_ALLOW_ZERO is set) and returns the parent rate. This behaviour assumes a zero divisor acts as a pass-through, which does not apply to all hardware. Some dividers, for example PLL pre-dividers on Amlogic SoCs, come out of reset with a zero value that does not produce a usable clock. Returning the parent rate hides this fault behind an incorrect, plausible value. CLK_DIVIDER_ALLOW_ZERO only suppresses the warning while still reporting the parent rate, so it cannot represent this hardware behaviour. Add CLK_DIVIDER_INVALID_ZERO for dividers where a zero divisor value is invalid. When this flag is set, recalc_rate() returns 0, making the faulty state visible to the clock framework rather than hiding it as a pass-through. Return -EINVAL when the decoded divisor is zero in divider_ro_determine_rate, rather than dividing by zero or reporting a rate which does not exist. Signed-off-by: Jian Hu --- drivers/clk/clk-divider.c | 5 +++++ include/linux/clk-provider.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c index f68216c65d3d..74ae203e5ff8 100644 --- a/drivers/clk/clk-divider.c +++ b/drivers/clk/clk-divider.c @@ -143,6 +143,9 @@ unsigned long divider_recalc_rate(struct clk_hw *hw, unsigned long parent_rate, div = _get_div(table, val, flags, width); if (!div) { + if (flags & CLK_DIVIDER_INVALID_ZERO) + return 0; + WARN(!(flags & CLK_DIVIDER_ALLOW_ZERO), "%s: Zero divisor and CLK_DIVIDER_ALLOW_ZERO not set\n", clk_hw_get_name(hw)); @@ -380,6 +383,8 @@ int divider_ro_determine_rate(struct clk_hw *hw, struct clk_rate_request *req, int div; div = _get_div(table, val, flags, width); + if (!div) + return -EINVAL; /* Even a read-only clock can propagate a rate change */ if (clk_hw_get_flags(hw) & CLK_SET_RATE_PARENT) { diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h index a355d1ee5189..ee964f0c9b0d 100644 --- a/include/linux/clk-provider.h +++ b/include/linux/clk-provider.h @@ -747,6 +747,8 @@ struct clk_div_table { * big endian. * CLK_DIVIDER_EVEN_INTEGERS - clock divisor is 2, 4, 6, 8, 10, etc. * Formula is 2 * (value read from hardware + 1). + * CLK_DIVIDER_INVALID_ZERO - A decoded divisor of zero indicates no usable + * output. recalc_rate() returns 0 instead of the parent rate. */ struct clk_divider { struct clk_hw hw; @@ -770,6 +772,7 @@ struct clk_divider { #define CLK_DIVIDER_MAX_AT_ZERO BIT(6) #define CLK_DIVIDER_BIG_ENDIAN BIT(7) #define CLK_DIVIDER_EVEN_INTEGERS BIT(8) +#define CLK_DIVIDER_INVALID_ZERO BIT(9) extern const struct clk_ops clk_divider_ops; extern const struct clk_ops clk_divider_ro_ops; -- 2.47.1 _______________________________________________ linux-amlogic mailing list linux-amlogic@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-amlogic