From patchwork Wed Sep 7 16:13:24 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Genoud X-Patchwork-Id: 9319635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 30C7C60752 for ; Wed, 7 Sep 2016 16:17:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D34C293D6 for ; Wed, 7 Sep 2016 16:17:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 114B229403; Wed, 7 Sep 2016 16:17:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 873CE293D6 for ; Wed, 7 Sep 2016 16:17:03 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bhfUl-00045k-Ha; Wed, 07 Sep 2016 16:14:39 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bhfUI-0003n6-VB for linux-arm-kernel@lists.infradead.org; Wed, 07 Sep 2016 16:14:12 +0000 Received: by mail-wm0-x244.google.com with SMTP id a6so3698483wmc.2 for ; Wed, 07 Sep 2016 09:13:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OwQhVi0B1Fdy5ricVZUNpMKlrDIk3I60oEhTtJpJtZA=; b=ShE76d1EpcPE5sQ4hKv5FYaBpVB6NKC6yaYjCL6mzuxq5DumISD5l4DYdt/enSPD+e DOAXlMGwLdcOufyNQh6AfeC/Dy3H4MNjfG7IWhrU52N38aO8FZGPWhWz2oPFX+yoky5O 7uaTeS+dCriPcDMAyz8J1lZXUGoZ0PAaMvN5MSE2wsE3etCNVLqxemlo3e8xfxNYwqEO Cj486/ATfxOm9rFqUpKCzO6L3ifW/WmE45rQ275cafzPMxoSH8gMBbm15EDk31zYQ6GK BV9wX2a7QXEKEEso137qGycpWpNOqvbZLFK469DchKt6LrkBXx9ZJ6jM/S6upHRoaFDm UyhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OwQhVi0B1Fdy5ricVZUNpMKlrDIk3I60oEhTtJpJtZA=; b=AaI5QgUOimq5zBy/06OncIsPvwIq/4WfXDJ0UNhoAsMO/bdaXTc4dez+eaHX3OWPkd WFfixHvJoyP32zBqqdjc1M4Ncd/DPe2ChT0it6b1hDVuXbkHs68gWLba4v2PPs6ZOSHb YNNvWB3UmO7Hjb5MtMW2if7VWQ9AG5vuMOvrTC6UznKB9WntpTzRow6gvQe/wBTI6sbv hLpa0GCVVXYInMEULiDx5aiDnSfR2stxRQkcnR+lQz7Bb8nUDjJtPp0t+8embEi9qixs McFPbmGFfKaZNaqgZKtpXcv6hQJwwk0QwVne1e+OwhWuyGx1Dv5MnOt8AdsZxKbjViJH XfwQ== X-Gm-Message-State: AE9vXwO6lzQBqq2LcosixpplOrsnJESXwJ8XYGMTTdCEn7WGRw9FMNWImOCGuJVtlFL8Fg== X-Received: by 10.28.37.67 with SMTP id l64mr4756284wml.105.1473264833713; Wed, 07 Sep 2016 09:13:53 -0700 (PDT) Received: from localhost ([46.227.18.67]) by smtp.gmail.com with ESMTPSA id va3sm39639788wjb.18.2016.09.07.09.13.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Sep 2016 09:13:53 -0700 (PDT) From: Richard Genoud To: Cyrille Pitchen , Alexandre Belloni , Nicolas Ferre Subject: [PATCH 3/3] tty/serial: at91: fix hardware handshake when DMA is not used Date: Wed, 7 Sep 2016 18:13:24 +0200 Message-Id: <20160907161324.27774-3-richard.genoud@gmail.com> X-Mailer: git-send-email 2.10.0 In-Reply-To: <20160907161324.27774-1-richard.genoud@gmail.com> References: <20160907161324.27774-1-richard.genoud@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160907_091411_237126_B6B43C09 X-CRM114-Status: GOOD ( 15.86 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Richard Genoud , Greg Kroah-Hartman , linux-serial@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Commit 1cf6e8fc8341 ("tty/serial: at91: fix RTS line management when hardware handshake is enabled") broke the hardware handshake when DMA is not used. So, here's a summary: If DMA is NOT USED the mode should be ATMEL_US_USMODE_NORMAL because the controller can't drive the RTS pin (there's no way for it to know when we can't receive data anymore). If DMA is USED along with FIFOs, the mode should be ATMEL_US_USMODE_HWHS because when there's a FIFO, it can know when it's full and then drive the RTS pin accordingly. NB: I didn't test this mode since my board (at91sam9g35-cm) has not the FIFO mechanism. If DMA is USED WITHOUT FIFOs, then this is the bad case: the controller can't control the RTS pin, and we can't control it either by hand. So, the hardware handshake is disabled. (that's what commit 5be605ac9af9 ("tty/serial: atmel: fix hardware handshake selection") did). There's still something obscure to me: In the SAM9G35 datasheet, it's said that "Setting the USART to operate with hardware handshaking is performed by writing the USART_MODE field in US_MR to the value 0x2. [..] Using this mode requires using the DMA channel for reception." So, according to this, it *should* be possible to use automatic hardware handshake with the DMA and without FIFO (sam9x5 have no FIFOs like samad controllers) NB: -stable is not Cced because it doesn't cleanly apply on 4.1+ Signed-off-by: Richard Genoud Fixes: 1cf6e8fc8341 ("tty/serial: at91: fix RTS line management when hardware handshake is enabled") --- drivers/tty/serial/atmel_serial.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index e9b4fbf88c2d..503fbc623227 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -2130,14 +2130,26 @@ static void atmel_set_termios(struct uart_port *port, struct ktermios *termios, } else if ((termios->c_cflag & CRTSCTS) && !mctrl_gpio_use_rtscts(atmel_port->gpios)) { /* - * RS232 with hardware handshake (RTS/CTS) - * handled by the controller. + * Automatic hardware handshake (RTS/CTS) only work with + * DMA enabled and FIFOs. + * TODO: sam9x5 controllers don't have FIFOs like samad + * controllers, and yet, the datasheet says that the + * ATMEL_US_USMODE_HWHS can be used with (and only with) a DMA + * channel for reception. */ - if (atmel_use_dma_rx(port) && !atmel_use_fifo(port)) { - dev_info(port->dev, "not enabling hardware flow control because DMA is used"); - termios->c_cflag &= ~CRTSCTS; + if (atmel_use_dma_rx(port)) { + if (atmel_use_fifo(port)) { + mode |= ATMEL_US_USMODE_HWHS; + } else { + dev_info(port->dev, "not enabling hardware flow control because DMA is used without fifo"); + termios->c_cflag &= ~CRTSCTS; + } } else { - mode |= ATMEL_US_USMODE_HWHS; + /* + * if DMA is not used, tell the controller that it + * should not handle the RTS pin automatically + */ + mode |= ATMEL_US_USMODE_NORMAL; } } else { /* RS232 without hadware handshake or controlled by GPIOs */