lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1307737580-14131-2-git-send-email-bfreed@chromium.org>
Date:	Fri, 10 Jun 2011 13:26:20 -0700
From:	Bryan Freed <bfreed@...omium.org>
To:	linux-kernel@...r.kernel.org
Cc:	jic23@....ac.uk, jbrenner@...sinc.com, gregkh@...e.de,
	arnd@...db.de, Bryan Freed <bfreed@...omium.org>
Subject: [PATCH 2/2] light sensor: Preserve granularity of amplified tsl2583 light sensor values.

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@...omium.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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ