Commit 699c20f3 authored by Haojian Zhuang's avatar Haojian Zhuang Committed by Haojian Zhuang

serial: pxa: add OF support

Parse uart device id from alias in DTS file.
Signed-off-by: default avatarHaojian Zhuang <haojian.zhuang@marvell.com>
parent 192cfd58
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <linux/circ_buf.h> #include <linux/circ_buf.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/of.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/tty.h> #include <linux/tty.h>
#include <linux/tty_flip.h> #include <linux/tty_flip.h>
...@@ -44,6 +45,8 @@ ...@@ -44,6 +45,8 @@
#include <linux/io.h> #include <linux/io.h>
#include <linux/slab.h> #include <linux/slab.h>
#define PXA_NAME_LEN 8
struct uart_pxa_port { struct uart_pxa_port {
struct uart_port port; struct uart_port port;
unsigned char ier; unsigned char ier;
...@@ -51,7 +54,7 @@ struct uart_pxa_port { ...@@ -51,7 +54,7 @@ struct uart_pxa_port {
unsigned char mcr; unsigned char mcr;
unsigned int lsr_break_flag; unsigned int lsr_break_flag;
struct clk *clk; struct clk *clk;
char *name; char name[PXA_NAME_LEN];
}; };
static inline unsigned int serial_in(struct uart_pxa_port *up, int offset) static inline unsigned int serial_in(struct uart_pxa_port *up, int offset)
...@@ -781,6 +784,31 @@ static const struct dev_pm_ops serial_pxa_pm_ops = { ...@@ -781,6 +784,31 @@ static const struct dev_pm_ops serial_pxa_pm_ops = {
}; };
#endif #endif
static struct of_device_id serial_pxa_dt_ids[] = {
{ .compatible = "mrvl,pxa-uart", },
{ .compatible = "mrvl,mmp-uart", },
{}
};
MODULE_DEVICE_TABLE(of, serial_pxa_dt_ids);
static int serial_pxa_probe_dt(struct platform_device *pdev,
struct uart_pxa_port *sport)
{
struct device_node *np = pdev->dev.of_node;
int ret;
if (!np)
return 1;
ret = of_alias_get_id(np, "serial");
if (ret < 0) {
dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
return ret;
}
sport->port.line = ret;
return 0;
}
static int serial_pxa_probe(struct platform_device *dev) static int serial_pxa_probe(struct platform_device *dev)
{ {
struct uart_pxa_port *sport; struct uart_pxa_port *sport;
...@@ -808,20 +836,16 @@ static int serial_pxa_probe(struct platform_device *dev) ...@@ -808,20 +836,16 @@ static int serial_pxa_probe(struct platform_device *dev)
sport->port.irq = irqres->start; sport->port.irq = irqres->start;
sport->port.fifosize = 64; sport->port.fifosize = 64;
sport->port.ops = &serial_pxa_pops; sport->port.ops = &serial_pxa_pops;
sport->port.line = dev->id;
sport->port.dev = &dev->dev; sport->port.dev = &dev->dev;
sport->port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF; sport->port.flags = UPF_IOREMAP | UPF_BOOT_AUTOCONF;
sport->port.uartclk = clk_get_rate(sport->clk); sport->port.uartclk = clk_get_rate(sport->clk);
switch (dev->id) { ret = serial_pxa_probe_dt(dev, sport);
case 0: sport->name = "FFUART"; break; if (ret > 0)
case 1: sport->name = "BTUART"; break; sport->port.line = dev->id;
case 2: sport->name = "STUART"; break; else if (ret < 0)
case 3: sport->name = "HWUART"; break; goto err_clk;
default: snprintf(sport->name, PXA_NAME_LEN - 1, "UART%d", sport->port.line + 1);
sport->name = "???";
break;
}
sport->port.membase = ioremap(mmres->start, resource_size(mmres)); sport->port.membase = ioremap(mmres->start, resource_size(mmres));
if (!sport->port.membase) { if (!sport->port.membase) {
...@@ -829,7 +853,7 @@ static int serial_pxa_probe(struct platform_device *dev) ...@@ -829,7 +853,7 @@ static int serial_pxa_probe(struct platform_device *dev)
goto err_clk; goto err_clk;
} }
serial_pxa_ports[dev->id] = sport; serial_pxa_ports[sport->port.line] = sport;
uart_add_one_port(&serial_pxa_reg, &sport->port); uart_add_one_port(&serial_pxa_reg, &sport->port);
platform_set_drvdata(dev, sport); platform_set_drvdata(dev, sport);
...@@ -866,6 +890,7 @@ static struct platform_driver serial_pxa_driver = { ...@@ -866,6 +890,7 @@ static struct platform_driver serial_pxa_driver = {
#ifdef CONFIG_PM #ifdef CONFIG_PM
.pm = &serial_pxa_pm_ops, .pm = &serial_pxa_pm_ops,
#endif #endif
.of_match_table = serial_pxa_dt_ids,
}, },
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment