[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-Id: <D5RVBLKL19B7.3JUQKEVC5T0HF@gmail.com>
Date: Thu, 21 Nov 2024 13:50:24 +0100
From: "Javier Carrasco" <javier.carrasco.cruz@...il.com>
To: "Per-Daniel Olsson" <perdaniel.olsson@...s.com>, "Jonathan Cameron"
<jic23@...nel.org>, "Lars-Peter Clausen" <lars@...afoo.de>, "Rob Herring"
<robh@...nel.org>, "Krzysztof Kozlowski" <krzk+dt@...nel.org>, "Conor
Dooley" <conor+dt@...nel.org>
Cc: <linux-iio@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<devicetree@...r.kernel.org>, <rickard.andersson@...s.com>,
<kernel@...s.com>
Subject: Re: [PATCH v6 2/2] iio: light: Add support for TI OPT4060 color
sensor
Hello Per-Daniel,
A few minor comments inline, LGTM in general.
On Wed Nov 20, 2024 at 5:32 PM CET, Per-Daniel Olsson wrote:
> Add support for Texas Instruments OPT4060 RGBW Color sensor.
>
> Signed-off-by: Per-Daniel Olsson <perdaniel.olsson@...s.com>
...
> + * Function for calculating color components independent of light intensity. The
> + * raw values are multiplied by individual factors that correspond to the
> + * sensitivity of the different color filters. The returned value is normalized.
> + */
> +static int opt4060_read_chan_scale(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int *val, int *val2)
> +{
> + struct opt4060_chip *chip = iio_priv(indio_dev);
> + static const u32 color_factors[] = { 24, 10, 13 };
> + u32 adc_raw[3], sum = 0, rem;
> + int ret;
> +
> + ret = opt4060_trigger_new_samples(indio_dev);
> + if (ret) {
> + dev_err(chip->dev, "Failed to trigger new samples.\n");
> + return ret;
> + }
> +
> + for (int color = OPT4060_RED; color <= OPT4060_BLUE; color++) {
Nit: no need for parenthesis around adc_raw[color].
> + ret = opt4060_read_raw_value(chip, indio_dev->channels[color].address,
> + &(adc_raw[color]));
> + if (ret) {
> + dev_err(chip->dev, "Reading raw channel data failed\n");
> + return ret;
> + }
> + adc_raw[color] *= color_factors[color];
> + sum += adc_raw[color];
> + }
> + *val = div_u64_rem((u64)adc_raw[chan->scan_index], sum, &rem);
> + *val2 = DIV_U64_ROUND_CLOSEST((u64)(rem * MICRO), sum);
> + return IIO_VAL_INT_PLUS_MICRO;
> +}
> +
Nit: wrong alignment in the second line of the arguments.
> +static ssize_t opt4060_read_ev_period(struct opt4060_chip *chip, int *val,
> + int *val2)
> +{
> + int ret, pers, fault_count, int_time;
> + u64 uval;
> +
> + int_time = opt4060_int_time_reg[chip->int_time][0];
> +
> + ret = regmap_read(chip->regmap, OPT4060_CTRL, &fault_count);
> + if (ret < 0)
> + return ret;
> +
> + fault_count = fault_count & OPT4060_CTRL_FAULT_COUNT_MASK;
> + switch (fault_count) {
> + case OPT4060_CTRL_FAULT_COUNT_2:
> + pers = 2;
> + break;
> + case OPT4060_CTRL_FAULT_COUNT_4:
> + pers = 4;
> + break;
> + case OPT4060_CTRL_FAULT_COUNT_8:
> + pers = 8;
> + break;
> +
> + default:
> + pers = 1;
> + break;
> + }
> +
> + uval = mul_u32_u32(int_time, pers);
> + *val = div_u64_rem(uval, MICRO, val2);
> +
> + return IIO_VAL_INT_PLUS_MICRO;
> +}
> +
Same here.
> +static ssize_t opt4060_write_ev_period(struct opt4060_chip *chip, int val,
> + int val2)
> +{
Note that state has become a bool, so if a new version of this driver is
required, please use a newer base (e.g. linux-next, iio/testing) to
avoid future issues.
> +static int opt4060_write_event_config(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + enum iio_event_type type,
> + enum iio_event_direction dir, int state)
> +{
> + int ch_sel, ch_idx = chan->scan_index;
> + struct opt4060_chip *chip = iio_priv(indio_dev);
> + int ret;
Best regards,
Javier Carrasco
Powered by blists - more mailing lists