Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1370929img; Tue, 19 Mar 2019 06:21:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqw4updVzt651J3xE6Ur+3+drlsKOoAUWxNluCIv3y4rGr9pljzR6eSZMrylUOVkinUbHRLA X-Received: by 2002:a65:4844:: with SMTP id i4mr1984073pgs.347.1553001696138; Tue, 19 Mar 2019 06:21:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553001696; cv=none; d=google.com; s=arc-20160816; b=g3hAsODgaU9ia5ch9w1hpCcI18iH4hAvUPWsgPkXoUFNvvRww7IuN9x9W5FqoXw9ZU NJPdE4eXhTJVzHo6bDN+io/F+Glb0BtDhVCHZSMZXOTB2DL9NxOvSojTeWtkv7zIVUZ/ nAZSzBgMG+Kn/vuXuKcc9SlddJNkYacivuGJW2Kj9ynoRwHuulFz6ihTX/+CGruCqD7H 47v68y3mRfepQUYE0syRIoAUhpqHOC1OZhdD4TsLBD4y7qjbO+wit4SRQqT+bcFbNNMm OhjVKg1eDkbDW53sNM63JJbeevmBUZI2PpR1oqqwv3CoSZ43Q9aVKRDWAFDzOPKJcFZb X7Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Gy6XChwKrhZwgwp1MZjrcTI5UlW3zaehsZTE/urIrZU=; b=mNDK1cnFNiAh1Lh7/bKksWl+TIN5Halm6K40hte5uaNfmcBBWWlsD6TbfqwCOglGjo DOM1JwO2+sunH+uZChWUispzQUYav44eiBusXO8bR5gmi5SYR62CeHUGGB29e+m88DDF uXjd5tqF87fVQXWfhk2OW4cI50Nqg/JrwMb6TPBcSPEkIEHLka0ABw2/Ta+boJ7FhEhG L467FI3qYOHECSdlWHr63bjw4r4n5x45f4+cIaoKZOT3jeC/GngF/zgTWSygHOAKGeh3 NLOm+CgdOvXX80A4u8G/sSqxJxDSOKINSqS45qpyD7/uaQZFD6z8ndIRhCK3+tzklslV liNQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f32si11191095plf.24.2019.03.19.06.21.21; Tue, 19 Mar 2019 06:21:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727235AbfCSNUl (ORCPT + 99 others); Tue, 19 Mar 2019 09:20:41 -0400 Received: from esa1.microchip.iphmx.com ([68.232.147.91]:31053 "EHLO esa1.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726007AbfCSNUk (ORCPT ); Tue, 19 Mar 2019 09:20:40 -0400 X-IronPort-AV: E=Sophos;i="5.58,498,1544511600"; d="scan'208";a="29630298" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa1.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 Mar 2019 06:20:39 -0700 Received: from rob-ult-m50855.microchip.com (10.10.76.4) by chn-sv-exch03.mchp-main.com (10.10.76.49) with Microsoft SMTP Server id 14.3.352.0; Tue, 19 Mar 2019 06:20:39 -0700 From: Razvan Stefanescu To: Richard Genoud , Greg Kroah-Hartman , Jiri Slaby CC: Gil Weber , Nicolas Ferre , Alexandre Belloni , Ludovic Desroches , , , Subject: [PATCH v2 1/2] tty/serial: atmel: Add is_half_duplex helper Date: Tue, 19 Mar 2019 15:20:34 +0200 Message-ID: <20190319132035.18481-2-razvan.stefanescu@microchip.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190319132035.18481-1-razvan.stefanescu@microchip.com> References: <20190319132035.18481-1-razvan.stefanescu@microchip.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use a helper function to check that a port needs to use half duplex communication, replacing several occurrences of multi-line bit checking. Fixes: b389f173aaa1 ("tty/serial: atmel: RS485 half duplex w/DMA: enable RX after TX is done") Signed-off-by: Razvan Stefanescu --- Changelog: v2: - remove extra check - add fix info drivers/tty/serial/atmel_serial.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 05147fe24343..b4b89a16a41b 100644 --- a/drivers/tty/serial/atmel_serial.c +++ b/drivers/tty/serial/atmel_serial.c @@ -231,6 +231,13 @@ static inline void atmel_uart_write_char(struct uart_port *port, u8 value) __raw_writeb(value, port->membase + ATMEL_US_THR); } +static inline int atmel_uart_is_half_duplex(struct uart_port *port) +{ + return ((port->rs485.flags & SER_RS485_ENABLED) && + !(port->rs485.flags & SER_RS485_RX_DURING_TX)) || + (port->iso7816.flags & SER_ISO7816_ENABLED); +} + #ifdef CONFIG_SERIAL_ATMEL_PDC static bool atmel_use_pdc_rx(struct uart_port *port) { @@ -608,10 +615,9 @@ static void atmel_stop_tx(struct uart_port *port) /* Disable interrupts */ atmel_uart_writel(port, ATMEL_US_IDR, atmel_port->tx_done_mask); - if (((port->rs485.flags & SER_RS485_ENABLED) && - !(port->rs485.flags & SER_RS485_RX_DURING_TX)) || - port->iso7816.flags & SER_ISO7816_ENABLED) + if (atmel_uart_is_half_duplex(port)) atmel_start_rx(port); + } /* @@ -628,9 +634,7 @@ static void atmel_start_tx(struct uart_port *port) return; if (atmel_use_pdc_tx(port) || atmel_use_dma_tx(port)) - if (((port->rs485.flags & SER_RS485_ENABLED) && - !(port->rs485.flags & SER_RS485_RX_DURING_TX)) || - port->iso7816.flags & SER_ISO7816_ENABLED) + if (atmel_uart_is_half_duplex(port)) atmel_stop_rx(port); if (atmel_use_pdc_tx(port)) @@ -928,9 +932,7 @@ static void atmel_complete_tx_dma(void *arg) */ if (!uart_circ_empty(xmit)) atmel_tasklet_schedule(atmel_port, &atmel_port->tasklet_tx); - else if (((port->rs485.flags & SER_RS485_ENABLED) && - !(port->rs485.flags & SER_RS485_RX_DURING_TX)) || - port->iso7816.flags & SER_ISO7816_ENABLED) { + else if (atmel_uart_is_half_duplex(port)) { /* DMA done, stop TX, start RX for RS485 */ atmel_start_rx(port); } @@ -1508,9 +1510,7 @@ static void atmel_tx_pdc(struct uart_port *port) atmel_uart_writel(port, ATMEL_US_IER, atmel_port->tx_done_mask); } else { - if (((port->rs485.flags & SER_RS485_ENABLED) && - !(port->rs485.flags & SER_RS485_RX_DURING_TX)) || - port->iso7816.flags & SER_ISO7816_ENABLED) { + if (atmel_uart_is_half_duplex(port)) { /* DMA done, stop TX, start RX for RS485 */ atmel_start_rx(port); } -- 2.19.1