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