All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: axp209: Implement get_direction
@ 2016-09-21 20:51 Maxime Ripard
  2016-09-23 13:13 ` Linus Walleij
  0 siblings, 1 reply; 2+ messages in thread
From: Maxime Ripard @ 2016-09-21 20:51 UTC (permalink / raw)
  To: Linus Walleij, Alexandre Courbot; +Cc: linux-gpio, Chen-Yu Tsai, Maxime Ripard

Implement the get_direction callback for the GPIOs found in the AXP209
PMIC.

Due to the way they are implemented, in the same register you have the
muxing options, GPIO directions and GPIO values. Since you have no control
over what value is there at reset, simply use output as the default.

Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>
---
 drivers/gpio/gpio-axp209.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/drivers/gpio/gpio-axp209.c b/drivers/gpio/gpio-axp209.c
index 3174799c27c6..d9c2a517c6df 100644
--- a/drivers/gpio/gpio-axp209.c
+++ b/drivers/gpio/gpio-axp209.c
@@ -77,6 +77,35 @@ static int axp20x_gpio_get(struct gpio_chip *chip, unsigned offset)
 	return !!(val & BIT(offset + 4));
 }
 
+static int axp20x_gpio_get_direction(struct gpio_chip *chip, unsigned offset)
+{
+	struct axp20x_gpio *gpio = gpiochip_get_data(chip);
+	unsigned int val;
+	int reg, ret;
+
+	reg = axp20x_gpio_get_reg(offset);
+	if (reg < 0)
+		return reg;
+
+	ret = regmap_read(gpio->regmap, reg, &val);
+	if (ret)
+		return ret;
+
+	/*
+	 * This shouldn't really happen if the pin is in use already,
+	 * or if it's not in use yet, it doesn't matter since we're
+	 * going to change the value soon anyway. Default to output.
+	 */
+	if ((val & AXP20X_GPIO_FUNCTIONS) > 2)
+		return 0;
+
+	/*
+	 * The GPIO directions are the three lowest values.
+	 * 2 is input, 0 and 1 are output
+	 */
+	return val & 2;
+}
+
 static int axp20x_gpio_output(struct gpio_chip *chip, unsigned offset,
 			      int value)
 {
@@ -123,6 +152,7 @@ static int axp20x_gpio_probe(struct platform_device *pdev)
 	gpio->chip.label		= dev_name(&pdev->dev);
 	gpio->chip.owner		= THIS_MODULE;
 	gpio->chip.get			= axp20x_gpio_get;
+	gpio->chip.get_direction	= axp20x_gpio_get_direction;
 	gpio->chip.set			= axp20x_gpio_set;
 	gpio->chip.direction_input	= axp20x_gpio_input;
 	gpio->chip.direction_output	= axp20x_gpio_output;
-- 
2.9.3


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

* Re: [PATCH] gpio: axp209: Implement get_direction
  2016-09-21 20:51 [PATCH] gpio: axp209: Implement get_direction Maxime Ripard
@ 2016-09-23 13:13 ` Linus Walleij
  0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2016-09-23 13:13 UTC (permalink / raw)
  To: Maxime Ripard; +Cc: Alexandre Courbot, linux-gpio, Chen-Yu Tsai

On Wed, Sep 21, 2016 at 10:51 PM, Maxime Ripard
<maxime.ripard@free-electrons.com> wrote:

> Implement the get_direction callback for the GPIOs found in the AXP209
> PMIC.
>
> Due to the way they are implemented, in the same register you have the
> muxing options, GPIO directions and GPIO values. Since you have no control
> over what value is there at reset, simply use output as the default.
>
> Signed-off-by: Maxime Ripard <maxime.ripard@free-electrons.com>

Patch applied. Thanks!

Yours,
Linus Walleij

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

end of thread, other threads:[~2016-09-23 13:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-21 20:51 [PATCH] gpio: axp209: Implement get_direction Maxime Ripard
2016-09-23 13:13 ` Linus Walleij

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.