Skip to content

Commit 4d47228

Browse files
author
Da Xue
committed
meson-uart: add tx and rx invert
1 parent 8038769 commit 4d47228

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

drivers/tty/serial/meson_uart.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,13 @@
4040
#define AML_UART_TX_RST BIT(22)
4141
#define AML_UART_RX_RST BIT(23)
4242
#define AML_UART_CLEAR_ERR BIT(24)
43+
#define AML_UART_RX_INV BIT(25)
44+
#define AML_UART_TX_INV BIT(26)
4345
#define AML_UART_RX_INT_EN BIT(27)
4446
#define AML_UART_TX_INT_EN BIT(28)
47+
#define AML_UART_CTS_INV BIT(29)
48+
#define AML_UART_ERR_MASK BIT(30)
49+
#define AML_UART_RTS_INV BIT(31)
4550
#define AML_UART_DATA_LEN_MASK (0x03 << 20)
4651
#define AML_UART_DATA_LEN_8BIT (0x00 << 20)
4752
#define AML_UART_DATA_LEN_7BIT (0x01 << 20)
@@ -95,6 +100,30 @@ static unsigned int meson_uart_get_mctrl(struct uart_port *port)
95100
return TIOCM_CTS;
96101
}
97102

103+
static void meson_uart_set_rx_invert(struct uart_port *port, bool invert_rx)
104+
{
105+
u32 val;
106+
107+
val = readl(port->membase + AML_UART_CONTROL);
108+
if (invert_rx)
109+
val |= AML_UART_RX_INV;
110+
else
111+
val &= ~AML_UART_RX_INV;
112+
writel(val, port->membase + AML_UART_CONTROL);
113+
}
114+
115+
static void meson_uart_set_tx_invert(struct uart_port *port, bool invert_tx)
116+
{
117+
u32 val;
118+
119+
val = readl(port->membase + AML_UART_CONTROL);
120+
if (invert_tx)
121+
val |= AML_UART_TX_INV;
122+
else
123+
val &= ~AML_UART_TX_INV;
124+
writel(val, port->membase + AML_UART_CONTROL);
125+
}
126+
98127
static unsigned int meson_uart_tx_empty(struct uart_port *port)
99128
{
100129
u32 val;
@@ -710,6 +739,7 @@ static int meson_uart_probe(struct platform_device *pdev)
710739
int ret = 0;
711740
int irq;
712741
bool has_rtscts;
742+
bool invert_rx, invert_tx, invert_cts, invert_rts;
713743

714744
if (pdev->dev.of_node)
715745
pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
@@ -739,6 +769,11 @@ static int meson_uart_probe(struct platform_device *pdev)
739769
of_property_read_u32(pdev->dev.of_node, "fifo-size", &fifosize);
740770
has_rtscts = of_property_read_bool(pdev->dev.of_node, "uart-has-rtscts");
741771

772+
invert_rx = of_property_read_bool(pdev->dev.of_node, "uart-invert-rx");
773+
invert_tx = of_property_read_bool(pdev->dev.of_node, "uart-invert-tx");
774+
invert_cts = of_property_read_bool(pdev->dev.of_node, "uart-invert-cts");
775+
invert_rts = of_property_read_bool(pdev->dev.of_node, "uart-invert-rts");
776+
742777
if (meson_ports[pdev->id]) {
743778
return dev_err_probe(&pdev->dev, -EBUSY,
744779
"port %d already allocated\n", pdev->id);
@@ -792,6 +827,9 @@ static int meson_uart_probe(struct platform_device *pdev)
792827
if (ret)
793828
meson_ports[pdev->id] = NULL;
794829

830+
meson_uart_set_rx_invert(port, invert_rx);
831+
meson_uart_set_tx_invert(port, invert_tx);
832+
795833
return ret;
796834
}
797835

0 commit comments

Comments
 (0)