Commit 9861d2da authored by Brian Masney's avatar Brian Masney Committed by Jonathan Cameron

staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values

The thresh periods assumed an integration time of 3ms. This patch adds
support for the correct integration time (2.72ms or 2.73ms). The code
had the ALS filter values as going up to 15, however the values actually
went up to 60 since the values scaled in increments of 5 once the
persistence value went above 3.
Signed-off-by: default avatarBrian Masney <masneyb@onstation.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 77b69a0e
...@@ -103,8 +103,6 @@ ...@@ -103,8 +103,6 @@
#define TSL2X7X_CNTL_PROXPON_ENBL 0x0F #define TSL2X7X_CNTL_PROXPON_ENBL 0x0F
#define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F #define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F
#define TSL2X7X_MIN_ITIME 3
/* TAOS txx2x7x Device family members */ /* TAOS txx2x7x Device family members */
enum { enum {
tsl2571, tsl2571,
...@@ -984,7 +982,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, ...@@ -984,7 +982,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
int val, int val2) int val, int val2)
{ {
struct tsl2X7X_chip *chip = iio_priv(indio_dev); struct tsl2X7X_chip *chip = iio_priv(indio_dev);
int ret = -EINVAL, y, z, filter_delay; int ret = -EINVAL, count, persistence;
u8 time; u8 time;
switch (info) { switch (info) {
...@@ -1023,15 +1021,20 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, ...@@ -1023,15 +1021,20 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
else else
time = chip->settings.prox_time; time = chip->settings.prox_time;
y = (TSL2X7X_MAX_TIMER_CNT - time) + 1; count = 256 - time;
z = y * TSL2X7X_MIN_ITIME; persistence = ((val * 1000000) + val2) /
(count * tsl2x7x_int_time_avail[chip->id][3]);
filter_delay = DIV_ROUND_UP((val * 1000) + val2, z); if (chan->type == IIO_INTENSITY) {
/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
if (persistence > 3)
persistence = (persistence / 5) + 3;
chip->settings.als_persistence = persistence;
} else {
chip->settings.prox_persistence = persistence;
}
if (chan->type == IIO_INTENSITY)
chip->settings.als_persistence = filter_delay;
else
chip->settings.prox_persistence = filter_delay;
ret = 0; ret = 0;
break; break;
default: default:
...@@ -1052,7 +1055,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, ...@@ -1052,7 +1055,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
int *val, int *val2) int *val, int *val2)
{ {
struct tsl2X7X_chip *chip = iio_priv(indio_dev); struct tsl2X7X_chip *chip = iio_priv(indio_dev);
int filter_delay, mult; int filter_delay, persistence;
u8 time; u8 time;
switch (info) { switch (info) {
...@@ -1084,18 +1087,21 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, ...@@ -1084,18 +1087,21 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev,
case IIO_EV_INFO_PERIOD: case IIO_EV_INFO_PERIOD:
if (chan->type == IIO_INTENSITY) { if (chan->type == IIO_INTENSITY) {
time = chip->settings.als_time; time = chip->settings.als_time;
mult = chip->settings.als_persistence; persistence = chip->settings.als_persistence;
/* ALS filter values are 1, 2, 3, 5, 10, 15, ..., 60 */
if (persistence > 3)
persistence = (persistence - 3) * 5;
} else { } else {
time = chip->settings.prox_time; time = chip->settings.prox_time;
mult = chip->settings.prox_persistence; persistence = chip->settings.prox_persistence;
} }
/* Determine integration time */ filter_delay = persistence * (256 - time) *
*val = (TSL2X7X_MAX_TIMER_CNT - time) + 1; tsl2x7x_int_time_avail[chip->id][3];
*val2 = *val * TSL2X7X_MIN_ITIME;
filter_delay = *val2 * mult; *val = filter_delay / 1000000;
*val = filter_delay / 1000; *val2 = filter_delay % 1000000;
*val2 = filter_delay % 1000;
return IIO_VAL_INT_PLUS_MICRO; return IIO_VAL_INT_PLUS_MICRO;
default: default:
return -EINVAL; return -EINVAL;
......
...@@ -31,7 +31,6 @@ struct tsl2x7x_lux { ...@@ -31,7 +31,6 @@ struct tsl2x7x_lux {
#define TSL2X7X_50_mA 0x01 #define TSL2X7X_50_mA 0x01
#define TSL2X7X_25_mA 0x02 #define TSL2X7X_25_mA 0x02
#define TSL2X7X_13_mA 0x03 #define TSL2X7X_13_mA 0x03
#define TSL2X7X_MAX_TIMER_CNT 0xFF
/** /**
* struct tsl2x7x_settings - Settings for the tsl2x7x driver * struct tsl2x7x_settings - Settings for the tsl2x7x driver
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment