[PATCH 1/2] mci: add card_write_protected

Jean-Christophe PLAGNIOL-VILLARD plagnioj at jcrosoft.com
Fri Jan 25 10:38:27 EST 2013


Currently there is no common way for the mci host driver to tell
that thee car is write protected. This adds a card_write_protected callback
which is used by the framework to tell whether it's protected or not.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj at jcrosoft.com>
---
 drivers/mci/mci-core.c |    6 ++++++
 include/mci.h          |    2 ++
 2 files changed, 8 insertions(+)

diff --git a/drivers/mci/mci-core.c b/drivers/mci/mci-core.c
index fd052f1..a269aee 100644
--- a/drivers/mci/mci-core.c
+++ b/drivers/mci/mci-core.c
@@ -1111,8 +1111,14 @@ static int __maybe_unused mci_sd_write(struct block_device *blk,
 				const void *buffer, int block, int num_blocks)
 {
 	struct mci *mci = container_of(blk, struct mci, blk);
+	struct mci_host *host = mci->host;
 	int rc;
 
+	if (host->card_write_protected && host->card_write_protected(host)) {
+		dev_err(mci->mci_dev, "card write protected\n");
+		return -EPERM;
+	}
+
 	dev_dbg(mci->mci_dev, "%s: Write %d block(s), starting at %d\n",
 		__func__, num_blocks, block);
 
diff --git a/include/mci.h b/include/mci.h
index c0d179b..cf9582d 100644
--- a/include/mci.h
+++ b/include/mci.h
@@ -302,6 +302,8 @@ struct mci_host {
 	int (*send_cmd)(struct mci_host*, struct mci_cmd*, struct mci_data*);
 	/** check if a card is inserted */
 	int (*card_present)(struct mci_host *);
+	/** check if a card is write protected */
+	int (*card_write_protected)(struct mci_host *);
 };
 
 /** MMC/SD and interface instance information */
-- 
1.7.10.4




More information about the barebox mailing list