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