summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-02-04 21:21:55 -0700
committerTom Rini <trini@konsulko.com>2021-03-03 14:51:06 -0500
commit13979fc44667cbc577f3c4d07b6692de104a3174 (patch)
tree1d4cd85975f13a4160653e2b300e14abbbe42c60
parent4fe406729c87f41b745269c0f509da7d27f0a5c1 (diff)
downloadu-boot-13979fc44667cbc577f3c4d07b6692de104a3174.tar.gz
u-boot-13979fc44667cbc577f3c4d07b6692de104a3174.tar.bz2
u-boot-13979fc44667cbc577f3c4d07b6692de104a3174.zip
dm: gpio: Rename set_dir_flags() method to update_flags()
The current method is a misnomer since it is also used (e.g. by stm32) to update pull settings and open source/open drain. Rename it and expand the documentation to cover a few more details. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Pratyush Yadav <p.yadav@ti.com> Reviewed-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
-rw-r--r--drivers/gpio/gpio-uclass.c16
-rw-r--r--drivers/gpio/sandbox.c6
-rw-r--r--drivers/gpio/stm32_gpio.c6
-rw-r--r--drivers/pinctrl/pinctrl-stmfx.c6
-rw-r--r--include/asm-generic/gpio.h28
-rw-r--r--test/dm/gpio.c8
6 files changed, 43 insertions, 27 deletions
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 1db5ef001e..d42e778ed8 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -620,7 +620,7 @@ static int check_dir_flags(ulong flags)
return 0;
}
-static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
+static int _dm_gpio_set_flags(struct gpio_desc *desc, ulong flags)
{
struct udevice *dev = desc->dev;
struct dm_gpio_ops *ops = gpio_get_ops(dev);
@@ -638,9 +638,9 @@ static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
return ret;
}
- /* GPIOD_ are directly managed by driver in set_dir_flags*/
- if (ops->set_dir_flags) {
- ret = ops->set_dir_flags(dev, desc->offset, flags);
+ /* GPIOD_ are directly managed by driver in set_flags */
+ if (ops->set_flags) {
+ ret = ops->set_flags(dev, desc->offset, flags);
} else {
if (flags & GPIOD_IS_OUT) {
ret = ops->direction_output(dev, desc->offset,
@@ -667,7 +667,7 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)
/* combine the requested flags (for IN/OUT) and the descriptor flags */
flags |= desc->flags;
- ret = _dm_gpio_set_dir_flags(desc, flags);
+ ret = _dm_gpio_set_flags(desc, flags);
return ret;
}
@@ -680,7 +680,7 @@ int dm_gpio_set_dir(struct gpio_desc *desc)
if (ret)
return ret;
- return _dm_gpio_set_dir_flags(desc, desc->flags);
+ return _dm_gpio_set_flags(desc, desc->flags);
}
int dm_gpio_get_dir_flags(struct gpio_desc *desc, ulong *flags)
@@ -1308,8 +1308,8 @@ static int gpio_post_bind(struct udevice *dev)
ops->get_function += gd->reloc_off;
if (ops->xlate)
ops->xlate += gd->reloc_off;
- if (ops->set_dir_flags)
- ops->set_dir_flags += gd->reloc_off;
+ if (ops->set_flags)
+ ops->set_flags += gd->reloc_off;
if (ops->get_dir_flags)
ops->get_dir_flags += gd->reloc_off;
diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c
index dc8d506e8d..05f17928f0 100644
--- a/drivers/gpio/sandbox.c
+++ b/drivers/gpio/sandbox.c
@@ -177,8 +177,8 @@ static int sb_gpio_xlate(struct udevice *dev, struct gpio_desc *desc,
return 0;
}
-static int sb_gpio_set_dir_flags(struct udevice *dev, unsigned int offset,
- ulong flags)
+static int sb_gpio_set_flags(struct udevice *dev, unsigned int offset,
+ ulong flags)
{
ulong *dir_flags;
@@ -272,7 +272,7 @@ 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,
+ .set_flags = sb_gpio_set_flags,
.get_dir_flags = sb_gpio_get_dir_flags,
#if CONFIG_IS_ENABLED(ACPIGEN)
.get_acpi = sb_gpio_get_acpi,
diff --git a/drivers/gpio/stm32_gpio.c b/drivers/gpio/stm32_gpio.c
index 7184db3c52..6d1bef63c3 100644
--- a/drivers/gpio/stm32_gpio.c
+++ b/drivers/gpio/stm32_gpio.c
@@ -191,8 +191,8 @@ static int stm32_gpio_get_function(struct udevice *dev, unsigned int offset)
return GPIOF_FUNC;
}
-static int stm32_gpio_set_dir_flags(struct udevice *dev, unsigned int offset,
- ulong flags)
+static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset,
+ ulong flags)
{
struct stm32_gpio_priv *priv = dev_get_priv(dev);
struct stm32_gpio_regs *regs = priv->regs;
@@ -270,7 +270,7 @@ static const struct dm_gpio_ops gpio_stm32_ops = {
.get_value = stm32_gpio_get_value,
.set_value = stm32_gpio_set_value,
.get_function = stm32_gpio_get_function,
- .set_dir_flags = stm32_gpio_set_dir_flags,
+ .set_flags = stm32_gpio_set_flags,
.get_dir_flags = stm32_gpio_get_dir_flags,
};
diff --git a/drivers/pinctrl/pinctrl-stmfx.c b/drivers/pinctrl/pinctrl-stmfx.c
index 1a8d0a3a35..6147e867dc 100644
--- a/drivers/pinctrl/pinctrl-stmfx.c
+++ b/drivers/pinctrl/pinctrl-stmfx.c
@@ -163,8 +163,8 @@ static int stmfx_gpio_direction_output(struct udevice *dev,
return stmfx_write_reg(dev, STMFX_REG_GPIO_DIR, offset, 1);
}
-static int stmfx_gpio_set_dir_flags(struct udevice *dev, unsigned int offset,
- ulong flags)
+static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset,
+ ulong flags)
{
int ret = -ENOTSUPP;
@@ -266,7 +266,7 @@ static const struct dm_gpio_ops stmfx_gpio_ops = {
.get_function = stmfx_gpio_get_function,
.direction_input = stmfx_gpio_direction_input,
.direction_output = stmfx_gpio_direction_output,
- .set_dir_flags = stmfx_gpio_set_dir_flags,
+ .set_flags = stmfx_gpio_set_flags,
.get_dir_flags = stmfx_gpio_get_dir_flags,
};
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 82294cbdc5..de16cabcbf 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -301,20 +301,36 @@ struct dm_gpio_ops {
struct ofnode_phandle_args *args);
/**
- * set_dir_flags() - Set GPIO dir flags
+ * set_flags() - Adjust GPIO flags
*
* This function should set up the GPIO configuration according to the
- * information provide by the direction flags bitfield.
+ * information provided by @flags.
+ *
+ * If any flags cannot be set (e.g. the driver or hardware does not
+ * support them or this particular GPIO does not have the requested
+ * feature), the driver should return -EINVAL.
+ *
+ * The uclass checks that flags do not obviously conflict (e.g. input
+ * and output). If the driver finds other conflicts it should return
+ * -ERECALLCONFLICT
+ *
+ * Note that GPIOD_ACTIVE_LOW should be ignored, since the uclass
+ * adjusts for it automatically. For example, for an output GPIO,
+ * GPIOD_ACTIVE_LOW causes GPIOD_IS_OUT_ACTIVE to be inverted by the
+ * uclass, so the driver always sees the value that should be set at the
+ * pin (1=high, 0=low).
*
* This method is optional.
*
* @dev: GPIO device
* @offset: GPIO offset within that device
- * @flags: GPIO configuration to use
- * @return 0 if OK, -ve on error
+ * @flags: New flags value (GPIOD_...)
+ *
+ * @return 0 if OK, -EINVAL if unsupported, -ERECALLCONFLICT if flags
+ * conflict in some * non-obvious way and were not applied,
+ * other -ve on error
*/
- int (*set_dir_flags)(struct udevice *dev, unsigned int offset,
- ulong flags);
+ int (*set_flags)(struct udevice *dev, unsigned int offset, ulong flags);
/**
* get_dir_flags() - Get GPIO dir flags
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index d7b85e74ce..36bbaedb01 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -81,12 +81,12 @@ static int dm_test_gpio(struct unit_test_state *uts)
/* Make it an open drain output, and reset it */
ut_asserteq(GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE,
sandbox_gpio_get_dir_flags(dev, offset));
- ut_assertok(ops->set_dir_flags(dev, offset,
- GPIOD_IS_OUT | GPIOD_OPEN_DRAIN));
+ ut_assertok(ops->set_flags(dev, offset,
+ GPIOD_IS_OUT | GPIOD_OPEN_DRAIN));
ut_asserteq(GPIOD_IS_OUT | GPIOD_OPEN_DRAIN,
sandbox_gpio_get_dir_flags(dev, offset));
- ut_assertok(ops->set_dir_flags(dev, offset,
- GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE));
+ ut_assertok(ops->set_flags(dev, offset,
+ GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE));
ut_asserteq(GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE,
sandbox_gpio_get_dir_flags(dev, offset));