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

serial: pxa: add OF support

Parse uart device id from alias in DTS file.

Signed-off-by: Haojian Zhuang <haojian.zhuang@marvell.com>

authored by

Haojian Zhuang and committed by
Haojian Zhuang
699c20f3 192cfd58

+37 -12
+37 -12
drivers/tty/serial/pxa.c
··· 36 36 #include <linux/circ_buf.h> 37 37 #include <linux/delay.h> 38 38 #include <linux/interrupt.h> 39 + #include <linux/of.h> 39 40 #include <linux/platform_device.h> 40 41 #include <linux/tty.h> 41 42 #include <linux/tty_flip.h> ··· 45 44 #include <linux/io.h> 46 45 #include <linux/slab.h> 47 46 47 + #define PXA_NAME_LEN 8 48 + 48 49 struct uart_pxa_port { 49 50 struct uart_port port; 50 51 unsigned char ier; ··· 54 51 unsigned char mcr; 55 52 unsigned int lsr_break_flag; 56 53 struct clk *clk; 57 - char *name; 54 + char name[PXA_NAME_LEN]; 58 55 }; 59 56 60 57 static inline unsigned int serial_in(struct uart_pxa_port *up, int offset) ··· 784 781 }; 785 782 #endif 786 783 784 + static struct of_device_id serial_pxa_dt_ids[] = { 785 + { .compatible = "mrvl,pxa-uart", }, 786 + { .compatible = "mrvl,mmp-uart", }, 787 + {} 788 + }; 789 + MODULE_DEVICE_TABLE(of, serial_pxa_dt_ids); 790 + 791 + static int serial_pxa_probe_dt(struct platform_device *pdev, 792 + struct uart_pxa_port *sport) 793 + { 794 + struct device_node *np = pdev->dev.of_node; 795 + int ret; 796 + 797 + if (!np) 798 + return 1; 799 + 800 + ret = of_alias_get_id(np, "serial"); 801 + if (ret < 0) { 802 + dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret); 803 + return ret; 804 + } 805 + sport->port.line = ret; 806 + return 0; 807 + } 808 + 787 809 static int serial_pxa_probe(struct platform_device *dev) 788 810 { 789 811 struct uart_pxa_port *sport; ··· 836 808 sport->port.irq = irqres->start; 837 809 sport->port.fifosize = 64; 838 810 sport->port.ops = &serial_pxa_pops; 839 - sport->port.line = dev->id; 840 811 sport->port.dev = &dev->dev; 841 812 sport->port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; 842 813 sport->port.uartclk = clk_get_rate(sport->clk); 843 814 844 - switch (dev->id) { 845 - case 0: sport->name = "FFUART"; break; 846 - case 1: sport->name = "BTUART"; break; 847 - case 2: sport->name = "STUART"; break; 848 - case 3: sport->name = "HWUART"; break; 849 - default: 850 - sport->name = "???"; 851 - break; 852 - } 815 + ret = serial_pxa_probe_dt(dev, sport); 816 + if (ret > 0) 817 + sport->port.line = dev->id; 818 + else if (ret < 0) 819 + goto err_clk; 820 + snprintf(sport->name, PXA_NAME_LEN - 1, "UART%d", sport->port.line + 1); 853 821 854 822 sport->port.membase = ioremap(mmres->start, resource_size(mmres)); 855 823 if (!sport->port.membase) { ··· 853 829 goto err_clk; 854 830 } 855 831 856 - serial_pxa_ports[dev->id] = sport; 832 + serial_pxa_ports[sport->port.line] = sport; 857 833 858 834 uart_add_one_port(&serial_pxa_reg, &sport->port); 859 835 platform_set_drvdata(dev, sport); ··· 890 866 #ifdef CONFIG_PM 891 867 .pm = &serial_pxa_pm_ops, 892 868 #endif 869 + .of_match_table = serial_pxa_dt_ids, 893 870 }, 894 871 }; 895 872