All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pinctrl/amd: add get_direction handler
@ 2018-02-16 19:12 ` Daniel Kurtz
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Kurtz @ 2018-02-16 19:12 UTC (permalink / raw)
  Cc: Daniel Kurtz, Linus Walleij, open list:PIN CONTROL SUBSYSTEM, open list

On boot, gpiochip_add_data() initializes the FLAG_IS_OUT bit in
desc->flags iff its gpio_chip does not have ->direction_input() handler,
else it is initialized to 0, which implies the GPIO is an "input".

Later, the sysfs "direction" handler will use gpiod_get_direction() to
get the current direction, but if no ->get_direction() handler is
installed, the result will just be the current (initial) value of flags,
which will always be OUT irregardless of the initial register value.

Add a get_direction() handler to pinctrl-amd to fix this and always
provide the correct value for direction.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/pinctrl/pinctrl-amd.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index 61d830c2bc17..281b700fe7e9 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -40,6 +40,19 @@
 #include "pinctrl-utils.h"
 #include "pinctrl-amd.h"
 
+static int amd_gpio_get_direction(struct gpio_chip *gc, unsigned offset)
+{
+	unsigned long flags;
+	u32 pin_reg;
+	struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
+
+	raw_spin_lock_irqsave(&gpio_dev->lock, flags);
+	pin_reg = readl(gpio_dev->base + offset * 4);
+	raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
+
+	return !(pin_reg & BIT(OUTPUT_ENABLE_OFF));
+}
+
 static int amd_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
 {
 	unsigned long flags;
@@ -845,6 +858,7 @@ static int amd_gpio_probe(struct platform_device *pdev)
 #endif
 
 	gpio_dev->pdev = pdev;
+	gpio_dev->gc.get_direction	= amd_gpio_get_direction;
 	gpio_dev->gc.direction_input	= amd_gpio_direction_input;
 	gpio_dev->gc.direction_output	= amd_gpio_direction_output;
 	gpio_dev->gc.get			= amd_gpio_get_value;
-- 
2.16.1.291.g4437f3f132-goog

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

* [PATCH] pinctrl/amd: add get_direction handler
@ 2018-02-16 19:12 ` Daniel Kurtz
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Kurtz @ 2018-02-16 19:12 UTC (permalink / raw)
  Cc: Daniel Kurtz, Linus Walleij, open list:PIN CONTROL SUBSYSTEM, open list

On boot, gpiochip_add_data() initializes the FLAG_IS_OUT bit in
desc->flags iff its gpio_chip does not have ->direction_input() handler,
else it is initialized to 0, which implies the GPIO is an "input".

Later, the sysfs "direction" handler will use gpiod_get_direction() to
get the current direction, but if no ->get_direction() handler is
installed, the result will just be the current (initial) value of flags,
which will always be OUT irregardless of the initial register value.

Add a get_direction() handler to pinctrl-amd to fix this and always
provide the correct value for direction.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>
---
 drivers/pinctrl/pinctrl-amd.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index 61d830c2bc17..281b700fe7e9 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -40,6 +40,19 @@
 #include "pinctrl-utils.h"
 #include "pinctrl-amd.h"
 
+static int amd_gpio_get_direction(struct gpio_chip *gc, unsigned offset)
+{
+	unsigned long flags;
+	u32 pin_reg;
+	struct amd_gpio *gpio_dev = gpiochip_get_data(gc);
+
+	raw_spin_lock_irqsave(&gpio_dev->lock, flags);
+	pin_reg = readl(gpio_dev->base + offset * 4);
+	raw_spin_unlock_irqrestore(&gpio_dev->lock, flags);
+
+	return !(pin_reg & BIT(OUTPUT_ENABLE_OFF));
+}
+
 static int amd_gpio_direction_input(struct gpio_chip *gc, unsigned offset)
 {
 	unsigned long flags;
@@ -845,6 +858,7 @@ static int amd_gpio_probe(struct platform_device *pdev)
 #endif
 
 	gpio_dev->pdev = pdev;
+	gpio_dev->gc.get_direction	= amd_gpio_get_direction;
 	gpio_dev->gc.direction_input	= amd_gpio_direction_input;
 	gpio_dev->gc.direction_output	= amd_gpio_direction_output;
 	gpio_dev->gc.get			= amd_gpio_get_value;
-- 
2.16.1.291.g4437f3f132-goog

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

* Re: [PATCH] pinctrl/amd: add get_direction handler
  2018-02-16 19:12 ` Daniel Kurtz
  (?)
@ 2018-02-22 14:53 ` Linus Walleij
  -1 siblings, 0 replies; 3+ messages in thread
From: Linus Walleij @ 2018-02-22 14:53 UTC (permalink / raw)
  To: Daniel Kurtz; +Cc: open list:PIN CONTROL SUBSYSTEM, open list

On Fri, Feb 16, 2018 at 8:12 PM, Daniel Kurtz <djkurtz@chromium.org> wrote:

> On boot, gpiochip_add_data() initializes the FLAG_IS_OUT bit in
> desc->flags iff its gpio_chip does not have ->direction_input() handler,
> else it is initialized to 0, which implies the GPIO is an "input".
>
> Later, the sysfs "direction" handler will use gpiod_get_direction() to
> get the current direction, but if no ->get_direction() handler is
> installed, the result will just be the current (initial) value of flags,
> which will always be OUT irregardless of the initial register value.
>
> Add a get_direction() handler to pinctrl-amd to fix this and always
> provide the correct value for direction.
>
> Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>

Hm, please don't use the sysfs... use the chardev!

Anyways, patch is fine and applied.

Yours,
Linus Walleij

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

end of thread, other threads:[~2018-02-22 14:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-16 19:12 [PATCH] pinctrl/amd: add get_direction handler Daniel Kurtz
2018-02-16 19:12 ` Daniel Kurtz
2018-02-22 14:53 ` 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.