mmc: Add SD Status register to debugfs
authorHao Ying <hao.ying@intel.com>
Thu, 21 Jul 2011 04:36:15 +0000 (12:36 +0800)
committermgross <mark.gross@intel.com>
Wed, 9 Nov 2011 21:21:11 +0000 (13:21 -0800)
BZ:  5522

This patch add the SD status register to debugfs. SD Status register is
a SD card register which contains status bits that are related to the SD
Memory Card proprietary features and may be used by future application-specific
usge, it is helpful to see its value.

Change-Id: Ia9041833bd432bd37df9e1d846aa66a856b19efc
Signed-off-by: Hao Ying <hao.ying@intel.com>
Reviewed-on: http://android.intel.com:8080/23128
Reviewed-by: Gross, Mark <mark.gross@intel.com>
Tested-by: Gross, Mark <mark.gross@intel.com>
drivers/mmc/core/debugfs.c

index 998797e..81fc6ac 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "core.h"
 #include "mmc_ops.h"
+#include "sd_ops.h"
 
 /* The debugfs functions are optimized away when CONFIG_DEBUG_FS isn't set. */
 static int mmc_ios_show(struct seq_file *s, void *data)
@@ -277,6 +278,64 @@ static int mmc_ext_csd_release(struct inode *inode, struct file *file)
        return 0;
 }
 
+#define SSR_STR_LEN 129
+
+static int mmc_ssr_open(struct inode *inode, struct file *filp)
+{
+       struct mmc_card *card = inode->i_private;
+       char *buf;
+       ssize_t n = 0;
+       u32 *ssr;
+       int err, i;
+
+       buf = kmalloc(SSR_STR_LEN + 1, GFP_KERNEL);
+       if (!buf)
+               return -ENOMEM;
+
+       ssr = kmalloc(64, GFP_KERNEL);
+       if (!ssr) {
+               err = -ENOMEM;
+               goto out_free;
+       }
+
+       mmc_claim_host(card->host);
+       err = mmc_app_sd_status(card, ssr);
+       mmc_release_host(card->host);
+       if (err)
+               goto out_free;
+
+       for (i = 0; i <= 15; i++) {
+               ssr[i] = be32_to_cpu(ssr[i]);
+               n += sprintf(buf + n, "%08x", ssr[i]);
+       }
+       n += sprintf(buf + n, "\n");
+       BUG_ON(n != SSR_STR_LEN);
+
+       filp->private_data = buf;
+       kfree(ssr);
+       return 0;
+
+out_free:
+       kfree(buf);
+       kfree(ssr);
+       return err;
+}
+
+static ssize_t mmc_ssr_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, SSR_STR_LEN);
+}
+
+static int mmc_ssr_release(struct inode *inode, struct file *file)
+{
+       kfree(file->private_data);
+       return 0;
+}
+
 static const struct file_operations mmc_dbg_ext_csd_fops = {
        .open           = mmc_ext_csd_open,
        .read           = mmc_ext_csd_read,
@@ -284,6 +343,13 @@ static const struct file_operations mmc_dbg_ext_csd_fops = {
        .llseek         = default_llseek,
 };
 
+static const struct file_operations mmc_dbg_ssr_fops = {
+       .open           = mmc_ssr_open,
+       .read           = mmc_ssr_read,
+       .release        = mmc_ssr_release,
+       .llseek         = default_llseek,
+};
+
 void mmc_add_card_debugfs(struct mmc_card *card)
 {
        struct mmc_host *host = card->host;
@@ -311,6 +377,11 @@ void mmc_add_card_debugfs(struct mmc_card *card)
                                        &mmc_dbg_card_status_fops))
                        goto err;
 
+       if (mmc_card_sd(card))
+               if (!debugfs_create_file("ssr", S_IRUSR, root, card,
+                                       &mmc_dbg_ssr_fops))
+                       goto err;
+
        if (mmc_card_mmc(card))
                if (!debugfs_create_file("ext_csd", S_IRUSR, root, card,
                                        &mmc_dbg_ext_csd_fops))