summaryrefslogtreecommitdiff
path: root/lib/utils
diff options
context:
space:
mode:
authorNikita Shubin <n.shubin@yadro.com>2021-11-02 17:39:11 +0300
committerAnup Patel <anup@brainfault.org>2021-11-03 13:27:56 +0300
commit0979ffda12b636fab58228c2b40bab1e2f6b327b (patch)
tree8850f7326bda43655e80651bd3f771f350a0b087 /lib/utils
parent013ba4ef3d94de67d040376535131012134ed54f (diff)
downloadopensbi-0979ffda12b636fab58228c2b40bab1e2f6b327b.tar.xz
lib: utils/gpio: use list for drivers
Convert static array to sbi_list. This removes size limitation, makes add/remove more efficient and saves space. Signed-off-by: Nikita Shubin <n.shubin@yadro.com> Reviewed-by: Anup Patel <anup.patel@wdc.com>
Diffstat (limited to 'lib/utils')
-rw-r--r--lib/utils/gpio/gpio.c42
1 files changed, 12 insertions, 30 deletions
diff --git a/lib/utils/gpio/gpio.c b/lib/utils/gpio/gpio.c
index fb30c0f..3a3a6b2 100644
--- a/lib/utils/gpio/gpio.c
+++ b/lib/utils/gpio/gpio.c
@@ -10,58 +10,40 @@
#include <sbi/sbi_error.h>
#include <sbi_utils/gpio/gpio.h>
-#define GPIO_CHIP_MAX 16
-
-static struct gpio_chip *gc_array[GPIO_CHIP_MAX];
+static SBI_LIST_HEAD(gpio_chip_list);
struct gpio_chip *gpio_chip_find(unsigned int id)
{
- unsigned int i;
- struct gpio_chip *ret = NULL;
-
- for (i = 0; i < GPIO_CHIP_MAX; i++) {
- if (gc_array[i] && gc_array[i]->id == id) {
- ret = gc_array[i];
- break;
- }
+ struct sbi_dlist *pos;
+
+ sbi_list_for_each(pos, &(gpio_chip_list)) {
+ struct gpio_chip *chip = to_gpio_chip(pos);
+
+ if (chip->id == id)
+ return chip;
}
- return ret;
+ return NULL;
}
int gpio_chip_add(struct gpio_chip *gc)
{
- int i, ret = SBI_ENOSPC;
-
if (!gc)
return SBI_EINVAL;
if (gpio_chip_find(gc->id))
return SBI_EALREADY;
- for (i = 0; i < GPIO_CHIP_MAX; i++) {
- if (!gc_array[i]) {
- gc_array[i] = gc;
- ret = 0;
- break;
- }
- }
+ sbi_list_add(&(gc->node), &(gpio_chip_list));
- return ret;
+ return 0;
}
void gpio_chip_remove(struct gpio_chip *gc)
{
- int i;
-
if (!gc)
return;
- for (i = 0; i < GPIO_CHIP_MAX; i++) {
- if (gc_array[i] == gc) {
- gc_array[i] = NULL;
- break;
- }
- }
+ sbi_list_del(&(gc->node));
}
int gpio_get_direction(struct gpio_pin *gp)