Skip to contentSkip to conversation

Raspberry Pi auxiliary UART fixes & cleanups

PATCH In review Lukas Wunner 3 participants 12 messages Jan 16, 2020

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

cover Raspberry Pi auxiliary UART fixes & cleanups

Here's a collection of fixes & cleanups for the Raspberry Pi auxiliary UART to prepare for upcoming feature work on the driver.

With compliments from Revolution Pi labs (https://revolution.kunbus.com/).

Lukas Wunner (5):
serial: 8250_bcm2835aux: Fix line mismatch on driver unbind
serial: 8250_bcm2835aux: Suppress register_port error on -EPROBE_DEFER
serial: 8250_bcm2835aux: Allocate uart_8250_port on stack
serial: 8250_bcm2835aux: Use generic remapping code
serial: 8250_bcm2835aux: Document struct bcm2835aux_data

Phil Elwell (1):
serial: 8250_bcm2835aux: Suppress clk_get error on -EPROBE_DEFER

 drivers/tty/serial/8250/8250_bcm2835aux.c | 50 ++++++++++++-----------
 1 file changed, 26 insertions(+), 24 deletions(-)
Signature · 1 line
2.24.0
#1 lore raw

PATCH 1/6 serial: 8250_bcm2835aux: Fix line mismatch on driver unbind

Unbinding the bcm2835aux UART driver raises the following error if the maximum number of 8250 UARTs is set to 1 (via the 8250.nr_uarts module parameter or CONFIG_SERIAL_8250_RUNTIME_UARTS):

(NULL device *): Removing wrong port: a6f80333 != fa20408b

That's because bcm2835aux_serial_probe() retrieves UART line number 1 from the devicetree and stores it in data->uart.port.line, while serial8250_register_8250_port() instead uses UART line number 0, which is stored in data->line.

On driver unbind, bcm2835aux_serial_remove() uses data->uart.port.line, which contains the wrong number. Fix it.

The issue does not occur if the maximum number of 8250 UARTs is >= 2.

Fixes bdc5f3009580 ("serial: bcm2835: add driver for bcm2835-aux-uart")
Cc Martin Sperl <[email protected]>
---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +1 -1
index 8ce700c1a7fc..4997c519ebb3 100644
@@ -113,7 +113,7 @@ static int bcm2835aux_serial_remove(struct platform_device *pdev)
 {
 	struct bcm2835aux_data *data = platform_get_drvdata(pdev);
 
-	serial8250_unregister_port(data->uart.port.line);
+	serial8250_unregister_port(data->line);
 	clk_disable_unprepare(data->clk);
 
 	return 0;
Signature · 1 line
2.24.0
#2 lore raw

PATCH 2/6 serial: 8250_bcm2835aux: Suppress clk_get error on -EPROBE_DEFER

In reply to Lukas Wunner

From: Phil Elwell <[email protected]>

Suppress a gratuitous error message if devm_clk_get() returns -EPROBE_DEFER.

[lukas: extend commit message]
---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +2 -1
index 4997c519ebb3..33da68341c3a 100644
@@ -50,7 +50,8 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	data->clk = devm_clk_get(&pdev->dev, NULL);
 	ret = PTR_ERR_OR_ZERO(data->clk);
 	if (ret) {
-		dev_err(&pdev->dev, "could not get clk: %d\n", ret);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "could not get clk: %d\n", ret);
 		return ret;
 	}
 
Signature · 1 line
2.24.0
Reviewed-by on v1 2/6
#3 lore raw

Re: [PATCH 2/6] serial: 8250_bcm2835aux: Suppress clk_get error on -EPROBE_DEFER

Quoted 8 lines · Lukas Wunner

From: Phil Elwell <[email protected]>

Suppress a gratuitous error message if devm_clk_get() returns -EPROBE_DEFER.

[lukas: extend commit message]
Quoted 19 lines
---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +2 -1
index 4997c519ebb3..33da68341c3a 100644
@@ -50,7 +50,8 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	data->clk = devm_clk_get(&pdev->dev, NULL);
 	ret = PTR_ERR_OR_ZERO(data->clk);
 	if (ret) {
-		dev_err(&pdev->dev, "could not get clk: %d\n", ret);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&pdev->dev, "could not get clk: %d\n", ret);
 		return ret;
 	}
 
#4 lore raw

PATCH 3/6 serial: 8250_bcm2835aux: Suppress register_port error on -EPROBE_DEFER

In reply to Lukas Wunner

Suppress a gratuitous error message if serial8250_register_8250_port() returns -EPROBE_DEFER.

---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +3 -2
index 33da68341c3a..fb850d0ad643 100644
@@ -95,8 +95,9 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	/* register the port */
 	ret = serial8250_register_8250_port(&data->uart);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "unable to register 8250 port - %d\n",
-			ret);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&pdev->dev,
+				"unable to register 8250 port - %d\n", ret);
 		goto dis_clk;
 	}
 	data->line = ret;
Signature · 1 line
2.24.0
Reviewed-by on v1 3/6
#5 lore raw

Re: [PATCH 3/6] serial: 8250_bcm2835aux: Suppress register_port error on -EPROBE_DEFER

Quoted 4 lines · Lukas Wunner

Suppress a gratuitous error message if serial8250_register_8250_port() returns -EPROBE_DEFER.

Quoted 21 lines
---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +3 -2
index 33da68341c3a..fb850d0ad643 100644
@@ -95,8 +95,9 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	/* register the port */
 	ret = serial8250_register_8250_port(&data->uart);
 	if (ret < 0) {
-		dev_err(&pdev->dev, "unable to register 8250 port - %d\n",
-			ret);
+		if (ret != -EPROBE_DEFER)
+			dev_err(&pdev->dev,
+				"unable to register 8250 port - %d\n", ret);
 		goto dis_clk;
 	}
 	data->line = ret;
#6 lore raw

PATCH 4/6 serial: 8250_bcm2835aux: Allocate uart_8250_port on stack

In reply to Lukas Wunner

The bcm2835aux UART driver stores a struct uart_8250_port in its private data even though it's only passed once to serial8250_register_8250_port() (which copies all relevant data) and becomes obsolete afterwards. Allocate the struct on the stack instead for simplicity and to conserve memory.

The driver also initializes a spinlock in the struct which is never used. Drop that as well.

---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 33 +++++++++++------------
 1 file changed, 15 insertions(+), 18 deletions(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +15 -18
index fb850d0ad643..f03d38e7c3a7 100644
@@ -17,13 +17,13 @@
 #include "8250.h"
 
 struct bcm2835aux_data {
-	struct uart_8250_port uart;
 	struct clk *clk;
 	int line;
 };
 
 static int bcm2835aux_serial_probe(struct platform_device *pdev)
 {
+	struct uart_8250_port up = { };
 	struct bcm2835aux_data *data;
 	struct resource *res;
 	int ret;
@@ -34,17 +34,14 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	/* initialize data */
-	spin_lock_init(&data->uart.port.lock);
-	data->uart.capabilities = UART_CAP_FIFO | UART_CAP_MINI;
-	data->uart.port.dev = &pdev->dev;
-	data->uart.port.regshift = 2;
-	data->uart.port.type = PORT_16550;
-	data->uart.port.iotype = UPIO_MEM;
-	data->uart.port.fifosize = 8;
-	data->uart.port.flags = UPF_SHARE_IRQ |
-				UPF_FIXED_PORT |
-				UPF_FIXED_TYPE |
-				UPF_SKIP_TEST;
+	up.capabilities = UART_CAP_FIFO | UART_CAP_MINI;
+	up.port.dev = &pdev->dev;
+	up.port.regshift = 2;
+	up.port.type = PORT_16550;
+	up.port.iotype = UPIO_MEM;
+	up.port.fifosize = 8;
+	up.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT | UPF_FIXED_TYPE |
+			UPF_SKIP_TEST;
 
 	/* get the clock - this also enables the HW */
 	data->clk = devm_clk_get(&pdev->dev, NULL);
@@ -59,7 +56,7 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	ret = platform_get_irq(pdev, 0);
 	if (ret < 0)
 		return ret;
-	data->uart.port.irq = ret;
+	up.port.irq = ret;
 
 	/* map the main registers */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -67,15 +64,15 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "memory resource not found");
 		return -EINVAL;
 	}
-	data->uart.port.membase = devm_ioremap_resource(&pdev->dev, res);
-	ret = PTR_ERR_OR_ZERO(data->uart.port.membase);
+	up.port.membase = devm_ioremap_resource(&pdev->dev, res);
+	ret = PTR_ERR_OR_ZERO(up.port.membase);
 	if (ret)
 		return ret;
 
 	/* Check for a fixed line number */
 	ret = of_alias_get_id(pdev->dev.of_node, "serial");
 	if (ret >= 0)
-		data->uart.port.line = ret;
+		up.port.line = ret;
 
 	/* enable the clock as a last step */
 	ret = clk_prepare_enable(data->clk);
@@ -90,10 +87,10 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	 * so we have to multiply the actual clock by 2
 	 * to get identical baudrates.
 	 */
-	data->uart.port.uartclk = clk_get_rate(data->clk) * 2;
+	up.port.uartclk = clk_get_rate(data->clk) * 2;
 
 	/* register the port */
-	ret = serial8250_register_8250_port(&data->uart);
+	ret = serial8250_register_8250_port(&up);
 	if (ret < 0) {
 		if (ret != -EPROBE_DEFER)
 			dev_err(&pdev->dev,
Signature · 1 line
2.24.0
Reviewed-by on v1 4/6
#7 lore raw

Re: [PATCH 4/6] serial: 8250_bcm2835aux: Allocate uart_8250_port on stack

Quoted 11 lines · Lukas Wunner

The bcm2835aux UART driver stores a struct uart_8250_port in its private data even though it's only passed once to serial8250_register_8250_port() (which copies all relevant data) and becomes obsolete afterwards. Allocate the struct on the stack instead for simplicity and to conserve memory.

The driver also initializes a spinlock in the struct which is never used. Drop that as well.

Quoted 91 lines
---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 33 +++++++++++------------
 1 file changed, 15 insertions(+), 18 deletions(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +15 -18
index fb850d0ad643..f03d38e7c3a7 100644
@@ -17,13 +17,13 @@
 #include "8250.h"
 
 struct bcm2835aux_data {
-	struct uart_8250_port uart;
 	struct clk *clk;
 	int line;
 };
 
 static int bcm2835aux_serial_probe(struct platform_device *pdev)
 {
+	struct uart_8250_port up = { };
 	struct bcm2835aux_data *data;
 	struct resource *res;
 	int ret;
@@ -34,17 +34,14 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 		return -ENOMEM;
 
 	/* initialize data */
-	spin_lock_init(&data->uart.port.lock);
-	data->uart.capabilities = UART_CAP_FIFO | UART_CAP_MINI;
-	data->uart.port.dev = &pdev->dev;
-	data->uart.port.regshift = 2;
-	data->uart.port.type = PORT_16550;
-	data->uart.port.iotype = UPIO_MEM;
-	data->uart.port.fifosize = 8;
-	data->uart.port.flags = UPF_SHARE_IRQ |
-				UPF_FIXED_PORT |
-				UPF_FIXED_TYPE |
-				UPF_SKIP_TEST;
+	up.capabilities = UART_CAP_FIFO | UART_CAP_MINI;
+	up.port.dev = &pdev->dev;
+	up.port.regshift = 2;
+	up.port.type = PORT_16550;
+	up.port.iotype = UPIO_MEM;
+	up.port.fifosize = 8;
+	up.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT | UPF_FIXED_TYPE |
+			UPF_SKIP_TEST;
 
 	/* get the clock - this also enables the HW */
 	data->clk = devm_clk_get(&pdev->dev, NULL);
@@ -59,7 +56,7 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	ret = platform_get_irq(pdev, 0);
 	if (ret < 0)
 		return ret;
-	data->uart.port.irq = ret;
+	up.port.irq = ret;
 
 	/* map the main registers */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -67,15 +64,15 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "memory resource not found");
 		return -EINVAL;
 	}
-	data->uart.port.membase = devm_ioremap_resource(&pdev->dev, res);
-	ret = PTR_ERR_OR_ZERO(data->uart.port.membase);
+	up.port.membase = devm_ioremap_resource(&pdev->dev, res);
+	ret = PTR_ERR_OR_ZERO(up.port.membase);
 	if (ret)
 		return ret;
 
 	/* Check for a fixed line number */
 	ret = of_alias_get_id(pdev->dev.of_node, "serial");
 	if (ret >= 0)
-		data->uart.port.line = ret;
+		up.port.line = ret;
 
 	/* enable the clock as a last step */
 	ret = clk_prepare_enable(data->clk);
@@ -90,10 +87,10 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	 * so we have to multiply the actual clock by 2
 	 * to get identical baudrates.
 	 */
-	data->uart.port.uartclk = clk_get_rate(data->clk) * 2;
+	up.port.uartclk = clk_get_rate(data->clk) * 2;
 
 	/* register the port */
-	ret = serial8250_register_8250_port(&data->uart);
+	ret = serial8250_register_8250_port(&up);
 	if (ret < 0) {
 		if (ret != -EPROBE_DEFER)
 			dev_err(&pdev->dev,
#8 lore raw

PATCH 5/6 serial: 8250_bcm2835aux: Use generic remapping code

In reply to Lukas Wunner

On probe the bcm2835aux UART driver misreports the register base address as 0x0:

ttyS0 at MMIO 0x0 (irq = 53, base_baud = 50000000) is a 16550

That's because the driver remaps the registers itself. Take advantage of the generic remapping code in serial8250_request_std_resource() to get a message with the correct address and to simplify the driver.

---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +3 -5
index f03d38e7c3a7..d21460c9ef4b 100644
@@ -41,7 +41,7 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 	up.port.iotype = UPIO_MEM;
 	up.port.fifosize = 8;
 	up.port.flags = UPF_SHARE_IRQ | UPF_FIXED_PORT | UPF_FIXED_TYPE |
-			UPF_SKIP_TEST;
+			UPF_SKIP_TEST | UPF_IOREMAP;
 
 	/* get the clock - this also enables the HW */
 	data->clk = devm_clk_get(&pdev->dev, NULL);
@@ -64,10 +64,8 @@ static int bcm2835aux_serial_probe(struct platform_device *pdev)
 		dev_err(&pdev->dev, "memory resource not found");
 		return -EINVAL;
 	}
-	up.port.membase = devm_ioremap_resource(&pdev->dev, res);
-	ret = PTR_ERR_OR_ZERO(up.port.membase);
-	if (ret)
-		return ret;
+	up.port.mapbase = res->start;
+	up.port.mapsize = resource_size(res);
 
 	/* Check for a fixed line number */
 	ret = of_alias_get_id(pdev->dev.of_node, "serial");
Signature · 1 line
2.24.0
#9 lore raw

PATCH 6/6 serial: 8250_bcm2835aux: Document struct bcm2835aux_data

In reply to Lukas Wunner

Document the driver private data of the BCM2835 auxiliary UART so that upcoming commits may add further members with proper kerneldoc.

---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/tty/serial/8250/8250_bcm2835aux.c +5 -0
index d21460c9ef4b..e70e3cc30050 100644
@@ -16,6 +16,11 @@
 
 #include "8250.h"
 
+/**
+ * struct bcm2835aux_data - driver private data of BCM2835 auxiliary UART
+ * @clk: clock producer of the port's uartclk
+ * @line: index of the port's serial8250_ports[] entry
+ */
 struct bcm2835aux_data {
 	struct clk *clk;
 	int line;
Signature · 1 line
2.24.0
Reviewed-by on v1 6/6
#10 lore raw

Re: [PATCH 6/6] serial: 8250_bcm2835aux: Document struct bcm2835aux_data

Quoted 4 lines · Lukas Wunner

Document the driver private data of the BCM2835 auxiliary UART so that upcoming commits may add further members with proper kerneldoc.

Quoted 21 lines
---
 drivers/tty/serial/8250/8250_bcm2835aux.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/tty/serial/8250/8250_bcm2835aux.c +5 -0
index d21460c9ef4b..e70e3cc30050 100644
@@ -16,6 +16,11 @@
 
 #include "8250.h"
 
+/**
+ * struct bcm2835aux_data - driver private data of BCM2835 auxiliary UART
+ * @clk: clock producer of the port's uartclk
+ * @line: index of the port's serial8250_ports[] entry
+ */
 struct bcm2835aux_data {
 	struct clk *clk;
 	int line;
Reviewed-by Tested-by on the v1 series
#11 lore raw
In reply to Lukas Wunner

Hi Lukas,

Quoted 12 lines · Lukas Wunner

Here's a collection of fixes & cleanups for the Raspberry Pi auxiliary UART to prepare for upcoming feature work on the driver.

With compliments from Revolution Pi labs (https://revolution.kunbus.com/).

Lukas Wunner (5):
serial: 8250_bcm2835aux: Fix line mismatch on driver unbind
serial: 8250_bcm2835aux: Suppress register_port error on -EPROBE_DEFER
serial: 8250_bcm2835aux: Allocate uart_8250_port on stack
serial: 8250_bcm2835aux: Use generic remapping code
serial: 8250_bcm2835aux: Document struct bcm2835aux_data

Quoted 6 lines

Phil Elwell (1):
serial: 8250_bcm2835aux: Suppress clk_get error on -EPROBE_DEFER

 drivers/tty/serial/8250/8250_bcm2835aux.c | 50 ++++++++++++-----------
 1 file changed, 26 insertions(+), 24 deletions(-)

Thanks!
Nicolas