mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: barebox@lists.infradead.org
Cc: Andrey Smirnov <andrew.smirnov@gmail.com>
Subject: [PATCH 3/7] mfd: syscon: Decouple syscon interface from platform devices
Date: Wed, 13 Jul 2016 23:11:01 -0700	[thread overview]
Message-ID: <1468476665-26409-3-git-send-email-andrew.smirnov@gmail.com> (raw)
In-Reply-To: <1468476665-26409-1-git-send-email-andrew.smirnov@gmail.com>

Follow Linux Kernel change introduced in
bdb0066df96e74a4002125467ebe459feff1ebef and avoid device/driver model
for DT-based platforms. See the original kernel commit for the rationale.

Also make syscon_base_lookup_by_pdevname() behave the same way as its
kernel counterpart in the case whern "property" argument is NULL.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 drivers/mfd/syscon.c | 79 ++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 61 insertions(+), 18 deletions(-)

diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index ac46122..5fd22dd 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -17,15 +17,68 @@
 #include <driver.h>
 #include <malloc.h>
 #include <xfuncs.h>
-
+#include <of_address.h>
 #include <linux/err.h>
 
 #include <mfd/syscon.h>
 
+static LIST_HEAD(syscon_list);
+
 struct syscon {
+	struct device_node *np;
 	void __iomem *base;
+	struct list_head list;
 };
 
+static struct syscon *of_syscon_register(struct device_node *np)
+{
+	int ret;
+	struct syscon *syscon;
+	struct resource res;
+
+	if (!of_device_is_compatible(np, "syscon"))
+		return ERR_PTR(-EINVAL);
+
+	syscon = xzalloc(sizeof(*syscon));
+
+	if (of_address_to_resource(np, 0, &res)) {
+		ret = -ENOMEM;
+		goto err_map;
+	}
+
+	syscon->base = IOMEM(res.start);
+	syscon->np   = np;
+
+	list_add_tail(&syscon->list, &syscon_list);
+
+	return syscon;
+
+err_map:
+	kfree(syscon);
+	return ERR_PTR(ret);
+}
+
+void __iomem *syscon_node_to_base(struct device_node *np)
+{
+	struct syscon *entry, *syscon = NULL;
+
+	list_for_each_entry(entry, &syscon_list, list)
+		if (entry->np == np) {
+			syscon = entry;
+			break;
+		}
+
+	if (!syscon)
+		syscon = of_syscon_register(np);
+
+	if (IS_ERR(syscon))
+		return ERR_CAST(syscon);
+
+	return syscon->base;
+}
+EXPORT_SYMBOL_GPL(syscon_node_to_regmap);
+
+
 void __iomem *syscon_base_lookup_by_pdevname(const char *s)
 {
 	struct syscon *syscon;
@@ -44,21 +97,17 @@ void __iomem *syscon_base_lookup_by_pdevname(const char *s)
 void __iomem *syscon_base_lookup_by_phandle(struct device_node *np,
 					    const char *property)
 {
-	struct device_node *node;
-	struct syscon *syscon;
-	struct device_d *dev;
+	struct device_node *syscon_np;
 
-	node = of_parse_phandle(np, property, 0);
-	if (!node)
-		return ERR_PTR(-ENODEV);
+	if (property)
+		syscon_np = of_parse_phandle(np, property, 0);
+	else
+		syscon_np = np;
 
-	dev = of_find_device_by_node(node);
-	if (!dev)
+	if (!syscon_np)
 		return ERR_PTR(-ENODEV);
 
-	syscon = dev->priv;
-
-	return syscon->base;
+	return syscon_node_to_base(syscon_np);
 }
 
 static int syscon_probe(struct device_d *dev)
@@ -89,16 +138,10 @@ static struct platform_device_id syscon_ids[] = {
 	{ }
 };
 
-static struct of_device_id of_syscon_match[] = {
-	{ .compatible = "syscon" },
-	{ },
-};
-
 static struct driver_d syscon_driver = {
 	.name		= "syscon",
 	.probe		= syscon_probe,
 	.id_table	= syscon_ids,
-	.of_compatible	= DRV_OF_COMPAT(of_syscon_match),
 };
 
 static int __init syscon_init(void)
-- 
2.5.5


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-07-14  6:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-14  6:10 [PATCH 1/7] Revert "syscon: Decrease driver registration priority" Andrey Smirnov
2016-07-14  6:11 ` [PATCH 2/7] mfd: syscon: Don't call request_iomem_region() Andrey Smirnov
2016-07-15  5:53   ` Sascha Hauer
2016-07-15  9:11     ` Re[2]: " Alexander Shiyan
2016-07-14  6:11 ` Andrey Smirnov [this message]
2016-07-15  5:59   ` [PATCH 3/7] mfd: syscon: Decouple syscon interface from platform devices Sascha Hauer
2016-07-15 21:50     ` Andrey Smirnov
2016-07-18  6:18       ` Sascha Hauer
2016-07-14  6:11 ` [PATCH 4/7] mfd: syscon: Don't check xzalloc return for NULL Andrey Smirnov
2016-07-14  6:11 ` [PATCH 5/7] mfd: syscon: Use IOMEM instead of explicit cast Andrey Smirnov
2016-07-14  6:11 ` [PATCH 6/7] imx_thermal: Remove leftover debug output Andrey Smirnov
2016-07-14  6:11 ` [PATCH 7/7] i.MX: ocotp: Register regmap against orignal device Andrey Smirnov

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=1468476665-26409-3-git-send-email-andrew.smirnov@gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@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