From: Brian Masney <masneyb@onstation.org> To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: devel@driverdev.osuosl.org, lars@metafoo.de, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org, pmeerw@pmeerw.net, knaack.h@gmx.de, drew.paterson@ams.com Subject: [PATCH v2 09/11] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values Date: Thu, 3 May 2018 22:53:17 -0400 [thread overview] Message-ID: <20180504025319.28953-10-masneyb@onstation.org> (raw) In-Reply-To: <20180504025319.28953-1-masneyb@onstation.org> 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: Brian Masney <masneyb@onstation.org> --- drivers/staging/iio/light/tsl2x7x.c | 44 +++++++++++++++++++++---------------- drivers/staging/iio/light/tsl2x7x.h | 1 - 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 39de5e60fd33..f912f4bc61c4 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -103,8 +103,6 @@ #define TSL2X7X_CNTL_PROXPON_ENBL 0x0F #define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F -#define TSL2X7X_MIN_ITIME 3 - /* TAOS txx2x7x Device family members */ enum { tsl2571, @@ -972,7 +970,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, int val, int val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL, y, z, filter_delay; + int ret = -EINVAL, count, persistence; u8 time; switch (info) { @@ -1011,15 +1009,20 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, else time = chip->settings.prox_time; - y = (TSL2X7X_MAX_TIMER_CNT - time) + 1; - z = y * TSL2X7X_MIN_ITIME; + count = 256 - time; + persistence = ((val * 1000000) + val2) / + (count * tsl2x7x_int_time[chip->id].increment_us); - 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; break; default: @@ -1040,7 +1043,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, int *val, int *val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL, filter_delay, mult; + int ret = -EINVAL, filter_delay, persistence; u8 time; switch (info) { @@ -1076,18 +1079,21 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, case IIO_EV_INFO_PERIOD: if (chan->type == IIO_INTENSITY) { 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 { time = chip->settings.prox_time; - mult = chip->settings.prox_persistence; + persistence = chip->settings.prox_persistence; } - /* Determine integration time */ - *val = (TSL2X7X_MAX_TIMER_CNT - time) + 1; - *val2 = *val * TSL2X7X_MIN_ITIME; - filter_delay = *val2 * mult; - *val = filter_delay / 1000; - *val2 = filter_delay % 1000; + filter_delay = persistence * (256 - time) * + tsl2x7x_int_time[chip->id].increment_us; + + *val = filter_delay / 1000000; + *val2 = filter_delay % 1000000; ret = IIO_VAL_INT_PLUS_MICRO; break; default: diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index 1097ee890ce2..f74427f4ab6e 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -31,7 +31,6 @@ struct tsl2x7x_lux { #define TSL2X7X_50_mA 0x01 #define TSL2X7X_25_mA 0x02 #define TSL2X7X_13_mA 0x03 -#define TSL2X7X_MAX_TIMER_CNT 0xFF /** * struct tsl2x7x_settings - Settings for the tsl2x7x driver -- 2.14.3 _______________________________________________ devel mailing list devel@linuxdriverproject.org http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel
WARNING: multiple messages have this Message-ID (diff)
From: Brian Masney <masneyb@onstation.org> To: jic23@kernel.org, linux-iio@vger.kernel.org Cc: gregkh@linuxfoundation.org, devel@driverdev.osuosl.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, linux-kernel@vger.kernel.org, drew.paterson@ams.com Subject: [PATCH v2 09/11] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values Date: Thu, 3 May 2018 22:53:17 -0400 [thread overview] Message-ID: <20180504025319.28953-10-masneyb@onstation.org> (raw) In-Reply-To: <20180504025319.28953-1-masneyb@onstation.org> 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: Brian Masney <masneyb@onstation.org> --- drivers/staging/iio/light/tsl2x7x.c | 44 +++++++++++++++++++++---------------- drivers/staging/iio/light/tsl2x7x.h | 1 - 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 39de5e60fd33..f912f4bc61c4 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -103,8 +103,6 @@ #define TSL2X7X_CNTL_PROXPON_ENBL 0x0F #define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F -#define TSL2X7X_MIN_ITIME 3 - /* TAOS txx2x7x Device family members */ enum { tsl2571, @@ -972,7 +970,7 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, int val, int val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL, y, z, filter_delay; + int ret = -EINVAL, count, persistence; u8 time; switch (info) { @@ -1011,15 +1009,20 @@ static int tsl2x7x_write_event_value(struct iio_dev *indio_dev, else time = chip->settings.prox_time; - y = (TSL2X7X_MAX_TIMER_CNT - time) + 1; - z = y * TSL2X7X_MIN_ITIME; + count = 256 - time; + persistence = ((val * 1000000) + val2) / + (count * tsl2x7x_int_time[chip->id].increment_us); - 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; break; default: @@ -1040,7 +1043,7 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, int *val, int *val2) { struct tsl2X7X_chip *chip = iio_priv(indio_dev); - int ret = -EINVAL, filter_delay, mult; + int ret = -EINVAL, filter_delay, persistence; u8 time; switch (info) { @@ -1076,18 +1079,21 @@ static int tsl2x7x_read_event_value(struct iio_dev *indio_dev, case IIO_EV_INFO_PERIOD: if (chan->type == IIO_INTENSITY) { 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 { time = chip->settings.prox_time; - mult = chip->settings.prox_persistence; + persistence = chip->settings.prox_persistence; } - /* Determine integration time */ - *val = (TSL2X7X_MAX_TIMER_CNT - time) + 1; - *val2 = *val * TSL2X7X_MIN_ITIME; - filter_delay = *val2 * mult; - *val = filter_delay / 1000; - *val2 = filter_delay % 1000; + filter_delay = persistence * (256 - time) * + tsl2x7x_int_time[chip->id].increment_us; + + *val = filter_delay / 1000000; + *val2 = filter_delay % 1000000; ret = IIO_VAL_INT_PLUS_MICRO; break; default: diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index 1097ee890ce2..f74427f4ab6e 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -31,7 +31,6 @@ struct tsl2x7x_lux { #define TSL2X7X_50_mA 0x01 #define TSL2X7X_25_mA 0x02 #define TSL2X7X_13_mA 0x03 -#define TSL2X7X_MAX_TIMER_CNT 0xFF /** * struct tsl2x7x_settings - Settings for the tsl2x7x driver -- 2.14.3
next prev parent reply other threads:[~2018-05-04 2:53 UTC|newest] Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-05-04 2:53 [PATCH v2 00/11] staging: iio: tsl2x7x: move out of staging Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-04 2:53 ` [PATCH v2 01/11] staging: iio: tsl2x7x: use GPL-2.0+ SPDX license identifier Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-06 17:59 ` Jonathan Cameron 2018-05-06 17:59 ` Jonathan Cameron 2018-05-04 2:53 ` [PATCH v2 02/11] staging: iio: tsl2x7x: add range checking to three sysfs attributes Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-06 18:01 ` Jonathan Cameron 2018-05-06 18:01 ` Jonathan Cameron 2018-05-04 2:53 ` [PATCH v2 03/11] staging: iio: tsl2x7x: don't setup event handlers if interrupts are not configured Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-06 18:05 ` Jonathan Cameron 2018-05-06 18:05 ` Jonathan Cameron 2018-05-04 2:53 ` [PATCH v2 04/11] staging: iio: tsl2x7x: move calibscale_available attribute to IIO_INTENSITY channel Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-06 18:06 ` Jonathan Cameron 2018-05-06 18:06 ` Jonathan Cameron 2018-05-04 2:53 ` [PATCH v2 05/11] staging: iio: tsl2x7x: use IIO_CONST_ATTR for calibscale_available Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-06 18:07 ` Jonathan Cameron 2018-05-06 18:07 ` Jonathan Cameron 2018-05-04 2:53 ` [PATCH v2 06/11] staging: iio: tsl2x7x: correct integration time and lux equation Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-06 18:11 ` Jonathan Cameron 2018-05-06 18:11 ` Jonathan Cameron 2018-05-04 2:53 ` [PATCH v2 07/11] staging: iio: tsl2x7x: support 2.72 and 2.73 ALS increments Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-06 18:19 ` Jonathan Cameron 2018-05-04 2:53 ` [PATCH v2 08/11] staging: iio: tsl2x7x: add device ids for code readability Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-06 18:26 ` Jonathan Cameron 2018-05-06 18:26 ` Jonathan Cameron 2018-05-04 2:53 ` Brian Masney [this message] 2018-05-04 2:53 ` [PATCH v2 09/11] staging: iio: tsl2x7x: correct IIO_EV_INFO_PERIOD values Brian Masney 2018-05-06 18:27 ` Jonathan Cameron 2018-05-06 18:27 ` Jonathan Cameron 2018-05-04 2:53 ` [PATCH v2 10/11] staging: iio: tsl2x7x: rename driver to tsl2772 Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-06 18:29 ` Jonathan Cameron 2018-05-06 18:29 ` Jonathan Cameron 2018-05-04 2:53 ` [PATCH v2 11/11] staging: iio: tsl2x7x/tsl2772: move out of staging Brian Masney 2018-05-04 2:53 ` Brian Masney 2018-05-04 2:56 ` Brian Masney 2018-05-04 2:56 ` Brian Masney 2018-05-06 19:00 ` Jonathan Cameron 2018-05-06 19:00 ` Jonathan Cameron
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20180504025319.28953-10-masneyb@onstation.org \ --to=masneyb@onstation.org \ --cc=devel@driverdev.osuosl.org \ --cc=drew.paterson@ams.com \ --cc=gregkh@linuxfoundation.org \ --cc=jic23@kernel.org \ --cc=knaack.h@gmx.de \ --cc=lars@metafoo.de \ --cc=linux-iio@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=pmeerw@pmeerw.net \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.