diff mbox

[v3] serial: pl011: honour serial aliases in device tree

Message ID 1346168488-9309-1-git-send-email-matthew.leach@arm.com (mailing list archive)
State New, archived
Headers show

Commit Message

Matthew Leach Aug. 28, 2012, 3:41 p.m. UTC
If the order of UART nodes is changed in the device tree, then tty dev
devices are attached to different serial ports causing the console to
be directed to a different physical serial port. The "serial" aliases
in the device tree should prevent this.

This patch ensures that the UART driver creates tty devices that
honour these aliases if a device tree is present.

Acked-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Will Deacon <will.deacon@arm.com>
Acked-by: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Matthew Leach <matthew.leach@arm.com>
---
v3: minor consistency correction
v2: use IS_ENABLED instead of ifdefs
 drivers/tty/serial/amba-pl011.c |   36 ++++++++++++++++++++++++++++++++++++
 1 files changed, 36 insertions(+), 0 deletions(-)

Comments

Matthew Leach Sept. 4, 2012, 11:06 a.m. UTC | #1
Alan,

> If the order of UART nodes is changed in the device tree, then tty dev
> devices are attached to different serial ports causing the console to
> be directed to a different physical serial port. The "serial" aliases
> in the device tree should prevent this.

Are you okay merging this patch?

Thanks,
Matt
Alan Cox Sept. 4, 2012, 11:42 a.m. UTC | #2
On Tue, 4 Sep 2012 12:06:27 +0100
"Matthew Leach" <matthew.leach@arm.com> wrote:

> Alan,
> 
> > If the order of UART nodes is changed in the device tree, then tty
> > dev devices are attached to different serial ports causing the
> > console to be directed to a different physical serial port. The
> > "serial" aliases in the device tree should prevent this.
> 
> Are you okay merging this patch?

Yes
diff mbox

Patch

diff --git a/drivers/tty/serial/amba-pl011.c b/drivers/tty/serial/amba-pl011.c
index d3553b5..dc05dd1 100644
--- a/drivers/tty/serial/amba-pl011.c
+++ b/drivers/tty/serial/amba-pl011.c
@@ -52,6 +52,8 @@ 
 #include <linux/scatterlist.h>
 #include <linux/delay.h>
 #include <linux/types.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/sizes.h>
 
@@ -1869,6 +1871,38 @@  static struct uart_driver amba_reg = {
 	.cons			= AMBA_CONSOLE,
 };
 
+static int pl011_probe_dt_alias(int index, struct device *dev)
+{
+	struct device_node *np;
+	static bool seen_dev_with_alias = false;
+	static bool seen_dev_without_alias = false;
+	int ret = index;
+
+	if (!IS_ENABLED(CONFIG_OF))
+		return ret;
+
+	np = dev->of_node;
+	if (!np)
+		return ret;
+
+	ret = of_alias_get_id(np, "serial");
+	if (IS_ERR_VALUE(ret)) {
+		seen_dev_without_alias = true;
+		ret = index;
+	} else {
+		seen_dev_with_alias = true;
+		if (ret >= ARRAY_SIZE(amba_ports) || amba_ports[ret] != NULL) {
+			dev_warn(dev, "requested serial port %d  not available.\n", ret);
+			ret = index;
+		}
+	}
+
+	if (seen_dev_with_alias && seen_dev_without_alias)
+		dev_warn(dev, "aliased and non-aliased serial devices found in device tree. Serial port enumeration may be unpredictable.\n");
+
+	return ret;
+}
+
 static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
 {
 	struct uart_amba_port *uap;
@@ -1891,6 +1925,8 @@  static int pl011_probe(struct amba_device *dev, const struct amba_id *id)
 		goto out;
 	}
 
+	i = pl011_probe_dt_alias(i, &dev->dev);
+
 	base = ioremap(dev->res.start, resource_size(&dev->res));
 	if (!base) {
 		ret = -ENOMEM;