Merge tag 'tty-6.9-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty
[sfrench/cifs-2.6.git] / drivers / tty / serial / serial_port.c
index 6779a008e67aadaf1d567d8aea75caa3d1adf3cb..22b9eeb23e68adb2cfd949ff20c18816bb78b1cb 100644 (file)
@@ -49,8 +49,31 @@ out:
        return 0;
 }
 
+static int serial_port_runtime_suspend(struct device *dev)
+{
+       struct serial_port_device *port_dev = to_serial_base_port_device(dev);
+       struct uart_port *port = port_dev->port;
+       unsigned long flags;
+       bool busy;
+
+       if (port->flags & UPF_DEAD)
+               return 0;
+
+       uart_port_lock_irqsave(port, &flags);
+       busy = __serial_port_busy(port);
+       if (busy)
+               port->ops->start_tx(port);
+       uart_port_unlock_irqrestore(port, flags);
+
+       if (busy)
+               pm_runtime_mark_last_busy(dev);
+
+       return busy ? -EBUSY : 0;
+}
+
 static DEFINE_RUNTIME_DEV_PM_OPS(serial_port_pm,
-                                NULL, serial_port_runtime_resume, NULL);
+                                serial_port_runtime_suspend,
+                                serial_port_runtime_resume, NULL);
 
 static int serial_port_probe(struct device *dev)
 {