All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: Jiri Slaby <jirislaby@kernel.org>
Cc: Lino Sanfilippo <LinoSanfilippo@gmx.de>,
	linux@armlinux.org.uk, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] serial: amba-pl011: add RS485 support
Date: Wed, 16 Jun 2021 08:29:14 +0200	[thread overview]
Message-ID: <YMmaOn8tEl7PcOE8@kroah.com> (raw)
In-Reply-To: <5f00ff43-9287-4027-7d80-474da957703c@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 <LinoSanfilippo@gmx.de>
> > ---
> > 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

  reply	other threads:[~2021-06-16  6:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-10 13:50 [PATCH] serial: amba-pl011: add RS485 support Lino Sanfilippo
2021-06-16  6:18 ` Jiri Slaby
2021-06-16  6:29   ` Greg KH [this message]
2021-06-17 16:12   ` Lino Sanfilippo
2021-06-17 17:44   ` Lino Sanfilippo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YMmaOn8tEl7PcOE8@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=LinoSanfilippo@gmx.de \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.