aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lechner <dlechner@baylibre.com>2024-03-19 09:27:45 -0500
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2024-03-23 18:29:54 +0000
commit8d22de75f0fe6c0645bc8e3979af6eedfd59f9a2 (patch)
tree920e761480002e7e871050eac23adab11c93dd87
parentd7a3a7bb77d2321e399f0a7cb6235cb2840576af (diff)
downloadiio-8d22de75f0fe6c0645bc8e3979af6eedfd59f9a2.tar.gz
iio: adc: ad7944: simplify adi,spi-mode property parsing
This simplifies the adi,spi-mode property parsing by using device_property_match_property_string() instead of two separate functions. Also, the error return value is now more informative in cases where there was a problem parsing the property. Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://lore.kernel.org/r/20240319-ad7944-cleanups-v2-1-50e77269351b@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
-rw-r--r--drivers/iio/adc/ad7944.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c
index d5ec6b5a41c7da..261a3f645fd81c 100644
--- a/drivers/iio/adc/ad7944.c
+++ b/drivers/iio/adc/ad7944.c
@@ -366,7 +366,6 @@ static int ad7944_probe(struct spi_device *spi)
struct ad7944_adc *adc;
bool have_refin = false;
struct regulator *ref;
- const char *str_val;
int ret;
indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
@@ -382,16 +381,18 @@ static int ad7944_probe(struct spi_device *spi)
adc->timing_spec = chip_info->timing_spec;
- if (device_property_read_string(dev, "adi,spi-mode", &str_val) == 0) {
- ret = sysfs_match_string(ad7944_spi_modes, str_val);
- if (ret < 0)
- return dev_err_probe(dev, -EINVAL,
- "unsupported adi,spi-mode\n");
+ ret = device_property_match_property_string(dev, "adi,spi-mode",
+ ad7944_spi_modes,
+ ARRAY_SIZE(ad7944_spi_modes));
+ if (ret < 0) {
+ if (ret != -EINVAL)
+ return dev_err_probe(dev, ret,
+ "getting adi,spi-mode property failed\n");
- adc->spi_mode = ret;
- } else {
/* absence of adi,spi-mode property means default mode */
adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
+ } else {
+ adc->spi_mode = ret;
}
if (adc->spi_mode == AD7944_SPI_MODE_CHAIN)