Raspberry Pi auxiliary UART fixes & cleanups
Subsystems (3)
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
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.
--- drivers/tty/serial/8250/8250_bcm2835aux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +1 -1
@@ -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
PATCH 2/6 serial: 8250_bcm2835aux: Suppress clk_get error on -EPROBE_DEFER
In reply to Lukas WunnerFrom: Phil Elwell <[email protected]>
Suppress a gratuitous error message if devm_clk_get() returns -EPROBE_DEFER.
--- drivers/tty/serial/8250/8250_bcm2835aux.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/tty/serial/8250/8250_bcm2835aux.c +2 -1
@@ -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
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.Signed-off-by Phil Elwell <[email protected]>[lukas: extend commit message]Signed-off-by Lukas Wunner <[email protected]>
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@@ -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; }
PATCH 3/6 serial: 8250_bcm2835aux: Suppress register_port error on -EPROBE_DEFER
In reply to Lukas WunnerSuppress 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
@@ -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
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.Signed-off-by Lukas Wunner <[email protected]>
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@@ -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;
PATCH 4/6 serial: 8250_bcm2835aux: Allocate uart_8250_port on stack
In reply to Lukas WunnerThe 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
@@ -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
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_portin its private data even though it's only passed once toserial8250_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.
Signed-off-by Lukas Wunner <[email protected]>Cc Martin Sperl <[email protected]>
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@@ -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,
PATCH 5/6 serial: 8250_bcm2835aux: Use generic remapping code
In reply to Lukas WunnerOn 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
@@ -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
PATCH 6/6 serial: 8250_bcm2835aux: Document struct bcm2835aux_data
In reply to Lukas WunnerDocument 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
@@ -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
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.
Signed-off-by Lukas Wunner <[email protected]>
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@@ -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;
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: Suppressregister_porterror on -EPROBE_DEFER
serial: 8250_bcm2835aux: Allocateuart_8250_porton stack
serial: 8250_bcm2835aux: Use generic remapping code
serial: 8250_bcm2835aux: Document structbcm2835aux_data
Quoted 6 lines
Phil Elwell (1):
serial: 8250_bcm2835aux: Suppressclk_geterror on -EPROBE_DEFERdrivers/tty/serial/8250/8250_bcm2835aux.c | 50 ++++++++++++----------- 1 file changed, 26 insertions(+), 24 deletions(-)
Thanks!
Nicolas