68d0d6
Bugzilla: 785814
68d0d6
Upstream-status: ??
68d0d6
Dave Jones abc7c8
>From 56fb161a9ca0129f8e266e4dbe79346552ff8089 Mon Sep 17 00:00:00 2001
Dave Jones abc7c8
From: =?UTF-8?q?=C3=89ric=20Piel?= <eric.piel@tremplin-utc.net>
Dave Jones abc7c8
Date: Thu, 3 Nov 2011 16:22:40 +0100
Dave Jones abc7c8
Subject: [PATCH] lis3: Improve handling of null rate
Dave Jones abc7c8
MIME-Version: 1.0
Dave Jones abc7c8
Content-Type: text/plain; charset=UTF-8
Dave Jones abc7c8
Content-Transfer-Encoding: 8bit
Dave Jones abc7c8
Dave Jones abc7c8
When obtaining a rate of 0, we would disable the device supposely
Dave Jones abc7c8
because it seems to behave incorectly. It actually only comes from the
Dave Jones abc7c8
fact that the device is off and on lis3dc it's reflected in the rate.
Dave Jones abc7c8
So handle this nicely by just waiting a safe time, and then using the
Dave Jones abc7c8
device as normally.
Dave Jones abc7c8
Dave Jones abc7c8
Signed-off-by: ??ric Piel <eric.piel@tremplin-utc.net>
Dave Jones abc7c8
---
Dave Jones abc7c8
 drivers/misc/lis3lv02d/lis3lv02d.c |   16 ++++++++--------
Dave Jones abc7c8
 1 files changed, 8 insertions(+), 8 deletions(-)
Dave Jones abc7c8
Dave Jones abc7c8
diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
Dave Jones abc7c8
index 35c67e0..42dce2a 100644
Dave Jones abc7c8
--- a/drivers/misc/lis3lv02d/lis3lv02d.c
Dave Jones abc7c8
+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
Dave Jones abc7c8
@@ -188,7 +188,8 @@ static void lis3lv02d_get_xyz(struct lis3lv02d *lis3, int *x, int *y, int *z)
Dave Jones abc7c8
 /* conversion btw sampling rate and the register values */
Dave Jones abc7c8
 static int lis3_12_rates[4] = {40, 160, 640, 2560};
Dave Jones abc7c8
 static int lis3_8_rates[2] = {100, 400};
Dave Jones abc7c8
-static int lis3_3dc_rates[16] = {0, 1, 10, 25, 50, 100, 200, 400, 1600, 5000};
Dave Jones abc7c8
+/* LIS3DC: 0 = power off, above 9 = undefined */
Dave Jones abc7c8
+static int lis3_3dc_rates[16] = {0, 1, 10, 25, 50, 100, 200, 400, 1600, 5000, -1, -1, -1, -1, -1, -1};
fc8536
 static int lis3_3dlh_rates[4] = {50, 100, 400, 1000};
Dave Jones abc7c8
 
Dave Jones abc7c8
 /* ODR is Output Data Rate */
Dave Jones abc7c8
@@ -202,12 +203,11 @@ static int lis3lv02d_get_odr(struct lis3lv02d *lis3)
Dave Jones abc7c8
 	return lis3->odrs[(ctrl >> shift)];
Dave Jones abc7c8
 }
Dave Jones abc7c8
 
Dave Jones abc7c8
-static int lis3lv02d_get_pwron_wait(struct lis3lv02d *lis3)
Dave Jones abc7c8
+static int lis3lv02d_wait_pwron(struct lis3lv02d *lis3)
Dave Jones abc7c8
 {
Dave Jones abc7c8
 	int div = lis3lv02d_get_odr(lis3);
Dave Jones abc7c8
-
Dave Jones abc7c8
-	if (WARN_ONCE(div == 0, "device returned spurious data"))
Dave Jones abc7c8
-		return -ENXIO;
Dave Jones abc7c8
+	if (div <= 0)
Dave Jones abc7c8
+		div = 1; /* maximum delay */
Dave Jones abc7c8
 
Dave Jones abc7c8
 	/* LIS3 power on delay is quite long */
Dave Jones abc7c8
 	msleep(lis3->pwron_delay / div);
Dave Jones abc7c8
@@ -274,7 +274,7 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
Dave Jones abc7c8
 
Dave Jones abc7c8
 	lis3->read(lis3, ctlreg, ®);
Dave Jones abc7c8
 	lis3->write(lis3, ctlreg, (reg | selftest));
Dave Jones abc7c8
-	ret = lis3lv02d_get_pwron_wait(lis3);
Dave Jones abc7c8
+	ret = lis3lv02d_wait_pwron(lis3);
Dave Jones abc7c8
 	if (ret)
Dave Jones abc7c8
 		goto fail;
Dave Jones abc7c8
 
Dave Jones abc7c8
@@ -285,7 +285,7 @@ static int lis3lv02d_selftest(struct lis3lv02d *lis3, s16 results[3])
Dave Jones abc7c8
 
Dave Jones abc7c8
 	/* back to normal settings */
Dave Jones abc7c8
 	lis3->write(lis3, ctlreg, reg);
Dave Jones abc7c8
-	ret = lis3lv02d_get_pwron_wait(lis3);
Dave Jones abc7c8
+	ret = lis3lv02d_wait_pwron(lis3);
Dave Jones abc7c8
 	if (ret)
Dave Jones abc7c8
 		goto fail;
Dave Jones abc7c8
 
Dave Jones abc7c8
@@ -397,7 +397,7 @@ int lis3lv02d_poweron(struct lis3lv02d *lis3)
Dave Jones abc7c8
 		lis3->write(lis3, CTRL_REG2, reg);
Dave Jones abc7c8
 	}
Dave Jones abc7c8
 
Dave Jones abc7c8
-	err = lis3lv02d_get_pwron_wait(lis3);
Dave Jones abc7c8
+	err = lis3lv02d_wait_pwron(lis3);
Dave Jones abc7c8
 	if (err)
Dave Jones abc7c8
 		return err;
Dave Jones abc7c8
 
Dave Jones abc7c8
-- 
Dave Jones abc7c8
1.7.7.1
Dave Jones abc7c8