Index: bootloader/telechips.c =================================================================== --- bootloader/telechips.c (revision 17990) +++ bootloader/telechips.c (working copy) @@ -57,19 +57,110 @@ /* 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; + + /* From the Sansa C100 firmware */ + CSCFG2 = 0x318a8010; + + GPIOC_DIR |= 0x2000000; /* output mode */ + GPIOC_FUNC &= ~0x2000000; /* normal IO port */ + GPIOC_FUNC |= 0x1; + + /* 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; int power_count = 0; 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; button = button_get(false); - + /* Power-off if POWER button has been held for a time This loop is currently running at about 100 iterations/second */ @@ -80,14 +171,16 @@ } else { power_count = 0; } - + if (button & BUTTON_SELECT){ - _backlight_off(); + _backlight_off(); } else{ _backlight_on(); } - + printf("NAND: 0x%02x 0x%02x",id_buf[0],id_buf[1]); + printf("0x%02x 0x%02x 0x%02x",id_buf[2],id_buf[3],id_buf[4]); + /*printf("Btn: 0x%08x",button); printf("Tick: %d",current_tick); printf("GPIOA: 0x%08x",GPIOA); @@ -118,7 +211,7 @@ printf("(NOT) POWERED OFF"); while (true); - + } #else /* !CPU_TCC77X */ void show_debug_screen(void)