aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/regmap/regmap-debugfs.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2012-12-05 23:29:05 -0500
committerMark Brown <broonie@opensource.wolfsonmicro.com>2012-12-06 01:10:21 -0500
commitcbc1938badc31f43ab77e92a9b1a51c4fe8b4113 (patch)
tree2a0ac524a04b56ce06e413ff4058a722c6f107b7 /drivers/base/regmap/regmap-debugfs.c
parent1a61cfe3445218637f38b355c76fc3132865a0a6 (diff)
regmap: Cache register and value sizes for debugfs
No point in calculating them every time. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/base/regmap/regmap-debugfs.c')
-rw-r--r--drivers/base/regmap/regmap-debugfs.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index f4b9dd01c981..00fbd58706b2 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -60,7 +60,6 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
60 unsigned int to, char __user *user_buf, 60 unsigned int to, char __user *user_buf,
61 size_t count, loff_t *ppos) 61 size_t count, loff_t *ppos)
62{ 62{
63 int reg_len, val_len, tot_len;
64 size_t buf_pos = 0; 63 size_t buf_pos = 0;
65 loff_t p = 0; 64 loff_t p = 0;
66 ssize_t ret; 65 ssize_t ret;
@@ -76,9 +75,13 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
76 return -ENOMEM; 75 return -ENOMEM;
77 76
78 /* Calculate the length of a fixed format */ 77 /* Calculate the length of a fixed format */
79 reg_len = regmap_calc_reg_len(map->max_register, buf, count); 78 if (!map->debugfs_tot_len) {
80 val_len = 2 * map->format.val_bytes; 79 map->debugfs_reg_len = regmap_calc_reg_len(map->max_register,
81 tot_len = reg_len + val_len + 3; /* : \n */ 80 buf, count);
81 map->debugfs_val_len = 2 * map->format.val_bytes;
82 map->debugfs_tot_len = map->debugfs_reg_len +
83 map->debugfs_val_len + 3; /* : \n */
84 }
82 85
83 for (i = from; i <= to; i += map->reg_stride) { 86 for (i = from; i <= to; i += map->reg_stride) {
84 if (!regmap_readable(map, i)) 87 if (!regmap_readable(map, i))
@@ -90,26 +93,27 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
90 /* If we're in the region the user is trying to read */ 93 /* If we're in the region the user is trying to read */
91 if (p >= *ppos) { 94 if (p >= *ppos) {
92 /* ...but not beyond it */ 95 /* ...but not beyond it */
93 if (buf_pos >= count - 1 - tot_len) 96 if (buf_pos >= count - 1 - map->debugfs_tot_len)
94 break; 97 break;
95 98
96 /* Format the register */ 99 /* Format the register */
97 snprintf(buf + buf_pos, count - buf_pos, "%.*x: ", 100 snprintf(buf + buf_pos, count - buf_pos, "%.*x: ",
98 reg_len, i - from); 101 map->debugfs_reg_len, i - from);
99 buf_pos += reg_len + 2; 102 buf_pos += map->debugfs_reg_len + 2;
100 103
101 /* Format the value, write all X if we can't read */ 104 /* Format the value, write all X if we can't read */
102 ret = regmap_read(map, i, &val); 105 ret = regmap_read(map, i, &val);
103 if (ret == 0) 106 if (ret == 0)
104 snprintf(buf + buf_pos, count - buf_pos, 107 snprintf(buf + buf_pos, count - buf_pos,
105 "%.*x", val_len, val); 108 "%.*x", map->debugfs_val_len, val);
106 else 109 else
107 memset(buf + buf_pos, 'X', val_len); 110 memset(buf + buf_pos, 'X',
111 map->debugfs_val_len);
108 buf_pos += 2 * map->format.val_bytes; 112 buf_pos += 2 * map->format.val_bytes;
109 113
110 buf[buf_pos++] = '\n'; 114 buf[buf_pos++] = '\n';
111 } 115 }
112 p += tot_len; 116 p += map->debugfs_tot_len;
113 } 117 }
114 118
115 ret = buf_pos; 119 ret = buf_pos;