2nd set of IIO fixes for 6.1
Another mixed bag of driver fixes. * atmel,at91-sama5d2 - Drop a 5 degree offset as not needed for production devices. - Missing iio_trigger_free() in error path. * bosch,bma400 - Turn power on before trying to read chip ID. * bosch,bno055 - Avoid uninitialized variable warning (no actual impact) * meas,ms5611 - Fix multiple instances of driver sharing single prom array. - Stop forcing SPI speed to max devices supports * mps,mp2629 - Wrong structure field used to match channel. - Missing NULL terminator. * sysfs-trigger - Fix memory leak in error path. * tools - Fix wrong read size when calling with noevents. -----BEGIN PGP SIGNATURE----- iQJFBAABCAAvFiEEbilms4eEBlKRJoGxVIU0mcT0FogFAmNkLUkRHGppYzIzQGtl cm5lbC5vcmcACgkQVIU0mcT0FoidoRAAhirBh1fRfDxzvlBIUHVsa4fKCkuzhqb8 ZeGiWyzkZGLzvl+QxM/5M2hn37mN0WPXYTeHiykjF9azpEUDKG3TAECK/m4VmNWU puNBQla55MfaE0dGUn3SMCFlN5mJMT59cG9Rc1thPadHmL+Gd6iK4ttlSs+cVY4w p8aR1v4bal7GUY3FQXsbWCoaYZyqnmxcU7cWLXfPLJlC8O3ZPFvTcNLWUZ6qhhca kNrei9g7nEowvAAeNrl6rzXGedCVOb6uwzWEqrWxjJMnK2c6W5MMMXx57c1Sd55D y/pHMWsg3ZTLE1SXmia57jabY/tQ4pcRdPZpnj1nLKPszlD7IgnyhsBPrklfkgxG LWqfP5018FlCCtNX6DHrDpdBAUxoaoH4OEC2ws39LT51vYNwG6WcbKSS5Bn96T+g q/8ByXt9/g8Rf8EUXQpR7CpNF53pmEjUBIzk+ZPZCl+4gS31yokaVM6w8mmmI6HP 07mSu8zXhzpMxII3Pp3+qat83kwW+QRlRQUUnzsICYGW1H45OvuU99b/E7XdZywM WY98foGW2CEN7fbb0v0V1ZNfYu0vVLt0xUvXW40LhdwIbEuoObbCCCNg8u5l92DO R9qgc0e1+GM9sB+3afhxh/jpmjjEnvXWmVRPmIkwChO7dIhhRNS/TGmQUGFiSnrO rR6s2QrhVyg= =G2Qe -----END PGP SIGNATURE----- Merge tag 'iio-fixes-for-6.1b' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-linus Jonathan writes: "2nd set of IIO fixes for 6.1 Another mixed bag of driver fixes. * atmel,at91-sama5d2 - Drop a 5 degree offset as not needed for production devices. - Missing iio_trigger_free() in error path. * bosch,bma400 - Turn power on before trying to read chip ID. * bosch,bno055 - Avoid uninitialized variable warning (no actual impact) * meas,ms5611 - Fix multiple instances of driver sharing single prom array. - Stop forcing SPI speed to max devices supports * mps,mp2629 - Wrong structure field used to match channel. - Missing NULL terminator. * sysfs-trigger - Fix memory leak in error path. * tools - Fix wrong read size when calling with noevents." * tag 'iio-fixes-for-6.1b' of https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: tools: iio: iio_generic_buffer: Fix read size iio: imu: bno055: uninitialized variable bug in bno055_trigger_handler() iio: adc: at91_adc: fix possible memory leak in at91_adc_allocate_trigger() iio: adc: mp2629: fix potential array out of bound access iio: adc: mp2629: fix wrong comparison of channel iio: pressure: ms5611: changed hardcoded SPI speed to value limited iio: pressure: ms5611: fixed value compensation bug iio: accel: bma400: Ensure VDDIO is enable defore reading the chip ID. iio: adc: at91-sama5d2_adc: get rid of 5 degrees Celsius adjustment iio: trigger: sysfs: fix possible memory leak in iio_sysfs_trig_init()
This commit is contained in:
Коммит
38e9f21f64
|
@ -869,18 +869,6 @@ static int bma400_init(struct bma400_data *data)
|
|||
unsigned int val;
|
||||
int ret;
|
||||
|
||||
/* Try to read chip_id register. It must return 0x90. */
|
||||
ret = regmap_read(data->regmap, BMA400_CHIP_ID_REG, &val);
|
||||
if (ret) {
|
||||
dev_err(data->dev, "Failed to read chip id register\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (val != BMA400_ID_REG_VAL) {
|
||||
dev_err(data->dev, "Chip ID mismatch\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
data->regulators[BMA400_VDD_REGULATOR].supply = "vdd";
|
||||
data->regulators[BMA400_VDDIO_REGULATOR].supply = "vddio";
|
||||
ret = devm_regulator_bulk_get(data->dev,
|
||||
|
@ -906,6 +894,18 @@ static int bma400_init(struct bma400_data *data)
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
/* Try to read chip_id register. It must return 0x90. */
|
||||
ret = regmap_read(data->regmap, BMA400_CHIP_ID_REG, &val);
|
||||
if (ret) {
|
||||
dev_err(data->dev, "Failed to read chip id register\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (val != BMA400_ID_REG_VAL) {
|
||||
dev_err(data->dev, "Chip ID mismatch\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
ret = bma400_get_power_mode(data);
|
||||
if (ret) {
|
||||
dev_err(data->dev, "Failed to get the initial power-mode\n");
|
||||
|
|
|
@ -2307,11 +2307,9 @@ static int at91_adc_temp_sensor_init(struct at91_adc_state *st,
|
|||
clb->p6 = buf[AT91_ADC_TS_CLB_IDX_P6];
|
||||
|
||||
/*
|
||||
* We prepare here the conversion to milli and also add constant
|
||||
* factor (5 degrees Celsius) to p1 here to avoid doing it on
|
||||
* hotpath.
|
||||
* We prepare here the conversion to milli to avoid doing it on hotpath.
|
||||
*/
|
||||
clb->p1 = clb->p1 * 1000 + 5000;
|
||||
clb->p1 = clb->p1 * 1000;
|
||||
|
||||
free_buf:
|
||||
kfree(buf);
|
||||
|
|
|
@ -634,8 +634,10 @@ static struct iio_trigger *at91_adc_allocate_trigger(struct iio_dev *idev,
|
|||
trig->ops = &at91_adc_trigger_ops;
|
||||
|
||||
ret = iio_trigger_register(trig);
|
||||
if (ret)
|
||||
if (ret) {
|
||||
iio_trigger_free(trig);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return trig;
|
||||
}
|
||||
|
|
|
@ -57,7 +57,8 @@ static struct iio_map mp2629_adc_maps[] = {
|
|||
MP2629_MAP(SYSTEM_VOLT, "system-volt"),
|
||||
MP2629_MAP(INPUT_VOLT, "input-volt"),
|
||||
MP2629_MAP(BATT_CURRENT, "batt-current"),
|
||||
MP2629_MAP(INPUT_CURRENT, "input-current")
|
||||
MP2629_MAP(INPUT_CURRENT, "input-current"),
|
||||
{ }
|
||||
};
|
||||
|
||||
static int mp2629_read_raw(struct iio_dev *indio_dev,
|
||||
|
@ -74,7 +75,7 @@ static int mp2629_read_raw(struct iio_dev *indio_dev,
|
|||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (chan->address == MP2629_INPUT_VOLT)
|
||||
if (chan->channel == MP2629_INPUT_VOLT)
|
||||
rval &= GENMASK(6, 0);
|
||||
*val = rval;
|
||||
return IIO_VAL_INT;
|
||||
|
|
|
@ -632,7 +632,7 @@ static int bno055_set_regmask(struct bno055_priv *priv, int val, int val2,
|
|||
return -EINVAL;
|
||||
}
|
||||
delta = abs(tbl_val - req_val);
|
||||
if (delta < best_delta || first) {
|
||||
if (first || delta < best_delta) {
|
||||
best_delta = delta;
|
||||
hwval = i;
|
||||
first = false;
|
||||
|
|
|
@ -25,13 +25,6 @@ enum {
|
|||
MS5607,
|
||||
};
|
||||
|
||||
struct ms5611_chip_info {
|
||||
u16 prom[MS5611_PROM_WORDS_NB];
|
||||
|
||||
int (*temp_and_pressure_compensate)(struct ms5611_chip_info *chip_info,
|
||||
s32 *temp, s32 *pressure);
|
||||
};
|
||||
|
||||
/*
|
||||
* OverSampling Rate descriptor.
|
||||
* Warning: cmd MUST be kept aligned on a word boundary (see
|
||||
|
@ -50,12 +43,15 @@ struct ms5611_state {
|
|||
const struct ms5611_osr *pressure_osr;
|
||||
const struct ms5611_osr *temp_osr;
|
||||
|
||||
u16 prom[MS5611_PROM_WORDS_NB];
|
||||
|
||||
int (*reset)(struct ms5611_state *st);
|
||||
int (*read_prom_word)(struct ms5611_state *st, int index, u16 *word);
|
||||
int (*read_adc_temp_and_pressure)(struct ms5611_state *st,
|
||||
s32 *temp, s32 *pressure);
|
||||
|
||||
struct ms5611_chip_info *chip_info;
|
||||
int (*compensate_temp_and_pressure)(struct ms5611_state *st, s32 *temp,
|
||||
s32 *pressure);
|
||||
struct regulator *vdd;
|
||||
};
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ static int ms5611_read_prom(struct iio_dev *indio_dev)
|
|||
struct ms5611_state *st = iio_priv(indio_dev);
|
||||
|
||||
for (i = 0; i < MS5611_PROM_WORDS_NB; i++) {
|
||||
ret = st->read_prom_word(st, i, &st->chip_info->prom[i]);
|
||||
ret = st->read_prom_word(st, i, &st->prom[i]);
|
||||
if (ret < 0) {
|
||||
dev_err(&indio_dev->dev,
|
||||
"failed to read prom at %d\n", i);
|
||||
|
@ -93,7 +93,7 @@ static int ms5611_read_prom(struct iio_dev *indio_dev)
|
|||
}
|
||||
}
|
||||
|
||||
if (!ms5611_prom_is_valid(st->chip_info->prom, MS5611_PROM_WORDS_NB)) {
|
||||
if (!ms5611_prom_is_valid(st->prom, MS5611_PROM_WORDS_NB)) {
|
||||
dev_err(&indio_dev->dev, "PROM integrity check failed\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
@ -114,21 +114,20 @@ static int ms5611_read_temp_and_pressure(struct iio_dev *indio_dev,
|
|||
return ret;
|
||||
}
|
||||
|
||||
return st->chip_info->temp_and_pressure_compensate(st->chip_info,
|
||||
temp, pressure);
|
||||
return st->compensate_temp_and_pressure(st, temp, pressure);
|
||||
}
|
||||
|
||||
static int ms5611_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info,
|
||||
static int ms5611_temp_and_pressure_compensate(struct ms5611_state *st,
|
||||
s32 *temp, s32 *pressure)
|
||||
{
|
||||
s32 t = *temp, p = *pressure;
|
||||
s64 off, sens, dt;
|
||||
|
||||
dt = t - (chip_info->prom[5] << 8);
|
||||
off = ((s64)chip_info->prom[2] << 16) + ((chip_info->prom[4] * dt) >> 7);
|
||||
sens = ((s64)chip_info->prom[1] << 15) + ((chip_info->prom[3] * dt) >> 8);
|
||||
dt = t - (st->prom[5] << 8);
|
||||
off = ((s64)st->prom[2] << 16) + ((st->prom[4] * dt) >> 7);
|
||||
sens = ((s64)st->prom[1] << 15) + ((st->prom[3] * dt) >> 8);
|
||||
|
||||
t = 2000 + ((chip_info->prom[6] * dt) >> 23);
|
||||
t = 2000 + ((st->prom[6] * dt) >> 23);
|
||||
if (t < 2000) {
|
||||
s64 off2, sens2, t2;
|
||||
|
||||
|
@ -154,17 +153,17 @@ static int ms5611_temp_and_pressure_compensate(struct ms5611_chip_info *chip_inf
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int ms5607_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info,
|
||||
static int ms5607_temp_and_pressure_compensate(struct ms5611_state *st,
|
||||
s32 *temp, s32 *pressure)
|
||||
{
|
||||
s32 t = *temp, p = *pressure;
|
||||
s64 off, sens, dt;
|
||||
|
||||
dt = t - (chip_info->prom[5] << 8);
|
||||
off = ((s64)chip_info->prom[2] << 17) + ((chip_info->prom[4] * dt) >> 6);
|
||||
sens = ((s64)chip_info->prom[1] << 16) + ((chip_info->prom[3] * dt) >> 7);
|
||||
dt = t - (st->prom[5] << 8);
|
||||
off = ((s64)st->prom[2] << 17) + ((st->prom[4] * dt) >> 6);
|
||||
sens = ((s64)st->prom[1] << 16) + ((st->prom[3] * dt) >> 7);
|
||||
|
||||
t = 2000 + ((chip_info->prom[6] * dt) >> 23);
|
||||
t = 2000 + ((st->prom[6] * dt) >> 23);
|
||||
if (t < 2000) {
|
||||
s64 off2, sens2, t2, tmp;
|
||||
|
||||
|
@ -342,15 +341,6 @@ static int ms5611_write_raw(struct iio_dev *indio_dev,
|
|||
|
||||
static const unsigned long ms5611_scan_masks[] = {0x3, 0};
|
||||
|
||||
static struct ms5611_chip_info chip_info_tbl[] = {
|
||||
[MS5611] = {
|
||||
.temp_and_pressure_compensate = ms5611_temp_and_pressure_compensate,
|
||||
},
|
||||
[MS5607] = {
|
||||
.temp_and_pressure_compensate = ms5607_temp_and_pressure_compensate,
|
||||
}
|
||||
};
|
||||
|
||||
static const struct iio_chan_spec ms5611_channels[] = {
|
||||
{
|
||||
.type = IIO_PRESSURE,
|
||||
|
@ -433,7 +423,20 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
|
|||
struct ms5611_state *st = iio_priv(indio_dev);
|
||||
|
||||
mutex_init(&st->lock);
|
||||
st->chip_info = &chip_info_tbl[type];
|
||||
|
||||
switch (type) {
|
||||
case MS5611:
|
||||
st->compensate_temp_and_pressure =
|
||||
ms5611_temp_and_pressure_compensate;
|
||||
break;
|
||||
case MS5607:
|
||||
st->compensate_temp_and_pressure =
|
||||
ms5607_temp_and_pressure_compensate;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
st->temp_osr =
|
||||
&ms5611_avail_temp_osr[ARRAY_SIZE(ms5611_avail_temp_osr) - 1];
|
||||
st->pressure_osr =
|
||||
|
|
|
@ -91,7 +91,7 @@ static int ms5611_spi_probe(struct spi_device *spi)
|
|||
spi_set_drvdata(spi, indio_dev);
|
||||
|
||||
spi->mode = SPI_MODE_0;
|
||||
spi->max_speed_hz = 20000000;
|
||||
spi->max_speed_hz = min(spi->max_speed_hz, 20000000U);
|
||||
spi->bits_per_word = 8;
|
||||
ret = spi_setup(spi);
|
||||
if (ret < 0)
|
||||
|
|
|
@ -203,9 +203,13 @@ static int iio_sysfs_trigger_remove(int id)
|
|||
|
||||
static int __init iio_sysfs_trig_init(void)
|
||||
{
|
||||
int ret;
|
||||
device_initialize(&iio_sysfs_trig_dev);
|
||||
dev_set_name(&iio_sysfs_trig_dev, "iio_sysfs_trigger");
|
||||
return device_add(&iio_sysfs_trig_dev);
|
||||
ret = device_add(&iio_sysfs_trig_dev);
|
||||
if (ret)
|
||||
put_device(&iio_sysfs_trig_dev);
|
||||
return ret;
|
||||
}
|
||||
module_init(iio_sysfs_trig_init);
|
||||
|
||||
|
|
|
@ -715,12 +715,12 @@ int main(int argc, char **argv)
|
|||
continue;
|
||||
}
|
||||
|
||||
toread = buf_len;
|
||||
} else {
|
||||
usleep(timedelay);
|
||||
toread = 64;
|
||||
}
|
||||
|
||||
toread = buf_len;
|
||||
|
||||
read_size = read(buf_fd, data, toread * scan_size);
|
||||
if (read_size < 0) {
|
||||
if (errno == EAGAIN) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче