[PATCH] TSL2550 driver bugfix

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

 



Hi all,

I've tested TSL2550 driver and I've found a bug: when light is off, returned value from tsl2550_calculate_lux function is -1 when it should be 0 (sensor correctly read that light was off).

I think the bug is that a zero c0 value (approximated value of ch0) is misinterpreted as an error.
I'm attaching you a patch that fixes the bug.

Regards,
Michele Jr De Candia
Signed-off-by: Michele Jr De Candia <michele.decandia@xxxxxxxxxxxxx>

diff --git a/drivers/i2c/chips/tsl2550.c b/drivers/i2c/chips/tsl2550.c
index 1a9cc13..6bad072 100644
--- a/drivers/i2c/chips/tsl2550.c
+++ b/drivers/i2c/chips/tsl2550.c
@@ -189,10 +189,16 @@ static int tsl2550_calculate_lux(u8 ch0, u8 ch1)
 	u8 r = 128;
 
 	/* Avoid division by 0 and count 1 cannot be greater than count 0 */
-	if (c0 && (c1 <= c0))
-		r = c1 * 128 / c0;
-	else
-		return -1;
+	if (c0)	{
+		if (c1 <= c0)
+			r = c1 * 128 / c0;
+		else
+			return -1;
+			
+		/* Calculate LUX */
+		lux = ((c0 - c1) * ratio_lut[r]) / 256;
+	}
+	else lux = 0;
 
 	/* Calculate LUX */
 	lux = ((c0 - c1) * ratio_lut[r]) / 256;

[Index of Archives]     [Linux GPIO]     [Linux SPI]     [Linux Hardward Monitoring]     [LM Sensors]     [Linux USB Devel]     [Linux Media]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux