serial: 8250_dw: add em485 support

A patch from »serial: 8250: Add rs485 emulation to 8250_dw« in state Mainline for linux-kernel

From: Giulio Benetti <giulio.benetti@...> Date: Wed, 6 Jun 2018 11:51:54 +0200

Commit-Message

Need to use rs485 transceiver so let's use existing em485 485 emulation layer on top of 8250. Add rs485_config callback to port. Signed-off-by: Giulio Benetti <giulio.benetti@...> Signed-off-by: Heiko Stuebner <heiko.stuebner@...>

Patch-Comment

drivers/tty/serial/8250/8250_dw.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)

Statistics

  • 31 lines added
  • 0 lines removed

Changes

---------------------- drivers/tty/serial/8250/8250_dw.c -----------------------
index 1c72fdc2dd37..7023b656658d 100644
@@ -320,6 +320,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, false);
+
+ 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
@@ -417,6 +447,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)
 
 

Recent Patches

About Us

Sed lacus. Donec lectus. Nullam pretium nibh ut turpis. Nam bibendum. In nulla tortor, elementum vel, tempor at, varius non, purus. Mauris vitae nisl nec metus placerat consectetuer.

Read More...