From: Andy Shevchenko <andy@kernel.org>
To: "Nuno Sá" <noname.nuno@gmail.com>
Cc: Nuno Sa <nuno.sa@analog.com>,
linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
devicetree@vger.kernel.org, Bartosz Golaszewski <brgl@bgdev.pl>,
Jonathan Corbet <corbet@lwn.net>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Linus Walleij <linus.walleij@linaro.org>,
Guenter Roeck <linux@roeck-us.net>,
Rob Herring <robh+dt@kernel.org>,
Jean Delvare <jdelvare@suse.com>,
Conor Dooley <conor+dt@kernel.org>
Subject: Re: [PATCH 2/2] hwmon: ltc4282: add support for the LTC4282 chip
Date: Mon, 13 Nov 2023 18:31:41 +0200 [thread overview]
Message-ID: <ZVJPbV2469kjqbHu@smile.fi.intel.com> (raw)
In-Reply-To: <581aec9c6313e3885aae8b1e12dfcc9f392716db.camel@gmail.com>
On Mon, Nov 13, 2023 at 11:13:44AM +0100, Nuno Sá wrote:
> On Fri, 2023-11-10 at 18:50 +0200, Andy Shevchenko wrote:
> > On Fri, Nov 10, 2023 at 04:18:46PM +0100, Nuno Sa wrote:
...
> > > +/*
> > > + * relaxed version of FIELD_PREP() to be used when mask is not a compile
> > > time constant
> > > + * u32_encode_bits() can't also be used as the compiler needs to be able to
> > > evaluate
> > > + * mask at compile time.
> > > + */
> > > +#define LTC4282_FIELD_PREP(m, v) (((v) << (ffs(m) - 1)) & (m))
> >
> > Can we name it accordingly as done in other places, and TBH it's a time to
> > move
> > it to the header. (At least I know about two more implementations of this).
>
> Not sure what you mean? Is there some other drivers doing it already? I'll,
> anyways, wait on more feedback for the GPIO stuff because we might end up not
> needing it...
$ git grep -n 'define field_prep'
...
> > > + /* GPIO_2,3 and the ALERT pin require setting the bit to 1 to pull
> > > down the line */
> > > + if (!gpio->active_high)
> >
> > Hmm... Why do you need a separate flag for this? Shouldn't be described or
> > autodetected somehow?
>
> Well, if a consumer as an active high gpio, it expects to call
> gpiod_set_value(..., 1) and the line to assert, right? To have that, we need to
> write 0 on the device register for some of the pins.
It doesn't matter, the GPIO (not _raw) APIs are using logical levels, 1 — activate,
0 — deactivate.
> And the same story is true for active low. gpiod_set_value(..., 0) will have the
> gpiolib to automatically invert the value and we get 1 in the callback.
Yes, but why do you have that flag in the structure?
> > > + val = !val;
...
> > > + *val = DIV_ROUND_CLOSEST_ULL(be16_to_cpu(in) * (u64)fs, U16_MAX);
> >
> > I'm wondering if you can do some trick to "divide" actually to 2^16 so, it
> > will
> > not use division op at all?
>
> Hmm, not sure if it will be obvious but you mean something like:
>
> *val = (be16_to_cpu(in) * (u64)fs) >> 16;
>
> Is this what you mean? If so, we`ll loose the "CLOSEST" handling... Not so sure
> if we need to be "that" performant in such a code path. But Guenter can also
> share his opinion...
*val = DIV_ROUND_CLOSEST_ULL(be16_to_cpu(in) * (u64)fs + (BIT(16) - 1), BIT(16));
will give the same result without division, no?
What you need is to make sure that the multiplication won't get closer to
U64_MAX, which seems not the case here (max 48-bit number).
Ditto for all other similar cases which I already pointed out.
...
> > > + u64 temp = DECA * 40ULL * st->vfs_out * 1 << 16, temp_2;
> >
> > "* BIT(16)" / "* BIT_ULL(16)" ?
>
> Well, I can just place the number as in the formula. Not too keen on the BIT()
> macros as this is not really a mask.
I'm not sure I got this. The << 16 neither a plain number and BIT() is equally
good. With power of two it's most likely that this is due to internal
implementation of the firmware or hardware, so again BIT() can be still good
enough to show that.
...
> > > + msleep(3200);
> >
> > Not a single letter to comment such a huge delay :-(
>
> Well, it's after doing a reset so it should be pretty obvious is the number
> given in the DS. But I'll put a comment on it.
Please do.
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2023-11-13 16:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-10 15:18 [PATCH 0/2] Add support for LTC4282 Nuno Sa
2023-11-10 15:18 ` [PATCH 1/2] dt-bindings: hwmon: Add LTC4282 bindings Nuno Sa
2023-11-10 18:42 ` Conor Dooley
2023-11-13 9:32 ` Nuno Sá
2023-11-13 20:12 ` Conor Dooley
2023-11-20 15:03 ` Guenter Roeck
2023-11-10 15:18 ` [PATCH 2/2] hwmon: ltc4282: add support for the LTC4282 chip Nuno Sa
2023-11-10 16:50 ` Andy Shevchenko
2023-11-13 10:13 ` Nuno Sá
2023-11-13 16:31 ` Andy Shevchenko [this message]
2023-11-14 8:36 ` Nuno Sá
2023-11-20 15:00 ` Guenter Roeck
2023-11-11 1:04 ` kernel test robot
2023-11-11 17:22 ` Guenter Roeck
2023-11-13 9:24 ` Nuno Sá
2023-11-20 12:10 ` Dan Carpenter
2023-11-20 14:52 ` Guenter Roeck
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=ZVJPbV2469kjqbHu@smile.fi.intel.com \
--to=andy@kernel.org \
--cc=brgl@bgdev.pl \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=jdelvare@suse.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linus.walleij@linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=noname.nuno@gmail.com \
--cc=nuno.sa@analog.com \
--cc=robh+dt@kernel.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