diff mbox series

[v4,09/16] gpio: sandbox: Make sandbox_gpio_set_flags() set all flags

Message ID 20210205042210.2949365-10-sjg@chromium.org
State Accepted
Commit e87e86f31c54a4e49159dca7fbd6d9694efcd720
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
Allow this function to see all flags, including the internal sandbox ones.
This allows the tests to fully control the behaviour of the driver.

To make this work, move the setting of GPIOD_EXT_HIGH -to where the flags
are updated via driver model, rather than the sandbox 'back door'.

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 | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

Comments

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

> Allow this function to see all flags, including the internal sandbox ones.
> This allows the tests to fully control the behaviour of the driver.
> 
> To make this work, move the setting of GPIOD_EXT_HIGH -to where the flags
> are updated via driver model, rather than the sandbox 'back door'.
> 
> 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 912c333e560..d1e561ab5e6 100644
--- a/drivers/gpio/sandbox.c
+++ b/drivers/gpio/sandbox.c
@@ -114,13 +114,7 @@  int sandbox_gpio_set_flags(struct udevice *dev, uint offset, ulong flags)
 {
 	struct gpio_state *state = get_gpio_state(dev, offset);
 
-	/*
-	 * We don't need to clear GPIOD_EXT_HIGH here to make the tests pass,
-	 * but this is handled in a future patch.
-	 */
-	if (flags & GPIOD_IS_OUT_ACTIVE)
-		flags |= GPIOD_EXT_HIGH;
-	state->flags = (state->flags & GPIOD_SANDBOX_MASK) | flags;
+	state->flags = flags;
 
 	return 0;
 }
@@ -221,14 +215,23 @@  static int sb_gpio_set_flags(struct udevice *dev, unsigned int offset,
 			     ulong flags)
 {
 	debug("%s: offset:%u, flags = %lx\n", __func__, offset, flags);
+	struct gpio_state *state = get_gpio_state(dev, offset);
 
-	return sandbox_gpio_set_flags(dev, offset, flags);
+	if (flags & GPIOD_IS_OUT) {
+		if (flags & GPIOD_IS_OUT_ACTIVE)
+			flags |= GPIOD_EXT_HIGH;
+		else
+			flags &= ~GPIOD_EXT_HIGH;
+	}
+	state->flags = flags;
+
+	return 0;
 }
 
 static int sb_gpio_get_flags(struct udevice *dev, uint offset, ulong *flagsp)
 {
 	debug("%s: offset:%u\n", __func__, offset);
-	*flagsp = *get_gpio_flags(dev, offset);
+	*flagsp = *get_gpio_flags(dev, offset) & ~GPIOD_SANDBOX_MASK;
 
 	return 0;
 }