/* Our own private GPIO flags, which musn't conflict with GPIOD_... */
#define GPIOD_EXT_HIGH BIT(31) /* external source is high (else low) */
+#define GPIOD_EXT_DRIVEN BIT(30) /* external source is driven */
-#define GPIOD_SANDBOX_MASK BIT(31)
+#define GPIOD_SANDBOX_MASK GENMASK(31, 30)
/**
* Return the simulated value of a GPIO (used only in sandbox test code)
int sandbox_gpio_get_value(struct udevice *dev, unsigned offset)
{
struct gpio_state *state = get_gpio_state(dev, offset);
+ bool val;
if (get_gpio_flag(dev, offset, GPIOD_IS_OUT))
debug("sandbox_gpio: get_value on output gpio %u\n", offset);
- return state->flags & GPIOD_EXT_HIGH ? true : false;
+ if (state->flags & GPIOD_EXT_DRIVEN)
+ val = state->flags & GPIOD_EXT_HIGH;
+ else
+ val = false;
+
+ return val;
}
int sandbox_gpio_set_value(struct udevice *dev, unsigned offset, int value)
{
- set_gpio_flag(dev, offset, GPIOD_EXT_HIGH, value);
+ set_gpio_flag(dev, offset, GPIOD_EXT_DRIVEN | GPIOD_EXT_HIGH, value);
return 0;
}
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);
+ ret = set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE |
+ GPIOD_EXT_DRIVEN | GPIOD_EXT_HIGH, value);
if (ret)
return ret;
return -1;
}
- ret = set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE | GPIOD_EXT_HIGH,
- value);
+ ret = set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE |
+ GPIOD_EXT_DRIVEN | GPIOD_EXT_HIGH, value);
if (ret)
return ret;
struct gpio_state *state = get_gpio_state(dev, offset);
if (flags & GPIOD_IS_OUT) {
+ flags |= GPIOD_EXT_DRIVEN;
if (flags & GPIOD_IS_OUT_ACTIVE)
flags |= GPIOD_EXT_HIGH;
else
flags &= ~GPIOD_EXT_HIGH;
+ } else {
+ flags |= state->flags & GPIOD_SANDBOX_MASK;
}
state->flags = flags;