Skip to contentSkip to conversation

mmc: Add SD_STATUS register dump to debugfs

PATCH New [email protected] 1 participant 1 message Nov 30, 2009 MMC, SD and SDIO

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 mmc: Add SD_STATUS register dump to debugfs

Add a file to debugfs to read back the SD_STATUS register from an SD card. SD_STATUS contains performance-related information.

Signed-off-by [email protected]
---
 drivers/mmc/core/debugfs.c |   56 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/core/sd_ops.c  |   51 ++++++++++++++++++++++++++++++++++++++++
 drivers/mmc/core/sd_ops.h  |    1 
 include/linux/mmc/sd.h     |    1 
 4 files changed, 109 insertions(+)
drivers/mmc/core/sd_ops.c +51 -0
Index: linux-2.6/drivers/mmc/core/sd_ops.c
===================================================================
@@ -299,6 +299,57 @@ int mmc_app_send_scr(struct mmc_card *ca
 	return 0;
 }
 
+int mmc_send_sd_status(struct mmc_card *card, u32 *sd_status)
+{
+	int err;
+	struct mmc_request mrq;
+	struct mmc_command cmd;
+	struct mmc_data data;
+	struct scatterlist sg;
+	int i;
+
+	BUG_ON(!card);
+	BUG_ON(!card->host);
+	BUG_ON(!sd_status);
+
+	err = mmc_app_cmd(card->host, card);
+	if (err)
+		return err;
+
+	memset(&mrq, 0, sizeof(struct mmc_request));
+	memset(&cmd, 0, sizeof(struct mmc_command));
+	memset(&data, 0, sizeof(struct mmc_data));
+
+	mrq.cmd = &cmd;
+	mrq.data = &data;
+
+	cmd.opcode = SD_APP_SEND_SD_STATUS;
+	cmd.arg = 0;  /* not used */
+	cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC;
+
+	data.blksz = 16*sizeof(u32);
+	data.blocks = 1;
+	data.flags = MMC_DATA_READ;
+	data.sg = &sg;
+	data.sg_len = 1;
+
+	sg_init_one(&sg, sd_status, 16*sizeof(u32));
+
+	mmc_set_data_timeout(&data, card);
+
+	mmc_wait_for_req(card->host, &mrq);
+
+	if (cmd.error)
+		return cmd.error;
+	if (data.error)
+		return data.error;
+
+	for (i = 0; i < 16; i++)
+		sd_status[i] = be32_to_cpu(sd_status[i]);
+
+	return 0;
+}
+
 int mmc_sd_switch(struct mmc_card *card, int mode, int group,
 	u8 value, u8 *resp)
 {
drivers/mmc/core/sd_ops.h +1 -0
Index: linux-2.6/drivers/mmc/core/sd_ops.h
===================================================================
@@ -13,6 +13,7 @@
 #define _MMC_SD_OPS_H
 
 int mmc_app_set_bus_width(struct mmc_card *card, int width);
+int mmc_send_sd_status(struct mmc_card *card, u32 *sd_status);
 int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr);
 int mmc_send_if_cond(struct mmc_host *host, u32 ocr);
 int mmc_send_relative_addr(struct mmc_host *host, unsigned int *rca);
include/linux/mmc/sd.h +1 -0
Index: linux-2.6/include/linux/mmc/sd.h
===================================================================
@@ -26,6 +26,7 @@
 #define SD_APP_SEND_NUM_WR_BLKS  22   /* adtc                    R1  */
 #define SD_APP_OP_COND           41   /* bcr  [31:0] OCR         R3  */
 #define SD_APP_SEND_SCR          51   /* adtc                    R1  */
+#define SD_APP_SEND_SD_STATUS    13   /* adtc                    R1  */
 
 /*
  * SD_SWITCH argument format:
drivers/mmc/core/debugfs.c +56 -0

74 lines not on this page · raw message