Commit 99b8f42e authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'regmap-3.8' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap

Pull regmap updates from Mark Brown:
 "Quite a few enhancements this time around, helpers and diagnostics for
  the most part which is good to see:

   - Addition of table based lookups for the register access checks from
     Davide Ciminaghi, making life easier for drivers with big blocks of
     similar registers.
   - Allow drivers to get the irqdomain for regmap irq_chips, allowing
     the domain to be used with other APIs.
   - Debug improvements for paged register maps.
   - Performance improvments for some of the diagnostic infrastructure,
     very helpful for devices with large register maps."

* tag 'regmap-3.8' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap:
  regmap: debugfs: Cache offsets of valid regions for dump
  regmap: debugfs: Factor out initial seek
  regmap: debugfs: Avoid overflows for very small reads
  regmap: Cache register and value sizes for debugfs
  regmap: introduce tables for readable/writeable/volatile/precious checks
  regmap: core: Report registers in hex when we can't cache
  regmap: Fix printing of size_t variable
  regmap: make lock/unlock functions customizable
  regmap: silence GCC warning
  regmap: Split raw writes that cross window boundaries
  regmap: Make return code checks consistent
  regmap: Factor range lookup out of page selection
  regmap: Provide debugfs read of register ranges
  regmap: Factor out debugfs register read
  regmap: Allow ranges to be named
  regmap: When we sanity check during range adds say what errors we find
  regmap: Rename n_ranges to num_ranges
  regmap: irq: Allow users to retrieve the irq_domain
parents 139353ff 7c8a2994
......@@ -15,10 +15,18 @@
#include <linux/regmap.h>
#include <linux/fs.h>
#include <linux/list.h>
struct regmap;
struct regcache_ops;
struct regmap_debugfs_off_cache {
struct list_head list;
off_t min;
off_t max;
unsigned int base_reg;
};
struct regmap_format {
size_t buf_size;
size_t reg_bytes;
......@@ -31,14 +39,12 @@ struct regmap_format {
unsigned int (*parse_val)(void *buf);
};
typedef void (*regmap_lock)(struct regmap *map);
typedef void (*regmap_unlock)(struct regmap *map);
struct regmap {
struct mutex mutex;
spinlock_t spinlock;
regmap_lock lock;
regmap_unlock unlock;
void *lock_arg; /* This is passed to lock/unlock functions */
struct device *dev; /* Device we do I/O on */
void *work_buf; /* Scratch buffer used to format I/O */
......@@ -50,6 +56,12 @@ struct regmap {
#ifdef CONFIG_DEBUG_FS
struct dentry *debugfs;
const char *debugfs_name;
unsigned int debugfs_reg_len;
unsigned int debugfs_val_len;
unsigned int debugfs_tot_len;
struct list_head debugfs_off_cache;
#endif
unsigned int max_register;
......@@ -57,6 +69,10 @@ 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);
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;
u8 read_flag_mask;
u8 write_flag_mask;
......@@ -120,6 +136,8 @@ int _regmap_write(struct regmap *map, unsigned int reg,
struct regmap_range_node {
struct rb_node node;
const char *name;
struct regmap *map;
unsigned int range_min;
unsigned int range_max;
......
......@@ -56,17 +56,74 @@ static const struct file_operations regmap_name_fops = {
.llseek = default_llseek,
};
static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos)
/*
* Work out where the start offset maps into register numbers, bearing
* in mind that we suppress hidden registers.
*/
static unsigned int regmap_debugfs_get_dump_start(struct regmap *map,
unsigned int base,
loff_t from,
loff_t *pos)
{
int reg_len, val_len, tot_len;
size_t buf_pos = 0;
struct regmap_debugfs_off_cache *c = NULL;
loff_t p = 0;
unsigned int i, ret;
/*
* If we don't have a cache build one so we don't have to do a
* linear scan each time.
*/
if (list_empty(&map->debugfs_off_cache)) {
for (i = base; i <= map->max_register; i += map->reg_stride) {
/* Skip unprinted registers, closing off cache entry */
if (!regmap_readable(map, i) ||
regmap_precious(map, i)) {
if (c) {
c->max = p - 1;
list_add_tail(&c->list,
&map->debugfs_off_cache);
c = NULL;
}
continue;
}
/* No cache entry? Start a new one */
if (!c) {
c = kzalloc(sizeof(*c), GFP_KERNEL);
if (!c)
break;
c->min = p;
c->base_reg = i;
}
p += map->debugfs_tot_len;
}
}
/* Find the relevant block */
list_for_each_entry(c, &map->debugfs_off_cache, list) {
if (*pos >= c->min && *pos <= c->max) {
*pos = c->min;
return c->base_reg;
}
ret = c->max;
}
return ret;
}
static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
unsigned int to, char __user *user_buf,
size_t count, loff_t *ppos)
{
size_t buf_pos = 0;
loff_t p = *ppos;
ssize_t ret;
int i;
struct regmap *map = file->private_data;
char *buf;
unsigned int val;
unsigned int val, start_reg;
if (*ppos < 0 || !count)
return -EINVAL;
......@@ -76,11 +133,18 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
return -ENOMEM;
/* Calculate the length of a fixed format */
reg_len = regmap_calc_reg_len(map->max_register, buf, count);
val_len = 2 * map->format.val_bytes;
tot_len = reg_len + val_len + 3; /* : \n */
if (!map->debugfs_tot_len) {
map->debugfs_reg_len = regmap_calc_reg_len(map->max_register,
buf, count);
map->debugfs_val_len = 2 * map->format.val_bytes;
map->debugfs_tot_len = map->debugfs_reg_len +
map->debugfs_val_len + 3; /* : \n */
}
for (i = 0; i <= map->max_register; i += map->reg_stride) {
/* Work out which register we're starting at */
start_reg = regmap_debugfs_get_dump_start(map, from, *ppos, &p);
for (i = start_reg; i <= to; i += map->reg_stride) {
if (!regmap_readable(map, i))
continue;
......@@ -90,26 +154,27 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
/* If we're in the region the user is trying to read */
if (p >= *ppos) {
/* ...but not beyond it */
if (buf_pos >= count - 1 - tot_len)
if (buf_pos + 1 + map->debugfs_tot_len >= count)
break;
/* Format the register */
snprintf(buf + buf_pos, count - buf_pos, "%.*x: ",
reg_len, i);
buf_pos += reg_len + 2;
map->debugfs_reg_len, i - from);
buf_pos += map->debugfs_reg_len + 2;
/* Format the value, write all X if we can't read */
ret = regmap_read(map, i, &val);
if (ret == 0)
snprintf(buf + buf_pos, count - buf_pos,
"%.*x", val_len, val);
"%.*x", map->debugfs_val_len, val);
else
memset(buf + buf_pos, 'X', val_len);
memset(buf + buf_pos, 'X',
map->debugfs_val_len);
buf_pos += 2 * map->format.val_bytes;
buf[buf_pos++] = '\n';
}
p += tot_len;
p += map->debugfs_tot_len;
}
ret = buf_pos;
......@@ -126,6 +191,15 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
return ret;
}
static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos)
{
struct regmap *map = file->private_data;
return regmap_read_debugfs(map, 0, map->max_register, user_buf,
count, ppos);
}
#undef REGMAP_ALLOW_WRITE_DEBUGFS
#ifdef REGMAP_ALLOW_WRITE_DEBUGFS
/*
......@@ -174,6 +248,22 @@ static const struct file_operations regmap_map_fops = {
.llseek = default_llseek,
};
static ssize_t regmap_range_read_file(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos)
{
struct regmap_range_node *range = file->private_data;
struct regmap *map = range->map;
return regmap_read_debugfs(map, range->range_min, range->range_max,
user_buf, count, ppos);
}
static const struct file_operations regmap_range_fops = {
.open = simple_open,
.read = regmap_range_read_file,
.llseek = default_llseek,
};
static ssize_t regmap_access_read_file(struct file *file,
char __user *user_buf, size_t count,
loff_t *ppos)
......@@ -244,6 +334,11 @@ static const struct file_operations regmap_access_fops = {
void regmap_debugfs_init(struct regmap *map, const char *name)
{
struct rb_node *next;
struct regmap_range_node *range_node;
INIT_LIST_HEAD(&map->debugfs_off_cache);
if (name) {
map->debugfs_name = kasprintf(GFP_KERNEL, "%s-%s",
dev_name(map->dev), name);
......@@ -276,11 +371,32 @@ void regmap_debugfs_init(struct regmap *map, const char *name)
debugfs_create_bool("cache_bypass", 0400, map->debugfs,
&map->cache_bypass);
}
next = rb_first(&map->range_tree);
while (next) {
range_node = rb_entry(next, struct regmap_range_node, node);
if (range_node->name)
debugfs_create_file(range_node->name, 0400,
map->debugfs, range_node,
&regmap_range_fops);
next = rb_next(&range_node->node);
}
}
void regmap_debugfs_exit(struct regmap *map)
{
struct regmap_debugfs_off_cache *c;
debugfs_remove_recursive(map->debugfs);
while (!list_empty(&map->debugfs_off_cache)) {
c = list_first_entry(&map->debugfs_off_cache,
struct regmap_debugfs_off_cache,
list);
list_del(&c->list);
kfree(c);
}
kfree(map->debugfs_name);
}
......
......@@ -458,3 +458,22 @@ int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq)
return irq_create_mapping(data->domain, irq);
}
EXPORT_SYMBOL_GPL(regmap_irq_get_virq);
/**
* regmap_irq_get_domain(): Retrieve the irq_domain for the chip
*
* Useful for drivers to request their own IRQs and for integration
* with subsystems. For ease of integration NULL is accepted as a
* domain, allowing devices to just call this even if no domain is
* allocated.
*
* @data: regmap_irq controller to operate on.
*/
struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data)
{
if (data)
return data->domain;
else
return NULL;
}
EXPORT_SYMBOL_GPL(regmap_irq_get_domain);
This diff is collapsed.
......@@ -19,6 +19,7 @@
struct module;
struct device;
struct i2c_client;
struct irq_domain;
struct spi_device;
struct regmap;
struct regmap_range_cfg;
......@@ -53,6 +54,39 @@ enum regmap_endian {
REGMAP_ENDIAN_NATIVE,
};
/**
* A register range, used for access related checks
* (readable/writeable/volatile/precious checks)
*
* @range_min: address of first register
* @range_max: address of last register
*/
struct regmap_range {
unsigned int range_min;
unsigned int range_max;
};
/*
* A table of ranges including some yes ranges and some no ranges.
* If a register belongs to a no_range, the corresponding check function
* will return false. If a register belongs to a yes range, the corresponding
* check function will return true. "no_ranges" are searched first.
*
* @yes_ranges : pointer to an array of regmap ranges used as "yes ranges"
* @n_yes_ranges: size of the above array
* @no_ranges: pointer to an array of regmap ranges used as "no ranges"
* @n_no_ranges: size of the above array
*/
struct regmap_access_table {
const struct regmap_range *yes_ranges;
unsigned int n_yes_ranges;
const struct regmap_range *no_ranges;
unsigned int n_no_ranges;
};
typedef void (*regmap_lock)(void *);
typedef void (*regmap_unlock)(void *);
/**
* Configuration for the register map of a device.
*
......@@ -67,16 +101,39 @@ enum regmap_endian {
* @val_bits: Number of bits in a register value, mandatory.
*
* @writeable_reg: Optional callback returning true if the register
* can be written to.
* can be written to. If this field is NULL but wr_table
* (see below) is not, the check is performed on such table
* (a register is writeable if it belongs to one of the ranges
* specified by wr_table).
* @readable_reg: Optional callback returning true if the register
* can be read from.
* can be read from. If this field is NULL but rd_table
* (see below) is not, the check is performed on such table
* (a register is readable if it belongs to one of the ranges
* specified by rd_table).
* @volatile_reg: Optional callback returning true if the register
* value can't be cached.
* value can't be cached. If this field is NULL but
* volatile_table (see below) is not, the check is performed on
* such table (a register is volatile if it belongs to one of
* the ranges specified by volatile_table).
* @precious_reg: Optional callback returning true if the rgister
* should not be read outside of a call from the driver
* (eg, a clear on read interrupt status register).
* should not be read outside of a call from the driver
* (eg, a clear on read interrupt status register). If this
* 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).
* @lock: Optional lock callback (overrides regmap's default lock
* function, based on spinlock or mutex).
* @unlock: As above for unlocking.
* @lock_arg: this field is passed as the only argument of lock/unlock
* functions (ignored in case regular lock/unlock functions
* are not overridden).
*
* @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.
* @rd_table: As above, for read access.
* @volatile_table: As above, for volatile registers.
* @precious_table: As above, for precious registers.
* @reg_defaults: Power on reset values for registers (for use with
* register cache support).
* @num_reg_defaults: Number of elements in reg_defaults.
......@@ -116,8 +173,15 @@ 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);
regmap_lock lock;
regmap_unlock unlock;
void *lock_arg;
unsigned int max_register;
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 reg_default *reg_defaults;
unsigned int num_reg_defaults;
enum regcache_type cache_type;
......@@ -133,7 +197,7 @@ struct regmap_config {
enum regmap_endian val_format_endian;
const struct regmap_range_cfg *ranges;
unsigned int n_ranges;
unsigned int num_ranges;
};
/**
......@@ -142,6 +206,8 @@ struct regmap_config {
* 1. page selector register update;
* 2. access through data window registers.
*
* @name: Descriptive name for diagnostics
*
* @range_min: Address of the lowest register address in virtual range.
* @range_max: Address of the highest register in virtual range.
*
......@@ -153,6 +219,8 @@ struct regmap_config {
* @window_len: Number of registers in data window.
*/
struct regmap_range_cfg {
const char *name;
/* Registers of virtual address range */
unsigned int range_min;
unsigned int range_max;
......@@ -181,7 +249,9 @@ typedef void (*regmap_hw_free_context)(void *context);
* Description of a hardware bus for the register map infrastructure.
*
* @fast_io: Register IO is fast. Use a spinlock instead of a mutex
* to perform locking.
* to perform locking. This field is ignored if custom lock/unlock
* functions are used (see fields lock/unlock of
* struct regmap_config).
* @write: Write operation.
* @gather_write: Write operation with split register/value, return -ENOTSUPP
* if not implemented on a given device.
......@@ -262,6 +332,16 @@ void regcache_mark_dirty(struct regmap *map);
int regmap_register_patch(struct regmap *map, const struct reg_default *regs,
int num_regs);
static inline bool regmap_reg_in_range(unsigned int reg,
const struct regmap_range *range)
{
return reg >= range->range_min && reg <= range->range_max;
}
bool regmap_reg_in_ranges(unsigned int reg,
const struct regmap_range *ranges,
unsigned int nranges);
/**
* Description of an IRQ for the generic regmap irq_chip.
*
......@@ -317,6 +397,7 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
void regmap_del_irq_chip(int irq, struct regmap_irq_chip_data *data);
int regmap_irq_chip_get_base(struct regmap_irq_chip_data *data);
int regmap_irq_get_virq(struct regmap_irq_chip_data *data, int irq);
struct irq_domain *regmap_irq_get_domain(struct regmap_irq_chip_data *data);
#else
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment