From patchwork Wed Nov 23 08:27:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13053248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD658C433FE for ; Wed, 23 Nov 2022 08:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=LTng8CgNHJyTsXhBEO5vctev5a3oj36PpL/pjsE1E/Y=; b=0nHHWaVdoylW/5 JmNcGXxCC776Mt9AIRk+k20QH1vrGC5KaTOGydAL9wP1KyKkxGvy51HsRQV3i40Zy+X7dmhezg9PR 29iEhwSEUrgodDREwaUsg2lJCV1PzhpqBptF1wVskXF2r4vLbo38F2+S7ZopHQGbQxq3Van1LPwxi y6u3she8+vYByYTeWFaBxesdf5Ai5Ak2OoObq+3xEbW89r2gSCgMh8MCR8N0Fi72G1eQQEd7CYG6k u8c4/QP+cpooII9rrLHigvouKquB2Goeda6uj39eM7d3nw1wzeko/RWeszXwU5Z++iVk+OUqlHsR3 23Ooib3JGFbV9fSz1H4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxl6i-00FWa5-Ju; Wed, 23 Nov 2022 08:27:48 +0000 Received: from ams.source.kernel.org ([145.40.68.75]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxl6f-00FWWP-05 for linux-arm-kernel@lists.infradead.org; Wed, 23 Nov 2022 08:27:46 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 5E45FB81E50; Wed, 23 Nov 2022 08:27:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EAABDC433C1; Wed, 23 Nov 2022 08:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669192061; bh=2ofp/BMPjwg+BMvx/7faulMyTjPJEKpup6ALMxyJL58=; h=From:To:Cc:Subject:Date:From; b=WJjXJ2whn+6+lj2hNLVPETN8pcvKGKN/7RZr09IksU6GqhO4uboDzNGmG07PzA6Xn 3TZFVMavwDUNBC/lZQm8Mq87b3kDb2M22FtR0JIuGTubD9vS6FiW2ZtNEf3eb2LDrj q+LN3LFj5KNruZDDkaebHcbVofdqt6OcPUCsmqnh8r114pwzYSbV9q0WE2tRMwSt88 VF9QY6iUH6D0XLJt4NqY9zVonmVsWAWShywx9FXniazaV7GL2yTbfINhBZ1LoLe8wJ r9wSoo1YNN3IOOGCQLBqCAKbPS3fbre9YW4s3Box8UYDU5qG9XwVlw3l6O5QS0+3NT 4PGcFZAly+Xaw== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Subject: [PATCH 1/2] serial: atmel: cleanup atmel_start+stop_tx() Date: Wed, 23 Nov 2022 09:27:35 +0100 Message-Id: <20221123082736.24566-1-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221123_002745_394323_AF0F02AC X-CRM114-Status: GOOD ( 15.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Richard Genoud , linux-kernel@vger.kernel.org, Michael Walle , linux-serial@vger.kernel.org, "Jiri Slaby \(SUSE\)" , Claudiu Beznea , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Define local variables holding information about whether pdc or dma is used in the HW. These are retested several times by calls to atmel_use_pdc_tx() and atmel_use_dma_tx(). So to make the code more readable, simply cache the values. This is also a preparatory patch for the next one (where is_pdc is used once more in atmel_stop_tx()). Cc: Richard Genoud Cc: Nicolas Ferre Cc: Alexandre Belloni Cc: Claudiu Beznea Cc: linux-arm-kernel@lists.infradead.org Reported-by: Michael Walle Signed-off-by: Jiri Slaby (SUSE) Tested-by: Michael Walle Acked-by: Richard Genoud --- drivers/tty/serial/atmel_serial.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 4ca04676c406..65f63dccfd72 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -552,8 +552,9 @@ static u_int atmel_get_mctrl(struct uart_port *port) static void atmel_stop_tx(struct uart_port *port) { struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); + bool is_pdc = atmel_use_pdc_tx(port); - if (atmel_use_pdc_tx(port)) { + if (is_pdc) { /* disable PDC transmit */ atmel_uart_writel(port, ATMEL_PDC_PTCR, ATMEL_PDC_TXTDIS); } @@ -572,7 +573,6 @@ static void atmel_stop_tx(struct uart_port *port) if (atmel_uart_is_half_duplex(port)) if (!atomic_read(&atmel_port->tasklet_shutdown)) atmel_start_rx(port); - } /* @@ -581,20 +581,22 @@ static void atmel_stop_tx(struct uart_port *port) static void atmel_start_tx(struct uart_port *port) { struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); + bool is_pdc = atmel_use_pdc_tx(port); + bool is_dma = is_pdc || atmel_use_dma_tx(port); - if (atmel_use_pdc_tx(port) && (atmel_uart_readl(port, ATMEL_PDC_PTSR) + if (is_pdc && (atmel_uart_readl(port, ATMEL_PDC_PTSR) & ATMEL_PDC_TXTEN)) /* The transmitter is already running. Yes, we really need this.*/ return; - if (atmel_use_pdc_tx(port) || atmel_use_dma_tx(port)) - if (atmel_uart_is_half_duplex(port)) - atmel_stop_rx(port); + if (is_dma && atmel_uart_is_half_duplex(port)) + atmel_stop_rx(port); - if (atmel_use_pdc_tx(port)) + if (is_pdc) { /* re-enable PDC transmit */ atmel_uart_writel(port, ATMEL_PDC_PTCR, ATMEL_PDC_TXTEN); + } /* Enable interrupts */ atmel_uart_writel(port, ATMEL_US_IER, atmel_port->tx_done_mask); From patchwork Wed Nov 23 08:27:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Slaby X-Patchwork-Id: 13053249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6E16CC4332F for ; Wed, 23 Nov 2022 08:29:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=E3c1KFv5vnuOrR4sdAGP4tbZ8PqDI/wo1+e4dHaxtC4=; b=A/BdnPcnAiEugG xSZbvY98YjpqX1TnqLlCoAGTRlSIUjiJ78qZKkNdV22AEaKqkp1xctLKzqxGzaTZ/RdsPXfqtnKUI TUwtJYXtEiBHRFht3ZQxAH2LxTU83G+7LfOwGEAxeowQkUEotwlcBx2Q6pgoqJwzg7eyyuVq0nsJU uScZoJMvvqqGIVZX72Sf1vhY9nTZCP5ZPu24kSlyTDf2MB0Ul2Lxrqyjcc6YnlthICngsLcaEVpBq EI82jJC8qs9c2WD645ND3kxAWlecuy7mEk+DCA2jwpMsjrgzWHRGAh9TioElsPDjB8UUQYN/QKMWa zeB7D7x0n+0u+PukNEUw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxl75-00FWii-Df; Wed, 23 Nov 2022 08:28:11 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oxl6g-00FWYW-QP for linux-arm-kernel@lists.infradead.org; Wed, 23 Nov 2022 08:27:48 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2AABBB81EEA; Wed, 23 Nov 2022 08:27:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 962ACC433D7; Wed, 23 Nov 2022 08:27:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669192063; bh=+Gj9VY8s8NivuczNkGfzHn17+4LSQEt5i0IRoGeWmyc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=leqf/6jLvGhj6Vo0mGKQlru4xbl5WhJElvBN0FT2SCaHSpIXBm1QJnND/RwqkHniX UN254aoLDitmLzn65QxcdHj5EBSIToN0XmuAPy72V3O6M8nXwOg45TEhQHsQma3LDd GTE2G4vT9X0qwAtea+cM0OiforWe7iGdwzNqS5xZXtJO/Dbx0HGDC57JT3GDMKt4HF 8WgR4p2Gg2XFcX0idYJ13zhZSXSLALftFKnnxgIdKBOfHTHTTvpBEphEut479s0xbn Iq8ZGSNi+3TnA6vPAzeVDQ9cAI0QjRvcei38ZlEpOlB/o/JckE8hjRruwIUR/vGnNr 7AnoR5oizfUmQ== From: "Jiri Slaby (SUSE)" To: gregkh@linuxfoundation.org Subject: [PATCH 2/2] serial: atmel: don't stop the transmitter when doing PIO Date: Wed, 23 Nov 2022 09:27:36 +0100 Message-Id: <20221123082736.24566-2-jirislaby@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123082736.24566-1-jirislaby@kernel.org> References: <20221123082736.24566-1-jirislaby@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221123_002747_192549_B14E0ABE X-CRM114-Status: GOOD ( 18.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Richard Genoud , linux-kernel@vger.kernel.org, Michael Walle , linux-serial@vger.kernel.org, "Jiri Slaby \(SUSE\)" , Claudiu Beznea , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Writing ATMEL_US_TXDIS to ATMEL_US_CR makes the transmitter NOT to send the just queued character. This means when the character is last and uart calls ops->stop_tx(), the character is not sent at all. The usart datasheet is not much specific on this, it just says the transmitter is stopped. But apparently, the character is dropped. So we should stop the transmitter only for DMA and PDC transfers to not send any more characters. For PIO, this is unexpected and deviates from other drivers. In particular, the below referenced commit broke TX as it added a call to ->stop_tx() after the very last character written to the transmitter. So fix this by limiting the write of ATMEL_US_TXDIS to DMA transfers only. Even there, I don't know if it is correctly implemented. Are all the queued characters sent once ->start_tx() is called? Anyone tested flow control -- be it hard (RTSCTS) or the soft (XOFF/XON) one? Fixes: 2d141e683e9a ("tty: serial: use uart_port_tx() helper") Cc: Richard Genoud Cc: Nicolas Ferre Cc: Alexandre Belloni Cc: Claudiu Beznea Cc: linux-arm-kernel@lists.infradead.org Reported-by: Michael Walle Signed-off-by: Jiri Slaby (SUSE) Tested-by: Michael Walle Acked-by: Richard Genoud --- drivers/tty/serial/atmel_serial.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 65f63dccfd72..f1c06e12efa0 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -553,19 +553,22 @@ static void atmel_stop_tx(struct uart_port *port) { struct atmel_uart_port *atmel_port = to_atmel_uart_port(port); bool is_pdc = atmel_use_pdc_tx(port); + bool is_dma = is_pdc || atmel_use_dma_tx(port); if (is_pdc) { /* disable PDC transmit */ atmel_uart_writel(port, ATMEL_PDC_PTCR, ATMEL_PDC_TXTDIS); } - /* - * Disable the transmitter. - * This is mandatory when DMA is used, otherwise the DMA buffer - * is fully transmitted. - */ - atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXDIS); - atmel_port->tx_stopped = true; + if (is_dma) { + /* + * Disable the transmitter. + * This is mandatory when DMA is used, otherwise the DMA buffer + * is fully transmitted. + */ + atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXDIS); + atmel_port->tx_stopped = true; + } /* Disable interrupts */ atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); @@ -601,9 +604,11 @@ static void atmel_start_tx(struct uart_port *port) /* Enable interrupts */ atmel_uart_writel(port, ATMEL_US_IER, atmel_port->tx_done_mask); - /* re-enable the transmitter */ - atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN); - atmel_port->tx_stopped = false; + if (is_dma) { + /* re-enable the transmitter */ + atmel_uart_writel(port, ATMEL_US_CR, ATMEL_US_TXEN); + atmel_port->tx_stopped = false; + } } /*