aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/tty/serial
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2011-03-28 07:57:11 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2011-04-19 19:31:19 -0400
commita664ec9675d77aa2196e797afa5516d3e476da77 (patch)
tree31d01adbd517d31fb20a1538453ee5d62ee98df4 /drivers/tty/serial
parent0259894c732837c801565d038eaecdcf8fc5bbe7 (diff)
serial: altera_uart: Scan for a free port if platform device id is -1
Devices extracted from device tree all seem to have pdev->id set to -1. Up until now we mapped all devices with id -1 to the first device. This behaviour could lead to problems when using more than one Altera UART in a system. This patch changes the behaviour of the driver to scan for the next free id in case the id is -1. Because we cannot refer back to the assigned id in altera_uart_remove, the port instance needs to be stored in device drvdata. Reported-by: David Smoot <davidsmoot@gmail.com> Cc: Anton Vorontsov <cbouatmailru@gmail.com> Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/tty/serial')
-rw-r--r--drivers/tty/serial/altera_uart.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/drivers/tty/serial/altera_uart.c b/drivers/tty/serial/altera_uart.c
index 6d5b036ac783..50bc5a5ac653 100644
--- a/drivers/tty/serial/altera_uart.c
+++ b/drivers/tty/serial/altera_uart.c
@@ -540,11 +540,14 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
540 int i = pdev->id; 540 int i = pdev->id;
541 int ret; 541 int ret;
542 542
543 /* -1 emphasizes that the platform must have one port, no .N suffix */ 543 /* if id is -1 scan for a free id and use that one */
544 if (i == -1) 544 if (i == -1) {
545 i = 0; 545 for (i = 0; i < CONFIG_SERIAL_ALTERA_UART_MAXPORTS; i++)
546 if (altera_uart_ports[i].port.mapbase == 0)
547 break;
548 }
546 549
547 if (i >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS) 550 if (i < 0 || i >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS)
548 return -EINVAL; 551 return -EINVAL;
549 552
550 port = &altera_uart_ports[i].port; 553 port = &altera_uart_ports[i].port;
@@ -587,6 +590,8 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
587 port->ops = &altera_uart_ops; 590 port->ops = &altera_uart_ops;
588 port->flags = UPF_BOOT_AUTOCONF; 591 port->flags = UPF_BOOT_AUTOCONF;
589 592
593 dev_set_drvdata(&pdev->dev, port);
594
590 uart_add_one_port(&altera_uart_driver, port); 595 uart_add_one_port(&altera_uart_driver, port);
591 596
592 return 0; 597 return 0;
@@ -594,14 +599,13 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
594 599
595static int __devexit altera_uart_remove(struct platform_device *pdev) 600static int __devexit altera_uart_remove(struct platform_device *pdev)
596{ 601{
597 struct uart_port *port; 602 struct uart_port *port = dev_get_drvdata(&pdev->dev);
598 int i = pdev->id;
599 603
600 if (i == -1) 604 if (port) {
601 i = 0; 605 uart_remove_one_port(&altera_uart_driver, port);
602 606 dev_set_drvdata(&pdev->dev, NULL);
603 port = &altera_uart_ports[i].port; 607 port->mapbase = 0;
604 uart_remove_one_port(&altera_uart_driver, port); 608 }
605 609
606 return 0; 610 return 0;
607} 611}