All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Balbi <balbi@ti.com>
To: Tony Lindgren <tony@atomide.com>
Cc: Linux OMAP Mailing List <linux-omap@vger.kernel.org>,
	Felipe Balbi <balbi@ti.com>
Subject: [PATCH 13/27] cbus: tahvo: start using irq_chip
Date: Thu, 13 Oct 2011 11:34:48 +0300	[thread overview]
Message-ID: <1318494902-13093-13-git-send-email-balbi@ti.com> (raw)
In-Reply-To: <1318494902-13093-1-git-send-email-balbi@ti.com>

in order to chieve that, we needed to allocate
our children devices (currently only one) and
fix up the irq handler.

Signed-off-by: Felipe Balbi <balbi@ti.com>
---
 arch/arm/mach-omap1/board-nokia770.c |    6 --
 arch/arm/mach-omap2/board-n8x0.c     |    6 --
 drivers/cbus/tahvo.c                 |  110 ++++++++++++++++++++++++---------
 3 files changed, 80 insertions(+), 42 deletions(-)

diff --git a/arch/arm/mach-omap1/board-nokia770.c b/arch/arm/mach-omap1/board-nokia770.c
index 95b90a7..3a72a44 100644
--- a/arch/arm/mach-omap1/board-nokia770.c
+++ b/arch/arm/mach-omap1/board-nokia770.c
@@ -155,11 +155,6 @@ static struct platform_device tahvo_device = {
 	},
 };
 
-static struct platform_device tahvo_usb_device = {
-	.name		= "tahvo-usb",
-	.id		= -1,
-};
-
 static void __init nokia770_cbus_init(void)
 {
 	int		ret;
@@ -200,7 +195,6 @@ static void __init nokia770_cbus_init(void)
 
 	tahvo_resource[0].start = gpio_to_irq(40);
 	platform_device_register(&tahvo_device);
-	platform_device_register(&tahvo_usb_device);
 }
 
 #else
diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
index f81f7ee..bf2e51f 100644
--- a/arch/arm/mach-omap2/board-n8x0.c
+++ b/arch/arm/mach-omap2/board-n8x0.c
@@ -251,11 +251,6 @@ static struct platform_device tahvo_device = {
 	},
 };
 
-static struct platform_device tahvo_usb_device = {
-	.name		= "tahvo-usb",
-	.id		= -1,
-};
-
 static void __init n8x0_cbus_init(void)
 {
 	int		ret;
@@ -297,7 +292,6 @@ static void __init n8x0_cbus_init(void)
 
 	tahvo_resource[0].start = gpio_to_irq(111);
 	platform_device_register(&tahvo_device);
-	platform_device_register(&tahvo_usb_device);
 }
 
 #else
diff --git a/drivers/cbus/tahvo.c b/drivers/cbus/tahvo.c
index 3aaf0eb..f01defc 100644
--- a/drivers/cbus/tahvo.c
+++ b/drivers/cbus/tahvo.c
@@ -215,39 +215,26 @@ EXPORT_SYMBOL(tahvo_set_backlight_level);
 
 static irqreturn_t tahvo_irq_handler(int irq, void *_tahvo)
 {
-	struct tahvo_irq_handler_desc *hnd;
-
 	struct tahvo		*tahvo = _tahvo;
 	u16			id;
 	u16			im;
-	int			i;
-
-	for (;;) {
-		id = __tahvo_read_reg(tahvo, TAHVO_REG_IDR);
-		im = ~__tahvo_read_reg(tahvo, TAHVO_REG_IMR);
-		id &= im;
-
-		if (!id)
-			break;
-
-		for (i = 0; id != 0; i++, id >>= 1) {
-			if (!(id & 1))
-				continue;
-			hnd = &tahvo_irq_handlers[i];
-			if (hnd->func == NULL) {
-				/* Spurious tahvo interrupt - just ack it */
-				dev_err(tahvo->dev, "Spurious interrupt "
-						 "(id %d)\n", i);
-				tahvo_disable_irq(i);
-				tahvo_ack_irq(i);
-				continue;
-			}
-			hnd->func(hnd->arg);
-			/*
-			 * Don't acknowledge the interrupt here
-			 * It must be done explicitly
-			 */
-		}
+
+	id = __tahvo_read_reg(tahvo, TAHVO_REG_IDR);
+	im = __tahvo_read_reg(tahvo, TAHVO_REG_IMR);
+	id &= ~im;
+
+	if (!id) {
+		dev_vdbg(tahvo->dev, "No IRQ, spurious ?\n");
+		return IRQ_NONE;
+	}
+
+	while (id) {
+		unsigned long	pending = __ffs(id);
+		unsigned int	irq;
+
+		id &= ~BIT(pending);
+		irq = pending + tahvo->irq_base;
+		handle_nested_irq(irq);
 	}
 
 	return IRQ_HANDLED;
@@ -397,6 +384,63 @@ static void tahvo_irq_init(struct tahvo *tahvo)
 
 /* -------------------------------------------------------------------------- */
 
+static struct resource generic_resources[] = {
+	{
+		.start		= -EINVAL,	/* fixed later */
+		.flags		= IORESOURCE_IRQ,
+	},
+};
+
+static struct device *tahvo_allocate_child(const char *name,
+		struct device *parent, int irq)
+{
+	struct platform_device	*pdev;
+	int			ret;
+
+	pdev = platform_device_alloc(name, -1);
+	if (!pdev) {
+		dev_dbg(parent, "can't allocate %s\n", name);
+		goto err0;
+	}
+
+	pdev->dev.parent = parent;
+
+	generic_resources[0].start = irq;
+
+	ret = platform_device_add_resources(pdev,
+			generic_resources, ARRAY_SIZE(generic_resources));
+	if (ret < 0) {
+		dev_dbg(parent, "can't add resources to %s\n", name);
+		goto err1;
+	}
+
+	ret = platform_device_add(pdev);
+	if (ret < 0) {
+		dev_dbg(parent, "can't add %s\n", name);
+		goto err1;
+	}
+
+	return &pdev->dev;
+
+err1:
+	platform_device_put(pdev);
+
+err0:
+	return NULL;
+}
+
+static int tahvo_allocate_children(struct device *parent, int irq_base)
+{
+	struct device		*child;
+
+	child = tahvo_allocate_child("tahvo-usb", parent,
+			irq_base + TAHVO_INT_VBUSON);
+	if (!child)
+		return -ENOMEM;
+
+	return 0;
+}
+
 static int __devinit tahvo_probe(struct platform_device *pdev)
 {
 	struct tahvo		*tahvo;
@@ -450,6 +494,12 @@ static int __devinit tahvo_probe(struct platform_device *pdev)
 		goto err2;
 	}
 
+	ret = tahvo_allocate_children(&pdev->dev, tahvo->irq_base);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "failed to allocate children\n");
+		goto err2;
+	}
+
 	dev_err(&pdev->dev, "%s v%d.%d found\n",
 			tahvo->is_betty ? "Betty" : "Tahvo",
 			(rev >> 4) & 0x0f, rev & 0x0f);
-- 
1.7.6.396.ge0613


  parent reply	other threads:[~2011-10-13  8:35 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-13  8:34 [PATCH 01/27] cbus: tahvo: convert spinlock into mutex Felipe Balbi
2011-10-13  8:34 ` [PATCH 02/27] cbus: tahvo: move to __devinit/__devexit sections Felipe Balbi
2011-10-13  8:34 ` [PATCH 03/27] cbus: tahvo: a switch looks better Felipe Balbi
2011-10-13  8:34 ` [PATCH 04/27] cbus: tahvo: don't go over 80 columns Felipe Balbi
2011-10-13  8:34 ` [PATCH 05/27] cbus: tahvo: drop the tasklet Felipe Balbi
2011-10-13  8:34 ` [PATCH 06/27] cbus: retu: set IRQF_ONESHOT flag Felipe Balbi
2011-10-13  8:34 ` [PATCH 07/27] cbus: tahvo: git it a context structure Felipe Balbi
2011-10-13  8:34 ` [PATCH 08/27] cbus: tahvo: pass tahvo to IRQ handler Felipe Balbi
2011-10-13  8:34 ` [PATCH 09/27] cbus: tahvo: introduce __tahvo_(read/write)_reg Felipe Balbi
2011-10-13  8:34 ` [PATCH 10/27] cbus: tahvo: drop some unneded defines Felipe Balbi
2011-10-13  8:34 ` [PATCH 11/27] cbus: retu: IRQ demux optimization Felipe Balbi
2011-10-13  8:34 ` [PATCH 12/27] cbus: tahvo: give it an irq_chip Felipe Balbi
2011-10-13  8:34 ` Felipe Balbi [this message]
2011-10-13  8:34 ` [PATCH 14/27] cbus: tahvo: usb: fix up to use threaded irqs Felipe Balbi
2011-10-13  8:34 ` [PATCH 15/27] cbus: tahvo drop the legacy interfaces Felipe Balbi
2011-10-13  8:34 ` [PATCH 16/27] cbus: tahvo: usb: drop unused variable Felipe Balbi
2011-10-13  8:34 ` [PATCH 17/27] cbus: tahvo: no need to mask interrupts on exit Felipe Balbi
2011-10-13  8:34 ` [PATCH 18/27] cbus: tahvo: drop the get_status hack Felipe Balbi
2011-10-13  8:34 ` [PATCH 19/27] cbus: tahvo: drop more unused interfaces Felipe Balbi
2011-10-13  8:34 ` [PATCH 20/27] cbus: tahvo: pass child device pointer Felipe Balbi
2011-10-13  8:34 ` [PATCH 21/27] cbus: tahvo: drop backlight interfaces Felipe Balbi
2011-10-13  8:34 ` [PATCH 22/27] cbus: tahvo: drop static global pointer Felipe Balbi
2011-10-13  8:34 ` [PATCH 23/27] cbus: tahvo: prepare for children without IRQ Felipe Balbi
2011-10-13  8:34 ` [PATCH 24/27] cbus: tahvo: allocate tahvo-pwm child Felipe Balbi
2011-10-13  8:35 ` [PATCH 25/27] cbus: fix compile issue on tahvo and retu Felipe Balbi
2011-10-13  8:35 ` [PATCH 26/27] cbus: use platform_driver_register " Felipe Balbi
2011-10-13  8:35 ` [PATCH 27/27] cbus: mark dependencies for ARCH_OMAP Felipe Balbi
2011-10-17 17:20 ` [PATCH 01/27] cbus: tahvo: convert spinlock into mutex Tony Lindgren
2011-10-17 18:04   ` Felipe Balbi
2011-10-17 18:19     ` Tony Lindgren
2011-10-17 18:26       ` Felipe Balbi

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=1318494902-13093-13-git-send-email-balbi@ti.com \
    --to=balbi@ti.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=tony@atomide.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.