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

+132 -64
+1 -1
drivers/iio/accel/sca3300.c
··· 477 477 struct iio_dev *indio_dev = pf->indio_dev; 478 478 struct sca3300_data *data = iio_priv(indio_dev); 479 479 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) = { }; 481 481 482 482 iio_for_each_active_channel(indio_dev, bit) { 483 483 ret = sca3300_read_reg(data, indio_dev->channels[bit].address, &val);
+1 -1
drivers/iio/adc/Kconfig
··· 1300 1300 1301 1301 config ROHM_BD79124 1302 1302 tristate "Rohm BD79124 ADC driver" 1303 - depends on I2C 1303 + depends on I2C && GPIOLIB 1304 1304 select REGMAP_I2C 1305 1305 select IIO_ADC_HELPER 1306 1306 help
+7 -7
drivers/iio/adc/ad7124.c
··· 849 849 static int ad7124_syscalib_locked(struct ad7124_state *st, const struct iio_chan_spec *chan) 850 850 { 851 851 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]; 853 853 int ret; 854 854 855 855 if (ch->syscalib_mode == AD7124_SYSCALIB_ZERO_SCALE) { ··· 865 865 if (ret < 0) 866 866 return ret; 867 867 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); 870 870 } else { 871 871 ch->cfg.calibration_gain = st->gain_default; 872 872 ··· 880 880 if (ret < 0) 881 881 return ret; 882 882 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); 885 885 } 886 886 887 887 return 0; ··· 924 924 { 925 925 struct ad7124_state *st = iio_priv(indio_dev); 926 926 927 - st->channels[chan->channel].syscalib_mode = mode; 927 + st->channels[chan->address].syscalib_mode = mode; 928 928 929 929 return 0; 930 930 } ··· 934 934 { 935 935 struct ad7124_state *st = iio_priv(indio_dev); 936 936 937 - return st->channels[chan->channel].syscalib_mode; 937 + return st->channels[chan->address].syscalib_mode; 938 938 } 939 939 940 940 static const struct iio_enum ad7124_syscalib_mode_enum = {
+75 -12
drivers/iio/adc/ad7173.c
··· 200 200 /* 201 201 * Following fields are used to compare equality. If you 202 202 * make adaptations in it, you most likely also have to adapt 203 - * ad7173_find_live_config(), too. 203 + * ad7173_is_setup_equal(), too. 204 204 */ 205 205 struct_group(config_props, 206 206 bool bipolar; ··· 561 561 st->config_usage_counter = 0; 562 562 } 563 563 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) 566 576 { 567 - struct ad7173_channel_config *cfg_aux; 568 - int i; 569 - 570 577 /* 571 578 * This is just to make sure that the comparison is adapted after 572 579 * struct ad7173_channel_config was changed. ··· 586 579 u8 ref_sel; 587 580 })); 588 581 582 + return cfg1->bipolar == cfg2->bipolar && 583 + cfg1->input_buf == cfg2->input_buf && 584 + cfg1->odr == cfg2->odr && 585 + cfg1->ref_sel == cfg2->ref_sel; 586 + } 587 + 588 + static struct ad7173_channel_config * 589 + ad7173_find_live_config(struct ad7173_state *st, struct ad7173_channel_config *cfg) 590 + { 591 + struct ad7173_channel_config *cfg_aux; 592 + int i; 593 + 589 594 for (i = 0; i < st->num_channels; i++) { 590 595 cfg_aux = &st->channels[i].cfg; 591 596 592 - if (cfg_aux->live && 593 - cfg->bipolar == cfg_aux->bipolar && 594 - cfg->input_buf == cfg_aux->input_buf && 595 - cfg->odr == cfg_aux->odr && 596 - cfg->ref_sel == cfg_aux->ref_sel) 597 + if (cfg_aux->live && ad7173_is_setup_equal(cfg, cfg_aux)) 597 598 return cfg_aux; 598 599 } 599 600 return NULL; ··· 1243 1228 const unsigned long *scan_mask) 1244 1229 { 1245 1230 struct ad7173_state *st = iio_priv(indio_dev); 1246 - int i, ret; 1231 + int i, j, k, ret; 1247 1232 1248 1233 for (i = 0; i < indio_dev->num_channels; i++) { 1249 1234 if (test_bit(i, scan_mask)) ··· 1252 1237 ret = ad_sd_write_reg(&st->sd, AD7173_REG_CH(i), 2, 0); 1253 1238 if (ret < 0) 1254 1239 return ret; 1240 + } 1241 + 1242 + /* 1243 + * On some chips, there are more channels that setups, so if there were 1244 + * more unique setups requested than the number of available slots, 1245 + * ad7173_set_channel() will have written over some of the slots. We 1246 + * can detect this by making sure each assigned cfg_slot matches the 1247 + * requested configuration. If it doesn't, we know that the slot was 1248 + * overwritten by a different channel. 1249 + */ 1250 + for_each_set_bit(i, scan_mask, indio_dev->num_channels) { 1251 + const struct ad7173_channel_config *cfg1, *cfg2; 1252 + 1253 + cfg1 = &st->channels[i].cfg; 1254 + 1255 + for_each_set_bit(j, scan_mask, indio_dev->num_channels) { 1256 + cfg2 = &st->channels[j].cfg; 1257 + 1258 + /* 1259 + * Only compare configs that are assigned to the same 1260 + * SETUP_SEL slot and don't compare channel to itself. 1261 + */ 1262 + if (i == j || cfg1->cfg_slot != cfg2->cfg_slot) 1263 + continue; 1264 + 1265 + /* 1266 + * If we find two different configs trying to use the 1267 + * same SETUP_SEL slot, then we know that the that we 1268 + * have too many unique configurations requested for 1269 + * the available slots and at least one was overwritten. 1270 + */ 1271 + if (!ad7173_is_setup_equal(cfg1, cfg2)) { 1272 + /* 1273 + * At this point, there isn't a way to tell 1274 + * which setups are actually programmed in the 1275 + * ADC anymore, so we could read them back to 1276 + * see, but it is simpler to just turn off all 1277 + * of the live flags so that everything gets 1278 + * reprogramed on the next attempt read a sample. 1279 + */ 1280 + for (k = 0; k < st->num_channels; k++) 1281 + st->channels[k].cfg.live = false; 1282 + 1283 + dev_err(&st->sd.spi->dev, 1284 + "Too many unique channel configurations requested for scan\n"); 1285 + return -EINVAL; 1286 + } 1287 + } 1255 1288 } 1256 1289 1257 1290 return 0;
+1
drivers/iio/adc/ad7380.c
··· 873 873 .has_hardware_gain = true, 874 874 .available_scan_masks = ad7380_4_channel_scan_masks, 875 875 .timing_specs = &ad7380_4_timing, 876 + .max_conversion_rate_hz = 4 * MEGA, 876 877 }; 877 878 878 879 static const struct spi_offload_config ad7380_offload_config = {
+10 -23
drivers/iio/adc/rzg2l_adc.c
··· 89 89 struct completion completion; 90 90 struct mutex lock; 91 91 u16 last_val[RZG2L_ADC_MAX_CHANNELS]; 92 - bool was_rpm_active; 93 92 }; 94 93 95 94 /** ··· 427 428 if (!indio_dev) 428 429 return -ENOMEM; 429 430 431 + platform_set_drvdata(pdev, indio_dev); 432 + 430 433 adc = iio_priv(indio_dev); 431 434 432 435 adc->hw_params = device_get_match_data(dev); ··· 460 459 ret = devm_pm_runtime_enable(dev); 461 460 if (ret) 462 461 return ret; 463 - 464 - platform_set_drvdata(pdev, indio_dev); 465 462 466 463 ret = rzg2l_adc_hw_init(dev, adc); 467 464 if (ret) ··· 540 541 }; 541 542 int ret; 542 543 543 - if (pm_runtime_suspended(dev)) { 544 - adc->was_rpm_active = false; 545 - } else { 546 - ret = pm_runtime_force_suspend(dev); 547 - if (ret) 548 - return ret; 549 - adc->was_rpm_active = true; 550 - } 544 + ret = pm_runtime_force_suspend(dev); 545 + if (ret) 546 + return ret; 551 547 552 548 ret = reset_control_bulk_assert(ARRAY_SIZE(resets), resets); 553 549 if (ret) ··· 551 557 return 0; 552 558 553 559 rpm_restore: 554 - if (adc->was_rpm_active) 555 - pm_runtime_force_resume(dev); 556 - 560 + pm_runtime_force_resume(dev); 557 561 return ret; 558 562 } 559 563 ··· 569 577 if (ret) 570 578 return ret; 571 579 572 - if (adc->was_rpm_active) { 573 - ret = pm_runtime_force_resume(dev); 574 - if (ret) 575 - goto resets_restore; 576 - } 580 + ret = pm_runtime_force_resume(dev); 581 + if (ret) 582 + goto resets_restore; 577 583 578 584 ret = rzg2l_adc_hw_init(dev, adc); 579 585 if (ret) ··· 580 590 return 0; 581 591 582 592 rpm_restore: 583 - if (adc->was_rpm_active) { 584 - pm_runtime_mark_last_busy(dev); 585 - pm_runtime_put_autosuspend(dev); 586 - } 593 + pm_runtime_force_suspend(dev); 587 594 resets_restore: 588 595 reset_control_bulk_assert(ARRAY_SIZE(resets), resets); 589 596 return ret;
+5 -1
drivers/iio/imu/inv_icm42600/inv_icm42600_temp.c
··· 32 32 goto exit; 33 33 34 34 *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 + */ 35 39 if (*temp == INV_ICM42600_DATA_INVALID) 36 - ret = -EINVAL; 40 + ret = -EBUSY; 37 41 38 42 exit: 39 43 mutex_unlock(&st->lock);
+1 -1
drivers/iio/light/as73211.c
··· 639 639 struct { 640 640 __le16 chan[4]; 641 641 aligned_s64 ts; 642 - } scan; 642 + } scan = { }; 643 643 int data_result, ret; 644 644 645 645 mutex_lock(&data->mutex);
+5 -4
drivers/iio/pressure/bmp280-core.c
··· 3213 3213 3214 3214 /* Bring chip out of reset if there is an assigned GPIO line */ 3215 3215 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 + 3216 3219 /* 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); 3221 3222 3222 3223 data->regmap = regmap; 3223 3224
+10 -4
drivers/iio/proximity/isl29501.c
··· 938 938 struct iio_dev *indio_dev = pf->indio_dev; 939 939 struct isl29501_private *isl29501 = iio_priv(indio_dev); 940 940 const unsigned long *active_mask = indio_dev->active_scan_mask; 941 - u32 buffer[4] __aligned(8) = {}; /* 1x16-bit + naturally aligned ts */ 941 + u32 value; 942 + struct { 943 + u16 data; 944 + aligned_s64 ts; 945 + } scan = { }; 942 946 943 - if (test_bit(ISL29501_DISTANCE_SCAN_INDEX, active_mask)) 944 - isl29501_register_read(isl29501, REG_DISTANCE, buffer); 947 + if (test_bit(ISL29501_DISTANCE_SCAN_INDEX, active_mask)) { 948 + isl29501_register_read(isl29501, REG_DISTANCE, &value); 949 + scan.data = value; 950 + } 945 951 946 - iio_push_to_buffers_with_timestamp(indio_dev, buffer, pf->timestamp); 952 + iio_push_to_buffers_with_timestamp(indio_dev, &scan, pf->timestamp); 947 953 iio_trigger_notify_done(indio_dev->trig); 948 954 949 955 return IRQ_HANDLED;
+16 -10
drivers/iio/temperature/maxim_thermocouple.c
··· 11 11 #include <linux/module.h> 12 12 #include <linux/err.h> 13 13 #include <linux/spi/spi.h> 14 + #include <linux/types.h> 14 15 #include <linux/iio/iio.h> 15 16 #include <linux/iio/sysfs.h> 16 17 #include <linux/iio/trigger.h> ··· 122 121 struct spi_device *spi; 123 122 const struct maxim_thermocouple_chip *chip; 124 123 char tc_type; 125 - 126 - u8 buffer[16] __aligned(IIO_DMA_MINALIGN); 124 + /* Buffer for reading up to 2 hardware channels. */ 125 + struct { 126 + union { 127 + __be16 raw16; 128 + __be32 raw32; 129 + __be16 raw[2]; 130 + }; 131 + aligned_s64 timestamp; 132 + } buffer __aligned(IIO_DMA_MINALIGN); 127 133 }; 128 134 129 135 static int maxim_thermocouple_read(struct maxim_thermocouple_data *data, ··· 138 130 { 139 131 unsigned int storage_bytes = data->chip->read_size; 140 132 unsigned int shift = chan->scan_type.shift + (chan->address * 8); 141 - __be16 buf16; 142 - __be32 buf32; 143 133 int ret; 144 134 145 135 switch (storage_bytes) { 146 136 case 2: 147 - ret = spi_read(data->spi, (void *)&buf16, storage_bytes); 148 - *val = be16_to_cpu(buf16); 137 + ret = spi_read(data->spi, &data->buffer.raw16, storage_bytes); 138 + *val = be16_to_cpu(data->buffer.raw16); 149 139 break; 150 140 case 4: 151 - ret = spi_read(data->spi, (void *)&buf32, storage_bytes); 152 - *val = be32_to_cpu(buf32); 141 + ret = spi_read(data->spi, &data->buffer.raw32, storage_bytes); 142 + *val = be32_to_cpu(data->buffer.raw32); 153 143 break; 154 144 default: 155 145 ret = -EINVAL; ··· 172 166 struct maxim_thermocouple_data *data = iio_priv(indio_dev); 173 167 int ret; 174 168 175 - ret = spi_read(data->spi, data->buffer, data->chip->read_size); 169 + ret = spi_read(data->spi, data->buffer.raw, data->chip->read_size); 176 170 if (!ret) { 177 - iio_push_to_buffers_with_ts(indio_dev, data->buffer, 171 + iio_push_to_buffers_with_ts(indio_dev, &data->buffer, 178 172 sizeof(data->buffer), 179 173 iio_get_time_ns(indio_dev)); 180 174 }