Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 281236
b: refs/heads/master
c: 014fcb1
h: refs/heads/master
v: v3
  • Loading branch information
Bryan Freed authored and Greg Kroah-Hartman committed Dec 8, 2011
1 parent 108ecfa commit de01e99
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: d666c0d490d85d35fe6d6d45ba029cf16046dc82
refs/heads/master: 014fcb1db5d8fd1dde1e3b777389edcd8d85a2e2
17 changes: 14 additions & 3 deletions trunk/drivers/staging/iio/light/tsl2583.c
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ static int taos_get_lux(struct iio_dev *indio_dev)
{
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;
Expand Down Expand Up @@ -297,9 +298,19 @@ static int taos_get_lux(struct iio_dev *indio_dev)
lux = (lux + (chip->als_time_scale >> 1)) /
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;
/* Adjust for active gain scale.
* The taos_device_lux tables above have a factor of 8192 built in,
* so we need to shift right.
* User-specified gain provides a multiplier.
* Apply user-specified gain before shifting right to retain precision.
* Use 64 bits to avoid overflow on multiplication.
* Then go back to 32 bits before division to avoid using div_u64().
*/
lux64 = lux;
lux64 = lux64 * chip->taos_settings.als_gain_trim;
lux64 >>= 13;
lux = lux64;
lux = (lux + 500) / 1000;
if (lux > TSL258X_LUX_CALC_OVER_FLOW) { /* check for overflow */
return_max:
lux = TSL258X_LUX_CALC_OVER_FLOW;
Expand Down

0 comments on commit de01e99

Please sign in to comment.