Skip to content

Commit fe4c593

Browse files
committed
Merge tag 'iio-fixes-for-5.4b' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus
Second set of IIO fixes for the 5.4 cycle. * adis16480 - Prevent negative numbers being accepted for sampling frequency. * inv_mpu6050 - Fix an issue where fifo overflow bits don't actually work as expected, by checking the fifo count instead. * srf04 - Allow more time for echo to signal as some sensors supported have a higher range. * stm32-adc - Fix a potential race in dma disable by ensuring all transfers are done. * tag 'iio-fixes-for-5.4b' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: iio: adc: stm32-adc: fix stopping dma iio: imu: inv_mpu6050: fix no data on MPU6050 iio: srf04: fix wrong limitation in distance measuring iio: imu: adis16480: make sure provided frequency is positive
2 parents df40286 + e6afcf6 commit fe4c593

File tree

6 files changed

+44
-20
lines changed

6 files changed

+44
-20
lines changed

drivers/iio/adc/stm32-adc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,7 +1399,7 @@ static int stm32_adc_dma_start(struct iio_dev *indio_dev)
13991399
cookie = dmaengine_submit(desc);
14001400
ret = dma_submit_error(cookie);
14011401
if (ret) {
1402-
dmaengine_terminate_all(adc->dma_chan);
1402+
dmaengine_terminate_sync(adc->dma_chan);
14031403
return ret;
14041404
}
14051405

@@ -1477,7 +1477,7 @@ static void __stm32_adc_buffer_predisable(struct iio_dev *indio_dev)
14771477
stm32_adc_conv_irq_disable(adc);
14781478

14791479
if (adc->dma_chan)
1480-
dmaengine_terminate_all(adc->dma_chan);
1480+
dmaengine_terminate_sync(adc->dma_chan);
14811481

14821482
if (stm32_adc_set_trig(indio_dev, NULL))
14831483
dev_err(&indio_dev->dev, "Can't clear trigger\n");

drivers/iio/imu/adis16480.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,11 @@ static int adis16480_set_freq(struct iio_dev *indio_dev, int val, int val2)
317317
struct adis16480 *st = iio_priv(indio_dev);
318318
unsigned int t, reg;
319319

320+
if (val < 0 || val2 < 0)
321+
return -EINVAL;
322+
320323
t = val * 1000 + val2 / 1000;
321-
if (t <= 0)
324+
if (t == 0)
322325
return -EINVAL;
323326

324327
/*

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);

drivers/iio/proximity/srf04.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static int srf04_read(struct srf04_data *data)
110110
udelay(data->cfg->trigger_pulse_us);
111111
gpiod_set_value(data->gpiod_trig, 0);
112112

113-
/* it cannot take more than 20 ms */
113+
/* it should not take more than 20 ms until echo is rising */
114114
ret = wait_for_completion_killable_timeout(&data->rising, HZ/50);
115115
if (ret < 0) {
116116
mutex_unlock(&data->lock);
@@ -120,7 +120,8 @@ static int srf04_read(struct srf04_data *data)
120120
return -ETIMEDOUT;
121121
}
122122

123-
ret = wait_for_completion_killable_timeout(&data->falling, HZ/50);
123+
/* it cannot take more than 50 ms until echo is falling */
124+
ret = wait_for_completion_killable_timeout(&data->falling, HZ/20);
124125
if (ret < 0) {
125126
mutex_unlock(&data->lock);
126127
return ret;
@@ -135,19 +136,19 @@ static int srf04_read(struct srf04_data *data)
135136

136137
dt_ns = ktime_to_ns(ktime_dt);
137138
/*
138-
* measuring more than 3 meters is beyond the capabilities of
139-
* the sensor
139+
* measuring more than 6,45 meters is beyond the capabilities of
140+
* the supported sensors
140141
* ==> filter out invalid results for not measuring echos of
141142
* another us sensor
142143
*
143144
* formula:
144-
* distance 3 m
145-
* time = ---------- = --------- = 9404389 ns
146-
* speed 319 m/s
145+
* distance 6,45 * 2 m
146+
* time = ---------- = ------------ = 40438871 ns
147+
* speed 319 m/s
147148
*
148149
* using a minimum speed at -20 °C of 319 m/s
149150
*/
150-
if (dt_ns > 9404389)
151+
if (dt_ns > 40438871)
151152
return -EIO;
152153

153154
time_ns = dt_ns;
@@ -159,20 +160,20 @@ static int srf04_read(struct srf04_data *data)
159160
* with Temp in °C
160161
* and speed in m/s
161162
*
162-
* use 343 m/s as ultrasonic speed at 20 °C here in absence of the
163+
* use 343,5 m/s as ultrasonic speed at 20 °C here in absence of the
163164
* temperature
164165
*
165166
* therefore:
166-
* time 343
167-
* distance = ------ * -----
168-
* 10^6 2
167+
* time 343,5 time * 106
168+
* distance = ------ * ------- = ------------
169+
* 10^6 2 617176
169170
* with time in ns
170171
* and distance in mm (one way)
171172
*
172-
* because we limit to 3 meters the multiplication with 343 just
173+
* because we limit to 6,45 meters the multiplication with 106 just
173174
* fits into 32 bit
174175
*/
175-
distance_mm = time_ns * 343 / 2000000;
176+
distance_mm = time_ns * 106 / 617176;
176177

177178
return distance_mm;
178179
}

0 commit comments

Comments
 (0)