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

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
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -1429,9 +1429,11 @@ static int adxl367_verify_devid(struct adxl367_state *st)
	unsigned int val;
	int ret;

	ret = regmap_read_poll_timeout(st->regmap, ADXL367_REG_DEVID, val,
				       val == ADXL367_DEVID_AD, 1000, 10000);
	ret = regmap_read(st->regmap, ADXL367_REG_DEVID, &val);
	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,
				     "Invalid dev id 0x%02X, expected 0x%02X\n",
				     val, ADXL367_DEVID_AD);
@@ -1510,6 +1512,8 @@ int adxl367_probe(struct device *dev, const struct adxl367_ops *ops,
	if (ret)
		return ret;

	fsleep(15000);

	ret = adxl367_verify_devid(st);
	if (ret)
		return ret;
+1 −1
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@

#include "adxl367.h"

#define ADXL367_I2C_FIFO_DATA	0x42
#define ADXL367_I2C_FIFO_DATA	0x18

struct adxl367_i2c_state {
	struct regmap *regmap;
+2 −0
Original line number Diff line number Diff line
@@ -109,6 +109,8 @@ irqreturn_t inv_mpu6050_read_fifo(int irq, void *p)
	/* compute and process only all complete datum */
	nb = fifo_count / 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 */
	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);
+5 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ int inv_mpu6050_prepare_fifo(struct inv_mpu6050_state *st, bool enable)
	if (enable) {
		/* reset timestamping */
		inv_sensors_timestamp_reset(&st->timestamp);
		inv_sensors_timestamp_apply_odr(&st->timestamp, 0, 0, 0);
		/* reset FIFO */
		d = st->chip_config.user_ctrl | INV_MPU6050_BIT_FIFO_RST;
		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)
		if (result)
			goto error_power_off;
	} 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);
		if (result)
			goto error_power_off;
+49 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@
 *
 * Inspired by the older BMP085 driver drivers/misc/bmp085-spi.c
 */
#include <linux/bits.h>
#include <linux/module.h>
#include <linux/spi/spi.h>
#include <linux/err.h>
@@ -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);
}

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 = {
	.write = bmp280_regmap_spi_write,
	.read = bmp280_regmap_spi_read,
@@ -42,10 +71,19 @@ static struct regmap_bus bmp280_regmap_bus = {
	.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)
{
	const struct spi_device_id *id = spi_get_device_id(spi);
	const struct bmp280_chip_info *chip_info;
	struct regmap_bus *bmp_regmap_bus;
	struct regmap *regmap;
	int ret;

@@ -58,8 +96,18 @@ static int bmp280_spi_probe(struct spi_device *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,
				  &bmp280_regmap_bus,
				  bmp_regmap_bus,
				  &spi->dev,
				  chip_info->regmap_config);
	if (IS_ERR(regmap)) {
Loading