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

iio: ad7266: Convert to use GPIO descriptors

The AD7266 have no in-tree users making use of the platform
data mechanism to pass address GPIO lines when not using
a fixed address, so we can easily convert this to use
GPIO descriptors instead of the platform data integers
currently passed.

Lowercase the labels "ad0".."ad2" as this will make a better
fit for platform descriptions like device tree that prefer
lowercase names such as "ad0-gpios" rather than "AD0-gpios".

Board files and other static users of this device can pass
the same GPIO descriptors using machine descriptor
tables if need be.

Cc: Alison Schofield <amsfield22@gmail.com>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Linus Walleij and committed by
Jonathan Cameron
5750ebab b747e352

+12 -20
+12 -17
drivers/iio/adc/ad7266.c
··· 11 11 #include <linux/spi/spi.h> 12 12 #include <linux/regulator/consumer.h> 13 13 #include <linux/err.h> 14 - #include <linux/gpio.h> 14 + #include <linux/gpio/consumer.h> 15 15 #include <linux/module.h> 16 16 17 17 #include <linux/interrupt.h> ··· 34 34 enum ad7266_range range; 35 35 enum ad7266_mode mode; 36 36 bool fixed_addr; 37 - struct gpio gpios[3]; 37 + struct gpio_desc *gpios[3]; 38 38 39 39 /* 40 40 * DMA (thus cache coherency maintenance) requires the ··· 117 117 } 118 118 119 119 for (i = 0; i < 3; ++i) 120 - gpio_set_value(st->gpios[i].gpio, (bool)(nr & BIT(i))); 120 + gpiod_set_value(st->gpios[i], (bool)(nr & BIT(i))); 121 121 } 122 122 123 123 static int ad7266_update_scan_mode(struct iio_dev *indio_dev, ··· 376 376 } 377 377 378 378 static const char * const ad7266_gpio_labels[] = { 379 - "AD0", "AD1", "AD2", 379 + "ad0", "ad1", "ad2", 380 380 }; 381 381 382 382 static int ad7266_probe(struct spi_device *spi) ··· 419 419 420 420 if (!st->fixed_addr) { 421 421 for (i = 0; i < ARRAY_SIZE(st->gpios); ++i) { 422 - st->gpios[i].gpio = pdata->addr_gpios[i]; 423 - st->gpios[i].flags = GPIOF_OUT_INIT_LOW; 424 - st->gpios[i].label = ad7266_gpio_labels[i]; 422 + st->gpios[i] = devm_gpiod_get(&spi->dev, 423 + ad7266_gpio_labels[i], 424 + GPIOD_OUT_LOW); 425 + if (IS_ERR(st->gpios[i])) { 426 + ret = PTR_ERR(st->gpios[i]); 427 + goto error_disable_reg; 428 + } 425 429 } 426 - ret = gpio_request_array(st->gpios, 427 - ARRAY_SIZE(st->gpios)); 428 - if (ret) 429 - goto error_disable_reg; 430 430 } 431 431 } else { 432 432 st->fixed_addr = true; ··· 465 465 ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time, 466 466 &ad7266_trigger_handler, &iio_triggered_buffer_setup_ops); 467 467 if (ret) 468 - goto error_free_gpios; 468 + goto error_disable_reg; 469 469 470 470 ret = iio_device_register(indio_dev); 471 471 if (ret) ··· 475 475 476 476 error_buffer_cleanup: 477 477 iio_triggered_buffer_cleanup(indio_dev); 478 - error_free_gpios: 479 - if (!st->fixed_addr) 480 - gpio_free_array(st->gpios, ARRAY_SIZE(st->gpios)); 481 478 error_disable_reg: 482 479 if (!IS_ERR(st->reg)) 483 480 regulator_disable(st->reg); ··· 489 492 490 493 iio_device_unregister(indio_dev); 491 494 iio_triggered_buffer_cleanup(indio_dev); 492 - if (!st->fixed_addr) 493 - gpio_free_array(st->gpios, ARRAY_SIZE(st->gpios)); 494 495 if (!IS_ERR(st->reg)) 495 496 regulator_disable(st->reg); 496 497
-3
include/linux/platform_data/ad7266.h
··· 40 40 * @range: Reference voltage range the device is configured for 41 41 * @mode: Sample mode the device is configured for 42 42 * @fixed_addr: Whether the address pins are hard-wired 43 - * @addr_gpios: GPIOs used for controlling the address pins, only used if 44 - * fixed_addr is set to false. 45 43 */ 46 44 struct ad7266_platform_data { 47 45 enum ad7266_range range; 48 46 enum ad7266_mode mode; 49 47 bool fixed_addr; 50 - unsigned int addr_gpios[3]; 51 48 }; 52 49 53 50 #endif