]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - packages/devs/flash/arm/mxc/v2_0/include/mxc_nfc_v3.h
TX51/TX53 Release 2011-08-19
[karo-tx-redboot.git] / packages / devs / flash / arm / mxc / v2_0 / include / mxc_nfc_v3.h
index 89b31ffd70139627400d173a74c7ea84da856e2b..347e813330504550e995a75c66d8f5c157e3118f 100644 (file)
@@ -109,17 +109,19 @@ enum nfc_output_mode {
        CYG_MACRO_START                                                                                                         \
        int loops = MAX_LOOPS;                                                                                          \
        static int max_loops = MAX_LOOPS;                                                                       \
+                                                                                                                                               \
        while ((nfc_reg_read(NFC_IPC_REG) & NFC_IPC_AUTO_DONE) == 0) {          \
                HAL_DELAY_US(10);                                                                                               \
                if (loops-- < 0) {                                                                                              \
-                       diag_printf("%s: Timeout waiting for prog done\n", __FUNCTION__); \
+                       diag_printf("%s: Timeout waiting for prog done\n",                      \
+                                               __func__);                                                                              \
                        break;                                                                                                          \
                }                                                                                                                               \
        }                                                                                                                                       \
-       if (loops < max_loops) {                                                                                        \
+       if (MAX_LOOPS - loops < max_loops) {                                                            \
                diag_printf1("%s: auto_prog done after %u loops\n",                             \
                                        __FUNCTION__, MAX_LOOPS - loops);                                       \
-               max_loops = loops;                                                                                              \
+               max_loops = MAX_LOOPS - loops;                                                                  \
        }                                                                                                                                       \
        nfc_reg_write((nfc_reg_read(NFC_IPC_REG) & ~NFC_IPC_AUTO_DONE),         \
                                NFC_IPC_REG);                                                                                   \
@@ -130,23 +132,49 @@ enum nfc_output_mode {
        CYG_MACRO_START                                                                                                         \
        int loops = MAX_LOOPS;                                                                                          \
        static int max_loops = MAX_LOOPS;                                                                       \
+                                                                                                                                               \
        while ((nfc_reg_read(NFC_IPC_REG) & NFC_IPC_INT) == 0) {                        \
                HAL_DELAY_US(10);                                                                                               \
                if (loops-- < 0) {                                                                                              \
-                       diag_printf("%s: Timeout waiting for NFC ready\n", __FUNCTION__); \
+                       diag_printf("%s: Timeout waiting for NFC ready\n",                      \
+                                               __func__);                                                                              \
                        break;                                                                                                          \
                }                                                                                                                               \
        }                                                                                                                                       \
-       if (loops < max_loops) {                                                                                        \
+       if (MAX_LOOPS - loops < max_loops) {                                                            \
                diag_printf1("%s: NFC ready after %u loops\n",                                  \
                                        __FUNCTION__, MAX_LOOPS - loops);                                       \
-               max_loops = loops;                                                                                              \
+               max_loops = MAX_LOOPS - loops;                                                                  \
        }                                                                                                                                       \
        nfc_reg_write(0, NFC_IPC_REG);                                                                          \
        CYG_MACRO_END
 
+#if 0
 #define nfc_reg_read(r)                        readl(r)
 #define nfc_reg_write(v, r)            writel(v, r)
+#else
+#define nfc_reg_read(r)                        __nfc_reg_read(r, #r, __func__, __LINE__)
+#define nfc_reg_write(v, r)            __nfc_reg_write(v, r, #r, __func__, __LINE__)
+
+static inline u32 __nfc_reg_read(unsigned long reg, const char *reg_name,
+                                                               const char *fn, int ln)
+{
+       u32 val;
+
+       val = readl(reg);
+       if (g_nfc_debug_level >= NFC_DEBUG_MAX)
+               diag_printf("%s@%d: Read %08x from %s[%08lx]\n", fn, ln, val, reg_name, reg);
+       return val;
+}
+
+static inline void __nfc_reg_write(u32 val, unsigned long reg,
+                                                               const char *reg_name, const char *fn, int ln)
+{
+       if (g_nfc_debug_level >= NFC_DEBUG_MAX)
+               diag_printf("%s@%d: Writing %08x to %s[%08lx]\n", fn, ln, val, reg_name, reg);
+       writel(val, reg);
+}
+#endif
 
 static void write_nfc_ip_reg(u32 val, u32 reg)
 {
@@ -167,10 +195,10 @@ static void write_nfc_ip_reg(u32 val, u32 reg)
                        return;
                }
        }
-       if (loops < max_loops) {
-               diag_printf("%s: NFC ready after %u loops\n",
+       if (MAX_LOOPS - loops < max_loops) {
+               diag_printf1("%s: NFC ready after %u loops\n",
                                        __FUNCTION__, MAX_LOOPS - loops);
-               max_loops = loops;
+               max_loops = MAX_LOOPS - loops;
        }
        nfc_reg_write(val, reg);
        nfc_reg_write((nfc_reg_read(NFC_IPC_REG) & ~NFC_IPC_CREQ), NFC_IPC_REG);
@@ -225,7 +253,6 @@ static void NFC_SET_NFC_ACTIVE_CS(u32 cs_line)
        nfc_reg_write(v, NAND_CONFIGURATION1_REG);
 }
 
-#ifdef IMX51_TO_2
 static inline u16 NFC_STATUS_READ(void)
 {
        u16 val = nfc_reg_read(NAND_STATUS_SUM_REG);
@@ -235,28 +262,6 @@ static inline u16 NFC_STATUS_READ(void)
        }
        return val;
 }
-#else
-static inline u16 NFC_STATUS_READ(void)
-{
-       u32 status;
-       int i;
-       u16 status_sum = 0;
-
-       /* Cannot rely on STATUS_SUM register due to errata */
-       for (i = 0; i < num_of_nand_chips; i++) {
-               NFC_SET_NFC_ACTIVE_CS(i);
-               do {
-                       nfc_reg_write(NAND_LAUNCH_AUTO_STAT, NAND_LAUNCH_REG);
-                       status = (nfc_reg_read(NAND_CONFIGURATION1_REG) & 0x00FF0000) >> 16;
-               } while ((status & 0x40) == 0); // make sure I/O 6 == 1
-               /* Get Pass/Fail status */
-               status = (nfc_reg_read(NAND_CONFIGURATION1_REG) >> 16) & 0x1;
-               status_sum |= (status << i);
-       }
-       diag_printf("NFC TO2 STATUS: %04x\n", status_sum);
-       return status_sum;
-}
-#endif
 
 /* This function uses a global variable for the page size. It shouldn't be a big
  * problem since we don't expect mixed page size nand flash parts on the same IC.