Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1370867img; Tue, 19 Mar 2019 06:21:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqxoLf2QqK7tBPmPlQNPzLd6vxS8/DQeUP8N/3LUowlWP299Qr0cMenMwgOApf2hblJmkXqQ X-Received: by 2002:a63:ed0a:: with SMTP id d10mr1833397pgi.452.1553001692715; Tue, 19 Mar 2019 06:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553001692; cv=none; d=google.com; s=arc-20160816; b=ju40MJChVZGC8uBN++3He8fIQshX/Hjw1UK/hHXpAdw0yZyJq8QWeJcYJT5fW0vwOX 2en7K9ow8lmn6UVsBJUqMl+mLCOn6le4EqOYLdOqShfT7kt6OMfV7yGXOo+YmljMRaRv XimrIfkr5DjQ9sa+Vkv/b62gym0ofF4mCnuqUKDY+a9/UkLPREuWi1CSrdY2N0w+bWEN IR7awESZvulWki2Q9l0Ap1iU18NY6sDIpsZvVXExjC/qT/4AqP+saDQzfdSl9UTD/4OL JzYWEOa1anfwisdfKR12njhorWdfLLhjDcdOO5nk45W3TQ+jJR0VVncKmuwSM5/UBeqO waCQ== 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 :message-id:date:subject:cc:to:from; bh=tGx+uqf/BfkAHMU5MWJRKai6g8h2MVoUl6WJxm9L3Bc=; b=oOQDg3Dw2XTo7rS8aziY5YtPjRk0MJ0PFYw12FJbxor3AhkudEzbssayw4tl6eCYOx 8W2eoJAjUzEo8+qehMIRFtEk02K94cQ9jnwHLR4cUTGDUaVtInt5zQ7VlF3HrEaBXTO8 KyVzOP2dujXwRaLKU5ECvQn6Z42QsMnf5JVcevvefG7jGcEaysb4mT8r8XFeFeFBLmEm X1UN0biCCUS+ucVdwUjjHYVO9mqYPm9baM+G299897FepLDVnzjYatprgIi701/1RW/T dGkNqgyZUakp1pm8vRMsFJ6o1Q6Pzu4NZ1Gw0V75zgvNf2saVtGciHwbNiNByo04k/k/ D0Yg== 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 o188si11437318pga.297.2019.03.19.06.21.16; Tue, 19 Mar 2019 06:21:32 -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 S1727018AbfCSNUh (ORCPT + 99 others); Tue, 19 Mar 2019 09:20:37 -0400 Received: from esa2.microchip.iphmx.com ([68.232.149.84]:32635 "EHLO esa2.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726007AbfCSNUh (ORCPT ); Tue, 19 Mar 2019 09:20:37 -0400 X-IronPort-AV: E=Sophos;i="5.58,498,1544511600"; d="scan'208";a="28347284" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa2.microchip.iphmx.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 19 Mar 2019 06:20:36 -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:36 -0700 From: Razvan Stefanescu To: Richard Genoud , Greg Kroah-Hartman , Jiri Slaby CC: Gil Weber , Nicolas Ferre , Alexandre Belloni , Ludovic Desroches , , , Subject: [PATCH v2 0/2] tty/serial: atmel: Fix RS485 half duplex operation Date: Tue, 19 Mar 2019 15:20:33 +0200 Message-ID: <20190319132035.18481-1-razvan.stefanescu@microchip.com> X-Mailer: git-send-email 2.19.1 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 Using a loopback serial cable with RS485 protocol shows that data is received: $ stty -F /dev/ttyS3 raw -echo speed 4800 $ cat /dev/ttyS3 & $ echo "Hello, world" > /dev/ttyS3 Hello, world Last line should not be displayed, as it indicates that RX was started before TX finished. This happens because driver activates RX when the DMA transfer completes, but that does not necessarily mean the TX FIFO was emptied. First patch will add a helper that checks if the transmission is half-duplex and uses it throughout the driver, replacing multiple lines of code. Second patch implements the fix by adding a variable to the port struct. This is used to indicate that RX needs to be started. When the DMA transfer completes, the variable is set and the ATMEL_US_TXEMPTY is reactivated. In the interrupt handler, if the variable is set, RX is started. Changelog: v1 -> v2: - remove wrongly added check; - start rx and display warning message in case of error - add fix info Razvan Stefanescu (2): tty/serial: atmel: Add is_half_duplex helper tty/serial: atmel: RS485 HD w/DMA: enable RX after TX is stopped drivers/tty/serial/atmel_serial.c | 48 +++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 15 deletions(-) -- 2.19.1