Commit 490941db authored by Brian Masney's avatar Brian Masney Committed by Jonathan Cameron

staging: iio: tsl2x7x: split out als and prox persistence settings

The struct tsl2x7x_settings contained a persistence member that
contained both the ALS and proximity persistence fields. This patch
splits this out into two separate fields so that the bitmasks in
several parts of the code are no longer necessary.

The default persistence settings are also changed by this patch from:

- Proximity: 0 (Every proximity cycle generates an interrupt)
- ALS: 255 (60 consecutive values out of range)

to something a little more reasonable based on my testing:

- Proximity: 1 (1 proximity value out of range)
- ALS: 1 (1 value outside of threshold range)
Signed-off-by: default avatarBrian Masney <masneyb@onstation.org>
Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 8bf09ec4
...@@ -226,10 +226,11 @@ static const struct tsl2x7x_settings tsl2x7x_default_settings = { ...@@ -226,10 +226,11 @@ static const struct tsl2x7x_settings tsl2x7x_default_settings = {
.prox_config = 0, .prox_config = 0,
.als_gain_trim = 1000, .als_gain_trim = 1000,
.als_cal_target = 150, .als_cal_target = 150,
.als_persistence = 1,
.als_interrupt_en = false, .als_interrupt_en = false,
.als_thresh_low = 200, .als_thresh_low = 200,
.als_thresh_high = 256, .als_thresh_high = 256,
.persistence = 255, .prox_persistence = 1,
.prox_interrupt_en = false, .prox_interrupt_en = false,
.prox_thres_low = 0, .prox_thres_low = 0,
.prox_thres_high = 512, .prox_thres_high = 512,
...@@ -621,7 +622,9 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) ...@@ -621,7 +622,9 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev)
(chip->settings.als_thresh_high) & 0xFF; (chip->settings.als_thresh_high) & 0xFF;
chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHHI] = chip->tsl2x7x_config[TSL2X7X_ALS_MAXTHRESHHI] =
(chip->settings.als_thresh_high >> 8) & 0xFF; (chip->settings.als_thresh_high >> 8) & 0xFF;
chip->tsl2x7x_config[TSL2X7X_PERSISTENCE] = chip->settings.persistence; chip->tsl2x7x_config[TSL2X7X_PERSISTENCE] =
(chip->settings.prox_persistence & 0xFF) << 4 |
(chip->settings.als_persistence & 0xFF);
chip->tsl2x7x_config[TSL2X7X_PRX_COUNT] = chip->tsl2x7x_config[TSL2X7X_PRX_COUNT] =
chip->settings.prox_pulse_count; chip->settings.prox_pulse_count;
...@@ -1043,15 +1046,10 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, ...@@ -1043,15 +1046,10 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev,
filter_delay = DIV_ROUND_UP((val * 1000) + val2, z); filter_delay = DIV_ROUND_UP((val * 1000) + val2, z);
if (chan->type == IIO_INTENSITY) { if (chan->type == IIO_INTENSITY)
chip->settings.persistence &= 0xF0; chip->settings.als_persistence = filter_delay;
chip->settings.persistence |= else
(filter_delay & 0x0F); chip->settings.prox_persistence = filter_delay;
} else {
chip->settings.persistence &= 0x0F;
chip->settings.persistence |=
((filter_delay << 4) & 0xF0);
}
ret = 0; ret = 0;
break; break;
default: default:
...@@ -1108,10 +1106,10 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, ...@@ -1108,10 +1106,10 @@ 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.persistence & 0x0F; mult = chip->settings.als_persistence;
} else { } else {
time = chip->settings.prx_time; time = chip->settings.prx_time;
mult = (chip->settings.persistence & 0xF0) >> 4; mult = chip->settings.prox_persistence;
} }
/* Determine integration time */ /* Determine integration time */
......
...@@ -50,11 +50,13 @@ struct tsl2x7x_lux { ...@@ -50,11 +50,13 @@ struct tsl2x7x_lux {
* @prox_config: Prox configuration filters. * @prox_config: Prox configuration filters.
* @als_cal_target: Known external ALS reading for * @als_cal_target: Known external ALS reading for
* calibration. * calibration.
* @persistence: H/W Filters, Number of 'out of limits' * @als_persistence: H/W Filters, Number of 'out of limits'
* ADC readings PRX/ALS. * ALS readings.
* @als_interrupt_en: Enable/Disable ALS interrupts * @als_interrupt_en: Enable/Disable ALS interrupts
* @als_thresh_low: CH0 'low' count to trigger interrupt. * @als_thresh_low: CH0 'low' count to trigger interrupt.
* @als_thresh_high: CH0 'high' count to trigger interrupt. * @als_thresh_high: CH0 'high' count to trigger interrupt.
* @prox_persistence: H/W Filters, Number of 'out of limits'
* proximity readings.
* @prox_interrupt_en: Enable/Disable proximity interrupts * @prox_interrupt_en: Enable/Disable proximity interrupts
* @prox_thres_low: Low threshold proximity detection. * @prox_thres_low: Low threshold proximity detection.
* @prox_thres_high: High threshold proximity detection * @prox_thres_high: High threshold proximity detection
...@@ -70,10 +72,11 @@ struct tsl2x7x_settings { ...@@ -70,10 +72,11 @@ struct tsl2x7x_settings {
int prox_gain; int prox_gain;
int prox_config; int prox_config;
int als_cal_target; int als_cal_target;
u8 persistence; u8 als_persistence;
bool als_interrupt_en; bool als_interrupt_en;
int als_thresh_low; int als_thresh_low;
int als_thresh_high; int als_thresh_high;
u8 prox_persistence;
bool prox_interrupt_en; bool prox_interrupt_en;
int prox_thres_low; int prox_thres_low;
int prox_thres_high; int prox_thres_high;
......
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