All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] mfd: syscon: Add non-DT support
@ 2013-02-18 14:42 Alexander Shiyan
  2013-02-18 16:02 ` Arnd Bergmann
  0 siblings, 1 reply; 25+ messages in thread
From: Alexander Shiyan @ 2013-02-18 14:42 UTC (permalink / raw)
  To: linux-kernel
  Cc: Dong Aisheng, Samuel Ortiz, Mark Brown, Arnd Bergmann, Alexander Shiyan

This patch allow using syscon driver from the platform data, i.e.
possibility using driver on systems without oftree support.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/mfd/Kconfig  |  1 -
 drivers/mfd/syscon.c | 76 +++++++++++++++++++++++++++++++++++++++-------------
 2 files changed, 57 insertions(+), 20 deletions(-)

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 671f5b1..8fdd87e 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -1070,7 +1070,6 @@ config MFD_STA2X11
 
 config MFD_SYSCON
 	bool "System Controller Register R/W Based on Regmap"
-	depends on OF
 	select REGMAP_MMIO
 	help
 	  Select this option to enable accessing system control registers
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 4a7ed5a..3c0abcb 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -28,7 +28,7 @@ struct syscon {
 	struct regmap *regmap;
 };
 
-static int syscon_match(struct device *dev, void *data)
+static int syscon_match_node(struct device *dev, void *data)
 {
 	struct device_node *dn = data;
 
@@ -41,7 +41,7 @@ struct regmap *syscon_node_to_regmap(struct device_node *np)
 	struct device *dev;
 
 	dev = driver_find_device(&syscon_driver.driver, NULL, np,
-				 syscon_match);
+				 syscon_match_node);
 	if (!dev)
 		return ERR_PTR(-EPROBE_DEFER);
 
@@ -51,19 +51,41 @@ struct regmap *syscon_node_to_regmap(struct device_node *np)
 }
 EXPORT_SYMBOL_GPL(syscon_node_to_regmap);
 
+static int syscon_match_id(struct device *dev, void *data)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+	const struct platform_device_id *id = platform_get_device_id(pdev);
+
+	if (id)
+		return !strcmp(id->name, (const char *)data);
+
+	return 0;
+}
+
 struct regmap *syscon_regmap_lookup_by_compatible(const char *s)
 {
 	struct device_node *syscon_np;
 	struct regmap *regmap;
+	struct syscon *syscon;
+	struct device *dev;
 
 	syscon_np = of_find_compatible_node(NULL, NULL, s);
-	if (!syscon_np)
+	if (syscon_np) {
+		regmap = syscon_node_to_regmap(syscon_np);
+		of_node_put(syscon_np);
+
+		return regmap;
+	}
+
+	/* Fallback to search by id_entry.name string */
+	dev = driver_find_device(&syscon_driver.driver, NULL, (void *)s,
+				 syscon_match_id);
+	if (!dev)
 		return ERR_PTR(-ENODEV);
 
-	regmap = syscon_node_to_regmap(syscon_np);
-	of_node_put(syscon_np);
+	syscon = dev_get_drvdata(dev);
 
-	return regmap;
+	return syscon->regmap;
 }
 EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_compatible);
 
@@ -100,37 +122,53 @@ static int syscon_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
 	struct syscon *syscon;
-	struct resource res;
+	struct resource *res, res_of;
 	int ret;
 
-	if (!np)
-		return -ENOENT;
-
 	syscon = devm_kzalloc(dev, sizeof(struct syscon),
 			    GFP_KERNEL);
 	if (!syscon)
 		return -ENOMEM;
 
-	syscon->base = of_iomap(np, 0);
-	if (!syscon->base)
-		return -EADDRNOTAVAIL;
-
-	ret = of_address_to_resource(np, 0, &res);
-	if (ret)
-		return ret;
+	if (IS_ENABLED(CONFIG_OF) && np) {
+		syscon->base = of_iomap(np, 0);
+		if (!syscon->base)
+			return -EADDRNOTAVAIL;
+
+		res = &res_of;
+		ret = of_address_to_resource(np, 0, res);
+		if (ret) {
+			iounmap(syscon->base);
+			return ret;
+		}
+	} else {
+		res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+		if (!res)
+			return -ENOENT;
+
+		if (!devm_request_mem_region(dev, res->start,
+					     resource_size(res),
+					     dev_name(&pdev->dev)))
+			return -EBUSY;
+
+		syscon->base = ioremap(res->start, resource_size(res));
+		if (!syscon->base)
+			return -EADDRNOTAVAIL;
+	}
 
-	syscon_regmap_config.max_register = res.end - res.start - 3;
+	syscon_regmap_config.max_register = res->end - res->start - 3;
 	syscon->regmap = devm_regmap_init_mmio(dev, syscon->base,
 					&syscon_regmap_config);
 	if (IS_ERR(syscon->regmap)) {
 		dev_err(dev, "regmap init failed\n");
+		iounmap(syscon->base);
 		return PTR_ERR(syscon->regmap);
 	}
 
 	platform_set_drvdata(pdev, syscon);
 
 	dev_info(dev, "syscon regmap start 0x%x end 0x%x registered\n",
-		res.start, res.end);
+		res->start, res->end);
 
 	return 0;
 }
-- 
1.7.12.4


^ permalink raw reply related	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2013-02-21 15:27 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-18 14:42 [PATCH v3] mfd: syscon: Add non-DT support Alexander Shiyan
2013-02-18 16:02 ` Arnd Bergmann
2013-02-19  5:52   ` Dong Aisheng
2013-02-19  7:03   ` Re[2]: " Alexander Shiyan
2013-02-19  7:55     ` Dong Aisheng
2013-02-19  8:02       ` Dong Aisheng
2013-02-19  8:56     ` Re[4]: " Alexander Shiyan
2013-02-19  9:58       ` Dong Aisheng
2013-02-19 10:54       ` Re[6]: " Alexander Shiyan
2013-02-20  5:20         ` Dong Aisheng
2013-02-20  5:41         ` Re[8]: " Alexander Shiyan
2013-02-20  6:01           ` Dong Aisheng
2013-02-20 10:06           ` Arnd Bergmann
2013-02-20 11:05             ` Dong Aisheng
2013-02-20 11:14               ` Arnd Bergmann
2013-02-20 11:28                 ` Dong Aisheng
2013-02-20 12:16                   ` Arnd Bergmann
2013-02-20 12:47                 ` Re[10]: " Alexander Shiyan
2013-02-20 15:00                   ` Arnd Bergmann
2013-02-20 16:06                     ` Re[12]: " Alexander Shiyan
2013-02-20 17:16                       ` Arnd Bergmann
2013-02-20 17:27                         ` Re[14]: " Alexander Shiyan
2013-02-20 21:27                           ` Arnd Bergmann
2013-02-21 15:27                             ` Re[16]: " Alexander Shiyan
2013-02-19 10:49     ` Re[2]: " Arnd Bergmann

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.