[RFC 1/2] serial: Add OF alias support for uartlite

Michal Simek monstr at monstr.eu
Wed Nov 9 00:35:06 EST 2011


Signed-off-by: John Williams <john.williams at petalogix.com>
Signed-off-by: Michal Simek <monstr at monstr.eu>
---
 drivers/tty/serial/uartlite.c |   26 ++++++++++++++++++++++----
 1 files changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/uartlite.c b/drivers/tty/serial/uartlite.c
index 0aed022..71ba422 100644
--- a/drivers/tty/serial/uartlite.c
+++ b/drivers/tty/serial/uartlite.c
@@ -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);
-- 
1.7.5.4



More information about the devicetree-discuss mailing list