gpio: add gpio-hog support
Subsystems (2)
PATCH v4 1/1 gpio: add gpio-hog support
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:doc/device-tree-bindings/gpio/gpio.txt
---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419
Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use new UCLASS_NOP
hog detection + DT parsing in gpio_post_bind() .... info saved in platdata gpio configuration for hog (request and set_dir) => probe function
Changes in v3:
- probe now all gpio devices with gpio-hogs
from board_r before board_late_init() call
or if someone wants to access gpio-hog
based gpios with gpio_hog_lookup_name()
This is needed, because we cannot be sure,
if a gpio device which contains gpio-hogs
is probed.
- add line-name property as Michal recommended
- renamed gpio_priv_one into gpio_priv_one_hog
and protected through CONFIG_DM_GPIO_HOG
Changes in v2:
- move gpio_hog() call from post_probe() to post_bind() call. Check if current gpio device has gpio-hog definitions, if so, probe it.
common/board_r.c | 6 + doc/device-tree-bindings/gpio/gpio.txt | 55 ++++++++ drivers/gpio/Kconfig | 10 ++ drivers/gpio/gpio-uclass.c | 181 ++++++++++++++++++++++--- include/asm-generic/gpio.h | 32 +++++ 5 files changed, 268 insertions(+), 16 deletions(-)
common/board_r.c +6 -0
@@ -49,6 +49,9 @@#include <linux/err.h> #include <efi_loader.h> #include <wdt.h> +#if defined(CONFIG_DM_GPIO_HOG ) +#include <asm/gpio.h> +#endif DECLARE_GLOBAL_DATA_PTR ;
@@ -796,6 +799,9 @@ static init_fnc_t init_sequence_r[] = {#ifdef CONFIG_CMD_NET initr_ethaddr,#endif +#if defined(CONFIG_DM_GPIO_HOG ) + gpio_hog_probe_all, +#endif #ifdef CONFIG_BOARD_LATE_INIT board_late_init,#endif
doc/device-tree-bindings/gpio/gpio.txt +55 -0
58 lines not on this page · raw message
drivers/gpio/Kconfig +10 -0
@@ -14,6 +14,16 @@ config DM_GPIO particular GPIOs that they provide. The uclass interface is defined in include/asm-generic/gpio.h. +config DM_GPIO_HOG + bool "Enable GPIO hog support" + depends on DM_GPIO + default n + help + Enable gpio hog support + The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. + config ALTERA_PIO bool "Altera PIO driver" depends on DM_GPIO
drivers/gpio/gpio-uclass.c +165 -16
249 lines not on this page · raw message
include/asm-generic/gpio.h +32 -0
@@ -348,6 +348,22 @@ const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);*/ int dm_gpio_lookup_name (const char *name,struct gpio_desc *desc); +/** +* gpio_hog_lookup_name() - Look up a named GPIO and return the gpio descr. +* +* @name: Name to look up +* @return: Returns gpio_desc for gpio +*/ +struct gpio_desc *gpio_hog_lookup_name (const char *name); + +/** +* gpio_hog_probe_all() - probe all gpio devices with +* gpio-hog subnodes. +* +* @return: Returns return value from device_probe() +*/ +int gpio_hog_probe_all (void ); +/** * gpio_lookup_name - Look up a GPIO name and return its details *
@@ -503,6 +519,22 @@ int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, struct gpio_desc *desc_list, int max_count, int flags); +/** +* gpio_dev_request_index() - request single GPIO from gpio device +* +* @dev: GPIO device +* @nodename: Name of node +* @list_name: Name of GPIO list (e.g. "board-id-gpios") +* @index: Index number of the GPIO in that list use request (0=first) +* @flags: GPIOD_* flags +* @dtflags: GPIO flags read from DT +* @desc: GPIO descriotor filled from this function +* @return: return value from gpio_request_tail() +*/ +int gpio_dev_request_index (struct udevice *dev,const char *nodename, +char *list_name,int index,int flags, +int dtflags,struct gpio_desc *desc); +/** * dm_gpio_free() - Free a single GPIO *
Signature · 1 line
2.21.0
PATCH v4 1/1 gpio: add gpio-hog support
Quoted 456 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe functionChanges in v3:
- probe now all gpio devices with gpio-hogs
fromboard_rbeforeboard_late_init()call
or if someone wants to access gpio-hog
based gpios withgpio_hog_lookup_name()
This is needed, because we cannot be sure,
if a gpio device which contains gpio-hogs
is probed.
- add line-name property as Michal recommended
- renamedgpio_priv_oneintogpio_priv_one_hog
and protected throughCONFIG_DM_GPIO_HOGChanges in v2:
- movegpio_hog()call frompost_probe()topost_bind()call. Check if current gpio device has gpio-hog definitions, if so, probe it.common/board_r.c | 6 + doc/device-tree-bindings/gpio/gpio.txt | 55 ++++++++ drivers/gpio/Kconfig | 10 ++ drivers/gpio/gpio-uclass.c | 181 ++++++++++++++++++++++--- include/asm-generic/gpio.h | 32 +++++ 5 files changed, 268 insertions(+), 16 deletions(-)common/board_r.c +6
-0@@ -49,6 +49,9 @@#include <linux/err.h> #include <efi_loader.h> #include <wdt.h> +#if defined(CONFIG_DM_GPIO_HOG ) +#include <asm/gpio.h> +#endif DECLARE_GLOBAL_DATA_PTR ;@@ -796,6 +799,9 @@ static init_fnc_t init_sequence_r[] = {#ifdef CONFIG_CMD_NET initr_ethaddr,#endif +#if defined(CONFIG_DM_GPIO_HOG ) + gpio_hog_probe_all, +#endif #ifdef CONFIG_BOARD_LATE_INIT board_late_init,#endif doc/device-tree-bindings/gpio/gpio.txt +55
-0@@ -210,3 +210,58 @@ Example 2: Here, three GPIO ranges are defined wrt. two pin controllers. pinctrl1 GPIO ranges are defined using pin numbers whereas the GPIO ranges wrt. pinctrl2 are named "foo" and "bar". + +3) GPIO hog definitions +----------------------- + +The GPIO chip may contain GPIO hog definitions. GPIO hogging is a mechanism +providing automatic GPIO request and configuration as part of the +gpio-controller's driver probe function. + +Each GPIO hog definition is represented as a child node of the GPIO controller. +Required properties: +- gpio-hog: A property specifying that this child node represents a GPIO hog. +- gpios: Store the GPIO information (id, flags) for the GPIO to + affect. + + ! Not yet support more than one gpio ! + +Only one of the following properties scanned in the order shown below. +- input: A property specifying to set the GPIO direction as input. +- output-low A property specifying to set the GPIO direction as output with + the value low. +- output-high A property specifying to set the GPIO direction as output with + the value high. + +Optional properties: +- line-name: The GPIO label name. If not present the node name is used. + +Example: + + tca6416 at 20 { + compatible = "ti,tca6416"; + reg = <0x20>; + #gpio-cells = <2>; + gpio-controller; + + env_reset { + gpio-hog; + input; + gpios = <6 GPIO_ACTIVE_LOW>; + }; + boot_rescue { + gpio-hog; + input; + gpios = <7 GPIO_ACTIVE_LOW>; + }; + }; + +For the above Example you can than access the gpio in your boardcode +with: + + desc = gpio_hog_lookup_name("boot_rescue.gpio-hog"); + if (desc) { + if (dm_gpio_get_value(desc)) + printf("\nBooting into Rescue System\n"); + else + printf("\nBoot normal\n");drivers/gpio/Kconfig +10
-0@@ -14,6 +14,16 @@ config DM_GPIO particular GPIOs that they provide. The uclass interface is defined in include/asm-generic/gpio.h. +config DM_GPIO_HOG + bool "Enable GPIO hog support" + depends on DM_GPIO + default n + help + Enable gpio hog support + The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. + config ALTERA_PIO bool "Altera PIO driver" depends on DM_GPIOdrivers/gpio/gpio-uclass.c +165
-16@@ -5,6 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> #include <dt-bindings/gpio/gpio.h> #include <errno.h> #include <fdtdec.h> @@ -141,6 +144,118 @@ static int gpio_find_and_xlate(struct gpio_desc *desc,return gpio_xlate_offs_flags (desc->dev, desc, args); } +#if defined(CONFIG_DM_GPIO_HOG ) + +struct gpio_hog_priv { +struct gpio_desc gpiod; +}; + +struct gpio_hog_data { +int gpiod_flags; +int value; +u32 val[2 ]; +}; + +static int gpio_hog_ofdata_to_platdata (struct udevice *dev) +{ +struct gpio_hog_data *plat =dev_get_platdata (dev); +const char *nodename; +int ret; + + plat->value =0 ; +if (dev_read_bool (dev,"input" )) { + plat->gpiod_flags =GPIOD_IS_IN ; + }else if (dev_read_bool (dev,"output-high" )) { + plat->value =1 ; + plat->gpiod_flags =GPIOD_IS_OUT ; + }else if (dev_read_bool (dev,"output-low" )) { + plat->gpiod_flags =GPIOD_IS_OUT ; + }else { +printf ("%s: missing gpio-hog state.\n" , __func__); +return -EINVAL ; + } + ret =dev_read_u32_array (dev,"gpios" , plat->val,2 ); +if (ret) { +printf ("%s: wrong gpios property, 2 values needed %d\n" , + __func__, ret); +return ret; + } + nodename =dev_read_string (dev,"line-name" ); +if (!nodename) + nodename =dev_read_name (dev); +device_set_name (dev, nodename); + +return 0 ; +} + +static int gpio_hog_probe (struct udevice *dev) +{ +struct gpio_hog_data *plat =dev_get_platdata (dev); +struct gpio_hog_priv *priv =dev_get_priv (dev); +int ret; + + ret =gpio_dev_request_index (dev->parent, dev->name,"gpio-hog" , + plat->val[0 ], plat->gpiod_flags, + plat->val[1 ], &priv->gpiod); +if (ret <0 ) { +debug ("%s: node %s could not get gpio.\n" , __func__, + dev->name); +return ret; + } +dm_gpio_set_dir (&priv->gpiod); +if (plat->gpiod_flags ==GPIOD_IS_OUT ) +dm_gpio_set_value (&priv->gpiod, plat->value); + +return 0 ; +} + +int gpio_hog_probe_all (void ) +{ +struct udevice *dev; +int ret; + +for (uclass_first_device (UCLASS_NOP , &dev); + dev; +uclass_find_next_device (&dev)) { +if (dev->driver ==DM_GET_DRIVER (gpio_hog)) { + ret =device_probe (dev); +if (ret) +return ret; + } + } + +return 0 ; +} + +struct gpio_desc *gpio_hog_lookup_name (const char *name) +{ +struct udevice *dev; + +gpio_hog_probe_all (); +if (!uclass_get_device_by_name (UCLASS_NOP , name, &dev)) { +struct gpio_hog_priv *priv =dev_get_priv (dev); + +return &priv->gpiod; + } + +return NULL ; +} + +U_BOOT_DRIVER (gpio_hog) = { + .name ="gpio_hog" , + .id =UCLASS_NOP , + .ofdata_to_platdata = gpio_hog_ofdata_to_platdata, + .probe = gpio_hog_probe, + .priv_auto_alloc_size =sizeof (struct gpio_hog_priv ), + .platdata_auto_alloc_size =sizeof (struct gpio_hog_data ), +}; +#else +struct gpio_desc *gpio_hog_lookup_name (const char *name) +{ +return NULL ; +} +#endif +int dm_gpio_request (struct gpio_desc *desc,const char *label) {struct udevice *dev = desc->dev;@@ -640,22 +755,25 @@ int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count)return vector; } -static int gpio_request_tail (int ret,ofnode node, +static int gpio_request_tail (int ret,const char *nodename,struct ofnode_phandle_args *args,const char *list_name,int index, -struct gpio_desc *desc,int flags,bool add_index) +struct gpio_desc *desc,int flags, +bool add_index,struct udevice *dev) { - desc->dev =NULL ; + desc->dev = dev; desc->offset =0 ; desc->flags =0 ;if (ret) goto err; - ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, - &desc->dev); -if (ret) { -debug ("%s: uclass_get_device_by_ofnode failed\n" , __func__); - goto err; +if (!desc->dev) { + ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, + &desc->dev); +if (ret) { +debug ("%s: uclass_get_device_by_ofnode failed\n" , __func__); + goto err; + } } ret =gpio_find_and_xlate (desc, args);if (ret) {@@ -663,8 +781,7 @@ static int gpio_request_tail(int ret, ofnode node, goto err; } ret =dm_gpio_requestf (desc, add_index ?"%s.%s%d" :"%s.%s" , -ofnode_get_name (node), - list_name, index); + nodename, list_name, index);if (ret) {debug ("%s: dm_gpio_requestf failed\n" , __func__); goto err;@@ -678,7 +795,7 @@ static int gpio_request_tail(int ret, ofnode node,return 0 ; err:debug ("%s: Node '%s', property '%s', failed to request GPIO index %d: %d\n" , - __func__,ofnode_get_name (node), list_name, index, ret); + __func__, nodename, list_name, index, ret);return ret; }@@ -692,8 +809,8 @@ static int _gpio_request_by_name_nodev(ofnode node, const char *list_name, ret =ofnode_parse_phandle_with_args (node, list_name,"#gpio-cells" ,0 , index, &args); -return gpio_request_tail (ret, node, &args, list_name, index, desc, - flags, add_index); +return gpio_request_tail (ret,ofnode_get_name (node), &args, list_name, + index, desc, flags, add_index,NULL ); } int gpio_request_by_name_nodev(ofnode node, const char *list_name, int index,@@ -707,13 +824,14 @@ int gpio_request_by_name(struct udevice *dev, const char *list_name, int index, struct gpio_desc *desc, int flags) {struct ofnode_phandle_args args; +ofnode node;int ret; ret =dev_read_phandle_with_args (dev, list_name,"#gpio-cells" ,0 , index, &args); - -return gpio_request_tail (ret,dev_ofnode (dev), &args, list_name, - index, desc, flags, index >0 ); + node =dev_ofnode (dev); +return gpio_request_tail (ret,ofnode_get_name (node), &args, list_name, + index, desc, flags, index >0 ,NULL ); } int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,@@ -854,8 +972,28 @@ static int gpio_pre_remove(struct udevice *dev)return gpio_renumber (dev); } +int gpio_dev_request_index (struct udevice *dev,const char *nodename, +char *list_name,int index,int flags, +int dtflags,struct gpio_desc *desc) +{ +struct ofnode_phandle_args args; + + args.node =ofnode_null (); + args.args_count =2 ; + args.args[0 ] = index; + args.args[1 ] = dtflags; + +return gpio_request_tail (0 , nodename, &args, list_name, index, desc, + flags,0 , dev); +} +static int gpio_post_bind (struct udevice *dev) { +#if defined(CONFIG_DM_GPIO_HOG ) +struct udevice *child; +ofnode node; +#endif +#if defined(CONFIG_NEEDS_MANUAL_RELOC )struct dm_gpio_ops *ops = (struct dm_gpio_ops *)device_get_ops (dev);static int reloc_done;@@ -885,6 +1023,17 @@ static int gpio_post_bind(struct udevice *dev) reloc_done++; }#endif + +#if defined(CONFIG_DM_GPIO_HOG ) +dev_for_each_subnode (node, dev) { +if (ofnode_read_bool (node,"gpio-hog" )) { +const char *name =ofnode_get_name (node); + +device_bind_driver_to_node (dev,"gpio_hog" , name, + node, &child); + } + } +#endif return 0 ; }include/asm-generic/gpio.h +25
-0@@ -348,6 +348,22 @@ const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);*/ int dm_gpio_lookup_name (const char *name,struct gpio_desc *desc); +/** +* gpio_hog_lookup_name() - Look up a named GPIO and return the gpio descr. +* +* @name: Name to look up +* @return: Returns gpio_desc for gpio +*/ +struct gpio_desc *gpio_hog_lookup_name (const char *name); + +/** +* gpio_hog_probe_all() - probe all gpio devices with +* gpio-hog subnodes. +* +* @return: Returns return value from device_probe() +*/ +int gpio_hog_probe_all (void ); +/** * gpio_lookup_name - Look up a GPIO name and return its details * @@ -503,6 +519,22 @@ int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, struct gpio_desc *desc_list, int max_count, int flags); +/** +* gpio_dev_request_index() - request single GPIO from gpio device +* +* @dev: GPIO device +* @nodename: Name of node +* @list_name: Name of GPIO list (e.g. "board-id-gpios") +* @index: Index number of the GPIO in that list use request (0=first) +* @flags: GPIOD_* flags +* @dtflags: GPIO flags read from DT
include/asm-generic/gpio.h int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, · line 540
Quoted 10 lines
include/asm-generic/gpio.h +7
-0+* @desc: GPIO descriotor filled from this function +* @return: return value from gpio_request_tail() +*/ +int gpio_dev_request_index (struct udevice *dev,const char *nodename, +char *list_name,int index,int flags, +int dtflags,struct gpio_desc *desc); +/** * dm_gpio_free() - Free a single GPIO *
Thanks,
Michal
PATCH v4 1/1 gpio: add gpio-hog support
Hi Mickael
Quoted 63 lines
Subject: Re: [PATCH v4] gpio: add gpio-hog support
Importance: HighQuoted 59 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe functionChanges in v3:
- probe now all gpio devices with gpio-hogs
fromboard_rbeforeboard_late_init()call
or if someone wants to access gpio-hog
based gpios withgpio_hog_lookup_name()
This is needed, because we cannot be sure,
if a gpio device which contains gpio-hogs
is probed.
- add line-name property as Michal recommended
- renamedgpio_priv_oneintogpio_priv_one_hog
and protected throughCONFIG_DM_GPIO_HOGChanges in v2:
- movegpio_hog()call frompost_probe()topost_bind()call. Check if current gpio device has gpio-hog definitions, if so, probe it.common/board_r.c | 6 + doc/device-tree-bindings/gpio/gpio.txt | 55 ++++++++ drivers/gpio/Kconfig | 10 ++ drivers/gpio/gpio-uclass.c | 181 ++++++++++++++++++++++--- include/asm-generic/gpio.h | 32 +++++ 5 files changed, 268 insertions(+), 16 deletions(-)common/board_r.c index renamed from common/board_r.c +0
-0
150e8cd424..507da4c74a100644common/board_r.c +3
-0@@ -49,6 +49,9 @@#include <linux/err.h> #include <efi_loader.h> #include <wdt.h> +#if defined(CONFIG_DM_GPIO_HOG ) +#include <asm/gpio.h> +#endif DECLARE_GLOBAL_DATA_PTR ;
Quoted 7 lines
common/board_r.c static init_fnc_t init_sequence_r[] = { · line 804
Quoted 7 lines
common/board_r.c +0
-0@@ -796,6 +799,9 @@ static init_fnc_t init_sequence_r[] = { #ifdef
CONFIG_CMD_NETcommon/board_r.c +3
-0initr_ethaddr,#endif +#if defined(CONFIG_DM_GPIO_HOG ) + gpio_hog_probe_all, +#endif
Any reason to have hog at this place ?
Before board_late_init....
I expect more before board_init() for my future use-case, to replace the current (dirty) implementation with pinctrl-0
#if defined(CONFIG_WDT)
initr_watchdog,
#endif
+#if defined(CONFIG_DM_GPIO_HOG)
+ gpio_hog_probe_all,
+#endif
#if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || defined(CONFIG_RISCV) || \
defined(CONFIG_SANDBOX)
board_init, /* Setup chipselects */
#endif
In my device tree I have :
stmfx: stmfx at 42 {
compatible = "st,stmfx-0300";
reg = <0x42>;
interrupts = <8 IRQ_TYPE_EDGE_RISING>;
interrupt-parent = <&gpioi>;
vdd-supply = <&v3v3>;
stmfx_pinctrl: stmfx-pin-controller {
compatible = "st,stmfx-0300-pinctrl";
gpio-controller;
#gpio-cells = <2>;
interrupt-controller;
#interrupt-cells = <2>;
gpio-ranges = <&stmfx_pinctrl 0 0 24>;
pinctrl-names = "default";
pinctrl-0 = <&hog_pins>;
hog_pins: hog {
pins = "gpio14";
drive-push-pull;
bias-pull-down;
};
};And in board, I force probe to configure HOG....before to initialize the DISPLAY, so in
./board/st/stm32mp1/stm32mp1.c : board _init()
/* board dependent setup after realloc */
int board_init(void)
{
.....
/* probe all PINCTRL for hog */
for (uclass_first_device(UCLASS_PINCTRL, &dev);
dev;
uclass_next_device(&dev)) {
pr_debug("probe pincontrol = %s\n", dev->name);
}Or you can let each board choose when call the function
as it is already done for other function as regulators_enable_boot_on() So don't add it in init_sequence_r[] / board_r.c ?...
Anyway it is not blocking for me, it just a question.
Quoted 404 lines
Quoted 12 lines
#ifdef
CONFIG_BOARD_LATE_INITcommon/board_r.c +0
-0board_late_init,#endif doc/device-tree-bindings/gpio/gpio.txt +0
-0@@ -210,3 +210,58 @@ Example 2: Here, three GPIO ranges are defined wrt. two pin controllers.pinctrl1 GPIO ranges are defined using pin numbers whereas the GPIO ranges wrt. pinctrl2 are named "foo" and "bar".
doc/device-tree-bindings/gpio/gpio.txt Example 2:
Quoted 9 lines
doc/device-tree-bindings/gpio/gpio.txt +9
-0+ +3) GPIO hog definitions +----------------------- + +The GPIO chip may contain GPIO hog definitions. GPIO hogging is a +mechanism providing automatic GPIO request and configuration as part +of the gpio-controller's driver probe function. + +Each GPIO hog definition is represented as a child node of the GPIOcontroller.
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc
Quoted 82 lines
doc/device-tree-bindings/gpio/gpio.txt +46
-0+Required properties: +- gpio-hog: A property specifying that this child node represents a GPIO hog. +- gpios: Store the GPIO information (id, flags) for the GPIO to + affect. + + ! Not yet support more than one gpio ! + +Only one of the following properties scanned in the order shown below. +- input: A property specifying to set the GPIO direction as input. +- output-low A property specifying to set the GPIO direction as output with + the value low. +- output-high A property specifying to set the GPIO direction as output with + the value high. + +Optional properties: +- line-name: The GPIO label name. If not present the node name is used. + +Example: + + tca6416 at 20 { + compatible = "ti,tca6416"; + reg = <0x20>; + #gpio-cells = <2>; + gpio-controller; + + env_reset { + gpio-hog; + input; + gpios = <6 GPIO_ACTIVE_LOW>; + }; + boot_rescue { + gpio-hog; + input; + gpios = <7 GPIO_ACTIVE_LOW>; + }; + }; + +For the above Example you can than access the gpio in your boardcode +with: + + desc = gpio_hog_lookup_name("boot_rescue.gpio-hog"); + if (desc) { + if (dm_gpio_get_value(desc)) + printf("\nBooting into Rescue System\n"); + else + printf("\nBoot normal\n");drivers/gpio/Kconfig index renamed from drivers/gpio/Kconfig +0
-0
e36a8abc42..fa1c99700f100644drivers/gpio/Kconfig +10
-0@@ -14,6 +14,16 @@ config DM_GPIO particular GPIOs that they provide. The uclass interface is defined in include/asm-generic/gpio.h. +config DM_GPIO_HOG + bool "Enable GPIO hog support" + depends on DM_GPIO + default n + help + Enable gpio hog support + The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. + config ALTERA_PIO bool "Altera PIO driver" depends on DM_GPIOdrivers/gpio/gpio-uclass.c +3
-0@@ -5,6 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> #include <dt-bindings/gpio/gpio.h> #include <errno.h> #include <fdtdec.h> @@ -141,6 +144,118 @@ static int gpio_find_and_xlate(struct gpio_desc*desc,
drivers/gpio/gpio-uclass.c int dm_gpio_get_values_as_int(const struct
Quoted 111 lines
drivers/gpio/gpio-uclass.c +106
-0return gpio_xlate_offs_flags (desc->dev, desc, args); } +#if defined(CONFIG_DM_GPIO_HOG ) + +struct gpio_hog_priv { +struct gpio_desc gpiod; +}; + +struct gpio_hog_data { +int gpiod_flags; +int value; +u32 val[2 ]; +}; + +static int gpio_hog_ofdata_to_platdata (struct udevice *dev) { +struct gpio_hog_data *plat =dev_get_platdata (dev); +const char *nodename; +int ret; + + plat->value =0 ; +if (dev_read_bool (dev,"input" )) { + plat->gpiod_flags =GPIOD_IS_IN ; + }else if (dev_read_bool (dev,"output-high" )) { + plat->value =1 ; + plat->gpiod_flags =GPIOD_IS_OUT ; + }else if (dev_read_bool (dev,"output-low" )) { + plat->gpiod_flags =GPIOD_IS_OUT ; + }else { +printf ("%s: missing gpio-hog state.\n" , __func__); +return -EINVAL ; + } + ret =dev_read_u32_array (dev,"gpios" , plat->val,2 ); +if (ret) { +printf ("%s: wrong gpios property, 2 values needed %d\n" , + __func__, ret); +return ret; + } + nodename =dev_read_string (dev,"line-name" ); +if (!nodename) + nodename =dev_read_name (dev); +device_set_name (dev, nodename); + +return 0 ; +} + +static int gpio_hog_probe (struct udevice *dev) { +struct gpio_hog_data *plat =dev_get_platdata (dev); +struct gpio_hog_priv *priv =dev_get_priv (dev); +int ret; + + ret =gpio_dev_request_index (dev->parent, dev->name,"gpio-hog" , + plat->val[0 ], plat->gpiod_flags, + plat->val[1 ], &priv->gpiod); +if (ret <0 ) { +debug ("%s: node %s could not get gpio.\n" , __func__, + dev->name); +return ret; + } +dm_gpio_set_dir (&priv->gpiod); +if (plat->gpiod_flags ==GPIOD_IS_OUT ) +dm_gpio_set_value (&priv->gpiod, plat->value); + +return 0 ; +} + +int gpio_hog_probe_all (void ) +{ +struct udevice *dev; +int ret; + +for (uclass_first_device (UCLASS_NOP , &dev); + dev; +uclass_find_next_device (&dev)) { +if (dev->driver ==DM_GET_DRIVER (gpio_hog)) { + ret =device_probe (dev); +if (ret) +return ret; + } + } + +return 0 ; +} + +struct gpio_desc *gpio_hog_lookup_name (const char *name) { +struct udevice *dev; + +gpio_hog_probe_all (); +if (!uclass_get_device_by_name (UCLASS_NOP , name, &dev)) { +struct gpio_hog_priv *priv =dev_get_priv (dev); + +return &priv->gpiod; + } + +return NULL ; +} + +U_BOOT_DRIVER (gpio_hog) = { + .name ="gpio_hog" , + .id =UCLASS_NOP , + .ofdata_to_platdata = gpio_hog_ofdata_to_platdata, + .probe = gpio_hog_probe, + .priv_auto_alloc_size =sizeof (struct gpio_hog_priv ), + .platdata_auto_alloc_size =sizeof (struct gpio_hog_data ), };#else +struct gpio_desc *gpio_hog_lookup_name (const char *name) { +return NULL ; +} +#endif +int dm_gpio_request (struct gpio_desc *desc,const char *label) {struct udevice *dev = desc->dev;@@ -640,22 +755,25 @@ int dm_gpio_get_values_as_int(const struct
gpio_desc*desc_list, int count)Quoted 18 lines
drivers/gpio/gpio-uclass.c +4
-3return vector; } -static int gpio_request_tail (int ret,ofnode node, +static int gpio_request_tail (int ret,const char *nodename,struct ofnode_phandle_args *args,const char *list_name,int index, -struct gpio_desc *desc,int flags,bool add_index) +struct gpio_desc *desc,int flags, +bool add_index,struct udevice *dev) { - desc->dev =NULL ; + desc->dev = dev; desc->offset =0 ; desc->flags =0 ;if (ret) goto err;drivers/gpio/gpio-uclass.c int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count)
Quoted 10 lines
drivers/gpio/gpio-uclass.c +5
-5- ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, - &desc->dev); -if (ret) { -debug ("%s: uclass_get_device_by_ofnode failed\n" , __func__); - goto err; +if (!desc->dev) { + ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, + &desc->dev); +if (ret) { + debug("%s: uclass_get_device_by_ofnode failed\n",
__func__);Quoted 16 lines
drivers/gpio/gpio-uclass.c +3
-2+ goto err; + } } ret =gpio_find_and_xlate (desc, args);if (ret) {@@ -663,8 +781,7 @@ static int gpio_request_tail(int ret, ofnode node, goto err; } ret =dm_gpio_requestf (desc, add_index ?"%s.%s%d" :"%s.%s" , -ofnode_get_name (node), - list_name, index); + nodename, list_name, index);if (ret) {debug ("%s: dm_gpio_requestf failed\n" , __func__); goto err;drivers/gpio/gpio-uclass.c static int gpio_request_tail(int ret, ofnode node, · line 797
Quoted 3 lines
drivers/gpio/gpio-uclass.c +0
-0@@ -678,7 +795,7 @@ static int gpio_request_tail(int ret, ofnode node,return 0 ; err: debug("%s: Node '%s', property '%s', failed to request GPIO index %d:%d\n",
drivers/gpio/gpio-uclass.c static int _gpio_request_by_name_nodev(ofnode node,
Quoted 6 lines
drivers/gpio/gpio-uclass.c +1
-1- __func__, ofnode_get_name(node), list_name, index, ret); + __func__, nodename, list_name, index, ret);return ret; }@@ -692,8 +809,8 @@ static int _gpio_request_by_name_nodev(ofnode node,const char
*list_name,Quoted 11 lines
drivers/gpio/gpio-uclass.c +2
-2ret =ofnode_parse_phandle_with_args (node, list_name,"#gpio-cells" ,0 , index, &args); -return gpio_request_tail (ret, node, &args, list_name, index, desc, - flags, add_index); +return gpio_request_tail (ret,ofnode_get_name (node), &args, list_name, + index, desc, flags, add_index,NULL ); } int gpio_request_by_name_nodev(ofnode node, const char *list_name,int index, @@ -707,13 +824,14 @@ int gpio_request_by_name(struct udevice
*dev, const char
*list_name, int index,Quoted 16 lines
drivers/gpio/gpio-uclass.c +4
-3struct gpio_desc *desc, int flags) {struct ofnode_phandle_args args; +ofnode node;int ret; ret =dev_read_phandle_with_args (dev, list_name,"#gpio-cells" ,0 , index, &args); - -return gpio_request_tail (ret,dev_ofnode (dev), &args, list_name, - index, desc, flags, index >0 ); + node =dev_ofnode (dev); +return gpio_request_tail (ret,ofnode_get_name (node), &args, list_name, + index, desc, flags, index >0 ,NULL ); } int gpio_request_list_by_name_nodev(ofnode node, const charQuoted 1 line
*list_name, @@ -854,8 +972,28 @@ static int gpio_pre_remove(struct udevice*dev)
include/asm-generic/gpio.h const char *gpio_get_bank_info(struct udevice *dev,
Quoted 49 lines
drivers/gpio/gpio-uclass.c +30
-0return gpio_renumber (dev); } +int gpio_dev_request_index (struct udevice *dev,const char *nodename, +char *list_name,int index,int flags, +int dtflags,struct gpio_desc *desc) { +struct ofnode_phandle_args args; + + args.node =ofnode_null (); + args.args_count =2 ; + args.args[0 ] = index; + args.args[1 ] = dtflags; + +return gpio_request_tail (0 , nodename, &args, list_name, index, desc, + flags,0 , dev); +} +static int gpio_post_bind (struct udevice *dev) { +#if defined(CONFIG_DM_GPIO_HOG ) +struct udevice *child; +ofnode node; +#endif +#if defined(CONFIG_NEEDS_MANUAL_RELOC )struct dm_gpio_ops *ops = (struct dm_gpio_ops *)device_get_ops (dev);static int reloc_done;@@ -885,6 +1023,17 @@ static int gpio_post_bind(struct udevice *dev) reloc_done++; }#endif + +#if defined(CONFIG_DM_GPIO_HOG ) +dev_for_each_subnode (node, dev) { +if (ofnode_read_bool (node,"gpio-hog" )) { +const char *name =ofnode_get_name (node); + +device_bind_driver_to_node (dev,"gpio_hog" , name, + node, &child); + } + } +#endif return 0 ; }include/asm-generic/gpio.h +0
-0@@ -348,6 +348,22 @@ const char *gpio_get_bank_info(struct udevice *dev,int
*offset_count);include/asm-generic/gpio.h const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);
Quoted 5 lines
include/asm-generic/gpio.h +2
-0*/ int dm_gpio_lookup_name (const char *name,struct gpio_desc *desc); +/** +* gpio_hog_lookup_name() - Look up a named GPIO and return the gpio descr.
include/asm-generic/gpio.h int gpio_request_list_by_name_nodev(ofnode node,
Quoted 18 lines
include/asm-generic/gpio.h +14
-0+* +* @name: Name to look up +* @return: Returns gpio_desc for gpio +*/ +struct gpio_desc *gpio_hog_lookup_name (const char *name); + +/** +* gpio_hog_probe_all() - probe all gpio devices with +* gpio-hog subnodes. +* +* @return: Returns return value from device_probe() +*/ +int gpio_hog_probe_all (void ); +/** * gpio_lookup_name - Look up a GPIO name and return its details * @@ -503,6 +519,22 @@ int gpio_request_list_by_name_nodev(ofnode node,const char
*list_name,Quoted 13 lines
include/asm-generic/gpio.h +9
-0struct gpio_desc *desc_list, int max_count, int flags); +/** +* gpio_dev_request_index() - request single GPIO from gpio device +* +* @dev: GPIO device +* @nodename: Name of node +* @list_name: Name of GPIO list (e.g. "board-id-gpios") +* @index: Index number of the GPIO in that list use request (0=first) +* @flags: GPIOD_* flags +* @dtflags: GPIO flags read from DT include/asm-generic/gpio.h int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, · line 540
Quoted 10 lines
include/asm-generic/gpio.h +7
-0+* @desc: GPIO descriotor filled from this function +* @return: return value from gpio_request_tail() +*/ +int gpio_dev_request_index (struct udevice *dev,const char *nodename, +char *list_name,int index,int flags, +int dtflags,struct gpio_desc *desc); +/** * dm_gpio_free() - Free a single GPIO *
Quoted 2 lines
Thanks,
Michal
For the patch Review and tested on stm32mp1 board.
Regards
PAtrick
PATCH v4 1/1 gpio: add gpio-hog support
Hello Patrick,
Am 21.06.2019 um 18:09 schrieb Patrick DELAUNAY:
Quoted 65 lines
Hi Mickael
Quoted 63 lines
Subject: Re: [PATCH v4] gpio: add gpio-hog support
Importance: HighQuoted 59 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe functionChanges in v3:
- probe now all gpio devices with gpio-hogs
fromboard_rbeforeboard_late_init()call
or if someone wants to access gpio-hog
based gpios withgpio_hog_lookup_name()
This is needed, because we cannot be sure,
if a gpio device which contains gpio-hogs
is probed.
- add line-name property as Michal recommended
- renamedgpio_priv_oneintogpio_priv_one_hog
and protected throughCONFIG_DM_GPIO_HOGChanges in v2:
- movegpio_hog()call frompost_probe()topost_bind()call. Check if current gpio device has gpio-hog definitions, if so, probe it.common/board_r.c | 6 + doc/device-tree-bindings/gpio/gpio.txt | 55 ++++++++ drivers/gpio/Kconfig | 10 ++ drivers/gpio/gpio-uclass.c | 181 ++++++++++++++++++++++--- include/asm-generic/gpio.h | 32 +++++ 5 files changed, 268 insertions(+), 16 deletions(-)common/board_r.c index renamed from common/board_r.c +0
-0
150e8cd424..507da4c74a100644common/board_r.c +3
-0@@ -49,6 +49,9 @@#include <linux/err.h> #include <efi_loader.h> #include <wdt.h> +#if defined(CONFIG_DM_GPIO_HOG ) +#include <asm/gpio.h> +#endif DECLARE_GLOBAL_DATA_PTR ;
Quoted 9 lines
Quoted 7 lines
common/board_r.c static init_fnc_t init_sequence_r[] = { · line 804
Quoted 7 lines
common/board_r.c +0
-0@@ -796,6 +799,9 @@ static init_fnc_t init_sequence_r[] = { #ifdef
CONFIG_CMD_NET
initr_ethaddr,
#endifcommon/board_r.c +3
-0+#if defined(CONFIG_DM_GPIO_HOG ) + gpio_hog_probe_all, +#endif Any reason to have hog at this place ?
Not really, but we need to check at some point if all gpio hogs are processed, and I thought at a late time it does not break anything...
Quoted 60 lines
Before
board_late_init....I expect more before
board_init()for my future use-case, to replace the current (dirty) implementation with pinctrl-0#if
defined(CONFIG_WDT)
initr_watchdog,
#endifcommon/board_r.c +3
-0+#if defined(CONFIG_DM_GPIO_HOG ) + gpio_hog_probe_all, +#endif #if
defined(CONFIG_ARM)||defined(CONFIG_NDS32)||defined(CONFIG_RISCV)|| \
defined(CONFIG_SANDBOX)
board_init, /* Setup chipselects */
#endifIn my device tree I have :
stmfx: stmfx at 42 { compatible = "st,stmfx-0300"; reg = <0x42>; interrupts = <8 IRQ_TYPE_EDGE_RISING>; interrupt-parent = <&gpioi>; vdd-supply = <&v3v3>; stmfx_pinctrl: stmfx-pin-controller { compatible = "st,stmfx-0300-pinctrl"; gpio-controller; #gpio-cells = <2>; interrupt-controller; #interrupt-cells = <2>; gpio-ranges = <&stmfx_pinctrl 0 0 24>; pinctrl-names = "default"; pinctrl-0 = <&hog_pins>; hog_pins: hog { pins = "gpio14"; drive-push-pull; bias-pull-down; }; };And in board, I force probe to configure HOG....before to initialize the DISPLAY, so in
./board/st/stm32mp1/stm32mp1.c: board_init()/* board dependent setup after realloc */
intboard_init(void)
{
...../* probe all PINCTRL for hog */ for (uclass_first_device(UCLASS_PINCTRL, &dev); dev; uclass_next_device(&dev)) { pr_debug("probe pincontrol = %s\n", dev->name); }
Quoted 3 lines
Or you can let each board choose when call the function
as it is already done for other function asregulators_enable_boot_on()So don't add it in init_sequence_r[] /board_r.c?...
Hmm... I do not like this, because if you enable gpio-hog support, you don;t want to think to call gpio_hog_probe_all().
But it should be possible to call gpio_hog_probe_all() earlier from board code, as gpio_hog_probe_all() calls device_probe():
212 int gpio_hog_probe_all(void)
213 {
214 struct udevice *dev;
215 int ret;
216
217 for (uclass_first_device(UCLASS_NOP, &dev);
218 dev;
219 uclass_find_next_device(&dev)) {
220 if (dev->driver == DM_GET_DRIVER(gpio_hog)) {
221 ret = device_probe(dev);device_probe() checks if it is already probed, and simply returns if so, see:
May you can test if this works for you?
Quoted 2 lines
Anyway it is not blocking for me, it just a question.
Fine.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
#ifdef CONFIG_BOARD_LATE_INIT board_late_init,
[...]
Quoted 4 lines
For the patch Review and tested on stm32mp1 board.
Tested-by Patrick Delaunay <[email protected]>
Thanks for testing!
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 v4 1/1 gpio: add gpio-hog support
Hi Heiko,
Quoted 82 lines
From: Heiko Schocher <[email protected]>
Sent: samedi 22 juin 2019 07:32Hello Patrick,
Am 21.06.2019 um 18:09 schrieb Patrick DELAUNAY:
Quoted 66 lines
Hi Mickael
Quoted 64 lines
Subject: Re: [PATCH v4] gpio: add gpio-hog support
Importance: HighQuoted 60 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe
functionChanges in v3:
- probe now all gpio devices with gpio-hogs
fromboard_rbeforeboard_late_init()call
or if someone wants to access gpio-hog
based gpios withgpio_hog_lookup_name()
This is needed, because we cannot be sure,
if a gpio device which contains gpio-hogs
is probed.
- add line-name property as Michal recommended
- renamedgpio_priv_oneintogpio_priv_one_hog
and protected throughCONFIG_DM_GPIO_HOGChanges in v2:
- movegpio_hog()call frompost_probe()topost_bind()call. Check if current gpio device has gpio-hog definitions, if so, probe it.common/board_r.c | 6 + doc/device-tree-bindings/gpio/gpio.txt | 55 ++++++++ drivers/gpio/Kconfig | 10 ++ drivers/gpio/gpio-uclass.c | 181 ++++++++++++++++++++++--- include/asm-generic/gpio.h | 32 +++++ 5 files changed, 268 insertions(+), 16 deletions(-)common/board_r.c index renamed from common/board_r.c +0
-0
150e8cd424..507da4c74a100644common/board_r.c +3
-0@@ -49,6 +49,9 @@#include <linux/err.h> #include <efi_loader.h> #include <wdt.h> +#if defined(CONFIG_DM_GPIO_HOG ) +#include <asm/gpio.h> +#endif DECLARE_GLOBAL_DATA_PTR ;Quoted 9 lines
Quoted 7 lines
common/board_r.c static init_fnc_t init_sequence_r[] = { · line 804
Quoted 7 lines
common/board_r.c +0
-0@@ -796,6 +799,9 @@ static init_fnc_t init_sequence_r[] = { #ifdef
CONFIG_CMD_NET
initr_ethaddr,
#endifcommon/board_r.c +3
-0+#if defined(CONFIG_DM_GPIO_HOG ) + gpio_hog_probe_all, +#endif Any reason to have hog at this place ?
Quoted 2 lines
Not really, but we need to check at some point if all gpio hogs are processed, and I thought at a late time it does not break anything...
Ok. It is safe....
and anyway any board can choose the call the function earlier if the hog was required (for nay initcall before board_late_init : initr_nand, initr_mmc ....)
Quoted 63 lines
Quoted 11 lines
Before
board_late_init....I expect more before
board_init()for my future use-case, to replace the current (dirty) implementation with pinctrl-0#if
defined(CONFIG_WDT)
initr_watchdog,
#endifcommon/board_r.c +3
-0+#if defined(CONFIG_DM_GPIO_HOG ) + gpio_hog_probe_all, +#endif Quoted 1 line
#if
defined(CONFIG_ARM)||defined(CONFIG_NDS32)||
defined(CONFIG_RISCV)|| \Quoted 46 lines
defined(CONFIG_SANDBOX)
board_init, /* Setup chipselects */
#endifIn my device tree I have :
stmfx: stmfx at 42 { compatible = "st,stmfx-0300"; reg = <0x42>; interrupts = <8 IRQ_TYPE_EDGE_RISING>; interrupt-parent = <&gpioi>; vdd-supply = <&v3v3>; stmfx_pinctrl: stmfx-pin-controller { compatible = "st,stmfx-0300-pinctrl"; gpio-controller; #gpio-cells = <2>; interrupt-controller; #interrupt-cells = <2>; gpio-ranges = <&stmfx_pinctrl 0 0 24>; pinctrl-names = "default"; pinctrl-0 = <&hog_pins>; hog_pins: hog { pins = "gpio14"; drive-push-pull; bias-pull-down; }; };And in board, I force probe to configure HOG....before to initialize the DISPLAY, so in
./board/st/stm32mp1/stm32mp1.c: board_init()/* board dependent setup after realloc */ int
board_init(void){ ...../* probe all PINCTRL for hog */ for (uclass_first_device(UCLASS_PINCTRL, &dev); dev; uclass_next_device(&dev)) { pr_debug("probe pincontrol = %s\n", dev->name); }Quoted 3 lines
Or you can let each board choose when call the function as it is already done for other function as
regulators_enable_boot_on()So don't add it in init_sequence_r[] /board_r.c?...
Quoted 5 lines
Hmm... I do not like this, because if you enable gpio-hog support, you don;t want to think to call
gpio_hog_probe_all().But it should be possible to call
gpio_hog_probe_all()earlier from board code, asgpio_hog_probe_all()callsdevice_probe():
Fine.
Quoted 12 lines
212 int gpio_hog_probe_all(void)
213 {
214 struct udevice *dev;
215 int ret;
216
217 for (uclass_first_device(UCLASS_NOP, &dev);
218 dev;
219 uclass_find_next_device(&dev)) {
220 if (dev->driver == DM_GET_DRIVER(gpio_hog)) {
221 ret = device_probe(dev);Quoted 7 lines
device_probe()checks if it is already probed, and simply returns if so, see:http://git.denx.de/?p=u-
boot.git;a=blob;f=drivers/core/device.c;h=0d15e5062b66123cd364bd9803e076db7 e7dd97c;hb=77f6e2dd0551d8a825bab391a1bd6b838874bcd4#l319May you can test if this works for you?
I have the same idea, it is why I say is was no't blocking for me.
Already tested and it is working (gpio hog is called only one time even if gpio_hog_probe_all several time).
Quoted 9 lines
Quoted 2 lines
Anyway it is not blocking for me, it just a question.
Fine.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
#ifdef CONFIG_BOARD_LATE_INIT board_late_init,[...]
Quoted 1 line
Quoted 8 lines
Quoted 3 lines
For the patch Review and tested on stm32mp1 board.
Tested-by Patrick Delaunay <[email protected]>Thanks for testing!
bye,
Heiko
Regards
Patrick
PATCH v4 1/1 gpio: add gpio-hog support
In reply to Heiko SchocherHi Heiko,
Quoted 14 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419
Quoted 7 lines
Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe function
Sorry for not getting to this earlier.
Quoted 73 lines
Changes in v3:
- probe now all gpio devices with gpio-hogs
fromboard_rbeforeboard_late_init()call
or if someone wants to access gpio-hog
based gpios withgpio_hog_lookup_name()
This is needed, because we cannot be sure,
if a gpio device which contains gpio-hogs
is probed.
- add line-name property as Michal recommended
- renamedgpio_priv_oneintogpio_priv_one_hog
and protected throughCONFIG_DM_GPIO_HOGChanges in v2:
- movegpio_hog()call frompost_probe()topost_bind()call. Check if current gpio device has gpio-hog definitions, if so, probe it.common/board_r.c | 6 + doc/device-tree-bindings/gpio/gpio.txt | 55 ++++++++ drivers/gpio/Kconfig | 10 ++ drivers/gpio/gpio-uclass.c | 181 ++++++++++++++++++++++--- include/asm-generic/gpio.h | 32 +++++ 5 files changed, 268 insertions(+), 16 deletions(-)common/board_r.c +6
-0@@ -49,6 +49,9 @@#include <linux/err.h> #include <efi_loader.h> #include <wdt.h> +#if defined(CONFIG_DM_GPIO_HOG ) +#include <asm/gpio.h> +#endif DECLARE_GLOBAL_DATA_PTR ;@@ -796,6 +799,9 @@ static init_fnc_t init_sequence_r[] = {#ifdef CONFIG_CMD_NET initr_ethaddr,#endif +#if defined(CONFIG_DM_GPIO_HOG ) + gpio_hog_probe_all, +#endif #ifdef CONFIG_BOARD_LATE_INIT board_late_init,#endif doc/device-tree-bindings/gpio/gpio.txt +15
-0@@ -210,3 +210,58 @@ Example 2: Here, three GPIO ranges are defined wrt. two pin controllers. pinctrl1 GPIO ranges are defined using pin numbers whereas the GPIO ranges wrt. pinctrl2 are named "foo" and "bar". + +3) GPIO hog definitions +----------------------- + +The GPIO chip may contain GPIO hog definitions. GPIO hogging is a mechanism +providing automatic GPIO request and configuration as part of the +gpio-controller's driver probe function. + +Each GPIO hog definition is represented as a child node of the GPIO controller. +Required properties: +- gpio-hog: A property specifying that this child node represents a GPIO hog. +- gpios: Store the GPIO information (id, flags) for the GPIO to + affect. + + ! Not yet support more than one gpio !
doc/device-tree-bindings/gpio/gpio.txt Example 2: · line 237
Quoted 10 lines
doc/device-tree-bindings/gpio/gpio.txt +10
-0+ +Only one of the following properties scanned in the order shown below. +- input: A property specifying to set the GPIO direction as input. +- output-low A property specifying to set the GPIO direction as output with + the value low. +- output-high A property specifying to set the GPIO direction as output with + the value high. + +Optional properties: +- line-name: The GPIO label name. If not present the node name is used.
This seems a strange name. I suppose this is what linux called it.
Quoted 8 lines
doc/device-tree-bindings/gpio/gpio.txt +8
-0+ +Example: + + tca6416 at 20 { + compatible = "ti,tca6416"; + reg = <0x20>; + #gpio-cells = <2>; + gpio-controller;
doc/device-tree-bindings/gpio/gpio.txt Example 2: · line 255
Quoted 10 lines
doc/device-tree-bindings/gpio/gpio.txt +10
-0+ + env_reset { + gpio-hog; + input; + gpios = <6 GPIO_ACTIVE_LOW>; + }; + boot_rescue { + gpio-hog; + input; + gpios = <7 GPIO_ACTIVE_LOW>;
Should have an example for line-name
doc/device-tree-bindings/gpio/gpio.txt Example 2: · line 262
Quoted 7 lines
doc/device-tree-bindings/gpio/gpio.txt +7
-0+ }; + }; + +For the above Example you can than access the gpio in your boardcode +with: + + desc = gpio_hog_lookup_name("boot_rescue.gpio-hog");
Could we drop the .gpio-hog suffix? It doesn't seem necessary, but perhaps you are worried about people getting confused otherwise?
Also this function should be passed a desc struct pointer, not return static data.
doc/device-tree-bindings/gpio/gpio.txt Example 2: · line 264
Quoted 2 lines
doc/device-tree-bindings/gpio/gpio.txt +2
-0+ if (desc) { + if (dm_gpio_get_value(desc))
You should check the error here.
dm_gpio_get_value() returns -ve on error, including if desc returns an invalid GPIO (dev=NULL), so you should be able to do:
gpio_hog_lookup_name("boot_rescue.gpio-hog", &desc); if (dm_gpio_get_value(desc) == 1)
So in fact
drivers/gpio/Kconfig config DM_GPIO · line 17
Quoted 12 lines
doc/device-tree-bindings/gpio/gpio.txt +3
-0+ printf("\nBooting into Rescue System\n"); + else + printf("\nBoot normal\n");drivers/gpio/Kconfig +1
-0@@ -14,6 +14,16 @@ config DM_GPIO particular GPIOs that they provide. The uclass interface is defined in include/asm-generic/gpio.h. +config DM_GPIO_HOG
Can we drop the DM_ prefix? At some point DM_GPIO will go away and we don't want to rename these sorts of options.
Quoted 27 lines
drivers/gpio/Kconfig +9
-0+ bool "Enable GPIO hog support" + depends on DM_GPIO + default n + help + Enable gpio hog support + The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. + config ALTERA_PIO bool "Altera PIO driver" depends on DM_GPIOdrivers/gpio/gpio-uclass.c +3
-0@@ -5,6 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> #include <dt-bindings/gpio/gpio.h> #include <errno.h> #include <fdtdec.h>
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 150
Quoted 7 lines
drivers/gpio/gpio-uclass.c +4
-0@@ -141,6 +144,118 @@ static int gpio_find_and_xlate(struct gpio_desc *desc,return gpio_xlate_offs_flags (desc->dev, desc, args); } +#if defined(CONFIG_DM_GPIO_HOG) + +struct gpio_hog_priv { + struct gpio_desc gpiod;
As above I don't think you need this.
Quoted 26 lines
drivers/gpio/gpio-uclass.c +26
-0+}; + +struct gpio_hog_data { +int gpiod_flags; +int value; +u32 val[2 ]; +}; + +static int gpio_hog_ofdata_to_platdata (struct udevice *dev) +{ +struct gpio_hog_data *plat =dev_get_platdata (dev); +const char *nodename; +int ret; + + plat->value =0 ; +if (dev_read_bool (dev,"input" )) { + plat->gpiod_flags =GPIOD_IS_IN ; + }else if (dev_read_bool (dev,"output-high" )) { + plat->value =1 ; + plat->gpiod_flags =GPIOD_IS_OUT ; + }else if (dev_read_bool (dev,"output-low" )) { + plat->gpiod_flags =GPIOD_IS_OUT ; + }else { +printf ("%s: missing gpio-hog state.\n" , __func__); +return -EINVAL ; + }
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 186
Quoted 10 lines
drivers/gpio/gpio-uclass.c +10
-0+ ret =dev_read_u32_array (dev,"gpios" , plat->val,2 ); +if (ret) { +printf ("%s: wrong gpios property, 2 values needed %d\n" , + __func__, ret); +return ret; + } + nodename =dev_read_string (dev,"line-name" ); +if (!nodename) + nodename =dev_read_name (dev); +device_set_name (dev, nodename);
I don't think you should set the device name unless needed. But why not store this in the device data, rather than changing its name? If we want to change the name, why not just use that for the node name in the .dts?
Quoted 9 lines
drivers/gpio/gpio-uclass.c +9
-0+ +return 0 ; +} + +static int gpio_hog_probe (struct udevice *dev) +{ +struct gpio_hog_data *plat =dev_get_platdata (dev); +struct gpio_hog_priv *priv =dev_get_priv (dev); +int ret;
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 205
Quoted 10 lines
drivers/gpio/gpio-uclass.c +10
-0+ + ret =gpio_dev_request_index (dev->parent, dev->name,"gpio-hog" , + plat->val[0 ], plat->gpiod_flags, + plat->val[1 ], &priv->gpiod); +if (ret <0 ) { +debug ("%s: node %s could not get gpio.\n" , __func__, + dev->name); +return ret; + } +dm_gpio_set_dir (&priv->gpiod);
Check error
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 207
Quoted 2 lines
drivers/gpio/gpio-uclass.c +2
-0+if (plat->gpiod_flags ==GPIOD_IS_OUT ) +dm_gpio_set_value (&priv->gpiod, plat->value);
check error
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 217
Quoted 10 lines
drivers/gpio/gpio-uclass.c +10
-0+ +return 0 ; +} + +int gpio_hog_probe_all (void ) +{ +struct udevice *dev; +int ret; + + for (uclass_first_device(UCLASS_NOP, &dev);
Perhaps you should create a new uclass for this?
Quoted 45 lines
drivers/gpio/gpio-uclass.c +41
-0+dev ; + uclass_find_next_device(&dev)) { +if (dev->driver ==DM_GET_DRIVER (gpio_hog)) { + ret =device_probe (dev); +if (ret) +return ret; + } + } + +return 0 ; +} + +struct gpio_desc *gpio_hog_lookup_name (const char *name) +{ +struct udevice *dev; + +gpio_hog_probe_all (); +if (!uclass_get_device_by_name (UCLASS_NOP , name, &dev)) { +struct gpio_hog_priv *priv =dev_get_priv (dev); + +return &priv->gpiod; + } + +return NULL ; +} + +U_BOOT_DRIVER (gpio_hog) = { + .name ="gpio_hog" , + .id =UCLASS_NOP , + .ofdata_to_platdata = gpio_hog_ofdata_to_platdata, + .probe = gpio_hog_probe, + .priv_auto_alloc_size =sizeof (struct gpio_hog_priv ), + .platdata_auto_alloc_size =sizeof (struct gpio_hog_data ), +}; +#else +struct gpio_desc *gpio_hog_lookup_name (const char *name) +{ +return NULL ; +} +#endif +int dm_gpio_request (struct gpio_desc *desc,const char *label) {struct udevice *dev = desc->dev;
drivers/gpio/gpio-uclass.c int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count) · line 762
Quoted 10 lines
drivers/gpio/gpio-uclass.c +3
-2@@ -640,22 +755,25 @@ int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count)return vector; } -static int gpio_request_tail (int ret,ofnode node, +static int gpio_request_tail (int ret,const char *nodename,struct ofnode_phandle_args *args,const char *list_name,int index, -struct gpio_desc *desc,int flags,bool add_index) +struct gpio_desc *desc,int flags, +bool add_index,struct udevice *dev)
This function badly needs a comment now. Also 'dev' is not a great name.
Quoted 101 lines
drivers/gpio/gpio-uclass.c +36
-14{ - desc->dev =NULL ; + desc->dev = dev; desc->offset =0 ; desc->flags =0 ;if (ret) goto err; - ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, - &desc->dev); -if (ret) { -debug ("%s: uclass_get_device_by_ofnode failed\n" , __func__); - goto err; +if (!desc->dev) { + ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, + &desc->dev); +if (ret) { +debug ("%s: uclass_get_device_by_ofnode failed\n" , __func__); + goto err; + } } ret =gpio_find_and_xlate (desc, args);if (ret) {@@ -663,8 +781,7 @@ static int gpio_request_tail(int ret, ofnode node, goto err; } ret =dm_gpio_requestf (desc, add_index ?"%s.%s%d" :"%s.%s" , -ofnode_get_name (node), - list_name, index); + nodename, list_name, index);if (ret) {debug ("%s: dm_gpio_requestf failed\n" , __func__); goto err;@@ -678,7 +795,7 @@ static int gpio_request_tail(int ret, ofnode node,return 0 ; err:debug ("%s: Node '%s', property '%s', failed to request GPIO index %d: %d\n" , - __func__,ofnode_get_name (node), list_name, index, ret); + __func__, nodename, list_name, index, ret);return ret; }@@ -692,8 +809,8 @@ static int _gpio_request_by_name_nodev(ofnode node, const char *list_name, ret =ofnode_parse_phandle_with_args (node, list_name,"#gpio-cells" ,0 , index, &args); -return gpio_request_tail (ret, node, &args, list_name, index, desc, - flags, add_index); +return gpio_request_tail (ret,ofnode_get_name (node), &args, list_name, + index, desc, flags, add_index,NULL ); } int gpio_request_by_name_nodev(ofnode node, const char *list_name, int index,@@ -707,13 +824,14 @@ int gpio_request_by_name(struct udevice *dev, const char *list_name, int index, struct gpio_desc *desc, int flags) {struct ofnode_phandle_args args; +ofnode node;int ret; ret =dev_read_phandle_with_args (dev, list_name,"#gpio-cells" ,0 , index, &args); - -return gpio_request_tail (ret,dev_ofnode (dev), &args, list_name, - index, desc, flags, index >0 ); + node =dev_ofnode (dev); +return gpio_request_tail (ret,ofnode_get_name (node), &args, list_name, + index, desc, flags, index >0 ,NULL ); } int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,@@ -854,8 +972,28 @@ static int gpio_pre_remove(struct udevice *dev)return gpio_renumber (dev); } +int gpio_dev_request_index (struct udevice *dev,const char *nodename, +char *list_name,int index,int flags, +int dtflags,struct gpio_desc *desc) +{ +struct ofnode_phandle_args args; + + args.node =ofnode_null (); + args.args_count =2 ; + args.args[0 ] = index; + args.args[1 ] = dtflags; + +return gpio_request_tail (0 , nodename, &args, list_name, index, desc, + flags,0 , dev); +} +static int gpio_post_bind (struct udevice *dev) { +#if defined(CONFIG_DM_GPIO_HOG ) +struct udevice *child; +ofnode node; +#endif +#if defined(CONFIG_NEEDS_MANUAL_RELOC )struct dm_gpio_ops *ops = (struct dm_gpio_ops *)device_get_ops (dev);static int reloc_done;
drivers/gpio/gpio-uclass.c static int gpio_post_bind(struct udevice *dev) · line 1027
Quoted 5 lines
drivers/gpio/gpio-uclass.c +2
-0@@ -885,6 +1023,17 @@ static int gpio_post_bind(struct udevice *dev) reloc_done++; }#endif + +#if defined(CONFIG_DM_GPIO_HOG )
Can you use if (IS_ENABLED(CONFIG....
drivers/gpio/gpio-uclass.c static int gpio_post_bind(struct udevice *dev) · line 1033
Quoted 6 lines
drivers/gpio/gpio-uclass.c +6
-0+dev_for_each_subnode (node, dev) { +if (ofnode_read_bool (node,"gpio-hog" )) { +const char *name =ofnode_get_name (node); + +device_bind_driver_to_node (dev,"gpio_hog" , name, + node, &child);
Check error? This might run out of memory, perhaps.
Quoted 17 lines
drivers/gpio/gpio-uclass.c +3
-0+ } + } +#endif return 0 ; }include/asm-generic/gpio.h +3
-0@@ -348,6 +348,22 @@ const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);*/ int dm_gpio_lookup_name (const char *name,struct gpio_desc *desc); +/** +* gpio_hog_lookup_name() - Look up a named GPIO and return the gpio descr. +*
include/asm-generic/gpio.h const char *gpio_get_bank_info(struct udevice *dev, int *offset_count); · line 363
Quoted 10 lines
include/asm-generic/gpio.h +10
-0+* @name: Name to look up +* @return: Returns gpio_desc for gpio +*/ +struct gpio_desc *gpio_hog_lookup_name (const char *name); + +/** +* gpio_hog_probe_all() - probe all gpio devices with +* gpio-hog subnodes. +* +* @return: Returns return value from device_probe()
What if one fails and the others succeed?
Quoted 7 lines
include/asm-generic/gpio.h +3
-0+*/ +int gpio_hog_probe_all (void ); +/** * gpio_lookup_name - Look up a GPIO name and return its details *
include/asm-generic/gpio.h int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, · line 526
Quoted 8 lines
include/asm-generic/gpio.h +5
-0@@ -503,6 +519,22 @@ int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, struct gpio_desc *desc_list, int max_count, int flags); +/** +* gpio_dev_request_index() - request single GPIO from gpio device +* +* @dev: GPIO device +* @nodename: Name of node
What is a node? Can you expand this a bit?
include/asm-generic/gpio.h int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, · line 530
Quoted 4 lines
include/asm-generic/gpio.h +4
-0+* @list_name: Name of GPIO list (e.g. "board-id-gpios") +* @index: Index number of the GPIO in that list use request (0=first) +* @flags: GPIOD_* flags +* @dtflags: GPIO flags read from DT
Reference GPIOD_... mask here?
include/asm-generic/gpio.h int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, · line 531
Quoted 1 line
include/asm-generic/gpio.h +1
-0+* @desc: GPIO descriotor filled from this function
returns GPIO descriptor...
Quoted 10 lines
include/asm-generic/gpio.h +6
-1+* @return: return value from gpio_request_tail() +*/ +int gpio_dev_request_index (struct udevice *dev,const char *nodename, +char *list_name,int index,int flags, +int dtflags,struct gpio_desc *desc); +/** * dm_gpio_free() - Free a single GPIO * --
Quoted 2 lines
2.21.0
Regards,
Simon
PATCH v4 1/1 gpio: add gpio-hog support
Hello Simon,
Am 22.06.2019 um 21:09 schrieb Simon Glass:
Quoted 26 lines
Hi Heiko,
Quoted 14 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419Quoted 7 lines
Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe function
Quoted 1 line
Sorry for not getting to this earlier.
no problem, thanks for your time!
Quoted 75 lines
Quoted 75 lines
Changes in v3:
- probe now all gpio devices with gpio-hogs
fromboard_rbeforeboard_late_init()call
or if someone wants to access gpio-hog
based gpios withgpio_hog_lookup_name()
This is needed, because we cannot be sure,
if a gpio device which contains gpio-hogs
is probed.
- add line-name property as Michal recommended
- renamedgpio_priv_oneintogpio_priv_one_hog
and protected throughCONFIG_DM_GPIO_HOGChanges in v2:
- movegpio_hog()call frompost_probe()topost_bind()call. Check if current gpio device has gpio-hog definitions, if so, probe it.common/board_r.c | 6 + doc/device-tree-bindings/gpio/gpio.txt | 55 ++++++++ drivers/gpio/Kconfig | 10 ++ drivers/gpio/gpio-uclass.c | 181 ++++++++++++++++++++++--- include/asm-generic/gpio.h | 32 +++++ 5 files changed, 268 insertions(+), 16 deletions(-)common/board_r.c +6
-0@@ -49,6 +49,9 @@#include <linux/err.h> #include <efi_loader.h> #include <wdt.h> +#if defined(CONFIG_DM_GPIO_HOG ) +#include <asm/gpio.h> +#endif DECLARE_GLOBAL_DATA_PTR ;@@ -796,6 +799,9 @@ static init_fnc_t init_sequence_r[] = {#ifdef CONFIG_CMD_NET initr_ethaddr,#endif +#if defined(CONFIG_DM_GPIO_HOG ) + gpio_hog_probe_all, +#endif #ifdef CONFIG_BOARD_LATE_INIT board_late_init,#endif doc/device-tree-bindings/gpio/gpio.txt +19
-0@@ -210,3 +210,58 @@ Example 2: Here, three GPIO ranges are defined wrt. two pin controllers. pinctrl1 GPIO ranges are defined using pin numbers whereas the GPIO ranges wrt. pinctrl2 are named "foo" and "bar". + +3) GPIO hog definitions +----------------------- + +The GPIO chip may contain GPIO hog definitions. GPIO hogging is a mechanism +providing automatic GPIO request and configuration as part of the +gpio-controller's driver probe function. + +Each GPIO hog definition is represented as a child node of the GPIO controller. +Required properties: +- gpio-hog: A property specifying that this child node represents a GPIO hog. +- gpios: Store the GPIO information (id, flags) for the GPIO to + affect. + + ! Not yet support more than one gpio ! + +Only one of the following properties scanned in the order shown below. +- input: A property specifying to set the GPIO direction as input. +- output-low A property specifying to set the GPIO direction as output with
Quoted 8 lines
doc/device-tree-bindings/gpio/gpio.txt Example 2: · line 237
Quoted 6 lines
doc/device-tree-bindings/gpio/gpio.txt +6
-0+ the value low. +- output-high A property specifying to set the GPIO direction as output with + the value high. + +Optional properties: +- line-name: The GPIO label name. If not present the node name is used.This seems a strange name. I suppose this is what linux called it.
Yes.
Quoted 12 lines
Quoted 12 lines
doc/device-tree-bindings/gpio/gpio.txt +12
-0+ +Example: + + tca6416 at 20 { + compatible = "ti,tca6416"; + reg = <0x20>; + #gpio-cells = <2>; + gpio-controller; + + env_reset { + gpio-hog; + input;
Quoted 8 lines
doc/device-tree-bindings/gpio/gpio.txt Example 2: · line 255
Quoted 6 lines
doc/device-tree-bindings/gpio/gpio.txt +6
-0+ gpios = <6 GPIO_ACTIVE_LOW>; + }; + boot_rescue { + gpio-hog; + input; + gpios = <7 GPIO_ACTIVE_LOW>;Should have an example for line-name
Oh, yes of course, I added the "line-name" part later, and forgot the example.
Quoted 11 lines
doc/device-tree-bindings/gpio/gpio.txt Example 2: · line 262
Quoted 8 lines
doc/device-tree-bindings/gpio/gpio.txt +7
-0+ }; + }; + +For the above Example you can than access the gpio in your boardcode +with: + + desc = gpio_hog_lookup_name("boot_rescue.gpio-hog");Could we drop the .gpio-hog suffix? It doesn't seem necessary, but perhaps you are worried about people getting confused otherwise?
Good catch! Since v4 it is already without this suffix, so I correct the doc here.
Quoted 6 lines
Also this function should be passed a desc struct pointer, not return static data.
doc/device-tree-bindings/gpio/gpio.txt Example 2: · line 264
Quoted 2 lines
doc/device-tree-bindings/gpio/gpio.txt +2
-0+ if (desc) { + if (dm_gpio_get_value(desc))
Quoted 6 lines
You should check the error here.
dm_gpio_get_value()returns -ve on error, including if desc returns an invalid GPIO (dev=NULL), so you should be able to do:
gpio_hog_lookup_name("boot_rescue.gpio-hog", &desc);
Also we should check here the return value.
Quoted 1 line
if (
dm_gpio_get_value(desc)== 1)
Good point. I rework this, thanks!
Quoted 12 lines
So in fact
Quoted 11 lines
doc/device-tree-bindings/gpio/gpio.txt +3
-0+ printf("\nBooting into Rescue System\n"); + else + printf("\nBoot normal\n");drivers/gpio/Kconfig +0
-0@@ -14,6 +14,16 @@ config DM_GPIO particular GPIOs that they provide. The uclass interface is defined in include/asm-generic/gpio.h.
Quoted 4 lines
drivers/gpio/Kconfig config DM_GPIO · line 17
Quoted 1 line
drivers/gpio/Kconfig +1
-0+config DM_GPIO_HOGCan we drop the
DM_prefix? At some pointDM_GPIOwill go away and we don't want to rename these sorts of options.
Hmm... we also have the DM_GPIO symbol, as the gpio hog only works with DM_GPIO enabled, I thought DM_GPIO_HOG is the better choice, but of course I can change this.
Quoted 30 lines
Quoted 30 lines
drivers/gpio/Kconfig +9
-0+ bool "Enable GPIO hog support" + depends on DM_GPIO + default n + help + Enable gpio hog support + The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. + config ALTERA_PIO bool "Altera PIO driver" depends on DM_GPIOdrivers/gpio/gpio-uclass.c +3
-0@@ -5,6 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> #include <dt-bindings/gpio/gpio.h> #include <errno.h> #include <fdtdec.h> @@ -141,6 +144,118 @@ static int gpio_find_and_xlate(struct gpio_desc *desc,return gpio_xlate_offs_flags (desc->dev, desc, args); }
Quoted 6 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 150
Quoted 4 lines
drivers/gpio/gpio-uclass.c +4
-0+#if defined(CONFIG_DM_GPIO_HOG) + +struct gpio_hog_priv { + struct gpio_desc gpiod;As above I don't think you need this.
Hmm.. when probing I need to request the gpio with gpio_dev_request_index() for which I need to pass a pointer to struct gpio_desc ...
And later I want to have the possibility to access the gpio for example with dm_gpio_set_value() and need therefore the gpio descriptor, so I must store it somewhere. Or do I overlook something obvious?
Quoted 33 lines
Quoted 33 lines
drivers/gpio/gpio-uclass.c +33
-0+}; + +struct gpio_hog_data { +int gpiod_flags; +int value; +u32 val[2 ]; +}; + +static int gpio_hog_ofdata_to_platdata (struct udevice *dev) +{ +struct gpio_hog_data *plat =dev_get_platdata (dev); +const char *nodename; +int ret; + + plat->value =0 ; +if (dev_read_bool (dev,"input" )) { + plat->gpiod_flags =GPIOD_IS_IN ; + }else if (dev_read_bool (dev,"output-high" )) { + plat->value =1 ; + plat->gpiod_flags =GPIOD_IS_OUT ; + }else if (dev_read_bool (dev,"output-low" )) { + plat->gpiod_flags =GPIOD_IS_OUT ; + }else { +printf ("%s: missing gpio-hog state.\n" , __func__); +return -EINVAL ; + } + ret =dev_read_u32_array (dev,"gpios" , plat->val,2 ); +if (ret) { +printf ("%s: wrong gpios property, 2 values needed %d\n" , + __func__, ret); +return ret; + } + nodename =dev_read_string (dev,"line-name" );
Quoted 8 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 186
Quoted 3 lines
drivers/gpio/gpio-uclass.c +3
-0+if (!nodename) + nodename =dev_read_name (dev); +device_set_name (dev, nodename);I don't think you should set the device name unless needed. But why not store this in the device data, rather than changing its name? If we want to change the name, why not just use that for the node name in the .dts?
Because I use the device name for finding the gpio through gpio_hog_lookup_name().
Ok, if there is no line-name property, we do not need to set the device name, as it has already the correct name, so this can be changed to:
nodename = dev_read_string(dev, "line-name");
if (nodename)
device_set_name(dev, nodename);Quoted 13 lines
Quoted 13 lines
drivers/gpio/gpio-uclass.c +13
-0+ +return 0 ; +} + +static int gpio_hog_probe (struct udevice *dev) +{ +struct gpio_hog_data *plat =dev_get_platdata (dev); +struct gpio_hog_priv *priv =dev_get_priv (dev); +int ret; + + ret =gpio_dev_request_index (dev->parent, dev->name,"gpio-hog" , + plat->val[0 ], plat->gpiod_flags, + plat->val[1 ], &priv->gpiod);
Quoted 8 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 205
Quoted 6 lines
drivers/gpio/gpio-uclass.c +6
-0+if (ret <0 ) { +debug ("%s: node %s could not get gpio.\n" , __func__, + dev->name); +return ret; + } +dm_gpio_set_dir (&priv->gpiod);Check error
Yes ... Hmm, while checking, this is not needed anymore, as gpio_dev_request_index() calls gpio_request_tail() which calls dm_gpio_set_dir(), so I remove this.
Quoted 5 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 207
Quoted 3 lines
drivers/gpio/gpio-uclass.c +2
-0+if (plat->gpiod_flags ==GPIOD_IS_OUT ) +dm_gpio_set_value (&priv->gpiod, plat->value);check error
done.
Quoted 4 lines
Quoted 4 lines
drivers/gpio/gpio-uclass.c +4
-0+ +return 0 ; +} +
Quoted 8 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 217
Quoted 6 lines
drivers/gpio/gpio-uclass.c +6
-0+int gpio_hog_probe_all (void ) +{ +struct udevice *dev; +int ret; + + for (uclass_first_device(UCLASS_NOP, &dev);Perhaps you should create a new uclass for this?
Hmm.. yes, I had an approach with a new uclass, but I thought, the new [1] UCLASS_NOP is valid for this here to?
[1] http://patchwork.ozlabs.org/patch/1098913/
Quoted 48 lines
Quoted 48 lines
drivers/gpio/gpio-uclass.c +41
-0+dev ; + uclass_find_next_device(&dev)) { +if (dev->driver ==DM_GET_DRIVER (gpio_hog)) { + ret =device_probe (dev); +if (ret) +return ret; + } + } + +return 0 ; +} + +struct gpio_desc *gpio_hog_lookup_name (const char *name) +{ +struct udevice *dev; + +gpio_hog_probe_all (); +if (!uclass_get_device_by_name (UCLASS_NOP , name, &dev)) { +struct gpio_hog_priv *priv =dev_get_priv (dev); + +return &priv->gpiod; + } + +return NULL ; +} + +U_BOOT_DRIVER (gpio_hog) = { + .name ="gpio_hog" , + .id =UCLASS_NOP , + .ofdata_to_platdata = gpio_hog_ofdata_to_platdata, + .probe = gpio_hog_probe, + .priv_auto_alloc_size =sizeof (struct gpio_hog_priv ), + .platdata_auto_alloc_size =sizeof (struct gpio_hog_data ), +}; +#else +struct gpio_desc *gpio_hog_lookup_name (const char *name) +{ +return NULL ; +} +#endif +int dm_gpio_request (struct gpio_desc *desc,const char *label) {struct udevice *dev = desc->dev;@@ -640,22 +755,25 @@ int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count)return vector; }
Quoted 9 lines
drivers/gpio/gpio-uclass.c int dm_gpio_get_values_as_int(const struct gpio_desc *desc_list, int count) · line 762
Quoted 7 lines
drivers/gpio/gpio-uclass.c +3
-2-static int gpio_request_tail (int ret,ofnode node, +static int gpio_request_tail (int ret,const char *nodename,struct ofnode_phandle_args *args,const char *list_name,int index, -struct gpio_desc *desc,int flags,bool add_index) +struct gpio_desc *desc,int flags, +bool add_index,struct udevice *dev)This function badly needs a comment now. Also 'dev' is not a great name.
Before my patch I think, it needed a comment ;-)
I try to add one...
Hmm... the name "dev" is the same as in struct gpio_desc ... what is a good name?
parent? gpio_dev?
I tend to name it gpio_dev ...
Quoted 100 lines
Quoted 100 lines
drivers/gpio/gpio-uclass.c +36
-14{ - desc->dev =NULL ; + desc->dev = dev; desc->offset =0 ; desc->flags =0 ;if (ret) goto err; - ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, - &desc->dev); -if (ret) { -debug ("%s: uclass_get_device_by_ofnode failed\n" , __func__); - goto err; +if (!desc->dev) { + ret =uclass_get_device_by_ofnode (UCLASS_GPIO , args->node, + &desc->dev); +if (ret) { +debug ("%s: uclass_get_device_by_ofnode failed\n" , __func__); + goto err; + } } ret =gpio_find_and_xlate (desc, args);if (ret) {@@ -663,8 +781,7 @@ static int gpio_request_tail(int ret, ofnode node, goto err; } ret =dm_gpio_requestf (desc, add_index ?"%s.%s%d" :"%s.%s" , -ofnode_get_name (node), - list_name, index); + nodename, list_name, index);if (ret) {debug ("%s: dm_gpio_requestf failed\n" , __func__); goto err;@@ -678,7 +795,7 @@ static int gpio_request_tail(int ret, ofnode node,return 0 ; err:debug ("%s: Node '%s', property '%s', failed to request GPIO index %d: %d\n" , - __func__,ofnode_get_name (node), list_name, index, ret); + __func__, nodename, list_name, index, ret);return ret; }@@ -692,8 +809,8 @@ static int _gpio_request_by_name_nodev(ofnode node, const char *list_name, ret =ofnode_parse_phandle_with_args (node, list_name,"#gpio-cells" ,0 , index, &args); -return gpio_request_tail (ret, node, &args, list_name, index, desc, - flags, add_index); +return gpio_request_tail (ret,ofnode_get_name (node), &args, list_name, + index, desc, flags, add_index,NULL ); } int gpio_request_by_name_nodev(ofnode node, const char *list_name, int index,@@ -707,13 +824,14 @@ int gpio_request_by_name(struct udevice *dev, const char *list_name, int index, struct gpio_desc *desc, int flags) {struct ofnode_phandle_args args; +ofnode node;int ret; ret =dev_read_phandle_with_args (dev, list_name,"#gpio-cells" ,0 , index, &args); - -return gpio_request_tail (ret,dev_ofnode (dev), &args, list_name, - index, desc, flags, index >0 ); + node =dev_ofnode (dev); +return gpio_request_tail (ret,ofnode_get_name (node), &args, list_name, + index, desc, flags, index >0 ,NULL ); } int gpio_request_list_by_name_nodev(ofnode node, const char *list_name,@@ -854,8 +972,28 @@ static int gpio_pre_remove(struct udevice *dev)return gpio_renumber (dev); } +int gpio_dev_request_index (struct udevice *dev,const char *nodename, +char *list_name,int index,int flags, +int dtflags,struct gpio_desc *desc) +{ +struct ofnode_phandle_args args; + + args.node =ofnode_null (); + args.args_count =2 ; + args.args[0 ] = index; + args.args[1 ] = dtflags; + +return gpio_request_tail (0 , nodename, &args, list_name, index, desc, + flags,0 , dev); +} +static int gpio_post_bind (struct udevice *dev) { +#if defined(CONFIG_DM_GPIO_HOG ) +struct udevice *child; +ofnode node; +#endif +#if defined(CONFIG_NEEDS_MANUAL_RELOC )struct dm_gpio_ops *ops = (struct dm_gpio_ops *)device_get_ops (dev);static int reloc_done;
Quoted 8 lines
drivers/gpio/gpio-uclass.c static int gpio_post_bind(struct udevice *dev) · line 1027
Quoted 6 lines
drivers/gpio/gpio-uclass.c +2
-0@@ -885,6 +1023,17 @@ static int gpio_post_bind(struct udevice *dev) reloc_done++; }#endif + +#if defined(CONFIG_DM_GPIO_HOG )Can you use if (IS_ENABLED(CONFIG....
Yes, changed.
Quoted 8 lines
drivers/gpio/gpio-uclass.c static int gpio_post_bind(struct udevice *dev) · line 1033
Quoted 6 lines
drivers/gpio/gpio-uclass.c +6
-0+dev_for_each_subnode (node, dev) { +if (ofnode_read_bool (node,"gpio-hog" )) { +const char *name =ofnode_get_name (node); + +device_bind_driver_to_node (dev,"gpio_hog" , name, + node, &child);Check error? This might run out of memory, perhaps.
done.
Quoted 14 lines
Quoted 14 lines
drivers/gpio/gpio-uclass.c +3
-0+ } + } +#endif return 0 ; }include/asm-generic/gpio.h +0
-0@@ -348,6 +348,22 @@ const char *gpio_get_bank_info(struct udevice *dev, int *offset_count);*/ int dm_gpio_lookup_name (const char *name,struct gpio_desc *desc);
Quoted 15 lines
include/asm-generic/gpio.h const char *gpio_get_bank_info(struct udevice *dev, int *offset_count); · line 363
Quoted 13 lines
include/asm-generic/gpio.h +13
-0+/** +* gpio_hog_lookup_name() - Look up a named GPIO and return the gpio descr. +* +* @name: Name to look up +* @return: Returns gpio_desc for gpio +*/ +struct gpio_desc *gpio_hog_lookup_name (const char *name); + +/** +* gpio_hog_probe_all() - probe all gpio devices with +* gpio-hog subnodes. +* +* @return: Returns return value from device_probe() What if one fails and the others succeed?
Currently I return with error code from device_probe(). So the rest of the gpio-hogs are not probed.
Hmm.. may it is better to emmit a debug message and continue?
Quoted 10 lines
Quoted 10 lines
include/asm-generic/gpio.h +3
-0+*/ +int gpio_hog_probe_all (void ); +/** * gpio_lookup_name - Look up a GPIO name and return its details * @@ -503,6 +519,22 @@ int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, struct gpio_desc *desc_list, int max_count, int flags);
Quoted 7 lines
include/asm-generic/gpio.h int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, · line 526
Quoted 5 lines
include/asm-generic/gpio.h +5
-0+/** +* gpio_dev_request_index() - request single GPIO from gpio device +* +* @dev: GPIO device +* @nodename: Name of node What is a node? Can you expand this a bit?
changed to:
* @nodename: Name of node for which gpio gets requested, used
* for the gpio label name
Quoted 7 lines
include/asm-generic/gpio.h int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, · line 530
Quoted 5 lines
include/asm-generic/gpio.h +4
-0+* @list_name: Name of GPIO list (e.g. "board-id-gpios") +* @index: Index number of the GPIO in that list use request (0=first) +* @flags: GPIOD_* flags +* @dtflags: GPIO flags read from DT Reference
GPIOD_... mask here?
Yep, added.
Quoted 3 lines
include/asm-generic/gpio.h int gpio_request_list_by_name_nodev(ofnode node, const char *list_name, · line 531
Quoted 1 line
include/asm-generic/gpio.h +1
-0+* @desc: GPIO descriotor filled from this function returns GPIO descriptor...
changed.
Quoted 7 lines
Quoted 7 lines
include/asm-generic/gpio.h +6
-0+* @return: return value from gpio_request_tail() +*/ +int gpio_dev_request_index (struct udevice *dev,const char *nodename, +char *list_name,int index,int flags, +int dtflags,struct gpio_desc *desc); +/**
Quoted 8 lines
Quoted 5 lines
include/asm-generic/gpio.h +0
-1* dm_gpio_free() - Free a single GPIO * -- 2.21.0
Regards,
Simon
Thanks for this review!
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 v4 1/1 gpio: add gpio-hog support
Hi Heiko,
Quoted 30 lines · Heiko Schocher
Hello Simon,
Am 22.06.2019 um 21:09 schrieb Simon Glass:
Quoted 26 lines
Hi Heiko,
Quoted 21 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe function
[..]
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
+config
DM_GPIO_HOGCan we drop the
DM_prefix? At some pointDM_GPIOwill go away and we don't want to rename these sorts of options.Hmm... we also have the
DM_GPIOsymbol, as the gpio hog only works withDM_GPIOenabled, I thoughtDM_GPIO_HOGis the better choice, but of course I can change this.
Yes I understand that, but in general we hope one day to rename DM_GPIO to GPIO, once everything uses DM. That's why I am trying to keep the DM_ suffix only for things that need it.
Quoted 38 lines
Quoted 31 lines
Quoted 31 lines
drivers/gpio/Kconfig +9
-0+ bool "Enable GPIO hog support" + depends on DM_GPIO + default n + help + Enable gpio hog support + The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. + config ALTERA_PIO bool "Altera PIO driver" depends on DM_GPIOdrivers/gpio/gpio-uclass.c +3
-0@@ -5,6 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> #include <dt-bindings/gpio/gpio.h> #include <errno.h> #include <fdtdec.h> @@ -141,6 +144,118 @@ static int gpio_find_and_xlate(struct gpio_desc *desc,return gpio_xlate_offs_flags (desc->dev, desc, args); }Quoted 6 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 150
Quoted 4 lines
drivers/gpio/gpio-uclass.c +4
-0+#if defined(CONFIG_DM_GPIO_HOG) + +struct gpio_hog_priv { + struct gpio_desc gpiod;As above I don't think you need this.
Quoted 2 lines
Hmm.. when probing I need to request the gpio with
gpio_dev_request_index()for which I need to pass a pointer to structgpio_desc...
The caller can declare this in a local variable.
Quoted 4 lines
And later I want to have the possibility to access the gpio for example with
dm_gpio_set_value()and need therefore the gpio descriptor, so I must store it somewhere. Or do I overlook something obvious?
In that case the caller should store it, perhaps in a local variable, or perhaps in a private data structure if needed for a long time.
[..]
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpio/gpio-uclass.c +4
-0+ +return 0 ; +} +Quoted 8 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 217
Quoted 6 lines
drivers/gpio/gpio-uclass.c +6
-0+int gpio_hog_probe_all (void ) +{ +struct udevice *dev; +int ret; + + for (uclass_first_device(UCLASS_NOP, &dev);Perhaps you should create a new uclass for this?
Quoted 4 lines
Hmm.. yes, I had an approach with a new uclass, but I thought, the new [1]
UCLASS_NOPis valid for this here to?
I see your point and I can see arguments for each side. But the fact that you have to check the driver suggests to me that a new uclass is better.
[..]
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
drivers/gpio/gpio-uclass.c +5
-0+/** +* gpio_hog_probe_all() - probe all gpio devices with +* gpio-hog subnodes. +* +* @return: Returns return value from device_probe()
Quoted 6 lines
Quoted 1 line
What if one fails and the others succeed?
Currently I return with error code from
device_probe(). So the rest of the gpio-hogs are not probed.Hmm.. may it is better to emmit a debug message and continue?
Sounds reasonable. But it seems to me that if there is an error there should be some visible report, so this could perhaps return the error code? Then the caller could print a messag?
Regards,
SImon
PATCH v4 1/1 gpio: add gpio-hog support
Hello Simon,
Am 26.06.2019 um 17:07 schrieb Simon Glass:
Quoted 41 lines
Hi Heiko,
Quoted 30 lines · Heiko Schocher
Hello Simon,
Am 22.06.2019 um 21:09 schrieb Simon Glass:
Quoted 26 lines
Hi Heiko,
Quoted 21 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe function[..]
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
+config
DM_GPIO_HOGCan we drop the
DM_prefix? At some pointDM_GPIOwill go away and we don't want to rename these sorts of options.
Quoted 7 lines
Quoted 3 lines
Hmm... we also have the
DM_GPIOsymbol, as the gpio hog only works withDM_GPIOenabled, I thoughtDM_GPIO_HOGis the better choice, but of course I can change this.Yes I understand that, but in general we hope one day to rename
DM_GPIOto GPIO, once everything uses DM. That's why I am trying to keep theDM_suffix only for things that need it.
Yep, already dropped, see temp version (travisbuild clean):
https://github.com/hsdenx/u-boot-test/commit/509bad758b8abc94dbbebc2a387b9e97c30b6543
Quoted 38 lines
Quoted 38 lines
Quoted 37 lines
Quoted 28 lines
drivers/gpio/Kconfig +9
-0+ bool "Enable GPIO hog support" + depends on DM_GPIO + default n + help + Enable gpio hog support + The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. + config ALTERA_PIO bool "Altera PIO driver" depends on DM_GPIOdrivers/gpio/gpio-uclass.c +3
-0@@ -5,6 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> #include <dt-bindings/gpio/gpio.h> #include <errno.h> #include <fdtdec.h> drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 150
Quoted 7 lines
drivers/gpio/gpio-uclass.c +4
-0@@ -141,6 +144,118 @@ static int gpio_find_and_xlate(struct gpio_desc *desc,return gpio_xlate_offs_flags (desc->dev, desc, args); } +#if defined(CONFIG_DM_GPIO_HOG) + +struct gpio_hog_priv { + struct gpio_desc gpiod;As above I don't think you need this.
Quoted 4 lines
Quoted 2 lines
Hmm.. when probing I need to request the gpio with
gpio_dev_request_index()for which I need to pass a pointer to structgpio_desc...The caller can declare this in a local variable.
The caller is always the device probe function, as gpio_hog_probe_all() loops over all gpio hog devices and probes them with device_probe() which cannot return a gpio_desc pointer, nor can such a pointer passed to.
Why isn't it valid to store in each gpio hog device the gpio desc it belongs too in device private data?
Quoted 8 lines
Quoted 3 lines
And later I want to have the possibility to access the gpio for example with
dm_gpio_set_value()and need therefore the gpio descriptor, so I must store it somewhere. Or do I overlook something obvious?In that case the caller should store it, perhaps in a local variable, or perhaps in a private data structure if needed for a long time.
[..]
Of course I can introduce a list for each gpio hog definition filled when calling gpio_hog_probe_all() ... but than I have a second list which uses memory, may has to keep in sync the list if device are removed ... I want to avoid such an approach ... as we have already a list of gpio hog devices and the priv storage pointer for device private data.
What do you think?
Quoted 16 lines
Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpio/gpio-uclass.c +4
-0+ +return 0 ; +} +Quoted 8 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 217
Quoted 6 lines
drivers/gpio/gpio-uclass.c +6
-0+int gpio_hog_probe_all (void ) +{ +struct udevice *dev; +int ret; + + for (uclass_first_device(UCLASS_NOP, &dev);Perhaps you should create a new uclass for this?
Hmm.. yes, I had an approach with a new uclass, but I thought, the new [1]
UCLASS_NOPis valid for this here to?
Quoted 7 lines
Quoted 1 line
I see your point and I can see arguments for each side. But the fact that you have to check the driver suggests to me that a new uclass is better.
[..]
Ok with this approach the gpio_hog additions to gpio-uclass can be moved to a gpio-hog-uclass.c file. Also the problem where to store the gpio descriptor moves from device private data to uclass private data?
Is it worth?
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 165
Quoted 5 lines
drivers/gpio/gpio-uclass.c +5
-0+/** +* gpio_hog_probe_all() - probe all gpio devices with +* gpio-hog subnodes. +* +* @return: Returns return value from device_probe() What if one fails and the others succeed?
Quoted 8 lines
Quoted 4 lines
Currently I return with error code from
device_probe(). So the rest of the gpio-hogs are not probed.Hmm.. may it is better to emmit a debug message and continue?
Sounds reasonable. But it seems to me that if there is an error there should be some visible report, so this could perhaps return the error code? Then the caller could print a messag?
Ok, so I add a printf message. I like more to add it in gpio_hog_probe_all(), because more than one gpio_hog can fail.
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 v4 1/1 gpio: add gpio-hog support
Hello Simon,
gentle ping to my questions only ... hope I did not missed an answer from you ...
Am 27.06.2019 um 06:12 schrieb Heiko Schocher:
Quoted 96 lines
Hello Simon,
Am 26.06.2019 um 17:07 schrieb Simon Glass:
Quoted 41 lines
Hi Heiko,
Quoted 30 lines · Heiko Schocher
Hello Simon,
Am 22.06.2019 um 21:09 schrieb Simon Glass:
Quoted 26 lines
Hi Heiko,
Quoted 21 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe function[..]
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
+config
DM_GPIO_HOGCan we drop the
DM_prefix? At some pointDM_GPIOwill go away and we don't want to rename these sorts of options.Quoted 7 lines
Quoted 3 lines
Hmm... we also have the
DM_GPIOsymbol, as the gpio hog only works withDM_GPIOenabled, I thoughtDM_GPIO_HOGis the better choice, but of course I can change this.Yes I understand that, but in general we hope one day to rename
DM_GPIOto GPIO, once everything uses DM. That's why I am trying to keep theDM_suffix only for things that need it.Yep, already dropped, see temp version (travisbuild clean):
https://github.com/hsdenx/u-boot-test/commit/509bad758b8abc94dbbebc2a387b9e97c30b6543Quoted 41 lines
Quoted 40 lines
Quoted 31 lines
Quoted 31 lines
+ bool "Enable GPIO hog support"
+ depends onDM_GPIO
+ default n
+ help
+ Enable gpio hog support
+ The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. +
configALTERA_PIO
bool "Altera PIO driver"
depends onDM_GPIOdrivers/gpio/gpio-uclass.c +3
-0@@ -5,6 +5,9 @@ #include <common.h> #include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> #include <dt-bindings/gpio/gpio.h> #include <errno.h> #include <fdtdec.h>@@ -141,6 +144,118 @@ static int gpio_find_and_xlate(struct gpio_desc *desc, return gpio_xlate_offs_flags(desc->dev, desc, args); }Quoted 6 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 150
Quoted 4 lines
drivers/gpio/gpio-uclass.c +4
-0+#if defined(CONFIG_DM_GPIO_HOG) + +struct gpio_hog_priv { + struct gpio_desc gpiod;As above I don't think you need this.
Hmm.. when probing I need to request the gpio with
gpio_dev_request_index()for which I need to pass a pointer to structgpio_desc...
Quoted 8 lines
Quoted 1 line
The caller can declare this in a local variable.
The caller is always the device probe function, as
gpio_hog_probe_all()loops over all gpio hog devices and probes them withdevice_probe()which cannot return agpio_descpointer, nor can such a pointer passed to.Why isn't it valid to store in each gpio hog device the gpio desc it belongs too in device private data?
?
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
And later I want to have the possibility to access the gpio for example with
dm_gpio_set_value()and need therefore the gpio descriptor, so I must store it somewhere. Or do I overlook something obvious?In that case the caller should store it, perhaps in a local variable, or perhaps in a private data structure if needed for a long time.
[..]
Quoted 8 lines
Of course I can introduce a list for each gpio hog definition filled when calling
gpio_hog_probe_all()... but than I have a second list which uses memory, may has to keep in sync the list if device are removed ... I want to avoid such an approach ... as we have already a list of gpio hog devices and the priv storage pointer for device private data.What do you think?
?
Quoted 22 lines
Quoted 22 lines
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpio/gpio-uclass.c +4
-0+ + return 0; +} +Quoted 8 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 217
Quoted 6 lines
drivers/gpio/gpio-uclass.c +6
-0+int gpio_hog_probe_all (void ) +{ + struct udevice *dev; + int ret; + + for (uclass_first_device(UCLASS_NOP, &dev);Perhaps you should create a new uclass for this?
Quoted 4 lines
Hmm.. yes, I had an approach with a new uclass, but I thought, the new [1]
UCLASS_NOPis valid for this here to?I see your point and I can see arguments for each side. But the fact that you have to check the driver suggests to me that a new uclass is better.
Quoted 8 lines
Quoted 1 line
[..]
Ok with this approach the
gpio_hogadditions to gpio-uclass can be moved to agpio-hog-uclass.cfile. Also the problem where to store the gpio descriptor moves from device private data to uclass private data?Is it worth?
?
Quoted 17 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
+/**
+ *gpio_hog_probe_all()- probe all gpio devices with
+ * gpio-hog subnodes.
+ *
+ * @return: Returns return value fromdevice_probe()What if one fails and the others succeed?
Quoted 8 lines
Quoted 4 lines
Currently I return with error code from
device_probe(). So the rest of the gpio-hogs are not probed.Hmm.. may it is better to emmit a debug message and continue?
Sounds reasonable. But it seems to me that if there is an error there should be some visible report, so this could perhaps return the error code? Then the caller could print a messag?
Quoted 5 lines
Ok, so I add a printf message. I like more to add it in
gpio_hog_probe_all(), because more than onegpio_hogcan fail.bye,
Heiko
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 v4 1/1 gpio: add gpio-hog support
In reply to Heiko SchocherHi Heiko,
Quoted 97 lines · Heiko Schocher
Hello Simon,
Am 26.06.2019 um 17:07 schrieb Simon Glass:
Quoted 41 lines
Hi Heiko,
Quoted 30 lines · Heiko Schocher
Hello Simon,
Am 22.06.2019 um 21:09 schrieb Simon Glass:
Quoted 26 lines
Hi Heiko,
Quoted 21 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe function[..]
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
+config
DM_GPIO_HOGCan we drop the
DM_prefix? At some pointDM_GPIOwill go away and we don't want to rename these sorts of options.Quoted 7 lines
Quoted 3 lines
Hmm... we also have the
DM_GPIOsymbol, as the gpio hog only works withDM_GPIOenabled, I thoughtDM_GPIO_HOGis the better choice, but of course I can change this.Yes I understand that, but in general we hope one day to rename
DM_GPIOto GPIO, once everything uses DM. That's why I am trying to keep theDM_suffix only for things that need it.Yep, already dropped, see temp version (travisbuild clean):
https://github.com/hsdenx/u-boot-test/commit/509bad758b8abc94dbbebc2a387b9e97c30b6543Quoted 41 lines
Quoted 40 lines
Quoted 31 lines
Quoted 31 lines
drivers/gpio/Kconfig +9
-0+ bool "Enable GPIO hog support" + depends on DM_GPIO + default n + help + Enable gpio hog support + The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. + config ALTERA_PIO bool "Altera PIO driver" depends on DM_GPIOdrivers/gpio/gpio-uclass.c +3
-0@@ -5,6 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> #include <dt-bindings/gpio/gpio.h> #include <errno.h> #include <fdtdec.h> @@ -141,6 +144,118 @@ static int gpio_find_and_xlate(struct gpio_desc *desc,return gpio_xlate_offs_flags (desc->dev, desc, args); }Quoted 6 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 150
Quoted 4 lines
drivers/gpio/gpio-uclass.c +4
-0+#if defined(CONFIG_DM_GPIO_HOG) + +struct gpio_hog_priv { + struct gpio_desc gpiod;As above I don't think you need this.
Hmm.. when probing I need to request the gpio with
gpio_dev_request_index()for which I need to pass a pointer to structgpio_desc...
Quoted 8 lines
Quoted 1 line
The caller can declare this in a local variable.
The caller is always the device probe function, as
gpio_hog_probe_all()loops over all gpio hog devices and probes them withdevice_probe()which cannot return agpio_descpointer, nor can such a pointer passed to.Why isn't it valid to store in each gpio hog device the gpio desc it belongs too in device private data?
I don't see any point. Your caller needs to store the pointer anyway, or if not, could just as easily have a local variable with the info.
Also, passing a pointer to the struct is how we consistently do it so far.
What is the benefit of storing it in the callee rather than the caller?
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
And later I want to have the possibility to access the gpio for example with
dm_gpio_set_value()and need therefore the gpio descriptor, so I must store it somewhere. Or do I overlook something obvious?In that case the caller should store it, perhaps in a local variable, or perhaps in a private data structure if needed for a long time.
Quoted 8 lines
Quoted 1 line
[..]
Of course I can introduce a list for each gpio hog definition filled when calling
gpio_hog_probe_all()... but than I have a second list which uses memory, may has to keep in sync the list if device are removed ... I want to avoid such an approach ... as we have already a list of gpio hog devices and the priv storage pointer for device private data.
I understand what you are saying about devices being removed, but actually removable is fine, it's only unbinding that is dangerous. And we already have that problem. We would need to add refcounts to fix it, and given that bootloaders don't normally need to unbind, I have not worried about it too much.
The approach I suggest would not use any more memory I think.
Quoted 2 lines
What do you think?
Well I still think it is better to have the caller own the struct.
Quoted 23 lines
Quoted 23 lines
Quoted 14 lines
Quoted 13 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 217
Quoted 11 lines
drivers/gpio/gpio-uclass.c +10
-0+ +return 0 ; +} + +int gpio_hog_probe_all (void ) +{ +struct udevice *dev; +int ret; + + for (uclass_first_device(UCLASS_NOP, &dev);Perhaps you should create a new uclass for this?
Quoted 4 lines
Hmm.. yes, I had an approach with a new uclass, but I thought, the new [1]
UCLASS_NOPis valid for this here to?I see your point and I can see arguments for each side. But the fact that you have to check the driver suggests to me that a new uclass is better.
Quoted 6 lines
Quoted 1 line
[..]
Ok with this approach the
gpio_hogadditions to gpio-uclass can be moved to agpio-hog-uclass.cfile. Also the problem where to store the gpio descriptor moves from device private data to uclass private data?
I don't think you have explained why you actually need to store the GPIO descriptor. Where do you use it later? Is it just the gpio_hog_probe_all() function?
Quoted 14 lines
Is it worth?
Quoted 11 lines
Quoted 11 lines
Quoted 7 lines
Quoted 5 lines
+/**
+ *gpio_hog_probe_all()- probe all gpio devices with
+ * gpio-hog subnodes.
+ *
+ * @return: Returns return value fromdevice_probe()What if one fails and the others succeed?
Currently I return with error code from
device_probe(). So the rest of the gpio-hogs are not probed.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
Hmm.. may it is better to emmit a debug message and continue?
Sounds reasonable. But it seems to me that if there is an error there should be some visible report, so this could perhaps return the error code? Then the caller could print a messag?
Ok, so I add a printf message. I like more to add it in
gpio_hog_probe_all(), because more than onegpio_hogcan fail.
Regards,
Simon
PATCH v4 1/1 gpio: add gpio-hog support
Hello Simon,
Am 12.07.2019 um 23:11 schrieb Simon Glass:
Quoted 171 lines
Hi Heiko,
Quoted 97 lines · Heiko Schocher
Hello Simon,
Am 26.06.2019 um 17:07 schrieb Simon Glass:
Quoted 41 lines
Hi Heiko,
Quoted 30 lines · Heiko Schocher
Hello Simon,
Am 22.06.2019 um 21:09 schrieb Simon Glass:
Quoted 26 lines
Hi Heiko,
Quoted 21 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>---
clean travis build, see result:
https://travis-ci.org/hsdenx/u-boot-test/builds/544040419Changes in v4:
- rework as suggested by Patrick
based on patch:
http://patchwork.ozlabs.org/patch/1098913/
use newUCLASS_NOP
hog detection + DT parsing ingpio_post_bind().... info saved in platdata gpio configuration for hog (request andset_dir) => probe function[..]
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
+config
DM_GPIO_HOGCan we drop the
DM_prefix? At some pointDM_GPIOwill go away and we don't want to rename these sorts of options.Quoted 7 lines
Quoted 3 lines
Hmm... we also have the
DM_GPIOsymbol, as the gpio hog only works withDM_GPIOenabled, I thoughtDM_GPIO_HOGis the better choice, but of course I can change this.Yes I understand that, but in general we hope one day to rename
DM_GPIOto GPIO, once everything uses DM. That's why I am trying to keep theDM_suffix only for things that need it.Yep, already dropped, see temp version (travisbuild clean):
https://github.com/hsdenx/u-boot-test/commit/509bad758b8abc94dbbebc2a387b9e97c30b6543Quoted 41 lines
Quoted 40 lines
Quoted 31 lines
Quoted 31 lines
drivers/gpio/Kconfig +9
-0+ bool "Enable GPIO hog support" + depends on DM_GPIO + default n + help + Enable gpio hog support + The GPIO chip may contain GPIO hog definitions. GPIO hogging + is a mechanism providing automatic GPIO request and config- + uration as part of the gpio-controller's driver probe function. + config ALTERA_PIO bool "Altera PIO driver" depends on DM_GPIOdrivers/gpio/gpio-uclass.c +3
-0@@ -5,6 +5,9 @@#include <common.h> #include <dm.h> +#include <dm/device-internal.h> +#include <dm/lists.h> +#include <dm/uclass-internal.h> #include <dt-bindings/gpio/gpio.h> #include <errno.h> #include <fdtdec.h> @@ -141,6 +144,118 @@ static int gpio_find_and_xlate(struct gpio_desc *desc,return gpio_xlate_offs_flags (desc->dev, desc, args); }Quoted 6 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 150
Quoted 4 lines
drivers/gpio/gpio-uclass.c +4
-0+#if defined(CONFIG_DM_GPIO_HOG) + +struct gpio_hog_priv { + struct gpio_desc gpiod;As above I don't think you need this.
Hmm.. when probing I need to request the gpio with
gpio_dev_request_index()for which I need to pass a pointer to structgpio_desc...Quoted 8 lines
Quoted 1 line
The caller can declare this in a local variable.
The caller is always the device probe function, as
gpio_hog_probe_all()loops over all gpio hog devices and probes them withdevice_probe()which cannot return agpio_descpointer, nor can such a pointer passed to.Why isn't it valid to store in each gpio hog device the gpio desc it belongs too in device private data?
I don't see any point. Your caller needs to store the pointer anyway, or if not, could just as easily have a local variable with the info.
Also, passing a pointer to the struct is how we consistently do it so far.
What is the benefit of storing it in the callee rather than the caller?
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
And later I want to have the possibility to access the gpio for example with
dm_gpio_set_value()and need therefore the gpio descriptor, so I must store it somewhere. Or do I overlook something obvious?In that case the caller should store it, perhaps in a local variable, or perhaps in a private data structure if needed for a long time.
Quoted 8 lines
Quoted 1 line
[..]
Of course I can introduce a list for each gpio hog definition filled when calling
gpio_hog_probe_all()... but than I have a second list which uses memory, may has to keep in sync the list if device are removed ... I want to avoid such an approach ... as we have already a list of gpio hog devices and the priv storage pointer for device private data.I understand what you are saying about devices being removed, but actually removable is fine, it's only unbinding that is dangerous. And we already have that problem. We would need to add refcounts to fix it, and given that bootloaders don't normally need to unbind, I have not worried about it too much.
The approach I suggest would not use any more memory I think.
Quoted 2 lines
What do you think?
Well I still think it is better to have the caller own the struct.
Quoted 25 lines
Quoted 24 lines
Quoted 14 lines
Quoted 13 lines
drivers/gpio/gpio-uclass.c static int gpio_find_and_xlate(struct gpio_desc *desc, · line 217
Quoted 11 lines
drivers/gpio/gpio-uclass.c +10
-0+ +return 0 ; +} + +int gpio_hog_probe_all (void ) +{ +struct udevice *dev; +int ret; + + for (uclass_first_device(UCLASS_NOP, &dev);Perhaps you should create a new uclass for this?
Quoted 4 lines
Hmm.. yes, I had an approach with a new uclass, but I thought, the new [1]
UCLASS_NOPis valid for this here to?I see your point and I can see arguments for each side. But the fact that you have to check the driver suggests to me that a new uclass is better.
[..]
Quoted 8 lines
Quoted 4 lines
Ok with this approach the
gpio_hogadditions to gpio-uclass can be moved to agpio-hog-uclass.cfile. Also the problem where to store the gpio descriptor moves from device private data to uclass private data?I don't think you have explained why you actually need to store the GPIO descriptor. Where do you use it later? Is it just the
gpio_hog_probe_all()function?
You can use it later! See example this patch adds in doc/device-tree-bindings/gpio/gpio.txt:
+ struct gpio_desc *desc;
+ int ret;
+
+ ret = gpio_hog_lookup_name("boot_rescue", &desc);
+ if (ret)
+ return;
+ if (dm_gpio_get_value(desc) == 1)
+ printf("\nBooting into Rescue System\n");
+ else if (dm_gpio_get_value(desc) == 0)
+ printf("\nBoot normal\n");
So in this example, gpio "board_rescue" is defined through DTS and code which uses this gpio is generic ... makes it nice to handle board differences (as I have on the aristainetos board, which I rework for DM support).
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 v4 1/1 gpio: add gpio-hog support
In reply to Heiko SchocherQuoted 10 lines · Heiko Schocher
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>Tested-by Patrick Delaunay <[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: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190714/d6b0ad81/attachment.sig>
PATCH v4 1/1 gpio: add gpio-hog support
Hello Tom,
Am 14.07.2019 um 15:08 schrieb Tom Rini:
Quoted 6 lines · Heiko Schocher
Quoted 5 lines
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
Quoted 8 lines
Quoted 6 lines
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>Tested-by Patrick Delaunay <[email protected]>Applied to u-boot/master, thanks!
Ups, Simon (added to cc) has some comments to v4 I mainly worked in ...
Is it OK to send based on this commit a followup patch with the comments from Simon worked in?
If you want to look into this patch, you will find current state here:
https://github.com/hsdenx/u-boot-test/commit/30134bab8d5e56708943473f294676b237e8614c
travis build in progress:
https://travis-ci.org/hsdenx/u-boot-test/builds/558774593
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 v4 1/1 gpio: add gpio-hog support
Quoted 20 lines · Heiko Schocher
Hello Tom,
Am 14.07.2019 um 15:08 schrieb Tom Rini:
Quoted 6 lines · Heiko Schocher
Quoted 5 lines
add gpio-hog support. GPIO hogging is a mechanism providing automatic GPIO request and configuration as part of the gpio-controller's driver probe function.
Quoted 8 lines
Quoted 6 lines
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>Tested-by Patrick Delaunay <[email protected]>Applied to u-boot/master, thanks!
Ups, Simon (added to cc) has some comments to v4 I mainly worked in ...
Quoted 8 lines
Is it OK to send based on this commit a followup patch with the comments from Simon worked in?
If you want to look into this patch, you will find current state here:
https://github.com/hsdenx/u-boot-test/commit/30134bab8d5e56708943473f294676b237e8614ctravis build in progress:
https://travis-ci.org/hsdenx/u-boot-test/builds/558774593
Yes please, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190715/d18fd994/attachment.sig>