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 4/8] regmap: Allow left shifting register offset before access
Date: Sat, 6 Jun 2020 02:00:21 +0530	[thread overview]
Message-ID: <20200605203025.15466-5-p.yadav@ti.com> (raw)
In-Reply-To: <20200605203025.15466-1-p.yadav@ti.com>

Drivers can configure it to adjust the final read/write location.

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

diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index c71b961234..173ae80890 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -261,8 +261,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;
@@ -349,6 +351,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;
@@ -458,6 +461,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 19474e6de1..e6c59dfbce 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];
 };
-- 
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 ` Pratyush Yadav [this message]
2020-06-05 20:30 ` [PATCH v2 5/8] regmap: Add regmap_init_mem_range() Pratyush Yadav
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-5-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