[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <9927c607-5740-406a-8cd6-0550e8b92038@wanadoo.fr>
Date: Sat, 3 Aug 2024 21:42:38 +0200
From: Christophe JAILLET <christophe.jaillet@...adoo.fr>
To: abhashkumarjha123@...il.com
Cc: anshulusr@...il.com, jic23@...nel.org, lars@...afoo.de,
linux-iio@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH v6 1/2] iio: light: ltr390: Add ALS channel and support
for gain and resolution
Le 03/08/2024 à 20:09, Abhash Jha a écrit :
> Add new ALS channel and allow reading lux and scale values.
> Also provide gain and resolution configuration for ALS channel.
> Add automatic mode switching between the UVS and ALS channel
> based on which channel is being accessed.
> The default mode in which the sensor start is ALS mode.
>
> Signed-off-by: Abhash Jha <abhashkumarjha123-Re5JQEeQqe8AvxtiuMwx3w@...lic.gmane.org>
> ---
Hi,
...
> @@ -95,6 +101,25 @@ static int ltr390_register_read(struct ltr390_data *data, u8 register_address)
> return get_unaligned_le24(recieve_buffer);
> }
>
> +static int ltr390_set_mode(struct ltr390_data *data, enum ltr390_mode mode)
> +{
> + if (data->mode == mode)
> + return 0;
> +
> + switch (mode) {
> + case LTR390_SET_ALS_MODE:
> + regmap_clear_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_UVS_MODE);
Should this be:
ret = regmap_clear_bits();
if (ret)
return ret;
?
Otherwise, 0 is returned in all cases and ltr390_read_raw() could be
simplified.
> + break;
> +
> + case LTR390_SET_UVS_MODE:
> + regmap_set_bits(data->regmap, LTR390_MAIN_CTRL, LTR390_UVS_MODE);
Same.
> + break;
> + }
> +
> + data->mode = mode;
> + return 0;
> +}
> +
> static int ltr390_read_raw(struct iio_dev *iio_device,
> struct iio_chan_spec const *chan, int *val,
> int *val2, long mask)
> @@ -105,15 +130,47 @@ static int ltr390_read_raw(struct iio_dev *iio_device,
> guard(mutex)(&data->lock);
> switch (mask) {
> case IIO_CHAN_INFO_RAW:
> - ret = ltr390_register_read(data, LTR390_UVS_DATA);
> - if (ret < 0)
> - return ret;
> + switch (chan->type) {
> + case IIO_UVINDEX:
> + ret = ltr390_set_mode(data, LTR390_SET_UVS_MODE);
> + if (ret < 0)
> + return ret;
> +
> + ret = ltr390_register_read(data, LTR390_UVS_DATA);
> + if (ret < 0)
> + return ret;
> + break;
> +
> + case IIO_LIGHT:
> + ret = ltr390_set_mode(data, LTR390_SET_ALS_MODE);
> + if (ret < 0)
> + return ret;
> +
> + ret = ltr390_register_read(data, LTR390_ALS_DATA);
> + if (ret < 0)
> + return ret;
> + break;
...
CJ
Powered by blists - more mailing lists