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