mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [for next PATCH 0/2] MMC: introduce write protect support
@ 2013-01-25 15:28 Jean-Christophe PLAGNIOL-VILLARD
  2013-01-25 15:38 ` [PATCH 1/2] mci: add card_write_protected Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 3+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 15:28 UTC (permalink / raw)
  To: barebox

HI,

	introduce write protect support and implement it on at91

The following changes since commit caea28cd5ebfe0bee2fb1be22bc0e56c7d6120cf:

  atmel_mci: gpio: request and configure card detect (2013-01-21 17:09:20 +0800)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git delivery/atmel_mci_next

for you to fetch changes up to a4dcf41b8bfd19bdef1b45482742d6aae75275a3:

  atmel_mci: add write protect detection support (2013-01-21 17:09:20 +0800)

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (2):
      mci: add card_write_protected
      atmel_mci: add write protect detection support

 drivers/mci/atmel_mci.c |   42 +++++++++++++++++++++++++++++++++++++++++-
 drivers/mci/mci-core.c  |    6 ++++++
 include/mci.h           |    2 ++
 3 files changed, 49 insertions(+), 1 deletion(-)

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 1/2] mci: add card_write_protected
  2013-01-25 15:28 [for next PATCH 0/2] MMC: introduce write protect support Jean-Christophe PLAGNIOL-VILLARD
@ 2013-01-25 15:38 ` Jean-Christophe PLAGNIOL-VILLARD
  2013-01-25 15:38   ` [PATCH 2/2] atmel_mci: add write protect detection support Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 3+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 15:38 UTC (permalink / raw)
  To: barebox

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@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

* [PATCH 2/2] atmel_mci: add write protect detection support
  2013-01-25 15:38 ` [PATCH 1/2] mci: add card_write_protected Jean-Christophe PLAGNIOL-VILLARD
@ 2013-01-25 15:38   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 3+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-01-25 15:38 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 drivers/mci/atmel_mci.c |   42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/drivers/mci/atmel_mci.c b/drivers/mci/atmel_mci.c
index 4ef45b5..261ac49 100644
--- a/drivers/mci/atmel_mci.c
+++ b/drivers/mci/atmel_mci.c
@@ -371,6 +371,23 @@ static int atmci_card_present(struct mci_host *mci)
 	return ret == 0 ? 1 : 0;
 }
 
+static int atmci_card_write_protected(struct mci_host *mci)
+{
+	struct atmel_mci_host *host = to_mci_host(mci);
+	struct atmel_mci_platform_data *pd = host->hw_dev->platform_data;
+	int ret;
+
+	/* No gpio, assume card is not protected */
+	if (!gpio_is_valid(pd->wp_pin))
+		return 0;
+
+	ret = gpio_get_value(pd->detect_pin);
+	if (ret < 0)
+		return 0;
+
+	return ret;
+}
+
 /** init the host interface */
 static int atmci_reset(struct mci_host *mci, struct device_d *mci_dev)
 {
@@ -491,6 +508,9 @@ static void atmci_info(struct device_d *mci_dev)
 	printf("\n  Card detection support: %s\n",
 		gpio_is_valid(pd->detect_pin) ? "yes" : "no");
 
+	printf("  Card write protected support: %s\n",
+		gpio_is_valid(pd->wp_pin) ? "yes" : "no");
+
 }
 #endif /* CONFIG_MCI_INFO */
 /*
@@ -558,11 +578,28 @@ static int atmci_probe(struct device_d *hw_dev)
 		}
 	}
 
+	if (gpio_is_valid(pd->wp_pin)) {
+		ret = gpio_request(pd->wp_pin, "mci_wp");
+		if (ret) {
+			dev_err(hw_dev, "Impossible to request WP gpio %d (%d)\n",
+				ret, pd->wp_pin);
+			goto err_gpio_cd_request;
+		}
+
+		ret = gpio_direction_input(pd->wp_pin);
+		if (ret) {
+			dev_err(hw_dev, "Impossible to configure WP gpio %d as input (%d)\n",
+				ret, pd->wp_pin);
+			goto err_gpio_wp_request;
+		}
+	}
+
 	host = xzalloc(sizeof(*host));
 	host->mci.send_cmd = atmci_request;
 	host->mci.set_ios = atmci_set_ios;
 	host->mci.init = atmci_reset;
 	host->mci.card_present = atmci_card_present;
+	host->mci.card_write_protected = atmci_card_write_protected;
 	host->mci.hw_dev = hw_dev;
 
 	if (pd->bus_width >= 4)
@@ -578,7 +615,7 @@ static int atmci_probe(struct device_d *hw_dev)
 	if (IS_ERR(host->clk)) {
 		dev_err(hw_dev, "no mci_clk\n");
 		ret = PTR_ERR(host->clk);
-		goto err_gpio_cd_request;
+		goto err_gpio_wp_request;
 	}
 
 	clk_enable(host->clk);
@@ -606,6 +643,9 @@ static int atmci_probe(struct device_d *hw_dev)
 
 	return 0;
 
+err_gpio_wp_request:
+	if (gpio_is_valid(pd->wp_pin))
+		gpio_free(pd->wp_pin);
 err_gpio_cd_request:
 	if (gpio_is_valid(pd->detect_pin))
 		gpio_free(pd->detect_pin);
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

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

end of thread, other threads:[~2013-01-25 15:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-25 15:28 [for next PATCH 0/2] MMC: introduce write protect support Jean-Christophe PLAGNIOL-VILLARD
2013-01-25 15:38 ` [PATCH 1/2] mci: add card_write_protected Jean-Christophe PLAGNIOL-VILLARD
2013-01-25 15:38   ` [PATCH 2/2] atmel_mci: add write protect detection support Jean-Christophe PLAGNIOL-VILLARD

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