Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: adc: ad799x: add reference voltage capability to chip_info

If the chip supports an external reference voltage
on REFIN pin then the "vref-supply" regulator may be used.

This commit partially refactors 6b104e7895ab16b9b7f466c5f2ca282b87f661e8
to add the capability of the chip to have an external
voltage reference and then remove the ugly conditional check
on chip id.

Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Stefano Manni <stefano.manni@gmail.com>
Acked-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250807074850.130831-2-stefano.manni@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Stefano Manni and committed by
Jonathan Cameron
ed187a20 d2d75e25

+12 -17
+12 -17
drivers/iio/adc/ad799x.c
··· 114 114 * @num_channels: number of channels 115 115 * @noirq_config: device configuration w/o IRQ 116 116 * @irq_config: device configuration w/IRQ 117 + * @has_vref: device supports external reference voltage 117 118 */ 118 119 struct ad799x_chip_info { 119 120 int num_channels; 120 121 const struct ad799x_chip_config noirq_config; 121 122 const struct ad799x_chip_config irq_config; 123 + bool has_vref; 122 124 }; 123 125 124 126 struct ad799x_state { ··· 606 604 static const struct ad799x_chip_info ad799x_chip_info_tbl[] = { 607 605 [ad7991] = { 608 606 .num_channels = 5, 607 + .has_vref = true, 609 608 .noirq_config = { 610 609 .channel = { 611 610 AD799X_CHANNEL(0, 12), ··· 620 617 }, 621 618 [ad7995] = { 622 619 .num_channels = 5, 620 + .has_vref = true, 623 621 .noirq_config = { 624 622 .channel = { 625 623 AD799X_CHANNEL(0, 10), ··· 634 630 }, 635 631 [ad7999] = { 636 632 .num_channels = 5, 633 + .has_vref = true, 637 634 .noirq_config = { 638 635 .channel = { 639 636 AD799X_CHANNEL(0, 8), ··· 814 809 return ret; 815 810 816 811 /* check if an external reference is supplied */ 817 - st->vref = devm_regulator_get_optional(&client->dev, "vref"); 818 - 819 - if (IS_ERR(st->vref)) { 820 - if (PTR_ERR(st->vref) == -ENODEV) { 812 + if (chip_info->has_vref) { 813 + st->vref = devm_regulator_get_optional(&client->dev, "vref"); 814 + ret = PTR_ERR_OR_ZERO(st->vref); 815 + if (ret) { 816 + if (ret != -ENODEV) 817 + goto error_disable_reg; 821 818 st->vref = NULL; 822 819 dev_info(&client->dev, "Using VCC reference voltage\n"); 823 - } else { 824 - ret = PTR_ERR(st->vref); 825 - goto error_disable_reg; 826 820 } 827 - } 828 821 829 - if (st->vref) { 830 - /* 831 - * Use external reference voltage if supported by hardware. 832 - * This is optional if voltage / regulator present, use VCC otherwise. 833 - */ 834 - if ((st->id == ad7991) || (st->id == ad7995) || (st->id == ad7999)) { 822 + if (st->vref) { 835 823 dev_info(&client->dev, "Using external reference voltage\n"); 836 824 extra_config |= AD7991_REF_SEL; 837 825 ret = regulator_enable(st->vref); 838 826 if (ret) 839 827 goto error_disable_reg; 840 - } else { 841 - st->vref = NULL; 842 - dev_warn(&client->dev, "Supplied reference not supported\n"); 843 828 } 844 829 } 845 830