All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peng Fan <peng.fan@oss.nxp.com>
To: Cristian Marussi <cristian.marussi@arm.com>
Cc: linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, arm-scmi@vger.kernel.org,
	linux-clk@vger.kernel.org, linux-renesas-soc@vger.kernel.org,
	sudeep.holla@arm.com, philip.radford@arm.com,
	james.quinlan@broadcom.com, f.fainelli@gmail.com,
	vincent.guittot@linaro.org, etienne.carriere@foss.st.com,
	michal.simek@amd.com, dan.carpenter@linaro.org,
	geert+renesas@glider.be, kuninori.morimoto.gx@renesas.com,
	marek.vasut+renesas@gmail.com
Subject: Re: [PATCH 01/11] firmware: arm_scmi: Add clock determine_rate operation
Date: Sat, 28 Feb 2026 08:27:11 +0800	[thread overview]
Message-ID: <aaI2X6qnGabtW1t0@shlinux89> (raw)
In-Reply-To: <20260227153225.2778358-2-cristian.marussi@arm.com>

Hi Cristian,

On Fri, Feb 27, 2026 at 03:32:15PM +0000, Cristian Marussi wrote:
>Add a clock operation to help determining the effective rate, closest to
>the required one, that a specific clock can support.
>
>Calculation is currently performed kernel side and the logic is taken
>directly from the SCMI Clock driver: embedding the determinate rate logic
>in the protocol layer enables semplifications in the SCMI Clock protocol
>interface and  will more easily accommodate further evolutions where such
>determine_rate logic into is optionally delegated to the platform SCMI
>server.
>
>Signed-off-by: Cristian Marussi <cristian.marussi@arm.com>
>---
>Spoiler alert next SCMI spec will most probably include a new
>CLOCK_DETERMINE_RATE command to delegate to the platform such calculations,
>so this clock proto_ops will be needed anyway sooner or later

Is there any early reviewing version available?

Thanks,
Peng

>---
> drivers/firmware/arm_scmi/clock.c | 42 +++++++++++++++++++++++++++++++
> include/linux/scmi_protocol.h     |  6 +++++
> 2 files changed, 48 insertions(+)
>
>diff --git a/drivers/firmware/arm_scmi/clock.c b/drivers/firmware/arm_scmi/clock.c
>index ab36871650a1..54e8b59c3941 100644
>--- a/drivers/firmware/arm_scmi/clock.c
>+++ b/drivers/firmware/arm_scmi/clock.c
>@@ -8,6 +8,7 @@
> #include <linux/module.h>
> #include <linux/limits.h>
> #include <linux/sort.h>
>+#include <asm/div64.h>
> 
> #include "protocols.h"
> #include "notify.h"
>@@ -624,6 +625,46 @@ static int scmi_clock_rate_set(const struct scmi_protocol_handle *ph,
> 	return ret;
> }
> 
>+static int scmi_clock_determine_rate(const struct scmi_protocol_handle *ph,
>+				     u32 clk_id, unsigned long *rate)
>+{
>+	u64 fmin, fmax, ftmp;
>+	struct scmi_clock_info *clk;
>+	struct clock_info *ci = ph->get_priv(ph);
>+
>+	if (!rate)
>+		return -EINVAL;
>+
>+	clk = scmi_clock_domain_lookup(ci, clk_id);
>+	if (IS_ERR(clk))
>+		return PTR_ERR(clk);
>+
>+	/*
>+	 * If we can't figure out what rate it will be, so just return the
>+	 * rate back to the caller.
>+	 */
>+	if (clk->rate_discrete)
>+		return 0;
>+
>+	fmin = clk->range.min_rate;
>+	fmax = clk->range.max_rate;
>+	if (*rate <= fmin) {
>+		*rate = fmin;
>+		return 0;
>+	} else if (*rate >= fmax) {
>+		*rate = fmax;
>+		return 0;
>+	}
>+
>+	ftmp = *rate - fmin;
>+	ftmp += clk->range.step_size - 1; /* to round up */
>+	do_div(ftmp, clk->range.step_size);
>+
>+	*rate = ftmp * clk->range.step_size + fmin;
>+
>+	return 0;
>+}
>+
> static int
> scmi_clock_config_set(const struct scmi_protocol_handle *ph, u32 clk_id,
> 		      enum clk_state state,
>@@ -936,6 +977,7 @@ static const struct scmi_clk_proto_ops clk_proto_ops = {
> 	.info_get = scmi_clock_info_get,
> 	.rate_get = scmi_clock_rate_get,
> 	.rate_set = scmi_clock_rate_set,
>+	.determine_rate = scmi_clock_determine_rate,
> 	.enable = scmi_clock_enable,
> 	.disable = scmi_clock_disable,
> 	.state_get = scmi_clock_state_get,
>diff --git a/include/linux/scmi_protocol.h b/include/linux/scmi_protocol.h
>index aafaac1496b0..28579c145045 100644
>--- a/include/linux/scmi_protocol.h
>+++ b/include/linux/scmi_protocol.h
>@@ -91,6 +91,10 @@ enum scmi_clock_oem_config {
>  * @info_get: get the information of the specified clock
>  * @rate_get: request the current clock rate of a clock
>  * @rate_set: set the clock rate of a clock
>+ * @determine_rate: determine the effective rate that can be supported by a
>+ *		    clock calculating the closest allowed rate.
>+ *		    Note that @rate is an input/output parameter used both to
>+ *		    describe the requested rate and report the closest match
>  * @enable: enables the specified clock
>  * @disable: disables the specified clock
>  * @state_get: get the status of the specified clock
>@@ -108,6 +112,8 @@ struct scmi_clk_proto_ops {
> 			u64 *rate);
> 	int (*rate_set)(const struct scmi_protocol_handle *ph, u32 clk_id,
> 			u64 rate);
>+	int (*determine_rate)(const struct scmi_protocol_handle *ph, u32 clk_id,
>+			      unsigned long *rate);
> 	int (*enable)(const struct scmi_protocol_handle *ph, u32 clk_id,
> 		      bool atomic);
> 	int (*disable)(const struct scmi_protocol_handle *ph, u32 clk_id,
>-- 
>2.53.0
>

  parent reply	other threads:[~2026-02-28  0:25 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-27 15:32 [PATCH 00/11] SCMI Clock rates discovery rework Cristian Marussi
2026-02-27 15:32 ` [PATCH 01/11] firmware: arm_scmi: Add clock determine_rate operation Cristian Marussi
2026-02-27 16:50   ` Jonathan Cameron
2026-02-28 10:07     ` Cristian Marussi
2026-02-28  0:27   ` Peng Fan [this message]
2026-02-28 10:13     ` Cristian Marussi
2026-03-02 12:37   ` Geert Uytterhoeven
2026-03-03 12:46     ` Cristian Marussi
2026-02-27 15:32 ` [PATCH 02/11] clk: scmi: Use new determine_rate clock operation Cristian Marussi
2026-02-28  0:56   ` Peng Fan
2026-02-28 10:23     ` Cristian Marussi
2026-03-02 17:11     ` Brian Masney
2026-03-03  2:54       ` Peng Fan
2026-03-03 12:47       ` Cristian Marussi
2026-03-02 12:39   ` Geert Uytterhoeven
2026-03-03 12:49     ` Cristian Marussi
2026-02-27 15:32 ` [PATCH 03/11] firmware: arm_scmi: Simplify clock rates exposed interface Cristian Marussi
2026-02-28  2:07   ` Peng Fan
2026-02-28 10:34     ` Cristian Marussi
2026-03-02 12:48   ` Geert Uytterhoeven
2026-03-02 13:09     ` Geert Uytterhoeven
2026-03-03 12:42       ` Cristian Marussi
2026-03-03 12:40     ` Cristian Marussi
2026-02-27 15:32 ` [PATCH 04/11] clk: scmi: Use new simplified per-clock rate properties Cristian Marussi
2026-02-28  2:12   ` Peng Fan
2026-02-27 15:32 ` [PATCH 05/11] firmware: arm_scmi: Drop unused clock rate interfaces Cristian Marussi
2026-02-28  2:13   ` Peng Fan
2026-02-27 15:32 ` [PATCH 06/11] firmware: arm_scmi: Make clock rates allocation dynamic Cristian Marussi
2026-02-28  2:29   ` Peng Fan
2026-02-28 10:36     ` Cristian Marussi
2026-02-27 15:32 ` [PATCH 07/11] firmware: arm_scmi: Harden clock parents discovery Cristian Marussi
2026-02-28  2:39   ` Peng Fan
2026-02-28 10:37     ` Cristian Marussi
2026-02-27 15:32 ` [PATCH 08/11] firmware: arm_scmi: Refactor iterators internal allocation Cristian Marussi
2026-02-27 15:32 ` [PATCH 09/11] firmware: arm_scmi: Add bound iterators support Cristian Marussi
2026-02-28  2:44   ` Peng Fan
2026-02-28  2:43     ` Peng Fan (OSS)
2026-02-28 10:42       ` Cristian Marussi
2026-02-27 15:32 ` [PATCH 10/11] firmware: arm_scmi: Use bound iterators to minimize discovered rates Cristian Marussi
2026-02-27 16:53   ` Jonathan Cameron
2026-02-28 10:43     ` Cristian Marussi
2026-02-27 15:32 ` [PATCH 11/11] firmware: arm_scmi: Introduce all_rates_get clock operation Cristian Marussi
2026-02-28  2:49   ` Peng Fan
2026-02-28 10:47     ` Cristian Marussi
2026-03-02  7:18       ` Peng Fan
2026-03-02 10:47         ` Cristian Marussi
2026-03-02 13:25 ` [PATCH 00/11] SCMI Clock rates discovery rework Geert Uytterhoeven
2026-03-03 13:08   ` Cristian Marussi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aaI2X6qnGabtW1t0@shlinux89 \
    --to=peng.fan@oss.nxp.com \
    --cc=arm-scmi@vger.kernel.org \
    --cc=cristian.marussi@arm.com \
    --cc=dan.carpenter@linaro.org \
    --cc=etienne.carriere@foss.st.com \
    --cc=f.fainelli@gmail.com \
    --cc=geert+renesas@glider.be \
    --cc=james.quinlan@broadcom.com \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=marek.vasut+renesas@gmail.com \
    --cc=michal.simek@amd.com \
    --cc=philip.radford@arm.com \
    --cc=sudeep.holla@arm.com \
    --cc=vincent.guittot@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.