From: "Théo Lebrun" <theo.lebrun@bootlin.com>
To: "Théo Lebrun" <theo.lebrun@bootlin.com>,
"Linus Walleij" <linus.walleij@linaro.org>
Cc: "Andi Shyti" <andi.shyti@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
linux-arm-kernel@lists.infradead.org, linux-i2c@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Grégory Clement" <gregory.clement@bootlin.com>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Tawfik Bayouk" <tawfik.bayouk@mobileye.com>
Subject: Re: [PATCH v2 5/6] i2c: nomadik: fix BRCR computation
Date: Wed, 09 Oct 2024 15:34:47 +0200 [thread overview]
Message-ID: <D4RBC5VO5DLQ.PATCQSM33ORM@bootlin.com> (raw)
In-Reply-To: <D4RB9IS3O0L1.2G9E2688BL4PZ@bootlin.com>
On Wed Oct 9, 2024 at 3:31 PM CEST, Théo Lebrun wrote:
> On Wed Oct 9, 2024 at 1:34 PM CEST, Linus Walleij wrote:
> > On Wed, Oct 9, 2024 at 12:23 PM Théo Lebrun <theo.lebrun@bootlin.com> 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_dev *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 <=400kHz, not >=400kHz.
>
> I'll add that last sentence "Eg when you ask for 400kHz you want a bus
> rate <=400kHz (and not >=400kHz)". It is straight forward and easy to
> understand.
>
> > > brcr1 = FIELD_PREP(I2C_BRCR_BRCNT1, 0);
> > > - brcr2 = FIELD_PREP(I2C_BRCR_BRCNT2, i2c_clk / (priv->clk_freq * div));
> > > + brcr2 = FIELD_PREP(I2C_BRCR_BRCNT2, i2c_clk / (priv->clk_freq * div) + 1);
> >
> > Doesn't the last part correspond to something like
> > #include <linux/math.h>
> > u64 scaler = DIV_ROUND_DOWN_ULL(i2c_clk, (priv->clk_freq * div));
> > brcr2 = 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 the
> > fine details of the math here.
>
> Indeed what we want is:
> DIV_ROUND_DOWN(i2c_clk, priv->clk_freq * div)
s/DIV_ROUND_DOWN/DIV_ROUND_UP/
(sorry for the confusion)
>
> I see no reason to use DIV_ROUND_DOWN_ULL(). It would be useful if
s/DIV_ROUND_DOWN_ULL/DIV_ROUND_UP_ULL/
> i2c_clk + (priv->clk_freq * div)
> had a chance to overflow.
>
> Worst case is:
> 3_400_000 + (48_000_000 * 3) = 147_400_000
>
> Will send v3 straight away as this is a significant change,
> thanks Linus!
>
> --
> Théo Lebrun, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
Regards,
--
Théo Lebrun, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
next prev parent reply other threads:[~2024-10-09 13:34 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-09 10:23 [PATCH v2 0/6] i2c: nomadik: support >=1MHz & Mobileye EyeQ6H platform Théo Lebrun
2024-10-09 10:23 ` [PATCH v2 1/6] dt-bindings: i2c: nomadik: add mobileye,eyeq6h-i2c bindings Théo Lebrun
2024-10-09 11:20 ` Linus Walleij
2024-10-09 10:23 ` [PATCH v2 2/6] dt-bindings: i2c: nomadik: support 400kHz < clock-frequency <= 3.4MHz Théo Lebrun
2024-10-09 11:21 ` Linus Walleij
2024-10-09 10:23 ` [PATCH v2 3/6] i2c: nomadik: switch from of_device_is_compatible() to of_match_device() Théo Lebrun
2024-10-09 11:21 ` Linus Walleij
2024-10-09 10:23 ` [PATCH v2 4/6] i2c: nomadik: support Mobileye EyeQ6H I2C controller Théo Lebrun
2024-10-09 11:22 ` Linus Walleij
2024-10-09 10:23 ` [PATCH v2 5/6] i2c: nomadik: fix BRCR computation Théo Lebrun
2024-10-09 11:34 ` Linus Walleij
2024-10-09 13:31 ` Théo Lebrun
2024-10-09 13:34 ` Théo Lebrun [this message]
2024-10-09 10:23 ` [PATCH v2 6/6] i2c: nomadik: support >=1MHz speed modes Théo Lebrun
2024-10-09 11:36 ` Linus Walleij
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=D4RBC5VO5DLQ.PATCQSM33ORM@bootlin.com \
--to=theo.lebrun@bootlin.com \
--cc=andi.shyti@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregory.clement@bootlin.com \
--cc=krzk+dt@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh@kernel.org \
--cc=tawfik.bayouk@mobileye.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=vladimir.kondratiev@mobileye.com \
/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.