+++ /dev/null
-From 74eab89b26ac433ad857292f4707b43c1a8f0209 Mon Sep 17 00:00:00 2001
-From: Lino Sanfilippo <l.sanfilippo@kunbus.com>
-Date: Wed, 3 Jan 2024 07:18:16 +0100
-Subject: serial: core, imx: do not set RS485 enabled if it is not supported
-MIME-Version: 1.0
-Content-Type: text/plain; charset=UTF-8
-Content-Transfer-Encoding: 8bit
-
-From: Lino Sanfilippo <l.sanfilippo@kunbus.com>
-
-commit 74eab89b26ac433ad857292f4707b43c1a8f0209 upstream.
-
-If the imx driver cannot support RS485 it nullifies the ports
-rs485_supported structure. But it still calls uart_get_rs485_mode() which
-may set the RS485_ENABLED flag nevertheless.
-
-This may lead to an attempt to configure RS485 even if it is not supported
-when the flag is evaluated in uart_configure_port() at port startup.
-
-Avoid this by bailing out of uart_get_rs485_mode() if the RS485_ENABLED
-flag is not supported by the caller.
-
-With this fix a check for RTS availability is now obsolete in the imx
-driver, since it can not evaluate to true any more. So remove this check.
-
-Furthermore the explicit nullifcation of rs485_supported is not needed,
-since the memory has already been set to zeros at allocation. So remove
-this, too.
-
-Fixes: 00d7a00e2a6f ("serial: imx: Fill in rs485_supported")
-Cc: Shawn Guo <shawnguo@kernel.org>
-Cc: Sascha Hauer <s.hauer@pengutronix.de>
-Cc: <stable@vger.kernel.org>
-Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
-Signed-off-by: Lino Sanfilippo <l.sanfilippo@kunbus.com>
-Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
-Link: https://lore.kernel.org/r/20240103061818.564-6-l.sanfilippo@kunbus.com
-Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
----
- drivers/tty/serial/imx.c | 7 -------
- drivers/tty/serial/serial_core.c | 3 +++
- 2 files changed, 3 insertions(+), 7 deletions(-)
-
-diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c
-index 8b7d9c5a7455..4aa72d5aeafb 100644
---- a/drivers/tty/serial/imx.c
-+++ b/drivers/tty/serial/imx.c
-@@ -2211,7 +2211,6 @@ static enum hrtimer_restart imx_trigger_stop_tx(struct hrtimer *t)
- return HRTIMER_NORESTART;
- }
-
--static const struct serial_rs485 imx_no_rs485 = {}; /* No RS485 if no RTS */
- static const struct serial_rs485 imx_rs485_supported = {
- .flags = SER_RS485_ENABLED | SER_RS485_RTS_ON_SEND | SER_RS485_RTS_AFTER_SEND |
- SER_RS485_RX_DURING_TX,
-@@ -2295,8 +2294,6 @@ static int imx_uart_probe(struct platform_device *pdev)
- /* RTS is required to control the RS485 transmitter */
- if (sport->have_rtscts || sport->have_rtsgpio)
- sport->port.rs485_supported = imx_rs485_supported;
-- else
-- sport->port.rs485_supported = imx_no_rs485;
- sport->port.flags = UPF_BOOT_AUTOCONF;
- timer_setup(&sport->timer, imx_uart_timeout, 0);
-
-@@ -2331,10 +2328,6 @@ static int imx_uart_probe(struct platform_device *pdev)
- if (ret)
- goto err_clk;
-
-- if (sport->port.rs485.flags & SER_RS485_ENABLED &&
-- (!sport->have_rtscts && !sport->have_rtsgpio))
-- dev_err(&pdev->dev, "no RTS control, disabling rs485\n");
--
- /*
- * If using the i.MX UART RTS/CTS control then the RTS (CTS_B)
- * signal cannot be set low during transmission in case the
-diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
-index b9606db78c92..b56ed8c376b2 100644
---- a/drivers/tty/serial/serial_core.c
-+++ b/drivers/tty/serial/serial_core.c
-@@ -3607,6 +3607,9 @@ int uart_get_rs485_mode(struct uart_port *port)
- u32 rs485_delay[2];
- int ret;
-
-+ if (!(port->rs485_supported.flags & SER_RS485_ENABLED))
-+ return 0;
-+
- ret = device_property_read_u32_array(dev, "rs485-rts-delay",
- rs485_delay, 2);
- if (!ret) {
---
-2.43.0
-
--- /dev/null
+From 7c45eaa813476bd195ac1227a64b52f9cf2e2030 Mon Sep 17 00:00:00 2001
+From: Christoph Niedermaier <cniedermaier@dh-electronics.com>
+Date: Tue, 26 Dec 2023 12:36:47 +0100
+Subject: serial: imx: Ensure that imx_uart_rs485_config() is called with enabled clock
+
+From: Christoph Niedermaier <cniedermaier@dh-electronics.com>
+
+commit 7c45eaa813476bd195ac1227a64b52f9cf2e2030 upstream.
+
+There are register accesses in the function imx_uart_rs485_config(). The
+clock must be enabled for these accesses. This was ensured by calling it
+via the function uart_rs485_config() in the probe() function within the
+range where the clock is enabled. With the commit 7c7f9bc986e6 ("serial:
+Deassert Transmit Enable on probe in driver-specific way") it was removed
+from the probe() function and is now only called through the function
+uart_add_one_port() which is located at the end of the probe() function.
+But the clock is already switched off in this area. To ensure that the
+clock is enabled during register access, move the disabling of the clock
+to the very end of the probe() function. To avoid leaking enabled clocks
+on error also add an error path for exiting with disabling the clock.
+
+Fixes: 7c7f9bc986e6 ("serial: Deassert Transmit Enable on probe in driver-specific way")
+Cc: stable <stable@kernel.org>
+Signed-off-by: Christoph Niedermaier <cniedermaier@dh-electronics.com>
+Reviewed-by: Lukas Wunner <lukas@wunner.de>
+Link: https://lore.kernel.org/r/20231226113647.39376-1-cniedermaier@dh-electronics.com
+Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
+---
+ drivers/tty/serial/imx.c | 23 ++++++++++++-----------
+ 1 file changed, 12 insertions(+), 11 deletions(-)
+
+--- a/drivers/tty/serial/imx.c
++++ b/drivers/tty/serial/imx.c
+@@ -2330,10 +2330,8 @@ static int imx_uart_probe(struct platfor
+ sport->ufcr = readl(sport->port.membase + UFCR);
+
+ ret = uart_get_rs485_mode(&sport->port);
+- if (ret) {
+- clk_disable_unprepare(sport->clk_ipg);
+- return ret;
+- }
++ if (ret)
++ goto err_clk;
+
+ if (sport->port.rs485.flags & SER_RS485_ENABLED &&
+ (!sport->have_rtscts && !sport->have_rtsgpio))
+@@ -2417,8 +2415,6 @@ static int imx_uart_probe(struct platfor
+ imx_uart_writel(sport, ucr3, UCR3);
+ }
+
+- clk_disable_unprepare(sport->clk_ipg);
+-
+ hrtimer_init(&sport->trigger_start_tx, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+ hrtimer_init(&sport->trigger_stop_tx, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+ sport->trigger_start_tx.function = imx_trigger_start_tx;
+@@ -2434,7 +2430,7 @@ static int imx_uart_probe(struct platfor
+ if (ret) {
+ dev_err(&pdev->dev, "failed to request rx irq: %d\n",
+ ret);
+- return ret;
++ goto err_clk;
+ }
+
+ ret = devm_request_irq(&pdev->dev, txirq, imx_uart_txint, 0,
+@@ -2442,7 +2438,7 @@ static int imx_uart_probe(struct platfor
+ if (ret) {
+ dev_err(&pdev->dev, "failed to request tx irq: %d\n",
+ ret);
+- return ret;
++ goto err_clk;
+ }
+
+ ret = devm_request_irq(&pdev->dev, rtsirq, imx_uart_rtsint, 0,
+@@ -2450,14 +2446,14 @@ static int imx_uart_probe(struct platfor
+ if (ret) {
+ dev_err(&pdev->dev, "failed to request rts irq: %d\n",
+ ret);
+- return ret;
++ goto err_clk;
+ }
+ } else {
+ ret = devm_request_irq(&pdev->dev, rxirq, imx_uart_int, 0,
+ dev_name(&pdev->dev), sport);
+ if (ret) {
+ dev_err(&pdev->dev, "failed to request irq: %d\n", ret);
+- return ret;
++ goto err_clk;
+ }
+ }
+
+@@ -2465,7 +2461,12 @@ static int imx_uart_probe(struct platfor
+
+ platform_set_drvdata(pdev, sport);
+
+- return uart_add_one_port(&imx_uart_uart_driver, &sport->port);
++ ret = uart_add_one_port(&imx_uart_uart_driver, &sport->port);
++
++err_clk:
++ clk_disable_unprepare(sport->clk_ipg);
++
++ return ret;
+ }
+
+ static int imx_uart_remove(struct platform_device *pdev)