hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/base/regmap/regmap-debugfs.c
....@@ -1,14 +1,10 @@
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>
128
139 #include <linux/slab.h>
1410 #include <linux/mutex.h>
....@@ -21,7 +17,6 @@
2117
2218 struct regmap_debugfs_node {
2319 struct regmap *map;
24
- const char *name;
2520 struct list_head link;
2621 };
2722
....@@ -188,11 +183,33 @@
188183 {
189184 /* Calculate the length of a fixed format */
190185 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);
192187 map->debugfs_val_len = 2 * map->format.val_bytes;
193188 map->debugfs_tot_len = map->debugfs_reg_len +
194189 map->debugfs_val_len + 3; /* : \n */
195190 }
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;
196213 }
197214
198215 static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
....@@ -221,12 +238,8 @@
221238 /* Work out which register we're starting at */
222239 start_reg = regmap_debugfs_get_dump_start(map, from, *ppos, &p);
223240
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)) {
230243
231244 /* If we're in the region the user is trying to read */
232245 if (p >= *ppos) {
....@@ -441,17 +454,7 @@
441454 return 0;
442455 }
443456
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);
455458
456459 static ssize_t regmap_cache_only_write_file(struct file *file,
457460 const char __user *user_buf,
....@@ -540,11 +543,12 @@
540543 .write = regmap_cache_bypass_write_file,
541544 };
542545
543
-void regmap_debugfs_init(struct regmap *map, const char *name)
546
+void regmap_debugfs_init(struct regmap *map)
544547 {
545548 struct rb_node *next;
546549 struct regmap_range_node *range_node;
547550 const char *devname = "dummy";
551
+ const char *name = map->name;
548552
549553 /*
550554 * Userspace can initiate reads from the hardware over debugfs.
....@@ -565,7 +569,6 @@
565569 if (!node)
566570 return;
567571 node->map = map;
568
- node->name = name;
569572 mutex_lock(&regmap_debugfs_early_lock);
570573 list_add(&node->link, &regmap_debugfs_early_list);
571574 mutex_unlock(&regmap_debugfs_early_lock);
....@@ -601,14 +604,6 @@
601604 }
602605
603606 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
- }
612607
613608 debugfs_create_file("name", 0400, map->debugfs,
614609 map, &regmap_name_fops);
....@@ -686,14 +681,10 @@
686681 struct regmap_debugfs_node *node, *tmp;
687682
688683 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
- }
693684
694685 mutex_lock(&regmap_debugfs_early_lock);
695686 list_for_each_entry_safe(node, tmp, &regmap_debugfs_early_list, link) {
696
- regmap_debugfs_init(node->map, node->name);
687
+ regmap_debugfs_init(node->map);
697688 list_del(&node->link);
698689 kfree(node);
699690 }