linux-omap.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ARM: omap1: Make serial wakeup GPIOs use descriptors
@ 2023-04-30 17:51 Linus Walleij
  2023-05-17 18:03 ` Aaro Koskinen
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2023-04-30 17:51 UTC (permalink / raw)
  To: Aaro Koskinen, Janusz Krzysztofik, Tony Lindgren
  Cc: linux-omap, Linus Walleij

The code in serial.c looks up GPIOs corresponding to a line
on the UART when muxed in as GPIO to use this as a wakeup
on serial activity for OMAP1.

Utilize the NULL device to define some board-specific
GPIO lookups and use these to immediately look up the
same GPIOs, set as input and convert to IRQ numbers,
then set these to wakeup IRQs. This is ugly but should work.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 arch/arm/mach-omap1/serial.c | 44 ++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 15 deletions(-)

diff --git a/arch/arm/mach-omap1/serial.c b/arch/arm/mach-omap1/serial.c
index c7f590645774..ceadbb17a651 100644
--- a/arch/arm/mach-omap1/serial.c
+++ b/arch/arm/mach-omap1/serial.c
@@ -4,7 +4,8 @@
  *
  * OMAP1 serial support.
  */
-#include <linux/gpio.h>
+#include <linux/gpio/machine.h>
+#include <linux/gpio/consumer.h>
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/init.h>
@@ -196,39 +197,52 @@ void omap_serial_wake_trigger(int enable)
 	}
 }
 
-static void __init omap_serial_set_port_wakeup(int gpio_nr)
+static void __init omap_serial_set_port_wakeup(int idx)
 {
+	struct gpio_desc *d;
 	int ret;
 
-	ret = gpio_request(gpio_nr, "UART wake");
-	if (ret < 0) {
-		printk(KERN_ERR "Could not request UART wake GPIO: %i\n",
-		       gpio_nr);
+	d = gpiod_get_index(NULL, "wakeup", idx, GPIOD_IN);
+	if (IS_ERR(d)) {
+		pr_err("Unable to get UART wakeup GPIO descriptor\n");
 		return;
 	}
-	gpio_direction_input(gpio_nr);
-	ret = request_irq(gpio_to_irq(gpio_nr), &omap_serial_wake_interrupt,
+	ret = request_irq(gpiod_to_irq(d), &omap_serial_wake_interrupt,
 			  IRQF_TRIGGER_RISING, "serial wakeup", NULL);
 	if (ret) {
-		gpio_free(gpio_nr);
-		printk(KERN_ERR "No interrupt for UART wake GPIO: %i\n",
-		       gpio_nr);
+		gpiod_put(d);
+		pr_err("No interrupt for UART%d wake GPIO\n" idx + 1);
 		return;
 	}
-	enable_irq_wake(gpio_to_irq(gpio_nr));
+	enable_irq_wake(gpiod_to_irq(d));
 }
 
+static struct gpiod_lookup_table omap_serial_uart_gpio_table = {
+	.dev_id = NULL,
+	.table = {
+		GPIO_LOOKUP_IDX("gpio-32-47", 5, "wakeup", 0,
+			    GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX("gpio-16-31", 2, "wakeup", 1,
+			    GPIO_ACTIVE_HIGH),
+		GPIO_LOOKUP_IDX("gpio-48-63", 1, "wakeup", 2,
+			    GPIO_ACTIVE_HIGH),
+		{ }
+	},
+};
+
 int __init omap_serial_wakeup_init(void)
 {
 	if (!cpu_is_omap16xx())
 		return 0;
 
+	gpiod_add_lookup_table(&omap_serial_uart_gpio_table);
+
 	if (uart1_ck != NULL)
-		omap_serial_set_port_wakeup(37);
+		omap_serial_set_port_wakeup(0);
 	if (uart2_ck != NULL)
-		omap_serial_set_port_wakeup(18);
+		omap_serial_set_port_wakeup(1);
 	if (uart3_ck != NULL)
-		omap_serial_set_port_wakeup(49);
+		omap_serial_set_port_wakeup(2);
 
 	return 0;
 }
-- 
2.34.1


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

* Re: [PATCH] ARM: omap1: Make serial wakeup GPIOs use descriptors
  2023-04-30 17:51 [PATCH] ARM: omap1: Make serial wakeup GPIOs use descriptors Linus Walleij
@ 2023-05-17 18:03 ` Aaro Koskinen
  2023-05-17 19:06   ` Aaro Koskinen
  0 siblings, 1 reply; 4+ messages in thread
From: Aaro Koskinen @ 2023-05-17 18:03 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Janusz Krzysztofik, Tony Lindgren, linux-omap

Hi,

This patch (now also in gpio-descriptors-omap branch) does not
compile:

On Sun, Apr 30, 2023 at 07:51:30PM +0200, Linus Walleij wrote:
> +		pr_err("No interrupt for UART%d wake GPIO\n" idx + 1);

Comma is missing.                                          ^^^

A.

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

* Re: [PATCH] ARM: omap1: Make serial wakeup GPIOs use descriptors
  2023-05-17 18:03 ` Aaro Koskinen
@ 2023-05-17 19:06   ` Aaro Koskinen
  2023-05-17 21:02     ` Linus Walleij
  0 siblings, 1 reply; 4+ messages in thread
From: Aaro Koskinen @ 2023-05-17 19:06 UTC (permalink / raw)
  To: Linus Walleij; +Cc: Janusz Krzysztofik, Tony Lindgren, linux-omap

Hi,

On Wed, May 17, 2023 at 09:03:49PM +0300, Aaro Koskinen wrote:
> This patch (now also in gpio-descriptors-omap branch) does not
> compile:
> 
> On Sun, Apr 30, 2023 at 07:51:30PM +0200, Linus Walleij wrote:
> > +		pr_err("No interrupt for UART%d wake GPIO\n" idx + 1);
> 
> Comma is missing.                                          ^^^

And when tested something goes wrong:

[    2.555725] (NULL device *): using lookup tables for GPIO lookup
[    2.561950] (NULL device *): No GPIO consumer wakeup found
[    2.567871] Unable to get UART wakeup GPIO descriptor
[    2.573272] (NULL device *): using lookup tables for GPIO lookup
[    2.579498] (NULL device *): No GPIO consumer wakeup found
[    2.585357] Unable to get UART wakeup GPIO descriptor
[    2.590576] (NULL device *): using lookup tables for GPIO lookup
[    2.596954] (NULL device *): No GPIO consumer wakeup found
[    2.602813] Unable to get UART wakeup GPIO descriptor

There are now two tables with the NULL device - one in the board file,
and another in serial.c. Maybe that does not work?

A.

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

* Re: [PATCH] ARM: omap1: Make serial wakeup GPIOs use descriptors
  2023-05-17 19:06   ` Aaro Koskinen
@ 2023-05-17 21:02     ` Linus Walleij
  0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2023-05-17 21:02 UTC (permalink / raw)
  To: Aaro Koskinen; +Cc: Janusz Krzysztofik, Tony Lindgren, linux-omap

On Wed, May 17, 2023 at 9:06 PM Aaro Koskinen <aaro.koskinen@iki.fi> wrote:
> On Wed, May 17, 2023 at 09:03:49PM +0300, Aaro Koskinen wrote:

> > This patch (now also in gpio-descriptors-omap branch) does not
> > compile:
> >
> > On Sun, Apr 30, 2023 at 07:51:30PM +0200, Linus Walleij wrote:
> > > +           pr_err("No interrupt for UART%d wake GPIO\n" idx + 1);
> >
> > Comma is missing.                                          ^^^

Hm I wonder what happened. Allright fixed it up.

> And when tested something goes wrong:
>
> [    2.555725] (NULL device *): using lookup tables for GPIO lookup
> [    2.561950] (NULL device *): No GPIO consumer wakeup found
> [    2.567871] Unable to get UART wakeup GPIO descriptor
> [    2.573272] (NULL device *): using lookup tables for GPIO lookup
> [    2.579498] (NULL device *): No GPIO consumer wakeup found
> [    2.585357] Unable to get UART wakeup GPIO descriptor
> [    2.590576] (NULL device *): using lookup tables for GPIO lookup
> [    2.596954] (NULL device *): No GPIO consumer wakeup found
> [    2.602813] Unable to get UART wakeup GPIO descriptor
>
> There are now two tables with the NULL device - one in the board file,
> and another in serial.c. Maybe that does not work?

Hm I pushed it down to each boardfile NULL device instead.

I sent out a v2, I will update the branch in my git as well as soon
as I looked into your other review comments.

Yours,
Linus Walleij

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

end of thread, other threads:[~2023-05-17 21:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-30 17:51 [PATCH] ARM: omap1: Make serial wakeup GPIOs use descriptors Linus Walleij
2023-05-17 18:03 ` Aaro Koskinen
2023-05-17 19:06   ` Aaro Koskinen
2023-05-17 21:02     ` Linus Walleij

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).