All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] mtd: rawnand: Add Macronix NAND read retry support
@ 2019-05-10  7:41 ` Mason Yang
  0 siblings, 0 replies; 22+ messages in thread
From: Mason Yang @ 2019-05-10  7:41 UTC (permalink / raw)
  To: bbrezillon, marek.vasut, linux-kernel, miquel.raynal, richard,
	dwmw2, computersforpeace, linux-mtd
  Cc: juliensu, masonccyang

Add a driver for Macronix NAND read retry.

Macronix NAND supports specfical read for data recovery and enabled
it by Set Feature.
Driver check byte 167 of Vendor Blocks in ONFI parameter page table
to see if this high reliability function is support or not.

Signed-off-by: Mason Yang <masonccyang@mxic.com.tw>
---
 drivers/mtd/nand/raw/nand_macronix.c | 52 ++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/drivers/mtd/nand/raw/nand_macronix.c b/drivers/mtd/nand/raw/nand_macronix.c
index 47d8cda..5cd1e5f 100644
--- a/drivers/mtd/nand/raw/nand_macronix.c
+++ b/drivers/mtd/nand/raw/nand_macronix.c
@@ -17,6 +17,57 @@
 
 #include "internals.h"
 
+#define MACRONIX_READ_RETRY_BIT BIT(0)
+#define MACRONIX_READ_RETRY_MODE 5
+
+struct nand_onfi_vendor_macronix {
+	u8 reserved[1];
+	u8 reliability_func;
+} __packed;
+
+static int macronix_nand_setup_read_retry(struct nand_chip *chip, int mode)
+{
+	u8 feature[ONFI_SUBFEATURE_PARAM_LEN] = {0};
+	int ret;
+
+	if (mode > MACRONIX_READ_RETRY_MODE)
+		mode = MACRONIX_READ_RETRY_MODE;
+
+	feature[0] = mode;
+	ret =  nand_set_features(chip, ONFI_FEATURE_ADDR_READ_RETRY, feature);
+	if (ret)
+		pr_err("set feature failed to read retry moded:%d\n", mode);
+
+	ret =  nand_get_features(chip, ONFI_FEATURE_ADDR_READ_RETRY, feature);
+	if (ret || feature[0] != mode)
+		pr_err("get feature failed to read retry moded:%d(%d)\n",
+		       mode, feature[0]);
+
+	return ret;
+}
+
+static void macronix_nand_onfi_init(struct nand_chip *chip)
+{
+	struct nand_parameters *p = &chip->parameters;
+
+	if (p->onfi) {
+		struct nand_onfi_vendor_macronix *mxic =
+				(void *)p->onfi->vendor;
+
+		if (mxic->reliability_func & MACRONIX_READ_RETRY_BIT) {
+			chip->read_retries = MACRONIX_READ_RETRY_MODE + 1;
+			chip->setup_read_retry =
+				 macronix_nand_setup_read_retry;
+			if (p->supports_set_get_features) {
+				set_bit(ONFI_FEATURE_ADDR_READ_RETRY,
+					p->set_feature_list);
+				set_bit(ONFI_FEATURE_ADDR_READ_RETRY,
+					p->get_feature_list);
+			}
+		}
+	}
+}
+
 /*
  * Macronix AC series does not support using SET/GET_FEATURES to change
  * the timings unlike what is declared in the parameter page. Unflag
@@ -65,6 +116,7 @@ static int macronix_nand_init(struct nand_chip *chip)
 		chip->bbt_options |= NAND_BBT_SCAN2NDPAGE;
 
 	macronix_nand_fix_broken_get_timings(chip);
+	macronix_nand_onfi_init(chip);
 
 	return 0;
 }
-- 
1.9.1


______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

^ permalink raw reply related	[flat|nested] 22+ messages in thread

end of thread, other threads:[~2019-05-15  1:30 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-10  7:41 [PATCH v1] mtd: rawnand: Add Macronix NAND read retry support Mason Yang
2019-05-10  7:41 ` Mason Yang
2019-05-10  7:45 ` Miquel Raynal
2019-05-10  7:45   ` Miquel Raynal
     [not found]   ` <OF5E2BF75D.98A43E33-ON482583F6.002E7A65-482583F6.0030A2DE@mxic.com.tw>
2019-05-10  9:12     ` Miquel Raynal
2019-05-10  9:12       ` Miquel Raynal
     [not found]       ` <OF3A216E48.80ABBB8A-ON482583F9.002A09DA-482583F9.002AD40E@mxic.com.tw>
2019-05-13  9:59         ` Miquel Raynal
2019-05-13  9:59           ` Miquel Raynal
2019-05-14  2:16           ` masonccyang
2019-05-14  2:16             ` masonccyang
2019-05-10 13:37 ` Thomas Petazzoni
2019-05-10 13:37   ` Thomas Petazzoni
2019-05-10 13:53   ` Miquel Raynal
2019-05-10 13:53     ` Miquel Raynal
2019-05-10 14:18   ` Miquel Raynal
2019-05-10 14:18     ` Miquel Raynal
     [not found]   ` <OF1EDBA487.7723094D-ON482583F9.00297ABF-482583F9.0029E3EE@mxic.com.tw>
2019-05-13  9:40     ` Thomas Petazzoni
2019-05-13  9:40       ` Thomas Petazzoni
     [not found]       ` <OFB5D53BFC.6B44E7E0-ON482583FA.00090982-482583FA.000A5E93@mxic.com.tw>
2019-05-14  7:41         ` Thomas Petazzoni
2019-05-14  7:41           ` Thomas Petazzoni
2019-05-15  1:30           ` masonccyang
2019-05-15  1:30             ` masonccyang

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.