diff mbox

serial: 8250: omap: Provide ability to enable/disable UART as wakeup source

Message ID 20180327120217.4749-1-vigneshr@ti.com (mailing list archive)
State New, archived
Headers show

Commit Message

Vignesh Raghavendra March 27, 2018, 12:02 p.m. UTC
Enable/Clear module level UART wakeup in UART_OMAP_WER register based on
return value of device_may_wakeup() in .suspend(). This allows
userspace to use sysfs to control the ability of UART to wakeup the
system from deep sleep state. Register is restored back in .startup()
call that happens as part of resume sequence.

With this patch, userspace can control UART wakeup capability via sysfs:
To enable wakeup capability:
echo enabled >  /sys/class/tty/ttyXX/device/power/wakeup
For disabling wakeup capability:
echo disabled > /sys/class/tty/ttyXX/device/power/wakeup

Signed-off-by: Vignesh R <vigneshr@ti.com>
---
 drivers/tty/serial/8250/8250_omap.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Tony Lindgren March 28, 2018, 10:30 p.m. UTC | #1
* Vignesh R <vigneshr@ti.com> [180327 12:03]:
> Enable/Clear module level UART wakeup in UART_OMAP_WER register based on
> return value of device_may_wakeup() in .suspend(). This allows
> userspace to use sysfs to control the ability of UART to wakeup the
> system from deep sleep state. Register is restored back in .startup()
> call that happens as part of resume sequence.
> 
> With this patch, userspace can control UART wakeup capability via sysfs:
> To enable wakeup capability:
> echo enabled >  /sys/class/tty/ttyXX/device/power/wakeup
> For disabling wakeup capability:
> echo disabled > /sys/class/tty/ttyXX/device/power/wakeup

To avoid confusion, can you please add this to the description:

Note that the UART wakeup events configured in the 8250 hardware only
work for idle modes that do not cut off power for the UART. For deeper
idle states, dedicated padconf wakeirqs must be used. Or in some cases
the UART RX pin can be remuxed to GPIO input if the GPIO block stays
powered.

I tested this briefly and the dedicated wakeirqs still work for me,
so from that point of view:

Tested-by: Tony Lindgren <tony@atomide.com>
--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Vignesh Raghavendra March 29, 2018, 5:32 a.m. UTC | #2
On Thursday 29 March 2018 04:00 AM, Tony Lindgren wrote:
> * Vignesh R <vigneshr@ti.com> [180327 12:03]:
>> Enable/Clear module level UART wakeup in UART_OMAP_WER register based on
>> return value of device_may_wakeup() in .suspend(). This allows
>> userspace to use sysfs to control the ability of UART to wakeup the
>> system from deep sleep state. Register is restored back in .startup()
>> call that happens as part of resume sequence.
>> 
>> With this patch, userspace can control UART wakeup capability via sysfs:
>> To enable wakeup capability:
>> echo enabled >  /sys/class/tty/ttyXX/device/power/wakeup
>> For disabling wakeup capability:
>> echo disabled > /sys/class/tty/ttyXX/device/power/wakeup
> 
> To avoid confusion, can you please add this to the description:
> 
> Note that the UART wakeup events configured in the 8250 hardware only
> work for idle modes that do not cut off power for the UART. For deeper
> idle states, dedicated padconf wakeirqs must be used. Or in some cases
> the UART RX pin can be remuxed to GPIO input if the GPIO block stays
> powered.
> 

That makes sense, I will add it to patch description in v2.

> I tested this briefly and the dedicated wakeirqs still work for me,
> so from that point of view:
> 
> Tested-by: Tony Lindgren <tony@atomide.com>

Thanks for testing!
diff mbox

Patch

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
index 624b501fd253..6aaa84355fd1 100644
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -1310,8 +1310,17 @@  static void omap8250_complete(struct device *dev)
 static int omap8250_suspend(struct device *dev)
 {
 	struct omap8250_priv *priv = dev_get_drvdata(dev);
+	struct uart_8250_port *up = serial8250_get_port(priv->line);
 
 	serial8250_suspend_port(priv->line);
+
+	pm_runtime_get_sync(dev);
+	if (!device_may_wakeup(dev))
+		priv->wer = 0;
+	serial_out(up, UART_OMAP_WER, priv->wer);
+	pm_runtime_mark_last_busy(dev);
+	pm_runtime_put_autosuspend(dev);
+
 	flush_work(&priv->qos_work);
 	return 0;
 }
@@ -1403,6 +1412,8 @@  static int omap8250_runtime_suspend(struct device *dev)
 
 		/* Restore to UART mode after reset (for wakeup) */
 		omap8250_update_mdr1(up, priv);
+		/* Restore wakeup enable register */
+		serial_out(up, UART_OMAP_WER, priv->wer);
 	}
 
 	if (up->dma && up->dma->rxchan)