[U-Boot] [PATCH v2 08/18] gpio: Add gpio_request_simple function

Stefan Roese sr at denx.de
Wed Jan 18 17:34:48 CET 2017


On 11.01.2017 16:00, Mario Six wrote:
> For board initialization, usage of GPIOs is sometimes needed, e.g. to
> initialize certain devices such as FPGAs. But since there currently is no
> device associated to the board itself, initialization routines have to
> cumbersomely get GPIOs via gpio_request_by_name_nodev.
>
> This patch adds a convenience function aimed at such scenarios, which wraps the
> gpio_request_by_name_nodev and some error checking. The GPIO is identified via
> its compatible string in the device tree.
>
> Signed-off-by: Mario Six <mario.six at gdsys.cc>
> ---
> Changes in v2:
>
> New in v2
> ---
>  drivers/gpio/gpio-uclass.c | 17 +++++++++++++++++
>  include/asm-generic/gpio.h | 22 ++++++++++++++++++++++
>  2 files changed, 39 insertions(+)
>
> diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
> index 4559739..197d987 100644
> --- a/drivers/gpio/gpio-uclass.c
> +++ b/drivers/gpio/gpio-uclass.c
> @@ -751,6 +751,23 @@ int gpio_request_list_by_name(struct udevice *dev, const char *list_name,
>  					       flags);
>  }
>
> +bool gpio_request_simple(char *name, struct gpio_desc *gpio)
> +{
> +	int node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, name);
> +	int ret;
> +
> +	if (node < 0)
> +		return false;
> +
> +	ret = gpio_request_by_name_nodev(gd->fdt_blob, node, "gpios", 0, gpio,
> +					 0);
> +
> +	if (ret < 0)
> +		return false;
> +
> +	return dm_gpio_is_valid(gpio);
> +}
> +
>  int gpio_get_list_count(struct udevice *dev, const char *list_name)
>  {
>  	int ret;
> diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
> index 4aa0004..5c3e599 100644
> --- a/include/asm-generic/gpio.h
> +++ b/include/asm-generic/gpio.h
> @@ -457,6 +457,28 @@ int gpio_request_list_by_name(struct udevice *dev, const char *list_name,
>  			      int flags);
>
>  /**
> + * gpio_request_simple() - Simple wrapper function to request GPIO via
> + *                         fdt compatible name
> + *
> + * Convenience method to get useable GPIO description information from a device
> + * tree declaration such as:
> + *
> + *   fpga_ready_gpio {
> + *       compatible = "generic,fpga-ready-gpio";
> + *       gpios = <&PCA22 27 0>;
> + *   };
> + *
> + * This is convenient for setting and reading GPIOs from board files (where no
> + * associated device is in play).
> + *
> + * @name: The fdt compatible string of the GPIO in question
> + * @gpio: Return the GPIO description information of the GPIO in question
> + *
> + * @return true if the operation succeeded, false if not
> + */
> +bool gpio_request_simple(char *name, struct gpio_desc *gpio);

So you have GPIOs that are not directly integrated in some other
device, like its usually the case for some power or reset GPIOs
that are e.g. used in USB DT nodes?

I'm not sure if this DT implementation would be accepted in the
Linux kernel. How do you handle it in Linux?

Thanks,
Stefan


More information about the U-Boot mailing list