mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2025-08-25 07:41:42 +01:00
lib: utils/gpio: Generate FDT gpio driver list at compile-time
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> Reviewed-by: Atish Patra <atishp@rivosinc.com>
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include <sbi_utils/gpio/gpio.h>
|
#include <sbi_utils/gpio/gpio.h>
|
||||||
|
|
||||||
|
struct fdt_phandle_args;
|
||||||
|
|
||||||
/** FDT based GPIO driver */
|
/** FDT based GPIO driver */
|
||||||
struct fdt_gpio {
|
struct fdt_gpio {
|
||||||
const struct fdt_match *match_table;
|
const struct fdt_match *match_table;
|
||||||
|
@@ -12,11 +12,9 @@
|
|||||||
#include <sbi_utils/fdt/fdt_helper.h>
|
#include <sbi_utils/fdt/fdt_helper.h>
|
||||||
#include <sbi_utils/gpio/fdt_gpio.h>
|
#include <sbi_utils/gpio/fdt_gpio.h>
|
||||||
|
|
||||||
extern struct fdt_gpio fdt_gpio_sifive;
|
/* List of FDT gpio drivers generated at compile time */
|
||||||
|
extern struct fdt_gpio *fdt_gpio_drivers[];
|
||||||
static struct fdt_gpio *gpio_drivers[] = {
|
extern unsigned long fdt_gpio_drivers_size;
|
||||||
&fdt_gpio_sifive
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct fdt_gpio *fdt_gpio_driver(struct gpio_chip *chip)
|
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)
|
if (!chip)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
for (pos = 0; pos < array_size(gpio_drivers); pos++) {
|
for (pos = 0; pos < fdt_gpio_drivers_size; pos++) {
|
||||||
if (chip->driver == gpio_drivers[pos])
|
if (chip->driver == fdt_gpio_drivers[pos])
|
||||||
return gpio_drivers[pos];
|
return fdt_gpio_drivers[pos];
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -49,8 +47,8 @@ static int fdt_gpio_init(void *fdt, u32 phandle)
|
|||||||
return SBI_EINVAL;
|
return SBI_EINVAL;
|
||||||
|
|
||||||
/* Try all GPIO drivers one-by-one */
|
/* Try all GPIO drivers one-by-one */
|
||||||
for (pos = 0; pos < array_size(gpio_drivers); pos++) {
|
for (pos = 0; pos < fdt_gpio_drivers_size; pos++) {
|
||||||
drv = gpio_drivers[pos];
|
drv = fdt_gpio_drivers[pos];
|
||||||
|
|
||||||
match = fdt_match_node(fdt, nodeoff, drv->match_table);
|
match = fdt_match_node(fdt, nodeoff, drv->match_table);
|
||||||
if (match && drv->init) {
|
if (match && drv->init) {
|
||||||
|
3
lib/utils/gpio/fdt_gpio_drivers.carray
Normal file
3
lib/utils/gpio/fdt_gpio_drivers.carray
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
HEADER: sbi_utils/gpio/fdt_gpio.h
|
||||||
|
TYPE: struct fdt_gpio
|
||||||
|
NAME: fdt_gpio_drivers
|
@@ -8,5 +8,9 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
libsbiutils-objs-y += gpio/fdt_gpio.o
|
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/fdt_gpio_sifive.o
|
||||||
|
|
||||||
libsbiutils-objs-y += gpio/gpio.o
|
libsbiutils-objs-y += gpio/gpio.o
|
||||||
|
Reference in New Issue
Block a user