gpio: Update and simplify the uclass API
Subsystems (5)
v4 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 v4:
- Update dm_gpio_set_dir_flags() to clear direction flags first
Changes in v3:
- Drop the word 'direction' in comments also
- Drop 'dir' in 'GPIO dir flags' comment
- Start at BIT(31) for sandbox-specific flags
- Add a comment to sandbox_gpio_set_flags() about clearing GPIOD_EXT_HIGH
- Incorporate GPIOD_FLAGS_OUTPUT() changes from Patrick Delaunay
- Use bit 30 for GPIOD_EXT_DRIVEN
- Split out the log-category change to a separate patch
- Use bits 28, 29 for the new flags
- Assert that count parameter is within range
- Redo digit logic to be easier to understand
- Update function comment to explain the meaning of the digits
- Fix 'compare' typo
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 (16):
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: Define the log category in the uclass
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 | 243 ++++++++++++++------ drivers/gpio/intel_gpio.c | 72 +++--- drivers/gpio/sandbox.c | 138 +++++++---- drivers/gpio/stm32_gpio.c | 17 +- drivers/pinctrl/pinctrl-stmfx.c | 19 +- include/asm-generic/gpio.h | 139 +++++++++-- test/dm/gpio.c | 268 +++++++++++++++++++--- 9 files changed, 690 insertions(+), 228 deletions(-)
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 1/16 gpio: Disable functions not used with of-platdata
These functions use devicetree and cannot work 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.
Series-changes; 3
- Fix 'wprl' typo
---
(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.478.g8a0d178c01-goog
PATCH v4 1/16 gpio: Disable functions not used with of-platdata
Quoted 9 lines · Simon Glass
These functions use devicetree and cannot work 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.
Quoted 6 lines
Series-changes; 3
- Fix 'wprl' typoSigned-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/911e0431/attachment.sig>
PATCH v4 2/16 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.
---
(no changes since v2)
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.478.g8a0d178c01-goog
PATCH v4 2/16 dm: gpio: Rename set_dir_flags() method to update_flags()
Quoted 9 lines · Simon Glass
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 <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/64df87f5/attachment.sig>
PATCH v4 3/16 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.478.g8a0d178c01-goog
PATCH v4 3/16 dm: gpio: Rename get_dir_flags() method to get_flags()
Quoted 11 lines · Simon Glass
It 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.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/68d25c80/attachment.sig>
PATCH v4 4/16 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 v3)
Changes in v3:
- Drop the word 'direction' in comments also
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.478.g8a0d178c01-goog
PATCH v4 4/16 gpio: Rename dm_gpio_get_dir_flags() to dm_gpio_get_flags()
Quoted 6 lines · Simon Glass
This function can be used to get any flags, not just direction flags. Rename it to avoid confusion.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>Reviewed-by Pratyush Yadav <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/13d7f44a/attachment.sig>
PATCH v4 5/16 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.478.g8a0d178c01-goog
PATCH v4 5/16 gpio: Drop dm_gpio_set_dir()
Quoted 5 lines · Simon Glass
This function is not used. Drop it.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>
I'm dropping this patch as it seems to be an explicit break of:
commit 6befb51f349459c96ed64412070feda7472cf152
Author: Harm Berntsen <[email protected]> Date: Sun Nov 29 09:47:15 2020 +0000
i2c: i2c-gpio: Fix GPIO output
The dm_gpio_set_dir_flags function cannot be used to update the configuration of a GPIO pin because it does a bitwise OR with the existing flags. Looks like commit 788ea834124b ("gpio: add function _dm_gpio_set_dir_flags") has introduced this behaviour and the i2c-gpio driver has been broken since.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210303/c7e72a34/attachment.sig>
PATCH v4 5/16 gpio: Drop dm_gpio_set_dir()
Hi Tom,
Quoted 22 lines · Tom Rini
Quoted 5 lines · Simon Glass
This function is not used. Drop it.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>I'm dropping this patch as it seems to be an explicit break of:
commit6befb51f349459c96ed64412070feda7472cf152Author: Harm Berntsen <[email protected]> Date: Sun Nov 29 09:47:15 2020 +0000i2c: i2c-gpio: Fix GPIO output
The
dm_gpio_set_dir_flagsfunction cannot be used to update the configuration of a GPIO pin because it does a bitwise OR with the existing flags. Looks like commit788ea834124b("gpio: add function_dm_gpio_set_dir_flags") has introduced this behaviour and the i2c-gpio driver has been broken since.
Quoted 3 lines
Signed-off-by Harm Berntsen <[email protected]>CC Heiko Schocher <[email protected]>CC Patrick Delaunay <[email protected]>
Yes I noticed that but only recently, somehow. I have a patch to adjust it.
Does this mean you are planning to apply the rest of the series? If so I'll see how things land and send a patch after that.
Regards,
Simon
PATCH v4 5/16 gpio: Drop dm_gpio_set_dir()
Quoted 25 lines · Simon Glass
Hi Tom,
Quoted 22 lines · Tom Rini
Quoted 5 lines · Simon Glass
This function is not used. Drop it.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>I'm dropping this patch as it seems to be an explicit break of:
commit6befb51f349459c96ed64412070feda7472cf152Author: Harm Berntsen <[email protected]> Date: Sun Nov 29 09:47:15 2020 +0000i2c: i2c-gpio: Fix GPIO output
The
dm_gpio_set_dir_flagsfunction cannot be used to update the configuration of a GPIO pin because it does a bitwise OR with the existing flags. Looks like commit788ea834124b("gpio: add function_dm_gpio_set_dir_flags") has introduced this behaviour and the i2c-gpio driver has been broken since.
Quoted 8 lines
Quoted 3 lines
Signed-off-by Harm Berntsen <[email protected]>CC Heiko Schocher <[email protected]>CC Patrick Delaunay <[email protected]>Yes I noticed that but only recently, somehow. I have a patch to adjust it.
Does this mean you are planning to apply the rest of the series? If so I'll see how things land and send a patch after that.
Yes, I have the rest of the series about to go in to -next.
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/9d3e8396/attachment.sig>
PATCH v4 6/16 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.
---
(no changes since v3)
Changes in v3:
- Drop 'dir' in 'GPIO dir flags' comment
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.478.g8a0d178c01-goog
PATCH v4 6/16 gpio: sandbox: Rename GPIO dir_flags to flags
Quoted 9 lines · Simon Glass
Adjust 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_flagssince we can rely on a segfault if something is wrong.Signed-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/b0452d93/attachment.sig>
PATCH v4 7/16 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 v3)
Changes in v3:
- Start at BIT(31) for sandbox-specific flags
- Add a comment to sandbox_gpio_set_flags() about clearing GPIOD_EXT_HIGH
arch/sandbox/include/asm/gpio.h | 5 ++++ drivers/gpio/sandbox.c | 47 +++++++++++++++++---------------- 2 files changed, 29 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(31)/* external source is high (else low) */ + +#define GPIOD_SANDBOX_MASK BIT(31) +/** * Return the simulated value of a GPIO (used only in sandbox test code) *
drivers/gpio/sandbox.c +24 -23
92 lines not on this page · raw message
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 7/16 gpio: sandbox: Use a separate flag for the value
Quoted 5 lines · Simon Glass
At present with the sandbox GPIO driver it is not possible to change the value of
GPIOD_IS_OUT_ACTIVEunless 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.
Quoted 7 lines
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.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/955afc0a/attachment.sig>
PATCH v4 8/16 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 ; }
@@ -141,10 +141,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' */
@@ -158,6 +167,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)) {
@@ -166,7 +177,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.478.g8a0d178c01-goog
PATCH v4 8/16 gpio: sandbox: Fully separate pin value from output value
Quoted 9 lines · Simon Glass
At 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_ACTIVEflag 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.Signed-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/8852eab1/attachment.sig>
PATCH v4 9/16 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 | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-)
drivers/gpio/sandbox.c +12 -9
@@ -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 ; }
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 9/16 gpio: sandbox: Make sandbox_gpio_set_flags() set all flags
Quoted 9 lines · Simon Glass
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 <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/79848a6c/attachment.sig>
PATCH v4 10/16 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.
Also update the STM32 drivers to let the uclass handle the active low/high logic.
Drop the GPIOD_FLAGS_OUTPUT() macro which is no-longer used.
---
Changes in v4:
- Update dm_gpio_set_dir_flags() to clear direction flags first
Changes in v3:
- Incorporate GPIOD_FLAGS_OUTPUT() changes from Patrick Delaunay
drivers/gpio/gpio-uclass.c | 75 ++++++++++++++---- drivers/gpio/stm32_gpio.c | 3 +- drivers/pinctrl/pinctrl-stmfx.c | 5 +- include/asm-generic/gpio.h | 31 ++++++-- test/dm/gpio.c | 132 ++++++++++++++++++++++++++++---- 5 files changed, 203 insertions(+), 43 deletions(-)
drivers/gpio/gpio-uclass.c +58 -17
@@ -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,38 +661,52 @@ 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); }else {if (flags &GPIOD_IS_OUT ) { - ret = ops->direction_output (dev, desc->offset, -GPIOD_FLAGS_OUTPUT (flags)); +bool 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); } } -/* 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,GPIOD_MASK_DIR , flags); }int dm_gpio_get_flags (struct gpio_desc *desc,ulong *flagsp)
@@ -999,7 +1037,10 @@ static int gpio_request_tail(int ret, const char *nodename,debug ("%s: dm_gpio_requestf failed\n" , __func__); goto err; } - ret =dm_gpio_set_dir_flags (desc, flags); + +/* Keep any direction flags provided by the devicetree */ + ret =dm_gpio_set_dir_flags (desc, + flags | (desc->flags &GPIOD_MASK_DIR ));if (ret) {debug ("%s: dm_gpio_set_dir failed\n" , __func__); goto err;
drivers/gpio/stm32_gpio.c +2 -1
@@ -203,12 +203,13 @@ static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset,return idx;if (flags &GPIOD_IS_OUT ) { -int value =GPIOD_FLAGS_OUTPUT (flags); +bool 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);
drivers/pinctrl/pinctrl-stmfx.c +3 -2
@@ -169,6 +169,8 @@ static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset,int ret = -ENOTSUPP ;if (flags &GPIOD_IS_OUT ) { +bool 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_set_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 +25 -6
@@ -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
@@ -135,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 *
@@ -657,6 +657,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 +115 -17
165 lines not on this page · raw message
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 10/16 dm: gpio: Add a way to update flags
Quoted 27 lines · On Thu, 4 Feb 2021 21:22:03 -0700 Simon Glass <[email protected]> wrote:
It 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.Also update the STM32 drivers to let the uclass handle the active low/high logic.
Drop the
GPIOD_FLAGS_OUTPUT()macro which is no-longer used.Signed-off-by Simon Glass <[email protected]>---
Changes in v4:
- Updatedm_gpio_set_dir_flags()to clear direction flags firstChanges in v3:
- IncorporateGPIOD_FLAGS_OUTPUT()changes from Patrick Delaunay
Quoted 7 lines
drivers/gpio/gpio-uclass.c | 75 ++++++++++++++---- drivers/gpio/stm32_gpio.c | 3 +- drivers/pinctrl/pinctrl-stmfx.c | 5 +- include/asm-generic/gpio.h | 31 ++++++-- test/dm/gpio.c | 132 ++++++++++++++++++++++++++++---- 5 files changed, 203 insertions(+), 43 deletions(-)
PATCH v4 10/16 dm: gpio: Add a way to update flags
In reply to Simon GlassHi Simon,
2 minor remarks,
Quoted 33 lines · Simon Glass
It 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.Also update the STM32 drivers to let the uclass handle the active low/high logic.
Drop the
GPIOD_FLAGS_OUTPUT()macro which is no-longer used.Signed-off-by Simon Glass <[email protected]>---
Changes in v4:
- Updatedm_gpio_set_dir_flags()to clear direction flags firstChanges in v3:
- IncorporateGPIOD_FLAGS_OUTPUT()changes from Patrick Delaunaydrivers/gpio/gpio-uclass.c | 75 ++++++++++++++---- drivers/gpio/stm32_gpio.c | 3 +- drivers/pinctrl/pinctrl-stmfx.c | 5 +- include/asm-generic/gpio.h | 31 ++++++-- test/dm/gpio.c | 132 ++++++++++++++++++++++++++++---- 5 files changed, 203 insertions(+), 43 deletions(-)
(...)
drivers/gpio/stm32_gpio.c static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset, · line 206
Quoted 10 lines
drivers/gpio/stm32_gpio.c +1
-1@@ -203,12 +203,13 @@ static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset,return idx;if (flags &GPIOD_IS_OUT ) { -int value =GPIOD_FLAGS_OUTPUT (flags); +bool value = flags &GPIOD_IS_OUT_ACTIVE ;
here the bool variable valeu can be 0 or GPIOD_IS_OUT_ACTIVE = BIT(4), so it should have
+ bool value = !!(flags & GPIOD_IS_OUT_ACTIVE);
or
+ int value = flags & GPIOD_IS_OUT_ACTIVE;
PS: not functional impact as
#define BSRR_BIT(gpio_pin, value)??? BIT((gpio_pin) + (value ? 0 : 16))
Quoted 14 lines
drivers/gpio/stm32_gpio.c +1
-0if (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);drivers/pinctrl/pinctrl-stmfx.c +0
-0
drivers/pinctrl/pinctrl-stmfx.c static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset, · line 173
Quoted 5 lines
drivers/pinctrl/pinctrl-stmfx.c +2
-0@@ -169,6 +169,8 @@ static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset,int ret = -ENOTSUPP ;if (flags &GPIOD_IS_OUT ) { +bool value = flags &GPIOD_IS_OUT_ACTIVE ; +
same here
+ int value = flags & GPIOD_IS_OUT_ACTIVE;
or
+ bool value = !!(flags & GPIOD_IS_OUT_ACTIVE);
But no impact
drivers/pinctrl/pinctrl-stmfx.c static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset, · line 185
Quoted 13 lines
drivers/pinctrl/pinctrl-stmfx.c +1
-2if (flags &GPIOD_OPEN_SOURCE )return -ENOTSUPP ;if (flags &GPIOD_OPEN_DRAIN )@@ -177,8 +179,7 @@ static int stmfx_gpio_set_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)
(...)
With the 2 remarks
Regards,
Patrick
PATCH v4 10/16 dm: gpio: Add a way to update flags
Hi Patrick,
Quoted 89 lines · Patrick DELAUNAY
Hi Simon,
2 minor remarks,
Quoted 33 lines · Simon Glass
It 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.Also update the STM32 drivers to let the uclass handle the active low/high logic.
Drop the
GPIOD_FLAGS_OUTPUT()macro which is no-longer used.Signed-off-by Simon Glass <[email protected]>---
Changes in v4:
- Updatedm_gpio_set_dir_flags()to clear direction flags firstChanges in v3:
- IncorporateGPIOD_FLAGS_OUTPUT()changes from Patrick Delaunaydrivers/gpio/gpio-uclass.c | 75 ++++++++++++++---- drivers/gpio/stm32_gpio.c | 3 +- drivers/pinctrl/pinctrl-stmfx.c | 5 +- include/asm-generic/gpio.h | 31 ++++++-- test/dm/gpio.c | 132 ++++++++++++++++++++++++++++---- 5 files changed, 203 insertions(+), 43 deletions(-)(...)
drivers/gpio/stm32_gpio.c static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset, · line 206
Quoted 10 lines
drivers/gpio/stm32_gpio.c +1
-1@@ -203,12 +203,13 @@ static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset,return idx;if (flags &GPIOD_IS_OUT ) { -int value =GPIOD_FLAGS_OUTPUT (flags); +bool value = flags &GPIOD_IS_OUT_ACTIVE ;here the bool variable valeu can be 0 or
GPIOD_IS_OUT_ACTIVE= BIT(4), so it should have+ bool value = !!(flags &
GPIOD_IS_OUT_ACTIVE);or
+ int value = flags &
GPIOD_IS_OUT_ACTIVE;PS: not functional impact as
#define
BSRR_BIT(gpio_pin, value)BIT((gpio_pin) + (value ? 0 : 16))Quoted 14 lines
drivers/gpio/stm32_gpio.c +1
-0if (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);drivers/pinctrl/pinctrl-stmfx.c +0
-0drivers/pinctrl/pinctrl-stmfx.c static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset, · line 173
Quoted 5 lines
drivers/pinctrl/pinctrl-stmfx.c +2
-0@@ -169,6 +169,8 @@ static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset,int ret = -ENOTSUPP ;if (flags &GPIOD_IS_OUT ) { +bool value = flags &GPIOD_IS_OUT_ACTIVE ; +same here
Quoted 3 lines
+ int value = flags &
GPIOD_IS_OUT_ACTIVE;
or
+ bool value = !!(flags &GPIOD_IS_OUT_ACTIVE);
The bool type should do this automatically. I tested this and it seems to do the right thing.
Quoted 23 lines
But no impact
Quoted 13 lines
drivers/pinctrl/pinctrl-stmfx.c +1
-2if (flags &GPIOD_OPEN_SOURCE )return -ENOTSUPP ;if (flags &GPIOD_OPEN_DRAIN )@@ -177,8 +179,7 @@ static int stmfx_gpio_set_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)(...)
Quoted 5 lines
With the 2 remarks
Reviewed-by Patrick Delaunay <[email protected]>Tested-by Patrick Delaunay <[email protected]>
Regards,
SImon
PATCH v4 10/16 dm: gpio: Add a way to update flags
Quoted 88 lines · Simon Glass
Hi Patrick,
Quoted 84 lines · Patrick DELAUNAY
Hi Simon,
2 minor remarks,
Quoted 33 lines · Simon Glass
It 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.Also update the STM32 drivers to let the uclass handle the active low/high logic.
Drop the
GPIOD_FLAGS_OUTPUT()macro which is no-longer used.Signed-off-by Simon Glass <[email protected]>---
Changes in v4:
- Updatedm_gpio_set_dir_flags()to clear direction flags firstChanges in v3:
- IncorporateGPIOD_FLAGS_OUTPUT()changes from Patrick Delaunaydrivers/gpio/gpio-uclass.c | 75 ++++++++++++++---- drivers/gpio/stm32_gpio.c | 3 +- drivers/pinctrl/pinctrl-stmfx.c | 5 +- include/asm-generic/gpio.h | 31 ++++++-- test/dm/gpio.c | 132 ++++++++++++++++++++++++++++---- 5 files changed, 203 insertions(+), 43 deletions(-)(...)
drivers/gpio/stm32_gpio.c static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset, · line 206
Quoted 10 lines
drivers/gpio/stm32_gpio.c +1
-1@@ -203,12 +203,13 @@ static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset,return idx;if (flags &GPIOD_IS_OUT ) { -int value =GPIOD_FLAGS_OUTPUT (flags); +bool value = flags &GPIOD_IS_OUT_ACTIVE ;here the bool variable valeu can be 0 or
GPIOD_IS_OUT_ACTIVE= BIT(4), so it should have+ bool value = !!(flags &
GPIOD_IS_OUT_ACTIVE);or
+ int value = flags &
GPIOD_IS_OUT_ACTIVE;PS: not functional impact as
#define
BSRR_BIT(gpio_pin, value)BIT((gpio_pin) + (value ? 0 : 16))Quoted 13 lines
drivers/gpio/stm32_gpio.c +1
-0if (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);drivers/pinctrl/pinctrl-stmfx.c +0
-0drivers/pinctrl/pinctrl-stmfx.c static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset, · line 173
Quoted 5 lines
drivers/pinctrl/pinctrl-stmfx.c +2
-0@@ -169,6 +169,8 @@ static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset,int ret = -ENOTSUPP ;if (flags &GPIOD_IS_OUT ) { +bool value = flags &GPIOD_IS_OUT_ACTIVE ; +same here
Quoted 6 lines
Quoted 3 lines
+ int value = flags &
GPIOD_IS_OUT_ACTIVE;
or
+ bool value = !!(flags &GPIOD_IS_OUT_ACTIVE);The bool type should do this automatically. I tested this and it seems to do the right thing.
I confirmed that it is working, forget my remarks.
for information: I tested it in stm32MP157C-DK2 board (with gcc 9.2)....
After check, it is my old habit / coding rule, when the bool type
don't exist in C (it was a typedef to int)
but, since C++ introducing a proper bool type,
the cast to 'bool' is enough with current compilers .
Quoted 3 lines
Regards,
SImon
Regards
PATCH v4 10/16 dm: gpio: Add a way to update flags
Hi Patrick,
Quoted 102 lines · Patrick DELAUNAY
Quoted 88 lines · Simon Glass
Hi Patrick,
Quoted 84 lines · Patrick DELAUNAY
Hi Simon,
2 minor remarks,
Quoted 33 lines · Simon Glass
It 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.Also update the STM32 drivers to let the uclass handle the active low/high logic.
Drop the
GPIOD_FLAGS_OUTPUT()macro which is no-longer used.Signed-off-by Simon Glass <[email protected]>---
Changes in v4:
- Updatedm_gpio_set_dir_flags()to clear direction flags firstChanges in v3:
- IncorporateGPIOD_FLAGS_OUTPUT()changes from Patrick Delaunaydrivers/gpio/gpio-uclass.c | 75 ++++++++++++++---- drivers/gpio/stm32_gpio.c | 3 +- drivers/pinctrl/pinctrl-stmfx.c | 5 +- include/asm-generic/gpio.h | 31 ++++++-- test/dm/gpio.c | 132 ++++++++++++++++++++++++++++---- 5 files changed, 203 insertions(+), 43 deletions(-)(...)
drivers/gpio/stm32_gpio.c static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset, · line 206
Quoted 10 lines
drivers/gpio/stm32_gpio.c +1
-1@@ -203,12 +203,13 @@ static int stm32_gpio_set_flags(struct udevice *dev, unsigned int offset,return idx;if (flags &GPIOD_IS_OUT ) { -int value =GPIOD_FLAGS_OUTPUT (flags); +bool value = flags &GPIOD_IS_OUT_ACTIVE ;here the bool variable valeu can be 0 or
GPIOD_IS_OUT_ACTIVE= BIT(4), so it should have+ bool value = !!(flags &
GPIOD_IS_OUT_ACTIVE);or
+ int value = flags &
GPIOD_IS_OUT_ACTIVE;PS: not functional impact as
#define
BSRR_BIT(gpio_pin, value)BIT((gpio_pin) + (value ? 0 : 16))Quoted 13 lines
drivers/gpio/stm32_gpio.c +1
-0if (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);drivers/pinctrl/pinctrl-stmfx.c +0
-0drivers/pinctrl/pinctrl-stmfx.c static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset, · line 173
Quoted 5 lines
drivers/pinctrl/pinctrl-stmfx.c +2
-0@@ -169,6 +169,8 @@ static int stmfx_gpio_set_flags(struct udevice *dev, unsigned int offset,int ret = -ENOTSUPP ;if (flags &GPIOD_IS_OUT ) { +bool value = flags &GPIOD_IS_OUT_ACTIVE ; +same here
Quoted 6 lines
Quoted 3 lines
+ int value = flags &
GPIOD_IS_OUT_ACTIVE;
or
+ bool value = !!(flags &GPIOD_IS_OUT_ACTIVE);The bool type should do this automatically. I tested this and it seems to do the right thing.
I confirmed that it is working, forget my remarks.
for information: I tested it in stm32MP157C-DK2 board (with gcc 9.2)....
Quoted 7 lines
After check, it is my old habit / coding rule, when the bool type
don't exist in C (it was a typedef to int)
but, since C++ introducing a proper bool type,
the cast to 'bool' is enough with current compilers .
Yes I am still getting used to it myself!
Quoted 4 lines
Reviewed-by Patrick Delaunay <[email protected]>Tested-by Patrick Delaunay <[email protected]>
Regards,
Simon
PATCH v4 10/16 dm: gpio: Add a way to update flags
In reply to Simon GlassQuoted 16 lines · Simon Glass
It 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.Also update the STM32 drivers to let the uclass handle the active low/high logic.
Quoted 8 lines
Drop the
GPIOD_FLAGS_OUTPUT()macro which is no-longer used.Signed-off-by Simon Glass <[email protected]>Tested-by Kory Maincent <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>Tested-by Patrick Delaunay <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>Tested-by Patrick Delaunay <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/f4374d53/attachment.sig>
PATCH v4 11/16 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
@@ -260,10 +260,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
@@ -320,7 +342,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.478.g8a0d178c01-goog
PATCH v4 11/16 gpio: Replace direction_input() and direction_output()
Quoted 7 lines · Simon Glass
The 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.Signed-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/e591ab40/attachment.sig>
PATCH v4 12/16 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 ;
@@ -710,7 +713,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" );
@@ -808,7 +811,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))
@@ -845,7 +848,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;
@@ -885,7 +888,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.478.g8a0d178c01-goog
PATCH v4 12/16 gpio: Use an 'ops' variable everywhere
Quoted 7 lines · Simon Glass
Update 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.Signed-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/ae84df4b/attachment.sig>
PATCH v4 13/16 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.478.g8a0d178c01-goog
PATCH v4 13/16 gpio: x86: Drop the deprecated methods in intel_gpio
Quoted 4 lines · Simon Glass
We don't need to implement
direction_input()anddirection_output()anymore. Drop them and useupdate_flags()instead.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/ec39eabc/attachment.sig>
PATCH v4 14/16 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 v3)
Changes in v3:
- Use bit 30 for GPIOD_EXT_DRIVEN
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(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)
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.478.g8a0d178c01-goog
PATCH v4 14/16 gpio: sandbox: Track whether a GPIO is driven
Quoted 8 lines · Simon Glass
Add 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.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/1bf22f5b/attachment.sig>
PATCH v4 15/16 gpio: Define the log category in the uclass
In reply to Simon GlassThis uses log_debug(), etc. but does not define the category. Fix this.
---
(no changes since v3)
Changes in v3:
- Split out the log-category change to a separate patch
drivers/gpio/gpio-uclass.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpio/gpio-uclass.c +2 -0
@@ -3,6 +3,8 @@* Copyright (c) 2013 Google, Inc */ +#define LOG_CATEGORY UCLASS_GPIO +#include <common.h> #include <dm.h> #include <log.h>
Signature · 1 line
2.30.0.478.g8a0d178c01-goog
PATCH v4 15/16 gpio: Define the log category in the uclass
Quoted 3 lines · Simon Glass
This uses
log_debug(), etc. but does not define the category. Fix this.Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/0f4e8685/attachment.sig>
PATCH v4 16/16 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 v3)
Changes in v3:
- Use bits 28, 29 for the new flags
- Assert that count parameter is within range
- Redo digit logic to be easier to understand
- Update function comment to explain the meaning of the digits
- Fix 'compare' typo
arch/sandbox/include/asm/gpio.h | 5 +- drivers/gpio/gpio-uclass.c | 81 +++++++++++++++++++++++++++ drivers/gpio/sandbox.c | 13 +++-- include/asm-generic/gpio.h | 40 ++++++++++++++ test/dm/gpio.c | 98 +++++++++++++++++++++++++++++++++ 5 files changed, 232 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(31)/* external source is high (else low) */ #define GPIOD_EXT_DRIVEN BIT(30)/* external source is driven */ +#define GPIOD_EXT_PULL_UP BIT(29)/* GPIO has external pull-up */ +#define GPIOD_EXT_PULL_DOWN BIT(28)/* GPIO has external pull-down */ -#define GPIOD_SANDBOX_MASK GENMASK(31, 30) +#define GPIOD_EXT_PULL (BIT(28) | BIT(29)) +#define GPIOD_SANDBOX_MASK GENMASK(31, 28)/** * Return the simulated value of a GPIO (used only in sandbox test code)
drivers/gpio/gpio-uclass.c +81 -0
99 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 +40 -0
@@ -497,6 +497,31 @@ 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: +* 0 : external pull-down +* 1 : external pull-up +* 2 : floating +* +* 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, compared 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 *
@@ -714,6 +739,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.478.g8a0d178c01-goog
PATCH v4 16/16 gpio: Add a way to read 3-way strapping pins
Hi Simon,
Quoted 36 lines · Simon Glass
Using 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 caseGPIO_EXT_HIGHprovides 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 flagsOf course the outside source does not really exist in sandbox. We are just modelling it for test purpose.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v3)
Changes in v3:
- Use bits 28, 29 for the new flags
- Assert that count parameter is within range
- Redo digit logic to be easier to understand
- Update function comment to explain the meaning of the digits
- Fix 'compare' typoarch/sandbox/include/asm/gpio.h | 5 +- drivers/gpio/gpio-uclass.c | 81 +++++++++++++++++++++++++++ drivers/gpio/sandbox.c | 13 +++-- include/asm-generic/gpio.h | 40 ++++++++++++++ test/dm/gpio.c | 98 +++++++++++++++++++++++++++++++++ 5 files changed, 232 insertions(+), 5 deletions(-)
(...)
Quoted 13 lines
drivers/gpio/sandbox.c +0
-1@@ -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_...) */
drivers/gpio/sandbox.c int sandbox_gpio_get_value(struct udevice *dev, unsigned offset) · line 84
Quoted 6 lines
drivers/gpio/sandbox.c +1
-1@@ -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 ;
bool here, not int
+ val = !!(state->flags & GPIOD_EXT_HIGH);
drivers/gpio/sandbox.c int sandbox_gpio_get_value(struct udevice *dev, unsigned offset) · line 91
Quoted 9 lines
drivers/gpio/sandbox.c +7
-2-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 ;
bool also
+ val = !!(state->flags & GPIOD_PULL_UP );
drivers/gpio/sandbox.c int sandbox_gpio_get_value(struct udevice *dev, unsigned offset) · line 95
Quoted 4 lines
drivers/gpio/sandbox.c +1
-0+ }return val; }
(...)
Just to be sure that the sandbox gpio value is 0 or 1
with the current code, sandbox_gpio_get_value can return GPIOD_EXT_HIGH or GPIOD_PULL_UP, and it is strange (even if result in int).
with these 2 changes, you can add my? Reviewed-by
Regards
Patrick
PATCH v4 16/16 gpio: Add a way to read 3-way strapping pins
Hi Patrick,
Quoted 87 lines · Patrick DELAUNAY
Hi Simon,
Quoted 36 lines · Simon Glass
Using 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 caseGPIO_EXT_HIGHprovides 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 flagsOf course the outside source does not really exist in sandbox. We are just modelling it for test purpose.
Signed-off-by Simon Glass <[email protected]>---
(no changes since v3)
Changes in v3:
- Use bits 28, 29 for the new flags
- Assert that count parameter is within range
- Redo digit logic to be easier to understand
- Update function comment to explain the meaning of the digits
- Fix 'compare' typoarch/sandbox/include/asm/gpio.h | 5 +- drivers/gpio/gpio-uclass.c | 81 +++++++++++++++++++++++++++ drivers/gpio/sandbox.c | 13 +++-- include/asm-generic/gpio.h | 40 ++++++++++++++ test/dm/gpio.c | 98 +++++++++++++++++++++++++++++++++ 5 files changed, 232 insertions(+), 5 deletions(-)(...)
Quoted 13 lines
drivers/gpio/sandbox.c +0
-1@@ -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_...) */ drivers/gpio/sandbox.c int sandbox_gpio_get_value(struct udevice *dev, unsigned offset) · line 84
Quoted 6 lines
drivers/gpio/sandbox.c +1
-1@@ -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 ;bool here, not int
+ val = !!(state->flags &
GPIOD_EXT_HIGH);drivers/gpio/sandbox.c int sandbox_gpio_get_value(struct udevice *dev, unsigned offset) · line 91
Quoted 9 lines
drivers/gpio/sandbox.c +7
-2-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 ;bool also
+ val = !!(state->flags &
GPIOD_PULL_UP);drivers/gpio/sandbox.c int sandbox_gpio_get_value(struct udevice *dev, unsigned offset) · line 95
Quoted 4 lines
drivers/gpio/sandbox.c +1
-0+ }return val; }
Quoted 6 lines
(...)
Just to be sure that the sandbox gpio value is 0 or 1
with the current code,
sandbox_gpio_get_valuecan returnGPIOD_EXT_HIGHorGPIOD_PULL_UP, and it is strange (even if result in int).
I think that is a hack to work around not having a 'bool' type, but we do have one in U-Boot, so I feel it is better to use it, instead using !!
See the 'bool val;' in that function.
Quoted 3 lines
with these 2 changes, you can add my Reviewed-by
Regards,
Simon
PATCH v4 16/16 gpio: Add a way to read 3-way strapping pins
In reply to Simon GlassQuoted 14 lines · Simon Glass
Using 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 caseGPIO_EXT_HIGHprovides 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
Quoted 4 lines
Of course the outside source does not really exist in sandbox. We are just modelling it for test purpose.
Signed-off-by Simon Glass <[email protected]>
Applied to u-boot/next, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 659 bytes Desc: not available URL: <https://lists.denx.de/pipermail/u-boot/attachments/20210304/3b0bc7e3/attachment.sig>