regmap: debugfs: Factor out initial seek
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Sun, 9 Dec 2012 08:20:10 +0000 (17:20 +0900)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 10 Dec 2012 16:29:47 +0000 (01:29 +0900)
In preparation for doing things a bit more quickly than a linear scan
factor out the initial seek from the debugfs register dump.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
drivers/base/regmap/regmap-debugfs.c

index 3df274e06062443968035ca47a2a14d53164d196..749a1dc5bbfbbbf5e371ac712979b6c8e422a500 100644 (file)
@@ -56,16 +56,46 @@ static const struct file_operations regmap_name_fops = {
        .llseek = default_llseek,
 };
 
+/*
+ * Work out where the start offset maps into register numbers, bearing
+ * in mind that we suppress hidden registers.
+ */
+static unsigned int regmap_debugfs_get_dump_start(struct regmap *map,
+                                                 unsigned int base,
+                                                 loff_t from,
+                                                 loff_t *pos)
+{
+       loff_t p = *pos;
+       unsigned int i;
+
+       for (i = base; i <= map->max_register; i += map->reg_stride) {
+               if (!regmap_readable(map, i))
+                       continue;
+
+               if (regmap_precious(map, i))
+                       continue;
+
+               if (i >= from) {
+                       *pos = p;
+                       return i;
+               }
+
+               p += map->debugfs_tot_len;
+       }
+
+       return base;
+}
+
 static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
                                   unsigned int to, char __user *user_buf,
                                   size_t count, loff_t *ppos)
 {
        size_t buf_pos = 0;
-       loff_t p = 0;
+       loff_t p = *ppos;
        ssize_t ret;
        int i;
        char *buf;
-       unsigned int val;
+       unsigned int val, start_reg;
 
        if (*ppos < 0 || !count)
                return -EINVAL;
@@ -83,7 +113,10 @@ static ssize_t regmap_read_debugfs(struct regmap *map, unsigned int from,
                        map->debugfs_val_len + 3;      /* : \n */
        }
 
-       for (i = from; i <= to; i += map->reg_stride) {
+       /* Work out which register we're starting at */
+       start_reg = regmap_debugfs_get_dump_start(map, from, *ppos, &p);
+
+       for (i = start_reg; i <= to; i += map->reg_stride) {
                if (!regmap_readable(map, i))
                        continue;