linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sanchayan Maity <maitysanchayan@gmail.com>
To: arnd@arndb.de, shawnguo@kernel.org
Cc: stefan@agner.ch, robh+dt@kernel.org, lee.jones@linaro.org,
	linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	Sanchayan Maity <maitysanchayan@gmail.com>
Subject: [PATCH v2 1/5] mfd: syscon: Introduce syscon_regmap_read_from_offset
Date: Mon,  2 May 2016 12:35:00 +0530	[thread overview]
Message-ID: <b234b680c77ae5f0678be10a226eac7976a83c34.1462171990.git.maitysanchayan@gmail.com> (raw)
In-Reply-To: <cover.1462171989.git.maitysanchayan@gmail.com>
In-Reply-To: <cover.1462171989.git.maitysanchayan@gmail.com>

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>
---
 drivers/mfd/syscon.c       | 30 ++++++++++++++++++++++++++++++
 include/linux/mfd/syscon.h | 10 ++++++++++
 2 files changed, 40 insertions(+)

diff --git a/drivers/mfd/syscon.c b/drivers/mfd/syscon.c
index 2f2225e..74724c3 100644
--- a/drivers/mfd/syscon.c
+++ b/drivers/mfd/syscon.c
@@ -136,6 +136,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;
diff --git a/include/linux/mfd/syscon.h b/include/linux/mfd/syscon.h
index 1088149..42b0759 100644
--- a/include/linux/mfd/syscon.h
+++ b/include/linux/mfd/syscon.h
@@ -26,6 +26,9 @@ extern struct regmap *syscon_regmap_lookup_by_pdevname(const char *s);
 extern struct regmap *syscon_regmap_lookup_by_phandle(
 					struct device_node *np,
 					const char *property);
+extern int syscon_regmap_read_from_offset(struct device_node *np,
+					  const char *s,
+					  unsigned int *val);
 #else
 static inline struct regmap *syscon_node_to_regmap(struct device_node *np)
 {
@@ -48,6 +51,13 @@ static inline struct regmap *syscon_regmap_lookup_by_phandle(
 {
 	return ERR_PTR(-ENOTSUPP);
 }
+
+static inline int syscon_regmap_read_from_offset(struct device_node *np,
+						 const char *s,
+						 unsigned int *val)
+{
+	return ERR_PTR(-ENOSYS);
+}
 #endif
 
 #endif /* __LINUX_MFD_SYSCON_H__ */
-- 
2.8.2

  reply	other threads:[~2016-05-02  7:11 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-02  7:04 [PATCH v2 0/5] Implement SoC bus driver for Vybrid Sanchayan Maity
2016-05-02  7:05 ` Sanchayan Maity [this message]
2016-05-02  7:05 ` [PATCH v2 2/5] ARM: dts: vfxxx: Add device tree node for OCOTP Sanchayan Maity
2016-05-02  7:31   ` Arnd Bergmann
2016-05-02  8:12     ` maitysanchayan
2016-05-02  7:05 ` [PATCH v2 3/5] ARM: dts: vfxxx: Add OCROM and phandle entries for Vybrid SoC bus driver Sanchayan Maity
2016-05-02  7:05 ` [PATCH v2 4/5] soc: Add SoC bus driver for Freescale Vybrid Platform Sanchayan Maity
2016-05-02  7:05 ` [PATCH v2 5/5] vf610-soc: Add Vybrid SoC device tree binding documentation Sanchayan Maity
2016-05-04  2:30   ` Rob Herring
2016-05-05  8:27     ` maitysanchayan
2016-05-09 17:14       ` Rob Herring
2016-05-09 18:25         ` Stefan Agner
2016-05-09 22:58           ` Rob Herring
2016-05-10  1:13             ` Stefan Agner
2016-05-11  3:24               ` Rob Herring

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=b234b680c77ae5f0678be10a226eac7976a83c34.1462171990.git.maitysanchayan@gmail.com \
    --to=maitysanchayan@gmail.com \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=shawnguo@kernel.org \
    --cc=stefan@agner.ch \
    /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;
as well as URLs for NNTP newsgroup(s).