diff mbox series

[5/8] regmap: Add regmap_init_mem_range()

Message ID 20200527125208.24881-6-p.yadav@ti.com
State Accepted
Commit 0e01a7c3f4b6a42f768a19f7fc1df92d3e3b5d37
Headers show
Series regmap: Add managed API, regmap fields, regmap config | expand

Commit Message

Pratyush Yadav May 27, 2020, 12:52 p.m. UTC
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 at ti.com>
---
 drivers/core/regmap.c | 27 +++++++++++++++++++++++++++
 include/regmap.h      | 19 +++++++++++++++++++
 2 files changed, 46 insertions(+)

Comments

Simon Glass May 31, 2020, 2:08 p.m. UTC | #1
On Wed, 27 May 2020 at 06:52, Pratyush Yadav <p.yadav at ti.com> wrote:
>
> 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 at ti.com>
> ---
>  drivers/core/regmap.c | 27 +++++++++++++++++++++++++++
>  include/regmap.h      | 19 +++++++++++++++++++
>  2 files changed, 46 insertions(+)
>

Reviewed-by: Simon Glass <sjg at chromium.org>
diff mbox series

Patch

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 8ba4270d2d..f019a4e9ce 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -160,6 +160,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 dacdf1f39b..ea6d8b253d 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -352,6 +352,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)
  *