All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anup Patel <apatel@ventanamicro.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 09/11] lib: utils/gpio: Generate FDT gpio driver list at compile-time
Date: Tue,  3 May 2022 09:07:57 +0530	[thread overview]
Message-ID: <20220503033759.544156-10-apatel@ventanamicro.com> (raw)
In-Reply-To: <20220503033759.544156-1-apatel@ventanamicro.com>

Instead of having FDT gpio driver list hard-coded in the C source,
we generate it using carray.sh at compile-time.

Signed-off-by: Anup Patel <apatel@ventanamicro.com>
---
 include/sbi_utils/gpio/fdt_gpio.h      |  2 ++
 lib/utils/gpio/fdt_gpio.c              | 18 ++++++++----------
 lib/utils/gpio/fdt_gpio_drivers.carray |  3 +++
 lib/utils/gpio/objects.mk              |  4 ++++
 4 files changed, 17 insertions(+), 10 deletions(-)
 create mode 100644 lib/utils/gpio/fdt_gpio_drivers.carray

diff --git a/include/sbi_utils/gpio/fdt_gpio.h b/include/sbi_utils/gpio/fdt_gpio.h
index 19e1b58..ccbf2a1 100644
--- a/include/sbi_utils/gpio/fdt_gpio.h
+++ b/include/sbi_utils/gpio/fdt_gpio.h
@@ -12,6 +12,8 @@
 
 #include <sbi_utils/gpio/gpio.h>
 
+struct fdt_phandle_args;
+
 /** FDT based GPIO driver */
 struct fdt_gpio {
 	const struct fdt_match *match_table;
diff --git a/lib/utils/gpio/fdt_gpio.c b/lib/utils/gpio/fdt_gpio.c
index 297b248..7258128 100644
--- a/lib/utils/gpio/fdt_gpio.c
+++ b/lib/utils/gpio/fdt_gpio.c
@@ -12,11 +12,9 @@
 #include <sbi_utils/fdt/fdt_helper.h>
 #include <sbi_utils/gpio/fdt_gpio.h>
 
-extern struct fdt_gpio fdt_gpio_sifive;
-
-static struct fdt_gpio *gpio_drivers[] = {
-	&fdt_gpio_sifive
-};
+/* List of FDT gpio drivers generated at compile time */
+extern struct fdt_gpio *fdt_gpio_drivers[];
+extern unsigned long fdt_gpio_drivers_size;
 
 static struct fdt_gpio *fdt_gpio_driver(struct gpio_chip *chip)
 {
@@ -25,9 +23,9 @@ static struct fdt_gpio *fdt_gpio_driver(struct gpio_chip *chip)
 	if (!chip)
 		return NULL;
 
-	for (pos = 0; pos < array_size(gpio_drivers); pos++) {
-		if (chip->driver == gpio_drivers[pos])
-			return gpio_drivers[pos];
+	for (pos = 0; pos < fdt_gpio_drivers_size; pos++) {
+		if (chip->driver == fdt_gpio_drivers[pos])
+			return fdt_gpio_drivers[pos];
 	}
 
 	return NULL;
@@ -49,8 +47,8 @@ static int fdt_gpio_init(void *fdt, u32 phandle)
 		return SBI_EINVAL;
 
 	/* Try all GPIO drivers one-by-one */
-	for (pos = 0; pos < array_size(gpio_drivers); pos++) {
-		drv = gpio_drivers[pos];
+	for (pos = 0; pos < fdt_gpio_drivers_size; pos++) {
+		drv = fdt_gpio_drivers[pos];
 
 		match = fdt_match_node(fdt, nodeoff, drv->match_table);
 		if (match && drv->init) {
diff --git a/lib/utils/gpio/fdt_gpio_drivers.carray b/lib/utils/gpio/fdt_gpio_drivers.carray
new file mode 100644
index 0000000..e863f1c
--- /dev/null
+++ b/lib/utils/gpio/fdt_gpio_drivers.carray
@@ -0,0 +1,3 @@
+HEADER: sbi_utils/gpio/fdt_gpio.h
+TYPE: struct fdt_gpio
+NAME: fdt_gpio_drivers
diff --git a/lib/utils/gpio/objects.mk b/lib/utils/gpio/objects.mk
index 8eb7736..a5e131b 100644
--- a/lib/utils/gpio/objects.mk
+++ b/lib/utils/gpio/objects.mk
@@ -8,5 +8,9 @@
 #
 
 libsbiutils-objs-y += gpio/fdt_gpio.o
+libsbiutils-objs-y += gpio/fdt_gpio_drivers.o
+
+carray-fdt_gpio_drivers-y += fdt_gpio_sifive
 libsbiutils-objs-y += gpio/fdt_gpio_sifive.o
+
 libsbiutils-objs-y += gpio/gpio.o
-- 
2.34.1



  parent reply	other threads:[~2022-05-03  3:37 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-03  3:37 [PATCH 00/11] OpenSBI compile-time C arrays Anup Patel
2022-05-03  3:37 ` [PATCH 01/11] Makefile: Allow generated C source to be anywhere in build directory Anup Patel
2022-05-09 17:24   ` Atish Patra
2022-05-03  3:37 ` [PATCH 02/11] Makefile: Add support for generating C array at compile time Anup Patel
2022-05-09 17:26   ` Atish Patra
2022-05-03  3:37 ` [PATCH 03/11] lib: utils/reset: Generate FDT reset driver list at compile-time Anup Patel
2022-05-03  3:37 ` [PATCH 04/11] lib: utils/serial: Generate FDT serial " Anup Patel
2022-05-03  3:37 ` [PATCH 05/11] lib: utils/timer: Generate FDT timer " Anup Patel
2022-05-03  3:37 ` [PATCH 06/11] lib: utils/irqchip: Generate FDT irqchip " Anup Patel
2022-05-03  3:37 ` [PATCH 07/11] lib: utils/ipi: Generate FDT ipi " Anup Patel
2022-05-03  3:37 ` [PATCH 08/11] lib: utils/i2c: Generate FDT i2c adapter " Anup Patel
2022-05-03  3:37 ` Anup Patel [this message]
2022-05-03  3:37 ` [PATCH 10/11] platform: generic: Generate platform override module " Anup Patel
2022-05-03  3:37 ` [PATCH 11/11] platform: generic: Move Sifive platform overrides into own directory Anup Patel
2022-05-09 17:28   ` Atish Patra
2022-05-03  3:42 ` [PATCH 00/11] OpenSBI compile-time C arrays Jessica Clarke
2022-05-03  3:52   ` Anup Patel
2022-05-03  3:54     ` Jessica Clarke
2022-05-03  4:04       ` Anup Patel
2022-05-03  4:13         ` Jessica Clarke
2022-05-03  4:17           ` Anup Patel
2022-05-03  4:23             ` Jessica Clarke
2022-05-03  4:30               ` Anup Patel
2022-05-03  4:45                 ` Jessica Clarke
2022-05-03  4:47                   ` Anup Patel
2022-05-03 15:35 ` Xiang W
2022-05-03 16:24   ` Anup Patel
2022-05-09 17:29 ` Atish Patra
2022-05-13  4:03   ` Anup Patel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220503033759.544156-10-apatel@ventanamicro.com \
    --to=apatel@ventanamicro.com \
    --cc=opensbi@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.