summaryrefslogtreecommitdiff
path: root/drivers/gpio/gpio-uclass.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-08-07 16:24:12 +0300
committerSimon Glass <sjg@chromium.org>2021-09-25 18:46:15 +0300
commit48609d0789f811014b33e6eefc2c27c99be7fea7 (patch)
treea60a6c721d5776859926501269c2a9f08235bb26 /drivers/gpio/gpio-uclass.c
parent3e57ad907caa55bab8ba52ef87ddbc5130aede2c (diff)
downloadu-boot-48609d0789f811014b33e6eefc2c27c99be7fea7.tar.xz
dm: gpio: Add of-platdata support
Add support for accessing GPIOs using of-plata. This uses the same mechanism as for clocks, but allows use of the xlate() method so that the driver can interpret the parameters. Update the condition for GPIO_HOG so that it is not built into SPL, since it needs SPL_OF_REAL which is not enabled in sandbox_spl. Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/gpio/gpio-uclass.c')
-rw-r--r--drivers/gpio/gpio-uclass.c26
1 files changed, 24 insertions, 2 deletions
diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index e0d3ae6f8c..bb2f23241e 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -7,6 +7,7 @@
#include <common.h>
#include <dm.h>
+#include <dt-structs.h>
#include <log.h>
#include <dm/devres.h>
#include <dm/device_compat.h>
@@ -231,7 +232,7 @@ static int gpio_find_and_xlate(struct gpio_desc *desc,
return gpio_xlate_offs_flags(desc->dev, desc, args);
}
-#if defined(CONFIG_GPIO_HOG)
+#if CONFIG_IS_ENABLED(GPIO_HOG)
struct gpio_hog_priv {
struct gpio_desc gpiod;
@@ -1226,6 +1227,27 @@ int gpio_get_list_count(struct udevice *dev, const char *list_name)
}
#endif /* OF_PLATDATA */
+#if CONFIG_IS_ENABLED(OF_PLATDATA)
+int gpio_request_by_phandle(struct udevice *dev,
+ const struct phandle_2_arg *cells,
+ struct gpio_desc *desc, int flags)
+{
+ struct ofnode_phandle_args args;
+ struct udevice *gpio_dev;
+ const int index = 0;
+ int ret;
+
+ ret = device_get_by_ofplat_idx(cells->idx, &gpio_dev);
+ if (ret)
+ return ret;
+ args.args[0] = cells->arg[0];
+ args.args[1] = cells->arg[1];
+
+ return gpio_request_tail(ret, NULL, &args, NULL, index, desc, flags,
+ index > 0, gpio_dev);
+}
+#endif
+
int dm_gpio_free(struct udevice *dev, struct gpio_desc *desc)
{
/* For now, we don't do any checking of dev */
@@ -1430,7 +1452,7 @@ static int gpio_post_bind(struct udevice *dev)
}
#endif
- if (IS_ENABLED(CONFIG_GPIO_HOG)) {
+ if (CONFIG_IS_ENABLED(OF_REAL) && IS_ENABLED(CONFIG_GPIO_HOG)) {
dev_for_each_subnode(node, dev) {
if (ofnode_read_bool(node, "gpio-hog")) {
const char *name = ofnode_get_name(node);