lkml.org 
[lkml]   [2011]   [Jun]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 2/2] light sensor: Preserve granularity of amplified tsl2583 light sensor values.
Date
Use 64bit lux64 to amplify lux values while preserving granularity.
Normalize illuminance_calibbias amplification value at 1024 instead of 1000
so we can avoid 64bit division (div_u64).

Signed-off-by: Bryan Freed <bfreed@chromium.org>
---
drivers/staging/iio/light/tsl2583.c | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 5694610..0324ac1 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -146,7 +146,7 @@ static void taos_defaults(struct tsl2583_chip *chip)
chip->taos_settings.als_gain = 0;
/* this is actually an index into the gain table */
/* assume clear glass as default */
- chip->taos_settings.als_gain_trim = 1000;
+ chip->taos_settings.als_gain_trim = 1024;
/* default gain trim to account for aperture effects */
chip->taos_settings.als_cal_target = 130;
/* Known external ALS reading used for calibration */
@@ -195,6 +195,7 @@ static int taos_get_lux(struct i2c_client *client)
{
u16 ch0, ch1; /* separated ch0/ch1 data from device */
u32 lux; /* raw lux calculated from device data */
+ u64 lux64;
u32 ratio;
u8 buf[5];
struct taos_lux *p;
@@ -298,8 +299,10 @@ static int taos_get_lux(struct i2c_client *client)
chip->als_time_scale;

/* adjust for active gain scale */
- lux >>= 13; /* tables have factor of 8192 builtin for accuracy */
- lux = (lux * chip->taos_settings.als_gain_trim + 500) / 1000;
+ lux64 = lux;
+ lux64 = (lux64 * chip->taos_settings.als_gain_trim + 512) >> 10;
+ lux64 >>= 13; /* tables have factor of 8192 builtin for accuracy */
+ lux = lux64;
if (lux > TSL258X_LUX_CALC_OVER_FLOW) { /* check for overflow */
return_max:
lux = TSL258X_LUX_CALC_OVER_FLOW;
--
1.7.3.1


\
 
 \ /
  Last update: 2011-06-10 22:39    [from the cache]
©2003-2011 Jasper Spaans