regmap: Allow specifying read/write width
Right now, regmap_read() and regmap_write() read/write a 32-bit value
only. To write other lengths, regmap_raw_read() and regmap_raw_write()
need to be used.
This means that any driver ported from Linux that relies on
regmap_{read,write}() to know the size already has to be updated at each
callsite. This makes the port harder to maintain.
So, allow specifying the read/write width to make it easier to port the
drivers, since now the only change needed is when initializing the
regmap.
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 809f584..c71b961 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -25,6 +25,10 @@
* regmap_alloc() - Allocate a regmap with a given number of ranges.
*
* @count: Number of ranges to be allocated for the regmap.
+ *
+ * The default regmap width is set to REGMAP_SIZE_32. Callers can override it
+ * if they need.
+ *
* Return: A pointer to the newly allocated regmap, or NULL on error.
*/
static struct regmap *regmap_alloc(int count)
@@ -36,6 +40,7 @@
if (!map)
return NULL;
map->range_count = count;
+ map->width = REGMAP_SIZE_32;
return map;
}
@@ -244,7 +249,7 @@
const struct regmap_config *config)
{
int rc;
- struct regmap **mapp;
+ struct regmap **mapp, *map;
mapp = devres_alloc(devm_regmap_release, sizeof(struct regmap *),
__GFP_ZERO);
@@ -255,6 +260,10 @@
if (rc)
return ERR_PTR(rc);
+ map = *mapp;
+ if (config)
+ map->width = config->width;
+
devres_add(dev, mapp);
return *mapp;
}
@@ -377,7 +386,7 @@
int regmap_read(struct regmap *map, uint offset, uint *valp)
{
- return regmap_raw_read(map, offset, valp, REGMAP_SIZE_32);
+ return regmap_raw_read(map, offset, valp, map->width);
}
static inline void __write_8(u8 *addr, const u8 *val,
@@ -487,7 +496,7 @@
int regmap_write(struct regmap *map, uint offset, uint val)
{
- return regmap_raw_write(map, offset, &val, REGMAP_SIZE_32);
+ return regmap_raw_write(map, offset, &val, map->width);
}
int regmap_update_bits(struct regmap *map, uint offset, uint mask, uint val)