Commit cbc1938b authored by Mark Brown's avatar Mark Brown

regmap: Cache register and value sizes for debugfs

No point in calculating them every time.
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 1a61cfe3
...@@ -50,6 +50,10 @@ struct regmap { ...@@ -50,6 +50,10 @@ struct regmap {
#ifdef CONFIG_DEBUG_FS #ifdef CONFIG_DEBUG_FS
struct dentry *debugfs; struct dentry *debugfs;
const char *debugfs_name; const char *debugfs_name;
unsigned int debugfs_reg_len;
unsigned int debugfs_val_len;
unsigned int debugfs_tot_len;
#endif #endif
unsigned int max_register; unsigned int max_register;
......
...@@ -60,7 +60,6 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from, ...@@ -60,7 +60,6 @@ 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)
{ {
int reg_len, val_len, tot_len;
size_t buf_pos = 0; size_t buf_pos = 0;
loff_t p = 0; loff_t p = 0;
ssize_t ret; ssize_t ret;
...@@ -76,9 +75,13 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from, ...@@ -76,9 +75,13 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
return -ENOMEM; return -ENOMEM;
/* Calculate the length of a fixed format */ /* Calculate the length of a fixed format */
reg_len = regmap_calc_reg_len(map->max_register, buf, count); if (!map->debugfs_tot_len) {
val_len = 2 * map->format.val_bytes; map->debugfs_reg_len = regmap_calc_reg_len(map->max_register,
tot_len = reg_len + val_len + 3; /* : \n */ 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 = from; i <= to; i += map->reg_stride) { for (i = from; i <= to; i += map->reg_stride) {
if (!regmap_readable(map, i)) if (!regmap_readable(map, i))
...@@ -90,26 +93,27 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from, ...@@ -90,26 +93,27 @@ 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 >= count - 1 - tot_len) if (buf_pos >= count - 1 - map->debugfs_tot_len)
break; break;
/* Format the register */ /* Format the register */
snprintf(buf + buf_pos, count - buf_pos, "%.*x: ", snprintf(buf + buf_pos, count - buf_pos, "%.*x: ",
reg_len, i - from); map->debugfs_reg_len, i - from);
buf_pos += reg_len + 2; buf_pos += map->debugfs_reg_len + 2;
/* Format the value, write all X if we can't read */ /* Format the value, write all X if we can't read */
ret = regmap_read(map, i, &val); ret = regmap_read(map, i, &val);
if (ret == 0) if (ret == 0)
snprintf(buf + buf_pos, count - buf_pos, snprintf(buf + buf_pos, count - buf_pos,
"%.*x", val_len, val); "%.*x", map->debugfs_val_len, val);
else 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_pos += 2 * map->format.val_bytes;
buf[buf_pos++] = '\n'; buf[buf_pos++] = '\n';
} }
p += tot_len; p += map->debugfs_tot_len;
} }
ret = buf_pos; ret = buf_pos;
......
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