linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
To: linux-sh@vger.kernel.org
Cc: linux-serial@vger.kernel.org,
	Bastian Hecht <hechtb+renesas@gmail.com>,
	Paul Mundt <lethal@linux-sh.org>
Subject: [PATCH v3 07/29] serial: sh-sci: Support resources passed through platform resources
Date: Tue, 19 Nov 2013 14:02:08 +0000	[thread overview]
Message-ID: <1384869751-9786-8-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <1384869751-9786-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com>

Memory and IRQ resources are currently passed to the driver through
platform data. Support passing them through the standard platform
resources mechanism instead. This deprecates platform data resources.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Acked-by: Simon Horman <horms+renesas@verge.net.au>
---
 drivers/tty/serial/sh-sci.c | 65 ++++++++++++++++++++++++++++++++++-----------
 include/linux/serial_sci.h  |  8 +++---
 2 files changed, 53 insertions(+), 20 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index b0c9d24..c5abe5c 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -74,6 +74,7 @@ struct sci_port {
 	/* Function clock */
 	struct clk		*fclk;
 
+	int			irqs[SCIx_NR_IRQS];
 	char			*irqstr[SCIx_NR_IRQS];
 	char			*gpiostr[SCIx_NR_FNS];
 
@@ -1075,19 +1076,19 @@ static int sci_request_irq(struct sci_port *port)
 
 	for (i = j = 0; i < SCIx_NR_IRQS; i++, j++) {
 		struct sci_irq_desc *desc;
-		unsigned int irq;
+		int irq;
 
 		if (SCIx_IRQ_IS_MUXED(port)) {
 			i = SCIx_MUX_IRQ;
 			irq = up->irq;
 		} else {
-			irq = port->cfg->irqs[i];
+			irq = port->irqs[i];
 
 			/*
 			 * Certain port types won't support all of the
 			 * available interrupt sources.
 			 */
-			if (unlikely(!irq))
+			if (unlikely(irq < 0))
 				continue;
 		}
 
@@ -1112,7 +1113,7 @@ static int sci_request_irq(struct sci_port *port)
 
 out_noirq:
 	while (--i >= 0)
-		free_irq(port->cfg->irqs[i], port);
+		free_irq(port->irqs[i], port);
 
 out_nomem:
 	while (--j >= 0)
@@ -1130,16 +1131,16 @@ static void sci_free_irq(struct sci_port *port)
 	 * IRQ first.
 	 */
 	for (i = 0; i < SCIx_NR_IRQS; i++) {
-		unsigned int irq = port->cfg->irqs[i];
+		int irq = port->irqs[i];
 
 		/*
 		 * Certain port types won't support all of the available
 		 * interrupt sources.
 		 */
-		if (unlikely(!irq))
+		if (unlikely(irq < 0))
 			continue;
 
-		free_irq(port->cfg->irqs[i], port);
+		free_irq(port->irqs[i], port);
 		kfree(port->irqstr[i]);
 
 		if (SCIx_IRQ_IS_MUXED(port)) {
@@ -1655,7 +1656,7 @@ static void rx_timer_fn(unsigned long arg)
 
 	if (port->type = PORT_SCIFA || port->type = PORT_SCIFB) {
 		scr &= ~0x4000;
-		enable_irq(s->cfg->irqs[1]);
+		enable_irq(s->irqs[SCIx_RXI_IRQ]);
 	}
 	serial_port_out(port, SCSCR, scr | SCSCR_RIE);
 	dev_dbg(port->dev, "DMA Rx timed out\n");
@@ -2145,11 +2146,12 @@ static struct uart_ops sci_uart_ops = {
 };
 
 static int sci_init_single(struct platform_device *dev,
-				     struct sci_port *sci_port,
-				     unsigned int index,
-				     struct plat_sci_port *p)
+			   struct sci_port *sci_port, unsigned int index,
+			   struct plat_sci_port *p, bool early)
 {
 	struct uart_port *port = &sci_port->port;
+	const struct resource *res;
+	unsigned int i;
 	int ret;
 
 	sci_port->cfg	= p;
@@ -2158,6 +2160,38 @@ static int sci_init_single(struct platform_device *dev,
 	port->iotype	= UPIO_MEM;
 	port->line	= index;
 
+	if (dev->num_resources) {
+		/* Device has resources, use them. */
+		res = platform_get_resource(dev, IORESOURCE_MEM, 0);
+		if (res = NULL)
+			return -ENOMEM;
+
+		port->mapbase = res->start;
+
+		for (i = 0; i < ARRAY_SIZE(sci_port->irqs); ++i)
+			sci_port->irqs[i] = platform_get_irq(dev, i);
+
+		/* The SCI generates several interrupts. They can be muxed
+		 * together or connected to different interrupt lines. In the
+		 * muxed case only one interrupt resource is specified. In the
+		 * non-muxed case three or four interrupt resources are
+		 * specified, as the BRI interrupt is optional.
+		 */
+		if (sci_port->irqs[0] < 0)
+			return -ENXIO;
+
+		if (sci_port->irqs[1] < 0) {
+			sci_port->irqs[1] = sci_port->irqs[0];
+			sci_port->irqs[2] = sci_port->irqs[0];
+			sci_port->irqs[3] = sci_port->irqs[0];
+		}
+	} else {
+		/* No resources, use old-style platform data. */
+		port->mapbase = p->mapbase;
+		for (i = 0; i < ARRAY_SIZE(sci_port->irqs); ++i)
+			sci_port->irqs[i] = p->irqs[i] ? p->irqs[i] : -ENXIO;
+	}
+
 	switch (p->type) {
 	case PORT_SCIFB:
 		port->fifosize = 256;
@@ -2182,7 +2216,7 @@ static int sci_init_single(struct platform_device *dev,
 			return ret;
 	}
 
-	if (dev) {
+	if (!early) {
 		sci_port->iclk = clk_get(&dev->dev, "sci_ick");
 		if (IS_ERR(sci_port->iclk)) {
 			sci_port->iclk = clk_get(&dev->dev, "peripheral_clk");
@@ -2237,7 +2271,6 @@ static int sci_init_single(struct platform_device *dev,
 		p->error_mask |= (1 << p->overrun_bit);
 	}
 
-	port->mapbase		= p->mapbase;
 	port->type		= p->type;
 	port->flags		= UPF_FIXED_PORT | p->flags;
 	port->regshift		= p->regshift;
@@ -2249,7 +2282,7 @@ static int sci_init_single(struct platform_device *dev,
 	 *
 	 * For the muxed case there's nothing more to do.
 	 */
-	port->irq		= p->irqs[SCIx_RXI_IRQ];
+	port->irq		= sci_port->irqs[SCIx_RXI_IRQ];
 	port->irqflags		= 0;
 
 	port->serial_in		= sci_serial_in;
@@ -2381,7 +2414,7 @@ static int sci_probe_earlyprintk(struct platform_device *pdev)
 
 	early_serial_console.index = pdev->id;
 
-	sci_init_single(NULL, &sci_ports[pdev->id], pdev->id, cfg);
+	sci_init_single(pdev, &sci_ports[pdev->id], pdev->id, cfg, true);
 
 	serial_console_setup(&early_serial_console, early_serial_buf);
 
@@ -2448,7 +2481,7 @@ static int sci_probe_single(struct platform_device *dev,
 		return -EINVAL;
 	}
 
-	ret = sci_init_single(dev, sciport, index, p);
+	ret = sci_init_single(dev, sciport, index, p, false);
 	if (ret)
 		return ret;
 
diff --git a/include/linux/serial_sci.h b/include/linux/serial_sci.h
index eb787d4..68cf0bf 100644
--- a/include/linux/serial_sci.h
+++ b/include/linux/serial_sci.h
@@ -107,10 +107,10 @@ enum {
 }
 
 #define SCIx_IRQ_IS_MUXED(port)			\
-	((port)->cfg->irqs[SCIx_ERI_IRQ] =	\
-	 (port)->cfg->irqs[SCIx_RXI_IRQ]) ||	\
-	((port)->cfg->irqs[SCIx_ERI_IRQ] &&	\
-	 !(port)->cfg->irqs[SCIx_RXI_IRQ])
+	((port)->irqs[SCIx_ERI_IRQ] =	\
+	 (port)->irqs[SCIx_RXI_IRQ]) ||	\
+	((port)->irqs[SCIx_ERI_IRQ] &&	\
+	 ((port)->irqs[SCIx_RXI_IRQ] < 0))
 /*
  * SCI register subset common for all port types.
  * Not all registers will exist on all parts.
-- 
1.8.3.2


  parent reply	other threads:[~2013-11-19 14:02 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-19 14:02 [PATCH v3 00/29] Add OF support to the sh-sci serial port driver Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 01/29] serial: sh-sci: Sort headers alphabetically Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 02/29] serial: sh-sci: Remove baud rate calculation algorithm 5 Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 03/29] serial: sh-sci: Simplify baud rate calculation algorithms Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 04/29] serial: sh-sci: Remove duplicate interrupt check in verify port op Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 05/29] serial: sh-sci: Set the UPF_FIXED_PORT flag Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 06/29] serial: sh-sci: Don't check IRQ in verify port operation Laurent Pinchart
2013-11-19 14:02 ` Laurent Pinchart [this message]
2013-11-19 14:02 ` [PATCH v3 08/29] ARM: shmobile: sh7372: Use macros to declare SCIF devices Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 09/29] ARM: shmobile: sh73a0: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 10/29] ARM: shmobile: r8a7740: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 11/29] ARM: shmobile: r8a7779: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 12/29] ARM: shmobile: r7s72100: Don't define SCIF platform data in an array Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 13/29] ARM: shmobile: r8a73a4: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 14/29] ARM: shmobile: r8a7778: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 15/29] ARM: shmobile: r8a7790: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 16/29] ARM: shmobile: r8a7791: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 17/29] ARM: shmobile: sh7372: Declare SCIF register base and IRQ as resources Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 18/29] ARM: shmobile: sh73a0: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 19/29] ARM: shmobile: r7s72100: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 20/29] ARM: shmobile: r8a73a4: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 21/29] ARM: shmobile: r8a7740: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 22/29] ARM: shmobile: r8a7778: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 23/29] ARM: shmobile: r8a7779: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 24/29] ARM: shmobile: r8a7790: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 25/29] ARM: shmobile: r8a7791: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 26/29] sh: " Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 27/29] serial: sh-sci: Remove platform data mapbase and irqs fields Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 28/29] serial: sh-sci: Add device tree bindings documentation Laurent Pinchart
2013-11-19 14:02 ` [PATCH v3 29/29] serial: sh-sci: Add OF support Laurent Pinchart
2013-11-21  4:40 ` [PATCH v3 00/29] Add OF support to the sh-sci serial port driver Simon Horman
2013-11-21  7:17   ` Laurent Pinchart
2013-12-03 18:09     ` Greg KH
2013-12-03 18:28       ` Laurent Pinchart
2013-12-05  3:33         ` Simon Horman
2013-12-05  5:53           ` Laurent Pinchart
2013-12-05  7:03             ` Simon Horman
2013-12-05 10:13               ` Laurent Pinchart
2013-12-05 14:38                 ` Simon Horman
2013-12-09 18:59               ` Olof Johansson
2013-12-09 23:42                 ` Simon Horman
2013-12-10  1:03                   ` Laurent Pinchart
2013-12-20  1:48                   ` Laurent Pinchart

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=1384869751-9786-8-git-send-email-laurent.pinchart+renesas@ideasonboard.com \
    --to=laurent.pinchart+renesas@ideasonboard.com \
    --cc=hechtb+renesas@gmail.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=linux-sh@vger.kernel.org \
    /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).