Commit 43280026 authored by Mark Brown's avatar Mark Brown

Merge remote-tracking branch 'regmap/topic/debugfs' into regmap-next

parents 3689cf7f 4dd7c553
...@@ -26,6 +26,7 @@ struct regmap_debugfs_off_cache { ...@@ -26,6 +26,7 @@ struct regmap_debugfs_off_cache {
off_t min; off_t min;
off_t max; off_t max;
unsigned int base_reg; unsigned int base_reg;
unsigned int max_reg;
}; };
struct regmap_format { struct regmap_format {
......
...@@ -81,6 +81,8 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map, ...@@ -81,6 +81,8 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map,
struct regmap_debugfs_off_cache *c = NULL; struct regmap_debugfs_off_cache *c = NULL;
loff_t p = 0; loff_t p = 0;
unsigned int i, ret; unsigned int i, ret;
unsigned int fpos_offset;
unsigned int reg_offset;
/* /*
* If we don't have a cache build one so we don't have to do a * If we don't have a cache build one so we don't have to do a
...@@ -93,6 +95,9 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map, ...@@ -93,6 +95,9 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map,
regmap_precious(map, i)) { regmap_precious(map, i)) {
if (c) { if (c) {
c->max = p - 1; c->max = p - 1;
fpos_offset = c->max - c->min;
reg_offset = fpos_offset / map->debugfs_tot_len;
c->max_reg = c->base_reg + reg_offset;
list_add_tail(&c->list, list_add_tail(&c->list,
&map->debugfs_off_cache); &map->debugfs_off_cache);
c = NULL; c = NULL;
...@@ -119,6 +124,9 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map, ...@@ -119,6 +124,9 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map,
/* Close the last entry off if we didn't scan beyond it */ /* Close the last entry off if we didn't scan beyond it */
if (c) { if (c) {
c->max = p - 1; c->max = p - 1;
fpos_offset = c->max - c->min;
reg_offset = fpos_offset / map->debugfs_tot_len;
c->max_reg = c->base_reg + reg_offset;
list_add_tail(&c->list, list_add_tail(&c->list,
&map->debugfs_off_cache); &map->debugfs_off_cache);
} }
...@@ -128,25 +136,38 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map, ...@@ -128,25 +136,38 @@ static unsigned int regmap_debugfs_get_dump_start(struct regmap *map,
* allocate and we should never be in this code if there are * allocate and we should never be in this code if there are
* no registers at all. * no registers at all.
*/ */
if (list_empty(&map->debugfs_off_cache)) {
WARN_ON(list_empty(&map->debugfs_off_cache)); WARN_ON(list_empty(&map->debugfs_off_cache));
return base; ret = base;
}
/* Find the relevant block */ /* Find the relevant block:offset */
list_for_each_entry(c, &map->debugfs_off_cache, list) { list_for_each_entry(c, &map->debugfs_off_cache, list) {
if (from >= c->min && from <= c->max) { if (from >= c->min && from <= c->max) {
*pos = c->min; fpos_offset = from - c->min;
return c->base_reg; reg_offset = fpos_offset / map->debugfs_tot_len;
*pos = c->min + (reg_offset * map->debugfs_tot_len);
return c->base_reg + reg_offset;
} }
*pos = c->min; *pos = c->max;
ret = c->base_reg; ret = c->max_reg;
} }
return ret; return ret;
} }
static inline void regmap_calc_tot_len(struct regmap *map,
void *buf, size_t count)
{
/* Calculate the length of a fixed format */
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 */
}
}
static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from, static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
unsigned int to, char __user *user_buf, unsigned int to, char __user *user_buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
...@@ -165,14 +186,7 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from, ...@@ -165,14 +186,7 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
if (!buf) if (!buf)
return -ENOMEM; return -ENOMEM;
/* Calculate the length of a fixed format */ regmap_calc_tot_len(map, buf, count);
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 */
}
/* Work out which register we're starting at */ /* Work out which register we're starting at */
start_reg = regmap_debugfs_get_dump_start(map, from, *ppos, &p); start_reg = regmap_debugfs_get_dump_start(map, from, *ppos, &p);
...@@ -187,7 +201,7 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from, ...@@ -187,7 +201,7 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
/* If we're in the region the user is trying to read */ /* If we're in the region the user is trying to read */
if (p >= *ppos) { if (p >= *ppos) {
/* ...but not beyond it */ /* ...but not beyond it */
if (buf_pos + 1 + map->debugfs_tot_len >= count) if (buf_pos + map->debugfs_tot_len > count)
break; break;
/* Format the register */ /* Format the register */
......
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