From: Wolfram Sang <wsa@the-dreams.de>
To: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Wolfram Sang <wsa+renesas@sang-engineering.com>,
Linux I2C <linux-i2c@vger.kernel.org>,
Linux-Renesas <linux-renesas-soc@vger.kernel.org>,
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: Re: [RFC PATCH] i2c: refactor parsing of timings
Date: Thu, 26 Mar 2020 11:52:41 +0100 [thread overview]
Message-ID: <20200326105241.GA1538@ninjato> (raw)
In-Reply-To: <CAMuHMdXVy1acwXxD9C==gGve-Xb-oPbF7BOpu1BaT=1gvUTdQQ@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1523 bytes --]
Hi Geert,
> > +{
> > + int ret;
> > +
> > + ret = device_property_read_u32(dev, prop_name, cur_val_p);
> > + if (ret && use_def)
> > + *cur_val_p = def_val;
>
> Alternatively, you could just preinitialize the value with the default value
> before calling this function, and ignoring ret.
> That would remove the need for both the def_val and use_def parameters.
I can't do that because if !use_def and ret, then the value must not be
changed.
> > + if (t->bus_freq_hz <= I2C_MAX_STANDARD_MODE_FREQ)
> > + d = 1000;
> > + else if (t->bus_freq_hz <= I2C_MAX_FAST_MODE_FREQ)
> > + d = 300;
> > + else
> > + d = 120;
> > + i2c_parse_timing(dev, "i2c-scl-rising-time-ns", &t->scl_rise_ns, d, u);
> >
> > - ret = device_property_read_u32(dev, "i2c-analog-filter-cutoff-frequency", &t->analog_filter_cutoff_freq_hz);
> > - if (ret && use_defaults)
> > - t->analog_filter_cutoff_freq_hz = 0;
> > + if (t->bus_freq_hz <= I2C_MAX_FAST_MODE_FREQ)
> > + d = 300;
> > + else
> > + d = 120;
>
> Is the difference with above intentional, or an oversight?
If this is an oversight, then it is also in the I2C specs ;)
> if the former, I like the dreaded ternary operator (only) for cases like this:
>
> d = t->bus_freq_hz <= I2C_MAX_FAST_MODE_FREQ ? 300 : 120
Yup, that would be an improvement!
Thanks,
Wolfram
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-03-26 10:52 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-26 10:16 [RFC PATCH] i2c: refactor parsing of timings Wolfram Sang
2020-03-26 10:36 ` Geert Uytterhoeven
2020-03-26 10:50 ` Andy Shevchenko
2020-03-26 10:52 ` Wolfram Sang [this message]
2020-03-26 11:15 ` Geert Uytterhoeven
2020-03-26 12:05 ` Andy Shevchenko
2020-03-26 10:47 ` Andy Shevchenko
2020-03-26 11:00 ` Wolfram Sang
2020-03-26 11:16 ` 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=20200326105241.GA1538@ninjato \
--to=wsa@the-dreams.de \
--cc=andriy.shevchenko@linux.intel.com \
--cc=geert@linux-m68k.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=wsa+renesas@sang-engineering.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox