serial: sifive: Add suspend and resume operations
authorNick Hu <nick.hu@sifive.com>
Tue, 15 Aug 2023 09:02:16 +0000 (17:02 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Aug 2023 13:29:10 +0000 (15:29 +0200)
If the Sifive Uart is not used as the wake up source, suspend the uart
before the system enter the suspend state to prevent it woken up by
unexpected uart interrupt. Resume the uart once the system woken up.

Signed-off-by: Nick Hu <nick.hu@sifive.com>
Reviewed-by: Ben Dooks <ben.dooks@codethink.co.uk>
Link: https://lore.kernel.org/r/20230815090216.2575971-1-nick.hu@sifive.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/serial/sifive.c

index e2efc3f..d195c5d 100644 (file)
@@ -1019,6 +1019,23 @@ static int sifive_serial_remove(struct platform_device *dev)
        return 0;
 }
 
+static int sifive_serial_suspend(struct device *dev)
+{
+       struct sifive_serial_port *ssp = dev_get_drvdata(dev);
+
+       return uart_suspend_port(&sifive_serial_uart_driver, &ssp->port);
+}
+
+static int sifive_serial_resume(struct device *dev)
+{
+       struct sifive_serial_port *ssp = dev_get_drvdata(dev);
+
+       return uart_resume_port(&sifive_serial_uart_driver, &ssp->port);
+}
+
+DEFINE_SIMPLE_DEV_PM_OPS(sifive_uart_pm_ops, sifive_serial_suspend,
+                        sifive_serial_resume);
+
 static const struct of_device_id sifive_serial_of_match[] = {
        { .compatible = "sifive,fu540-c000-uart0" },
        { .compatible = "sifive,uart0" },
@@ -1031,6 +1048,7 @@ static struct platform_driver sifive_serial_platform_driver = {
        .remove         = sifive_serial_remove,
        .driver         = {
                .name   = SIFIVE_SERIAL_NAME,
+               .pm = pm_sleep_ptr(&sifive_uart_pm_ops),
                .of_match_table = sifive_serial_of_match,
        },
 };