13 #include <linux/slab.h>
17 #include <linux/device.h>
21 static struct dentry *regmap_debugfs_root;
24 static size_t regmap_calc_reg_len(
int max_val,
char *
buf,
size_t buf_size)
26 snprintf(buf, buf_size,
"%x", max_val);
31 char __user *user_buf,
size_t count,
55 .read = regmap_name_read_file,
59 static ssize_t regmap_map_read_file(
struct file *file,
char __user *user_buf,
60 size_t count, loff_t *ppos)
62 int reg_len, val_len, tot_len;
71 if (*ppos < 0 || !count)
79 reg_len = regmap_calc_reg_len(map->
max_register, buf, count);
80 val_len = 2 * map->
format.val_bytes;
81 tot_len = reg_len + val_len + 3;
93 if (buf_pos >= count - 1 - tot_len)
97 snprintf(buf + buf_pos, count - buf_pos,
"%.*x: ",
99 buf_pos += reg_len + 2;
104 snprintf(buf + buf_pos, count - buf_pos,
105 "%.*x", val_len, val);
107 memset(buf + buf_pos,
'X', val_len);
108 buf_pos += 2 * map->
format.val_bytes;
110 buf[buf_pos++] =
'\n';
129 #undef REGMAP_ALLOW_WRITE_DEBUGFS
130 #ifdef REGMAP_ALLOW_WRITE_DEBUGFS
138 const char __user *user_buf,
139 size_t count, loff_t *ppos)
147 buf_size =
min(count, (
sizeof(buf)-1));
152 while (*start ==
' ')
155 while (*start ==
' ')
167 #define regmap_map_write_file NULL
172 .read = regmap_map_read_file,
177 static ssize_t regmap_access_read_file(
struct file *file,
178 char __user *user_buf,
size_t count,
181 int reg_len, tot_len;
189 if (*ppos < 0 || !count)
197 reg_len = regmap_calc_reg_len(map->
max_register, buf, count);
198 tot_len = reg_len + 10;
208 if (buf_pos >= count - 1 - tot_len)
212 snprintf(buf + buf_pos, count - buf_pos,
213 "%.*x: %c %c %c %c\n",
241 .read = regmap_access_read_file,
249 dev_name(map->
dev), name);
250 name = map->debugfs_name;
252 name = dev_name(map->
dev);
257 dev_warn(map->
dev,
"Failed to create debugfs directory\n");
262 map, ®map_name_fops);
266 map, ®map_map_fops);
268 map, ®map_access_fops);
284 kfree(map->debugfs_name);
290 if (!regmap_debugfs_root) {
291 pr_warn(
"regmap: Failed to create debugfs root\n");