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); \
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)
{
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);
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);
}
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.