Skip to content

Commit 687911b

Browse files
11matt556gregkh
authored andcommitted
serial: exar: Add RS-485 support for Sealevel XR17V35X based cards
Sealevel XR17V35X based cards utilize DTR to control RS-485 Enable, but the current implementation of 8250_exar uses RTS for the auto-RS485-Enable mode of the XR17V35X UARTs. This patch implements DTR Auto-RS485 on Sealevel cards. Signed-off-by: Matthew Howell <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 6c756af commit 687911b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

drivers/tty/serial/8250/8250_exar.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@
7777

7878
#define UART_EXAR_RS485_DLY(x) ((x) << 4)
7979

80+
#define UART_EXAR_DLD 0x02 /* Divisor Fractional */
81+
#define UART_EXAR_DLD_485_POLARITY 0x80 /* RS-485 Enable Signal Polarity */
82+
8083
/*
8184
* IOT2040 MPIO wiring semantics:
8285
*
@@ -438,6 +441,44 @@ static int generic_rs485_config(struct uart_port *port, struct ktermios *termios
438441
return 0;
439442
}
440443

444+
static int sealevel_rs485_config(struct uart_port *port, struct ktermios *termios,
445+
struct serial_rs485 *rs485)
446+
{
447+
u8 __iomem *p = port->membase;
448+
u8 old_lcr;
449+
u8 efr;
450+
u8 dld;
451+
int ret;
452+
453+
ret = generic_rs485_config(port, termios, rs485);
454+
if (ret)
455+
return ret;
456+
457+
if (rs485->flags & SER_RS485_ENABLED) {
458+
old_lcr = readb(p + UART_LCR);
459+
460+
/* Set EFR[4]=1 to enable enhanced feature registers */
461+
efr = readb(p + UART_XR_EFR);
462+
efr |= UART_EFR_ECB;
463+
writeb(efr, p + UART_XR_EFR);
464+
465+
/* Set MCR to use DTR as Auto-RS485 Enable signal */
466+
writeb(UART_MCR_OUT1, p + UART_MCR);
467+
468+
/* Set LCR[7]=1 to enable access to DLD register */
469+
writeb(old_lcr | UART_LCR_DLAB, p + UART_LCR);
470+
471+
/* Set DLD[7]=1 for inverted RS485 Enable logic */
472+
dld = readb(p + UART_EXAR_DLD);
473+
dld |= UART_EXAR_DLD_485_POLARITY;
474+
writeb(dld, p + UART_EXAR_DLD);
475+
476+
writeb(old_lcr, p + UART_LCR);
477+
}
478+
479+
return 0;
480+
}
481+
441482
static const struct serial_rs485 generic_rs485_supported = {
442483
.flags = SER_RS485_ENABLED,
443484
};
@@ -559,6 +600,9 @@ pci_xr17v35x_setup(struct exar8250 *priv, struct pci_dev *pcidev,
559600
port->port.rs485_config = platform->rs485_config;
560601
port->port.rs485_supported = *(platform->rs485_supported);
561602

603+
if (pcidev->subsystem_vendor == PCI_VENDOR_ID_SEALEVEL)
604+
port->port.rs485_config = sealevel_rs485_config;
605+
562606
/*
563607
* Setup the UART clock for the devices on expansion slot to
564608
* half the clock speed of the main chip (which is 125MHz)

0 commit comments

Comments
 (0)