gpio: add gpio_add_lookup_tables() to add several tables at once
PATCH 1/1 gpio: add gpio_add_lookup_tables() to add several tables at once
When converting legacy board to use gpiod API() there migt be several lookup tables in board file, let's provide a way to register them all at once.
--- drivers/gpio/gpiolib.c | 18 ++++++++++++++++++ include/linux/gpio/machine.h | 2 ++ 2 files changed, 20 insertions(+)
drivers/gpio/gpiolib.c +18 -0
@@ -3010,6 +3010,24 @@ 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 table of consumers to register +* @n: number of tables in the list +*/ +void gpiod_add_lookup_tables (struct gpiod_lookup_table **tables, +unsigned int 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 +2 -0
@@ -58,6 +58,8 @@ 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, +unsigned int n);void gpiod_remove_lookup_table (struct gpiod_lookup_table *table);#else static inline
Signature · 5 lines
2.14.0.rc0.400.g1c36432dff-goog -- Dmitry
Quoted 4 lines · Dmitry Torokhov
When converting legacy board to use gpiod
API()there migt be several lookup tables in board file, let's provide a way to register them all at
once.
Looking into the code which is using several GPIO look up tables I noticed that the pattern often something like
gpiod_add_lookup_table(x_tbl);platform_device_register(x_dev);
...
gpiod_add_lookup_table(y_tbl);platform_device_register(y_dev);
which looks also logical.
So, I have no strong opinion here, though it would be nice to have an example where it makes sense.
Quoted 55 lines
Signed-off-by Dmitry Torokhov <[email protected]>---
drivers/gpio/gpiolib.c | 18 ++++++++++++++++++include/linux/gpio/machine.h| 2 ++2 files changed, 20 insertions(+)drivers/gpio/gpiolib.c +0
-0@@ -3010,6 +3010,24 @@ void gpiod_add_lookup_table(struct gpiod_lookup_table *table) mutex_unlock(&gpio_lookup_lock); }drivers/gpio/gpiolib.c +18
-0+/** +* gpiod_add_lookup_tables() - register GPIO device consumers +* @tables: list of table of consumers to register +* @n: number of tables in the list +*/ +void gpiod_add_lookup_tables (struct gpiod_lookup_table **tables, + unsigned int 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 unregisterinclude/linux/gpio/machine.h +0
-0@@ -58,6 +58,8 @@ struct gpiod_lookup_table {
#ifdefCONFIG_GPIOLIB
voidgpiod_add_lookup_table(struct gpiod_lookup_table *table);include/linux/gpio/machine.h +2
-0+void gpiod_add_lookup_tables (struct gpiod_lookup_table **tables, + unsigned int n);void
gpiod_remove_lookup_table(struct gpiod_lookup_table *table); #else
static inline
--
2.14.0.rc0.400.g1c36432dff-goog
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 15 lines · Andy Shevchenko
Quoted 4 lines · Dmitry Torokhov
When converting legacy board to use gpiod
API()there migt be several lookup tables in board file, let's provide a way to register them all at
once.Looking into the code which is using several GPIO look up tables I noticed that the pattern often something like
gpiod_add_lookup_table(x_tbl);platform_device_register(x_dev);...
Quoted 7 lines
gpiod_add_lookup_table(y_tbl);platform_device_register(y_dev);which looks also logical.
So, I have no strong opinion here, though it would be nice to have an example where it makes sense.
Here is an example. It actually does not have multiple GPIO tables, but it allows to keep the structure of init sequence for the board, which relies on having series of arrays conditionally populated with devices and other data that need to be registered.
static int __init tll6527m_init(void)
{
printk(KERN_INFO "%s(): registering device resources\n", __func__);
gpiod_add_lookup_tables(tll6527m_gpio_tables,
AERRAY_SIZE(tll6527m_gpio_tables));
i2c_register_board_info(0, bfin_i2c_board_info,
ARRAY_SIZE(bfin_i2c_board_info));
platform_add_devices(tll6527m_devices, ARRAY_SIZE(tll6527m_devices));
spi_register_board_info(bfin_spi_board_info,
ARRAY_SIZE(bfin_spi_board_info));
return 0;
}--->8---------------------->8---------------------->8-----------------
blackfin: tll6527m: switch to using generic gpio-backlight driver
From: Dmitry Torokhov <[email protected]>
Instead of having lq035q1 control backlight, let's use standard gpio-backlight driver.
--- arch/blackfin/mach-bf527/boards/tll6527m.c | 44 +++++++++++++++++++++------- arch/sh/boards/mach-ecovec24/setup.c | 2 + 2 files changed, 34 insertions(+), 12 deletions(-)
arch/blackfin/mach-bf527/boards/tll6527m.c +33 -11
@@ -10,11 +10,13 @@#include <linux/device.h> #include <linux/export.h> #include <linux/platform_device.h> +#include <linux/property.h> #include <linux/mtd/mtd.h> #include <linux/mtd/partitions.h> #include <linux/mtd/physmap.h> #include <linux/spi/spi.h> #include <linux/spi/flash.h> +#include <linux/gpio/machine.h> #include <linux/i2c.h> #include <linux/irq.h> #include <linux/interrupt.h>
@@ -28,14 +30,6 @@#include <asm/portmux.h> #include <asm/dpmc.h> -#if IS_ENABLED (CONFIG_TOUCHSCREEN_AD7879 ) -#include <linux/platform_data/ad7879.h> -#define LCD_BACKLIGHT_GPIO 0x40 -/* TLL6527M uses TLL7UIQ35 / ADI LCD EZ Extender. AD7879 AUX GPIO is used for -* LCD Backlight Enable -*/ -#endif -/* * Name the Board for the /proc/cpuinfo */
@@ -109,8 +103,6 @@ static struct platform_device musb_device = {static struct bfin_lq035q1fb_disp_info bfin_lq035q1_data = { .mode =LQ035_NORM |LQ035_RGB |LQ035_RL |LQ035_TB , .ppi_mode =USE_RGB565_16_BIT_PPI , - .use_bl =1 , - .gpio_bl =LCD_BACKLIGHT_GPIO , };static struct resource bfin_lq035q1_resources[] = {
@@ -132,6 +124,23 @@ static struct platform_device bfin_lq035q1_device = { };#endif +#if IS_ENABLED (CONFIG_BACKLIGHT_GPIO ) +/* TLL6527M uses TLL7UIQ35 / ADI LCD EZ Extender. AD7879 AUX GPIO is used for +* LCD Backlight Enable +*/ +static struct gpiod_lookup_table bfin_gpio_backlight_gpios_table = { + .dev_id ="gpio-backlight.0" , + .table = { +GPIO_LOOKUP ("AD7879-GPIO" ,0 ,NULL ,GPIO_ACTIVE_HIGH ), + { } + }, +}; + +static struct platform_device bfin_gpio_backlight_device = { + .name ="gpio-backlight" , +}; +#endif + #if IS_ENABLED(CONFIG_MTD_GPIO_ADDR) static struct mtd_partition tll6527m_partitions[] = { {
@@ -323,6 +332,7 @@ static struct bfin5xx_spi_chip mmc_spi_chip_info = {#endif #if IS_ENABLED (CONFIG_TOUCHSCREEN_AD7879 ) +#include <linux/platform_data/ad7879.h> static const struct ad7879_platform_data bfin_ad7879_ts_info = { .model =7879 ,/* Model = AD7879 */ .x_plate_ohms = 620, /* 620 Ohm from the touch datasheet */
@@ -336,7 +346,7 @@ static const struct ad7879_platform_data bfin_ad7879_ts_info = {/* take the average of 4 middle samples */ .pen_down_acc_interval = 255, /* 9.4 ms */ .gpio_export = 1, /* configure AUX as GPIO output*/ - .gpio_base = LCD_BACKLIGHT_GPIO, + .gpio_base = -1, };#endif
@@ -836,6 +846,10 @@ static struct platform_device *tll6527m_devices[] __initdata = { &bfin_lq035q1_device,#endif +#if IS_ENABLED (CONFIG_BACKLIGHT_GPIO ) + &bfin_gpio_backlight_device, +#endif +#if IS_ENABLED (CONFIG_SERIAL_BFIN )#ifdef CONFIG_SERIAL_BFIN_UART0 &bfin_uart0_device,
@@ -880,9 +894,17 @@ static struct platform_device *tll6527m_devices[] __initdata = {#endif }; +static struct gpiod_lookup_table *tll6527m_gpio_tables[] = { +#if IS_ENABLED(CONFIG_BACKLIGHT_GPIO) + &bfin_gpio_backlight_gpios_table, +#endif +}; +static int __init tll6527m_init (void ) {printk (KERN_INFO "%s(): registering device resources\n" , __func__); +gpiod_add_lookup_tables (tll6527m_gpio_tables, +AERRAY_SIZE (tll6527m_gpio_tables));i2c_register_board_info (0 , bfin_i2c_board_info,ARRAY_SIZE (bfin_i2c_board_info));platform_add_devices (tll6527m_devices,ARRAY_SIZE (tll6527m_devices));
arch/sh/boards/mach-ecovec24/setup.c +1 -1
@@ -372,7 +372,7 @@ static struct platform_device lcdc_device = {static struct gpiod_lookup_table gpio_backlight_gpios_table = { .dev_id ="gpio-backlight.0" , .table = { - GPIO_LOOKUP_IDX("sh7724_pfc", GPIO_PTR1, NULL, 0, GPIO_ACTIVE_HIGH); +GPIO_LOOKUP ("sh7724_pfc" ,GPIO_PTR1 ,NULL ,GPIO_ACTIVE_HIGH ), { } }, };
Signature · 1 line
Dmitry
Andy Shevchenko
Reviewed-byQuoted 27 lines · Dmitry Torokhov
Quoted 17 lines · Andy Shevchenko
Quoted 6 lines · Dmitry Torokhov
When converting legacy board to use gpiod
API()there migt be several
lookup tables in board file, let's provide a way to register them all
at
once.Looking into the code which is using several GPIO look up tables I noticed that the pattern often something like
gpiod_add_lookup_table(x_tbl);platform_device_register(x_dev);...
Quoted 8 lines
gpiod_add_lookup_table(y_tbl);platform_device_register(y_dev);which looks also logical.
So, I have no strong opinion here, though it would be nice to have an
example where it makes sense.
Quoted 5 lines
Here is an example. It actually does not have multiple GPIO tables, but
it allows to keep the structure of init sequence for the board, which relies on having series of arrays conditionally populated with devices and other data that need to be registered.
I see your point. Okay, no objections from me.
Please, add a stub for !GPIOLIB case.
After addressing it,
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 34 lines · Andy Shevchenko
Quoted 27 lines · Dmitry Torokhov
Quoted 17 lines · Andy Shevchenko
Quoted 6 lines · Dmitry Torokhov
When converting legacy board to use gpiod
API()there migt be several
lookup tables in board file, let's provide a way to register them all
at
once.Looking into the code which is using several GPIO look up tables I noticed that the pattern often something like
gpiod_add_lookup_table(x_tbl);platform_device_register(x_dev);...
Quoted 8 lines
gpiod_add_lookup_table(y_tbl);platform_device_register(y_dev);which looks also logical.
So, I have no strong opinion here, though it would be nice to have an
example where it makes sense.Quoted 5 lines
Here is an example. It actually does not have multiple GPIO tables, but
it allows to keep the structure of init sequence for the board, which relies on having series of arrays conditionally populated with devices and other data that need to be registered.
Quoted 7 lines
I see your point. Okay, no objections from me.
Please, add a stub for !GPIOLIB case.
After addressing it,
Reviewed-by Andy Shevchenko <[email protected]>
OK I wait for the stub-inclusive patch.
Yours,
Linus Walleij
drivers/gpio/gpiolib.c void gpiod_add_lookup_table(struct gpiod_lookup_table *table) · line 3019
Quoted 2 lines · Dmitry Torokhov
drivers/gpio/gpiolib.c +2
-0+void gpiod_add_lookup_tables (struct gpiod_lookup_table **tables, +unsigned int n)
This should probably be size_t instead.
Regardless this looks useful so,