summaryrefslogtreecommitdiff
path: root/drivers/mfd
diff options
context:
space:
mode:
authorSanchayan Maity <maitysanchayan@gmail.com>2016-03-04 17:01:19 +0530
committerStefan Agner <stefan.agner@toradex.com>2016-03-09 13:34:01 -0800
commit0c2d2e753259d8b84fa0cd3dfc5889e388051025 (patch)
tree9bdd05ddbd292b5bb183c09c625cbbe937316e7e /drivers/mfd
parentcac87642fd3e8239af3a20541232892366728195 (diff)
mfd: syscon: Introduce syscon_regmap_read_from_offset
Currently syscon does not provide an abstraction to access a register from syscon reference like below ocotp-cfg1 = <&ocotp 0x20> syscon_regmap_read_from_offset provides a generic abstraction to access a register from syscon reference as above. It allows to specify the node and node name of phandle reference, reading the offset from the node entry and providing the value from the offset in the register map. Signed-off-by: Sanchayan Maity <maitysanchayan@gmail.com>
Diffstat (limited to 'drivers/mfd')
-rw-r--r--drivers/mfd/syscon.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 176bf0fa2685..34d71de1bc1c 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -116,6 +116,36 @@ struct regmap *syscon_node_to_regmap(struct device_node *np)
}
EXPORT_SYMBOL_GPL(syscon_node_to_regmap);
+int syscon_regmap_read_from_offset(struct device_node *np,
+ const char *s, unsigned int *val)
+{
+ struct of_phandle_args pargs;
+ struct regmap *regmap;
+ int offset;
+ int ret;
+
+ if (!np)
+ return -ENODEV;
+
+ ret = of_parse_phandle_with_fixed_args(np, s, 1, 0, &pargs);
+ if (ret)
+ return ret;
+
+ regmap = syscon_node_to_regmap(pargs.np);
+ if (IS_ERR(regmap)) {
+ of_node_put(pargs.np);
+ return PTR_ERR(regmap);
+ }
+
+ offset = pargs.args[0];
+ of_node_put(pargs.np);
+
+ ret = regmap_read(regmap, offset, val);
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(syscon_regmap_read_from_offset);
+
struct regmap *syscon_regmap_lookup_by_compatible(const char *s)
{
struct device_node *syscon_np;