From: Alain Volmat <alain.volmat-qxv4g6HH51o@public.gmane.org>
To: Andy Shevchenko
<andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>,
Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
Pierre Yves MORDRET
<pierre-yves.mordret-qxv4g6HH51o@public.gmane.org>,
Maxime Coquelin
<mcoquelin.stm32-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
Alexandre TORGUE <alexandre.torgue-qxv4g6HH51o@public.gmane.org>,
linux-i2c <linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
devicetree <devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
"linux-stm32-XDFAJ8BFU24N7RejjzZ/Li2xQDfSxrLKVpNB7YpNyf8@public.gmane.org"
<linux-stm32-XDFAJ8BFU24N7RejjzZ/Li2xQDfSxrLKVpNB7YpNyf8@public.gmane.org>,
linux-arm Mailing List
<linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>,
Linux Kernel Mailing List
<linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
Fabrice GASNIER <fabrice.gasnier-qxv4g6HH51o@public.gmane.org>
Subject: Re: [PATCH 2/2] i2c: i2c-stm32f7: allows for any bus frequency
Date: Thu, 26 Mar 2020 11:12:19 +0100 [thread overview]
Message-ID: <20200326101219.GA21190@gnbcxd0016.gnb.st.com> (raw)
In-Reply-To: <CAHp75VdPCWdpGo=2n9g0ivti-g2m4jZ=cG4BKHBLk8BVDzaCyg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
Hi Andy,
Thanks for the review.
On Wed, Mar 25, 2020 at 06:53:45PM +0000, Andy Shevchenko wrote:
> On Wed, Mar 25, 2020 at 8:38 PM Alain Volmat <alain.volmat-qxv4g6HH51o@public.gmane.org> wrote:
> >
> > Do not limitate to the 3 (100KHz, 400KHz, 1MHz) bus frequency but
> > instead allows any frequency (if it matches timing requirements).
> > Depending on the requested frequency, use the spec data from either
> > Standard, Fast or Fast Plus mode.
> >
> > Hardcoding of min/max bus frequencies is removed and is instead computed.
> >
> > The driver do not use anymore speed identifier but instead handle
> > directly the frequency and figure out the spec data (necessary
> > for the computation of the timing register) based on the frequency.
>
> ...
>
> > +static struct stm32f7_i2c_spec *get_specs(u32 rate)
> > +{
> > + int i;
> > +
> > + for (i = 0; i < ARRAY_SIZE(i2c_specs); i++)
> > + if (rate <= i2c_specs[i].rate)
> > + return &i2c_specs[i];
> > +
>
> > + /* NOT REACHED */
> > + return ERR_PTR(-EINVAL);
>
> WARN_ONCE() ?
The comment should actually be removed. get_specs return value is
properly checked in stm32f7_i2c_compute_timing and an error message
is displayed in case of an error.
>
> > +}
>
> ...
>
> > - if ((tscl_l < i2c_specs[setup->speed].l_min) ||
> > + if ((tscl_l < specs->l_min) ||
>
> > (i2cclk >=
> > ((tscl_l - af_delay_min - dnf_delay) / 4))) {
>
> Perhaps squash above two to one line at the same time?
I agree that this is not very pretty to read now but that would lead to
a line exceeding 80 characters. To fix that it'd be better to rework the code
but in such case that should be done at a separate time to keep this commit
as small / simpler to understand as possible. So I'd prefer leave this code
for the time being.
>
> ...
>
> > + int i;
> > +
> > + for (i = ARRAY_SIZE(i2c_specs) - 1; i >= 0; i--)
>
>
> Perhaps
>
> int i = ARRAY_SIZE(i2c_specs);
>
> while(i--)
>
> ?
I propose the following code to make it a bit easier to read/understand:
static u32 get_lower_rate(u32 rate)
{
int i = ARRAY_SIZE(i2c_specs);
while (i--)
if (i2c_specs[i].rate < rate)
break;
return i2c_specs[i].rate;
}
If you agree with that I'll push a v2.
>
> > + if (i2c_specs[i].rate < rate)
> > + return i2c_specs[i].rate;
>
> --
> With Best Regards,
> Andy Shevchenko
next prev parent reply other threads:[~2020-03-26 10:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-25 18:35 [PATCH 0/2] i2c: i2c-stm32f7: allow range of I2C bus frequency Alain Volmat
2020-03-25 18:36 ` [PATCH 1/2] dt-bindings: i2c: i2c-stm32f7: allow clock-frequency range Alain Volmat
2020-03-25 18:36 ` [PATCH 2/2] i2c: i2c-stm32f7: allows for any bus frequency Alain Volmat
[not found] ` <1585161361-3408-3-git-send-email-alain.volmat-qxv4g6HH51o@public.gmane.org>
2020-03-25 18:53 ` Andy Shevchenko
[not found] ` <CAHp75VdPCWdpGo=2n9g0ivti-g2m4jZ=cG4BKHBLk8BVDzaCyg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2020-03-26 10:12 ` Alain Volmat [this message]
[not found] ` <20200326101219.GA21190-KtquC145j2edsQPTSGfZHNvLeJWuRmrY@public.gmane.org>
2020-03-26 11:38 ` Andy Shevchenko
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=20200326101219.GA21190@gnbcxd0016.gnb.st.com \
--to=alain.volmat-qxv4g6hh51o@public.gmane.org \
--cc=alexandre.torgue-qxv4g6HH51o@public.gmane.org \
--cc=andy.shevchenko-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=fabrice.gasnier-qxv4g6HH51o@public.gmane.org \
--cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-stm32-XDFAJ8BFU24N7RejjzZ/Li2xQDfSxrLKVpNB7YpNyf8@public.gmane.org \
--cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
--cc=mcoquelin.stm32-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=pierre-yves.mordret-qxv4g6HH51o@public.gmane.org \
--cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).