Skip to contentSkip to conversation

mtd: rawnand: Add support manufacturer postponed initialization

RFC PATCH In review Mason Yang 3 participants 20 messages Sep 18, 2019 – Oct 25, 2019 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

Mason Yang

author
#0 lore raw

RFC PATCH 1/3 mtd: rawnand: Add support manufacturer postponed initialization

Manufacturer postponed initialization is for MTD default call-back function replacement for vendor soecific operation, i.e., _lock/_unlock, _suspend/_resume and so on.

---
 drivers/mtd/nand/raw/internals.h |  4 ++++
 drivers/mtd/nand/raw/nand_base.c | 19 +++++++++++++++++++
 2 files changed, 23 insertions(+)
drivers/mtd/nand/raw/internals.h +4 -0
index cba6fe7..505dd46 100644
@@ -42,6 +42,9 @@
  *	     is here to let vendor specific code release those resources.
  * @fixup_onfi_param_page: apply vendor specific fixups to the ONFI parameter
  *			   page. This is called after the checksum is verified.
+ * @post_init: postponed initialization is for MTD default call-back function
+ *	       replacement for vendor specific operation i.e., _lock/_unlock,
+ *	       _suspend/_resume and so on.
  */
 struct nand_manufacturer_ops {
 	void (*detect)(struct nand_chip *chip);
@@ -49,6 +52,7 @@ struct nand_manufacturer_ops {
 	void (*cleanup)(struct nand_chip *chip);
 	void (*fixup_onfi_param_page)(struct nand_chip *chip,
 				      struct nand_onfi_params *p);
+	void (*post_init)(struct nand_chip *chip);
 };
 
 /**
drivers/mtd/nand/raw/nand_base.c +19 -0
index 91f046d..7835b81 100644
@@ -4619,6 +4619,21 @@ static int nand_manufacturer_init(struct nand_chip *chip)
 }
 
 /*
+ * Manufacturer postponed initialization. This function is called for all NANDs
+ * whose MTD default call-back function replacement is needed.
+ * Manufacturer drivers should put all their specific postponed initialization
+ * code in their ->post_init() hook.
+ */
+static void nand_manufacturer_post_init(struct nand_chip *chip)
+{
+	if (!chip->manufacturer.desc || !chip->manufacturer.desc->ops ||
+	    !chip->manufacturer.desc->ops->post_init)
+		return;
+
+	return chip->manufacturer.desc->ops->post_init(chip);
+}
+
+/*
  * Manufacturer cleanup. This function is called for all NANDs including
  * ONFI and JEDEC compliant ones.
  * Manufacturer drivers should put all their specific cleanup code in their
@@ -5812,6 +5827,10 @@ static int nand_scan_tail(struct nand_chip *chip)
 			goto err_nanddev_cleanup;
 	}
 
+	nand_select_target(chip, 0);
+	nand_manufacturer_post_init(chip);
+	nand_deselect_target(chip);
+
 	/* Check, if we should skip the bad block table scan */
 	if (chip->options & NAND_SKIP_BBTSCAN)
 		return 0;
Signature · 1 line
1.9.1
author
#1 lore raw

RFC PATCH 2/3 mtd: rawnand: Add support Macronix Block Protection function

Macronix AC series support using SET/GET_FEATURES to change Block Protection and Unprotection.

MTD default _lock/_unlock function replacement by manufacturer postponed initialization.

---
 drivers/mtd/nand/raw/nand_macronix.c | 80 +++++++++++++++++++++++++++++++++---
 1 file changed, 75 insertions(+), 5 deletions(-)
drivers/mtd/nand/raw/nand_macronix.c +75 -5
index 58511ae..991c636 100644
@@ -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,10 +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)
-{
-	unsigned int i;
-	static const char * const broken_get_timings[] = {
+static const char * const broken_get_timings[] = {
 		"MX30LF1G18AC",
 		"MX30LF1G28AC",
 		"MX30LF2G18AC",
@@ -75,7 +76,11 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
 		"MX30UF4G18AC",
 		"MX30UF4G16AC",
 		"MX30UF4G28AC",
-	};
+};
+
+static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
+{
+	unsigned int i;
 
 	if (!chip->parameters.supports_set_get_features)
 		return;
@@ -105,6 +110,71 @@ static int macronix_nand_init(struct nand_chip *chip)
 	return 0;
 }
 
+static int mxic_nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+	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 mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+	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 AC series support using SET/GET_FEATURES to change
+ * Block Protection and Unprotection.
+ *
+ * MTD call-back function replacement by manufacturer postponed
+ * initialization.
+ */
+static void macronix_nand_post_init(struct nand_chip *chip)
+{
+	unsigned int i, blockprotected = 0;
+	struct mtd_info *mtd = nand_to_mtd(chip);
+
+	for (i = 0; i < ARRAY_SIZE(broken_get_timings); i++) {
+		if (!strcmp(broken_get_timings[i], chip->parameters.model)) {
+			blockprotected = 1;
+			break;
+		}
+	}
+
+	if (blockprotected && chip->parameters.supports_set_get_features) {
+		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);
+
+		mtd->_lock = mxic_nand_lock;
+		mtd->_unlock = mxic_nand_unlock;
+	}
+}
+
 const struct nand_manufacturer_ops macronix_nand_manuf_ops = {
 	.init = macronix_nand_init,
+	.post_init = macronix_nand_post_init,
 };
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function

Hi Mason,

Mason Yang <[email protected]> wrote on Wed, 18 Sep 2019 15:56:25 +0800:

Quoted 5 lines

Macronix AC series support using SET/GET_FEATURES to change Block Protection and Unprotection.

MTD default _lock/_unlock function replacement by manufacturer postponed initialization.

Why would we do that?

Anyway your solution looks overkill, if we ever decide to implement these hooks for raw nand, it is better just to not overwrite them in nand_scan_tail() if they have been filled previously (ie. by the manufacturer code).

Quoted 107 lines
---
 drivers/mtd/nand/raw/nand_macronix.c | 80 +++++++++++++++++++++++++++++++++---
 1 file changed, 75 insertions(+), 5 deletions(-)
drivers/mtd/nand/raw/nand_macronix.c +68 -5
index 58511ae..991c636 100644
@@ -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,10 +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)
-{
-	unsigned int i;
-	static const char * const broken_get_timings[] = {
+static const char * const broken_get_timings[] = {
 		"MX30LF1G18AC",
 		"MX30LF1G28AC",
 		"MX30LF2G18AC",
@@ -75,7 +76,11 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
 		"MX30UF4G18AC",
 		"MX30UF4G16AC",
 		"MX30UF4G28AC",
-	};
+};
+
+static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
+{
+	unsigned int i;
 
 	if (!chip->parameters.supports_set_get_features)
 		return;
@@ -105,6 +110,71 @@ static int macronix_nand_init(struct nand_chip *chip)
 	return 0;
 }
 
+static int mxic_nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+	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 mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+	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 AC series support using SET/GET_FEATURES to change
+ * Block Protection and Unprotection.
+ *
+ * MTD call-back function replacement by manufacturer postponed
+ * initialization.
+ */
+static void macronix_nand_post_init(struct nand_chip *chip)
+{
+	unsigned int i, blockprotected = 0;
+	struct mtd_info *mtd = nand_to_mtd(chip);
+
+	for (i = 0; i < ARRAY_SIZE(broken_get_timings); i++) {
+		if (!strcmp(broken_get_timings[i], chip->parameters.model)) {
+			blockprotected = 1;
+			break;
+		}
+	}
+
+	if (blockprotected && chip->parameters.supports_set_get_features) {
+		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);

drivers/mtd/nand/raw/nand_macronix.c static int macronix_nand_init(struct nand_chip *chip) · line 180

Quoted 10 lines
drivers/mtd/nand/raw/nand_macronix.c +7 -0
+
+		mtd->_lock = mxic_nand_lock;
+		mtd->_unlock = mxic_nand_unlock;
+	}
+}
+
 const struct nand_manufacturer_ops macronix_nand_manuf_ops = {
 	.init = macronix_nand_init,
+	.post_init = macronix_nand_post_init,
 };

Thanks,
Miquèl

maintainer
#3 lore raw

Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function

Hi Mason,

Miquel Raynal <[email protected]> wrote on Mon, 7 Oct 2019 10:45:11 +0200:

Quoted 11 lines

Hi Mason,

Mason Yang <[email protected]> wrote on Wed, 18 Sep 2019 15:56:25 +0800:

Quoted 5 lines

Macronix AC series support using SET/GET_FEATURES to change Block Protection and Unprotection.

MTD default _lock/_unlock function replacement by manufacturer postponed initialization.

Quoted 6 lines

Why would we do that?

Anyway your solution looks overkill, if we ever decide to implement these hooks for raw nand, it is better just to not overwrite them in nand_scan_tail() if they have been filled previously (ie. by the manufacturer code).

Actually you should add two NAND hooks that do the interface with the MTD hooks. In the NAND hooks, check that the request is to lock all the device, otherwise return -ENOTSUPP.

Then fill-in these two hooks from the manufacturer code, without the postponed init.

Quoted 114 lines
Quoted 114 lines
---
 drivers/mtd/nand/raw/nand_macronix.c | 80 +++++++++++++++++++++++++++++++++---
 1 file changed, 75 insertions(+), 5 deletions(-)
drivers/mtd/nand/raw/nand_macronix.c +74 -5
index 58511ae..991c636 100644
@@ -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,10 +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)
-{
-	unsigned int i;
-	static const char * const broken_get_timings[] = {
+static const char * const broken_get_timings[] = {
 		"MX30LF1G18AC",
 		"MX30LF1G28AC",
 		"MX30LF2G18AC",
@@ -75,7 +76,11 @@ static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
 		"MX30UF4G18AC",
 		"MX30UF4G16AC",
 		"MX30UF4G28AC",
-	};
+};
+
+static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
+{
+	unsigned int i;
 
 	if (!chip->parameters.supports_set_get_features)
 		return;
@@ -105,6 +110,71 @@ static int macronix_nand_init(struct nand_chip *chip)
 	return 0;
 }
 
+static int mxic_nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+	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 mtd_info *mtd, loff_t ofs, uint64_t len)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+	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 AC series support using SET/GET_FEATURES to change
+ * Block Protection and Unprotection.
+ *
+ * MTD call-back function replacement by manufacturer postponed
+ * initialization.
+ */
+static void macronix_nand_post_init(struct nand_chip *chip)
+{
+	unsigned int i, blockprotected = 0;
+	struct mtd_info *mtd = nand_to_mtd(chip);
+
+	for (i = 0; i < ARRAY_SIZE(broken_get_timings); i++) {
+		if (!strcmp(broken_get_timings[i], chip->parameters.model)) {
+			blockprotected = 1;
+			break;
+		}
+	}
+
+	if (blockprotected && chip->parameters.supports_set_get_features) {
+		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);
+
+		mtd->_lock = mxic_nand_lock;
+		mtd->_unlock = mxic_nand_unlock;
+	}
+}
+
Quoted 8 lines

drivers/mtd/nand/raw/nand_macronix.c static int macronix_nand_init(struct nand_chip *chip) · line 180

Quoted 4 lines
drivers/mtd/nand/raw/nand_macronix.c +1 -0
 const struct nand_manufacturer_ops macronix_nand_manuf_ops = {
 	.init = macronix_nand_init,
+	.post_init = macronix_nand_post_init,
 };  

Thanks,
Miquèl

Thanks,
Miquèl

#4 lore raw

Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function

Hi Miquel,

Quoted 9 lines
Quoted 9 lines
Quoted 6 lines

Macronix AC series support using SET/GET_FEATURES to change Block Protection and Unprotection.

MTD default _lock/_unlock function replacement by manufacturer postponed initialization.

Why would we do that?

Quoted 8 lines
Quoted 4 lines

Anyway your solution looks overkill, if we ever decide to implement these hooks for raw nand, it is better just to not overwrite them in nand_scan_tail() if they have been filled previously (ie. by the manufacturer code).

Actually you should add two NAND hooks that do the interface with the MTD hooks. In the NAND hooks, check that the request is to lock all the device, otherwise return -ENOTSUPP.

sorry, can't get your point.

Because the NAND entire chip will be protected if PT(protection) pin is active high at power-on.

Quoted 4 lines

Then fill-in these two hooks from the manufacturer code, without the postponed init.

But in the final of nand_scan_tail(), mtd->_lock/_unlock will be filled by NULL, right ?

thanks & best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

maintainer
#5 lore raw

Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function

Hi Mason,

[email protected] wrote on Tue, 8 Oct 2019 10:33:11 +0800:

Quoted 16 lines

Hi Miquel,

Quoted 14 lines
Quoted 13 lines
Quoted 6 lines

Macronix AC series support using SET/GET_FEATURES to change Block Protection and Unprotection.

MTD default _lock/_unlock function replacement by manufacturer postponed initialization.

Why would we do that?

Anyway your solution looks overkill, if we ever decide to implement these hooks for raw nand, it is better just to not overwrite them in nand_scan_tail() if they have been filled previously (ie. by the manufacturer code).

Quoted 8 lines
Quoted 3 lines

Actually you should add two NAND hooks that do the interface with the MTD hooks. In the NAND hooks, check that the request is to lock all the device, otherwise return -ENOTSUPP.

sorry, can't get your point.

Because the NAND entire chip will be protected if PT(protection) pin is active high at power-on.

In your implementation of the locking, you should check that the locking request is over the entire device, unless you can lock a smaller portion of course.

Quoted 8 lines
Quoted 5 lines

Then fill-in these two hooks from the manufacturer code, without the postponed init.

But in the final of nand_scan_tail(), mtd->_lock/_unlock will be filled by NULL, right ?

The NAND core should set mtd->_lock/_unlock() to NAND specific hooks so that the MTD layer is abstracted and and drivers do not see it. Then, in the NAND helper, either there is no specific hook defined by a manufacturer driver and you return -ENOTSUPP, or you execute the defined hook.

Thanks,
Miquèl

#6 lore raw

Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function

Hi Miquel,

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Macronix AC series support using SET/GET_FEATURES to change Block Protection and Unprotection.

MTD default _lock/_unlock function replacement by manufacturer postponed initialization.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

Why would we do that?

Anyway your solution looks overkill, if we ever decide to implement these hooks for raw nand, it is better just to not overwrite them in nand_scan_tail() if they have been filled previously (ie. by the manufacturer code).

Actually you should add two NAND hooks that do the interface with

the

Quoted 1 line
Quoted 1 line
Quoted 1 line

MTD hooks. In the NAND hooks, check that the request is to lock all

the

Quoted 10 lines
Quoted 6 lines
Quoted 1 line

device, otherwise return -ENOTSUPP.

sorry, can't get your point.

Because the NAND entire chip will be protected if PT(protection) pin is active high at power-on.

In your implementation of the locking, you should check that the locking request is over the entire device, unless you can lock a smaller portion of course.

yes, I can lock a smaller portion.
And at the power-on of device with PT pin at high voltage, all blocks are locked.
They have to be unlocked by set feature command.

Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Then fill-in these two hooks from the manufacturer code, without the postponed init.

Quoted 8 lines
Quoted 2 lines

But in the final of nand_scan_tail(), mtd->_lock/_unlock will be filled by NULL, right ?

The NAND core should set mtd->_lock/_unlock() to NAND specific hooks so that the MTD layer is abstracted and and drivers do not see it. Then, in the NAND helper, either there is no specific hook defined by a manufacturer driver and you return -ENOTSUPP, or you execute the defined hook.

okay, patch specific manufacturer _lock/_unlock driver in nand_manufacturer_init();

and in the final of nand_scan_tail()
if (!mtd->_lock)

        mtd->_lock = NULL;
if (!mtd->_unlock)
        mtd->_unlock = NULL;

thanks for your time and comments.
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

A message that is not in the archive (sent off-list or not yet received): OFB4F10613.467EB346-ON48258494.0020403E-48258494.002550A2@LocalDomain

#8 lore raw

Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function

Hi Miquel,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Then fill-in these two hooks from the manufacturer code, without

the

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

postponed init.

But in the final of nand_scan_tail(), mtd->_lock/_unlock will be filled by NULL, right ?

The NAND core should set mtd->_lock/_unlock() to NAND specific hooks

so

Quoted 5 lines
Quoted 4 lines

that the MTD layer is abstracted and and drivers do not see it. Then, in the NAND helper, either there is no specific hook defined by a manufacturer driver and you return -ENOTSUPP, or you execute the defined hook.

Quoted 8 lines

okay, patch specific manufacturer _lock/_unlock driver in nand_manufacturer_init();

and in the final of nand_scan_tail()
if (!mtd->_lock)
mtd->_lock = NULL;
if (!mtd->_unlock)
mtd->_unlock = NULL;

I'm still considering of post_init() in nand_scan_tail() for MTD layer default call-back function replacement because there would be more call-back functions need it. i.e.,
MTD->_lock/_unlokc
MTD->_suspend/_resume
NTD->_point/_unpoint
...

actually, my patch series are including MTD->_locl/_unlock and MTD->_suspend/_resume. how do you think ?

thanks for your time & comments.
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#9 lore raw

Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function

Quoted 28 lines · On Mon, 21 Oct 2019 15:23:57 +0800 [email protected] wrote:

Hi Miquel,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Then fill-in these two hooks from the manufacturer code, without

the

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

postponed init.

But in the final of nand_scan_tail(), mtd->_lock/_unlock will be filled by NULL, right ?

The NAND core should set mtd->_lock/_unlock() to NAND specific hooks

so

Quoted 5 lines
Quoted 4 lines

that the MTD layer is abstracted and and drivers do not see it. Then, in the NAND helper, either there is no specific hook defined by a manufacturer driver and you return -ENOTSUPP, or you execute the defined hook.

Quoted 8 lines

okay, patch specific manufacturer _lock/_unlock driver in nand_manufacturer_init();

and in the final of nand_scan_tail()
if (!mtd->_lock)
mtd->_lock = NULL;
if (!mtd->_unlock)
mtd->_unlock = NULL;

Quoted 6 lines

I'm still considering of post_init() in nand_scan_tail() for MTD layer default call-back function replacement because there would be more call-back functions need it. i.e.,
MTD->_lock/_unlokc
MTD->_suspend/_resume

Again, that's something that needs to be abstracted so that both the NAND manufacturer driver and the NAND controller driver can take appropriate actions on suspend/resume operations.

Quoted 1 line

NTD->_point/_unpoint

->_point/_unpoint() are irrelevant for a NAND chip.

Quoted 5 lines

...

actually, my patch series are including MTD->_locl/_unlock and MTD->_suspend/_resume. how do you think ?

Miquel was suggesting to add nand_chip->{lock,unlock,is_locked}() methods that would be implemented by the NAND manufacturer drivers, and have generic wrappers implemented in nand_base.c:

static int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)

{
	struct nand_chip *chip = mtd_to_nand(mtd);

	if (!chip->lock)
		return -ENOTSUPP;

	return chip->lock(chip, ofs, len);
}

...

If you do that, you won't need this post_init() hook.

#10 lore raw

Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function

Hi Boris,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Then fill-in these two hooks from the manufacturer code,

without

Quoted 8 lines
Quoted 8 lines

the

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

postponed init.

But in the final of nand_scan_tail(), mtd->_lock/_unlock will be filled by NULL, right ?

The NAND core should set mtd->_lock/_unlock() to NAND specific

hooks

Quoted 2 lines
Quoted 2 lines

so

Quoted 1 line
Quoted 1 line

that the MTD layer is abstracted and and drivers do not see it.

Then,

Quoted 49 lines
Quoted 14 lines
Quoted 4 lines
Quoted 3 lines

in the NAND helper, either there is no specific hook defined by a manufacturer driver and you return -ENOTSUPP, or you execute the defined hook.

Quoted 8 lines

okay, patch specific manufacturer _lock/_unlock driver in nand_manufacturer_init();

and in the final of nand_scan_tail()
if (!mtd->_lock)
mtd->_lock = NULL;
if (!mtd->_unlock)
mtd->_unlock = NULL;

Quoted 6 lines

I'm still considering of post_init() in nand_scan_tail() for MTD layer default call-back function replacement because there would be more call-back functions need it. i.e.,
MTD->_lock/_unlokc
MTD->_suspend/_resume

Again, that's something that needs to be abstracted so that both the NAND manufacturer driver and the NAND controller driver can take appropriate actions on suspend/resume operations.

Quoted 1 line

NTD->_point/_unpoint

->_point/_unpoint() are irrelevant for a NAND chip.

Quoted 5 lines

...

actually, my patch series are including MTD->_locl/_unlock and MTD->_suspend/_resume. how do you think ?

Miquel was suggesting to add nand_chip->{lock,unlock,is_locked}() methods that would be implemented by the NAND manufacturer drivers, and have generic wrappers implemented in nand_base.c:

static int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)

{
   struct nand_chip *chip = mtd_to_nand(mtd);

   if (!chip->lock)
      return -ENOTSUPP;

   return chip->lock(chip, ofs, len);
}
Quoted 3 lines

...

If you do that, you won't need this post_init() hook.

got it, but ...
user space program flash_lock/flash_unlock are calling mtd_lock() & mtd_unlock().
i.e.,
int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)

{
         if (!mtd->_lock)
                 return -EOPNOTSUPP;
         if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
                 return -EINVAL;
         if (!len)
                 return 0;
         return mtd->_lock(mtd, ofs, len);
}

thanks for your time & comments.
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#11 lore raw

Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function

Quoted 75 lines · On Mon, 21 Oct 2019 16:40:57 +0800 [email protected] wrote:

Hi Boris,

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Then fill-in these two hooks from the manufacturer code,

without

Quoted 8 lines
Quoted 8 lines

the

Quoted 7 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

postponed init.

But in the final of nand_scan_tail(), mtd->_lock/_unlock will be filled by NULL, right ?

The NAND core should set mtd->_lock/_unlock() to NAND specific

hooks

Quoted 2 lines
Quoted 2 lines

so

Quoted 1 line
Quoted 1 line

that the MTD layer is abstracted and and drivers do not see it.

Then,

Quoted 49 lines
Quoted 14 lines
Quoted 4 lines
Quoted 3 lines

in the NAND helper, either there is no specific hook defined by a manufacturer driver and you return -ENOTSUPP, or you execute the defined hook.

Quoted 8 lines

okay, patch specific manufacturer _lock/_unlock driver in nand_manufacturer_init();

and in the final of nand_scan_tail()
if (!mtd->_lock)
mtd->_lock = NULL;
if (!mtd->_unlock)
mtd->_unlock = NULL;

Quoted 6 lines

I'm still considering of post_init() in nand_scan_tail() for MTD layer default call-back function replacement because there would be more call-back functions need it. i.e.,
MTD->_lock/_unlokc
MTD->_suspend/_resume

Again, that's something that needs to be abstracted so that both the NAND manufacturer driver and the NAND controller driver can take appropriate actions on suspend/resume operations.

Quoted 1 line

NTD->_point/_unpoint

->_point/_unpoint() are irrelevant for a NAND chip.

Quoted 5 lines

...

actually, my patch series are including MTD->_locl/_unlock and MTD->_suspend/_resume. how do you think ?

Miquel was suggesting to add nand_chip->{lock,unlock,is_locked}() methods that would be implemented by the NAND manufacturer drivers, and have generic wrappers implemented in nand_base.c:

static int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)

{
   struct nand_chip *chip = mtd_to_nand(mtd);

   if (!chip->lock)
      return -ENOTSUPP;

   return chip->lock(chip, ofs, len);
}
Quoted 3 lines

...

If you do that, you won't need this post_init() hook.

got it, but ...
user space program flash_lock/flash_unlock are calling mtd_lock() & mtd_unlock().
i.e.,
int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)

Quoted 10 lines
{
         if (!mtd->_lock)
                 return -EOPNOTSUPP;
         if (ofs < 0 || ofs >= mtd->size || len > mtd->size - ofs)
                 return -EINVAL;
         if (!len)
                 return 0;
         return mtd->_lock(mtd, ofs, len);
}

Assign mtd lock/unlock/is_locked hooks to the generic wrappers in nand_scan_tail():

	mtd->_lock = nand_lock;
	mtd->_unlock = nand_unlock;
	mtd->_is_locked = nand_is_locked;

Seriously, we've almost implemented the thing for you with all the details we've given. At some point you have to look more closely at how things are done/designed in the NAND framework if you want to contribute core changes. I'm fine giving hints but we're far beyond that point here.

#12 lore raw

Re: [PATCH RFC 2/3] mtd: rawnand: Add support Macronix Block Protection function

Hi Boris,

Quoted 8 lines

Assign mtd lock/unlock/is_locked hooks to the generic wrappers in nand_scan_tail():

   mtd->_lock = nand_lock;
   mtd->_unlock = nand_unlock;
   mtd->_is_locked = nand_is_locked;
Quoted 5 lines

Seriously, we've almost implemented the thing for you with all the details we've given. At some point you have to look more closely at how things are done/designed in the NAND framework if you want to contribute core changes. I'm fine giving hints but we're far beyond that point here.

got your point & idea.

thanks a lot for your time & opinions.
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

author
#13 lore raw

RFC PATCH 3/3 mtd: rawnand: Add support Macronix power down mode

In reply to Mason Yang

Macronix AD series support using power down command to enter a minimum power consumption state.

MTD default _suspend/_resume function replacement by manufacturer postponed initialization.

---
 drivers/mtd/nand/raw/nand_macronix.c | 78 +++++++++++++++++++++++++++++++++++-
 1 file changed, 77 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_macronix.c +77 -1
index 991c636..99a7b2e 100644
@@ -15,6 +15,8 @@
 #define MXIC_BLOCK_PROTECTION_ALL_LOCK 0x38
 #define MXIC_BLOCK_PROTECTION_ALL_UNLOCK 0x0
 
+#define NAND_CMD_POWER_DOWN 0xB9
+
 struct nand_onfi_vendor_macronix {
 	u8 reserved;
 	u8 reliability_func;
@@ -78,6 +80,12 @@ static void macronix_nand_onfi_init(struct nand_chip *chip)
 		"MX30UF4G28AC",
 };
 
+static const char * const nand_power_down[] = {
+		"MX30LF1G28AD",
+		"MX30LF2G28AD",
+		"MX30LF4G28AD",
+};
+
 static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
 {
 	unsigned int i;
@@ -144,8 +152,64 @@ static int mxic_nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 	return ret;
 }
 
+int nand_power_down_op(struct nand_chip *chip)
+{
+	int ret;
+
+	if (nand_has_exec_op(chip)) {
+		struct nand_op_instr instrs[] = {
+			NAND_OP_CMD(NAND_CMD_POWER_DOWN, 0),
+		};
+
+		struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs);
+
+		ret = nand_exec_op(chip, &op);
+		if (ret)
+			return ret;
+
+	} else {
+		chip->legacy.cmdfunc(chip, NAND_CMD_POWER_DOWN, -1, -1);
+	}
+
+	return 0;
+}
+
+static int mxic_nand_suspend(struct mtd_info *mtd)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+
+	mutex_lock(&chip->lock);
+
+	nand_select_target(chip, 0);
+	nand_power_down_op(chip);
+	nand_deselect_target(chip);
+
+	chip->suspend = 1;
+	mutex_unlock(&chip->lock);
+
+	return 0;
+}
+
+static void mxic_nand_resume(struct mtd_info *mtd)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+
+	mutex_lock(&chip->lock);
+	// toggle #CS pin to resume NAND device
+	nand_select_target(chip, 0);
+	ndelay(20);
+	nand_deselect_target(chip);
+
+	if (chip->suspend)
+		chip->suspended = 0;
+	else
+		pr_err("%s call for a chip which is not in suspended state\n",
+		       __func__);
+	mutex_unlock(&chip->lock);
+}
+
 /*
- * Macronix AC series support using SET/GET_FEATURES to change
+ * Macronix AC and AD series support using SET/GET_FEATURES to change
  * Block Protection and Unprotection.
  *
  * MTD call-back function replacement by manufacturer postponed
@@ -163,6 +227,18 @@ static void macronix_nand_post_init(struct nand_chip *chip)
 		}
 	}
 
+	for (i = 0; i < ARRAY_SIZE(nand_power_down); i++) {
+		if (!strcmp(nand_power_down[i], chip->parameters.model)) {
+			blockprotected = 1;
+			break;
+		}
+	}
+
+	if (i < ARRAY_SIZE(nand_power_down)) {
+		mtd->_suspend = mxic_nand_suspend;
+		mtd->_resume = mxic_nand_resume;
+	}
+
 	if (blockprotected && chip->parameters.supports_set_get_features) {
 		bitmap_set(chip->parameters.set_feature_list,
 			   ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1);
Signature · 1 line
1.9.1
maintainer
#14 lore raw

Re: [PATCH RFC 3/3] mtd: rawnand: Add support Macronix power down mode

Hi Mason,

Mason Yang <[email protected]> wrote on Wed, 18 Sep 2019 15:56:26 +0800:

Quoted 75 lines

Macronix AD series support using power down command to enter a minimum power consumption state.

MTD default _suspend/_resume function replacement by manufacturer postponed initialization.

---
 drivers/mtd/nand/raw/nand_macronix.c | 78 +++++++++++++++++++++++++++++++++++-
 1 file changed, 77 insertions(+), 1 deletion(-)
drivers/mtd/nand/raw/nand_macronix.c +42 -0
index 991c636..99a7b2e 100644
@@ -15,6 +15,8 @@
 #define MXIC_BLOCK_PROTECTION_ALL_LOCK 0x38
 #define MXIC_BLOCK_PROTECTION_ALL_UNLOCK 0x0
 
+#define NAND_CMD_POWER_DOWN 0xB9
+
 struct nand_onfi_vendor_macronix {
 	u8 reserved;
 	u8 reliability_func;
@@ -78,6 +80,12 @@ static void macronix_nand_onfi_init(struct nand_chip *chip)
 		"MX30UF4G28AC",
 };
 
+static const char * const nand_power_down[] = {
+		"MX30LF1G28AD",
+		"MX30LF2G28AD",
+		"MX30LF4G28AD",
+};
+
 static void macronix_nand_fix_broken_get_timings(struct nand_chip *chip)
 {
 	unsigned int i;
@@ -144,8 +152,64 @@ static int mxic_nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
 	return ret;
 }
 
+int nand_power_down_op(struct nand_chip *chip)
+{
+	int ret;
+
+	if (nand_has_exec_op(chip)) {
+		struct nand_op_instr instrs[] = {
+			NAND_OP_CMD(NAND_CMD_POWER_DOWN, 0),
+		};
+
+		struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs);
+
+		ret = nand_exec_op(chip, &op);
+		if (ret)
+			return ret;
+
+	} else {
+		chip->legacy.cmdfunc(chip, NAND_CMD_POWER_DOWN, -1, -1);
+	}
+
+	return 0;
+}
+
+static int mxic_nand_suspend(struct mtd_info *mtd)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+
+	mutex_lock(&chip->lock);
+
+	nand_select_target(chip, 0);
+	nand_power_down_op(chip);
+	nand_deselect_target(chip);
+
+	chip->suspend = 1;
+	mutex_unlock(&chip->lock);

drivers/mtd/nand/raw/nand_macronix.c static int mxic_nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) · line 198

Quoted 10 lines
drivers/mtd/nand/raw/nand_macronix.c +10 -0
+
+	return 0;
+}
+
+static void mxic_nand_resume(struct mtd_info *mtd)
+{
+	struct nand_chip *chip = mtd_to_nand(mtd);
+
+	mutex_lock(&chip->lock);
+	// toggle #CS pin to resume NAND device

C++ style comments are forbidden in code.

drivers/mtd/nand/raw/nand_macronix.c static int mxic_nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) · line 199

Quoted 1 line
drivers/mtd/nand/raw/nand_macronix.c +1 -0
+	nand_select_target(chip, 0);

On several NAND controllers there is no way to act on the CS line without actually writing bytes to the NAND chip. So basically this is very likely to not work.

drivers/mtd/nand/raw/nand_macronix.c static int mxic_nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) · line 200

Quoted 1 line
drivers/mtd/nand/raw/nand_macronix.c +1 -0
+	ndelay(20);

Is this delay known somewhere? Is this purely experimental?

Quoted 25 lines
drivers/mtd/nand/raw/nand_macronix.c +16 -1
+	nand_deselect_target(chip);
+
+	if (chip->suspend)
+		chip->suspended = 0;
+	else
+		pr_err("%s call for a chip which is not in suspended state\n",
+		       __func__);
+	mutex_unlock(&chip->lock);
+}
+
 /*
- * Macronix AC series support using SET/GET_FEATURES to change
+ * Macronix AC and AD series support using SET/GET_FEATURES to change
  * Block Protection and Unprotection.
  *
  * MTD call-back function replacement by manufacturer postponed
@@ -163,6 +227,18 @@ static void macronix_nand_post_init(struct nand_chip *chip)
 		}
 	}
 
+	for (i = 0; i < ARRAY_SIZE(nand_power_down); i++) {
+		if (!strcmp(nand_power_down[i], chip->parameters.model)) {
+			blockprotected = 1;
+			break;
+		}

drivers/mtd/nand/raw/nand_macronix.c static void macronix_nand_post_init(struct nand_chip *chip) · line 244

Quoted 10 lines
drivers/mtd/nand/raw/nand_macronix.c +7 -0
+	}
+
+	if (i < ARRAY_SIZE(nand_power_down)) {
+		mtd->_suspend = mxic_nand_suspend;
+		mtd->_resume = mxic_nand_resume;
+	}
+
 	if (blockprotected && chip->parameters.supports_set_get_features) {
 		bitmap_set(chip->parameters.set_feature_list,
 			   ONFI_FEATURE_ADDR_MXIC_PROTECTION, 1);

Thanks,
Miquèl

#15 lore raw

Re: [PATCH RFC 3/3] mtd: rawnand: Add support Macronix power down mode

Hi Miquel,

Quoted 10 lines

drivers/mtd/nand/raw/nand_macronix.c static int mxic_nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)

Quoted 10 lines
drivers/mtd/nand/raw/nand_macronix.c +10 -0
+int nand_power_down_op(struct nand_chip *chip)
+{
+   int ret;
+
+   if (nand_has_exec_op(chip)) {
+      struct nand_op_instr instrs[] = {
+         NAND_OP_CMD(NAND_CMD_POWER_DOWN, 0),
+      };
+
+      struct nand_operation op = NAND_OPERATION(chip->cur_cs, 

instrs);

Quoted 28 lines
Quoted 28 lines
drivers/mtd/nand/raw/nand_macronix.c +28 -0
+
+      ret = nand_exec_op(chip, &op);
+      if (ret)
+         return ret;
+
+   } else {
+      chip->legacy.cmdfunc(chip, NAND_CMD_POWER_DOWN, -1, -1);
+   }
+
+   return 0;
+}
+
+static int mxic_nand_suspend(struct mtd_info *mtd)
+{
+   struct nand_chip *chip = mtd_to_nand(mtd);
+
+   mutex_lock(&chip->lock);
+
+   nand_select_target(chip, 0);
+   nand_power_down_op(chip);
+   nand_deselect_target(chip);
+
+   chip->suspend = 1;
+   mutex_unlock(&chip->lock);
+
+   return 0;
+}
+
Quoted 8 lines

drivers/mtd/nand/raw/nand_macronix.c static int mxic_nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) · line 198

Quoted 6 lines
drivers/mtd/nand/raw/nand_macronix.c +6 -0
+static void mxic_nand_resume(struct mtd_info *mtd)
+{
+   struct nand_chip *chip = mtd_to_nand(mtd);
+
+   mutex_lock(&chip->lock);
+   // toggle #CS pin to resume NAND device

C++ style comments are forbidden in code.

okay, got it. thanks.

Quoted 6 lines
Quoted 2 lines

+ nand_select_target(chip, 0);

On several NAND controllers there is no way to act on the CS line without actually writing bytes to the NAND chip. So basically this is very likely to not work.

any other way to make it work ? GPIO ?
or just have some comments description here.
i.e,.

/* The NAND chip will exit the deep power down mode with #CS toggling,
* please refer to datasheet for the timing requirement of tCRDP and tRDP. */

Quoted 4 lines
Quoted 2 lines

+ ndelay(20);

Is this delay known somewhere? Is this purely experimental?

it's timing requirement tCRDP 20 ns(min) to release device from deep power-down mode.
You may download datasheet at
https://www.macronix.com/zh-tw/products/NAND-Flash/SLC-NAND-Flash/Pages/spec.aspx?p=MX30LF4G28AD&m=SLC%20NAND&n=PM2579

Quoted 10 lines

drivers/mtd/nand/raw/nand_macronix.c static int mxic_nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) · line 209

Quoted 10 lines
drivers/mtd/nand/raw/nand_macronix.c +9 -0
+   nand_deselect_target(chip);
+
+   if (chip->suspend)
+      chip->suspended = 0;
+   else
+      pr_err("%s call for a chip which is not in suspended state\n",
+             __func__);
+   mutex_unlock(&chip->lock);
+}

thanks & best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#16 lore raw

Re: [PATCH RFC 3/3] mtd: rawnand: Add support Macronix power down mode

Quoted 6 lines · On Tue, 8 Oct 2019 10:06:50 +0800 [email protected] wrote:
Quoted 5 lines
Quoted 1 line

+ nand_select_target(chip, 0);

On several NAND controllers there is no way to act on the CS line without actually writing bytes to the NAND chip. So basically this is very likely to not work.

Quoted 8 lines

any other way to make it work ? GPIO ?
or just have some comments description here.
i.e,.

/* The NAND chip will exit the deep power down mode with #CS toggling,
* please refer to datasheet for the timing requirement of tCRDP and tRDP. */

Good luck with that. As Miquel said, on most NAND controllers select_target() is a dummy operation that just assigns nand_chip->target to the specified value but doesn't assert the CS line. You could send a dummy command here, like a READ_ID, but I guess you need CS to be asserted for at least 20ns before asserting any other signals (CLE/ALE) which might be an issue.

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

+ ndelay(20);

Is this delay known somewhere? Is this purely experimental?

it's timing requirement tCRDP 20 ns(min) to release device from deep power-down mode.
You may download datasheet at
https://www.macronix.com/zh-tw/products/NAND-Flash/SLC-NAND-Flash/Pages/spec.aspx?p=MX30LF4G28AD&m=SLC%20NAND&n=PM2579

Just looked at the datasheet, and there's actually more than tCRDP:

- you have to make sure you entered power-down state for at least tDPDD before you try to wake up the device
- the device goes back to stand-by state tRDP after the CS pin has been deasserted.

I guess we can use ndelay() for those, since they happen before/after the CS pin is asserted/de-asserted. Be careful with ndelay() though, it's not guaranteed to wait the the time you pass, it can return before (maybe we should add a helper to deal with that). Another solution would be to describe CS assertion/de-assertion in the instruction flow, but that requires patching all exec_op() drivers.

For the tCRDP timing, I think we should use a nand_operation, this way we can check if the controller is able to deal with dummy CS-assertion before entering deep-power mode.
In order to do that you'll have to add a NAND_OP_DUMMY_INSTR (or NAND_OP_DELAY_INSTR), and then have something like:

struct nand_op_instr instrs[] = {
NAND_OP_DUMMY(tCRDP),
};

#17 lore raw

Re: [PATCH RFC 3/3] mtd: rawnand: Add support Macronix power down mode

Hi Boris,

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

+ nand_select_target(chip, 0);

On several NAND controllers there is no way to act on the CS line without actually writing bytes to the NAND chip. So basically this is very likely to not work.

Quoted 7 lines
Quoted 7 lines

any other way to make it work ? GPIO ?
or just have some comments description here.
i.e,.

/* The NAND chip will exit the deep power down mode with #CS toggling,

* please refer to datasheet for the timing requirement of tCRDP and

tRDP.

Quoted 9 lines
Quoted 2 lines

*/

Good luck with that. As Miquel said, on most NAND controllers select_target() is a dummy operation that just assigns nand_chip->target to the specified value but doesn't assert the CS line. You could send a dummy command here, like a READ_ID, but I guess you need CS to be asserted for at least 20ns before asserting any other signals (CLE/ALE) which might be an issue.

okay, got it.
But if possible, I think adding CS line control in nand_select_target() is a simple and generic way for MTD and all raw NAND controllers.

Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

+ ndelay(20);

Is this delay known somewhere? Is this purely experimental?

it's timing requirement tCRDP 20 ns(min) to release device from deep power-down mode.
You may download datasheet at

https://www.macronix.com/zh-tw/products/NAND-Flash/SLC-NAND-Flash/Pages/

Quoted 22 lines

spec.aspx?p=MX30LF4G28AD&m=SLC%20NAND&n=PM2579

Just looked at the datasheet, and there's actually more than tCRDP:

- you have to make sure you entered power-down state for at least tDPDD before you try to wake up the device
- the device goes back to stand-by state tRDP after the CS pin has been deasserted.

I guess we can use ndelay() for those, since they happen before/after the CS pin is asserted/de-asserted. Be careful with ndelay() though, it's not guaranteed to wait the the time you pass, it can return before (maybe we should add a helper to deal with that). Another solution would be to describe CS assertion/de-assertion in the instruction flow, but that requires patching all exec_op() drivers.

For the tCRDP timing, I think we should use a nand_operation, this way we can check if the controller is able to deal with dummy CS-assertion before entering deep-power mode.
In order to do that you'll have to add a NAND_OP_DUMMY_INSTR (or NAND_OP_DELAY_INSTR), and then have something like:

Quoted 3 lines

struct nand_op_instr instrs[] = {
NAND_OP_DUMMY(tCRDP),
};

got it.

thanks for your time and comments.

best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

maintainer
#18 lore raw

Re: [PATCH RFC 3/3] mtd: rawnand: Add support Macronix power down mode

Hi Mason,

[email protected] wrote on Tue, 15 Oct 2019 10:33:29 +0800:

Quoted 27 lines

Hi Boris,

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 1 line

+ nand_select_target(chip, 0);

On several NAND controllers there is no way to act on the CS line without actually writing bytes to the NAND chip. So basically this is very likely to not work.

Quoted 7 lines
Quoted 7 lines

any other way to make it work ? GPIO ?
or just have some comments description here.
i.e,.

/* The NAND chip will exit the deep power down mode with #CS toggling,

* please refer to datasheet for the timing requirement of tCRDP and

tRDP.

Quoted 9 lines
Quoted 2 lines

*/

Good luck with that. As Miquel said, on most NAND controllers select_target() is a dummy operation that just assigns nand_chip->target to the specified value but doesn't assert the CS line. You could send a dummy command here, like a READ_ID, but I guess you need CS to be asserted for at least 20ns before asserting any other signals (CLE/ALE) which might be an issue.

Quoted 3 lines

okay, got it.
But if possible, I think adding CS line control in nand_select_target() is a simple and generic way for MTD and all raw NAND controllers.

The problem is not that we do not want to; the problem is that controllers are not capable of doing it reliably if no byte is sent over the NAND bus.

Thanks,
Miquèl

#19 lore raw

Re: [PATCH RFC 3/3] mtd: rawnand: Add support Macronix power down mode

Hi Miquel,

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

+ nand_select_target(chip, 0);

On several NAND controllers there is no way to act on the CS

line

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

without actually writing bytes to the NAND chip. So basically

this

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 1 line

is very likely to not work.

any other way to make it work ? GPIO ?
or just have some comments description here.
i.e,.

/* The NAND chip will exit the deep power down mode with #CS

toggling,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

* please refer to datasheet for the timing requirement of tCRDP

and

Quoted 6 lines
Quoted 6 lines

tRDP.

Quoted 5 lines
Quoted 2 lines

*/

Good luck with that. As Miquel said, on most NAND controllers select_target() is a dummy operation that just assigns

nand_chip->target

Quoted 1 line
Quoted 1 line
Quoted 1 line

to the specified value but doesn't assert the CS line. You could

send a

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

dummy command here, like a READ_ID, but I guess you need CS to be asserted for at least 20ns before asserting any other signals

(CLE/ALE)

Quoted 4 lines
Quoted 4 lines
Quoted 1 line

which might be an issue.

okay, got it.
But if possible, I think adding CS line control in

nand_select_target()

Quoted 5 lines
Quoted 1 line

is a simple and generic way for MTD and all raw NAND controllers.

The problem is not that we do not want to; the problem is that controllers are not capable of doing it reliably if no byte is sent over the NAND bus.

okay, it's kind of pity even though our raw NAND controller is capable of

doing it with no byte is sent over the NAND bus.

As you mentioned that other controllers are not capable of doing it reliably
if no byte is sent over the NAND bus.
if so, does it work by adding a NAND_OP_DUMMY_INSTR ? (as Boris's comments)

thanks for your time & comments.

Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

#20 lore raw

Re: [PATCH RFC 3/3] mtd: rawnand: Add support Macronix power down mode

In reply to Boris Brezillon

Hi Boris,

Quoted 21 lines

Subject

Re: [PATCH RFC 3/3] mtd: rawnand: Add support Macronix power down mode

Quoted 13 lines · On Tue, 8 Oct 2019 10:06:50 +0800 [email protected] wrote:
Quoted 5 lines
Quoted 1 line

+ nand_select_target(chip, 0);

On several NAND controllers there is no way to act on the CS line without actually writing bytes to the NAND chip. So basically this is very likely to not work.

any other way to make it work ? GPIO ?
or just have some comments description here.
i.e,.

/* The NAND chip will exit the deep power down mode with #CS toggling,

* please refer to datasheet for the timing requirement of tCRDP and

tRDP.

Quoted 10 lines
Quoted 2 lines

*/

Good luck with that. As Miquel said, on most NAND controllers select_target() is a dummy operation that just assigns nand_chip->target to the specified value but doesn't assert the CS line. You could send a dummy command here, like a READ_ID, but I guess you need CS to be asserted for at least 20ns before asserting any other signals (CLE/ALE) which might be an issue.

I have validated & checked w/ designer that NANDs device just need CS# line
toggling and don't care of CLE/WE#/RE#. That is raw NAND controller sending
a command nand_status_op() or nand_power_down_op() will exit the deep power down too. The first command(just CS# line toggling) to NAND device in deep power down mode will not be recognized. We may publish the application notes or update the datasheet later.

thanks & best regards,
Mason

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================

============================================================================

CONFIDENTIALITY NOTE:

This e-mail and any attachments may contain confidential information and/or personal data, which is protected by applicable laws. Please be reminded that duplication, disclosure, distribution, or use of this e-mail (and/or its attachments) or any part thereof is prohibited. If you receive this e-mail in error, please notify us immediately and delete this mail as well as its attachment(s) from your system. In addition, please be informed that collection, processing, and/or use of personal data is prohibited unless expressly permitted by personal data protection laws. Thank you for your attention and cooperation.

Macronix International Co., Ltd.

=====================================================================