From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>,
Lars-Peter Clausen <lars@metafoo.de>,
Paul Gazzillo <paul@pgazz.com>,
Zhigang Shi <Zhigang.Shi@liteon.com>,
Shreeya Patel <shreeya.patel@collabora.com>,
Dmitry Osipenko <dmitry.osipenko@collabora.com>,
linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org
Subject: Re: [PATCH v2 5/6] iio: light: ROHM BU27034 Ambient Light Sensor
Date: Sat, 4 Mar 2023 22:28:43 +0200 [thread overview]
Message-ID: <9c62d3f1-7d07-a695-67a0-f4a373e96073@gmail.com> (raw)
In-Reply-To: <20230304190254.2ea052eb@jic23-huawei>
On 3/4/23 21:02, Jonathan Cameron wrote:
>>> ...
>>>
>>>> +/*
>>>> + * Available scales with gain 1x - 4096x, timings 55, 100, 200, 400 mS
>>>> + * Time impacts to gain: 1x, 2x, 4x, 8x.
>>>> + *
>>>> + * => Max total gain is HWGAIN * gain by integration time (8 * 4096) = 32768
>>>> + *
>>>> + * Using NANO precision for scale we must use scale 64x corresponding gain 1x
>>>> + * to avoid precision loss. (32x would result scale 976 562.5(nanos).
>>>> + */
>>>> +#define BU27034_SCALE_1X 64
>>>> +
>>>> +#define BU27034_GSEL_1X 0x00
>>>> +#define BU27034_GSEL_4X 0x08
>>>> +#define BU27034_GSEL_16X 0x0a
>>>> +#define BU27034_GSEL_32X 0x0b
>>>> +#define BU27034_GSEL_64X 0x0c
>>>> +#define BU27034_GSEL_256X 0x18
>>>> +#define BU27034_GSEL_512X 0x19
>>>> +#define BU27034_GSEL_1024X 0x1a
>>>> +#define BU27034_GSEL_2048X 0x1b
>>>> +#define BU27034_GSEL_4096X 0x1c
>>>
>>> Shouldn't the values be in plain decimal?
>>
>> Why?
>
> Normally go with datasheet on this as it makes reviewer simpler.
> But datasheet is in binary so meh.
>
>>
>>> Otherwise I would like to understand bit mapping inside these hex values.
>>
>> I like having register values in hex. It makes it obvious they don't
>> necessarily directly match any 'real world' human-readable values.
>
> Perhaps a cross reference to the table in the spec is appropriate here?
I think adding a reference to the table in the data-sheet is good.
Although - I gave some feedback about the data-sheet inside the company.
It may be we will eventually see another version of it...
> whilst there are some patterns they aren't terribly consistent so probably
> best to just point at the table in the spec.
>
>
>>>> + if (helper64 < 0xFFFFFFFFFFFFFLLU) {
>>>
>>> Perhaps this needs a definition.
>>
>> I like seeing the value here. It makes this less obfuscating. Comment
>> makes the purpose obvious so adding a define would not really give any
>> extra advantage.
>
> It's not immediately obvious why it is that many f's. Perhaps change
> to refer to number of bits (which is what matters really I think)
> and then use GENMASK() to fill this in? I think it's 52 bits?
I am personally not used to the GENMASK(). I am always wondering whether
the parameters were start + end bits, or star bit + number of set bits
or ... It's somehow easier for me to understand the hex values -
(especially when they are composed of all fff's or 1, 3, 7 or 2, 4, 8 ... ).
Well, I understand that is not universally true though so GENMASK() can
for sure be simpler for most others - and it does not hide the value as
define would do. So yes, GENMASK() could make sense here.
>>>> + helper64 *= gain0;
>>>> + do_div(helper64, ch0);
>>>> + } else {
>>>> + do_div(helper64, ch0);
>>>> + helper64 *= gain0;
>>>> + }
>
>>>
>>> ...> >> + if (!res[0])
>>>
>>> Positive conditional?
>>
>> No. Again, we check for the very specific case where res has all bits
>> zeroed. Inverse condition is counter intuitive.
>>
>>>
>>>> + ch0 = 1;
>>>> + else
>>>> + ch0 = le16_to_cpu(res[0]);
>>>> +
>>>> + if (!res[1])
>>>> + ch1 = 1;
>>>
>>> Ditto.
>>>
>>>> + else
>>>> + ch1 = le16_to_cpu(res[1]);
>>>
>>> But why not to read and convert first and then check.
>>
>> Because conversion is not needed if channel data is zero.
>
> Conversion is trivial. I agree with Andy here that the logic would look
> a bit simpler as (taking it a little further)
>
> ch0 = max(1, le16_to_cpu(res[0]));
It's strange how differently we read the code. For me:
if (!val)
ch = 1;
else
ch = le16_to_cpu(val);
tells what is happening at a glance whereas the:
ch0 = max(1, le16_to_cpu(res[0]));
really requires some focusing to see what is going on. For me it is both
less clear and less efficient :(
But alas, if this is what is preferred by both of you, then I guess
that's what it will look like.
>>>
>>>> + switch (mask) {
>>>> + case IIO_CHAN_INFO_INT_TIME:
>>>> + return iio_gts_avail_times(&data->gts, vals, type, length);
>>>> + case IIO_CHAN_INFO_SCALE:
>>>> + return iio_gts_all_avail_scales(&data->gts, vals, type, length);
>>>> + default:
>>>> + break;
>>>> + }
>>>> +
>>>> + return -EINVAL;
>>>
>>> You may do it from default case.
>>>
>>
>> I think we have discussed this one in the past too. I like having return
>> at the end of a non void function.
>
> Given all the earlier returns and the fact that the compiler will shout at
> you if it you can get here and it is missing, I'd also suggest just putting
> it in the switch statement.
Ok. IIO is your territory. If the roles were switched I would definitely
ask for having the returns at the end of the function - and at the end
of the function only (when possible w/o lot of extra complication).
So perhaps I just have to accept that you want to have it your way with
IIO :)
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
next prev parent reply other threads:[~2023-03-04 20:28 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-02 10:57 [PATCH v2 0/6] Support ROHM BU27034 ALS sensor Matti Vaittinen
2023-03-02 10:57 ` [PATCH v2 1/6] dt-bindings: iio: light: Support ROHM BU27034 Matti Vaittinen
2023-03-02 10:57 ` [PATCH v2 2/6] iio: light: Add gain-time-scale helpers Matti Vaittinen
2023-03-02 15:05 ` Andy Shevchenko
2023-03-03 7:54 ` Vaittinen, Matti
2023-03-06 11:13 ` Andy Shevchenko
2023-03-13 11:31 ` Matti Vaittinen
2023-03-13 14:39 ` Andy Shevchenko
2023-03-14 10:28 ` Matti Vaittinen
2023-03-14 11:31 ` Andy Shevchenko
2023-03-14 11:36 ` Andy Shevchenko
2023-03-15 7:20 ` Vaittinen, Matti
2023-03-18 16:49 ` Jonathan Cameron
2023-03-04 18:35 ` Jonathan Cameron
2023-03-04 19:42 ` Matti Vaittinen
2023-03-06 11:15 ` Andy Shevchenko
2023-03-02 10:58 ` [PATCH v2 3/6] iio: test: test " Matti Vaittinen
2023-03-02 10:58 ` [PATCH v2 4/6] MAINTAINERS: Add IIO " Matti Vaittinen
2023-03-02 10:58 ` [PATCH v2 5/6] iio: light: ROHM BU27034 Ambient Light Sensor Matti Vaittinen
2023-03-02 14:17 ` Matti Vaittinen
2023-03-02 15:34 ` Andy Shevchenko
2023-03-03 9:17 ` Matti Vaittinen
2023-03-04 19:02 ` Jonathan Cameron
2023-03-04 20:28 ` Matti Vaittinen [this message]
2023-03-04 20:17 ` Jonathan Cameron
2023-03-05 12:22 ` Matti Vaittinen
2023-03-12 15:36 ` Jonathan Cameron
2023-03-13 9:39 ` Matti Vaittinen
2023-03-18 16:54 ` Jonathan Cameron
2023-03-19 15:59 ` Matti Vaittinen
2023-03-14 9:39 ` Matti Vaittinen
2023-03-18 16:57 ` Jonathan Cameron
2023-03-05 13:10 ` Matti Vaittinen
2023-03-06 11:21 ` Andy Shevchenko
2023-03-13 8:54 ` Matti Vaittinen
2023-03-02 10:59 ` [PATCH v2 6/6] MAINTAINERS: Add ROHM BU27034 Matti Vaittinen
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=9c62d3f1-7d07-a695-67a0-f4a373e96073@gmail.com \
--to=mazziesaccount@gmail.com \
--cc=Zhigang.Shi@liteon.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=dmitry.osipenko@collabora.com \
--cc=jic23@kernel.org \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=matti.vaittinen@fi.rohmeurope.com \
--cc=paul@pgazz.com \
--cc=shreeya.patel@collabora.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