mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/1] atmel_mci: add write protect detection support
@ 2013-04-14 12:07 Jean-Christophe PLAGNIOL-VILLARD
  2013-04-16 12:48 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2013-04-14 12:07 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 f032403..4e8b86e 100644
--- a/drivers/mci/atmel_mci.c
+++ b/drivers/mci/atmel_mci.c
@@ -370,6 +370,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)
 {
@@ -490,6 +507,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 */
 /*
@@ -557,11 +577,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)
@@ -577,7 +614,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);
@@ -605,6 +642,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] 2+ messages in thread

* Re: [PATCH 1/1] atmel_mci: add write protect detection support
  2013-04-14 12:07 [PATCH 1/1] atmel_mci: add write protect detection support Jean-Christophe PLAGNIOL-VILLARD
@ 2013-04-16 12:48 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2013-04-16 12:48 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Sun, Apr 14, 2013 at 02:07:38PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> 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 f032403..4e8b86e 100644
> --- a/drivers/mci/atmel_mci.c
> +++ b/drivers/mci/atmel_mci.c
> @@ -370,6 +370,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;

This is unnecessary. gpio_get_value will check for gpio_is_valid aswell.

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

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

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

end of thread, other threads:[~2013-04-16 12:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-14 12:07 [PATCH 1/1] atmel_mci: add write protect detection support Jean-Christophe PLAGNIOL-VILLARD
2013-04-16 12:48 ` Sascha Hauer

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