Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Jon Loeliger | b930726 | 2007-07-09 18:24:55 -0500 | [diff] [blame] | 25 | #if defined(CONFIG_CMD_NAND) |
Jean-Christophe PLAGNIOL-VILLARD | cc4a0ce | 2008-08-13 01:40:43 +0200 | [diff] [blame] | 26 | #if !defined(CONFIG_NAND_LEGACY) |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 27 | |
| 28 | #include <nand.h> |
| 29 | #include <asm/arch/pxa-regs.h> |
| 30 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 31 | #ifdef CFG_DFC_DEBUG1 |
| 32 | # define DFC_DEBUG1(fmt, args...) printf(fmt, ##args) |
| 33 | #else |
| 34 | # define DFC_DEBUG1(fmt, args...) |
| 35 | #endif |
| 36 | |
| 37 | #ifdef CFG_DFC_DEBUG2 |
| 38 | # define DFC_DEBUG2(fmt, args...) printf(fmt, ##args) |
| 39 | #else |
| 40 | # define DFC_DEBUG2(fmt, args...) |
| 41 | #endif |
| 42 | |
Markus Klotzbücher | f9e0291 | 2006-03-06 13:45:42 +0100 | [diff] [blame] | 43 | #ifdef CFG_DFC_DEBUG3 |
| 44 | # define DFC_DEBUG3(fmt, args...) printf(fmt, ##args) |
| 45 | #else |
| 46 | # define DFC_DEBUG3(fmt, args...) |
| 47 | #endif |
| 48 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 49 | #define MIN(x, y) ((x < y) ? x : y) |
| 50 | |
| 51 | /* These really don't belong here, as they are specific to the NAND Model */ |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 52 | static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; |
| 53 | |
| 54 | static struct nand_bbt_descr delta_bbt_descr = { |
| 55 | .options = 0, |
| 56 | .offs = 0, |
| 57 | .len = 2, |
| 58 | .pattern = scan_ff_pattern |
| 59 | }; |
| 60 | |
| 61 | static struct nand_oobinfo delta_oob = { |
Markus Klotzbücher | f9e0291 | 2006-03-06 13:45:42 +0100 | [diff] [blame] | 62 | .useecc = MTD_NANDECC_AUTOPL_USR, /* MTD_NANDECC_PLACEONLY, */ |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 63 | .eccbytes = 6, |
| 64 | .eccpos = {2, 3, 4, 5, 6, 7}, |
| 65 | .oobfree = { {8, 2}, {12, 4} } |
| 66 | }; |
| 67 | |
| 68 | |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 69 | /* |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 70 | * not required for Monahans DFC |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 71 | */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 72 | static void dfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 73 | { |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 74 | return; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 75 | } |
| 76 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 77 | #if 0 |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 78 | /* read device ready pin */ |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 79 | static int dfc_device_ready(struct mtd_info *mtdinfo) |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 80 | { |
| 81 | if(NDSR & NDSR_RDY) |
| 82 | return 1; |
| 83 | else |
| 84 | return 0; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 85 | return 0; |
| 86 | } |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 87 | #endif |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 88 | |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 89 | /* |
| 90 | * Write buf to the DFC Controller Data Buffer |
| 91 | */ |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 92 | static void dfc_write_buf(struct mtd_info *mtd, const u_char *buf, int len) |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 93 | { |
| 94 | unsigned long bytes_multi = len & 0xfffffffc; |
| 95 | unsigned long rest = len & 0x3; |
| 96 | unsigned long *long_buf; |
| 97 | int i; |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 98 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 99 | DFC_DEBUG2("dfc_write_buf: writing %d bytes starting with 0x%x.\n", len, *((unsigned long*) buf)); |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 100 | if(bytes_multi) { |
| 101 | for(i=0; i<bytes_multi; i+=4) { |
| 102 | long_buf = (unsigned long*) &buf[i]; |
| 103 | NDDB = *long_buf; |
| 104 | } |
| 105 | } |
| 106 | if(rest) { |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 107 | printf("dfc_write_buf: ERROR, writing non 4-byte aligned data.\n"); |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 108 | } |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 113 | static void dfc_read_buf(struct mtd_info *mtd, u_char* const buf, int len) |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 114 | { |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 115 | int i=0, j; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 116 | |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 117 | /* we have to be carefull not to overflow the buffer if len is |
| 118 | * not a multiple of 4 */ |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 119 | unsigned long bytes_multi = len & 0xfffffffc; |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 120 | unsigned long rest = len & 0x3; |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 121 | unsigned long *long_buf; |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 122 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 123 | DFC_DEBUG3("dfc_read_buf: reading %d bytes.\n", len); |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 124 | /* if there are any, first copy multiple of 4 bytes */ |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 125 | if(bytes_multi) { |
| 126 | for(i=0; i<bytes_multi; i+=4) { |
| 127 | long_buf = (unsigned long*) &buf[i]; |
Markus Klotzbücher | bb1ff04 | 2006-03-02 12:10:01 +0100 | [diff] [blame] | 128 | *long_buf = NDDB; |
| 129 | } |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 130 | } |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 131 | |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 132 | /* ...then the rest */ |
| 133 | if(rest) { |
| 134 | unsigned long rest_data = NDDB; |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 135 | for(j=0;j<rest; j++) |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 136 | buf[i+j] = (u_char) ((rest_data>>j) & 0xff); |
| 137 | } |
| 138 | |
| 139 | return; |
| 140 | } |
| 141 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 142 | /* |
| 143 | * read a word. Not implemented as not used in NAND code. |
| 144 | */ |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 145 | static u16 dfc_read_word(struct mtd_info *mtd) |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 146 | { |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 147 | printf("dfc_read_word: UNIMPLEMENTED.\n"); |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 148 | return 0; |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /* global var, too bad: mk@tbd: move to ->priv pointer */ |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 152 | static unsigned long read_buf = 0; |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 153 | static int bytes_read = -1; |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 154 | |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 155 | /* |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 156 | * read a byte from NDDB Because we can only read 4 bytes from NDDB at |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 157 | * a time, we buffer the remaining bytes. The buffer is reset when a |
| 158 | * new command is sent to the chip. |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 159 | * |
| 160 | * WARNING: |
| 161 | * This function is currently only used to read status and id |
| 162 | * bytes. For these commands always 8 bytes need to be read from |
| 163 | * NDDB. So we read and discard these bytes right now. In case this |
| 164 | * function is used for anything else in the future, we must check |
| 165 | * what was the last command issued and read the appropriate amount of |
| 166 | * bytes respectively. |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 167 | */ |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 168 | static u_char dfc_read_byte(struct mtd_info *mtd) |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 169 | { |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 170 | unsigned char byte; |
Markus Klotzbücher | f9e0291 | 2006-03-06 13:45:42 +0100 | [diff] [blame] | 171 | unsigned long dummy; |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 172 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 173 | if(bytes_read < 0) { |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 174 | read_buf = NDDB; |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 175 | dummy = NDDB; |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 176 | bytes_read = 0; |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 177 | } |
| 178 | byte = (unsigned char) (read_buf>>(8 * bytes_read++)); |
| 179 | if(bytes_read >= 4) |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 180 | bytes_read = -1; |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 181 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 182 | DFC_DEBUG2("dfc_read_byte: byte %u: 0x%x of (0x%x).\n", bytes_read - 1, byte, read_buf); |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 183 | return byte; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 184 | } |
| 185 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 186 | /* calculate delta between OSCR values start and now */ |
| 187 | static unsigned long get_delta(unsigned long start) |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 188 | { |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 189 | unsigned long cur = OSCR; |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 190 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 191 | if(cur < start) /* OSCR overflowed */ |
| 192 | return (cur + (start^0xffffffff)); |
| 193 | else |
| 194 | return (cur - start); |
| 195 | } |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 196 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 197 | /* delay function, this doesn't belong here */ |
| 198 | static void wait_us(unsigned long us) |
| 199 | { |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 200 | unsigned long start = OSCR; |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 201 | us *= OSCR_CLK_FREQ; |
| 202 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 203 | while (get_delta(start) < us) { |
| 204 | /* do nothing */ |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
Wolfgang Denk | d52fb7e | 2006-03-11 22:53:33 +0100 | [diff] [blame] | 208 | static void dfc_clear_nddb(void) |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 209 | { |
| 210 | NDCR &= ~NDCR_ND_RUN; |
| 211 | wait_us(CFG_NAND_OTHER_TO); |
| 212 | } |
| 213 | |
| 214 | /* wait_event with timeout */ |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 215 | static unsigned long dfc_wait_event(unsigned long event) |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 216 | { |
| 217 | unsigned long ndsr, timeout, start = OSCR; |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 218 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 219 | if(!event) |
| 220 | return 0xff000000; |
| 221 | else if(event & (NDSR_CS0_CMDD | NDSR_CS0_BBD)) |
| 222 | timeout = CFG_NAND_PROG_ERASE_TO * OSCR_CLK_FREQ; |
| 223 | else |
| 224 | timeout = CFG_NAND_OTHER_TO * OSCR_CLK_FREQ; |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 225 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 226 | while(1) { |
| 227 | ndsr = NDSR; |
| 228 | if(ndsr & event) { |
| 229 | NDSR |= event; |
| 230 | break; |
| 231 | } |
| 232 | if(get_delta(start) > timeout) { |
Jean-Christophe PLAGNIOL-VILLARD | 0a5676b | 2008-07-12 14:36:34 +0200 | [diff] [blame] | 233 | DFC_DEBUG1("dfc_wait_event: TIMEOUT waiting for event: 0x%lx.\n", event); |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 234 | return 0xff000000; |
| 235 | } |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 236 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 237 | } |
| 238 | return ndsr; |
| 239 | } |
| 240 | |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 241 | /* we don't always wan't to do this */ |
Wolfgang Denk | d52fb7e | 2006-03-11 22:53:33 +0100 | [diff] [blame] | 242 | static void dfc_new_cmd(void) |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 243 | { |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 244 | int retry = 0; |
| 245 | unsigned long status; |
| 246 | |
| 247 | while(retry++ <= CFG_NAND_SENDCMD_RETRY) { |
| 248 | /* Clear NDSR */ |
| 249 | NDSR = 0xFFF; |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 250 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 251 | /* set NDCR[NDRUN] */ |
| 252 | if(!(NDCR & NDCR_ND_RUN)) |
| 253 | NDCR |= NDCR_ND_RUN; |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 254 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 255 | status = dfc_wait_event(NDSR_WRCMDREQ); |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 256 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 257 | if(status & NDSR_WRCMDREQ) |
| 258 | return; |
| 259 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 260 | DFC_DEBUG2("dfc_new_cmd: FAILED to get WRITECMDREQ, retry: %d.\n", retry); |
| 261 | dfc_clear_nddb(); |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 262 | } |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 263 | DFC_DEBUG1("dfc_new_cmd: giving up after %d retries.\n", retry); |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 264 | } |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 265 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 266 | /* this function is called after Programm and Erase Operations to |
| 267 | * check for success or failure */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 268 | static int dfc_wait(struct mtd_info *mtd, struct nand_chip *this) |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 269 | { |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 270 | unsigned long ndsr=0, event=0; |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 271 | int state = this->state; |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 272 | |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 273 | if(state == FL_WRITING) { |
| 274 | event = NDSR_CS0_CMDD | NDSR_CS0_BBD; |
| 275 | } else if(state == FL_ERASING) { |
Markus Klotzbücher | f8785e9 | 2006-03-03 20:13:43 +0100 | [diff] [blame] | 276 | event = NDSR_CS0_CMDD | NDSR_CS0_BBD; |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 277 | } |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 278 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 279 | ndsr = dfc_wait_event(event); |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 280 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 281 | if((ndsr & NDSR_CS0_BBD) || (ndsr & 0xff000000)) |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 282 | return(0x1); /* Status Read error */ |
| 283 | return 0; |
| 284 | } |
| 285 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 286 | /* cmdfunc send commands to the DFC */ |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 287 | static void dfc_cmdfunc(struct mtd_info *mtd, unsigned command, |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 288 | int column, int page_addr) |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 289 | { |
| 290 | /* register struct nand_chip *this = mtd->priv; */ |
Markus Klotzbücher | e2053f9 | 2006-03-02 14:02:36 +0100 | [diff] [blame] | 291 | unsigned long ndcb0=0, ndcb1=0, ndcb2=0, event=0; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 292 | |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 293 | /* clear the ugly byte read buffer */ |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 294 | bytes_read = -1; |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 295 | read_buf = 0; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 296 | |
| 297 | switch (command) { |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 298 | case NAND_CMD_READ0: |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 299 | DFC_DEBUG3("dfc_cmdfunc: NAND_CMD_READ0, page_addr: 0x%x, column: 0x%x.\n", page_addr, (column>>1)); |
| 300 | dfc_new_cmd(); |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 301 | ndcb0 = (NAND_CMD_READ0 | (4<<16)); |
| 302 | column >>= 1; /* adjust for 16 bit bus */ |
| 303 | ndcb1 = (((column>>1) & 0xff) | |
| 304 | ((page_addr<<8) & 0xff00) | |
| 305 | ((page_addr<<8) & 0xff0000) | |
| 306 | ((page_addr<<8) & 0xff000000)); /* make this 0x01000000 ? */ |
Markus Klotzbücher | e2053f9 | 2006-03-02 14:02:36 +0100 | [diff] [blame] | 307 | event = NDSR_RDDREQ; |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 308 | goto write_cmd; |
Markus Klotzbücher | f9e0291 | 2006-03-06 13:45:42 +0100 | [diff] [blame] | 309 | case NAND_CMD_READ1: |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 310 | DFC_DEBUG2("dfc_cmdfunc: NAND_CMD_READ1 unimplemented!\n"); |
Markus Klotzbücher | f9e0291 | 2006-03-06 13:45:42 +0100 | [diff] [blame] | 311 | goto end; |
| 312 | case NAND_CMD_READOOB: |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 313 | DFC_DEBUG1("dfc_cmdfunc: NAND_CMD_READOOB unimplemented!\n"); |
Markus Klotzbücher | f9e0291 | 2006-03-06 13:45:42 +0100 | [diff] [blame] | 314 | goto end; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 315 | case NAND_CMD_READID: |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 316 | dfc_new_cmd(); |
| 317 | DFC_DEBUG2("dfc_cmdfunc: NAND_CMD_READID.\n"); |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 318 | ndcb0 = (NAND_CMD_READID | (3 << 21) | (1 << 16)); /* addr cycles*/ |
Markus Klotzbücher | e2053f9 | 2006-03-02 14:02:36 +0100 | [diff] [blame] | 319 | event = NDSR_RDDREQ; |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 320 | goto write_cmd; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 321 | case NAND_CMD_PAGEPROG: |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 322 | /* sent as a multicommand in NAND_CMD_SEQIN */ |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 323 | DFC_DEBUG2("dfc_cmdfunc: NAND_CMD_PAGEPROG empty due to multicmd.\n"); |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 324 | goto end; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 325 | case NAND_CMD_ERASE1: |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 326 | DFC_DEBUG2("dfc_cmdfunc: NAND_CMD_ERASE1, page_addr: 0x%x, column: 0x%x.\n", page_addr, (column>>1)); |
| 327 | dfc_new_cmd(); |
Markus Klotzbücher | f8785e9 | 2006-03-03 20:13:43 +0100 | [diff] [blame] | 328 | ndcb0 = (0xd060 | (1<<25) | (2<<21) | (1<<19) | (3<<16)); |
| 329 | ndcb1 = (page_addr & 0x00ffffff); |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 330 | goto write_cmd; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 331 | case NAND_CMD_ERASE2: |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 332 | DFC_DEBUG2("dfc_cmdfunc: NAND_CMD_ERASE2 empty due to multicmd.\n"); |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 333 | goto end; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 334 | case NAND_CMD_SEQIN: |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 335 | /* send PAGE_PROG command(0x1080) */ |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 336 | dfc_new_cmd(); |
| 337 | DFC_DEBUG2("dfc_cmdfunc: NAND_CMD_SEQIN/PAGE_PROG, page_addr: 0x%x, column: 0x%x.\n", page_addr, (column>>1)); |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 338 | ndcb0 = (0x1080 | (1<<25) | (1<<21) | (1<<19) | (4<<16)); |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 339 | column >>= 1; /* adjust for 16 bit bus */ |
| 340 | ndcb1 = (((column>>1) & 0xff) | |
| 341 | ((page_addr<<8) & 0xff00) | |
| 342 | ((page_addr<<8) & 0xff0000) | |
| 343 | ((page_addr<<8) & 0xff000000)); /* make this 0x01000000 ? */ |
| 344 | event = NDSR_WRDREQ; |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 345 | goto write_cmd; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 346 | case NAND_CMD_STATUS: |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 347 | DFC_DEBUG2("dfc_cmdfunc: NAND_CMD_STATUS.\n"); |
| 348 | dfc_new_cmd(); |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 349 | ndcb0 = NAND_CMD_STATUS | (4<<21); |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 350 | event = NDSR_RDDREQ; |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 351 | goto write_cmd; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 352 | case NAND_CMD_RESET: |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 353 | DFC_DEBUG2("dfc_cmdfunc: NAND_CMD_RESET.\n"); |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 354 | ndcb0 = NAND_CMD_RESET | (5<<21); |
| 355 | event = NDSR_CS0_CMDD; |
| 356 | goto write_cmd; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 357 | default: |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 358 | printk("dfc_cmdfunc: error, unsupported command.\n"); |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 359 | goto end; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 360 | } |
| 361 | |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 362 | write_cmd: |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 363 | NDCB0 = ndcb0; |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 364 | NDCB0 = ndcb1; |
| 365 | NDCB0 = ndcb2; |
Markus Klotzbücher | e2053f9 | 2006-03-02 14:02:36 +0100 | [diff] [blame] | 366 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 367 | /* wait_event: */ |
| 368 | dfc_wait_event(event); |
Markus Klotzbücher | 19fdeff | 2006-03-03 12:11:11 +0100 | [diff] [blame] | 369 | end: |
| 370 | return; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 371 | } |
| 372 | |
Wolfgang Denk | d52fb7e | 2006-03-11 22:53:33 +0100 | [diff] [blame] | 373 | static void dfc_gpio_init(void) |
Markus Klotzbücher | 00c35bd | 2006-02-28 22:51:01 +0100 | [diff] [blame] | 374 | { |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 375 | DFC_DEBUG2("Setting up DFC GPIO's.\n"); |
Markus Klotzbücher | 00c35bd | 2006-02-28 22:51:01 +0100 | [diff] [blame] | 376 | |
| 377 | /* no idea what is done here, see zylonite.c */ |
| 378 | GPIO4 = 0x1; |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 379 | |
Markus Klotzbücher | 00c35bd | 2006-02-28 22:51:01 +0100 | [diff] [blame] | 380 | DF_ALE_WE1 = 0x00000001; |
| 381 | DF_ALE_WE2 = 0x00000001; |
| 382 | DF_nCS0 = 0x00000001; |
| 383 | DF_nCS1 = 0x00000001; |
| 384 | DF_nWE = 0x00000001; |
| 385 | DF_nRE = 0x00000001; |
| 386 | DF_IO0 = 0x00000001; |
| 387 | DF_IO8 = 0x00000001; |
| 388 | DF_IO1 = 0x00000001; |
| 389 | DF_IO9 = 0x00000001; |
| 390 | DF_IO2 = 0x00000001; |
| 391 | DF_IO10 = 0x00000001; |
| 392 | DF_IO3 = 0x00000001; |
| 393 | DF_IO11 = 0x00000001; |
| 394 | DF_IO4 = 0x00000001; |
| 395 | DF_IO12 = 0x00000001; |
| 396 | DF_IO5 = 0x00000001; |
| 397 | DF_IO13 = 0x00000001; |
| 398 | DF_IO6 = 0x00000001; |
| 399 | DF_IO14 = 0x00000001; |
| 400 | DF_IO7 = 0x00000001; |
| 401 | DF_IO15 = 0x00000001; |
| 402 | |
| 403 | DF_nWE = 0x1901; |
| 404 | DF_nRE = 0x1901; |
| 405 | DF_CLE_NOE = 0x1900; |
| 406 | DF_ALE_WE1 = 0x1901; |
| 407 | DF_INT_RnB = 0x1900; |
| 408 | } |
| 409 | |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 410 | /* |
| 411 | * Board-specific NAND initialization. The following members of the |
| 412 | * argument are board-specific (per include/linux/mtd/nand_new.h): |
| 413 | * - IO_ADDR_R?: address to read the 8 I/O lines of the flash device |
| 414 | * - IO_ADDR_W?: address to write the 8 I/O lines of the flash device |
| 415 | * - hwcontrol: hardwarespecific function for accesing control-lines |
| 416 | * - dev_ready: hardwarespecific function for accesing device ready/busy line |
| 417 | * - enable_hwecc?: function to enable (reset) hardware ecc generator. Must |
| 418 | * only be provided if a hardware ECC is available |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 419 | * - ecc.mode: mode of ecc, see defines |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 420 | * - chip_delay: chip dependent delay for transfering data from array to |
| 421 | * read regs (tR) |
| 422 | * - options: various chip options. They can partly be set to inform |
| 423 | * nand_scan about special functionality. See the defines for further |
| 424 | * explanation |
| 425 | * Members with a "?" were not set in the merged testing-NAND branch, |
| 426 | * so they are not set here either. |
| 427 | */ |
Heiko Schocher | fa23044 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 428 | int board_nand_init(struct nand_chip *nand) |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 429 | { |
| 430 | unsigned long tCH, tCS, tWH, tWP, tRH, tRP, tRP_high, tR, tWHR, tAR; |
| 431 | |
| 432 | /* set up GPIO Control Registers */ |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 433 | dfc_gpio_init(); |
Markus Klotzbücher | 00c35bd | 2006-02-28 22:51:01 +0100 | [diff] [blame] | 434 | |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 435 | /* turn on the NAND Controller Clock (104 MHz @ D0) */ |
| 436 | CKENA |= (CKENA_4_NAND | CKENA_9_SMC); |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 437 | |
Markus Klotzbücher | f9e0291 | 2006-03-06 13:45:42 +0100 | [diff] [blame] | 438 | #undef CFG_TIMING_TIGHT |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 439 | #ifndef CFG_TIMING_TIGHT |
| 440 | tCH = MIN(((unsigned long) (NAND_TIMING_tCH * DFC_CLK_PER_US) + 1), |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 441 | DFC_MAX_tCH); |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 442 | tCS = MIN(((unsigned long) (NAND_TIMING_tCS * DFC_CLK_PER_US) + 1), |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 443 | DFC_MAX_tCS); |
| 444 | tWH = MIN(((unsigned long) (NAND_TIMING_tWH * DFC_CLK_PER_US) + 1), |
| 445 | DFC_MAX_tWH); |
| 446 | tWP = MIN(((unsigned long) (NAND_TIMING_tWP * DFC_CLK_PER_US) + 1), |
| 447 | DFC_MAX_tWP); |
| 448 | tRH = MIN(((unsigned long) (NAND_TIMING_tRH * DFC_CLK_PER_US) + 1), |
| 449 | DFC_MAX_tRH); |
| 450 | tRP = MIN(((unsigned long) (NAND_TIMING_tRP * DFC_CLK_PER_US) + 1), |
| 451 | DFC_MAX_tRP); |
| 452 | tR = MIN(((unsigned long) (NAND_TIMING_tR * DFC_CLK_PER_US) + 1), |
| 453 | DFC_MAX_tR); |
| 454 | tWHR = MIN(((unsigned long) (NAND_TIMING_tWHR * DFC_CLK_PER_US) + 1), |
| 455 | DFC_MAX_tWHR); |
| 456 | tAR = MIN(((unsigned long) (NAND_TIMING_tAR * DFC_CLK_PER_US) + 1), |
| 457 | DFC_MAX_tAR); |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 458 | #else /* this is the tight timing */ |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 459 | |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 460 | tCH = MIN(((unsigned long) (NAND_TIMING_tCH * DFC_CLK_PER_US)), |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 461 | DFC_MAX_tCH); |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 462 | tCS = MIN(((unsigned long) (NAND_TIMING_tCS * DFC_CLK_PER_US)), |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 463 | DFC_MAX_tCS); |
| 464 | tWH = MIN(((unsigned long) (NAND_TIMING_tWH * DFC_CLK_PER_US)), |
| 465 | DFC_MAX_tWH); |
| 466 | tWP = MIN(((unsigned long) (NAND_TIMING_tWP * DFC_CLK_PER_US)), |
| 467 | DFC_MAX_tWP); |
| 468 | tRH = MIN(((unsigned long) (NAND_TIMING_tRH * DFC_CLK_PER_US)), |
| 469 | DFC_MAX_tRH); |
| 470 | tRP = MIN(((unsigned long) (NAND_TIMING_tRP * DFC_CLK_PER_US)), |
| 471 | DFC_MAX_tRP); |
| 472 | tR = MIN(((unsigned long) (NAND_TIMING_tR * DFC_CLK_PER_US) - tCH - 2), |
| 473 | DFC_MAX_tR); |
| 474 | tWHR = MIN(((unsigned long) (NAND_TIMING_tWHR * DFC_CLK_PER_US) - tCH - 2), |
| 475 | DFC_MAX_tWHR); |
| 476 | tAR = MIN(((unsigned long) (NAND_TIMING_tAR * DFC_CLK_PER_US) - 2), |
| 477 | DFC_MAX_tAR); |
| 478 | #endif /* CFG_TIMING_TIGHT */ |
| 479 | |
| 480 | |
| 481 | DFC_DEBUG2("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); |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 482 | |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 483 | /* tRP value is split in the register */ |
| 484 | if(tRP & (1 << 4)) { |
| 485 | tRP_high = 1; |
| 486 | tRP &= ~(1 << 4); |
| 487 | } else { |
| 488 | tRP_high = 0; |
| 489 | } |
| 490 | |
| 491 | NDTR0CS0 = (tCH << 19) | |
| 492 | (tCS << 16) | |
| 493 | (tWH << 11) | |
| 494 | (tWP << 8) | |
| 495 | (tRP_high << 6) | |
| 496 | (tRH << 3) | |
| 497 | (tRP << 0); |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 498 | |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 499 | NDTR1CS0 = (tR << 16) | |
| 500 | (tWHR << 4) | |
| 501 | (tAR << 0); |
| 502 | |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 503 | /* If it doesn't work (unlikely) think about: |
| 504 | * - ecc enable |
| 505 | * - chip select don't care |
| 506 | * - read id byte count |
| 507 | * |
| 508 | * Intentionally enabled by not setting bits: |
| 509 | * - dma (DMA_EN) |
| 510 | * - page size = 512 |
| 511 | * - cs don't care, see if we can enable later! |
| 512 | * - row address start position (after second cycle) |
| 513 | * - pages per block = 32 |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 514 | * - ND_RDY : clears command buffer |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 515 | */ |
Markus Klotzbücher | f8785e9 | 2006-03-03 20:13:43 +0100 | [diff] [blame] | 516 | /* NDCR_NCSX | /\* Chip select busy don't care *\/ */ |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 517 | |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 518 | NDCR = (NDCR_SPARE_EN | /* use the spare area */ |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 519 | NDCR_DWIDTH_C | /* 16bit DFC data bus width */ |
| 520 | NDCR_DWIDTH_M | /* 16 bit Flash device data bus width */ |
Markus Klotzbücher | f9e0291 | 2006-03-06 13:45:42 +0100 | [diff] [blame] | 521 | (2 << 16) | /* read id count = 7 ???? mk@tbd */ |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 522 | NDCR_ND_ARB_EN | /* enable bus arbiter */ |
| 523 | NDCR_RDYM | /* flash device ready ir masked */ |
| 524 | NDCR_CS0_PAGEDM | /* ND_nCSx page done ir masked */ |
| 525 | NDCR_CS1_PAGEDM | |
| 526 | NDCR_CS0_CMDDM | /* ND_CSx command done ir masked */ |
| 527 | NDCR_CS1_CMDDM | |
| 528 | NDCR_CS0_BBDM | /* ND_CSx bad block detect ir masked */ |
| 529 | NDCR_CS1_BBDM | |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 530 | NDCR_DBERRM | /* double bit error ir masked */ |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 531 | NDCR_SBERRM | /* single bit error ir masked */ |
| 532 | NDCR_WRDREQM | /* write data request ir masked */ |
| 533 | NDCR_RDDREQM | /* read data request ir masked */ |
| 534 | NDCR_WRCMDREQM); /* write command request ir masked */ |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 535 | |
Markus Klotzbücher | 481911c | 2006-03-01 23:33:27 +0100 | [diff] [blame] | 536 | |
| 537 | /* wait 10 us due to cmd buffer clear reset */ |
Markus Klotzbuecher | 552fc62 | 2006-03-20 20:19:37 +0100 | [diff] [blame] | 538 | /* wait(10); */ |
Wolfgang Denk | 951a954 | 2006-03-06 23:18:48 +0100 | [diff] [blame] | 539 | |
| 540 | |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 541 | nand->cmd_ctrl = dfc_hwcontrol; |
Markus Klotzbuecher | 552fc62 | 2006-03-20 20:19:37 +0100 | [diff] [blame] | 542 | /* nand->dev_ready = dfc_device_ready; */ |
William Juul | cfa460a | 2007-10-31 13:53:06 +0100 | [diff] [blame] | 543 | nand->ecc.mode = NAND_ECC_SOFT; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 544 | nand->options = NAND_BUSWIDTH_16; |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 545 | nand->waitfunc = dfc_wait; |
| 546 | nand->read_byte = dfc_read_byte; |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 547 | nand->read_word = dfc_read_word; |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 548 | nand->read_buf = dfc_read_buf; |
| 549 | nand->write_buf = dfc_write_buf; |
Markus Klotzbücher | 9187a35 | 2006-03-03 15:37:01 +0100 | [diff] [blame] | 550 | |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 551 | nand->cmdfunc = dfc_cmdfunc; |
William Juul | 5e1dae5 | 2007-11-09 13:32:30 +0100 | [diff] [blame] | 552 | /* nand->autooob = &delta_oob; */ |
Markus Klotzbücher | bf7cac0 | 2006-03-04 18:35:51 +0100 | [diff] [blame] | 553 | nand->badblock_pattern = &delta_bbt_descr; |
Heiko Schocher | fa23044 | 2006-12-21 17:17:02 +0100 | [diff] [blame] | 554 | return 0; |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | #else |
Markus Klotzbücher | 43638c6 | 2006-03-06 15:04:25 +0100 | [diff] [blame] | 558 | #error "U-Boot legacy NAND support not available for Monahans DFC." |
Markus Klotzbücher | 6949328 | 2006-02-28 18:05:25 +0100 | [diff] [blame] | 559 | #endif |
| 560 | #endif |