diff mbox

MXS getting AUART to work with DT.

Message ID 2CC96C7FBBE82548A0B1766B8D8348AD9C169E@mx2.grid-net.com
State New
Headers show

Commit Message

Matt Burtch June 14, 2012, 4:49 p.m. UTC
Here is the patch I put together to get the AUART recognized with the dt.  I'm pretty new to dt development, so this was a quick first pass. I'm sure there are more proper ways to get the device id and pass literals between the dt and probe function...but this works for now.

Regards,
-Matt Burtch

Comments

Fabio Estevam June 15, 2012, 1:38 a.m. UTC | #1
Hi Matt,

On Thu, Jun 14, 2012 at 1:49 PM, Matt Burtch <matt@grid-net.com> wrote:
> Here is the patch I put together to get the AUART recognized with the dt.  I'm pretty new to dt development, so this was a quick first pass. I'm sure there are more proper ways to get the device id and pass literals between the dt and probe function...but this works for now.

Ok, I managed to fix it properly now.

Will submit the patches tomorrow.

Regards,

Fabio Estevam
diff mbox

Patch

diff --git a/arch/arm/boot/dts/imx28.dtsi b/arch/arm/boot/dts/imx28.dtsi
index fd67809..0b72bf6 100644
--- a/arch/arm/boot/dts/imx28.dtsi
+++ b/arch/arm/boot/dts/imx28.dtsi
@@ -440,6 +448,7 @@ 
 				reg = <0x8006a000 0x2000>;
 				interrupts = <112 70 71>;
 				status = "disabled";
+				id = "0";
 			};
 
 			auart1: serial@8006c000 {
@@ -447,6 +456,7 @@ 
 				reg = <0x8006c000 0x2000>;
 				interrupts = <113 72 73>;
 				status = "disabled";
+				id = "1";
 			};
 
 			auart2: serial@8006e000 {
@@ -454,6 +464,7 @@ 
 				reg = <0x8006e000 0x2000>;
 				interrupts = <114 74 75>;
 				status = "disabled";
+				id = "2";
 			};
 
 			auart3: serial@80070000 {
@@ -461,6 +472,7 @@ 
 				reg = <0x80070000 0x2000>;
 				interrupts = <115 76 77>;
 				status = "disabled";
+				id = "3";
 			};
 
 			auart4: serial@80072000 {
@@ -468,6 +480,7 @@ 
 				reg = <0x80072000 0x2000>;
 				interrupts = <116 78 79>;
 				status = "disabled";
+				id = "4";
 			};
 
 			duart: serial@80074000 {
diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c
index aaae433..315aebd 100644
--- a/drivers/tty/serial/mxs-auart.c
+++ b/drivers/tty/serial/mxs-auart.c
@@ -33,6 +33,9 @@ 
 #include <linux/delay.h>
 #include <linux/io.h>
 #include <linux/pinctrl/consumer.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/pinctrl/consumer.h>
 
 #include <asm/cacheflush.h>
 
@@ -675,6 +678,50 @@  static struct uart_driver auart_driver = {
 #endif
 };
 
+static struct of_device_id mxs_auart_dt_ids[] = {
+	{ .compatible = "fsl,imx28-auart", },
+	{ /* sentinel */ }
+};
+
+
+static int mxs_auart_probe_dt(struct mxs_auart_port *s,
+		struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	const struct of_device_id *of_id =
+			of_match_device(mxs_auart_dt_ids, &pdev->dev);
+	int *ret;
+	int copy;
+
+	if (!np)
+		/* no device tree device */
+		return 1;
+
+	ret = of_get_property(np, "id", NULL);
+	if (ret == NULL) {
+		dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
+		return ret;
+	}
+
+	copy = *ret - 48;
+	s->port.line = copy;
+
+	return 0;
+}
+
+static void mxs_auart_probe_pdev(struct mxs_auart_port *s,
+		struct platform_device *pdev)
+{
+	struct imxuart_platform_data *pdata = pdev->dev.platform_data;
+
+	s->port.line = pdev->id < 0 ? 0 : pdev->id;
+
+	if (!pdata)
+		return;
+}
+
 static int __devinit mxs_auart_probe(struct platform_device *pdev)
 {
 	struct mxs_auart_port *s;
@@ -688,6 +735,15 @@  static int __devinit mxs_auart_probe(struct platform_device *pdev)
 		ret = -ENOMEM;
 		goto out;
 	}
+
+	ret = mxs_auart_probe_dt(s, pdev);
+	if (ret > 0)
+		mxs_auart_probe_pdev(s, pdev);
+	else if (ret < 0) {
+		ret - EINVAL;
+		goto out;
+	}
+
 
 	pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
 	if (IS_ERR(pinctrl)) {
@@ -711,7 +767,7 @@  static int __devinit mxs_auart_probe(struct platform_device *pdev)
 	s->port.membase = ioremap(r->start, resource_size(r));
 	s->port.ops = &mxs_auart_ops;
 	s->port.iotype = UPIO_MEM;
-	s->port.line = pdev->id < 0 ? 0 : pdev->id;
+
 	s->port.fifosize = 16;
 	s->port.uartclk = clk_get_rate(s->clk);
 	s->port.type = PORT_IMX;