From patchwork Fri Feb 18 08:12:10 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Liu X-Patchwork-Id: 165 Return-Path: Delivered-To: unknown Received: from imap.gmail.com (74.125.159.109) by localhost6.localdomain6 with IMAP4-SSL; 08 Jun 2011 14:40:30 -0000 Delivered-To: patches@linaro.org Received: by 10.146.25.23 with SMTP id 23cs86417yay; Fri, 18 Feb 2011 00:14:34 -0800 (PST) Received: by 10.229.181.78 with SMTP id bx14mr289404qcb.296.1298016874277; Fri, 18 Feb 2011 00:14:34 -0800 (PST) Received: from TX2EHSOBE002.bigfish.com (tx2ehsobe001.messaging.microsoft.com [65.55.88.11]) by mx.google.com with ESMTPS id 6si3816227qcc.37.2011.02.18.00.14.34 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 18 Feb 2011 00:14:34 -0800 (PST) Received-SPF: neutral (google.com: 65.55.88.11 is neither permitted nor denied by best guess record for domain of r64343@freescale.com) client-ip=65.55.88.11; Authentication-Results: mx.google.com; spf=neutral (google.com: 65.55.88.11 is neither permitted nor denied by best guess record for domain of r64343@freescale.com) smtp.mail=r64343@freescale.com Received: from mail7-tx2-R.bigfish.com (10.9.14.240) by TX2EHSOBE002.bigfish.com (10.9.40.22) with Microsoft SMTP Server id 14.1.225.8; Fri, 18 Feb 2011 08:14:33 +0000 Received: from mail7-tx2 (localhost.localdomain [127.0.0.1]) by mail7-tx2-R.bigfish.com (Postfix) with ESMTP id 3D6D4C286EF; Fri, 18 Feb 2011 08:14:33 +0000 (UTC) X-SpamScore: 0 X-BigFish: VS0(zzzz1202hzz8275bhz2dh2a8h668h61h) X-Spam-TCS-SCL: 0:0 X-Forefront-Antispam-Report: KIP:(null); UIP:(null); IPVD:NLI; H:de01egw02.freescale.net; RD:de01egw02.freescale.net; EFVD:NLI Received: from mail7-tx2 (localhost.localdomain [127.0.0.1]) by mail7-tx2 (MessageSwitch) id 1298016872978343_615; Fri, 18 Feb 2011 08:14:32 +0000 (UTC) Received: from TX2EHSMHS046.bigfish.com (unknown [10.9.14.250]) by mail7-tx2.bigfish.com (Postfix) with ESMTP id EB26B12E004D; Fri, 18 Feb 2011 08:14:32 +0000 (UTC) Received: from de01egw02.freescale.net (192.88.165.103) by TX2EHSMHS046.bigfish.com (10.9.99.146) with Microsoft SMTP Server (TLS) id 14.1.225.8; Fri, 18 Feb 2011 08:14:32 +0000 Received: from az33smr01.freescale.net (az33smr01.freescale.net [10.64.34.199]) by de01egw02.freescale.net (8.14.3/8.14.3) with ESMTP id p1I8EURL007441; Fri, 18 Feb 2011 01:14:31 -0700 (MST) Received: from localhost.localdomain (r64343-desktop.ap.freescale.net [10.192.242.36]) by az33smr01.freescale.net (8.13.1/8.13.0) with ESMTP id p1I8EGYi022541; Fri, 18 Feb 2011 02:14:29 -0600 (CST) From: Jason Liu To: CC: , , Subject: [PATCH 3/3] serial/imx: parse from device tree support Date: Fri, 18 Feb 2011 16:12:10 +0800 Message-ID: <1298016730-22761-4-git-send-email-r64343@freescale.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1298016730-22761-1-git-send-email-r64343@freescale.com> References: <1298016730-22761-1-git-send-email-r64343@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com Signed-off-by: Jason Liu --- drivers/tty/serial/imx.c | 81 ++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 71 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c old mode 100644 new mode 100755 index dfcf4b1..3388599 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -52,6 +52,10 @@ #include #include #include +#ifdef CONFIG_OF +#include +#include +#endif /* CONFIG_OF */ /* Register definitions */ #define URXD0 0x0 /* Receiver Register */ @@ -1224,6 +1228,54 @@ static int serial_imx_resume(struct platform_device *dev) return 0; } +#ifdef CONFIG_OF +static int serial_imx_probe_dt(struct imx_port *sport, + struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + static int line; + + if (!node) + return -ENODEV; + + if (of_get_property(node, "rts-cts", NULL)) + sport->have_rtscts = 1; + +#ifdef CONFIG_IRDA + if (of_get_property(node, "irda", NULL)) + sport->use_irda = 1; +#endif + sport->port.line = line++; + + return 0; +} +#else +static int serial_imx_probe_dt(struct imx_port *sport, + struct platform_device *pdev) +{ + return -ENODEV; +} +#endif + +static int serial_imx_probe_pdata(struct imx_port *sport, + struct platform_device *pdev) +{ + struct imxuart_platform_data *pdata = pdev->dev.platform_data; + + if (!pdata) + return 0; + + if (pdata->flags & IMXUART_HAVE_RTSCTS) + sport->have_rtscts = 1; + +#ifdef CONFIG_IRDA + if (pdata->flags & IMXUART_IRDA) + sport->use_irda = 1; +#endif + sport->port.line = pdev->id; + + return 0; +} static int serial_imx_probe(struct platform_device *pdev) { struct imx_port *sport; @@ -1236,6 +1288,12 @@ static int serial_imx_probe(struct platform_device *pdev) if (!sport) return -ENOMEM; + ret = serial_imx_probe_dt(sport, pdev); + if (ret == -ENODEV) + ret = serial_imx_probe_pdata(sport, pdev); + if (ret) + goto free; + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!res) { ret = -ENODEV; @@ -1260,7 +1318,6 @@ static int serial_imx_probe(struct platform_device *pdev) sport->port.fifosize = 32; sport->port.ops = &imx_pops; sport->port.flags = UPF_BOOT_AUTOCONF; - sport->port.line = pdev->id; init_timer(&sport->timer); sport->timer.function = imx_timeout; sport->timer.data = (unsigned long)sport; @@ -1274,17 +1331,13 @@ static int serial_imx_probe(struct platform_device *pdev) sport->port.uartclk = clk_get_rate(sport->clk); - imx_ports[pdev->id] = sport; + if (imx_ports[sport->port.line]) { + ret = -EBUSY; + goto clkput; + } + imx_ports[sport->port.line] = sport; pdata = pdev->dev.platform_data; - if (pdata && (pdata->flags & IMXUART_HAVE_RTSCTS)) - sport->have_rtscts = 1; - -#ifdef CONFIG_IRDA - if (pdata && (pdata->flags & IMXUART_IRDA)) - sport->use_irda = 1; -#endif - if (pdata && pdata->init) { ret = pdata->init(pdev); if (ret) @@ -1336,6 +1389,11 @@ static int serial_imx_remove(struct platform_device *pdev) return 0; } +static struct of_device_id imx_uart_matches[] = { + { .compatible = "imx-uart" }, + {}, +}; + static struct platform_driver serial_imx_driver = { .probe = serial_imx_probe, .remove = serial_imx_remove, @@ -1345,6 +1403,9 @@ static struct platform_driver serial_imx_driver = { .driver = { .name = "imx-uart", .owner = THIS_MODULE, +#if defined(CONFIG_OF) + .of_match_table = imx_uart_matches, +#endif }, };