From: Mason Yang <masonccyang@mxic.com.tw> To: miquel.raynal@bootlin.com, richard@nod.at, marek.vasut@gmail.com, dwmw2@infradead.org, bbrezillon@kernel.org, computersforpeace@gmail.com, vigneshr@ti.com Cc: juliensu@mxic.com.tw, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, masonccyang@mxic.com.tw Subject: [PATCH v2 2/4] mtd: rawnand: Add support Macronix Block Protection function Date: Mon, 28 Oct 2019 17:55:25 +0800 [thread overview] Message-ID: <1572256527-5074-3-git-send-email-masonccyang@mxic.com.tw> (raw) In-Reply-To: <1572256527-5074-1-git-send-email-masonccyang@mxic.com.tw> Macronix AC series support using SET_FEATURES to change Block Protection and Unprotection. Signed-off-by: Mason Yang <masonccyang@mxic.com.tw> --- drivers/mtd/nand/raw/nand_macronix.c | 69 +++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c index 58511ae..13929bf 100644 --- a/drivers/mtd/nand/raw/nand_macronix.c +++ b/drivers/mtd/nand/raw/nand_macronix.c @@ -11,6 +11,10 @@ #define MACRONIX_READ_RETRY_BIT BIT(0) #define MACRONIX_NUM_READ_RETRY_MODES 6 +#define ONFI_FEATURE_ADDR_MXIC_PROTECTION 0xA0 +#define MXIC_BLOCK_PROTECTION_ALL_LOCK 0x38 +#define MXIC_BLOCK_PROTECTION_ALL_UNLOCK 0x0 + struct nand_onfi_vendor_macronix { u8 reserved; u8 reliability_func; @@ -57,7 +61,7 @@ static void macronix_nand_onfi_init(struct nand_chip *chip) * the timings unlike what is declared in the parameter page. Unflag * this feature to avoid unnecessary downturns. */ -static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip) +static int macronix_nand_fix_broken_get_timings(struct nand_chip *chip) { unsigned int i; static const char * const broken_get_timings[] = { @@ -78,7 +82,7 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip) }; if (!chip->parameters.supports_set_get_features) - return; + return 0; for (i = 0; i < ARRAY_SIZE(broken_get_timings); i++) { if (!strcmp(broken_get_timings[i], chip->parameters.model)) @@ -86,22 +90,79 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip) } if (i == ARRAY_SIZE(broken_get_timings)) - return; + return 0; bitmap_clear(chip->parameters.get_feature_list, ONFI_FEATURE_ADDR_TIMING_MODE, 1); bitmap_clear(chip->parameters.set_feature_list, ONFI_FEATURE_ADDR_TIMING_MODE, 1); + return 1; +} + +/* + * Macronix NAND supports Block Protection by Protectoin(PT) pin; + * active high at power-on which protects the entire chip even the #WP is + * disabled. Lock/unlock protection area can be partition according to + * protection bits, i.e. upper 1/2 locked, upper 1/4 locked and so on. + */ +static int mxic_nand_lock(struct nand_chip *chip, loff_t ofs, uint64_t len) +{ + u8 feature[ONFI_SUBFEATURE_PARAM_LEN]; + int ret; + + feature[0] = MXIC_BLOCK_PROTECTION_ALL_LOCK; + nand_select_target(chip, 0); + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_PROTECTION, + feature); + nand_deselect_target(chip); + if (ret) + pr_err("%s all blocks failed\n", __func__); + + return ret; +} + +static int mxic_nand_unlock(struct nand_chip *chip, loff_t ofs, uint64_t len) +{ + u8 feature[ONFI_SUBFEATURE_PARAM_LEN]; + int ret; + + feature[0] = MXIC_BLOCK_PROTECTION_ALL_UNLOCK; + nand_select_target(chip, 0); + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_PROTECTION, + feature); + nand_deselect_target(chip); + if (ret) + pr_err("%s all blocks failed\n", __func__); + + return ret; } +/* + * Macronix NAND AC series support Block Protection by SET_FEATURES + * to lock/unlock blocks. + */ static int macronix_nand_init(struct nand_chip *chip) { + bool blockprotected = false; + if (nand_is_slc(chip)) chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE; - macronix_nand_fix_broken_get_timings(chip); + if (macronix_nand_fix_broken_get_timings(chip)) + blockprotected = true; + macronix_nand_onfi_init(chip); + if (blockprotected) { + bitmap_set(chip->parameters.set_feature_list, + ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1); + bitmap_set(chip->parameters.get_feature_list, + ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1); + + chip->_lock = mxic_nand_lock; + chip->_unlock = mxic_nand_unlock; + } + return 0; } -- 1.9.1
WARNING: multiple messages have this Message-ID (diff)
From: Mason Yang <masonccyang@mxic.com.tw> To: miquel.raynal@bootlin.com, richard@nod.at, marek.vasut@gmail.com, dwmw2@infradead.org, bbrezillon@kernel.org, computersforpeace@gmail.com, vigneshr@ti.com Cc: juliensu@mxic.com.tw, masonccyang@mxic.com.tw, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] mtd: rawnand: Add support Macronix Block Protection function Date: Mon, 28 Oct 2019 17:55:25 +0800 [thread overview] Message-ID: <1572256527-5074-3-git-send-email-masonccyang@mxic.com.tw> (raw) In-Reply-To: <1572256527-5074-1-git-send-email-masonccyang@mxic.com.tw> Macronix AC series support using SET_FEATURES to change Block Protection and Unprotection. Signed-off-by: Mason Yang <masonccyang@mxic.com.tw> --- drivers/mtd/nand/raw/nand_macronix.c | 69 +++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c index 58511ae..13929bf 100644 --- a/drivers/mtd/nand/raw/nand_macronix.c +++ b/drivers/mtd/nand/raw/nand_macronix.c @@ -11,6 +11,10 @@ #define MACRONIX_READ_RETRY_BIT BIT(0) #define MACRONIX_NUM_READ_RETRY_MODES 6 +#define ONFI_FEATURE_ADDR_MXIC_PROTECTION 0xA0 +#define MXIC_BLOCK_PROTECTION_ALL_LOCK 0x38 +#define MXIC_BLOCK_PROTECTION_ALL_UNLOCK 0x0 + struct nand_onfi_vendor_macronix { u8 reserved; u8 reliability_func; @@ -57,7 +61,7 @@ static void macronix_nand_onfi_init(struct nand_chip *chip) * the timings unlike what is declared in the parameter page. Unflag * this feature to avoid unnecessary downturns. */ -static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip) +static int macronix_nand_fix_broken_get_timings(struct nand_chip *chip) { unsigned int i; static const char * const broken_get_timings[] = { @@ -78,7 +82,7 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip) }; if (!chip->parameters.supports_set_get_features) - return; + return 0; for (i = 0; i < ARRAY_SIZE(broken_get_timings); i++) { if (!strcmp(broken_get_timings[i], chip->parameters.model)) @@ -86,22 +90,79 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip) } if (i == ARRAY_SIZE(broken_get_timings)) - return; + return 0; bitmap_clear(chip->parameters.get_feature_list, ONFI_FEATURE_ADDR_TIMING_MODE, 1); bitmap_clear(chip->parameters.set_feature_list, ONFI_FEATURE_ADDR_TIMING_MODE, 1); + return 1; +} + +/* + * Macronix NAND supports Block Protection by Protectoin(PT) pin; + * active high at power-on which protects the entire chip even the #WP is + * disabled. Lock/unlock protection area can be partition according to + * protection bits, i.e. upper 1/2 locked, upper 1/4 locked and so on. + */ +static int mxic_nand_lock(struct nand_chip *chip, loff_t ofs, uint64_t len) +{ + u8 feature[ONFI_SUBFEATURE_PARAM_LEN]; + int ret; + + feature[0] = MXIC_BLOCK_PROTECTION_ALL_LOCK; + nand_select_target(chip, 0); + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_PROTECTION, + feature); + nand_deselect_target(chip); + if (ret) + pr_err("%s all blocks failed\n", __func__); + + return ret; +} + +static int mxic_nand_unlock(struct nand_chip *chip, loff_t ofs, uint64_t len) +{ + u8 feature[ONFI_SUBFEATURE_PARAM_LEN]; + int ret; + + feature[0] = MXIC_BLOCK_PROTECTION_ALL_UNLOCK; + nand_select_target(chip, 0); + ret = nand_set_features(chip, ONFI_FEATURE_ADDR_MXIC_PROTECTION, + feature); + nand_deselect_target(chip); + if (ret) + pr_err("%s all blocks failed\n", __func__); + + return ret; } +/* + * Macronix NAND AC series support Block Protection by SET_FEATURES + * to lock/unlock blocks. + */ static int macronix_nand_init(struct nand_chip *chip) { + bool blockprotected = false; + if (nand_is_slc(chip)) chip->options |= NAND_BBM_FIRSTPAGE | NAND_BBM_SECONDPAGE; - macronix_nand_fix_broken_get_timings(chip); + if (macronix_nand_fix_broken_get_timings(chip)) + blockprotected = true; + macronix_nand_onfi_init(chip); + if (blockprotected) { + bitmap_set(chip->parameters.set_feature_list, + ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1); + bitmap_set(chip->parameters.get_feature_list, + ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1); + + chip->_lock = mxic_nand_lock; + chip->_unlock = mxic_nand_unlock; + } + return 0; } -- 1.9.1 ______________________________________________________ Linux MTD discussion mailing list http://lists.infradead.org/mailman/listinfo/linux-mtd/
next prev parent reply other threads:[~2019-10-28 9:29 UTC|newest] Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-10-28 9:55 [PATCH v2 0/4] mtd: rawnand: Add support Macronix Block Protection & deep power down mode Mason Yang 2019-10-28 9:55 ` Mason Yang 2019-10-28 9:55 ` [PATCH v2 1/4] mtd: rawnand: Add support manufacturer specific lock/unlock operatoin Mason Yang 2019-10-28 9:55 ` Mason Yang 2019-10-30 3:22 ` kbuild test robot 2019-10-30 3:22 ` kbuild test robot 2019-10-30 3:22 ` kbuild test robot 2020-01-09 16:41 ` Miquel Raynal 2020-01-09 16:41 ` Miquel Raynal 2020-02-17 8:05 ` masonccyang 2020-02-17 8:05 ` masonccyang 2020-01-09 19:30 ` Boris Brezillon 2020-01-09 19:30 ` Boris Brezillon 2020-02-17 8:14 ` masonccyang 2020-02-17 8:14 ` masonccyang 2020-02-17 9:01 ` Miquel Raynal 2020-02-17 9:01 ` Miquel Raynal 2020-02-17 9:22 ` Boris Brezillon 2020-02-17 9:22 ` Boris Brezillon 2020-02-18 3:13 ` masonccyang 2020-02-18 3:13 ` masonccyang 2019-10-28 9:55 ` Mason Yang [this message] 2019-10-28 9:55 ` [PATCH v2 2/4] mtd: rawnand: Add support Macronix Block Protection function Mason Yang 2020-01-09 16:47 ` Miquel Raynal 2020-01-09 16:47 ` Miquel Raynal 2020-02-17 8:24 ` masonccyang 2020-02-17 8:24 ` masonccyang 2019-10-28 9:55 ` [PATCH v2 3/4] mtd: rawnand: Add support manufacturer specific suspend/resume operation Mason Yang 2019-10-28 9:55 ` Mason Yang 2019-10-30 5:56 ` kbuild test robot 2019-10-30 5:56 ` kbuild test robot 2019-10-30 5:56 ` kbuild test robot 2020-01-09 16:53 ` Miquel Raynal 2020-01-09 16:53 ` Miquel Raynal 2019-10-28 9:55 ` [PATCH v2 4/4] mtd: rawnand: Add support Macronix deep power down mode Mason Yang 2019-10-28 9:55 ` Mason Yang 2019-10-31 7:36 ` kbuild test robot 2019-10-31 7:36 ` kbuild test robot 2019-10-31 7:36 ` kbuild test robot 2019-10-31 7:36 ` [RFC PATCH] mtd: rawnand: nand_power_down_op() can be static kbuild test robot 2019-10-31 7:36 ` kbuild test robot 2019-10-31 7:36 ` kbuild test robot 2020-01-09 17:01 ` [PATCH v2 4/4] mtd: rawnand: Add support Macronix deep power down mode Miquel Raynal 2020-01-09 17:01 ` Miquel Raynal 2020-02-21 2:44 ` masonccyang 2020-02-21 2:44 ` masonccyang
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=1572256527-5074-3-git-send-email-masonccyang@mxic.com.tw \ --to=masonccyang@mxic.com.tw \ --cc=bbrezillon@kernel.org \ --cc=computersforpeace@gmail.com \ --cc=dwmw2@infradead.org \ --cc=juliensu@mxic.com.tw \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mtd@lists.infradead.org \ --cc=marek.vasut@gmail.com \ --cc=miquel.raynal@bootlin.com \ --cc=richard@nod.at \ --cc=vigneshr@ti.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: linkBe 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.