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>
This commit is contained in:
Родитель
0259894c73
Коммит
a664ec9675
|
@ -540,11 +540,14 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
|
||||||
int i = pdev->id;
|
int i = pdev->id;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* -1 emphasizes that the platform must have one port, no .N suffix */
|
/* if id is -1 scan for a free id and use that one */
|
||||||
if (i == -1)
|
if (i == -1) {
|
||||||
i = 0;
|
for (i = 0; i < CONFIG_SERIAL_ALTERA_UART_MAXPORTS; i++)
|
||||||
|
if (altera_uart_ports[i].port.mapbase == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (i >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS)
|
if (i < 0 || i >= CONFIG_SERIAL_ALTERA_UART_MAXPORTS)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
port = &altera_uart_ports[i].port;
|
port = &altera_uart_ports[i].port;
|
||||||
|
@ -587,6 +590,8 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
|
||||||
port->ops = &altera_uart_ops;
|
port->ops = &altera_uart_ops;
|
||||||
port->flags = UPF_BOOT_AUTOCONF;
|
port->flags = UPF_BOOT_AUTOCONF;
|
||||||
|
|
||||||
|
dev_set_drvdata(&pdev->dev, port);
|
||||||
|
|
||||||
uart_add_one_port(&altera_uart_driver, port);
|
uart_add_one_port(&altera_uart_driver, port);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -594,14 +599,13 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
static int __devexit altera_uart_remove(struct platform_device *pdev)
|
static int __devexit altera_uart_remove(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct uart_port *port;
|
struct uart_port *port = dev_get_drvdata(&pdev->dev);
|
||||||
int i = pdev->id;
|
|
||||||
|
|
||||||
if (i == -1)
|
if (port) {
|
||||||
i = 0;
|
uart_remove_one_port(&altera_uart_driver, port);
|
||||||
|
dev_set_drvdata(&pdev->dev, NULL);
|
||||||
port = &altera_uart_ports[i].port;
|
port->mapbase = 0;
|
||||||
uart_remove_one_port(&altera_uart_driver, port);
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче