blob: d37a49e1950170df0d99784b2752b6212481b076 [file] [log] [blame]
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +01001/*
2 * (C) Copyright 2006 DENX Software Engineering
3 *
4 * See file CREDITS for list of people who contributed to this
5 * project.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 * MA 02111-1307 USA
21 */
22
23#include <common.h>
24
25#if (CONFIG_COMMANDS & CFG_CMD_NAND)
26#ifdef CONFIG_NEW_NAND_CODE
27
28#include <nand.h>
29#include <asm/arch/pxa-regs.h>
30
31/*
Markus Klotzbücher432a7b42006-03-01 23:33:27 +010032 * not required for Monahans DFC
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +010033 */
34static void delta_hwcontrol(struct mtd_info *mtdinfo, int cmd)
35{
Markus Klotzbücher432a7b42006-03-01 23:33:27 +010036 return;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +010037}
38
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +010039/* read device ready pin */
40static int delta_device_ready(struct mtd_info *mtdinfo)
41{
42 if(NDSR & NDSR_RDY)
43 return 1;
44 else
45 return 0;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +010046 return 0;
47}
48
Markus Klotzbücherddd78b02006-03-03 12:11:11 +010049/*
50 * Write buf to the DFC Controller Data Buffer
51 */
52static void delta_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
53{
54 unsigned long bytes_multi = len & 0xfffffffc;
55 unsigned long rest = len & 0x3;
56 unsigned long *long_buf;
57 int i;
58
59 if(bytes_multi) {
60 for(i=0; i<bytes_multi; i+=4) {
61 long_buf = (unsigned long*) &buf[i];
62 NDDB = *long_buf;
63 }
64 }
65 if(rest) {
66 printf("delta_write_buf: ERROR, writing non 4-byte aligned data.\n");
67 }
68 return;
69}
70
71
72/*
73 * These functions are quite problematic for the DFC. Luckily they are
74 * not used in the current nand code, except for nand_command, which
75 * we've defined our own anyway. The problem is, that we always need
76 * to write 4 bytes to the DFC Data Buffer, but in these functions we
77 * don't know if to buffer the bytes/half words until we've gathered 4
78 * bytes or if to send them straight away.
79 *
80 * Solution: Don't use these with Mona's DFC and complain loudly.
81 */
82static void delta_write_word(struct mtd_info *mtd, u16 word)
83{
84 printf("delta_write_word: WARNING, this function does not work with the Monahans DFC!\n");
85}
86static void delta_write_byte(struct mtd_info *mtd, u_char byte)
87{
88 printf("delta_write_byte: WARNING, this function does not work with the Monahans DFC!\n");
89}
90
Markus Klotzbücher432a7b42006-03-01 23:33:27 +010091/* The original:
92 * static void delta_read_buf(struct mtd_info *mtd, const u_char *buf, int len)
93 *
94 * Shouldn't this be "u_char * const buf" ?
95 */
96static void delta_read_buf(struct mtd_info *mtd, u_char* const buf, int len)
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +010097{
Markus Klotzbücher432a7b42006-03-01 23:33:27 +010098 int i, j;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +010099
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100100 /* we have to be carefull not to overflow the buffer if len is
101 * not a multiple of 4 */
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100102 unsigned long bytes_multi = len & 0xfffffffc;
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100103 unsigned long rest = len & 0x3;
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100104 unsigned long *long_buf;
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100105
106 /* if there are any, first copy multiple of 4 bytes */
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100107 if(bytes_multi) {
108 for(i=0; i<bytes_multi; i+=4) {
109 long_buf = (unsigned long*) &buf[i];
Markus Klotzbüchera3bedae2006-03-02 12:10:01 +0100110 *long_buf = NDDB;
111 }
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100112 }
113
114 /* ...then the rest */
115 if(rest) {
116 unsigned long rest_data = NDDB;
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100117 for(j=0;j<rest; j++)
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100118 buf[i+j] = (u_char) ((rest_data>>j) & 0xff);
119 }
120
121 return;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100122}
123
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100124static u16 delta_read_word(struct mtd_info *mtd)
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100125{
126 printf("delta_write_byte: UNIMPLEMENTED.\n");
127}
128
129/* global var, too bad: mk@tbd: move to ->priv pointer */
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100130static unsigned long read_buf = 0;
131static unsigned char bytes_read = 0;
132
133static u_char delta_read_byte(struct mtd_info *mtd)
134{
135/* struct nand_chip *this = mtd->priv; */
136 unsigned char byte;
137
138 if(bytes_read == 0) {
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100139 read_buf = NDDB;
140 printk("delta_read_byte: 0x%x.\n", read_buf);
141 }
142 byte = (unsigned char) (read_buf>>(8 * bytes_read++));
143 if(bytes_read >= 4)
144 bytes_read = 0;
145
146 printf("delta_read_byte: returning 0x%x.\n", byte);
147 return byte;
148}
149
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100150/* delay function */
151static void wait(unsigned long us)
152{
153#define OSCR_CLK_FREQ 3.250 /* kHz */
154
155 unsigned long start = OSCR;
156 unsigned long delta = 0, cur;
157 us *= OSCR_CLK_FREQ;
158
159 while (delta < us) {
160 cur = OSCR;
161 if(cur < start) /* OSCR overflowed */
162 delta = cur + (start^0xffffffff);
163 else
164 delta = cur - start;
165 }
166}
167
168/* poll the NAND Controller Status Register for event */
169static void delta_wait_event(unsigned long event)
170{
171 if(!event)
172 return;
173
174 while(1) {
175 if(NDSR & event) {
176 NDSR |= event;
177 break;
178 }
179 }
180}
181
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100182static unsigned long delta_wait_event2(unsigned long event)
183{
184 unsigned long ndsr;
185 if(!event)
186 return;
187
188 while(1) {
189 ndsr = NDSR;
190 if(ndsr & event) {
191 NDSR |= event;
192 break;
193 }
194 }
195 return ndsr;
196}
197
198/* we don't always wan't to do this */
199static void delta_new_cmd()
200{
201 /* Clear NDSR */
202 NDSR = 0xFFF;
203
204 /* apparently NDCR[NDRUN] needs to be set before writing to NDCBx */
205 if(!(NDCR & NDCR_ND_RUN)) {
206 NDCR |= NDCR_ND_RUN;
207
208 while(1) {
209 if(NDSR & NDSR_WRCMDREQ) {
210 NDSR |= NDSR_WRCMDREQ; /* Ack */
211 break;
212 }
213 }
214 }
215}
216
217static int delta_wait(struct mtd_info *mtd, struct nand_chip *this, int state)
218{
219/* unsigned long timeo; */
220 unsigned long ndsr=0, event=0;
221 unsigned long dummy;
222
223 /* mk@tbd set appropriate timeouts */
224 /* if (state == FL_ERASING) */
225 /* timeo = CFG_HZ * 400; */
226 /* else */
227 /* timeo = CFG_HZ * 20; */
228 if(state == FL_WRITING) {
229 event = NDSR_CS0_CMDD | NDSR_CS0_BBD;
230 } else if(state == FL_ERASING) {
231 /* do something else */
232 }
233
234/* dummy = NDDB; */
235 ndsr = delta_wait_event2(event);
236
237 if(ndsr & NDSR_CS0_BBD)
238 return(0x1); /* Status Read error */
239 return 0;
240}
241
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100242/* this is really monahans, not board specific ... */
243static void delta_cmdfunc(struct mtd_info *mtd, unsigned command,
244 int column, int page_addr)
245{
246 /* register struct nand_chip *this = mtd->priv; */
Markus Klotzbücherf0840da2006-03-02 14:02:36 +0100247 unsigned long ndcb0=0, ndcb1=0, ndcb2=0, event=0;
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100248 unsigned long what_the_hack;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100249
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100250 /* clear the ugly byte read buffer */
251 bytes_read = 0;
252 read_buf = 0;
253
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100254 /* if command is a double byte cmd, we set bit double cmd bit 19 */
255 /* command2 = (command>>8) & 0xFF; */
256 /* ndcb0 = command | ((command2 ? 1 : 0) << 19); *\/ */
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100257
258 switch (command) {
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100259 case NAND_CMD_READ0:
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100260 delta_new_cmd();
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100261 ndcb0 = (NAND_CMD_READ0 | (4<<16));
262 column >>= 1; /* adjust for 16 bit bus */
263 ndcb1 = (((column>>1) & 0xff) |
264 ((page_addr<<8) & 0xff00) |
265 ((page_addr<<8) & 0xff0000) |
266 ((page_addr<<8) & 0xff000000)); /* make this 0x01000000 ? */
Markus Klotzbücherf0840da2006-03-02 14:02:36 +0100267 event = NDSR_RDDREQ;
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100268 break;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100269 case NAND_CMD_READID:
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100270 delta_new_cmd();
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100271 printk("delta_cmdfunc: NAND_CMD_READID.\n");
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100272 ndcb0 = (NAND_CMD_READID | (3 << 21) | (1 << 16)); /* addr cycles*/
Markus Klotzbücherf0840da2006-03-02 14:02:36 +0100273 event = NDSR_RDDREQ;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100274 break;
275 case NAND_CMD_PAGEPROG:
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100276 /* sent as a multicommand in NAND_CMD_SEQIN */
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100277 printk("delta_cmdfunc: NAND_CMD_PAGEPROG.\n");
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100278 goto end;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100279 case NAND_CMD_ERASE1:
280 case NAND_CMD_ERASE2:
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100281 printf("delta_cmdfunc: NAND_CMD_ERASEx unimplemented.\n");
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100282 goto end;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100283 case NAND_CMD_SEQIN:
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100284 /* send PAGE_PROG command(0x1080) */
285 delta_new_cmd();
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100286 printf("delta_cmdfunc: NAND_CMD_SEQIN/PAGE_PROG.\n");
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100287 ndcb0 = (0x1080 | (1<<25) | (1<<21) | (1<<19) | (4<<16));
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100288 column >>= 1; /* adjust for 16 bit bus */
289 ndcb1 = (((column>>1) & 0xff) |
290 ((page_addr<<8) & 0xff00) |
291 ((page_addr<<8) & 0xff0000) |
292 ((page_addr<<8) & 0xff000000)); /* make this 0x01000000 ? */
293 event = NDSR_WRDREQ;
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100294 break;
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100295/* case NAND_CMD_SEQIN_pointer_operation: */
296
297/* /\* This is confusing because the command names are */
298/* * different compared to the ones in the K9K12Q0C */
299/* * datasheet. Infact this has nothing to do with */
300/* * reading, as the but with page programming */
301/* * (writing). */
302/* * Here we send the multibyte commands */
303/* * cmd1=0x00, cmd2=0x80 (for programming main area) or */
304/* * cmd1=0x50, cmd2=0x80 (for spare area) */
305/* * */
306/* * When all data is written to the buffer, the page */
307/* * program command (0x10) is sent to actually write */
308/* * the data. */
309/* *\/ */
310
311/* printf("delta_cmdfunc: NAND_CMD_SEQIN pointer op called.\n"); */
312
313/* ndcb0 = (NAND_CMD_SEQIN<<8) | (1<<21) | (1<<19) | (4<<16); */
314/* if(column >= mtd->oobblock) { */
315/* /\* OOB area *\/ */
316/* column -= mtd->oobblock; */
317/* ndcb0 |= NAND_CMD_READOOB; */
318/* } else if (column < 256) { */
319/* /\* First 256 bytes --> READ0 *\/ */
320/* ndcb0 |= NAND_CMD_READ0; */
321/* } else { */
322/* /\* Only for 8 bit devices - not delta!!! *\/ */
323/* column -= 256; */
324/* ndcb0 |= NAND_CMD_READ1; */
325/* } */
326/* event = NDSR_WRDREQ; */
327/* break; */
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100328 case NAND_CMD_STATUS:
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100329 /* oh, this is not nice. for some reason the real
330 * status byte is in the second read from the data
331 * buffer. The hack is to read the first byte right
332 * here, so the next read access by the nand code
333 * yields the right one.
334 */
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100335 delta_new_cmd();
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100336 ndcb0 = (NAND_CMD_STATUS | (4<<21));
337 event = NDSR_RDDREQ;
Markus Klotzbücher332a0222006-03-03 16:09:28 +0100338#ifdef READ_STATUS_BUG
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100339 NDCB0 = ndcb0;
340 NDCB0 = ndcb1;
341 NDCB0 = ndcb2;
342 delta_wait_event(event);
343 what_the_hack = NDDB;
344 goto end;
Markus Klotzbücher332a0222006-03-03 16:09:28 +0100345#endif
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100346 break;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100347 case NAND_CMD_RESET:
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100348 printf("delta_cmdfunc: NAND_CMD_RESET unimplemented.\n");
349 break;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100350 default:
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100351 printk("delta_cmdfunc: error, unsupported command.\n");
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100352 return;
353 }
354
355 NDCB0 = ndcb0;
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100356 NDCB0 = ndcb1;
357 NDCB0 = ndcb2;
Markus Klotzbücherf0840da2006-03-02 14:02:36 +0100358
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100359 wait_event:
Markus Klotzbücherf0840da2006-03-02 14:02:36 +0100360 delta_wait_event(event);
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100361 end:
362 return;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100363}
364
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100365static void delta_dfc_gpio_init()
Markus Klotzbücherf14cc262006-02-28 22:51:01 +0100366{
367 printf("Setting up DFC GPIO's.\n");
368
369 /* no idea what is done here, see zylonite.c */
370 GPIO4 = 0x1;
371
372 DF_ALE_WE1 = 0x00000001;
373 DF_ALE_WE2 = 0x00000001;
374 DF_nCS0 = 0x00000001;
375 DF_nCS1 = 0x00000001;
376 DF_nWE = 0x00000001;
377 DF_nRE = 0x00000001;
378 DF_IO0 = 0x00000001;
379 DF_IO8 = 0x00000001;
380 DF_IO1 = 0x00000001;
381 DF_IO9 = 0x00000001;
382 DF_IO2 = 0x00000001;
383 DF_IO10 = 0x00000001;
384 DF_IO3 = 0x00000001;
385 DF_IO11 = 0x00000001;
386 DF_IO4 = 0x00000001;
387 DF_IO12 = 0x00000001;
388 DF_IO5 = 0x00000001;
389 DF_IO13 = 0x00000001;
390 DF_IO6 = 0x00000001;
391 DF_IO14 = 0x00000001;
392 DF_IO7 = 0x00000001;
393 DF_IO15 = 0x00000001;
394
395 DF_nWE = 0x1901;
396 DF_nRE = 0x1901;
397 DF_CLE_NOE = 0x1900;
398 DF_ALE_WE1 = 0x1901;
399 DF_INT_RnB = 0x1900;
400}
401
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100402/*
403 * Board-specific NAND initialization. The following members of the
404 * argument are board-specific (per include/linux/mtd/nand_new.h):
405 * - IO_ADDR_R?: address to read the 8 I/O lines of the flash device
406 * - IO_ADDR_W?: address to write the 8 I/O lines of the flash device
407 * - hwcontrol: hardwarespecific function for accesing control-lines
408 * - dev_ready: hardwarespecific function for accesing device ready/busy line
409 * - enable_hwecc?: function to enable (reset) hardware ecc generator. Must
410 * only be provided if a hardware ECC is available
411 * - eccmode: mode of ecc, see defines
412 * - chip_delay: chip dependent delay for transfering data from array to
413 * read regs (tR)
414 * - options: various chip options. They can partly be set to inform
415 * nand_scan about special functionality. See the defines for further
416 * explanation
417 * Members with a "?" were not set in the merged testing-NAND branch,
418 * so they are not set here either.
419 */
420void board_nand_init(struct nand_chip *nand)
421{
422 unsigned long tCH, tCS, tWH, tWP, tRH, tRP, tRP_high, tR, tWHR, tAR;
423
424 /* set up GPIO Control Registers */
Markus Klotzbücherf14cc262006-02-28 22:51:01 +0100425 delta_dfc_gpio_init();
426
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100427 /* turn on the NAND Controller Clock (104 MHz @ D0) */
428 CKENA |= (CKENA_4_NAND | CKENA_9_SMC);
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100429
430 /* wait ? */
431/* printf("stupid loop start...\n"); */
432/* wait(200); */
433/* printf("stupid loop end.\n"); */
434
435
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100436 /* NAND Timing Parameters (in ns) */
437#define NAND_TIMING_tCH 10
438#define NAND_TIMING_tCS 0
439#define NAND_TIMING_tWH 20
440#define NAND_TIMING_tWP 40
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100441/* #define NAND_TIMING_tRH 20 */
442/* #define NAND_TIMING_tRP 40 */
443
444#define NAND_TIMING_tRH 25
445#define NAND_TIMING_tRP 50
446
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100447#define NAND_TIMING_tR 11123
448#define NAND_TIMING_tWHR 110
449#define NAND_TIMING_tAR 10
450
451/* Maximum values for NAND Interface Timing Registers in DFC clock
452 * periods */
453#define DFC_MAX_tCH 7
454#define DFC_MAX_tCS 7
455#define DFC_MAX_tWH 7
456#define DFC_MAX_tWP 7
457#define DFC_MAX_tRH 7
458#define DFC_MAX_tRP 15
459#define DFC_MAX_tR 65535
460#define DFC_MAX_tWHR 15
461#define DFC_MAX_tAR 15
462
463#define DFC_CLOCK 104 /* DFC Clock is 104 MHz */
464#define DFC_CLK_PER_US DFC_CLOCK/1000 /* clock period in ns */
465#define MIN(x, y) ((x < y) ? x : y)
466
467
468 tCH = MIN(((unsigned long) (NAND_TIMING_tCH * DFC_CLK_PER_US) + 1),
469 DFC_MAX_tCH);
470 tCS = MIN(((unsigned long) (NAND_TIMING_tCS * DFC_CLK_PER_US) + 1),
471 DFC_MAX_tCS);
472 tWH = MIN(((unsigned long) (NAND_TIMING_tWH * DFC_CLK_PER_US) + 1),
473 DFC_MAX_tWH);
474 tWP = MIN(((unsigned long) (NAND_TIMING_tWP * DFC_CLK_PER_US) + 1),
475 DFC_MAX_tWP);
476 tRH = MIN(((unsigned long) (NAND_TIMING_tRH * DFC_CLK_PER_US) + 1),
477 DFC_MAX_tRH);
478 tRP = MIN(((unsigned long) (NAND_TIMING_tRP * DFC_CLK_PER_US) + 1),
479 DFC_MAX_tRP);
480 tR = MIN(((unsigned long) (NAND_TIMING_tR * DFC_CLK_PER_US) + 1),
481 DFC_MAX_tR);
482 tWHR = MIN(((unsigned long) (NAND_TIMING_tWHR * DFC_CLK_PER_US) + 1),
483 DFC_MAX_tWHR);
484 tAR = MIN(((unsigned long) (NAND_TIMING_tAR * DFC_CLK_PER_US) + 1),
485 DFC_MAX_tAR);
486
487
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100488 printf("tCH=%u, tCS=%u, tWH=%u, tWP=%u, tRH=%u, tRP=%u, tR=%u, tWHR=%u, tAR=%u.\n", tCH, tCS, tWH, tWP, tRH, tRP, tR, tWHR, tAR);
489
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100490 /* tRP value is split in the register */
491 if(tRP & (1 << 4)) {
492 tRP_high = 1;
493 tRP &= ~(1 << 4);
494 } else {
495 tRP_high = 0;
496 }
497
498 NDTR0CS0 = (tCH << 19) |
499 (tCS << 16) |
500 (tWH << 11) |
501 (tWP << 8) |
502 (tRP_high << 6) |
503 (tRH << 3) |
504 (tRP << 0);
505
506 NDTR1CS0 = (tR << 16) |
507 (tWHR << 4) |
508 (tAR << 0);
509
510
511
512 /* If it doesn't work (unlikely) think about:
513 * - ecc enable
514 * - chip select don't care
515 * - read id byte count
516 *
517 * Intentionally enabled by not setting bits:
518 * - dma (DMA_EN)
519 * - page size = 512
520 * - cs don't care, see if we can enable later!
521 * - row address start position (after second cycle)
522 * - pages per block = 32
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100523 * - ND_RDY : clears command buffer
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100524 */
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100525 NDCR = (NDCR_SPARE_EN | /* use the spare area */
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100526 NDCR_DWIDTH_C | /* 16bit DFC data bus width */
527 NDCR_DWIDTH_M | /* 16 bit Flash device data bus width */
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100528 NDCR_NCSX | /* Chip select busy don't care */
529 (7 << 16) | /* read id count = 7 ???? mk@tbd */
530 NDCR_ND_ARB_EN | /* enable bus arbiter */
531 NDCR_RDYM | /* flash device ready ir masked */
532 NDCR_CS0_PAGEDM | /* ND_nCSx page done ir masked */
533 NDCR_CS1_PAGEDM |
534 NDCR_CS0_CMDDM | /* ND_CSx command done ir masked */
535 NDCR_CS1_CMDDM |
536 NDCR_CS0_BBDM | /* ND_CSx bad block detect ir masked */
537 NDCR_CS1_BBDM |
538 NDCR_DBERRM | /* double bit error ir masked */
539 NDCR_SBERRM | /* single bit error ir masked */
540 NDCR_WRDREQM | /* write data request ir masked */
541 NDCR_RDDREQM | /* read data request ir masked */
542 NDCR_WRCMDREQM); /* write command request ir masked */
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100543
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100544
545 /* wait 10 us due to cmd buffer clear reset */
546/* wait(10); */
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100547
548
549 nand->hwcontrol = delta_hwcontrol;
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100550/* nand->dev_ready = delta_device_ready; */
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100551 nand->eccmode = NAND_ECC_SOFT;
552 nand->chip_delay = NAND_DELAY_US;
553 nand->options = NAND_BUSWIDTH_16;
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100554 nand->waitfunc = delta_wait;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100555 nand->read_byte = delta_read_byte;
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100556 nand->write_byte = delta_write_byte;
557 nand->read_word = delta_read_word;
558 nand->write_word = delta_write_word;
Markus Klotzbücher432a7b42006-03-01 23:33:27 +0100559 nand->read_buf = delta_read_buf;
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100560 nand->write_buf = delta_write_buf;
Markus Klotzbücherb6c2d402006-03-03 15:37:01 +0100561
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100562 nand->cmdfunc = delta_cmdfunc;
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100563}
564
565#else
Markus Klotzbücherddd78b02006-03-03 12:11:11 +0100566 #error "U-Boot legacy NAND support not available for delta board."
Markus Klotzbücherf4a5c612006-02-28 18:05:25 +0100567#endif
568#endif