Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp7786121ybl; Thu, 16 Jan 2020 05:39:32 -0800 (PST) X-Google-Smtp-Source: APXvYqzlyKYKNRBPtQo5dpuA/arULShuZipMdmmWsx3SSdxB29H1PJ9gcvViXRiugjDFAifelg99 X-Received: by 2002:a05:6830:1f13:: with SMTP id u19mr1846788otg.237.1579181971901; Thu, 16 Jan 2020 05:39:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579181971; cv=none; d=google.com; s=arc-20160816; b=IIUlT4xCkEpGyN/rEkjDpaVCAIIcCxeA2iD9cxfBKxAoEivxE/h2EU6fWUd17wLh1+ ZO1FK1yDGtbMGKn5JmkCfnMcfXybOWbr7HBo06R0jSnmEeUhCi2qHMqT7BfFziN0iQNY 1/AG3B9s2Skb+3/IGXX8tq8S/3gp1q0n+BP9ViHT9zRIKTBcybgYIYgCLyLBuksb1jAK lUYUCz74BFG0CD41eJaskqift33ULWyiiwmXQBCIOMdyT/rZmkepZcs/iKczAVTm6q1N m04SguPtvvh7NMoDUI8Uh8sgXqJQzNjHyuMzhagqQUYfHKrT7ky/2W7NAAePI0Q6Pzol eqkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=mNAqf4f9pDpdGm7/Hbek6B9rTRngT3FlPbncnDLXHh0=; b=ObyBBTqWDdkVqz5eK247IbxKBGSyyGmbO/mLe9WtQvg778e95mb66RcS68IVC9WN3A GfnTsQmgNyXXztmd0kkhPrZQdkBYhJatIpmuVZ4ekyPFEEfQov8BzjTOp9zvtWF7l721 1QXnD4iDG5JleeEnGu0V/DU2jJLqMFmherxmsQECzAUjc8sc0ZeoNmatxQbA7zcKNhRF 0dmQHunJbRyHLVDLHamc7wEmyULnk59uU0hFCr5pFd4zpOvqQcKFcGGgTd+3+9VT9Yv5 lJnWn+w9kwB46PEVQRdg4XfrkZtWDnAYZv3sv9bbsr9Xb6M8g5D56AmyTor4O04xYaws C6jQ== 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 t16si13194010otp.257.2020.01.16.05.39.19; Thu, 16 Jan 2020 05:39:31 -0800 (PST) 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 S1728897AbgAPNiS (ORCPT + 99 others); Thu, 16 Jan 2020 08:38:18 -0500 Received: from bmailout3.hostsharing.net ([176.9.242.62]:38819 "EHLO bmailout3.hostsharing.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727040AbgAPNiS (ORCPT ); Thu, 16 Jan 2020 08:38:18 -0500 X-Greylist: delayed 501 seconds by postgrey-1.27 at vger.kernel.org; Thu, 16 Jan 2020 08:38:17 EST Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "*.hostsharing.net", Issuer "COMODO RSA Domain Validation Secure Server CA" (not verified)) by bmailout3.hostsharing.net (Postfix) with ESMTPS id 040CA100BE781; Thu, 16 Jan 2020 14:29:55 +0100 (CET) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 99C9DDFE15; Thu, 16 Jan 2020 14:29:54 +0100 (CET) Date: Thu, 16 Jan 2020 14:29:54 +0100 From: Lukas Wunner To: Ivan Sistik Cc: Russell King , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Eric Anholt , Stefan Wahren , Greg Kroah-Hartman , Jiri Slaby , linux-arm-kernel@lists.infradead.org, linux-rpi-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, Nicolas Saenz Julienne Subject: Re: [PATCH] tty: serial: amba-pl011: added RS485 support Message-ID: <20200116132954.5tcxmezs5qhseiem@wunner.de> References: <20200106235203.27256-1-sistik@3ksolutions.sk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200106235203.27256-1-sistik@3ksolutions.sk> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 07, 2020 at 12:52:03AM +0100, Ivan Sistik wrote: > AMBA PL011 do not have hardware support for RS485. This implementation is > for drive enable signal (DE), which switch direction of RS485 driver chip. So I've implemented rs485 support for amba-pl011.c two years ago but the patches need a little more polishing before they can be upstreamed and I haven't gotten around to that yet. I apologize that it meant you had to reinvent the wheel. You can find my implementation on this branch: https://github.com/RevolutionPi/linux/commits/revpi-4.19 Specifically this commit: https://github.com/RevolutionPi/linux/commit/0099313962a5 You've used hrtimers in case delays are necessary after assertion or before deassertion of RTS. Note that 8250_port.c already contains code for that. If one wants to go that route, it would probably be best to move that code into serial_core.c to make it available to non-8250 ports. I took a completely different approach: I converted amba-pl011.c to threaded interrupt handling using two kthreads, one for sending, one for receiving. This allows simultaneous writing to and reading from the FIFO. The driver keeps track of the FIFO fill level, which allows writing to the FIFO blindly. The hardirq handler updates the fill level counter and wakes either of the IRQ threads. Once the driver was converted to threaded interrupts, it became possible to sleep in the IRQ handler, so I just used msleep() for the RTS delays. The above-linked branch also has rs485 console support for amba-pl011.c as well as for the auxiliary UART on the Raspberry Pi. > There is missing FIFO empty interrupt in PL011. It is replaced by second > hrtimer which is started if there are no more data in port transmit buffer. The tty layer lets you know when there's nothing more to transmit by calling the ->stop_tx() hook. Then you just busy-wait for the FIFO to empty before you deassert RTS. Another idea would be to set TXIFLSEL (TX interrupt FIFO level select) in the UARTIFLS register to the lowest possible setting. Then you'll get an interrupt when the TX FIFO only contains 2 bytes (on a PL011 with 16 byte FIFOs), thus minimizing the busy-wait duration. Thanks, Lukas