gpio: add possibility to search for gpio label name
v6 cover gpio: add possibility to search for gpio label name
search for gpio label if gpio name from bankname is not found.
This makes sense on boards with different hardware verions. You can now search for the gpio label name, and can give the gpio a unique name. The real gpio pin number is not needed in board code anymore.
while at it add basic gpio hog test functions in seperate patch.
Travis:
https://travis-ci.org/github/hsdenx/u-boot-test/builds/689908393
Changes in v6:
- add reviewed by from Patrick and Fixes tag
- add Reviewed-by tag from Simon
- add additional comments from Simon:
- remove "default n" in Kconfig for SPL_DM_GPIO_LOOKUP_LABEL
- type of function in same line as the function
- add negativ test, where label is not found
Changes in v5:
- add comment from patrick, update the descriptor flags in _dm_gpio_set_dir_flags() if setting direction was OK.
- add Reviewed-by tag from Simon
Changes in v4:
- new in version 4
- rebased to current master ac14bc4169
- rebased to current master ac14bc4169
Changes in v3:
- add comment from Simon Glass
make this new function configurable through Kconfig option DM_GPIO_LOOKUP_LABEL
Changes in v2:
- add basic gpio hog test functions
- add comment from Simon Glass
move code into seperate function dm_gpio_lookup_label() add test if dm_gpio_lookup_label() works
Heiko Schocher (3):
gpio-uclass.c: save the GPIOD flags also in the gpio descriptor sandbox, test: add test for GPIO_HOG function
gpio: search for gpio label if gpio is not found through bank name
arch/sandbox/dts/test.dts | 20 +++++++++++ configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sandbox_flattree_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + drivers/gpio/Kconfig | 21 ++++++++++++ drivers/gpio/gpio-uclass.c | 54 +++++++++++++++++++++++++++--- test/dm/gpio.c | 32 ++++++++++++++++++ 8 files changed, 127 insertions(+), 4 deletions(-)
Signature · 1 line
2.24.1
PATCH v6 1/3 gpio-uclass.c: save the GPIOD flags also in the gpio descriptor
save the GPIOD_ flags also in the gpio descriptor.
---
Changes in v6:
- add reviewed by from Patrick and Fixes tag
Changes in v5:
- add comment from patrick, update the descriptor flags in _dm_gpio_set_dir_flags() if setting direction was OK.
Changes in v4:
- new in version 4
Changes in v3: None
Changes in v2: None
drivers/gpio/gpio-uclass.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpio/gpio-uclass.c +4 -4
@@ -600,6 +600,10 @@ static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) } } +/* save the flags also in descriptor */ +if (!ret) + desc->flags = flags; +return ret; }
@@ -615,10 +619,6 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) flags |= desc->flags; ret =_dm_gpio_set_dir_flags (desc, flags); -/* update the descriptor flags */ -if (ret) - desc->flags = flags; -return ret; }
Signature · 1 line
2.24.1
PATCH v6 1/3 gpio-uclass.c: save the GPIOD flags also in the gpio descriptor
Quoted 16 lines · Heiko Schocher
save the
GPIOD_flags also in the gpio descriptor.Signed-off-by Heiko Schocher <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>Fixes 788ea834124b ("gpio: add function _dm_gpio_set_dir_flags")---
Changes in v6:
- add reviewed by from Patrick and Fixes tagChanges in v5:
- add comment from patrick, update the descriptor flags in_dm_gpio_set_dir_flags()if setting direction was OK.
Quoted 8 lines
Changes in v4:
- new in version 4Changes in v3: None
Changes in v2: Nonedrivers/gpio/gpio-uclass.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
PATCH v6 1/3 gpio-uclass.c: save the GPIOD flags also in the gpio descriptor
In reply to Heiko SchocherHi Heiko
Quoted 5 lines · Heiko Schocher
save the
GPIOD_flags also in the gpio descriptor.Signed-off-by Heiko Schocher <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>Fixes 788ea834124b ("gpio: add function _dm_gpio_set_dir_flags")
Thanks for this fix, without it the MMC driver of my iMX6 Hummingboard produces "Card did not respond to voltage select!" and does not work.
Quoted 34 lines
---
Changes in v6:
- add reviewed by from Patrick and Fixes tagChanges in v5:
- add comment from patrick, update the descriptor flags in_dm_gpio_set_dir_flags()if setting direction was OK.Changes in v4:
- new in version 4Changes in v3: None
Changes in v2: Nonedrivers/gpio/gpio-uclass.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpio/gpio-uclass.c +4
-0@@ -600,6 +600,10 @@ static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) } } +/* save the flags also in descriptor */ +if (!ret) + desc->flags = flags; +return ret; }
drivers/gpio/gpio-uclass.c int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) · line 624
Quoted 10 lines
drivers/gpio/gpio-uclass.c +0
-4@@ -615,10 +619,6 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) flags |= desc->flags; ret =_dm_gpio_set_dir_flags (desc, flags); -/* update the descriptor flags */ -if (ret) - desc->flags = flags; -return ret; }
Regards,
Walter
PATCH v6 1/3 gpio-uclass.c: save the GPIOD flags also in the gpio descriptor
Quoted 5 lines · Walter Lozano
Hi Heiko
Quoted 2 lines · Heiko Schocher
save the
GPIOD_flags also in the gpio descriptor.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Heiko Schocher <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>Fixes 788ea834124b ("gpio: add function _dm_gpio_set_dir_flags")Thanks for this fix, without it the MMC driver of my iMX6 Hummingboard produces "Card did not respond to voltage select!" and does not work.
Regards,
Walter
Quoted 49 lines
Quoted 35 lines
---
Changes in v6:
- add reviewed by from Patrick and Fixes tagChanges in v5:
- add comment from patrick, update the descriptor flags ?? in_dm_gpio_set_dir_flags()if setting direction was OK.Changes in v4:
- new in version 4Changes in v3: None
Changes in v2: None?
drivers/gpio/gpio-uclass.c| 8 ++++----
? 1 file changed, 4 insertions(+), 4 deletions(-)drivers/gpio/gpio-uclass.c +0
-0@@ -600,6 +600,10 @@ static int _dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags) ????????? } ????? }? +??? /* save the flags also in descriptor */
+??? if (!ret)
+???????desc->flags= flags;
+
????? return ret;
? }
? @@ -615,10 +619,6 @@ intdm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags)Quoted 8 lines
????? flags |=
desc->flags;
????? ret =_dm_gpio_set_dir_flags(desc, flags);
? -??? /* update the descriptor flags */
-??? if (ret)
-???????desc->flags= flags;
-
????? return ret;
? }Regards,
Walter
PATCH v6 1/3 gpio-uclass.c: save the GPIOD flags also in the gpio descriptor
In reply to Heiko SchocherQuoted 7 lines · Heiko Schocher
save the
GPIOD_flags also in the gpio descriptor.Signed-off-by Heiko Schocher <[email protected]>Reviewed-by Patrick Delaunay <[email protected]>Fixes 788ea834124b ("gpio: add function _dm_gpio_set_dir_flags")Reviewed-by Simon Glass <[email protected]>Tested-by Walter Lozano <[email protected]>
Applied to u-boot/master, 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/20200705/aab9978b/attachment.sig>
PATCH v6 2/3 sandbox, test: add test for GPIO_HOG function
In reply to Heiko Schochercurrently gpio hog function is not tested with "ut dm gpio" so add some basic tests for gpio hog functionality.
For this enable GPIO_HOG in sandbox_defconfig, add in DTS some gpio hog entries, and add testcase in "ut dm gpio" command.
---
Changes in v6: None
Changes in v5:
- add Reviewed-by tag from Simon
Changes in v4:
- rebased to current master ac14bc4169
Changes in v3: None
Changes in v2:
- add basic gpio hog test functions
arch/sandbox/dts/test.dts | 20 ++++++++++++++++++++ configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sandbox_flattree_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + test/dm/gpio.c | 23 +++++++++++++++++++++++ 6 files changed, 47 insertions(+)
arch/sandbox/dts/test.dts +20 -0
@@ -343,6 +343,26 @@ #gpio-cells = <1>; gpio-bank-name = "a"; sandbox,gpio-count = <20>; + hog_input_active_low { + gpio-hog; + input; + gpios = <0 GPIO_ACTIVE_LOW>; + }; + hog_input_active_high { + gpio-hog; + input; + gpios = <1 GPIO_ACTIVE_HIGH>; + }; + hog_output_low { + gpio-hog; + output-low; + gpios = <2 GPIO_ACTIVE_HIGH>; + }; + hog_output_high { + gpio-hog; + output-high; + gpios = <3 GPIO_ACTIVE_HIGH>; + }; }; gpio_b: extra-gpios {
configs/sandbox64_defconfig +1 -0
@@ -98,6 +98,7 @@ CONFIG_DM_DEMO_SIMPLE=y CONFIG_DM_DEMO_SHAPE=y CONFIG_BOARD=y CONFIG_BOARD_SANDBOX=y +CONFIG_GPIO_HOG=y CONFIG_PM8916_GPIO=y CONFIG_SANDBOX_GPIO=y CONFIG_I2C_CROS_EC_TUNNEL=y
configs/sandbox_defconfig +1 -0
@@ -115,6 +115,7 @@ CONFIG_BOARD_SANDBOX=y CONFIG_DMA=y CONFIG_DMA_CHANNELS=y CONFIG_SANDBOX_DMA=y +CONFIG_GPIO_HOG=y CONFIG_PM8916_GPIO=y CONFIG_SANDBOX_GPIO=y CONFIG_DM_HWSPINLOCK=y
configs/sandbox_flattree_defconfig +1 -0
@@ -83,6 +83,7 @@ CONFIG_DM_DEMO_SIMPLE=y CONFIG_DM_DEMO_SHAPE=y CONFIG_BOARD=y CONFIG_BOARD_SANDBOX=y +CONFIG_GPIO_HOG=y CONFIG_PM8916_GPIO=y CONFIG_SANDBOX_GPIO=y CONFIG_I2C_CROS_EC_TUNNEL=y
configs/sandbox_spl_defconfig +1 -0
@@ -102,6 +102,7 @@ CONFIG_DM_DEMO_SHAPE=y CONFIG_BOARD=y CONFIG_BOARD_SANDBOX=y CONFIG_SPL_FIRMWARE=y +CONFIG_GPIO_HOG=y CONFIG_PM8916_GPIO=y CONFIG_SANDBOX_GPIO=y CONFIG_I2C_CROS_EC_TUNNEL=y
test/dm/gpio.c +23 -0
@@ -20,6 +20,7 @@ static int dm_test_gpio(struct unit_test_state *uts)unsigned int offset, gpio;struct dm_gpio_ops *ops;struct udevice *dev; +struct gpio_desc *desc;const char *name;int offset_count;char buf[80 ];
@@ -109,6 +110,28 @@ static int dm_test_gpio(struct unit_test_state *uts)ut_asserteq_str ("a" , name);ut_asserteq (20 , offset_count); +/* add gpio hog tests */ +ut_assertok (gpio_hog_lookup_name ("hog_input_active_low" , &desc)); +ut_asserteq (GPIOD_IS_IN |GPIOD_ACTIVE_LOW , desc->flags); +ut_asserteq (0 , desc->offset); +ut_asserteq (1 ,dm_gpio_get_value (desc)); +ut_assertok (gpio_hog_lookup_name ("hog_input_active_high" , &desc)); +ut_asserteq (GPIOD_IS_IN , desc->flags); +ut_asserteq (1 , desc->offset); +ut_asserteq (0 ,dm_gpio_get_value (desc)); +ut_assertok (gpio_hog_lookup_name ("hog_output_low" , &desc)); +ut_asserteq (GPIOD_IS_OUT , desc->flags); +ut_asserteq (2 , desc->offset); +ut_asserteq (0 ,dm_gpio_get_value (desc)); +ut_assertok (dm_gpio_set_value (desc,1 )); +ut_asserteq (1 ,dm_gpio_get_value (desc)); +ut_assertok (gpio_hog_lookup_name ("hog_output_high" , &desc)); +ut_asserteq (GPIOD_IS_OUT , desc->flags); +ut_asserteq (3 , desc->offset); +ut_asserteq (1 ,dm_gpio_get_value (desc)); +ut_assertok (dm_gpio_set_value (desc,0 )); +ut_asserteq (0 ,dm_gpio_get_value (desc)); +return 0 ; }DM_TEST (dm_test_gpio,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.24.1
PATCH v6 2/3 sandbox, test: add test for GPIO_HOG function
Quoted 9 lines · Heiko Schocher
currently gpio hog function is not tested with "ut dm gpio" so add some basic tests for gpio hog functionality.
For this enable
GPIO_HOGinsandbox_defconfig, add in DTS some gpio hog entries, and add testcase in "ut dm gpio" command.Signed-off-by Heiko Schocher <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, 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/20200705/35c58518/attachment.sig>
PATCH v6 3/3 gpio: search for gpio label if gpio is not found through bank name
In reply to Heiko Schocherdm_gpio_lookup_name() searches for a gpio through the bank name. But we have also gpio labels, and it makes sense to search for a gpio also in the labels we have defined, if no gpio is found through the bank name definition.
This is useful for example if you have a wp pin on different gpios on different board versions.
If dm_gpio_lookup_name() searches also for the gpio labels, you can give the gpio an unique label name and search for this label, and do not need to differ between board revisions.
---
Example on the aristainetos board:
=> gpio clear wp_spi_nor.gpio-hog
gpio: pin wp_spi_nor.gpio-hog (gpio 47) value is 0 =>
before this patch, you need to know where your
pin is:
=> gpio clear GPIO2_15
gpio: pin GPIO2_15 (gpio 47) value is 0
=>
travis build:
Changes in v6:
- add Reviewed-by tag from Simon
- add additional comments from Simon:
- remove "default n" in Kconfig for SPL_DM_GPIO_LOOKUP_LABEL
- type of function in same line as the function
- add negativ test, where label is not found
Changes in v5: None
Changes in v4:
- rebased to current master ac14bc4169
Changes in v3:
- add comment from Simon Glass
make this new function configurable through Kconfig option DM_GPIO_LOOKUP_LABEL
Changes in v2:
- add comment from Simon Glass
move code into seperate function dm_gpio_lookup_label() add test if dm_gpio_lookup_label() works
drivers/gpio/Kconfig | 21 +++++++++++++++++ drivers/gpio/gpio-uclass.c | 46 ++++++++++++++++++++++++++++++++++++++ test/dm/gpio.c | 9 ++++++++ 3 files changed, 76 insertions(+)
drivers/gpio/Kconfig +21 -0
@@ -46,6 +46,27 @@ config GPIO_HOG is a mechanism providing automatic GPIO request and config- uration as part of the gpio-controller's driver probe function. +config DM_GPIO_LOOKUP_LABEL + bool "Enable searching for gpio labelnames" + depends on DM_GPIO + default y + help + This option enables searching for gpio names in + the defined gpio labels, if the search for the + gpio bank name failed. This makes sense if you use + different gpios on different hardware versions + for the same functionality in board code. + +config SPL_DM_GPIO_LOOKUP_LABEL + bool "Enable searching for gpio labelnames" + depends on DM_GPIO && SPL_DM && SPL_GPIO_SUPPORT + help + This option enables searching for gpio names in + the defined gpio labels, if the search for the + gpio bank name failed. This makes sense if you use + different gpios on different hardware versions + for the same functionality in board code. + config ALTERA_PIO bool "Altera PIO driver" depends on DM_GPIO
drivers/gpio/gpio-uclass.c +46 -0
58 lines not on this page · raw message
test/dm/gpio.c +9 -0
@@ -132,6 +132,15 @@ static int dm_test_gpio(struct unit_test_state *uts)ut_assertok (dm_gpio_set_value (desc,0 ));ut_asserteq (0 ,dm_gpio_get_value (desc)); +/* Check if lookup for labels work */ +ut_assertok (gpio_lookup_name ("hog_input_active_low" , &dev, &offset, + &gpio)); +ut_asserteq_str (dev->name,"base-gpios" ); +ut_asserteq (0 , offset); +ut_asserteq (CONFIG_SANDBOX_GPIO_COUNT +0 , gpio); +ut_assert (gpio_lookup_name ("hog_not_exist" , &dev, &offset, + &gpio)); +return 0 ; }DM_TEST (dm_test_gpio,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.24.1
PATCH v6 3/3 gpio: search for gpio label if gpio is not found through bank name
Quoted 9 lines · Heiko Schocher
dm_gpio_lookup_name()searches for a gpio through the bank name. But we have also gpio labels, and it makes sense to search for a gpio also in the labels we have defined, if no gpio is found through the bank name definition.This is useful for example if you have a wp pin on different gpios on different board versions.
Quoted 7 lines
If
dm_gpio_lookup_name()searches also for the gpio labels, you can give the gpio an unique label name and search for this label, and do not need to differ between board revisions.Signed-off-by Heiko Schocher <[email protected]>Reviewed-by Simon Glass <[email protected]>
Applied to u-boot/master, 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/20200707/5fa1f5d1/attachment.sig>
PATCH v6 3/3 gpio: search for gpio label if gpio is not found through bank name
In reply to Heiko SchocherHi Heiko,
p? 22. 5. 2020 v 11:10 odes?latel Heiko Schocher <[email protected]> napsal:
Quoted 25 lines
dm_gpio_lookup_name()searches for a gpio through the bank name. But we have also gpio labels, and it makes sense to search for a gpio also in the labels we have defined, if no gpio is found through the bank name definition.This is useful for example if you have a wp pin on different gpios on different board versions.
If
dm_gpio_lookup_name()searches also for the gpio labels, you can give the gpio an unique label name and search for this label, and do not need to differ between board revisions.Signed-off-by Heiko Schocher <[email protected]>Reviewed-by Simon Glass <[email protected]>---
Example on the aristainetos board:
=> gpio clear wp_spi_nor.gpio-hog
gpio: pin wp_spi_nor.gpio-hog (gpio 47) value is 0 =>
Quoted 6 lines
before this patch, you need to know where your
pin is:=> gpio clear
GPIO2_15
gpio: pinGPIO2_15(gpio 47) value is 0
=>
I spotted this patch and I am curious if you have thought about also supporting gpio-line-names.
Thanks,
Michal
PATCH v6 3/3 gpio: search for gpio label if gpio is not found through bank name
Hi Michal,
Am 20.07.2020 um 10:30 schrieb Michal Simek:
Quoted 31 lines
Hi Heiko,
p? 22. 5. 2020 v 11:10 odes?latel Heiko Schocher <[email protected]> napsal:
Quoted 28 lines
dm_gpio_lookup_name()searches for a gpio through the bank name. But we have also gpio labels, and it makes sense to search for a gpio also in the labels we have defined, if no gpio is found through the bank name definition.This is useful for example if you have a wp pin on different gpios on different board versions.
If
dm_gpio_lookup_name()searches also for the gpio labels, you can give the gpio an unique label name and search for this label, and do not need to differ between board revisions.Signed-off-by Heiko Schocher <[email protected]>Reviewed-by Simon Glass <[email protected]>---
Example on the aristainetos board:
=> gpio clear wp_spi_nor.gpio-hog
gpio: pin wp_spi_nor.gpio-hog (gpio 47) value is 0 =>before this patch, you need to know where your
pin is:
Quoted 6 lines
Quoted 3 lines
=> gpio clear
GPIO2_15
gpio: pinGPIO2_15(gpio 47) value is 0
=>I spotted this patch and I am curious if you have thought about also supporting gpio-line-names.
Yes, that would be a good extension!
searching for "gpio-line-names" in u-boot source shows only an entry in
./doc/device-tree-bindings/gpio/gpio.txt
and some DTS files in arch/arm
but no driver code, which handles the property, so there is some work to do.
Currently I have no project (and time) to give this a chance...
But if the code, which handle "gpio-line-names" saves the name in "struct gpio_dev_priv name", DM_GPIO_LOOKUP_LABEL based code should work with it.
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
PATCH v6 3/3 gpio: search for gpio label if gpio is not found through bank name
Quoted 49 lines · Heiko Schocher
Hi Michal,
Am 20.07.2020 um 10:30 schrieb Michal Simek:
Quoted 31 lines
Hi Heiko,
p? 22. 5. 2020 v 11:10 odes?latel Heiko Schocher <[email protected]> napsal:
Quoted 28 lines
dm_gpio_lookup_name()searches for a gpio through the bank name. But we have also gpio labels, and it makes sense to search for a gpio also in the labels we have defined, if no gpio is found through the bank name definition.This is useful for example if you have a wp pin on different gpios on different board versions.
If
dm_gpio_lookup_name()searches also for the gpio labels, you can give the gpio an unique label name and search for this label, and do not need to differ between board revisions.Signed-off-by Heiko Schocher <[email protected]>Reviewed-by Simon Glass <[email protected]>---
Example on the aristainetos board:
=> gpio clear wp_spi_nor.gpio-hog
gpio: pin wp_spi_nor.gpio-hog (gpio 47) value is 0 =>before this patch, you need to know where your
pin is:Quoted 6 lines
Quoted 3 lines
=> gpio clear
GPIO2_15
gpio: pinGPIO2_15(gpio 47) value is 0
=>I spotted this patch and I am curious if you have thought about also supporting gpio-line-names.
Yes, that would be a good extension!
searching for "gpio-line-names" in u-boot source shows only an entry in
./doc/device-tree-bindings/gpio/gpio.txtand some DTS files in
arch/arm
Quoted 8 lines
but no driver code, which handles the property, so there is some work to do.
Currently I have no project (and time) to give this a chance...
But if the code, which handle "gpio-line-names" saves the name in "struct
gpio_dev_privname",DM_GPIO_LOOKUP_LABELbased code should work with it.
I have sent a patch for it. Please take a look.
Thanks,
Michal