Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 325105
b: refs/heads/master
c: 932323b
h: refs/heads/master
i:
  325103: e39ce7f
v: v3
  • Loading branch information
Bryan Freed authored and Jonathan Cameron committed Sep 8, 2012
1 parent 433e68b commit c9f63b0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 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: 7b123c85bbb3fadbd02b82d77d5aee0c399b0e06
refs/heads/master: 932323b74e2535dbb6a1b245dfa1aa8cd2bbd8e2
17 changes: 15 additions & 2 deletions trunk/drivers/staging/iio/light/isl29018.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ struct isl29018_chip {
struct regmap *regmap;
struct mutex lock;
unsigned int lux_scale;
unsigned int lux_uscale;
unsigned int range;
unsigned int adc_bit;
int prox_scheme;
Expand Down Expand Up @@ -145,13 +146,22 @@ static int isl29018_read_sensor_input(struct isl29018_chip *chip, int mode)
static int isl29018_read_lux(struct isl29018_chip *chip, int *lux)
{
int lux_data;
unsigned int data_x_range, lux_unshifted;

lux_data = isl29018_read_sensor_input(chip, COMMMAND1_OPMODE_ALS_ONCE);

if (lux_data < 0)
return lux_data;

*lux = (lux_data * chip->range * chip->lux_scale) >> chip->adc_bit;
/* To support fractional scaling, separate the unshifted lux
* into two calculations: int scaling and micro-scaling.
* lux_uscale ranges from 0-999999, so about 20 bits. Split
* the /1,000,000 in two to reduce the risk of over/underflow.
*/
data_x_range = lux_data * chip->range;
lux_unshifted = data_x_range * chip->lux_scale;
lux_unshifted += data_x_range / 1000 * chip->lux_uscale / 1000;
*lux = lux_unshifted >> chip->adc_bit;

return 0;
}
Expand Down Expand Up @@ -339,6 +349,8 @@ static int isl29018_write_raw(struct iio_dev *indio_dev,
mutex_lock(&chip->lock);
if (mask == IIO_CHAN_INFO_CALIBSCALE && chan->type == IIO_LIGHT) {
chip->lux_scale = val;
/* With no write_raw_get_fmt(), val2 is a MICRO fraction. */
chip->lux_uscale = val2;
ret = 0;
}
mutex_unlock(&chip->lock);
Expand Down Expand Up @@ -379,7 +391,8 @@ static int isl29018_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_CALIBSCALE:
if (chan->type == IIO_LIGHT) {
*val = chip->lux_scale;
ret = IIO_VAL_INT;
*val2 = chip->lux_uscale;
ret = IIO_VAL_INT_PLUS_MICRO;
}
break;
default:
Expand Down

0 comments on commit c9f63b0

Please sign in to comment.