From: Tony Lindgren <tony@atomide.com>
To: John Ogness <john.ogness@linutronix.de>
Cc: "Chen-Yu Tsai" <wenst@chromium.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Jiri Slaby" <jirislaby@kernel.org>,
"Andy Shevchenko" <andriy.shevchenko@intel.com>,
"Dhruva Gole" <d-gole@ti.com>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Johan Hovold" <johan@kernel.org>,
"Sebastian Andrzej Siewior" <bigeasy@linutronix.de>,
"Vignesh Raghavendra" <vigneshr@ti.com>,
linux-omap@vger.kernel.org,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
"Nícolas F. R. A. Prado" <nfraprado@collabora.com>,
"AngeloGioacchino Del Regno"
<angelogioacchino.delregno@collabora.com>,
linux-mediatek@lists.infradead.org
Subject: Re: [PATCH v12 1/1] serial: core: Start managing serial controllers to enable runtime PM
Date: Mon, 5 Jun 2023 09:15:11 +0300 [thread overview]
Message-ID: <20230605061511.GW14287@atomide.com> (raw)
In-Reply-To: <20230603063533.GS14287@atomide.com>
* Tony Lindgren <tony@atomide.com> [230603 06:35]:
> * Tony Lindgren <tony@atomide.com> [230603 05:41]:
> > I don't think 8250_mtk needs to do register access before and after the
> > serial port registration, but if it does, then adding custom read/write
> > functions can be done that do not rely on initialized port like
> > serial_out().
>
> Oh but mtk8250_runtime_suspend() calls serial_in(up, MTK_UART_DEBUG0), so
> yeah if that gets called before registration is complete it causes a NULL
> pointer exception. If the serial_ctrl and serial_port devices do runtime
> suspend before port registration completes, things will fail.
>
> Sounds like doing pm_runtime_resume_and_get() in mtk8250_probe() might
> fix the issue. Still seems that adding a custom read function for
> mtk8250_runtime_suspend() to use instead of calling serial_in() should
> not be needed.
Looking at this again, if serial8250_register_8250_port() fails, then
mtk8250_runtime_suspend() would again try to access uninitialized port.
Here's a better untested version of the patch to try.
Regards,
Tony
8< ---------------------------
diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c
--- a/drivers/tty/serial/8250/8250_mtk.c
+++ b/drivers/tty/serial/8250/8250_mtk.c
@@ -57,6 +57,8 @@
#define MTK_UART_XON1 40 /* I/O: Xon character 1 */
#define MTK_UART_XOFF1 42 /* I/O: Xoff character 1 */
+#define MTK_UART_REGSHIFT 2
+
#ifdef CONFIG_SERIAL_8250_DMA
enum dma_rx_status {
DMA_RX_START = 0,
@@ -69,6 +71,7 @@ struct mtk8250_data {
int line;
unsigned int rx_pos;
unsigned int clk_count;
+ void __iomem *membase;
struct clk *uart_clk;
struct clk *bus_clk;
struct uart_8250_dma *dma;
@@ -187,6 +190,17 @@ static void mtk8250_dma_enable(struct uart_8250_port *up)
}
#endif
+/* Read and write for register access before and after port registration */
+static u32 __maybe_unused mtk8250_read(struct mtk8250_data *data, u32 reg)
+{
+ return readl(data->membase + (reg << MTK_UART_REGSHIFT));
+}
+
+static void mtk8250_write(struct mtk8250_data *data, u32 reg, u32 val)
+{
+ writel(val, data->membase + (reg << MTK_UART_REGSHIFT));
+}
+
static int mtk8250_startup(struct uart_port *port)
{
#ifdef CONFIG_SERIAL_8250_DMA
@@ -425,11 +439,10 @@ mtk8250_set_termios(struct uart_port *port, struct ktermios *termios,
static int __maybe_unused mtk8250_runtime_suspend(struct device *dev)
{
struct mtk8250_data *data = dev_get_drvdata(dev);
- struct uart_8250_port *up = serial8250_get_port(data->line);
/* wait until UART in idle status */
while
- (serial_in(up, MTK_UART_DEBUG0));
+ (mtk8250_read(data, MTK_UART_DEBUG0));
if (data->clk_count == 0U) {
dev_dbg(dev, "%s clock count is 0\n", __func__);
@@ -553,6 +566,7 @@ static int mtk8250_probe(struct platform_device *pdev)
if (!data)
return -ENOMEM;
+ data->membase = uart.port.membase;
data->clk_count = 0;
if (pdev->dev.of_node) {
@@ -570,7 +584,7 @@ static int mtk8250_probe(struct platform_device *pdev)
uart.port.flags = UPF_BOOT_AUTOCONF | UPF_FIXED_PORT;
uart.port.dev = &pdev->dev;
uart.port.iotype = UPIO_MEM32;
- uart.port.regshift = 2;
+ uart.port.regshift = MTK_UART_REGSHIFT;
uart.port.private_data = data;
uart.port.shutdown = mtk8250_shutdown;
uart.port.startup = mtk8250_startup;
@@ -581,27 +595,30 @@ static int mtk8250_probe(struct platform_device *pdev)
uart.dma = data->dma;
#endif
- /* Disable Rate Fix function */
- writel(0x0, uart.port.membase +
- (MTK_UART_RATE_FIX << uart.port.regshift));
-
platform_set_drvdata(pdev, data);
pm_runtime_enable(&pdev->dev);
- err = mtk8250_runtime_resume(&pdev->dev);
+ err = pm_runtime_resume_and_get(&pdev->dev);
if (err)
goto err_pm_disable;
+ /* Disable Rate Fix function */
+ mtk8250_write(data, 0, MTK_UART_RATE_FIX);
+
data->line = serial8250_register_8250_port(&uart);
if (data->line < 0) {
err = data->line;
- goto err_pm_disable;
+ goto err_pm_put;
}
data->rx_wakeup_irq = platform_get_irq_optional(pdev, 1);
+ pm_runtime_put_sync(&pdev->dev);
+
return 0;
+err_pm_put:
+ pm_runtime_put_sync(&pdev->dev);
err_pm_disable:
pm_runtime_disable(&pdev->dev);
@@ -694,7 +711,7 @@ static int __init early_mtk8250_setup(struct earlycon_device *device,
return -ENODEV;
device->port.iotype = UPIO_MEM32;
- device->port.regshift = 2;
+ device->port.regshift = MTK_UART_REGSHIFT;
return early_serial8250_setup(device, NULL);
}
next prev parent reply other threads:[~2023-06-05 6:15 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230525113034.46880-1-tony@atomide.com>
2023-06-02 8:33 ` [PATCH v12 1/1] serial: core: Start managing serial controllers to enable runtime PM Chen-Yu Tsai
2023-06-02 9:27 ` Tony Lindgren
2023-06-02 10:13 ` John Ogness
2023-06-03 5:41 ` Tony Lindgren
2023-06-03 6:35 ` Tony Lindgren
2023-06-05 6:15 ` Tony Lindgren [this message]
2023-06-05 11:28 ` Andy Shevchenko
2023-06-05 12:25 ` Tony Lindgren
2023-06-05 11:34 ` Chen-Yu Tsai
2023-06-05 12:24 ` Tony Lindgren
2023-06-05 13:01 ` Chen-Yu Tsai
2023-06-05 13:18 ` Tony Lindgren
2023-06-06 9:16 ` Chen-Yu Tsai
2023-06-06 12:20 ` Tony Lindgren
2023-06-07 4:46 ` Chen-Yu Tsai
2023-06-07 7:17 ` AngeloGioacchino Del Regno
2023-06-07 20:20 ` Andy Shevchenko
2023-06-03 21:57 ` Sebastian Reichel
2023-06-04 6:04 ` Tony Lindgren
2023-06-05 3:04 ` Chen-Yu Tsai
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=20230605061511.GW14287@atomide.com \
--to=tony@atomide.com \
--cc=andriy.shevchenko@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=angelogioacchino.delregno@collabora.com \
--cc=bigeasy@linutronix.de \
--cc=d-gole@ti.com \
--cc=gregkh@linuxfoundation.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jirislaby@kernel.org \
--cc=johan@kernel.org \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mediatek@lists.infradead.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=nfraprado@collabora.com \
--cc=vigneshr@ti.com \
--cc=wenst@chromium.org \
/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).