[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211217224104.1747758-3-linuxkernel@fbautosys.co.uk>
Date: Fri, 17 Dec 2021 22:41:01 +0000
From: linuxkernel@...utosys.co.uk
To: linux-kernel@...r.kernel.org
Cc: broonie@...nel.org
Subject: [RFC PATCH 2/5] regmap: Altered regmap_X_X_write functions to account for padding bits
From: Christopher Tyerman <c.tyerman@...ebladeautomationsystems.co.uk>
modified: drivers/base/regmap/regmap.c
Signed-off-by: Christopher Tyerman <c.tyerman@...ebladeautomationsystems.co.uk>
---
drivers/base/regmap/regmap.c | 22 ++++++++++++++++------
1 file changed, 16 insertions(+), 6 deletions(-)
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 05c104659381..07d6d804c4b9 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -232,42 +232,52 @@ static void regmap_format_2_6_write(struct regmap *map,
unsigned int reg, unsigned int val)
{
u8 *out = map->work_buf;
+ u8 shift = map->reg_shift;
- *out = (reg << 6) | val;
+ *out = (reg << (6 + shift) | val);
}
static void regmap_format_4_12_write(struct regmap *map,
unsigned int reg, unsigned int val)
{
+ u8 shift = map->reg_shift;
__be16 *out = map->work_buf;
- *out = cpu_to_be16((reg << 12) | val);
+
+ *out = cpu_to_be16((reg << (12 + shift)) | val);
}
static void regmap_format_7_9_write(struct regmap *map,
unsigned int reg, unsigned int val)
{
+ u8 shift = map->reg_shift;
__be16 *out = map->work_buf;
- *out = cpu_to_be16((reg << 9) | val);
+
+ *out = cpu_to_be16((reg << (9 + shift)) | val);
}
static void regmap_format_7_17_write(struct regmap *map,
unsigned int reg, unsigned int val)
{
+ u8 shift = map->reg_shift;
u8 *out = map->work_buf;
out[2] = val;
out[1] = val >> 8;
- out[0] = (val >> 16) | (reg << 1);
+ out[0] = (val >> 16) | (reg << (1 + shift));
}
static void regmap_format_10_14_write(struct regmap *map,
unsigned int reg, unsigned int val)
{
+ u8 shift = map->reg_shift;
u8 *out = map->work_buf;
out[2] = val;
- out[1] = (val >> 8) | (reg << 6);
- out[0] = reg >> 2;
+ out[1] = (val >> 8) | (reg << (6 + shift));
+ if (shift <= 2)
+ out[0] = reg >> (2 - shift);
+ else
+ out[0] = reg << shift;
}
static void regmap_format_8(void *buf, unsigned int val, unsigned int shift)
--
2.25.1
Powered by blists - more mailing lists