aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2011-02-18 05:35:32 -0500
committerGrant Likely <grant.likely@secretlab.ca>2011-03-01 11:38:27 -0500
commit7c9325d79a3c3d51c98812161d47876d6830c062 (patch)
treee749efa50ac29719d4ff159f94f03abc455cee06 /drivers/tty
parentd714d1979d7b4df7e2c127407f4014ce71f73cd0 (diff)
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>
Diffstat (limited to 'drivers/tty')
-rw-r--r--drivers/tty/serial/altera_uart.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/drivers/tty/serial/altera_uart.c b/drivers/tty/serial/altera_uart.c
index 721216292a50..1803c37d58ab 100644
--- a/drivers/tty/serial/altera_uart.c
+++ b/drivers/tty/serial/altera_uart.c
@@ -24,6 +24,7 @@
24#include <linux/serial.h> 24#include <linux/serial.h>
25#include <linux/serial_core.h> 25#include <linux/serial_core.h>
26#include <linux/platform_device.h> 26#include <linux/platform_device.h>
27#include <linux/of.h>
27#include <linux/io.h> 28#include <linux/io.h>
28#include <linux/altera_uart.h> 29#include <linux/altera_uart.h>
29 30
@@ -511,6 +512,29 @@ static struct uart_driver altera_uart_driver = {
511 .cons = ALTERA_UART_CONSOLE, 512 .cons = ALTERA_UART_CONSOLE,
512}; 513};
513 514
515#ifdef CONFIG_OF
516static int altera_uart_get_of_uartclk(struct platform_device *pdev,
517 struct uart_port *port)
518{
519 int len;
520 const __be32 *clk;
521
522 clk = of_get_property(pdev->dev.of_node, "clock-frequency", &len);
523 if (!clk || len < sizeof(__be32))
524 return -ENODEV;
525
526 port->uartclk = be32_to_cpup(clk);
527
528 return 0;
529}
530#else
531static int altera_uart_get_of_uartclk(struct platform_device *pdev,
532 struct uart_port *port)
533{
534 return -ENODEV;
535}
536#endif /* CONFIG_OF */
537
514static int __devinit altera_uart_probe(struct platform_device *pdev) 538static int __devinit altera_uart_probe(struct platform_device *pdev)
515{ 539{
516 struct altera_uart_platform_uart *platp = pdev->dev.platform_data; 540 struct altera_uart_platform_uart *platp = pdev->dev.platform_data;
@@ -518,6 +542,7 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
518 struct resource *res_mem; 542 struct resource *res_mem;
519 struct resource *res_irq; 543 struct resource *res_irq;
520 int i = pdev->id; 544 int i = pdev->id;
545 int ret;
521 546
522 /* -1 emphasizes that the platform must have one port, no .N suffix */ 547 /* -1 emphasizes that the platform must have one port, no .N suffix */
523 if (i == -1) 548 if (i == -1)
@@ -542,6 +567,15 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
542 else if (platp->irq) 567 else if (platp->irq)
543 port->irq = platp->irq; 568 port->irq = platp->irq;
544 569
570 /* Check platform data first so we can override device node data */
571 if (platp)
572 port->uartclk = platp->uartclk;
573 else {
574 ret = altera_uart_get_of_uartclk(pdev, port);
575 if (ret)
576 return ret;
577 }
578
545 port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE); 579 port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE);
546 if (!port->membase) 580 if (!port->membase)
547 return -ENOMEM; 581 return -ENOMEM;
@@ -549,7 +583,6 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
549 port->line = i; 583 port->line = i;
550 port->type = PORT_ALTERA_UART; 584 port->type = PORT_ALTERA_UART;
551 port->iotype = SERIAL_IO_MEM; 585 port->iotype = SERIAL_IO_MEM;
552 port->uartclk = platp->uartclk;
553 port->ops = &altera_uart_ops; 586 port->ops = &altera_uart_ops;
554 port->flags = UPF_BOOT_AUTOCONF; 587 port->flags = UPF_BOOT_AUTOCONF;
555 port->private_data = platp; 588 port->private_data = platp;
@@ -567,13 +600,23 @@ static int __devexit altera_uart_remove(struct platform_device *pdev)
567 return 0; 600 return 0;
568} 601}
569 602
603#ifdef CONFIG_OF
604static struct of_device_id altera_uart_match[] = {
605 { .compatible = "ALTR,uart-1.0", },
606 {},
607};
608MODULE_DEVICE_TABLE(of, altera_uart_match);
609#else
610#define altera_uart_match NULL
611#endif /* CONFIG_OF */
612
570static struct platform_driver altera_uart_platform_driver = { 613static struct platform_driver altera_uart_platform_driver = {
571 .probe = altera_uart_probe, 614 .probe = altera_uart_probe,
572 .remove = __devexit_p(altera_uart_remove), 615 .remove = __devexit_p(altera_uart_remove),
573 .driver = { 616 .driver = {
574 .name = DRV_NAME, 617 .name = DRV_NAME,
575 .owner = THIS_MODULE, 618 .owner = THIS_MODULE,
576 .pm = NULL, 619 .of_match_table = altera_uart_match,
577 }, 620 },
578}; 621};
579 622