mirror of
https://github.com/torvalds/linux.git
synced 2026-07-28 01:55:51 +02:00
iio: adc: ad4170: use lookup table for gpio mask selection
Both ad4170_gpio_direction_input() and ad4170_gpio_direction_output() duplicate the same switch statement to map a GPIO offset to its corresponding mask. Replace the switch with a static lookup table, simplifying the code and avoiding duplication. This also makes future extensions easier. No functional change intended. Signed-off-by: Guilherme Ivo Bozi <guilherme.bozi@usp.br> Acked-by: Marcelo Schmitt <marcelo.schmitt1@gmail.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
277a2d241c
commit
1ebc22b9b3
|
|
@ -1699,34 +1699,29 @@ static int ad4170_gpio_get_direction(struct gpio_chip *gc, unsigned int offset)
|
|||
return ret;
|
||||
}
|
||||
|
||||
static const unsigned long gpio_masks[] = {
|
||||
AD4170_GPIO_MODE_GPIO0_MSK,
|
||||
AD4170_GPIO_MODE_GPIO1_MSK,
|
||||
AD4170_GPIO_MODE_GPIO2_MSK,
|
||||
AD4170_GPIO_MODE_GPIO3_MSK,
|
||||
};
|
||||
|
||||
static int ad4170_gpio_direction_input(struct gpio_chip *gc, unsigned int offset)
|
||||
{
|
||||
struct iio_dev *indio_dev = gpiochip_get_data(gc);
|
||||
struct ad4170_state *st = iio_priv(indio_dev);
|
||||
unsigned long gpio_mask;
|
||||
int ret;
|
||||
|
||||
if (!iio_device_claim_direct(indio_dev))
|
||||
return -EBUSY;
|
||||
|
||||
switch (offset) {
|
||||
case 0:
|
||||
gpio_mask = AD4170_GPIO_MODE_GPIO0_MSK;
|
||||
break;
|
||||
case 1:
|
||||
gpio_mask = AD4170_GPIO_MODE_GPIO1_MSK;
|
||||
break;
|
||||
case 2:
|
||||
gpio_mask = AD4170_GPIO_MODE_GPIO2_MSK;
|
||||
break;
|
||||
case 3:
|
||||
gpio_mask = AD4170_GPIO_MODE_GPIO3_MSK;
|
||||
break;
|
||||
default:
|
||||
if (offset >= ARRAY_SIZE(gpio_masks)) {
|
||||
ret = -EINVAL;
|
||||
goto err_release;
|
||||
}
|
||||
ret = regmap_update_bits(st->regmap, AD4170_GPIO_MODE_REG, gpio_mask,
|
||||
|
||||
ret = regmap_update_bits(st->regmap, AD4170_GPIO_MODE_REG,
|
||||
gpio_masks[offset],
|
||||
AD4170_GPIO_MODE_GPIO_INPUT << (2 * offset));
|
||||
|
||||
err_release:
|
||||
|
|
@ -1740,7 +1735,6 @@ static int ad4170_gpio_direction_output(struct gpio_chip *gc,
|
|||
{
|
||||
struct iio_dev *indio_dev = gpiochip_get_data(gc);
|
||||
struct ad4170_state *st = iio_priv(indio_dev);
|
||||
unsigned long gpio_mask;
|
||||
int ret;
|
||||
|
||||
ret = ad4170_gpio_set(gc, offset, value);
|
||||
|
|
@ -1750,24 +1744,13 @@ static int ad4170_gpio_direction_output(struct gpio_chip *gc,
|
|||
if (!iio_device_claim_direct(indio_dev))
|
||||
return -EBUSY;
|
||||
|
||||
switch (offset) {
|
||||
case 0:
|
||||
gpio_mask = AD4170_GPIO_MODE_GPIO0_MSK;
|
||||
break;
|
||||
case 1:
|
||||
gpio_mask = AD4170_GPIO_MODE_GPIO1_MSK;
|
||||
break;
|
||||
case 2:
|
||||
gpio_mask = AD4170_GPIO_MODE_GPIO2_MSK;
|
||||
break;
|
||||
case 3:
|
||||
gpio_mask = AD4170_GPIO_MODE_GPIO3_MSK;
|
||||
break;
|
||||
default:
|
||||
if (offset >= ARRAY_SIZE(gpio_masks)) {
|
||||
ret = -EINVAL;
|
||||
goto err_release;
|
||||
}
|
||||
ret = regmap_update_bits(st->regmap, AD4170_GPIO_MODE_REG, gpio_mask,
|
||||
|
||||
ret = regmap_update_bits(st->regmap, AD4170_GPIO_MODE_REG,
|
||||
gpio_masks[offset],
|
||||
AD4170_GPIO_MODE_GPIO_OUTPUT << (2 * offset));
|
||||
|
||||
err_release:
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user