linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: lee.jones@linaro.org (Lee Jones)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 03/15] mfd: Make MFD core code Device Tree and IRQ domain aware
Date: Wed, 20 Jun 2012 13:56:39 +0100	[thread overview]
Message-ID: <1340197011-5435-4-git-send-email-lee.jones@linaro.org> (raw)
In-Reply-To: <1340197011-5435-1-git-send-email-lee.jones@linaro.org>

During Device Tree enablement of the ab8500 and db8500-prcmu drivers,
a decision was made to omit registration through the MFD API and use
Device Tree directly. However, because MFD devices have a different
address space and the ab8500 and db8500 both use I2C to communicate,
this causes issues with address translation during execution of
of_platform_populate(). So the solution is to make the MFD core aware
of Device Tree and have it assign the correct node pointers instead.

To make this work the MFD core also needs to be awere of IRQ domains,
as Device Tree insists on IRQ domain compatibility. So, instead of
providing an irq-base via platform code, in the DT case we simply
look up the IRQ domain and map to the correct virtual IRQ.

Cc: Samuel Ortiz <sameo@linux.intel.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/mfd/mfd-core.c   |   31 +++++++++++++++++++++++++++----
 include/linux/mfd/core.h |    1 +
 2 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/mfd-core.c b/drivers/mfd/mfd-core.c
index ffc3d48..effc4f5 100644
--- a/drivers/mfd/mfd-core.c
+++ b/drivers/mfd/mfd-core.c
@@ -18,6 +18,8 @@
 #include <linux/pm_runtime.h>
 #include <linux/slab.h>
 #include <linux/module.h>
+#include <linux/irqdomain.h>
+#include <linux/of.h>
 
 int mfd_cell_enable(struct platform_device *pdev)
 {
@@ -76,6 +78,8 @@ static int mfd_add_device(struct device *parent, int id,
 {
 	struct resource *res;
 	struct platform_device *pdev;
+	struct device_node *np = NULL;
+	struct irq_domain *domain = NULL;
 	int ret = -ENOMEM;
 	int r;
 
@@ -89,6 +93,18 @@ static int mfd_add_device(struct device *parent, int id,
 
 	pdev->dev.parent = parent;
 
+	if (parent->of_node) {
+		if (cell->of_compatible) {
+			for_each_child_of_node(parent->of_node, np) {
+				if (of_device_is_compatible(np, cell->of_compatible)) {
+					pdev->dev.of_node = np;
+					domain = irq_find_host(parent->of_node);
+					break;
+				}
+			}
+		}
+	}
+
 	if (cell->pdata_size) {
 		ret = platform_device_add_data(pdev,
 					cell->platform_data, cell->pdata_size);
@@ -112,10 +128,17 @@ static int mfd_add_device(struct device *parent, int id,
 			res[r].end = mem_base->start +
 				cell->resources[r].end;
 		} else if (cell->resources[r].flags & IORESOURCE_IRQ) {
-			res[r].start = irq_base +
-				cell->resources[r].start;
-			res[r].end   = irq_base +
-				cell->resources[r].end;
+			if (domain) {
+				/* Unable to create mappings for IRQ ranges. */
+				WARN_ON(cell->resources[r].start != cell->resources[r].end);
+				res[r].start = res[r].end = irq_create_mapping(
+					domain, cell->resources[r].start);
+			} else {
+				res[r].start = irq_base +
+					cell->resources[r].start;
+				res[r].end   = irq_base +
+					cell->resources[r].end;
+			}
 		} else {
 			res[r].parent = cell->resources[r].parent;
 			res[r].start = cell->resources[r].start;
diff --git a/include/linux/mfd/core.h b/include/linux/mfd/core.h
index 4e76163..99b7eb1 100644
--- a/include/linux/mfd/core.h
+++ b/include/linux/mfd/core.h
@@ -36,6 +36,7 @@ struct mfd_cell {
 	/* platform data passed to the sub devices drivers */
 	void			*platform_data;
 	size_t			pdata_size;
+	const char		*of_compatible;
 
 	/*
 	 * These resources can be specified relative to the parent device.
-- 
1.7.9.5

  parent reply	other threads:[~2012-06-20 12:56 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-20 12:56 [PATCH 00/15] Device Tree related re-works and clean-ups Lee Jones
2012-06-20 12:56 ` [PATCH 01/15] mfd: Add IRQ domain support for the AB8500 Lee Jones
2012-06-29 14:51   ` Samuel Ortiz
2012-06-20 12:56 ` [PATCH 02/15] mfd: Generically describe interactions with the DB8500 PRCMU Lee Jones
2012-06-29 14:53   ` Samuel Ortiz
2012-06-20 12:56 ` Lee Jones [this message]
2012-06-29 14:55   ` [PATCH 03/15] mfd: Make MFD core code Device Tree and IRQ domain aware Samuel Ortiz
2012-06-29 14:52     ` Lee Jones
2012-06-29 18:49       ` Samuel Ortiz
2012-07-02  9:57         ` Lee Jones
2012-07-02 15:01           ` Samuel Ortiz
2012-06-20 12:56 ` [PATCH 04/15] mfd: ab8500: Register devices using the newly DT:ed MFD API Lee Jones
2012-06-29 15:09   ` Samuel Ortiz
2012-06-29 16:04     ` Lee Jones
2012-06-29 18:50       ` Samuel Ortiz
2012-07-02 10:03         ` Lee Jones
2012-07-02 15:14           ` Samuel Ortiz
2012-07-04 15:29             ` Lee Jones
2012-06-20 12:56 ` [PATCH 05/15] mfd: db8500-prcmu: " Lee Jones
2012-06-29 15:11   ` Samuel Ortiz
2012-06-20 12:56 ` [PATCH 06/15] mfd: Register the ab8500 from db8500-prcmu using the " Lee Jones
2012-06-29 15:15   ` Samuel Ortiz
2012-06-20 12:56 ` [PATCH 07/15] i2c: Add Device Tree support to the Nomadik I2C driver Lee Jones
2012-06-20 19:30   ` Linus Walleij
2012-06-21  6:47     ` Srinidhi Kasagar
2012-06-20 12:56 ` [PATCH 08/15] regulator: Stop initialising AB8500's registers during bring-up Lee Jones
2012-06-20 13:08   ` Mark Brown
2012-06-20 13:19     ` Lee Jones
2012-06-20 13:26   ` Mark Brown
2012-06-20 12:56 ` [PATCH 09/15] pinctrl: pinctrl-nomadik: Fix possible memory leak Lee Jones
2012-06-20 12:56 ` [PATCH 10/15] pinctrl: pinctrl-nomadik: Append sleepmode property with vendor specific prefixes Lee Jones
2012-06-20 12:56 ` [PATCH 11/15] ARM: ux500: Remove AB8500 regulator register initialisation information Lee Jones
2012-06-20 12:56 ` [PATCH 12/15] ARM: ux500: Ensure vendor specific properties have the vendor's identifier Lee Jones
2012-06-20 12:56 ` [PATCH 13/15] ARM: ux500: Remove temporary snowball_of_platform_devs enablement structure Lee Jones
2012-06-20 12:56 ` [PATCH 14/15] ARM: ux500: Remove PMU platform registration when booting with DT Lee Jones
2012-06-20 12:56 ` [PATCH 15/15] ARM: perf: handle muxed CPU IRQ lines Lee Jones
2012-06-20 13:28   ` Will Deacon
2012-06-20 13:44     ` Lee Jones
2012-06-20 14:01       ` Will Deacon
2012-06-20 14:13         ` Lee Jones

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=1340197011-5435-4-git-send-email-lee.jones@linaro.org \
    --to=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.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).