linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: serial: meson: if no alias specified use an available id
@ 2019-01-14 16:54 Loys Ollivier
  2019-01-15  9:35 ` Neil Armstrong
  0 siblings, 1 reply; 2+ messages in thread
From: Loys Ollivier @ 2019-01-14 16:54 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby, Kevin Hilman
  Cc: Loys Ollivier, linux-serial, linux-arm-kernel, linux-amlogic,
	linux-kernel

At probe, the uart driver tries to get an id from a device tree alias.
When no alias was specified, the driver would return an error and probing
would fail.

Providing an alias for registering a serial device should not be mandatory.
If the device tree does not specify an alias, provide an id from a reserved
range so that the probing can continue.

Signed-off-by: Loys Ollivier <lollivier@baylibre.com>
---
 drivers/tty/serial/meson_uart.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c
index 8a842591b37c..fbc5bc022a39 100644
--- a/drivers/tty/serial/meson_uart.c
+++ b/drivers/tty/serial/meson_uart.c
@@ -72,7 +72,8 @@
 #define AML_UART_BAUD_USE		BIT(23)
 #define AML_UART_BAUD_XTAL		BIT(24)
 
-#define AML_UART_PORT_NUM		6
+#define AML_UART_PORT_NUM		12
+#define AML_UART_PORT_OFFSET		6
 #define AML_UART_DEV_NAME		"ttyAML"
 
 
@@ -654,10 +655,20 @@ static int meson_uart_probe(struct platform_device *pdev)
 	struct resource *res_mem, *res_irq;
 	struct uart_port *port;
 	int ret = 0;
+	int id = -1;
 
 	if (pdev->dev.of_node)
 		pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
 
+	if (pdev->id < 0) {
+		for (id = AML_UART_PORT_OFFSET; id < AML_UART_PORT_NUM; id++) {
+			if (!meson_ports[id]) {
+				pdev->id = id;
+				break;
+			}
+		}
+	}
+
 	if (pdev->id < 0 || pdev->id >= AML_UART_PORT_NUM)
 		return -EINVAL;
 
-- 
2.7.4


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

* Re: [PATCH] tty: serial: meson: if no alias specified use an available id
  2019-01-14 16:54 [PATCH] tty: serial: meson: if no alias specified use an available id Loys Ollivier
@ 2019-01-15  9:35 ` Neil Armstrong
  0 siblings, 0 replies; 2+ messages in thread
From: Neil Armstrong @ 2019-01-15  9:35 UTC (permalink / raw)
  To: Loys Ollivier, Greg Kroah-Hartman, Jiri Slaby, Kevin Hilman
  Cc: linux-amlogic, linux-arm-kernel, linux-serial, linux-kernel

On 14/01/2019 17:54, Loys Ollivier wrote:
> At probe, the uart driver tries to get an id from a device tree alias.
> When no alias was specified, the driver would return an error and probing
> would fail.
> 
> Providing an alias for registering a serial device should not be mandatory.
> If the device tree does not specify an alias, provide an id from a reserved
> range so that the probing can continue.
> 
> Signed-off-by: Loys Ollivier <lollivier@baylibre.com>
> ---
>  drivers/tty/serial/meson_uart.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/tty/serial/meson_uart.c b/drivers/tty/serial/meson_uart.c
> index 8a842591b37c..fbc5bc022a39 100644
> --- a/drivers/tty/serial/meson_uart.c
> +++ b/drivers/tty/serial/meson_uart.c
> @@ -72,7 +72,8 @@
>  #define AML_UART_BAUD_USE		BIT(23)
>  #define AML_UART_BAUD_XTAL		BIT(24)
>  
> -#define AML_UART_PORT_NUM		6
> +#define AML_UART_PORT_NUM		12
> +#define AML_UART_PORT_OFFSET		6
>  #define AML_UART_DEV_NAME		"ttyAML"
>  
>  
> @@ -654,10 +655,20 @@ static int meson_uart_probe(struct platform_device *pdev)
>  	struct resource *res_mem, *res_irq;
>  	struct uart_port *port;
>  	int ret = 0;
> +	int id = -1;
>  
>  	if (pdev->dev.of_node)
>  		pdev->id = of_alias_get_id(pdev->dev.of_node, "serial");
>  
> +	if (pdev->id < 0) {
> +		for (id = AML_UART_PORT_OFFSET; id < AML_UART_PORT_NUM; id++) {
> +			if (!meson_ports[id]) {
> +				pdev->id = id;
> +				break;
> +			}
> +		}
> +	}
> +
>  	if (pdev->id < 0 || pdev->id >= AML_UART_PORT_NUM)
>  		return -EINVAL;
>  
> 

This is welcome !

You could also add:
Suggested-by: Rob Herring <robh@kernel.org>

Reviewed-by: Neil Armstrong <narmstrong@baylibre.com>

Neil

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

end of thread, other threads:[~2019-01-15  9:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-14 16:54 [PATCH] tty: serial: meson: if no alias specified use an available id Loys Ollivier
2019-01-15  9:35 ` Neil Armstrong

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).