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