serial: OF alias support
Subsystems (3)
cover serial: OF alias support
Hi,
I am sending two patches for uartlite and uart16550/8250 serial drivers.
Our aim is to be able to probe serial drivers based on order in alias node. We are using of_alias_get_id function to get correct ID.
These patches are based on the latest Linaro git tree
(git://git.linaro.org/kernel/linux-linaro-3.1.git).
"Merge branch 'devicetree/arm-linaro-3.1' of git://git.secretlab.ca/git/linux-2.6 into linaro-3.1" (sha1: af1bdb79ca64ceadc7b44b11929b384eff66ce59)
Thanks for you comments,
Michal
Michal Simek (2):
serial: Add OF alias support for uartlite
serial: 8250: Add OF alias support
drivers/tty/serial/8250.c | 7 +++++++ drivers/tty/serial/of_serial.c | 15 +++++++++++++++ drivers/tty/serial/uartlite.c | 26 ++++++++++++++++++++++---- 3 files changed, 44 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.5.4
RFC 1/2 serial: Add OF alias support for uartlite
--- drivers/tty/serial/uartlite.c | 26 ++++++++++++++++++++++---- 1 files changed, 22 insertions(+), 4 deletions(-)
drivers/tty/serial/uartlite.c +22 -4
@@ -573,13 +573,31 @@ MODULE_DEVICE_TABLE(of, ulite_of_match);static int __devinit ulite_probe (struct platform_device *pdev) {struct resource *res, *res2; +unsigned int *idp;int id = pdev->id; +#ifdef CONFIG_OF -const __be32 *prop; +/* Look for a serialN alias */ + id =of_alias_get_id (pdev->dev.of_node,"serial" ); +if (id <0 ) { +dev_warn (&pdev->dev,"failed to get alias id, errno %d\n" , id); +/* Fall back to old port-number property */ + idp =of_get_property (pdev->dev.of_node,"port-number" ,NULL ); +if (idp <0 ) { +dev_warn (&pdev->dev, +"failed to get port-number, errno %d\n" , idp); + id =-1 ; + }else + id =be32_to_cpup (idp); + } - prop =of_get_property (pdev->dev.of_node,"port-number" ,NULL ); -if (prop) - id =be32_to_cpup (prop); +/* We can't register ids which are greater than number of uartlites */ +if (id >=ULITE_NR_UARTS ) { +dev_warn (&op->dev, +"Extern number of allocated uartlite entries " +"ULITE_NR_UARTS, id %d\n" , id); +return -ENODEV ; + }#endif res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
Signature · 1 line
1.7.5.4
RFC 2/2 serial: 8250: Add OF alias support
Follow alias number for OF driven boards.
For example:
aliases {
serial2 = &RS232_Uart_1;
} ;Setup port->line number in of_platform_serial_probe from alias node.
Fixing serial8250_find_match_or_unused function is more complicated because it is key function which check which port is available.
This was probably done for any ancient ISA support where all ports are registered first in serial8250_register_ports (serial8250_isa_init_ports). and then, if they are usused, unregistered and registered with proper setting. Not sure if this is needed.
If port entry matches, it is used. If not, code looks first at entry at port->line number to be able to assign ttySX number according port->line setup from of_platform_serial_probe. If this port is used code looks for the first free entry as before.
The only one change is to check entry on port->line first.
This patch requires more testing because there are several usage of standard 8250 compatible driver.
--- drivers/tty/serial/8250.c | 7 +++++++ drivers/tty/serial/of_serial.c | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 0 deletions(-)
drivers/tty/serial/8250.c +7 -0
@@ -3212,6 +3212,13 @@ static struct uart_8250_port *serial8250_find_match_or_unused(struct uart_port *if (uart_match_port (&serial8250_ports[i].port, port))return &serial8250_ports[i]; +/* Look at setup port->line port first. If is available, use it */ +if (port->line >=0 && port->line < nr_uarts) +if (serial8250_ports[port->line].port.type ==PORT_UNKNOWN && + serial8250_ports[port->line].port.iobase ==0 ) { +return &serial8250_ports[port->line]; + } +/* * We didn't find a matching entry, so look for the first * free entry. We look for one which hasn't been previously
drivers/tty/serial/of_serial.c +15 -0
@@ -98,6 +98,7 @@ static int __devinit of_platform_serial_probe(struct platform_device *ofdev)struct uart_port port;int port_type;int ret; +int id; match =of_match_device (of_platform_serial_table, &ofdev->dev);if (!match)
@@ -115,6 +116,20 @@ static int __devinit of_platform_serial_probe(struct platform_device *ofdev)if (ret) goto out; + id =of_alias_get_id (ofdev->dev.of_node,"serial" ); +if (id <0 ) { +dev_warn (&ofdev->dev,"FAILED to find out alias id\n" ); + }else { +if (id <CONFIG_SERIAL_8250_RUNTIME_UARTS ) + port.line = id; +else { +dev_warn (&ofdev->dev, +"FAILED to register serial driver with id %d\n" , + id); + goto out; + } + } +switch (port_type) {#ifdef CONFIG_SERIAL_8250 case PORT_8250 ... PORT_MAX_8250:
Signature · 1 line
1.7.5.4