summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2009-01-22 00:04:20 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2009-01-22 00:04:20 +0000
commit311d2f12ed024cf11971f23231e05a0143361115 (patch)
tree3537e656cbb1a1e6bbba3a8431a34059cc8398b1
parente79fc8aaef541b48a84a23e6771e3ec5a2efe5ac (diff)
downloadrockbox-311d2f12ed024cf11971f23231e05a0143361115.tar.gz
rockbox-311d2f12ed024cf11971f23231e05a0143361115.zip
Onda VX747: get NAND driver working
generic NAND ID driver: clean up git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19817 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/drivers/nand_id.c32
-rw-r--r--firmware/export/jz4740.h10
-rw-r--r--firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c78
3 files changed, 66 insertions, 54 deletions
diff --git a/firmware/drivers/nand_id.c b/firmware/drivers/nand_id.c
index 4dc1ec1ceb..dfb96c8820 100644
--- a/firmware/drivers/nand_id.c
+++ b/firmware/drivers/nand_id.c
@@ -24,35 +24,38 @@
24 24
25struct nand_manufacturer 25struct nand_manufacturer
26{ 26{
27 unsigned char id; 27 unsigned char id;
28 struct nand_info* info; 28 struct nand_info* info;
29 unsigned short total; 29 unsigned short total;
30}; 30};
31 31
32/* { pages_per_block, blocks_per_bank, page_size, spare_size, col_cycles, row_cycles } */
33
34static const struct nand_info samsung[] = 32static const struct nand_info samsung[] =
35{ 33{
36 /* K9F4G08UOM */ 34/* { id1, id2, pages_per_block, blocks_per_bank, page_size, spare_size, col_cycles, row_cycles } */
37 {0xDC, 0x10, 64, 4096, 2048, 64, 2, 3}, 35
38 /* K9K8G08UOM */ 36 /* K9F4G08UOM */
39 {0xD3, 0x51, 64, 8192, 2048, 64, 2, 3}, 37 {0xDC, 0x10, 64, 4096, 2048, 64, 2, 3 },
40 /* K9LAG08UOM */ 38 /* K9K8G08UOM */
41 {0xD5, 0x55, 128, 8192, 2048, 64, 2, 3}, 39 {0xD3, 0x51, 64, 8192, 2048, 64, 2, 3 },
42 /* K9LBG08UOM, K9HBG08U1M, K9MCG08U5M */ 40 /* K9LAG08UOM */
43 {0xD7, 0x55, 128, 8192, 4096, 128, 2, 3} 41 {0xD5, 0x55, 128, 8192, 2048, 64, 2, 3 },
42 /* K9LBG08UOM, K9HBG08U1M, K9MCG08U5M */
43 {0xD7, 0x55, 128, 8192, 4096, 128, 2, 3 },
44}; 44};
45 45
46#define M(id, x) {id, (struct nand_info*)x, (sizeof(x)/sizeof(struct nand_info))} 46#define NI(id, x) {id, (struct nand_info*)x, (sizeof(x)/sizeof(struct nand_info))}
47static const struct nand_manufacturer all[] = 47static const struct nand_manufacturer all[] =
48{ 48{
49 M(0xEC, samsung), 49 NI(0xEC, samsung),
50}; 50};
51 51
52// --------------------------------------------------------------------------------------------------
53
52struct nand_info* nand_identify(unsigned char data[5]) 54struct nand_info* nand_identify(unsigned char data[5])
53 { 55 {
54 unsigned int i; 56 unsigned int i;
55 int found = -1; 57 int found = -1;
58
56 for(i = 0; i < (sizeof(all)/sizeof(struct nand_manufacturer)); i++) 59 for(i = 0; i < (sizeof(all)/sizeof(struct nand_manufacturer)); i++)
57 { 60 {
58 if(data[0] == all[i].id) 61 if(data[0] == all[i].id)
@@ -61,6 +64,7 @@ struct nand_info* nand_identify(unsigned char data[5])
61 break; 64 break;
62 } 65 }
63 } 66 }
67
64 if(found < 0) 68 if(found < 0)
65 return NULL; 69 return NULL;
66 70
diff --git a/firmware/export/jz4740.h b/firmware/export/jz4740.h
index aa31a229f9..7910fbec92 100644
--- a/firmware/export/jz4740.h
+++ b/firmware/export/jz4740.h
@@ -1762,14 +1762,16 @@
1762#define EMC_SACR_MASK_MASK (0xff << EMC_SACR_MASK_BIT) 1762#define EMC_SACR_MASK_MASK (0xff << EMC_SACR_MASK_BIT)
1763 1763
1764/* NAND Flash Control/Status Register */ 1764/* NAND Flash Control/Status Register */
1765#define EMC_NFCSR_NFCE4 (1 << 7) /* NAND Flash Enable */ 1765#define EMC_NFCSR_NFCE4 (1 << 7) /* NAND Flash Enable */
1766#define EMC_NFCSR_NFE4 (1 << 6) /* NAND Flash FCE# Assertion Enable */ 1766#define EMC_NFCSR_NFE4 (1 << 6) /* NAND Flash FCE# Assertion Enable */
1767#define EMC_NFCSR_NFCE3 (1 << 5) 1767#define EMC_NFCSR_NFCE3 (1 << 5)
1768#define EMC_NFCSR_NFE3 (1 << 4) 1768#define EMC_NFCSR_NFE3 (1 << 4)
1769#define EMC_NFCSR_NFCE2 (1 << 3) 1769#define EMC_NFCSR_NFCE2 (1 << 3)
1770#define EMC_NFCSR_NFE2 (1 << 2) 1770#define EMC_NFCSR_NFE2 (1 << 2)
1771#define EMC_NFCSR_NFCE1 (1 << 1) 1771#define EMC_NFCSR_NFCE1 (1 << 1)
1772#define EMC_NFCSR_NFE1 (1 << 0) 1772#define EMC_NFCSR_NFE1 (1 << 0)
1773#define EMC_NFCSR_NFE(n) (1 << (((n)-1)*2))
1774#define EMC_NFCSR_NFCE(n) (1 << (((n)*2)-1))
1773 1775
1774/* NAND Flash ECC Control Register */ 1776/* NAND Flash ECC Control Register */
1775#define EMC_NFECR_PRDY (1 << 4) /* Parity Ready */ 1777#define EMC_NFECR_PRDY (1 << 4) /* Parity Ready */
diff --git a/firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c b/firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c
index 8c4ad40f72..851472bf62 100644
--- a/firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c
+++ b/firmware/target/mips/ingenic_jz47xx/ata-nand-jz4740.c
@@ -30,8 +30,10 @@
30#include "storage.h" 30#include "storage.h"
31#include "buffer.h" 31#include "buffer.h"
32#include "string.h" 32#include "string.h"
33#include "logf.h"
33 34
34//#define USE_DMA 35//#define USE_DMA
36//#define USE_ECC
35 37
36/* 38/*
37 * Standard NAND flash commands 39 * Standard NAND flash commands
@@ -51,9 +53,9 @@
51#define NAND_CMD_RESET 0xff 53#define NAND_CMD_RESET 0xff
52 54
53/* Extended commands for large page devices */ 55/* Extended commands for large page devices */
54#define NAND_CMD_READSTART 0x30 56#define NAND_CMD_READSTART 0x30
55#define NAND_CMD_RNDOUTSTART 0xE0 57#define NAND_CMD_RNDOUTSTART 0xE0
56#define NAND_CMD_CACHEDPROG 0x15 58#define NAND_CMD_CACHEDPROG 0x15
57 59
58/* Status bits */ 60/* Status bits */
59#define NAND_STATUS_FAIL 0x01 61#define NAND_STATUS_FAIL 0x01
@@ -69,8 +71,8 @@ struct nand_param
69{ 71{
70 unsigned int bus_width; /* data bus width: 8-bit/16-bit */ 72 unsigned int bus_width; /* data bus width: 8-bit/16-bit */
71 unsigned int row_cycle; /* row address cycles: 2/3 */ 73 unsigned int row_cycle; /* row address cycles: 2/3 */
72 unsigned int page_size; /* page size in bytes: 512/2048 */ 74 unsigned int page_size; /* page size in bytes: 512/2048/4096 */
73 unsigned int oob_size; /* oob size in bytes: 16/64 */ 75 unsigned int oob_size; /* oob size in bytes: 16/64/128 */
74 unsigned int page_per_block; /* pages per block: 32/64/128 */ 76 unsigned int page_per_block; /* pages per block: 32/64/128 */
75}; 77};
76 78
@@ -83,9 +85,9 @@ struct nand_param
83 * 85 *
84 */ 86 */
85 87
86#define NAND_DATAPORT 0xb8000000 88#define NAND_DATAPORT 0xB8000000
87#define NAND_ADDRPORT 0xb8010000 89#define NAND_ADDRPORT 0xB8010000
88#define NAND_COMMPORT 0xb8008000 90#define NAND_COMMPORT 0xB8008000
89 91
90#define ECC_BLOCK 512 92#define ECC_BLOCK 512
91#define ECC_POS 6 93#define ECC_POS 6
@@ -93,8 +95,8 @@ struct nand_param
93 95
94#define __nand_cmd(n) (REG8(NAND_COMMPORT) = (n)) 96#define __nand_cmd(n) (REG8(NAND_COMMPORT) = (n))
95#define __nand_addr(n) (REG8(NAND_ADDRPORT) = (n)) 97#define __nand_addr(n) (REG8(NAND_ADDRPORT) = (n))
96#define __nand_data8() REG8(NAND_DATAPORT) 98#define __nand_data8() (REG8(NAND_DATAPORT))
97#define __nand_data16() REG16(NAND_DATAPORT) 99#define __nand_data16() (REG16(NAND_DATAPORT))
98 100
99#define __nand_enable() (REG_EMC_NFCSR |= EMC_NFCSR_NFE1 | EMC_NFCSR_NFCE1) 101#define __nand_enable() (REG_EMC_NFCSR |= EMC_NFCSR_NFE1 | EMC_NFCSR_NFCE1)
100#define __nand_disable() (REG_EMC_NFCSR &= ~(EMC_NFCSR_NFCE1)) 102#define __nand_disable() (REG_EMC_NFCSR &= ~(EMC_NFCSR_NFCE1))
@@ -118,17 +120,16 @@ static unsigned char temp_page[4096]; /* Max page size */
118 120
119static inline void jz_nand_wait_ready(void) 121static inline void jz_nand_wait_ready(void)
120{ 122{
121 unsigned int timeout = 1000; 123 register unsigned int timeout = 1000;
122 while ((REG_GPIO_PXPIN(2) & 0x40000000) && timeout--); 124 while ((REG_GPIO_PXPIN(2) & 0x40000000) && timeout--);
123 while (!(REG_GPIO_PXPIN(2) & 0x40000000)); 125 while (!(REG_GPIO_PXPIN(2) & 0x40000000));
124} 126}
125 127
126#ifndef USE_DMA 128#ifndef USE_DMA
127
128static inline void jz_nand_read_buf16(void *buf, int count) 129static inline void jz_nand_read_buf16(void *buf, int count)
129{ 130{
130 int i; 131 register int i;
131 unsigned short *p = (unsigned short *)buf; 132 register unsigned short *p = (unsigned short *)buf;
132 133
133 for (i = 0; i < count; i += 2) 134 for (i = 0; i < count; i += 2)
134 *p++ = __nand_data16(); 135 *p++ = __nand_data16();
@@ -136,15 +137,13 @@ static inline void jz_nand_read_buf16(void *buf, int count)
136 137
137static inline void jz_nand_read_buf8(void *buf, int count) 138static inline void jz_nand_read_buf8(void *buf, int count)
138{ 139{
139 int i; 140 register int i;
140 unsigned char *p = (unsigned char *)buf; 141 register unsigned char *p = (unsigned char *)buf;
141 142
142 for (i = 0; i < count; i++) 143 for (i = 0; i < count; i++)
143 *p++ = __nand_data8(); 144 *p++ = __nand_data8();
144} 145}
145
146#else 146#else
147
148static void jz_nand_write_dma(void *source, unsigned int len, int bw) 147static void jz_nand_write_dma(void *source, unsigned int len, int bw)
149{ 148{
150 mutex_lock(&nand_mtx); 149 mutex_lock(&nand_mtx);
@@ -226,8 +225,7 @@ void DMA_CALLBACK(DMA_NAND_CHANNEL)(void)
226 225
227 wakeup_signal(&nand_wkup); 226 wakeup_signal(&nand_wkup);
228} 227}
229 228#endif /* USE_DMA */
230#endif
231 229
232static inline void jz_nand_read_buf(void *buf, int count, int bw) 230static inline void jz_nand_read_buf(void *buf, int count, int bw)
233{ 231{
@@ -244,6 +242,7 @@ static inline void jz_nand_read_buf(void *buf, int count, int bw)
244#endif 242#endif
245} 243}
246 244
245#ifdef USE_ECC
247/* 246/*
248 * Correct 1~9-bit errors in 512-bytes data 247 * Correct 1~9-bit errors in 512-bytes data
249 */ 248 */
@@ -258,7 +257,8 @@ static void jz_rs_correct(unsigned char *dat, int idx, int mask)
258 i = (j == 0) ? (i - 1) : i; 257 i = (j == 0) ? (i - 1) : i;
259 j = (j == 0) ? 7 : (j - 1); 258 j = (j == 0) ? 7 : (j - 1);
260 259
261 if (i > 512) return; 260 if (i > 512)
261 return;
262 262
263 if (i == 512) 263 if (i == 512)
264 d = dat[i - 1]; 264 d = dat[i - 1];
@@ -275,11 +275,12 @@ static void jz_rs_correct(unsigned char *dat, int idx, int mask)
275 if (i < 512) 275 if (i < 512)
276 dat[i] = (d >> 8) & 0xff; 276 dat[i] = (d >> 8) & 0xff;
277} 277}
278#endif
278 279
279/* 280/*
280 * Read oob 281 * Read oob
281 */ 282 */
282static int jz_nand_read_oob(int page_addr, unsigned char *buf, int size) 283static int jz_nand_read_oob(unsigned long page_addr, unsigned char *buf, int size)
283{ 284{
284 struct nand_param *nandp = &internal_param; 285 struct nand_param *nandp = &internal_param;
285 int page_size, row_cycle, bus_width; 286 int page_size, row_cycle, bus_width;
@@ -335,14 +336,14 @@ static int jz_nand_read_oob(int page_addr, unsigned char *buf, int size)
335 * page - page number within a block: 0, 1, 2, ... 336 * page - page number within a block: 0, 1, 2, ...
336 * dst - pointer to target buffer 337 * dst - pointer to target buffer
337 */ 338 */
338static int jz_nand_read_page(int block, int page, unsigned char *dst) 339static int jz_nand_read_page(unsigned long page_addr, unsigned char *dst)
339{ 340{
340 struct nand_param *nandp = &internal_param; 341 struct nand_param *nandp = &internal_param;
341 int page_size, oob_size, page_per_block; 342 int page_size, oob_size, page_per_block;
342 int row_cycle, bus_width, ecc_count; 343 int row_cycle, bus_width, ecc_count;
343 int page_addr, i, j; 344 int i, j;
344 unsigned char *data_buf; 345 unsigned char *data_buf;
345 unsigned char oob_buf[128]; 346 unsigned char oob_buf[nandp->oob_size];
346 347
347 page_size = nandp->page_size; 348 page_size = nandp->page_size;
348 oob_size = nandp->oob_size; 349 oob_size = nandp->oob_size;
@@ -350,8 +351,6 @@ static int jz_nand_read_page(int block, int page, unsigned char *dst)
350 row_cycle = nandp->row_cycle; 351 row_cycle = nandp->row_cycle;
351 bus_width = nandp->bus_width; 352 bus_width = nandp->bus_width;
352 353
353 page_addr = page + block * page_per_block;
354
355 /* 354 /*
356 * Read oob data 355 * Read oob data
357 */ 356 */
@@ -372,7 +371,7 @@ static int jz_nand_read_page(int block, int page, unsigned char *dst)
372 /* Send page address */ 371 /* Send page address */
373 __nand_addr(page_addr & 0xff); 372 __nand_addr(page_addr & 0xff);
374 __nand_addr((page_addr >> 8) & 0xff); 373 __nand_addr((page_addr >> 8) & 0xff);
375 if (row_cycle == 3) 374 if (row_cycle >= 3)
376 __nand_addr((page_addr >> 16) & 0xff); 375 __nand_addr((page_addr >> 16) & 0xff);
377 376
378 /* Send READSTART command for 2048 ps NAND */ 377 /* Send READSTART command for 2048 ps NAND */
@@ -389,16 +388,19 @@ static int jz_nand_read_page(int block, int page, unsigned char *dst)
389 388
390 for (i = 0; i < ecc_count; i++) 389 for (i = 0; i < ecc_count; i++)
391 { 390 {
391#ifdef USE_ECC
392 volatile unsigned char *paraddr = (volatile unsigned char *)EMC_NFPAR0; 392 volatile unsigned char *paraddr = (volatile unsigned char *)EMC_NFPAR0;
393 unsigned int stat; 393 unsigned int stat;
394 394
395 /* Enable RS decoding */ 395 /* Enable RS decoding */
396 REG_EMC_NFINTS = 0x0; 396 REG_EMC_NFINTS = 0x0;
397 __nand_ecc_rs_decoding(); 397 __nand_ecc_rs_decoding();
398#endif
398 399
399 /* Read data */ 400 /* Read data */
400 jz_nand_read_buf((void *)data_buf, ECC_BLOCK, bus_width); 401 jz_nand_read_buf((void *)data_buf, ECC_BLOCK, bus_width);
401 402
403#ifdef USE_ECC
402 /* Set PAR values */ 404 /* Set PAR values */
403 for (j = 0; j < PAR_SIZE; j++) 405 for (j = 0; j < PAR_SIZE; j++)
404 *paraddr++ = oob_buf[ECC_POS + i*PAR_SIZE + j]; 406 *paraddr++ = oob_buf[ECC_POS + i*PAR_SIZE + j];
@@ -420,7 +422,7 @@ static int jz_nand_read_page(int block, int page, unsigned char *dst)
420 if (stat & EMC_NFINTS_UNCOR) 422 if (stat & EMC_NFINTS_UNCOR)
421 { 423 {
422 /* Uncorrectable error occurred */ 424 /* Uncorrectable error occurred */
423 panicf("Uncorrectable ECC error at NAND page 0x%x block 0x%x", page, block); 425 panicf("Uncorrectable ECC error at NAND page address 0x%lx", page_addr);
424 return -1; 426 return -1;
425 } 427 }
426 else 428 else
@@ -452,6 +454,7 @@ static int jz_nand_read_page(int block, int page, unsigned char *dst)
452 } 454 }
453 } 455 }
454 } 456 }
457#endif
455 458
456 data_buf += ECC_BLOCK; 459 data_buf += ECC_BLOCK;
457 } 460 }
@@ -502,7 +505,7 @@ static int jz_nand_init(void)
502 internal_param.bus_width = 8; 505 internal_param.bus_width = 8;
503 internal_param.row_cycle = chip_info->row_cycles; 506 internal_param.row_cycle = chip_info->row_cycles;
504 internal_param.page_size = chip_info->page_size; 507 internal_param.page_size = chip_info->page_size;
505 internal_param.oob_size = chip_info->page_size/32; 508 internal_param.oob_size = chip_info->spare_size;
506 internal_param.page_per_block = chip_info->pages_per_block; 509 internal_param.page_per_block = chip_info->pages_per_block;
507 510
508 return 0; 511 return 0;
@@ -532,21 +535,24 @@ int nand_read_sectors(IF_MV2(int drive,) unsigned long start, int count, void* b
532{ 535{
533 int i, ret = 0; 536 int i, ret = 0;
534 537
538 logf("nand_read_sectors(%ld, %d, 0x%x)", start, count, (int)buf);
539
535 start *= 512; 540 start *= 512;
536 count *= 512; 541 count *= 512;
537 542
538 if(count <= chip_info->page_size) 543 if(count <= chip_info->page_size)
539 { 544 {
540 ret = jz_nand_read_page(start % (chip_info->page_size * chip_info->pages_per_block), start % chip_info->page_size, temp_page); 545 ret = jz_nand_read_page(start/chip_info->page_size, temp_page);
541 memcpy(buf, temp_page, count); 546 memcpy(buf, temp_page+(start%chip_info->page_size), count);
542 return ret; 547 return ret;
543 } 548 }
544 else 549 else
545 { 550 {
546 for(i=0; i<count && ret == 0; i+=chip_info->page_size) 551 for(i=0; i<count && ret==0; i+=chip_info->page_size)
547 { 552 {
548 ret = jz_nand_read_page((start+i) % (chip_info->page_size * chip_info->pages_per_block), (start+i) % chip_info->page_size, temp_page); 553 ret = jz_nand_read_page((start+i)/chip_info->page_size, temp_page);
549 memcpy(buf+i, temp_page, (count-i < chip_info->page_size ? count-i : chip_info->page_size)); 554 memcpy(buf+i, temp_page+((start+i)%chip_info->page_size),
555 (count-i < chip_info->page_size ? count-i : chip_info->page_size));
550 } 556 }
551 return ret; 557 return ret;
552 } 558 }
@@ -607,7 +613,7 @@ void nand_get_info(IF_MV2(int drive,) struct storage_info *info)
607 613
608 /* blocks count */ 614 /* blocks count */
609 /* TODO: proper amount of sectors! */ 615 /* TODO: proper amount of sectors! */
610 info->num_sectors = (chip_info->page_size / 512) * chip_info->pages_per_block * chip_info->blocks_per_bank; 616 info->num_sectors = ((chip_info->page_size+chip_info->spare_size) / 512) * chip_info->pages_per_block * chip_info->blocks_per_bank;
611 info->sector_size = 512; 617 info->sector_size = 512;
612} 618}
613#endif 619#endif