From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] regmap: implement regmap_multi_reg_write()
Date: Fri, 25 Oct 2024 10:43:28 +0200 [thread overview]
Message-ID: <20241025084328.2021437-1-s.hauer@pengutronix.de> (raw)
regmap_multi_reg_write() can be used to write multiple regmap registers
at once. The code is taken from Linux-6.12 and simplified for barebox.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
drivers/base/regmap/regmap.c | 36 ++++++++++++++++++++++++++++++++++++
include/linux/regmap.h | 26 ++++++++++++++++++++++++++
2 files changed, 62 insertions(+)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 1f10424a42..777636c0b3 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -573,6 +573,42 @@ int regmap_field_bulk_alloc(struct regmap *regmap,
return 0;
}
+/**
+ * regmap_multi_reg_write() - Write multiple registers to the device
+ *
+ * @map: Register map to write to
+ * @regs: Array of structures containing register,value to be written
+ * @num_regs: Number of registers to write
+ *
+ * Write multiple registers to the device where the set of register, value
+ * pairs are supplied in any order, possibly not all in a single range.
+ *
+ * The 'normal' block write mode will send ultimately send data on the
+ * target bus as R,V1,V2,V3,..,Vn where successively higher registers are
+ * addressed. However, this alternative block multi write mode will send
+ * the data as R1,V1,R2,V2,..,Rn,Vn on the target bus. The target device
+ * must of course support the mode.
+ *
+ * A value of zero will be returned on success, a negative errno will be
+ * returned in error cases.
+ */
+int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
+ int num_regs)
+{
+ int i;
+ int ret;
+
+ for (i = 0; i < num_regs; i++) {
+ ret = regmap_write(map, regs[i].reg, regs[i].def);
+ if (ret != 0)
+ return ret;
+
+ if (regs[i].delay_us)
+ udelay(regs[i].delay_us);
+ }
+ return 0;
+}
+
/*
* regmap_register_cdev - register a devfs file for a regmap
*
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index e38b4f2dc8..c24b877712 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -276,6 +276,32 @@ static inline int regmap_clear_bits(struct regmap *map,
size_t regmap_size_bytes(struct regmap *map);
+/**
+ * struct reg_sequence - An individual write from a sequence of writes.
+ *
+ * @reg: Register address.
+ * @def: Register value.
+ * @delay_us: Delay to be applied after the register write in microseconds
+ *
+ * Register/value pairs for sequences of writes with an optional delay in
+ * microseconds to be applied after each write.
+ */
+struct reg_sequence {
+ unsigned int reg;
+ unsigned int def;
+ unsigned int delay_us;
+};
+
+#define REG_SEQ(_reg, _def, _delay_us) { \
+ .reg = _reg, \
+ .def = _def, \
+ .delay_us = _delay_us, \
+ }
+#define REG_SEQ0(_reg, _def) REG_SEQ(_reg, _def, 0)
+
+int regmap_multi_reg_write(struct regmap *map, const struct reg_sequence *regs,
+ int num_regs);
+
/**
* regmap_read_poll_timeout - Poll until a condition is met or a timeout occurs
*
--
2.39.5
next reply other threads:[~2024-10-25 8:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-25 8:43 Sascha Hauer [this message]
2024-10-28 12:12 ` Sascha Hauer
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=20241025084328.2021437-1-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.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