summaryrefslogtreecommitdiff
path: root/drivers/gpio
diff options
context:
space:
mode:
authorPatrick Delaunay <patrick.delaunay@st.com>2020-01-13 13:35:14 +0300
committerTom Rini <trini@konsulko.com>2020-04-17 06:06:54 +0300
commitff52665d03e220ada14e3e02f8d485b48d8c8eaa (patch)
treee05a05e9d1e7be9808ab49c7f6e7556b690638c8 /drivers/gpio
parent2c0f782e0fc0f0dcc619d81237c3a8718f4e282f (diff)
downloadu-boot-ff52665d03e220ada14e3e02f8d485b48d8c8eaa.tar.xz
test: dm: update test for pins configuration in gpio
Add tests for new API set_dir_flags and set_dir_flags and associated code in gpio uclass. Test support for new flags GPIO_OPEN_DRAIN, GPIO_OPEN_SOURCE GPIO_PULL_UP and GPIO_PULL_DOWN. Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/sandbox.c86
1 files changed, 66 insertions, 20 deletions
diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c
index c2a8adc647..a9c470ee5e 100644
--- a/drivers/gpio/sandbox.c
+++ b/drivers/gpio/sandbox.c
@@ -8,43 +8,43 @@
#include <fdtdec.h>
#include <malloc.h>
#include <asm/gpio.h>
+#include <dm/lists.h>
#include <dm/of.h>
+#include <dm/pinctrl.h>
#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/gpio/sandbox-gpio.h>
-/* Flags for each GPIO */
-#define GPIOF_OUTPUT (1 << 0) /* Currently set as an output */
-#define GPIOF_HIGH (1 << 1) /* Currently set high */
struct gpio_state {
const char *label; /* label given by requester */
- u8 flags; /* flags (GPIOF_...) */
+ ulong dir_flags; /* dir_flags (GPIOD_...) */
};
-/* Access routines for GPIO state */
-static u8 *get_gpio_flags(struct udevice *dev, unsigned offset)
+/* Access routines for GPIO dir flags */
+static ulong *get_gpio_dir_flags(struct udevice *dev, unsigned int offset)
{
struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
struct gpio_state *state = dev_get_priv(dev);
if (offset >= uc_priv->gpio_count) {
- static u8 invalid_flags;
+ static ulong invalid_dir_flags;
printf("sandbox_gpio: error: invalid gpio %u\n", offset);
- return &invalid_flags;
+ return &invalid_dir_flags;
}
- return &state[offset].flags;
+ return &state[offset].dir_flags;
+
}
-static int get_gpio_flag(struct udevice *dev, unsigned offset, int flag)
+static int get_gpio_flag(struct udevice *dev, unsigned int offset, ulong flag)
{
- return (*get_gpio_flags(dev, offset) & flag) != 0;
+ return (*get_gpio_dir_flags(dev, offset) & flag) != 0;
}
-static int set_gpio_flag(struct udevice *dev, unsigned offset, int flag,
+static int set_gpio_flag(struct udevice *dev, unsigned int offset, ulong flag,
int value)
{
- u8 *gpio = get_gpio_flags(dev, offset);
+ ulong *gpio = get_gpio_dir_flags(dev, offset);
if (value)
*gpio |= flag;
@@ -60,24 +60,40 @@ static int set_gpio_flag(struct udevice *dev, unsigned offset, int flag,
int sandbox_gpio_get_value(struct udevice *dev, unsigned offset)
{
- if (get_gpio_flag(dev, offset, GPIOF_OUTPUT))
+ if (get_gpio_flag(dev, offset, GPIOD_IS_OUT))
debug("sandbox_gpio: get_value on output gpio %u\n", offset);
- return get_gpio_flag(dev, offset, GPIOF_HIGH);
+ return get_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE);
}
int sandbox_gpio_set_value(struct udevice *dev, unsigned offset, int value)
{
- return set_gpio_flag(dev, offset, GPIOF_HIGH, value);
+ return set_gpio_flag(dev, offset, GPIOD_IS_OUT_ACTIVE, value);
}
int sandbox_gpio_get_direction(struct udevice *dev, unsigned offset)
{
- return get_gpio_flag(dev, offset, GPIOF_OUTPUT);
+ return get_gpio_flag(dev, offset, GPIOD_IS_OUT);
}
int sandbox_gpio_set_direction(struct udevice *dev, unsigned offset, int output)
{
- return set_gpio_flag(dev, offset, GPIOF_OUTPUT, output);
+ set_gpio_flag(dev, offset, GPIOD_IS_OUT, output);
+ set_gpio_flag(dev, offset, GPIOD_IS_IN, !(output));
+
+ return 0;
+}
+
+ulong sandbox_gpio_get_dir_flags(struct udevice *dev, unsigned int offset)
+{
+ return *get_gpio_dir_flags(dev, offset);
+}
+
+int sandbox_gpio_set_dir_flags(struct udevice *dev, unsigned int offset,
+ ulong flags)
+{
+ *get_gpio_dir_flags(dev, offset) = flags;
+
+ return 0;
}
/*
@@ -126,9 +142,12 @@ static int sb_gpio_set_value(struct udevice *dev, unsigned offset, int value)
static int sb_gpio_get_function(struct udevice *dev, unsigned offset)
{
- if (get_gpio_flag(dev, offset, GPIOF_OUTPUT))
+ if (get_gpio_flag(dev, offset, GPIOD_IS_OUT))
return GPIOF_OUTPUT;
- return GPIOF_INPUT;
+ if (get_gpio_flag(dev, offset, GPIOD_IS_IN))
+ return GPIOF_INPUT;
+
+ return GPIOF_INPUT; /*GPIO is not configurated */
}
static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
@@ -143,14 +162,39 @@ static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
/* sandbox test specific, not defined in gpio.h */
if (args->args[1] & GPIO_IN)
desc->flags |= GPIOD_IS_IN;
+
if (args->args[1] & GPIO_OUT)
desc->flags |= GPIOD_IS_OUT;
+
if (args->args[1] & GPIO_OUT_ACTIVE)
desc->flags |= GPIOD_IS_OUT_ACTIVE;
return 0;
}
+static int sb_gpio_set_dir_flags(struct udevice *dev, unsigned int offset,
+ ulong flags)
+{
+ ulong *dir_flags;
+
+ debug("%s: offset:%u, dir_flags = %lx\n", __func__, offset, flags);
+
+ dir_flags = get_gpio_dir_flags(dev, offset);
+
+ *dir_flags = flags;
+
+ return 0;
+}
+
+static int sb_gpio_get_dir_flags(struct udevice *dev, unsigned int offset,
+ ulong *flags)
+{
+ debug("%s: offset:%u\n", __func__, offset);
+ *flags = *get_gpio_dir_flags(dev, offset);
+
+ return 0;
+}
+
static const struct dm_gpio_ops gpio_sandbox_ops = {
.direction_input = sb_gpio_direction_input,
.direction_output = sb_gpio_direction_output,
@@ -158,6 +202,8 @@ static const struct dm_gpio_ops gpio_sandbox_ops = {
.set_value = sb_gpio_set_value,
.get_function = sb_gpio_get_function,
.xlate = sb_gpio_xlate,
+ .set_dir_flags = sb_gpio_set_dir_flags,
+ .get_dir_flags = sb_gpio_get_dir_flags,
};
static int sandbox_gpio_ofdata_to_platdata(struct udevice *dev)