regmap: Allow devices to specify which registers are accessible

This is currently unused but we need to know which registers exist and
their properties in order to implement diagnostics like register map
dumps and the cache features.

We use callbacks partly because properties can vary at runtime (eg, through
access locks on registers) and partly because big switch statements are a
good compromise between readable code and small data size for providing
information on big register maps.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
This commit is contained in:
Mark Brown 2011-07-20 22:33:39 +01:00
parent dd898b2095
commit 2e2ae66df3
2 changed files with 22 additions and 0 deletions

View File

@ -37,6 +37,11 @@ struct regmap {
void *work_buf; /* Scratch buffer used to format I/O */ void *work_buf; /* Scratch buffer used to format I/O */
struct regmap_format format; /* Buffer format */ struct regmap_format format; /* Buffer format */
const struct regmap_bus *bus; const struct regmap_bus *bus;
unsigned int max_register;
bool (*writeable_reg)(struct device *dev, unsigned int reg);
bool (*readable_reg)(struct device *dev, unsigned int reg);
bool (*volatile_reg)(struct device *dev, unsigned int reg);
}; };
static void regmap_format_4_12_write(struct regmap *map, static void regmap_format_4_12_write(struct regmap *map,
@ -116,6 +121,10 @@ struct regmap *regmap_init(struct device *dev,
map->format.val_bytes = config->val_bits / 8; map->format.val_bytes = config->val_bits / 8;
map->dev = dev; map->dev = dev;
map->bus = bus; map->bus = bus;
map->max_register = config->max_register;
map->writeable_reg = config->writeable_reg;
map->readable_reg = config->readable_reg;
map->volatile_reg = config->volatile_reg;
switch (config->reg_bits) { switch (config->reg_bits) {
case 4: case 4:

View File

@ -25,10 +25,23 @@ struct spi_device;
* *
* @reg_bits: Number of bits in a register address, mandatory. * @reg_bits: Number of bits in a register address, mandatory.
* @val_bits: Number of bits in a register value, mandatory. * @val_bits: Number of bits in a register value, mandatory.
*
* @max_register: Optional, specifies the maximum valid register index.
* @writeable_register: Optional callback returning true if the register
* can be written to.
* @readable_register: Optional callback returning true if the register
* can be read from.
* @volatile_register: Optional callback returning true if the register
* value can't be cached.
*/ */
struct regmap_config { struct regmap_config {
int reg_bits; int reg_bits;
int val_bits; int val_bits;
unsigned int max_register;
bool (*writeable_reg)(struct device *dev, unsigned int reg);
bool (*readable_reg)(struct device *dev, unsigned int reg);
bool (*volatile_reg)(struct device *dev, unsigned int reg);
}; };
typedef int (*regmap_hw_write)(struct device *dev, const void *data, typedef int (*regmap_hw_write)(struct device *dev, const void *data,