Skip to content

Commit fe85261

Browse files
committed
Merge tag 'iio-fixes-for-6.17a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio into char-misc-linus
Jonathan writes: IIO: 1st set of fixes for 6.17 Usual mixed bunch of ancient issues and relatively new ones. adi,ad7124 - Fix channel lookup to use chan->address for indexing array. adi,ad7173 - Stop accidentally enabling more configs than supported at one time. adi,ad7380 - Fill in missing max_conversion_rate_hz for adaq4381-4 ams,as73211 - Fix uninitialized holes in scan data exposed to userspace. bosch,bmp280 - Check for error when requesting optional GPIO rather than simply assuming success or a NULL return when no GPIO provided. invensense,icm42600 - Change error code returned to -EBUSY on a temperature read with neither accelerometer nor gyroscope in use. Reduces chance of misinterpretation by userspace. kionix,sca3300 - Fix uninitialized holes in scan data exposed to userspace. maxim,thermocouple - Use a DMA-safe buffer for spi_read(). renesas,isl29501 - Fix ordering issue for big endian systems renesas,rsg2l - Fix an underflow issue around suspend/resume. - Make sure driver data is in place before enabling runtime PM that uses it. rohm,bd79124 - Add missing GPIOLIB dependency. May rework in future to allow this to be optional in future but for now this is the least invasive build fix. * tag 'iio-fixes-for-6.17a' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio: iio: pressure: bmp280: Use IS_ERR() in bmp280_common_probe() iio: light: as73211: Ensure buffer holes are zeroed iio: adc: rzg2l_adc: Set driver data before enabling runtime PM iio: adc: rzg2l: Cleanup suspend/resume path iio: adc: ad7380: fix missing max_conversion_rate_hz on adaq4381-4 iio: adc: bd79124: Add GPIOLIB dependency iio: imu: inv_icm42600: change invalid data error to -EBUSY iio: adc: ad7124: fix channel lookup in syscalib functions iio: temperature: maxim_thermocouple: use DMA-safe buffer for spi_read() iio: adc: ad7173: prevent scan if too many setups requested iio: proximity: isl29501: fix buffered read on big-endian systems iio: accel: sca3300: fix uninitialized iio scan data
2 parents b47b493 + 43c0f64 commit fe85261

File tree

11 files changed

+133
-65
lines changed

11 files changed

+133
-65
lines changed

drivers/iio/accel/sca3300.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static irqreturn_t sca3300_trigger_handler(int irq, void *p)
477477
struct iio_dev *indio_dev = pf->indio_dev;
478478
struct sca3300_data *data = iio_priv(indio_dev);
479479
int bit, ret, val, i = 0;
480-
IIO_DECLARE_BUFFER_WITH_TS(s16, channels, SCA3300_SCAN_MAX);
480+
IIO_DECLARE_BUFFER_WITH_TS(s16, channels, SCA3300_SCAN_MAX) = { };
481481

482482
iio_for_each_active_channel(indio_dev, bit) {
483483
ret = sca3300_read_reg(data, indio_dev->channels[bit].address, &val);

drivers/iio/adc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ config RN5T618_ADC
13001300

13011301
config ROHM_BD79124
13021302
tristate "Rohm BD79124 ADC driver"
1303-
depends on I2C
1303+
depends on I2C && GPIOLIB
13041304
select REGMAP_I2C
13051305
select IIO_ADC_HELPER
13061306
help

drivers/iio/adc/ad7124.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ enum {
849849
static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan_spec *chan)
850850
{
851851
struct device *dev = &st->sd.spi->dev;
852-
struct ad7124_channel *ch = &st->channels[chan->channel];
852+
struct ad7124_channel *ch = &st->channels[chan->address];
853853
int ret;
854854

855855
if (ch->syscalib_mode == AD7124_SYSCALIB_ZERO_SCALE) {
@@ -865,8 +865,8 @@ static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan
865865
if (ret < 0)
866866
return ret;
867867

868-
dev_dbg(dev, "offset for channel %d after zero-scale calibration: 0x%x\n",
869-
chan->channel, ch->cfg.calibration_offset);
868+
dev_dbg(dev, "offset for channel %lu after zero-scale calibration: 0x%x\n",
869+
chan->address, ch->cfg.calibration_offset);
870870
} else {
871871
ch->cfg.calibration_gain = st->gain_default;
872872

@@ -880,8 +880,8 @@ static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan
880880
if (ret < 0)
881881
return ret;
882882

883-
dev_dbg(dev, "gain for channel %d after full-scale calibration: 0x%x\n",
884-
chan->channel, ch->cfg.calibration_gain);
883+
dev_dbg(dev, "gain for channel %lu after full-scale calibration: 0x%x\n",
884+
chan->address, ch->cfg.calibration_gain);
885885
}
886886

887887
return 0;
@@ -924,7 +924,7 @@ static int ad7124_set_syscalib_mode(struct iio_dev *indio_dev,
924924
{
925925
struct ad7124_state *st = iio_priv(indio_dev);
926926

927-
st->channels[chan->channel].syscalib_mode = mode;
927+
st->channels[chan->address].syscalib_mode = mode;
928928

929929
return 0;
930930
}
@@ -934,7 +934,7 @@ static int ad7124_get_syscalib_mode(struct iio_dev *indio_dev,
934934
{
935935
struct ad7124_state *st = iio_priv(indio_dev);
936936

937-
return st->channels[chan->channel].syscalib_mode;
937+
return st->channels[chan->address].syscalib_mode;
938938
}
939939

940940
static const struct iio_enum ad7124_syscalib_mode_enum = {

drivers/iio/adc/ad7173.c

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ struct ad7173_channel_config {
200200
/*
201201
* Following fields are used to compare equality. If you
202202
* make adaptations in it, you most likely also have to adapt
203-
* ad7173_find_live_config(), too.
203+
* ad7173_is_setup_equal(), too.
204204
*/
205205
struct_group(config_props,
206206
bool bipolar;
@@ -561,12 +561,19 @@ static void ad7173_reset_usage_cnts(struct ad7173_state *st)
561561
st->config_usage_counter = 0;
562562
}
563563

564-
static struct ad7173_channel_config *
565-
ad7173_find_live_config(struct ad7173_state *st, struct ad7173_channel_config *cfg)
564+
/**
565+
* ad7173_is_setup_equal - Compare two channel setups
566+
* @cfg1: First channel configuration
567+
* @cfg2: Second channel configuration
568+
*
569+
* Compares all configuration options that affect the registers connected to
570+
* SETUP_SEL, namely CONFIGx, FILTERx, GAINx and OFFSETx.
571+
*
572+
* Returns: true if the setups are identical, false otherwise
573+
*/
574+
static bool ad7173_is_setup_equal(const struct ad7173_channel_config *cfg1,
575+
const struct ad7173_channel_config *cfg2)
566576
{
567-
struct ad7173_channel_config *cfg_aux;
568-
int i;
569-
570577
/*
571578
* This is just to make sure that the comparison is adapted after
572579
* struct ad7173_channel_config was changed.
@@ -579,14 +586,22 @@ ad7173_find_live_config(struct ad7173_state *st, struct ad7173_channel_config *c
579586
u8 ref_sel;
580587
}));
581588

589+
return cfg1->bipolar == cfg2->bipolar &&
590+
cfg1->input_buf == cfg2->input_buf &&
591+
cfg1->odr == cfg2->odr &&
592+
cfg1->ref_sel == cfg2->ref_sel;
593+
}
594+
595+
static struct ad7173_channel_config *
596+
ad7173_find_live_config(struct ad7173_state *st, struct ad7173_channel_config *cfg)
597+
{
598+
struct ad7173_channel_config *cfg_aux;
599+
int i;
600+
582601
for (i = 0; i < st->num_channels; i++) {
583602
cfg_aux = &st->channels[i].cfg;
584603

585-
if (cfg_aux->live &&
586-
cfg->bipolar == cfg_aux->bipolar &&
587-
cfg->input_buf == cfg_aux->input_buf &&
588-
cfg->odr == cfg_aux->odr &&
589-
cfg->ref_sel == cfg_aux->ref_sel)
604+
if (cfg_aux->live && ad7173_is_setup_equal(cfg, cfg_aux))
590605
return cfg_aux;
591606
}
592607
return NULL;
@@ -1228,7 +1243,7 @@ static int ad7173_update_scan_mode(struct iio_dev *indio_dev,
12281243
const unsigned long *scan_mask)
12291244
{
12301245
struct ad7173_state *st = iio_priv(indio_dev);
1231-
int i, ret;
1246+
int i, j, k, ret;
12321247

12331248
for (i = 0; i < indio_dev->num_channels; i++) {
12341249
if (test_bit(i, scan_mask))
@@ -1239,6 +1254,54 @@ static int ad7173_update_scan_mode(struct iio_dev *indio_dev,
12391254
return ret;
12401255
}
12411256

1257+
/*
1258+
* On some chips, there are more channels that setups, so if there were
1259+
* more unique setups requested than the number of available slots,
1260+
* ad7173_set_channel() will have written over some of the slots. We
1261+
* can detect this by making sure each assigned cfg_slot matches the
1262+
* requested configuration. If it doesn't, we know that the slot was
1263+
* overwritten by a different channel.
1264+
*/
1265+
for_each_set_bit(i, scan_mask, indio_dev->num_channels) {
1266+
const struct ad7173_channel_config *cfg1, *cfg2;
1267+
1268+
cfg1 = &st->channels[i].cfg;
1269+
1270+
for_each_set_bit(j, scan_mask, indio_dev->num_channels) {
1271+
cfg2 = &st->channels[j].cfg;
1272+
1273+
/*
1274+
* Only compare configs that are assigned to the same
1275+
* SETUP_SEL slot and don't compare channel to itself.
1276+
*/
1277+
if (i == j || cfg1->cfg_slot != cfg2->cfg_slot)
1278+
continue;
1279+
1280+
/*
1281+
* If we find two different configs trying to use the
1282+
* same SETUP_SEL slot, then we know that the that we
1283+
* have too many unique configurations requested for
1284+
* the available slots and at least one was overwritten.
1285+
*/
1286+
if (!ad7173_is_setup_equal(cfg1, cfg2)) {
1287+
/*
1288+
* At this point, there isn't a way to tell
1289+
* which setups are actually programmed in the
1290+
* ADC anymore, so we could read them back to
1291+
* see, but it is simpler to just turn off all
1292+
* of the live flags so that everything gets
1293+
* reprogramed on the next attempt read a sample.
1294+
*/
1295+
for (k = 0; k < st->num_channels; k++)
1296+
st->channels[k].cfg.live = false;
1297+
1298+
dev_err(&st->sd.spi->dev,
1299+
"Too many unique channel configurations requested for scan\n");
1300+
return -EINVAL;
1301+
}
1302+
}
1303+
}
1304+
12421305
return 0;
12431306
}
12441307

drivers/iio/adc/ad7380.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,6 +873,7 @@ static const struct ad7380_chip_info adaq4381_4_chip_info = {
873873
.has_hardware_gain = true,
874874
.available_scan_masks = ad7380_4_channel_scan_masks,
875875
.timing_specs = &ad7380_4_timing,
876+
.max_conversion_rate_hz = 4 * MEGA,
876877
};
877878

878879
static const struct spi_offload_config ad7380_offload_config = {

drivers/iio/adc/rzg2l_adc.c

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ struct rzg2l_adc {
8989
struct completion completion;
9090
struct mutex lock;
9191
u16 last_val[RZG2L_ADC_MAX_CHANNELS];
92-
bool was_rpm_active;
9392
};
9493

9594
/**
@@ -428,6 +427,8 @@ static int rzg2l_adc_probe(struct platform_device *pdev)
428427
if (!indio_dev)
429428
return -ENOMEM;
430429

430+
platform_set_drvdata(pdev, indio_dev);
431+
431432
adc = iio_priv(indio_dev);
432433

433434
adc->hw_params = device_get_match_data(dev);
@@ -460,8 +461,6 @@ static int rzg2l_adc_probe(struct platform_device *pdev)
460461
if (ret)
461462
return ret;
462463

463-
platform_set_drvdata(pdev, indio_dev);
464-
465464
ret = rzg2l_adc_hw_init(dev, adc);
466465
if (ret)
467466
return dev_err_probe(&pdev->dev, ret,
@@ -541,14 +540,9 @@ static int rzg2l_adc_suspend(struct device *dev)
541540
};
542541
int ret;
543542

544-
if (pm_runtime_suspended(dev)) {
545-
adc->was_rpm_active = false;
546-
} else {
547-
ret = pm_runtime_force_suspend(dev);
548-
if (ret)
549-
return ret;
550-
adc->was_rpm_active = true;
551-
}
543+
ret = pm_runtime_force_suspend(dev);
544+
if (ret)
545+
return ret;
552546

553547
ret = reset_control_bulk_assert(ARRAY_SIZE(resets), resets);
554548
if (ret)
@@ -557,9 +551,7 @@ static int rzg2l_adc_suspend(struct device *dev)
557551
return 0;
558552

559553
rpm_restore:
560-
if (adc->was_rpm_active)
561-
pm_runtime_force_resume(dev);
562-
554+
pm_runtime_force_resume(dev);
563555
return ret;
564556
}
565557

@@ -577,11 +569,9 @@ static int rzg2l_adc_resume(struct device *dev)
577569
if (ret)
578570
return ret;
579571

580-
if (adc->was_rpm_active) {
581-
ret = pm_runtime_force_resume(dev);
582-
if (ret)
583-
goto resets_restore;
584-
}
572+
ret = pm_runtime_force_resume(dev);
573+
if (ret)
574+
goto resets_restore;
585575

586576
ret = rzg2l_adc_hw_init(dev, adc);
587577
if (ret)
@@ -590,10 +580,7 @@ static int rzg2l_adc_resume(struct device *dev)
590580
return 0;
591581

592582
rpm_restore:
593-
if (adc->was_rpm_active) {
594-
pm_runtime_mark_last_busy(dev);
595-
pm_runtime_put_autosuspend(dev);
596-
}
583+
pm_runtime_force_suspend(dev);
597584
resets_restore:
598585
reset_control_bulk_assert(ARRAY_SIZE(resets), resets);
599586
return ret;

drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ static int inv_icm42600_temp_read(struct inv_icm42600_state *st, s16 *temp)
3232
goto exit;
3333

3434
*temp = (s16)be16_to_cpup(raw);
35+
/*
36+
* Temperature data is invalid if both accel and gyro are off.
37+
* Return -EBUSY in this case.
38+
*/
3539
if (*temp == INV_ICM42600_DATA_INVALID)
36-
ret = -EINVAL;
40+
ret = -EBUSY;
3741

3842
exit:
3943
mutex_unlock(&st->lock);

drivers/iio/light/as73211.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ static irqreturn_t as73211_trigger_handler(int irq __always_unused, void *p)
639639
struct {
640640
__le16 chan[4];
641641
aligned_s64 ts;
642-
} scan;
642+
} scan = { };
643643
int data_result, ret;
644644

645645
mutex_lock(&data->mutex);

drivers/iio/pressure/bmp280-core.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3213,11 +3213,12 @@ int bmp280_common_probe(struct device *dev,
32133213

32143214
/* Bring chip out of reset if there is an assigned GPIO line */
32153215
gpiod = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
3216+
if (IS_ERR(gpiod))
3217+
return dev_err_probe(dev, PTR_ERR(gpiod), "failed to get reset GPIO\n");
3218+
32163219
/* Deassert the signal */
3217-
if (gpiod) {
3218-
dev_info(dev, "release reset\n");
3219-
gpiod_set_value(gpiod, 0);
3220-
}
3220+
dev_info(dev, "release reset\n");
3221+
gpiod_set_value(gpiod, 0);
32213222

32223223
data->regmap = regmap;
32233224

drivers/iio/proximity/isl29501.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -938,12 +938,18 @@ static irqreturn_t isl29501_trigger_handler(int irq, void *p)
938938
struct iio_dev *indio_dev = pf->indio_dev;
939939
struct isl29501_private *isl29501 = iio_priv(indio_dev);
940940
const unsigned long *active_mask = indio_dev->active_scan_mask;
941-
u32 buffer[4] __aligned(8) = {}; /* 1x16-bit + naturally aligned ts */
942-
943-
if (test_bit(ISL29501_DISTANCE_SCAN_INDEX, active_mask))
944-
isl29501_register_read(isl29501, REG_DISTANCE, buffer);
941+
u32 value;
942+
struct {
943+
u16 data;
944+
aligned_s64 ts;
945+
} scan = { };
946+
947+
if (test_bit(ISL29501_DISTANCE_SCAN_INDEX, active_mask)) {
948+
isl29501_register_read(isl29501, REG_DISTANCE, &value);
949+
scan.data = value;
950+
}
945951

946-
iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp);
952+
iio_push_to_buffers_with_timestamp(indio_dev, &scan, pf->timestamp);
947953
iio_trigger_notify_done(indio_dev->trig);
948954

949955
return IRQ_HANDLED;

0 commit comments

Comments
 (0)