From nobody Thu Nov 05 14:51:09 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jL4xn5GfWz706Xx for ; Thu, 05 Nov 2026 14:51:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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) by mx1.freebsd.org (Postfix) with ESMTPS id 4jL4xn3zZhz3Dg2 for ; Thu, 05 Nov 2026 14:51:09 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793890269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NeZ/Jl/JJ4kWPzgTvQP29yxvj9IEUlfGPlDohScnOVE=; b=PjEzDBO99uTiFMnpcXKJdR8XdPHfMTQ6EqYGr84mc8Yxv7asNeGru9TWdCIE9EG8zeMmIJ i/meNjsN5hH0xFiDEKNgkPid9rL7IB83jKoPMlNSUQvatcRICyRRjlr05SXiTDybQyCLkq 3sMFFlrdYiypa7o5aGU65e2bFA15eqTC4W7aIxlpxOGD5JiYSeWScmHh+NVYbrMi7p/lBM vIP+vArJj5sOBbFMjeNJzB3HX1cyf9OwJMHIteMai8w92WtfV3gs2PibmntiLJRIkaJEVL 9ig6nJbELGoOQN5VOxmdWq14jRp1Ked3XeFBih61eapgbRMvzzr2TVXHN5tZhA== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793890269; b=fRKf+SqwmU02XfIO/I/A3xky8cqGXyBaV6vmHfQARvdN1hAzRzS6eRXIk7EiAk5QoxhhaT loK3G1sEylN9Oj6SexAU9Xlljzx2uJ4sQ0EG8lAu7oDR7MoPTFVH5I7bxLJaGg3BtLNy79 9pjAojg53O3h1FDyvnq3iPOu8Ln7h1i6oqJ89su5jnLhZxgQ2gG5o61hBsTklDF11cpz3p sTfID7OdE/iBYXfnNELygWjEn5Fk1vcQZitrSeeRZJC/59bEkf8MQWTvj4nUVVhRxgkWNv DmWaJsyca7dpz2V0/jZYXS2XwtQyWNzwy1AvRo3c6C5UwP/K2jFJoBSGesOwAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793890269; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=NeZ/Jl/JJ4kWPzgTvQP29yxvj9IEUlfGPlDohScnOVE=; b=xm8bKv1yWsoxRu1IKIgOPYBZ8qvjUGmFnJf+9pvZnzno0KhbKcjB4yTeSFeG+oCJG129Ir wCRZLXJJcyTirq1aCVAfYKoCtN7MOh9KmMTlD9c1G7LocwnHyP43gILtxunOKu5UndFvs0 6UZEp4Yddu1o1gpEtev1lYYH1zfa/ujmqQLlw2ytRIkDyQzqMYU10OglImfPupT0mg7Ct6 kbJSogJuiTuMS3Pw/VBlnHA5b2Wzwuv21Z1zA6t32YTuDz7gxaZs0PVDruJeJTJeQm8h0K p+hHLnXM5eO8Boi+7jn2CYh2ezhaEJ6IhVvrQ6AZ7v2l0gls3aX6kK/gplWv+A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jL4xn2wHhzv9R for ; Thu, 05 Nov 2026 14:51:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 22517 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 05 Nov 2026 14:51:09 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Emmanuel Vadot Subject: git: 9c85482ca5dd - main - clk: rockchip: Add a mux flag to select the closest parent List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: manu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9c85482ca5ddbc1b9f6ae7f69d7dd1bdc07429a5 Auto-Submitted: auto-generated Date: Thu, 05 Nov 2026 14:51:09 +0000 Message-Id: <6aec97dd.22517.4b7a4d39@gitrepo.freebsd.org> The branch main has been updated by manu: URL: https://cgit.FreeBSD.org/src/commit/?id=9c85482ca5ddbc1b9f6ae7f69d7dd1bdc07429a5 commit 9c85482ca5ddbc1b9f6ae7f69d7dd1bdc07429a5 Author: Emmanuel Vadot AuthorDate: 2026-10-20 11:04:15 +0000 Commit: Emmanuel Vadot CommitDate: 2026-11-05 14:50:11 +0000 clk: rockchip: Add a mux flag to select the closest parent Add RK_CLK_MUX_ROUND_PARENT for muxes whose parents are fixed rate clocks that can be shared with other consumers. When a rate is requested, pick the parent with the rate that best fits the rounding flags and never change the rate of a parent. Without it the request is passed up to the shared parents, which refuse to change. Reviewed by: mmel Differential Revision: https://reviews.freebsd.org/D60890 --- sys/dev/clk/rockchip/rk_clk_mux.c | 51 +++++++++++++++++++++++++++++++++++++++ sys/dev/clk/rockchip/rk_clk_mux.h | 2 ++ 2 files changed, 53 insertions(+) diff --git a/sys/dev/clk/rockchip/rk_clk_mux.c b/sys/dev/clk/rockchip/rk_clk_mux.c index 97c1ad6f2f1c..40eeaf61b962 100644 --- a/sys/dev/clk/rockchip/rk_clk_mux.c +++ b/sys/dev/clk/rockchip/rk_clk_mux.c @@ -161,6 +161,55 @@ rk_clk_mux_set_mux(struct clknode *clk, int idx) return(0); } +/* + * The parents are fixed rate clocks (possibly shared with other consumers), + * so only select the one that is the closest to the requested rate according + * to the rounding flags and leave its rate alone. + */ +static int +rk_clk_mux_round_parent(struct clknode *clk, uint64_t *fout, int flags, + int *stop) +{ + struct clknode *p_clk; + const char **p_names; + uint64_t pfreq, best_freq, diff, best_diff; + int p_idx, best_idx, round; + + round = CLK_SET_ROUND(flags); + p_names = clknode_get_parent_names(clk); + best_idx = -1; + best_freq = 0; + best_diff = 0; + for (p_idx = 0; p_idx != clknode_get_parents_num(clk); p_idx++) { + p_clk = clknode_find_by_name(p_names[p_idx]); + if (p_clk == NULL || clknode_get_freq(p_clk, &pfreq) != 0) + continue; + if (round == CLK_SET_ROUND_DOWN && pfreq > *fout) + continue; + if (round == CLK_SET_ROUND_UP && pfreq < *fout) + continue; + if (round == CLK_SET_ROUND_EXACT && pfreq != *fout) + continue; + diff = pfreq > *fout ? pfreq - *fout : *fout - pfreq; + if (best_idx == -1 || diff < best_diff) { + best_idx = p_idx; + best_freq = pfreq; + best_diff = diff; + } + } + if (best_idx == -1) + return (ERANGE); + + *stop = 1; + *fout = best_freq; + if ((flags & CLK_SET_DRYRUN) != 0) + return (0); + + if (clknode_get_parent_idx(clk) != best_idx) + return (clknode_set_parent_by_idx(clk, best_idx)); + return (0); +} + static int rk_clk_mux_set_freq(struct clknode *clk, uint64_t fparent, uint64_t *fout, int flags, int *stop) @@ -177,6 +226,8 @@ rk_clk_mux_set_freq(struct clknode *clk, uint64_t fparent, uint64_t *fout, *stop = 1; return (ENOTSUP); } + if ((sc->mux_flags & RK_CLK_MUX_ROUND_PARENT) != 0) + return (rk_clk_mux_round_parent(clk, fout, flags, stop)); if ((sc->mux_flags & RK_CLK_MUX_REPARENT) == 0) { *stop = 0; return (0); diff --git a/sys/dev/clk/rockchip/rk_clk_mux.h b/sys/dev/clk/rockchip/rk_clk_mux.h index c6c261294b68..2d0e0e7ed923 100644 --- a/sys/dev/clk/rockchip/rk_clk_mux.h +++ b/sys/dev/clk/rockchip/rk_clk_mux.h @@ -41,6 +41,8 @@ struct rk_clk_mux_def { #define RK_CLK_MUX_MASK 0xFFFF0000 #define RK_CLK_MUX_REPARENT (1 << 0) #define RK_CLK_MUX_GRF (1 << 1) +/* Select the parent with the closest rate, never change a parent rate. */ +#define RK_CLK_MUX_ROUND_PARENT (1 << 2) int rk_clk_mux_register(struct clkdom *clkdom, struct rk_clk_mux_def *clkdef);