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

Merge tag 'iio-fixes-for-5.18a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio

Pull set of IIO fixes for 5.18 from Jonathan Cameron:
  "1st set of IIO fixes for the 5.18 cycle

  ad3552r:
   - Fix a bug with error codes being stored in unsigned local variable.
   - Fix IS_ERR when value is either NULL or not rather than ERR_PTR
  ad5446
   - Fix shifting of read_raw value.
  ad5592r
   - Fix missing return value being set for a fwnode property read.
  ad7280a
   - Wrong variable being used to set thresholds.
  admv8818
   - Kconfig dependency fix.
  ak8975
   - Missing regulator disable in error path.
  bmi160
   - Disable regulators in an error path.
  dac5571
   - Fix chip id detection for devices with OF bindings.
  inv_icm42600
   - Handle a case of a missing I2C NACK during initially configuration.
  ltc2688
   - Fix voltage scaling where integer part was written twice and
     decimal part not at all.
  scd4x
   - Handle error before using value.
  sx9310
   - Device property parsing against indio_dev->dev.of_node which
     hasn't been set yet.
  sx9324
   - Fix hardware gain related maths.
   - Wrong defaults for precharge internal resistance register."

* tag 'iio-fixes-for-5.18a' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio:
  iio: imu: inv_icm42600: Fix I2C init possible nack
  iio: dac: ltc2688: fix voltage scale read
  iio:dac:ad3552r: Fix an IS_ERR() vs NULL check
  iio: sx9324: Fix default precharge internal resistance register
  iio: dac: ad5446: Fix read_raw not returning set value
  iio: magnetometer: ak8975: Fix the error handling in ak8975_power_on()
  iio:proximity:sx9324: Fix hardware gain read/write
  iio:proximity:sx_common: Fix device property parsing on DT systems
  iio: adc: ad7280a: Fix wrong variable used when setting thresholds.
  iio:filter:admv8818: select REGMAP_SPI for ADMV8818
  iio: dac: ad5592r: Fix the missing return value.
  iio: dac: dac5571: Fix chip id detection for OF devices
  iio:imu:bmi160: disable regulator in error path
  iio: scd4x: check return of scd4x_write_and_fetch
  iio: dac: ad3552r: fix signedness bug in ad3552r_reset()
parents 5b47b751 b5d6ba09
......@@ -745,7 +745,7 @@ static int ad7280a_write_thresh(struct iio_dev *indio_dev,
case IIO_EV_DIR_RISING:
addr = AD7280A_CELL_OVERVOLTAGE_REG;
ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
1, val);
1, value);
if (ret)
break;
st->cell_threshhigh = value;
......@@ -753,7 +753,7 @@ static int ad7280a_write_thresh(struct iio_dev *indio_dev,
case IIO_EV_DIR_FALLING:
addr = AD7280A_CELL_UNDERVOLTAGE_REG;
ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
1, val);
1, value);
if (ret)
break;
st->cell_threshlow = value;
......@@ -770,18 +770,18 @@ static int ad7280a_write_thresh(struct iio_dev *indio_dev,
case IIO_EV_DIR_RISING:
addr = AD7280A_AUX_ADC_OVERVOLTAGE_REG;
ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
1, val);
1, value);
if (ret)
break;
st->aux_threshhigh = val;
st->aux_threshhigh = value;
break;
case IIO_EV_DIR_FALLING:
addr = AD7280A_AUX_ADC_UNDERVOLTAGE_REG;
ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, addr,
1, val);
1, value);
if (ret)
break;
st->aux_threshlow = val;
st->aux_threshlow = value;
break;
default:
ret = -EINVAL;
......
......@@ -471,12 +471,15 @@ static ssize_t calibration_forced_value_store(struct device *dev,
ret = scd4x_write_and_fetch(state, CMD_FRC, arg, &val, sizeof(val));
mutex_unlock(&state->lock);
if (ret)
return ret;
if (val == 0xff) {
dev_err(dev, "forced calibration has failed");
return -EINVAL;
}
return ret ?: len;
return len;
}
static IIO_DEVICE_ATTR_RW(calibration_auto_enable, 0);
......
......@@ -656,7 +656,7 @@ static int ad3552r_reset(struct ad3552r_desc *dac)
{
struct reg_addr_pool addr;
int ret;
u16 val;
int val;
dac->gpio_reset = devm_gpiod_get_optional(&dac->spi->dev, "reset",
GPIOD_OUT_LOW);
......@@ -809,10 +809,10 @@ static int ad3552r_configure_custom_gain(struct ad3552r_desc *dac,
gain_child = fwnode_get_named_child_node(child,
"custom-output-range-config");
if (IS_ERR(gain_child)) {
if (!gain_child) {
dev_err(dev,
"mandatory custom-output-range-config property missing\n");
return PTR_ERR(gain_child);
return -EINVAL;
}
dac->ch_data[ch].range_override = 1;
......
......@@ -178,7 +178,7 @@ static int ad5446_read_raw(struct iio_dev *indio_dev,
switch (m) {
case IIO_CHAN_INFO_RAW:
*val = st->cached_val;
*val = st->cached_val >> chan->scan_type.shift;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = st->vref_mv;
......
......@@ -522,7 +522,7 @@ static int ad5592r_alloc_channels(struct iio_dev *iio_dev)
if (!ret)
st->channel_modes[reg] = tmp;
fwnode_property_read_u32(child, "adi,off-state", &tmp);
ret = fwnode_property_read_u32(child, "adi,off-state", &tmp);
if (!ret)
st->channel_offstate[reg] = tmp;
}
......
......@@ -298,7 +298,7 @@ static int ltc2688_read_raw(struct iio_dev *indio_dev,
if (ret)
return ret;
*val = 16;
*val2 = 16;
return IIO_VAL_FRACTIONAL_LOG2;
case IIO_CHAN_INFO_CALIBBIAS:
ret = regmap_read(st->regmap,
......
......@@ -19,6 +19,7 @@
#include <linux/i2c.h>
#include <linux/module.h>
#include <linux/mod_devicetable.h>
#include <linux/property.h>
#include <linux/regulator/consumer.h>
enum chip_id {
......@@ -311,6 +312,7 @@ static int dac5571_probe(struct i2c_client *client,
const struct dac5571_spec *spec;
struct dac5571_data *data;
struct iio_dev *indio_dev;
enum chip_id chip_id;
int ret, i;
indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
......@@ -326,7 +328,13 @@ static int dac5571_probe(struct i2c_client *client,
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = dac5571_channels;
spec = &dac5571_spec[id->driver_data];
if (dev_fwnode(dev))
chip_id = (uintptr_t)device_get_match_data(dev);
else
chip_id = id->driver_data;
spec = &dac5571_spec[chip_id];
indio_dev->num_channels = spec->num_channels;
data->spec = spec;
......@@ -385,15 +393,15 @@ static int dac5571_remove(struct i2c_client *i2c)
}
static const struct of_device_id dac5571_of_id[] = {
{.compatible = "ti,dac5571"},
{.compatible = "ti,dac6571"},
{.compatible = "ti,dac7571"},
{.compatible = "ti,dac5574"},
{.compatible = "ti,dac6574"},
{.compatible = "ti,dac7574"},
{.compatible = "ti,dac5573"},
{.compatible = "ti,dac6573"},
{.compatible = "ti,dac7573"},
{.compatible = "ti,dac5571", .data = (void *)single_8bit},
{.compatible = "ti,dac6571", .data = (void *)single_10bit},
{.compatible = "ti,dac7571", .data = (void *)single_12bit},
{.compatible = "ti,dac5574", .data = (void *)quad_8bit},
{.compatible = "ti,dac6574", .data = (void *)quad_10bit},
{.compatible = "ti,dac7574", .data = (void *)quad_12bit},
{.compatible = "ti,dac5573", .data = (void *)quad_8bit},
{.compatible = "ti,dac6573", .data = (void *)quad_10bit},
{.compatible = "ti,dac7573", .data = (void *)quad_12bit},
{}
};
MODULE_DEVICE_TABLE(of, dac5571_of_id);
......
......@@ -8,6 +8,7 @@ menu "Filters"
config ADMV8818
tristate "Analog Devices ADMV8818 High-Pass and Low-Pass Filter"
depends on SPI && COMMON_CLK && 64BIT
select REGMAP_SPI
help
Say yes here to build support for Analog Devices ADMV8818
2 GHz to 18 GHz, Digitally Tunable, High-Pass and Low-Pass Filter.
......
......@@ -730,7 +730,7 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
ret = regmap_write(data->regmap, BMI160_REG_CMD, BMI160_CMD_SOFTRESET);
if (ret)
return ret;
goto disable_regulator;
usleep_range(BMI160_SOFTRESET_USLEEP, BMI160_SOFTRESET_USLEEP + 1);
......@@ -741,29 +741,37 @@ static int bmi160_chip_init(struct bmi160_data *data, bool use_spi)
if (use_spi) {
ret = regmap_read(data->regmap, BMI160_REG_DUMMY, &val);
if (ret)
return ret;
goto disable_regulator;
}
ret = regmap_read(data->regmap, BMI160_REG_CHIP_ID, &val);
if (ret) {
dev_err(dev, "Error reading chip id\n");
return ret;
goto disable_regulator;
}
if (val != BMI160_CHIP_ID_VAL) {
dev_err(dev, "Wrong chip id, got %x expected %x\n",
val, BMI160_CHIP_ID_VAL);
return -ENODEV;
ret = -ENODEV;
goto disable_regulator;
}
ret = bmi160_set_mode(data, BMI160_ACCEL, true);
if (ret)
return ret;
goto disable_regulator;
ret = bmi160_set_mode(data, BMI160_GYRO, true);
if (ret)
return ret;
goto disable_accel;
return 0;
disable_accel:
bmi160_set_mode(data, BMI160_ACCEL, false);
disable_regulator:
regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
return ret;
}
static int bmi160_data_rdy_trigger_set_state(struct iio_trigger *trig,
......
......@@ -18,12 +18,15 @@ static int inv_icm42600_i2c_bus_setup(struct inv_icm42600_state *st)
unsigned int mask, val;
int ret;
/* setup interface registers */
ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG6,
INV_ICM42600_INTF_CONFIG6_MASK,
INV_ICM42600_INTF_CONFIG6_I3C_EN);
if (ret)
return ret;
/*
* setup interface registers
* This register write to REG_INTF_CONFIG6 enables a spike filter that
* is impacting the line and can prevent the I2C ACK to be seen by the
* controller. So we don't test the return value.
*/
regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG6,
INV_ICM42600_INTF_CONFIG6_MASK,
INV_ICM42600_INTF_CONFIG6_I3C_EN);
ret = regmap_update_bits(st->map, INV_ICM42600_REG_INTF_CONFIG4,
INV_ICM42600_INTF_CONFIG4_I3C_BUS_ONLY, 0);
......
......@@ -416,6 +416,7 @@ static int ak8975_power_on(const struct ak8975_data *data)
if (ret) {
dev_warn(&data->client->dev,
"Failed to enable specified Vid supply\n");
regulator_disable(data->vdd);
return ret;
}
......
......@@ -70,13 +70,17 @@
#define SX9324_REG_AFE_PH2 0x2a
#define SX9324_REG_AFE_PH3 0x2b
#define SX9324_REG_AFE_CTRL8 0x2c
#define SX9324_REG_AFE_CTRL8_RESFILTN_4KOHM 0x02
#define SX9324_REG_AFE_CTRL8_RESERVED 0x10
#define SX9324_REG_AFE_CTRL8_RESFILTIN_4KOHM 0x02
#define SX9324_REG_AFE_CTRL9 0x2d
#define SX9324_REG_AFE_CTRL9_AGAIN_1 0x08
#define SX9324_REG_PROX_CTRL0 0x30
#define SX9324_REG_PROX_CTRL0_GAIN_MASK GENMASK(5, 3)
#define SX9324_REG_PROX_CTRL0_GAIN_1 0x80
#define SX9324_REG_PROX_CTRL0_GAIN_SHIFT 3
#define SX9324_REG_PROX_CTRL0_GAIN_RSVD 0x0
#define SX9324_REG_PROX_CTRL0_GAIN_1 0x1
#define SX9324_REG_PROX_CTRL0_GAIN_8 0x4
#define SX9324_REG_PROX_CTRL0_RAWFILT_MASK GENMASK(2, 0)
#define SX9324_REG_PROX_CTRL0_RAWFILT_1P50 0x01
#define SX9324_REG_PROX_CTRL1 0x31
......@@ -379,7 +383,14 @@ static int sx9324_read_gain(struct sx_common_data *data,
if (ret)
return ret;
*val = 1 << FIELD_GET(SX9324_REG_PROX_CTRL0_GAIN_MASK, regval);
regval = FIELD_GET(SX9324_REG_PROX_CTRL0_GAIN_MASK, regval);
if (regval)
regval--;
else if (regval == SX9324_REG_PROX_CTRL0_GAIN_RSVD ||
regval > SX9324_REG_PROX_CTRL0_GAIN_8)
return -EINVAL;
*val = 1 << regval;
return IIO_VAL_INT;
}
......@@ -725,8 +736,12 @@ static int sx9324_write_gain(struct sx_common_data *data,
unsigned int gain, reg;
int ret;
gain = ilog2(val);
reg = SX9324_REG_PROX_CTRL0 + chan->channel / 2;
gain = ilog2(val) + 1;
if (val <= 0 || gain > SX9324_REG_PROX_CTRL0_GAIN_8)
return -EINVAL;
gain = FIELD_PREP(SX9324_REG_PROX_CTRL0_GAIN_MASK, gain);
mutex_lock(&data->mutex);
......@@ -781,12 +796,15 @@ static const struct sx_common_reg_default sx9324_default_regs[] = {
{ SX9324_REG_AFE_PH2, 0x1a },
{ SX9324_REG_AFE_PH3, 0x16 },
{ SX9324_REG_AFE_CTRL8, SX9324_REG_AFE_CTRL8_RESFILTN_4KOHM },
{ SX9324_REG_AFE_CTRL8, SX9324_REG_AFE_CTRL8_RESERVED |
SX9324_REG_AFE_CTRL8_RESFILTIN_4KOHM },
{ SX9324_REG_AFE_CTRL9, SX9324_REG_AFE_CTRL9_AGAIN_1 },
{ SX9324_REG_PROX_CTRL0, SX9324_REG_PROX_CTRL0_GAIN_1 |
{ SX9324_REG_PROX_CTRL0,
SX9324_REG_PROX_CTRL0_GAIN_1 << SX9324_REG_PROX_CTRL0_GAIN_SHIFT |
SX9324_REG_PROX_CTRL0_RAWFILT_1P50 },
{ SX9324_REG_PROX_CTRL1, SX9324_REG_PROX_CTRL0_GAIN_1 |
{ SX9324_REG_PROX_CTRL1,
SX9324_REG_PROX_CTRL0_GAIN_1 << SX9324_REG_PROX_CTRL0_GAIN_SHIFT |
SX9324_REG_PROX_CTRL0_RAWFILT_1P50 },
{ SX9324_REG_PROX_CTRL2, SX9324_REG_PROX_CTRL2_AVGNEG_THRESH_16K },
{ SX9324_REG_PROX_CTRL3, SX9324_REG_PROX_CTRL3_AVGDEB_2SAMPLES |
......
......@@ -521,6 +521,7 @@ int sx_common_probe(struct i2c_client *client,
return dev_err_probe(dev, ret, "error reading WHOAMI\n");
ACPI_COMPANION_SET(&indio_dev->dev, ACPI_COMPANION(dev));
indio_dev->dev.of_node = client->dev.of_node;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->channels = data->chip_info->iio_channels;
......
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