aboutsummaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
authorSamuel Holland <samuel.holland@sifive.com>2024-09-03 19:09:38 -0700
committerAnup Patel <anup@brainfault.org>2024-11-05 17:54:39 +0530
commitd71150ee7047c4d7ad67525731cc6271939d782c (patch)
tree4f339d945d8122deb8dace659cff1ee6c6bf577d /lib/utils
parent598cf961d82a12afa3ccbed9645edae2275b76f3 (diff)
downloadopensbi-d71150ee7047c4d7ad67525731cc6271939d782c.zip
opensbi-d71150ee7047c4d7ad67525731cc6271939d782c.tar.gz
opensbi-d71150ee7047c4d7ad67525731cc6271939d782c.tar.bz2
lib: utils/gpio: Use FDT node offset as GPIO chip ID
Since the FDT is not modified during driver initialization, node offsets are just as suitable as phandles for use as identifiers: they are stable and unique. With this change, it is no longer necessary to pass the phandle to the driver init functions, so these init functions now use the same prototype as other kinds of drivers. This matches what is already done for I2C adapters. Signed-off-by: Samuel Holland <samuel.holland@sifive.com> Reviewed-by: Anup Patel <anup@brainfault.org>
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/gpio/fdt_gpio.c23
-rw-r--r--lib/utils/gpio/fdt_gpio_designware.c4
-rw-r--r--lib/utils/gpio/fdt_gpio_sifive.c4
-rw-r--r--lib/utils/gpio/fdt_gpio_starfive.c4
4 files changed, 14 insertions, 21 deletions
diff --git a/lib/utils/gpio/fdt_gpio.c b/lib/utils/gpio/fdt_gpio.c
index 6422c45..953fa13 100644
--- a/lib/utils/gpio/fdt_gpio.c
+++ b/lib/utils/gpio/fdt_gpio.c
@@ -16,17 +16,12 @@
extern struct fdt_gpio *fdt_gpio_drivers[];
extern unsigned long fdt_gpio_drivers_size;
-static int fdt_gpio_init(const void *fdt, u32 phandle)
+static int fdt_gpio_init(const void *fdt, int nodeoff)
{
- int pos, nodeoff, rc;
+ int pos, rc;
struct fdt_gpio *drv;
const struct fdt_match *match;
- /* Find node offset */
- nodeoff = fdt_node_offset_by_phandle(fdt, phandle);
- if (nodeoff < 0)
- return nodeoff;
-
/* Check "gpio-controller" property */
if (!fdt_getprop(fdt, nodeoff, "gpio-controller", &rc))
return SBI_EINVAL;
@@ -37,7 +32,7 @@ static int fdt_gpio_init(const void *fdt, u32 phandle)
match = fdt_match_node(fdt, nodeoff, drv->match_table);
if (match && drv->init) {
- rc = drv->init(fdt, nodeoff, phandle, match);
+ rc = drv->init(fdt, nodeoff, match);
if (rc == SBI_ENODEV)
continue;
if (rc)
@@ -49,20 +44,20 @@ static int fdt_gpio_init(const void *fdt, u32 phandle)
return SBI_ENOSYS;
}
-static int fdt_gpio_chip_find(const void *fdt, u32 phandle,
+static int fdt_gpio_chip_find(const void *fdt, int nodeoff,
struct gpio_chip **out_chip)
{
int rc;
- struct gpio_chip *chip = gpio_chip_find(phandle);
+ struct gpio_chip *chip = gpio_chip_find(nodeoff);
if (!chip) {
/* GPIO chip not found so initialize matching driver */
- rc = fdt_gpio_init(fdt, phandle);
+ rc = fdt_gpio_init(fdt, nodeoff);
if (rc)
return rc;
/* Try to find GPIO chip again */
- chip = gpio_chip_find(phandle);
+ chip = gpio_chip_find(nodeoff);
if (!chip)
return SBI_ENOSYS;
}
@@ -77,7 +72,6 @@ int fdt_gpio_pin_get(const void *fdt, int nodeoff, int index,
struct gpio_pin *out_pin)
{
int rc;
- u32 phandle;
struct fdt_gpio *drv;
struct gpio_chip *chip = NULL;
struct fdt_phandle_args pargs;
@@ -92,8 +86,7 @@ int fdt_gpio_pin_get(const void *fdt, int nodeoff, int index,
if (rc)
return rc;
- phandle = fdt_get_phandle(fdt, pargs.node_offset);
- rc = fdt_gpio_chip_find(fdt, phandle, &chip);
+ rc = fdt_gpio_chip_find(fdt, pargs.node_offset, &chip);
if (rc)
return rc;
diff --git a/lib/utils/gpio/fdt_gpio_designware.c b/lib/utils/gpio/fdt_gpio_designware.c
index b5baf1c..26e0a7c 100644
--- a/lib/utils/gpio/fdt_gpio_designware.c
+++ b/lib/utils/gpio/fdt_gpio_designware.c
@@ -75,7 +75,7 @@ static void dw_gpio_set(struct gpio_pin *gp, int value)
* bank A is the only one with irq support but we're not using it here
*/
-static int dw_gpio_init_bank(const void *fdt, int nodeoff, u32 phandle,
+static int dw_gpio_init_bank(const void *fdt, int nodeoff,
const struct fdt_match *match)
{
struct dw_gpio_chip *chip;
@@ -111,7 +111,7 @@ static int dw_gpio_init_bank(const void *fdt, int nodeoff, u32 phandle,
chip->dr = (void *)(uintptr_t)addr + (bank * 0xc);
chip->ext = (void *)(uintptr_t)addr + (bank * 4) + 0x50;
chip->chip.driver = &fdt_gpio_designware;
- chip->chip.id = phandle;
+ chip->chip.id = nodeoff;
chip->chip.ngpio = nr_pins;
chip->chip.set = dw_gpio_set;
chip->chip.direction_output = dw_gpio_direction_output;
diff --git a/lib/utils/gpio/fdt_gpio_sifive.c b/lib/utils/gpio/fdt_gpio_sifive.c
index e5dbe2b..d96bf77 100644
--- a/lib/utils/gpio/fdt_gpio_sifive.c
+++ b/lib/utils/gpio/fdt_gpio_sifive.c
@@ -62,7 +62,7 @@ static void sifive_gpio_set(struct gpio_pin *gp, int value)
extern struct fdt_gpio fdt_gpio_sifive;
-static int sifive_gpio_init(const void *fdt, int nodeoff, u32 phandle,
+static int sifive_gpio_init(const void *fdt, int nodeoff,
const struct fdt_match *match)
{
int rc;
@@ -81,7 +81,7 @@ static int sifive_gpio_init(const void *fdt, int nodeoff, u32 phandle,
chip->addr = addr;
chip->chip.driver = &fdt_gpio_sifive;
- chip->chip.id = phandle;
+ chip->chip.id = nodeoff;
chip->chip.ngpio = SIFIVE_GPIO_PINS_DEF;
chip->chip.direction_output = sifive_gpio_direction_output;
chip->chip.set = sifive_gpio_set;
diff --git a/lib/utils/gpio/fdt_gpio_starfive.c b/lib/utils/gpio/fdt_gpio_starfive.c
index d84ff1f..5575242 100644
--- a/lib/utils/gpio/fdt_gpio_starfive.c
+++ b/lib/utils/gpio/fdt_gpio_starfive.c
@@ -71,7 +71,7 @@ static void starfive_gpio_set(struct gpio_pin *gp, int value)
extern struct fdt_gpio fdt_gpio_starfive;
-static int starfive_gpio_init(const void *fdt, int nodeoff, u32 phandle,
+static int starfive_gpio_init(const void *fdt, int nodeoff,
const struct fdt_match *match)
{
int rc;
@@ -90,7 +90,7 @@ static int starfive_gpio_init(const void *fdt, int nodeoff, u32 phandle,
chip->addr = addr;
chip->chip.driver = &fdt_gpio_starfive;
- chip->chip.id = phandle;
+ chip->chip.id = nodeoff;
chip->chip.ngpio = STARFIVE_GPIO_PINS_DEF;
chip->chip.direction_output = starfive_gpio_direction_output;
chip->chip.set = starfive_gpio_set;