mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Javier Carrasco" <javier.carrasco.cruz@gmail.com>
To: "Per-Daniel Olsson" <perdaniel.olsson@axis.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>
Cc: <linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<devicetree@vger.kernel.org>, <rickard.andersson@axis.com>,
	<kernel@axis.com>
Subject: Re: [PATCH v6 2/2] iio: light: Add support for TI OPT4060 color sensor
Date: Thu, 21 Nov 2024 13:50:24 +0100	[thread overview]
Message-ID: <D5RVBLKL19B7.3JUQKEVC5T0HF@gmail.com> (raw)
In-Reply-To: <20241120163247.2791600-3-perdaniel.olsson@axis.com>

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@axis.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

      reply	other threads:[~2024-11-21 12:50 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-20 16:32 [PATCH v6 0/2] Support for Texas Instruments OPT4060 RGBW Color sensor Per-Daniel Olsson
2024-11-20 16:32 ` [PATCH v6 1/2] dt-bindings: iio: light: Document TI OPT4060 RGBW sensor Per-Daniel Olsson
2024-11-21 12:33   ` Javier Carrasco
2024-11-20 16:32 ` [PATCH v6 2/2] iio: light: Add support for TI OPT4060 color sensor Per-Daniel Olsson
2024-11-21 12:50   ` Javier Carrasco [this message]

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=D5RVBLKL19B7.3JUQKEVC5T0HF@gmail.com \
    --to=javier.carrasco.cruz@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=kernel@axis.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=perdaniel.olsson@axis.com \
    --cc=rickard.andersson@axis.com \
    --cc=robh@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

all inboxes | Powered by JetHome®