From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/2] atmel_mci: add write protect detection support
Date: Fri, 25 Jan 2013 16:38:28 +0100 [thread overview]
Message-ID: <1359128308-31235-2-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1359128308-31235-1-git-send-email-plagnioj@jcrosoft.com>
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
prev parent reply other threads:[~2013-01-25 15:39 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Jean-Christophe PLAGNIOL-VILLARD [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359128308-31235-2-git-send-email-plagnioj@jcrosoft.com \
--to=plagnioj@jcrosoft.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox