Linux-OMAP Archive mirror
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: linux-omap@vger.kernel.org
Cc: Dhruva Gole <d-gole@ti.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Philipp Zabel <p.zabel@pengutronix.de>,
	linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org
Subject: [RFC PATCH 4/4] serial: 8250: omap: Use reset control for resets
Date: Thu, 11 Apr 2024 08:22:57 +0300	[thread overview]
Message-ID: <20240411052257.2113-5-tony@atomide.com> (raw)
In-Reply-To: <20240411052257.2113-1-tony@atomide.com>

For at least am335x and omap4, we set the UART_ERRATA_CLOCK_DISABLE quirk
that ends up calling reset for the interconnect target. We can do this with
reset control framework and simplify the 8250_omap driver.

Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/tty/serial/8250/8250_omap.c | 66 +++++++++++------------------
 1 file changed, 24 insertions(+), 42 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_omap.c b/drivers/tty/serial/8250/8250_omap.c
--- a/drivers/tty/serial/8250/8250_omap.c
+++ b/drivers/tty/serial/8250/8250_omap.c
@@ -29,6 +29,7 @@
 #include <linux/dma-mapping.h>
 #include <linux/sys_soc.h>
 #include <linux/pm_domain.h>
+#include <linux/reset.h>
 
 #include "8250.h"
 
@@ -147,6 +148,7 @@ struct omap8250_priv {
 	struct pm_qos_request pm_qos_request;
 	struct work_struct qos_work;
 	struct uart_8250_dma omap8250_dma;
+	struct reset_control *reset;
 	spinlock_t rx_dma_lock;
 	bool rx_dma_broken;
 	bool throttled;
@@ -1490,6 +1492,14 @@ static int omap8250_probe(struct platform_device *pdev)
 	priv->line = -ENODEV;
 	priv->latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE;
 	priv->calc_latency = PM_QOS_CPU_LATENCY_DEFAULT_VALUE;
+
+	if (priv->habit & UART_ERRATA_CLOCK_DISABLE) {
+		priv->reset = devm_reset_control_get_exclusive(&pdev->dev,
+							       "softreset");
+		if (IS_ERR(priv->reset))
+			return PTR_ERR(priv->reset);
+	}
+
 	cpu_latency_qos_add_request(&priv->pm_qos_request, priv->latency);
 	INIT_WORK(&priv->qos_work, omap8250_uart_qos_work);
 
@@ -1695,47 +1705,6 @@ static void uart_write(struct omap8250_priv *priv, u32 reg, u32 val)
 	writel(val, priv->membase + (reg << OMAP_UART_REGSHIFT));
 }
 
-/* TODO: in future, this should happen via API in drivers/reset/ */
-static int omap8250_soft_reset(struct device *dev)
-{
-	struct omap8250_priv *priv = dev_get_drvdata(dev);
-	int timeout = 100;
-	int sysc;
-	int syss;
-
-	/*
-	 * At least on omap4, unused uarts may not idle after reset without
-	 * a basic scr dma configuration even with no dma in use. The
-	 * module clkctrl status bits will be 1 instead of 3 blocking idle
-	 * for the whole clockdomain. The softreset below will clear scr,
-	 * and we restore it on resume so this is safe to do on all SoCs
-	 * needing omap8250_soft_reset() quirk. Do it in two writes as
-	 * recommended in the comment for omap8250_update_scr().
-	 */
-	uart_write(priv, UART_OMAP_SCR, OMAP_UART_SCR_DMAMODE_1);
-	uart_write(priv, UART_OMAP_SCR,
-		   OMAP_UART_SCR_DMAMODE_1 | OMAP_UART_SCR_DMAMODE_CTL);
-
-	sysc = uart_read(priv, UART_OMAP_SYSC);
-
-	/* softreset the UART */
-	sysc |= OMAP_UART_SYSC_SOFTRESET;
-	uart_write(priv, UART_OMAP_SYSC, sysc);
-
-	/* By experiments, 1us enough for reset complete on AM335x */
-	do {
-		udelay(1);
-		syss = uart_read(priv, UART_OMAP_SYSS);
-	} while (--timeout && !(syss & OMAP_UART_SYSS_RESETDONE));
-
-	if (!timeout) {
-		dev_err(dev, "timed out waiting for reset done\n");
-		return -ETIMEDOUT;
-	}
-
-	return 0;
-}
-
 static int omap8250_runtime_suspend(struct device *dev)
 {
 	struct omap8250_priv *priv = dev_get_drvdata(dev);
@@ -1747,7 +1716,20 @@ static int omap8250_runtime_suspend(struct device *dev)
 	if (priv->habit & UART_ERRATA_CLOCK_DISABLE) {
 		int ret;
 
-		ret = omap8250_soft_reset(dev);
+		/*
+		 * At least on omap4, unused uarts may not idle after reset without
+		 * a basic scr dma configuration even with no dma in use. The
+		 * module clkctrl status bits will be 1 instead of 3 blocking idle
+		 * for the whole clockdomain. The softreset below will clear scr,
+		 * and we restore it on resume so this is safe to do on all SoCs
+		 * needing omap8250_soft_reset() quirk. Do it in two writes as
+		 * recommended in the comment for omap8250_update_scr().
+		 */
+		uart_write(priv, UART_OMAP_SCR, OMAP_UART_SCR_DMAMODE_1);
+		uart_write(priv, UART_OMAP_SCR,
+			   OMAP_UART_SCR_DMAMODE_1 | OMAP_UART_SCR_DMAMODE_CTL);
+
+		ret = reset_control_reset(priv->reset);
 		if (ret)
 			return ret;
 
-- 
2.44.0

      parent reply	other threads:[~2024-04-11  5:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11  5:22 [RFC PATCH 0/4] Provide interconnect resets for ti-sysc users Tony Lindgren
2024-04-11  5:22 ` [RFC PATCH 1/4] reset: Fall back to lookup if no reset node is found Tony Lindgren
2024-04-11  5:22 ` [RFC PATCH 2/4] reset: Allow removing a lookup Tony Lindgren
2024-04-11  5:22 ` [RFC PATCH 3/4] bus: ti-sysc: Implement reset control framework for soft reset Tony Lindgren
2024-04-11  5:22 ` Tony Lindgren [this message]

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=20240411052257.2113-5-tony@atomide.com \
    --to=tony@atomide.com \
    --cc=d-gole@ti.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=p.zabel@pengutronix.de \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).