.. | .. |
---|
1 | | -/* |
---|
2 | | - * Register map access API - debugfs |
---|
3 | | - * |
---|
4 | | - * Copyright 2011 Wolfson Microelectronics plc |
---|
5 | | - * |
---|
6 | | - * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
---|
7 | | - * |
---|
8 | | - * This program is free software; you can redistribute it and/or modify |
---|
9 | | - * it under the terms of the GNU General Public License version 2 as |
---|
10 | | - * published by the Free Software Foundation. |
---|
11 | | - */ |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
---|
| 2 | +// |
---|
| 3 | +// Register map access API - debugfs |
---|
| 4 | +// |
---|
| 5 | +// Copyright 2011 Wolfson Microelectronics plc |
---|
| 6 | +// |
---|
| 7 | +// Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
---|
12 | 8 | |
---|
13 | 9 | #include <linux/slab.h> |
---|
14 | 10 | #include <linux/mutex.h> |
---|
.. | .. |
---|
21 | 17 | |
---|
22 | 18 | struct regmap_debugfs_node { |
---|
23 | 19 | struct regmap *map; |
---|
24 | | - const char *name; |
---|
25 | 20 | struct list_head link; |
---|
26 | 21 | }; |
---|
27 | 22 | |
---|
.. | .. |
---|
188 | 183 | { |
---|
189 | 184 | /* Calculate the length of a fixed format */ |
---|
190 | 185 | if (!map->debugfs_tot_len) { |
---|
191 | | - map->debugfs_reg_len = regmap_calc_reg_len(map->max_register), |
---|
| 186 | + map->debugfs_reg_len = regmap_calc_reg_len(map->max_register); |
---|
192 | 187 | map->debugfs_val_len = 2 * map->format.val_bytes; |
---|
193 | 188 | map->debugfs_tot_len = map->debugfs_reg_len + |
---|
194 | 189 | map->debugfs_val_len + 3; /* : \n */ |
---|
195 | 190 | } |
---|
| 191 | +} |
---|
| 192 | + |
---|
| 193 | +static int regmap_next_readable_reg(struct regmap *map, int reg) |
---|
| 194 | +{ |
---|
| 195 | + struct regmap_debugfs_off_cache *c; |
---|
| 196 | + int ret = -EINVAL; |
---|
| 197 | + |
---|
| 198 | + if (regmap_printable(map, reg + map->reg_stride)) { |
---|
| 199 | + ret = reg + map->reg_stride; |
---|
| 200 | + } else { |
---|
| 201 | + mutex_lock(&map->cache_lock); |
---|
| 202 | + list_for_each_entry(c, &map->debugfs_off_cache, list) { |
---|
| 203 | + if (reg > c->max_reg) |
---|
| 204 | + continue; |
---|
| 205 | + if (reg < c->base_reg) { |
---|
| 206 | + ret = c->base_reg; |
---|
| 207 | + break; |
---|
| 208 | + } |
---|
| 209 | + } |
---|
| 210 | + mutex_unlock(&map->cache_lock); |
---|
| 211 | + } |
---|
| 212 | + return ret; |
---|
196 | 213 | } |
---|
197 | 214 | |
---|
198 | 215 | static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from, |
---|
.. | .. |
---|
221 | 238 | /* Work out which register we're starting at */ |
---|
222 | 239 | start_reg = regmap_debugfs_get_dump_start(map, from, *ppos, &p); |
---|
223 | 240 | |
---|
224 | | - for (i = start_reg; i <= to; i += map->reg_stride) { |
---|
225 | | - if (!regmap_readable(map, i) && !regmap_cached(map, i)) |
---|
226 | | - continue; |
---|
227 | | - |
---|
228 | | - if (regmap_precious(map, i)) |
---|
229 | | - continue; |
---|
| 241 | + for (i = start_reg; i >= 0 && i <= to; |
---|
| 242 | + i = regmap_next_readable_reg(map, i)) { |
---|
230 | 243 | |
---|
231 | 244 | /* If we're in the region the user is trying to read */ |
---|
232 | 245 | if (p >= *ppos) { |
---|
.. | .. |
---|
441 | 454 | return 0; |
---|
442 | 455 | } |
---|
443 | 456 | |
---|
444 | | -static int access_open(struct inode *inode, struct file *file) |
---|
445 | | -{ |
---|
446 | | - return single_open(file, regmap_access_show, inode->i_private); |
---|
447 | | -} |
---|
448 | | - |
---|
449 | | -static const struct file_operations regmap_access_fops = { |
---|
450 | | - .open = access_open, |
---|
451 | | - .read = seq_read, |
---|
452 | | - .llseek = seq_lseek, |
---|
453 | | - .release = single_release, |
---|
454 | | -}; |
---|
| 457 | +DEFINE_SHOW_ATTRIBUTE(regmap_access); |
---|
455 | 458 | |
---|
456 | 459 | static ssize_t regmap_cache_only_write_file(struct file *file, |
---|
457 | 460 | const char __user *user_buf, |
---|
.. | .. |
---|
540 | 543 | .write = regmap_cache_bypass_write_file, |
---|
541 | 544 | }; |
---|
542 | 545 | |
---|
543 | | -void regmap_debugfs_init(struct regmap *map, const char *name) |
---|
| 546 | +void regmap_debugfs_init(struct regmap *map) |
---|
544 | 547 | { |
---|
545 | 548 | struct rb_node *next; |
---|
546 | 549 | struct regmap_range_node *range_node; |
---|
547 | 550 | const char *devname = "dummy"; |
---|
| 551 | + const char *name = map->name; |
---|
548 | 552 | |
---|
549 | 553 | /* |
---|
550 | 554 | * Userspace can initiate reads from the hardware over debugfs. |
---|
.. | .. |
---|
565 | 569 | if (!node) |
---|
566 | 570 | return; |
---|
567 | 571 | node->map = map; |
---|
568 | | - node->name = name; |
---|
569 | 572 | mutex_lock(®map_debugfs_early_lock); |
---|
570 | 573 | list_add(&node->link, ®map_debugfs_early_list); |
---|
571 | 574 | mutex_unlock(®map_debugfs_early_lock); |
---|
.. | .. |
---|
601 | 604 | } |
---|
602 | 605 | |
---|
603 | 606 | map->debugfs = debugfs_create_dir(name, regmap_debugfs_root); |
---|
604 | | - if (!map->debugfs) { |
---|
605 | | - dev_warn(map->dev, |
---|
606 | | - "Failed to create %s debugfs directory\n", name); |
---|
607 | | - |
---|
608 | | - kfree(map->debugfs_name); |
---|
609 | | - map->debugfs_name = NULL; |
---|
610 | | - return; |
---|
611 | | - } |
---|
612 | 607 | |
---|
613 | 608 | debugfs_create_file("name", 0400, map->debugfs, |
---|
614 | 609 | map, ®map_name_fops); |
---|
.. | .. |
---|
686 | 681 | struct regmap_debugfs_node *node, *tmp; |
---|
687 | 682 | |
---|
688 | 683 | regmap_debugfs_root = debugfs_create_dir("regmap", NULL); |
---|
689 | | - if (!regmap_debugfs_root) { |
---|
690 | | - pr_warn("regmap: Failed to create debugfs root\n"); |
---|
691 | | - return; |
---|
692 | | - } |
---|
693 | 684 | |
---|
694 | 685 | mutex_lock(®map_debugfs_early_lock); |
---|
695 | 686 | list_for_each_entry_safe(node, tmp, ®map_debugfs_early_list, link) { |
---|
696 | | - regmap_debugfs_init(node->map, node->name); |
---|
| 687 | + regmap_debugfs_init(node->map); |
---|
697 | 688 | list_del(&node->link); |
---|
698 | 689 | kfree(node); |
---|
699 | 690 | } |
---|