aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mfd/syscon.c
diff options
context:
space:
mode:
authorPankaj Dubey <pankaj.dubey@samsung.com>2014-09-30 04:35:27 -0400
committerLee Jones <lee.jones@linaro.org>2014-11-25 11:18:41 -0500
commitbdb0066df96e74a4002125467ebe459feff1ebef (patch)
tree968441b2c02fc1ec7ef1a8a29e041e160c33ae29 /drivers/mfd/syscon.c
parentee828d02611f325a70ef6a3c1fd2dd1eb3bc9704 (diff)
mfd: syscon: Decouple syscon interface from platform devices
Currently a syscon entity can be only registered directly through a platform device that binds to a dedicated syscon driver. However in certain use cases it is desirable to make a device used with another driver a syscon interface provider. For example, certain SoCs (e.g. Exynos) contain system controller blocks which perform various functions such as power domain control, CPU power management, low power mode control, but in addition contain certain IP integration glue, such as various signal masks, coprocessor power control, etc. In such case, there is a need to have a dedicated driver for such system controller but also share registers with other drivers. The latter is where the syscon interface is helpful. In case of DT based platforms, this patch decouples syscon object from syscon platform driver, and allows to create syscon objects first time when it is required by calling of syscon_regmap_lookup_by APIs and keep a list of such syscon objects along with syscon provider device_nodes and regmap handles. For non-DT based platforms, this patch keeps syscon platform driver structure so that syscon can be probed and such non-DT based drivers can use syscon_regmap_lookup_by_pdev API and access regmap handles. Once all users of "syscon_regmap_lookup_by_pdev" migrated to DT based, we can completely remove platform driver of syscon, and keep only helper functions to get regmap handles. Suggested-by: Arnd Bergmann <arnd@arndb.de> Suggested-by: Tomasz Figa <tomasz.figa@gmail.com> Tested-by: Vivek Gautam <gautam.vivek@samsung.com> Tested-by: Javier Martinez Canillas <javier.martinez@collabora.co.uk> Signed-off-by: Pankaj Dubey <pankaj.dubey@samsung.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Tested-by: Heiko Stuebner <heiko@sntech.de> Reviewed-by: Heiko Stuebner <heiko@sntech.de> Signed-off-by: Lee Jones <lee.jones@linaro.org>
Diffstat (limited to 'drivers/mfd/syscon.c')
-rw-r--r--drivers/mfd/syscon.c96
1 files changed, 74 insertions, 22 deletions
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index ca15878ce5c0..72373b113885 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -15,6 +15,7 @@
15#include <linux/err.h> 15#include <linux/err.h>
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/list.h>
18#include <linux/of.h> 19#include <linux/of.h>
19#include <linux/of_address.h> 20#include <linux/of_address.h>
20#include <linux/of_platform.h> 21#include <linux/of_platform.h>
@@ -22,31 +23,94 @@
22#include <linux/platform_device.h> 23#include <linux/platform_device.h>
23#include <linux/regmap.h> 24#include <linux/regmap.h>
24#include <linux/mfd/syscon.h> 25#include <linux/mfd/syscon.h>
26#include <linux/slab.h>
25 27
26static struct platform_driver syscon_driver; 28static struct platform_driver syscon_driver;
27 29
30static DEFINE_SPINLOCK(syscon_list_slock);
31static LIST_HEAD(syscon_list);
32
28struct syscon { 33struct syscon {
34 struct device_node *np;
29 struct regmap *regmap; 35 struct regmap *regmap;
36 struct list_head list;
37};
38
39static struct regmap_config syscon_regmap_config = {
40 .reg_bits = 32,
41 .val_bits = 32,
42 .reg_stride = 4,
30}; 43};
31 44
32static int syscon_match_node(struct device *dev, void *data) 45static struct syscon *of_syscon_register(struct device_node *np)
33{ 46{
34 struct device_node *dn = data; 47 struct syscon *syscon;
48 struct regmap *regmap;
49 void __iomem *base;
50 int ret;
51 struct regmap_config syscon_config = syscon_regmap_config;
52
53 if (!of_device_is_compatible(np, "syscon"))
54 return ERR_PTR(-EINVAL);
55
56 syscon = kzalloc(sizeof(*syscon), GFP_KERNEL);
57 if (!syscon)
58 return ERR_PTR(-ENOMEM);
59
60 base = of_iomap(np, 0);
61 if (!base) {
62 ret = -ENOMEM;
63 goto err_map;
64 }
65
66 /* Parse the device's DT node for an endianness specification */
67 if (of_property_read_bool(np, "big-endian"))
68 syscon_config.val_format_endian = REGMAP_ENDIAN_BIG;
69 else if (of_property_read_bool(np, "little-endian"))
70 syscon_config.val_format_endian = REGMAP_ENDIAN_LITTLE;
71
72 regmap = regmap_init_mmio(NULL, base, &syscon_config);
73 if (IS_ERR(regmap)) {
74 pr_err("regmap init failed\n");
75 ret = PTR_ERR(regmap);
76 goto err_regmap;
77 }
78
79 syscon->regmap = regmap;
80 syscon->np = np;
81
82 spin_lock(&syscon_list_slock);
83 list_add_tail(&syscon->list, &syscon_list);
84 spin_unlock(&syscon_list_slock);
35 85
36 return (dev->of_node == dn) ? 1 : 0; 86 return syscon;
87
88err_regmap:
89 iounmap(base);
90err_map:
91 kfree(syscon);
92 return ERR_PTR(ret);
37} 93}
38 94
39struct regmap *syscon_node_to_regmap(struct device_node *np) 95struct regmap *syscon_node_to_regmap(struct device_node *np)
40{ 96{
41 struct syscon *syscon; 97 struct syscon *entry, *syscon = NULL;
42 struct device *dev;
43 98
44 dev = driver_find_device(&syscon_driver.driver, NULL, np, 99 spin_lock(&syscon_list_slock);
45 syscon_match_node);
46 if (!dev)
47 return ERR_PTR(-EPROBE_DEFER);
48 100
49 syscon = dev_get_drvdata(dev); 101 list_for_each_entry(entry, &syscon_list, list)
102 if (entry->np == np) {
103 syscon = entry;
104 break;
105 }
106
107 spin_unlock(&syscon_list_slock);
108
109 if (!syscon)
110 syscon = of_syscon_register(np);
111
112 if (IS_ERR(syscon))
113 return ERR_CAST(syscon);
50 114
51 return syscon->regmap; 115 return syscon->regmap;
52} 116}
@@ -110,17 +174,6 @@ struct regmap *syscon_regmap_lookup_by_phandle(struct device_node *np,
110} 174}
111EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_phandle); 175EXPORT_SYMBOL_GPL(syscon_regmap_lookup_by_phandle);
112 176
113static const struct of_device_id of_syscon_match[] = {
114 { .compatible = "syscon", },
115 { },
116};
117
118static struct regmap_config syscon_regmap_config = {
119 .reg_bits = 32,
120 .val_bits = 32,
121 .reg_stride = 4,
122};
123
124static int syscon_probe(struct platform_device *pdev) 177static int syscon_probe(struct platform_device *pdev)
125{ 178{
126 struct device *dev = &pdev->dev; 179 struct device *dev = &pdev->dev;
@@ -167,7 +220,6 @@ static struct platform_driver syscon_driver = {
167 .driver = { 220 .driver = {
168 .name = "syscon", 221 .name = "syscon",
169 .owner = THIS_MODULE, 222 .owner = THIS_MODULE,
170 .of_match_table = of_syscon_match,
171 }, 223 },
172 .probe = syscon_probe, 224 .probe = syscon_probe,
173 .id_table = syscon_ids, 225 .id_table = syscon_ids,