lib: utils/gpio: Use fdt_driver for initialization

FDT gpio drivers have an extra .xlate operation, so they need to embed
the `struct fdt_driver` inside the subsystem-specific type. The gpio
subsystem always initializes the driver for a specific DT node.

Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
Reviewed-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Samuel Holland
2024-11-11 14:02:49 -08:00
committed by Anup Patel
parent 10df2d6fb5
commit bef8f9b806
7 changed files with 28 additions and 40 deletions

View File

@@ -13,34 +13,15 @@
#include <sbi_utils/gpio/fdt_gpio.h>
/* List of FDT gpio drivers generated at compile time */
extern struct fdt_gpio *const fdt_gpio_drivers[];
extern const struct fdt_driver *const fdt_gpio_drivers[];
static int fdt_gpio_init(const void *fdt, int nodeoff)
{
int pos, rc;
struct fdt_gpio *drv;
const struct fdt_match *match;
/* Check "gpio-controller" property */
if (!fdt_getprop(fdt, nodeoff, "gpio-controller", &rc))
if (!fdt_getprop(fdt, nodeoff, "gpio-controller", NULL))
return SBI_EINVAL;
/* Try all GPIO drivers one-by-one */
for (pos = 0; fdt_gpio_drivers[pos]; pos++) {
drv = fdt_gpio_drivers[pos];
match = fdt_match_node(fdt, nodeoff, drv->match_table);
if (match && drv->init) {
rc = drv->init(fdt, nodeoff, match);
if (rc == SBI_ENODEV)
continue;
if (rc)
return rc;
return 0;
}
}
return SBI_ENOSYS;
return fdt_driver_init_by_offset(fdt, nodeoff, fdt_gpio_drivers);
}
static int fdt_gpio_chip_find(const void *fdt, int nodeoff,
@@ -71,7 +52,7 @@ int fdt_gpio_pin_get(const void *fdt, int nodeoff, int index,
struct gpio_pin *out_pin)
{
int rc;
struct fdt_gpio *drv;
const struct fdt_gpio *drv;
struct gpio_chip *chip = NULL;
struct fdt_phandle_args pargs;

View File

@@ -30,7 +30,7 @@ struct dw_gpio_chip {
struct gpio_chip chip;
};
extern struct fdt_gpio fdt_gpio_designware;
const struct fdt_gpio fdt_gpio_designware;
#define pin_to_chip(__p) container_of((__p)->chip, struct dw_gpio_chip, chip);
@@ -132,8 +132,10 @@ static const struct fdt_match dw_gpio_match[] = {
{ },
};
struct fdt_gpio fdt_gpio_designware = {
.match_table = dw_gpio_match,
const struct fdt_gpio fdt_gpio_designware = {
.driver = {
.match_table = dw_gpio_match,
.init = dw_gpio_init_bank,
},
.xlate = fdt_gpio_simple_xlate,
.init = dw_gpio_init_bank,
};

View File

@@ -1,3 +1,5 @@
HEADER: sbi_utils/gpio/fdt_gpio.h
TYPE: struct fdt_gpio
TYPE: const struct fdt_gpio
NAME: fdt_gpio_drivers
MEMBER-NAME: driver
MEMBER-TYPE: const struct fdt_driver

View File

@@ -60,7 +60,7 @@ static void sifive_gpio_set(struct gpio_pin *gp, int value)
writel(v, (volatile void *)(chip->addr + SIFIVE_GPIO_OUTVAL));
}
extern struct fdt_gpio fdt_gpio_sifive;
const struct fdt_gpio fdt_gpio_sifive;
static int sifive_gpio_init(const void *fdt, int nodeoff,
const struct fdt_match *match)
@@ -99,8 +99,10 @@ static const struct fdt_match sifive_gpio_match[] = {
{ },
};
struct fdt_gpio fdt_gpio_sifive = {
.match_table = sifive_gpio_match,
const struct fdt_gpio fdt_gpio_sifive = {
.driver = {
.match_table = sifive_gpio_match,
.init = sifive_gpio_init,
},
.xlate = fdt_gpio_simple_xlate,
.init = sifive_gpio_init,
};

View File

@@ -69,7 +69,7 @@ static void starfive_gpio_set(struct gpio_pin *gp, int value)
writel(val, (void *)(reg_addr + STARFIVE_GPIO_OUTVAL));
}
extern struct fdt_gpio fdt_gpio_starfive;
const struct fdt_gpio fdt_gpio_starfive;
static int starfive_gpio_init(const void *fdt, int nodeoff,
const struct fdt_match *match)
@@ -109,8 +109,10 @@ static const struct fdt_match starfive_gpio_match[] = {
{ },
};
struct fdt_gpio fdt_gpio_starfive = {
.match_table = starfive_gpio_match,
const struct fdt_gpio fdt_gpio_starfive = {
.driver = {
.match_table = starfive_gpio_match,
.init = starfive_gpio_init,
},
.xlate = fdt_gpio_simple_xlate,
.init = starfive_gpio_init,
};