Hi Robert,

I recently got the Weather Cape (rev b) and noticed an issue with the
tsl2550 light sensor in low light.  It turns out Matt Ranostay posted
a patch to LKML back in 2013 that fixes the issue:

[PATCH] tsl2550: fix lux1_input error in low light
https://lkml.org/lkml/2013/6/14/16

However, it doesn't seem that patch was ever picked up.  I've applied
the patch to 4.4.35-ti-r70 and tested OK.  The patch also applies OK
to mainline (4.9-rc7).  More details in this gist (also attached):
https://gist.github.com/pdp7/4c91813a9ca79aba200d20884a0a0d63

Could you add the attached patch to ti-linux-kernel-dev?


thanks,
drew

-- 
For more options, visit http://beagleboard.org/discuss
--- 
You received this message because you are subscribed to the Google Groups 
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to beagleboard+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/CAPgEAj4tD6ppXk0V-LMC3fynqSvVjp4XDRYTES28wZzgk8VfMw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
From c23e541ef11dc848ca60218aa74690dbb0158114 Mon Sep 17 00:00:00 2001
From: "mranos...@gmail.com" <mranos...@gmail.com>
Date: Mon, 3 Jun 2013 22:38:49 +0000
Subject: [PATCH] tsl2550: fix lux1_input error in low light

ADC channel 0 photodiode detects both infrared + visible light,
but ADC channel 1 just detects infrared. However, the latter is a bit
more sensitive in that range so complete darkness or low light causes
a error condition in which the chan0 - chan1 is negative that
results in a -EAGAIN.

This patch changes the resulting lux1_input sysfs attribute message from
"Resource temporarily unavailable" to a user-grokable lux value of 0.

Signed-off-by: Matt Ranostay <mranos...@gmail.com>
---
 drivers/misc/tsl2550.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/tsl2550.c b/drivers/misc/tsl2550.c
index 87a1337..eb57610 100644
--- a/drivers/misc/tsl2550.c
+++ b/drivers/misc/tsl2550.c
@@ -177,7 +177,7 @@ static int tsl2550_calculate_lux(u8 ch0, u8 ch1)
 		} else
 			lux = 0;
 	else
-		return -EAGAIN;
+		return 0;
 
 	/* LUX range check */
 	return lux > TSL2550_MAX_LUX ? TSL2550_MAX_LUX : lux;
-- 
2.9.3

## [PATCH] tsl2550: fix lux1_input error in low light
[Patch from LKML post by Matt Ranostay](https://lkml.org/lkml/2013/6/14/16)
```
From c23e541ef11dc848ca60218aa74690dbb0158114 Mon Sep 17 00:00:00 2001
From: Matt Ranostay <mranos...@gmail.com>
Date: Mon, 3 Jun 2013 22:38:49 +0000
Subject: [PATCH] tsl2550: fix lux1_input error in low light

ADC channel 0 photodiode detects both infrared + visible light,
but ADC channel 1 just detects infrared. However, the latter is a bit
more sensitive in that range so complete darkness or low light causes
a error condition in which the chan0 - chan1 is negative that
results in a -EAGAIN.

This patch changes the resulting lux1_input sysfs attribute message from
"Resource temporarily unavailable" to a user-grokable lux value of 0.

Signed-off-by: Matt Ranostay <mranos...@gmail.com>
---
 drivers/misc/tsl2550.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/misc/tsl2550.c b/drivers/misc/tsl2550.c
index 87a1337..eb57610 100644
--- a/drivers/misc/tsl2550.c
+++ b/drivers/misc/tsl2550.c
@@ -177,7 +177,7 @@ static int tsl2550_calculate_lux(u8 ch0, u8 ch1)
                } else  
                        lux = 0;
        else
-               return -EAGAIN;
+               return 0;

        /* LUX range check */
        return lux > TSL2550_MAX_LUX ? TSL2550_MAX_LUX : lux;
-- 
2.9.3
```


## Build Info
### ti-linux-kernel-dev
```
[pdp7@skylake ti-linux-kernel-dev]$ git log -1 --oneline
9c848e7 4.4.35-ti-r70 release

[pdp7@skylake ti-linux-kernel-dev]$ git status
On branch ti-linux-4.4.y
Your branch is up-to-date with 'origin/ti-linux-4.4.y'.
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   patches/defconfig

no changes added to commit (use "git add" and/or "git commit -a")

[pdp7@skylake KERNEL]$ git status
On branch v4.4.35-ti-r70

[pdp7@skylake KERNEL]$ git log --oneline -2 ./drivers/misc/tsl2550.c 
c23e541 tsl2550: fix lux1_input error in low light
14e51e5 misc: Drop owner assignment from i2c_driver
```

### BeagleBone
```
root@beaglebone:~# cat /etc/dogtag 
BeagleBoard.org Debian Image 2016-08-14
root@beaglebone:~# cat /etc/debian_version 
8.6
root@beaglebone:~# uname -a
Linux beaglebone 4.4.35-ti-r70 #1 SMP Fri Dec 2 05:22:17 CST 2016 armv7l GNU/Linux
```

## Example
### Low light in the room
#### Before patch

```
root@beaglebone:~# cat /sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0039/lux1_input
cat: /sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0039/lux1_input: Resource temporarily unavailable
```
### After patch
```
root@beaglebone:~# cat /sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0039/lux1_input
0
```
## Smartphone backlight over sensor
```
root@beaglebone:~# cat /sys/devices/platform/ocp/4819c000.i2c/i2c-2/2-0039/lux1_input
364
```

Reply via email to