devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
To: Matti Vaittinen <mazziesaccount@gmail.com>,
	Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Marek Vasut <marex@denx.de>, Anshul Dalal <anshulusr@gmail.com>,
	Javier Carrasco <javier.carrasco.cruz@gmail.com>
Cc: Matt Ranostay <matt@ranostay.sg>,
	Stefan Windfeldt-Prytz <stefan.windfeldt-prytz@axis.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v8 5/5] iio: light: Add support for APDS9306 Light Sensor
Date: Thu, 29 Feb 2024 22:21:52 +1030	[thread overview]
Message-ID: <47739cca-db41-4182-9f80-ff138f5b8ec8@tweaklogic.com> (raw)
In-Reply-To: <a828e77c-b3d4-49bb-b0bb-b9fd6cb7d114@gmail.com>

On 28/2/24 23:38, Matti Vaittinen wrote:
> On 2/28/24 14:24, Subhajit Ghosh wrote:
>> Driver support for Avago (Broadcom) APDS9306 Ambient Light Sensor.
>> It has two channels - ALS and CLEAR. The ALS (Ambient Light Sensor)
>> channel approximates the response of the human-eye providing direct
>> read out where the output count is proportional to ambient light levels.
>> It is internally temperature compensated and rejects 50Hz and 60Hz flicker
>> caused by artificial light sources. Hardware interrupt configuration is
>> optional. It is a low power device with 20 bit resolution and has
>> configurable adaptive interrupt mode and interrupt persistence mode.
>> The device also features inbuilt hardware gain, multiple integration time
>> selection options and sampling frequency selection options.
>>
>> This driver also uses the IIO GTS (Gain Time Scale) Helpers Namespace for
>> Scales, Gains and Integration time implementation.
>>
>> Signed-off-by: Subhajit Ghosh <subhajit.ghosh@tweaklogic.com>
>> ---
>> v7 -> v8:
>>   - Renamed APDS9306_INT_CH_CLEAR to APDS9306_INT_SRC_CLEAR macro for higher
>>     readability
>>   - Removed APDS9306_CHANNEL macro for higher readability
>>   - Updated iio_push_event() functions with correct type of events (Light or Intensity)
>>   - Updated variable name "event_ch_is_light" to "int_src" and change as per
>>     review to fix compiler warning
>>   - Used scope for guard() functions
>>   - Other fixes as per reviews
>>     https://lore.kernel.org/all/20240224151340.3f2f51e8@jic23-huawei/
>>     https://lore.kernel.org/all/ZdycR6nr3rtrnuth@smile.fi.intel.com/
>>
...

Hi Matti,
>> ---
> 
> Hi Subhajit,
> 
> I just happened to notice couple of minor things. I see the series is already in a v8 and don't want to cause extra re-spins. So, perhaps consider these points if you need to do v9 but I am sending these only as 'nits'. I don't think any of my findings are very serious.
>Thank for reviewing. I will do as many re-spins as it takes to get things correct if required.
It is best possible source of learning for me.
> ...
> 
>> +static int apds9306_intg_time_set(struct apds9306_data *data, int val2)
>> +{
>> +    struct device *dev = data->dev;
>> +    struct apds9306_regfields *rf = &data->rf;
>> +    int ret, intg_old, gain_old, gain_new, gain_new_closest, intg_time_idx;
>> +    int gain_idx;
>> +    bool ok;
>> +
>> +    if (!iio_gts_valid_time(&data->gts, val2)) {
>> +        dev_err_ratelimited(dev, "Unsupported integration time %u\n", val2);
>> +        return -EINVAL;
>> +    }
>> +
>> +    ret = regmap_field_read(rf->intg_time, &intg_time_idx);
>> +    if (ret)
>> +        return ret;
>> +
>> +    ret = regmap_field_read(rf->gain, &gain_idx);
>> +    if (ret)
>> +        return ret;
>> +
>> +    intg_old = iio_gts_find_int_time_by_sel(&data->gts, intg_time_idx);
>> +    if (ret < 0)
>> +        return ret;
>> +
>> +    if (intg_old == val2)
>> +        return 0;
>> +
>> +    gain_old = iio_gts_find_gain_by_sel(&data->gts, gain_idx);
>> +    if (gain_old < 0)
>> +        return gain_old;
>> +
>> +    ret = iio_gts_find_new_gain_by_old_gain_time(&data->gts, gain_old,
>> +                             intg_old, val2, &gain_new);
> 
> You don't use the 'ret' here, so maybe for the clarity, not assign it.
> Or, maybe you wan't to try to squeeze out few cycles for succesful case and check the ret for '0' - in which case you should be able to omit the check right below as well as the call to iio_find_closest_gain_low(). OTOH, this is likely not a "hot path" so I don't care too much about the extra call if you think code is clearer this way.
I will stick to the first option and remove the unused ret. The code looks linear and clearer
that way. Although it depends upon further reviews.

Regards,
Subhajit Ghosh
> 
>> +    if (gain_new < 0) {
>> +        dev_err_ratelimited(dev, "Unsupported gain with time\n");
>> +        return gain_new;
>> +    }
>> +
>> +    gain_new_closest = iio_find_closest_gain_low(&data->gts, gain_new, &ok);
>> +    if (gain_new_closest < 0) {
>> +        gain_new_closest = iio_gts_get_min_gain(&data->gts);
>> +        if (gain_new_closest < 0)
>> +            return gain_new_closest;
>> +    }
>> +    if (!ok)
>> +        dev_dbg(dev, "Unable to find optimum gain, setting minimum");
>> +
>> +    ret = iio_gts_find_sel_by_int_time(&data->gts, val2);
>> +    if (ret < 0)
>> +        return ret;
>> +
>> +    ret = regmap_field_write(rf->intg_time, ret);
>> +    if (ret)
>> +        return ret;
>> +
>> +    ret = iio_gts_find_sel_by_gain(&data->gts, gain_new_closest);
>> +    if (ret < 0)
>> +        return ret;
>> +
>> +    return regmap_field_write(rf->gain, ret);
>> +}
> 
> 


  parent reply	other threads:[~2024-02-29 11:52 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-28 12:24 [PATCH v8 0/5] Support for Avago APDS9306 Ambient Light Sensor Subhajit Ghosh
2024-02-28 12:24 ` [PATCH v8 1/5] dt-bindings: iio: light: Merge APDS9300 and APDS9960 schemas Subhajit Ghosh
2024-02-28 12:24 ` [PATCH v8 2/5] dt-bindings: iio: light: adps9300: Add missing vdd-supply Subhajit Ghosh
2024-02-28 12:24 ` [PATCH v8 3/5] dt-bindings: iio: light: adps9300: Update interrupt definitions Subhajit Ghosh
2024-02-28 12:24 ` [PATCH v8 4/5] dt-bindings: iio: light: Avago APDS9306 Subhajit Ghosh
2024-02-28 12:24 ` [PATCH v8 5/5] iio: light: Add support for APDS9306 Light Sensor Subhajit Ghosh
2024-02-28 13:08   ` Matti Vaittinen
2024-02-28 17:27     ` Andy Shevchenko
2024-02-29 12:34       ` Subhajit Ghosh
2024-02-29 12:58         ` Matti Vaittinen
2024-02-29 13:42           ` Andy Shevchenko
2024-02-29 15:35             ` Matti Vaittinen
2024-03-03 14:55               ` Jonathan Cameron
2024-02-29 11:51     ` Subhajit Ghosh [this message]
2024-03-03 15:14   ` Jonathan Cameron
2024-03-04 12:48     ` Subhajit Ghosh

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=47739cca-db41-4182-9f80-ff138f5b8ec8@tweaklogic.com \
    --to=subhajit.ghosh@tweaklogic.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=anshulusr@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=javier.carrasco.cruz@gmail.com \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=matt@ranostay.sg \
    --cc=mazziesaccount@gmail.com \
    --cc=robh+dt@kernel.org \
    --cc=stefan.windfeldt-prytz@axis.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;
as well as URLs for NNTP newsgroup(s).