Skip to content

Commit 80979ce

Browse files
justephnunojsa
authored andcommitted
iio: adc: ad7380: fix supplies for ad7380-4
ad7380-4 is the only device in the family that does not have an internal reference. It uses "refin" as a required external reference. All other devices in the family use "refio"" as an optional external reference. Fixes: 737413d ("iio: adc: ad7380: add support for ad738x-4 4 channels variants") Reviewed-by: Nuno Sa <nuno.sa@analog.com> Reviewed-by: David Lechner <dlechner@baylibre.com> Signed-off-by: Julien Stephan <jstephan@baylibre.com> Link: https://patch.msgid.link/20241022-ad7380-fix-supplies-v3-4-f0cefe1b7fa6@baylibre.com Cc: <Stable@vger.kernel.org> Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent 4379a3c commit 80979ce

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

drivers/iio/adc/ad7380.c

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ struct ad7380_chip_info {
8989
bool has_mux;
9090
const char * const *supplies;
9191
unsigned int num_supplies;
92+
bool external_ref_only;
9293
const char * const *vcm_supplies;
9394
unsigned int num_vcm_supplies;
9495
const unsigned long *available_scan_masks;
@@ -431,6 +432,7 @@ static const struct ad7380_chip_info ad7380_4_chip_info = {
431432
.num_simult_channels = 4,
432433
.supplies = ad7380_supplies,
433434
.num_supplies = ARRAY_SIZE(ad7380_supplies),
435+
.external_ref_only = true,
434436
.available_scan_masks = ad7380_4_channel_scan_masks,
435437
.timing_specs = &ad7380_4_timing,
436438
};
@@ -1047,17 +1049,31 @@ static int ad7380_probe(struct spi_device *spi)
10471049
"Failed to enable power supplies\n");
10481050
fsleep(T_POWERUP_US);
10491051

1050-
/*
1051-
* If there is no REFIO supply, then it means that we are using
1052-
* the internal 2.5V reference, otherwise REFIO is reference voltage.
1053-
*/
1054-
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "refio");
1055-
if (ret < 0 && ret != -ENODEV)
1056-
return dev_err_probe(&spi->dev, ret,
1057-
"Failed to get refio regulator\n");
1052+
if (st->chip_info->external_ref_only) {
1053+
ret = devm_regulator_get_enable_read_voltage(&spi->dev,
1054+
"refin");
1055+
if (ret < 0)
1056+
return dev_err_probe(&spi->dev, ret,
1057+
"Failed to get refin regulator\n");
1058+
1059+
st->vref_mv = ret / 1000;
10581060

1059-
external_ref_en = ret != -ENODEV;
1060-
st->vref_mv = external_ref_en ? ret / 1000 : AD7380_INTERNAL_REF_MV;
1061+
/* these chips don't have a register bit for this */
1062+
external_ref_en = false;
1063+
} else {
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;
1076+
}
10611077

10621078
if (st->chip_info->num_vcm_supplies > ARRAY_SIZE(st->vcm_mv))
10631079
return dev_err_probe(&spi->dev, -EINVAL,

0 commit comments

Comments
 (0)