Skip to contentSkip to conversation

serial: 8250_mtk: Add ACPI support

PATCH In review Yenchia Chen 2 participants 2 messages Jan 24, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 serial: 8250_mtk: Add ACPI support

Add ACPI support to 8250_mtk driver. This makes it possible to use UART on ARM-based desktops with EDK2 UEFI firmware.

---
 drivers/tty/serial/8250/8250_mtk.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
drivers/tty/serial/8250/8250_mtk.c +18 -3
index b44de2ed7413..d06952081191 100644
@@ -5,6 +5,7 @@
  * Copyright (c) 2014 MundoReader S.L.
  * Author: Matthias Brugger <[email protected]>
  */
+#include <linux/acpi.h>
 #include <linux/clk.h>
 #include <linux/io.h>
 #include <linux/module.h>
@@ -15,6 +16,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/serial_8250.h>
 #include <linux/serial_reg.h>
+#include <linux/units.h>
 #include <linux/console.h>
 #include <linux/dma-mapping.h>
 #include <linux/tty.h>
@@ -519,6 +521,7 @@ static int mtk8250_probe(struct platform_device *pdev)
 	struct mtk8250_data *data;
 	struct resource *regs;
 	int irq, err;
+	acpi_handle acpi_dev_handle = ACPI_HANDLE(&pdev->dev);
 
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
@@ -545,8 +548,9 @@ static int mtk8250_probe(struct platform_device *pdev)
 		err = mtk8250_probe_of(pdev, &uart.port, data);
 		if (err)
 			return err;
-	} else
+	} else if (!acpi_dev_handle) {
 		return -ENODEV;
+	}
 
 	spin_lock_init(&uart.port.lock);
 	uart.port.mapbase = regs->start;
@@ -562,14 +566,18 @@ static int mtk8250_probe(struct platform_device *pdev)
 	uart.port.startup = mtk8250_startup;
 	uart.port.set_termios = mtk8250_set_termios;
 	uart.port.uartclk = clk_get_rate(data->uart_clk);
+	if (!uart.port.uartclk)
+		uart.port.uartclk = 26 * HZ_PER_MHZ;
 #ifdef CONFIG_SERIAL_8250_DMA
 	if (data->dma)
 		uart.dma = data->dma;
 #endif
 
-	/* Disable Rate Fix function */
-	writel(0x0, uart.port.membase +
+	if (!acpi_dev_handle) {
+		/* Disable Rate Fix function */
+		writel(0x0, uart.port.membase +
 			(MTK_UART_RATE_FIX << uart.port.regshift));
+	}
 
 	platform_set_drvdata(pdev, data);
 
@@ -647,11 +655,18 @@ static const struct of_device_id mtk8250_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, mtk8250_of_match);
 
+static const struct acpi_device_id mtk8250_acpi_match[] = {
+	{ "MTKI0511", 0 },
+	{},
+};
+MODULE_DEVICE_TABLE(acpi, mtk8250_acpi_match);
+
 static struct platform_driver mtk8250_platform_driver = {
 	.driver = {
 		.name		= "mt6577-uart",
 		.pm		= &mtk8250_pm_ops,
 		.of_match_table	= mtk8250_of_match,
+		.acpi_match_table = mtk8250_acpi_match,
 	},
 	.probe			= mtk8250_probe,
 	.remove			= mtk8250_remove,
Signature · 1 line
2.45.2
#1 lore raw
Quoted 2 lines · Yenchia Chen

Add ACPI support to 8250_mtk driver. This makes it possible to use UART on ARM-based desktops with EDK2 UEFI firmware.

...

Quoted 1 line

+#include <linux/acpi.h>

This will not be needed (see below)

drivers/tty/serial/8250/8250_mtk.c line 20

Quoted 9 lines

#include <linux/clk.h>
#include <linux/io.h>
#include <linux/module.h>

drivers/tty/serial/8250/8250_mtk.c +1 -0
@@ -15,6 +16,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/serial_8250.h>
 #include <linux/serial_reg.h>
 
+#include <linux/units.h>

This might not be needed either (see below)

Quoted 3 lines
drivers/tty/serial/8250/8250_mtk.c +0 -0
 #include <linux/console.h>
 #include <linux/dma-mapping.h>

#include <linux/tty.h>

You probably want to sort header inclusions first for easier maintenance and feature additions like this one.

Can you add that one?

...

drivers/tty/serial/8250/8250_mtk.c static int mtk8250_probe(struct platform_device *pdev)

Quoted 3 lines
drivers/tty/serial/8250/8250_mtk.c +2 -0
+	} else if (!acpi_dev_handle) {
 
+	}

This should look like

	struct fwnode_handle *fwnode = dev_fwnode(&pdev->dev);
	...
	if (is_of_node(fwnode)) {
		...parse OF...
	} else if (!fwnode) {
		return -ENODEV;
	}

...

drivers/tty/serial/8250/8250_mtk.c static int mtk8250_probe(struct platform_device *pdev) · line 570

Quoted 3 lines
drivers/tty/serial/8250/8250_mtk.c +2 -0
 	uart.port.uartclk = clk_get_rate(data->uart_clk);
+	if (!uart.port.uartclk)
+		uart.port.uartclk = 26 * HZ_PER_MHZ;

Why doesn't your table provide the clock-frequency property?

What I expect to see is the use of uart_read_port_properties().

...

drivers/tty/serial/8250/8250_mtk.c static int mtk8250_probe(struct platform_device *pdev) · line 574

Quoted 4 lines

#ifdef CONFIG_SERIAL_8250_DMA

drivers/tty/serial/8250/8250_mtk.c +0 -0
 	if (data->dma)
 		uart.dma = data->dma;
 #endif

Btw, how do you handle DMA in ACPI case?

...

drivers/tty/serial/8250/8250_mtk.c static int mtk8250_probe(struct platform_device *pdev) · line 580

Quoted 7 lines
drivers/tty/serial/8250/8250_mtk.c +4 -2
-	/* Disable Rate Fix function */
-	writel(0x0, uart.port.membase +
+	if (!acpi_dev_handle) {
+		/* Disable Rate Fix function */
+		writel(0x0, uart.port.membase +
 			(MTK_UART_RATE_FIX << uart.port.regshift));
+	}
	if (is_of_node()) {
		...
	}

...

drivers/tty/serial/8250/8250_mtk.c static const struct of_device_id mtk8250_of_match[] = { · line 659

Quoted 2 lines
drivers/tty/serial/8250/8250_mtk.c +2 -0
+static const struct acpi_device_id mtk8250_acpi_match[] = {
+	{ "MTKI0511", 0 },

No ', 0' part, please.

drivers/tty/serial/8250/8250_mtk.c static const struct of_device_id mtk8250_of_match[] = { · line 660

Quoted 1 line
drivers/tty/serial/8250/8250_mtk.c +1 -0
+	{},

No comma in the terminator line.

Quoted 1 line

+};

Signature · 2 lines
With Best Regards,
Andy Shevchenko