regmap: Add functions to check for access on registers
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Wed, 10 Aug 2011 08:14:41 +0000 (17:14 +0900)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Sun, 14 Aug 2011 10:51:11 +0000 (19:51 +0900)
We're going to be using these in quite a few places so factor out the
readable/writable/volatile/precious checks.

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

index a67dc68aba5e34abe2a201541b50cbf60608e1de..5ab3fefa4b05dbf0eac29c8b006ee1496017e88e 100644 (file)
@@ -48,6 +48,11 @@ struct regmap {
        bool (*precious_reg)(struct device *dev, unsigned int reg);
 };
 
+bool regmap_writeable(struct regmap *map, unsigned int reg);
+bool regmap_readable(struct regmap *map, unsigned int reg);
+bool regmap_volatile(struct regmap *map, unsigned int reg);
+bool regmap_precious(struct regmap *map, unsigned int reg);
+
 #ifdef CONFIG_DEBUG_FS
 extern void regmap_debugfs_initcall(void);
 extern void regmap_debugfs_init(struct regmap *map);
index 6e304a4e2706ac0e8bb87ceec1193756a83e4399..fff8e832a985ff3963cebdda175c8277ceb759ff 100644 (file)
@@ -52,12 +52,10 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
        tot_len = reg_len + val_len + 3;      /* : \n */
 
        for (i = 0; i < map->max_register; i++) {
-               if (map->readable_reg &&
-                   !map->readable_reg(map->dev, i))
+               if (!regmap_readable(map, i))
                        continue;
 
-               if (map->precious_reg &&
-                   map->precious_reg(map->dev, i))
+               if (regmap_precious(map, i))
                        continue;
 
                /* If we're in the region the user is trying to read */
index d74d306a938b54df3c2acfa962753b356e17feb8..fa2bd896eb208fa8a92732eb6a2accf3ee3a4732 100644 (file)
 
 #include "internal.h"
 
+bool regmap_writeable(struct regmap *map, unsigned int reg)
+{
+       if (map->max_register && reg > map->max_register)
+               return false;
+
+       if (map->writeable_reg)
+               return map->writeable_reg(map->dev, reg);
+
+       return true;
+}
+
+bool regmap_readable(struct regmap *map, unsigned int reg)
+{
+       if (map->max_register && reg > map->max_register)
+               return false;
+
+       if (map->readable_reg)
+               return map->readable_reg(map->dev, reg);
+
+       return true;
+}
+
+bool regmap_volatile(struct regmap *map, unsigned int reg)
+{
+       if (map->max_register && reg > map->max_register)
+               return false;
+
+       if (map->volatile_reg)
+               return map->volatile_reg(map->dev, reg);
+
+       return true;
+}
+
+bool regmap_precious(struct regmap *map, unsigned int reg)
+{
+       if (map->max_register && reg > map->max_register)
+               return false;
+
+       if (map->precious_reg)
+               return map->precious_reg(map->dev, reg);
+
+       return false;
+}
+
 static void regmap_format_4_12_write(struct regmap *map,
                                     unsigned int reg, unsigned int val)
 {