From: Steve Magnani <smagnani@iscandar.digidescorp.com>
To: Chris Ball <cjb@laptop.org>
Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org,
"Steven J. Magnani" <steve@digidescorp.com>
Subject: [PATCH] mmc: debugfs: Add debugfs ability to read CID and CSD
Date: Fri, 12 Apr 2013 14:46:53 -0500 [thread overview]
Message-ID: <1365796013-11399-1-git-send-email-smagnani@iscandar.digidescorp.com> (raw)
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,
next reply other threads:[~2013-04-12 19:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-04-12 19:46 Steve Magnani [this message]
[not found] ` <CA+20K0DFA9r+fLhhbFnzx+t2wQ6+UH3DAWhoiF2W1g=ok8hyBQ@mail.gmail.com>
2013-04-13 1:54 ` Steven J. Magnani
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1365796013-11399-1-git-send-email-smagnani@iscandar.digidescorp.com \
--to=smagnani@iscandar.digidescorp.com \
--cc=cjb@laptop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mmc@vger.kernel.org \
--cc=steve@digidescorp.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®