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