Commit da85c25c authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

Merge tag 'iio-fixes-for-6.8b' of...

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
parents febbe9b9 11dadb63
...@@ -1429,9 +1429,11 @@ static int adxl367_verify_devid(struct adxl367_state *st) ...@@ -1429,9 +1429,11 @@ static int adxl367_verify_devid(struct adxl367_state *st)
unsigned int val; unsigned int val;
int ret; int ret;
ret = regmap_read_poll_timeout(st->regmap, ADXL367_REG_DEVID, val, ret = regmap_read(st->regmap, ADXL367_REG_DEVID, &val);
val == ADXL367_DEVID_AD, 1000, 10000);
if (ret) if (ret)
return dev_err_probe(st->dev, ret, "Failed to read dev id\n");
if (val != ADXL367_DEVID_AD)
return dev_err_probe(st->dev, -ENODEV, return dev_err_probe(st->dev, -ENODEV,
"Invalid dev id 0x%02X, expected 0x%02X\n", "Invalid dev id 0x%02X, expected 0x%02X\n",
val, ADXL367_DEVID_AD); val, ADXL367_DEVID_AD);
...@@ -1510,6 +1512,8 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops, ...@@ -1510,6 +1512,8 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,
if (ret) if (ret)
return ret; return ret;
fsleep(15000);
ret = adxl367_verify_devid(st); ret = adxl367_verify_devid(st);
if (ret) if (ret)
return ret; return ret;
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "adxl367.h" #include "adxl367.h"
#define ADXL367_I2C_FIFO_DATA 0x42 #define ADXL367_I2C_FIFO_DATA 0x18
struct adxl367_i2c_state { struct adxl367_i2c_state {
struct regmap *regmap; struct regmap *regmap;
......
...@@ -109,6 +109,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p) ...@@ -109,6 +109,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
/* compute and process only all complete datum */ /* compute and process only all complete datum */
nb = fifo_count / bytes_per_datum; nb = fifo_count / bytes_per_datum;
fifo_count = nb * bytes_per_datum; fifo_count = nb * bytes_per_datum;
if (nb == 0)
goto end_session;
/* Each FIFO data contains all sensors, so same number for FIFO and sensor data */ /* Each FIFO data contains all sensors, so same number for FIFO and sensor data */
fifo_period = NSEC_PER_SEC / INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider); fifo_period = NSEC_PER_SEC / INV_MPU6050_DIVIDER_TO_FIFO_RATE(st->chip_config.divider);
inv_sensors_timestamp_interrupt(&st->timestamp, fifo_period, nb, nb, pf->timestamp); inv_sensors_timestamp_interrupt(&st->timestamp, fifo_period, nb, nb, pf->timestamp);
......
...@@ -111,6 +111,7 @@ int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable) ...@@ -111,6 +111,7 @@ int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable)
if (enable) { if (enable) {
/* reset timestamping */ /* reset timestamping */
inv_sensors_timestamp_reset(&st->timestamp); inv_sensors_timestamp_reset(&st->timestamp);
inv_sensors_timestamp_apply_odr(&st->timestamp, 0, 0, 0);
/* reset FIFO */ /* reset FIFO */
d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_RST; d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_RST;
ret = regmap_write(st->map, st->reg->user_ctrl, d); 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) ...@@ -184,6 +185,10 @@ static int inv_mpu6050_set_enable(struct iio_dev *indio_dev, bool enable)
if (result) if (result)
goto error_power_off; goto error_power_off;
} else { } else {
st->chip_config.gyro_fifo_enable = 0;
st->chip_config.accl_fifo_enable = 0;
st->chip_config.temp_fifo_enable = 0;
st->chip_config.magn_fifo_enable = 0;
result = inv_mpu6050_prepare_fifo(st, false); result = inv_mpu6050_prepare_fifo(st, false);
if (result) if (result)
goto error_power_off; goto error_power_off;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* *
* Inspired by the older BMP085 driver drivers/misc/bmp085-spi.c * Inspired by the older BMP085 driver drivers/misc/bmp085-spi.c
*/ */
#include <linux/bits.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/spi/spi.h> #include <linux/spi/spi.h>
#include <linux/err.h> #include <linux/err.h>
...@@ -35,6 +36,34 @@ static int bmp280_regmap_spi_read(void *context, const void *reg, ...@@ -35,6 +36,34 @@ static int bmp280_regmap_spi_read(void *context, const void *reg,
return spi_write_then_read(spi, reg, reg_size, val, val_size); return spi_write_then_read(spi, reg, reg_size, val, val_size);
} }
static int bmp380_regmap_spi_read(void *context, const void *reg,
size_t reg_size, void *val, size_t val_size)
{
struct spi_device *spi = to_spi_device(context);
u8 rx_buf[4];
ssize_t status;
/*
* Maximum number of consecutive bytes read for a temperature or
* pressure measurement is 3.
*/
if (val_size > 3)
return -EINVAL;
/*
* According to the BMP3xx datasheets, for a basic SPI read opertion,
* the first byte needs to be dropped and the rest are the requested
* data.
*/
status = spi_write_then_read(spi, reg, 1, rx_buf, val_size + 1);
if (status)
return status;
memcpy(val, rx_buf + 1, val_size);
return 0;
}
static struct regmap_bus bmp280_regmap_bus = { static struct regmap_bus bmp280_regmap_bus = {
.write = bmp280_regmap_spi_write, .write = bmp280_regmap_spi_write,
.read = bmp280_regmap_spi_read, .read = bmp280_regmap_spi_read,
...@@ -42,10 +71,19 @@ static struct regmap_bus bmp280_regmap_bus = { ...@@ -42,10 +71,19 @@ static struct regmap_bus bmp280_regmap_bus = {
.val_format_endian_default = REGMAP_ENDIAN_BIG, .val_format_endian_default = REGMAP_ENDIAN_BIG,
}; };
static struct regmap_bus bmp380_regmap_bus = {
.write = bmp280_regmap_spi_write,
.read = bmp380_regmap_spi_read,
.read_flag_mask = BIT(7),
.reg_format_endian_default = REGMAP_ENDIAN_BIG,
.val_format_endian_default = REGMAP_ENDIAN_BIG,
};
static int bmp280_spi_probe(struct spi_device *spi) static int bmp280_spi_probe(struct spi_device *spi)
{ {
const struct spi_device_id *id = spi_get_device_id(spi); const struct spi_device_id *id = spi_get_device_id(spi);
const struct bmp280_chip_info *chip_info; const struct bmp280_chip_info *chip_info;
struct regmap_bus *bmp_regmap_bus;
struct regmap *regmap; struct regmap *regmap;
int ret; int ret;
...@@ -58,8 +96,18 @@ static int bmp280_spi_probe(struct spi_device *spi) ...@@ -58,8 +96,18 @@ static int bmp280_spi_probe(struct spi_device *spi)
chip_info = spi_get_device_match_data(spi); chip_info = spi_get_device_match_data(spi);
switch (chip_info->chip_id[0]) {
case BMP380_CHIP_ID:
case BMP390_CHIP_ID:
bmp_regmap_bus = &bmp380_regmap_bus;
break;
default:
bmp_regmap_bus = &bmp280_regmap_bus;
break;
}
regmap = devm_regmap_init(&spi->dev, regmap = devm_regmap_init(&spi->dev,
&bmp280_regmap_bus, bmp_regmap_bus,
&spi->dev, &spi->dev,
chip_info->regmap_config); chip_info->regmap_config);
if (IS_ERR(regmap)) { if (IS_ERR(regmap)) {
......
...@@ -250,7 +250,7 @@ static irqreturn_t dlh_trigger_handler(int irq, void *private) ...@@ -250,7 +250,7 @@ static irqreturn_t dlh_trigger_handler(int irq, void *private)
struct dlh_state *st = iio_priv(indio_dev); struct dlh_state *st = iio_priv(indio_dev);
int ret; int ret;
unsigned int chn, i = 0; unsigned int chn, i = 0;
__be32 tmp_buf[2]; __be32 tmp_buf[2] = { };
ret = dlh_start_capture_and_read(st); ret = dlh_start_capture_and_read(st);
if (ret) if (ret)
...@@ -258,10 +258,9 @@ static irqreturn_t dlh_trigger_handler(int irq, void *private) ...@@ -258,10 +258,9 @@ static irqreturn_t dlh_trigger_handler(int irq, void *private)
for_each_set_bit(chn, indio_dev->active_scan_mask, for_each_set_bit(chn, indio_dev->active_scan_mask,
indio_dev->masklength) { indio_dev->masklength) {
memcpy(tmp_buf + i, memcpy(&tmp_buf[i++],
&st->rx_buf[1] + chn * DLH_NUM_DATA_BYTES, &st->rx_buf[1] + chn * DLH_NUM_DATA_BYTES,
DLH_NUM_DATA_BYTES); DLH_NUM_DATA_BYTES);
i++;
} }
iio_push_to_buffers(indio_dev, tmp_buf); iio_push_to_buffers(indio_dev, tmp_buf);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment