All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Ulf Hansson <ulf.hansson@linaro.org>
Cc: "Seungwon Jeon" <tgih.jun@samsung.com>,
	"Jaehoon Chung" <jh80.chung@samsung.com>,
	"Michal Simek" <michal.simek@xilinx.com>,
	"Sören Brinkmann" <soren.brinkmann@xilinx.com>,
	"Thomas Abraham" <thomas.abraham@linaro.org>,
	"Mike Looijmans" <mike.looijmans@topic.nl>,
	linux-mmc@vger.kernel.org, devicetree@vger.kernel.org,
	"Lars-Peter Clausen" <lars@metafoo.de>
Subject: [PATCH v2 1/4] mmc: Add support for disabling write-protect detection
Date: Wed,  6 May 2015 20:31:19 +0200	[thread overview]
Message-ID: <1430937082-27149-1-git-send-email-lars@metafoo.de> (raw)

It is not uncommon to see systems where there is no physical write-protect
signal (e.g. when using eMMC or microSD card slots). For some controllers,
which have a dedicated write-protection detection logic (like SDHCI
controllers), the get_ro() callback can return bogus data in such a case.

Instead of handling this on a per controller basis this patch adds a new
capability flag to the MMC core that can be set to specify that the result
of get_ro() is invalid. When the flag is set the core will not call
get_ro() and assume that the card is always read-write.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 drivers/mmc/core/sd.c    | 30 +++++++++++++++++++++++-------
 include/linux/mmc/host.h |  1 +
 2 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 31a9ef2..8f6864a 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -804,6 +804,28 @@ int mmc_sd_get_csd(struct mmc_host *host, struct mmc_card *card)
 	return 0;
 }
 
+static int mmc_sd_get_ro(struct mmc_host *host)
+{
+	int ro;
+
+	/*
+	 * Some systems don't feature a write-protect pin and don't need one.
+	 * E.g. because they only have micro-SD card slot. For those systems
+	 * assume that the SD card is always read-write.
+	 */
+	if (host->caps2 & MMC_CAP2_NO_WRITE_PROTECT)
+		return 0;
+
+	if (!host->ops->get_ro)
+		return -1;
+
+	mmc_host_clk_hold(host);
+	ro = host->ops->get_ro(host);
+	mmc_host_clk_release(host);
+
+	return ro;
+}
+
 int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
 	bool reinit)
 {
@@ -855,13 +877,7 @@ int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card,
 	 * Check if read-only switch is active.
 	 */
 	if (!reinit) {
-		int ro = -1;
-
-		if (host->ops->get_ro) {
-			mmc_host_clk_hold(card->host);
-			ro = host->ops->get_ro(host);
-			mmc_host_clk_release(card->host);
-		}
+		int ro = mmc_sd_get_ro(host);
 
 		if (ro < 0) {
 			pr_warn("%s: host does not support reading read-only switch, assuming write-enable\n",
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index b5bedae..3b92fd4 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -285,6 +285,7 @@ struct mmc_host {
 				 MMC_CAP2_HS400_1_2V)
 #define MMC_CAP2_HSX00_1_2V	(MMC_CAP2_HS200_1_2V_SDR | MMC_CAP2_HS400_1_2V)
 #define MMC_CAP2_SDIO_IRQ_NOTHREAD (1 << 17)
+#define MMC_CAP2_NO_WRITE_PROTECT (1 << 18)	/* No physical write protect pin, assume that card is always read-write */
 
 	mmc_pm_flag_t		pm_caps;	/* supported pm features */
 
-- 
1.8.0


             reply	other threads:[~2015-05-06 18:31 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-06 18:31 Lars-Peter Clausen [this message]
     [not found] ` <1430937082-27149-1-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2015-05-06 18:31   ` [PATCH v2 2/4] mmc: dt: Allow to specify that no write protect signal is present Lars-Peter Clausen
2015-05-11 10:30     ` Ulf Hansson
2015-05-06 18:31 ` [PATCH v2 3/4] mmc: sdhci-of-arasan: Call mmc_of_parse() Lars-Peter Clausen
2015-05-07  5:00   ` Michal Simek
2015-05-07  5:44     ` Lars-Peter Clausen
2015-05-06 18:31 ` [PATCH v2 4/4] mmc: dw_mmc: Use core to handle absent write protect line Lars-Peter Clausen
     [not found]   ` <1430937082-27149-4-git-send-email-lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>
2015-05-11 10:30     ` Ulf Hansson
2015-05-12  7:33       ` Jaehoon Chung
2015-05-15  9:40         ` Jaehoon Chung
2015-05-11 10:30 ` [PATCH v2 1/4] mmc: Add support for disabling write-protect detection Ulf Hansson

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=1430937082-27149-1-git-send-email-lars@metafoo.de \
    --to=lars@metafoo.de \
    --cc=devicetree@vger.kernel.org \
    --cc=jh80.chung@samsung.com \
    --cc=linux-mmc@vger.kernel.org \
    --cc=michal.simek@xilinx.com \
    --cc=mike.looijmans@topic.nl \
    --cc=soren.brinkmann@xilinx.com \
    --cc=tgih.jun@samsung.com \
    --cc=thomas.abraham@linaro.org \
    --cc=ulf.hansson@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.