tty: serial: altera_uart: Add devicetree support

With the recent switch of the (currently still out-of-tree) Nios2 Linux
port to devicetree we want to be able to retrieve the resources and
properties from dts.

The old method to retrieve resources and properties from platform data
is still supported.

Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
This commit is contained in:
Tobias Klauser 2011-02-18 11:35:32 +01:00 committed by Grant Likely
parent d714d1979d
commit 7c9325d79a
2 changed files with 54 additions and 4 deletions

View File

@ -0,0 +1,7 @@
Altera UART
Required properties:
- compatible : should be "ALTR,uart-1.0"
Optional properties:
- clock-frequency : frequency of the clock input to the UART

View File

@ -24,6 +24,7 @@
#include <linux/serial.h> #include <linux/serial.h>
#include <linux/serial_core.h> #include <linux/serial_core.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/of.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/altera_uart.h> #include <linux/altera_uart.h>
@ -511,6 +512,29 @@ static struct uart_driver altera_uart_driver = {
.cons = ALTERA_UART_CONSOLE, .cons = ALTERA_UART_CONSOLE,
}; };
#ifdef CONFIG_OF
static int altera_uart_get_of_uartclk(struct platform_device *pdev,
struct uart_port *port)
{
int len;
const __be32 *clk;
clk = of_get_property(pdev->dev.of_node, "clock-frequency", &len);
if (!clk || len < sizeof(__be32))
return -ENODEV;
port->uartclk = be32_to_cpup(clk);
return 0;
}
#else
static int altera_uart_get_of_uartclk(struct platform_device *pdev,
struct uart_port *port)
{
return -ENODEV;
}
#endif /* CONFIG_OF */
static int __devinit altera_uart_probe(struct platform_device *pdev) static int __devinit altera_uart_probe(struct platform_device *pdev)
{ {
struct altera_uart_platform_uart *platp = pdev->dev.platform_data; struct altera_uart_platform_uart *platp = pdev->dev.platform_data;
@ -518,6 +542,7 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
struct resource *res_mem; struct resource *res_mem;
struct resource *res_irq; struct resource *res_irq;
int i = pdev->id; int i = pdev->id;
int ret;
/* -1 emphasizes that the platform must have one port, no .N suffix */ /* -1 emphasizes that the platform must have one port, no .N suffix */
if (i == -1) if (i == -1)
@ -542,6 +567,15 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
else if (platp->irq) else if (platp->irq)
port->irq = platp->irq; port->irq = platp->irq;
/* Check platform data first so we can override device node data */
if (platp)
port->uartclk = platp->uartclk;
else {
ret = altera_uart_get_of_uartclk(pdev, port);
if (ret)
return ret;
}
port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE); port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE);
if (!port->membase) if (!port->membase)
return -ENOMEM; return -ENOMEM;
@ -549,7 +583,6 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
port->line = i; port->line = i;
port->type = PORT_ALTERA_UART; port->type = PORT_ALTERA_UART;
port->iotype = SERIAL_IO_MEM; port->iotype = SERIAL_IO_MEM;
port->uartclk = platp->uartclk;
port->ops = &altera_uart_ops; port->ops = &altera_uart_ops;
port->flags = UPF_BOOT_AUTOCONF; port->flags = UPF_BOOT_AUTOCONF;
port->private_data = platp; port->private_data = platp;
@ -567,13 +600,23 @@ static int __devexit altera_uart_remove(struct platform_device *pdev)
return 0; return 0;
} }
#ifdef CONFIG_OF
static struct of_device_id altera_uart_match[] = {
{ .compatible = "ALTR,uart-1.0", },
{},
};
MODULE_DEVICE_TABLE(of, altera_uart_match);
#else
#define altera_uart_match NULL
#endif /* CONFIG_OF */
static struct platform_driver altera_uart_platform_driver = { static struct platform_driver altera_uart_platform_driver = {
.probe = altera_uart_probe, .probe = altera_uart_probe,
.remove = __devexit_p(altera_uart_remove), .remove = __devexit_p(altera_uart_remove),
.driver = { .driver = {
.name = DRV_NAME, .name = DRV_NAME,
.owner = THIS_MODULE, .owner = THIS_MODULE,
.pm = NULL, .of_match_table = altera_uart_match,
}, },
}; };