Skip to content

Commit 6e82ae6

Browse files
jmaneyrol-invnjic23
authored andcommitted
iio: imu: inv_mpu6050: fix no data on MPU6050
Some chips have a fifo overflow bit issue where the bit is always set. The result is that every data is dropped. Change fifo overflow management by checking fifo count against a maximum value. Add fifo size in chip hardware set of values. Fixes: f5057e7 ("iio: imu: inv_mpu6050: better fifo overflow handling") Cc: [email protected] Signed-off-by: Jean-Baptiste Maneyrol <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 431f766 commit 6e82ae6

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

drivers/iio/imu/inv_mpu6050/inv_mpu_core.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,54 +114,63 @@ static const struct inv_mpu6050_hw hw_info[] = {
114114
.name = "MPU6050",
115115
.reg = &reg_set_6050,
116116
.config = &chip_config_6050,
117+
.fifo_size = 1024,
117118
},
118119
{
119120
.whoami = INV_MPU6500_WHOAMI_VALUE,
120121
.name = "MPU6500",
121122
.reg = &reg_set_6500,
122123
.config = &chip_config_6050,
124+
.fifo_size = 512,
123125
},
124126
{
125127
.whoami = INV_MPU6515_WHOAMI_VALUE,
126128
.name = "MPU6515",
127129
.reg = &reg_set_6500,
128130
.config = &chip_config_6050,
131+
.fifo_size = 512,
129132
},
130133
{
131134
.whoami = INV_MPU6000_WHOAMI_VALUE,
132135
.name = "MPU6000",
133136
.reg = &reg_set_6050,
134137
.config = &chip_config_6050,
138+
.fifo_size = 1024,
135139
},
136140
{
137141
.whoami = INV_MPU9150_WHOAMI_VALUE,
138142
.name = "MPU9150",
139143
.reg = &reg_set_6050,
140144
.config = &chip_config_6050,
145+
.fifo_size = 1024,
141146
},
142147
{
143148
.whoami = INV_MPU9250_WHOAMI_VALUE,
144149
.name = "MPU9250",
145150
.reg = &reg_set_6500,
146151
.config = &chip_config_6050,
152+
.fifo_size = 512,
147153
},
148154
{
149155
.whoami = INV_MPU9255_WHOAMI_VALUE,
150156
.name = "MPU9255",
151157
.reg = &reg_set_6500,
152158
.config = &chip_config_6050,
159+
.fifo_size = 512,
153160
},
154161
{
155162
.whoami = INV_ICM20608_WHOAMI_VALUE,
156163
.name = "ICM20608",
157164
.reg = &reg_set_6500,
158165
.config = &chip_config_6050,
166+
.fifo_size = 512,
159167
},
160168
{
161169
.whoami = INV_ICM20602_WHOAMI_VALUE,
162170
.name = "ICM20602",
163171
.reg = &reg_set_icm20602,
164172
.config = &chip_config_6050,
173+
.fifo_size = 1008,
165174
},
166175
};
167176

drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,14 @@ struct inv_mpu6050_chip_config {
100100
* @name: name of the chip.
101101
* @reg: register map of the chip.
102102
* @config: configuration of the chip.
103+
* @fifo_size: size of the FIFO in bytes.
103104
*/
104105
struct inv_mpu6050_hw {
105106
u8 whoami;
106107
u8 *name;
107108
const struct inv_mpu6050_reg_map *reg;
108109
const struct inv_mpu6050_chip_config *config;
110+
size_t fifo_size;
109111
};
110112

111113
/*

drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,6 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
180180
"failed to ack interrupt\n");
181181
goto flush_fifo;
182182
}
183-
/* handle fifo overflow by reseting fifo */
184-
if (int_status & INV_MPU6050_BIT_FIFO_OVERFLOW_INT)
185-
goto flush_fifo;
186183
if (!(int_status & INV_MPU6050_BIT_RAW_DATA_RDY_INT)) {
187184
dev_warn(regmap_get_device(st->map),
188185
"spurious interrupt with status 0x%x\n", int_status);
@@ -211,6 +208,18 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
211208
if (result)
212209
goto end_session;
213210
fifo_count = get_unaligned_be16(&data[0]);
211+
212+
/*
213+
* Handle fifo overflow by resetting fifo.
214+
* Reset if there is only 3 data set free remaining to mitigate
215+
* possible delay between reading fifo count and fifo data.
216+
*/
217+
nb = 3 * bytes_per_datum;
218+
if (fifo_count >= st->hw->fifo_size - nb) {
219+
dev_warn(regmap_get_device(st->map), "fifo overflow reset\n");
220+
goto flush_fifo;
221+
}
222+
214223
/* compute and process all complete datum */
215224
nb = fifo_count / bytes_per_datum;
216225
inv_mpu6050_update_period(st, pf->timestamp, nb);

0 commit comments

Comments
 (0)