gpio: add gpio_add_lookup_tables() to add several tables at once
PATCH v2 1/1 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.
---
V2:
- added the !CONFIG_GPIOLIB stub (Andy)
- changed size from unsigned int to size_t at Mika's suggestion
- added Reviewed-bys.
drivers/gpio/gpiolib.c | 17 +++++++++++++++++ include/linux/gpio/machine.h | 3 +++ 2 files changed, 20 insertions(+)
drivers/gpio/gpiolib.c +17 -0
@@ -3010,6 +3010,23 @@ void gpiod_add_lookup_table(struct gpiod_lookup_table *table)mutex_unlock (&gpio_lookup_lock); } +/** +* gpiod_add_lookup_tables() - register GPIO device consumers +* @tables: list of tables of consumers to register +* @n: number of tables in the list +*/ +void gpiod_add_lookup_tables (struct gpiod_lookup_table **tables,size_t n) +{ +unsigned int i; + +mutex_lock (&gpio_lookup_lock); + +for (i =0 ; i < n; i++) +list_add_tail (&tables[i]->list, &gpio_lookup_list); + +mutex_unlock (&gpio_lookup_lock); +} +/** * gpiod_remove_lookup_table() - unregister GPIO device consumers * @table: table of consumers to unregister
include/linux/gpio/machine.h +3 -0
@@ -58,11 +58,14 @@ struct gpiod_lookup_table {#ifdef CONFIG_GPIOLIB void gpiod_add_lookup_table (struct gpiod_lookup_table *table); +void gpiod_add_lookup_tables (struct gpiod_lookup_table **tables,size_t n);void gpiod_remove_lookup_table (struct gpiod_lookup_table *table);#else static inline void gpiod_add_lookup_table (struct gpiod_lookup_table *table) {}static inline +void gpiod_add_lookup_tables (struct gpiod_lookup_table **tables,size_t n) {} +static inline void gpiod_remove_lookup_table (struct gpiod_lookup_table *table) {}#endif
Signature · 5 lines
2.14.0.434.g98096fd7a8-goog -- Dmitry
Quoted 7 lines · Dmitry Torokhov
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]>
Quoted 6 lines
---
V2:
- added the !CONFIG_GPIOLIB stub (Andy)
- changed size from unsigned int tosize_tat Mika's suggestion
- added Reviewed-bys.
Patch applied!
Usually I don't like adding APIs with no users, but you have a good track record so I believe you are going to put this to good use in coming merge windows.
Yours,
Linus Walleij