Re: [PATCH v6 1/2] iio: light: ltr390: Add ALS channel and support for gain and resolution

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxxxx>
---

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





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux