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 BD1E9606A327 for ; Mon, 30 Nov 2026 10:51:19 +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=MqkSeq54; dkim=pass (2048-bit key) header.d=baylibre.com header.i=@baylibre.com header.a=rsa-sha256 header.s=google header.b=HqT/yjvF DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: Message-ID:Date:References:In-Reply-To:Subject:Cc:To:From:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=5dnZJ9XWuR4I/QQHBrmwZspDanfZVvJVYIbyIjI3FRE=; b=MqkSeq54g3pglY9St2GgSH9W3M NRqGNUZUAx+m1lhQBpnS3F1QTyvnnn6RaymcyXqSRocK3f4VPPj5D0nEIc8z9BI2ePHRzYo49UlFh u3WDc8Avpl6bWhdlDHDmDs+bgOkWPxSxdnlrUMjZnWjzbz1sliMYYJ61theRqH06XS5MqFFQmYhqL VpVH143eXn8m13da4r0HURDPF9Eux2M5vpI5ZFtFYNHeYxjLzfn9sLvHPe37A4s+2oo8OWdWp96V8 92zVWcJQnhHMUF8NEVbFxb7P5IiKyahBEwDwLqSnzjXpeYlnHXm2TMloEvZGNVn954szCzPvweoCM pAN8Q1lw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXyyR-00000004Ciq-31z5; Mon, 30 Nov 2026 10:51:07 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xXyyO-00000004ChF-2cYj for linux-arm-kernel@lists.infradead.org; Mon, 30 Nov 2026 10:51:06 +0000 Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-c4d427836e9so1338978766b.1 for ; Mon, 30 Nov 2026 02:51:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre.com; s=google; t=1796035863; x=1796640663; darn=lists.infradead.org; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=5dnZJ9XWuR4I/QQHBrmwZspDanfZVvJVYIbyIjI3FRE=; b=HqT/yjvFCx3rp9VTfQEegQicIsByt5lRZ+zoTyYa3XCh2hs2NqqNapqtsy3hPX4Z0M d38MYm2XWcJ5NhUTH6fWKba+Wur9yhDYM2yzpXCGhl/P3W9P4SlwNiOp4nCUh6QxtG0C EhnPlFqKlxqrUJsq2oUWAqR9O7p/4MQZ5DSIRBUwEWqWU/4Gj+9JYTTm00Z2jiVHM6If hn5Jz6QkgmSCQf6Rn+TOFCEBCNXHlKENGXLPat/1a9B0HavH1tAMbx1JojRbjxRyXgSW CUNK+ONhbFsf35L3JLPKCcTEDXhfk0IUbVjJGzOhEDhyv25uPxIuSDXbKD9GKM1gRSgs 6kUA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796035863; x=1796640663; h=content-type:mime-version:message-id:date:references:in-reply-to :subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to:content-type; bh=5dnZJ9XWuR4I/QQHBrmwZspDanfZVvJVYIbyIjI3FRE=; b=U1K7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NPHNLbseHs3ownDXyyK3UiiwCkREmd38IAWFuvUAKQ5GZ5SLO5xgepTyZ kiBoQYsuMhYuGeZ1HP/QDHB7ZDILlKt1MbheBP6cEVupPaUIv75O/6Y5PjZCxwZDe8jRiWP+BNm t3W4gVOigRjYhQaxqXSBHfoiPe3SJ3/+lPD02mc7DwrgSl/e X-Received: by 2002:a17:907:3c92:b0:c50:51e1:c141 with SMTP id a640c23a62f3a-c513a4aea6fmr2718248466b.2.1796035862686; Mon, 30 Nov 2026 02:51:02 -0800 (PST) Received: from localhost (82-67-6-57.subs.proxad.net. [82.67.6.57]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c513b01e242sm1110794166b.82.2026.11.30.02.51.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 02:51:02 -0800 (PST) From: Jerome Brunet To: Jian Hu Cc: Neil Armstrong , Stephen Boyd , Brian Masney , Kevin Hilman , Martin Blumenstingl , Jerome Brunet , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org Subject: Re: [PATCH RFC RFT v2 2/3] clk: divider: add CLK_DIVIDER_INVALID_ZERO flag In-Reply-To: <179390104085.2573818.16461908615505096359.b4-review@b4> References: <20261029-meson_refactor_n-v2-0-ff4ac74e527b@amlogic.com> <20261029-meson_refactor_n-v2-2-ff4ac74e527b@amlogic.com> <179390104085.2573818.16461908615505096359.b4-review@b4> Date: Mon, 30 Nov 2026 11:51:01 +0100 Message-ID: <1jjylusicq.fsf@starbuckisacylon.baylibre.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261130_025104_697654_7CF2C8A3 X-CRM114-Status: GOOD ( 24.15 ) X-Spam-Score: -2.1 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 On jeu. 05 nov. 2026 at 18:50, Jerome Brunet wrote: >> 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. >> >> Signed-off-by: Jian Hu >> --- >> drivers/clk/clk-divider.c | 3 +++ >> include/linux/clk-provider.h | 6 ++++++ >> 2 files changed, 9 insertions(+) >> >> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c >> index f68216c65d3d..6c1523d22477 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; > > While I think CLK_DIVIDER_INVALID_ZERO really makes sense for a writeable divider > only, to gracefully handle a reset value at zero that we would later correct, > we should still handle all paths correctly. This include a RO divider and its > determine rate path. I'll try to send something for this soon. Hi Jian, After looking at it, I think you should keep divider_recalc_rate() as sent here. For the RO divider, return -EINVAL in divider_ro_determine_rate() after _get_div() since it is now a possible expected value. The documentation could read like this: CLK_DIVIDER_INVALID_ZERO - A decoded divisor of zero indicates no usable output. recalc_rate() returns 0 instead of the parent rate. > >> + >> WARN(!(flags & CLK_DIVIDER_ALLOW_ZERO), >> "%s: Zero divisor and CLK_DIVIDER_ALLOW_ZERO not set\n", >> clk_hw_get_name(hw)); >> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h >> index dc8e161f9c2c..fe2dbbba49e3 100644 >> --- a/include/linux/clk-provider.h >> +++ b/include/linux/clk-provider.h >> @@ -744,6 +744,11 @@ 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 zero value read from the register is not a >> + * divide by one / bypass but an invalid setting which does not produce >> + * a usable clock. recalc_rate() returns 0 so that the broken state is >> + * reported to the framework instead of the parent rate, without >> + * triggering the CLK_DIVIDER_ALLOW_ZERO warning. > > > CLK_DIVIDER_INVALID_ZERO - a zero divisor is an invalid setting with no > usable output. recalc_rate() returns 0 instead of the parent rate. > Takes precedence over CLK_DIVIDER_ALLOW_ZERO. > > -- > Jerome > -- Jerome