summaryrefslogtreecommitdiffstats
path: root/drivers/mfd
diff options
context:
space:
mode:
authorAndrey Smirnov <andrew.smirnov@gmail.com>2017-03-08 14:08:51 -0800
committerSascha Hauer <s.hauer@pengutronix.de>2017-03-09 08:13:38 +0100
commit943a9eeac42f073518a94f1decd37529c0da5d42 (patch)
tree7791acbda0169faad2373c8b9d600d3f5ad40702 /drivers/mfd
parent2574148ad9a678838dcf361cd920531c5a542ec5 (diff)
downloadbarebox-943a9eeac42f073518a94f1decd37529c0da5d42.tar.gz
barebox-943a9eeac42f073518a94f1decd37529c0da5d42.tar.xz
regmap: Implement syscon_node_to_regmap()
Implement syscon_node_to_regmap() to simplify porting kernel code. Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/syscon.c54
1 files changed, 53 insertions, 1 deletions
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 6ef30ce195..957d9a7267 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -28,6 +28,34 @@ struct syscon {
struct device_node *np;
void __iomem *base;
struct list_head list;
+ struct regmap *regmap;
+};
+
+static int syscon_reg_write(void *context, unsigned int reg,
+ unsigned int val)
+{
+ struct syscon *syscon = context;
+ writel(val, syscon->base + reg);
+ return 0;
+}
+
+static int syscon_reg_read(void *context, unsigned int reg,
+ unsigned int *val)
+{
+ struct syscon *syscon = context;
+ *val = readl(syscon->base + reg);
+ return 0;
+}
+
+static const struct regmap_bus syscon_regmap_bus = {
+ .reg_write = syscon_reg_write,
+ .reg_read = syscon_reg_read,
+};
+
+static const struct regmap_config syscon_regmap_config = {
+ .reg_bits = 32,
+ .val_bits = 32,
+ .reg_stride = 4,
};
static struct syscon *of_syscon_register(struct device_node *np)
@@ -51,6 +79,10 @@ static struct syscon *of_syscon_register(struct device_node *np)
list_add_tail(&syscon->list, &syscon_list);
+ syscon->regmap = regmap_init(NULL,
+ &syscon_regmap_bus,
+ syscon,
+ &syscon_regmap_config);
return syscon;
err_map:
@@ -58,7 +90,7 @@ err_map:
return ERR_PTR(ret);
}
-static void __iomem *syscon_node_to_base(struct device_node *np)
+static struct syscon *node_to_syscon(struct device_node *np)
{
struct syscon *entry, *syscon = NULL;
@@ -74,6 +106,16 @@ static void __iomem *syscon_node_to_base(struct device_node *np)
if (IS_ERR(syscon))
return ERR_CAST(syscon);
+ return syscon;
+}
+
+static void __iomem *syscon_node_to_base(struct device_node *np)
+{
+ struct syscon *syscon = node_to_syscon(np);
+
+ if (IS_ERR(syscon))
+ return ERR_CAST(syscon);
+
return syscon->base;
}
@@ -108,6 +150,16 @@ void __iomem *syscon_base_lookup_by_phandle(struct device_node *np,
return syscon_node_to_base(syscon_np);
}
+struct regmap *syscon_node_to_regmap(struct device_node *np)
+{
+ struct syscon *syscon = node_to_syscon(np);
+
+ if (IS_ERR(syscon))
+ return ERR_CAST(syscon);
+
+ return syscon->regmap;
+}
+
static int syscon_probe(struct device_d *dev)
{
struct syscon *syscon;