iio: light: tsl2772: fix ALS calibscale readback
PATCH 1/1 iio: light: tsl2772: fix ALS calibscale readback
The read_raw() implementation uses IIO_LIGHT to distinguish between the ambient light and proximity channels when handling IIO_CHAN_INFO_CALIBSCALE.
However, the ALS channel is registered as IIO_INTENSITY, while write_raw() correctly writes to IIO_INTENSITY. As a result, reading in_intensity0_calibscale incorrectly returns the proximity gain instead of the ALS gain.
This causes the following user-visible behavior:
- Writing in_intensity0_calibscale appears to have no effect because the readback reports the proximity gain.
- Writing in_proximity0_calibscale causes both in_proximity0_calibscale and in_intensity0_calibscale to report the same value.
Fix this by checking for IIO_INTENSITY in read_raw(), matching the channel definition and the existing write_raw() implementation.
--- drivers/iio/light/tsl2772.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iio/light/tsl2772.c +1 -1
@@ -1274,7 +1274,7 @@ static int tsl2772_read_raw(struct iio_dev *indio_dev, }break ;case IIO_CHAN_INFO_CALIBSCALE : -if (chan->type ==IIO_LIGHT ) +if (chan->type ==IIO_INTENSITY ) *val = tsl2772_als_gain[chip->settings.als_gain];else *val = tsl2772_prox_gain[chip->settings.prox_gain];
---
base-commit: 1590cf0329716306e948a8fc29f1d3ee87d3989f
change-id: 20260724-tsl2772-calibscale-fix-0cc42518d5fc
Best regards,
Signature · 1 line
Yuanshen Cao <[email protected]>
Quoted 41 lines · Yuanshen Cao
The
read_raw()implementation usesIIO_LIGHTto distinguish between the ambient light and proximity channels when handlingIIO_CHAN_INFO_CALIBSCALE.However, the ALS channel is registered as
IIO_INTENSITY, whilewrite_raw()correctly writes toIIO_INTENSITY. As a result, readingin_intensity0_calibscaleincorrectly returns the proximity gain instead of the ALS gain.This causes the following user-visible behavior:
- Writingin_intensity0_calibscaleappears to have no effect because the readback reports the proximity gain.
- Writingin_proximity0_calibscalecauses bothin_proximity0_calibscaleandin_intensity0_calibscaleto report the same value.Fix this by checking for
IIO_INTENSITYinread_raw(), matching the channel definition and the existingwrite_raw()implementation.Signed-off-by Yuanshen Cao <[email protected]>--- drivers/iio/light/tsl2772.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/light/tsl2772.c +1
-2@@ -1274,7 +1274,7 @@ static int tsl2772_read_raw(struct iio_dev *indio_dev, }break ;case IIO_CHAN_INFO_CALIBSCALE : -if (chan->type ==IIO_LIGHT ) +if (chan->type ==IIO_INTENSITY ) *val = tsl2772_als_gain[chip->settings.als_gain];else *val = tsl2772_prox_gain[chip->settings.prox_gain]; ---base-commit:
1590cf0329716306e948a8fc29f1d3ee87d3989f
change-id: 20260724-tsl2772-calibscale-fix-0cc42518d5fc
Quoted 4 lines
Best regards,
Signature · 1 line
Yuanshen Cao <[email protected]>
Jonathan Cameron
maintainerQuoted 15 lines · On Fri, 24 Jul 2026 23:46:01 +0000 Yuanshen Cao <[email protected]> wrote:
The
read_raw()implementation usesIIO_LIGHTto distinguish between the ambient light and proximity channels when handlingIIO_CHAN_INFO_CALIBSCALE.However, the ALS channel is registered as
IIO_INTENSITY, whilewrite_raw()correctly writes toIIO_INTENSITY. As a result, readingin_intensity0_calibscaleincorrectly returns the proximity gain instead of the ALS gain.This causes the following user-visible behavior:
- Writingin_intensity0_calibscaleappears to have no effect because the readback reports the proximity gain.
- Writingin_proximity0_calibscalecauses bothin_proximity0_calibscaleandin_intensity0_calibscaleto report the same value.
Quoted 4 lines
Fix this by checking for
IIO_INTENSITYinread_raw(), matching the channel definition and the existingwrite_raw()implementation.Signed-off-by Yuanshen Cao <[email protected]>
Hi,
Fix looks good and the explanation correct. Was this an AI found one, or did you either spot this whilst reading the code or best of all saw it in practice and went looking for what is wrong?
Give it is fix, what is missing is a suitable Fixes tag. Please see if you can figure out what that should be. No need to send a v2 unless anything else comes up in review. Just reply to this thread with the Fixes tag so I'll get it when I use b4 to pick up the patch
Thanks,
Jonathan
Quoted 26 lines
--- drivers/iio/light/tsl2772.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/light/tsl2772.c +1
-2@@ -1274,7 +1274,7 @@ static int tsl2772_read_raw(struct iio_dev *indio_dev, }break ;case IIO_CHAN_INFO_CALIBSCALE : -if (chan->type ==IIO_LIGHT ) +if (chan->type ==IIO_INTENSITY ) *val = tsl2772_als_gain[chip->settings.als_gain];else *val = tsl2772_prox_gain[chip->settings.prox_gain]; ---base-commit:
1590cf0329716306e948a8fc29f1d3ee87d3989f
change-id: 20260724-tsl2772-calibscale-fix-0cc42518d5fcBest regards,
Signature · 1 line
Yuanshen Cao <[email protected]>
Quoted 21 lines · Jonathan Cameron
Quoted 18 lines · On Fri, 24 Jul 2026 23:46:01 +0000 Yuanshen Cao <[email protected]> wrote:
The
read_raw()implementation usesIIO_LIGHTto distinguish between the ambient light and proximity channels when handlingIIO_CHAN_INFO_CALIBSCALE.However, the ALS channel is registered as
IIO_INTENSITY, whilewrite_raw()correctly writes toIIO_INTENSITY. As a result, readingin_intensity0_calibscaleincorrectly returns the proximity gain instead of the ALS gain.This causes the following user-visible behavior:
- Writingin_intensity0_calibscaleappears to have no effect because the readback reports the proximity gain.
- Writingin_proximity0_calibscalecauses bothin_proximity0_calibscaleandin_intensity0_calibscaleto report the same value.Fix this by checking for
IIO_INTENSITYinread_raw(), matching the channel definition and the existingwrite_raw()implementation.
Quoted 6 lines
Quoted 1 line
Signed-off-by Yuanshen Cao <[email protected]>Hi,
Fix looks good and the explanation correct. Was this an AI found one, or did you either spot this whilst reading the code or best of all saw it in practice and went looking for what is wrong?
Hi Jonathan,
It's actually a bit of both. I first noticed the strange calibscale behavior while testing a device with this sensor. Since most part of this driver has been around for 7+ years, I wasn't expecting to find a bug there. I asked ChatGPT for some ideas about what might explain the behavior, and it pointed out the mismatch. I then went back and verified it, and sure enough, it turned out to be a 14-year-old bug. After that, I checked the rest of the file for similar issues, but this appears to be the only instance. Also this was tested on the device and it works as intended now.
Quoted 5 lines
Give it is fix, what is missing is a suitable Fixes tag. Please see if you can figure out what that should be. No need to send a v2 unless anything else comes up in review. Just reply to this thread with the Fixes tag so I'll get it when I use b4 to pick up the patch
Thanks for pointing this out.
The missing tag is:
Best,
Yuanshen (Alex) Cao
Quoted 31 lines
Thanks,
Jonathan
Quoted 26 lines
--- drivers/iio/light/tsl2772.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/light/tsl2772.c +1
-2@@ -1274,7 +1274,7 @@ static int tsl2772_read_raw(struct iio_dev *indio_dev, }break ;case IIO_CHAN_INFO_CALIBSCALE : -if (chan->type ==IIO_LIGHT ) +if (chan->type ==IIO_INTENSITY ) *val = tsl2772_als_gain[chip->settings.als_gain];else *val = tsl2772_prox_gain[chip->settings.prox_gain]; ---base-commit:
1590cf0329716306e948a8fc29f1d3ee87d3989f
change-id: 20260724-tsl2772-calibscale-fix-0cc42518d5fcBest regards,
Signature · 1 line
Yuanshen Cao <[email protected]>
Jonathan Cameron
maintainerQuoted 31 lines · On Mon, 27 Jul 2026 04:40:13 +0000 Yuanshen Cao <[email protected]> wrote:
Quoted 21 lines · Jonathan Cameron
Quoted 18 lines · On Fri, 24 Jul 2026 23:46:01 +0000 Yuanshen Cao <[email protected]> wrote:
The
read_raw()implementation usesIIO_LIGHTto distinguish between the ambient light and proximity channels when handlingIIO_CHAN_INFO_CALIBSCALE.However, the ALS channel is registered as
IIO_INTENSITY, whilewrite_raw()correctly writes toIIO_INTENSITY. As a result, readingin_intensity0_calibscaleincorrectly returns the proximity gain instead of the ALS gain.This causes the following user-visible behavior:
- Writingin_intensity0_calibscaleappears to have no effect because the readback reports the proximity gain.
- Writingin_proximity0_calibscalecauses bothin_proximity0_calibscaleandin_intensity0_calibscaleto report the same value.Fix this by checking for
IIO_INTENSITYinread_raw(), matching the channel definition and the existingwrite_raw()implementation.Quoted 6 lines
Quoted 1 line
Signed-off-by Yuanshen Cao <[email protected]>Hi,
Fix looks good and the explanation correct. Was this an AI found one, or did you either spot this whilst reading the code or best of all saw it in practice and went looking for what is wrong?
Hi Jonathan,
Quoted 9 lines
It's actually a bit of both. I first noticed the strange calibscale behavior while testing a device with this sensor. Since most part of this driver has been around for 7+ years, I wasn't expecting to find a bug there. I asked ChatGPT for some ideas about what might explain the behavior, and it pointed out the mismatch. I then went back and verified it, and sure enough, it turned out to be a 14-year-old bug. After that, I checked the rest of the file for similar issues, but this appears to be the only instance. Also this was tested on the device and it works as intended now.
I can't remember what the exact rules are for an Assisted tag but to me it sounds fine to not have one here.
Quoted 11 lines
Quoted 6 lines
Give it is fix, what is missing is a suitable Fixes tag. Please see if you can figure out what that should be. No need to send a v2 unless anything else comes up in review. Just reply to this thread with the Fixes tag so I'll get it when I use b4 to pick up the patch
Thanks for pointing this out.
The missing tag is:Fixes 3c97c08b5735 ("iio: light: add TAOS tsl2x7x driver")
Thanks. Given it's ancient and Linus is getting fussier about non critical bugs late in the cycle, I've queued this up for the next merge window and marked it for stable rather than going the quick route.
thanks,
Jonathan
Quoted 37 lines
Best,
Yuanshen (Alex) Cao
Quoted 31 lines
Thanks,
Jonathan
Quoted 26 lines
--- drivers/iio/light/tsl2772.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/light/tsl2772.c +1
-2@@ -1274,7 +1274,7 @@ static int tsl2772_read_raw(struct iio_dev *indio_dev, }break ;case IIO_CHAN_INFO_CALIBSCALE : -if (chan->type ==IIO_LIGHT ) +if (chan->type ==IIO_INTENSITY ) *val = tsl2772_als_gain[chip->settings.als_gain];else *val = tsl2772_prox_gain[chip->settings.prox_gain]; ---base-commit:
1590cf0329716306e948a8fc29f1d3ee87d3989f
change-id: 20260724-tsl2772-calibscale-fix-0cc42518d5fcBest regards,
Signature · 1 line
Yuanshen Cao <[email protected]>
Jonathan Cameron
maintainerQuoted 47 lines · On Mon, 27 Jul 2026 04:40:13 +0000 Yuanshen Cao <[email protected]> wrote:
Quoted 21 lines · Jonathan Cameron
Quoted 18 lines · On Fri, 24 Jul 2026 23:46:01 +0000 Yuanshen Cao <[email protected]> wrote:
The
read_raw()implementation usesIIO_LIGHTto distinguish between the ambient light and proximity channels when handlingIIO_CHAN_INFO_CALIBSCALE.However, the ALS channel is registered as
IIO_INTENSITY, whilewrite_raw()correctly writes toIIO_INTENSITY. As a result, readingin_intensity0_calibscaleincorrectly returns the proximity gain instead of the ALS gain.This causes the following user-visible behavior:
- Writingin_intensity0_calibscaleappears to have no effect because the readback reports the proximity gain.
- Writingin_proximity0_calibscalecauses bothin_proximity0_calibscaleandin_intensity0_calibscaleto report the same value.Fix this by checking for
IIO_INTENSITYinread_raw(), matching the channel definition and the existingwrite_raw()implementation.Quoted 6 lines
Quoted 1 line
Signed-off-by Yuanshen Cao <[email protected]>Hi,
Fix looks good and the explanation correct. Was this an AI found one, or did you either spot this whilst reading the code or best of all saw it in practice and went looking for what is wrong?
Hi Jonathan,
It's actually a bit of both. I first noticed the strange calibscale behavior while testing a device with this sensor. Since most part of this driver has been around for 7+ years, I wasn't expecting to find a bug there. I asked ChatGPT for some ideas about what might explain the behavior, and it pointed out the mismatch. I then went back and verified it, and sure enough, it turned out to be a 14-year-old bug. After that, I checked the rest of the file for similar issues, but this appears to be the only instance. Also this was tested on the device and it works as intended now.
Quoted 5 lines
Give it is fix, what is missing is a suitable Fixes tag. Please see if you can figure out what that should be. No need to send a v2 unless anything else comes up in review. Just reply to this thread with the Fixes tag so I'll get it when I use b4 to pick up the patch
Quoted 4 lines
Thanks for pointing this out.
The missing tag is:Fixes 3c97c08b5735 ("iio: light: add TAOS tsl2x7x driver")
That's not the patch title. Unfortunately I missed running a check on this and it surfaced in linux-next forcing a rebase of the IIO tree to repair things.
It's an ancient commit and the title didn't follow modern conventions
staging: iio: add TAOS tsl2x7x driver
Anyhow fixed up now
Thanks,
Jonathan
Quoted 37 lines
Best,
Yuanshen (Alex) Cao
Quoted 31 lines
Thanks,
Jonathan
Quoted 26 lines
--- drivers/iio/light/tsl2772.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/iio/light/tsl2772.c +1
-2@@ -1274,7 +1274,7 @@ static int tsl2772_read_raw(struct iio_dev *indio_dev, }break ;case IIO_CHAN_INFO_CALIBSCALE : -if (chan->type ==IIO_LIGHT ) +if (chan->type ==IIO_INTENSITY ) *val = tsl2772_als_gain[chip->settings.als_gain];else *val = tsl2772_prox_gain[chip->settings.prox_gain]; ---base-commit:
1590cf0329716306e948a8fc29f1d3ee87d3989f
change-id: 20260724-tsl2772-calibscale-fix-0cc42518d5fcBest regards,
Signature · 1 line
Yuanshen Cao <[email protected]>