regmap: Support non-incrementing registers
Some devices have individual registers that don't autoincrement the register address during bulk reads but instead repeatedly read the same value, for example for monitoring GPIOs or ADCs. Add support for these. -----BEGIN PGP SIGNATURE----- iQFHBAABCgAxFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAltsE8YTHGJyb29uaWVA a2VybmVsLm9yZwAKCRAk1otyXVSH0DeLB/sHEWAdyUCz9dO9pDdpi6WfpnKXuCCd ZFnx8VXBvzVLRCZYGXuMOUEzBQU2lTr2KPFDmE1k4FclyiWaI+hRIJ0s/x8FAl51 EFDoR4TM7t2n2aY0sPQCZKnoAhdQ9YPxlA9JjDUE57h0KoC76Dh8OB44dlAlxUAY PUjkv64/7AtvkBX7UZPQxckaPOLKM00P/hXwCB9MZCkjqnSWkUGgNCWPgKn9j2yL jiUQO0Wo9u8RkvYvndHPkh4NzgeH1sUFUdNys/Fopu6C2miIYBNKzvEo2OXhelHf k5rsoMQXYdiPdy4vRbeaWFetyEeBjxKIAQHKD0WJviFPw8j+ET+2GNjx =p0Mu -----END PGP SIGNATURE----- gpgsig -----BEGIN PGP SIGNATURE----- iQFHBAABCgAxFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAltsFCwTHGJyb29uaWVA a2VybmVsLm9yZwAKCRAk1otyXVSH0NcxB/wMqH+78D7GdJfMkxMKhCHFUxozfCe9 cgWgZ7+vlWpIwEGvM65FHMrFyc5ZrS3/vD6Hy8lqpsqGBVv6wS6Z0lsoOyj/QvTl T8USWKvQnvtzlPY5lRZL0xuGiaGGtpGa0eaLKH2lY7uvoge0oHz8VV6ar5y7eA1S 1INBpgTdHJgCQLZoc1pFNOcZ0EMFl6ZAygIWJTpqIwoQlvPEgtCQ4wjPlMUKrevP psJWd9obyM6+02mYFVMAlYpcMSoZ/MjPeMb7VGhLGwA1BA6dNcbiIeS7GCeH2r/i /vxvarsEm38MfLBIyORW06onHyRhVwXdLoD1jblmvYtRlfW5ANjr5g/O =mbi1 -----END PGP SIGNATURE----- Merge tag 'regmap-noinc-read' into regmap-4.19 regmap: Support non-incrementing registers Some devices have individual registers that don't autoincrement the register address during bulk reads but instead repeatedly read the same value, for example for monitoring GPIOs or ADCs. Add support for these.
This commit is contained in:
commit
1cbddedbed
|
@ -94,10 +94,12 @@ struct regmap {
|
|||
bool (*readable_reg)(struct device *dev, unsigned int reg);
|
||||
bool (*volatile_reg)(struct device *dev, unsigned int reg);
|
||||
bool (*precious_reg)(struct device *dev, unsigned int reg);
|
||||
bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
|
||||
const struct regmap_access_table *wr_table;
|
||||
const struct regmap_access_table *rd_table;
|
||||
const struct regmap_access_table *volatile_table;
|
||||
const struct regmap_access_table *precious_table;
|
||||
const struct regmap_access_table *rd_noinc_table;
|
||||
|
||||
int (*reg_read)(void *context, unsigned int reg, unsigned int *val);
|
||||
int (*reg_write)(void *context, unsigned int reg, unsigned int val);
|
||||
|
@ -181,6 +183,7 @@ bool regmap_writeable(struct regmap *map, unsigned int reg);
|
|||
bool regmap_readable(struct regmap *map, unsigned int reg);
|
||||
bool regmap_volatile(struct regmap *map, unsigned int reg);
|
||||
bool regmap_precious(struct regmap *map, unsigned int reg);
|
||||
bool regmap_readable_noinc(struct regmap *map, unsigned int reg);
|
||||
|
||||
int _regmap_write(struct regmap *map, unsigned int reg,
|
||||
unsigned int val);
|
||||
|
|
|
@ -168,6 +168,17 @@ bool regmap_precious(struct regmap *map, unsigned int reg)
|
|||
return false;
|
||||
}
|
||||
|
||||
bool regmap_readable_noinc(struct regmap *map, unsigned int reg)
|
||||
{
|
||||
if (map->readable_noinc_reg)
|
||||
return map->readable_noinc_reg(map->dev, reg);
|
||||
|
||||
if (map->rd_noinc_table)
|
||||
return regmap_check_range_table(map, reg, map->rd_noinc_table);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool regmap_volatile_range(struct regmap *map, unsigned int reg,
|
||||
size_t num)
|
||||
{
|
||||
|
@ -766,10 +777,12 @@ struct regmap *__regmap_init(struct device *dev,
|
|||
map->rd_table = config->rd_table;
|
||||
map->volatile_table = config->volatile_table;
|
||||
map->precious_table = config->precious_table;
|
||||
map->rd_noinc_table = config->rd_noinc_table;
|
||||
map->writeable_reg = config->writeable_reg;
|
||||
map->readable_reg = config->readable_reg;
|
||||
map->volatile_reg = config->volatile_reg;
|
||||
map->precious_reg = config->precious_reg;
|
||||
map->readable_noinc_reg = config->readable_noinc_reg;
|
||||
map->cache_type = config->cache_type;
|
||||
|
||||
spin_lock_init(&map->async_lock);
|
||||
|
@ -1285,6 +1298,7 @@ int regmap_reinit_cache(struct regmap *map, const struct regmap_config *config)
|
|||
map->readable_reg = config->readable_reg;
|
||||
map->volatile_reg = config->volatile_reg;
|
||||
map->precious_reg = config->precious_reg;
|
||||
map->readable_noinc_reg = config->readable_noinc_reg;
|
||||
map->cache_type = config->cache_type;
|
||||
|
||||
regmap_debugfs_init(map, config->name);
|
||||
|
@ -2564,7 +2578,70 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val,
|
|||
EXPORT_SYMBOL_GPL(regmap_raw_read);
|
||||
|
||||
/**
|
||||
* regmap_field_read() - Read a value to a single register field
|
||||
* regmap_noinc_read(): Read data from a register without incrementing the
|
||||
* register number
|
||||
*
|
||||
* @map: Register map to read from
|
||||
* @reg: Register to read from
|
||||
* @val: Pointer to data buffer
|
||||
* @val_len: Length of output buffer in bytes.
|
||||
*
|
||||
* The regmap API usually assumes that bulk bus read operations will read a
|
||||
* range of registers. Some devices have certain registers for which a read
|
||||
* operation read will read from an internal FIFO.
|
||||
*
|
||||
* The target register must be volatile but registers after it can be
|
||||
* completely unrelated cacheable registers.
|
||||
*
|
||||
* This will attempt multiple reads as required to read val_len bytes.
|
||||
*
|
||||
* A value of zero will be returned on success, a negative errno will be
|
||||
* returned in error cases.
|
||||
*/
|
||||
int regmap_noinc_read(struct regmap *map, unsigned int reg,
|
||||
void *val, size_t val_len)
|
||||
{
|
||||
size_t read_len;
|
||||
int ret;
|
||||
|
||||
if (!map->bus)
|
||||
return -EINVAL;
|
||||
if (!map->bus->read)
|
||||
return -ENOTSUPP;
|
||||
if (val_len % map->format.val_bytes)
|
||||
return -EINVAL;
|
||||
if (!IS_ALIGNED(reg, map->reg_stride))
|
||||
return -EINVAL;
|
||||
if (val_len == 0)
|
||||
return -EINVAL;
|
||||
|
||||
map->lock(map->lock_arg);
|
||||
|
||||
if (!regmap_volatile(map, reg) || !regmap_readable_noinc(map, reg)) {
|
||||
ret = -EINVAL;
|
||||
goto out_unlock;
|
||||
}
|
||||
|
||||
while (val_len) {
|
||||
if (map->max_raw_read && map->max_raw_read < val_len)
|
||||
read_len = map->max_raw_read;
|
||||
else
|
||||
read_len = val_len;
|
||||
ret = _regmap_raw_read(map, reg, val, read_len);
|
||||
if (ret)
|
||||
goto out_unlock;
|
||||
val = ((u8 *)val) + read_len;
|
||||
val_len -= read_len;
|
||||
}
|
||||
|
||||
out_unlock:
|
||||
map->unlock(map->lock_arg);
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(regmap_noinc_read);
|
||||
|
||||
/**
|
||||
* regmap_field_read(): Read a value to a single register field
|
||||
*
|
||||
* @field: Register field to read from
|
||||
* @val: Pointer to store read value
|
||||
|
|
|
@ -268,6 +268,13 @@ typedef void (*regmap_unlock)(void *);
|
|||
* field is NULL but precious_table (see below) is not, the
|
||||
* check is performed on such table (a register is precious if
|
||||
* it belongs to one of the ranges specified by precious_table).
|
||||
* @readable_noinc_reg: Optional callback returning true if the register
|
||||
* supports multiple read operations without incrementing
|
||||
* the register number. If this field is NULL but
|
||||
* rd_noinc_table (see below) is not, the check is
|
||||
* performed on such table (a register is no increment
|
||||
* readable if it belongs to one of the ranges specified
|
||||
* by rd_noinc_table).
|
||||
* @disable_locking: This regmap is either protected by external means or
|
||||
* is guaranteed not be be accessed from multiple threads.
|
||||
* Don't use any locking mechanisms.
|
||||
|
@ -295,6 +302,7 @@ typedef void (*regmap_unlock)(void *);
|
|||
* @rd_table: As above, for read access.
|
||||
* @volatile_table: As above, for volatile registers.
|
||||
* @precious_table: As above, for precious registers.
|
||||
* @rd_noinc_table: As above, for no increment readable registers.
|
||||
* @reg_defaults: Power on reset values for registers (for use with
|
||||
* register cache support).
|
||||
* @num_reg_defaults: Number of elements in reg_defaults.
|
||||
|
@ -344,6 +352,7 @@ struct regmap_config {
|
|||
bool (*readable_reg)(struct device *dev, unsigned int reg);
|
||||
bool (*volatile_reg)(struct device *dev, unsigned int reg);
|
||||
bool (*precious_reg)(struct device *dev, unsigned int reg);
|
||||
bool (*readable_noinc_reg)(struct device *dev, unsigned int reg);
|
||||
|
||||
bool disable_locking;
|
||||
regmap_lock lock;
|
||||
|
@ -360,6 +369,7 @@ struct regmap_config {
|
|||
const struct regmap_access_table *rd_table;
|
||||
const struct regmap_access_table *volatile_table;
|
||||
const struct regmap_access_table *precious_table;
|
||||
const struct regmap_access_table *rd_noinc_table;
|
||||
const struct reg_default *reg_defaults;
|
||||
unsigned int num_reg_defaults;
|
||||
enum regcache_type cache_type;
|
||||
|
@ -981,6 +991,8 @@ int regmap_raw_write_async(struct regmap *map, unsigned int reg,
|
|||
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);
|
||||
int regmap_noinc_read(struct regmap *map, unsigned int reg,
|
||||
void *val, size_t val_len);
|
||||
int regmap_bulk_read(struct regmap *map, unsigned int reg, void *val,
|
||||
size_t val_count);
|
||||
int regmap_update_bits_base(struct regmap *map, unsigned int reg,
|
||||
|
@ -1231,6 +1243,13 @@ static inline int regmap_raw_read(struct regmap *map, unsigned int reg,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
static inline int regmap_noinc_read(struct regmap *map, unsigned int reg,
|
||||
void *val, size_t val_len)
|
||||
{
|
||||
WARN_ONCE(1, "regmap API is disabled");
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
static inline int regmap_bulk_read(struct regmap *map, unsigned int reg,
|
||||
void *val, size_t val_count)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue