Add "no-bus" configuration for regmap API
Subsystems (2)
v2 cover Add "no-bus" configuration for regmap API
Second version of the initial patchset(can be found here:
https://lkml.org/lkml/2012/12/21/98)
This version contains following improvements:
- Provisions to switch between mutexes and spinlocks for locking in "no-bus" configuration
- "reg_read" and "reg_write" have "void *context" as a first argument in all the patches
- Minor improvements in documentation
Andrey Smirnov (3):
Add provisions to have user-defined read operation Add provisions to have user-defined write operation Add "no-bus" option for regmap API
drivers/base/regmap/internal.h | 5 ++ drivers/base/regmap/regmap.c | 156 +++++++++++++++++++++++++++++----------- include/linux/regmap.h | 18 ++++- 3 files changed, 135 insertions(+), 44 deletions(-)
Signature · 1 line
1.7.9.5
PATCH v2 1/3 Add provisions to have user-defined read operation
This commit is a preparatory commit to provide "no-bus" configuration option for regmap API. It adds necessary plumbing needed to have the ability to provide user define register read function.
--- drivers/base/regmap/internal.h | 2 ++ drivers/base/regmap/regmap.c | 35 ++++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-)
drivers/base/regmap/internal.h +2 -0
@@ -74,6 +74,8 @@ struct regmap {const struct regmap_access_table *volatile_table;const struct regmap_access_table *precious_table; +int (*reg_read)(void *context,unsigned int reg,unsigned int *val); +u8 read_flag_mask;u8 write_flag_mask;
drivers/base/regmap/regmap.c +26 -9
@@ -34,6 +34,9 @@ static int _regmap_update_bits(struct regmap *map, unsigned int reg, unsigned int mask, unsigned int val, bool *change); +static int _regmap_bus_read (void *context,unsigned int reg, +unsigned int *val); +bool regmap_reg_in_ranges (unsigned int reg,const struct regmap_range *ranges,unsigned int nranges)
@@ -430,6 +433,8 @@ struct regmap *regmap_init(struct device *dev, map->read_flag_mask = bus->read_flag_mask; } + map->reg_read = _regmap_bus_read; + reg_endian = config->reg_format_endian;if (reg_endian ==REGMAP_ENDIAN_DEFAULT ) reg_endian = bus->reg_format_endian_default;
@@ -1202,10 +1207,27 @@ static int _regmap_raw_read(struct regmap *map, unsigned int reg, void *val,return ret; } +static int _regmap_bus_read (void *context,unsigned int reg, +unsigned int *val) +{ +int ret; +struct regmap *map = context; + +if (!map->format.parse_val) +return -EINVAL ; + + ret =_regmap_raw_read (map, reg, map->work_buf, map->format.val_bytes); +if (ret ==0 ) + *val = map->format.parse_val (map->work_buf); + +return ret; +} +static int _regmap_read (struct regmap *map,unsigned int reg,unsigned int *val) {int ret; +BUG_ON (!map->reg_read);if (!map->cache_bypass) { ret =regcache_read (map, reg, val);
@@ -1213,26 +1235,21 @@ static int _regmap_read(struct regmap *map, unsigned int reg,return 0 ; } -if (!map->format.parse_val) -return -EINVAL ; -if (map->cache_only)return -EBUSY ; - ret =_regmap_raw_read (map, reg, map->work_buf, map->format.val_bytes); + ret = map->reg_read (map, reg, val);if (ret ==0 ) { - *val = map->format.parse_val (map->work_buf); -#ifdef LOG_DEVICE if (strcmp (dev_name (map->dev),LOG_DEVICE ) ==0 )dev_info (map->dev,"%x => %x\n" , reg, *val);#endif trace_regmap_reg_read (map->dev, reg, *val); - } -if (ret ==0 && !map->cache_bypass) -regcache_write (map, reg, *val); +if (!map->cache_bypass) +regcache_write (map, reg, *val); + }return ret; }
Signature · 1 line
1.7.9.5
PATCH v2 2/3 Add provisions to have user-defined write operation
In reply to Andrey SmirnovThis commit is a preparatory commit to provide "no-bus" configuration option for regmap API. It adds necessary plumbing needed to have the ability to provide user define register write function.
--- drivers/base/regmap/internal.h | 1 + drivers/base/regmap/regmap.c | 83 ++++++++++++++++++++++++++-------------- 2 files changed, 55 insertions(+), 29 deletions(-)
drivers/base/regmap/internal.h +1 -0
@@ -75,6 +75,7 @@ struct regmap {const struct regmap_access_table *precious_table;int (*reg_read)(void *context,unsigned int reg,unsigned int *val); +int (*reg_write)(void *context,unsigned int reg,unsigned int val);u8 read_flag_mask;u8 write_flag_mask;
drivers/base/regmap/regmap.c +54 -29
111 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v2 3/3 Add "no-bus" option for regmap API
In reply to Andrey SmirnovThis commit adds provision for "no-bus" usage of the regmap API. In this configuration user can provide API with two callbacks 'reg_read' and 'reg_write' which are to be called when reads and writes to one of device's registers is performed. This is useful for devices that expose registers but whose register access sequence does not fit the 'bus' abstraction.
--- drivers/base/regmap/internal.h | 2 ++ drivers/base/regmap/regmap.c | 52 ++++++++++++++++++++++++++++++---------- include/linux/regmap.h | 18 +++++++++++++- 3 files changed, 59 insertions(+), 13 deletions(-)
drivers/base/regmap/internal.h +2 -0
@@ -77,6 +77,8 @@ struct regmap {int (*reg_read)(void *context,unsigned int reg,unsigned int *val);int (*reg_write)(void *context,unsigned int reg,unsigned int val); +bool cache_registers; +u8 read_flag_mask;u8 write_flag_mask;
drivers/base/regmap/regmap.c +40 -12
160 lines not on this page · raw message
include/linux/regmap.h +17 -1
@@ -127,7 +127,18 @@ typedef void (*regmap_unlock)(void *);* @lock_arg: this field is passed as the only argument of lock/unlock * functions (ignored in case regular lock/unlock functions * are not overridden). -* +* @reg_read: Optional callback that if filled will be used to perform +* all the reads from the registers. Should only be provided for +* devices whos read operation cannot be represented as a simple read +* operation on a bus such as SPI, I2C, etc. Most of the devices do +* not need this. +* @reg_write: Same as above for writing. +* @fast_io: Register IO is fast. Use a spinlock instead of a mutex +* to perform locking. This field is ignored if custom lock/unlock +* functions are used (see fields lock/unlock of struct regmap_config). +* This field is a duplicate of a similar file in +* 'struct regmap_bus' and serves exact same purpose. +* Use it only for "no-bus" cases. * @max_register: Optional, specifies the maximum valid register index. * @wr_table: Optional, points to a struct regmap_access_table specifying * valid ranges for write access.
@@ -177,6 +188,11 @@ struct regmap_config {regmap_unlock unlock;void *lock_arg; +int (*reg_read)(void *context,unsigned int reg,unsigned int *val); +int (*reg_write)(void *context,unsigned int reg,unsigned int val); + +bool fast_io; +unsigned int max_register;const struct regmap_access_table *wr_table;const struct regmap_access_table *rd_table;
Signature · 1 line
1.7.9.5