tty: ar933x_uart: add device tree support and binding documentation
[deliverable/linux.git] / drivers / tty / serial / ar933x_uart.c
index 2d83a45dcc8d060b8160b7da528b6f804ac3a0e8..acd03af7cd52287759a5b06275119f0856325fc0 100644 (file)
@@ -17,6 +17,8 @@
 #include <linux/sysrq.h>
 #include <linux/delay.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
 #include <linux/serial_core.h>
@@ -50,6 +52,11 @@ struct ar933x_uart_port {
        struct clk              *clk;
 };
 
+static inline bool ar933x_uart_console_enabled(void)
+{
+       return config_enabled(CONFIG_SERIAL_AR933X_CONSOLE);
+}
+
 static inline unsigned int ar933x_uart_read(struct ar933x_uart_port *up,
                                            int offset)
 {
@@ -500,8 +507,6 @@ static struct uart_ops ar933x_uart_ops = {
        .verify_port    = ar933x_uart_verify_port,
 };
 
-#ifdef CONFIG_SERIAL_AR933X_CONSOLE
-
 static struct ar933x_uart_port *
 ar933x_console_ports[CONFIG_SERIAL_AR933X_NR_UARTS];
 
@@ -600,25 +605,18 @@ static struct console ar933x_uart_console = {
 
 static void ar933x_uart_add_console_port(struct ar933x_uart_port *up)
 {
+       if (!ar933x_uart_console_enabled())
+               return;
+
        ar933x_console_ports[up->port.line] = up;
 }
 
-#define AR933X_SERIAL_CONSOLE  (&ar933x_uart_console)
-
-#else
-
-static inline void ar933x_uart_add_console_port(struct ar933x_uart_port *up) {}
-
-#define AR933X_SERIAL_CONSOLE  NULL
-
-#endif /* CONFIG_SERIAL_AR933X_CONSOLE */
-
 static struct uart_driver ar933x_uart_driver = {
        .owner          = THIS_MODULE,
        .driver_name    = DRIVER_NAME,
        .dev_name       = "ttyATH",
        .nr             = CONFIG_SERIAL_AR933X_NR_UARTS,
-       .cons           = AR933X_SERIAL_CONSOLE,
+       .cons           = NULL, /* filled in runtime */
 };
 
 static int ar933x_uart_probe(struct platform_device *pdev)
@@ -627,13 +625,24 @@ static int ar933x_uart_probe(struct platform_device *pdev)
        struct uart_port *port;
        struct resource *mem_res;
        struct resource *irq_res;
+       struct device_node *np;
        unsigned int baud;
        int id;
        int ret;
 
-       id = pdev->id;
-       if (id == -1)
-               id = 0;
+       np = pdev->dev.of_node;
+       if (config_enabled(CONFIG_OF) && np) {
+               id = of_alias_get_id(np, "serial");
+               if (id < 0) {
+                       dev_err(&pdev->dev, "unable to get alias id, err=%d\n",
+                               id);
+                       return id;
+               }
+       } else {
+               id = pdev->id;
+               if (id == -1)
+                       id = 0;
+       }
 
        if (id > CONFIG_SERIAL_AR933X_NR_UARTS)
                return -EINVAL;
@@ -717,12 +726,21 @@ static int ar933x_uart_remove(struct platform_device *pdev)
        return 0;
 }
 
+#ifdef CONFIG_OF
+static const struct of_device_id ar933x_uart_of_ids[] = {
+       { .compatible = "qca,ar9330-uart" },
+       {},
+};
+MODULE_DEVICE_TABLE(of, ar933x_uart_of_ids);
+#endif
+
 static struct platform_driver ar933x_uart_platform_driver = {
        .probe          = ar933x_uart_probe,
        .remove         = ar933x_uart_remove,
        .driver         = {
                .name           = DRIVER_NAME,
                .owner          = THIS_MODULE,
+               .of_match_table = of_match_ptr(ar933x_uart_of_ids),
        },
 };
 
@@ -730,6 +748,9 @@ static int __init ar933x_uart_init(void)
 {
        int ret;
 
+       if (ar933x_uart_console_enabled())
+               ar933x_uart_driver.cons = &ar933x_uart_console;
+
        ret = uart_register_driver(&ar933x_uart_driver);
        if (ret)
                goto err_out;
This page took 0.02672 seconds and 5 git commands to generate.