From 9d8ca9fce48ae87cde8c555ea7ccaa0b6efe0bff Mon Sep 17 00:00:00 2001 From: Carlos Llamas Date: Tue, 5 May 2026 20:29:06 +0000 Subject: [PATCH] Revert "gpio: remove of_get_named_gpio() and " This reverts commit b6420bd5aa0c374331bad6c0fa2eb5f0f87cf5a0. There are many OOT drivers still using this API, so bring this back temporarily while all the users are converted to the new descriptor based GPIO alternative. Bug: 509877995 Change-Id: I3bbdef1934593f9e03ab1a8970b525bafde26bed Signed-off-by: Carlos Llamas --- MAINTAINERS | 1 + drivers/gpio/TODO | 28 ++++++++++++++++++++++++++++ drivers/gpio/gpiolib-of.c | 27 +++++++++++++++++++++++++++ include/linux/of_gpio.h | 38 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 include/linux/of_gpio.h diff --git a/MAINTAINERS b/MAINTAINERS index 165c045c0707..4312bec61f24 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10982,6 +10982,7 @@ F: drivers/gpio/ F: include/dt-bindings/gpio/ F: include/linux/gpio.h F: include/linux/gpio/ +F: include/linux/of_gpio.h K: (devm_)?gpio_(request|free|direction|get|set) K: GPIOD_FLAGS_BIT_NONEXCLUSIVE K: devm_gpiod_unhinge diff --git a/drivers/gpio/TODO b/drivers/gpio/TODO index 7ce80fde1f17..5acaeab029ec 100644 --- a/drivers/gpio/TODO +++ b/drivers/gpio/TODO @@ -58,6 +58,34 @@ Work items: ------------------------------------------------------------------------------- +Get rid of + +This header and helpers appeared at one point when there was no proper +driver infrastructure for doing simpler MMIO GPIO devices and there was +no core support for parsing device tree GPIOs from the core library with +the [devm_]gpiod_get() calls we have today that will implicitly go into +the device tree back-end. It is legacy and should not be used in new code. + +Work items: + +- Change all consumer drivers that #include to + #include and stop doing custom parsing of the + GPIO lines from the device tree. This can be tricky and often involves + changing board files, etc. + +- Pull semantics for legacy device tree (OF) GPIO lookups into + gpiolib-of.c: in some cases subsystems are doing custom flags and + lookups for polarity inversion, open drain and what not. As we now + handle this with generic OF bindings, pull all legacy handling into + gpiolib so the library API becomes narrow and deep and handle all + legacy bindings internally. (See e.g. commits 6953c57ab172, + 6a537d48461d etc) + +- Delete when all the above is complete and everything + uses or instead. + +------------------------------------------------------------------------------- + Collect drivers Collect GPIO drivers from arch/* and other places that should be placed diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 727d6956748f..c9a365d96308 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -446,6 +447,32 @@ out: return desc; } +/** + * of_get_named_gpio() - Get a GPIO number to use with GPIO API + * @np: device node to get GPIO from + * @propname: Name of property containing gpio specifier(s) + * @index: index of the GPIO + * + * **DEPRECATED** This function is deprecated and must not be used in new code. + * + * Returns: + * GPIO number to use with Linux generic GPIO API, or one of the errno + * value on the error condition. + */ +int of_get_named_gpio(const struct device_node *np, const char *propname, + int index) +{ + struct gpio_desc *desc; + + desc = of_get_named_gpiod_flags(np, propname, index, NULL); + + if (IS_ERR(desc)) + return PTR_ERR(desc); + else + return desc_to_gpio(desc); +} +EXPORT_SYMBOL_GPL(of_get_named_gpio); + /* Converts gpio_lookup_flags into bitmask of GPIO_* values */ static unsigned long of_convert_gpio_flags(enum of_gpio_flags flags) { diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h new file mode 100644 index 000000000000..d0f66a5e1b2a --- /dev/null +++ b/include/linux/of_gpio.h @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* + * OF helpers for the GPIO API + * + * Copyright (c) 2007-2008 MontaVista Software, Inc. + * + * Author: Anton Vorontsov + */ + +#ifndef __LINUX_OF_GPIO_H +#define __LINUX_OF_GPIO_H + +#include +#include +#include /* FIXME: Shouldn't be here */ +#include + +struct device_node; + +#ifdef CONFIG_OF_GPIO + +extern int of_get_named_gpio(const struct device_node *np, + const char *list_name, int index); + +#else /* CONFIG_OF_GPIO */ + +#include + +/* Drivers may not strictly depend on the GPIO support, so let them link. */ +static inline int of_get_named_gpio(const struct device_node *np, + const char *propname, int index) +{ + return -ENOSYS; +} + +#endif /* CONFIG_OF_GPIO */ + +#endif /* __LINUX_OF_GPIO_H */