All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 1/3] gpio: pca953x: Introduce a long awaited ->get_direction()
@ 2017-03-20 15:45 Andy Shevchenko
  2017-03-20 15:45 ` [PATCH v1 2/3] gpio: pca953x: Sort headers alphabetically Andy Shevchenko
  2017-03-20 15:45 ` [PATCH v1 3/3] gpio: pca953x: Expand comment for "reset" GPIO in ACPI case Andy Shevchenko
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2017-03-20 15:45 UTC (permalink / raw)
  To: Linus Walleij, linux-gpio; +Cc: Andy Shevchenko

Introduce ->get_direction() callback for the driver.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpio-pca953x.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index d44232aadb6c..968e8bf5b286 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -363,6 +363,21 @@ static void pca953x_gpio_set_value(struct gpio_chip *gc, unsigned off, int val)
 	mutex_unlock(&chip->i2c_lock);
 }
 
+static int pca953x_gpio_get_direction(struct gpio_chip *gc, unsigned off)
+{
+	struct pca953x_chip *chip = gpiochip_get_data(gc);
+	u32 reg_val;
+	int ret;
+
+	mutex_lock(&chip->i2c_lock);
+	ret = pca953x_read_single(chip, chip->regs->direction, &reg_val, off);
+	mutex_unlock(&chip->i2c_lock);
+	if (ret < 0)
+		return ret;
+
+	return (reg_val & (1u << (off % BANK_SZ))) ? GPIOF_DIR_OUT : GPIOF_DIR_IN;
+}
+
 static void pca953x_gpio_set_multiple(struct gpio_chip *gc,
 				      unsigned long *mask, unsigned long *bits)
 {
@@ -408,6 +423,7 @@ static void pca953x_setup_gpio(struct pca953x_chip *chip, int gpios)
 	gc->direction_output = pca953x_gpio_direction_output;
 	gc->get = pca953x_gpio_get_value;
 	gc->set = pca953x_gpio_set_value;
+	gc->get_direction = pca953x_gpio_get_direction;
 	gc->set_multiple = pca953x_gpio_set_multiple;
 	gc->can_sleep = true;
 
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-03-20 15:46 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-20 15:45 [PATCH v1 1/3] gpio: pca953x: Introduce a long awaited ->get_direction() Andy Shevchenko
2017-03-20 15:45 ` [PATCH v1 2/3] gpio: pca953x: Sort headers alphabetically Andy Shevchenko
2017-03-20 15:45 ` [PATCH v1 3/3] gpio: pca953x: Expand comment for "reset" GPIO in ACPI case Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.