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
6a9155
Subject: [PATCH] lis3: improve handling of null rate
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
6a9155
Bugzilla: 785814
6a9155
Upstream-status: ??
6a9155
Dave Jones abc7c8
Signed-off-by: ??ric Piel <eric.piel@tremplin-utc.net>
Dave Jones abc7c8
---
6a9155
 drivers/misc/lis3lv02d/lis3lv02d.c | 16 ++++++++--------
6a9155
 1 file 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
088a50
index fb8705fc3aca..50c2b93c1273 100644
Dave Jones abc7c8
--- a/drivers/misc/lis3lv02d/lis3lv02d.c
Dave Jones abc7c8
+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
6a9155
@@ -216,7 +216,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 */
6a9155
@@ -231,12 +232,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);
6a9155
@@ -303,7 +303,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
 
6a9155
@@ -314,7 +314,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
 
6a9155
@@ -434,7 +434,7 @@ int lis3lv02d_poweron(struct lis3lv02d *lis3)
6a9155
 		}
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