linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] MediaTek 8250 UART: fixes and improvements
@ 2022-04-27 13:23 AngeloGioacchino Del Regno
  2022-04-27 13:23 ` [PATCH 1/3] serial: 8250_mtk: Fix UART_EFR register address AngeloGioacchino Del Regno
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-04-27 13:23 UTC (permalink / raw)
  To: gregkh
  Cc: jirislaby, matthias.bgg, angelogioacchino.delregno, zhiyong.tao,
	colin.king, linux-serial, linux-arm-kernel, linux-mediatek,
	linux-kernel

Even though the UART IP on MTK platforms is 16550A compatible, some
registers are not at a "standard" offset. In order to allow full
functionality of the flow control features and to make Linux able
to fully and properly reconfigure the UART IP, eventually allowing
communication at high speed after a full IP reset, some register
offset fixes have been done.
While at it, even though this bit is always set, also paranoidly
make sure that the "new register map" feature is enabled, as that's
done with just one writel() at probe time, introducing no overhead.

This has been tested on multiple Chromebooks featuring different
SoCs, and a MT6795 Xperia M5 smartphone.

AngeloGioacchino Del Regno (3):
  serial: 8250_mtk: Fix UART_EFR register address
  serial: 8250_mtk: Make sure to select the right FEATURE_SEL
  serial: 8250_mtk: Fix register address for XON/XOFF character

 drivers/tty/serial/8250/8250_mtk.c | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

-- 
2.35.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/3] serial: 8250_mtk: Fix UART_EFR register address
  2022-04-27 13:23 [PATCH 0/3] MediaTek 8250 UART: fixes and improvements AngeloGioacchino Del Regno
@ 2022-04-27 13:23 ` AngeloGioacchino Del Regno
  2022-04-27 13:23 ` [PATCH 2/3] serial: 8250_mtk: Make sure to select the right FEATURE_SEL AngeloGioacchino Del Regno
  2022-04-27 13:23 ` [PATCH 3/3] serial: 8250_mtk: Fix register address for XON/XOFF character AngeloGioacchino Del Regno
  2 siblings, 0 replies; 4+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-04-27 13:23 UTC (permalink / raw)
  To: gregkh
  Cc: jirislaby, matthias.bgg, angelogioacchino.delregno, zhiyong.tao,
	colin.king, linux-serial, linux-arm-kernel, linux-mediatek,
	linux-kernel

On MediaTek SoCs, the UART IP is 16550A compatible, but there are some
specific quirks: we are declaring a register shift of 2, but this is
only valid for the majority of the registers, as there are some that
are out of the standard layout.

Specifically, this driver is using definitions from serial_reg.h, where
we have a UART_EFR register defined as 2: this results in a 0x8 offset,
but there we have the FCR register instead.

The right offset for the EFR register on MediaTek UART is at 0x98,
so, following the decimal definition convention in serial_reg.h and
accounting for the register left shift of two, add and use the correct
register address for this IP, defined as decimal 38, so that the final
calculation results in (0x26 << 2) = 0x98.

Fixes: bdbd0a7f8f03 ("serial: 8250-mtk: modify baudrate setting")
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/tty/serial/8250/8250_mtk.c | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c
index f4a0caa56f84..cd62a5f34014 100644
--- a/drivers/tty/serial/8250/8250_mtk.c
+++ b/drivers/tty/serial/8250/8250_mtk.c
@@ -37,6 +37,7 @@
 #define MTK_UART_IER_RTSI	0x40	/* Enable RTS Modem status interrupt */
 #define MTK_UART_IER_CTSI	0x80	/* Enable CTS Modem status interrupt */
 
+#define MTK_UART_EFR		38	/* I/O: Extended Features Register */
 #define MTK_UART_EFR_EN		0x10	/* Enable enhancement feature */
 #define MTK_UART_EFR_RTS	0x40	/* Enable hardware rx flow control */
 #define MTK_UART_EFR_CTS	0x80	/* Enable hardware tx flow control */
@@ -169,7 +170,7 @@ static void mtk8250_dma_enable(struct uart_8250_port *up)
 		   MTK_UART_DMA_EN_RX | MTK_UART_DMA_EN_TX);
 
 	serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
-	serial_out(up, UART_EFR, UART_EFR_ECB);
+	serial_out(up, MTK_UART_EFR, UART_EFR_ECB);
 	serial_out(up, UART_LCR, lcr);
 
 	if (dmaengine_slave_config(dma->rxchan, &dma->rxconf) != 0)
@@ -232,7 +233,7 @@ static void mtk8250_set_flow_ctrl(struct uart_8250_port *up, int mode)
 	int lcr = serial_in(up, UART_LCR);
 
 	serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
-	serial_out(up, UART_EFR, UART_EFR_ECB);
+	serial_out(up, MTK_UART_EFR, UART_EFR_ECB);
 	serial_out(up, UART_LCR, lcr);
 	lcr = serial_in(up, UART_LCR);
 
@@ -241,7 +242,7 @@ static void mtk8250_set_flow_ctrl(struct uart_8250_port *up, int mode)
 		serial_out(up, MTK_UART_ESCAPE_DAT, MTK_UART_ESCAPE_CHAR);
 		serial_out(up, MTK_UART_ESCAPE_EN, 0x00);
 		serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
-		serial_out(up, UART_EFR, serial_in(up, UART_EFR) &
+		serial_out(up, MTK_UART_EFR, serial_in(up, MTK_UART_EFR) &
 			(~(MTK_UART_EFR_HW_FC | MTK_UART_EFR_SW_FC_MASK)));
 		serial_out(up, UART_LCR, lcr);
 		mtk8250_disable_intrs(up, MTK_UART_IER_XOFFI |
@@ -255,8 +256,8 @@ static void mtk8250_set_flow_ctrl(struct uart_8250_port *up, int mode)
 		serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
 
 		/*enable hw flow control*/
-		serial_out(up, UART_EFR, MTK_UART_EFR_HW_FC |
-			(serial_in(up, UART_EFR) &
+		serial_out(up, MTK_UART_EFR, MTK_UART_EFR_HW_FC |
+			(serial_in(up, MTK_UART_EFR) &
 			(~(MTK_UART_EFR_HW_FC | MTK_UART_EFR_SW_FC_MASK))));
 
 		serial_out(up, UART_LCR, lcr);
@@ -270,8 +271,8 @@ static void mtk8250_set_flow_ctrl(struct uart_8250_port *up, int mode)
 		serial_out(up, UART_LCR, UART_LCR_CONF_MODE_B);
 
 		/*enable sw flow control */
-		serial_out(up, UART_EFR, MTK_UART_EFR_XON1_XOFF1 |
-			(serial_in(up, UART_EFR) &
+		serial_out(up, MTK_UART_EFR, MTK_UART_EFR_XON1_XOFF1 |
+			(serial_in(up, MTK_UART_EFR) &
 			(~(MTK_UART_EFR_HW_FC | MTK_UART_EFR_SW_FC_MASK))));
 
 		serial_out(up, UART_XON1, START_CHAR(port->state->port.tty));
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/3] serial: 8250_mtk: Make sure to select the right FEATURE_SEL
  2022-04-27 13:23 [PATCH 0/3] MediaTek 8250 UART: fixes and improvements AngeloGioacchino Del Regno
  2022-04-27 13:23 ` [PATCH 1/3] serial: 8250_mtk: Fix UART_EFR register address AngeloGioacchino Del Regno
@ 2022-04-27 13:23 ` AngeloGioacchino Del Regno
  2022-04-27 13:23 ` [PATCH 3/3] serial: 8250_mtk: Fix register address for XON/XOFF character AngeloGioacchino Del Regno
  2 siblings, 0 replies; 4+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-04-27 13:23 UTC (permalink / raw)
  To: gregkh
  Cc: jirislaby, matthias.bgg, angelogioacchino.delregno, zhiyong.tao,
	colin.king, linux-serial, linux-arm-kernel, linux-mediatek,
	linux-kernel

Set the FEATURE_SEL at probe time to make sure that BIT(0) is enabled:
this guarantees that when the port is configured as AP UART, the
right register layout is interpreted by the UART IP.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/tty/serial/8250/8250_mtk.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c
index cd62a5f34014..28e36459642c 100644
--- a/drivers/tty/serial/8250/8250_mtk.c
+++ b/drivers/tty/serial/8250/8250_mtk.c
@@ -54,6 +54,9 @@
 #define MTK_UART_TX_TRIGGER	1
 #define MTK_UART_RX_TRIGGER	MTK_UART_RX_SIZE
 
+#define MTK_UART_FEATURE_SEL	39	/* Feature Selection register */
+#define MTK_UART_FEAT_NEWRMAP	BIT(0)	/* Use new register map */
+
 #ifdef CONFIG_SERIAL_8250_DMA
 enum dma_rx_status {
 	DMA_RX_START = 0,
@@ -569,6 +572,10 @@ static int mtk8250_probe(struct platform_device *pdev)
 		uart.dma = data->dma;
 #endif
 
+	/* Set AP UART new register map */
+	writel(MTK_UART_FEAT_NEWRMAP, uart.port.membase +
+	       (MTK_UART_FEATURE_SEL << uart.port.regshift));
+
 	/* Disable Rate Fix function */
 	writel(0x0, uart.port.membase +
 			(MTK_UART_RATE_FIX << uart.port.regshift));
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/3] serial: 8250_mtk: Fix register address for XON/XOFF character
  2022-04-27 13:23 [PATCH 0/3] MediaTek 8250 UART: fixes and improvements AngeloGioacchino Del Regno
  2022-04-27 13:23 ` [PATCH 1/3] serial: 8250_mtk: Fix UART_EFR register address AngeloGioacchino Del Regno
  2022-04-27 13:23 ` [PATCH 2/3] serial: 8250_mtk: Make sure to select the right FEATURE_SEL AngeloGioacchino Del Regno
@ 2022-04-27 13:23 ` AngeloGioacchino Del Regno
  2 siblings, 0 replies; 4+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-04-27 13:23 UTC (permalink / raw)
  To: gregkh
  Cc: jirislaby, matthias.bgg, angelogioacchino.delregno, zhiyong.tao,
	colin.king, linux-serial, linux-arm-kernel, linux-mediatek,
	linux-kernel

The XON1/XOFF1 character registers are at offset 0xa0 and 0xa8
respectively, so we cannot use the definition in serial_port.h.

Fixes: bdbd0a7f8f03 ("serial: 8250-mtk: modify baudrate setting")
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/tty/serial/8250/8250_mtk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/8250/8250_mtk.c b/drivers/tty/serial/8250/8250_mtk.c
index 28e36459642c..21053db93ff1 100644
--- a/drivers/tty/serial/8250/8250_mtk.c
+++ b/drivers/tty/serial/8250/8250_mtk.c
@@ -57,6 +57,9 @@
 #define MTK_UART_FEATURE_SEL	39	/* Feature Selection register */
 #define MTK_UART_FEAT_NEWRMAP	BIT(0)	/* Use new register map */
 
+#define MTK_UART_XON1		40	/* I/O: Xon character 1 */
+#define MTK_UART_XOFF1		42	/* I/O: Xoff character 1 */
+
 #ifdef CONFIG_SERIAL_8250_DMA
 enum dma_rx_status {
 	DMA_RX_START = 0,
@@ -278,8 +281,8 @@ static void mtk8250_set_flow_ctrl(struct uart_8250_port *up, int mode)
 			(serial_in(up, MTK_UART_EFR) &
 			(~(MTK_UART_EFR_HW_FC | MTK_UART_EFR_SW_FC_MASK))));
 
-		serial_out(up, UART_XON1, START_CHAR(port->state->port.tty));
-		serial_out(up, UART_XOFF1, STOP_CHAR(port->state->port.tty));
+		serial_out(up, MTK_UART_XON1, START_CHAR(port->state->port.tty));
+		serial_out(up, MTK_UART_XOFF1, STOP_CHAR(port->state->port.tty));
 		serial_out(up, UART_LCR, lcr);
 		mtk8250_disable_intrs(up, MTK_UART_IER_CTSI|MTK_UART_IER_RTSI);
 		mtk8250_enable_intrs(up, MTK_UART_IER_XOFFI);
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-04-27 13:23 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-27 13:23 [PATCH 0/3] MediaTek 8250 UART: fixes and improvements AngeloGioacchino Del Regno
2022-04-27 13:23 ` [PATCH 1/3] serial: 8250_mtk: Fix UART_EFR register address AngeloGioacchino Del Regno
2022-04-27 13:23 ` [PATCH 2/3] serial: 8250_mtk: Make sure to select the right FEATURE_SEL AngeloGioacchino Del Regno
2022-04-27 13:23 ` [PATCH 3/3] serial: 8250_mtk: Fix register address for XON/XOFF character AngeloGioacchino Del Regno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).