<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: bug in lpuart32_setup_watermark - clears all other UARTMODIR fields when setting RTSWATER in i.MX Processors</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1632739#M204111</link>
    <description>&lt;P&gt;The software team has fixed this bug in upstream, you can import this in L5.X&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 899066daf16a..238ab0944284 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1722,7 +1722,7 @@ static void lpuart32_setup_watermark(struct lpuart_port *sport)
        /* set RTS watermark */
        if (!uart_console(&amp;amp;sport-&amp;gt;port)) {
                val = lpuart32_read(&amp;amp;sport-&amp;gt;port, UARTMODIR);
-               val = (sport-&amp;gt;rxfifo_size &amp;gt;&amp;gt; 1) &amp;lt;&amp;lt; UARTMODIR_RTSWATER_S;
+               val |= (sport-&amp;gt;rxfifo_size &amp;gt;&amp;gt; 1) &amp;lt;&amp;lt; UARTMODIR_RTSWATER_S;
                lpuart32_write(&amp;amp;sport-&amp;gt;port, val, UARTMODIR);
        }

 

@@ -2029,7 +2029,6 @@ static void lpuart32_shutdown(struct uart_port *port)
                UARTCTRL_TCIE | UARTCTRL_RIE | UARTCTRL_ILIE |
                UARTCTRL_LOOPS);
        lpuart32_write(port, temp, UARTCTRL);
-       lpuart32_write(port, 0, UARTMODIR);

 

        if (sport-&amp;gt;lpuart_dma_rx_use)
                sport-&amp;gt;dma_rx_chan_active = false;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2023 03:52:02 GMT</pubDate>
    <dc:creator>Zhiming_Liu</dc:creator>
    <dc:date>2023-04-13T03:52:02Z</dc:date>
    <item>
      <title>bug in lpuart32_setup_watermark - clears all other UARTMODIR fields when setting RTSWATER</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1626149#M203558</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;Looks like there is a bug in lpuart32_setup_watermark.&lt;BR /&gt;It clears all other UARTMODIR fields when setting the RTSWATER field:&lt;/P&gt;&lt;P&gt;&lt;A href="https://github.com/nxp-imx/linux-imx/blob/lf-5.15.y/drivers/tty/serial/fsl_lpuart.c#L1719" target="_blank" rel="noopener"&gt;https://github.com/nxp-imx/linux-imx/blob/lf-5.15.y/drivers/tty/serial/fsl_lpuart.c#L1719&lt;/A&gt;&lt;/P&gt;&lt;P&gt;/* set RTS watermark */&lt;BR /&gt;if (!uart_console(&amp;amp;sport-&amp;gt;port)) {&lt;BR /&gt;val = lpuart32_read(&amp;amp;sport-&amp;gt;port, UARTMODIR);&lt;BR /&gt;val = (sport-&amp;gt;rxfifo_size &amp;gt;&amp;gt; 1) &amp;lt;&amp;lt; UARTMODIR_RTSWATER_S;&lt;BR /&gt;lpuart32_write(&amp;amp;sport-&amp;gt;port, val, UARTMODIR);&lt;BR /&gt;}&lt;/P&gt;&lt;P&gt;It forgets to mask RTSWATER, to preserve the other fields e.g. TXRTSPOL, TXRTSE etc.&lt;BR /&gt;Compare with the masking (&amp;amp;= ~ and |=) when handling FIFO mode in the same function.&lt;/P&gt;&lt;P&gt;PS. The issue that we are having is that we have in the device tree:&lt;BR /&gt;&amp;amp;lpuart1 {&lt;BR /&gt;linux,rs485-enabled-at-boot-time;&lt;/P&gt;&lt;P&gt;TXRTSPOL, TXRTSE have the expected values initially, but after echo or cat /dev/ttyLP1, lpuart32_setup_watermark clears those bits...&lt;/P&gt;&lt;P&gt;Thank you&lt;BR /&gt;-- Peter&lt;/P&gt;</description>
      <pubDate>Fri, 31 Mar 2023 15:12:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1626149#M203558</guid>
      <dc:creator>petero5</dc:creator>
      <dc:date>2023-03-31T15:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: bug in lpuart32_setup_watermark - clears all other UARTMODIR fields when setting RTSWATER</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1628104#M203751</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/206875"&gt;@petero5&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want to report this bug or you already have solution to fix this ?&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;Zhiming&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 08:13:13 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1628104#M203751</guid>
      <dc:creator>Zhiming_Liu</dc:creator>
      <dc:date>2023-04-05T08:13:13Z</dc:date>
    </item>
    <item>
      <title>Re: bug in lpuart32_setup_watermark - clears all other UARTMODIR fields when setting RTSWATER</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1628253#M203767</link>
      <description>&lt;P&gt;Hi Zhiming &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/151788"&gt;@Zhiming_Liu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes please, I'd like to report this bug in lpuart32_setup_watermark plus a similar issue in lpuart32_shutdown.&lt;BR /&gt;What do we need to do to report these please?&lt;BR /&gt;Also need some advice re the lpuart32_shutdown side of this please.&lt;/P&gt;&lt;P&gt;Our transceiver, ST485B, needs RTS to be high when the the lpuart is sending, but low at all other times.&lt;BR /&gt;Using linux,rs485-enabled-at-boot-time in the device tree sets RTS low from boot.&lt;BR /&gt;The modem register fields, TXRTSE and TXRTSPOL are 1, which is what we need.&lt;/P&gt;&lt;P&gt;However, when anything calls open() on /dev/ttyLP1, the bug in lpuart32_setup_watermark clears those bits, which makes RTS permanently high instead of low...&lt;BR /&gt;And even if we workaround that bug on open(), on the close(), lpuart32_shutdown zeros the modem register again, making RTS permanently high again...&lt;/P&gt;&lt;P&gt;I've fixed my copy of lpuart32_setup_watermark, by adding the missing bit masking.&lt;BR /&gt;I guess that the author of lpuart32_setup_watermark forgot to add the masking, as the read is there, but the val that was read is overwritten?&lt;BR /&gt;Be good if this could be fixed in the official repo(s).&lt;/P&gt;&lt;P&gt;However for lpuart32_shutdown, the issue seems more intentional, and I'm less sure on the correct solution.&lt;/P&gt;&lt;P&gt;The issue in lpuart32_shutdown is:&lt;BR /&gt;&lt;A href="https://github.com/nxp-imx/linux-imx/blob/lf-5.15.y/drivers/tty/serial/fsl_lpuart.c#L2026" target="_blank" rel="noopener"&gt;https://github.com/nxp-imx/linux-imx/blob/lf-5.15.y/drivers/tty/serial/fsl_lpuart.c#L2026&lt;/A&gt;&lt;BR /&gt;lpuart32_write(port, 0, UARTMODIR)&lt;/P&gt;&lt;P&gt;We do not want this to zero TXRTSE and TXRTSPOL, so we could workaround this, quick and dirty by saving just those two bits.&lt;BR /&gt;But for a proper fix, which of all of the modem register fields should be zero'd and which should be preserved on close/shutdown?&lt;/P&gt;&lt;P&gt;Thank you&lt;BR /&gt;-- Peter&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2023 12:38:26 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1628253#M203767</guid>
      <dc:creator>petero5</dc:creator>
      <dc:date>2023-04-05T12:38:26Z</dc:date>
    </item>
    <item>
      <title>Re: bug in lpuart32_setup_watermark - clears all other UARTMODIR fields when setting RTSWATER</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1632739#M204111</link>
      <description>&lt;P&gt;The software team has fixed this bug in upstream, you can import this in L5.X&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;diff --git a/drivers/tty/serial/fsl_lpuart.c b/drivers/tty/serial/fsl_lpuart.c
index 899066daf16a..238ab0944284 100644
--- a/drivers/tty/serial/fsl_lpuart.c
+++ b/drivers/tty/serial/fsl_lpuart.c
@@ -1722,7 +1722,7 @@ static void lpuart32_setup_watermark(struct lpuart_port *sport)
        /* set RTS watermark */
        if (!uart_console(&amp;amp;sport-&amp;gt;port)) {
                val = lpuart32_read(&amp;amp;sport-&amp;gt;port, UARTMODIR);
-               val = (sport-&amp;gt;rxfifo_size &amp;gt;&amp;gt; 1) &amp;lt;&amp;lt; UARTMODIR_RTSWATER_S;
+               val |= (sport-&amp;gt;rxfifo_size &amp;gt;&amp;gt; 1) &amp;lt;&amp;lt; UARTMODIR_RTSWATER_S;
                lpuart32_write(&amp;amp;sport-&amp;gt;port, val, UARTMODIR);
        }

 

@@ -2029,7 +2029,6 @@ static void lpuart32_shutdown(struct uart_port *port)
                UARTCTRL_TCIE | UARTCTRL_RIE | UARTCTRL_ILIE |
                UARTCTRL_LOOPS);
        lpuart32_write(port, temp, UARTCTRL);
-       lpuart32_write(port, 0, UARTMODIR);

 

        if (sport-&amp;gt;lpuart_dma_rx_use)
                sport-&amp;gt;dma_rx_chan_active = false;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 03:52:02 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1632739#M204111</guid>
      <dc:creator>Zhiming_Liu</dc:creator>
      <dc:date>2023-04-13T03:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: bug in lpuart32_setup_watermark - clears all other UARTMODIR fields when setting RTSWATER</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1632898#M204125</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/151788"&gt;@Zhiming_Liu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;BR /&gt;Is that fix to lpuart32_setup_watermark definitely correct?&lt;BR /&gt;It looks like it will OR the old RTSWATER bits with the new RTSWATER bits, rather than replace them cleanly.&lt;BR /&gt;By comparison, higher up in that function when working with RXIDEN, it first zeros the RXIDEN bits using &amp;amp; and ~ like so:&lt;BR /&gt;&lt;A href="https://github.com/nxp-imx/linux-imx/blob/lf-5.15.y/drivers/tty/serial/fsl_lpuart.c#L1703" target="_blank"&gt;https://github.com/nxp-imx/linux-imx/blob/lf-5.15.y/drivers/tty/serial/fsl_lpuart.c#L1703&lt;/A&gt;&lt;BR /&gt;val &amp;amp;= ~(UARTFIFO_RXIDEN_MASK &amp;lt;&amp;lt; UARTFIFO_RXIDEN_OFF);&lt;BR /&gt;val |= ((rxiden_cnt &amp;amp; UARTFIFO_RXIDEN_MASK) &amp;lt;&amp;lt; UARTFIFO_RXIDEN_OFF);&lt;/P&gt;&lt;P&gt;Thank you&lt;BR /&gt;-- Peter&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 07:15:19 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1632898#M204125</guid>
      <dc:creator>petero5</dc:creator>
      <dc:date>2023-04-13T07:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: bug in lpuart32_setup_watermark - clears all other UARTMODIR fields when setting RTSWATER</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1635818#M204406</link>
      <description>&lt;P&gt;This is a simple fix, please refer the last upstream code.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Apr 2023 03:39:22 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1635818#M204406</guid>
      <dc:creator>Zhiming_Liu</dc:creator>
      <dc:date>2023-04-19T03:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: bug in lpuart32_setup_watermark - clears all other UARTMODIR fields when setting RTSWATER</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1640331#M204845</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.nxp.com/t5/user/viewprofilepage/user-id/151788"&gt;@Zhiming_Liu&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;BR /&gt;I've spent some time searching for the last upstream code, but am still unsure where to look.&lt;BR /&gt;What is the URL or repo and branch for upstream please?&lt;BR /&gt;&lt;BR /&gt;For example, I can still see the bug in lpuart32_setup_watermark in the following places:&lt;BR /&gt;&lt;A href="https://github.com/nxp-imx/linux-imx/blob/lf-5.15.y/drivers/tty/serial/fsl_lpuart.c#L1719" target="_blank"&gt;https://github.com/nxp-imx/linux-imx/blob/lf-5.15.y/drivers/tty/serial/fsl_lpuart.c#L1719&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://github.com/nxp-imx/linux-imx/blob/lf-6.1.y/drivers/tty/serial/fsl_lpuart.c#L1649" target="_blank"&gt;https://github.com/nxp-imx/linux-imx/blob/lf-6.1.y/drivers/tty/serial/fsl_lpuart.c#L1649&lt;/A&gt;&lt;BR /&gt;&lt;A href="https://github.com/Freescale/linux-fslc/blob/5.15-2.2.x-imx/drivers/tty/serial/fsl_lpuart.c#L1720" target="_blank"&gt;https://github.com/Freescale/linux-fslc/blob/5.15-2.2.x-imx/drivers/tty/serial/fsl_lpuart.c#L1720&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Thank you&lt;BR /&gt;-- Peter&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 07:48:46 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/bug-in-lpuart32-setup-watermark-clears-all-other-UARTMODIR/m-p/1640331#M204845</guid>
      <dc:creator>petero5</dc:creator>
      <dc:date>2023-04-26T07:48:46Z</dc:date>
    </item>
  </channel>
</rss>

