Linux IIO development
 help / color / mirror / Atom feed
From: "Javier Carrasco" <javier.carrasco.cruz@gmail.com>
To: "Christophe JAILLET" <christophe.jaillet@wanadoo.fr>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Christian Eggers" <ceggers@arri.de>
Cc: "Jonathan Cameron" <Jonathan.Cameron@huawei.com>,
	<linux-iio@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<stable@vger.kernel.org>
Subject: Re: [PATCH v3] iio: light: as73211: fix channel handling in only-color triggered buffer
Date: Thu, 12 Dec 2024 19:48:16 +0100	[thread overview]
Message-ID: <D69Y31IERSV2.1R9057MJA27NS@gmail.com> (raw)
In-Reply-To: <e8564c63-0c2b-4327-8e39-767530b29b11@wanadoo.fr>

Hi Christophe, thank you for your prompt feedback.

On Thu Dec 12, 2024 at 7:15 PM CET, Christophe JAILLET wrote:
> Le 12/12/2024 à 18:56, Javier Carrasco a écrit :
> > The channel index is off by one unit if AS73211_SCAN_MASK_ALL is not
> > set (optimized path for color channel readings), and it must be shifted
> > instead of leaving an empty channel for the temperature when it is off.
> >
> > Once the channel index is fixed, the uninitialized channel must be set
> > to zero to avoid pushing uninitialized data.
> >
> > Add available_scan_masks for all channels and only-color channels to let
> > the IIO core demux and repack the enabled channels.
> >
> > Cc: stable@vger.kernel.org
> > Fixes: 403e5586b52e ("iio: light: as73211: New driver")
> > Tested-by: Christian Eggers <ceggers@arri.de>
> > Signed-off-by: Javier Carrasco <javier.carrasco.cruz@gmail.com>
>
> ...
>
> > diff --git a/drivers/iio/light/as73211.c b/drivers/iio/light/as73211.c
> > index be0068081ebb..4be2e349a068 100644
> > --- a/drivers/iio/light/as73211.c
> > +++ b/drivers/iio/light/as73211.c
> > @@ -177,6 +177,12 @@ struct as73211_data {
> >   	BIT(AS73211_SCAN_INDEX_TEMP) | \
> >   	AS73211_SCAN_MASK_COLOR)
> >
> > +static const unsigned long as73211_scan_masks[] = {
> > +	AS73211_SCAN_MASK_ALL,
> > +	AS73211_SCAN_MASK_COLOR,
> > +	0,
> > +};
> > +
> >   static const struct iio_chan_spec as73211_channels[] = {
> >   	{
> >   		.type = IIO_TEMP,
> > @@ -672,9 +678,12 @@ static irqreturn_t as73211_trigger_handler(int irq __always_unused, void *p)
> >
> >   		/* AS73211 starts reading at address 2 */
>
> Should this comment be updated?
>
> Or maybe moved close to "if (*indio_dev->active_scan_mask ==
> AS73211_SCAN_MASK_ALL)" below?
>

The comment is still true, as address = 1 stores the temperature, and
the first color value can be found at address = 2. I think it used to
be more relevant (even if it was not the correct approach) when the
first received element was stored in chan[1]. Nevertheless, as it might
not be obvious without knowing the address map, it could stay where it
is.

> >   		ret = i2c_master_recv(data->client,
> > -				(char *)&scan.chan[1], 3 * sizeof(scan.chan[1]));
> > +				(char *)&scan.chan[0], 3 * sizeof(scan.chan[0]));
> >   		if (ret < 0)
> >   			goto done;
> > +
> > +		/* Avoid pushing uninitialized data */
> > +		scan.chan[3] = 0;
> >   	}
> >
> >   	if (data_result) {
> > @@ -682,9 +691,15 @@ static irqreturn_t as73211_trigger_handler(int irq __always_unused, void *p)
> >   		 * Saturate all channels (in case of overflows). Temperature channel
> >   		 * is not affected by overflows.
> >   		 */
> > -		scan.chan[1] = cpu_to_le16(U16_MAX);
> > -		scan.chan[2] = cpu_to_le16(U16_MAX);
> > -		scan.chan[3] = cpu_to_le16(U16_MAX);
> > +		if (*indio_dev->active_scan_mask == AS73211_SCAN_MASK_ALL) {
>
> Should [0]...
>
> > +			scan.chan[1] = cpu_to_le16(U16_MAX);
> > +			scan.chan[2] = cpu_to_le16(U16_MAX);
> > +			scan.chan[3] = cpu_to_le16(U16_MAX);
> > +		} else {
> > +			scan.chan[0] = cpu_to_le16(U16_MAX);
> > +			scan.chan[1] = cpu_to_le16(U16_MAX);
> > +			scan.chan[2] = cpu_to_le16(U16_MAX);
>
> ... and [3] be forced as-well?
> (just a blind guess)
>
> CJ
>

in the first case (all channels are read), the temperature (scan[0])
only has 12 bits, and there are no overflows. In the second case,
scan.chan[3] is set to zero as it is not used, and there is no need to
force the U16_MAX value.

Best regards,
Javier Carrasco

  reply	other threads:[~2024-12-12 18:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-12 17:56 [PATCH v3] iio: light: as73211: fix channel handling in only-color triggered buffer Javier Carrasco
2024-12-12 18:15 ` Christophe JAILLET
2024-12-12 18:48   ` Javier Carrasco [this message]
2024-12-14 14:22 ` Jonathan Cameron
2024-12-14 15:16   ` Javier Carrasco

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=D69Y31IERSV2.1R9057MJA27NS@gmail.com \
    --to=javier.carrasco.cruz@gmail.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=ceggers@arri.de \
    --cc=christophe.jaillet@wanadoo.fr \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.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