Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * drivers/mtd/nand/diskonchip.c |
| 3 | * |
| 4 | * (C) 2003 Red Hat, Inc. |
| 5 | * (C) 2004 Dan Brown <dan_brown@ieee.org> |
| 6 | * (C) 2004 Kalev Lember <kalev@smartlink.ee> |
| 7 | * |
| 8 | * Author: David Woodhouse <dwmw2@infradead.org> |
| 9 | * Additional Diskonchip 2000 and Millennium support by Dan Brown <dan_brown@ieee.org> |
| 10 | * Diskonchip Millennium Plus support by Kalev Lember <kalev@smartlink.ee> |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 11 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | * Error correction code lifted from the old docecc code |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 13 | * Author: Fabrice Bellard (fabrice.bellard@netgem.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * Copyright (C) 2000 Netgem S.A. |
| 15 | * converted to the generic Reed-Solomon library by Thomas Gleixner <tglx@linutronix.de> |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 16 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * Interface to generic NAND code for M-Systems DiskOnChip devices |
| 18 | * |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 19 | * $Id: diskonchip.c,v 1.55 2005/11/07 11:14:30 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/init.h> |
| 24 | #include <linux/sched.h> |
| 25 | #include <linux/delay.h> |
| 26 | #include <linux/rslib.h> |
| 27 | #include <linux/moduleparam.h> |
| 28 | #include <asm/io.h> |
| 29 | |
| 30 | #include <linux/mtd/mtd.h> |
| 31 | #include <linux/mtd/nand.h> |
| 32 | #include <linux/mtd/doc2000.h> |
| 33 | #include <linux/mtd/compatmac.h> |
| 34 | #include <linux/mtd/partitions.h> |
| 35 | #include <linux/mtd/inftl.h> |
| 36 | |
| 37 | /* Where to look for the devices? */ |
Thomas Gleixner | 651078b | 2005-01-31 20:36:46 +0000 | [diff] [blame] | 38 | #ifndef CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS |
| 39 | #define CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #endif |
| 41 | |
| 42 | static unsigned long __initdata doc_locations[] = { |
| 43 | #if defined (__alpha__) || defined(__i386__) || defined(__x86_64__) |
Thomas Gleixner | 651078b | 2005-01-31 20:36:46 +0000 | [diff] [blame] | 44 | #ifdef CONFIG_MTD_NAND_DISKONCHIP_PROBE_HIGH |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 45 | 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000, |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 47 | 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000, |
| 48 | 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000, |
| 50 | #else /* CONFIG_MTD_DOCPROBE_HIGH */ |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 51 | 0xc8000, 0xca000, 0xcc000, 0xce000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | 0xd0000, 0xd2000, 0xd4000, 0xd6000, |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 53 | 0xd8000, 0xda000, 0xdc000, 0xde000, |
| 54 | 0xe0000, 0xe2000, 0xe4000, 0xe6000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | 0xe8000, 0xea000, 0xec000, 0xee000, |
| 56 | #endif /* CONFIG_MTD_DOCPROBE_HIGH */ |
| 57 | #elif defined(__PPC__) |
| 58 | 0xe4000000, |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 59 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #warning Unknown architecture for DiskOnChip. No default probe locations defined |
| 61 | #endif |
| 62 | 0xffffffff }; |
| 63 | |
| 64 | static struct mtd_info *doclist = NULL; |
| 65 | |
| 66 | struct doc_priv { |
| 67 | void __iomem *virtadr; |
| 68 | unsigned long physadr; |
| 69 | u_char ChipID; |
| 70 | u_char CDSNControl; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 71 | int chips_per_floor; /* The number of chips detected on each floor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | int curfloor; |
| 73 | int curchip; |
| 74 | int mh0_page; |
| 75 | int mh1_page; |
| 76 | struct mtd_info *nextdoc; |
| 77 | }; |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* This is the syndrome computed by the HW ecc generator upon reading an empty |
| 80 | page, one with all 0xff for data and stored ecc code. */ |
| 81 | static u_char empty_read_syndrome[6] = { 0x26, 0xff, 0x6d, 0x47, 0x73, 0x7a }; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 82 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | /* This is the ecc value computed by the HW ecc generator upon writing an empty |
| 84 | page, one with all 0xff for data. */ |
| 85 | static u_char empty_write_ecc[6] = { 0x4b, 0x00, 0xe2, 0x0e, 0x93, 0xf7 }; |
| 86 | |
| 87 | #define INFTL_BBT_RESERVED_BLOCKS 4 |
| 88 | |
| 89 | #define DoC_is_MillenniumPlus(doc) ((doc)->ChipID == DOC_ChipID_DocMilPlus16 || (doc)->ChipID == DOC_ChipID_DocMilPlus32) |
| 90 | #define DoC_is_Millennium(doc) ((doc)->ChipID == DOC_ChipID_DocMil) |
| 91 | #define DoC_is_2000(doc) ((doc)->ChipID == DOC_ChipID_Doc2k) |
| 92 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 93 | static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd, |
| 94 | unsigned int bitmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | static void doc200x_select_chip(struct mtd_info *mtd, int chip); |
| 96 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 97 | static int debug = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | module_param(debug, int, 0); |
| 99 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 100 | static int try_dword = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | module_param(try_dword, int, 0); |
| 102 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 103 | static int no_ecc_failures = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | module_param(no_ecc_failures, int, 0); |
| 105 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 106 | static int no_autopart = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | module_param(no_autopart, int, 0); |
Dan Brown | 1a78ff6 | 2005-03-29 21:57:48 +0100 | [diff] [blame] | 108 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 109 | static int show_firmware_partition = 0; |
Dan Brown | 1a78ff6 | 2005-03-29 21:57:48 +0100 | [diff] [blame] | 110 | module_param(show_firmware_partition, int, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
Robert P. J. Day | 89e2bf6 | 2007-03-07 18:33:25 -0500 | [diff] [blame] | 112 | #ifdef CONFIG_MTD_NAND_DISKONCHIP_BBTWRITE |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 113 | static int inftl_bbt_write = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | #else |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 115 | static int inftl_bbt_write = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | #endif |
| 117 | module_param(inftl_bbt_write, int, 0); |
| 118 | |
Thomas Gleixner | 651078b | 2005-01-31 20:36:46 +0000 | [diff] [blame] | 119 | static unsigned long doc_config_location = CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | module_param(doc_config_location, ulong, 0); |
| 121 | MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip"); |
| 122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | /* Sector size for HW ECC */ |
| 124 | #define SECTOR_SIZE 512 |
| 125 | /* The sector bytes are packed into NB_DATA 10 bit words */ |
| 126 | #define NB_DATA (((SECTOR_SIZE + 1) * 8 + 6) / 10) |
| 127 | /* Number of roots */ |
| 128 | #define NROOTS 4 |
| 129 | /* First consective root */ |
| 130 | #define FCR 510 |
| 131 | /* Number of symbols */ |
| 132 | #define NN 1023 |
| 133 | |
| 134 | /* the Reed Solomon control structure */ |
| 135 | static struct rs_control *rs_decoder; |
| 136 | |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 137 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | * The HW decoder in the DoC ASIC's provides us a error syndrome, |
| 139 | * which we must convert to a standard syndrom usable by the generic |
| 140 | * Reed-Solomon library code. |
| 141 | * |
| 142 | * Fabrice Bellard figured this out in the old docecc code. I added |
| 143 | * some comments, improved a minor bit and converted it to make use |
| 144 | * of the generic Reed-Solomon libary. tglx |
| 145 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 146 | static int doc_ecc_decode(struct rs_control *rs, uint8_t *data, uint8_t *ecc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
| 148 | int i, j, nerr, errpos[8]; |
| 149 | uint8_t parity; |
| 150 | uint16_t ds[4], s[5], tmp, errval[8], syn[4]; |
| 151 | |
| 152 | /* Convert the ecc bytes into words */ |
| 153 | ds[0] = ((ecc[4] & 0xff) >> 0) | ((ecc[5] & 0x03) << 8); |
| 154 | ds[1] = ((ecc[5] & 0xfc) >> 2) | ((ecc[2] & 0x0f) << 6); |
| 155 | ds[2] = ((ecc[2] & 0xf0) >> 4) | ((ecc[3] & 0x3f) << 4); |
| 156 | ds[3] = ((ecc[3] & 0xc0) >> 6) | ((ecc[0] & 0xff) << 2); |
| 157 | parity = ecc[1]; |
| 158 | |
| 159 | /* Initialize the syndrom buffer */ |
| 160 | for (i = 0; i < NROOTS; i++) |
| 161 | s[i] = ds[0]; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 162 | /* |
| 163 | * Evaluate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | * s[i] = ds[3]x^3 + ds[2]x^2 + ds[1]x^1 + ds[0] |
| 165 | * where x = alpha^(FCR + i) |
| 166 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 167 | for (j = 1; j < NROOTS; j++) { |
| 168 | if (ds[j] == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | continue; |
| 170 | tmp = rs->index_of[ds[j]]; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 171 | for (i = 0; i < NROOTS; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | s[i] ^= rs->alpha_to[rs_modnn(rs, tmp + (FCR + i) * j)]; |
| 173 | } |
| 174 | |
| 175 | /* Calc s[i] = s[i] / alpha^(v + i) */ |
| 176 | for (i = 0; i < NROOTS; i++) { |
| 177 | if (syn[i]) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 178 | syn[i] = rs_modnn(rs, rs->index_of[s[i]] + (NN - FCR - i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |
| 180 | /* Call the decoder library */ |
| 181 | nerr = decode_rs16(rs, NULL, NULL, 1019, syn, 0, errpos, 0, errval); |
| 182 | |
| 183 | /* Incorrectable errors ? */ |
| 184 | if (nerr < 0) |
| 185 | return nerr; |
| 186 | |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 187 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | * Correct the errors. The bitpositions are a bit of magic, |
| 189 | * but they are given by the design of the de/encoder circuit |
| 190 | * in the DoC ASIC's. |
| 191 | */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 192 | for (i = 0; i < nerr; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | int index, bitpos, pos = 1015 - errpos[i]; |
| 194 | uint8_t val; |
| 195 | if (pos >= NB_DATA && pos < 1019) |
| 196 | continue; |
| 197 | if (pos < NB_DATA) { |
| 198 | /* extract bit position (MSB first) */ |
| 199 | pos = 10 * (NB_DATA - 1 - pos) - 6; |
| 200 | /* now correct the following 10 bits. At most two bytes |
| 201 | can be modified since pos is even */ |
| 202 | index = (pos >> 3) ^ 1; |
| 203 | bitpos = pos & 7; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 204 | if ((index >= 0 && index < SECTOR_SIZE) || index == (SECTOR_SIZE + 1)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | val = (uint8_t) (errval[i] >> (2 + bitpos)); |
| 206 | parity ^= val; |
| 207 | if (index < SECTOR_SIZE) |
| 208 | data[index] ^= val; |
| 209 | } |
| 210 | index = ((pos >> 3) + 1) ^ 1; |
| 211 | bitpos = (bitpos + 10) & 7; |
| 212 | if (bitpos == 0) |
| 213 | bitpos = 8; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 214 | if ((index >= 0 && index < SECTOR_SIZE) || index == (SECTOR_SIZE + 1)) { |
| 215 | val = (uint8_t) (errval[i] << (8 - bitpos)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | parity ^= val; |
| 217 | if (index < SECTOR_SIZE) |
| 218 | data[index] ^= val; |
| 219 | } |
| 220 | } |
| 221 | } |
| 222 | /* If the parity is wrong, no rescue possible */ |
Jörn Engel | eb68450 | 2007-10-20 23:16:32 +0200 | [diff] [blame] | 223 | return parity ? -EBADMSG : nerr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static void DoC_Delay(struct doc_priv *doc, unsigned short cycles) |
| 227 | { |
| 228 | volatile char dummy; |
| 229 | int i; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 230 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | for (i = 0; i < cycles; i++) { |
| 232 | if (DoC_is_Millennium(doc)) |
| 233 | dummy = ReadDOC(doc->virtadr, NOP); |
| 234 | else if (DoC_is_MillenniumPlus(doc)) |
| 235 | dummy = ReadDOC(doc->virtadr, Mplus_NOP); |
| 236 | else |
| 237 | dummy = ReadDOC(doc->virtadr, DOCStatus); |
| 238 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 239 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | #define CDSN_CTRL_FR_B_MASK (CDSN_CTRL_FR_B0 | CDSN_CTRL_FR_B1) |
| 243 | |
| 244 | /* DOC_WaitReady: Wait for RDY line to be asserted by the flash chip */ |
| 245 | static int _DoC_WaitReady(struct doc_priv *doc) |
| 246 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 247 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | unsigned long timeo = jiffies + (HZ * 10); |
| 249 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 250 | if (debug) |
| 251 | printk("_DoC_WaitReady...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | /* Out-of-line routine to wait for chip response */ |
| 253 | if (DoC_is_MillenniumPlus(doc)) { |
| 254 | while ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) { |
| 255 | if (time_after(jiffies, timeo)) { |
| 256 | printk("_DoC_WaitReady timed out.\n"); |
| 257 | return -EIO; |
| 258 | } |
| 259 | udelay(1); |
| 260 | cond_resched(); |
| 261 | } |
| 262 | } else { |
| 263 | while (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) { |
| 264 | if (time_after(jiffies, timeo)) { |
| 265 | printk("_DoC_WaitReady timed out.\n"); |
| 266 | return -EIO; |
| 267 | } |
| 268 | udelay(1); |
| 269 | cond_resched(); |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | return 0; |
| 274 | } |
| 275 | |
| 276 | static inline int DoC_WaitReady(struct doc_priv *doc) |
| 277 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 278 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | int ret = 0; |
| 280 | |
| 281 | if (DoC_is_MillenniumPlus(doc)) { |
| 282 | DoC_Delay(doc, 4); |
| 283 | |
| 284 | if ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) |
| 285 | /* Call the out-of-line routine to wait */ |
| 286 | ret = _DoC_WaitReady(doc); |
| 287 | } else { |
| 288 | DoC_Delay(doc, 4); |
| 289 | |
| 290 | if (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) |
| 291 | /* Call the out-of-line routine to wait */ |
| 292 | ret = _DoC_WaitReady(doc); |
| 293 | DoC_Delay(doc, 2); |
| 294 | } |
| 295 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 296 | if (debug) |
| 297 | printk("DoC_WaitReady OK\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | return ret; |
| 299 | } |
| 300 | |
| 301 | static void doc2000_write_byte(struct mtd_info *mtd, u_char datum) |
| 302 | { |
| 303 | struct nand_chip *this = mtd->priv; |
| 304 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 305 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 307 | if (debug) |
| 308 | printk("write_byte %02x\n", datum); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | WriteDOC(datum, docptr, CDSNSlowIO); |
| 310 | WriteDOC(datum, docptr, 2k_CDSN_IO); |
| 311 | } |
| 312 | |
| 313 | static u_char doc2000_read_byte(struct mtd_info *mtd) |
| 314 | { |
| 315 | struct nand_chip *this = mtd->priv; |
| 316 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 317 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | u_char ret; |
| 319 | |
| 320 | ReadDOC(docptr, CDSNSlowIO); |
| 321 | DoC_Delay(doc, 2); |
| 322 | ret = ReadDOC(docptr, 2k_CDSN_IO); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 323 | if (debug) |
| 324 | printk("read_byte returns %02x\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | return ret; |
| 326 | } |
| 327 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 328 | static void doc2000_writebuf(struct mtd_info *mtd, const u_char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
| 330 | struct nand_chip *this = mtd->priv; |
| 331 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 332 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | int i; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 334 | if (debug) |
| 335 | printk("writebuf of %d bytes: ", len); |
| 336 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | WriteDOC_(buf[i], docptr, DoC_2k_CDSN_IO + i); |
| 338 | if (debug && i < 16) |
| 339 | printk("%02x ", buf[i]); |
| 340 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 341 | if (debug) |
| 342 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 345 | static void doc2000_readbuf(struct mtd_info *mtd, u_char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | { |
| 347 | struct nand_chip *this = mtd->priv; |
| 348 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 349 | void __iomem *docptr = doc->virtadr; |
| 350 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 352 | if (debug) |
| 353 | printk("readbuf of %d bytes: ", len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 355 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | buf[i] = ReadDOC(docptr, 2k_CDSN_IO + i); |
| 357 | } |
| 358 | } |
| 359 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 360 | static void doc2000_readbuf_dword(struct mtd_info *mtd, u_char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | { |
| 362 | struct nand_chip *this = mtd->priv; |
| 363 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 364 | void __iomem *docptr = doc->virtadr; |
| 365 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 367 | if (debug) |
| 368 | printk("readbuf_dword of %d bytes: ", len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 370 | if (unlikely((((unsigned long)buf) | len) & 3)) { |
| 371 | for (i = 0; i < len; i++) { |
| 372 | *(uint8_t *) (&buf[i]) = ReadDOC(docptr, 2k_CDSN_IO + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | } else { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 375 | for (i = 0; i < len; i += 4) { |
| 376 | *(uint32_t *) (&buf[i]) = readl(docptr + DoC_2k_CDSN_IO + i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | } |
| 379 | } |
| 380 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 381 | static int doc2000_verifybuf(struct mtd_info *mtd, const u_char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | { |
| 383 | struct nand_chip *this = mtd->priv; |
| 384 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 385 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | int i; |
| 387 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 388 | for (i = 0; i < len; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | if (buf[i] != ReadDOC(docptr, 2k_CDSN_IO)) |
| 390 | return -EFAULT; |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | static uint16_t __init doc200x_ident_chip(struct mtd_info *mtd, int nr) |
| 395 | { |
| 396 | struct nand_chip *this = mtd->priv; |
| 397 | struct doc_priv *doc = this->priv; |
| 398 | uint16_t ret; |
| 399 | |
| 400 | doc200x_select_chip(mtd, nr); |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 401 | doc200x_hwcontrol(mtd, NAND_CMD_READID, |
| 402 | NAND_CTRL_CLE | NAND_CTRL_CHANGE); |
| 403 | doc200x_hwcontrol(mtd, 0, NAND_CTRL_ALE | NAND_CTRL_CHANGE); |
| 404 | doc200x_hwcontrol(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 405 | |
Thomas Gleixner | dfd6129 | 2005-02-22 21:48:25 +0000 | [diff] [blame] | 406 | /* We cant' use dev_ready here, but at least we wait for the |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 407 | * command to complete |
Thomas Gleixner | dfd6129 | 2005-02-22 21:48:25 +0000 | [diff] [blame] | 408 | */ |
| 409 | udelay(50); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | ret = this->read_byte(mtd) << 8; |
| 412 | ret |= this->read_byte(mtd); |
| 413 | |
| 414 | if (doc->ChipID == DOC_ChipID_Doc2k && try_dword && !nr) { |
| 415 | /* First chip probe. See if we get same results by 32-bit access */ |
| 416 | union { |
| 417 | uint32_t dword; |
| 418 | uint8_t byte[4]; |
| 419 | } ident; |
| 420 | void __iomem *docptr = doc->virtadr; |
| 421 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 422 | doc200x_hwcontrol(mtd, NAND_CMD_READID, |
| 423 | NAND_CTRL_CLE | NAND_CTRL_CHANGE); |
| 424 | doc200x_hwcontrol(mtd, 0, NAND_CTRL_ALE | NAND_CTRL_CHANGE); |
| 425 | doc200x_hwcontrol(mtd, NAND_CMD_NONE, |
| 426 | NAND_NCE | NAND_CTRL_CHANGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Thomas Gleixner | dfd6129 | 2005-02-22 21:48:25 +0000 | [diff] [blame] | 428 | udelay(50); |
| 429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | ident.dword = readl(docptr + DoC_2k_CDSN_IO); |
| 431 | if (((ident.byte[0] << 8) | ident.byte[1]) == ret) { |
| 432 | printk(KERN_INFO "DiskOnChip 2000 responds to DWORD access\n"); |
| 433 | this->read_buf = &doc2000_readbuf_dword; |
| 434 | } |
| 435 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 436 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | return ret; |
| 438 | } |
| 439 | |
| 440 | static void __init doc2000_count_chips(struct mtd_info *mtd) |
| 441 | { |
| 442 | struct nand_chip *this = mtd->priv; |
| 443 | struct doc_priv *doc = this->priv; |
| 444 | uint16_t mfrid; |
| 445 | int i; |
| 446 | |
| 447 | /* Max 4 chips per floor on DiskOnChip 2000 */ |
| 448 | doc->chips_per_floor = 4; |
| 449 | |
| 450 | /* Find out what the first chip is */ |
| 451 | mfrid = doc200x_ident_chip(mtd, 0); |
| 452 | |
| 453 | /* Find how many chips in each floor. */ |
| 454 | for (i = 1; i < 4; i++) { |
| 455 | if (doc200x_ident_chip(mtd, i) != mfrid) |
| 456 | break; |
| 457 | } |
| 458 | doc->chips_per_floor = i; |
| 459 | printk(KERN_DEBUG "Detected %d chips per floor.\n", i); |
| 460 | } |
| 461 | |
Thomas Gleixner | 7bc3312 | 2006-06-20 20:05:05 +0200 | [diff] [blame] | 462 | static int doc200x_wait(struct mtd_info *mtd, struct nand_chip *this) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | { |
| 464 | struct doc_priv *doc = this->priv; |
| 465 | |
| 466 | int status; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | DoC_WaitReady(doc); |
| 469 | this->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); |
| 470 | DoC_WaitReady(doc); |
| 471 | status = (int)this->read_byte(mtd); |
| 472 | |
| 473 | return status; |
| 474 | } |
| 475 | |
| 476 | static void doc2001_write_byte(struct mtd_info *mtd, u_char datum) |
| 477 | { |
| 478 | struct nand_chip *this = mtd->priv; |
| 479 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 480 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | |
| 482 | WriteDOC(datum, docptr, CDSNSlowIO); |
| 483 | WriteDOC(datum, docptr, Mil_CDSN_IO); |
| 484 | WriteDOC(datum, docptr, WritePipeTerm); |
| 485 | } |
| 486 | |
| 487 | static u_char doc2001_read_byte(struct mtd_info *mtd) |
| 488 | { |
| 489 | struct nand_chip *this = mtd->priv; |
| 490 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 491 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | //ReadDOC(docptr, CDSNSlowIO); |
| 494 | /* 11.4.5 -- delay twice to allow extended length cycle */ |
| 495 | DoC_Delay(doc, 2); |
| 496 | ReadDOC(docptr, ReadPipeInit); |
| 497 | //return ReadDOC(docptr, Mil_CDSN_IO); |
| 498 | return ReadDOC(docptr, LastDataRead); |
| 499 | } |
| 500 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 501 | static void doc2001_writebuf(struct mtd_info *mtd, const u_char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | { |
| 503 | struct nand_chip *this = mtd->priv; |
| 504 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 505 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | int i; |
| 507 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 508 | for (i = 0; i < len; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | WriteDOC_(buf[i], docptr, DoC_Mil_CDSN_IO + i); |
| 510 | /* Terminate write pipeline */ |
| 511 | WriteDOC(0x00, docptr, WritePipeTerm); |
| 512 | } |
| 513 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 514 | static void doc2001_readbuf(struct mtd_info *mtd, u_char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | { |
| 516 | struct nand_chip *this = mtd->priv; |
| 517 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 518 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | int i; |
| 520 | |
| 521 | /* Start read pipeline */ |
| 522 | ReadDOC(docptr, ReadPipeInit); |
| 523 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 524 | for (i = 0; i < len - 1; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | buf[i] = ReadDOC(docptr, Mil_CDSN_IO + (i & 0xff)); |
| 526 | |
| 527 | /* Terminate read pipeline */ |
| 528 | buf[i] = ReadDOC(docptr, LastDataRead); |
| 529 | } |
| 530 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 531 | static int doc2001_verifybuf(struct mtd_info *mtd, const u_char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
| 533 | struct nand_chip *this = mtd->priv; |
| 534 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 535 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | int i; |
| 537 | |
| 538 | /* Start read pipeline */ |
| 539 | ReadDOC(docptr, ReadPipeInit); |
| 540 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 541 | for (i = 0; i < len - 1; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | if (buf[i] != ReadDOC(docptr, Mil_CDSN_IO)) { |
| 543 | ReadDOC(docptr, LastDataRead); |
| 544 | return i; |
| 545 | } |
| 546 | if (buf[i] != ReadDOC(docptr, LastDataRead)) |
| 547 | return i; |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | static u_char doc2001plus_read_byte(struct mtd_info *mtd) |
| 552 | { |
| 553 | struct nand_chip *this = mtd->priv; |
| 554 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 555 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | u_char ret; |
| 557 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 558 | ReadDOC(docptr, Mplus_ReadPipeInit); |
| 559 | ReadDOC(docptr, Mplus_ReadPipeInit); |
| 560 | ret = ReadDOC(docptr, Mplus_LastDataRead); |
| 561 | if (debug) |
| 562 | printk("read_byte returns %02x\n", ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | return ret; |
| 564 | } |
| 565 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 566 | static void doc2001plus_writebuf(struct mtd_info *mtd, const u_char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | { |
| 568 | struct nand_chip *this = mtd->priv; |
| 569 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 570 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | int i; |
| 572 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 573 | if (debug) |
| 574 | printk("writebuf of %d bytes: ", len); |
| 575 | for (i = 0; i < len; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | WriteDOC_(buf[i], docptr, DoC_Mil_CDSN_IO + i); |
| 577 | if (debug && i < 16) |
| 578 | printk("%02x ", buf[i]); |
| 579 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 580 | if (debug) |
| 581 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } |
| 583 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 584 | static void doc2001plus_readbuf(struct mtd_info *mtd, u_char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | { |
| 586 | struct nand_chip *this = mtd->priv; |
| 587 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 588 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | int i; |
| 590 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 591 | if (debug) |
| 592 | printk("readbuf of %d bytes: ", len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
| 594 | /* Start read pipeline */ |
| 595 | ReadDOC(docptr, Mplus_ReadPipeInit); |
| 596 | ReadDOC(docptr, Mplus_ReadPipeInit); |
| 597 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 598 | for (i = 0; i < len - 2; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | buf[i] = ReadDOC(docptr, Mil_CDSN_IO); |
| 600 | if (debug && i < 16) |
| 601 | printk("%02x ", buf[i]); |
| 602 | } |
| 603 | |
| 604 | /* Terminate read pipeline */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 605 | buf[len - 2] = ReadDOC(docptr, Mplus_LastDataRead); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | if (debug && i < 16) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 607 | printk("%02x ", buf[len - 2]); |
| 608 | buf[len - 1] = ReadDOC(docptr, Mplus_LastDataRead); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | if (debug && i < 16) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 610 | printk("%02x ", buf[len - 1]); |
| 611 | if (debug) |
| 612 | printk("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
| 614 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 615 | static int doc2001plus_verifybuf(struct mtd_info *mtd, const u_char *buf, int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | { |
| 617 | struct nand_chip *this = mtd->priv; |
| 618 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 619 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | int i; |
| 621 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 622 | if (debug) |
| 623 | printk("verifybuf of %d bytes: ", len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | /* Start read pipeline */ |
| 626 | ReadDOC(docptr, Mplus_ReadPipeInit); |
| 627 | ReadDOC(docptr, Mplus_ReadPipeInit); |
| 628 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 629 | for (i = 0; i < len - 2; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | if (buf[i] != ReadDOC(docptr, Mil_CDSN_IO)) { |
| 631 | ReadDOC(docptr, Mplus_LastDataRead); |
| 632 | ReadDOC(docptr, Mplus_LastDataRead); |
| 633 | return i; |
| 634 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 635 | if (buf[len - 2] != ReadDOC(docptr, Mplus_LastDataRead)) |
| 636 | return len - 2; |
| 637 | if (buf[len - 1] != ReadDOC(docptr, Mplus_LastDataRead)) |
| 638 | return len - 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | return 0; |
| 640 | } |
| 641 | |
| 642 | static void doc2001plus_select_chip(struct mtd_info *mtd, int chip) |
| 643 | { |
| 644 | struct nand_chip *this = mtd->priv; |
| 645 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 646 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | int floor = 0; |
| 648 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 649 | if (debug) |
| 650 | printk("select chip (%d)\n", chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | |
| 652 | if (chip == -1) { |
| 653 | /* Disable flash internally */ |
| 654 | WriteDOC(0, docptr, Mplus_FlashSelect); |
| 655 | return; |
| 656 | } |
| 657 | |
| 658 | floor = chip / doc->chips_per_floor; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 659 | chip -= (floor * doc->chips_per_floor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | |
| 661 | /* Assert ChipEnable and deassert WriteProtect */ |
| 662 | WriteDOC((DOC_FLASH_CE), docptr, Mplus_FlashSelect); |
| 663 | this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); |
| 664 | |
| 665 | doc->curchip = chip; |
| 666 | doc->curfloor = floor; |
| 667 | } |
| 668 | |
| 669 | static void doc200x_select_chip(struct mtd_info *mtd, int chip) |
| 670 | { |
| 671 | struct nand_chip *this = mtd->priv; |
| 672 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 673 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | int floor = 0; |
| 675 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 676 | if (debug) |
| 677 | printk("select chip (%d)\n", chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
| 679 | if (chip == -1) |
| 680 | return; |
| 681 | |
| 682 | floor = chip / doc->chips_per_floor; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 683 | chip -= (floor * doc->chips_per_floor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
| 685 | /* 11.4.4 -- deassert CE before changing chip */ |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 686 | doc200x_hwcontrol(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | |
| 688 | WriteDOC(floor, docptr, FloorSelect); |
| 689 | WriteDOC(chip, docptr, CDSNDeviceSelect); |
| 690 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 691 | doc200x_hwcontrol(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | |
| 693 | doc->curchip = chip; |
| 694 | doc->curfloor = floor; |
| 695 | } |
| 696 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 697 | #define CDSN_CTRL_MSK (CDSN_CTRL_CE | CDSN_CTRL_CLE | CDSN_CTRL_ALE) |
| 698 | |
| 699 | static void doc200x_hwcontrol(struct mtd_info *mtd, int cmd, |
| 700 | unsigned int ctrl) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | { |
| 702 | struct nand_chip *this = mtd->priv; |
| 703 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 704 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 706 | if (ctrl & NAND_CTRL_CHANGE) { |
| 707 | doc->CDSNControl &= ~CDSN_CTRL_MSK; |
| 708 | doc->CDSNControl |= ctrl & CDSN_CTRL_MSK; |
| 709 | if (debug) |
| 710 | printk("hwcontrol(%d): %02x\n", cmd, doc->CDSNControl); |
| 711 | WriteDOC(doc->CDSNControl, docptr, CDSNControl); |
| 712 | /* 11.4.3 -- 4 NOPs after CSDNControl write */ |
| 713 | DoC_Delay(doc, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | } |
Thomas Gleixner | cad74f2 | 2006-05-23 23:28:48 +0200 | [diff] [blame] | 715 | if (cmd != NAND_CMD_NONE) { |
| 716 | if (DoC_is_2000(doc)) |
| 717 | doc2000_write_byte(mtd, cmd); |
| 718 | else |
| 719 | doc2001_write_byte(mtd, cmd); |
| 720 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | } |
| 722 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 723 | static void doc2001plus_command(struct mtd_info *mtd, unsigned command, int column, int page_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | { |
| 725 | struct nand_chip *this = mtd->priv; |
| 726 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 727 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | |
| 729 | /* |
| 730 | * Must terminate write pipeline before sending any commands |
| 731 | * to the device. |
| 732 | */ |
| 733 | if (command == NAND_CMD_PAGEPROG) { |
| 734 | WriteDOC(0x00, docptr, Mplus_WritePipeTerm); |
| 735 | WriteDOC(0x00, docptr, Mplus_WritePipeTerm); |
| 736 | } |
| 737 | |
| 738 | /* |
| 739 | * Write out the command to the device. |
| 740 | */ |
| 741 | if (command == NAND_CMD_SEQIN) { |
| 742 | int readcmd; |
| 743 | |
Joern Engel | 2831877 | 2006-05-22 23:18:05 +0200 | [diff] [blame] | 744 | if (column >= mtd->writesize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | /* OOB area */ |
Joern Engel | 2831877 | 2006-05-22 23:18:05 +0200 | [diff] [blame] | 746 | column -= mtd->writesize; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | readcmd = NAND_CMD_READOOB; |
| 748 | } else if (column < 256) { |
| 749 | /* First 256 bytes --> READ0 */ |
| 750 | readcmd = NAND_CMD_READ0; |
| 751 | } else { |
| 752 | column -= 256; |
| 753 | readcmd = NAND_CMD_READ1; |
| 754 | } |
| 755 | WriteDOC(readcmd, docptr, Mplus_FlashCmd); |
| 756 | } |
| 757 | WriteDOC(command, docptr, Mplus_FlashCmd); |
| 758 | WriteDOC(0, docptr, Mplus_WritePipeTerm); |
| 759 | WriteDOC(0, docptr, Mplus_WritePipeTerm); |
| 760 | |
| 761 | if (column != -1 || page_addr != -1) { |
| 762 | /* Serially input address */ |
| 763 | if (column != -1) { |
| 764 | /* Adjust columns for 16 bit buswidth */ |
| 765 | if (this->options & NAND_BUSWIDTH_16) |
| 766 | column >>= 1; |
| 767 | WriteDOC(column, docptr, Mplus_FlashAddress); |
| 768 | } |
| 769 | if (page_addr != -1) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 770 | WriteDOC((unsigned char)(page_addr & 0xff), docptr, Mplus_FlashAddress); |
| 771 | WriteDOC((unsigned char)((page_addr >> 8) & 0xff), docptr, Mplus_FlashAddress); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | /* One more address cycle for higher density devices */ |
| 773 | if (this->chipsize & 0x0c000000) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 774 | WriteDOC((unsigned char)((page_addr >> 16) & 0x0f), docptr, Mplus_FlashAddress); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | printk("high density\n"); |
| 776 | } |
| 777 | } |
| 778 | WriteDOC(0, docptr, Mplus_WritePipeTerm); |
| 779 | WriteDOC(0, docptr, Mplus_WritePipeTerm); |
| 780 | /* deassert ALE */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 781 | if (command == NAND_CMD_READ0 || command == NAND_CMD_READ1 || |
| 782 | command == NAND_CMD_READOOB || command == NAND_CMD_READID) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | WriteDOC(0, docptr, Mplus_FlashControl); |
| 784 | } |
| 785 | |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 786 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | * program and erase have their own busy handlers |
| 788 | * status and sequential in needs no delay |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 789 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | switch (command) { |
| 791 | |
| 792 | case NAND_CMD_PAGEPROG: |
| 793 | case NAND_CMD_ERASE1: |
| 794 | case NAND_CMD_ERASE2: |
| 795 | case NAND_CMD_SEQIN: |
| 796 | case NAND_CMD_STATUS: |
| 797 | return; |
| 798 | |
| 799 | case NAND_CMD_RESET: |
| 800 | if (this->dev_ready) |
| 801 | break; |
| 802 | udelay(this->chip_delay); |
| 803 | WriteDOC(NAND_CMD_STATUS, docptr, Mplus_FlashCmd); |
| 804 | WriteDOC(0, docptr, Mplus_WritePipeTerm); |
| 805 | WriteDOC(0, docptr, Mplus_WritePipeTerm); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 806 | while (!(this->read_byte(mtd) & 0x40)) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | return; |
| 808 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 809 | /* This applies to read commands */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | default: |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 811 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | * If we don't have access to the busy pin, we apply the given |
| 813 | * command delay |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 814 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | if (!this->dev_ready) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 816 | udelay(this->chip_delay); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | return; |
| 818 | } |
| 819 | } |
| 820 | |
| 821 | /* Apply this short delay always to ensure that we do wait tWB in |
| 822 | * any case on any machine. */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 823 | ndelay(100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | /* wait until command is processed */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 825 | while (!this->dev_ready(mtd)) ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | } |
| 827 | |
| 828 | static int doc200x_dev_ready(struct mtd_info *mtd) |
| 829 | { |
| 830 | struct nand_chip *this = mtd->priv; |
| 831 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 832 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
| 834 | if (DoC_is_MillenniumPlus(doc)) { |
| 835 | /* 11.4.2 -- must NOP four times before checking FR/B# */ |
| 836 | DoC_Delay(doc, 4); |
| 837 | if ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 838 | if (debug) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | printk("not ready\n"); |
| 840 | return 0; |
| 841 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 842 | if (debug) |
| 843 | printk("was ready\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | return 1; |
| 845 | } else { |
| 846 | /* 11.4.2 -- must NOP four times before checking FR/B# */ |
| 847 | DoC_Delay(doc, 4); |
| 848 | if (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 849 | if (debug) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | printk("not ready\n"); |
| 851 | return 0; |
| 852 | } |
| 853 | /* 11.4.2 -- Must NOP twice if it's ready */ |
| 854 | DoC_Delay(doc, 2); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 855 | if (debug) |
| 856 | printk("was ready\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | return 1; |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | static int doc200x_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip) |
| 862 | { |
| 863 | /* This is our last resort if we couldn't find or create a BBT. Just |
| 864 | pretend all blocks are good. */ |
| 865 | return 0; |
| 866 | } |
| 867 | |
| 868 | static void doc200x_enable_hwecc(struct mtd_info *mtd, int mode) |
| 869 | { |
| 870 | struct nand_chip *this = mtd->priv; |
| 871 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 872 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
| 874 | /* Prime the ECC engine */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 875 | switch (mode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | case NAND_ECC_READ: |
| 877 | WriteDOC(DOC_ECC_RESET, docptr, ECCConf); |
| 878 | WriteDOC(DOC_ECC_EN, docptr, ECCConf); |
| 879 | break; |
| 880 | case NAND_ECC_WRITE: |
| 881 | WriteDOC(DOC_ECC_RESET, docptr, ECCConf); |
| 882 | WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, ECCConf); |
| 883 | break; |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | static void doc2001plus_enable_hwecc(struct mtd_info *mtd, int mode) |
| 888 | { |
| 889 | struct nand_chip *this = mtd->priv; |
| 890 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 891 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | |
| 893 | /* Prime the ECC engine */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 894 | switch (mode) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | case NAND_ECC_READ: |
| 896 | WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf); |
| 897 | WriteDOC(DOC_ECC_EN, docptr, Mplus_ECCConf); |
| 898 | break; |
| 899 | case NAND_ECC_WRITE: |
| 900 | WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf); |
| 901 | WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, Mplus_ECCConf); |
| 902 | break; |
| 903 | } |
| 904 | } |
| 905 | |
| 906 | /* This code is only called on write */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 907 | static int doc200x_calculate_ecc(struct mtd_info *mtd, const u_char *dat, unsigned char *ecc_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | { |
| 909 | struct nand_chip *this = mtd->priv; |
| 910 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 911 | void __iomem *docptr = doc->virtadr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | int i; |
| 913 | int emptymatch = 1; |
| 914 | |
| 915 | /* flush the pipeline */ |
| 916 | if (DoC_is_2000(doc)) { |
| 917 | WriteDOC(doc->CDSNControl & ~CDSN_CTRL_FLASH_IO, docptr, CDSNControl); |
| 918 | WriteDOC(0, docptr, 2k_CDSN_IO); |
| 919 | WriteDOC(0, docptr, 2k_CDSN_IO); |
| 920 | WriteDOC(0, docptr, 2k_CDSN_IO); |
| 921 | WriteDOC(doc->CDSNControl, docptr, CDSNControl); |
| 922 | } else if (DoC_is_MillenniumPlus(doc)) { |
| 923 | WriteDOC(0, docptr, Mplus_NOP); |
| 924 | WriteDOC(0, docptr, Mplus_NOP); |
| 925 | WriteDOC(0, docptr, Mplus_NOP); |
| 926 | } else { |
| 927 | WriteDOC(0, docptr, NOP); |
| 928 | WriteDOC(0, docptr, NOP); |
| 929 | WriteDOC(0, docptr, NOP); |
| 930 | } |
| 931 | |
| 932 | for (i = 0; i < 6; i++) { |
| 933 | if (DoC_is_MillenniumPlus(doc)) |
| 934 | ecc_code[i] = ReadDOC_(docptr, DoC_Mplus_ECCSyndrome0 + i); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 935 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | ecc_code[i] = ReadDOC_(docptr, DoC_ECCSyndrome0 + i); |
| 937 | if (ecc_code[i] != empty_write_ecc[i]) |
| 938 | emptymatch = 0; |
| 939 | } |
| 940 | if (DoC_is_MillenniumPlus(doc)) |
| 941 | WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf); |
| 942 | else |
| 943 | WriteDOC(DOC_ECC_DIS, docptr, ECCConf); |
| 944 | #if 0 |
| 945 | /* If emptymatch=1, we might have an all-0xff data buffer. Check. */ |
| 946 | if (emptymatch) { |
| 947 | /* Note: this somewhat expensive test should not be triggered |
| 948 | often. It could be optimized away by examining the data in |
| 949 | the writebuf routine, and remembering the result. */ |
| 950 | for (i = 0; i < 512; i++) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 951 | if (dat[i] == 0xff) |
| 952 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | emptymatch = 0; |
| 954 | break; |
| 955 | } |
| 956 | } |
| 957 | /* If emptymatch still =1, we do have an all-0xff data buffer. |
| 958 | Return all-0xff ecc value instead of the computed one, so |
| 959 | it'll look just like a freshly-erased page. */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 960 | if (emptymatch) |
| 961 | memset(ecc_code, 0xff, 6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | #endif |
| 963 | return 0; |
| 964 | } |
| 965 | |
Thomas Gleixner | f5bbdac | 2006-05-25 10:07:16 +0200 | [diff] [blame] | 966 | static int doc200x_correct_data(struct mtd_info *mtd, u_char *dat, |
| 967 | u_char *read_ecc, u_char *isnull) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | { |
| 969 | int i, ret = 0; |
| 970 | struct nand_chip *this = mtd->priv; |
| 971 | struct doc_priv *doc = this->priv; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 972 | void __iomem *docptr = doc->virtadr; |
Thomas Gleixner | f5bbdac | 2006-05-25 10:07:16 +0200 | [diff] [blame] | 973 | uint8_t calc_ecc[6]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | volatile u_char dummy; |
| 975 | int emptymatch = 1; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 976 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | /* flush the pipeline */ |
| 978 | if (DoC_is_2000(doc)) { |
| 979 | dummy = ReadDOC(docptr, 2k_ECCStatus); |
| 980 | dummy = ReadDOC(docptr, 2k_ECCStatus); |
| 981 | dummy = ReadDOC(docptr, 2k_ECCStatus); |
| 982 | } else if (DoC_is_MillenniumPlus(doc)) { |
| 983 | dummy = ReadDOC(docptr, Mplus_ECCConf); |
| 984 | dummy = ReadDOC(docptr, Mplus_ECCConf); |
| 985 | dummy = ReadDOC(docptr, Mplus_ECCConf); |
| 986 | } else { |
| 987 | dummy = ReadDOC(docptr, ECCConf); |
| 988 | dummy = ReadDOC(docptr, ECCConf); |
| 989 | dummy = ReadDOC(docptr, ECCConf); |
| 990 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | /* Error occured ? */ |
| 993 | if (dummy & 0x80) { |
| 994 | for (i = 0; i < 6; i++) { |
| 995 | if (DoC_is_MillenniumPlus(doc)) |
| 996 | calc_ecc[i] = ReadDOC_(docptr, DoC_Mplus_ECCSyndrome0 + i); |
| 997 | else |
| 998 | calc_ecc[i] = ReadDOC_(docptr, DoC_ECCSyndrome0 + i); |
| 999 | if (calc_ecc[i] != empty_read_syndrome[i]) |
| 1000 | emptymatch = 0; |
| 1001 | } |
| 1002 | /* If emptymatch=1, the read syndrome is consistent with an |
| 1003 | all-0xff data and stored ecc block. Check the stored ecc. */ |
| 1004 | if (emptymatch) { |
| 1005 | for (i = 0; i < 6; i++) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1006 | if (read_ecc[i] == 0xff) |
| 1007 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1008 | emptymatch = 0; |
| 1009 | break; |
| 1010 | } |
| 1011 | } |
| 1012 | /* If emptymatch still =1, check the data block. */ |
| 1013 | if (emptymatch) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1014 | /* Note: this somewhat expensive test should not be triggered |
| 1015 | often. It could be optimized away by examining the data in |
| 1016 | the readbuf routine, and remembering the result. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | for (i = 0; i < 512; i++) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1018 | if (dat[i] == 0xff) |
| 1019 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | emptymatch = 0; |
| 1021 | break; |
| 1022 | } |
| 1023 | } |
| 1024 | /* If emptymatch still =1, this is almost certainly a freshly- |
| 1025 | erased block, in which case the ECC will not come out right. |
| 1026 | We'll suppress the error and tell the caller everything's |
| 1027 | OK. Because it is. */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1028 | if (!emptymatch) |
| 1029 | ret = doc_ecc_decode(rs_decoder, dat, calc_ecc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | if (ret > 0) |
| 1031 | printk(KERN_ERR "doc200x_correct_data corrected %d errors\n", ret); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1032 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | if (DoC_is_MillenniumPlus(doc)) |
| 1034 | WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf); |
| 1035 | else |
| 1036 | WriteDOC(DOC_ECC_DIS, docptr, ECCConf); |
Jörn Engel | eb68450 | 2007-10-20 23:16:32 +0200 | [diff] [blame] | 1037 | if (no_ecc_failures && (ret == -EBADMSG)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | printk(KERN_ERR "suppressing ECC failure\n"); |
| 1039 | ret = 0; |
| 1040 | } |
| 1041 | return ret; |
| 1042 | } |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | //u_char mydatabuf[528]; |
| 1045 | |
Dan Brown | abc37e6 | 2005-04-07 15:22:58 +0100 | [diff] [blame] | 1046 | /* The strange out-of-order .oobfree list below is a (possibly unneeded) |
| 1047 | * attempt to retain compatibility. It used to read: |
| 1048 | * .oobfree = { {8, 8} } |
| 1049 | * Since that leaves two bytes unusable, it was changed. But the following |
| 1050 | * scheme might affect existing jffs2 installs by moving the cleanmarker: |
| 1051 | * .oobfree = { {6, 10} } |
| 1052 | * jffs2 seems to handle the above gracefully, but the current scheme seems |
| 1053 | * safer. The only problem with it is that any code that parses oobfree must |
| 1054 | * be able to handle out-of-order segments. |
| 1055 | */ |
Thomas Gleixner | 5bd34c0 | 2006-05-27 22:16:10 +0200 | [diff] [blame] | 1056 | static struct nand_ecclayout doc200x_oobinfo = { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1057 | .eccbytes = 6, |
| 1058 | .eccpos = {0, 1, 2, 3, 4, 5}, |
| 1059 | .oobfree = {{8, 8}, {6, 2}} |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | }; |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | /* Find the (I)NFTL Media Header, and optionally also the mirror media header. |
| 1063 | On sucessful return, buf will contain a copy of the media header for |
| 1064 | further processing. id is the string to scan for, and will presumably be |
| 1065 | either "ANAND" or "BNAND". If findmirror=1, also look for the mirror media |
| 1066 | header. The page #s of the found media headers are placed in mh0_page and |
| 1067 | mh1_page in the DOC private structure. */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1068 | static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const char *id, int findmirror) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | { |
| 1070 | struct nand_chip *this = mtd->priv; |
| 1071 | struct doc_priv *doc = this->priv; |
Dan Brown | 1a78ff6 | 2005-03-29 21:57:48 +0100 | [diff] [blame] | 1072 | unsigned offs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | int ret; |
| 1074 | size_t retlen; |
| 1075 | |
Dan Brown | 1a78ff6 | 2005-03-29 21:57:48 +0100 | [diff] [blame] | 1076 | for (offs = 0; offs < mtd->size; offs += mtd->erasesize) { |
Joern Engel | 2831877 | 2006-05-22 23:18:05 +0200 | [diff] [blame] | 1077 | ret = mtd->read(mtd, offs, mtd->writesize, &retlen, buf); |
| 1078 | if (retlen != mtd->writesize) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1079 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | if (ret) { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1081 | printk(KERN_WARNING "ECC error scanning DOC at 0x%x\n", offs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1083 | if (memcmp(buf, id, 6)) |
| 1084 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | printk(KERN_INFO "Found DiskOnChip %s Media Header at 0x%x\n", id, offs); |
| 1086 | if (doc->mh0_page == -1) { |
| 1087 | doc->mh0_page = offs >> this->page_shift; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1088 | if (!findmirror) |
| 1089 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | continue; |
| 1091 | } |
| 1092 | doc->mh1_page = offs >> this->page_shift; |
| 1093 | return 2; |
| 1094 | } |
| 1095 | if (doc->mh0_page == -1) { |
| 1096 | printk(KERN_WARNING "DiskOnChip %s Media Header not found.\n", id); |
| 1097 | return 0; |
| 1098 | } |
| 1099 | /* Only one mediaheader was found. We want buf to contain a |
| 1100 | mediaheader on return, so we'll have to re-read the one we found. */ |
| 1101 | offs = doc->mh0_page << this->page_shift; |
Joern Engel | 2831877 | 2006-05-22 23:18:05 +0200 | [diff] [blame] | 1102 | ret = mtd->read(mtd, offs, mtd->writesize, &retlen, buf); |
| 1103 | if (retlen != mtd->writesize) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | /* Insanity. Give up. */ |
| 1105 | printk(KERN_ERR "Read DiskOnChip Media Header once, but can't reread it???\n"); |
| 1106 | return 0; |
| 1107 | } |
| 1108 | return 1; |
| 1109 | } |
| 1110 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1111 | static inline int __init nftl_partscan(struct mtd_info *mtd, struct mtd_partition *parts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | { |
| 1113 | struct nand_chip *this = mtd->priv; |
| 1114 | struct doc_priv *doc = this->priv; |
| 1115 | int ret = 0; |
| 1116 | u_char *buf; |
| 1117 | struct NFTLMediaHeader *mh; |
| 1118 | const unsigned psize = 1 << this->page_shift; |
Dan Brown | 1a78ff6 | 2005-03-29 21:57:48 +0100 | [diff] [blame] | 1119 | int numparts = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | unsigned blocks, maxblocks; |
| 1121 | int offs, numheaders; |
| 1122 | |
Joern Engel | 2831877 | 2006-05-22 23:18:05 +0200 | [diff] [blame] | 1123 | buf = kmalloc(mtd->writesize, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | if (!buf) { |
| 1125 | printk(KERN_ERR "DiskOnChip mediaheader kmalloc failed!\n"); |
| 1126 | return 0; |
| 1127 | } |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1128 | if (!(numheaders = find_media_headers(mtd, buf, "ANAND", 1))) |
| 1129 | goto out; |
| 1130 | mh = (struct NFTLMediaHeader *)buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | |
Thomas Gleixner | f29a4b8 | 2005-01-31 22:22:24 +0000 | [diff] [blame] | 1132 | mh->NumEraseUnits = le16_to_cpu(mh->NumEraseUnits); |
| 1133 | mh->FirstPhysicalEUN = le16_to_cpu(mh->FirstPhysicalEUN); |
| 1134 | mh->FormattedSize = le32_to_cpu(mh->FormattedSize); |
| 1135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | printk(KERN_INFO " DataOrgID = %s\n" |
| 1137 | " NumEraseUnits = %d\n" |
| 1138 | " FirstPhysicalEUN = %d\n" |
| 1139 | " FormattedSize = %d\n" |
| 1140 | " UnitSizeFactor = %d\n", |
| 1141 | mh->DataOrgID, mh->NumEraseUnits, |
| 1142 | mh->FirstPhysicalEUN, mh->FormattedSize, |
| 1143 | mh->UnitSizeFactor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | |
| 1145 | blocks = mtd->size >> this->phys_erase_shift; |
| 1146 | maxblocks = min(32768U, mtd->erasesize - psize); |
| 1147 | |
| 1148 | if (mh->UnitSizeFactor == 0x00) { |
| 1149 | /* Auto-determine UnitSizeFactor. The constraints are: |
| 1150 | - There can be at most 32768 virtual blocks. |
| 1151 | - There can be at most (virtual block size - page size) |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1152 | virtual blocks (because MediaHeader+BBT must fit in 1). |
| 1153 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | mh->UnitSizeFactor = 0xff; |
| 1155 | while (blocks > maxblocks) { |
| 1156 | blocks >>= 1; |
| 1157 | maxblocks = min(32768U, (maxblocks << 1) + psize); |
| 1158 | mh->UnitSizeFactor--; |
| 1159 | } |
| 1160 | printk(KERN_WARNING "UnitSizeFactor=0x00 detected. Correct value is assumed to be 0x%02x.\n", mh->UnitSizeFactor); |
| 1161 | } |
| 1162 | |
| 1163 | /* NOTE: The lines below modify internal variables of the NAND and MTD |
| 1164 | layers; variables with have already been configured by nand_scan. |
| 1165 | Unfortunately, we didn't know before this point what these values |
| 1166 | should be. Thus, this code is somewhat dependant on the exact |
| 1167 | implementation of the NAND layer. */ |
| 1168 | if (mh->UnitSizeFactor != 0xff) { |
| 1169 | this->bbt_erase_shift += (0xff - mh->UnitSizeFactor); |
| 1170 | mtd->erasesize <<= (0xff - mh->UnitSizeFactor); |
| 1171 | printk(KERN_INFO "Setting virtual erase size to %d\n", mtd->erasesize); |
| 1172 | blocks = mtd->size >> this->bbt_erase_shift; |
| 1173 | maxblocks = min(32768U, mtd->erasesize - psize); |
| 1174 | } |
| 1175 | |
| 1176 | if (blocks > maxblocks) { |
| 1177 | printk(KERN_ERR "UnitSizeFactor of 0x%02x is inconsistent with device size. Aborting.\n", mh->UnitSizeFactor); |
| 1178 | goto out; |
| 1179 | } |
| 1180 | |
| 1181 | /* Skip past the media headers. */ |
| 1182 | offs = max(doc->mh0_page, doc->mh1_page); |
| 1183 | offs <<= this->page_shift; |
| 1184 | offs += mtd->erasesize; |
| 1185 | |
Dan Brown | 1a78ff6 | 2005-03-29 21:57:48 +0100 | [diff] [blame] | 1186 | if (show_firmware_partition == 1) { |
| 1187 | parts[0].name = " DiskOnChip Firmware / Media Header partition"; |
| 1188 | parts[0].offset = 0; |
| 1189 | parts[0].size = offs; |
| 1190 | numparts = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | } |
Dan Brown | 1a78ff6 | 2005-03-29 21:57:48 +0100 | [diff] [blame] | 1192 | |
| 1193 | parts[numparts].name = " DiskOnChip BDTL partition"; |
| 1194 | parts[numparts].offset = offs; |
| 1195 | parts[numparts].size = (mh->NumEraseUnits - numheaders) << this->bbt_erase_shift; |
| 1196 | |
| 1197 | offs += parts[numparts].size; |
| 1198 | numparts++; |
| 1199 | |
| 1200 | if (offs < mtd->size) { |
| 1201 | parts[numparts].name = " DiskOnChip Remainder partition"; |
| 1202 | parts[numparts].offset = offs; |
| 1203 | parts[numparts].size = mtd->size - offs; |
| 1204 | numparts++; |
| 1205 | } |
| 1206 | |
| 1207 | ret = numparts; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1208 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | kfree(buf); |
| 1210 | return ret; |
| 1211 | } |
| 1212 | |
| 1213 | /* This is a stripped-down copy of the code in inftlmount.c */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1214 | static inline int __init inftl_partscan(struct mtd_info *mtd, struct mtd_partition *parts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | { |
| 1216 | struct nand_chip *this = mtd->priv; |
| 1217 | struct doc_priv *doc = this->priv; |
| 1218 | int ret = 0; |
| 1219 | u_char *buf; |
| 1220 | struct INFTLMediaHeader *mh; |
| 1221 | struct INFTLPartition *ip; |
| 1222 | int numparts = 0; |
| 1223 | int blocks; |
| 1224 | int vshift, lastvunit = 0; |
| 1225 | int i; |
| 1226 | int end = mtd->size; |
| 1227 | |
| 1228 | if (inftl_bbt_write) |
| 1229 | end -= (INFTL_BBT_RESERVED_BLOCKS << this->phys_erase_shift); |
| 1230 | |
Joern Engel | 2831877 | 2006-05-22 23:18:05 +0200 | [diff] [blame] | 1231 | buf = kmalloc(mtd->writesize, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | if (!buf) { |
| 1233 | printk(KERN_ERR "DiskOnChip mediaheader kmalloc failed!\n"); |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1237 | if (!find_media_headers(mtd, buf, "BNAND", 0)) |
| 1238 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | doc->mh1_page = doc->mh0_page + (4096 >> this->page_shift); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1240 | mh = (struct INFTLMediaHeader *)buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | |
| 1242 | mh->NoOfBootImageBlocks = le32_to_cpu(mh->NoOfBootImageBlocks); |
| 1243 | mh->NoOfBinaryPartitions = le32_to_cpu(mh->NoOfBinaryPartitions); |
| 1244 | mh->NoOfBDTLPartitions = le32_to_cpu(mh->NoOfBDTLPartitions); |
| 1245 | mh->BlockMultiplierBits = le32_to_cpu(mh->BlockMultiplierBits); |
| 1246 | mh->FormatFlags = le32_to_cpu(mh->FormatFlags); |
| 1247 | mh->PercentUsed = le32_to_cpu(mh->PercentUsed); |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1248 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | printk(KERN_INFO " bootRecordID = %s\n" |
| 1250 | " NoOfBootImageBlocks = %d\n" |
| 1251 | " NoOfBinaryPartitions = %d\n" |
| 1252 | " NoOfBDTLPartitions = %d\n" |
| 1253 | " BlockMultiplerBits = %d\n" |
| 1254 | " FormatFlgs = %d\n" |
| 1255 | " OsakVersion = %d.%d.%d.%d\n" |
| 1256 | " PercentUsed = %d\n", |
| 1257 | mh->bootRecordID, mh->NoOfBootImageBlocks, |
| 1258 | mh->NoOfBinaryPartitions, |
| 1259 | mh->NoOfBDTLPartitions, |
| 1260 | mh->BlockMultiplierBits, mh->FormatFlags, |
| 1261 | ((unsigned char *) &mh->OsakVersion)[0] & 0xf, |
| 1262 | ((unsigned char *) &mh->OsakVersion)[1] & 0xf, |
| 1263 | ((unsigned char *) &mh->OsakVersion)[2] & 0xf, |
| 1264 | ((unsigned char *) &mh->OsakVersion)[3] & 0xf, |
| 1265 | mh->PercentUsed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1266 | |
| 1267 | vshift = this->phys_erase_shift + mh->BlockMultiplierBits; |
| 1268 | |
| 1269 | blocks = mtd->size >> vshift; |
| 1270 | if (blocks > 32768) { |
| 1271 | printk(KERN_ERR "BlockMultiplierBits=%d is inconsistent with device size. Aborting.\n", mh->BlockMultiplierBits); |
| 1272 | goto out; |
| 1273 | } |
| 1274 | |
| 1275 | blocks = doc->chips_per_floor << (this->chip_shift - this->phys_erase_shift); |
| 1276 | if (inftl_bbt_write && (blocks > mtd->erasesize)) { |
| 1277 | printk(KERN_ERR "Writeable BBTs spanning more than one erase block are not yet supported. FIX ME!\n"); |
| 1278 | goto out; |
| 1279 | } |
| 1280 | |
| 1281 | /* Scan the partitions */ |
| 1282 | for (i = 0; (i < 4); i++) { |
| 1283 | ip = &(mh->Partitions[i]); |
| 1284 | ip->virtualUnits = le32_to_cpu(ip->virtualUnits); |
| 1285 | ip->firstUnit = le32_to_cpu(ip->firstUnit); |
| 1286 | ip->lastUnit = le32_to_cpu(ip->lastUnit); |
| 1287 | ip->flags = le32_to_cpu(ip->flags); |
| 1288 | ip->spareUnits = le32_to_cpu(ip->spareUnits); |
| 1289 | ip->Reserved0 = le32_to_cpu(ip->Reserved0); |
| 1290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | printk(KERN_INFO " PARTITION[%d] ->\n" |
| 1292 | " virtualUnits = %d\n" |
| 1293 | " firstUnit = %d\n" |
| 1294 | " lastUnit = %d\n" |
| 1295 | " flags = 0x%x\n" |
| 1296 | " spareUnits = %d\n", |
| 1297 | i, ip->virtualUnits, ip->firstUnit, |
| 1298 | ip->lastUnit, ip->flags, |
| 1299 | ip->spareUnits); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | |
Dan Brown | 1a78ff6 | 2005-03-29 21:57:48 +0100 | [diff] [blame] | 1301 | if ((show_firmware_partition == 1) && |
| 1302 | (i == 0) && (ip->firstUnit > 0)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | parts[0].name = " DiskOnChip IPL / Media Header partition"; |
| 1304 | parts[0].offset = 0; |
| 1305 | parts[0].size = mtd->erasesize * ip->firstUnit; |
| 1306 | numparts = 1; |
| 1307 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
| 1309 | if (ip->flags & INFTL_BINARY) |
| 1310 | parts[numparts].name = " DiskOnChip BDK partition"; |
| 1311 | else |
| 1312 | parts[numparts].name = " DiskOnChip BDTL partition"; |
| 1313 | parts[numparts].offset = ip->firstUnit << vshift; |
| 1314 | parts[numparts].size = (1 + ip->lastUnit - ip->firstUnit) << vshift; |
| 1315 | numparts++; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1316 | if (ip->lastUnit > lastvunit) |
| 1317 | lastvunit = ip->lastUnit; |
| 1318 | if (ip->flags & INFTL_LAST) |
| 1319 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | } |
| 1321 | lastvunit++; |
| 1322 | if ((lastvunit << vshift) < end) { |
| 1323 | parts[numparts].name = " DiskOnChip Remainder partition"; |
| 1324 | parts[numparts].offset = lastvunit << vshift; |
| 1325 | parts[numparts].size = end - parts[numparts].offset; |
| 1326 | numparts++; |
| 1327 | } |
| 1328 | ret = numparts; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1329 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | kfree(buf); |
| 1331 | return ret; |
| 1332 | } |
| 1333 | |
| 1334 | static int __init nftl_scan_bbt(struct mtd_info *mtd) |
| 1335 | { |
| 1336 | int ret, numparts; |
| 1337 | struct nand_chip *this = mtd->priv; |
| 1338 | struct doc_priv *doc = this->priv; |
| 1339 | struct mtd_partition parts[2]; |
| 1340 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1341 | memset((char *)parts, 0, sizeof(parts)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | /* On NFTL, we have to find the media headers before we can read the |
| 1343 | BBTs, since they're stored in the media header eraseblocks. */ |
| 1344 | numparts = nftl_partscan(mtd, parts); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1345 | if (!numparts) |
| 1346 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | this->bbt_td->options = NAND_BBT_ABSPAGE | NAND_BBT_8BIT | |
| 1348 | NAND_BBT_SAVECONTENT | NAND_BBT_WRITE | |
| 1349 | NAND_BBT_VERSION; |
| 1350 | this->bbt_td->veroffs = 7; |
| 1351 | this->bbt_td->pages[0] = doc->mh0_page + 1; |
| 1352 | if (doc->mh1_page != -1) { |
| 1353 | this->bbt_md->options = NAND_BBT_ABSPAGE | NAND_BBT_8BIT | |
| 1354 | NAND_BBT_SAVECONTENT | NAND_BBT_WRITE | |
| 1355 | NAND_BBT_VERSION; |
| 1356 | this->bbt_md->veroffs = 7; |
| 1357 | this->bbt_md->pages[0] = doc->mh1_page + 1; |
| 1358 | } else { |
| 1359 | this->bbt_md = NULL; |
| 1360 | } |
| 1361 | |
| 1362 | /* It's safe to set bd=NULL below because NAND_BBT_CREATE is not set. |
| 1363 | At least as nand_bbt.c is currently written. */ |
| 1364 | if ((ret = nand_scan_bbt(mtd, NULL))) |
| 1365 | return ret; |
| 1366 | add_mtd_device(mtd); |
| 1367 | #ifdef CONFIG_MTD_PARTITIONS |
| 1368 | if (!no_autopart) |
| 1369 | add_mtd_partitions(mtd, parts, numparts); |
| 1370 | #endif |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
| 1374 | static int __init inftl_scan_bbt(struct mtd_info *mtd) |
| 1375 | { |
| 1376 | int ret, numparts; |
| 1377 | struct nand_chip *this = mtd->priv; |
| 1378 | struct doc_priv *doc = this->priv; |
| 1379 | struct mtd_partition parts[5]; |
| 1380 | |
| 1381 | if (this->numchips > doc->chips_per_floor) { |
| 1382 | printk(KERN_ERR "Multi-floor INFTL devices not yet supported.\n"); |
| 1383 | return -EIO; |
| 1384 | } |
| 1385 | |
| 1386 | if (DoC_is_MillenniumPlus(doc)) { |
| 1387 | this->bbt_td->options = NAND_BBT_2BIT | NAND_BBT_ABSPAGE; |
| 1388 | if (inftl_bbt_write) |
| 1389 | this->bbt_td->options |= NAND_BBT_WRITE; |
| 1390 | this->bbt_td->pages[0] = 2; |
| 1391 | this->bbt_md = NULL; |
| 1392 | } else { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1393 | this->bbt_td->options = NAND_BBT_LASTBLOCK | NAND_BBT_8BIT | NAND_BBT_VERSION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | if (inftl_bbt_write) |
| 1395 | this->bbt_td->options |= NAND_BBT_WRITE; |
| 1396 | this->bbt_td->offs = 8; |
| 1397 | this->bbt_td->len = 8; |
| 1398 | this->bbt_td->veroffs = 7; |
| 1399 | this->bbt_td->maxblocks = INFTL_BBT_RESERVED_BLOCKS; |
| 1400 | this->bbt_td->reserved_block_code = 0x01; |
| 1401 | this->bbt_td->pattern = "MSYS_BBT"; |
| 1402 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1403 | this->bbt_md->options = NAND_BBT_LASTBLOCK | NAND_BBT_8BIT | NAND_BBT_VERSION; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | if (inftl_bbt_write) |
| 1405 | this->bbt_md->options |= NAND_BBT_WRITE; |
| 1406 | this->bbt_md->offs = 8; |
| 1407 | this->bbt_md->len = 8; |
| 1408 | this->bbt_md->veroffs = 7; |
| 1409 | this->bbt_md->maxblocks = INFTL_BBT_RESERVED_BLOCKS; |
| 1410 | this->bbt_md->reserved_block_code = 0x01; |
| 1411 | this->bbt_md->pattern = "TBB_SYSM"; |
| 1412 | } |
| 1413 | |
| 1414 | /* It's safe to set bd=NULL below because NAND_BBT_CREATE is not set. |
| 1415 | At least as nand_bbt.c is currently written. */ |
| 1416 | if ((ret = nand_scan_bbt(mtd, NULL))) |
| 1417 | return ret; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1418 | memset((char *)parts, 0, sizeof(parts)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | numparts = inftl_partscan(mtd, parts); |
| 1420 | /* At least for now, require the INFTL Media Header. We could probably |
| 1421 | do without it for non-INFTL use, since all it gives us is |
| 1422 | autopartitioning, but I want to give it more thought. */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1423 | if (!numparts) |
| 1424 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | add_mtd_device(mtd); |
| 1426 | #ifdef CONFIG_MTD_PARTITIONS |
| 1427 | if (!no_autopart) |
| 1428 | add_mtd_partitions(mtd, parts, numparts); |
| 1429 | #endif |
| 1430 | return 0; |
| 1431 | } |
| 1432 | |
| 1433 | static inline int __init doc2000_init(struct mtd_info *mtd) |
| 1434 | { |
| 1435 | struct nand_chip *this = mtd->priv; |
| 1436 | struct doc_priv *doc = this->priv; |
| 1437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | this->read_byte = doc2000_read_byte; |
| 1439 | this->write_buf = doc2000_writebuf; |
| 1440 | this->read_buf = doc2000_readbuf; |
| 1441 | this->verify_buf = doc2000_verifybuf; |
| 1442 | this->scan_bbt = nftl_scan_bbt; |
| 1443 | |
| 1444 | doc->CDSNControl = CDSN_CTRL_FLASH_IO | CDSN_CTRL_ECC_IO; |
| 1445 | doc2000_count_chips(mtd); |
| 1446 | mtd->name = "DiskOnChip 2000 (NFTL Model)"; |
| 1447 | return (4 * doc->chips_per_floor); |
| 1448 | } |
| 1449 | |
| 1450 | static inline int __init doc2001_init(struct mtd_info *mtd) |
| 1451 | { |
| 1452 | struct nand_chip *this = mtd->priv; |
| 1453 | struct doc_priv *doc = this->priv; |
| 1454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | this->read_byte = doc2001_read_byte; |
| 1456 | this->write_buf = doc2001_writebuf; |
| 1457 | this->read_buf = doc2001_readbuf; |
| 1458 | this->verify_buf = doc2001_verifybuf; |
| 1459 | |
| 1460 | ReadDOC(doc->virtadr, ChipID); |
| 1461 | ReadDOC(doc->virtadr, ChipID); |
| 1462 | ReadDOC(doc->virtadr, ChipID); |
| 1463 | if (ReadDOC(doc->virtadr, ChipID) != DOC_ChipID_DocMil) { |
| 1464 | /* It's not a Millennium; it's one of the newer |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1465 | DiskOnChip 2000 units with a similar ASIC. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | Treat it like a Millennium, except that it |
| 1467 | can have multiple chips. */ |
| 1468 | doc2000_count_chips(mtd); |
| 1469 | mtd->name = "DiskOnChip 2000 (INFTL Model)"; |
| 1470 | this->scan_bbt = inftl_scan_bbt; |
| 1471 | return (4 * doc->chips_per_floor); |
| 1472 | } else { |
| 1473 | /* Bog-standard Millennium */ |
| 1474 | doc->chips_per_floor = 1; |
| 1475 | mtd->name = "DiskOnChip Millennium"; |
| 1476 | this->scan_bbt = nftl_scan_bbt; |
| 1477 | return 1; |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | static inline int __init doc2001plus_init(struct mtd_info *mtd) |
| 1482 | { |
| 1483 | struct nand_chip *this = mtd->priv; |
| 1484 | struct doc_priv *doc = this->priv; |
| 1485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | this->read_byte = doc2001plus_read_byte; |
| 1487 | this->write_buf = doc2001plus_writebuf; |
| 1488 | this->read_buf = doc2001plus_readbuf; |
| 1489 | this->verify_buf = doc2001plus_verifybuf; |
| 1490 | this->scan_bbt = inftl_scan_bbt; |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 1491 | this->cmd_ctrl = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | this->select_chip = doc2001plus_select_chip; |
| 1493 | this->cmdfunc = doc2001plus_command; |
Thomas Gleixner | 0cddd6c | 2006-05-23 15:59:58 +0200 | [diff] [blame] | 1494 | this->ecc.hwctl = doc2001plus_enable_hwecc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | |
| 1496 | doc->chips_per_floor = 1; |
| 1497 | mtd->name = "DiskOnChip Millennium Plus"; |
| 1498 | |
| 1499 | return 1; |
| 1500 | } |
| 1501 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 1502 | static int __init doc_probe(unsigned long physadr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1503 | { |
| 1504 | unsigned char ChipID; |
| 1505 | struct mtd_info *mtd; |
| 1506 | struct nand_chip *nand; |
| 1507 | struct doc_priv *doc; |
| 1508 | void __iomem *virtadr; |
| 1509 | unsigned char save_control; |
| 1510 | unsigned char tmp, tmpb, tmpc; |
| 1511 | int reg, len, numchips; |
| 1512 | int ret = 0; |
| 1513 | |
| 1514 | virtadr = ioremap(physadr, DOC_IOREMAP_LEN); |
| 1515 | if (!virtadr) { |
| 1516 | printk(KERN_ERR "Diskonchip ioremap failed: 0x%x bytes at 0x%lx\n", DOC_IOREMAP_LEN, physadr); |
| 1517 | return -EIO; |
| 1518 | } |
| 1519 | |
| 1520 | /* It's not possible to cleanly detect the DiskOnChip - the |
| 1521 | * bootup procedure will put the device into reset mode, and |
| 1522 | * it's not possible to talk to it without actually writing |
| 1523 | * to the DOCControl register. So we store the current contents |
| 1524 | * of the DOCControl register's location, in case we later decide |
| 1525 | * that it's not a DiskOnChip, and want to put it back how we |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1526 | * found it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1527 | */ |
| 1528 | save_control = ReadDOC(virtadr, DOCControl); |
| 1529 | |
| 1530 | /* Reset the DiskOnChip ASIC */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1531 | WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, virtadr, DOCControl); |
| 1532 | WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, virtadr, DOCControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | |
| 1534 | /* Enable the DiskOnChip ASIC */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1535 | WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, virtadr, DOCControl); |
| 1536 | WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, virtadr, DOCControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | |
| 1538 | ChipID = ReadDOC(virtadr, ChipID); |
| 1539 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1540 | switch (ChipID) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | case DOC_ChipID_Doc2k: |
| 1542 | reg = DoC_2k_ECCStatus; |
| 1543 | break; |
| 1544 | case DOC_ChipID_DocMil: |
| 1545 | reg = DoC_ECCConf; |
| 1546 | break; |
| 1547 | case DOC_ChipID_DocMilPlus16: |
| 1548 | case DOC_ChipID_DocMilPlus32: |
| 1549 | case 0: |
| 1550 | /* Possible Millennium Plus, need to do more checks */ |
| 1551 | /* Possibly release from power down mode */ |
| 1552 | for (tmp = 0; (tmp < 4); tmp++) |
| 1553 | ReadDOC(virtadr, Mplus_Power); |
| 1554 | |
| 1555 | /* Reset the Millennium Plus ASIC */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1556 | tmp = DOC_MODE_RESET | DOC_MODE_MDWREN | DOC_MODE_RST_LAT | DOC_MODE_BDECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | WriteDOC(tmp, virtadr, Mplus_DOCControl); |
| 1558 | WriteDOC(~tmp, virtadr, Mplus_CtrlConfirm); |
| 1559 | |
| 1560 | mdelay(1); |
| 1561 | /* Enable the Millennium Plus ASIC */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1562 | tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT | DOC_MODE_BDECT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | WriteDOC(tmp, virtadr, Mplus_DOCControl); |
| 1564 | WriteDOC(~tmp, virtadr, Mplus_CtrlConfirm); |
| 1565 | mdelay(1); |
| 1566 | |
| 1567 | ChipID = ReadDOC(virtadr, ChipID); |
| 1568 | |
| 1569 | switch (ChipID) { |
| 1570 | case DOC_ChipID_DocMilPlus16: |
| 1571 | reg = DoC_Mplus_Toggle; |
| 1572 | break; |
| 1573 | case DOC_ChipID_DocMilPlus32: |
| 1574 | printk(KERN_ERR "DiskOnChip Millennium Plus 32MB is not supported, ignoring.\n"); |
| 1575 | default: |
| 1576 | ret = -ENODEV; |
| 1577 | goto notfound; |
| 1578 | } |
| 1579 | break; |
| 1580 | |
| 1581 | default: |
| 1582 | ret = -ENODEV; |
| 1583 | goto notfound; |
| 1584 | } |
| 1585 | /* Check the TOGGLE bit in the ECC register */ |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1586 | tmp = ReadDOC_(virtadr, reg) & DOC_TOGGLE_BIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | tmpb = ReadDOC_(virtadr, reg) & DOC_TOGGLE_BIT; |
| 1588 | tmpc = ReadDOC_(virtadr, reg) & DOC_TOGGLE_BIT; |
| 1589 | if ((tmp == tmpb) || (tmp != tmpc)) { |
| 1590 | printk(KERN_WARNING "Possible DiskOnChip at 0x%lx failed TOGGLE test, dropping.\n", physadr); |
| 1591 | ret = -ENODEV; |
| 1592 | goto notfound; |
| 1593 | } |
| 1594 | |
| 1595 | for (mtd = doclist; mtd; mtd = doc->nextdoc) { |
| 1596 | unsigned char oldval; |
| 1597 | unsigned char newval; |
| 1598 | nand = mtd->priv; |
| 1599 | doc = nand->priv; |
| 1600 | /* Use the alias resolution register to determine if this is |
| 1601 | in fact the same DOC aliased to a new address. If writes |
| 1602 | to one chip's alias resolution register change the value on |
| 1603 | the other chip, they're the same chip. */ |
| 1604 | if (ChipID == DOC_ChipID_DocMilPlus16) { |
| 1605 | oldval = ReadDOC(doc->virtadr, Mplus_AliasResolution); |
| 1606 | newval = ReadDOC(virtadr, Mplus_AliasResolution); |
| 1607 | } else { |
| 1608 | oldval = ReadDOC(doc->virtadr, AliasResolution); |
| 1609 | newval = ReadDOC(virtadr, AliasResolution); |
| 1610 | } |
| 1611 | if (oldval != newval) |
| 1612 | continue; |
| 1613 | if (ChipID == DOC_ChipID_DocMilPlus16) { |
| 1614 | WriteDOC(~newval, virtadr, Mplus_AliasResolution); |
| 1615 | oldval = ReadDOC(doc->virtadr, Mplus_AliasResolution); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1616 | WriteDOC(newval, virtadr, Mplus_AliasResolution); // restore it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | } else { |
| 1618 | WriteDOC(~newval, virtadr, AliasResolution); |
| 1619 | oldval = ReadDOC(doc->virtadr, AliasResolution); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1620 | WriteDOC(newval, virtadr, AliasResolution); // restore it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | } |
| 1622 | newval = ~newval; |
| 1623 | if (oldval == newval) { |
| 1624 | printk(KERN_DEBUG "Found alias of DOC at 0x%lx to 0x%lx\n", doc->physadr, physadr); |
| 1625 | goto notfound; |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | printk(KERN_NOTICE "DiskOnChip found at 0x%lx\n", physadr); |
| 1630 | |
| 1631 | len = sizeof(struct mtd_info) + |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1632 | sizeof(struct nand_chip) + sizeof(struct doc_priv) + (2 * sizeof(struct nand_bbt_descr)); |
Burman Yan | 95b93a0 | 2006-11-15 21:10:29 +0200 | [diff] [blame] | 1633 | mtd = kzalloc(len, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | if (!mtd) { |
| 1635 | printk(KERN_ERR "DiskOnChip kmalloc (%d bytes) failed!\n", len); |
| 1636 | ret = -ENOMEM; |
| 1637 | goto fail; |
| 1638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | |
| 1640 | nand = (struct nand_chip *) (mtd + 1); |
| 1641 | doc = (struct doc_priv *) (nand + 1); |
| 1642 | nand->bbt_td = (struct nand_bbt_descr *) (doc + 1); |
| 1643 | nand->bbt_md = nand->bbt_td + 1; |
| 1644 | |
| 1645 | mtd->priv = nand; |
| 1646 | mtd->owner = THIS_MODULE; |
| 1647 | |
| 1648 | nand->priv = doc; |
| 1649 | nand->select_chip = doc200x_select_chip; |
Thomas Gleixner | 7abd3ef | 2006-05-23 23:25:53 +0200 | [diff] [blame] | 1650 | nand->cmd_ctrl = doc200x_hwcontrol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | nand->dev_ready = doc200x_dev_ready; |
| 1652 | nand->waitfunc = doc200x_wait; |
| 1653 | nand->block_bad = doc200x_block_bad; |
Thomas Gleixner | 6dfc6d2 | 2006-05-23 12:00:46 +0200 | [diff] [blame] | 1654 | nand->ecc.hwctl = doc200x_enable_hwecc; |
| 1655 | nand->ecc.calculate = doc200x_calculate_ecc; |
| 1656 | nand->ecc.correct = doc200x_correct_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
Thomas Gleixner | 5bd34c0 | 2006-05-27 22:16:10 +0200 | [diff] [blame] | 1658 | nand->ecc.layout = &doc200x_oobinfo; |
Thomas Gleixner | 6dfc6d2 | 2006-05-23 12:00:46 +0200 | [diff] [blame] | 1659 | nand->ecc.mode = NAND_ECC_HW_SYNDROME; |
| 1660 | nand->ecc.size = 512; |
| 1661 | nand->ecc.bytes = 6; |
Thomas Gleixner | f75e509 | 2006-05-26 18:52:08 +0200 | [diff] [blame] | 1662 | nand->options = NAND_USE_FLASH_BBT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
| 1664 | doc->physadr = physadr; |
| 1665 | doc->virtadr = virtadr; |
| 1666 | doc->ChipID = ChipID; |
| 1667 | doc->curfloor = -1; |
| 1668 | doc->curchip = -1; |
| 1669 | doc->mh0_page = -1; |
| 1670 | doc->mh1_page = -1; |
| 1671 | doc->nextdoc = doclist; |
| 1672 | |
| 1673 | if (ChipID == DOC_ChipID_Doc2k) |
| 1674 | numchips = doc2000_init(mtd); |
| 1675 | else if (ChipID == DOC_ChipID_DocMilPlus16) |
| 1676 | numchips = doc2001plus_init(mtd); |
| 1677 | else |
| 1678 | numchips = doc2001_init(mtd); |
| 1679 | |
| 1680 | if ((ret = nand_scan(mtd, numchips))) { |
| 1681 | /* DBB note: i believe nand_release is necessary here, as |
| 1682 | buffers may have been allocated in nand_base. Check with |
| 1683 | Thomas. FIX ME! */ |
| 1684 | /* nand_release will call del_mtd_device, but we haven't yet |
| 1685 | added it. This is handled without incident by |
| 1686 | del_mtd_device, as far as I can tell. */ |
| 1687 | nand_release(mtd); |
| 1688 | kfree(mtd); |
| 1689 | goto fail; |
| 1690 | } |
| 1691 | |
| 1692 | /* Success! */ |
| 1693 | doclist = mtd; |
| 1694 | return 0; |
| 1695 | |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1696 | notfound: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1697 | /* Put back the contents of the DOCControl register, in case it's not |
| 1698 | actually a DiskOnChip. */ |
| 1699 | WriteDOC(save_control, virtadr, DOCControl); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1700 | fail: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | iounmap(virtadr); |
| 1702 | return ret; |
| 1703 | } |
| 1704 | |
| 1705 | static void release_nanddoc(void) |
| 1706 | { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1707 | struct mtd_info *mtd, *nextmtd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1708 | struct nand_chip *nand; |
| 1709 | struct doc_priv *doc; |
| 1710 | |
| 1711 | for (mtd = doclist; mtd; mtd = nextmtd) { |
| 1712 | nand = mtd->priv; |
| 1713 | doc = nand->priv; |
| 1714 | |
| 1715 | nextmtd = doc->nextdoc; |
| 1716 | nand_release(mtd); |
| 1717 | iounmap(doc->virtadr); |
| 1718 | kfree(mtd); |
| 1719 | } |
| 1720 | } |
| 1721 | |
| 1722 | static int __init init_nanddoc(void) |
| 1723 | { |
| 1724 | int i, ret = 0; |
| 1725 | |
| 1726 | /* We could create the decoder on demand, if memory is a concern. |
Thomas Gleixner | 61b03bd | 2005-11-07 11:15:49 +0000 | [diff] [blame] | 1727 | * This way we have it handy, if an error happens |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1728 | * |
| 1729 | * Symbolsize is 10 (bits) |
| 1730 | * Primitve polynomial is x^10+x^3+1 |
| 1731 | * first consecutive root is 510 |
| 1732 | * primitve element to generate roots = 1 |
| 1733 | * generator polinomial degree = 4 |
| 1734 | */ |
| 1735 | rs_decoder = init_rs(10, 0x409, FCR, 1, NROOTS); |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1736 | if (!rs_decoder) { |
| 1737 | printk(KERN_ERR "DiskOnChip: Could not create a RS decoder\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | return -ENOMEM; |
| 1739 | } |
| 1740 | |
| 1741 | if (doc_config_location) { |
| 1742 | printk(KERN_INFO "Using configured DiskOnChip probe address 0x%lx\n", doc_config_location); |
| 1743 | ret = doc_probe(doc_config_location); |
| 1744 | if (ret < 0) |
| 1745 | goto outerr; |
| 1746 | } else { |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1747 | for (i = 0; (doc_locations[i] != 0xffffffff); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | doc_probe(doc_locations[i]); |
| 1749 | } |
| 1750 | } |
| 1751 | /* No banner message any more. Print a message if no DiskOnChip |
| 1752 | found, so the user knows we at least tried. */ |
| 1753 | if (!doclist) { |
| 1754 | printk(KERN_INFO "No valid DiskOnChip devices found\n"); |
| 1755 | ret = -ENODEV; |
| 1756 | goto outerr; |
| 1757 | } |
| 1758 | return 0; |
David Woodhouse | e0c7d76 | 2006-05-13 18:07:53 +0100 | [diff] [blame] | 1759 | outerr: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1760 | free_rs(rs_decoder); |
| 1761 | return ret; |
| 1762 | } |
| 1763 | |
| 1764 | static void __exit cleanup_nanddoc(void) |
| 1765 | { |
| 1766 | /* Cleanup the nand/DoC resources */ |
| 1767 | release_nanddoc(); |
| 1768 | |
| 1769 | /* Free the reed solomon resources */ |
| 1770 | if (rs_decoder) { |
| 1771 | free_rs(rs_decoder); |
| 1772 | } |
| 1773 | } |
| 1774 | |
| 1775 | module_init(init_nanddoc); |
| 1776 | module_exit(cleanup_nanddoc); |
| 1777 | |
| 1778 | MODULE_LICENSE("GPL"); |
| 1779 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); |
| 1780 | MODULE_DESCRIPTION("M-Systems DiskOnChip 2000, Millennium and Millennium Plus device driver\n"); |