diff mbox series

[4/8] regmap: Allow left shifting register offset before access

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

Commit Message

Pratyush Yadav May 27, 2020, 12:52 p.m. UTC
Drivers can configure it to adjust the final read/write location.

Signed-off-by: Pratyush Yadav <p.yadav at ti.com>
---
 drivers/core/regmap.c | 6 +++++-
 include/regmap.h      | 6 ++++++
 2 files changed, 11 insertions(+), 1 deletion(-)

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:
>
> Drivers can configure it to adjust the final read/write location.
>
> Signed-off-by: Pratyush Yadav <p.yadav at ti.com>
> ---
>  drivers/core/regmap.c | 6 +++++-
>  include/regmap.h      | 6 ++++++
>  2 files changed, 11 insertions(+), 1 deletion(-)
>
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 0180246095..8ba4270d2d 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -257,8 +257,10 @@  struct regmap *devm_regmap_init(struct udevice *dev,
 		return ERR_PTR(rc);
 
 	map = *mapp;
-	if (config)
+	if (config) {
 		map->width = config->width;
+		map->reg_offset_shift = config->reg_offset_shift;
+	}
 
 	devres_add(dev, mapp);
 	return *mapp;
@@ -345,6 +347,7 @@  int regmap_raw_read_range(struct regmap *map, uint range_num, uint offset,
 	}
 	range = &map->ranges[range_num];
 
+	offset <<= map->reg_offset_shift;
 	if (offset + val_len > range->size) {
 		debug("%s: offset/size combination invalid\n", __func__);
 		return -ERANGE;
@@ -455,6 +458,7 @@  int regmap_raw_write_range(struct regmap *map, uint range_num, uint offset,
 	}
 	range = &map->ranges[range_num];
 
+	offset <<= map->reg_offset_shift;
 	if (offset + val_len > range->size) {
 		debug("%s: offset/size combination invalid\n", __func__);
 		return -ERANGE;
diff --git a/include/regmap.h b/include/regmap.h
index 9362d864c0..dacdf1f39b 100644
--- a/include/regmap.h
+++ b/include/regmap.h
@@ -82,9 +82,12 @@  struct regmap_bus;
  *
  * @width:		Width of the read/write operations. Defaults to
  *			REGMAP_SIZE_32 if set to 0.
+ * @reg_offset_shift	Left shift the register offset by this value before
+ *			performing read or write.
  */
 struct regmap_config {
 	enum regmap_size_t width;
+	u32 reg_offset_shift;
 };
 
 /**
@@ -92,12 +95,15 @@  struct regmap_config {
  *
  * @width:		Width of the read/write operations. Defaults to
  *			REGMAP_SIZE_32 if set to 0.
+ * @reg_offset_shift	Left shift the register offset by this value before
+ *			performing read or write.
  * @range_count:	Number of ranges available within the map
  * @ranges:		Array of ranges
  */
 struct regmap {
 	enum regmap_endianness_t endianness;
 	enum regmap_size_t width;
+	u32 reg_offset_shift;
 	int range_count;
 	struct regmap_range ranges[0];
 };