summaryrefslogtreecommitdiff
path: root/drivers/core
diff options
context:
space:
mode:
authorPratyush Yadav <p.yadav@ti.com>2020-09-24 10:04:12 +0530
committerTom Rini <trini@konsulko.com>2020-09-30 11:55:22 -0400
commit78aaedba9f1b92335a4f0ce8344f6abf7a63dccb (patch)
tree256b4ef8de84fe33e82ba0e2aec9ab92c4910627 /drivers/core
parent97d8a6970a3da5856633f2a705f0687fca4af9a5 (diff)
downloadu-boot-78aaedba9f1b92335a4f0ce8344f6abf7a63dccb.tar.gz
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>
Diffstat (limited to 'drivers/core')
-rw-r--r--drivers/core/regmap.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c
index 809f58489f..c71b961234 100644
--- a/drivers/core/regmap.c
+++ b/drivers/core/regmap.c
@@ -25,6 +25,10 @@ DECLARE_GLOBAL_DATA_PTR;
* 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 @@ static struct regmap *regmap_alloc(int count)
if (!map)
return NULL;
map->range_count = count;
+ map->width = REGMAP_SIZE_32;
return map;
}
@@ -244,7 +249,7 @@ struct regmap *devm_regmap_init(struct udevice *dev,
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 @@ struct regmap *devm_regmap_init(struct udevice *dev,
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_raw_read(struct regmap *map, uint offset, void *valp, size_t val_len)
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_raw_write(struct regmap *map, uint offset, const void *val,
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)