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

Jonathan writes:

IIO: Fixes for 6.12, set 2

Usual mixed back of fixes for ancient bugs and some more recently
introduced problems.

gts-helper module
- Memory leak fixes for this library code to handle complex gain cases.
adi,ad7124
- Fix a divide by zero that can be triggered from userspace.
adi,ad7380
- Various supply fixes. Includes some minor rework that simplifies the
fix though increases the apparent scale of the change.
adi,ad9832
- Avoid a potential divide by zero if clk_get_rate() returns 0.
adi,ltc2642
- Fix wrong Kconfig regmap dependency.
vishay,veml6030
- Fix a scaling problem with decimal part of processed channel.
Note that only the illuminance channel is fixed as a larger series
of cleanups not suitable for this point in the rc cycle removes
the intensity channel anyway.

* tag 'iio-fixes-for-6.12b' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/jic23/iio:
iio: dac: Kconfig: Fix build error for ltc2664
iio: adc: ad7124: fix division by zero in ad7124_set_channel_odr()
staging: iio: frequency: ad9832: fix division by zero in ad9832_calc_freqreg()
docs: iio: ad7380: fix supply for ad7380-4
iio: adc: ad7380: fix supplies for ad7380-4
iio: adc: ad7380: add missing supplies
iio: adc: ad7380: use devm_regulator_get_enable_read_voltage()
dt-bindings: iio: adc: ad7380: fix ad7380-4 reference supply
iio: light: veml6030: fix microlux value calculation
iio: gts-helper: Fix memory leaks for the error path of iio_gts_build_avail_scale_table()
iio: gts-helper: Fix memory leaks in iio_gts_build_avail_scale_table()

+121 -66
+21
Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml
··· 67 67 A 2.5V to 3.3V supply for the external reference voltage. When omitted, 68 68 the internal 2.5V reference is used. 69 69 70 + refin-supply: 71 + description: 72 + A 2.5V to 3.3V supply for external reference voltage, for ad7380-4 only. 73 + 70 74 aina-supply: 71 75 description: 72 76 The common mode voltage supply for the AINA- pin on pseudo-differential ··· 138 134 properties: 139 135 ainc-supply: false 140 136 aind-supply: false 137 + 138 + # ad7380-4 uses refin-supply as external reference. 139 + # All other chips from ad738x family use refio as optional external reference. 140 + # When refio-supply is omitted, internal reference is used. 141 + - if: 142 + properties: 143 + compatible: 144 + enum: 145 + - adi,ad7380-4 146 + then: 147 + properties: 148 + refio-supply: false 149 + required: 150 + - refin-supply 151 + else: 152 + properties: 153 + refin-supply: false 141 154 142 155 examples: 143 156 - |
+11 -2
Documentation/iio/ad7380.rst
··· 41 41 Reference voltage 42 42 ----------------- 43 43 44 - 2 possible reference voltage sources are supported: 44 + ad7380-4 45 + ~~~~~~~~ 46 + 47 + ad7380-4 supports only an external reference voltage (2.5V to 3.3V). It must be 48 + declared in the device tree as ``refin-supply``. 49 + 50 + All other devices from ad738x family 51 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 52 + 53 + All other devices from ad738x support 2 possible reference voltage sources: 45 54 46 55 - Internal reference (2.5V) 47 56 - External reference (2.5V to 3.3V) 48 57 49 58 The source is determined by the device tree. If ``refio-supply`` is present, 50 - then the external reference is used, else the internal reference is used. 59 + then it is used as external reference, else the internal reference is used. 51 60 52 61 Oversampling and resolution boost 53 62 ---------------------------------
+1 -1
drivers/iio/adc/ad7124.c
··· 637 637 638 638 switch (info) { 639 639 case IIO_CHAN_INFO_SAMP_FREQ: 640 - if (val2 != 0) { 640 + if (val2 != 0 || val == 0) { 641 641 ret = -EINVAL; 642 642 break; 643 643 }
+78 -58
drivers/iio/adc/ad7380.c
··· 75 75 #define T_CONVERT_NS 190 /* conversion time */ 76 76 #define T_CONVERT_0_NS 10 /* 1st conversion start time (oversampling) */ 77 77 #define T_CONVERT_X_NS 500 /* xth conversion start time (oversampling) */ 78 + #define T_POWERUP_US 5000 /* Power up */ 78 79 79 80 struct ad7380_timing_specs { 80 81 const unsigned int t_csh_ns; /* CS minimum high time */ ··· 87 86 unsigned int num_channels; 88 87 unsigned int num_simult_channels; 89 88 bool has_mux; 89 + const char * const *supplies; 90 + unsigned int num_supplies; 91 + bool external_ref_only; 90 92 const char * const *vcm_supplies; 91 93 unsigned int num_vcm_supplies; 92 94 const unsigned long *available_scan_masks; ··· 247 243 DEFINE_AD7380_8_CHANNEL(ad7387_4_channels, 14, 0, u); 248 244 DEFINE_AD7380_8_CHANNEL(ad7388_4_channels, 12, 0, u); 249 245 246 + static const char * const ad7380_supplies[] = { 247 + "vcc", "vlogic", 248 + }; 249 + 250 250 static const char * const ad7380_2_channel_vcm_supplies[] = { 251 251 "aina", "ainb", 252 252 }; ··· 346 338 .channels = ad7380_channels, 347 339 .num_channels = ARRAY_SIZE(ad7380_channels), 348 340 .num_simult_channels = 2, 341 + .supplies = ad7380_supplies, 342 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 349 343 .available_scan_masks = ad7380_2_channel_scan_masks, 350 344 .timing_specs = &ad7380_timing, 351 345 }; ··· 357 347 .channels = ad7381_channels, 358 348 .num_channels = ARRAY_SIZE(ad7381_channels), 359 349 .num_simult_channels = 2, 350 + .supplies = ad7380_supplies, 351 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 360 352 .available_scan_masks = ad7380_2_channel_scan_masks, 361 353 .timing_specs = &ad7380_timing, 362 354 }; ··· 368 356 .channels = ad7383_channels, 369 357 .num_channels = ARRAY_SIZE(ad7383_channels), 370 358 .num_simult_channels = 2, 359 + .supplies = ad7380_supplies, 360 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 371 361 .vcm_supplies = ad7380_2_channel_vcm_supplies, 372 362 .num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies), 373 363 .available_scan_masks = ad7380_2_channel_scan_masks, ··· 381 367 .channels = ad7384_channels, 382 368 .num_channels = ARRAY_SIZE(ad7384_channels), 383 369 .num_simult_channels = 2, 370 + .supplies = ad7380_supplies, 371 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 384 372 .vcm_supplies = ad7380_2_channel_vcm_supplies, 385 373 .num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies), 386 374 .available_scan_masks = ad7380_2_channel_scan_masks, ··· 394 378 .channels = ad7386_channels, 395 379 .num_channels = ARRAY_SIZE(ad7386_channels), 396 380 .num_simult_channels = 2, 381 + .supplies = ad7380_supplies, 382 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 397 383 .has_mux = true, 398 384 .available_scan_masks = ad7380_2x2_channel_scan_masks, 399 385 .timing_specs = &ad7380_timing, ··· 406 388 .channels = ad7387_channels, 407 389 .num_channels = ARRAY_SIZE(ad7387_channels), 408 390 .num_simult_channels = 2, 391 + .supplies = ad7380_supplies, 392 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 409 393 .has_mux = true, 410 394 .available_scan_masks = ad7380_2x2_channel_scan_masks, 411 395 .timing_specs = &ad7380_timing, ··· 418 398 .channels = ad7388_channels, 419 399 .num_channels = ARRAY_SIZE(ad7388_channels), 420 400 .num_simult_channels = 2, 401 + .supplies = ad7380_supplies, 402 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 421 403 .has_mux = true, 422 404 .available_scan_masks = ad7380_2x2_channel_scan_masks, 423 405 .timing_specs = &ad7380_timing, ··· 430 408 .channels = ad7380_4_channels, 431 409 .num_channels = ARRAY_SIZE(ad7380_4_channels), 432 410 .num_simult_channels = 4, 411 + .supplies = ad7380_supplies, 412 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 413 + .external_ref_only = true, 433 414 .available_scan_masks = ad7380_4_channel_scan_masks, 434 415 .timing_specs = &ad7380_4_timing, 435 416 }; ··· 442 417 .channels = ad7381_4_channels, 443 418 .num_channels = ARRAY_SIZE(ad7381_4_channels), 444 419 .num_simult_channels = 4, 420 + .supplies = ad7380_supplies, 421 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 445 422 .available_scan_masks = ad7380_4_channel_scan_masks, 446 423 .timing_specs = &ad7380_4_timing, 447 424 }; ··· 453 426 .channels = ad7383_4_channels, 454 427 .num_channels = ARRAY_SIZE(ad7383_4_channels), 455 428 .num_simult_channels = 4, 429 + .supplies = ad7380_supplies, 430 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 456 431 .vcm_supplies = ad7380_4_channel_vcm_supplies, 457 432 .num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies), 458 433 .available_scan_masks = ad7380_4_channel_scan_masks, ··· 466 437 .channels = ad7384_4_channels, 467 438 .num_channels = ARRAY_SIZE(ad7384_4_channels), 468 439 .num_simult_channels = 4, 440 + .supplies = ad7380_supplies, 441 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 469 442 .vcm_supplies = ad7380_4_channel_vcm_supplies, 470 443 .num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies), 471 444 .available_scan_masks = ad7380_4_channel_scan_masks, ··· 479 448 .channels = ad7386_4_channels, 480 449 .num_channels = ARRAY_SIZE(ad7386_4_channels), 481 450 .num_simult_channels = 4, 451 + .supplies = ad7380_supplies, 452 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 482 453 .has_mux = true, 483 454 .available_scan_masks = ad7380_2x4_channel_scan_masks, 484 455 .timing_specs = &ad7380_4_timing, ··· 491 458 .channels = ad7387_4_channels, 492 459 .num_channels = ARRAY_SIZE(ad7387_4_channels), 493 460 .num_simult_channels = 4, 461 + .supplies = ad7380_supplies, 462 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 494 463 .has_mux = true, 495 464 .available_scan_masks = ad7380_2x4_channel_scan_masks, 496 465 .timing_specs = &ad7380_4_timing, ··· 503 468 .channels = ad7388_4_channels, 504 469 .num_channels = ARRAY_SIZE(ad7388_4_channels), 505 470 .num_simult_channels = 4, 471 + .supplies = ad7380_supplies, 472 + .num_supplies = ARRAY_SIZE(ad7380_supplies), 506 473 .has_mux = true, 507 474 .available_scan_masks = ad7380_2x4_channel_scan_masks, 508 475 .timing_specs = &ad7380_4_timing, ··· 993 956 .debugfs_reg_access = &ad7380_debugfs_reg_access, 994 957 }; 995 958 996 - static int ad7380_init(struct ad7380_state *st, struct regulator *vref) 959 + static int ad7380_init(struct ad7380_state *st, bool external_ref_en) 997 960 { 998 961 int ret; 999 962 ··· 1005 968 if (ret < 0) 1006 969 return ret; 1007 970 1008 - /* select internal or external reference voltage */ 1009 - ret = regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG1, 1010 - AD7380_CONFIG1_REFSEL, 1011 - FIELD_PREP(AD7380_CONFIG1_REFSEL, 1012 - vref ? 1 : 0)); 1013 - if (ret < 0) 1014 - return ret; 971 + if (external_ref_en) { 972 + /* select external reference voltage */ 973 + ret = regmap_set_bits(st->regmap, AD7380_REG_ADDR_CONFIG1, 974 + AD7380_CONFIG1_REFSEL); 975 + if (ret < 0) 976 + return ret; 977 + } 1015 978 1016 979 /* This is the default value after reset. */ 1017 980 st->oversampling_ratio = 1; ··· 1024 987 FIELD_PREP(AD7380_CONFIG2_SDO, 1)); 1025 988 } 1026 989 1027 - static void ad7380_regulator_disable(void *p) 1028 - { 1029 - regulator_disable(p); 1030 - } 1031 - 1032 990 static int ad7380_probe(struct spi_device *spi) 1033 991 { 1034 992 struct iio_dev *indio_dev; 1035 993 struct ad7380_state *st; 1036 - struct regulator *vref; 994 + bool external_ref_en; 1037 995 int ret, i; 1038 996 1039 997 indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); ··· 1041 1009 if (!st->chip_info) 1042 1010 return dev_err_probe(&spi->dev, -EINVAL, "missing match data\n"); 1043 1011 1044 - vref = devm_regulator_get_optional(&spi->dev, "refio"); 1045 - if (IS_ERR(vref)) { 1046 - if (PTR_ERR(vref) != -ENODEV) 1047 - return dev_err_probe(&spi->dev, PTR_ERR(vref), 1048 - "Failed to get refio regulator\n"); 1012 + ret = devm_regulator_bulk_get_enable(&spi->dev, st->chip_info->num_supplies, 1013 + st->chip_info->supplies); 1049 1014 1050 - vref = NULL; 1051 - } 1015 + if (ret) 1016 + return dev_err_probe(&spi->dev, ret, 1017 + "Failed to enable power supplies\n"); 1018 + fsleep(T_POWERUP_US); 1052 1019 1053 - /* 1054 - * If there is no REFIO supply, then it means that we are using 1055 - * the internal 2.5V reference, otherwise REFIO is reference voltage. 1056 - */ 1057 - if (vref) { 1058 - ret = regulator_enable(vref); 1059 - if (ret) 1060 - return ret; 1061 - 1062 - ret = devm_add_action_or_reset(&spi->dev, 1063 - ad7380_regulator_disable, vref); 1064 - if (ret) 1065 - return ret; 1066 - 1067 - ret = regulator_get_voltage(vref); 1020 + if (st->chip_info->external_ref_only) { 1021 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, 1022 + "refin"); 1068 1023 if (ret < 0) 1069 - return ret; 1024 + return dev_err_probe(&spi->dev, ret, 1025 + "Failed to get refin regulator\n"); 1070 1026 1071 1027 st->vref_mv = ret / 1000; 1028 + 1029 + /* these chips don't have a register bit for this */ 1030 + external_ref_en = false; 1072 1031 } else { 1073 - st->vref_mv = AD7380_INTERNAL_REF_MV; 1032 + /* 1033 + * If there is no REFIO supply, then it means that we are using 1034 + * the internal reference, otherwise REFIO is reference voltage. 1035 + */ 1036 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, 1037 + "refio"); 1038 + if (ret < 0 && ret != -ENODEV) 1039 + return dev_err_probe(&spi->dev, ret, 1040 + "Failed to get refio regulator\n"); 1041 + 1042 + external_ref_en = ret != -ENODEV; 1043 + st->vref_mv = external_ref_en ? ret / 1000 : AD7380_INTERNAL_REF_MV; 1074 1044 } 1075 1045 1076 1046 if (st->chip_info->num_vcm_supplies > ARRAY_SIZE(st->vcm_mv)) ··· 1084 1050 * input pin. 1085 1051 */ 1086 1052 for (i = 0; i < st->chip_info->num_vcm_supplies; i++) { 1087 - struct regulator *vcm; 1053 + const char *vcm = st->chip_info->vcm_supplies[i]; 1088 1054 1089 - vcm = devm_regulator_get(&spi->dev, 1090 - st->chip_info->vcm_supplies[i]); 1091 - if (IS_ERR(vcm)) 1092 - return dev_err_probe(&spi->dev, PTR_ERR(vcm), 1093 - "Failed to get %s regulator\n", 1094 - st->chip_info->vcm_supplies[i]); 1095 - 1096 - ret = regulator_enable(vcm); 1097 - if (ret) 1098 - return ret; 1099 - 1100 - ret = devm_add_action_or_reset(&spi->dev, 1101 - ad7380_regulator_disable, vcm); 1102 - if (ret) 1103 - return ret; 1104 - 1105 - ret = regulator_get_voltage(vcm); 1055 + ret = devm_regulator_get_enable_read_voltage(&spi->dev, vcm); 1106 1056 if (ret < 0) 1107 - return ret; 1057 + return dev_err_probe(&spi->dev, ret, 1058 + "Failed to get %s regulator\n", 1059 + vcm); 1108 1060 1109 1061 st->vcm_mv[i] = ret / 1000; 1110 1062 } ··· 1155 1135 if (ret) 1156 1136 return ret; 1157 1137 1158 - ret = ad7380_init(st, vref); 1138 + ret = ad7380_init(st, external_ref_en); 1159 1139 if (ret) 1160 1140 return ret; 1161 1141
+1 -1
drivers/iio/dac/Kconfig
··· 380 380 config LTC2664 381 381 tristate "Analog Devices LTC2664 and LTC2672 DAC SPI driver" 382 382 depends on SPI 383 - select REGMAP 383 + select REGMAP_SPI 384 384 help 385 385 Say yes here to build support for Analog Devices 386 386 LTC2664 and LTC2672 converters (DAC).
+3 -1
drivers/iio/industrialio-gts-helper.c
··· 307 307 if (ret) 308 308 goto err_free_out; 309 309 310 + for (i = 0; i < gts->num_itime; i++) 311 + kfree(per_time_gains[i]); 310 312 kfree(per_time_gains); 311 313 gts->per_time_avail_scale_tables = per_time_scales; 312 314 313 315 return 0; 314 316 315 317 err_free_out: 316 - for (i--; i; i--) { 318 + for (i--; i >= 0; i--) { 317 319 kfree(per_time_scales[i]); 318 320 kfree(per_time_gains[i]); 319 321 }
+1 -1
drivers/iio/light/veml6030.c
··· 522 522 } 523 523 if (mask == IIO_CHAN_INFO_PROCESSED) { 524 524 *val = (reg * data->cur_resolution) / 10000; 525 - *val2 = (reg * data->cur_resolution) % 10000; 525 + *val2 = (reg * data->cur_resolution) % 10000 * 100; 526 526 return IIO_VAL_INT_PLUS_MICRO; 527 527 } 528 528 *val = reg;
+5 -2
drivers/staging/iio/frequency/ad9832.c
··· 129 129 static int ad9832_write_frequency(struct ad9832_state *st, 130 130 unsigned int addr, unsigned long fout) 131 131 { 132 + unsigned long clk_freq; 132 133 unsigned long regval; 133 134 134 - if (fout > (clk_get_rate(st->mclk) / 2)) 135 + clk_freq = clk_get_rate(st->mclk); 136 + 137 + if (!clk_freq || fout > (clk_freq / 2)) 135 138 return -EINVAL; 136 139 137 - regval = ad9832_calc_freqreg(clk_get_rate(st->mclk), fout); 140 + regval = ad9832_calc_freqreg(clk_freq, fout); 138 141 139 142 st->freq_data[0] = cpu_to_be16((AD9832_CMD_FRE8BITSW << CMD_SHIFT) | 140 143 (addr << ADD_SHIFT) |