Skip to contentSkip to conversation

8250: Allow platform to register PM hook

PATCH New Kevin Hilman 1 participant 2 messages Nov 27, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 8250: Allow platform to register PM hook

Allow platform code to register a PM hook with the 8250 driver. This enables platform specific code to be run for suspend/resume events.

Since the per-port PM hook is local to the 8250 driver ('struct uart_port' doesn't have a PM hook) I pass the pm hook from the platform probe via serial8250_register_port().

---
 drivers/serial/8250.c       |    7 +++++--
 include/linux/serial_8250.h |    7 ++++++-
 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/serial/8250.c +5 -2
index 5f383d8..993a242 100644
@@ -2842,7 +2842,7 @@ static int __devinit serial8250_probe(struct platform_device *dev)
 		port.dev		= &dev->dev;
 		if (share_irqs)
 			port.flags |= UPF_SHARE_IRQ;
-		ret = serial8250_register_port(&port);
+		ret = serial8250_register_port(&port, p->pm);
 		if (ret < 0) {
 			dev_err(&dev->dev, "unable to register port at index %d "
 				"(IO%lx MEM%llx IRQ%d): %d\n", i,
@@ -2966,7 +2966,9 @@ static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *
  *
  *	On success the port is ready to use and the line number is returned.
  */
-int serial8250_register_port(struct uart_port *port)
+int serial8250_register_port(struct uart_port *port,
+			     void (*pm)(struct uart_port *, unsigned int state,
+					unsigned int oldstate))
 {
 	struct uart_8250_port *uart;
 	int ret = -ENOSPC;
@@ -2990,6 +2992,7 @@ int serial8250_register_port(struct uart_port *port)
 		uart->port.flags        = port->flags | UPF_BOOT_AUTOCONF;
 		uart->port.mapbase      = port->mapbase;
 		uart->port.private_data = port->private_data;
+		uart->pm = pm;
 		if (port->dev)
 			uart->port.dev = port->dev;
 
include/linux/serial_8250.h +6 -1
index 3d37c94..97723c5 100644
@@ -28,6 +28,9 @@ struct plat_serial8250_port {
 	unsigned char	iotype;		/* UPIO_* */
 	unsigned char	hub6;
 	upf_t		flags;		/* UPF_* flags */
+
+	void		(*pm)(struct uart_port *, unsigned int state,
+			      unsigned int oldstate);
 };
 
 /*
@@ -57,7 +60,9 @@ enum {
  */
 struct uart_port;
 
-int serial8250_register_port(struct uart_port *);
+int serial8250_register_port(struct uart_port *,
+			     void (*pm)(struct uart_port *, unsigned int state,
+					unsigned int oldstate));
 void serial8250_unregister_port(int line);
 void serial8250_suspend_port(int line);
 void serial8250_resume_port(int line);
Signature · 1 line
1.6.0.3
#1 lore raw

PATCH 1/1 8250: when waking, PM hook should be called before accessing port

The UART suspend hook may have disabled the UART clocks such that accesses to the port may fail. So before accessing the port call the PM hook so it has a chance to enable clocks.

---
 drivers/serial/8250.c |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
drivers/serial/8250.c +10 -2
index 993a242..a181667 100644
@@ -2334,10 +2334,18 @@ serial8250_pm(struct uart_port *port, unsigned int state,
 	      unsigned int oldstate)
 {
 	struct uart_8250_port *p = (struct uart_8250_port *)port;
+	int sleep = state != 0;
 
-	serial8250_set_sleep(p, state != 0);
+	/* If we're waking up, call the PM hook before waking up
+	 * so port can be properly activated/enabled if necessary */
+	if (p->pm && !sleep)
+		p->pm(port, state, oldstate);
+
+	serial8250_set_sleep(p, sleep);
 
-	if (p->pm)
+	/* If we're going to sleep, PM hook should be called after
+	 * to deactivate/disable port */
+	if (p->pm && sleep)
 		p->pm(port, state, oldstate);
 }
 
Signature · 1 line
1.6.0.3