Re: [PATCH 1/4] serial: 8250_dw: add em485 support
From: Andy Shevchenko
Date: Wed Jun 06 2018 - 12:51:57 EST
On Wed, Jun 6, 2018 at 12:51 PM, Giulio Benetti
<giulio.benetti@xxxxxxxxxxxxxxxx> wrote:
> Need to use rs485 transceiver so let's use existing em485 485 emulation
> layer on top of 8250.
>
> Add rs485_config callback to port.
Besides the fact the series lacks of cover letter, I think it should
be postponed until we get a clear understanding how RS485 is supposed
to be initialized and what exact problems you are trying to address.
>
> Signed-off-by: Giulio Benetti <giulio.benetti@xxxxxxxxxxxxxxxx>
> ---
> drivers/tty/serial/8250/8250_dw.c | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c
> index 6fcdb90f616a..45366e6e5411 100644
> --- a/drivers/tty/serial/8250/8250_dw.c
> +++ b/drivers/tty/serial/8250/8250_dw.c
> @@ -314,6 +314,36 @@ static void dw8250_set_ldisc(struct uart_port *p, struct ktermios *termios)
> serial8250_do_set_ldisc(p, termios);
> }
>
> +static int dw8250_rs485_config(struct uart_port *p,
> + struct serial_rs485 *rs485)
> +{
> + struct uart_8250_port *up = up_to_u8250p(p);
> +
> + /* Clamp the delays to [0, 100ms] */
> + rs485->delay_rts_before_send = min(rs485->delay_rts_before_send, 100U);
> + rs485->delay_rts_after_send = min(rs485->delay_rts_after_send, 100U);
> +
> + p->rs485 = *rs485;
> +
> + /*
> + * Both serial8250_em485_init and serial8250_em485_destroy
> + * are idempotent
> + */
> + if (rs485->flags & SER_RS485_ENABLED) {
> + int ret = serial8250_em485_init(up);
> +
> + if (ret) {
> + rs485->flags &= ~SER_RS485_ENABLED;
> + p->rs485.flags &= ~SER_RS485_ENABLED;
> + }
> + return ret;
> + }
> +
> + serial8250_em485_destroy(up);
> +
> + return 0;
> +}
> +
> /*
> * dw8250_fallback_dma_filter will prevent the UART from getting just any free
> * channel on platforms that have DMA engines, but don't have any channels
> @@ -449,6 +479,7 @@ static int dw8250_probe(struct platform_device *pdev)
> p->serial_out = dw8250_serial_out;
> p->set_ldisc = dw8250_set_ldisc;
> p->set_termios = dw8250_set_termios;
> + p->rs485_config = dw8250_rs485_config;
>
> p->membase = devm_ioremap(dev, regs->start, resource_size(regs));
> if (!p->membase)
> --
> 2.17.1
>
--
With Best Regards,
Andy Shevchenko