From bfa2c1d8c9e37f32bbb2823bbf327c166981faa2 Mon Sep 17 00:00:00 2001
From: johnchain <lijunqian@dhms.net>
Date: Tue, 26 Dec 2017 16:09:44 +0800
Subject: [PATCH] [kernel][flash][add] support MT29F8G08ABACAWP

TODO:
not ok
---
 linux-4.1.13/arch/arm/boot/dts/am335x-evm.dts | 26 ++++++++++++------------
 linux-4.1.13/drivers/mtd/nand/omap2.c         | 29 ++++++++++++++++++++-------
 2 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/linux-4.1.13/arch/arm/boot/dts/am335x-evm.dts b/linux-4.1.13/arch/arm/boot/dts/am335x-evm.dts
index fc403c206..b4b560ec8 100644
--- a/linux-4.1.13/arch/arm/boot/dts/am335x-evm.dts
+++ b/linux-4.1.13/arch/arm/boot/dts/am335x-evm.dts
@@ -322,7 +322,7 @@
 		interrupt-parent = <&intc>;
 		interrupts = <100>;
 		ready-gpio = <&gpmc 0 GPIO_ACTIVE_HIGH>; /* gpmc_wait0 */
-		ti,nand-ecc-opt = "bch8";
+		ti,nand-ecc-opt = "bch16";
 		ti,elm-id = <&elm>;
 		nand-bus-width = <8>;
 		gpmc,device-width = <1>;
@@ -353,51 +353,51 @@
 		#size-cells = <1>;
 		partition@0 {
 			label = "NAND.SPL";
-			reg = <0x00000000 0x000020000>;
+			reg = <0x00000000 0x000040000>;
 		};
 		partition@1 {
 			label = "NAND.SPL.backup1";
-			reg = <0x00020000 0x00020000>;
+			reg = <0x00040000 0x00040000>;
 		};
 		partition@2 {
 			label = "NAND.SPL.mode";
-			reg = <0x00040000 0x00020000>;
+			reg = <0x00080000 0x00040000>;
 		};
 		partition@3 {
 			label = "NAND.SPL.secrity";
-			reg = <0x00060000 0x00020000>;
+			reg = <0x000C0000 0x00040000>;
 		};
 		partition@4 {
 			label = "NAND.u-boot-spl-os";
-			reg = <0x00080000 0x00040000>;
+			reg = <0x00100000 0x00040000>;
 		};
 		partition@5 {
 			label = "NAND.u-boot";
-			reg = <0x000C0000 0x00100000>;
+			reg = <0x00140000 0x00100000>;
 		};
 		partition@6 {
 			label = "NAND.u-boot-env";
-			reg = <0x001C0000 0x00020000>;
+			reg = <0x00240000 0x00040000>;
 		};
 		partition@7 {
 			label = "NAND.u-boot-env.backup1";
-			reg = <0x001E0000 0x00020000>;
+			reg = <0x00280000 0x00040000>;
 		};
 		partition@8 {
 			label = "NAND.kernel";
-			reg = <0x00200000 0x00800000>;
+			reg = <0x002C0000 0x00800000>;
 		};
 		partition@9 {
 			label = "NAND.kernel.other";
-			reg = <0x00A00000 0x00800000>;
+			reg = <0x00AC0000 0x00800000>;
 		};
 		partition@10 {
 			label = "NAND.update";
-			reg = <0x01200000 0x00020000>;
+			reg = <0x012C0000 0x00040000>;
 		};
 		partition@11 {
 			label = "NAND.file-system";
-			reg = <0x01220000 0x3EDE0000>;
+			reg = <0x01300000 0x3ED00000>;
 		};
 	};
 };
diff --git a/linux-4.1.13/drivers/mtd/nand/omap2.c b/linux-4.1.13/drivers/mtd/nand/omap2.c
index 60fa89939..6192fde67 100644
--- a/linux-4.1.13/drivers/mtd/nand/omap2.c
+++ b/linux-4.1.13/drivers/mtd/nand/omap2.c
@@ -1950,7 +1950,7 @@ static int omap_nand_probe(struct platform_device *pdev)
 		break;
 
 	case OMAP_ECC_BCH8_CODE_HW:
-		pr_info("nand: using OMAP_ECC_BCH8_CODE_HW ECC scheme\n");
+		pr_info("[johnchain+++]nand: using OMAP_ECC_BCH8_CODE_HW ECC scheme\n");
 		nand_chip->ecc.mode		= NAND_ECC_HW;
 		nand_chip->ecc.size		= 512;
 		/* 14th bit is kept reserved for ROM-code compatibility */
@@ -1981,7 +1981,7 @@ static int omap_nand_probe(struct platform_device *pdev)
 		break;
 
 	case OMAP_ECC_BCH16_CODE_HW:
-		pr_info("using OMAP_ECC_BCH16_CODE_HW ECC scheme\n");
+		pr_info("[johnchain+++]nand: using OMAP_ECC_BCH16_CODE_HW ECC scheme\n");
 		nand_chip->ecc.mode		= NAND_ECC_HW;
 		nand_chip->ecc.size		= 512;
 		nand_chip->ecc.bytes		= 26;
@@ -2002,12 +2002,27 @@ static int omap_nand_probe(struct platform_device *pdev)
 		ecclayout->eccbytes		= nand_chip->ecc.bytes *
 							(mtd->writesize /
 							nand_chip->ecc.size);
-		oob_index			= BADBLOCK_MARKER_LENGTH;
-		for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
-			ecclayout->eccpos[i]	= oob_index;
+
+		for (i = 0; i < ecclayout->eccbytes; i++) {
+			if (nand_chip->options & NAND_BUSWIDTH_16)
+				ecclayout->eccpos[i] = i + 200;
+			else
+				ecclayout->eccpos[i] = i + 200;
+		}
+		ecclayout->oobfree[0].offset = 2;
+		ecclayout->oobfree[0].length = 38;
+
+//		oob_index			= BADBLOCK_MARKER_LENGTH;
+//		for (i = 0; i < ecclayout->eccbytes; i++, oob_index++)
+//			ecclayout->eccpos[i]	= oob_index;
 		/* reserved marker already included in ecclayout->eccbytes */
-		ecclayout->oobfree->offset	=
-				ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
+//		ecclayout->oobfree->offset	=
+//				ecclayout->eccpos[ecclayout->eccbytes - 1] + 1;
+		pr_info("\n[johnchain+++][kernel][debug MT nand]---ecclayout---:eccbytes=%d, offset=%d, length=%d, eccpos[0]=%d\n\n\n\n\n\n",
+				ecclayout->eccbytes,
+				ecclayout->oobfree->offset,
+				ecclayout->oobfree->length,
+				ecclayout->eccpos[0]);
 		break;
 	default:
 		dev_err(&info->pdev->dev, "invalid or unsupported ECC scheme\n");
-- 
2.14.3 (Apple Git-98)

