Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp269226ima; Fri, 15 Mar 2019 02:24:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqx/QeFnrCFjn+B3DEAH/j3YteqklAPKZhIDCi0ByeoWYReE6Vld9p07ZxgUqRVAPpFnGR58 X-Received: by 2002:a17:902:8d89:: with SMTP id v9mr3190843plo.254.1552641876553; Fri, 15 Mar 2019 02:24:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552641876; cv=none; d=google.com; s=arc-20160816; b=xgZ7h1qoqHyfoZpLVnqckyQzwTHCjjoepbXAYNmdvu1EhDviJ6nqauIQvZmaumA/Mq N4zV+WSLpl5zW36sKK4tKCgF+IZHQgC6qOxNn7AtgoeHPpOnfrnZ4LoiHPaLr1V6lS2s i5xLsiSIVDNTQYH68BiUEhoSQNajE9XMLFYHRJWDBcUIr0Ko5WsgoD99tSNAYvpvokw7 eyw7FJyHOt7nGufuDtx8A6jEpSbav9FwHIm5WrPAw/4fmQnNr07I5DmPN0rvTzHtmRJp fDj9v+UkhGuJkv1hacLRa5IucovmBVprlRU9599+2dLw/VUWyBN8uZM4VDZDC1MxRoDw ZWbw== 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=wkoH1J3ZCpdD8Xqq/RaGlPKFM2muZA0vGBPoXwzTJPg=; b=CEiPwioCYdCJj7SpHOFWdmE9ekh300pudMh00+GFk2ADrIPTqrefp2uJbT7CgUMvmp AvylFrI13V7yzJoGmKwcYCaFxtKdaZc/mh090LQp45sCcLZY9PxGO7WeBh/EZxKGW2Qc m8MiOaPGysPIaYL2K+VJlcHM29yVwLCvUSVVSR3AJRPAy+MZzkgZJ5pk5Iyy174HZPCk bbIhW5bQmFhJ+vpN4O0thZ29ejdmE5tR4hG3dd3oRJ7MZECvTbIyZDHfqcGYJnwbtg3K 80FT4cENhKaFjW1AUzLtj4uKkcbjmJCnNEl/Er8OHNNbziRmDE8zdTb6Pbk3H29M3bpK SksQ== 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 h18si1388318pgg.71.2019.03.15.02.24.21; Fri, 15 Mar 2019 02:24: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 S1728676AbfCOJXn (ORCPT + 99 others); Fri, 15 Mar 2019 05:23:43 -0400 Received: from esa6.microchip.iphmx.com ([216.71.154.253]:45822 "EHLO esa6.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726886AbfCOJXm (ORCPT ); Fri, 15 Mar 2019 05:23:42 -0400 X-IronPort-AV: E=Sophos;i="5.58,481,1544511600"; d="scan'208";a="25412863" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa6.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 15 Mar 2019 02:23:41 -0700 Received: from rob-ult-m50855.microchip.com (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.352.0; Fri, 15 Mar 2019 02:23:40 -0700 From: Razvan Stefanescu To: Richard Genoud , Greg Kroah-Hartman , Jiri Slaby CC: Nicolas Ferre , Alexandre Belloni , Ludovic Desroches , , , Subject: [PATCH 1/2] tty/serial: atmel: Add is_half_duplex helper Date: Fri, 15 Mar 2019 11:23:33 +0200 Message-ID: <20190315092334.13246-2-razvan.stefanescu@microchip.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190315092334.13246-1-razvan.stefanescu@microchip.com> References: <20190315092334.13246-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. Signed-off-by: Razvan Stefanescu --- drivers/tty/serial/atmel_serial.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/drivers/tty/serial/atmel_serial.c b/drivers/tty/serial/atmel_serial.c index 05147fe24343..a6577b1c4461 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,10 @@ 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) - atmel_start_rx(port); + if (atmel_uart_is_half_duplex(port)) + if (!atomic_read(&atmel_port->tasklet_shutdown)) + atmel_start_rx(port); + } /* @@ -628,9 +635,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 +933,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 +1511,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