From patchwork Sun Jul 19 21:13:16 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= X-Patchwork-Id: 2693 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 6BEE11C2CAE for ; Sun, 19 Jul 2026 23:15:09 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-24532-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-24532-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sea.lore.kernel.org (Postfix) with ESMTP id DD87030325A3 for ; Sun, 19 Jul 2026 21:13:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7749C312807; Sun, 19 Jul 2026 21:13:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Ti9SZ8Wx" X-Original-To: linux-sunxi@lists.linux.dev Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (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 73EED3128B8 for ; Sun, 19 Jul 2026 21:13:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784495629; cv=none; b=ZT7mhsDvAmzJAGHnBXQDYZz+3jRUhKPIm2hOmKztPtxluHZov+fDTtE1sOe4PqwqMerpsq4fMWP++2F212JVrihMhRtum7n6FRVyaUpc/YMOU6vUD64MKQEyjUw1k0AC5Zod+rHL2LR2htYbx3koAqudiSrao64P7ji/wZsC2ik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784495629; c=relaxed/simple; bh=FrJNlJDuje1fraZreQFeA7K8hMC+23M50saNKQjdz30=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Tr+ziNTe6MJ57YuE2AZK7VSdNFkPCj3dE8ivUMZhNV5TNhcOhyYNhe9osELZIh5kbJGgIGuYF2b1DYywJOIAnjSr5NAduiM+ARKO3G5Ur3LILJrCz+WOL02h2x+y5TEbUSGaXbnlXlCSOuM1HoafNtezcm4N2R+2bn0dbSlEa9Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Ti9SZ8Wx; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-4954a9e8490so10481975e9.1 for ; Sun, 19 Jul 2026 14:13:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784495626; x=1785100426; darn=lists.linux.dev; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=v7CaPFCYxjAp666DnXxZML+uPeZM+JIvYLGcdU4j6/g=; b=Ti9SZ8Wx6St0sPL0ryGNte7BDONiWLUP68D0Ew9nSs3WsIxt7+uIP5KlEQG4zKr8SL tWlTtnA5eKll0reTxWEf8XCqrGC6wyIqqHxYNDq/phgiGVqTJKVGuAJmK3JJFVq4SHQY 4a8UpBSRKyD3qWkxzEwsl4F63gV6K7Vxicu+vqqbXBXSgin4rtONgNBQEBDZ0QI6oxq2 0NcpDVEqB7OHQyacIq++fFlb42aQcMxhTzsNng54H7fLrG6HsnHtr1A/121MRjb7pwbo cRIopQhu2s4Y3SwrDbKS2dekmfNmbf87QMrh2cFUKMhq6g0geZ1u+0Br6+7YQByz/tK3 ahJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784495626; x=1785100426; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=v7CaPFCYxjAp666DnXxZML+uPeZM+JIvYLGcdU4j6/g=; b=Jovb3M3UD+F0OX8a+6I+gSCss9fjtra9LsKpXla0yk6GSz+497lmqXEAtvN+FAuFHz pr1YrF1ocrzloJmEIMkpSSFPfR90oIEgl7Zez7P6gVlrji6mpi56iqNMUxb4BNVR8bA0 bxiTjZHFEBdrdBU6iQu0RbB7+7cVqePJTgBnnR8Uv3ZDj7Jcd+HBYXNLR8OtkLUhggsN Yzp3lTR/T/YVElvr9iw3yt4wijFoxBjHzBzO9cfr4mDok1OQy6oTxv+uxRcrB6p/xHu3 wK9fS+4BZidxJ4QdjnqyknolngFI85q8Tp15x5gJXT8MnO4ZnNF0VQcOWWiNw/PJlanv 7G/g== X-Forwarded-Encrypted: i=1; AHgh+Rr9qWZHrXtDyt67vHRyoLRZzxRR/uYq7VhqbiMgyekzAzPv4nnbC6psmvzr6gyfyHb+0X2L8sxv3m35iQ==@lists.linux.dev X-Gm-Message-State: AOJu0YxwXn0AA0nsrV9klCi5OwEMYINYp6pBPr7dUYk6agguLjYIKihA oLEOQxoh6OtocZN/rAxmwk1rxjBSm1cmPy5vEJXVXenfqpCH/xSAPG1r X-Gm-Gg: AfdE7ckmKBnNiexgZAMhIUg+WK3AUrHR3/au1i1hHYRw8d9R3ybE/gKbMgZq9pkBt+5 29KIDB12zJ1OWPrtl2z+0n2jbBNs0Wmv5Px146Hcel0NQkrIIIyjeLTPKX3vvvMsLf0AIJQlmmC 3J0kxibDbGAsszZBbpioD+sguAsdC9PnVEVat5XFIPyApmxLGyx2LPMEaBTEbdtYCv9DTXIjsah waXGsWxVMYaNjmb6vnn0SvyHLuCuntc5d3Oxxx2LG4/pWbjknsyM/8DR2euZs86ndJsv+Vwtnlo CSUydi5YWpFDBFqpAtY8qS1Z78Y23DTZWpzMFj+KwfOhpZot/1l2X/JsxADXLIdY9bQef8c5fgy 1o1UFy+BFm7WsB7fKTfTd3ZeTczsHFs3YrKWDAthXKLPlS7Wo8Gmyz3D7jJVuq5wA/45I++iUHo RdQGTWAAezZ/jS9Q5zqHdgjPMT0RDGlP3N84CwFlMH3eZ2h9o= X-Received: by 2002:a05:600c:1906:b0:495:3bc6:d381 with SMTP id 5b1f17b1804b1-4954affd764mr114277385e9.2.1784495625577; Sun, 19 Jul 2026 14:13:45 -0700 (PDT) Received: from localhost.localdomain ([2a0d:3344:2841:7708:a101:2b8a:f76:a00f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49549a3e2a9sm224108815e9.4.2026.07.19.14.13.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jul 2026 14:13:44 -0700 (PDT) From: =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= To: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Brian Masney , Andre Przywara , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-clk@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= Subject: [PATCH v1 1/4] clk: sunxi-ng: add cycle-masking divider (maskdiv) clock type Date: Sun, 19 Jul 2026 23:13:16 +0200 Message-ID: <20260719211319.982285-2-juanmanuellopezcarrillo@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260719211319.982285-1-juanmanuellopezcarrillo@gmail.com> References: <20260719211319.982285-1-juanmanuellopezcarrillo@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= Some mod clocks do not divide their parent with a linear M+1 divider: the M factor masks (swallows) M pulses out of every 2^width parent cycles, so the average output rate is rate = parent * (2^width - M) / 2^width and the surviving pulses keep the parent period. The A523/T527 GPU clock (GPU_CLK_REG, 0x670) is such a divider: "FACTOR_M: mask M cycles at 16 cycles", GPU_CLK = Clock Source * ((16-M)/16) (T527 user manual v0.92, section 2.7.6.58). Modelling these registers with the linear ccu_div type programs a faster clock than requested for every M > 0 (e.g. M=1 on a 800 MHz parent yields 750 MHz, not 400 MHz). Add a small ccu type implementing the masking semantics. Because the masked output is not an even pulse train, determine_rate prefers, among the parents that reach the requested rate, the one needing the least masking. set_rate_and_parent follows the same ordering rule as clk_composite_set_rate_and_parent() so no intermediate configuration overshoots both the old and the new rate. Signed-off-by: Juan Manuel López Carrillo --- drivers/clk/sunxi-ng/Makefile | 1 + drivers/clk/sunxi-ng/ccu_maskdiv.c | 199 +++++++++++++++++++++++++++++ drivers/clk/sunxi-ng/ccu_maskdiv.h | 71 ++++++++++ 3 files changed, 271 insertions(+) create mode 100644 drivers/clk/sunxi-ng/ccu_maskdiv.c create mode 100644 drivers/clk/sunxi-ng/ccu_maskdiv.h diff --git a/drivers/clk/sunxi-ng/Makefile b/drivers/clk/sunxi-ng/Makefile index a1c4087d7..26313083c 100644 --- a/drivers/clk/sunxi-ng/Makefile +++ b/drivers/clk/sunxi-ng/Makefile @@ -10,6 +10,7 @@ sunxi-ccu-y += ccu_reset.o # Base clock types sunxi-ccu-y += ccu_div.o sunxi-ccu-y += ccu_frac.o +sunxi-ccu-y += ccu_maskdiv.o sunxi-ccu-y += ccu_gate.o sunxi-ccu-y += ccu_mux.o sunxi-ccu-y += ccu_mult.o diff --git a/drivers/clk/sunxi-ng/ccu_maskdiv.c b/drivers/clk/sunxi-ng/ccu_maskdiv.c new file mode 100644 index 000000000..2d3cccf08 --- /dev/null +++ b/drivers/clk/sunxi-ng/ccu_maskdiv.c @@ -0,0 +1,199 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2026 Juan Manuel López Carrillo + * + * Cycle-masking divider: the M factor masks M pulses out of every + * 2^width parent cycles instead of dividing the parent rate, so + * + * rate = parent * (2^width - M) / 2^width + * + * The masked output is not an even pulse train: the surviving pulses + * keep the parent period. Rate selection therefore prefers, among the + * parents that reach the requested rate, the one needing the least + * masking. + */ + +#include +#include +#include + +#include "ccu_gate.h" +#include "ccu_maskdiv.h" + +static unsigned long ccu_maskdiv_calc_rate(unsigned long parent_rate, + unsigned int m, unsigned int width) +{ + unsigned int n = 1 << width; + + return div_u64((u64)parent_rate * (n - m), n); +} + +/* + * Smallest M (least masking) whose output does not exceed the requested + * rate; masking everything (M == 2^width) is never returned. + */ +static unsigned int ccu_maskdiv_find_m(unsigned long parent_rate, + unsigned long rate, unsigned int width) +{ + unsigned int n = 1 << width; + u64 kept; + + if (!parent_rate || rate >= parent_rate) + return 0; + + kept = div64_ul((u64)rate * n, parent_rate); + if (!kept) + kept = 1; + + return n - (unsigned int)kept; +} + +static void ccu_maskdiv_disable(struct clk_hw *hw) +{ + struct ccu_maskdiv *cmd = hw_to_ccu_maskdiv(hw); + + return ccu_gate_helper_disable(&cmd->common, cmd->enable); +} + +static int ccu_maskdiv_enable(struct clk_hw *hw) +{ + struct ccu_maskdiv *cmd = hw_to_ccu_maskdiv(hw); + + return ccu_gate_helper_enable(&cmd->common, cmd->enable); +} + +static int ccu_maskdiv_is_enabled(struct clk_hw *hw) +{ + struct ccu_maskdiv *cmd = hw_to_ccu_maskdiv(hw); + + return ccu_gate_helper_is_enabled(&cmd->common, cmd->enable); +} + +static unsigned long ccu_maskdiv_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + struct ccu_maskdiv *cmd = hw_to_ccu_maskdiv(hw); + unsigned int m; + u32 reg; + + reg = readl(cmd->common.base + cmd->common.reg); + m = (reg >> cmd->shift) & ((1 << cmd->width) - 1); + + return ccu_maskdiv_calc_rate(parent_rate, m, cmd->width); +} + +static int ccu_maskdiv_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) +{ + struct ccu_maskdiv *cmd = hw_to_ccu_maskdiv(hw); + unsigned long best_rate = 0, best_parent_rate = 0; + struct clk_hw *best_parent = NULL; + unsigned int best_m = UINT_MAX; + unsigned int i; + + for (i = 0; i < clk_hw_get_num_parents(hw); i++) { + struct clk_hw *parent = clk_hw_get_parent_by_index(hw, i); + unsigned long parent_rate, new_rate; + unsigned int m; + + if (!parent) + continue; + + parent_rate = clk_hw_get_rate(parent); + m = ccu_maskdiv_find_m(parent_rate, req->rate, cmd->width); + new_rate = ccu_maskdiv_calc_rate(parent_rate, m, cmd->width); + + if (new_rate > req->rate) + continue; + + /* Closest rate first; on ties, the least masking */ + if (new_rate > best_rate || + (new_rate == best_rate && m < best_m)) { + best_rate = new_rate; + best_parent_rate = parent_rate; + best_parent = parent; + best_m = m; + } + } + + if (!best_parent) + return -EINVAL; + + req->best_parent_hw = best_parent; + req->best_parent_rate = best_parent_rate; + req->rate = best_rate; + + return 0; +} + +static int ccu_maskdiv_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + struct ccu_maskdiv *cmd = hw_to_ccu_maskdiv(hw); + unsigned int m; + unsigned long flags; + u32 reg; + + m = ccu_maskdiv_find_m(parent_rate, rate, cmd->width); + + spin_lock_irqsave(cmd->common.lock, flags); + + reg = readl(cmd->common.base + cmd->common.reg); + reg &= ~GENMASK(cmd->shift + cmd->width - 1, cmd->shift); + writel(reg | (m << cmd->shift), cmd->common.base + cmd->common.reg); + + spin_unlock_irqrestore(cmd->common.lock, flags); + + return 0; +} + +static u8 ccu_maskdiv_get_parent(struct clk_hw *hw) +{ + struct ccu_maskdiv *cmd = hw_to_ccu_maskdiv(hw); + + return ccu_mux_helper_get_parent(&cmd->common, &cmd->mux); +} + +static int ccu_maskdiv_set_parent(struct clk_hw *hw, u8 index) +{ + struct ccu_maskdiv *cmd = hw_to_ccu_maskdiv(hw); + + return ccu_mux_helper_set_parent(&cmd->common, &cmd->mux, index); +} + +static int ccu_maskdiv_set_rate_and_parent(struct clk_hw *hw, + unsigned long rate, + unsigned long parent_rate, u8 index) +{ + /* + * Same ordering rule as clk_composite_set_rate_and_parent(): if + * switching the mux with the current M would overshoot the + * requested rate, program the divider first, so the + * intermediate rate never exceeds both the old and the new + * rate. + */ + if (ccu_maskdiv_recalc_rate(hw, parent_rate) > rate) { + ccu_maskdiv_set_rate(hw, rate, parent_rate); + ccu_maskdiv_set_parent(hw, index); + } else { + ccu_maskdiv_set_parent(hw, index); + ccu_maskdiv_set_rate(hw, rate, parent_rate); + } + + return 0; +} + +const struct clk_ops ccu_maskdiv_ops = { + .disable = ccu_maskdiv_disable, + .enable = ccu_maskdiv_enable, + .is_enabled = ccu_maskdiv_is_enabled, + + .get_parent = ccu_maskdiv_get_parent, + .set_parent = ccu_maskdiv_set_parent, + + .determine_rate = ccu_maskdiv_determine_rate, + .recalc_rate = ccu_maskdiv_recalc_rate, + .set_rate = ccu_maskdiv_set_rate, + .set_rate_and_parent = ccu_maskdiv_set_rate_and_parent, +}; +EXPORT_SYMBOL_NS_GPL(ccu_maskdiv_ops, "SUNXI_CCU"); diff --git a/drivers/clk/sunxi-ng/ccu_maskdiv.h b/drivers/clk/sunxi-ng/ccu_maskdiv.h new file mode 100644 index 000000000..3cbfce064 --- /dev/null +++ b/drivers/clk/sunxi-ng/ccu_maskdiv.h @@ -0,0 +1,71 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2026 Juan Manuel López Carrillo + */ + +#ifndef _CCU_MASKDIV_H_ +#define _CCU_MASKDIV_H_ + +#include + +#include "ccu_common.h" +#include "ccu_mux.h" + +/* + * struct ccu_maskdiv - cycle-masking ("fractional") divider + * + * This divider does not divide the parent clock: it masks (swallows) M + * pulses out of every 2^width parent cycles, so the average output rate + * is + * + * rate = parent * (2^width - M) / 2^width + * + * with the remaining pulses keeping the parent period. The A523/T527 + * GPU clock (GPU_CLK_REG, 0x670) is such a divider: "FACTOR_M: mask M + * cycles at 16 cycles", GPU_CLK = Clock Source * ((16-M)/16) (T527 user + * manual v0.92, section 2.7.6.58). + * + * @shift: shift of the M field in the register + * @width: width of the M field; the mask window is 2^width cycles + */ +struct ccu_maskdiv { + u32 enable; + + u8 shift; + u8 width; + + struct ccu_mux_internal mux; + struct ccu_common common; +}; + +#define SUNXI_CCU_MASKDIV_HW_WITH_MUX_TABLE_GATE(_struct, _name, \ + _parents, _table, \ + _reg, \ + _mshift, _mwidth, \ + _muxshift, _muxwidth, \ + _gate, _flags) \ + struct ccu_maskdiv _struct = { \ + .enable = _gate, \ + .shift = _mshift, \ + .width = _mwidth, \ + .mux = _SUNXI_CCU_MUX_TABLE(_muxshift, _muxwidth, \ + _table), \ + .common = { \ + .reg = _reg, \ + .hw.init = CLK_HW_INIT_PARENTS_HW(_name, \ + _parents, \ + &ccu_maskdiv_ops, \ + _flags), \ + }, \ + } + +static inline struct ccu_maskdiv *hw_to_ccu_maskdiv(struct clk_hw *hw) +{ + struct ccu_common *common = hw_to_ccu_common(hw); + + return container_of(common, struct ccu_maskdiv, common); +} + +extern const struct clk_ops ccu_maskdiv_ops; + +#endif /* _CCU_MASKDIV_H_ */ From patchwork Sun Jul 19 21:13:17 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= X-Patchwork-Id: 2692 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sto.lore.kernel.org (sto.lore.kernel.org [172.232.135.74]) by mxe881.netcup.net (Postfix) with ESMTPS id E4C2E1C2CAE for ; Sun, 19 Jul 2026 23:13:57 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.232.135.74) smtp.mailfrom=linux-sunxi+bounces-24533-noreply=patchwork.local@lists.linux.dev smtp.helo=sto.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.232.135.74 as permitted sender) client-ip=172.232.135.74; envelope-from=linux-sunxi+bounces-24533-noreply=patchwork.local@lists.linux.dev; helo=sto.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sto.lore.kernel.org (Postfix) with ESMTP id 28C363008C05 for ; Sun, 19 Jul 2026 21:13:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8B92A30F543; Sun, 19 Jul 2026 21:13:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="hSjCslbi" X-Original-To: linux-sunxi@lists.linux.dev Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) (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 5E4F030F7E8 for ; Sun, 19 Jul 2026 21:13:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784495631; cv=none; b=o2zvmVjfpWSx5uqnCuSzsvxeLsctVkKMzX7uqX1dSO4ZMd8r2PExGpAeOtf49CuyVkMKKtNBZiW62ux99bEbQZusY1f/p2fzz4/DxHFzScl98KWRmYq55YaiBHUwNJrKm0HprVt7LIa/azNcATRkGlNH5qU1H8CyMibfQsDVbls= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784495631; c=relaxed/simple; bh=OIQ9wV1fytaPWVFvAnMGv/HqNSfH3VqUaIN7P0RyrC8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F52QS2iot9bTifCy0g3yn/VkT+jC5tldRKKMLVsOuAmkDmpghM2BlJ9lm5rnNgDdC00xR1P3D2JdXnXsGlSqH3DvusrAshKWLUZLrr4RgL3TC85q02YacadtT/RenWsaHf/75AF6i9yjNav2YJJ75QrfIY7GBUxea9C1bbCl2lI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=hSjCslbi; arc=none smtp.client-ip=209.85.128.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-4955adb04e8so3847275e9.2 for ; Sun, 19 Jul 2026 14:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784495628; x=1785100428; darn=lists.linux.dev; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=P704jdG4dY1gYMag6CkafUUs1KoIwLh9colggYiL2Zk=; b=hSjCslbiabGzXl8h5J323K1tKYEZgsWCsawsF8W/8kkDnGke2hM3Rw5qC8tr92XO2F 7sCqnWWK0/93qz2jqiQQgcG9x+U495HKeRVTZzHyIdFoz+TP0DrP8r9B2Lx0KRNopLuI TQpHSHx6nkrSbPdhfuzkg5fRtnCbxiL/vzpL1mC05bNrAit41k3ZXCyOM7v2zL04vaQM p0Rr824FjFaX9DsIPYGtkhhhUyjgTLiJft7rDO6AKR+YEwGQbuH51kVo0fxNGAGOTS7d 45sQrhe7iY7hC1pUq886CzdcoiEXorew5YzGl74I2eLYMQlvHt8J07SNYDWxVnTmtbvb iqwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784495628; x=1785100428; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=P704jdG4dY1gYMag6CkafUUs1KoIwLh9colggYiL2Zk=; b=bJEu0E09rGgqRzbbj0UIqazXInguQn99Nq5IU+CpioWzX0ageO/WBG2tqPRlAY4zFi 1jl1nFN9g3V0e8Jv2/cpQDuNoOvL8DmMCgawTNZXqoqzzAIlmB42hf5MtIZNAEhGJ7u7 vx0ld8DdLMmsWqO240iik6ZPKRG0w8zmnlFCo44xggT9cVTqc8xFWuVjFiH2DkLuMFnZ J8vOlElXm2orwBxunOT1G8gol3epUN9HCxVtdRz5wBPYJWYeJXSKkKg0sWuSpP8mdkrQ uodtGWnNp91dU5MYAIaxGYrnwcIgi43jpoDIM+KnaD4SO1NFX74gKuyhqqa8sHWH+lcy yaFQ== X-Forwarded-Encrypted: i=1; AHgh+Rrd8AIEaKOJWyaeDMoJQlvZKk+MV0/rEQzYqJN01tidqV78xKgwToGFickyhw/3XBSkydeEuTTUUe+ObQ==@lists.linux.dev X-Gm-Message-State: AOJu0YzNEeZ30PXeXYdsIPsxJGuNEEc8XgLyJSOA2nAvJEztnwnExvtR 4R3pkKSvuxyOERLc2vQ/GuIkFnnQADuajzl8PhsFkG3BQ6KCAd4VtfkQ X-Gm-Gg: AfdE7clqyvBGccodoH9E2wbIL/dIn1MBe4cIpW02l38I9Cc+4n6gs+/F4hWBQRHYRV4 ikoZrFsT8bmnzVhLA4ez+ivtKHiSNwkgai1dSW74fm8xP4AdetbI2HW4QqGaQ/fHF8mQsAnYL+l ocK8MpUiDgAr5ZRT+OmBqKF6MctpZ0cm+PRHMMV7lK+O3g0qj8g9q51JhlhM7+A2GIXBqT85hyU XONajAN9ROdt8g67qd8oGl/aMaaT5Xb/SZX/TXIpmP+lKSRq6R2hD5QgicKScWMPbUaxWUHJmC7 xHUoeQviuGcdRd/8rDy0mn+5YB7bTdkHRmdko87cg/NKIRffQg6oJYEvQW4iEtnDBuxRdyj4N5P k/KVYE8KXLRXGd0g/+j9XgfFv84phTt321bqWvIDfoSUiOPM8JLl4PoeX5VsvRU9Twnu792vS7K H0fxGS478356k0Smjf+K5hWIUUDrmZ3gMBBRgcrBORv81JZag= X-Received: by 2002:a05:600c:3b8e:b0:495:4bf3:2150 with SMTP id 5b1f17b1804b1-4954bf3216amr129364555e9.8.1784495627377; Sun, 19 Jul 2026 14:13:47 -0700 (PDT) Received: from localhost.localdomain ([2a0d:3344:2841:7708:a101:2b8a:f76:a00f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49549a3e2a9sm224108815e9.4.2026.07.19.14.13.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jul 2026 14:13:46 -0700 (PDT) From: =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= To: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Brian Masney , Andre Przywara , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-clk@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= Subject: [PATCH v1 2/4] clk: sunxi-ng: sun55i-a523: GPU clock divider is fractional, not linear Date: Sun, 19 Jul 2026 23:13:17 +0200 Message-ID: <20260719211319.982285-3-juanmanuellopezcarrillo@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260719211319.982285-1-juanmanuellopezcarrillo@gmail.com> References: <20260719211319.982285-1-juanmanuellopezcarrillo@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= The GPU mod clock (0x670) was modelled as a linear M+1 divider, but the M factor of this register is a cycle-masking divider: GPU_CLK = Clock Source * ((16-M)/16) (T527 user manual v0.92, section 2.7.6.58). With the linear model every OPP that needed M > 0 silently ran the GPU faster than requested. Measured on an Orange Pi 4A (T527) with the Mali cycle counter against the programmed register: OPP request programmed real rate 150 MHz 600M, M=3 487.5 MHz 200 MHz 800M, M=3 650 MHz 300 MHz 600M, M=1 562.5 MHz 400 MHz 800M, M=1 750 MHz 600 MHz 600M, M=0 600 MHz i.e. the "400 MHz" OPP ran the GPU at 750 MHz, 25% above the vendor ceiling of 600 MHz, at the low-OPP voltage. Thermal throttling to "400 MHz" actually overclocked the GPU. Switch the clock to the maskdiv type. With least-masking preference the vendor OPP set now resolves to 600/400/300/200 MHz taken undivided from their periph outputs and 150 MHz = pll-periph0-200M * 12/16, all verified exact on hardware with the same cycle-counter method. Drop pll-periph0-800M from the selectable parents (the mux table skips hardware index 1): the vendor BSP removed it from its parent list with the comment "If GPU use pll-peri0-800m, gpu will occur job fault", and with the masking semantics every vendor OPP matches exactly from the 800M parent first, so it would otherwise always be chosen. Also drop CLK_SET_RATE_PARENT: every OPP is reachable from the fixed pll-periph0 outputs, and pll-gpu must never be reprogrammed through this mux. Once the GPU moves off pll-gpu the PLL is no longer prepared, so it loses the rate protection of CLK_SET_RATE_GATE; a propagated rate request would then reprogram the PLL while its gate is off (the lock bit never asserts, 70 ms poll timeout per transition) and switch the running GPU onto it before it locks. Fixes: 6702d17f54a8 ("clk: sunxi-ng: a523: add video mod clocks") Signed-off-by: Juan Manuel López Carrillo --- drivers/clk/sunxi-ng/ccu-sun55i-a523.c | 32 +++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/drivers/clk/sunxi-ng/ccu-sun55i-a523.c b/drivers/clk/sunxi-ng/ccu-sun55i-a523.c index 20dad06b3..979e53e63 100644 --- a/drivers/clk/sunxi-ng/ccu-sun55i-a523.c +++ b/drivers/clk/sunxi-ng/ccu-sun55i-a523.c @@ -21,6 +21,7 @@ #include "ccu_div.h" #include "ccu_gate.h" +#include "ccu_maskdiv.h" #include "ccu_mp.h" #include "ccu_mult.h" #include "ccu_nk.h" @@ -442,18 +443,37 @@ static SUNXI_CCU_GATE_HWS(bus_g2d_clk, "bus-g2d", ahb_hws, 0x63c, BIT(0), 0); static const struct clk_hw *gpu_parents[] = { &pll_gpu_clk.common.hw, - &pll_periph0_800M_clk.common.hw, &pll_periph0_600M_clk.hw, &pll_periph0_400M_clk.hw, &pll_periph0_300M_clk.hw, &pll_periph0_200M_clk.hw, }; -static SUNXI_CCU_M_HW_WITH_MUX_GATE(gpu_clk, "gpu", gpu_parents, 0x670, - 0, 4, /* M */ - 24, 3, /* mux */ - BIT(31), /* gate */ - CLK_SET_RATE_PARENT); +/* + * Mux index 1 (pll-periph0-800M) is skipped: the vendor BSP removed it + * from the parent list ("If GPU use pll-peri0-800m, gpu will occur job + * fault"), and with the masking divider every OPP would match exactly + * from it first. + */ +static const u8 gpu_mux_table[] = { 0, 2, 3, 4, 5 }; + +/* + * The M factor is a cycle-masking (fractional) divider, not a linear + * one: rate = source * (16 - M) / 16 (T527 manual, GPU_CLK_REG). + * + * No CLK_SET_RATE_PARENT: every GPU OPP is reachable from the fixed + * pll-periph0 outputs, and pll-gpu must never be reprogrammed through this mux. + * Once the GPU moves off pll-gpu the PLL is no longer prepared, so it loses + * the rate protection of CLK_SET_RATE_GATE; a propagated rate request would + * then reprogram the PLL while its gate is off (the lock bit never asserts, + * 70 ms timeout) and switch the running GPU onto it before it locks. + */ +static SUNXI_CCU_MASKDIV_HW_WITH_MUX_TABLE_GATE(gpu_clk, "gpu", gpu_parents, + gpu_mux_table, 0x670, + 0, 4, /* M */ + 24, 3, /* mux */ + BIT(31), /* gate */ + 0); static SUNXI_CCU_GATE_HWS(bus_gpu_clk, "bus-gpu", ahb_hws, 0x67c, BIT(0), 0); From patchwork Sun Jul 19 21:13:18 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= X-Patchwork-Id: 2694 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 7FCE41C2CAE for ; Sun, 19 Jul 2026 23:15:55 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-24534-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-24534-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sea.lore.kernel.org (Postfix) with ESMTP id 2B3B3304B98E for ; Sun, 19 Jul 2026 21:13:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CAACD30FF2A; Sun, 19 Jul 2026 21:13:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b4iRxZ9E" X-Original-To: linux-sunxi@lists.linux.dev Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 1C18231352A for ; Sun, 19 Jul 2026 21:13:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784495632; cv=none; b=NGs223qxsj+IrnYZ5MyY+549u26p30VDMsuHJ1Dq8oI4CuGhuBrqL+2JET5+BX4CnuZyjBnsZibxyd59Mn4V6puF8a9PpNtn3VbtqxAyz8A93kNixNNG7H+MScmaQJZiUjPjw7dzyoN9WF49gy9pZh0NvY1EMiLqQBxhwiNI2d8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784495632; c=relaxed/simple; bh=DDsOXp+Z72kK9qdiLJoanRdwCGRm/6FA5U02/PGt8IU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aham9LjW8AeADIlNOgTyC/aCV6pFBrYpHoYXEa/wOOoomeINwfph1v8qAFpkufLjaiBRHsfDUTMsWG+vYMoGqgS3MPD3G5udpAw3eg/JLkIw0/j2X+ZZWybkNWEwnOhYDRAPjZ3sT6AGBQjaZGiBw3ZInFWGiRDpAxbI1ogp8iw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b4iRxZ9E; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-49554ebb87dso11178605e9.3 for ; Sun, 19 Jul 2026 14:13:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784495629; x=1785100429; darn=lists.linux.dev; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=vxznu+hS8HH5ynomOmnxMZ5VSR6lMdMjMbTUGrneUgI=; b=b4iRxZ9EvJD7YbbPLZacUODZCcRKuVVNZRCdbiAXh19zCY4Zla3l0nx8PkbeVtvR2p FoGb1SuEdfCKHUUccxN5l4qZQM/pBIdlCOD6moSXvvhbM+sPekDiEICdsmLm09qJFhk3 zuOQiNyn/7AUBNudU1Rwc2kD0EZmjYI6/Or/yLkjxXQymtZIOmjcx5oV6k2vi/APZDnd s//oFEl4tv2T82H/CoKIm6IIrXCk6LyWXCtFDlekbShrc6rNwvpT/OO+evtTKezX5MW+ bZN9zNL7vfTxY/TBRBPrFP1UlaJfPHwUxY6nvk9Ri/pmEJT7x0GVLESV7GVcR1G+TX2f Y9Dw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784495629; x=1785100429; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=vxznu+hS8HH5ynomOmnxMZ5VSR6lMdMjMbTUGrneUgI=; b=IHtE22cX44yru535p1rIQAt/px02Ag6XgkQG3cNfXUfKCs/VGkXkRb7kpJMiUGgHq8 Nw1xrkj/c+QRFAcbRMDtE5KotJu7dDQKYXrVwnwASmU6heSF9AvO5JZeJNtMR455mg70 lmkmdirS31DQduMehbo5FFGEGSPI5kXZp+SQAUu6DyKwCbogOHHWyqPTbdw3aPlQ/r+5 KsjUuaqcwomGmQjEawLtEdHwXOSytG2Y0gUysEacHpg/OzOOtyEevFMt/DQ3ZhZL2YUt NpfqJIwYwtJNve52F9XmP8XWRNNMY/Z7Yde64fz2y4d8arsAsf5lIGYMSSuauQ74bfye Salg== X-Forwarded-Encrypted: i=1; AHgh+Rr4I9A6YwWd02fWOPVbO5f87DFwDobBy4XG/uxk0d5OCW4nY9TsRPomXHEGWobL64rfkgm5gxXy4Zae0w==@lists.linux.dev X-Gm-Message-State: AOJu0YxFqSUmM0/ZZpUQC4GDTRv6CdnOx/4GxIwpxaHlobHvRYeSLVme os6IoXWB6Blke1+UjPvk3GpKMcIP8cJ/gyLJLsiEdLsIYCQAH77fLxK8 X-Gm-Gg: AfdE7ckNB6zU5bpNugiMUrRbbvwM7y2OUiYKeejK0H1QhCmAm10gyJEufDeUEqon68c cKhH3ZZzVIjiJa2cN3/RqZYAnIZs/0Ck+Dp74kvbzvvHfBpskKj8YkfE37rCKogX1eRqC08mWoQ LBvDYp/EfSBJg2cScMEEH+9DlNk3msVo2afSUvA5a7VIyMBBsdHYb9KF25mycaUHjG7X+kQ8qCK OyfpwoGtq26yoBjsgLljFVCZOXk5iJgBdwkkprTIF2fBBrjh8UL6Z44T2IgB9ClgEpoleCF4N0M TybIFvW52R4UvyaQf3BZvkI7FpwFhuVvnuihaEaoZyIDTeMCdaG9VyxsNIJlcH5l3YTG/CDsTjU C+rKwFwS8LfGipoq8BL2qDNwnYmA77v45VRMAFKs8yu5G5a8VDp22PWcBw9zGFVFaYygUyHXxi1 8hv65jJ5zwNpYtoNbKTiJxDCeEU4Qx+mzii50k X-Received: by 2002:a05:600c:4703:b0:495:4e89:3f30 with SMTP id 5b1f17b1804b1-4954e893f8cmr104567935e9.15.1784495629064; Sun, 19 Jul 2026 14:13:49 -0700 (PDT) Received: from localhost.localdomain ([2a0d:3344:2841:7708:a101:2b8a:f76:a00f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49549a3e2a9sm224108815e9.4.2026.07.19.14.13.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jul 2026 14:13:48 -0700 (PDT) From: =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= To: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Brian Masney , Andre Przywara , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-clk@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= Subject: [PATCH v1 3/4] clk: sunxi-ng: sun55i-a523: reparent GPU while pll-gpu changes rate Date: Sun, 19 Jul 2026 23:13:18 +0200 Message-ID: <20260719211319.982285-4-juanmanuellopezcarrillo@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260719211319.982285-1-juanmanuellopezcarrillo@gmail.com> References: <20260719211319.982285-1-juanmanuellopezcarrillo@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-0.16 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.15)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[16]; FREEMAIL_FROM(0.00)[gmail.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:rdns,sea.lore.kernel.org:helo]; TO_DN_SOME(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FORGED_SENDER_MAILLIST(0.00)[]; FREEMAIL_CC(0.00)[redhat.com,arm.com,kernel.org,vger.kernel.org,lists.linux.dev,lists.infradead.org,gmail.com]; FREEMAIL_TO(0.00)[baylibre.com,kernel.org,gmail.com,sholland.org]; TAGGED_RCPT(0.00)[dt]; FROM_HAS_DN(0.00)[]; RCVD_TLS_LAST(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc-20240116:i=1]; MIME_TRACE(0.00)[0:+]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; PRECEDENCE_BULK(0.00)[]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FROM_NEQ_ENVFROM(0.00)[juanmanuellopezcarrillo@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-24534-noreply=patchwork.local]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10]; RCVD_COUNT_FIVE(0.00)[6]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 7FCE41C2CAE X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= Register the existing sunxi-ng mux notifier on pll-gpu so the GPU mod clock is parked on the fixed pll-periph0-600M output while the PLL is being reprogrammed, and switched back once it has locked, following the cpux precedent of other sunxi SoCs. The mux switch is glitch-free per the T527 manual (GPU_CLK_REG, "The clock selection supports glitch-free switch"). Nothing retunes pll-gpu at runtime today (the mux does not propagate rate requests and all standard OPPs resolve to pll-periph0 outputs), but the higher speed-bin operating points (648-792 MHz) will need pll-gpu as a live parent, and any direct clk_set_rate() on the PLL is now safe. Signed-off-by: Juan Manuel López Carrillo --- drivers/clk/sunxi-ng/ccu-sun55i-a523.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/clk/sunxi-ng/ccu-sun55i-a523.c b/drivers/clk/sunxi-ng/ccu-sun55i-a523.c index 979e53e63..4341eb66c 100644 --- a/drivers/clk/sunxi-ng/ccu-sun55i-a523.c +++ b/drivers/clk/sunxi-ng/ccu-sun55i-a523.c @@ -1667,6 +1667,17 @@ static const u32 pll_regs[] = { SUN55I_A523_PLL_NPU_REG, }; +/* + * Park the GPU on the fixed pll-periph0-600M output while pll-gpu + * changes rate; the mux switch is glitch-free (T527 manual, GPU_CLK_REG). + */ +static struct ccu_mux_nb sun55i_a523_gpu_nb = { + .common = &gpu_clk.common, + .cm = &gpu_clk.mux, + .delay_us = 1, + .bypass_index = 1, /* pll-periph0-600M */ +}; + static int sun55i_a523_ccu_probe(struct platform_device *pdev) { void __iomem *reg; @@ -1698,6 +1709,10 @@ static int sun55i_a523_ccu_probe(struct platform_device *pdev) if (ret) return ret; + /* Reparent the GPU during pll-gpu rate changes */ + ccu_mux_notifier_register(pll_gpu_clk.common.hw.clk, + &sun55i_a523_gpu_nb); + return 0; } From patchwork Sun Jul 19 21:13:19 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= X-Patchwork-Id: 2695 Return-Path: X-Original-To: noreply@patchwork.local Delivered-To: noreply@patchwork.local Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10]) by mxe881.netcup.net (Postfix) with ESMTPS id 621B21C2CAE for ; Sun, 19 Jul 2026 23:16:25 +0200 (CEST) Authentication-Results: mxe881; dkim=pass header.d=gmail.com; spf=pass (sender IP is 172.234.253.10) smtp.mailfrom=linux-sunxi+bounces-24535-noreply=patchwork.local@lists.linux.dev smtp.helo=sea.lore.kernel.org Received-SPF: pass (mxe881: domain of lists.linux.dev designates 172.234.253.10 as permitted sender) client-ip=172.234.253.10; envelope-from=linux-sunxi+bounces-24535-noreply=patchwork.local@lists.linux.dev; helo=sea.lore.kernel.org; Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.90.174.1]) by sea.lore.kernel.org (Postfix) with ESMTP id 48CE430530D2 for ; Sun, 19 Jul 2026 21:13:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 59A3B3128D9; Sun, 19 Jul 2026 21:13:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cLTgGJFm" X-Original-To: linux-sunxi@lists.linux.dev Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 6A25C311946 for ; Sun, 19 Jul 2026 21:13:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784495635; cv=none; b=iqFSY/vPgOHaXH+neYizuJpRfKWAecFWLTBUE129XMUES/3CPmmU1KJd5A638MBlCfEfQ5W01SG3YYObbY6DgUj6TevCRGgskoSE14CkDuHxmHNzoXIzYL2n0nt6eQOcBdhh19r+Xvvn+oTAoREWw4rJhZBxfbCZ88A/a2JbQfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784495635; c=relaxed/simple; bh=uZZtbCVhOKhzC2tpXj5NKZbfR/sFeNe4FarJkD89skY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=aY2LZdnpyze+uLXDIBxQpAYpuLexf1ytkzFZl/Wnk45DKHjpMHXNdnDobcOZ416WmiopyD6AdIFCOmNPQcUC0FKAaF8in1wI6jsyYr3VHNdeRjiP+fEfQCAxB9ZiUSRsb8IgT336rwufCwx5aVDHmvh4nM8oS7pE0aC7Phh+n9w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=cLTgGJFm; arc=none smtp.client-ip=209.85.128.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-4955de8797cso1826845e9.3 for ; Sun, 19 Jul 2026 14:13:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784495632; x=1785100432; darn=lists.linux.dev; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=mSI4AxiakfLEoxCkbMXngSkCPIZ/Cb8g+GVzqOuksO8=; b=cLTgGJFmGDNjuIpJ9NYrSoWUQl2sCy8kwTCCMabS3rPAA9hHCguG2mwF3OFxQpr5OY 3wB7X02HR6AO+AGZJD/upMJSrgLiZ7/Rdsokt0lVXmnVIgl0sYpGaCqx0MwzBohrAjtc 7GJYo2O07kLNanScbV9wm2jXPCVnSWNhJ3444mD++fFrkN+QRiTn7mbWZjoY8Pnw/g4x ll2hVErktR0nQ5EVgtqI+XkSqGbM0i72H5Ar2jjYgOGo4rsKfq7wT391ig54Tez22w4c oe8UnEOQqlLylEOFJhCa2M4i5j/FYeAmuNAZwJ1kOKMgf0Jct+1oPhQ6/dmj9yFeOIwp v4lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784495632; x=1785100432; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=mSI4AxiakfLEoxCkbMXngSkCPIZ/Cb8g+GVzqOuksO8=; b=B8Bt/iLkEShrlpqfNLXPywCjcoJsRXx3c0wGDM96IpW1X1t7StiGjkNwLZ15tocQTx H7Qy18EFL24EVSFqpK1tENAmQKJHi8pG7HZCly1ihHYxrZvgdbMjXsSMk+Iryxqc1/Yl Qlw0RtNllDkYsGUNpEVUg+w0XZDrK4L1I3wcyW7F/rBHuPZr5KTAaKu/oe5oXXTBBp/p 6k6go5S99SnuYa6FPvHqygnLYghPjksdVdBN3WNFsDrJ750P5PFO8N2vCDr/CahljZ3c H427gt9TiEfZN0SJmsV2P7vdjwPMGG+h2QpRtcuBSxz/FAN/3glNTxOn+by/j9lIHH/S yQOg== X-Forwarded-Encrypted: i=1; AHgh+RpMj0bGOZFVJfiYFddjxtyZZHnyXT/UuDc5UzukQul/ESllywWE8bp/4Y0D5brHMvRrnTJuRXhwif88TA==@lists.linux.dev X-Gm-Message-State: AOJu0Yy1LsTSr4sX6Uakmth04JQOi8V/reZV9JKiB0GbPSsEqDOJT/dn YmvmUbG+7ia/ePeRrV2Gt7D9bApFLN7XrZF1ZyDtwpzHa11MbbvnqNyo X-Gm-Gg: AfdE7cmsvlzJdg+aFiqIFHRlMjWYD2xtHgujo5BSRvSTO6Oe3vnUHt7MbVgeBh1/iLu Yu/9Kc0Ws0/mYdtLjUoMrAupNLMYoupS4oZ2KYf04mecoUuwtBDd3lH0UqhoIAzV1hPZyag7ROY kDCqUvP0uKRLzE/X7WGYqBpgVZoRHz0xbTEXFASvrRSIZoM6BHTHF1ARPCW1cI9vgYGGM2q8oUn AxYdd4j1VqHNBCh9uv7wPJxcqYIFc3ctd6GYg+/Bm7WaA78DJ5O8IynBDrnkoX2EN0N2gLgwN2U zr11mmFdtxe0pU2p2nAxgmJXSIW/1LwqQp2yk2ZI4fXxBo33bmfbEZYsdL5fVOcGI6Qf/giCmEF GavvaO7iupw5QKMEsWinRRaz33h8b+P1P850FOpCJloDIi1AE6GgQZsGTPwlQeCToWfnWGiTVwR u53VkVi7+UCQgZS3w2ng7WQSFbdg8GJUD9j/Ql X-Received: by 2002:a05:600d:8494:10b0:495:4056:2c6d with SMTP id 5b1f17b1804b1-4954a402f4fmr101550685e9.23.1784495631684; Sun, 19 Jul 2026 14:13:51 -0700 (PDT) Received: from localhost.localdomain ([2a0d:3344:2841:7708:a101:2b8a:f76:a00f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49549a3e2a9sm224108815e9.4.2026.07.19.14.13.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Jul 2026 14:13:51 -0700 (PDT) From: =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= To: Michael Turquette , Stephen Boyd , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland Cc: Brian Masney , Andre Przywara , Rob Herring , Krzysztof Kozlowski , Conor Dooley , linux-clk@vger.kernel.org, linux-sunxi@lists.linux.dev, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Juan_Manuel_L=C3=B3pez_Carrillo?= Subject: [PATCH v1 4/4] arm64: dts: allwinner: t527-orangepi-4a: add GPU OPP table Date: Sun, 19 Jul 2026 23:13:19 +0200 Message-ID: <20260719211319.982285-5-juanmanuellopezcarrillo@gmail.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260719211319.982285-1-juanmanuellopezcarrillo@gmail.com> References: <20260719211319.982285-1-juanmanuellopezcarrillo@gmail.com> Precedence: bulk X-Mailing-List: linux-sunxi@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Rspamd-Server: rspamd-worker-8404 X-Spamd-Result: default: False [-0.16 / 15.00]; BAYES_HAM(-5.50)[100.00%]; RBL_SENDERSCORE(2.00)[172.234.253.10:from]; SUSPICIOUS_RECIPS(1.50)[]; MID_CONTAINS_FROM(1.00)[]; DMARC_POLICY_SOFTFAIL(1.00)[gmail.com : SPF not aligned (relaxed), No valid DKIM,none]; MAILLIST(-0.15)[generic]; BAD_REP_POLICIES(0.10)[]; MIME_GOOD(-0.10)[text/plain]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_TWELVE(0.00)[16]; FREEMAIL_FROM(0.00)[gmail.com]; DBL_BLOCKED_OPENRESOLVER(0.00)[sea.lore.kernel.org:rdns,sea.lore.kernel.org:helo]; TO_DN_SOME(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; FORGED_SENDER_MAILLIST(0.00)[]; FREEMAIL_CC(0.00)[redhat.com,arm.com,kernel.org,vger.kernel.org,lists.linux.dev,lists.infradead.org,gmail.com]; FREEMAIL_TO(0.00)[baylibre.com,kernel.org,gmail.com,sholland.org]; TAGGED_RCPT(0.00)[dt]; FROM_HAS_DN(0.00)[]; RCVD_TLS_LAST(0.00)[]; ARC_ALLOW(0.00)[subspace.kernel.org:s=arc-20240116:i=1]; MIME_TRACE(0.00)[0:+]; FORGED_RECIPIENTS_MAILLIST(0.00)[]; PRECEDENCE_BULK(0.00)[]; ASN(0.00)[asn:63949, ipnet:172.234.224.0/19, country:SG]; FROM_NEQ_ENVFROM(0.00)[juanmanuellopezcarrillo@gmail.com,linux-sunxi@lists.linux.dev]; TAGGED_FROM(0.00)[bounces-24535-noreply=patchwork.local]; R_SPF_ALLOW(0.00)[+ip4:172.234.253.10]; RCVD_COUNT_FIVE(0.00)[6]; RCVD_VIA_SMTP_AUTH(0.00)[] X-Rspamd-Queue-Id: 621B21C2CAE X-MORS-Enabled: yes X-MORS-DOMAIN: patchwork.local X-MORS-HOSTING: hosting172546 X-MORS-USER: hosting172546 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= Add the Mali-G57 operating points from the vendor BSP universal table (150/200/300/400/600 MHz) so panfrost devfreq can scale the GPU instead of running at the boot clock. All operating points use 920 mV: the BSP table specifies 900 mV for every universal OPP, but on this board the GPU rail (AXP717 DCDC2, vdd-gpu-sys) is a fixed 920 mV supply, so the OPP voltage states the actual rail value and voltage transitions are no-ops. The higher speed-bin points of the BSP (648-792 MHz) are not included: they are gated by a SID efuse bin and need pll-gpu as a live parent. Depends on the sun55i-a523 GPU clock divider fix (the OPP rates are only produced correctly with the cycle-masking divider model); validated on hardware with the Mali cycle counter: 149/199/300/399/597 MHz measured under load, thermal-emulation throttling included. Signed-off-by: Juan Manuel López Carrillo --- .../dts/allwinner/sun55i-t527-orangepi-4a.dts | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/arch/arm64/boot/dts/allwinner/sun55i-t527-orangepi-4a.dts b/arch/arm64/boot/dts/allwinner/sun55i-t527-orangepi-4a.dts index 055be86e5..0fd73a1bb 100644 --- a/arch/arm64/boot/dts/allwinner/sun55i-t527-orangepi-4a.dts +++ b/arch/arm64/boot/dts/allwinner/sun55i-t527-orangepi-4a.dts @@ -30,6 +30,35 @@ ext_osc32k: ext-osc32k-clk { clock-output-names = "ext_osc32k"; }; + gpu_opp_table: opp-table-gpu { + compatible = "operating-points-v2"; + + opp-150000000 { + opp-hz = /bits/ 64 <150000000>; + opp-microvolt = <920000>; + }; + + opp-200000000 { + opp-hz = /bits/ 64 <200000000>; + opp-microvolt = <920000>; + }; + + opp-300000000 { + opp-hz = /bits/ 64 <300000000>; + opp-microvolt = <920000>; + }; + + opp-400000000 { + opp-hz = /bits/ 64 <400000000>; + opp-microvolt = <920000>; + }; + + opp-600000000 { + opp-hz = /bits/ 64 <600000000>; + opp-microvolt = <920000>; + }; + }; + leds { compatible = "gpio-leds"; @@ -116,6 +145,7 @@ &gmac1 { &gpu { mali-supply = <®_dcdc2>; + operating-points-v2 = <&gpu_opp_table>; status = "okay"; };