Skip to contentSkip to conversation

iio: light: Add raw attribute

PATCH Superseded Shreeya Patel 3 participants 5 messages Aug 11, 2022 IIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iio: light: Add raw attribute

Add IIO_CHAN_INFO_RAW to the mask to be able to read raw values from the light sensor.

---
 drivers/iio/light/ltrf216a.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/iio/light/ltrf216a.c +13 -0
index e6e24e70d2b9..a717bf99bd2a 100644
@@ -93,6 +93,7 @@ static const struct iio_chan_spec ltrf216a_channels[] = {
 	{
 		.type = IIO_LIGHT,
 		.info_mask_separate =
+			BIT(IIO_CHAN_INFO_RAW) |
 			BIT(IIO_CHAN_INFO_PROCESSED) |
 			BIT(IIO_CHAN_INFO_INT_TIME),
 		.info_mask_separate_available =
@@ -259,6 +260,18 @@ static int ltrf216a_read_raw(struct iio_dev *indio_dev,
 	int ret;
 
 	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = ltrf216a_set_power_state(data, true);
+		if (ret)
+			return ret;
+		mutex_lock(&data->lock);
+		ret = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
+		mutex_unlock(&data->lock);
+		if (ret < 0)
+			return ret;
+		*val = ret;
+		ltrf216a_set_power_state(data, false);
+		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_PROCESSED:
 		mutex_lock(&data->lock);
 		ret = ltrf216a_get_lux(data);
Signature · 1 line
2.30.2
#1 lore raw

drivers/iio/light/ltrf216a.c static int ltrf216a_read_raw(struct iio_dev *indio_dev, · line 269

Quoted 7 lines · Shreeya Patel
drivers/iio/light/ltrf216a.c +7 -0
+	case IIO_CHAN_INFO_RAW:
+		ret = ltrf216a_set_power_state(data, true);
+		if (ret)
+			return ret;
+		mutex_lock(&data->lock);
+		ret = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
+		mutex_unlock(&data->lock);

ltrf216a_set_power_state(data, false) should be called before return.

Quoted 4 lines
drivers/iio/light/ltrf216a.c +4 -0
+		if (ret < 0)
+			return ret;
+		*val = ret;
+		ltrf216a_set_power_state(data, false);
Signature · 2 lines
Best regards,
Dmitry
#2 lore raw
Quoted 9 lines · Dmitry Osipenko

drivers/iio/light/ltrf216a.c static int ltrf216a_read_raw(struct iio_dev *indio_dev, · line 269

Quoted 7 lines · Shreeya Patel
drivers/iio/light/ltrf216a.c +7 -0
+	case IIO_CHAN_INFO_RAW:
+		ret = ltrf216a_set_power_state(data, true);
+		if (ret)
+			return ret;
+		mutex_lock(&data->lock);
+		ret = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
+		mutex_unlock(&data->lock);

ltrf216a_set_power_state(data, false) should be called before return.

ah! yes, missed that. Thanks for pointing out. I'll send a v2.

Thanks,
Shreeya Patel

Quoted 5 lines
Quoted 4 lines
drivers/iio/light/ltrf216a.c +4 -0
+		if (ret < 0)
+			return ret;
+		*val = ret;
+		ltrf216a_set_power_state(data, false);
#3 lore raw
In reply to Shreeya Patel
Quoted 2 lines · On Thu, 11 Aug 2022 15:44:43 +0530 Shreeya Patel <[email protected]>…

Add IIO_CHAN_INFO_RAW to the mask to be able to read raw values from the light sensor.

Why is this useful? It's rare to support _PROCESSED and _RAW for the same channel. Normally occurred to avoid breaking ABI.

Jonathan

Quoted 37 lines
---
 drivers/iio/light/ltrf216a.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
drivers/iio/light/ltrf216a.c +13 -0
index e6e24e70d2b9..a717bf99bd2a 100644
@@ -93,6 +93,7 @@ static const struct iio_chan_spec ltrf216a_channels[] = {
 	{
 		.type = IIO_LIGHT,
 		.info_mask_separate =
+			BIT(IIO_CHAN_INFO_RAW) |
 			BIT(IIO_CHAN_INFO_PROCESSED) |
 			BIT(IIO_CHAN_INFO_INT_TIME),
 		.info_mask_separate_available =
@@ -259,6 +260,18 @@ static int ltrf216a_read_raw(struct iio_dev *indio_dev,
 	int ret;
 
 	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = ltrf216a_set_power_state(data, true);
+		if (ret)
+			return ret;
+		mutex_lock(&data->lock);
+		ret = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
+		mutex_unlock(&data->lock);
+		if (ret < 0)
+			return ret;
+		*val = ret;
+		ltrf216a_set_power_state(data, false);
+		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_PROCESSED:
 		mutex_lock(&data->lock);
 		ret = ltrf216a_get_lux(data);
#4 lore raw
Quoted 7 lines · Jonathan Cameron
Quoted 2 lines · On Thu, 11 Aug 2022 15:44:43 +0530 Shreeya Patel <[email protected]>…

Add IIO_CHAN_INFO_RAW to the mask to be able to read raw values from the light sensor.

Why is this useful? It's rare to support _PROCESSED and _RAW for the same channel. Normally occurred to avoid breaking ABI.

Hi Jonathan,

For some context, we have been using a downstream driver for ltrf216a in steam deck. The formula for Lux calculation used in that driver is incorrect which we corrected in the driver that has been upstreamed now.

The userspace code to handle brightness on steam deck uses the in_illuminance_input value from sysfs and multiplies that value with some constant stored in BIOS at factory calibration time.

With the Lux calculation change in upstreamed driver, in_illuminance_input gives us a different value leading to change in the brightness on steam deck. It is also not possible for us to recalculate the constant stored in BIOS.

We need a way to add some magic in userspace code so that brightness adjustment works like before. So I'm trying to calculate a constant using the current formula that we are using :-
( greendata * 45 * LTRF216A_WIN_FAC ) / ( data->als_data_gain * data->int_time_fac)

Except for the greendata which is ALS_DATA, I have all the other values to calculate a constant, hence, I added RAW attribute so I can read the ALS_DATA value from userspace.

Thanks,
Shreeya Patel

Quoted 39 lines

Jonathan

Quoted 36 lines
---
  drivers/iio/light/ltrf216a.c | 13 +++++++++++++
  1 file changed, 13 insertions(+)
drivers/iio/light/ltrf216a.c +13 -0
index e6e24e70d2b9..a717bf99bd2a 100644
@@ -93,6 +93,7 @@ static const struct iio_chan_spec ltrf216a_channels[] = {
  	{
  		.type = IIO_LIGHT,
  		.info_mask_separate =
+			BIT(IIO_CHAN_INFO_RAW) |
  			BIT(IIO_CHAN_INFO_PROCESSED) |
  			BIT(IIO_CHAN_INFO_INT_TIME),
  		.info_mask_separate_available =
@@ -259,6 +260,18 @@ static int ltrf216a_read_raw(struct iio_dev *indio_dev,
  	int ret;
 
  	switch (mask) {
+	case IIO_CHAN_INFO_RAW:
+		ret = ltrf216a_set_power_state(data, true);
+		if (ret)
+			return ret;
+		mutex_lock(&data->lock);
+		ret = ltrf216a_read_data(data, LTRF216A_ALS_DATA_0);
+		mutex_unlock(&data->lock);
+		if (ret < 0)
+			return ret;
+		*val = ret;
+		ltrf216a_set_power_state(data, false);
+		return IIO_VAL_INT;
  	case IIO_CHAN_INFO_PROCESSED:
  		mutex_lock(&data->lock);
  		ret = ltrf216a_get_lux(data);