All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] regmap: Add functions to check for access on registers
@ 2011-08-14 10:50 Mark Brown
  2011-08-14 10:50 ` [PATCH 2/3] regmap: Share some of the debugfs infrastructure ready for more files Mark Brown
  2011-08-14 10:50 ` [PATCH 3/3] regmap: Provide access information via debugfs Mark Brown
  0 siblings, 2 replies; 3+ messages in thread
From: Mark Brown @ 2011-08-14 10:50 UTC (permalink / raw)
  To: linux-kernel; +Cc: patches, Mark Brown

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       |    5 ++++
 drivers/base/regmap/regmap-debugfs.c |    6 +---
 drivers/base/regmap/regmap.c         |   44 ++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/drivers/base/regmap/internal.h b/drivers/base/regmap/internal.h
index a67dc68..5ab3fef 100644
--- a/drivers/base/regmap/internal.h
+++ b/drivers/base/regmap/internal.h
@@ -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);
diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index 6e304a4..fff8e83 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -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 */
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index d74d306..fa2bd89 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -20,6 +20,50 @@
 
 #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)
 {
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/3] regmap: Share some of the debugfs infrastructure ready for more files
  2011-08-14 10:50 [PATCH 1/3] regmap: Add functions to check for access on registers Mark Brown
@ 2011-08-14 10:50 ` Mark Brown
  2011-08-14 10:50 ` [PATCH 3/3] regmap: Provide access information via debugfs Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2011-08-14 10:50 UTC (permalink / raw)
  To: linux-kernel; +Cc: patches, Mark Brown

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 drivers/base/regmap/regmap-debugfs.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index fff8e83..e541d7f4 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -20,7 +20,14 @@
 
 static struct dentry *regmap_debugfs_root;
 
-static int regmap_map_open_file(struct inode *inode, struct file *file)
+/* Calculate the length of a fixed format  */
+static size_t regmap_calc_reg_len(int max_val, char *buf, size_t buf_size)
+{
+	snprintf(buf, buf_size, "%x", max_val);
+	return strlen(buf);
+}
+
+static int regmap_open_file(struct inode *inode, struct file *file)
 {
 	file->private_data = inode->i_private;
 	return 0;
@@ -46,8 +53,7 @@ static ssize_t regmap_map_read_file(struct file *file, char __user *user_buf,
 		return -ENOMEM;
 
 	/* Calculate the length of a fixed format  */
-	snprintf(buf, count, "%x", map->max_register);
-	reg_len = strlen(buf);
+	reg_len = regmap_calc_reg_len(map->max_register, buf, count);
 	val_len = 2 * map->format.val_bytes;
 	tot_len = reg_len + val_len + 3;      /* : \n */
 
@@ -98,7 +104,7 @@ out:
 }
 
 static const struct file_operations regmap_map_fops = {
-	.open = regmap_map_open_file,
+	.open = regmap_open_file,
 	.read = regmap_map_read_file,
 	.llseek = default_llseek,
 };
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 3/3] regmap: Provide access information via debugfs
  2011-08-14 10:50 [PATCH 1/3] regmap: Add functions to check for access on registers Mark Brown
  2011-08-14 10:50 ` [PATCH 2/3] regmap: Share some of the debugfs infrastructure ready for more files Mark Brown
@ 2011-08-14 10:50 ` Mark Brown
  1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2011-08-14 10:50 UTC (permalink / raw)
  To: linux-kernel; +Cc: patches, Mark Brown

Let userspace know what the access map for the device is. This is helpful
for verifying that the access map is correctly configured and could also
be useful for programs that try to work with the data. File format is:

register: R W V P

where R, W, V and P are 'y' or 'n' showing readable, writable, volatile
and precious respectively.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---
 drivers/base/regmap/regmap-debugfs.c |   72 +++++++++++++++++++++++++++++++++-
 1 files changed, 71 insertions(+), 1 deletions(-)

diff --git a/drivers/base/regmap/regmap-debugfs.c b/drivers/base/regmap/regmap-debugfs.c
index e541d7f4..7a8d675 100644
--- a/drivers/base/regmap/regmap-debugfs.c
+++ b/drivers/base/regmap/regmap-debugfs.c
@@ -109,6 +109,73 @@ static const struct file_operations regmap_map_fops = {
 	.llseek = default_llseek,
 };
 
+static ssize_t regmap_access_read_file(struct file *file,
+				       char __user *user_buf, size_t count,
+				       loff_t *ppos)
+{
+	int reg_len, tot_len;
+	size_t buf_pos = 0;
+	loff_t p = 0;
+	ssize_t ret;
+	int i;
+	struct regmap *map = file->private_data;
+	char *buf;
+
+	if (*ppos < 0 || !count)
+		return -EINVAL;
+
+	buf = kmalloc(count, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	/* Calculate the length of a fixed format  */
+	reg_len = regmap_calc_reg_len(map->max_register, buf, count);
+	tot_len = reg_len + 10; /* ': R W V P\n' */
+
+	for (i = 0; i < map->max_register; i++) {
+		/* Ignore registers which are neither readable nor writable */
+		if (!regmap_readable(map, i) && !regmap_writeable(map, i))
+			continue;
+
+		/* If we're in the region the user is trying to read */
+		if (p >= *ppos) {
+			/* ...but not beyond it */
+			if (buf_pos >= count - 1 - tot_len)
+				break;
+
+			/* Format the register */
+			snprintf(buf + buf_pos, count - buf_pos,
+				 "%.*x: %c %c %c %c\n",
+				 reg_len, i,
+				 regmap_readable(map, i) ? 'y' : 'n',
+				 regmap_writeable(map, i) ? 'y' : 'n',
+				 regmap_volatile(map, i) ? 'y' : 'n',
+				 regmap_precious(map, i) ? 'y' : 'n');
+
+			buf_pos += tot_len;
+		}
+		p += tot_len;
+	}
+
+	ret = buf_pos;
+
+	if (copy_to_user(user_buf, buf, buf_pos)) {
+		ret = -EFAULT;
+		goto out;
+	}
+
+	*ppos += buf_pos;
+
+out:
+	kfree(buf);
+	return ret;
+}
+
+static const struct file_operations regmap_access_fops = {
+	.open = regmap_open_file,
+	.read = regmap_access_read_file,
+	.llseek = default_llseek,
+};
 
 void regmap_debugfs_init(struct regmap *map)
 {
@@ -119,9 +186,12 @@ void regmap_debugfs_init(struct regmap *map)
 		return;
 	}
 
-	if (map->max_register)
+	if (map->max_register) {
 		debugfs_create_file("registers", 0400, map->debugfs,
 				    map, &regmap_map_fops);
+		debugfs_create_file("access", 0400, map->debugfs,
+				    map, &regmap_access_fops);
+	}
 }
 
 void regmap_debugfs_exit(struct regmap *map)
-- 
1.7.5.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-08-14 10:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-08-14 10:50 [PATCH 1/3] regmap: Add functions to check for access on registers Mark Brown
2011-08-14 10:50 ` [PATCH 2/3] regmap: Share some of the debugfs infrastructure ready for more files Mark Brown
2011-08-14 10:50 ` [PATCH 3/3] regmap: Provide access information via debugfs Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.