Received: by 2002:ac0:a874:0:0:0:0:0 with SMTP id c49csp269185ima; Fri, 15 Mar 2019 02:24:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqy8l2wrZMyN28keNQNyda6qw5ouitmShod+1gt8Lf62usDtf+dklYRye4IWPonL6q4OHTEm X-Received: by 2002:a62:be02:: with SMTP id l2mr2996337pff.55.1552641872122; Fri, 15 Mar 2019 02:24:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552641872; cv=none; d=google.com; s=arc-20160816; b=Y8RzejMx0QyLumlduAg2rn4OSvzvftoNo8q6HIGBUXOvBaYXo3399H4mYCI3HbfPZT R9+oLal0NEyroqzx21i4EwSSQTWqAtDp8i8sufpUBfjWNVKBGqhjLRoKqBO6dykgTY/i +12I933I+AEa8AexZ5BrmIHfrI02BcyKrzb81wm/P/IWaByPFJqYVG7EHMrRgoPxEIeE X3wX525woVQ/c9dSyNHqDsLnHducjrS+LGPt861i4zn8ykxS1wJS1vszK9KxZ51jBqdZ QUnvgRssX3yDf3jre+HOEllYLG/9ELYXIgtp2TRIwVbZeeVXvBQd2G40AshoQLklI8OE 1Aew== 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=8HWI0DRcbo6ed9c4HyfLL3ajHfYgT5FcWSC0ny48Vfw=; b=j7B6fp+JYaehPGyWFBKDswTW52v9m2KDuD3vTDdp80dFx2XpjJG9wBQjw6w+ES/Hc6 1R9rt8aP/JvsuLtkKtQ2w38z5xiXvhSw2/tEEiS/pDgnBffg9GVcfeSO7bp4/M7K9okY pYQ+AureGE4OD2g4ecX5Bcd4QJ2zbzP8rTfa1X38v8IKzCq2iNLE4Mt7WB14J+36/uIZ hMghUOZxafz4WW23WGX5ggd7NDHA/FoKR4AhUruLzHaGLYhEQlZ+ewTvDQW7vmdShEFU 9MhJ7B7kjQyv8BsaileEntwDEqu0cMOAc6WNVInKkyod9uyY6uSTzuHcbY+5P/PRTIBe RqTA== 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 f6si1463413pfn.108.2019.03.15.02.24.17; Fri, 15 Mar 2019 02:24: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 S1728630AbfCOJXj (ORCPT + 99 others); Fri, 15 Mar 2019 05:23:39 -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 S1726886AbfCOJXj (ORCPT ); Fri, 15 Mar 2019 05:23:39 -0400 X-IronPort-AV: E=Sophos;i="5.58,481,1544511600"; d="scan'208";a="25412861" 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:38 -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:37 -0700 From: Razvan Stefanescu To: Richard Genoud , Greg Kroah-Hartman , Jiri Slaby CC: Nicolas Ferre , Alexandre Belloni , Ludovic Desroches , , , Subject: [PATCH 0/2] tty/serial: atmel: Fix RS485 half duplex operation Date: Fri, 15 Mar 2019 11:23:32 +0200 Message-ID: <20190315092334.13246-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. 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 | 52 +++++++++++++++++++++---------- 1 file changed, 36 insertions(+), 16 deletions(-) -- 2.19.1