regmap: Support for caching in reg_raw_write()
Subsystems (3)
PATCH v3 1/2 regmap: Support for caching in reg_raw_write()
Adding support for caching of data into the non-volatile register from the call of reg_raw_write().
This will allow the larger block of data write into multiple register without worrying whether register is cached or not through reg_raw_write().
---
Changes from V1:
- Add register number and return value in error case.
- Some variable usage cleanups..
Changes from V2:
- Fixing register number during error printing.
drivers/base/regmap/regmap.c | 26 +++++++++++++++++++++----- 1 files changed, 21 insertions(+), 5 deletions(-)
drivers/base/regmap/regmap.c +21 -5
@@ -323,6 +323,26 @@ static int _regmap_raw_write(struct regmap *map, unsigned int reg,if (!map->writeable_reg (map->dev, reg + i))return -EINVAL ; +if (!map->cache_bypass && map->format.parse_val) { +unsigned int ival; +int val_bytes = map->format.val_bytes; +for (i =0 ; i < val_len / val_bytes; i++) { +memcpy (map->work_buf, val + (i * val_bytes), val_bytes); + ival = map->format.parse_val (map->work_buf); + ret =regcache_write (map, reg + i, ival); +if (ret) { +dev_err (map->dev, +"Error in caching of register: %u ret: %d\n" , + reg + i, ret); +return ret; + } + } +if (map->cache_only) { + map->cache_dirty = true; +return 0 ; + } + } + map->format.format_reg (map->work_buf, reg); u8[0 ] |= map->write_flag_mask;
@@ -373,7 +393,7 @@ int _regmap_write(struct regmap *map, unsigned int reg,int ret;BUG_ON (!map->format.format_write && !map->format.format_val); -if (!map->cache_bypass) { +if (!map->cache_bypass && map->format.format_write) { ret =regcache_write (map, reg, val);if (ret !=0 )return ret;
@@ -450,12 +470,8 @@ EXPORT_SYMBOL_GPL(regmap_write);int regmap_raw_write (struct regmap *map,unsigned int reg,const void *val,size_t val_len) { -size_t val_count = val_len / map->format.val_bytes;int ret; -WARN_ON (!regmap_volatile_range (map, reg, val_count) && - map->cache_type !=REGCACHE_NONE ); -mutex_lock (&map->lock); ret =_regmap_raw_write (map, reg, val, val_len);
Signature · 1 line
1.7.1.1
PATCH v3 2/2 regmap: add regmap_bulk_write() for register write
The bulk_write() supports the data transfer to multi register which takes the data into cpu_endianness format and does formatting of data to device format before sending to device.
The transfer can be completed in single transfer or multiple transfer based on data formatting.
---
Changes from V1:
- Change commit message.
- Byte swapping in input data packet. Changes from V2:
- Remove formatting if val_byte is 1.
- Allocating proper size of memory for val_byte != 1
drivers/base/regmap/regmap.c | 61 ++++++++++++++++++++++++++++++++++++++++++ include/linux/regmap.h | 2 + 2 files changed, 63 insertions(+), 0 deletions(-)
drivers/base/regmap/regmap.c +61 -0
@@ -482,6 +482,67 @@ 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; +unsigned int ival; +size_t val_bytes = map->format.val_bytes; + +mutex_lock (&map->lock); + +if (map->format.parse_val) { +void *wval; +/* 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) { +mutex_unlock (&map->lock); +dev_err (map->dev, +"Error in memory allocation\n" ); +return -ENOMEM ; + } +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); + }else { +for (i =0 ; i < val_count; i++) { +memcpy (&ival, val + (i * val_bytes), val_bytes); + ret =_regmap_write (map, reg + i, ival); +if (ret) { +dev_err (map->dev, +"Error in register %u write, ret %d\n" , + reg + i, ret); +break ; + } + } + } + +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) {
include/linux/regmap.h +2 -0
@@ -135,6 +135,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);
Signature · 1 line
1.7.1.1
Re: [PATCH V3 2/2] regmap: add regmap_bulk_write() for register write
drivers/base/regmap/regmap.c int regmap_raw_write(struct regmap *map, unsigned int reg, · line 513
Quoted 4 lines · Laxman Dewangan
drivers/base/regmap/regmap.c +4
-0+/* No formatting is require if val_byte is 1 */ +if (val_bytes ==1 ) + wval = (void *)val; +else {
Please don't combine branches with and without braces.
drivers/base/regmap/regmap.c int regmap_raw_write(struct regmap *map, unsigned int reg, · line 519
Quoted 6 lines
drivers/base/regmap/regmap.c +6
-0+ wval =kmemdup (val, val_count * val_bytes,GFP_KERNEL ); +if (!wval) { +mutex_unlock (&map->lock); +dev_err (map->dev, +"Error in memory allocation\n" ); +return -ENOMEM ;
As a style thing a goto error pattern is clearer for stuff like this - there's so many branches that it's complex to keep track of the unwinding.
Mark Brown
AppliedQuoted 6 lines · Laxman Dewangan
Adding support for caching of data into the non-volatile register from the call of
reg_raw_write().This will allow the larger block of data write into multiple register without worrying whether register is cached or not through
reg_raw_write().
Applied, thanks. We really should refactor later on to not do the encode/decode dance if we don't have to but this is fine for now.