From 3e0c170397074c32f733ac2681e8a077f8d7a814 Mon Sep 17 00:00:00 2001 From: Samuel Holland Date: Fri, 25 Oct 2024 11:36:22 -0700 Subject: [PATCH] lib: utils/gpio: designware: Allocate chips on the heap This reduces firmware size for SoCs which do not use this driver. Signed-off-by: Samuel Holland Reviewed-by: Anup Patel --- lib/utils/gpio/fdt_gpio_designware.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/utils/gpio/fdt_gpio_designware.c b/lib/utils/gpio/fdt_gpio_designware.c index 20701a15..b5baf1c1 100644 --- a/lib/utils/gpio/fdt_gpio_designware.c +++ b/lib/utils/gpio/fdt_gpio_designware.c @@ -13,11 +13,11 @@ #include #include +#include #include #include -#define DW_GPIO_CHIP_MAX 4 /* need 1 per bank in use */ #define DW_GPIO_PINS_MAX 32 #define DW_GPIO_DDR 0x4 @@ -32,9 +32,6 @@ struct dw_gpio_chip { extern struct fdt_gpio fdt_gpio_designware; -static unsigned int dw_gpio_chip_count; -static struct dw_gpio_chip dw_gpio_chip_array[DW_GPIO_CHIP_MAX]; - #define pin_to_chip(__p) container_of((__p)->chip, struct dw_gpio_chip, chip); static int dw_gpio_direction_output(struct gpio_pin *gp, int value) @@ -86,9 +83,6 @@ static int dw_gpio_init_bank(const void *fdt, int nodeoff, u32 phandle, uint64_t addr; int rc, poff, nr_pins, bank, len; - if (dw_gpio_chip_count >= DW_GPIO_CHIP_MAX) - return SBI_ENOSPC; - /* need to get parent for the address property */ poff = fdt_parent_offset(fdt, nodeoff); if (poff < 0) @@ -110,7 +104,9 @@ static int dw_gpio_init_bank(const void *fdt, int nodeoff, u32 phandle, return SBI_EINVAL; nr_pins = fdt32_to_cpu(*val); - chip = &dw_gpio_chip_array[dw_gpio_chip_count]; + chip = sbi_zalloc(sizeof(*chip)); + if (!chip) + return SBI_ENOMEM; chip->dr = (void *)(uintptr_t)addr + (bank * 0xc); chip->ext = (void *)(uintptr_t)addr + (bank * 4) + 0x50; @@ -121,10 +117,13 @@ static int dw_gpio_init_bank(const void *fdt, int nodeoff, u32 phandle, chip->chip.direction_output = dw_gpio_direction_output; rc = gpio_chip_add(&chip->chip); if (rc) - return rc; + goto err_free_chip; - dw_gpio_chip_count++; return 0; + +err_free_chip: + sbi_free(chip); + return rc; } /* since we're only probed when used, match on port not main controller node */