summaryrefslogtreecommitdiff
path: root/include/sbi_utils/gpio
diff options
context:
space:
mode:
authorAnup Patel <anup.patel@wdc.com>2021-07-13 06:23:43 +0300
committerAnup Patel <anup@brainfault.org>2021-07-17 11:11:17 +0300
commitc14f1fe0dfd96d7be1ed2abba0a873110cdbcc9d (patch)
tree2de83bb9c9ed98d47e0d3672535489b541a3044e /include/sbi_utils/gpio
parent36b8effe4a07bbf476deca6c8769529c69078f08 (diff)
downloadopensbi-c14f1fe0dfd96d7be1ed2abba0a873110cdbcc9d.tar.xz
lib: utils/gpio: Add simple FDT based GPIO framework
We add a simple FDT based GPIO framework which is built on top of generic GPIO library. The phandle of FDT GPIO chip DT node is treated as unique GPIO chip ID required by the generic GPIO library. The FDT based GPIO chip drivers will be probed on-demand from fdt_gpio_pin_get() called by the GPIO client drivers. Signed-off-by: Anup Patel <anup.patel@wdc.com> Reviewed-by: Atish Patra <atish.patra@wdc.com>
Diffstat (limited to 'include/sbi_utils/gpio')
-rw-r--r--include/sbi_utils/gpio/fdt_gpio.h34
1 files changed, 34 insertions, 0 deletions
diff --git a/include/sbi_utils/gpio/fdt_gpio.h b/include/sbi_utils/gpio/fdt_gpio.h
new file mode 100644
index 0000000..19e1b58
--- /dev/null
+++ b/include/sbi_utils/gpio/fdt_gpio.h
@@ -0,0 +1,34 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2021 Western Digital Corporation or its affiliates.
+ *
+ * Authors:
+ * Anup Patel <anup.patel@wdc.com>
+ */
+
+#ifndef __FDT_GPIO_H__
+#define __FDT_GPIO_H__
+
+#include <sbi_utils/gpio/gpio.h>
+
+/** FDT based GPIO driver */
+struct fdt_gpio {
+ const struct fdt_match *match_table;
+ int (*xlate)(struct gpio_chip *chip,
+ const struct fdt_phandle_args *pargs,
+ struct gpio_pin *out_pin);
+ int (*init)(void *fdt, int nodeoff, u32 phandle,
+ const struct fdt_match *match);
+};
+
+/** Get a GPIO pin using "gpios" DT property of client DT node */
+int fdt_gpio_pin_get(void *fdt, int nodeoff, int index,
+ struct gpio_pin *out_pin);
+
+/** Simple xlate function to convert two GPIO FDT cells into GPIO pin */
+int fdt_gpio_simple_xlate(struct gpio_chip *chip,
+ const struct fdt_phandle_args *pargs,
+ struct gpio_pin *out_pin);
+
+#endif