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