gpio: Update and simplify the uclass API
Subsystems (5)
v2 cover gpio: Update and simplify the uclass API
At present the GPIO uclass mirrors what was in U-Boot before driver model. It works well in most cases but is becoming cumbersome with things like pull-up/down and drive strength. In those cases it is easier for the driver to deal with all the flags at one, rather than piece by piece.
In fact the current API does not officially have a method for adjusting anything other than the direction flags. While set_dir_flags() and get_dir_flags() do in fact support changing other flags, this is not documented.
Secondly, set_dir_flags actually ORs the current flags with the new ones so it is not possible to clear flags. It seems better to use a clr/set interface (bit clear followed by OR) to provide more flexibility.
Finally, direction_input() and direction_output() are really just the same thing as set_dir_flags(), with a different name. We currently use the latter if available, failing back to the former. But it makes sense to deprecate the old methods.
This series makes the above changes. Existing drivers are mostly left alone, since they should continue to operate as is. The sandbox driver is updated to add the required new tests and the x86 driver is switched over to the new API.
The STM32 driver should be checked to make sure the open source/open drain features still work as intended.
Changes in v2:
- Use set_flags() instead of update_flags()
- Fix 'provide' typo while we are here
- Make operation of set_flags() deterministic
- Swap newf and flags in sb_gpio_set_flags()
Simon Glass (15):
gpio: Disable functions not used with of-platdata
dm: gpio: Rename set_dir_flags() method to update_flags()
dm: gpio: Rename get_dir_flags() method to get_flags()
gpio: Rename dm_gpio_get_dir_flags() to dm_gpio_get_flags()
gpio: Drop dm_gpio_set_dir()
gpio: sandbox: Rename GPIO dir_flags to flags
gpio: sandbox: Use a separate flag for the value
gpio: sandbox: Fully separate pin value from output value
gpio: sandbox: Make sandbox_gpio_set_flags() set all flags
dm: gpio: Add a way to update flags
gpio: Replace direction_input() and direction_output()
gpio: Use an 'ops' variable everywhere
gpio: x86: Drop the deprecated methods in intel_gpio
gpio: sandbox: Track whether a GPIO is driven
gpio: Add a way to read 3-way strapping pins
arch/sandbox/include/asm/gpio.h | 17 +- arch/x86/include/asm/intel_pinctrl_defs.h | 5 + drivers/gpio/gpio-uclass.c | 228 ++++++++++++++----- drivers/gpio/intel_gpio.c | 72 +++--- drivers/gpio/sandbox.c | 138 ++++++++---- drivers/gpio/stm32_gpio.c | 14 +- drivers/pinctrl/pinctrl-stmfx.c | 14 +- include/asm-generic/gpio.h | 130 +++++++++-- test/dm/gpio.c | 261 +++++++++++++++++++--- 9 files changed, 663 insertions(+), 216 deletions(-)
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 1/15 gpio: Disable functions not used with of-platdata
These functions use devicetree and cannot wprl with of-platdata, which has no runtime devicetree.
If they are used, the current linker error is confusing, since it talks about missing functions in the bowels of driver model.
Avoid compiling these functions at all with of-platdata, so that a straightforward link error points to the problem.
---
(no changes since v1)
drivers/gpio/gpio-uclass.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpio/gpio-uclass.c +2 -0
@@ -1023,6 +1023,7 @@ err:return ret; } +#if !CONFIG_IS_ENABLED (OF_PLATDATA )static int _gpio_request_by_name_nodev (ofnode node,const char *list_name,int index,struct gpio_desc *desc,int flags,bool add_index)
@@ -1109,6 +1110,7 @@ int gpio_get_list_count(struct udevice *dev, const char *list_name) return ret; } +#endif /* OF_PLATDATA */ int dm_gpio_free (struct udevice *dev,struct gpio_desc *desc) {
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 2/15 dm: gpio: Rename set_dir_flags() method to update_flags()
In reply to Simon GlassThe 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.
---
Changes in v2:
- Use set_flags() instead of update_flags()
- Fix 'provide' typo while we are here
- Make operation of set_flags() deterministic
drivers/gpio/gpio-uclass.c | 16 ++++++++-------- drivers/gpio/sandbox.c | 6 +++--- drivers/gpio/stm32_gpio.c | 6 +++--- drivers/pinctrl/pinctrl-stmfx.c | 6 +++--- include/asm-generic/gpio.h | 28 ++++++++++++++++++++++------ test/dm/gpio.c | 8 ++++---- 6 files changed, 43 insertions(+), 27 deletions(-)
drivers/gpio/gpio-uclass.c +8 -8
@@ -619,7 +619,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);
@@ -637,9 +637,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,
@@ -666,7 +666,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; }
@@ -679,7 +679,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)
@@ -1307,8 +1307,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;
drivers/gpio/sandbox.c +3 -3
@@ -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,
drivers/gpio/stm32_gpio.c +3 -3
@@ -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, };
drivers/pinctrl/pinctrl-stmfx.c +3 -3
@@ -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, };
include/asm-generic/gpio.h +22 -6
@@ -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
test/dm/gpio.c +4 -4
@@ -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));
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 3/15 dm: gpio: Rename get_dir_flags() method to get_flags()
In reply to Simon GlassIt is more useful to be able to read all the flags, not just the direction ones. In fact this is what the STM32 driver does. Update the method name to reflect this.
Tweak the docs a little and use 'flagsp' as the return argument, as is common in driver model, to indicate it returns a value.
---
(no changes since v1)
drivers/gpio/gpio-uclass.c | 30 +++++++++++++++--------------- drivers/gpio/sandbox.c | 8 ++++---- drivers/gpio/stm32_gpio.c | 8 ++++---- drivers/pinctrl/pinctrl-stmfx.c | 8 ++++---- include/asm-generic/gpio.h | 11 ++++++----- 5 files changed, 33 insertions(+), 32 deletions(-)
drivers/gpio/gpio-uclass.c +15 -15
@@ -682,39 +682,39 @@ int dm_gpio_set_dir(struct gpio_desc *desc)return _dm_gpio_set_flags (desc, desc->flags); } -int dm_gpio_get_dir_flags (struct gpio_desc *desc,ulong *flags) +int dm_gpio_get_dir_flags (struct gpio_desc *desc,ulong *flagsp) {struct udevice *dev = desc->dev;int ret, value;struct dm_gpio_ops *ops =gpio_get_ops (dev); -ulong dir_flags; +ulong flags; - ret =check_reserved (desc,"get_dir_flags" ); + ret =check_reserved (desc,"get_flags" );if (ret)return ret;/* GPIOD_ are directly provided by driver except GPIOD_ACTIVE_LOW */ -if (ops->get_dir_flags) { - ret = ops->get_dir_flags (dev, desc->offset, &dir_flags); +if (ops->get_flags) { + ret = ops->get_flags (dev, desc->offset, &flags);if (ret)return ret;/* GPIOD_ACTIVE_LOW is saved in desc->flags */ - value = dir_flags &GPIOD_IS_OUT_ACTIVE ?1 :0 ; + value = flags &GPIOD_IS_OUT_ACTIVE ?1 :0 ;if (desc->flags &GPIOD_ACTIVE_LOW ) value = !value; - dir_flags &= ~(GPIOD_ACTIVE_LOW |GPIOD_IS_OUT_ACTIVE ); - dir_flags |= (desc->flags &GPIOD_ACTIVE_LOW ); + flags &= ~(GPIOD_ACTIVE_LOW |GPIOD_IS_OUT_ACTIVE ); + flags |= (desc->flags &GPIOD_ACTIVE_LOW );if (value) - dir_flags |=GPIOD_IS_OUT_ACTIVE ; + flags |=GPIOD_IS_OUT_ACTIVE ; }else { - dir_flags = desc->flags; + flags = desc->flags;/* only GPIOD_IS_OUT_ACTIVE is provided by uclass */ - dir_flags &= ~GPIOD_IS_OUT_ACTIVE ; + flags &= ~GPIOD_IS_OUT_ACTIVE ;if ((desc->flags &GPIOD_IS_OUT ) &&_gpio_get_value (desc)) - dir_flags |=GPIOD_IS_OUT_ACTIVE ; + flags |=GPIOD_IS_OUT_ACTIVE ; } - *flags = dir_flags; + *flagsp = flags;return 0 ; }
@@ -1309,8 +1309,8 @@ static int gpio_post_bind(struct udevice *dev) ops->xlate += 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; +if (ops->get_flags) + ops->get_flags += gd->reloc_off; reloc_done++; }
drivers/gpio/sandbox.c +4 -4
@@ -199,11 +199,11 @@ static int sb_gpio_set_flags(struct udevice *dev, unsigned int offset,return 0 ; } -static int sb_gpio_get_dir_flags (struct udevice *dev,unsigned int offset, -ulong *flags) +static int sb_gpio_get_flags (struct udevice *dev,unsigned int offset, +ulong *flagsp) {debug ("%s: offset:%u\n" , __func__, offset); - *flags = *get_gpio_dir_flags (dev, offset); + *flagsp = *get_gpio_dir_flags (dev, offset);return 0 ; }
@@ -273,7 +273,7 @@ static const struct dm_gpio_ops gpio_sandbox_ops = { .get_function = sb_gpio_get_function, .xlate = sb_gpio_xlate, .set_flags = sb_gpio_set_flags, - .get_dir_flags = sb_gpio_get_dir_flags, + .get_flags = sb_gpio_get_flags,#if CONFIG_IS_ENABLED (ACPIGEN ) .get_acpi = sb_gpio_get_acpi,#endif
drivers/gpio/stm32_gpio.c +4 -4
@@ -223,8 +223,8 @@ static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset,return 0 ; } -static int stm32_gpio_get_dir_flags (struct udevice *dev,unsigned int offset, -ulong *flags) +static int stm32_gpio_get_flags (struct udevice *dev,unsigned int offset, +ulong *flagsp) {struct stm32_gpio_priv *priv =dev_get_priv (dev);struct stm32_gpio_regs *regs = priv->regs;
@@ -259,7 +259,7 @@ static int stm32_gpio_get_dir_flags(struct udevice *dev, unsigned int offset,default :break ; } - *flags = dir_flags; + *flagsp = dir_flags;return 0 ; }
@@ -271,7 +271,7 @@ static const struct dm_gpio_ops gpio_stm32_ops = { .set_value = stm32_gpio_set_value, .get_function = stm32_gpio_get_function, .set_flags = stm32_gpio_set_flags, - .get_dir_flags = stm32_gpio_get_dir_flags, + .get_flags = stm32_gpio_get_flags, };static int gpio_stm32_probe (struct udevice *dev)
drivers/pinctrl/pinctrl-stmfx.c +4 -4
@@ -199,8 +199,8 @@ static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset,return ret; } -static int stmfx_gpio_get_dir_flags (struct udevice *dev,unsigned int offset, -ulong *flags) +static int stmfx_gpio_get_flags (struct udevice *dev,unsigned int offset, +ulong *flagsp) {ulong dir_flags =0 ;int ret;
@@ -233,7 +233,7 @@ static int stmfx_gpio_get_dir_flags(struct udevice *dev, unsigned int offset, dir_flags |=GPIOD_PULL_DOWN ; } } - *flags = dir_flags; + *flagsp = dir_flags;return 0 ; }
@@ -267,7 +267,7 @@ static const struct dm_gpio_ops stmfx_gpio_ops = { .direction_input = stmfx_gpio_direction_input, .direction_output = stmfx_gpio_direction_output, .set_flags = stmfx_gpio_set_flags, - .get_dir_flags = stmfx_gpio_get_dir_flags, + .get_flags = stmfx_gpio_get_flags, };U_BOOT_DRIVER (stmfx_gpio) = {
include/asm-generic/gpio.h +6 -5
@@ -333,19 +333,20 @@ struct dm_gpio_ops {int (*set_flags)(struct udevice *dev,unsigned int offset,ulong flags);/** -* get_dir_flags() - Get GPIO dir flags +* get_flags() - Get GPIO flags * -* This function return the GPIO direction flags used. +* This function return the GPIO flags used. It should read this from +* the hardware directly. * * This method is optional. * * @dev: GPIO device * @offset: GPIO offset within that device -* @flags: place to put the used direction flags by GPIO +* @flagsp: place to put the current flags value * @return 0 if OK, -ve on error */ -int (*get_dir_flags)(struct udevice *dev,unsigned int offset, -ulong *flags); +int (*get_flags)(struct udevice *dev,unsigned int offset, +ulong *flagsp);#if CONFIG_IS_ENABLED (ACPIGEN )/**
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 4/15 gpio: Rename dm_gpio_get_dir_flags() to dm_gpio_get_flags()
In reply to Simon GlassThis function can be used to get any flags, not just direction flags. Rename it to avoid confusion.
---
(no changes since v1)
drivers/gpio/gpio-uclass.c | 2 +- include/asm-generic/gpio.h | 6 +++--- test/dm/gpio.c | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-)
drivers/gpio/gpio-uclass.c +1 -1
@@ -682,7 +682,7 @@ int dm_gpio_set_dir(struct gpio_desc *desc)return _dm_gpio_set_flags (desc, desc->flags); } -int dm_gpio_get_dir_flags (struct gpio_desc *desc,ulong *flagsp) +int dm_gpio_get_flags (struct gpio_desc *desc,ulong *flagsp) {struct udevice *dev = desc->dev;int ret, value;
include/asm-generic/gpio.h +3 -3
@@ -683,16 +683,16 @@ int dm_gpio_set_dir(struct gpio_desc *desc);int dm_gpio_set_dir_flags (struct gpio_desc *desc,ulong flags);/** -* dm_gpio_get_dir_flags() - Get direction flags +* dm_gpio_get_flags() - Get flags * -* read the current direction flags +* Read the current flags * * @desc: GPIO description containing device, offset and flags, * previously returned by gpio_request_by_name() * @flags: place to put the used flags * @return 0 if OK, -ve on error, in which case desc->flags is not updated */ -int dm_gpio_get_dir_flags (struct gpio_desc *desc,ulong *flags); +int dm_gpio_get_flags (struct gpio_desc *desc,ulong *flags);/** * gpio_get_number() - Get the global GPIO number of a GPIO
test/dm/gpio.c +6 -6
@@ -397,22 +397,22 @@ static int dm_test_gpio_get_dir_flags(struct unit_test_state *uts)ut_asserteq (6 ,gpio_request_list_by_name (dev,"test3-gpios" , desc_list,ARRAY_SIZE (desc_list),0 )); -ut_assertok (dm_gpio_get_dir_flags (&desc_list[0 ], &flags)); +ut_assertok (dm_gpio_get_flags (&desc_list[0 ], &flags));ut_asserteq (GPIOD_IS_OUT |GPIOD_OPEN_DRAIN , flags); -ut_assertok (dm_gpio_get_dir_flags (&desc_list[1 ], &flags)); +ut_assertok (dm_gpio_get_flags (&desc_list[1 ], &flags));ut_asserteq (GPIOD_IS_OUT |GPIOD_OPEN_SOURCE , flags); -ut_assertok (dm_gpio_get_dir_flags (&desc_list[2 ], &flags)); +ut_assertok (dm_gpio_get_flags (&desc_list[2 ], &flags));ut_asserteq (GPIOD_IS_OUT , flags); -ut_assertok (dm_gpio_get_dir_flags (&desc_list[3 ], &flags)); +ut_assertok (dm_gpio_get_flags (&desc_list[3 ], &flags));ut_asserteq (GPIOD_IS_IN |GPIOD_PULL_UP , flags); -ut_assertok (dm_gpio_get_dir_flags (&desc_list[4 ], &flags)); +ut_assertok (dm_gpio_get_flags (&desc_list[4 ], &flags));ut_asserteq (GPIOD_IS_IN |GPIOD_PULL_DOWN , flags); -ut_assertok (dm_gpio_get_dir_flags (&desc_list[5 ], &flags)); +ut_assertok (dm_gpio_get_flags (&desc_list[5 ], &flags));ut_asserteq (GPIOD_IS_IN , flags);ut_assertok (gpio_free_list (dev, desc_list,6 ));
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 5/15 gpio: Drop dm_gpio_set_dir()
In reply to Simon GlassThis function is not used. Drop it.
---
(no changes since v1)
drivers/gpio/gpio-uclass.c | 11 ----------- include/asm-generic/gpio.h | 11 ----------- 2 files changed, 22 deletions(-)
drivers/gpio/gpio-uclass.c +0 -11
@@ -671,17 +671,6 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)return ret; } -int dm_gpio_set_dir (struct gpio_desc *desc) -{ -int ret; - - ret =check_reserved (desc,"set_dir" ); -if (ret) -return ret; - -return _dm_gpio_set_flags (desc, desc->flags); -} -int dm_gpio_get_flags (struct gpio_desc *desc,ulong *flagsp) {struct udevice *dev = desc->dev;
include/asm-generic/gpio.h +0 -11
@@ -657,17 +657,6 @@ int dm_gpio_get_value(const struct gpio_desc *desc);int dm_gpio_set_value (const struct gpio_desc *desc,int value); -/** -* dm_gpio_set_dir() - Set the direction for a GPIO -* -* This sets up the direction according to the GPIO flags: desc->flags. -* -* @desc: GPIO description containing device, offset and flags, -* previously returned by gpio_request_by_name() -* @return 0 if OK, -ve on error -*/ -int dm_gpio_set_dir (struct gpio_desc *desc); -/** * dm_gpio_set_dir_flags() - Set direction using description and added flags *
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 6/15 gpio: sandbox: Rename GPIO dir_flags to flags
In reply to Simon GlassAdjust the terminology in this driver to reflect that fact that all flags are handled, not just direction flags.
Create a new access function to get the full GPIO state, not just the direction flags. Drop the static invalid_dir_flags since we can rely on a segfault if something is wrong.
---
Changes in v2:
- Swap newf and flags in sb_gpio_set_flags()
arch/sandbox/include/asm/gpio.h | 8 ++--- drivers/gpio/sandbox.c | 60 +++++++++++++++++++-------------- test/dm/gpio.c | 18 +++++----- 3 files changed, 47 insertions(+), 39 deletions(-)
arch/sandbox/include/asm/gpio.h +4 -4
@@ -69,17 +69,17 @@ int sandbox_gpio_set_direction(struct udevice *dev, unsigned int offset,* @param offset GPIO offset within bank * @return dir_flags: bitfield accesses by GPIOD_ defines */ -ulong sandbox_gpio_get_dir_flags (struct udevice *dev,unsigned int offset); +ulong sandbox_gpio_get_flags (struct udevice *dev,unsigned int offset);/** * Set the simulated flags of a GPIO (used only in sandbox test code) * * @param dev device to use * @param offset GPIO offset within bank -* @param flags dir_flags: bitfield accesses by GPIOD_ defines +* @param flags bitfield accesses by GPIOD_ defines * @return -1 on error, 0 if ok */ -int sandbox_gpio_set_dir_flags (struct udevice *dev,unsigned int offset, -ulong flags); +int sandbox_gpio_set_flags (struct udevice *dev,unsigned int offset, +ulong flags);#endif
drivers/gpio/sandbox.c +34 -26
138 lines not on this page · raw message
test/dm/gpio.c +9 -9
@@ -80,15 +80,15 @@ 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)); +sandbox_gpio_get_flags (dev, offset));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)); +sandbox_gpio_get_flags (dev, offset));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)); +sandbox_gpio_get_flags (dev, offset));/* Make it an input */ ut_assertok (ops->direction_input (dev, offset));
@@ -176,7 +176,7 @@ static int dm_test_gpio_opendrain_opensource(struct unit_test_state *uts)/* GPIO 0 is (GPIO_OUT|GPIO_OPEN_DRAIN) */ ut_asserteq (GPIOD_IS_OUT |GPIOD_OPEN_DRAIN , -sandbox_gpio_get_dir_flags (gpio_c,0 )); +sandbox_gpio_get_flags (gpio_c,0 ));/* Set it as output high, should become an input */ ut_assertok (dm_gpio_set_value (&desc_list[0 ],1 ));
@@ -190,7 +190,7 @@ static int dm_test_gpio_opendrain_opensource(struct unit_test_state *uts)/* GPIO 1 is (GPIO_OUT|GPIO_OPEN_SOURCE) */ ut_asserteq (GPIOD_IS_OUT |GPIOD_OPEN_SOURCE , -sandbox_gpio_get_dir_flags (gpio_c,1 )); +sandbox_gpio_get_flags (gpio_c,1 ));/* Set it as output high, should become output high */ ut_assertok (dm_gpio_set_value (&desc_list[1 ],1 ));
@@ -204,7 +204,7 @@ static int dm_test_gpio_opendrain_opensource(struct unit_test_state *uts)/* GPIO 6 is (GPIO_ACTIVE_LOW|GPIO_OUT|GPIO_OPEN_DRAIN) */ ut_asserteq (GPIOD_ACTIVE_LOW |GPIOD_IS_OUT |GPIOD_OPEN_DRAIN , -sandbox_gpio_get_dir_flags (gpio_c,6 )); +sandbox_gpio_get_flags (gpio_c,6 ));/* Set it as output high, should become output low */ ut_assertok (dm_gpio_set_value (&desc_list[6 ],1 ));
@@ -218,7 +218,7 @@ static int dm_test_gpio_opendrain_opensource(struct unit_test_state *uts)/* GPIO 7 is (GPIO_ACTIVE_LOW|GPIO_OUT|GPIO_OPEN_SOURCE) */ ut_asserteq (GPIOD_ACTIVE_LOW |GPIOD_IS_OUT |GPIOD_OPEN_SOURCE , -sandbox_gpio_get_dir_flags (gpio_c,7 )); +sandbox_gpio_get_flags (gpio_c,7 ));/* Set it as output high, should become an input */ ut_assertok (dm_gpio_set_value (&desc_list[7 ],1 ));
@@ -363,12 +363,12 @@ static int dm_test_gpio_phandles(struct unit_test_state *uts)ut_assertok (gpio_free_list (dev, desc_list,3 ));ut_asserteq (GPIOD_IS_OUT |GPIOD_IS_OUT_ACTIVE , -sandbox_gpio_get_dir_flags (gpio_a,1 )); +sandbox_gpio_get_flags (gpio_a,1 ));ut_asserteq (6 ,gpio_request_list_by_name (dev,"test2-gpios" , desc_list,ARRAY_SIZE (desc_list),0 ));/* This was set to output previously but flags resetted to 0 = INPUT */ -ut_asserteq (0 ,sandbox_gpio_get_dir_flags (gpio_a,1 )); +ut_asserteq (0 ,sandbox_gpio_get_flags (gpio_a,1 ));ut_asserteq (GPIOF_INPUT ,gpio_get_function (gpio_a,1 ,NULL ));/* Active low should invert the input value */
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 7/15 gpio: sandbox: Use a separate flag for the value
In reply to Simon GlassAt present with the sandbox GPIO driver it is not possible to change the value of GPIOD_IS_OUT_ACTIVE unless the GPIO is an output. This makes it hard to test changing the flags since we need to be aware of the internal workings of the driver.
The feature is designed to aid testing.
Split this feature out into a separate sandbox-specific flag, so that the flags can change unimpeded. This will make it easier to allow updating the flags in a future patch.
---
(no changes since v1)
arch/sandbox/include/asm/gpio.h | 5 ++++ drivers/gpio/sandbox.c | 43 +++++++++++++++------------------ 2 files changed, 25 insertions(+), 23 deletions(-)
arch/sandbox/include/asm/gpio.h +5 -0
@@ -23,6 +23,11 @@*/ #include <asm-generic/gpio.h> +/* Our own private GPIO flags, which musn't conflict with GPIOD_... */ +#define GPIOD_EXT_HIGH BIT(20)/* external source is high (else low) */ + +#define GPIOD_SANDBOX_MASK BIT(20) +/** * Return the simulated value of a GPIO (used only in sandbox test code) *
drivers/gpio/sandbox.c +20 -23
88 lines not on this page · raw message
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 8/15 gpio: sandbox: Fully separate pin value from output value
In reply to Simon GlassAt 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.
---
(no changes since v1)
drivers/gpio/sandbox.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
drivers/gpio/sandbox.c +20 -4
@@ -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 ; }
@@ -137,10 +137,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' */
@@ -154,6 +163,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)) {
@@ -162,7 +173,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)
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 9/15 gpio: sandbox: Make sandbox_gpio_set_flags() set all flags
In reply to Simon GlassAllow 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'.
---
(no changes since v1)
drivers/gpio/sandbox.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
drivers/gpio/sandbox.c +12 -5
@@ -114,9 +114,7 @@ int sandbox_gpio_set_flags(struct udevice *dev, uint offset, ulong flags) {struct gpio_state *state =get_gpio_state (dev, offset); -if (flags &GPIOD_IS_OUT_ACTIVE ) - flags |=GPIOD_EXT_HIGH ; - state->flags = (state->flags &GPIOD_SANDBOX_MASK ) | flags; + state->flags = flags;return 0 ; }
@@ -217,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); + +if (flags &GPIOD_IS_OUT ) { +if (flags &GPIOD_IS_OUT_ACTIVE ) + flags |=GPIOD_EXT_HIGH ; +else + flags &= ~GPIOD_EXT_HIGH ; + } + state->flags = flags; -return sandbox_gpio_set_flags (dev, offset, 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 ; }
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 10/15 dm: gpio: Add a way to update flags
In reply to Simon GlassIt is convenient to be able to adjust some of the flags for a GPIO while leaving others alone. Add a function for this.
Update dm_gpio_set_dir_flags() to make use of this.
Also update dm_gpio_set_value() to use this also, since this allows the open-drain / open-source features to be implemented directly in the driver, rather than using the uclass workaround.
Update the sandbox tests accordingly. This involves a lot of changes to dm_test_gpio_opendrain_opensource() since we no-longer have the direciion being reported differently depending on the open drain/open source flags.
---
(no changes since v1)
drivers/gpio/gpio-uclass.c | 65 ++++++++++++++----- include/asm-generic/gpio.h | 25 ++++++++ test/dm/gpio.c | 125 ++++++++++++++++++++++++++++++++----- 3 files changed, 184 insertions(+), 31 deletions(-)
drivers/gpio/gpio-uclass.c +51 -14
@@ -568,6 +568,7 @@ int dm_gpio_get_value(const struct gpio_desc *desc)int dm_gpio_set_value (const struct gpio_desc *desc,int value) { +const struct dm_gpio_ops *ops;int ret; ret =check_reserved (desc,"set_value" );
@@ -577,21 +578,33 @@ int dm_gpio_set_value(const struct gpio_desc *desc, int value)if (desc->flags &GPIOD_ACTIVE_LOW ) value = !value; +/* GPIOD_ are directly managed by driver in set_flags */ + ops =gpio_get_ops (desc->dev); +if (ops->set_flags) { +ulong flags = desc->flags; + +if (value) + flags |=GPIOD_IS_OUT_ACTIVE ; +else + flags &= ~GPIOD_IS_OUT_ACTIVE ; +return ops->set_flags (desc->dev, desc->offset, flags); + } +/* * Emulate open drain by not actively driving the line high or * Emulate open source by not actively driving the line low */ if ((desc->flags &GPIOD_OPEN_DRAIN && value) || (desc->flags &GPIOD_OPEN_SOURCE && !value)) -return gpio_get_ops (desc->dev)->direction_input (desc->dev, - desc->offset); +return ops->direction_input (desc->dev, desc->offset);else if (desc->flags &GPIOD_OPEN_DRAIN || desc->flags &GPIOD_OPEN_SOURCE ) -return gpio_get_ops (desc->dev)->direction_output (desc->dev, - desc->offset, - value); +return ops->direction_output (desc->dev, desc->offset, value); + + ret = ops->set_value (desc->dev, desc->offset, value); +if (ret) +return ret; -gpio_get_ops (desc->dev)->set_value (desc->dev, desc->offset, value);return 0 ; }
@@ -619,6 +632,17 @@ static int check_dir_flags(ulong flags)return 0 ; } +/** +* _dm_gpio_set_flags() - Send flags to the driver +* +* This uses the best available method to send the given flags to the driver. +* Note that if flags & GPIOD_ACTIVE_LOW, the driver sees the opposite value +* of GPIOD_IS_OUT_ACTIVE. +* +* @desc: GPIO description +* @flags: flags value to set +* @return 0 if OK, -ve on error +*/ static int _dm_gpio_set_flags (struct gpio_desc *desc,ulong flags) {struct udevice *dev = desc->dev;
@@ -637,6 +661,11 @@ static int _dm_gpio_set_flags(struct gpio_desc *desc, ulong flags)return ret; } +/* If active low, invert the output state */ +if ((flags & (GPIOD_IS_OUT |GPIOD_ACTIVE_LOW )) == + (GPIOD_IS_OUT |GPIOD_ACTIVE_LOW )) + flags ^=GPIOD_IS_OUT_ACTIVE ; +/* GPIOD_ are directly managed by driver in set_flags */ if (ops->set_flags) { ret = ops->set_flags (dev, desc->offset, flags);
@@ -649,26 +678,34 @@ static int _dm_gpio_set_flags(struct gpio_desc *desc, ulong flags) } } -/* save the flags also in descriptor */ -if (!ret) - desc->flags = flags; -return ret; } -int dm_gpio_set_dir_flags (struct gpio_desc *desc,ulong flags) +int dm_gpio_clrset_flags (struct gpio_desc *desc,ulong clr,ulong set) { +ulong flags;int ret; ret =check_reserved (desc,"set_dir_flags" );if (ret)return ret; -/* combine the requested flags (for IN/OUT) and the descriptor flags */ - flags |= desc->flags; + flags = (desc->flags & ~clr) | set; + ret =_dm_gpio_set_flags (desc, flags); +if (ret) +return ret; -return ret; +/* save the flags also in descriptor */ + desc->flags = flags; + +return 0 ; +} + +int dm_gpio_set_dir_flags (struct gpio_desc *desc,ulong flags) +{ +/* combine the requested flags (for IN/OUT) and the descriptor flags */ +return dm_gpio_clrset_flags (desc,0 , flags); }int dm_gpio_get_flags (struct gpio_desc *desc,ulong *flagsp)
include/asm-generic/gpio.h +25 -0
@@ -128,6 +128,12 @@ struct gpio_desc {#define GPIOD_PULL_UP BIT(7)/* GPIO has pull-up enabled */ #define GPIOD_PULL_DOWN BIT(8)/* GPIO has pull-down enabled */ +/* Flags for updating the above */ +#define GPIOD_MASK_DIR (GPIOD_IS_OUT | GPIOD_IS_IN | \ + GPIOD_IS_OUT_ACTIVE) +#define GPIOD_MASK_DSTYPE (GPIOD_OPEN_DRAIN | GPIOD_OPEN_SOURCE) +#define GPIOD_MASK_PULL (GPIOD_PULL_UP | GPIOD_PULL_DOWN) +uint offset;/* GPIO offset within the device */ /* * We could consider adding the GPIO label in here. Possibly we could
@@ -657,6 +663,25 @@ int dm_gpio_get_value(const struct gpio_desc *desc);int dm_gpio_set_value (const struct gpio_desc *desc,int value); +/** +* dm_gpio_clrset_flags() - Update flags +* +* This updates the flags as directled. Note that desc->flags is updated by this +* function on success. If any changes cannot be made, best efforts are made. +* +* By use of @clr and @set any of flags can be individually updated, or left +* alone +* +* @desc: GPIO description containing device, offset and flags, +* previously returned by gpio_request_by_name() +* @clr: Flags to clear (GPIOD_...) +* @set: Flags to set (GPIOD_...) +* @return 0 if OK, -EINVAL if the flags had obvious conflicts, +* -ERECALLCONFLICT if there was a non-obvious hardware conflict when attempting +* to set the flags +*/ +int dm_gpio_clrset_flags (struct gpio_desc *desc,ulong clr,ulong set); +/** * dm_gpio_set_dir_flags() - Set direction using description and added flags *
test/dm/gpio.c +108 -17
158 lines not on this page · raw message
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 11/15 gpio: Replace direction_input() and direction_output()
In reply to Simon GlassThe new update_flags() method is more flexible since it allows the driver to see the full flags all at once. Use that in preference to these two functions. Add comments to that effect.
---
(no changes since v1)
drivers/gpio/gpio-uclass.c | 15 ++++++--------- include/asm-generic/gpio.h | 26 +++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 10 deletions(-)
drivers/gpio/gpio-uclass.c +6 -9
@@ -512,13 +512,10 @@ int gpio_direction_input(unsigned gpio)int ret; ret =gpio_to_device (gpio, &desc); -if (ret) -return ret; - ret =check_reserved (&desc,"dir_input" );if (ret)return ret; -return gpio_get_ops (desc.dev)->direction_input (desc.dev, desc.offset); +return dm_gpio_clrset_flags (&desc,GPIOD_MASK_DIR ,GPIOD_IS_IN ); }/**
@@ -533,17 +530,17 @@ int gpio_direction_input(unsigned gpio)int gpio_direction_output (unsigned gpio,int value) {struct gpio_desc desc; +ulong flags;int ret; ret =gpio_to_device (gpio, &desc); -if (ret) -return ret; - ret =check_reserved (&desc,"dir_output" );if (ret)return ret; -return gpio_get_ops (desc.dev)->direction_output (desc.dev, - desc.offset, value); + flags =GPIOD_IS_OUT ; +if (value) + flags |=GPIOD_IS_OUT_ACTIVE ; +return dm_gpio_clrset_flags (&desc,GPIOD_MASK_DIR , flags); }static int _gpio_get_value (const struct gpio_desc *desc)
include/asm-generic/gpio.h +25 -1
@@ -266,10 +266,32 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,struct dm_gpio_ops {int (*request)(struct udevice *dev,unsigned offset,const char *label);int (*rfree)(struct udevice *dev,unsigned int offset); + +/** +* direction_input() - deprecated +* +* Equivalent to set_flags(...GPIOD_IS_IN) +*/ int (*direction_input)(struct udevice *dev,unsigned offset); + +/** +* direction_output() - deprecated +* +* Equivalent to set_flags(...GPIOD_IS_OUT) with GPIOD_IS_OUT_ACTIVE +* also set if @value +*/ int (*direction_output)(struct udevice *dev,unsigned offset,int value); +int (*get_value)(struct udevice *dev,unsigned offset); + +/** +* set_value() - Sets the GPIO value of an output +* +* If the driver provides an @set_flags() method then that is used +* in preference to this, with GPIOD_IS_OUT_ACTIVE set according to +* @value. +*/ int (*set_value)(struct udevice *dev,unsigned offset,int value);/** * get_function() Get the GPIO function
@@ -326,7 +348,9 @@ struct dm_gpio_ops {* uclass, so the driver always sees the value that should be set at the * pin (1=high, 0=low). * -* This method is optional. +* This method is required and should be implemented by new drivers. At +* some point, it will supersede direction_input() and +* direction_output(), which wil be removed. * * @dev: GPIO device * @offset: GPIO offset within that device
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 12/15 gpio: Use an 'ops' variable everywhere
In reply to Simon GlassUpdate this driver to use the common method of putting the driver operations in an 'ops' variable install of calling gpio_get_ops() repeatedly. Make it const since operations do not change.
---
(no changes since v1)
drivers/gpio/gpio-uclass.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-)
drivers/gpio/gpio-uclass.c +14 -11
@@ -219,7 +219,7 @@ int gpio_xlate_offs_flags(struct udevice *dev, struct gpio_desc *desc,static int gpio_find_and_xlate (struct gpio_desc *desc,struct ofnode_phandle_args *args) { -struct dm_gpio_ops *ops =gpio_get_ops (desc->dev); +const struct dm_gpio_ops *ops =gpio_get_ops (desc->dev);if (ops->xlate)return ops->xlate (desc->dev, desc, args);
@@ -352,6 +352,7 @@ int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc)int dm_gpio_request (struct gpio_desc *desc,const char *label) { +const struct dm_gpio_ops *ops =gpio_get_ops (desc->dev);struct udevice *dev = desc->dev;struct gpio_dev_priv *uc_priv;char *str;
@@ -363,8 +364,8 @@ int dm_gpio_request(struct gpio_desc *desc, const char *label) str =strdup (label);if (!str)return -ENOMEM ; -if (gpio_get_ops (dev)->request) { - ret =gpio_get_ops (dev)->request (dev, desc->offset, label); +if (ops->request) { + ret = ops->request (dev, desc->offset, label);if (ret) {free (str);return ret;
@@ -441,14 +442,15 @@ int gpio_requestf(unsigned gpio, const char *fmt, ...)int _dm_gpio_free (struct udevice *dev,uint offset) { +const struct dm_gpio_ops *ops =gpio_get_ops (dev);struct gpio_dev_priv *uc_priv;int ret; uc_priv =dev_get_uclass_priv (dev);if (!uc_priv->name[offset])return -ENXIO ; -if (gpio_get_ops (dev)->rfree) { - ret =gpio_get_ops (dev)->rfree (dev, offset); +if (ops->rfree) { + ret = ops->rfree (dev, offset);if (ret)return ret; }
@@ -545,9 +547,10 @@ int gpio_direction_output(unsigned gpio, int value)static int _gpio_get_value (const struct gpio_desc *desc) { +const struct dm_gpio_ops *ops =gpio_get_ops (desc->dev);int value; - value =gpio_get_ops (desc->dev)->get_value (desc->dev, desc->offset); + value = ops->get_value (desc->dev, desc->offset);return desc->flags &GPIOD_ACTIVE_LOW ? !value : value; }
@@ -643,7 +646,7 @@ static int check_dir_flags(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); +const struct dm_gpio_ops *ops =gpio_get_ops (dev);struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev);int ret =0 ;
@@ -709,7 +712,7 @@ int dm_gpio_get_flags(struct gpio_desc *desc, ulong *flagsp) {struct udevice *dev = desc->dev;int ret, value; -struct dm_gpio_ops *ops =gpio_get_ops (dev); +const struct dm_gpio_ops *ops =gpio_get_ops (dev);ulong flags; ret =check_reserved (desc,"get_flags" );
@@ -807,7 +810,7 @@ static int get_function(struct udevice *dev, int offset, bool skip_unused, const char **namep) {struct gpio_dev_priv *uc_priv =dev_get_uclass_priv (dev); -struct dm_gpio_ops *ops =gpio_get_ops (dev); +const struct dm_gpio_ops *ops =gpio_get_ops (dev);BUILD_BUG_ON (GPIOF_COUNT !=ARRAY_SIZE (gpio_function));if (!device_active (dev))
@@ -844,7 +847,7 @@ int gpio_get_raw_function(struct udevice *dev, int offset, const char **namep)int gpio_get_status (struct udevice *dev,int offset,char *buf,int buffsize) { -struct dm_gpio_ops *ops =gpio_get_ops (dev); +const struct dm_gpio_ops *ops =gpio_get_ops (dev);struct gpio_dev_priv *priv;char *str = buf;int func;
@@ -884,7 +887,7 @@ int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)#if CONFIG_IS_ENABLED (ACPIGEN )int gpio_get_acpi (const struct gpio_desc *desc,struct acpi_gpio *gpio) { -struct dm_gpio_ops *ops; +const struct dm_gpio_ops *ops;memset (gpio,'\0' ,sizeof (*gpio));if (!dm_gpio_is_valid (desc)) {
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 13/15 gpio: x86: Drop the deprecated methods in intel_gpio
In reply to Simon GlassWe don't need to implement direction_input() and direction_output() anymore. Drop them and use update_flags() instead.
---
(no changes since v1)
arch/x86/include/asm/intel_pinctrl_defs.h | 5 ++ drivers/gpio/intel_gpio.c | 72 ++++++++++++----------- 2 files changed, 43 insertions(+), 34 deletions(-)
arch/x86/include/asm/intel_pinctrl_defs.h +5 -0
@@ -11,6 +11,11 @@/* This file is included by device trees, so avoid BIT() macros */ +#define GPIO_DW_SIZE (x) (sizeof(u32) * (x)) +#define PAD_CFG_OFFSET (x, dw_num) ((x) + GPIO_DW_SIZE(dw_num)) +#define PAD_CFG0_OFFSET (x) PAD_CFG_OFFSET(x, 0) +#define PAD_CFG1_OFFSET (x) PAD_CFG_OFFSET(x, 1) +#define PAD_CFG0_TX_STATE_BIT 0#define PAD_CFG0_TX_STATE (1 << PAD_CFG0_TX_STATE_BIT)#define PAD_CFG0_RX_STATE_BIT 1
drivers/gpio/intel_gpio.c +38 -34
100 lines not on this page · raw message
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 14/15 gpio: sandbox: Track whether a GPIO is driven
In reply to Simon GlassAdd a new flag to keep track of whether sandbox is driving the pin, or whether it is expecting an input signal. If it is driving, then the value of the pin is the value being driven (0 or 1). If not driving, then we consider the value 0, since we don't currently handle things like pull-ups yet.
---
(no changes since v1)
arch/sandbox/include/asm/gpio.h | 3 ++- drivers/gpio/sandbox.c | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-)
arch/sandbox/include/asm/gpio.h +2 -1
@@ -25,8 +25,9 @@/* Our own private GPIO flags, which musn't conflict with GPIOD_... */ #define GPIOD_EXT_HIGH BIT(20)/* external source is high (else low) */ +#define GPIOD_EXT_DRIVEN BIT(21)/* external source is driven */ -#define GPIOD_SANDBOX_MASK BIT(20) +#define GPIOD_SANDBOX_MASK GENMASK(21, 20)/** * Return the simulated value of a GPIO (used only in sandbox test code)
drivers/gpio/sandbox.c +15 -6
@@ -76,16 +76,22 @@ static int set_gpio_flag(struct udevice *dev, unsigned int offset, ulong flag,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 ; }
@@ -142,8 +148,8 @@ static int sb_gpio_direction_output(struct udevice *dev, unsigned offset, 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;
@@ -171,8 +177,8 @@ static int sb_gpio_set_value(struct udevice *dev, unsigned offset, int value)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;
@@ -218,10 +224,13 @@ static int sb_gpio_set_flags(struct udevice *dev, unsigned int offset,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;
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
PATCH v2 15/15 gpio: Add a way to read 3-way strapping pins
In reply to Simon GlassUsing the internal vs. external pull resistors it is possible to get 27 different combinations from 3 strapping pins. Add an implementation of this.
This involves updating the sandbox GPIO driver to model external and (weaker) internal pull resistors. The get_value() method now takes account of what is driving a pin:
sandbox: GPIOD_EXT_DRIVEN - in which case GPIO_EXT_HIGH provides the
value
outside source - in which case GPIO_EXT_PULL_UP/DOWN indicates the
external state and we work the final state using those flags and the internal GPIOD_PULL_UP/DOWN flags
Of course the outside source does not really exist in sandbox. We are just modelling it for test purpose.
---
(no changes since v1)
arch/sandbox/include/asm/gpio.h | 5 +- drivers/gpio/gpio-uclass.c | 78 ++++++++++++++++++++++++++ drivers/gpio/sandbox.c | 13 +++-- include/asm-generic/gpio.h | 37 +++++++++++++ test/dm/gpio.c | 98 +++++++++++++++++++++++++++++++++ 5 files changed, 226 insertions(+), 5 deletions(-)
arch/sandbox/include/asm/gpio.h +4 -1
@@ -26,8 +26,11 @@/* Our own private GPIO flags, which musn't conflict with GPIOD_... */ #define GPIOD_EXT_HIGH BIT(20)/* external source is high (else low) */ #define GPIOD_EXT_DRIVEN BIT(21)/* external source is driven */ +#define GPIOD_EXT_PULL_UP BIT(22)/* GPIO has external pull-up */ +#define GPIOD_EXT_PULL_DOWN BIT(23)/* GPIO has external pull-down */ -#define GPIOD_SANDBOX_MASK GENMASK(21, 20) +#define GPIOD_EXT_PULL (BIT(21) | BIT(22)) +#define GPIOD_SANDBOX_MASK GENMASK(23, 20)/** * Return the simulated value of a GPIO (used only in sandbox test code)
drivers/gpio/gpio-uclass.c +78 -0
102 lines not on this page · raw message
drivers/gpio/sandbox.c +9 -4
@@ -19,7 +19,6 @@#include <dt-bindings/gpio/gpio.h> #include <dt-bindings/gpio/sandbox-gpio.h> -struct gpio_state {const char *label;/* label given by requester */ ulong flags;/* flags (GPIOD_...) */
@@ -81,10 +80,16 @@ int sandbox_gpio_get_value(struct udevice *dev, unsigned offset)if (get_gpio_flag (dev, offset,GPIOD_IS_OUT ))debug ("sandbox_gpio: get_value on output gpio %u\n" , offset); -if (state->flags &GPIOD_EXT_DRIVEN ) +if (state->flags &GPIOD_EXT_DRIVEN ) { val = state->flags &GPIOD_EXT_HIGH ; -else - val = false; + }else { +if (state->flags &GPIOD_EXT_PULL_UP ) + val = true; +else if (state->flags &GPIOD_EXT_PULL_DOWN ) + val = false; +else + val = state->flags &GPIOD_PULL_UP ; + }return val; }
include/asm-generic/gpio.h +37 -0
@@ -503,6 +503,28 @@ int gpio_get_values_as_int(const int *gpio_list);*/ int dm_gpio_get_values_as_int (const struct gpio_desc *desc_list,int count); +/** +* dm_gpio_get_values_as_int_base3() - Create a base-3 int from a list of GPIOs +* +* This uses pull-ups/pull-downs to figure out whether a GPIO line is externally +* pulled down, pulled up or floating. This allows three different strap values +* for each pin. +* +* With this it is possible to obtain more combinations from the same number of +* strapping pins, when compared to dm_gpio_get_values_as_int(). The external +* pull resistors should be made stronger that the internal SoC pull resistors, +* for this to work. +* +* With 2 pins, 6 combinations are possible, compare with 4 +* With 3 pins, 27 are possible, compared with 8 +* +* @desc_list: List of GPIOs to collect +* @count: Number of GPIOs +* @return resulting integer value, or -ve on error +*/ +int dm_gpio_get_values_as_int_base3 (struct gpio_desc *desc_list, +int count); +/** * gpio_claim_vector() - claim a number of GPIOs for input *
@@ -720,6 +742,21 @@ int dm_gpio_clrset_flags(struct gpio_desc *desc, ulong clr, ulong set);*/ int dm_gpio_set_dir_flags (struct gpio_desc *desc,ulong flags); +/** +* dm_gpios_clrset_flags() - Sets flags for a set of GPIOs +* +* This clears and sets flags individually for each GPIO. +* +* @desc: List of GPIOs to update +* @count: Number of GPIOs in the list +* @clr: Flags to clear (GPIOD_...), e.g. GPIOD_MASK_DIR if you are +* changing the direction +* @set: Flags to set (GPIOD_...) +* @return 0 if OK, -ve on error +*/ +int dm_gpios_clrset_flags (struct gpio_desc *desc,int count,ulong clr, +ulong set); +/** * dm_gpio_get_flags() - Get flags *
test/dm/gpio.c +98 -0
101 lines not on this page · raw message
Signature · 1 line
2.30.0.296.g2bfb1c46d8-goog
v2 cover gpio: Update and simplify the uclass API
In reply to Simon GlassHi Simon,
Quoted 50 lines · Simon Glass
At present the GPIO uclass mirrors what was in U-Boot before driver model. It works well in most cases but is becoming cumbersome with things like pull-up/down and drive strength. In those cases it is easier for the driver to deal with all the flags at one, rather than piece by piece.
In fact the current API does not officially have a method for adjusting anything other than the direction flags. While
set_dir_flags()andget_dir_flags()do in fact support changing other flags, this is not documented.Secondly,
set_dir_flagsactually ORs the current flags with the new ones so it is not possible to clear flags. It seems better to use a clr/set interface (bit clear followed by OR) to provide more flexibility.Finally,
direction_input()anddirection_output()are really just the same thing asset_dir_flags(), with a different name. We currently use the latter if available, failing back to the former. But it makes sense to deprecate the old methods.This series makes the above changes. Existing drivers are mostly left alone, since they should continue to operate as is. The sandbox driver is updated to add the required new tests and the x86 driver is switched over to the new API.
The STM32 driver should be checked to make sure the open source/open drain features still work as intended.
Changes in v2:
- Useset_flags()instead ofupdate_flags()
- Fix 'provide' typo while we are here
- Make operation ofset_flags()deterministic
- Swap newf and flags insb_gpio_set_flags()Simon Glass (15):
gpio: Disable functions not used with of-platdata
dm: gpio: Renameset_dir_flags()method toupdate_flags()
dm: gpio: Renameget_dir_flags()method toget_flags()
gpio: Renamedm_gpio_get_dir_flags()todm_gpio_get_flags()
gpio: Dropdm_gpio_set_dir()
gpio: sandbox: Rename GPIOdir_flagsto flags
gpio: sandbox: Use a separate flag for the value
gpio: sandbox: Fully separate pin value from output value
gpio: sandbox: Makesandbox_gpio_set_flags()set all flags
dm: gpio: Add a way to update flags
gpio: Replacedirection_input()anddirection_output()
gpio: Use an 'ops' variable everywhere
gpio: x86: Drop the deprecated methods inintel_gpio
gpio: sandbox: Track whether a GPIO is driven
gpio: Add a way to read 3-way strapping pins
Quoted 11 lines
arch/sandbox/include/asm/gpio.h | 17 +- arch/x86/include/asm/intel_pinctrl_defs.h | 5 + drivers/gpio/gpio-uclass.c | 228 ++++++++++++++----- drivers/gpio/intel_gpio.c | 72 +++--- drivers/gpio/sandbox.c | 138 ++++++++---- drivers/gpio/stm32_gpio.c | 14 +- drivers/pinctrl/pinctrl-stmfx.c | 14 +- include/asm-generic/gpio.h | 130 +++++++++-- test/dm/gpio.c | 261 +++++++++++++++++++--- 9 files changed, 663 insertions(+), 216 deletions(-)
The open source/ open drain works correctly
But I found a issue for GPIOD_ACTIVE_LOW management in STM32
drivers after the serie corrected by the next patch
Tested with gpio hog on DK2 board (to force directly flags by DT)
?arch/arm/dts/stm32mp157c-dk2-u-boot.dtsi
+
+&gpioi {
+??? test1 {
+??? ??? gpio-hog;
+??? ??? input;
+??? ??? gpios = <0 0>;
+??? };
+??? test2 {
+??? ??? gpio-hog;
+??? ??? input;
+??? ??? gpios = <1 GPIO_PULL_UP>;
+??? };
+??? test3 {
+??? ??? gpio-hog;
+??? ??? input;
+??? ??? gpios = <2 GPIO_PULL_DOWN>;
+??? };
+??? test4 {
+??? ??? gpio-hog;
+??? ??? output-low;
+??? ??? gpios = <3 (GPIO_OPEN_DRAIN)>;
+??? };
+??? test5 {
+??? ??? gpio-hog;
+??? ??? output-low;
+??? ??? gpios = <4 (GPIO_OPEN_DRAIN | GPIO_PULL_UP)>; +??? };
+??? test6 {
+??? ??? gpio-hog;
+??? ??? output-high;
+??? ??? gpios = <5 (GPIO_OPEN_DRAIN | GPIO_PULL_DOWN)>; +??? };
+??? test7 {
+??? ??? gpio-hog;
+??? ??? output-high;
+??? ??? gpios = <6 0>;
+??? };
+??? test8 {
+??? ??? gpio-hog;
+??? ??? output-low;
+??? ??? gpios = <7 0>;
+??? };
+??? test9 {
+??? ??? gpio-hog;
+??? ??? output-high;
+??? ??? gpios = <8 GPIO_ACTIVE_LOW>;
+??? };
+??? test10 {
+??? ??? gpio-hog;
+??? ??? output-low;
+??? ??? gpios = <9 GPIO_ACTIVE_LOW>;
+??? };
+};
Then
STM32MP> pinmux status -a
--------------------------
pin-controller at 50002000:
....
GPIOI0??? : gpio input? test1.gpio-hog GPIOI1??? : gpio input pull-up test2.gpio-hog GPIOI2??? : gpio input pull-down test3.gpio-hog GPIOI3??? : gpio output open-drain? test4.gpio-hog GPIOI4??? : gpio output open-drain pull-up test5.gp GPIOI5??? : gpio output open-drain pull-down test6. GPIOI6??? : gpio output push-pull? test7.gpio-hog GPIOI7??? : gpio output push-pull? test8.gpio-hog GPIOI8??? : gpio output push-pull? test9.gpio-hog GPIOI9??? : gpio output push-pull? test10.gpio-hog GPIOI10?? : analog
GPIOI11?? : analog
....
And
STM32MP> gpio status -a
....
Bank GPIOI:
GPIOI0: input: 0 [x] test1.gpio-hog
GPIOI1: input: 1 [x] test2.gpio-hog
GPIOI2: input: 0 [x] test3.gpio-hog
GPIOI3: output: 0 [x] test4.gpio-hog
GPIOI4: output: 0 [x] test5.gpio-hog
GPIOI5: output: 0 [x] test6.gpio-hog
GPIOI6: output: 1 [x] test7.gpio-hog
GPIOI7: output: 0 [x] test8.gpio-hog
GPIOI8: output: 0 [x] test9.gpio-hog
GPIOI9: output: 1 [x] test10.gpio-hog
GPIOI10: unused: 0 [ ]
GPIOI11: unused: 0 [ ]
Warning: the gpio value provide here the real GPIO level
(result of ops->get_value() in gpio_get_status),
and not the logical level (with GPIO_ACTIVE_LOW support)
Regards
Patrick
??? fixup! dm: gpio: Add a way to update flags
??? Proposed update as GPIOD_ are directly managed by driver inupdate_flags
??? except GPIOD_ACTIVE_LOW, managed in GPIO u-class.
??? removed GPIOD_FLAGS_OUTPUT_MASK and associated calls in drivers
??? Signed-off-by: Patrick Delaunay <[email protected]> ??? Change-Id: I781236d1abadd2a46deafb2f737099188a45ab51
-------------------------- drivers/gpio/gpio-uclass.c
--------------------------
index 984c07d1df..f9ded5a624 100644
@@ -652,6 +652,7 @@ static int _dm_gpio_update_flags(struct gpio_desc *desc, ulong flags)
???? const struct dm_gpio_ops *ops = gpio_get_ops(dev); ???? struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev); ???? int ret = 0;
+??? int value;
???? ret = check_dir_flags(flags);
???? if (ret) {
@@ -674,8 +675,8 @@ static int _dm_gpio_update_flags(struct gpio_desc *desc, ulong flags)
???? ??? ret = ops->update_flags(dev, desc->offset, flags); ???? } else {
???? ??? if (flags & GPIOD_IS_OUT) {
-??? ??? ??? ret = ops->direction_output(dev, desc->offset, -??? ??? ??? ??? ??? ??? ??? GPIOD_FLAGS_OUTPUT(flags)); +??? ??? ??? value = !!(flags & GPIOD_IS_OUT_ACTIVE);
+??? ??? ??? ret = ops->direction_output(dev, desc->offset, value);
???? ??? } else if (flags & GPIOD_IS_IN) {
???? ??? ??? ret = ops->direction_input(dev, desc->offset); ???? ??? }
-------------------------- drivers/gpio/stm32_gpio.c
--------------------------
index 04dd4fa076..b08e7202fc 100644
@@ -203,12 +203,13 @@ static int stm32_gpio_update_flags(struct udevice *dev, unsigned int offset,
???? ??? return idx;
???? if (flags & GPIOD_IS_OUT) {
-??? ??? int value = GPIOD_FLAGS_OUTPUT(flags); +??? ??? int value = !!(flags & GPIOD_IS_OUT_ACTIVE);
???? ??? if (flags & GPIOD_OPEN_DRAIN)
???? ??? ??? stm32_gpio_set_otype(regs, idx, STM32_GPIO_OTYPE_OD); ???? ??? else
???? ??? ??? stm32_gpio_set_otype(regs, idx, STM32_GPIO_OTYPE_PP);
+
???? ??? stm32_gpio_set_moder(regs, idx, STM32_GPIO_MODE_OUT); ???? ??? writel(BSRR_BIT(idx, value), ®s->bsrr);
@@ -315,6 +316,8 @@ static int gpio_stm32_probe(struct udevice *dev)
???? ??? ret = dev_read_phandle_with_args(dev, "gpio-ranges", NULL, 3, ???? ??? ??? ??? ??? ??? ?++i, &args);
+??? ??? dev_dbg(dev, "dev_read_phandle_with_args(%d) = %d %d %d\n", i-1, ret, -ENOENT, dev_read_u32_default(dev, "ngpios", 0)); +
???? ??? if (!ret && args.args_count < 3)
???? ??? ??? return -EINVAL;
???? }
----------------------- drivers/pinctrl/pinctrl-stmfx.c
-----------------------
index 6477febbaa..e2c95d8d42 100644
@@ -169,6 +169,8 @@ static int stmfx_gpio_update_flags(struct udevice *dev, unsigned int offset,
???? int ret = -ENOTSUPP;
???? if (flags & GPIOD_IS_OUT) {
+??? ??? int value = !!(flags & GPIOD_IS_OUT_ACTIVE);
+
???? ??? if (flags & GPIOD_OPEN_SOURCE)
???? ??? ??? return -ENOTSUPP;
???? ??? if (flags & GPIOD_OPEN_DRAIN)
@@ -177,8 +179,7 @@ static int stmfx_gpio_update_flags(struct udevice *dev, unsigned int offset,
???? ??? ??? ret = stmfx_conf_set_type(dev, offset, 1); ???? ??? if (ret)
???? ??? ??? return ret;
-??? ??? ret = stmfx_gpio_direction_output(dev, offset, -??? ??? ??? ??? ??? ??? ? GPIOD_FLAGS_OUTPUT(flags)); +??? ??? ret = stmfx_gpio_direction_output(dev, offset, value);
???? } else if (flags & GPIOD_IS_IN) {
???? ??? ret = stmfx_gpio_direction_input(dev, offset); ???? ??? if (ret)
-------------------------- include/asm-generic/gpio.h
--------------------------
index 1cf81a3fc7..62514db5be 100644
@@ -141,12 +141,6 @@ struct gpio_desc {
???? ?*/
?};
-/* helper to compute the value of the gpio output */ -#define GPIOD_FLAGS_OUTPUT_MASK (GPIOD_ACTIVE_LOW | GPIOD_IS_OUT_ACTIVE) -#define GPIOD_FLAGS_OUTPUT(flags) \
-??? (((((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_IS_OUT_ACTIVE) || \
-??? ? (((flags) & GPIOD_FLAGS_OUTPUT_MASK) == GPIOD_ACTIVE_LOW))) -
?/**
? * dm_gpio_is_valid() - Check if a GPIO is valid
? *