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

gpio: twl4030: Implement .get_direction()

It's nice to be able to read back the direction of the GPIO
line from the hardware so implement .get_direction() for
twl4030.

Acked-by: Tony Lindgren <tony@atomide.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>

+41 -1
+41 -1
drivers/gpio/gpio-twl4030.c
··· 154 154 return ret; 155 155 } 156 156 157 + static int twl4030_get_gpio_direction(int gpio) 158 + { 159 + u8 d_bnk = gpio >> 3; 160 + u8 d_msk = BIT(gpio & 0x7); 161 + u8 base = REG_GPIODATADIR1 + d_bnk; 162 + int ret = 0; 163 + 164 + ret = gpio_twl4030_read(base); 165 + if (ret < 0) 166 + return ret; 167 + 168 + /* 1 = output, but gpiolib semantics are inverse so invert */ 169 + ret = !(ret & d_msk); 170 + 171 + return ret; 172 + } 173 + 157 174 static int twl4030_set_gpio_dataout(int gpio, int enable) 158 175 { 159 176 u8 d_bnk = gpio >> 3; ··· 376 359 return ret; 377 360 } 378 361 362 + static int twl_get_direction(struct gpio_chip *chip, unsigned offset) 363 + { 364 + struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); 365 + /* 366 + * Default 0 = output 367 + * LED GPIOs >= TWL4030_GPIO_MAX are always output 368 + */ 369 + int ret = 0; 370 + 371 + mutex_lock(&priv->mutex); 372 + if (offset < TWL4030_GPIO_MAX) { 373 + ret = twl4030_get_gpio_direction(offset); 374 + if (ret) { 375 + mutex_unlock(&priv->mutex); 376 + return ret; 377 + } 378 + } 379 + mutex_unlock(&priv->mutex); 380 + 381 + return ret; 382 + } 383 + 379 384 static int twl_to_irq(struct gpio_chip *chip, unsigned offset) 380 385 { 381 386 struct gpio_twl4030_priv *priv = gpiochip_get_data(chip); ··· 413 374 .request = twl_request, 414 375 .free = twl_free, 415 376 .direction_input = twl_direction_in, 416 - .get = twl_get, 417 377 .direction_output = twl_direction_out, 378 + .get_direction = twl_get_direction, 379 + .get = twl_get, 418 380 .set = twl_set, 419 381 .to_irq = twl_to_irq, 420 382 .can_sleep = true,