gpio: add gpio-hog support
Subsystems (2)
PATCH 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:
https://travis-ci.org/hsdenx/u-boot-test/builds/537358599
doc/device-tree-bindings/gpio/gpio.txt | 52 ++++++++ drivers/gpio/Kconfig | 10 ++ drivers/gpio/gpio-uclass.c | 162 +++++++++++++++++++++++-- include/asm-generic/gpio.h | 24 ++++ 4 files changed, 236 insertions(+), 12 deletions(-)
doc/device-tree-bindings/gpio/gpio.txt +52 -0
@@ -210,3 +210,55 @@ 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. + +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_GPIO
drivers/gpio/gpio-uclass.c +150 -12
233 lines not on this page · raw message
include/asm-generic/gpio.h +24 -0
@@ -348,6 +348,14 @@ 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_lookup_name - Look up a GPIO name and return its details *
@@ -503,6 +511,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 +* @ofnode: of node wich requests the GPIO +* @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,ofnode node,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 1/1 gpio: add gpio-hog support
Quoted 8 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]>
I have tested it on zcu102 where I use gpio hogs for gt muxes. gpio hogs are handled and setup only when gpio controller is probed. Do we have a way how to say that controllers with gpio hogs should be probed automatically?
Right now you are calling it in post_probe which make sense but on the other hand if you find gpio hog in bind you should probe the whole driver without asking for request.
Thanks,
Michal
PATCH 1/1 gpio: add gpio-hog support
Hello Michal,
Am 27.05.2019 um 09:13 schrieb Michal Simek:
Quoted 11 lines · Heiko Schocher
Quoted 8 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.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>I have tested it on zcu102 where I use gpio hogs for gt muxes.
Thanks!
Quoted 1 line
gpio hogs are handled and setup only when gpio controller is probed.
Yes, with my current approach ... If you need a gpio-hog in a gpio device, wich is not used, you can add in board code:
gpio_hog_lookup_name("name_of_the_gpio_hog");
and gpio driver (and gpio hogs) get probed ... but not really nice...
Quoted 2 lines
Do we have a way how to say that controllers with gpio hogs should be probed automatically?
No yet, but I am open for suggestions ;-)
Quoted 3 lines
Right now you are calling it in
post_probewhich make sense but on the other hand if you find gpio hog in bind you should probe the whole driver without asking for request.
Yes, I also thought about this approach, but the problem is in
static int gpio_hog(struct udevice *dev)
{
ofnode node;
struct gpio_dev_priv *uc_priv = NULL;
uc_priv = dev_get_uclass_priv(dev);
if (!uc_priv) {
printf("%s: missing private data.\n", __func__);
return -EINVAL;
}uc_priv is not valid @bind stage ...
But I can think of a function which scans all gpio nodes for gpio hog subnodes, and call device_probe() ?
But from where should this function be called?
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 1/1 gpio: add gpio-hog support
Quoted 48 lines · Heiko Schocher
Hello Michal,
Am 27.05.2019 um 09:13 schrieb Michal Simek:
Quoted 11 lines · Heiko Schocher
Quoted 8 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.
for more infos see:
doc/device-tree-bindings/gpio/gpio.txtSigned-off-by Heiko Schocher <[email protected]>I have tested it on zcu102 where I use gpio hogs for gt muxes.
Thanks!
Quoted 1 line
gpio hogs are handled and setup only when gpio controller is probed.
Yes, with my current approach ... If you need a gpio-hog in a gpio device, wich is not used, you can add in board code:
gpio_hog_lookup_name("name_of_the_gpio_hog");and gpio driver (and gpio hogs) get probed ... but not really nice...
Quoted 2 lines
Do we have a way how to say that controllers with gpio hogs should be probed automatically?
No yet, but I am open for suggestions ;-)
Quoted 3 lines
Right now you are calling it in
post_probewhich make sense but on the other hand if you find gpio hog in bind you should probe the whole driver without asking for request.Yes, I also thought about this approach, but the problem is in
static int
gpio_hog(struct udevice *dev)
{
ofnode node;
structgpio_dev_priv*uc_priv= NULL;
uc_priv=dev_get_uclass_priv(dev);
if (!uc_priv) {
printf("%s: missing private data.\n", __func__); return-EINVAL;
}
Quoted 6 lines
uc_privis not valid @bind stage ...But I can think of a function which scans all gpio nodes for gpio hog subnodes, and call
device_probe()?But from where should this function be called?
The question is if this patch is reading that gpio-hogs at right stage. Right now you are decoding them in post_probe. Normally getting information from DT is done in ofdata_to_platdata.
It is question if this approach is also working for non DT case.
Anyway let's say you setup a flag in ofdata_to_platdata that there are gpio hogs and then you know if you should probe that device or not.
btw: didn't send this before you v2 but should be still valid. Let me test v2 now.
M