From: Jonathan Cameron <jic23@kernel.org>
To: Shreeya Patel <shreeya.patel@collabora.com>
Cc: lars@metafoo.de, robh+dt@kernel.org, Zhigang.Shi@liteon.com,
krisman@collabora.com, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel@collabora.com, alvaro.soliverez@collabora.com
Subject: Re: [PATCH 3/3] iio: light: Add support for ltrf216a sensor
Date: Sat, 2 Apr 2022 17:49:03 +0100 [thread overview]
Message-ID: <20220402174903.035f1181@jic23-huawei> (raw)
In-Reply-To: <ffcdf821-38f2-f8d7-2bcd-8ea51cad1b96@collabora.com>
On Wed, 30 Mar 2022 01:33:19 +0530
Shreeya Patel <shreeya.patel@collabora.com> wrote:
> On 27/03/22 20:00, Jonathan Cameron wrote:
>
> Hi Jonathan,
>
> Thanks for your detailed review. I am working on v2 with the modifications
> suggested by you.
>
> Just one comment inline.
>
...
> >> +static int ltrf216a_set_it_time(struct ltrf216a_data *data, int itime)
> >> +{
> >> + int i, ret, index = -1;
> >> + u8 reg;
> >> +
> >> + for (i = 0; i < ARRAY_SIZE(int_time_mapping); i++) {
> >> + if (int_time_mapping[i] == itime) {
> >> + index = i;
> >> + break;
> >> + }
> >> + }
> >> + /* Make sure integration time index is valid */
> >> + if (index < 0)
> >> + return -EINVAL;
> >> +
> >> + if (index == 0) {
> > Switch statement seems more appropriate than this stack of if else
> >
> >> + reg = 0x03;
> > reg isn't a great name as I assume this is the value, not the address
> > which was my first thought... Perhaps reg_val?
> >> + data->int_time_fac = 4;
> >> + } else if (index == 1) {
> >> + reg = 0x13;
> >> + data->int_time_fac = 2;
> >> + } else {
> >> + reg = (index << 4) | 0x02;
> > Unless I'm missing something index == 2 if we get here.
> > So why the calculation? I'd suggest defining the two fields and using
> > FIELD_PREP() to set up each part probably to one of a set of
> > #define LTRF216A_ALS_MEAS_RATE_
>
> I think the calculation here is to set the default value when the
> integration time = 1.
1 isn't a possible value in int_time_available.
I guess you mean 100ms in which case if this were a switch statement
switch (index) {
case 0: /* 400msec */
reg = 0x03;
data->int_time_fac = 4;
break;
case 1: /* 200msec */
reg = 0x13;
data->int_time_fac = 2;
break;
case 2: /* 100sec */
reg = 0x22;
data->int_time_fac = 1;
break;
}
btw from datasheet, 50ms and 25ms also seem possible, why not support them?
Note the switch might be better handled as a constant look up table of appropriate
structures.
> In this case, reg value will be 34 (0x22) which
> is the default value of ALS_MEAS_RATE register.
>
> I will still confirm it once from Zhigang before sending a v2.
>
> >> + data->int_time_fac = 1;
> >> + }
> >> +
>
Jonathan
next prev parent reply other threads:[~2022-04-02 16:41 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-25 10:30 [PATCH 0/3] Add LTRF216A Driver Shreeya Patel
2022-03-25 10:30 ` [PATCH 1/3] dt-bindings: vendor-prefixes: Add 'ltr' as deprecated vendor prefix Shreeya Patel
2022-03-25 12:21 ` Krzysztof Kozlowski
2022-03-25 10:30 ` [PATCH 2/3] dt-bindings: Document ltrf216a light sensor bindings Shreeya Patel
2022-03-25 12:23 ` Krzysztof Kozlowski
2022-03-27 13:55 ` Jonathan Cameron
2022-03-28 2:49 ` Gabriel Krisman Bertazi
2022-03-25 10:30 ` [PATCH 3/3] iio: light: Add support for ltrf216a sensor Shreeya Patel
2022-03-25 12:25 ` Krzysztof Kozlowski
2022-03-27 14:30 ` Jonathan Cameron
2022-03-29 20:03 ` Shreeya Patel
2022-04-02 16:49 ` Jonathan Cameron [this message]
2022-04-11 17:06 ` Shreeya Patel
2022-04-12 14:06 ` Gabriel Krisman Bertazi
2022-04-12 14:53 ` Jonathan Cameron
2022-03-28 3:59 ` Gabriel Krisman Bertazi
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=20220402174903.035f1181@jic23-huawei \
--to=jic23@kernel.org \
--cc=Zhigang.Shi@liteon.com \
--cc=alvaro.soliverez@collabora.com \
--cc=devicetree@vger.kernel.org \
--cc=kernel@collabora.com \
--cc=krisman@collabora.com \
--cc=lars@metafoo.de \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@kernel.org \
--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