diff mbox series

ARM: omap1: Make serial wakeup GPIOs use descriptors

Message ID 20230430175130.574971-1-linus.walleij@linaro.org
State New
Headers show
Series ARM: omap1: Make serial wakeup GPIOs use descriptors | expand

Commit Message

Linus Walleij April 30, 2023, 5:51 p.m. UTC
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(-)

Comments

Aaro Koskinen May 17, 2023, 6:03 p.m. UTC | #1
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.
Aaro Koskinen May 17, 2023, 7:06 p.m. UTC | #2
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.
Linus Walleij May 17, 2023, 9:02 p.m. UTC | #3
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
diff mbox series

Patch

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;
 }