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

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: ad9467: fix reset gpio handling

The reset gpio was being handled with inverted polarity. This means that
as far as gpiolib is concerned we were actually leaving the pin asserted
(in theory, this would mean reset). However, inverting the polarity in
devicetree made things work. Fix it by doing it the proper way and how
gpiolib expects it to be done.

While at it, moved the handling to it's own function and dropped
'reset_gpio' from the 'struct ad9467_state' as we only need it during
probe. On top of that, refactored things so that we now request the gpio
asserted (i.e in reset) and then de-assert it. Also note that we now use
gpiod_set_value_cansleep() instead of gpiod_direction_output() as we
already request the pin as output.

Fixes: ad6797120238 ("iio: adc: ad9467: add support AD9467 ADC")
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20231207-iio-backend-prep-v2-1-a4a33bc4d70e@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sa and committed by
Jonathan Cameron
76f02853 17819da6

+18 -13
+18 -13
drivers/iio/adc/ad9467.c
··· 121 121 unsigned int output_mode; 122 122 123 123 struct gpio_desc *pwrdown_gpio; 124 - struct gpio_desc *reset_gpio; 125 124 }; 126 125 127 126 static int ad9467_spi_read(struct spi_device *spi, unsigned int reg) ··· 377 378 return ad9467_outputmode_set(st->spi, st->output_mode); 378 379 } 379 380 381 + static int ad9467_reset(struct device *dev) 382 + { 383 + struct gpio_desc *gpio; 384 + 385 + gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 386 + if (IS_ERR_OR_NULL(gpio)) 387 + return PTR_ERR_OR_ZERO(gpio); 388 + 389 + fsleep(1); 390 + gpiod_set_value_cansleep(gpio, 0); 391 + fsleep(10 * USEC_PER_MSEC); 392 + 393 + return 0; 394 + } 395 + 380 396 static int ad9467_probe(struct spi_device *spi) 381 397 { 382 398 const struct ad9467_chip_info *info; ··· 422 408 if (IS_ERR(st->pwrdown_gpio)) 423 409 return PTR_ERR(st->pwrdown_gpio); 424 410 425 - st->reset_gpio = devm_gpiod_get_optional(&spi->dev, "reset", 426 - GPIOD_OUT_LOW); 427 - if (IS_ERR(st->reset_gpio)) 428 - return PTR_ERR(st->reset_gpio); 429 - 430 - if (st->reset_gpio) { 431 - udelay(1); 432 - ret = gpiod_direction_output(st->reset_gpio, 1); 433 - if (ret) 434 - return ret; 435 - mdelay(10); 436 - } 411 + ret = ad9467_reset(&spi->dev); 412 + if (ret) 413 + return ret; 437 414 438 415 conv->chip_info = &info->axi_adc_info; 439 416