Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

tty: ar933x_uart: add device tree support and binding documentation

Modify the probe routine to get the port line number
from device tree if the 'of_node' is populated in the
platform device. The driver can be built as module,
thus add an OF specific module device table as well
to support module auto loading.

This makes it possible to use the driver for AR9330
UART devices specified in device tree.

Cc: devicetree@vger.kernel.org
Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Gabor Juhos and committed by
Greg Kroah-Hartman
dd910d98 284301ef

+59 -3
+34
Documentation/devicetree/bindings/tty/serial/qca,ar9330-uart.txt
··· 1 + * Qualcomm Atheros AR9330 High-Speed UART 2 + 3 + Required properties: 4 + 5 + - compatible: Must be "qca,ar9330-uart" 6 + 7 + - reg: Specifies the physical base address of the controller and 8 + the length of the memory mapped region. 9 + 10 + - interrupt-parent: The phandle for the interrupt controller that 11 + services interrupts for this device. 12 + 13 + - interrupts: Specifies the interrupt source of the parent interrupt 14 + controller. The format of the interrupt specifier depends on the 15 + parent interrupt controller. 16 + 17 + Additional requirements: 18 + 19 + Each UART port must have an alias correctly numbered in "aliases" 20 + node. 21 + 22 + Example: 23 + 24 + aliases { 25 + serial0 = &uart0; 26 + }; 27 + 28 + uart0: uart@18020000 { 29 + compatible = "qca,ar9330-uart"; 30 + reg = <0x18020000 0x14>; 31 + 32 + interrupt-parent = <&intc>; 33 + interrupts = <3>; 34 + };
+25 -3
drivers/tty/serial/ar933x_uart.c
··· 17 17 #include <linux/sysrq.h> 18 18 #include <linux/delay.h> 19 19 #include <linux/platform_device.h> 20 + #include <linux/of.h> 21 + #include <linux/of_platform.h> 20 22 #include <linux/tty.h> 21 23 #include <linux/tty_flip.h> 22 24 #include <linux/serial_core.h> ··· 625 623 struct uart_port *port; 626 624 struct resource *mem_res; 627 625 struct resource *irq_res; 626 + struct device_node *np; 628 627 unsigned int baud; 629 628 int id; 630 629 int ret; 631 630 632 - id = pdev->id; 633 - if (id == -1) 634 - id = 0; 631 + np = pdev->dev.of_node; 632 + if (config_enabled(CONFIG_OF) && np) { 633 + id = of_alias_get_id(np, "serial"); 634 + if (id < 0) { 635 + dev_err(&pdev->dev, "unable to get alias id, err=%d\n", 636 + id); 637 + return id; 638 + } 639 + } else { 640 + id = pdev->id; 641 + if (id == -1) 642 + id = 0; 643 + } 635 644 636 645 if (id > CONFIG_SERIAL_AR933X_NR_UARTS) 637 646 return -EINVAL; ··· 726 713 return 0; 727 714 } 728 715 716 + #ifdef CONFIG_OF 717 + static const struct of_device_id ar933x_uart_of_ids[] = { 718 + { .compatible = "qca,ar9330-uart" }, 719 + {}, 720 + }; 721 + MODULE_DEVICE_TABLE(of, ar933x_uart_of_ids); 722 + #endif 723 + 729 724 static struct platform_driver ar933x_uart_platform_driver = { 730 725 .probe = ar933x_uart_probe, 731 726 .remove = ar933x_uart_remove, 732 727 .driver = { 733 728 .name = DRIVER_NAME, 734 729 .owner = THIS_MODULE, 730 + .of_match_table = of_match_ptr(ar933x_uart_of_ids), 735 731 }, 736 732 }; 737 733