diff options
-rw-r--r-- | drivers/base/regmap/regmap.c | 50 | ||||
-rw-r--r-- | include/linux/regmap.h | 2 |
2 files changed, 52 insertions, 0 deletions
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 74a6d4f8e3b8..2366b6299f07 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -473,6 +473,56 @@ int regmap_raw_write(struct regmap *map, unsigned int reg, } EXPORT_SYMBOL_GPL(regmap_raw_write); +/* + * regmap_bulk_write(): Write multiple registers to the device + * + * @map: Register map to write to + * @reg: First register to be write from + * @val: Block of data to be written, in native register size for device + * @val_count: Number of registers to write + * + * This function is intended to be used for writing a large block of + * data to be device either in single transfer or multiple transfer. + * + * A value of zero will be returned on success, a negative errno will + * be returned in error cases. + */ +int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, + size_t val_count) +{ + int ret = 0, i; + size_t val_bytes = map->format.val_bytes; + void *wval; + + if (!map->format.parse_val) + return -EINVAL; + + mutex_lock(&map->lock); + + /* No formatting is require if val_byte is 1 */ + if (val_bytes == 1) { + wval = (void *)val; + } else { + wval = kmemdup(val, val_count * val_bytes, GFP_KERNEL); + if (!wval) { + ret = -ENOMEM; + dev_err(map->dev, "Error in memory allocation\n"); + goto out; + } + for (i = 0; i < val_count * val_bytes; i += val_bytes) + map->format.parse_val(wval + i); + } + ret = _regmap_raw_write(map, reg, wval, val_bytes * val_count); + + if (val_bytes != 1) + kfree(wval); + +out: + mutex_unlock(&map->lock); + return ret; +} +EXPORT_SYMBOL_GPL(regmap_bulk_write); + static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val, unsigned int val_len) { diff --git a/include/linux/regmap.h b/include/linux/regmap.h index eb93921cdd30..1859793bc4c0 100644 --- a/include/linux/regmap.h +++ b/include/linux/regmap.h @@ -133,6 +133,8 @@ int regmap_reinit_cache(struct regmap *map, int regmap_write(struct regmap *map, unsigned int reg, unsigned int val); int regmap_raw_write(struct regmap *map, unsigned int reg, const void *val, size_t val_len); +int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val, + size_t val_count); int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val); int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, size_t val_len); |