linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bryan Freed <bfreed@chromium.org>
To: linux-kernel@vger.kernel.org
Cc: jic23@cam.ac.uk, jbrenner@taosinc.com, gregkh@suse.de,
	arnd@arndb.de, Bryan Freed <bfreed@chromium.org>
Subject: [PATCH 2/2] light sensor: Preserve granularity of amplified tsl2583 light sensor values.
Date: Fri, 10 Jun 2011 13:26:20 -0700	[thread overview]
Message-ID: <1307737580-14131-2-git-send-email-bfreed@chromium.org> (raw)
In-Reply-To: <1307737580-14131-1-git-send-email-bfreed@chromium.org>

Use 64bit lux64 to amplify lux values while preserving granularity.
Normalize illuminance_calibbias amplification value at 1024 instead of 1000
so we can avoid 64bit division (div_u64).

Signed-off-by: Bryan Freed <bfreed@chromium.org>
---
 drivers/staging/iio/light/tsl2583.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/staging/iio/light/tsl2583.c b/drivers/staging/iio/light/tsl2583.c
index 5694610..0324ac1 100644
--- a/drivers/staging/iio/light/tsl2583.c
+++ b/drivers/staging/iio/light/tsl2583.c
@@ -146,7 +146,7 @@ static void taos_defaults(struct tsl2583_chip *chip)
 	chip->taos_settings.als_gain = 0;
 	/* this is actually an index into the gain table */
 	/* assume clear glass as default */
-	chip->taos_settings.als_gain_trim = 1000;
+	chip->taos_settings.als_gain_trim = 1024;
 	/* default gain trim to account for aperture effects */
 	chip->taos_settings.als_cal_target = 130;
 	/* Known external ALS reading used for calibration */
@@ -195,6 +195,7 @@ static int taos_get_lux(struct i2c_client *client)
 {
 	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;
@@ -298,8 +299,10 @@ static int taos_get_lux(struct i2c_client *client)
 			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;
+	lux64 = lux;
+	lux64 = (lux64 * chip->taos_settings.als_gain_trim + 512) >> 10;
+	lux64 >>= 13; /* tables have factor of 8192 builtin for accuracy */
+	lux = lux64;
 	if (lux > TSL258X_LUX_CALC_OVER_FLOW) { /* check for overflow */
 return_max:
 		lux = TSL258X_LUX_CALC_OVER_FLOW;
-- 
1.7.3.1


  reply	other threads:[~2011-06-10 20:36 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-10 20:26 [PATCH 1/2] light sensor: Add a calibration file to the isl29018 driver Bryan Freed
2011-06-10 20:26 ` Bryan Freed [this message]
2011-06-13  8:57 ` Jonathan Cameron
     [not found]   ` <BANLkTinPg158f7A7BSZ7v=M3QecZ-1HYLujq5sOjDa32oVDCkg@mail.gmail.com>
2011-06-16  9:09     ` Jonathan Cameron
     [not found]       ` <BANLkTikJ++PDyW2q6H0OiWVuGRgGqzCPg=0giBxEANgHO_n-0Q@mail.gmail.com>
2011-06-17  8:44         ` 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=1307737580-14131-2-git-send-email-bfreed@chromium.org \
    --to=bfreed@chromium.org \
    --cc=arnd@arndb.de \
    --cc=gregkh@suse.de \
    --cc=jbrenner@taosinc.com \
    --cc=jic23@cam.ac.uk \
    --cc=linux-kernel@vger.kernel.org \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).