From: Kumaravel Thiagarajan <kumaravel.thiagarajan@microchip.com>
To: <gregkh@linuxfoundation.org>, <jirislaby@kernel.org>,
<ilpo.jarvinen@linux.intel.com>, <andy.shevchenko@gmail.com>,
<u.kleine-koenig@pengutronix.de>, <johan@kernel.org>,
<wander@redhat.com>, <etremblay@distech-controls.com>,
<macro@orcam.me.uk>, <geert+renesas@glider.be>, <jk@ozlabs.org>,
<phil.edworthy@renesas.com>, <lukas@wunner.de>
Cc: <linux-kernel@vger.kernel.org>, <linux-serial@vger.kernel.org>,
<UNGLinuxDriver@microchip.com>
Subject: [PATCH v1 tty-next 2/2] 8250: microchip: pci1xxxx: Add power management functions to pci1xxxx's quad-uart driver.
Date: Tue, 30 Aug 2022 23:30:54 +0530 [thread overview]
Message-ID: <20220830180054.1998296-3-kumaravel.thiagarajan@microchip.com> (raw)
In-Reply-To: <20220830180054.1998296-1-kumaravel.thiagarajan@microchip.com>
pci1xxxx's quad-uart function has the capability to wake up the host from
suspend state. Enable wakeup before entering into suspend and disable
wakeup upon resume.
Signed-off-by: Kumaravel Thiagarajan <kumaravel.thiagarajan@microchip.com>
---
drivers/tty/serial/8250/8250_pci1xxxx.c | 122 ++++++++++++++++++++++++
1 file changed, 122 insertions(+)
diff --git a/drivers/tty/serial/8250/8250_pci1xxxx.c b/drivers/tty/serial/8250/8250_pci1xxxx.c
index 56852ae0585e..38c2a6a9e5d5 100644
--- a/drivers/tty/serial/8250/8250_pci1xxxx.c
+++ b/drivers/tty/serial/8250/8250_pci1xxxx.c
@@ -70,6 +70,7 @@
#define UART_PCI_CTRL_REG 0x80
#define UART_PCI_CTRL_SET_MULTIPLE_MSI BIT(4)
+#define UART_PCI_CTRL_D3_CLK_ENABLE BIT(0)
#define UART_WAKE_REG 0x8C
#define UART_WAKE_MASK_REG 0x90
@@ -78,6 +79,9 @@
#define UART_WAKE_INT BIT(0)
#define UART_WAKE_SRCS (UART_WAKE_N_PIN | UART_WAKE_NCTS | UART_WAKE_INT)
+#define UART_RESET_REG 0x94
+#define UART_RESET_D3_RESET_DISABLE BIT(16)
+
#define UART_BIT_SAMPLE_CNT 16
struct pci1xxxx_8250 {
@@ -439,6 +443,121 @@ static void pci1xxxx_serial_remove(struct pci_dev *dev)
serial8250_unregister_port(priv->line[i]);
}
+#ifdef CONFIG_PM_SLEEP
+
+static char pci1xxxx_port_suspend(int line)
+{
+ struct uart_8250_port *up = serial8250_get_port(line);
+ struct uart_port *port = &up->port;
+ unsigned long flags;
+ u8 wakeup_mask;
+ char ret = 0;
+
+ if (port->suspended == 0 && port->dev) {
+ wakeup_mask = readb(up->port.membase + UART_WAKE_MASK_REG);
+
+ spin_lock_irqsave(&port->lock, flags);
+ port->mctrl &= ~TIOCM_OUT2;
+ port->ops->set_mctrl(port, port->mctrl);
+ spin_unlock_irqrestore(&port->lock, flags);
+
+ if ((wakeup_mask & UART_WAKE_SRCS) != UART_WAKE_SRCS)
+ ret = 0x01;
+ else
+ ret = 0x00;
+ }
+
+ writeb(UART_WAKE_SRCS, port->membase + UART_WAKE_REG);
+
+ return ret;
+}
+
+void pci1xxxx_port_resume(int line)
+{
+ struct uart_8250_port *up = serial8250_get_port(line);
+ struct uart_port *port = &up->port;
+ unsigned long flags;
+
+ writeb(UART_WAKE_SRCS, port->membase + UART_WAKE_REG);
+
+ if (port->suspended == 0) {
+ spin_lock_irqsave(&port->lock, flags);
+ port->mctrl |= TIOCM_OUT2;
+ port->ops->set_mctrl(port, port->mctrl);
+ spin_unlock_irqrestore(&port->lock, flags);
+ }
+}
+
+static int pci1xxxx_suspend(struct device *dev)
+{
+ struct pci1xxxx_8250 *priv = dev_get_drvdata(dev);
+ struct pci_dev *pcidev = to_pci_dev(dev);
+ unsigned int data;
+ void __iomem *p;
+ char wakeup = 0;
+ int i;
+
+ for (i = 0; i < priv->nr; i++) {
+ if (priv->line[i] >= 0) {
+ serial8250_suspend_port(priv->line[i]);
+ wakeup |= pci1xxxx_port_suspend(priv->line[i]);
+ }
+ }
+
+ p = pci_ioremap_bar(pcidev, 0);
+ if (!p) {
+ dev_err(dev, "remapping of bar 0 memory failed");
+ return -ENOMEM;
+ }
+
+ data = readl(p + UART_RESET_REG);
+ writel(data | UART_RESET_D3_RESET_DISABLE, p + UART_RESET_REG);
+
+ if (wakeup)
+ writeb(UART_PCI_CTRL_D3_CLK_ENABLE, (p + UART_PCI_CTRL_REG));
+
+ iounmap(p);
+
+ device_set_wakeup_enable(dev, true);
+
+ pci_wake_from_d3(pcidev, true);
+
+ return 0;
+}
+
+static int pci1xxxx_resume(struct device *dev)
+{
+ struct pci1xxxx_8250 *priv = dev_get_drvdata(dev);
+ struct pci_dev *pcidev = to_pci_dev(dev);
+ unsigned int data;
+ void __iomem *p;
+ int i;
+
+ p = pci_ioremap_bar(pcidev, 0);
+ if (!p) {
+ dev_err(dev, "remapping of bar 0 memory failed");
+ return -ENOMEM;
+ }
+
+ data = readl(p + UART_RESET_REG);
+ writel(data & ~UART_RESET_D3_RESET_DISABLE, p + UART_RESET_REG);
+ iounmap(p);
+
+ for (i = 0; i < priv->nr; i++) {
+ if (priv->line[i] >= 0) {
+ pci1xxxx_port_resume(priv->line[i]);
+ serial8250_resume_port(priv->line[i]);
+ }
+ }
+
+ return 0;
+}
+
+#endif
+
+static SIMPLE_DEV_PM_OPS(pci1xxxx_pm_ops, pci1xxxx_suspend,
+ pci1xxxx_resume);
+
static const struct pci_device_id pci1xxxx_pci_tbl[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_MCHP_PCI1XXXX, PCI_DEVICE_ID_MCHP_PCI11010) },
{ PCI_DEVICE(PCI_VENDOR_ID_MCHP_PCI1XXXX, PCI_DEVICE_ID_MCHP_PCI11101) },
@@ -453,6 +572,9 @@ static struct pci_driver pci1xxxx_pci_driver = {
.name = "pci1xxxx serial",
.probe = pci1xxxx_serial_probe,
.remove = pci1xxxx_serial_remove,
+ .driver = {
+ .pm = &pci1xxxx_pm_ops,
+ },
.id_table = pci1xxxx_pci_tbl,
};
--
2.25.1
next prev parent reply other threads:[~2022-08-30 18:02 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-30 18:00 [PATCH v1 tty-next 0/2] 8250: microchip: pci1xxxx: Add driver for the pci1xxxx's quad-uart function Kumaravel Thiagarajan
2022-08-30 18:00 ` [PATCH v1 tty-next 1/2] 8250: microchip: pci1xxxx: Add driver for the quad-uart function in the multi-function endpoint of pci1xxxx device Kumaravel Thiagarajan
2022-08-30 19:53 ` Andy Shevchenko
2022-09-01 13:33 ` Kumaravel.Thiagarajan
2022-09-01 13:41 ` Ilpo Järvinen
2022-09-02 11:57 ` Kumaravel.Thiagarajan
2022-09-02 15:02 ` Andy Shevchenko
2022-09-05 12:01 ` Kumaravel.Thiagarajan
2022-08-30 19:58 ` Geert Uytterhoeven
2022-09-01 14:09 ` Kumaravel.Thiagarajan
2022-08-30 22:18 ` kernel test robot
2022-08-30 22:29 ` kernel test robot
2022-08-31 9:42 ` Ilpo Järvinen
2022-09-01 14:21 ` Kumaravel.Thiagarajan
2022-08-30 18:00 ` Kumaravel Thiagarajan [this message]
2022-08-30 19:56 ` [PATCH v1 tty-next 2/2] 8250: microchip: pci1xxxx: Add power management functions to pci1xxxx's quad-uart driver Andy Shevchenko
2022-09-01 13:49 ` Kumaravel.Thiagarajan
2022-09-29 9:34 ` Kumaravel.Thiagarajan
2022-08-30 23:00 ` kernel test robot
2022-08-31 9:53 ` Ilpo Järvinen
2022-09-02 2:20 ` Kumaravel.Thiagarajan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220830180054.1998296-3-kumaravel.thiagarajan@microchip.com \
--to=kumaravel.thiagarajan@microchip.com \
--cc=UNGLinuxDriver@microchip.com \
--cc=andy.shevchenko@gmail.com \
--cc=etremblay@distech-controls.com \
--cc=geert+renesas@glider.be \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jirislaby@kernel.org \
--cc=jk@ozlabs.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=macro@orcam.me.uk \
--cc=phil.edworthy@renesas.com \
--cc=u.kleine-koenig@pengutronix.de \
--cc=wander@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).