Skip to content

Commit

Permalink
regmap: new API regmap_multi_reg_write() definition
Browse files Browse the repository at this point in the history
New API regmap_multi_reg_write() is defined that allows a set of reg,val
pairs to be written to a I2C client device as one block transfer from the
point of view of a single I2C master system.

A simple demonstration implementation is included that just splits the
block write request into a sequence of single register writes.

The implementation will be modified later to support those I2C clients
that implement the alternative non-standard MULTIWRITE block write mode
so to achieve a single I2C transfer that will be atomic even in multiple
I2C master systems.

Signed-off-by: Anthony Olech <anthony.olech.opensource@diasemi.com>
Signed-off-by: David Dajun Chen <david.chen@diasemi.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
  • Loading branch information
Anthony Olech authored and Mark Brown committed Oct 14, 2013
1 parent 61e6cfa commit e33fabd
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
41 changes: 41 additions & 0 deletions drivers/base/regmap/regmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1439,6 +1439,47 @@ int regmap_bulk_write(struct regmap *map, unsigned int reg, const void *val,
}
EXPORT_SYMBOL_GPL(regmap_bulk_write);

/*
* regmap_multi_reg_write(): Write multiple registers to the device
*
* where the set of register are supplied in any order
*
* @map: Register map to write to
* @regs: Array of structures containing register,value to be written
* @num_regs: Number of registers to write
*
* This function is intended to be used for writing a large block of data
* atomically to the device in single transfer for those I2C client devices
* that implement this alternative block write mode.
*
* A value of zero will be returned on success, a negative errno will
* be returned in error cases.
*/
int regmap_multi_reg_write(struct regmap *map, struct reg_default *regs,
int num_regs)
{
int ret = 0, i;

for (i = 0; i < num_regs; i++) {
int reg = regs[i].reg;
if (reg % map->reg_stride)
return -EINVAL;
}

map->lock(map->lock_arg);

for (i = 0; i < num_regs; i++) {
ret = _regmap_write(map, regs[i].reg, regs[i].def);
if (ret != 0)
goto out;
}
out:
map->unlock(map->lock_arg);

return ret;
}
EXPORT_SYMBOL_GPL(regmap_multi_reg_write);

/**
* regmap_raw_write_async(): Write raw values to one or more registers
* asynchronously
Expand Down
2 changes: 2 additions & 0 deletions include/linux/regmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ 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_multi_reg_write(struct regmap *map, struct reg_default *regs,
int num_regs);
int regmap_raw_write_async(struct regmap *map, unsigned int reg,
const void *val, size_t val_len);
int regmap_read(struct regmap *map, unsigned int reg, unsigned int *val);
Expand Down

0 comments on commit e33fabd

Please sign in to comment.