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

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>

authored by

Tobias Klauser and committed by
Grant Likely
7c9325d7 d714d197

+54 -4
+7
Documentation/devicetree/bindings/serial/altera_uart.txt
··· 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
+47 -4
drivers/tty/serial/altera_uart.c
··· 24 24 #include <linux/serial.h> 25 25 #include <linux/serial_core.h> 26 26 #include <linux/platform_device.h> 27 + #include <linux/of.h> 27 28 #include <linux/io.h> 28 29 #include <linux/altera_uart.h> 29 30 ··· 512 511 .cons = ALTERA_UART_CONSOLE, 513 512 }; 514 513 514 + #ifdef CONFIG_OF 515 + static int altera_uart_get_of_uartclk(struct platform_device *pdev, 516 + struct uart_port *port) 517 + { 518 + int len; 519 + const __be32 *clk; 520 + 521 + clk = of_get_property(pdev->dev.of_node, "clock-frequency", &len); 522 + if (!clk || len < sizeof(__be32)) 523 + return -ENODEV; 524 + 525 + port->uartclk = be32_to_cpup(clk); 526 + 527 + return 0; 528 + } 529 + #else 530 + static int altera_uart_get_of_uartclk(struct platform_device *pdev, 531 + struct uart_port *port) 532 + { 533 + return -ENODEV; 534 + } 535 + #endif /* CONFIG_OF */ 536 + 515 537 static int __devinit altera_uart_probe(struct platform_device *pdev) 516 538 { 517 539 struct altera_uart_platform_uart *platp = pdev->dev.platform_data; ··· 542 518 struct resource *res_mem; 543 519 struct resource *res_irq; 544 520 int i = pdev->id; 521 + int ret; 545 522 546 523 /* -1 emphasizes that the platform must have one port, no .N suffix */ 547 524 if (i == -1) ··· 567 542 else if (platp->irq) 568 543 port->irq = platp->irq; 569 544 545 + /* Check platform data first so we can override device node data */ 546 + if (platp) 547 + port->uartclk = platp->uartclk; 548 + else { 549 + ret = altera_uart_get_of_uartclk(pdev, port); 550 + if (ret) 551 + return ret; 552 + } 553 + 570 554 port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE); 571 555 if (!port->membase) 572 556 return -ENOMEM; ··· 583 549 port->line = i; 584 550 port->type = PORT_ALTERA_UART; 585 551 port->iotype = SERIAL_IO_MEM; 586 - port->uartclk = platp->uartclk; 587 552 port->ops = &altera_uart_ops; 588 553 port->flags = UPF_BOOT_AUTOCONF; 589 554 port->private_data = platp; ··· 600 567 return 0; 601 568 } 602 569 570 + #ifdef CONFIG_OF 571 + static struct of_device_id altera_uart_match[] = { 572 + { .compatible = "ALTR,uart-1.0", }, 573 + {}, 574 + }; 575 + MODULE_DEVICE_TABLE(of, altera_uart_match); 576 + #else 577 + #define altera_uart_match NULL 578 + #endif /* CONFIG_OF */ 579 + 603 580 static struct platform_driver altera_uart_platform_driver = { 604 581 .probe = altera_uart_probe, 605 582 .remove = __devexit_p(altera_uart_remove), 606 583 .driver = { 607 - .name = DRV_NAME, 608 - .owner = THIS_MODULE, 609 - .pm = NULL, 584 + .name = DRV_NAME, 585 + .owner = THIS_MODULE, 586 + .of_match_table = altera_uart_match, 610 587 }, 611 588 }; 612 589