Commit 27eea477 authored by David Lechner's avatar David Lechner Committed by Jonathan Cameron

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: default avatarAndy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: default avatarDavid Lechner <dlechner@baylibre.com>
Link: https://lore.kernel.org/r/20240325-ad7944-cleanups-v3-1-3a19120cdd06@baylibre.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 3d797af1
...@@ -366,7 +366,6 @@ static int ad7944_probe(struct spi_device *spi) ...@@ -366,7 +366,6 @@ static int ad7944_probe(struct spi_device *spi)
struct ad7944_adc *adc; struct ad7944_adc *adc;
bool have_refin = false; bool have_refin = false;
struct regulator *ref; struct regulator *ref;
const char *str_val;
int ret; int ret;
indio_dev = devm_iio_device_alloc(dev, sizeof(*adc)); indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
...@@ -382,17 +381,17 @@ static int ad7944_probe(struct spi_device *spi) ...@@ -382,17 +381,17 @@ static int ad7944_probe(struct spi_device *spi)
adc->timing_spec = chip_info->timing_spec; adc->timing_spec = chip_info->timing_spec;
if (device_property_read_string(dev, "adi,spi-mode", &str_val) == 0) { ret = device_property_match_property_string(dev, "adi,spi-mode",
ret = sysfs_match_string(ad7944_spi_modes, str_val); ad7944_spi_modes,
if (ret < 0) ARRAY_SIZE(ad7944_spi_modes));
return dev_err_probe(dev, -EINVAL, /* absence of adi,spi-mode property means default mode */
"unsupported adi,spi-mode\n"); if (ret == -EINVAL)
adc->spi_mode = ret;
} else {
/* absence of adi,spi-mode property means default mode */
adc->spi_mode = AD7944_SPI_MODE_DEFAULT; adc->spi_mode = AD7944_SPI_MODE_DEFAULT;
} else if (ret < 0)
return dev_err_probe(dev, ret,
"getting adi,spi-mode property failed\n");
else
adc->spi_mode = ret;
if (adc->spi_mode == AD7944_SPI_MODE_CHAIN) if (adc->spi_mode == AD7944_SPI_MODE_CHAIN)
return dev_err_probe(dev, -EINVAL, return dev_err_probe(dev, -EINVAL,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment