Skip to content

Instantly share code, notes, and snippets.

@pdp7
Last active December 2, 2016 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdp7/4c91813a9ca79aba200d20884a0a0d63 to your computer and use it in GitHub Desktop.
Save pdp7/4c91813a9ca79aba200d20884a0a0d63 to your computer and use it in GitHub Desktop.
BeagleBone Weather Cape and tsl2550 patch by Matt Ranostay

[PATCH] tsl2550: fix lux1_input error in low light

Patch from LKML post by Matt Ranostay

From c23e541ef11dc848ca60218aa74690dbb0158114 Mon Sep 17 00:00:00 2001
From: Matt Ranostay <mranostay@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 <mranostay@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
@pdp7
Copy link
Author

pdp7 commented Dec 2, 2016

Mainline is the same

[pdp7@skylake linux]$ git log --oneline -1 ./drivers/misc/tsl2550.c 
14e51e5 misc: Drop owner assignment from i2c_driver

[pdp7@skylake linux]$ cat .git/config  |grep url
        url = https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git

[pdp7@skylake linux]$ git branch
* master

@pdp7
Copy link
Author

pdp7 commented Dec 2, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment