public inbox for linux-mmc@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mmc: debugfs: Add debugfs ability to read CID and CSD
@ 2013-04-12 19:46 Steve Magnani
       [not found] ` <CA+20K0DFA9r+fLhhbFnzx+t2wQ6+UH3DAWhoiF2W1g=ok8hyBQ@mail.gmail.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Steve Magnani @ 2013-04-12 19:46 UTC (permalink / raw)
  To: Chris Ball; +Cc: linux-mmc, linux-kernel, Steven J. Magnani

Adds 'cid' and 'csd' debugfs entries for SD/MMC devices that allow
userland to obtain the values of the corresponding device registers.

Signed-off-by: Steven J. Magnani <steve@digidescorp.com>
---
--- a/drivers/mmc/core/debugfs.c	2013-04-12 07:39:22.532586948 -0500
+++ b/drivers/mmc/core/debugfs.c	2013-04-12 07:40:14.513331587 -0500
@@ -321,7 +321,7 @@ static ssize_t mmc_ext_csd_read(struct f
 				       buf, EXT_CSD_STR_LEN);
 }
 
-static int mmc_ext_csd_release(struct inode *inode, struct file *file)
+static int mmc_dbg_buf_release(struct inode *inode, struct file *file)
 {
 	kfree(file->private_data);
 	return 0;
@@ -330,7 +330,65 @@ static int mmc_ext_csd_release(struct in
 static const struct file_operations mmc_dbg_ext_csd_fops = {
 	.open		= mmc_ext_csd_open,
 	.read		= mmc_ext_csd_read,
-	.release	= mmc_ext_csd_release,
+	.release	= mmc_dbg_buf_release,
+	.llseek		= default_llseek,
+};
+
+/* CSD and CID have the same length and so can be handled much the same */
+#define CXD_STR_LEN 33
+
+static int mmc_cxd_open(struct file *filp, u32 *raw_cxd)
+{
+	char *buf;
+	ssize_t n = 0;
+	int i;
+
+	buf = kmalloc(CXD_STR_LEN + 1, GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	for (i = 0; i < 4; i++)
+		n += sprintf(buf + n, "%08x", raw_cxd[i]);
+	n += sprintf(buf + n, "\n");
+	BUG_ON(n != CXD_STR_LEN);
+
+	filp->private_data = buf;
+	return 0;
+}
+
+static ssize_t mmc_cxd_read(struct file *filp, char __user *ubuf,
+				size_t cnt, loff_t *ppos)
+{
+	char *buf = filp->private_data;
+
+	return simple_read_from_buffer(ubuf, cnt, ppos,
+				       buf, CXD_STR_LEN);
+}
+
+static int mmc_csd_open(struct inode *inode, struct file *filp)
+{
+	struct mmc_card *card = inode->i_private;
+	return mmc_cxd_open(filp, card->raw_csd);
+}
+
+static const struct file_operations mmc_dbg_csd_fops = {
+	.open		= mmc_csd_open,
+	.read		= mmc_cxd_read,
+	.release	= mmc_dbg_buf_release,
+	.llseek		= default_llseek,
+};
+
+
+static int mmc_cid_open(struct inode *inode, struct file *filp)
+{
+	struct mmc_card *card = inode->i_private;
+	return mmc_cxd_open(filp, card->raw_cid);
+}
+
+static const struct file_operations mmc_dbg_cid_fops = {
+	.open		= mmc_cid_open,
+	.read		= mmc_cxd_read,
+	.release	= mmc_dbg_buf_release,
 	.llseek		= default_llseek,
 };
 
@@ -356,10 +414,17 @@ void mmc_add_card_debugfs(struct mmc_car
 	if (!debugfs_create_x32("state", S_IRUSR, root, &card->state))
 		goto err;
 
-	if (mmc_card_mmc(card) || mmc_card_sd(card))
+	if (mmc_card_mmc(card) || mmc_card_sd(card)) {
 		if (!debugfs_create_file("status", S_IRUSR, root, card,
 					&mmc_dbg_card_status_fops))
 			goto err;
+		if (!debugfs_create_file("csd", S_IRUSR, root, card,
+					&mmc_dbg_csd_fops))
+			goto err;
+		if (!debugfs_create_file("cid", S_IRUSR, root, card,
+					&mmc_dbg_cid_fops))
+			goto err;
+	}
 
 	if (mmc_card_mmc(card))
 		if (!debugfs_create_file("ext_csd", S_IRUSR, root, card,


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

end of thread, other threads:[~2013-04-13  2:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-12 19:46 [PATCH] mmc: debugfs: Add debugfs ability to read CID and CSD Steve Magnani
     [not found] ` <CA+20K0DFA9r+fLhhbFnzx+t2wQ6+UH3DAWhoiF2W1g=ok8hyBQ@mail.gmail.com>
2013-04-13  1:54   ` Steven J. Magnani

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox