Re: [PATCH 3/3] NAND: OMAP: Simplifying HWECC and removing unnecessary macros

2009-10-30 Thread Vimal Singh
Looping Linunx-omap mailing list.


From: Vimal Singh vimalsi...@ti.com
Date: Fri, 30 Oct 2009 11:33:34 +0530
Subject: [PATCH] NAND: OMAP: Simplifying HWECC and removing unnecessary macros

Removing number of macros from the top, which were being used
for generating ture ECC earlier. And simplifying the hwecc
correction methode. The idea is taken from:
http://git.denx.de/?p=u-boot/u-boot-arm.git;a=blob;f=drivers/mtd/nand/omap_gpmc.c;h=99b9cef17c29ecf73ef3b844474a5b196f29eeff;hb=4bc3d2afb380e78fdbb9c501d9a8da6d59eb178e

Signed-off-by: Vimal Singh vimalsi...@ti.com
---
 drivers/mtd/nand/omap2.c |  304 +++---
 1 files changed, 100 insertions(+), 204 deletions(-)

diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index ecc4d32..595926b 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -40,73 +40,6 @@
 #defineGPMC_BUF_FULL   0x0001
 #defineGPMC_BUF_EMPTY  0x

-#define NAND_Ecc_P1e   (1  0)
-#define NAND_Ecc_P2e   (1  1)
-#define NAND_Ecc_P4e   (1  2)
-#define NAND_Ecc_P8e   (1  3)
-#define NAND_Ecc_P16e  (1  4)
-#define NAND_Ecc_P32e  (1  5)
-#define NAND_Ecc_P64e  (1  6)
-#define NAND_Ecc_P128e (1  7)
-#define NAND_Ecc_P256e (1  8)
-#define NAND_Ecc_P512e (1  9)
-#define NAND_Ecc_P1024e(1  10)
-#define NAND_Ecc_P2048e(1  11)
-
-#define NAND_Ecc_P1o   (1  16)
-#define NAND_Ecc_P2o   (1  17)
-#define NAND_Ecc_P4o   (1  18)
-#define NAND_Ecc_P8o   (1  19)
-#define NAND_Ecc_P16o  (1  20)
-#define NAND_Ecc_P32o  (1  21)
-#define NAND_Ecc_P64o  (1  22)
-#define NAND_Ecc_P128o (1  23)
-#define NAND_Ecc_P256o (1  24)
-#define NAND_Ecc_P512o (1  25)
-#define NAND_Ecc_P1024o(1  26)
-#define NAND_Ecc_P2048o(1  27)
-
-#define TF(value)  (value ? 1 : 0)
-
-#define P2048e(a)  (TF(a  NAND_Ecc_P2048e) 0)
-#define P2048o(a)  (TF(a  NAND_Ecc_P2048o) 1)
-#define P1e(a) (TF(a  NAND_Ecc_P1e)2)
-#define P1o(a) (TF(a  NAND_Ecc_P1o)3)
-#define P2e(a) (TF(a  NAND_Ecc_P2e)4)
-#define P2o(a) (TF(a  NAND_Ecc_P2o)5)
-#define P4e(a) (TF(a  NAND_Ecc_P4e)6)
-#define P4o(a) (TF(a  NAND_Ecc_P4o)7)
-
-#define P8e(a) (TF(a  NAND_Ecc_P8e)0)
-#define P8o(a) (TF(a  NAND_Ecc_P8o)1)
-#define P16e(a)(TF(a  NAND_Ecc_P16e)   2)
-#define P16o(a)(TF(a  NAND_Ecc_P16o)   3)
-#define P32e(a)(TF(a  NAND_Ecc_P32e)   4)
-#define P32o(a)(TF(a  NAND_Ecc_P32o)   5)
-#define P64e(a)(TF(a  NAND_Ecc_P64e)   6)
-#define P64o(a)(TF(a  NAND_Ecc_P64o)   7)
-
-#define P128e(a)   (TF(a  NAND_Ecc_P128e)  0)
-#define P128o(a)   (TF(a  NAND_Ecc_P128o)  1)
-#define P256e(a)   (TF(a  NAND_Ecc_P256e)  2)
-#define P256o(a)   (TF(a  NAND_Ecc_P256o)  3)
-#define P512e(a)   (TF(a  NAND_Ecc_P512e)  4)
-#define P512o(a)   (TF(a  NAND_Ecc_P512o)  5)
-#define P1024e(a)  (TF(a  NAND_Ecc_P1024e) 6)
-#define P1024o(a)  (TF(a  NAND_Ecc_P1024o) 7)
-
-#define P8e_s(a)   (TF(a  NAND_Ecc_P8e)0)
-#define P8o_s(a)   (TF(a  NAND_Ecc_P8o)1)
-#define P16e_s(a)  (TF(a  NAND_Ecc_P16e)   2)
-#define P16o_s(a)  (TF(a  NAND_Ecc_P16o)   3)
-#define P1e_s(a)   (TF(a  NAND_Ecc_P1e)4)
-#define P1o_s(a)   (TF(a  NAND_Ecc_P1o)5)
-#define P2e_s(a)   (TF(a  NAND_Ecc_P2e)6)
-#define P2o_s(a)   (TF(a  NAND_Ecc_P2o)7)
-
-#define P4e_s(a)   (TF(a  NAND_Ecc_P4e)0)
-#define P4o_s(a)   (TF(a  NAND_Ecc_P4o)1)
-
 #ifdef CONFIG_MTD_PARTITIONS
 static const char *part_probes[] = { cmdlinepart, NULL };
 #endif
@@ -558,161 +491,124 @@ static void omap_hwecc_init(struct mtd_info *mtd)

 /**
  * gen_true_ecc - This function will generate true ECC value
- * @ecc_buf: buffer to store ecc code
+ * @ecc_buf:   buffer to store ecc code
+ * @return:re-formatted ECC value
  *
- * This generated true ECC value can be used when correcting
- * data read from NAND flash memory core
+ * This function will generate true ECC value, which
+ * can be used when correcting data read from NAND flash memory core
  */
-static void gen_true_ecc(u8 *ecc_buf)
+static uint32_t gen_true_ecc(uint8_t *ecc_buf)
 {
-   u32 tmp = ecc_buf[0] | (ecc_buf[1]  16) |
-   ((ecc_buf[2]  0xF0)  20) | ((ecc_buf[2]  0x0F)  8);
-
-   ecc_buf[0] = ~(P64o(tmp) | P64e(tmp) | P32o(tmp) | P32e(tmp) |
-   P16o(tmp) | P16e(tmp) | P8o(tmp) | 

Re: [PATCH 3/3] NAND: OMAP: Simplifying HWECC and removing unnecessary macros

2009-10-30 Thread Vimal Singh
I removed function description comments for 'omap_correct_data' by
mistake last time. Correcting that. Updated patch is below.

Sorry for noise.

-vimal

From: Vimal Singh vimalsi...@ti.com
Date: Fri, 30 Oct 2009 17:41:55 +0530
Subject: [PATCH] NAND: OMAP: Simplifying HWECC and removing unnecessary macros

Removing number of macros from the top, which were being used
for generating ture ECC earlier. And simplifying the hwecc
correction methode. The idea is taken from:
http://git.denx.de/?p=u-boot/u-boot-arm.git;a=blob;f=drivers/mtd/nand/omap_gpmc.c;h=99b9cef17c29ecf73ef3b844474a5b196f29eeff;hb=4bc3d2afb380e78fdbb9c501d9a8da6d59eb178e

Signed-off-by: Vimal Singh vimalsi...@ti.com
---
 drivers/mtd/nand/omap2.c |  293 --
 1 files changed, 100 insertions(+), 193 deletions(-)

diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index ecc4d32..a586dcf 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -40,73 +40,6 @@
 #defineGPMC_BUF_FULL   0x0001
 #defineGPMC_BUF_EMPTY  0x

-#define NAND_Ecc_P1e   (1  0)
-#define NAND_Ecc_P2e   (1  1)
-#define NAND_Ecc_P4e   (1  2)
-#define NAND_Ecc_P8e   (1  3)
-#define NAND_Ecc_P16e  (1  4)
-#define NAND_Ecc_P32e  (1  5)
-#define NAND_Ecc_P64e  (1  6)
-#define NAND_Ecc_P128e (1  7)
-#define NAND_Ecc_P256e (1  8)
-#define NAND_Ecc_P512e (1  9)
-#define NAND_Ecc_P1024e(1  10)
-#define NAND_Ecc_P2048e(1  11)
-
-#define NAND_Ecc_P1o   (1  16)
-#define NAND_Ecc_P2o   (1  17)
-#define NAND_Ecc_P4o   (1  18)
-#define NAND_Ecc_P8o   (1  19)
-#define NAND_Ecc_P16o  (1  20)
-#define NAND_Ecc_P32o  (1  21)
-#define NAND_Ecc_P64o  (1  22)
-#define NAND_Ecc_P128o (1  23)
-#define NAND_Ecc_P256o (1  24)
-#define NAND_Ecc_P512o (1  25)
-#define NAND_Ecc_P1024o(1  26)
-#define NAND_Ecc_P2048o(1  27)
-
-#define TF(value)  (value ? 1 : 0)
-
-#define P2048e(a)  (TF(a  NAND_Ecc_P2048e) 0)
-#define P2048o(a)  (TF(a  NAND_Ecc_P2048o) 1)
-#define P1e(a) (TF(a  NAND_Ecc_P1e)2)
-#define P1o(a) (TF(a  NAND_Ecc_P1o)3)
-#define P2e(a) (TF(a  NAND_Ecc_P2e)4)
-#define P2o(a) (TF(a  NAND_Ecc_P2o)5)
-#define P4e(a) (TF(a  NAND_Ecc_P4e)6)
-#define P4o(a) (TF(a  NAND_Ecc_P4o)7)
-
-#define P8e(a) (TF(a  NAND_Ecc_P8e)0)
-#define P8o(a) (TF(a  NAND_Ecc_P8o)1)
-#define P16e(a)(TF(a  NAND_Ecc_P16e)   2)
-#define P16o(a)(TF(a  NAND_Ecc_P16o)   3)
-#define P32e(a)(TF(a  NAND_Ecc_P32e)   4)
-#define P32o(a)(TF(a  NAND_Ecc_P32o)   5)
-#define P64e(a)(TF(a  NAND_Ecc_P64e)   6)
-#define P64o(a)(TF(a  NAND_Ecc_P64o)   7)
-
-#define P128e(a)   (TF(a  NAND_Ecc_P128e)  0)
-#define P128o(a)   (TF(a  NAND_Ecc_P128o)  1)
-#define P256e(a)   (TF(a  NAND_Ecc_P256e)  2)
-#define P256o(a)   (TF(a  NAND_Ecc_P256o)  3)
-#define P512e(a)   (TF(a  NAND_Ecc_P512e)  4)
-#define P512o(a)   (TF(a  NAND_Ecc_P512o)  5)
-#define P1024e(a)  (TF(a  NAND_Ecc_P1024e) 6)
-#define P1024o(a)  (TF(a  NAND_Ecc_P1024o) 7)
-
-#define P8e_s(a)   (TF(a  NAND_Ecc_P8e)0)
-#define P8o_s(a)   (TF(a  NAND_Ecc_P8o)1)
-#define P16e_s(a)  (TF(a  NAND_Ecc_P16e)   2)
-#define P16o_s(a)  (TF(a  NAND_Ecc_P16o)   3)
-#define P1e_s(a)   (TF(a  NAND_Ecc_P1e)4)
-#define P1o_s(a)   (TF(a  NAND_Ecc_P1o)5)
-#define P2e_s(a)   (TF(a  NAND_Ecc_P2e)6)
-#define P2o_s(a)   (TF(a  NAND_Ecc_P2o)7)
-
-#define P4e_s(a)   (TF(a  NAND_Ecc_P4e)0)
-#define P4o_s(a)   (TF(a  NAND_Ecc_P4o)1)
-
 #ifdef CONFIG_MTD_PARTITIONS
 static const char *part_probes[] = { cmdlinepart, NULL };
 #endif
@@ -558,148 +491,122 @@ static void omap_hwecc_init(struct mtd_info *mtd)

 /**
  * gen_true_ecc - This function will generate true ECC value
- * @ecc_buf: buffer to store ecc code
+ * @ecc_buf:   buffer to store ecc code
+ * @return:re-formatted ECC value
  *
- * This generated true ECC value can be used when correcting
- * data read from NAND flash memory core
+ * This function will generate true ECC value, which
+ * can be used when correcting data read from NAND flash memory core
  */
-static void gen_true_ecc(u8 *ecc_buf)
+static uint32_t gen_true_ecc(uint8_t *ecc_buf)
 {
-   u32 tmp = ecc_buf[0] | (ecc_buf[1]  16) |
-   ((ecc_buf[2]  0xF0)  20) | ((ecc_buf[2]  0x0F)  8);
-
-