Skip to contentSkip to conversation

iio: light: vcnl4035: Fix swapped raw channel readings

PATCH In review Hungyu Lin 2 participants 2 messages Nov 13 – Nov 14

Subsystems (2)
lore
Share & tools
lore

Hungyu Lin

author
#0 lore raw

PATCH v2 1/1 iio: light: vcnl4035: Fix swapped raw channel readings

The IIO_LIGHT channel has channel number 0 and the IIO_INTENSITY channel has channel number 1. vcnl4035_read_info_raw() selects the ALS register for a nonzero channel number, so in_illuminance_raw returns the white-channel sample and in_intensity_both_raw returns the ALS sample. This also causes the illuminance scale to be applied to a white-channel sample.

Table 13 of the VCNL4035X01 datasheet [1] lists 0x0b as the ALS data register and 0x0c as the white data register.

Select the ALS data register for IIO_LIGHT and the white data register for the intensity channel.

Fixes 55707294c4eb ("iio: light: Add support for vishay vcnl4035")

---
Changes in v2:
- Reference the datasheet's register table in the commit message.

v1: https://lore.kernel.org/r/[email protected]/

 drivers/iio/light/vcnl4035.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/vcnl4035.c +1 -1
index f1cc75245001..4bbb3b458eb5 100644
@@ -156,7 +156,7 @@ static int vcnl4035_read_info_raw(struct iio_dev *indio_dev,
 	if (!iio_device_claim_direct(indio_dev))
 		return -EBUSY;
 
-	if (chan->channel)
+	if (chan->type == IIO_LIGHT)
 		reg = VCNL4035_ALS_DATA;
 	else
 		reg = VCNL4035_WHITE_DATA;

base-commit: 9752760146e642f3e4a2ec860f8767fa72030d2c

maintainer
#1 lore raw
Quoted 10 lines · On Fri, 13 Nov 2026 22:26:09 +0000 Hungyu Lin <[email protected]> wrote:

The IIO_LIGHT channel has channel number 0 and the IIO_INTENSITY channel has channel number 1. vcnl4035_read_info_raw() selects the ALS register for a nonzero channel number, so in_illuminance_raw returns the white-channel sample and in_intensity_both_raw returns the ALS sample. This also causes the illuminance scale to be applied to a white-channel sample.

Table 13 of the VCNL4035X01 datasheet [1] lists 0x0b as the ALS data register and 0x0c as the white data register.

Quoted 7 lines

Select the ALS data register for IIO_LIGHT and the white data register for the intensity channel.

Fixes 55707294c4eb ("iio: light: Add support for vishay vcnl4035")

Addressed Andy's comments and indeed even without looking the datasheet the code is clearly backwards, so applied to the fixes-togreg branch of iio.git.

Quoted 24 lines

---
Changes in v2:
- Reference the datasheet's register table in the commit message.

v1: https://lore.kernel.org/r/[email protected]/

 drivers/iio/light/vcnl4035.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/vcnl4035.c +1 -1
index f1cc75245001..4bbb3b458eb5 100644
@@ -156,7 +156,7 @@ static int vcnl4035_read_info_raw(struct iio_dev *indio_dev,
 	if (!iio_device_claim_direct(indio_dev))
 		return -EBUSY;
 
-	if (chan->channel)
+	if (chan->type == IIO_LIGHT)
 		reg = VCNL4035_ALS_DATA;
 	else
 		reg = VCNL4035_WHITE_DATA;

base-commit: 9752760146e642f3e4a2ec860f8767fa72030d2c