
Add support for requesting GPIOs with a live device tree.
Signed-off-by: Simon Glass sjg@chromium.org ---
drivers/gpio/gpio-uclass.c | 44 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 8 deletions(-)
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c index 721e95cd929..377729e3c62 100644 --- a/drivers/gpio/gpio-uclass.c +++ b/drivers/gpio/gpio-uclass.c @@ -11,6 +11,8 @@ #include <fdtdec.h> #include <malloc.h> #include <asm/gpio.h> +#include <dm/of_access.h> +#include <dm/of_dev.h> #include <linux/bug.h> #include <linux/ctype.h>
@@ -711,16 +713,42 @@ int gpio_request_by_name_nodev(const void *blob, int node, flags, index > 0); }
-int gpio_request_by_name(struct udevice *dev, const char *list_name, int index, +static int _gpio_request_by_name(const struct device_node *np, + const char *list_name, int index, + struct gpio_desc *desc, int flags, + bool add_index) +{ + struct of_phandle_args of_args; + struct of_ref_phandle_args args; + int ret; + + ret = of_parse_phandle_with_args(np, list_name, "#gpio-cells", index, + &of_args); + if (ret) + debug("%s: of_parse_phandle_with_args failed\n", __func__); + else + of_ref_from_of_phandle_args(&of_args, &args); + + return gpio_request_tail(ret, of_node_to_ref(np), &args, list_name, + index, desc, flags, add_index); +} + +int gpio_request_by_name(struct udevice *dev, const char *list_name, int index, struct gpio_desc *desc, int flags) { - /* - * This isn't ideal since we don't use dev->name in the debug() - * calls in gpio_request_by_name(), but we can do this until - * gpio_request_by_name_nodev() can be dropped. - */ - return gpio_request_by_name_nodev(gd->fdt_blob, dev_of_offset(dev), - list_name, index, desc, flags); + if (of_use_livetree()) { + return _gpio_request_by_name(dev_of_node(dev), list_name, + index, desc, flags, index > 0); + } else { + /* + * This isn't ideal since we don't use dev->name in the debug() + * calls in gpio_request_by_name(), but we can do this until + * gpio_request_by_name_nodev() can be dropped. + */ + return gpio_request_by_name_nodev(gd->fdt_blob, + dev_of_offset(dev), list_name, + index, desc, flags); + } }
int gpio_request_list_by_name_nodev(const void *blob, int node,