diff options
-rw-r--r-- | Documentation/devicetree/bindings/serial/altera_uart.txt | 7 | ||||
-rw-r--r-- | drivers/tty/serial/altera_uart.c | 51 |
2 files changed, 54 insertions, 4 deletions
diff --git a/Documentation/devicetree/bindings/serial/altera_uart.txt b/Documentation/devicetree/bindings/serial/altera_uart.txt new file mode 100644 index 000000000000..71cae3f70100 --- /dev/null +++ b/Documentation/devicetree/bindings/serial/altera_uart.txt | |||
@@ -0,0 +1,7 @@ | |||
1 | Altera UART | ||
2 | |||
3 | Required properties: | ||
4 | - compatible : should be "ALTR,uart-1.0" | ||
5 | |||
6 | Optional properties: | ||
7 | - clock-frequency : frequency of the clock input to the UART | ||
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 | ||
516 | static 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 | ||
531 | static 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 | |||
514 | static int __devinit altera_uart_probe(struct platform_device *pdev) | 538 | static 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 | ||
604 | static struct of_device_id altera_uart_match[] = { | ||
605 | { .compatible = "ALTR,uart-1.0", }, | ||
606 | {}, | ||
607 | }; | ||
608 | MODULE_DEVICE_TABLE(of, altera_uart_match); | ||
609 | #else | ||
610 | #define altera_uart_match NULL | ||
611 | #endif /* CONFIG_OF */ | ||
612 | |||
570 | static struct platform_driver altera_uart_platform_driver = { | 613 | static 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 | ||