Skip to content

Commit da85c25

Browse files
committed
Merge tag 'iio-fixes-for-6.8b' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-linus
Jonathan writes: IIO: 2nd set of fixes for the 6.8 cycle. Given this is very late these can wait for the 6.9 cycle if you would prefer. adi,adxl367 - Sleep for 15ms after reset to avoid reading before the device is awake. - Fix FIFO register address. asc,dlhl60d - Avoid uninitialized data leak to user-space. Also suppress a false positive clang warning by refactoring a loop. bosch,bmp280 - Fix missing extra byte in SPI reads from BMP38x and BMP390 parts invensense,mpu6050 - Fix handing of empty FIFO which can happen due to a race condition. - Make sure frequency can be updated more than once when the FIFO is not enabled. * tag 'iio-fixes-for-6.8b' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: iio: accel: adxl367: fix I2C FIFO data register iio: accel: adxl367: fix DEVID read after reset iio: pressure: dlhl60d: Initialize empty DLH bytes iio: imu: inv_mpu6050: fix frequency setting when chip is off iio: pressure: Fixes BMP38x and BMP390 SPI support iio: imu: inv_mpu6050: fix FIFO parsing when empty
2 parents febbe9b + 11dadb6 commit da85c25

File tree

6 files changed

+66
-8
lines changed

6 files changed

+66
-8
lines changed

drivers/iio/accel/adxl367.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,9 +1429,11 @@ static int adxl367_verify_devid(struct adxl367_state *st)
14291429
unsigned int val;
14301430
int ret;
14311431

1432-
ret = regmap_read_poll_timeout(st->regmap, ADXL367_REG_DEVID, val,
1433-
val == ADXL367_DEVID_AD, 1000, 10000);
1432+
ret = regmap_read(st->regmap, ADXL367_REG_DEVID, &val);
14341433
if (ret)
1434+
return dev_err_probe(st->dev, ret, "Failed to read dev id\n");
1435+
1436+
if (val != ADXL367_DEVID_AD)
14351437
return dev_err_probe(st->dev, -ENODEV,
14361438
"Invalid dev id 0x%02X, expected 0x%02X\n",
14371439
val, ADXL367_DEVID_AD);
@@ -1510,6 +1512,8 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,
15101512
if (ret)
15111513
return ret;
15121514

1515+
fsleep(15000);
1516+
15131517
ret = adxl367_verify_devid(st);
15141518
if (ret)
15151519
return ret;

drivers/iio/accel/adxl367_i2c.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
#include "adxl367.h"
1313

14-
#define ADXL367_I2C_FIFO_DATA 0x42
14+
#define ADXL367_I2C_FIFO_DATA 0x18
1515

1616
struct adxl367_i2c_state {
1717
struct regmap *regmap;

drivers/iio/imu/inv_mpu6050/inv_mpu_ring.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
109109
/* compute and process only all complete datum */
110110
nb = fifo_count / bytes_per_datum;
111111
fifo_count = nb * bytes_per_datum;
112+
if (nb == 0)
113+
goto end_session;
112114
/* Each FIFO data contains all sensors, so same number for FIFO and sensor data */
113115
fifo_period = NSEC_PER_SEC / INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider);
114116
inv_sensors_timestamp_interrupt(&st->timestamp, fifo_period, nb, nb, pf->timestamp);

drivers/iio/imu/inv_mpu6050/inv_mpu_trigger.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable)
111111
if (enable) {
112112
/* reset timestamping */
113113
inv_sensors_timestamp_reset(&st->timestamp);
114+
inv_sensors_timestamp_apply_odr(&st->timestamp, 0, 0, 0);
114115
/* reset FIFO */
115116
d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_RST;
116117
ret = regmap_write(st->map, st->reg->user_ctrl, d);
@@ -184,6 +185,10 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable)
184185
if (result)
185186
goto error_power_off;
186187
} else {
188+
st->chip_config.gyro_fifo_enable = 0;
189+
st->chip_config.accl_fifo_enable = 0;
190+
st->chip_config.temp_fifo_enable = 0;
191+
st->chip_config.magn_fifo_enable = 0;
187192
result = inv_mpu6050_prepare_fifo(st, false);
188193
if (result)
189194
goto error_power_off;

drivers/iio/pressure/bmp280-spi.c

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*
55
* Inspired by the older BMP085 driver drivers/misc/bmp085-spi.c
66
*/
7+
#include <linux/bits.h>
78
#include <linux/module.h>
89
#include <linux/spi/spi.h>
910
#include <linux/err.h>
@@ -35,17 +36,54 @@ static int bmp280_regmap_spi_read(void *context, const void *reg,
3536
return spi_write_then_read(spi, reg, reg_size, val, val_size);
3637
}
3738

39+
static int bmp380_regmap_spi_read(void *context, const void *reg,
40+
size_t reg_size, void *val, size_t val_size)
41+
{
42+
struct spi_device *spi = to_spi_device(context);
43+
u8 rx_buf[4];
44+
ssize_t status;
45+
46+
/*
47+
* Maximum number of consecutive bytes read for a temperature or
48+
* pressure measurement is 3.
49+
*/
50+
if (val_size > 3)
51+
return -EINVAL;
52+
53+
/*
54+
* According to the BMP3xx datasheets, for a basic SPI read opertion,
55+
* the first byte needs to be dropped and the rest are the requested
56+
* data.
57+
*/
58+
status = spi_write_then_read(spi, reg, 1, rx_buf, val_size + 1);
59+
if (status)
60+
return status;
61+
62+
memcpy(val, rx_buf + 1, val_size);
63+
64+
return 0;
65+
}
66+
3867
static struct regmap_bus bmp280_regmap_bus = {
3968
.write = bmp280_regmap_spi_write,
4069
.read = bmp280_regmap_spi_read,
4170
.reg_format_endian_default = REGMAP_ENDIAN_BIG,
4271
.val_format_endian_default = REGMAP_ENDIAN_BIG,
4372
};
4473

74+
static struct regmap_bus bmp380_regmap_bus = {
75+
.write = bmp280_regmap_spi_write,
76+
.read = bmp380_regmap_spi_read,
77+
.read_flag_mask = BIT(7),
78+
.reg_format_endian_default = REGMAP_ENDIAN_BIG,
79+
.val_format_endian_default = REGMAP_ENDIAN_BIG,
80+
};
81+
4582
static int bmp280_spi_probe(struct spi_device *spi)
4683
{
4784
const struct spi_device_id *id = spi_get_device_id(spi);
4885
const struct bmp280_chip_info *chip_info;
86+
struct regmap_bus *bmp_regmap_bus;
4987
struct regmap *regmap;
5088
int ret;
5189

@@ -58,8 +96,18 @@ static int bmp280_spi_probe(struct spi_device *spi)
5896

5997
chip_info = spi_get_device_match_data(spi);
6098

99+
switch (chip_info->chip_id[0]) {
100+
case BMP380_CHIP_ID:
101+
case BMP390_CHIP_ID:
102+
bmp_regmap_bus = &bmp380_regmap_bus;
103+
break;
104+
default:
105+
bmp_regmap_bus = &bmp280_regmap_bus;
106+
break;
107+
}
108+
61109
regmap = devm_regmap_init(&spi->dev,
62-
&bmp280_regmap_bus,
110+
bmp_regmap_bus,
63111
&spi->dev,
64112
chip_info->regmap_config);
65113
if (IS_ERR(regmap)) {

drivers/iio/pressure/dlhl60d.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,18 +250,17 @@ static irqreturn_t dlh_trigger_handler(int irq, void *private)
250250
struct dlh_state *st = iio_priv(indio_dev);
251251
int ret;
252252
unsigned int chn, i = 0;
253-
__be32 tmp_buf[2];
253+
__be32 tmp_buf[2] = { };
254254

255255
ret = dlh_start_capture_and_read(st);
256256
if (ret)
257257
goto out;
258258

259259
for_each_set_bit(chn, indio_dev->active_scan_mask,
260-
indio_dev->masklength) {
261-
memcpy(tmp_buf + i,
260+
indio_dev->masklength) {
261+
memcpy(&tmp_buf[i++],
262262
&st->rx_buf[1] + chn * DLH_NUM_DATA_BYTES,
263263
DLH_NUM_DATA_BYTES);
264-
i++;
265264
}
266265

267266
iio_push_to_buffers(indio_dev, tmp_buf);

0 commit comments

Comments
 (0)