Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp185794pxj; Tue, 15 Jun 2021 23:31:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7xcZiCGgan/xOE//JnHXcqlW0Hi+D0+56OXx8CIlyAtyZmNd9a82fnxzHv/P94+wOxm6z X-Received: by 2002:a02:a587:: with SMTP id b7mr2664800jam.13.1623825095921; Tue, 15 Jun 2021 23:31:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623825095; cv=none; d=google.com; s=arc-20160816; b=B9RPfOdVu6OUqzEgsBdjGaol2fXS2XWaldT3DtYDJLyqauG4V8jvflrXMA/T9kvi4f NNLMsQKmsYxDF9CE1EZ4eMk1WzNysumeVW/XsSjl0J0qx9ISa0iVH45XEkFa14fpt4gh 0K00JhHqLZcNjadgqTicgkKgvwdbd32290vje3FwVTU2jO+W69W1sHn+eiKk0yl8gMvG 7CsRi6fpDuFXZyJwnB8vsJbxklQUsqJWezm1aq5ciKOTRR1APzUClJKI6O6btlHxyJu0 vNEeeaHPyeTLI87nzP2oJt4lumve/QikCcaA04zhwxyDBw8sCljrGBPQb0x2ulWf6up8 1UOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZJOEjHK5XoIJnfV4xNdpwWQcgWlp3L4RCBSrfQPszNM=; b=yvswW85M9J9+2Dwu5RK3WQHe5YNilQZPBwcCRhIW35fSxx4U4lKgDn3cukedI4RGT6 Lh4xyIMbpKzSENKWVXDHHaw0EuA3T2Vw5YEoXRHzzvud/b35M6GSUFaW1cagzUVLHQ0L tzMke6CESNz5cgsCAppyYFSPMhoHbCpuXc28MxGsTvvuEREpItNmZFbXbNnIbJaq4/P6 yx0eA3kyhTqCBIvJECO03Zd9lvgH6oNT4l4HVpnn9cmRQV2BvpNUpcEPsqnzJzHFyyPN aYZnOdhcWPNNaHKPRPPgqER6S88o9pJ+iiXBICaAGQEpvVdaKgR+5aJ5nvjFqE28U4TW YaEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=z6ey7M1J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w2si1221232iop.49.2021.06.15.23.31.24; Tue, 15 Jun 2021 23:31:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=z6ey7M1J; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231772AbhFPGcF (ORCPT + 99 others); Wed, 16 Jun 2021 02:32:05 -0400 Received: from mail.kernel.org ([198.145.29.99]:44034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231636AbhFPGbX (ORCPT ); Wed, 16 Jun 2021 02:31:23 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 256A9613C2; Wed, 16 Jun 2021 06:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623824957; bh=iS6BFCJPTZwDFmA1LAvtf4xTLCYj46S1LYq86CwMQgQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=z6ey7M1JJAdr2bV7sJVS0ZxM3acoGW6GJ+do5F5Nh+FKTTDgQqkJcll4SF040mvPw wyolF4Du+mA1eoVpdsFA6xi0GOV/emk4a7dyjf1gbu7ljVVR49qjHm/5PY4Cdxi9Dm wgmLeA39Xa2x2g1LhJrOObdSUTPpquF6tUp/V8ak= Date: Wed, 16 Jun 2021 08:29:14 +0200 From: Greg KH To: Jiri Slaby Cc: Lino Sanfilippo , linux@armlinux.org.uk, linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] serial: amba-pl011: add RS485 support Message-ID: References: <20210610135004.7585-1-LinoSanfilippo@gmx.de> <5f00ff43-9287-4027-7d80-474da957703c@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5f00ff43-9287-4027-7d80-474da957703c@kernel.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 16, 2021 at 08:18:01AM +0200, Jiri Slaby wrote: > On 10. 06. 21, 15:50, Lino Sanfilippo wrote: > > Add basic support for RS485: Provide a callback to configure rs485 > > settings. Handle the RS485 specific part in the functions > > pl011_rs485_tx_start() and pl011_rs485_tx_stop() which extend the generic > > start/stop callbacks. > > Beside via IOCTL from userspace RS485 can be enabled by means of the > > device tree property "rs485-enabled-at-boot-time". > > > > Signed-off-by: Lino Sanfilippo > > --- > > This patch has been tested with a Raspberry Pi CM3. > > > > drivers/tty/serial/amba-pl011.c | 143 +++++++++++++++++++++++++++++++- > > 1 file changed, 140 insertions(+), 3 deletions(-) > > > > diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c > > index 78682c12156a..36e8b938cdba 100644 > > --- a/drivers/tty/serial/amba-pl011.c > > +++ b/drivers/tty/serial/amba-pl011.c > ... > > @@ -1380,6 +1415,31 @@ static bool pl011_tx_char(struct uart_amba_port *uap, unsigned char c, > > return true; > > } > > +static void pl011_rs485_tx_start(struct uart_amba_port *uap) > > +{ > > + struct uart_port *port = &uap->port; > > + u32 cr; > > + > > + /* Enable transmitter */ > > + cr = pl011_read(uap, REG_CR); > > + cr |= UART011_CR_TXE; > > + /* Disable receiver if half-duplex */ > > + if (!(port->rs485.flags & SER_RS485_RX_DURING_TX)) > > + cr &= ~UART011_CR_RXE; > > + > > + if (port->rs485.flags & SER_RS485_RTS_ON_SEND) > > + cr &= ~UART011_CR_RTS; > > + else > > + cr |= UART011_CR_RTS; > > + > > + pl011_write(cr, uap, REG_CR); > > + > > + if (port->rs485.delay_rts_before_send) > > + mdelay(port->rs485.delay_rts_before_send); > > This is up to 1 second delay with interrupts disabled. Definitely not nice. > 8250 clamps this to 100 ms at least, why did you choose 1000 ms? > > > + > > + uap->rs485_tx_started = true; > > +} > > + > > /* Returns true if tx interrupts have to be (kept) enabled */ > > static bool pl011_tx_chars(struct uart_amba_port *uap, bool from_irq) > > { > ... > > @@ -1941,6 +2021,7 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios, > > unsigned int lcr_h, old_cr; > > unsigned long flags; > > unsigned int baud, quot, clkdiv; > > + unsigned int bits; > > if (uap->vendor->oversampling) > > clkdiv = 8; > > @@ -1968,25 +2049,32 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios, > > switch (termios->c_cflag & CSIZE) { > > case CS5: > > lcr_h = UART01x_LCRH_WLEN_5; > > + bits = 7; > > break; > > case CS6: > > lcr_h = UART01x_LCRH_WLEN_6; > > + bits = 8; > > break; > > case CS7: > > lcr_h = UART01x_LCRH_WLEN_7; > > + bits = 9; > > break; > > default: // CS8 > > lcr_h = UART01x_LCRH_WLEN_8; > > + bits = 10; > > break; > > } > > - if (termios->c_cflag & CSTOPB) > > + if (termios->c_cflag & CSTOPB) { > > lcr_h |= UART01x_LCRH_STP2; > > + bits++; > > + } > > if (termios->c_cflag & PARENB) { > > lcr_h |= UART01x_LCRH_PEN; > > if (!(termios->c_cflag & PARODD)) > > lcr_h |= UART01x_LCRH_EPS; > > if (termios->c_cflag & CMSPAR) > > lcr_h |= UART011_LCRH_SPS; > > + bits++; > > } > > You can do simply: > bits = tty_get_frame_size(termios->c_cflag); > now: > https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git/commit/?h=tty-testing&id=3ec2ff37230e1c961d4b0d0118dd23c46b5bcdbb I was wondering about that. I'll go drop this patch from my tty-next branch and wait for a new version that fixes the above delay issue and it can use this new call as well. thanks, greg k-h