Index: bootloader/telechips.c =================================================================== --- bootloader/telechips.c (revision 17727) +++ bootloader/telechips.c (working copy) @@ -55,6 +55,85 @@ /* The following function is just test/development code */ #ifdef CPU_TCC77X + +/* TCC77x NAND Flash Controller */ + +#define DEV_NAND (1<<16) + +#define NFC_CMD (*(volatile unsigned long *)0x90000000) +#define NFC_SADDR (*(volatile unsigned long *)0x9000000C) +#define NFC_SDATA (*(volatile unsigned long *)0x90000040) +#define NFC_WDATA (*(volatile unsigned long *)0x90000010) +#define NFC_CTRL (*(volatile unsigned long *)0x90000050) + #define NFC_16BIT (1<<26) + #define NFC_CS0 (1<<23) + #define NFC_CS1 (1<<22) + #define NFC_READY (1<<20) +#define NFC_IREQ (*(volatile unsigned long *)0x90000060) +#define NFC_RST (*(volatile unsigned long *)0x90000064) + +/* NAND physical access functions */ + +static void nand_chip_select(int bank) +{ + if (bank == -1) + { + NFC_CTRL |= NFC_CS0 | NFC_CS1; + } + else + { + /* NFC chip select */ + if (bank & 1) + { + NFC_CTRL &= ~NFC_CS0; + NFC_CTRL |= NFC_CS1; + } + else + { + NFC_CTRL |= NFC_CS0; + NFC_CTRL &= ~NFC_CS1; + } + } +} + + +static void nand_read_id(int bank, unsigned char* id_buf) +{ + int i; + + /* Enable NFC bus clock */ + BCLKCTR |= DEV_NAND; + + /* Reset NAND controller */ + NFC_RST = 0; + + /* Set slow cycle timings since the chip is as yet unidentified */ + NFC_CTRL = (NFC_CTRL &~0xFFF) | 0x353; + + nand_chip_select(bank); + + /* Reset command */ + NFC_CMD = 0xFF; + + /* Set 8-bit data width */ + NFC_CTRL &= ~NFC_16BIT; + + /* Read ID command, single address cycle */ + NFC_CMD = 0x90; + NFC_SADDR = 0x00; + + /* Read the 5 chip ID bytes */ + for (i = 0; i < 5; i++) + { + id_buf[i] = NFC_SDATA & 0xFF; + } + + nand_chip_select(-1); + + /* Disable NFC bus clock */ + BCLKCTR &= ~DEV_NAND; +} + void show_debug_screen(void) { int button; @@ -62,6 +141,11 @@ int count = 0; bool do_power_off = false; + unsigned char id_buf[8]; + + /* Read chip id from bank 0 */ + nand_read_id(0, id_buf); + lcd_puts_scroll(0,0,"this is a very long line to test scrolling"); while(!do_power_off) { line = 1; @@ -78,6 +162,9 @@ power_count = 0; } + printf("NAND: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x", + id_buf[0],id_buf[1],id_buf[2],id_buf[3],id_buf[4]); + printf("Btn: 0x%08x",button); printf("Tick: %d",current_tick);