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