forked from Mirrors/opensbi
lib: utils/gpio: Use heap in SiFive and StartFive GPIO drivers
Let's use heap allocation in SiFive and Starfive GPIO drivers instead of using a fixed size global array. Signed-off-by: Anup Patel <apatel@ventanamicro.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
This commit is contained in:
@@ -9,11 +9,10 @@
|
|||||||
|
|
||||||
#include <sbi/riscv_io.h>
|
#include <sbi/riscv_io.h>
|
||||||
#include <sbi/sbi_error.h>
|
#include <sbi/sbi_error.h>
|
||||||
|
#include <sbi/sbi_heap.h>
|
||||||
#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>
|
||||||
|
|
||||||
#define SIFIVE_GPIO_CHIP_MAX 2
|
|
||||||
|
|
||||||
#define SIFIVE_GPIO_PINS_MIN 1
|
#define SIFIVE_GPIO_PINS_MIN 1
|
||||||
#define SIFIVE_GPIO_PINS_MAX 32
|
#define SIFIVE_GPIO_PINS_MAX 32
|
||||||
#define SIFIVE_GPIO_PINS_DEF 16
|
#define SIFIVE_GPIO_PINS_DEF 16
|
||||||
@@ -27,9 +26,6 @@ struct sifive_gpio_chip {
|
|||||||
struct gpio_chip chip;
|
struct gpio_chip chip;
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned int sifive_gpio_chip_count;
|
|
||||||
static struct sifive_gpio_chip sifive_gpio_chip_array[SIFIVE_GPIO_CHIP_MAX];
|
|
||||||
|
|
||||||
static int sifive_gpio_direction_output(struct gpio_pin *gp, int value)
|
static int sifive_gpio_direction_output(struct gpio_pin *gp, int value)
|
||||||
{
|
{
|
||||||
unsigned int v;
|
unsigned int v;
|
||||||
@@ -73,13 +69,15 @@ static int sifive_gpio_init(void *fdt, int nodeoff, u32 phandle,
|
|||||||
struct sifive_gpio_chip *chip;
|
struct sifive_gpio_chip *chip;
|
||||||
uint64_t addr;
|
uint64_t addr;
|
||||||
|
|
||||||
if (SIFIVE_GPIO_CHIP_MAX <= sifive_gpio_chip_count)
|
chip = sbi_zalloc(sizeof(*chip));
|
||||||
return SBI_ENOSPC;
|
if (!chip)
|
||||||
chip = &sifive_gpio_chip_array[sifive_gpio_chip_count];
|
return SBI_ENOMEM;
|
||||||
|
|
||||||
rc = fdt_get_node_addr_size(fdt, nodeoff, 0, &addr, NULL);
|
rc = fdt_get_node_addr_size(fdt, nodeoff, 0, &addr, NULL);
|
||||||
if (rc)
|
if (rc) {
|
||||||
|
sbi_free(chip);
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
chip->addr = addr;
|
chip->addr = addr;
|
||||||
chip->chip.driver = &fdt_gpio_sifive;
|
chip->chip.driver = &fdt_gpio_sifive;
|
||||||
@@ -88,10 +86,11 @@ static int sifive_gpio_init(void *fdt, int nodeoff, u32 phandle,
|
|||||||
chip->chip.direction_output = sifive_gpio_direction_output;
|
chip->chip.direction_output = sifive_gpio_direction_output;
|
||||||
chip->chip.set = sifive_gpio_set;
|
chip->chip.set = sifive_gpio_set;
|
||||||
rc = gpio_chip_add(&chip->chip);
|
rc = gpio_chip_add(&chip->chip);
|
||||||
if (rc)
|
if (rc) {
|
||||||
|
sbi_free(chip);
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
sifive_gpio_chip_count++;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -9,11 +9,11 @@
|
|||||||
|
|
||||||
#include <sbi/riscv_io.h>
|
#include <sbi/riscv_io.h>
|
||||||
#include <sbi/sbi_error.h>
|
#include <sbi/sbi_error.h>
|
||||||
|
#include <sbi/sbi_heap.h>
|
||||||
#include <sbi/sbi_console.h>
|
#include <sbi/sbi_console.h>
|
||||||
#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>
|
||||||
|
|
||||||
#define STARFIVE_GPIO_CHIP_MAX 2
|
|
||||||
#define STARFIVE_GPIO_PINS_DEF 64
|
#define STARFIVE_GPIO_PINS_DEF 64
|
||||||
#define STARFIVE_GPIO_OUTVAL 0x40
|
#define STARFIVE_GPIO_OUTVAL 0x40
|
||||||
#define STARFIVE_GPIO_MASK 0xff
|
#define STARFIVE_GPIO_MASK 0xff
|
||||||
@@ -25,9 +25,6 @@ struct starfive_gpio_chip {
|
|||||||
struct gpio_chip chip;
|
struct gpio_chip chip;
|
||||||
};
|
};
|
||||||
|
|
||||||
static unsigned int starfive_gpio_chip_count;
|
|
||||||
static struct starfive_gpio_chip starfive_gpio_chip_array[STARFIVE_GPIO_CHIP_MAX];
|
|
||||||
|
|
||||||
static int starfive_gpio_direction_output(struct gpio_pin *gp, int value)
|
static int starfive_gpio_direction_output(struct gpio_pin *gp, int value)
|
||||||
{
|
{
|
||||||
u32 val;
|
u32 val;
|
||||||
@@ -82,13 +79,15 @@ static int starfive_gpio_init(void *fdt, int nodeoff, u32 phandle,
|
|||||||
struct starfive_gpio_chip *chip;
|
struct starfive_gpio_chip *chip;
|
||||||
u64 addr;
|
u64 addr;
|
||||||
|
|
||||||
if (starfive_gpio_chip_count >= STARFIVE_GPIO_CHIP_MAX)
|
chip = sbi_zalloc(sizeof(*chip));
|
||||||
return SBI_ENOSPC;
|
if (!chip)
|
||||||
chip = &starfive_gpio_chip_array[starfive_gpio_chip_count];
|
return SBI_ENOMEM;
|
||||||
|
|
||||||
rc = fdt_get_node_addr_size(fdt, nodeoff, 0, &addr, NULL);
|
rc = fdt_get_node_addr_size(fdt, nodeoff, 0, &addr, NULL);
|
||||||
if (rc)
|
if (rc) {
|
||||||
|
sbi_free(chip);
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
chip->addr = addr;
|
chip->addr = addr;
|
||||||
chip->chip.driver = &fdt_gpio_starfive;
|
chip->chip.driver = &fdt_gpio_starfive;
|
||||||
@@ -97,10 +96,11 @@ static int starfive_gpio_init(void *fdt, int nodeoff, u32 phandle,
|
|||||||
chip->chip.direction_output = starfive_gpio_direction_output;
|
chip->chip.direction_output = starfive_gpio_direction_output;
|
||||||
chip->chip.set = starfive_gpio_set;
|
chip->chip.set = starfive_gpio_set;
|
||||||
rc = gpio_chip_add(&chip->chip);
|
rc = gpio_chip_add(&chip->chip);
|
||||||
if (rc)
|
if (rc) {
|
||||||
|
sbi_free(chip);
|
||||||
return rc;
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
starfive_gpio_chip_count++;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user