mirror of https://gitee.com/openkylin/linux.git
tty: serial: lpuart: Add RS485 support for 32-bit uart flavour
This commits adds RS485 support for LPUART hardware that uses 32-bit registers. These are typically found in i.MX8 processors. Signed-off-by: Philippe Schenker <philippe.schenker@toradex.com> Reviewed-by: Fugang Duan <fugang.duan@nxp.com> Link: https://lore.kernel.org/r/20191017141428.10330-3-philippe.schenker@toradex.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
e3553fee81
commit
67b0183786
|
@ -1280,6 +1280,57 @@ static int lpuart_config_rs485(struct uart_port *port,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int lpuart32_config_rs485(struct uart_port *port,
|
||||||
|
struct serial_rs485 *rs485)
|
||||||
|
{
|
||||||
|
struct lpuart_port *sport = container_of(port,
|
||||||
|
struct lpuart_port, port);
|
||||||
|
|
||||||
|
unsigned long modem = lpuart32_read(&sport->port, UARTMODIR)
|
||||||
|
& ~(UARTMODEM_TXRTSPOL | UARTMODEM_TXRTSE);
|
||||||
|
lpuart32_write(&sport->port, modem, UARTMODIR);
|
||||||
|
|
||||||
|
/* clear unsupported configurations */
|
||||||
|
rs485->delay_rts_before_send = 0;
|
||||||
|
rs485->delay_rts_after_send = 0;
|
||||||
|
rs485->flags &= ~SER_RS485_RX_DURING_TX;
|
||||||
|
|
||||||
|
if (rs485->flags & SER_RS485_ENABLED) {
|
||||||
|
/* Enable auto RS-485 RTS mode */
|
||||||
|
modem |= UARTMODEM_TXRTSE;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RTS needs to be logic HIGH either during transer _or_ after
|
||||||
|
* transfer, other variants are not supported by the hardware.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if (!(rs485->flags & (SER_RS485_RTS_ON_SEND |
|
||||||
|
SER_RS485_RTS_AFTER_SEND)))
|
||||||
|
rs485->flags |= SER_RS485_RTS_ON_SEND;
|
||||||
|
|
||||||
|
if (rs485->flags & SER_RS485_RTS_ON_SEND &&
|
||||||
|
rs485->flags & SER_RS485_RTS_AFTER_SEND)
|
||||||
|
rs485->flags &= ~SER_RS485_RTS_AFTER_SEND;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The hardware defaults to RTS logic HIGH while transfer.
|
||||||
|
* Switch polarity in case RTS shall be logic HIGH
|
||||||
|
* after transfer.
|
||||||
|
* Note: UART is assumed to be active high.
|
||||||
|
*/
|
||||||
|
if (rs485->flags & SER_RS485_RTS_ON_SEND)
|
||||||
|
modem &= ~UARTMODEM_TXRTSPOL;
|
||||||
|
else if (rs485->flags & SER_RS485_RTS_AFTER_SEND)
|
||||||
|
modem |= UARTMODEM_TXRTSPOL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Store the new configuration */
|
||||||
|
sport->port.rs485 = *rs485;
|
||||||
|
|
||||||
|
lpuart32_write(&sport->port, modem, UARTMODIR);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned int lpuart_get_mctrl(struct uart_port *port)
|
static unsigned int lpuart_get_mctrl(struct uart_port *port)
|
||||||
{
|
{
|
||||||
unsigned int temp = 0;
|
unsigned int temp = 0;
|
||||||
|
@ -1878,6 +1929,13 @@ lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
|
||||||
ctrl |= UARTCTRL_M;
|
ctrl |= UARTCTRL_M;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When auto RS-485 RTS mode is enabled,
|
||||||
|
* hardware flow control need to be disabled.
|
||||||
|
*/
|
||||||
|
if (sport->port.rs485.flags & SER_RS485_ENABLED)
|
||||||
|
termios->c_cflag &= ~CRTSCTS;
|
||||||
|
|
||||||
if (termios->c_cflag & CRTSCTS) {
|
if (termios->c_cflag & CRTSCTS) {
|
||||||
modem |= (UARTMODIR_RXRTSE | UARTMODIR_TXCTSE);
|
modem |= (UARTMODIR_RXRTSE | UARTMODIR_TXCTSE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -2405,7 +2463,10 @@ static int lpuart_probe(struct platform_device *pdev)
|
||||||
sport->port.ops = &lpuart_pops;
|
sport->port.ops = &lpuart_pops;
|
||||||
sport->port.flags = UPF_BOOT_AUTOCONF;
|
sport->port.flags = UPF_BOOT_AUTOCONF;
|
||||||
|
|
||||||
sport->port.rs485_config = lpuart_config_rs485;
|
if (lpuart_is_32(sport))
|
||||||
|
sport->port.rs485_config = lpuart32_config_rs485;
|
||||||
|
else
|
||||||
|
sport->port.rs485_config = lpuart_config_rs485;
|
||||||
|
|
||||||
sport->ipg_clk = devm_clk_get(&pdev->dev, "ipg");
|
sport->ipg_clk = devm_clk_get(&pdev->dev, "ipg");
|
||||||
if (IS_ERR(sport->ipg_clk)) {
|
if (IS_ERR(sport->ipg_clk)) {
|
||||||
|
@ -2459,7 +2520,7 @@ static int lpuart_probe(struct platform_device *pdev)
|
||||||
sport->port.rs485.delay_rts_after_send)
|
sport->port.rs485.delay_rts_after_send)
|
||||||
dev_err(&pdev->dev, "driver doesn't support RTS delays\n");
|
dev_err(&pdev->dev, "driver doesn't support RTS delays\n");
|
||||||
|
|
||||||
lpuart_config_rs485(&sport->port, &sport->port.rs485);
|
sport->port.rs485_config(&sport->port, &sport->port.rs485);
|
||||||
|
|
||||||
sport->dma_tx_chan = dma_request_slave_channel(sport->port.dev, "tx");
|
sport->dma_tx_chan = dma_request_slave_channel(sport->port.dev, "tx");
|
||||||
if (!sport->dma_tx_chan)
|
if (!sport->dma_tx_chan)
|
||||||
|
|
Loading…
Reference in New Issue