From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 18425CEDD93 for ; Wed, 9 Oct 2024 13:34:34 +0000 (UTC) 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:In-Reply-To:References:From: To:Cc:Subject:Message-Id:Date:Content-Type:Content-Transfer-Encoding: Mime-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=bmB3TVTLAYoejXpiOXxmeOtUKDtgamIRXEwjeFLgEBk=; b=LV2cVrEI+GFIFB5pc/PgNg5Qru sYCyfWghQAUecPUTnbwNrPREehu+FjwxPSLmjaEYWxbSx5fjOh6QWPs5mAiaoWEO4r0SoxndjGKwx 6qlzrL143KG4WgO0c4Gu/uTY7VsOm0/vVVxN3DIE1XSScLsuf26t/GScWBfv4xLMfe6/2dF1mxzEi Z9axJtc7qsjiR/Gd+opCOSmFZNoqprurdJ5duawd6/zlv87IyqGQrbThB+GMXEBdxsqNRzWVZ8GL5 9aHODSSwLmItMKDBvqNkpkkwdhpvygYTYPR41FKwsbPlFmWYwDoSvshlKXTfNhPyItGS8+YZonhMC hqSavLsg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syWpX-00000009QNi-0dde; Wed, 09 Oct 2024 13:34:19 +0000 Received: from relay9-d.mail.gandi.net ([217.70.183.199]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syWmj-00000009Poo-1vp0 for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2024 13:31:28 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 4D4E5FF807; Wed, 9 Oct 2024 13:31:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1728480681; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=bmB3TVTLAYoejXpiOXxmeOtUKDtgamIRXEwjeFLgEBk=; b=fStKmwy/a24cNXVfFv6HOUgx+VRqdHvokCfSDoeKcmZlfI0GqbtJ28FJ9zrNBeaHj7GEw+ fIZ+67ymxDtcBZ+TNboySyb1WBuu5p0YRdx5g5tZAl6/qhnTnjtQorle0NkVYsOw5W9uNg lZmarUQQCIjCip+Btj+2b8xmshPg7rxw68036EQ39F1+eITNH6v4I+hY+aS+vO92c1jUQu QRhqUDGLBnpCuH/WReRH/nVMQJiiOLQ6Dnw9DjQvEfjkHtkyjJfdJ8NhIkXhWFuf5IpptN L1PNEXUI38bsO6NMETaOhCrmx03cPoLPmNUyvDdwbUFHj5u4k0MrEZTMB1z/fw== Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Wed, 09 Oct 2024 15:31:20 +0200 Message-Id: Subject: Re: [PATCH v2 5/6] i2c: nomadik: fix BRCR computation Cc: "Andi Shyti" , "Rob Herring" , "Krzysztof Kozlowski" , "Conor Dooley" , , , , , "Vladimir Kondratiev" , =?utf-8?q?Gr=C3=A9gory_Clement?= , "Thomas Petazzoni" , "Tawfik Bayouk" To: "Linus Walleij" From: =?utf-8?q?Th=C3=A9o_Lebrun?= X-Mailer: aerc 0.18.2-0-ge037c095a049 References: <20241009-mbly-i2c-v2-0-ac9230a8dac5@bootlin.com> <20241009-mbly-i2c-v2-5-ac9230a8dac5@bootlin.com> In-Reply-To: X-GND-Sasl: theo.lebrun@bootlin.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241009_063127_253448_FA9FF574 X-CRM114-Status: GOOD ( 15.47 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hello Linus, On Wed Oct 9, 2024 at 1:34 PM CEST, Linus Walleij wrote: > On Wed, Oct 9, 2024 at 12:23=E2=80=AFPM Th=C3=A9o Lebrun wrote: > > --- a/drivers/i2c/busses/i2c-nomadik.c > > +++ b/drivers/i2c/busses/i2c-nomadik.c > > @@ -454,9 +454,12 @@ static void setup_i2c_controller(struct nmk_i2c_de= v *priv) > > * operation, and the other is for std, fast mode, fast mode > > * plus operation. Currently we do not supprt high speed mode > > * so set brcr1 to 0. > > + * > > + * BRCR is a clock divider amount. Pick highest value that > > + * leads to rate strictly below target. > > */ > > You could push in some more details from the commit message here so it's = not > so terse. Most of the details from the commit message come from behavior changes: what was done previously versus what is the new behavior we implement. Having a clock divider picking the bus rate that is below the target speed rather than above sounds rather intuitive. Eg when you ask for 400kHz you want <=3D400kHz, not >=3D400kHz. I'll add that last sentence "Eg when you ask for 400kHz you want a bus rate <=3D400kHz (and not >=3D400kHz)". It is straight forward and easy to understand. > > brcr1 =3D FIELD_PREP(I2C_BRCR_BRCNT1, 0); > > - brcr2 =3D FIELD_PREP(I2C_BRCR_BRCNT2, i2c_clk / (priv->clk_freq= * div)); > > + brcr2 =3D FIELD_PREP(I2C_BRCR_BRCNT2, i2c_clk / (priv->clk_freq= * div) + 1); > > Doesn't the last part correspond to something like > #include > u64 scaler =3D DIV_ROUND_DOWN_ULL(i2c_clk, (priv->clk_freq * div)); > brcr2 =3D FIELD_PREP(I2C_BRCR_BRCNT2, (u32)scaler); > > Certianly one of the in-kernel division helpers like DIV_ROUND_DOWN > round_up() etc are better to use IMO, but I might not be understanding th= e > fine details of the math here. Indeed what we want is: DIV_ROUND_DOWN(i2c_clk, priv->clk_freq * div) I see no reason to use DIV_ROUND_DOWN_ULL(). It would be useful if i2c_clk + (priv->clk_freq * div) had a chance to overflow. Worst case is: 3_400_000 + (48_000_000 * 3) =3D 147_400_000 Will send v3 straight away as this is a significant change, thanks Linus! -- Th=C3=A9o Lebrun, Bootlin Embedded Linux and Kernel engineering https://bootlin.com