linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Seunghui Lee <sh043.lee@samsung.com>
To: ulf.hansson@linaro.org, pali@kernel.org, huyue2@yulong.com,
	tiantao6@hisilicon.com, linux-mmc@vger.kernel.org,
	linux-kernel@vger.kernel.org
Cc: grant.jung@samsung.com, jt77.jang@samsung.com,
	dh0421.hwang@samsung.com, junwoo80.lee@samsung.com,
	jangsub.yi@samsung.com, cw9316.lee@samsung.com,
	sh8267.baek@samsung.com, wkon.kim@samsung.com,
	Seunghui Lee <sh043.lee@samsung.com>
Subject: [PATCH] mmc: core: set read only with permanent write protect
Date: Mon, 22 Feb 2021 17:31:56 +0900	[thread overview]
Message-ID: <20210222083156.19158-1-sh043.lee@samsung.com> (raw)
In-Reply-To: CGME20210222081517epcas1p37fef998684dc9eae0bcd2764a3f82fb1@epcas1p3.samsung.com

Some of SD cards sets permanent write protection
due to lifespan or internal problem.
Host can find out it's protected permanantly during initialization.
Once set read only during initialization,
it could prevent unnecessary write operation in it.

Signed-off-by: Seunghui Lee <sh043.lee@samsung.com>
---
 drivers/mmc/core/sd.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c
index 6fa51a6ed058..2c48d6504101 100644
--- a/drivers/mmc/core/sd.c
+++ b/drivers/mmc/core/sd.c
@@ -135,6 +135,9 @@ static int mmc_decode_csd(struct mmc_card *card)
 			csd->erase_size = UNSTUFF_BITS(resp, 39, 7) + 1;
 			csd->erase_size <<= csd->write_blkbits - 9;
 		}
+
+		if (UNSTUFF_BITS(resp, 13, 1))
+			mmc_card_set_readonly(card);
 		break;
 	case 1:
 		/*
@@ -169,6 +172,9 @@ static int mmc_decode_csd(struct mmc_card *card)
 		csd->write_blkbits = 9;
 		csd->write_partial = 0;
 		csd->erase_size = 1;
+
+		if (UNSTUFF_BITS(resp, 13, 1))
+			mmc_card_set_readonly(card);
 		break;
 	default:
 		pr_err("%s: unrecognised CSD structure version %d\n",
-- 
2.29.0


       reply	other threads:[~2021-02-22  8:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CGME20210222081517epcas1p37fef998684dc9eae0bcd2764a3f82fb1@epcas1p3.samsung.com>
2021-02-22  8:31 ` Seunghui Lee [this message]
2021-02-25  7:17   ` [PATCH] mmc: core: set read only with permanent write protect 이승희
2021-03-02 10:39   ` 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=20210222083156.19158-1-sh043.lee@samsung.com \
    --to=sh043.lee@samsung.com \
    --cc=cw9316.lee@samsung.com \
    --cc=dh0421.hwang@samsung.com \
    --cc=grant.jung@samsung.com \
    --cc=huyue2@yulong.com \
    --cc=jangsub.yi@samsung.com \
    --cc=jt77.jang@samsung.com \
    --cc=junwoo80.lee@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=pali@kernel.org \
    --cc=sh8267.baek@samsung.com \
    --cc=tiantao6@hisilicon.com \
    --cc=ulf.hansson@linaro.org \
    --cc=wkon.kim@samsung.com \
    /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;
as well as URLs for NNTP newsgroup(s).