IIO: 2nd set of fixes for 6.15 (or 6.16 merge window)

Usual mixed bag.
 
 adi,ad4851
 - Avoid a buffer overrun due to bug in pointer arithmetic.
 adi,ad7173
 - Fix compiling if gpiolib is not enabled
 adi,ad7606
 - Fix raw reads for 18-bit chips by ensuring we mask out upper bits
   as some SPI controllers do not do so for 18bit words.
 - Fix wrong masking for register writes.
 adi,ad7944
 - Mask high bits for raw reads.
 adi,axi-adc
 - Add check on whether the busy flag has cleared before first access.
 invensense,icm42600
 - Fix the temperature offset to take scale into account.
 nxp,fxls8962af
 - Fix temperature to be in milli degrees Celsius not degrees.
 - Fix sign of temperature channel.
 -----BEGIN PGP SIGNATURE-----
 
 iQJFBAABCAAvFiEEbilms4eEBlKRJoGxVIU0mcT0FogFAmgqHbARHGppYzIzQGtl
 cm5lbC5vcmcACgkQVIU0mcT0FoiNqRAAgKHHnaUSDGkQMppDHQHgW8oKvStoaH/i
 cxpzGMYtMdUAcsVSPurT8Ul+ucnET8mbQne3+OhUpKsori4LYJE2WwVWzE+MhiMk
 2l66EGBx2i9EBz/9ST02Oi7nWO4Zzgir8liBNVCKeS/hkB7Sk+DJyfy/xNaTzNwz
 NV5ICR7l+3v51dkOQedYVu5uophV21n0FS2pus6i69xLtVxuuqEJdb/VFTuus8qr
 7SvU6zE+HAGBjRNmn0/i4FMnUaQULX2mDxmEEnPG6lyi0cULAYHWkqq/Kd5DM5CF
 bF2wnR0E0XABE90TYme39jMsOuAXD5Y3AgTXPeTJH5btVK4htWDhZXMx3MLo3I9l
 iPrPq0P4xHhdzoeIE37Hs/r6PnzowVsqjLC5kkMH0NGWfwbkDfvIz0NbJ5MvPyk6
 xio6L/qKi9+4stoeggeLpQlENu+XRX/IleT+g/cXcqpZn4tTeZEIDiaFNMKQsXqt
 PvcVXAnqLEKeUKLGU+LlkXAZuo7TSiGKpQ/6k7SQHFYl7dy1Twvy9ip6rsCd0QDY
 /8a0WqT4E1e7fmnk61AHyF9PFz8TGmT8aaxlFHTLPWecxBa2IIg1WwKBbv08ghHB
 y2xyZUzIJw/OKhCq9hWlFlIGphgGEjHht03tK69BrEzqO2WrmEjB8nxUhIXA48Rn
 XXi7qXjoDe4=
 =mGH+
 -----END PGP SIGNATURE-----

Merge tag 'iio-fixes-for-6.15b' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-next

Jonathan writes:

IIO: 2nd set of fixes for 6.15 (or 6.16 merge window)

Usual mixed bag.

adi,ad4851
- Avoid a buffer overrun due to bug in pointer arithmetic.
adi,ad7173
- Fix compiling if gpiolib is not enabled
adi,ad7606
- Fix raw reads for 18-bit chips by ensuring we mask out upper bits
  as some SPI controllers do not do so for 18bit words.
- Fix wrong masking for register writes.
adi,ad7944
- Mask high bits for raw reads.
adi,axi-adc
- Add check on whether the busy flag has cleared before first access.
invensense,icm42600
- Fix the temperature offset to take scale into account.
nxp,fxls8962af
- Fix temperature to be in milli degrees Celsius not degrees.
- Fix sign of temperature channel.

* tag 'iio-fixes-for-6.15b' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio:
  iio: accel: fxls8962af: Fix temperature scan element sign
  iio: accel: fxls8962af: Fix temperature calculation
  iio: adc: ad7944: mask high bits on direct read
  iio: adc: ad4851: fix ad4858 chan pointer handling
  iio: imu: inv_icm42600: Fix temperature calculation
  iio: dac: adi-axi-dac: fix bus read
  iio: adc: ad7606_spi: fix reg write value mask
  iio: adc: ad7606: fix raw read for 18-bit chips
  iio: adc: ad7173: fix compiling without gpiolib
This commit is contained in:
Greg Kroah-Hartman 2025-05-21 14:15:08 +02:00
commit a3245ebdfa
9 changed files with 50 additions and 40 deletions

View File

@ -23,6 +23,7 @@
#include <linux/regulator/consumer.h>
#include <linux/regmap.h>
#include <linux/types.h>
#include <linux/units.h>
#include <linux/iio/buffer.h>
#include <linux/iio/events.h>
@ -439,8 +440,16 @@ static int fxls8962af_read_raw(struct iio_dev *indio_dev,
*val = FXLS8962AF_TEMP_CENTER_VAL;
return IIO_VAL_INT;
case IIO_CHAN_INFO_SCALE:
*val = 0;
return fxls8962af_read_full_scale(data, val2);
switch (chan->type) {
case IIO_TEMP:
*val = MILLIDEGREE_PER_DEGREE;
return IIO_VAL_INT;
case IIO_ACCEL:
*val = 0;
return fxls8962af_read_full_scale(data, val2);
default:
return -EINVAL;
}
case IIO_CHAN_INFO_SAMP_FREQ:
return fxls8962af_read_samp_freq(data, val, val2);
default:
@ -736,9 +745,11 @@ static const struct iio_event_spec fxls8962af_event[] = {
.type = IIO_TEMP, \
.address = FXLS8962AF_TEMP_OUT, \
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
BIT(IIO_CHAN_INFO_SCALE) | \
BIT(IIO_CHAN_INFO_OFFSET),\
.scan_index = -1, \
.scan_type = { \
.sign = 's', \
.realbits = 8, \
.storagebits = 8, \
}, \

View File

@ -129,8 +129,9 @@ config AD7173
tristate "Analog Devices AD7173 driver"
depends on SPI_MASTER
select AD_SIGMA_DELTA
select GPIO_REGMAP if GPIOLIB
select REGMAP_SPI if GPIOLIB
select GPIOLIB
select GPIO_REGMAP
select REGMAP_SPI
help
Say yes here to build support for Analog Devices AD7173 and similar ADC
Currently supported models:

View File

@ -1034,7 +1034,7 @@ static int ad4858_parse_channels(struct iio_dev *indio_dev)
struct device *dev = &st->spi->dev;
struct iio_chan_spec *ad4851_channels;
const struct iio_chan_spec ad4851_chan = AD4858_IIO_CHANNEL;
int ret;
int ret, i = 0;
ret = ad4851_parse_channels_common(indio_dev, &ad4851_channels,
ad4851_chan);
@ -1042,15 +1042,15 @@ static int ad4858_parse_channels(struct iio_dev *indio_dev)
return ret;
device_for_each_child_node_scoped(dev, child) {
ad4851_channels->has_ext_scan_type = 1;
ad4851_channels[i].has_ext_scan_type = 1;
if (fwnode_property_read_bool(child, "bipolar")) {
ad4851_channels->ext_scan_type = ad4851_scan_type_20_b;
ad4851_channels->num_ext_scan_type = ARRAY_SIZE(ad4851_scan_type_20_b);
ad4851_channels[i].ext_scan_type = ad4851_scan_type_20_b;
ad4851_channels[i].num_ext_scan_type = ARRAY_SIZE(ad4851_scan_type_20_b);
} else {
ad4851_channels->ext_scan_type = ad4851_scan_type_20_u;
ad4851_channels->num_ext_scan_type = ARRAY_SIZE(ad4851_scan_type_20_u);
ad4851_channels[i].ext_scan_type = ad4851_scan_type_20_u;
ad4851_channels[i].num_ext_scan_type = ARRAY_SIZE(ad4851_scan_type_20_u);
}
ad4851_channels++;
i++;
}
indio_dev->channels = ad4851_channels;

View File

@ -230,10 +230,8 @@ struct ad7173_state {
unsigned long long *config_cnts;
struct clk *ext_clk;
struct clk_hw int_clk_hw;
#if IS_ENABLED(CONFIG_GPIOLIB)
struct regmap *reg_gpiocon_regmap;
struct gpio_regmap *gpio_regmap;
#endif
};
static unsigned int ad4115_sinc5_data_rates[] = {
@ -288,8 +286,6 @@ static const char *const ad7173_clk_sel[] = {
"ext-clk", "xtal"
};
#if IS_ENABLED(CONFIG_GPIOLIB)
static const struct regmap_range ad7173_range_gpio[] = {
regmap_reg_range(AD7173_REG_GPIO, AD7173_REG_GPIO),
};
@ -543,12 +539,6 @@ static int ad7173_gpio_init(struct ad7173_state *st)
return 0;
}
#else
static int ad7173_gpio_init(struct ad7173_state *st)
{
return 0;
}
#endif /* CONFIG_GPIOLIB */
static struct ad7173_state *ad_sigma_delta_to_ad7173(struct ad_sigma_delta *sd)
{
@ -1797,10 +1787,7 @@ static int ad7173_probe(struct spi_device *spi)
if (ret)
return ret;
if (IS_ENABLED(CONFIG_GPIOLIB))
return ad7173_gpio_init(st);
return 0;
return ad7173_gpio_init(st);
}
static const struct of_device_id ad7173_of_match[] = {

View File

@ -727,17 +727,16 @@ static int ad7606_scan_direct(struct iio_dev *indio_dev, unsigned int ch,
goto error_ret;
chan = &indio_dev->channels[ch + 1];
if (chan->scan_type.sign == 'u') {
if (realbits > 16)
*val = st->data.buf32[ch];
else
*val = st->data.buf16[ch];
} else {
if (realbits > 16)
*val = sign_extend32(st->data.buf32[ch], realbits - 1);
else
*val = sign_extend32(st->data.buf16[ch], realbits - 1);
}
if (realbits > 16)
*val = st->data.buf32[ch];
else
*val = st->data.buf16[ch];
*val &= GENMASK(realbits - 1, 0);
if (chan->scan_type.sign == 's')
*val = sign_extend32(*val, realbits - 1);
error_ret:
if (!st->gpio_convst) {

View File

@ -155,7 +155,7 @@ static int ad7606_spi_reg_write(struct ad7606_state *st,
struct spi_device *spi = to_spi_device(st->dev);
st->d16[0] = cpu_to_be16((st->bops->rd_wr_cmd(addr, 1) << 8) |
(val & 0x1FF));
(val & 0xFF));
return spi_write(spi, &st->d16[0], sizeof(st->d16[0]));
}

View File

@ -377,6 +377,8 @@ static int ad7944_single_conversion(struct ad7944_adc *adc,
if (chan->scan_type.sign == 's')
*val = sign_extend32(*val, chan->scan_type.realbits - 1);
else
*val &= GENMASK(chan->scan_type.realbits - 1, 0);
return IIO_VAL_INT;
}

View File

@ -707,6 +707,7 @@ static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val,
{
struct axi_dac_state *st = iio_backend_get_priv(back);
int ret;
u32 ival;
guard(mutex)(&st->lock);
@ -719,6 +720,13 @@ static int axi_dac_bus_reg_read(struct iio_backend *back, u32 reg, u32 *val,
if (ret)
return ret;
ret = regmap_read_poll_timeout(st->regmap,
AXI_DAC_UI_STATUS_REG, ival,
FIELD_GET(AXI_DAC_UI_STATUS_IF_BUSY, ival) == 0,
10, 100 * KILO);
if (ret)
return ret;
return regmap_read(st->regmap, AXI_DAC_CUSTOM_RD_REG, val);
}

View File

@ -67,16 +67,18 @@ int inv_icm42600_temp_read_raw(struct iio_dev *indio_dev,
return IIO_VAL_INT;
/*
* T°C = (temp / 132.48) + 25
* Tm°C = 1000 * ((temp * 100 / 13248) + 25)
* Tm°C = 1000 * ((temp / 132.48) + 25)
* Tm°C = 7.548309 * temp + 25000
* Tm°C = (temp + 3312) * 7.548309
* scale: 100000 / 13248 ~= 7.548309
* offset: 25000
* offset: 3312
*/
case IIO_CHAN_INFO_SCALE:
*val = 7;
*val2 = 548309;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_CHAN_INFO_OFFSET:
*val = 25000;
*val = 3312;
return IIO_VAL_INT;
default:
return -EINVAL;