MMC: introduce write protect support
cover MMC: introduce write protect support
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
PATCH 1/2 mci: add card_write_protected
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.
--- drivers/mci/mci-core.c | 6 ++++++ include/mci.h | 2 ++ 2 files changed, 8 insertions(+)
drivers/mci/mci-core.c +6 -0
@@ -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);
include/mci.h +2 -0
@@ -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 */
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox
PATCH 2/2 atmel_mci: add write protect detection support
--- drivers/mci/atmel_mci.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-)
drivers/mci/atmel_mci.c +41 -1
@@ -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);
Signature · 7 lines
1.7.10.4 _______________________________________________ barebox mailing list [email protected] http://lists.infradead.org/mailman/listinfo/barebox