Skip to content

Commit d0bc3b9

Browse files
committed
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()
2 parents 4adf613 + 7bd4923 commit d0bc3b9

File tree

8 files changed

+121
-66
lines changed

8 files changed

+121
-66
lines changed

Documentation/devicetree/bindings/iio/adc/adi,ad7380.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ properties:
6767
A 2.5V to 3.3V supply for the external reference voltage. When omitted,
6868
the internal 2.5V reference is used.
6969

70+
refin-supply:
71+
description:
72+
A 2.5V to 3.3V supply for external reference voltage, for ad7380-4 only.
73+
7074
aina-supply:
7175
description:
7276
The common mode voltage supply for the AINA- pin on pseudo-differential
@@ -135,6 +139,23 @@ allOf:
135139
ainc-supply: false
136140
aind-supply: false
137141

142+
# ad7380-4 uses refin-supply as external reference.
143+
# All other chips from ad738x family use refio as optional external reference.
144+
# When refio-supply is omitted, internal reference is used.
145+
- if:
146+
properties:
147+
compatible:
148+
enum:
149+
- adi,ad7380-4
150+
then:
151+
properties:
152+
refio-supply: false
153+
required:
154+
- refin-supply
155+
else:
156+
properties:
157+
refin-supply: false
158+
138159
examples:
139160
- |
140161
#include <dt-bindings/interrupt-controller/irq.h>

Documentation/iio/ad7380.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,22 @@ supports only 1 SDO line.
4141
Reference voltage
4242
-----------------
4343

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:
4554

4655
- Internal reference (2.5V)
4756
- External reference (2.5V to 3.3V)
4857

4958
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.
5160

5261
Oversampling and resolution boost
5362
---------------------------------

drivers/iio/adc/ad7124.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ static int ad7124_write_raw(struct iio_dev *indio_dev,
637637

638638
switch (info) {
639639
case IIO_CHAN_INFO_SAMP_FREQ:
640-
if (val2 != 0) {
640+
if (val2 != 0 || val == 0) {
641641
ret = -EINVAL;
642642
break;
643643
}

drivers/iio/adc/ad7380.c

Lines changed: 78 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
#define T_CONVERT_NS 190 /* conversion time */
7676
#define T_CONVERT_0_NS 10 /* 1st conversion start time (oversampling) */
7777
#define T_CONVERT_X_NS 500 /* xth conversion start time (oversampling) */
78+
#define T_POWERUP_US 5000 /* Power up */
7879

7980
struct ad7380_timing_specs {
8081
const unsigned int t_csh_ns; /* CS minimum high time */
@@ -86,6 +87,9 @@ struct ad7380_chip_info {
8687
unsigned int num_channels;
8788
unsigned int num_simult_channels;
8889
bool has_mux;
90+
const char * const *supplies;
91+
unsigned int num_supplies;
92+
bool external_ref_only;
8993
const char * const *vcm_supplies;
9094
unsigned int num_vcm_supplies;
9195
const unsigned long *available_scan_masks;
@@ -243,6 +247,10 @@ DEFINE_AD7380_8_CHANNEL(ad7386_4_channels, 16, 0, u);
243247
DEFINE_AD7380_8_CHANNEL(ad7387_4_channels, 14, 0, u);
244248
DEFINE_AD7380_8_CHANNEL(ad7388_4_channels, 12, 0, u);
245249

250+
static const char * const ad7380_supplies[] = {
251+
"vcc", "vlogic",
252+
};
253+
246254
static const char * const ad7380_2_channel_vcm_supplies[] = {
247255
"aina", "ainb",
248256
};
@@ -338,6 +346,8 @@ static const struct ad7380_chip_info ad7380_chip_info = {
338346
.channels = ad7380_channels,
339347
.num_channels = ARRAY_SIZE(ad7380_channels),
340348
.num_simult_channels = 2,
349+
.supplies = ad7380_supplies,
350+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
341351
.available_scan_masks = ad7380_2_channel_scan_masks,
342352
.timing_specs = &ad7380_timing,
343353
};
@@ -347,6 +357,8 @@ static const struct ad7380_chip_info ad7381_chip_info = {
347357
.channels = ad7381_channels,
348358
.num_channels = ARRAY_SIZE(ad7381_channels),
349359
.num_simult_channels = 2,
360+
.supplies = ad7380_supplies,
361+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
350362
.available_scan_masks = ad7380_2_channel_scan_masks,
351363
.timing_specs = &ad7380_timing,
352364
};
@@ -356,6 +368,8 @@ static const struct ad7380_chip_info ad7383_chip_info = {
356368
.channels = ad7383_channels,
357369
.num_channels = ARRAY_SIZE(ad7383_channels),
358370
.num_simult_channels = 2,
371+
.supplies = ad7380_supplies,
372+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
359373
.vcm_supplies = ad7380_2_channel_vcm_supplies,
360374
.num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies),
361375
.available_scan_masks = ad7380_2_channel_scan_masks,
@@ -367,6 +381,8 @@ static const struct ad7380_chip_info ad7384_chip_info = {
367381
.channels = ad7384_channels,
368382
.num_channels = ARRAY_SIZE(ad7384_channels),
369383
.num_simult_channels = 2,
384+
.supplies = ad7380_supplies,
385+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
370386
.vcm_supplies = ad7380_2_channel_vcm_supplies,
371387
.num_vcm_supplies = ARRAY_SIZE(ad7380_2_channel_vcm_supplies),
372388
.available_scan_masks = ad7380_2_channel_scan_masks,
@@ -378,6 +394,8 @@ static const struct ad7380_chip_info ad7386_chip_info = {
378394
.channels = ad7386_channels,
379395
.num_channels = ARRAY_SIZE(ad7386_channels),
380396
.num_simult_channels = 2,
397+
.supplies = ad7380_supplies,
398+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
381399
.has_mux = true,
382400
.available_scan_masks = ad7380_2x2_channel_scan_masks,
383401
.timing_specs = &ad7380_timing,
@@ -388,6 +406,8 @@ static const struct ad7380_chip_info ad7387_chip_info = {
388406
.channels = ad7387_channels,
389407
.num_channels = ARRAY_SIZE(ad7387_channels),
390408
.num_simult_channels = 2,
409+
.supplies = ad7380_supplies,
410+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
391411
.has_mux = true,
392412
.available_scan_masks = ad7380_2x2_channel_scan_masks,
393413
.timing_specs = &ad7380_timing,
@@ -398,6 +418,8 @@ static const struct ad7380_chip_info ad7388_chip_info = {
398418
.channels = ad7388_channels,
399419
.num_channels = ARRAY_SIZE(ad7388_channels),
400420
.num_simult_channels = 2,
421+
.supplies = ad7380_supplies,
422+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
401423
.has_mux = true,
402424
.available_scan_masks = ad7380_2x2_channel_scan_masks,
403425
.timing_specs = &ad7380_timing,
@@ -408,6 +430,9 @@ static const struct ad7380_chip_info ad7380_4_chip_info = {
408430
.channels = ad7380_4_channels,
409431
.num_channels = ARRAY_SIZE(ad7380_4_channels),
410432
.num_simult_channels = 4,
433+
.supplies = ad7380_supplies,
434+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
435+
.external_ref_only = true,
411436
.available_scan_masks = ad7380_4_channel_scan_masks,
412437
.timing_specs = &ad7380_4_timing,
413438
};
@@ -417,6 +442,8 @@ static const struct ad7380_chip_info ad7381_4_chip_info = {
417442
.channels = ad7381_4_channels,
418443
.num_channels = ARRAY_SIZE(ad7381_4_channels),
419444
.num_simult_channels = 4,
445+
.supplies = ad7380_supplies,
446+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
420447
.available_scan_masks = ad7380_4_channel_scan_masks,
421448
.timing_specs = &ad7380_4_timing,
422449
};
@@ -426,6 +453,8 @@ static const struct ad7380_chip_info ad7383_4_chip_info = {
426453
.channels = ad7383_4_channels,
427454
.num_channels = ARRAY_SIZE(ad7383_4_channels),
428455
.num_simult_channels = 4,
456+
.supplies = ad7380_supplies,
457+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
429458
.vcm_supplies = ad7380_4_channel_vcm_supplies,
430459
.num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies),
431460
.available_scan_masks = ad7380_4_channel_scan_masks,
@@ -437,6 +466,8 @@ static const struct ad7380_chip_info ad7384_4_chip_info = {
437466
.channels = ad7384_4_channels,
438467
.num_channels = ARRAY_SIZE(ad7384_4_channels),
439468
.num_simult_channels = 4,
469+
.supplies = ad7380_supplies,
470+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
440471
.vcm_supplies = ad7380_4_channel_vcm_supplies,
441472
.num_vcm_supplies = ARRAY_SIZE(ad7380_4_channel_vcm_supplies),
442473
.available_scan_masks = ad7380_4_channel_scan_masks,
@@ -448,6 +479,8 @@ static const struct ad7380_chip_info ad7386_4_chip_info = {
448479
.channels = ad7386_4_channels,
449480
.num_channels = ARRAY_SIZE(ad7386_4_channels),
450481
.num_simult_channels = 4,
482+
.supplies = ad7380_supplies,
483+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
451484
.has_mux = true,
452485
.available_scan_masks = ad7380_2x4_channel_scan_masks,
453486
.timing_specs = &ad7380_4_timing,
@@ -458,6 +491,8 @@ static const struct ad7380_chip_info ad7387_4_chip_info = {
458491
.channels = ad7387_4_channels,
459492
.num_channels = ARRAY_SIZE(ad7387_4_channels),
460493
.num_simult_channels = 4,
494+
.supplies = ad7380_supplies,
495+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
461496
.has_mux = true,
462497
.available_scan_masks = ad7380_2x4_channel_scan_masks,
463498
.timing_specs = &ad7380_4_timing,
@@ -468,6 +503,8 @@ static const struct ad7380_chip_info ad7388_4_chip_info = {
468503
.channels = ad7388_4_channels,
469504
.num_channels = ARRAY_SIZE(ad7388_4_channels),
470505
.num_simult_channels = 4,
506+
.supplies = ad7380_supplies,
507+
.num_supplies = ARRAY_SIZE(ad7380_supplies),
471508
.has_mux = true,
472509
.available_scan_masks = ad7380_2x4_channel_scan_masks,
473510
.timing_specs = &ad7380_4_timing,
@@ -956,7 +993,7 @@ static const struct iio_info ad7380_info = {
956993
.debugfs_reg_access = &ad7380_debugfs_reg_access,
957994
};
958995

959-
static int ad7380_init(struct ad7380_state *st, struct regulator *vref)
996+
static int ad7380_init(struct ad7380_state *st, bool external_ref_en)
960997
{
961998
int ret;
962999

@@ -968,13 +1005,13 @@ static int ad7380_init(struct ad7380_state *st, struct regulator *vref)
9681005
if (ret < 0)
9691006
return ret;
9701007

971-
/* select internal or external reference voltage */
972-
ret = regmap_update_bits(st->regmap, AD7380_REG_ADDR_CONFIG1,
973-
AD7380_CONFIG1_REFSEL,
974-
FIELD_PREP(AD7380_CONFIG1_REFSEL,
975-
vref ? 1 : 0));
976-
if (ret < 0)
977-
return ret;
1008+
if (external_ref_en) {
1009+
/* select external reference voltage */
1010+
ret = regmap_set_bits(st->regmap, AD7380_REG_ADDR_CONFIG1,
1011+
AD7380_CONFIG1_REFSEL);
1012+
if (ret < 0)
1013+
return ret;
1014+
}
9781015

9791016
/* This is the default value after reset. */
9801017
st->oversampling_ratio = 1;
@@ -987,16 +1024,11 @@ static int ad7380_init(struct ad7380_state *st, struct regulator *vref)
9871024
FIELD_PREP(AD7380_CONFIG2_SDO, 1));
9881025
}
9891026

990-
static void ad7380_regulator_disable(void *p)
991-
{
992-
regulator_disable(p);
993-
}
994-
9951027
static int ad7380_probe(struct spi_device *spi)
9961028
{
9971029
struct iio_dev *indio_dev;
9981030
struct ad7380_state *st;
999-
struct regulator *vref;
1031+
bool external_ref_en;
10001032
int ret, i;
10011033

10021034
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
@@ -1009,36 +1041,38 @@ static int ad7380_probe(struct spi_device *spi)
10091041
if (!st->chip_info)
10101042
return dev_err_probe(&spi->dev, -EINVAL, "missing match data\n");
10111043

1012-
vref = devm_regulator_get_optional(&spi->dev, "refio");
1013-
if (IS_ERR(vref)) {
1014-
if (PTR_ERR(vref) != -ENODEV)
1015-
return dev_err_probe(&spi->dev, PTR_ERR(vref),
1016-
"Failed to get refio regulator\n");
1017-
1018-
vref = NULL;
1019-
}
1044+
ret = devm_regulator_bulk_get_enable(&spi->dev, st->chip_info->num_supplies,
1045+
st->chip_info->supplies);
10201046

1021-
/*
1022-
* If there is no REFIO supply, then it means that we are using
1023-
* the internal 2.5V reference, otherwise REFIO is reference voltage.
1024-
*/
1025-
if (vref) {
1026-
ret = regulator_enable(vref);
1027-
if (ret)
1028-
return ret;
1029-
1030-
ret = devm_add_action_or_reset(&spi->dev,
1031-
ad7380_regulator_disable, vref);
1032-
if (ret)
1033-
return ret;
1047+
if (ret)
1048+
return dev_err_probe(&spi->dev, ret,
1049+
"Failed to enable power supplies\n");
1050+
fsleep(T_POWERUP_US);
10341051

1035-
ret = regulator_get_voltage(vref);
1052+
if (st->chip_info->external_ref_only) {
1053+
ret = devm_regulator_get_enable_read_voltage(&spi->dev,
1054+
"refin");
10361055
if (ret < 0)
1037-
return ret;
1056+
return dev_err_probe(&spi->dev, ret,
1057+
"Failed to get refin regulator\n");
10381058

10391059
st->vref_mv = ret / 1000;
1060+
1061+
/* these chips don't have a register bit for this */
1062+
external_ref_en = false;
10401063
} else {
1041-
st->vref_mv = AD7380_INTERNAL_REF_MV;
1064+
/*
1065+
* If there is no REFIO supply, then it means that we are using
1066+
* the internal reference, otherwise REFIO is reference voltage.
1067+
*/
1068+
ret = devm_regulator_get_enable_read_voltage(&spi->dev,
1069+
"refio");
1070+
if (ret < 0 && ret != -ENODEV)
1071+
return dev_err_probe(&spi->dev, ret,
1072+
"Failed to get refio regulator\n");
1073+
1074+
external_ref_en = ret != -ENODEV;
1075+
st->vref_mv = external_ref_en ? ret / 1000 : AD7380_INTERNAL_REF_MV;
10421076
}
10431077

10441078
if (st->chip_info->num_vcm_supplies > ARRAY_SIZE(st->vcm_mv))
@@ -1050,27 +1084,13 @@ static int ad7380_probe(struct spi_device *spi)
10501084
* input pin.
10511085
*/
10521086
for (i = 0; i < st->chip_info->num_vcm_supplies; i++) {
1053-
struct regulator *vcm;
1054-
1055-
vcm = devm_regulator_get(&spi->dev,
1056-
st->chip_info->vcm_supplies[i]);
1057-
if (IS_ERR(vcm))
1058-
return dev_err_probe(&spi->dev, PTR_ERR(vcm),
1059-
"Failed to get %s regulator\n",
1060-
st->chip_info->vcm_supplies[i]);
1087+
const char *vcm = st->chip_info->vcm_supplies[i];
10611088

1062-
ret = regulator_enable(vcm);
1063-
if (ret)
1064-
return ret;
1065-
1066-
ret = devm_add_action_or_reset(&spi->dev,
1067-
ad7380_regulator_disable, vcm);
1068-
if (ret)
1069-
return ret;
1070-
1071-
ret = regulator_get_voltage(vcm);
1089+
ret = devm_regulator_get_enable_read_voltage(&spi->dev, vcm);
10721090
if (ret < 0)
1073-
return ret;
1091+
return dev_err_probe(&spi->dev, ret,
1092+
"Failed to get %s regulator\n",
1093+
vcm);
10741094

10751095
st->vcm_mv[i] = ret / 1000;
10761096
}
@@ -1135,7 +1155,7 @@ static int ad7380_probe(struct spi_device *spi)
11351155
if (ret)
11361156
return ret;
11371157

1138-
ret = ad7380_init(st, vref);
1158+
ret = ad7380_init(st, external_ref_en);
11391159
if (ret)
11401160
return ret;
11411161

drivers/iio/dac/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ config LTC2632
380380
config LTC2664
381381
tristate "Analog Devices LTC2664 and LTC2672 DAC SPI driver"
382382
depends on SPI
383-
select REGMAP
383+
select REGMAP_SPI
384384
help
385385
Say yes here to build support for Analog Devices
386386
LTC2664 and LTC2672 converters (DAC).

0 commit comments

Comments
 (0)