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