summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Purchase <shotofadds@rockbox.org>2008-06-09 08:11:11 +0000
committerRob Purchase <shotofadds@rockbox.org>2008-06-09 08:11:11 +0000
commitbca9703b83a34d54b8ad7274834f9c0d556d856a (patch)
treeb8c879639cac285a9c5325ef4a9953e5572a06aa
parent84ca420ad12487680d1e0376df3a0fbaa538e62f (diff)
downloadrockbox-bca9703b83a34d54b8ad7274834f9c0d556d856a.tar.gz
rockbox-bca9703b83a34d54b8ad7274834f9c0d556d856a.zip
D2: Fixes for 16Gb models with four NAND banks: update MAX_BANKS, configure the chip select GPIO as output and use a couple of #defines to tidy things up.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@17705 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/target/arm/tcc780x/ata-nand-tcc780x.c36
1 files changed, 19 insertions, 17 deletions
diff --git a/firmware/target/arm/tcc780x/ata-nand-tcc780x.c b/firmware/target/arm/tcc780x/ata-nand-tcc780x.c
index 0bf83da1f3..117a53a53b 100644
--- a/firmware/target/arm/tcc780x/ata-nand-tcc780x.c
+++ b/firmware/target/arm/tcc780x/ata-nand-tcc780x.c
@@ -74,6 +74,15 @@ static struct mutex ata_mtx SHAREDBSS_ATTR;
74#define ECC_ERRDATA (*(volatile unsigned long *)0xF005B060) 74#define ECC_ERRDATA (*(volatile unsigned long *)0xF005B060)
75#define ECC_ERR (*(volatile unsigned long *)0xF005B070) 75#define ECC_ERR (*(volatile unsigned long *)0xF005B070)
76 76
77/* GPIOs */
78
79#define NAND_GPIO_SET(n) GPIOB_SET = n
80#define NAND_GPIO_CLEAR(n) GPIOB_CLEAR = n
81#define NAND_GPIO_OUT_EN(n) GPIOB_DIR |= n
82
83#define WE_GPIO_BIT (1<<19) /* Write Enable */
84#define CS_GPIO_BIT (1<<21) /* Chip Select (4 banks when used with NFC_CSx) */
85
77/* Chip characteristics, initialised by nand_get_chip_info() */ 86/* Chip characteristics, initialised by nand_get_chip_info() */
78 87
79static int page_size = 0; 88static int page_size = 0;
@@ -96,13 +105,7 @@ static int segments_per_bank = 0;
96#define MAX_BLOCKS_PER_BANK 8192 105#define MAX_BLOCKS_PER_BANK 8192
97#define MAX_PAGES_PER_BLOCK 128 106#define MAX_PAGES_PER_BLOCK 128
98#define BLOCKS_PER_SEGMENT 4 107#define BLOCKS_PER_SEGMENT 4
99 108#define MAX_BANKS 4
100/* In theory we can support 4 banks, but only 2 have been seen on 2/4/8Gb D2s */
101#ifdef COWON_D2
102#define MAX_BANKS 2
103#else
104#define MAX_BANKS 4
105#endif
106 109
107#define MAX_SEGMENTS (MAX_BLOCKS_PER_BANK * MAX_BANKS / BLOCKS_PER_SEGMENT) 110#define MAX_SEGMENTS (MAX_BLOCKS_PER_BANK * MAX_BANKS / BLOCKS_PER_SEGMENT)
108 111
@@ -174,7 +177,7 @@ static void nand_chip_select(int bank)
174 if (bank == -1) 177 if (bank == -1)
175 { 178 {
176 /* Disable both chip selects */ 179 /* Disable both chip selects */
177 GPIOB_CLEAR = (1<<21); 180 NAND_GPIO_CLEAR(CS_GPIO_BIT);
178 NFC_CTRL |= NFC_CS0 | NFC_CS1; 181 NFC_CTRL |= NFC_CS0 | NFC_CS1;
179 } 182 }
180 else 183 else
@@ -197,13 +200,9 @@ static void nand_chip_select(int bank)
197 200
198 /* Secondary chip select */ 201 /* Secondary chip select */
199 if (bank & 2) 202 if (bank & 2)
200 { 203 NAND_GPIO_SET(CS_GPIO_BIT);
201 GPIOB_SET = (1<<21);
202 }
203 else 204 else
204 { 205 NAND_GPIO_CLEAR(CS_GPIO_BIT);
205 GPIOB_CLEAR = (1<<21);
206 }
207 } 206 }
208} 207}
209 208
@@ -224,7 +223,7 @@ static void nand_read_id(int bank, unsigned char* id_buf)
224 nand_chip_select(bank); 223 nand_chip_select(bank);
225 224
226 /* Set write protect */ 225 /* Set write protect */
227 GPIOB_CLEAR = (1<<19); 226 NAND_GPIO_CLEAR(WE_GPIO_BIT);
228 227
229 /* Reset command */ 228 /* Reset command */
230 NFC_CMD = 0xFF; 229 NFC_CMD = 0xFF;
@@ -262,7 +261,7 @@ static void nand_read_uid(int bank, unsigned int* uid_buf)
262 nand_chip_select(bank); 261 nand_chip_select(bank);
263 262
264 /* Set write protect */ 263 /* Set write protect */
265 GPIOB_CLEAR = 1<<19; 264 NAND_GPIO_CLEAR(WE_GPIO_BIT);
266 265
267 /* Set 8-bit data width */ 266 /* Set 8-bit data width */
268 NFC_CTRL &= ~NFC_16BIT; 267 NFC_CTRL &= ~NFC_16BIT;
@@ -314,7 +313,7 @@ static void nand_read_raw(int bank, int row, int column, int size, void* buf)
314 nand_chip_select(bank); 313 nand_chip_select(bank);
315 314
316 /* Set write protect */ 315 /* Set write protect */
317 GPIOB_CLEAR = (1<<19); 316 NAND_GPIO_CLEAR(WE_GPIO_BIT);
318 317
319 /* Set 8-bit data width */ 318 /* Set 8-bit data width */
320 NFC_CTRL &= ~NFC_16BIT; 319 NFC_CTRL &= ~NFC_16BIT;
@@ -778,6 +777,9 @@ int ata_init(void)
778 } 777 }
779 } 778 }
780 779
780 /* Set GPIO direction for chip select & write protect */
781 NAND_GPIO_OUT_EN(CS_GPIO_BIT | WE_GPIO_BIT);
782
781 /* Scan banks to build up block translation table */ 783 /* Scan banks to build up block translation table */
782 for (bank = 0; bank < total_banks; bank++) 784 for (bank = 0; bank < total_banks; bank++)
783 { 785 {