public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Pratyush Yadav <p.yadav@ti.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 5/8] regmap: Add regmap_init_mem_range()
Date: Sat, 6 Jun 2020 02:00:22 +0530	[thread overview]
Message-ID: <20200605203025.15466-6-p.yadav@ti.com> (raw)
In-Reply-To: <20200605203025.15466-1-p.yadav@ti.com>

Right now, the base of a regmap can only be obtained from the device
tree. This makes it impossible for devices which calculate the base at
runtime to use a regmap. An example of such a device is the Cadence
Sierra PHY.

Allow creating a regmap with one range whose start and size can be
specified by the driver based on calculations at runtime.

Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
---
 drivers/core/regmap.c | 27 +++++++++++++++++++++++++++
 include/regmap.h      | 19 +++++++++++++++++++
 2 files changed, 46 insertions(+)

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 173ae80890..a9087df32b 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -164,6 +164,33 @@ err:
 	return ret;
 }
 
+int regmap_init_mem_range(ofnode node, ulong r_start, ulong r_size,
+			  struct regmap **mapp)
+{
+	struct regmap *map;
+	struct regmap_range *range;
+
+	map = regmap_alloc(1);
+	if (!map)
+		return -ENOMEM;
+
+	range = &map->ranges[0];
+	range->start = r_start;
+	range->size = r_size;
+
+	if (ofnode_read_bool(node, "little-endian"))
+		map->endianness = REGMAP_LITTLE_ENDIAN;
+	else if (ofnode_read_bool(node, "big-endian"))
+		map->endianness = REGMAP_BIG_ENDIAN;
+	else if (ofnode_read_bool(node, "native-endian"))
+		map->endianness = REGMAP_NATIVE_ENDIAN;
+	else /* Default: native endianness */
+		map->endianness = REGMAP_NATIVE_ENDIAN;
+
+	*mapp = map;
+	return 0;
+}
+
 int regmap_init_mem(ofnode node, struct regmap **mapp)
 {
 	struct regmap_range *range;
diff --git a/include/regmap.h b/include/regmap.h
index e6c59dfbce..7c8ad04759 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -350,6 +350,25 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count,
 
 int regmap_init_mem_index(ofnode node, struct regmap **mapp, int index);
 
+/**
+ * regmap_init_mem_range() - Set up a new memory region for ofnode with the
+ *			     specified range.
+ *
+ * @node:	The ofnode for the map.
+ * @r_start:	Start of the range.
+ * @r_size:	Size of the range.
+ * @mapp:	Returns allocated map.
+ *
+ * Return: 0 in success, -errno otherwise
+ *
+ * This creates a regmap with one range where instead of extracting the range
+ * from 'node', it is created based on the parameters specified. This is
+ * useful when a driver needs to calculate the base of the regmap at runtime,
+ * and can't specify it in device tree.
+ */
+int regmap_init_mem_range(ofnode node, ulong r_start, ulong r_size,
+			  struct regmap **mapp);
+
 /**
  * devm_regmap_init() - Initialise register map (device managed)
  *
-- 
2.27.0

  parent reply	other threads:[~2020-06-05 20:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-05 20:30 [PATCH v2 0/8] regmap: Add managed API, regmap fields, regmap config Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 1/8] regmap: Add devm_regmap_init() Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 2/8] regmap: zero out the regmap on allocation Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 3/8] regmap: Allow specifying read/write width Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 4/8] regmap: Allow left shifting register offset before access Pratyush Yadav
2020-06-05 20:30 ` Pratyush Yadav [this message]
2020-06-05 20:30 ` [PATCH v2 6/8] regmap: Allow devices to specify regmap range start and size in config Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 7/8] regmap: Add support for regmap fields Pratyush Yadav
2020-06-05 20:30 ` [PATCH v2 8/8] test: dm: Add tests for regmap managed API and " Pratyush Yadav
2020-08-06 14:25   ` Tom Rini
2020-08-05  8:07 ` [PATCH v2 0/8] regmap: Add managed API, regmap fields, regmap config Pratyush Yadav
2020-08-16  3:39   ` Simon Glass

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=20200605203025.15466-6-p.yadav@ti.com \
    --to=p.yadav@ti.com \
    --cc=u-boot@lists.denx.de \
    /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