]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - drivers/mtd/nand/mxs_nand.c
mtd: nand: mxs: Replace magic number for bits per ECC level with macro
[karo-tx-uboot.git] / drivers / mtd / nand / mxs_nand.c
index 47e407ed83b93e9b9d2db3da3466148266abb990..cca29fa1b2b3b1581056e740cddadfc5d6765e10 100644 (file)
@@ -37,7 +37,7 @@
 #define        MXS_NAND_CHUNK_DATA_CHUNK_SIZE_SHIFT    0
 #endif
 #define        MXS_NAND_METADATA_SIZE                  10
-
+#define        MXS_NAND_BITS_PER_ECC_LEVEL             13
 #define        MXS_NAND_COMMAND_BUFFER_SIZE            32
 
 /* BCH timeout in microseconds */
@@ -243,7 +243,7 @@ static uint32_t mxs_nand_ecc_chunk_cnt(struct mtd_info *mtd)
 
 static inline uint32_t mxs_nand_ecc_size_in_bits(uint32_t ecc_strength)
 {
-       return ecc_strength * 13;
+       return ecc_strength * MXS_NAND_BITS_PER_ECC_LEVEL;
 }
 
 static uint32_t mxs_nand_aux_status_offset(void)
@@ -275,26 +275,21 @@ static int mxs_nand_gpmi_init(void)
 static inline uint32_t mxs_nand_get_ecc_strength(uint32_t page_data_size,
                                                uint32_t page_oob_size)
 {
-       if (page_data_size == 2048) {
-               if (page_oob_size == 64)
-                       return 8;
-
-               if (page_oob_size == 112)
-                       return 14;
-       }
-
-       if (page_data_size == 4096) {
-               if (page_oob_size == 128)
-                       return 8;
-
-               if (page_oob_size == 218)
-                       return 16;
+       int ecc_strength;
 
-               if (page_oob_size == 224)
-                       return 16;
-       }
+       /*
+        * Determine the ECC layout with the formula:
+        *      ECC bits per chunk = (total page spare data bits) /
+        *              (bits per ECC level) / (chunks per page)
+        * where:
+        *      total page spare data bits =
+        *              (page oob size - meta data size) * (bits per byte)
+        */
+       ecc_strength = ((page_oob_size - MXS_NAND_METADATA_SIZE) * 8)
+                       / (MXS_NAND_BITS_PER_ECC_LEVEL *
+                               mxs_nand_ecc_chunk_cnt(page_data_size));
 
-       return 0;
+       return round_down(ecc_strength, 2);
 }
 
 static inline uint32_t mxs_nand_get_mark_offset(uint32_t page_data_size,
@@ -659,7 +654,7 @@ static void mxs_nand_write_buf(struct mtd_info *mtd, const uint8_t *buf,
        d->cmd.data =
                MXS_DMA_DESC_COMMAND_DMA_READ | MXS_DMA_DESC_IRQ |
                MXS_DMA_DESC_DEC_SEM | MXS_DMA_DESC_WAIT4END |
-               (4 << MXS_DMA_DESC_PIO_WORDS_OFFSET) |
+               (1 << MXS_DMA_DESC_PIO_WORDS_OFFSET) |
                (length << MXS_DMA_DESC_BYTES_OFFSET);
 
        d->cmd.address = (dma_addr_t)nand_info->data_buf;