]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blame - releases/4.4.61/iio-bmg160-reset-chip-when-probing.patch
Fixes for 4.19
[thirdparty/kernel/stable-queue.git] / releases / 4.4.61 / iio-bmg160-reset-chip-when-probing.patch
CommitLineData
f99637f6
GKH
1From 4bdc9029685ac03be50b320b29691766d2326c2b Mon Sep 17 00:00:00 2001
2From: Quentin Schulz <quentin.schulz@free-electrons.com>
3Date: Tue, 21 Mar 2017 16:52:14 +0100
4Subject: iio: bmg160: reset chip when probing
5
6From: Quentin Schulz <quentin.schulz@free-electrons.com>
7
8commit 4bdc9029685ac03be50b320b29691766d2326c2b upstream.
9
10The gyroscope chip might need to be reset to be used.
11
12Without the chip being reset, the driver stopped at the first
13regmap_read (to get the CHIP_ID) and failed to probe.
14
15The datasheet of the gyroscope says that a minimum wait of 30ms after
16the reset has to be done.
17
18This patch has been checked on a BMX055 and the datasheet of the BMG160
19and the BMI055 give the same reset register and bits.
20
21Signed-off-by: Quentin Schulz <quentin.schulz@free-electrons.com>
22Signed-off-by: Jonathan Cameron <jic23@kernel.org>
23Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
24
25---
26 drivers/iio/gyro/bmg160_core.c | 12 ++++++++++++
27 1 file changed, 12 insertions(+)
28
29--- a/drivers/iio/gyro/bmg160_core.c
30+++ b/drivers/iio/gyro/bmg160_core.c
31@@ -28,6 +28,7 @@
32 #include <linux/iio/trigger_consumer.h>
33 #include <linux/iio/triggered_buffer.h>
34 #include <linux/regmap.h>
35+#include <linux/delay.h>
36 #include "bmg160.h"
37
38 #define BMG160_IRQ_NAME "bmg160_event"
39@@ -53,6 +54,9 @@
40 #define BMG160_NO_FILTER 0
41 #define BMG160_DEF_BW 100
42
43+#define BMG160_GYRO_REG_RESET 0x14
44+#define BMG160_GYRO_RESET_VAL 0xb6
45+
46 #define BMG160_REG_INT_MAP_0 0x17
47 #define BMG160_INT_MAP_0_BIT_ANY BIT(1)
48
49@@ -186,6 +190,14 @@ static int bmg160_chip_init(struct bmg16
50 int ret;
51 unsigned int val;
52
53+ /*
54+ * Reset chip to get it in a known good state. A delay of 30ms after
55+ * reset is required according to the datasheet.
56+ */
57+ regmap_write(data->regmap, BMG160_GYRO_REG_RESET,
58+ BMG160_GYRO_RESET_VAL);
59+ usleep_range(30000, 30700);
60+
61 ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val);
62 if (ret < 0) {
63 dev_err(data->dev, "Error reading reg_chip_id\n");