Skip to content

Commit 3946d18

Browse files
dtorlinusw
authored andcommitted
gpio: add gpio_add_lookup_tables() to add several tables at once
When converting legacy board to use gpiod API() there might be several lookup tables in board file, let's provide a way to register them all at once. Reviewed-by: Andy Shevchenko <[email protected]> Reviewed-by: Mika Westerberg <[email protected]> Signed-off-by: Dmitry Torokhov <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 33f5dc8 commit 3946d18

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

drivers/gpio/gpiolib.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,6 +3010,23 @@ void gpiod_set_raw_array_value_cansleep(unsigned int array_size,
30103010
}
30113011
EXPORT_SYMBOL_GPL(gpiod_set_raw_array_value_cansleep);
30123012

3013+
/**
3014+
* gpiod_add_lookup_tables() - register GPIO device consumers
3015+
* @tables: list of tables of consumers to register
3016+
* @n: number of tables in the list
3017+
*/
3018+
void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n)
3019+
{
3020+
unsigned int i;
3021+
3022+
mutex_lock(&gpio_lookup_lock);
3023+
3024+
for (i = 0; i < n; i++)
3025+
list_add_tail(&tables[i]->list, &gpio_lookup_list);
3026+
3027+
mutex_unlock(&gpio_lookup_lock);
3028+
}
3029+
30133030
/**
30143031
* gpiod_set_array_value_cansleep() - assign values to an array of GPIOs
30153032
* @array_size: number of elements in the descriptor / value arrays

include/linux/gpio/machine.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,14 @@ struct gpiod_lookup_table {
6060

6161
#ifdef CONFIG_GPIOLIB
6262
void gpiod_add_lookup_table(struct gpiod_lookup_table *table);
63+
void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n);
6364
void gpiod_remove_lookup_table(struct gpiod_lookup_table *table);
6465
#else
6566
static inline
6667
void gpiod_add_lookup_table(struct gpiod_lookup_table *table) {}
6768
static inline
69+
void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}
70+
static inline
6871
void gpiod_remove_lookup_table(struct gpiod_lookup_table *table) {}
6972
#endif
7073

0 commit comments

Comments
 (0)