From: Xiubo Li <Li.Xiubo@freescale.com>
To: <broonie@kernel.org>, <rob@landley.net>
Cc: <robh+dt@kernel.org>, <pawel.moll@arm.com>,
<mark.rutland@arm.com>, <ijc+devicetree@hellion.org.uk>,
<galak@codeaurora.org>, <linux-doc@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, Xiubo Li <Li.Xiubo@freescale.com>
Subject: [PATCHv2 3/3] regmap: add DT endianness binding support.
Date: Wed, 23 Apr 2014 14:46:35 +0800 [thread overview]
Message-ID: <1398235595-13370-4-git-send-email-Li.Xiubo@freescale.com> (raw)
In-Reply-To: <1398235595-13370-1-git-send-email-Li.Xiubo@freescale.com>
For many drivers which will support rich endianness of CPU<-->Dev
need define DT properties by itself without the binding support.
The value endianness using regmap-mmio, for example:
Index CPU Device Endianess flag for DT property
------------------------------------------------------------
1 LE LE -
2 LE BE 'big-endian'
3 BE BE -
4 BE LE 'little-endian'
============
Here add DT endianness binding support will define two string
properties of the register and value endiannesses:
'regmap-reg-endian' and 'regmap-val-endian'.
And the value of them will be:
'le' : REGMAP_ENDIAN_LITTLE
'be' : REGMAP_ENDIAN_BIG
'native' : REGMAP_ENDIAN_NATIVE
Absent : REGMAP_ENDIAN_DEFAULT
The value endianness for regmap-mmio, for example:
Index CPU Device Endianess flag for DT property
------------------------------------------------------------
1 LE LE 'native' or absent
2 LE BE 'be'
3 BE BE 'native' or absent
4 BE LE 'le'
Please see the following documetation for detail usage:
Documentation/devicetree/bindings/regmap/regmap-endianness.txt
Signed-off-by: Xiubo Li <Li.Xiubo@freescale.com>
---
drivers/base/regmap/regmap.c | 96 +++++++++++++++++++++++++++++++++++++++-----
1 file changed, 85 insertions(+), 11 deletions(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 8e8cea1..cfc9302 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -15,6 +15,7 @@
#include <linux/export.h>
#include <linux/mutex.h>
#include <linux/err.h>
+#include <linux/of.h>
#include <linux/rbtree.h>
#include <linux/sched.h>
@@ -423,6 +424,81 @@ static void regmap_range_exit(struct regmap *map)
}
/**
+ * of_regmap_endian_get_by_name() - Parse and lookup the endianness referenced
+ * by a device node
+ * @np: pointer to clock consumer node
+ * @name: name of consumer's endianness input
+ *
+ * This function parses the device endianness property, and uses them to
+ * determine the endianness of the registers and values.
+ */
+static int of_regmap_endian_get_by_name(struct device_node *np,
+ const char *endian_name,
+ enum regmap_endian *out_endian)
+{
+ const char *endianness;
+ int ret;
+
+ if (!out_endian)
+ return -EINVAL;
+
+ /* Set the default endianness */
+ *out_endian = REGMAP_ENDIAN_DEFAULT;
+
+ /* Absent or being to use the flag from config of the drivers */
+ if (!of_find_property(np, endian_name, NULL))
+ return 0;
+
+ ret = of_property_read_string(np, endian_name, &endianness);
+ if (ret)
+ return ret;
+
+ if (!strcmp("le", endianness))
+ *out_endian = REGMAP_ENDIAN_LITTLE;
+ else if (!strcmp("be", endianness))
+ *out_endian = REGMAP_ENDIAN_BIG;
+ else if (!strcmp("native", endianness))
+ *out_endian = REGMAP_ENDIAN_NATIVE;
+
+ return 0;
+}
+
+static int of_regmap_get_endian(struct device *dev,
+ const struct regmap_bus *bus,
+ const struct regmap_config *config,
+ const char *endian_name,
+ enum regmap_endian *out_endian)
+{
+ int ret;
+
+ if (!out_endian)
+ return -EINVAL;
+
+ if (dev) {
+ ret = of_regmap_endian_get_by_name(dev->of_node, endian_name,
+ out_endian);
+ if (ret < 0)
+ return ret;
+ }
+
+ if (*out_endian != REGMAP_ENDIAN_DEFAULT)
+ return 0;
+
+ /*
+ * Parsing the endianness from driver's config
+ * or bus, this is to be compatible with the
+ * none DT and the old drivers.
+ */
+ *out_endian = config->reg_format_endian;
+ if (*out_endian == REGMAP_ENDIAN_DEFAULT)
+ *out_endian = bus->reg_format_endian_default;
+ if (*out_endian == REGMAP_ENDIAN_DEFAULT)
+ *out_endian = REGMAP_ENDIAN_BIG;
+
+ return 0;
+}
+
+/**
* regmap_init(): Initialise register map
*
* @dev: Device that will be interacted with
@@ -518,17 +594,15 @@ struct regmap *regmap_init(struct device *dev,
map->reg_read = _regmap_bus_read;
}
- reg_endian = config->reg_format_endian;
- if (reg_endian == REGMAP_ENDIAN_DEFAULT)
- reg_endian = bus->reg_format_endian_default;
- if (reg_endian == REGMAP_ENDIAN_DEFAULT)
- reg_endian = REGMAP_ENDIAN_BIG;
-
- val_endian = config->val_format_endian;
- if (val_endian == REGMAP_ENDIAN_DEFAULT)
- val_endian = bus->val_format_endian_default;
- if (val_endian == REGMAP_ENDIAN_DEFAULT)
- val_endian = REGMAP_ENDIAN_BIG;
+ ret = of_regmap_get_endian(dev, bus, config, "regmap-reg-endian",
+ ®_endian);
+ if (ret)
+ return ERR_PTR(ret);
+
+ ret = of_regmap_get_endian(dev, bus, config, "regmap-val-endian",
+ &val_endian);
+ if (ret)
+ return ERR_PTR(ret);
switch (config->reg_bits + map->reg_shift) {
case 2:
--
1.8.4
next prev parent reply other threads:[~2014-04-23 7:30 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-23 6:46 [PATCHv2 0/3] " Xiubo Li
2014-04-23 6:46 ` [PATCHv2 1/3] dt/bindings: Add the DT binding documentation for endianness Xiubo Li
2014-04-23 8:34 ` Mark Rutland
2014-04-30 5:08 ` Li.Xiubo
2014-04-23 6:46 ` [PATCHv2 2/3] regmap: " Xiubo Li
2014-04-23 8:40 ` Mark Rutland
2014-04-28 8:52 ` Li.Xiubo
2014-04-23 6:46 ` Xiubo Li [this message]
-- strict thread matches above, loose matches on Subject: below --
2014-04-02 10:09 [PATCHv2 0/3] regmap: add LE and DT binding " Xiubo Li
2014-04-02 10:09 ` [PATCHv2 3/3] regmap: add DT endianness binding support Xiubo Li
2014-04-02 19:50 ` Mark Brown
2014-04-03 5:26 ` Li.Xiubo
2014-04-14 21:07 ` Mark Brown
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=1398235595-13370-4-git-send-email-Li.Xiubo@freescale.com \
--to=li.xiubo@freescale.com \
--cc=broonie@kernel.org \
--cc=galak@codeaurora.org \
--cc=ijc+devicetree@hellion.org.uk \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=pawel.moll@arm.com \
--cc=rob@landley.net \
--cc=robh+dt@kernel.org \
/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
all inboxes | Powered by JetHome®