linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tobias Klauser <tklauser@distanz.ch>
To: Greg Kroah-Hartman <gregkh@suse.de>, linux-serial@vger.kernel.org
Cc: nios2-dev@sopc.et.ntust.edu.tw,
	devicetree-discuss@lists.ozlabs.org,
	linux-kernel@vger.kernel.org,
	Grant Likely <grant.likely@secretlab.ca>
Subject: [PATHV v2] tty: serial: altera_uart: Add devicetree support
Date: Wed, 16 Feb 2011 17:12:12 +0100	[thread overview]
Message-ID: <1297872732-10207-1-git-send-email-tklauser@distanz.ch> (raw)
In-Reply-To: <c7a7085602687d2f1b6ac505c030f19bafda04e3.1297245277.git.tklauser@distanz.ch>

With the recent switch of the (currently still out-of-tree) Nios2 Linux
port to devicetree we want to be able to retreive the resources and
properties from dts.

The old method to retreive resources and properties from platform data
is still supported.

Cc: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
---
 Thanks to Grant Likely for the review.

 changes in v2:
 - fall back to uartclk from platform data if the device tree property
   is not available.
 - Only include MODULE_DEVICE_TABLE if CONFIG_OF is set so we don't
   advertise device tree support if CONFIG_OF isn't active.
 - change vendor prefix in match table to be uppercase for consistency
   with documentation

 .../devicetree/bindings/serial/altera_uart.txt     |    7 +++
 drivers/tty/serial/altera_uart.c                   |   50 ++++++++++++++++++--
 2 files changed, 53 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/serial/altera_uart.txt

diff --git a/Documentation/devicetree/bindings/serial/altera_uart.txt b/Documentation/devicetree/bindings/serial/altera_uart.txt
new file mode 100644
index 0000000..71cae3f
--- /dev/null
+++ b/Documentation/devicetree/bindings/serial/altera_uart.txt
@@ -0,0 +1,7 @@
+Altera UART
+
+Required properties:
+- compatible : should be "ALTR,uart-1.0"
+
+Optional properties:
+- clock-frequency : frequency of the clock input to the UART
diff --git a/drivers/tty/serial/altera_uart.c b/drivers/tty/serial/altera_uart.c
index 5e80977..4f0898c 100644
--- a/drivers/tty/serial/altera_uart.c
+++ b/drivers/tty/serial/altera_uart.c
@@ -24,6 +24,7 @@
 #include <linux/serial.h>
 #include <linux/serial_core.h>
 #include <linux/platform_device.h>
+#include <linux/of.h>
 #include <linux/io.h>
 #include <linux/altera_uart.h>
 
@@ -484,6 +485,29 @@ static struct uart_driver altera_uart_driver = {
 	.cons		= ALTERA_UART_CONSOLE,
 };
 
+#ifdef CONFIG_OF
+static int altera_uart_get_of_uartclk(struct platform_device *pdev,
+				      struct uart_port *port)
+{
+	int len;
+	const __be32 *clk;
+
+	clk = of_get_property(pdev->dev.of_node, "clock-frequency", &len);
+	if (!clk || len < sizeof(__be32))
+		return -ENODEV;
+
+	port->uartclk = be32_to_cpup(clk);
+
+	return 0;
+}
+#else
+static int altera_uart_get_of_uartclk(struct platform_device *pdev,
+				      struct uart_port *port)
+{
+	return -ENODEV;
+}
+#endif /* CONFIG_OF */
+
 static int __devinit altera_uart_probe(struct platform_device *pdev)
 {
 	struct altera_uart_platform_uart *platp = pdev->dev.platform_data;
@@ -491,6 +515,7 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
 	struct resource *res_mem;
 	struct resource *res_irq;
 	int i = pdev->id;
+	int ret;
 
 	/* -1 emphasizes that the platform must have one port, no .N suffix */
 	if (i == -1)
@@ -515,6 +540,14 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
 	else if (platp->irq)
 		port->irq = platp->irq;
 
+	/* Try to get the uartclk from devicetree, fall back to platform data
+	 * otherwise */
+	ret = altera_uart_get_of_uartclk(pdev, port);
+	if (ret && platp)
+		port->uartclk = platp->uartclk;
+	else if (ret)
+		return ret;
+
 	port->membase = ioremap(port->mapbase, ALTERA_UART_SIZE);
 	if (!port->membase)
 		return -ENOMEM;
@@ -527,7 +560,6 @@ static int __devinit altera_uart_probe(struct platform_device *pdev)
 	port->line = i;
 	port->type = PORT_ALTERA_UART;
 	port->iotype = SERIAL_IO_MEM;
-	port->uartclk = platp->uartclk;
 	port->ops = &altera_uart_ops;
 	port->flags = UPF_BOOT_AUTOCONF;
 
@@ -550,13 +582,23 @@ static int __devexit altera_uart_remove(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_OF
+static struct of_device_id altera_uart_match[] = {
+	{ .compatible = "ALTR,uart-1.0", },
+	{},
+};
+MODULE_DEVICE_TABLE(of, altera_uart_match);
+#else
+#define altera_uart_match NULL
+#endif /* CONFIG_OF */
+
 static struct platform_driver altera_uart_platform_driver = {
 	.probe	= altera_uart_probe,
 	.remove	= __devexit_p(altera_uart_remove),
 	.driver	= {
-		.name	= DRV_NAME,
-		.owner	= THIS_MODULE,
-		.pm	= NULL,
+		.name		= DRV_NAME,
+		.owner		= THIS_MODULE,
+		.of_match_table	= altera_uart_match,
 	},
 };
 
-- 
1.7.0.4


  parent reply	other threads:[~2011-02-16 16:12 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-09  9:51 [PATCH 0/4] *** SUBJECT HERE *** Tobias Klauser
2011-02-09  9:51 ` [PATCH 1/4] tty: serial: altera_uart: Handle pdev->id == -1 in altera_uart_remove Tobias Klauser
2011-02-09  9:56   ` Tobias Klauser
2011-02-09  9:53 ` [PATCH 0/4] *** SUBJECT HERE *** Tobias Klauser
2011-02-09  9:55 ` [PATCH 0/4] tty: serial: Updates for altera_uart driver Tobias Klauser
2011-02-09  9:56   ` [PATCH 1/4] tty: serial: altera_uart: Handle pdev->id == -1 in altera_uart_remove Tobias Klauser
2011-02-09 10:46     ` Anton Vorontsov
2011-02-09  9:57   ` [PATCH 2/4] tty: serial: altera_uart: Use port->regshift to store bus shift Tobias Klauser
2011-02-09 10:46     ` Anton Vorontsov
2011-02-09  9:58   ` [PATCH 3/4] tty: serial: altera_uart: Add devicetree support Tobias Klauser
2011-02-16  4:32     ` Grant Likely
2011-02-16  7:43       ` Tobias Klauser
2011-02-16 12:07         ` Grant Likely
2011-02-16 16:12     ` Tobias Klauser [this message]
2011-02-17  2:24       ` [Nios2-dev] [PATHV v2] " Thomas Chou
2011-02-17  7:48         ` Tobias Klauser
2011-02-18  1:28           ` Thomas Chou
2011-02-18  8:08             ` Grant Likely
2011-02-18  8:15               ` Tobias Klauser
2011-02-18 10:35     ` [PATCH 3/4 v3] " Tobias Klauser
2011-02-25 17:58       ` Greg KH
     [not found]         ` <20110225175856.GA17072-U8xfFu+wG4EAvxtiuMwx3w@public.gmane.org>
2011-02-28  8:31           ` Grant Likely
2011-02-09  9:58   ` [PATCH 4/4] MAINTAINERS: Add myself as a maintainer for altera_uart/altera_jtaguart Tobias Klauser
2011-02-17  3:16     ` [Nios2-dev] " Thomas Chou
2011-02-17  7:51       ` Tobias Klauser
2011-02-17 18:02       ` Arnd Bergmann
2011-02-17 19:29         ` Tobias Klauser
2011-02-17 19:32   ` [PATCH 0/4] tty: serial: Updates for altera_uart driver Greg KH
2011-02-17 19:38     ` Tobias Klauser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1297872732-10207-1-git-send-email-tklauser@distanz.ch \
    --to=tklauser@distanz.ch \
    --cc=devicetree-discuss@lists.ozlabs.org \
    --cc=grant.likely@secretlab.ca \
    --cc=gregkh@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=nios2-dev@sopc.et.ntust.edu.tw \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).