diff mbox series

[v4,08/16] gpio: sandbox: Fully separate pin value from output value

Message ID 20210205042210.2949365-9-sjg@chromium.org
State Accepted
Commit 0242aecb4c40060d532b907e581f1bbd4c9ba9af
Delegated to: Tom Rini
Headers show
Series gpio: Update and simplify the uclass API | expand

Commit Message

Simon Glass Feb. 5, 2021, 4:22 a.m. UTC
At present we have the concept of a pin's external value. This is what
is used when getting the value of a pin. But we still set the
GPIOD_IS_OUT_ACTIVE flag when changing the value. This is not actually
correct, since if the pin changes from output to input, the external
value need not change. Adjust the logic for this difference.

Signed-off-by: Simon Glass <sjg@chromium.org>

Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

(no changes since v1)

 drivers/gpio/sandbox.c | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

Comments

Tom Rini March 4, 2021, 6:14 p.m. UTC | #1
On Thu, Feb 04, 2021 at 09:22:01PM -0700, Simon Glass wrote:

> At present we have the concept of a pin's external value. This is what
> is used when getting the value of a pin. But we still set the
> GPIOD_IS_OUT_ACTIVE flag when changing the value. This is not actually
> correct, since if the pin changes from output to input, the external
> value need not change. Adjust the logic for this difference.
> 
> Signed-off-by: Simon Glass <sjg@chromium.org>
> 
> Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>

Applied to u-boot/next, thanks!
diff mbox series

Patch

diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c
index 4d73b954b26..912c333e560 100644
--- a/drivers/gpio/sandbox.c
+++ b/drivers/gpio/sandbox.c
@@ -85,7 +85,7 @@  int sandbox_gpio_get_value(struct udevice *dev, unsigned offset)
 
 int sandbox_gpio_set_value(struct udevice *dev, unsigned offset, int value)
 {
-	set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE | GPIOD_EXT_HIGH, value);
+	set_gpio_flag(dev, offset, GPIOD_EXT_HIGH, value);
 
 	return 0;
 }
@@ -141,10 +141,19 @@  static int sb_gpio_direction_input(struct udevice *dev, unsigned offset)
 static int sb_gpio_direction_output(struct udevice *dev, unsigned offset,
 				    int value)
 {
+	int ret;
+
 	debug("%s: offset:%u, value = %d\n", __func__, offset, value);
 
-	return sandbox_gpio_set_direction(dev, offset, 1) |
-		sandbox_gpio_set_value(dev, offset, value);
+	ret = sandbox_gpio_set_direction(dev, offset, 1);
+	if (ret)
+		return ret;
+	ret = set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE | GPIOD_EXT_HIGH,
+			    value);
+	if (ret)
+		return ret;
+
+	return 0;
 }
 
 /* read GPIO IN value of port 'offset' */
@@ -158,6 +167,8 @@  static int sb_gpio_get_value(struct udevice *dev, unsigned offset)
 /* write GPIO OUT value to port 'offset' */
 static int sb_gpio_set_value(struct udevice *dev, unsigned offset, int value)
 {
+	int ret;
+
 	debug("%s: offset:%u, value = %d\n", __func__, offset, value);
 
 	if (!sandbox_gpio_get_direction(dev, offset)) {
@@ -166,7 +177,12 @@  static int sb_gpio_set_value(struct udevice *dev, unsigned offset, int value)
 		return -1;
 	}
 
-	return sandbox_gpio_set_value(dev, offset, value);
+	ret = set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE | GPIOD_EXT_HIGH,
+			    value);
+	if (ret)
+		return ret;
+
+	return 0;
 }
 
 static int sb_gpio_get_function(struct udevice *dev, unsigned offset)