From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44F501624DF; Tue, 3 Mar 2026 12:46:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772542021; cv=none; b=sSwuNagTtQqZlncQJ4An6CGnAaHMrnID/y+9ybWKtcFdtbjBxyX4MWNaOglI8I0w0rmFfF0ADRfpwxDg+zvNfrpSWkfoF825h3jRnX1oCDVrxKbLSdUmAHTUQcgeg0L5OkHs7zsXRftabuI4QhGVwct6ydM1mBk01be+uHvmcIY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772542021; c=relaxed/simple; bh=74eJWmuQvKvwedaHc+syTnjf1fOGcN8yCp+AH4IM9eE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=pCJaO+F9kl/Eug+toggL/OT+5/z+vWEh+31M0Q8oExJhXC3dPOlP5GeH6jsyM+V5vjgTrfEyVwKs7hbtM7FeU1YhZY3tRrSiaTjI9anx/rAqjKYzXRX8qthU07K7mpWBr7w1hNYXv7QA3x76lJvd5k7PHbY+9y0Sk/ZfbS7yHbI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 23655497; Tue, 3 Mar 2026 04:46:51 -0800 (PST) Received: from pluto (usa-sjc-mx-foss1.foss.arm.com [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B08AA3F7BD; Tue, 3 Mar 2026 04:46:53 -0800 (PST) Date: Tue, 3 Mar 2026 12:46:50 +0000 From: Cristian Marussi To: Geert Uytterhoeven Cc: Cristian Marussi , 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, peng.fan@oss.nxp.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 Message-ID: References: <20260227153225.2778358-1-cristian.marussi@arm.com> <20260227153225.2778358-2-cristian.marussi@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Mon, Mar 02, 2026 at 01:37:00PM +0100, Geert Uytterhoeven wrote: > Hi Cristian, > > On Fri, 27 Feb 2026 at 16:33, 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 > > Thanks for your patch! Hi, thanks for having a look. > > > --- a/drivers/firmware/arm_scmi/clock.c > > +++ b/drivers/firmware/arm_scmi/clock.c > > @@ -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); > > step_size is u64, while do_div() truncates it to 32-bit. Yes, as pointed out also by other reviewers, there are pre-existent bugs probably in this rounding...this patch was meant only to move the logic away from the CLK SCMI driver into the SCMI Clock protocol layer since it enables a few simplification... In the next V2, I will fix rounding errors by adding a dedicated Fix on top of the original code, before this 'relocation', so as to make the backport easier and move the fixed code. Thanks, Cristian