linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: add gpio_add_lookup_tables() to add several tables at once
@ 2017-07-25 20:58 Dmitry Torokhov
  2017-07-26 10:21 ` Andy Shevchenko
  2017-08-02  8:38 ` Mika Westerberg
  0 siblings, 2 replies; 6+ messages in thread
From: Dmitry Torokhov @ 2017-07-25 20:58 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Lars-Peter Clausen, Mika Westerberg, Andy Shevchenko, linux-gpio,
	linux-kernel

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.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/gpio/gpiolib.c       | 18 ++++++++++++++++++
 include/linux/gpio/machine.h |  2 ++
 2 files changed, 20 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a42a1eea5714..f8f4f8b61db8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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
diff --git a/include/linux/gpio/machine.h b/include/linux/gpio/machine.h
index f738d50cc17d..6f7ddce88fb8 100644
--- a/include/linux/gpio/machine.h
+++ b/include/linux/gpio/machine.h
@@ -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
-- 
2.14.0.rc0.400.g1c36432dff-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] gpio: add gpio_add_lookup_tables() to add several tables at once
  2017-07-25 20:58 [PATCH] gpio: add gpio_add_lookup_tables() to add several tables at once Dmitry Torokhov
@ 2017-07-26 10:21 ` Andy Shevchenko
  2017-08-01 19:24   ` Dmitry Torokhov
  2017-08-02  8:38 ` Mika Westerberg
  1 sibling, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2017-07-26 10:21 UTC (permalink / raw)
  To: Dmitry Torokhov, Linus Walleij
  Cc: Lars-Peter Clausen, Mika Westerberg, linux-gpio, linux-kernel

On Tue, 2017-07-25 at 13:58 -0700, Dmitry Torokhov wrote:
> 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.

> 
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/gpio/gpiolib.c       | 18 ++++++++++++++++++
>  include/linux/gpio/machine.h |  2 ++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index a42a1eea5714..f8f4f8b61db8 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -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
> diff --git a/include/linux/gpio/machine.h
> b/include/linux/gpio/machine.h
> index f738d50cc17d..6f7ddce88fb8 100644
> --- a/include/linux/gpio/machine.h
> +++ b/include/linux/gpio/machine.h
> @@ -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
> -- 
> 2.14.0.rc0.400.g1c36432dff-goog
> 
> 

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gpio: add gpio_add_lookup_tables() to add several tables at once
  2017-07-26 10:21 ` Andy Shevchenko
@ 2017-08-01 19:24   ` Dmitry Torokhov
  2017-08-02 12:06     ` Andy Shevchenko
  0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2017-08-01 19:24 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, Lars-Peter Clausen, Mika Westerberg, linux-gpio,
	linux-kernel

On Wed, Jul 26, 2017 at 01:21:37PM +0300, Andy Shevchenko wrote:
> On Tue, 2017-07-25 at 13:58 -0700, Dmitry Torokhov wrote:
> > 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.

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 <dmitry.torokhov@gmail.com>

Instead of having lq035q1 control backlight, let's use standard
gpio-backlight driver.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 arch/blackfin/mach-bf527/boards/tll6527m.c |   44 +++++++++++++++++++++-------
 arch/sh/boards/mach-ecovec24/setup.c       |    2 +
 2 files changed, 34 insertions(+), 12 deletions(-)

diff --git a/arch/blackfin/mach-bf527/boards/tll6527m.c b/arch/blackfin/mach-bf527/boards/tll6527m.c
index c1acce4c2e45..d7fd705a79e4 100644
--- a/arch/blackfin/mach-bf527/boards/tll6527m.c
+++ b/arch/blackfin/mach-bf527/boards/tll6527m.c
@@ -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));
diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c
index f59494dbfc0b..4724f8f93fd9 100644
--- a/arch/sh/boards/mach-ecovec24/setup.c
+++ b/arch/sh/boards/mach-ecovec24/setup.c
@@ -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),
 		{ }
 	},
 };

-- 
Dmitry

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] gpio: add gpio_add_lookup_tables() to add several tables at once
  2017-07-25 20:58 [PATCH] gpio: add gpio_add_lookup_tables() to add several tables at once Dmitry Torokhov
  2017-07-26 10:21 ` Andy Shevchenko
@ 2017-08-02  8:38 ` Mika Westerberg
  1 sibling, 0 replies; 6+ messages in thread
From: Mika Westerberg @ 2017-08-02  8:38 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Linus Walleij, Lars-Peter Clausen, Andy Shevchenko, linux-gpio,
	linux-kernel

On Tue, Jul 25, 2017 at 01:58:00PM -0700, Dmitry Torokhov wrote:
> +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,

Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gpio: add gpio_add_lookup_tables() to add several tables at once
  2017-08-01 19:24   ` Dmitry Torokhov
@ 2017-08-02 12:06     ` Andy Shevchenko
  2017-08-07 12:18       ` Linus Walleij
  0 siblings, 1 reply; 6+ messages in thread
From: Andy Shevchenko @ 2017-08-02 12:06 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Linus Walleij, Lars-Peter Clausen, Mika Westerberg, linux-gpio,
	linux-kernel

On Tue, 2017-08-01 at 12:24 -0700, Dmitry Torokhov wrote:
> On Wed, Jul 26, 2017 at 01:21:37PM +0300, Andy Shevchenko wrote:
> > On Tue, 2017-07-25 at 13:58 -0700, Dmitry Torokhov wrote:
> > > 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.
> 
> 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, 

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

-- 
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] gpio: add gpio_add_lookup_tables() to add several tables at once
  2017-08-02 12:06     ` Andy Shevchenko
@ 2017-08-07 12:18       ` Linus Walleij
  0 siblings, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2017-08-07 12:18 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Dmitry Torokhov, Lars-Peter Clausen, Mika Westerberg, linux-gpio,
	linux-kernel

On Wed, Aug 2, 2017 at 2:06 PM, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> On Tue, 2017-08-01 at 12:24 -0700, Dmitry Torokhov wrote:
>> On Wed, Jul 26, 2017 at 01:21:37PM +0300, Andy Shevchenko wrote:
>> > On Tue, 2017-07-25 at 13:58 -0700, Dmitry Torokhov wrote:
>> > > 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.
>>
>> 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,
>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

OK I wait for the stub-inclusive patch.

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2017-08-07 12:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-25 20:58 [PATCH] gpio: add gpio_add_lookup_tables() to add several tables at once Dmitry Torokhov
2017-07-26 10:21 ` Andy Shevchenko
2017-08-01 19:24   ` Dmitry Torokhov
2017-08-02 12:06     ` Andy Shevchenko
2017-08-07 12:18       ` Linus Walleij
2017-08-02  8:38 ` Mika Westerberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).