diff options
author | Artem Bityutskiy <artem.bityutskiy@linux.intel.com> | 2013-03-06 02:23:47 -0500 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2013-04-05 07:04:31 -0400 |
commit | b5a6c3095f0b8c69b1e5c4bacb7ee13069f2688d (patch) | |
tree | 67ef7bb97acc4a3f6fe92018e724bdecf7b9e5b7 /drivers/mtd/devices | |
parent | 8e12b474f9a2349bcaebda65bdc38e8398ff408e (diff) |
mtd: doc: remove support for DoC 2000/2001/2001+
These drivers are deprecated for very long time, and we have a different driver
for these called "diskonchip". Thus, kill the ancient cruft.
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers/mtd/devices')
-rw-r--r-- | drivers/mtd/devices/Kconfig | 63 | ||||
-rw-r--r-- | drivers/mtd/devices/Makefile | 5 | ||||
-rw-r--r-- | drivers/mtd/devices/doc2000.c | 1178 | ||||
-rw-r--r-- | drivers/mtd/devices/doc2001.c | 824 | ||||
-rw-r--r-- | drivers/mtd/devices/doc2001plus.c | 1080 | ||||
-rw-r--r-- | drivers/mtd/devices/docecc.c | 521 | ||||
-rw-r--r-- | drivers/mtd/devices/docprobe.c | 325 |
7 files changed, 0 insertions, 3996 deletions
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig index 12311f506ca1..ec4a2cc3e9b5 100644 --- a/drivers/mtd/devices/Kconfig +++ b/drivers/mtd/devices/Kconfig | |||
@@ -205,69 +205,6 @@ config MTD_BLOCK2MTD | |||
205 | 205 | ||
206 | comment "Disk-On-Chip Device Drivers" | 206 | comment "Disk-On-Chip Device Drivers" |
207 | 207 | ||
208 | config MTD_DOC2000 | ||
209 | tristate "M-Systems Disk-On-Chip 2000 and Millennium (DEPRECATED)" | ||
210 | depends on MTD_NAND | ||
211 | select MTD_DOCPROBE | ||
212 | select MTD_NAND_IDS | ||
213 | ---help--- | ||
214 | This provides an MTD device driver for the M-Systems DiskOnChip | ||
215 | 2000 and Millennium devices. Originally designed for the DiskOnChip | ||
216 | 2000, it also now includes support for the DiskOnChip Millennium. | ||
217 | If you have problems with this driver and the DiskOnChip Millennium, | ||
218 | you may wish to try the alternative Millennium driver below. To use | ||
219 | the alternative driver, you will need to undefine DOC_SINGLE_DRIVER | ||
220 | in the <file:drivers/mtd/devices/docprobe.c> source code. | ||
221 | |||
222 | If you use this device, you probably also want to enable the NFTL | ||
223 | 'NAND Flash Translation Layer' option below, which is used to | ||
224 | emulate a block device by using a kind of file system on the flash | ||
225 | chips. | ||
226 | |||
227 | NOTE: This driver is deprecated and will probably be removed soon. | ||
228 | Please try the new DiskOnChip driver under "NAND Flash Device | ||
229 | Drivers". | ||
230 | |||
231 | config MTD_DOC2001 | ||
232 | tristate "M-Systems Disk-On-Chip Millennium-only alternative driver (DEPRECATED)" | ||
233 | depends on MTD_NAND | ||
234 | select MTD_DOCPROBE | ||
235 | select MTD_NAND_IDS | ||
236 | ---help--- | ||
237 | This provides an alternative MTD device driver for the M-Systems | ||
238 | DiskOnChip Millennium devices. Use this if you have problems with | ||
239 | the combined DiskOnChip 2000 and Millennium driver above. To get | ||
240 | the DiskOnChip probe code to load and use this driver instead of | ||
241 | the other one, you will need to undefine DOC_SINGLE_DRIVER near | ||
242 | the beginning of <file:drivers/mtd/devices/docprobe.c>. | ||
243 | |||
244 | If you use this device, you probably also want to enable the NFTL | ||
245 | 'NAND Flash Translation Layer' option below, which is used to | ||
246 | emulate a block device by using a kind of file system on the flash | ||
247 | chips. | ||
248 | |||
249 | NOTE: This driver is deprecated and will probably be removed soon. | ||
250 | Please try the new DiskOnChip driver under "NAND Flash Device | ||
251 | Drivers". | ||
252 | |||
253 | config MTD_DOC2001PLUS | ||
254 | tristate "M-Systems Disk-On-Chip Millennium Plus" | ||
255 | depends on MTD_NAND | ||
256 | select MTD_DOCPROBE | ||
257 | select MTD_NAND_IDS | ||
258 | ---help--- | ||
259 | This provides an MTD device driver for the M-Systems DiskOnChip | ||
260 | Millennium Plus devices. | ||
261 | |||
262 | If you use this device, you probably also want to enable the INFTL | ||
263 | 'Inverse NAND Flash Translation Layer' option below, which is used | ||
264 | to emulate a block device by using a kind of file system on the | ||
265 | flash chips. | ||
266 | |||
267 | NOTE: This driver will soon be replaced by the new DiskOnChip driver | ||
268 | under "NAND Flash Device Drivers" (currently that driver does not | ||
269 | support all Millennium Plus devices). | ||
270 | |||
271 | config MTD_DOCG3 | 208 | config MTD_DOCG3 |
272 | tristate "M-Systems Disk-On-Chip G3" | 209 | tristate "M-Systems Disk-On-Chip G3" |
273 | select BCH | 210 | select BCH |
diff --git a/drivers/mtd/devices/Makefile b/drivers/mtd/devices/Makefile index 369a1943ca25..d83bd73096f6 100644 --- a/drivers/mtd/devices/Makefile +++ b/drivers/mtd/devices/Makefile | |||
@@ -2,12 +2,7 @@ | |||
2 | # linux/drivers/mtd/devices/Makefile | 2 | # linux/drivers/mtd/devices/Makefile |
3 | # | 3 | # |
4 | 4 | ||
5 | obj-$(CONFIG_MTD_DOC2000) += doc2000.o | ||
6 | obj-$(CONFIG_MTD_DOC2001) += doc2001.o | ||
7 | obj-$(CONFIG_MTD_DOC2001PLUS) += doc2001plus.o | ||
8 | obj-$(CONFIG_MTD_DOCG3) += docg3.o | 5 | obj-$(CONFIG_MTD_DOCG3) += docg3.o |
9 | obj-$(CONFIG_MTD_DOCPROBE) += docprobe.o | ||
10 | obj-$(CONFIG_MTD_DOCECC) += docecc.o | ||
11 | obj-$(CONFIG_MTD_SLRAM) += slram.o | 6 | obj-$(CONFIG_MTD_SLRAM) += slram.o |
12 | obj-$(CONFIG_MTD_PHRAM) += phram.o | 7 | obj-$(CONFIG_MTD_PHRAM) += phram.o |
13 | obj-$(CONFIG_MTD_PMC551) += pmc551.o | 8 | obj-$(CONFIG_MTD_PMC551) += pmc551.o |
diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c deleted file mode 100644 index 363ec3c55d92..000000000000 --- a/drivers/mtd/devices/doc2000.c +++ /dev/null | |||
@@ -1,1178 +0,0 @@ | |||
1 | |||
2 | /* | ||
3 | * Linux driver for Disk-On-Chip 2000 and Millennium | ||
4 | * (c) 1999 Machine Vision Holdings, Inc. | ||
5 | * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org> | ||
6 | */ | ||
7 | |||
8 | #include <linux/kernel.h> | ||
9 | #include <linux/module.h> | ||
10 | #include <asm/errno.h> | ||
11 | #include <asm/io.h> | ||
12 | #include <asm/uaccess.h> | ||
13 | #include <linux/delay.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/sched.h> | ||
16 | #include <linux/init.h> | ||
17 | #include <linux/types.h> | ||
18 | #include <linux/bitops.h> | ||
19 | #include <linux/mutex.h> | ||
20 | |||
21 | #include <linux/mtd/mtd.h> | ||
22 | #include <linux/mtd/nand.h> | ||
23 | #include <linux/mtd/doc2000.h> | ||
24 | |||
25 | #define DOC_SUPPORT_2000 | ||
26 | #define DOC_SUPPORT_2000TSOP | ||
27 | #define DOC_SUPPORT_MILLENNIUM | ||
28 | |||
29 | #ifdef DOC_SUPPORT_2000 | ||
30 | #define DoC_is_2000(doc) (doc->ChipID == DOC_ChipID_Doc2k) | ||
31 | #else | ||
32 | #define DoC_is_2000(doc) (0) | ||
33 | #endif | ||
34 | |||
35 | #if defined(DOC_SUPPORT_2000TSOP) || defined(DOC_SUPPORT_MILLENNIUM) | ||
36 | #define DoC_is_Millennium(doc) (doc->ChipID == DOC_ChipID_DocMil) | ||
37 | #else | ||
38 | #define DoC_is_Millennium(doc) (0) | ||
39 | #endif | ||
40 | |||
41 | /* #define ECC_DEBUG */ | ||
42 | |||
43 | /* I have no idea why some DoC chips can not use memcpy_from|to_io(). | ||
44 | * This may be due to the different revisions of the ASIC controller built-in or | ||
45 | * simplily a QA/Bug issue. Who knows ?? If you have trouble, please uncomment | ||
46 | * this: | ||
47 | #undef USE_MEMCPY | ||
48 | */ | ||
49 | |||
50 | static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, | ||
51 | size_t *retlen, u_char *buf); | ||
52 | static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, | ||
53 | size_t *retlen, const u_char *buf); | ||
54 | static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, | ||
55 | struct mtd_oob_ops *ops); | ||
56 | static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, | ||
57 | struct mtd_oob_ops *ops); | ||
58 | static int doc_write_oob_nolock(struct mtd_info *mtd, loff_t ofs, size_t len, | ||
59 | size_t *retlen, const u_char *buf); | ||
60 | static int doc_erase (struct mtd_info *mtd, struct erase_info *instr); | ||
61 | |||
62 | static struct mtd_info *doc2klist = NULL; | ||
63 | |||
64 | /* Perform the required delay cycles by reading from the appropriate register */ | ||
65 | static void DoC_Delay(struct DiskOnChip *doc, unsigned short cycles) | ||
66 | { | ||
67 | volatile char dummy; | ||
68 | int i; | ||
69 | |||
70 | for (i = 0; i < cycles; i++) { | ||
71 | if (DoC_is_Millennium(doc)) | ||
72 | dummy = ReadDOC(doc->virtadr, NOP); | ||
73 | else | ||
74 | dummy = ReadDOC(doc->virtadr, DOCStatus); | ||
75 | } | ||
76 | |||
77 | } | ||
78 | |||
79 | /* DOC_WaitReady: Wait for RDY line to be asserted by the flash chip */ | ||
80 | static int _DoC_WaitReady(struct DiskOnChip *doc) | ||
81 | { | ||
82 | void __iomem *docptr = doc->virtadr; | ||
83 | unsigned long timeo = jiffies + (HZ * 10); | ||
84 | |||
85 | pr_debug("_DoC_WaitReady called for out-of-line wait\n"); | ||
86 | |||
87 | /* Out-of-line routine to wait for chip response */ | ||
88 | while (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) { | ||
89 | /* issue 2 read from NOP register after reading from CDSNControl register | ||
90 | see Software Requirement 11.4 item 2. */ | ||
91 | DoC_Delay(doc, 2); | ||
92 | |||
93 | if (time_after(jiffies, timeo)) { | ||
94 | pr_debug("_DoC_WaitReady timed out.\n"); | ||
95 | return -EIO; | ||
96 | } | ||
97 | udelay(1); | ||
98 | cond_resched(); | ||
99 | } | ||
100 | |||
101 | return 0; | ||
102 | } | ||
103 | |||
104 | static inline int DoC_WaitReady(struct DiskOnChip *doc) | ||
105 | { | ||
106 | void __iomem *docptr = doc->virtadr; | ||
107 | |||
108 | /* This is inline, to optimise the common case, where it's ready instantly */ | ||
109 | int ret = 0; | ||
110 | |||
111 | /* 4 read form NOP register should be issued in prior to the read from CDSNControl | ||
112 | see Software Requirement 11.4 item 2. */ | ||
113 | DoC_Delay(doc, 4); | ||
114 | |||
115 | if (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) | ||
116 | /* Call the out-of-line routine to wait */ | ||
117 | ret = _DoC_WaitReady(doc); | ||
118 | |||
119 | /* issue 2 read from NOP register after reading from CDSNControl register | ||
120 | see Software Requirement 11.4 item 2. */ | ||
121 | DoC_Delay(doc, 2); | ||
122 | |||
123 | return ret; | ||
124 | } | ||
125 | |||
126 | /* DoC_Command: Send a flash command to the flash chip through the CDSN Slow IO register to | ||
127 | bypass the internal pipeline. Each of 4 delay cycles (read from the NOP register) is | ||
128 | required after writing to CDSN Control register, see Software Requirement 11.4 item 3. */ | ||
129 | |||
130 | static int DoC_Command(struct DiskOnChip *doc, unsigned char command, | ||
131 | unsigned char xtraflags) | ||
132 | { | ||
133 | void __iomem *docptr = doc->virtadr; | ||
134 | |||
135 | if (DoC_is_2000(doc)) | ||
136 | xtraflags |= CDSN_CTRL_FLASH_IO; | ||
137 | |||
138 | /* Assert the CLE (Command Latch Enable) line to the flash chip */ | ||
139 | WriteDOC(xtraflags | CDSN_CTRL_CLE | CDSN_CTRL_CE, docptr, CDSNControl); | ||
140 | DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */ | ||
141 | |||
142 | if (DoC_is_Millennium(doc)) | ||
143 | WriteDOC(command, docptr, CDSNSlowIO); | ||
144 | |||
145 | /* Send the command */ | ||
146 | WriteDOC_(command, docptr, doc->ioreg); | ||
147 | if (DoC_is_Millennium(doc)) | ||
148 | WriteDOC(command, docptr, WritePipeTerm); | ||
149 | |||
150 | /* Lower the CLE line */ | ||
151 | WriteDOC(xtraflags | CDSN_CTRL_CE, docptr, CDSNControl); | ||
152 | DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */ | ||
153 | |||
154 | /* Wait for the chip to respond - Software requirement 11.4.1 (extended for any command) */ | ||
155 | return DoC_WaitReady(doc); | ||
156 | } | ||
157 | |||
158 | /* DoC_Address: Set the current address for the flash chip through the CDSN Slow IO register to | ||
159 | bypass the internal pipeline. Each of 4 delay cycles (read from the NOP register) is | ||
160 | required after writing to CDSN Control register, see Software Requirement 11.4 item 3. */ | ||
161 | |||
162 | static int DoC_Address(struct DiskOnChip *doc, int numbytes, unsigned long ofs, | ||
163 | unsigned char xtraflags1, unsigned char xtraflags2) | ||
164 | { | ||
165 | int i; | ||
166 | void __iomem *docptr = doc->virtadr; | ||
167 | |||
168 | if (DoC_is_2000(doc)) | ||
169 | xtraflags1 |= CDSN_CTRL_FLASH_IO; | ||
170 | |||
171 | /* Assert the ALE (Address Latch Enable) line to the flash chip */ | ||
172 | WriteDOC(xtraflags1 | CDSN_CTRL_ALE | CDSN_CTRL_CE, docptr, CDSNControl); | ||
173 | |||
174 | DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */ | ||
175 | |||
176 | /* Send the address */ | ||
177 | /* Devices with 256-byte page are addressed as: | ||
178 | Column (bits 0-7), Page (bits 8-15, 16-23, 24-31) | ||
179 | * there is no device on the market with page256 | ||
180 | and more than 24 bits. | ||
181 | Devices with 512-byte page are addressed as: | ||
182 | Column (bits 0-7), Page (bits 9-16, 17-24, 25-31) | ||
183 | * 25-31 is sent only if the chip support it. | ||
184 | * bit 8 changes the read command to be sent | ||
185 | (NAND_CMD_READ0 or NAND_CMD_READ1). | ||
186 | */ | ||
187 | |||
188 | if (numbytes == ADDR_COLUMN || numbytes == ADDR_COLUMN_PAGE) { | ||
189 | if (DoC_is_Millennium(doc)) | ||
190 | WriteDOC(ofs & 0xff, docptr, CDSNSlowIO); | ||
191 | WriteDOC_(ofs & 0xff, docptr, doc->ioreg); | ||
192 | } | ||
193 | |||
194 | if (doc->page256) { | ||
195 | ofs = ofs >> 8; | ||
196 | } else { | ||
197 | ofs = ofs >> 9; | ||
198 | } | ||
199 | |||
200 | if (numbytes == ADDR_PAGE || numbytes == ADDR_COLUMN_PAGE) { | ||
201 | for (i = 0; i < doc->pageadrlen; i++, ofs = ofs >> 8) { | ||
202 | if (DoC_is_Millennium(doc)) | ||
203 | WriteDOC(ofs & 0xff, docptr, CDSNSlowIO); | ||
204 | WriteDOC_(ofs & 0xff, docptr, doc->ioreg); | ||
205 | } | ||
206 | } | ||
207 | |||
208 | if (DoC_is_Millennium(doc)) | ||
209 | WriteDOC(ofs & 0xff, docptr, WritePipeTerm); | ||
210 | |||
211 | DoC_Delay(doc, 2); /* Needed for some slow flash chips. mf. */ | ||
212 | |||
213 | /* FIXME: The SlowIO's for millennium could be replaced by | ||
214 | a single WritePipeTerm here. mf. */ | ||
215 | |||
216 | /* Lower the ALE line */ | ||
217 | WriteDOC(xtraflags1 | xtraflags2 | CDSN_CTRL_CE, docptr, | ||
218 | CDSNControl); | ||
219 | |||
220 | DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */ | ||
221 | |||
222 | /* Wait for the chip to respond - Software requirement 11.4.1 */ | ||
223 | return DoC_WaitReady(doc); | ||
224 | } | ||
225 | |||
226 | /* Read a buffer from DoC, taking care of Millennium odditys */ | ||
227 | static void DoC_ReadBuf(struct DiskOnChip *doc, u_char * buf, int len) | ||
228 | { | ||
229 | volatile int dummy; | ||
230 | int modulus = 0xffff; | ||
231 | void __iomem *docptr = doc->virtadr; | ||
232 | int i; | ||
233 | |||
234 | if (len <= 0) | ||
235 | return; | ||
236 | |||
237 | if (DoC_is_Millennium(doc)) { | ||
238 | /* Read the data via the internal pipeline through CDSN IO register, | ||
239 | see Pipelined Read Operations 11.3 */ | ||
240 | dummy = ReadDOC(docptr, ReadPipeInit); | ||
241 | |||
242 | /* Millennium should use the LastDataRead register - Pipeline Reads */ | ||
243 | len--; | ||
244 | |||
245 | /* This is needed for correctly ECC calculation */ | ||
246 | modulus = 0xff; | ||
247 | } | ||
248 | |||
249 | for (i = 0; i < len; i++) | ||
250 | buf[i] = ReadDOC_(docptr, doc->ioreg + (i & modulus)); | ||
251 | |||
252 | if (DoC_is_Millennium(doc)) { | ||
253 | buf[i] = ReadDOC(docptr, LastDataRead); | ||
254 | } | ||
255 | } | ||
256 | |||
257 | /* Write a buffer to DoC, taking care of Millennium odditys */ | ||
258 | static void DoC_WriteBuf(struct DiskOnChip *doc, const u_char * buf, int len) | ||
259 | { | ||
260 | void __iomem *docptr = doc->virtadr; | ||
261 | int i; | ||
262 | |||
263 | if (len <= 0) | ||
264 | return; | ||
265 | |||
266 | for (i = 0; i < len; i++) | ||
267 | WriteDOC_(buf[i], docptr, doc->ioreg + i); | ||
268 | |||
269 | if (DoC_is_Millennium(doc)) { | ||
270 | WriteDOC(0x00, docptr, WritePipeTerm); | ||
271 | } | ||
272 | } | ||
273 | |||
274 | |||
275 | /* DoC_SelectChip: Select a given flash chip within the current floor */ | ||
276 | |||
277 | static inline int DoC_SelectChip(struct DiskOnChip *doc, int chip) | ||
278 | { | ||
279 | void __iomem *docptr = doc->virtadr; | ||
280 | |||
281 | /* Software requirement 11.4.4 before writing DeviceSelect */ | ||
282 | /* Deassert the CE line to eliminate glitches on the FCE# outputs */ | ||
283 | WriteDOC(CDSN_CTRL_WP, docptr, CDSNControl); | ||
284 | DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */ | ||
285 | |||
286 | /* Select the individual flash chip requested */ | ||
287 | WriteDOC(chip, docptr, CDSNDeviceSelect); | ||
288 | DoC_Delay(doc, 4); | ||
289 | |||
290 | /* Reassert the CE line */ | ||
291 | WriteDOC(CDSN_CTRL_CE | CDSN_CTRL_FLASH_IO | CDSN_CTRL_WP, docptr, | ||
292 | CDSNControl); | ||
293 | DoC_Delay(doc, 4); /* Software requirement 11.4.3 for Millennium */ | ||
294 | |||
295 | /* Wait for it to be ready */ | ||
296 | return DoC_WaitReady(doc); | ||
297 | } | ||
298 | |||
299 | /* DoC_SelectFloor: Select a given floor (bank of flash chips) */ | ||
300 | |||
301 | static inline int DoC_SelectFloor(struct DiskOnChip *doc, int floor) | ||
302 | { | ||
303 | void __iomem *docptr = doc->virtadr; | ||
304 | |||
305 | /* Select the floor (bank) of chips required */ | ||
306 | WriteDOC(floor, docptr, FloorSelect); | ||
307 | |||
308 | /* Wait for the chip to be ready */ | ||
309 | return DoC_WaitReady(doc); | ||
310 | } | ||
311 | |||
312 | /* DoC_IdentChip: Identify a given NAND chip given {floor,chip} */ | ||
313 | |||
314 | static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip) | ||
315 | { | ||
316 | int mfr, id, i, j; | ||
317 | volatile char dummy; | ||
318 | |||
319 | /* Page in the required floor/chip */ | ||
320 | DoC_SelectFloor(doc, floor); | ||
321 | DoC_SelectChip(doc, chip); | ||
322 | |||
323 | /* Reset the chip */ | ||
324 | if (DoC_Command(doc, NAND_CMD_RESET, CDSN_CTRL_WP)) { | ||
325 | pr_debug("DoC_Command (reset) for %d,%d returned true\n", | ||
326 | floor, chip); | ||
327 | return 0; | ||
328 | } | ||
329 | |||
330 | |||
331 | /* Read the NAND chip ID: 1. Send ReadID command */ | ||
332 | if (DoC_Command(doc, NAND_CMD_READID, CDSN_CTRL_WP)) { | ||
333 | pr_debug("DoC_Command (ReadID) for %d,%d returned true\n", | ||
334 | floor, chip); | ||
335 | return 0; | ||
336 | } | ||
337 | |||
338 | /* Read the NAND chip ID: 2. Send address byte zero */ | ||
339 | DoC_Address(doc, ADDR_COLUMN, 0, CDSN_CTRL_WP, 0); | ||
340 | |||
341 | /* Read the manufacturer and device id codes from the device */ | ||
342 | |||
343 | if (DoC_is_Millennium(doc)) { | ||
344 | DoC_Delay(doc, 2); | ||
345 | dummy = ReadDOC(doc->virtadr, ReadPipeInit); | ||
346 | mfr = ReadDOC(doc->virtadr, LastDataRead); | ||
347 | |||
348 | DoC_Delay(doc, 2); | ||
349 | dummy = ReadDOC(doc->virtadr, ReadPipeInit); | ||
350 | id = ReadDOC(doc->virtadr, LastDataRead); | ||
351 | } else { | ||
352 | /* CDSN Slow IO register see Software Req 11.4 item 5. */ | ||
353 | dummy = ReadDOC(doc->virtadr, CDSNSlowIO); | ||
354 | DoC_Delay(doc, 2); | ||
355 | mfr = ReadDOC_(doc->virtadr, doc->ioreg); | ||
356 | |||
357 | /* CDSN Slow IO register see Software Req 11.4 item 5. */ | ||
358 | dummy = ReadDOC(doc->virtadr, CDSNSlowIO); | ||
359 | DoC_Delay(doc, 2); | ||
360 | id = ReadDOC_(doc->virtadr, doc->ioreg); | ||
361 | } | ||
362 | |||
363 | /* No response - return failure */ | ||
364 | if (mfr == 0xff || mfr == 0) | ||
365 | return 0; | ||
366 | |||
367 | /* Check it's the same as the first chip we identified. | ||
368 | * M-Systems say that any given DiskOnChip device should only | ||
369 | * contain _one_ type of flash part, although that's not a | ||
370 | * hardware restriction. */ | ||
371 | if (doc->mfr) { | ||
372 | if (doc->mfr == mfr && doc->id == id) | ||
373 | return 1; /* This is the same as the first */ | ||
374 | else | ||
375 | printk(KERN_WARNING | ||
376 | "Flash chip at floor %d, chip %d is different:\n", | ||
377 | floor, chip); | ||
378 | } | ||
379 | |||
380 | /* Print and store the manufacturer and ID codes. */ | ||
381 | for (i = 0; nand_flash_ids[i].name != NULL; i++) { | ||
382 | if (id == nand_flash_ids[i].dev_id) { | ||
383 | /* Try to identify manufacturer */ | ||
384 | for (j = 0; nand_manuf_ids[j].id != 0x0; j++) { | ||
385 | if (nand_manuf_ids[j].id == mfr) | ||
386 | break; | ||
387 | } | ||
388 | printk(KERN_INFO | ||
389 | "Flash chip found: Manufacturer ID: %2.2X, " | ||
390 | "Chip ID: %2.2X (%s:%s)\n", mfr, id, | ||
391 | nand_manuf_ids[j].name, nand_flash_ids[i].name); | ||
392 | if (!doc->mfr) { | ||
393 | doc->mfr = mfr; | ||
394 | doc->id = id; | ||
395 | doc->chipshift = | ||
396 | ffs((nand_flash_ids[i].chipsize << 20)) - 1; | ||
397 | doc->page256 = (nand_flash_ids[i].pagesize == 256) ? 1 : 0; | ||
398 | doc->pageadrlen = doc->chipshift > 25 ? 3 : 2; | ||
399 | doc->erasesize = | ||
400 | nand_flash_ids[i].erasesize; | ||
401 | return 1; | ||
402 | } | ||
403 | return 0; | ||
404 | } | ||
405 | } | ||
406 | |||
407 | |||
408 | /* We haven't fully identified the chip. Print as much as we know. */ | ||
409 | printk(KERN_WARNING "Unknown flash chip found: %2.2X %2.2X\n", | ||
410 | id, mfr); | ||
411 | |||
412 | printk(KERN_WARNING "Please report to dwmw2@infradead.org\n"); | ||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | /* DoC_ScanChips: Find all NAND chips present in a DiskOnChip, and identify them */ | ||
417 | |||
418 | static void DoC_ScanChips(struct DiskOnChip *this, int maxchips) | ||
419 | { | ||
420 | int floor, chip; | ||
421 | int numchips[MAX_FLOORS]; | ||
422 | int ret = 1; | ||
423 | |||
424 | this->numchips = 0; | ||
425 | this->mfr = 0; | ||
426 | this->id = 0; | ||
427 | |||
428 | /* For each floor, find the number of valid chips it contains */ | ||
429 | for (floor = 0; floor < MAX_FLOORS; floor++) { | ||
430 | ret = 1; | ||
431 | numchips[floor] = 0; | ||
432 | for (chip = 0; chip < maxchips && ret != 0; chip++) { | ||
433 | |||
434 | ret = DoC_IdentChip(this, floor, chip); | ||
435 | if (ret) { | ||
436 | numchips[floor]++; | ||
437 | this->numchips++; | ||
438 | } | ||
439 | } | ||
440 | } | ||
441 | |||
442 | /* If there are none at all that we recognise, bail */ | ||
443 | if (!this->numchips) { | ||
444 | printk(KERN_NOTICE "No flash chips recognised.\n"); | ||
445 | return; | ||
446 | } | ||
447 | |||
448 | /* Allocate an array to hold the information for each chip */ | ||
449 | this->chips = kmalloc(sizeof(struct Nand) * this->numchips, GFP_KERNEL); | ||
450 | if (!this->chips) { | ||
451 | printk(KERN_NOTICE "No memory for allocating chip info structures\n"); | ||
452 | return; | ||
453 | } | ||
454 | |||
455 | ret = 0; | ||
456 | |||
457 | /* Fill out the chip array with {floor, chipno} for each | ||
458 | * detected chip in the device. */ | ||
459 | for (floor = 0; floor < MAX_FLOORS; floor++) { | ||
460 | for (chip = 0; chip < numchips[floor]; chip++) { | ||
461 | this->chips[ret].floor = floor; | ||
462 | this->chips[ret].chip = chip; | ||
463 | this->chips[ret].curadr = 0; | ||
464 | this->chips[ret].curmode = 0x50; | ||
465 | ret++; | ||
466 | } | ||
467 | } | ||
468 | |||
469 | /* Calculate and print the total size of the device */ | ||
470 | this->totlen = this->numchips * (1 << this->chipshift); | ||
471 | |||
472 | printk(KERN_INFO "%d flash chips found. Total DiskOnChip size: %ld MiB\n", | ||
473 | this->numchips, this->totlen >> 20); | ||
474 | } | ||
475 | |||
476 | static int DoC2k_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2) | ||
477 | { | ||
478 | int tmp1, tmp2, retval; | ||
479 | if (doc1->physadr == doc2->physadr) | ||
480 | return 1; | ||
481 | |||
482 | /* Use the alias resolution register which was set aside for this | ||
483 | * purpose. If it's value is the same on both chips, they might | ||
484 | * be the same chip, and we write to one and check for a change in | ||
485 | * the other. It's unclear if this register is usuable in the | ||
486 | * DoC 2000 (it's in the Millennium docs), but it seems to work. */ | ||
487 | tmp1 = ReadDOC(doc1->virtadr, AliasResolution); | ||
488 | tmp2 = ReadDOC(doc2->virtadr, AliasResolution); | ||
489 | if (tmp1 != tmp2) | ||
490 | return 0; | ||
491 | |||
492 | WriteDOC((tmp1 + 1) % 0xff, doc1->virtadr, AliasResolution); | ||
493 | tmp2 = ReadDOC(doc2->virtadr, AliasResolution); | ||
494 | if (tmp2 == (tmp1 + 1) % 0xff) | ||
495 | retval = 1; | ||
496 | else | ||
497 | retval = 0; | ||
498 | |||
499 | /* Restore register contents. May not be necessary, but do it just to | ||
500 | * be safe. */ | ||
501 | WriteDOC(tmp1, doc1->virtadr, AliasResolution); | ||
502 | |||
503 | return retval; | ||
504 | } | ||
505 | |||
506 | /* This routine is found from the docprobe code by symbol_get(), | ||
507 | * which will bump the use count of this module. */ | ||
508 | void DoC2k_init(struct mtd_info *mtd) | ||
509 | { | ||
510 | struct DiskOnChip *this = mtd->priv; | ||
511 | struct DiskOnChip *old = NULL; | ||
512 | int maxchips; | ||
513 | |||
514 | /* We must avoid being called twice for the same device. */ | ||
515 | |||
516 | if (doc2klist) | ||
517 | old = doc2klist->priv; | ||
518 | |||
519 | while (old) { | ||
520 | if (DoC2k_is_alias(old, this)) { | ||
521 | printk(KERN_NOTICE | ||
522 | "Ignoring DiskOnChip 2000 at 0x%lX - already configured\n", | ||
523 | this->physadr); | ||
524 | iounmap(this->virtadr); | ||
525 | kfree(mtd); | ||
526 | return; | ||
527 | } | ||
528 | if (old->nextdoc) | ||
529 | old = old->nextdoc->priv; | ||
530 | else | ||
531 | old = NULL; | ||
532 | } | ||
533 | |||
534 | |||
535 | switch (this->ChipID) { | ||
536 | case DOC_ChipID_Doc2kTSOP: | ||
537 | mtd->name = "DiskOnChip 2000 TSOP"; | ||
538 | this->ioreg = DoC_Mil_CDSN_IO; | ||
539 | /* Pretend it's a Millennium */ | ||
540 | this->ChipID = DOC_ChipID_DocMil; | ||
541 | maxchips = MAX_CHIPS; | ||
542 | break; | ||
543 | case DOC_ChipID_Doc2k: | ||
544 | mtd->name = "DiskOnChip 2000"; | ||
545 | this->ioreg = DoC_2k_CDSN_IO; | ||
546 | maxchips = MAX_CHIPS; | ||
547 | break; | ||
548 | case DOC_ChipID_DocMil: | ||
549 | mtd->name = "DiskOnChip Millennium"; | ||
550 | this->ioreg = DoC_Mil_CDSN_IO; | ||
551 | maxchips = MAX_CHIPS_MIL; | ||
552 | break; | ||
553 | default: | ||
554 | printk("Unknown ChipID 0x%02x\n", this->ChipID); | ||
555 | kfree(mtd); | ||
556 | iounmap(this->virtadr); | ||
557 | return; | ||
558 | } | ||
559 | |||
560 | printk(KERN_NOTICE "%s found at address 0x%lX\n", mtd->name, | ||
561 | this->physadr); | ||
562 | |||
563 | mtd->type = MTD_NANDFLASH; | ||
564 | mtd->flags = MTD_CAP_NANDFLASH; | ||
565 | mtd->writebufsize = mtd->writesize = 512; | ||
566 | mtd->oobsize = 16; | ||
567 | mtd->ecc_strength = 2; | ||
568 | mtd->owner = THIS_MODULE; | ||
569 | mtd->_erase = doc_erase; | ||
570 | mtd->_read = doc_read; | ||
571 | mtd->_write = doc_write; | ||
572 | mtd->_read_oob = doc_read_oob; | ||
573 | mtd->_write_oob = doc_write_oob; | ||
574 | this->curfloor = -1; | ||
575 | this->curchip = -1; | ||
576 | mutex_init(&this->lock); | ||
577 | |||
578 | /* Ident all the chips present. */ | ||
579 | DoC_ScanChips(this, maxchips); | ||
580 | |||
581 | if (!this->totlen) { | ||
582 | kfree(mtd); | ||
583 | iounmap(this->virtadr); | ||
584 | } else { | ||
585 | this->nextdoc = doc2klist; | ||
586 | doc2klist = mtd; | ||
587 | mtd->size = this->totlen; | ||
588 | mtd->erasesize = this->erasesize; | ||
589 | mtd_device_register(mtd, NULL, 0); | ||
590 | return; | ||
591 | } | ||
592 | } | ||
593 | EXPORT_SYMBOL_GPL(DoC2k_init); | ||
594 | |||
595 | static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, | ||
596 | size_t * retlen, u_char * buf) | ||
597 | { | ||
598 | struct DiskOnChip *this = mtd->priv; | ||
599 | void __iomem *docptr = this->virtadr; | ||
600 | struct Nand *mychip; | ||
601 | unsigned char syndrome[6], eccbuf[6]; | ||
602 | volatile char dummy; | ||
603 | int i, len256 = 0, ret=0; | ||
604 | size_t left = len; | ||
605 | |||
606 | mutex_lock(&this->lock); | ||
607 | while (left) { | ||
608 | len = left; | ||
609 | |||
610 | /* Don't allow a single read to cross a 512-byte block boundary */ | ||
611 | if (from + len > ((from | 0x1ff) + 1)) | ||
612 | len = ((from | 0x1ff) + 1) - from; | ||
613 | |||
614 | /* The ECC will not be calculated correctly if less than 512 is read */ | ||
615 | if (len != 0x200) | ||
616 | printk(KERN_WARNING | ||
617 | "ECC needs a full sector read (adr: %lx size %lx)\n", | ||
618 | (long) from, (long) len); | ||
619 | |||
620 | /* printk("DoC_Read (adr: %lx size %lx)\n", (long) from, (long) len); */ | ||
621 | |||
622 | |||
623 | /* Find the chip which is to be used and select it */ | ||
624 | mychip = &this->chips[from >> (this->chipshift)]; | ||
625 | |||
626 | if (this->curfloor != mychip->floor) { | ||
627 | DoC_SelectFloor(this, mychip->floor); | ||
628 | DoC_SelectChip(this, mychip->chip); | ||
629 | } else if (this->curchip != mychip->chip) { | ||
630 | DoC_SelectChip(this, mychip->chip); | ||
631 | } | ||
632 | |||
633 | this->curfloor = mychip->floor; | ||
634 | this->curchip = mychip->chip; | ||
635 | |||
636 | DoC_Command(this, | ||
637 | (!this->page256 | ||
638 | && (from & 0x100)) ? NAND_CMD_READ1 : NAND_CMD_READ0, | ||
639 | CDSN_CTRL_WP); | ||
640 | DoC_Address(this, ADDR_COLUMN_PAGE, from, CDSN_CTRL_WP, | ||
641 | CDSN_CTRL_ECC_IO); | ||
642 | |||
643 | /* Prime the ECC engine */ | ||
644 | WriteDOC(DOC_ECC_RESET, docptr, ECCConf); | ||
645 | WriteDOC(DOC_ECC_EN, docptr, ECCConf); | ||
646 | |||
647 | /* treat crossing 256-byte sector for 2M x 8bits devices */ | ||
648 | if (this->page256 && from + len > (from | 0xff) + 1) { | ||
649 | len256 = (from | 0xff) + 1 - from; | ||
650 | DoC_ReadBuf(this, buf, len256); | ||
651 | |||
652 | DoC_Command(this, NAND_CMD_READ0, CDSN_CTRL_WP); | ||
653 | DoC_Address(this, ADDR_COLUMN_PAGE, from + len256, | ||
654 | CDSN_CTRL_WP, CDSN_CTRL_ECC_IO); | ||
655 | } | ||
656 | |||
657 | DoC_ReadBuf(this, &buf[len256], len - len256); | ||
658 | |||
659 | /* Let the caller know we completed it */ | ||
660 | *retlen += len; | ||
661 | |||
662 | /* Read the ECC data through the DiskOnChip ECC logic */ | ||
663 | /* Note: this will work even with 2M x 8bit devices as */ | ||
664 | /* they have 8 bytes of OOB per 256 page. mf. */ | ||
665 | DoC_ReadBuf(this, eccbuf, 6); | ||
666 | |||
667 | /* Flush the pipeline */ | ||
668 | if (DoC_is_Millennium(this)) { | ||
669 | dummy = ReadDOC(docptr, ECCConf); | ||
670 | dummy = ReadDOC(docptr, ECCConf); | ||
671 | i = ReadDOC(docptr, ECCConf); | ||
672 | } else { | ||
673 | dummy = ReadDOC(docptr, 2k_ECCStatus); | ||
674 | dummy = ReadDOC(docptr, 2k_ECCStatus); | ||
675 | i = ReadDOC(docptr, 2k_ECCStatus); | ||
676 | } | ||
677 | |||
678 | /* Check the ECC Status */ | ||
679 | if (i & 0x80) { | ||
680 | int nb_errors; | ||
681 | /* There was an ECC error */ | ||
682 | #ifdef ECC_DEBUG | ||
683 | printk(KERN_ERR "DiskOnChip ECC Error: Read at %lx\n", (long)from); | ||
684 | #endif | ||
685 | /* Read the ECC syndrome through the DiskOnChip ECC | ||
686 | logic. These syndrome will be all ZERO when there | ||
687 | is no error */ | ||
688 | for (i = 0; i < 6; i++) { | ||
689 | syndrome[i] = | ||
690 | ReadDOC(docptr, ECCSyndrome0 + i); | ||
691 | } | ||
692 | nb_errors = doc_decode_ecc(buf, syndrome); | ||
693 | |||
694 | #ifdef ECC_DEBUG | ||
695 | printk(KERN_ERR "Errors corrected: %x\n", nb_errors); | ||
696 | #endif | ||
697 | if (nb_errors < 0) { | ||
698 | /* We return error, but have actually done the | ||
699 | read. Not that this can be told to | ||
700 | user-space, via sys_read(), but at least | ||
701 | MTD-aware stuff can know about it by | ||
702 | checking *retlen */ | ||
703 | ret = -EIO; | ||
704 | } | ||
705 | } | ||
706 | |||
707 | #ifdef PSYCHO_DEBUG | ||
708 | printk(KERN_DEBUG "ECC DATA at %lxB: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", | ||
709 | (long)from, eccbuf[0], eccbuf[1], eccbuf[2], | ||
710 | eccbuf[3], eccbuf[4], eccbuf[5]); | ||
711 | #endif | ||
712 | |||
713 | /* disable the ECC engine */ | ||
714 | WriteDOC(DOC_ECC_DIS, docptr , ECCConf); | ||
715 | |||
716 | /* according to 11.4.1, we need to wait for the busy line | ||
717 | * drop if we read to the end of the page. */ | ||
718 | if(0 == ((from + len) & 0x1ff)) | ||
719 | { | ||
720 | DoC_WaitReady(this); | ||
721 | } | ||
722 | |||
723 | from += len; | ||
724 | left -= len; | ||
725 | buf += len; | ||
726 | } | ||
727 | |||
728 | mutex_unlock(&this->lock); | ||
729 | |||
730 | return ret; | ||
731 | } | ||
732 | |||
733 | static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, | ||
734 | size_t * retlen, const u_char * buf) | ||
735 | { | ||
736 | struct DiskOnChip *this = mtd->priv; | ||
737 | int di; /* Yes, DI is a hangover from when I was disassembling the binary driver */ | ||
738 | void __iomem *docptr = this->virtadr; | ||
739 | unsigned char eccbuf[6]; | ||
740 | volatile char dummy; | ||
741 | int len256 = 0; | ||
742 | struct Nand *mychip; | ||
743 | size_t left = len; | ||
744 | int status; | ||
745 | |||
746 | mutex_lock(&this->lock); | ||
747 | while (left) { | ||
748 | len = left; | ||
749 | |||
750 | /* Don't allow a single write to cross a 512-byte block boundary */ | ||
751 | if (to + len > ((to | 0x1ff) + 1)) | ||
752 | len = ((to | 0x1ff) + 1) - to; | ||
753 | |||
754 | /* The ECC will not be calculated correctly if less than 512 is written */ | ||
755 | /* DBB- | ||
756 | if (len != 0x200 && eccbuf) | ||
757 | printk(KERN_WARNING | ||
758 | "ECC needs a full sector write (adr: %lx size %lx)\n", | ||
759 | (long) to, (long) len); | ||
760 | -DBB */ | ||
761 | |||
762 | /* printk("DoC_Write (adr: %lx size %lx)\n", (long) to, (long) len); */ | ||
763 | |||
764 | /* Find the chip which is to be used and select it */ | ||
765 | mychip = &this->chips[to >> (this->chipshift)]; | ||
766 | |||
767 | if (this->curfloor != mychip->floor) { | ||
768 | DoC_SelectFloor(this, mychip->floor); | ||
769 | DoC_SelectChip(this, mychip->chip); | ||
770 | } else if (this->curchip != mychip->chip) { | ||
771 | DoC_SelectChip(this, mychip->chip); | ||
772 | } | ||
773 | |||
774 | this->curfloor = mychip->floor; | ||
775 | this->curchip = mychip->chip; | ||
776 | |||
777 | /* Set device to main plane of flash */ | ||
778 | DoC_Command(this, NAND_CMD_RESET, CDSN_CTRL_WP); | ||
779 | DoC_Command(this, | ||
780 | (!this->page256 | ||
781 | && (to & 0x100)) ? NAND_CMD_READ1 : NAND_CMD_READ0, | ||
782 | CDSN_CTRL_WP); | ||
783 | |||
784 | DoC_Command(this, NAND_CMD_SEQIN, 0); | ||
785 | DoC_Address(this, ADDR_COLUMN_PAGE, to, 0, CDSN_CTRL_ECC_IO); | ||
786 | |||
787 | /* Prime the ECC engine */ | ||
788 | WriteDOC(DOC_ECC_RESET, docptr, ECCConf); | ||
789 | WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, ECCConf); | ||
790 | |||
791 | /* treat crossing 256-byte sector for 2M x 8bits devices */ | ||
792 | if (this->page256 && to + len > (to | 0xff) + 1) { | ||
793 | len256 = (to | 0xff) + 1 - to; | ||
794 | DoC_WriteBuf(this, buf, len256); | ||
795 | |||
796 | DoC_Command(this, NAND_CMD_PAGEPROG, 0); | ||
797 | |||
798 | DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP); | ||
799 | /* There's an implicit DoC_WaitReady() in DoC_Command */ | ||
800 | |||
801 | dummy = ReadDOC(docptr, CDSNSlowIO); | ||
802 | DoC_Delay(this, 2); | ||
803 | |||
804 | if (ReadDOC_(docptr, this->ioreg) & 1) { | ||
805 | printk(KERN_ERR "Error programming flash\n"); | ||
806 | /* Error in programming */ | ||
807 | *retlen = 0; | ||
808 | mutex_unlock(&this->lock); | ||
809 | return -EIO; | ||
810 | } | ||
811 | |||
812 | DoC_Command(this, NAND_CMD_SEQIN, 0); | ||
813 | DoC_Address(this, ADDR_COLUMN_PAGE, to + len256, 0, | ||
814 | CDSN_CTRL_ECC_IO); | ||
815 | } | ||
816 | |||
817 | DoC_WriteBuf(this, &buf[len256], len - len256); | ||
818 | |||
819 | WriteDOC(CDSN_CTRL_ECC_IO | CDSN_CTRL_CE, docptr, CDSNControl); | ||
820 | |||
821 | if (DoC_is_Millennium(this)) { | ||
822 | WriteDOC(0, docptr, NOP); | ||
823 | WriteDOC(0, docptr, NOP); | ||
824 | WriteDOC(0, docptr, NOP); | ||
825 | } else { | ||
826 | WriteDOC_(0, docptr, this->ioreg); | ||
827 | WriteDOC_(0, docptr, this->ioreg); | ||
828 | WriteDOC_(0, docptr, this->ioreg); | ||
829 | } | ||
830 | |||
831 | WriteDOC(CDSN_CTRL_ECC_IO | CDSN_CTRL_FLASH_IO | CDSN_CTRL_CE, docptr, | ||
832 | CDSNControl); | ||
833 | |||
834 | /* Read the ECC data through the DiskOnChip ECC logic */ | ||
835 | for (di = 0; di < 6; di++) { | ||
836 | eccbuf[di] = ReadDOC(docptr, ECCSyndrome0 + di); | ||
837 | } | ||
838 | |||
839 | /* Reset the ECC engine */ | ||
840 | WriteDOC(DOC_ECC_DIS, docptr, ECCConf); | ||
841 | |||
842 | #ifdef PSYCHO_DEBUG | ||
843 | printk | ||
844 | ("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", | ||
845 | (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3], | ||
846 | eccbuf[4], eccbuf[5]); | ||
847 | #endif | ||
848 | DoC_Command(this, NAND_CMD_PAGEPROG, 0); | ||
849 | |||
850 | DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP); | ||
851 | /* There's an implicit DoC_WaitReady() in DoC_Command */ | ||
852 | |||
853 | if (DoC_is_Millennium(this)) { | ||
854 | ReadDOC(docptr, ReadPipeInit); | ||
855 | status = ReadDOC(docptr, LastDataRead); | ||
856 | } else { | ||
857 | dummy = ReadDOC(docptr, CDSNSlowIO); | ||
858 | DoC_Delay(this, 2); | ||
859 | status = ReadDOC_(docptr, this->ioreg); | ||
860 | } | ||
861 | |||
862 | if (status & 1) { | ||
863 | printk(KERN_ERR "Error programming flash\n"); | ||
864 | /* Error in programming */ | ||
865 | *retlen = 0; | ||
866 | mutex_unlock(&this->lock); | ||
867 | return -EIO; | ||
868 | } | ||
869 | |||
870 | /* Let the caller know we completed it */ | ||
871 | *retlen += len; | ||
872 | |||
873 | { | ||
874 | unsigned char x[8]; | ||
875 | size_t dummy; | ||
876 | int ret; | ||
877 | |||
878 | /* Write the ECC data to flash */ | ||
879 | for (di=0; di<6; di++) | ||
880 | x[di] = eccbuf[di]; | ||
881 | |||
882 | x[6]=0x55; | ||
883 | x[7]=0x55; | ||
884 | |||
885 | ret = doc_write_oob_nolock(mtd, to, 8, &dummy, x); | ||
886 | if (ret) { | ||
887 | mutex_unlock(&this->lock); | ||
888 | return ret; | ||
889 | } | ||
890 | } | ||
891 | |||
892 | to += len; | ||
893 | left -= len; | ||
894 | buf += len; | ||
895 | } | ||
896 | |||
897 | mutex_unlock(&this->lock); | ||
898 | return 0; | ||
899 | } | ||
900 | |||
901 | static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, | ||
902 | struct mtd_oob_ops *ops) | ||
903 | { | ||
904 | struct DiskOnChip *this = mtd->priv; | ||
905 | int len256 = 0, ret; | ||
906 | struct Nand *mychip; | ||
907 | uint8_t *buf = ops->oobbuf; | ||
908 | size_t len = ops->len; | ||
909 | |||
910 | BUG_ON(ops->mode != MTD_OPS_PLACE_OOB); | ||
911 | |||
912 | ofs += ops->ooboffs; | ||
913 | |||
914 | mutex_lock(&this->lock); | ||
915 | |||
916 | mychip = &this->chips[ofs >> this->chipshift]; | ||
917 | |||
918 | if (this->curfloor != mychip->floor) { | ||
919 | DoC_SelectFloor(this, mychip->floor); | ||
920 | DoC_SelectChip(this, mychip->chip); | ||
921 | } else if (this->curchip != mychip->chip) { | ||
922 | DoC_SelectChip(this, mychip->chip); | ||
923 | } | ||
924 | this->curfloor = mychip->floor; | ||
925 | this->curchip = mychip->chip; | ||
926 | |||
927 | /* update address for 2M x 8bit devices. OOB starts on the second */ | ||
928 | /* page to maintain compatibility with doc_read_ecc. */ | ||
929 | if (this->page256) { | ||
930 | if (!(ofs & 0x8)) | ||
931 | ofs += 0x100; | ||
932 | else | ||
933 | ofs -= 0x8; | ||
934 | } | ||
935 | |||
936 | DoC_Command(this, NAND_CMD_READOOB, CDSN_CTRL_WP); | ||
937 | DoC_Address(this, ADDR_COLUMN_PAGE, ofs, CDSN_CTRL_WP, 0); | ||
938 | |||
939 | /* treat crossing 8-byte OOB data for 2M x 8bit devices */ | ||
940 | /* Note: datasheet says it should automaticaly wrap to the */ | ||
941 | /* next OOB block, but it didn't work here. mf. */ | ||
942 | if (this->page256 && ofs + len > (ofs | 0x7) + 1) { | ||
943 | len256 = (ofs | 0x7) + 1 - ofs; | ||
944 | DoC_ReadBuf(this, buf, len256); | ||
945 | |||
946 | DoC_Command(this, NAND_CMD_READOOB, CDSN_CTRL_WP); | ||
947 | DoC_Address(this, ADDR_COLUMN_PAGE, ofs & (~0x1ff), | ||
948 | CDSN_CTRL_WP, 0); | ||
949 | } | ||
950 | |||
951 | DoC_ReadBuf(this, &buf[len256], len - len256); | ||
952 | |||
953 | ops->retlen = len; | ||
954 | /* Reading the full OOB data drops us off of the end of the page, | ||
955 | * causing the flash device to go into busy mode, so we need | ||
956 | * to wait until ready 11.4.1 and Toshiba TC58256FT docs */ | ||
957 | |||
958 | ret = DoC_WaitReady(this); | ||
959 | |||
960 | mutex_unlock(&this->lock); | ||
961 | return ret; | ||
962 | |||
963 | } | ||
964 | |||
965 | static int doc_write_oob_nolock(struct mtd_info *mtd, loff_t ofs, size_t len, | ||
966 | size_t * retlen, const u_char * buf) | ||
967 | { | ||
968 | struct DiskOnChip *this = mtd->priv; | ||
969 | int len256 = 0; | ||
970 | void __iomem *docptr = this->virtadr; | ||
971 | struct Nand *mychip = &this->chips[ofs >> this->chipshift]; | ||
972 | volatile int dummy; | ||
973 | int status; | ||
974 | |||
975 | // printk("doc_write_oob(%lx, %d): %2.2X %2.2X %2.2X %2.2X ... %2.2X %2.2X .. %2.2X %2.2X\n",(long)ofs, len, | ||
976 | // buf[0], buf[1], buf[2], buf[3], buf[8], buf[9], buf[14],buf[15]); | ||
977 | |||
978 | /* Find the chip which is to be used and select it */ | ||
979 | if (this->curfloor != mychip->floor) { | ||
980 | DoC_SelectFloor(this, mychip->floor); | ||
981 | DoC_SelectChip(this, mychip->chip); | ||
982 | } else if (this->curchip != mychip->chip) { | ||
983 | DoC_SelectChip(this, mychip->chip); | ||
984 | } | ||
985 | this->curfloor = mychip->floor; | ||
986 | this->curchip = mychip->chip; | ||
987 | |||
988 | /* disable the ECC engine */ | ||
989 | WriteDOC (DOC_ECC_RESET, docptr, ECCConf); | ||
990 | WriteDOC (DOC_ECC_DIS, docptr, ECCConf); | ||
991 | |||
992 | /* Reset the chip, see Software Requirement 11.4 item 1. */ | ||
993 | DoC_Command(this, NAND_CMD_RESET, CDSN_CTRL_WP); | ||
994 | |||
995 | /* issue the Read2 command to set the pointer to the Spare Data Area. */ | ||
996 | DoC_Command(this, NAND_CMD_READOOB, CDSN_CTRL_WP); | ||
997 | |||
998 | /* update address for 2M x 8bit devices. OOB starts on the second */ | ||
999 | /* page to maintain compatibility with doc_read_ecc. */ | ||
1000 | if (this->page256) { | ||
1001 | if (!(ofs & 0x8)) | ||
1002 | ofs += 0x100; | ||
1003 | else | ||
1004 | ofs -= 0x8; | ||
1005 | } | ||
1006 | |||
1007 | /* issue the Serial Data In command to initial the Page Program process */ | ||
1008 | DoC_Command(this, NAND_CMD_SEQIN, 0); | ||
1009 | DoC_Address(this, ADDR_COLUMN_PAGE, ofs, 0, 0); | ||
1010 | |||
1011 | /* treat crossing 8-byte OOB data for 2M x 8bit devices */ | ||
1012 | /* Note: datasheet says it should automaticaly wrap to the */ | ||
1013 | /* next OOB block, but it didn't work here. mf. */ | ||
1014 | if (this->page256 && ofs + len > (ofs | 0x7) + 1) { | ||
1015 | len256 = (ofs | 0x7) + 1 - ofs; | ||
1016 | DoC_WriteBuf(this, buf, len256); | ||
1017 | |||
1018 | DoC_Command(this, NAND_CMD_PAGEPROG, 0); | ||
1019 | DoC_Command(this, NAND_CMD_STATUS, 0); | ||
1020 | /* DoC_WaitReady() is implicit in DoC_Command */ | ||
1021 | |||
1022 | if (DoC_is_Millennium(this)) { | ||
1023 | ReadDOC(docptr, ReadPipeInit); | ||
1024 | status = ReadDOC(docptr, LastDataRead); | ||
1025 | } else { | ||
1026 | dummy = ReadDOC(docptr, CDSNSlowIO); | ||
1027 | DoC_Delay(this, 2); | ||
1028 | status = ReadDOC_(docptr, this->ioreg); | ||
1029 | } | ||
1030 | |||
1031 | if (status & 1) { | ||
1032 | printk(KERN_ERR "Error programming oob data\n"); | ||
1033 | /* There was an error */ | ||
1034 | *retlen = 0; | ||
1035 | return -EIO; | ||
1036 | } | ||
1037 | DoC_Command(this, NAND_CMD_SEQIN, 0); | ||
1038 | DoC_Address(this, ADDR_COLUMN_PAGE, ofs & (~0x1ff), 0, 0); | ||
1039 | } | ||
1040 | |||
1041 | DoC_WriteBuf(this, &buf[len256], len - len256); | ||
1042 | |||
1043 | DoC_Command(this, NAND_CMD_PAGEPROG, 0); | ||
1044 | DoC_Command(this, NAND_CMD_STATUS, 0); | ||
1045 | /* DoC_WaitReady() is implicit in DoC_Command */ | ||
1046 | |||
1047 | if (DoC_is_Millennium(this)) { | ||
1048 | ReadDOC(docptr, ReadPipeInit); | ||
1049 | status = ReadDOC(docptr, LastDataRead); | ||
1050 | } else { | ||
1051 | dummy = ReadDOC(docptr, CDSNSlowIO); | ||
1052 | DoC_Delay(this, 2); | ||
1053 | status = ReadDOC_(docptr, this->ioreg); | ||
1054 | } | ||
1055 | |||
1056 | if (status & 1) { | ||
1057 | printk(KERN_ERR "Error programming oob data\n"); | ||
1058 | /* There was an error */ | ||
1059 | *retlen = 0; | ||
1060 | return -EIO; | ||
1061 | } | ||
1062 | |||
1063 | *retlen = len; | ||
1064 | return 0; | ||
1065 | |||
1066 | } | ||
1067 | |||
1068 | static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, | ||
1069 | struct mtd_oob_ops *ops) | ||
1070 | { | ||
1071 | struct DiskOnChip *this = mtd->priv; | ||
1072 | int ret; | ||
1073 | |||
1074 | BUG_ON(ops->mode != MTD_OPS_PLACE_OOB); | ||
1075 | |||
1076 | mutex_lock(&this->lock); | ||
1077 | ret = doc_write_oob_nolock(mtd, ofs + ops->ooboffs, ops->len, | ||
1078 | &ops->retlen, ops->oobbuf); | ||
1079 | |||
1080 | mutex_unlock(&this->lock); | ||
1081 | return ret; | ||
1082 | } | ||
1083 | |||
1084 | static int doc_erase(struct mtd_info *mtd, struct erase_info *instr) | ||
1085 | { | ||
1086 | struct DiskOnChip *this = mtd->priv; | ||
1087 | __u32 ofs = instr->addr; | ||
1088 | __u32 len = instr->len; | ||
1089 | volatile int dummy; | ||
1090 | void __iomem *docptr = this->virtadr; | ||
1091 | struct Nand *mychip; | ||
1092 | int status; | ||
1093 | |||
1094 | mutex_lock(&this->lock); | ||
1095 | |||
1096 | if (ofs & (mtd->erasesize-1) || len & (mtd->erasesize-1)) { | ||
1097 | mutex_unlock(&this->lock); | ||
1098 | return -EINVAL; | ||
1099 | } | ||
1100 | |||
1101 | instr->state = MTD_ERASING; | ||
1102 | |||
1103 | /* FIXME: Do this in the background. Use timers or schedule_task() */ | ||
1104 | while(len) { | ||
1105 | mychip = &this->chips[ofs >> this->chipshift]; | ||
1106 | |||
1107 | if (this->curfloor != mychip->floor) { | ||
1108 | DoC_SelectFloor(this, mychip->floor); | ||
1109 | DoC_SelectChip(this, mychip->chip); | ||
1110 | } else if (this->curchip != mychip->chip) { | ||
1111 | DoC_SelectChip(this, mychip->chip); | ||
1112 | } | ||
1113 | this->curfloor = mychip->floor; | ||
1114 | this->curchip = mychip->chip; | ||
1115 | |||
1116 | DoC_Command(this, NAND_CMD_ERASE1, 0); | ||
1117 | DoC_Address(this, ADDR_PAGE, ofs, 0, 0); | ||
1118 | DoC_Command(this, NAND_CMD_ERASE2, 0); | ||
1119 | |||
1120 | DoC_Command(this, NAND_CMD_STATUS, CDSN_CTRL_WP); | ||
1121 | |||
1122 | if (DoC_is_Millennium(this)) { | ||
1123 | ReadDOC(docptr, ReadPipeInit); | ||
1124 | status = ReadDOC(docptr, LastDataRead); | ||
1125 | } else { | ||
1126 | dummy = ReadDOC(docptr, CDSNSlowIO); | ||
1127 | DoC_Delay(this, 2); | ||
1128 | status = ReadDOC_(docptr, this->ioreg); | ||
1129 | } | ||
1130 | |||
1131 | if (status & 1) { | ||
1132 | printk(KERN_ERR "Error erasing at 0x%x\n", ofs); | ||
1133 | /* There was an error */ | ||
1134 | instr->state = MTD_ERASE_FAILED; | ||
1135 | goto callback; | ||
1136 | } | ||
1137 | ofs += mtd->erasesize; | ||
1138 | len -= mtd->erasesize; | ||
1139 | } | ||
1140 | instr->state = MTD_ERASE_DONE; | ||
1141 | |||
1142 | callback: | ||
1143 | mtd_erase_callback(instr); | ||
1144 | |||
1145 | mutex_unlock(&this->lock); | ||
1146 | return 0; | ||
1147 | } | ||
1148 | |||
1149 | |||
1150 | /**************************************************************************** | ||
1151 | * | ||
1152 | * Module stuff | ||
1153 | * | ||
1154 | ****************************************************************************/ | ||
1155 | |||
1156 | static void __exit cleanup_doc2000(void) | ||
1157 | { | ||
1158 | struct mtd_info *mtd; | ||
1159 | struct DiskOnChip *this; | ||
1160 | |||
1161 | while ((mtd = doc2klist)) { | ||
1162 | this = mtd->priv; | ||
1163 | doc2klist = this->nextdoc; | ||
1164 | |||
1165 | mtd_device_unregister(mtd); | ||
1166 | |||
1167 | iounmap(this->virtadr); | ||
1168 | kfree(this->chips); | ||
1169 | kfree(mtd); | ||
1170 | } | ||
1171 | } | ||
1172 | |||
1173 | module_exit(cleanup_doc2000); | ||
1174 | |||
1175 | MODULE_LICENSE("GPL"); | ||
1176 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org> et al."); | ||
1177 | MODULE_DESCRIPTION("MTD driver for DiskOnChip 2000 and Millennium"); | ||
1178 | |||
diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c deleted file mode 100644 index 00644bb92cdf..000000000000 --- a/drivers/mtd/devices/doc2001.c +++ /dev/null | |||
@@ -1,824 +0,0 @@ | |||
1 | |||
2 | /* | ||
3 | * Linux driver for Disk-On-Chip Millennium | ||
4 | * (c) 1999 Machine Vision Holdings, Inc. | ||
5 | * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org> | ||
6 | */ | ||
7 | |||
8 | #include <linux/kernel.h> | ||
9 | #include <linux/module.h> | ||
10 | #include <asm/errno.h> | ||
11 | #include <asm/io.h> | ||
12 | #include <asm/uaccess.h> | ||
13 | #include <linux/delay.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/types.h> | ||
17 | #include <linux/bitops.h> | ||
18 | |||
19 | #include <linux/mtd/mtd.h> | ||
20 | #include <linux/mtd/nand.h> | ||
21 | #include <linux/mtd/doc2000.h> | ||
22 | |||
23 | /* #define ECC_DEBUG */ | ||
24 | |||
25 | /* I have no idea why some DoC chips can not use memcop_form|to_io(). | ||
26 | * This may be due to the different revisions of the ASIC controller built-in or | ||
27 | * simplily a QA/Bug issue. Who knows ?? If you have trouble, please uncomment | ||
28 | * this:*/ | ||
29 | #undef USE_MEMCPY | ||
30 | |||
31 | static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, | ||
32 | size_t *retlen, u_char *buf); | ||
33 | static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, | ||
34 | size_t *retlen, const u_char *buf); | ||
35 | static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, | ||
36 | struct mtd_oob_ops *ops); | ||
37 | static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, | ||
38 | struct mtd_oob_ops *ops); | ||
39 | static int doc_erase (struct mtd_info *mtd, struct erase_info *instr); | ||
40 | |||
41 | static struct mtd_info *docmillist = NULL; | ||
42 | |||
43 | /* Perform the required delay cycles by reading from the NOP register */ | ||
44 | static void DoC_Delay(void __iomem * docptr, unsigned short cycles) | ||
45 | { | ||
46 | volatile char dummy; | ||
47 | int i; | ||
48 | |||
49 | for (i = 0; i < cycles; i++) | ||
50 | dummy = ReadDOC(docptr, NOP); | ||
51 | } | ||
52 | |||
53 | /* DOC_WaitReady: Wait for RDY line to be asserted by the flash chip */ | ||
54 | static int _DoC_WaitReady(void __iomem * docptr) | ||
55 | { | ||
56 | unsigned short c = 0xffff; | ||
57 | |||
58 | pr_debug("_DoC_WaitReady called for out-of-line wait\n"); | ||
59 | |||
60 | /* Out-of-line routine to wait for chip response */ | ||
61 | while (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B) && --c) | ||
62 | ; | ||
63 | |||
64 | if (c == 0) | ||
65 | pr_debug("_DoC_WaitReady timed out.\n"); | ||
66 | |||
67 | return (c == 0); | ||
68 | } | ||
69 | |||
70 | static inline int DoC_WaitReady(void __iomem * docptr) | ||
71 | { | ||
72 | /* This is inline, to optimise the common case, where it's ready instantly */ | ||
73 | int ret = 0; | ||
74 | |||
75 | /* 4 read form NOP register should be issued in prior to the read from CDSNControl | ||
76 | see Software Requirement 11.4 item 2. */ | ||
77 | DoC_Delay(docptr, 4); | ||
78 | |||
79 | if (!(ReadDOC(docptr, CDSNControl) & CDSN_CTRL_FR_B)) | ||
80 | /* Call the out-of-line routine to wait */ | ||
81 | ret = _DoC_WaitReady(docptr); | ||
82 | |||
83 | /* issue 2 read from NOP register after reading from CDSNControl register | ||
84 | see Software Requirement 11.4 item 2. */ | ||
85 | DoC_Delay(docptr, 2); | ||
86 | |||
87 | return ret; | ||
88 | } | ||
89 | |||
90 | /* DoC_Command: Send a flash command to the flash chip through the CDSN IO register | ||
91 | with the internal pipeline. Each of 4 delay cycles (read from the NOP register) is | ||
92 | required after writing to CDSN Control register, see Software Requirement 11.4 item 3. */ | ||
93 | |||
94 | static void DoC_Command(void __iomem * docptr, unsigned char command, | ||
95 | unsigned char xtraflags) | ||
96 | { | ||
97 | /* Assert the CLE (Command Latch Enable) line to the flash chip */ | ||
98 | WriteDOC(xtraflags | CDSN_CTRL_CLE | CDSN_CTRL_CE, docptr, CDSNControl); | ||
99 | DoC_Delay(docptr, 4); | ||
100 | |||
101 | /* Send the command */ | ||
102 | WriteDOC(command, docptr, Mil_CDSN_IO); | ||
103 | WriteDOC(0x00, docptr, WritePipeTerm); | ||
104 | |||
105 | /* Lower the CLE line */ | ||
106 | WriteDOC(xtraflags | CDSN_CTRL_CE, docptr, CDSNControl); | ||
107 | DoC_Delay(docptr, 4); | ||
108 | } | ||
109 | |||
110 | /* DoC_Address: Set the current address for the flash chip through the CDSN IO register | ||
111 | with the internal pipeline. Each of 4 delay cycles (read from the NOP register) is | ||
112 | required after writing to CDSN Control register, see Software Requirement 11.4 item 3. */ | ||
113 | |||
114 | static inline void DoC_Address(void __iomem * docptr, int numbytes, unsigned long ofs, | ||
115 | unsigned char xtraflags1, unsigned char xtraflags2) | ||
116 | { | ||
117 | /* Assert the ALE (Address Latch Enable) line to the flash chip */ | ||
118 | WriteDOC(xtraflags1 | CDSN_CTRL_ALE | CDSN_CTRL_CE, docptr, CDSNControl); | ||
119 | DoC_Delay(docptr, 4); | ||
120 | |||
121 | /* Send the address */ | ||
122 | switch (numbytes) | ||
123 | { | ||
124 | case 1: | ||
125 | /* Send single byte, bits 0-7. */ | ||
126 | WriteDOC(ofs & 0xff, docptr, Mil_CDSN_IO); | ||
127 | WriteDOC(0x00, docptr, WritePipeTerm); | ||
128 | break; | ||
129 | case 2: | ||
130 | /* Send bits 9-16 followed by 17-23 */ | ||
131 | WriteDOC((ofs >> 9) & 0xff, docptr, Mil_CDSN_IO); | ||
132 | WriteDOC((ofs >> 17) & 0xff, docptr, Mil_CDSN_IO); | ||
133 | WriteDOC(0x00, docptr, WritePipeTerm); | ||
134 | break; | ||
135 | case 3: | ||
136 | /* Send 0-7, 9-16, then 17-23 */ | ||
137 | WriteDOC(ofs & 0xff, docptr, Mil_CDSN_IO); | ||
138 | WriteDOC((ofs >> 9) & 0xff, docptr, Mil_CDSN_IO); | ||
139 | WriteDOC((ofs >> 17) & 0xff, docptr, Mil_CDSN_IO); | ||
140 | WriteDOC(0x00, docptr, WritePipeTerm); | ||
141 | break; | ||
142 | default: | ||
143 | return; | ||
144 | } | ||
145 | |||
146 | /* Lower the ALE line */ | ||
147 | WriteDOC(xtraflags1 | xtraflags2 | CDSN_CTRL_CE, docptr, CDSNControl); | ||
148 | DoC_Delay(docptr, 4); | ||
149 | } | ||
150 | |||
151 | /* DoC_SelectChip: Select a given flash chip within the current floor */ | ||
152 | static int DoC_SelectChip(void __iomem * docptr, int chip) | ||
153 | { | ||
154 | /* Select the individual flash chip requested */ | ||
155 | WriteDOC(chip, docptr, CDSNDeviceSelect); | ||
156 | DoC_Delay(docptr, 4); | ||
157 | |||
158 | /* Wait for it to be ready */ | ||
159 | return DoC_WaitReady(docptr); | ||
160 | } | ||
161 | |||
162 | /* DoC_SelectFloor: Select a given floor (bank of flash chips) */ | ||
163 | static int DoC_SelectFloor(void __iomem * docptr, int floor) | ||
164 | { | ||
165 | /* Select the floor (bank) of chips required */ | ||
166 | WriteDOC(floor, docptr, FloorSelect); | ||
167 | |||
168 | /* Wait for the chip to be ready */ | ||
169 | return DoC_WaitReady(docptr); | ||
170 | } | ||
171 | |||
172 | /* DoC_IdentChip: Identify a given NAND chip given {floor,chip} */ | ||
173 | static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip) | ||
174 | { | ||
175 | int mfr, id, i, j; | ||
176 | volatile char dummy; | ||
177 | |||
178 | /* Page in the required floor/chip | ||
179 | FIXME: is this supported by Millennium ?? */ | ||
180 | DoC_SelectFloor(doc->virtadr, floor); | ||
181 | DoC_SelectChip(doc->virtadr, chip); | ||
182 | |||
183 | /* Reset the chip, see Software Requirement 11.4 item 1. */ | ||
184 | DoC_Command(doc->virtadr, NAND_CMD_RESET, CDSN_CTRL_WP); | ||
185 | DoC_WaitReady(doc->virtadr); | ||
186 | |||
187 | /* Read the NAND chip ID: 1. Send ReadID command */ | ||
188 | DoC_Command(doc->virtadr, NAND_CMD_READID, CDSN_CTRL_WP); | ||
189 | |||
190 | /* Read the NAND chip ID: 2. Send address byte zero */ | ||
191 | DoC_Address(doc->virtadr, 1, 0x00, CDSN_CTRL_WP, 0x00); | ||
192 | |||
193 | /* Read the manufacturer and device id codes of the flash device through | ||
194 | CDSN IO register see Software Requirement 11.4 item 5.*/ | ||
195 | dummy = ReadDOC(doc->virtadr, ReadPipeInit); | ||
196 | DoC_Delay(doc->virtadr, 2); | ||
197 | mfr = ReadDOC(doc->virtadr, Mil_CDSN_IO); | ||
198 | |||
199 | DoC_Delay(doc->virtadr, 2); | ||
200 | id = ReadDOC(doc->virtadr, Mil_CDSN_IO); | ||
201 | dummy = ReadDOC(doc->virtadr, LastDataRead); | ||
202 | |||
203 | /* No response - return failure */ | ||
204 | if (mfr == 0xff || mfr == 0) | ||
205 | return 0; | ||
206 | |||
207 | /* FIXME: to deal with multi-flash on multi-Millennium case more carefully */ | ||
208 | for (i = 0; nand_flash_ids[i].name != NULL; i++) { | ||
209 | if ( id == nand_flash_ids[i].dev_id) { | ||
210 | /* Try to identify manufacturer */ | ||
211 | for (j = 0; nand_manuf_ids[j].id != 0x0; j++) { | ||
212 | if (nand_manuf_ids[j].id == mfr) | ||
213 | break; | ||
214 | } | ||
215 | printk(KERN_INFO "Flash chip found: Manufacturer ID: %2.2X, " | ||
216 | "Chip ID: %2.2X (%s:%s)\n", | ||
217 | mfr, id, nand_manuf_ids[j].name, nand_flash_ids[i].name); | ||
218 | doc->mfr = mfr; | ||
219 | doc->id = id; | ||
220 | doc->chipshift = ffs((nand_flash_ids[i].chipsize << 20)) - 1; | ||
221 | break; | ||
222 | } | ||
223 | } | ||
224 | |||
225 | if (nand_flash_ids[i].name == NULL) | ||
226 | return 0; | ||
227 | else | ||
228 | return 1; | ||
229 | } | ||
230 | |||
231 | /* DoC_ScanChips: Find all NAND chips present in a DiskOnChip, and identify them */ | ||
232 | static void DoC_ScanChips(struct DiskOnChip *this) | ||
233 | { | ||
234 | int floor, chip; | ||
235 | int numchips[MAX_FLOORS_MIL]; | ||
236 | int ret; | ||
237 | |||
238 | this->numchips = 0; | ||
239 | this->mfr = 0; | ||
240 | this->id = 0; | ||
241 | |||
242 | /* For each floor, find the number of valid chips it contains */ | ||
243 | for (floor = 0,ret = 1; floor < MAX_FLOORS_MIL; floor++) { | ||
244 | numchips[floor] = 0; | ||
245 | for (chip = 0; chip < MAX_CHIPS_MIL && ret != 0; chip++) { | ||
246 | ret = DoC_IdentChip(this, floor, chip); | ||
247 | if (ret) { | ||
248 | numchips[floor]++; | ||
249 | this->numchips++; | ||
250 | } | ||
251 | } | ||
252 | } | ||
253 | /* If there are none at all that we recognise, bail */ | ||
254 | if (!this->numchips) { | ||
255 | printk("No flash chips recognised.\n"); | ||
256 | return; | ||
257 | } | ||
258 | |||
259 | /* Allocate an array to hold the information for each chip */ | ||
260 | this->chips = kmalloc(sizeof(struct Nand) * this->numchips, GFP_KERNEL); | ||
261 | if (!this->chips){ | ||
262 | printk("No memory for allocating chip info structures\n"); | ||
263 | return; | ||
264 | } | ||
265 | |||
266 | /* Fill out the chip array with {floor, chipno} for each | ||
267 | * detected chip in the device. */ | ||
268 | for (floor = 0, ret = 0; floor < MAX_FLOORS_MIL; floor++) { | ||
269 | for (chip = 0 ; chip < numchips[floor] ; chip++) { | ||
270 | this->chips[ret].floor = floor; | ||
271 | this->chips[ret].chip = chip; | ||
272 | this->chips[ret].curadr = 0; | ||
273 | this->chips[ret].curmode = 0x50; | ||
274 | ret++; | ||
275 | } | ||
276 | } | ||
277 | |||
278 | /* Calculate and print the total size of the device */ | ||
279 | this->totlen = this->numchips * (1 << this->chipshift); | ||
280 | printk(KERN_INFO "%d flash chips found. Total DiskOnChip size: %ld MiB\n", | ||
281 | this->numchips ,this->totlen >> 20); | ||
282 | } | ||
283 | |||
284 | static int DoCMil_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2) | ||
285 | { | ||
286 | int tmp1, tmp2, retval; | ||
287 | |||
288 | if (doc1->physadr == doc2->physadr) | ||
289 | return 1; | ||
290 | |||
291 | /* Use the alias resolution register which was set aside for this | ||
292 | * purpose. If it's value is the same on both chips, they might | ||
293 | * be the same chip, and we write to one and check for a change in | ||
294 | * the other. It's unclear if this register is usuable in the | ||
295 | * DoC 2000 (it's in the Millenium docs), but it seems to work. */ | ||
296 | tmp1 = ReadDOC(doc1->virtadr, AliasResolution); | ||
297 | tmp2 = ReadDOC(doc2->virtadr, AliasResolution); | ||
298 | if (tmp1 != tmp2) | ||
299 | return 0; | ||
300 | |||
301 | WriteDOC((tmp1+1) % 0xff, doc1->virtadr, AliasResolution); | ||
302 | tmp2 = ReadDOC(doc2->virtadr, AliasResolution); | ||
303 | if (tmp2 == (tmp1+1) % 0xff) | ||
304 | retval = 1; | ||
305 | else | ||
306 | retval = 0; | ||
307 | |||
308 | /* Restore register contents. May not be necessary, but do it just to | ||
309 | * be safe. */ | ||
310 | WriteDOC(tmp1, doc1->virtadr, AliasResolution); | ||
311 | |||
312 | return retval; | ||
313 | } | ||
314 | |||
315 | /* This routine is found from the docprobe code by symbol_get(), | ||
316 | * which will bump the use count of this module. */ | ||
317 | void DoCMil_init(struct mtd_info *mtd) | ||
318 | { | ||
319 | struct DiskOnChip *this = mtd->priv; | ||
320 | struct DiskOnChip *old = NULL; | ||
321 | |||
322 | /* We must avoid being called twice for the same device. */ | ||
323 | if (docmillist) | ||
324 | old = docmillist->priv; | ||
325 | |||
326 | while (old) { | ||
327 | if (DoCMil_is_alias(this, old)) { | ||
328 | printk(KERN_NOTICE "Ignoring DiskOnChip Millennium at " | ||
329 | "0x%lX - already configured\n", this->physadr); | ||
330 | iounmap(this->virtadr); | ||
331 | kfree(mtd); | ||
332 | return; | ||
333 | } | ||
334 | if (old->nextdoc) | ||
335 | old = old->nextdoc->priv; | ||
336 | else | ||
337 | old = NULL; | ||
338 | } | ||
339 | |||
340 | mtd->name = "DiskOnChip Millennium"; | ||
341 | printk(KERN_NOTICE "DiskOnChip Millennium found at address 0x%lX\n", | ||
342 | this->physadr); | ||
343 | |||
344 | mtd->type = MTD_NANDFLASH; | ||
345 | mtd->flags = MTD_CAP_NANDFLASH; | ||
346 | |||
347 | /* FIXME: erase size is not always 8KiB */ | ||
348 | mtd->erasesize = 0x2000; | ||
349 | mtd->writebufsize = mtd->writesize = 512; | ||
350 | mtd->oobsize = 16; | ||
351 | mtd->ecc_strength = 2; | ||
352 | mtd->owner = THIS_MODULE; | ||
353 | mtd->_erase = doc_erase; | ||
354 | mtd->_read = doc_read; | ||
355 | mtd->_write = doc_write; | ||
356 | mtd->_read_oob = doc_read_oob; | ||
357 | mtd->_write_oob = doc_write_oob; | ||
358 | this->curfloor = -1; | ||
359 | this->curchip = -1; | ||
360 | |||
361 | /* Ident all the chips present. */ | ||
362 | DoC_ScanChips(this); | ||
363 | |||
364 | if (!this->totlen) { | ||
365 | kfree(mtd); | ||
366 | iounmap(this->virtadr); | ||
367 | } else { | ||
368 | this->nextdoc = docmillist; | ||
369 | docmillist = mtd; | ||
370 | mtd->size = this->totlen; | ||
371 | mtd_device_register(mtd, NULL, 0); | ||
372 | return; | ||
373 | } | ||
374 | } | ||
375 | EXPORT_SYMBOL_GPL(DoCMil_init); | ||
376 | |||
377 | static int doc_read (struct mtd_info *mtd, loff_t from, size_t len, | ||
378 | size_t *retlen, u_char *buf) | ||
379 | { | ||
380 | int i, ret; | ||
381 | volatile char dummy; | ||
382 | unsigned char syndrome[6], eccbuf[6]; | ||
383 | struct DiskOnChip *this = mtd->priv; | ||
384 | void __iomem *docptr = this->virtadr; | ||
385 | struct Nand *mychip = &this->chips[from >> (this->chipshift)]; | ||
386 | |||
387 | /* Don't allow a single read to cross a 512-byte block boundary */ | ||
388 | if (from + len > ((from | 0x1ff) + 1)) | ||
389 | len = ((from | 0x1ff) + 1) - from; | ||
390 | |||
391 | /* Find the chip which is to be used and select it */ | ||
392 | if (this->curfloor != mychip->floor) { | ||
393 | DoC_SelectFloor(docptr, mychip->floor); | ||
394 | DoC_SelectChip(docptr, mychip->chip); | ||
395 | } else if (this->curchip != mychip->chip) { | ||
396 | DoC_SelectChip(docptr, mychip->chip); | ||
397 | } | ||
398 | this->curfloor = mychip->floor; | ||
399 | this->curchip = mychip->chip; | ||
400 | |||
401 | /* issue the Read0 or Read1 command depend on which half of the page | ||
402 | we are accessing. Polling the Flash Ready bit after issue 3 bytes | ||
403 | address in Sequence Read Mode, see Software Requirement 11.4 item 1.*/ | ||
404 | DoC_Command(docptr, (from >> 8) & 1, CDSN_CTRL_WP); | ||
405 | DoC_Address(docptr, 3, from, CDSN_CTRL_WP, 0x00); | ||
406 | DoC_WaitReady(docptr); | ||
407 | |||
408 | /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/ | ||
409 | WriteDOC (DOC_ECC_RESET, docptr, ECCConf); | ||
410 | WriteDOC (DOC_ECC_EN, docptr, ECCConf); | ||
411 | |||
412 | /* Read the data via the internal pipeline through CDSN IO register, | ||
413 | see Pipelined Read Operations 11.3 */ | ||
414 | dummy = ReadDOC(docptr, ReadPipeInit); | ||
415 | #ifndef USE_MEMCPY | ||
416 | for (i = 0; i < len-1; i++) { | ||
417 | /* N.B. you have to increase the source address in this way or the | ||
418 | ECC logic will not work properly */ | ||
419 | buf[i] = ReadDOC(docptr, Mil_CDSN_IO + (i & 0xff)); | ||
420 | } | ||
421 | #else | ||
422 | memcpy_fromio(buf, docptr + DoC_Mil_CDSN_IO, len - 1); | ||
423 | #endif | ||
424 | buf[len - 1] = ReadDOC(docptr, LastDataRead); | ||
425 | |||
426 | /* Let the caller know we completed it */ | ||
427 | *retlen = len; | ||
428 | ret = 0; | ||
429 | |||
430 | /* Read the ECC data from Spare Data Area, | ||
431 | see Reed-Solomon EDC/ECC 11.1 */ | ||
432 | dummy = ReadDOC(docptr, ReadPipeInit); | ||
433 | #ifndef USE_MEMCPY | ||
434 | for (i = 0; i < 5; i++) { | ||
435 | /* N.B. you have to increase the source address in this way or the | ||
436 | ECC logic will not work properly */ | ||
437 | eccbuf[i] = ReadDOC(docptr, Mil_CDSN_IO + i); | ||
438 | } | ||
439 | #else | ||
440 | memcpy_fromio(eccbuf, docptr + DoC_Mil_CDSN_IO, 5); | ||
441 | #endif | ||
442 | eccbuf[5] = ReadDOC(docptr, LastDataRead); | ||
443 | |||
444 | /* Flush the pipeline */ | ||
445 | dummy = ReadDOC(docptr, ECCConf); | ||
446 | dummy = ReadDOC(docptr, ECCConf); | ||
447 | |||
448 | /* Check the ECC Status */ | ||
449 | if (ReadDOC(docptr, ECCConf) & 0x80) { | ||
450 | int nb_errors; | ||
451 | /* There was an ECC error */ | ||
452 | #ifdef ECC_DEBUG | ||
453 | printk("DiskOnChip ECC Error: Read at %lx\n", (long)from); | ||
454 | #endif | ||
455 | /* Read the ECC syndrome through the DiskOnChip ECC logic. | ||
456 | These syndrome will be all ZERO when there is no error */ | ||
457 | for (i = 0; i < 6; i++) { | ||
458 | syndrome[i] = ReadDOC(docptr, ECCSyndrome0 + i); | ||
459 | } | ||
460 | nb_errors = doc_decode_ecc(buf, syndrome); | ||
461 | #ifdef ECC_DEBUG | ||
462 | printk("ECC Errors corrected: %x\n", nb_errors); | ||
463 | #endif | ||
464 | if (nb_errors < 0) { | ||
465 | /* We return error, but have actually done the read. Not that | ||
466 | this can be told to user-space, via sys_read(), but at least | ||
467 | MTD-aware stuff can know about it by checking *retlen */ | ||
468 | ret = -EIO; | ||
469 | } | ||
470 | } | ||
471 | |||
472 | #ifdef PSYCHO_DEBUG | ||
473 | printk("ECC DATA at %lx: %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", | ||
474 | (long)from, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3], | ||
475 | eccbuf[4], eccbuf[5]); | ||
476 | #endif | ||
477 | |||
478 | /* disable the ECC engine */ | ||
479 | WriteDOC(DOC_ECC_DIS, docptr , ECCConf); | ||
480 | |||
481 | return ret; | ||
482 | } | ||
483 | |||
484 | static int doc_write (struct mtd_info *mtd, loff_t to, size_t len, | ||
485 | size_t *retlen, const u_char *buf) | ||
486 | { | ||
487 | int i,ret = 0; | ||
488 | char eccbuf[6]; | ||
489 | volatile char dummy; | ||
490 | struct DiskOnChip *this = mtd->priv; | ||
491 | void __iomem *docptr = this->virtadr; | ||
492 | struct Nand *mychip = &this->chips[to >> (this->chipshift)]; | ||
493 | |||
494 | #if 0 | ||
495 | /* Don't allow a single write to cross a 512-byte block boundary */ | ||
496 | if (to + len > ( (to | 0x1ff) + 1)) | ||
497 | len = ((to | 0x1ff) + 1) - to; | ||
498 | #else | ||
499 | /* Don't allow writes which aren't exactly one block */ | ||
500 | if (to & 0x1ff || len != 0x200) | ||
501 | return -EINVAL; | ||
502 | #endif | ||
503 | |||
504 | /* Find the chip which is to be used and select it */ | ||
505 | if (this->curfloor != mychip->floor) { | ||
506 | DoC_SelectFloor(docptr, mychip->floor); | ||
507 | DoC_SelectChip(docptr, mychip->chip); | ||
508 | } else if (this->curchip != mychip->chip) { | ||
509 | DoC_SelectChip(docptr, mychip->chip); | ||
510 | } | ||
511 | this->curfloor = mychip->floor; | ||
512 | this->curchip = mychip->chip; | ||
513 | |||
514 | /* Reset the chip, see Software Requirement 11.4 item 1. */ | ||
515 | DoC_Command(docptr, NAND_CMD_RESET, 0x00); | ||
516 | DoC_WaitReady(docptr); | ||
517 | /* Set device to main plane of flash */ | ||
518 | DoC_Command(docptr, NAND_CMD_READ0, 0x00); | ||
519 | |||
520 | /* issue the Serial Data In command to initial the Page Program process */ | ||
521 | DoC_Command(docptr, NAND_CMD_SEQIN, 0x00); | ||
522 | DoC_Address(docptr, 3, to, 0x00, 0x00); | ||
523 | DoC_WaitReady(docptr); | ||
524 | |||
525 | /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/ | ||
526 | WriteDOC (DOC_ECC_RESET, docptr, ECCConf); | ||
527 | WriteDOC (DOC_ECC_EN | DOC_ECC_RW, docptr, ECCConf); | ||
528 | |||
529 | /* Write the data via the internal pipeline through CDSN IO register, | ||
530 | see Pipelined Write Operations 11.2 */ | ||
531 | #ifndef USE_MEMCPY | ||
532 | for (i = 0; i < len; i++) { | ||
533 | /* N.B. you have to increase the source address in this way or the | ||
534 | ECC logic will not work properly */ | ||
535 | WriteDOC(buf[i], docptr, Mil_CDSN_IO + i); | ||
536 | } | ||
537 | #else | ||
538 | memcpy_toio(docptr + DoC_Mil_CDSN_IO, buf, len); | ||
539 | #endif | ||
540 | WriteDOC(0x00, docptr, WritePipeTerm); | ||
541 | |||
542 | /* Write ECC data to flash, the ECC info is generated by the DiskOnChip ECC logic | ||
543 | see Reed-Solomon EDC/ECC 11.1 */ | ||
544 | WriteDOC(0, docptr, NOP); | ||
545 | WriteDOC(0, docptr, NOP); | ||
546 | WriteDOC(0, docptr, NOP); | ||
547 | |||
548 | /* Read the ECC data through the DiskOnChip ECC logic */ | ||
549 | for (i = 0; i < 6; i++) { | ||
550 | eccbuf[i] = ReadDOC(docptr, ECCSyndrome0 + i); | ||
551 | } | ||
552 | |||
553 | /* ignore the ECC engine */ | ||
554 | WriteDOC(DOC_ECC_DIS, docptr , ECCConf); | ||
555 | |||
556 | #ifndef USE_MEMCPY | ||
557 | /* Write the ECC data to flash */ | ||
558 | for (i = 0; i < 6; i++) { | ||
559 | /* N.B. you have to increase the source address in this way or the | ||
560 | ECC logic will not work properly */ | ||
561 | WriteDOC(eccbuf[i], docptr, Mil_CDSN_IO + i); | ||
562 | } | ||
563 | #else | ||
564 | memcpy_toio(docptr + DoC_Mil_CDSN_IO, eccbuf, 6); | ||
565 | #endif | ||
566 | |||
567 | /* write the block status BLOCK_USED (0x5555) at the end of ECC data | ||
568 | FIXME: this is only a hack for programming the IPL area for LinuxBIOS | ||
569 | and should be replace with proper codes in user space utilities */ | ||
570 | WriteDOC(0x55, docptr, Mil_CDSN_IO); | ||
571 | WriteDOC(0x55, docptr, Mil_CDSN_IO + 1); | ||
572 | |||
573 | WriteDOC(0x00, docptr, WritePipeTerm); | ||
574 | |||
575 | #ifdef PSYCHO_DEBUG | ||
576 | printk("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", | ||
577 | (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3], | ||
578 | eccbuf[4], eccbuf[5]); | ||
579 | #endif | ||
580 | |||
581 | /* Commit the Page Program command and wait for ready | ||
582 | see Software Requirement 11.4 item 1.*/ | ||
583 | DoC_Command(docptr, NAND_CMD_PAGEPROG, 0x00); | ||
584 | DoC_WaitReady(docptr); | ||
585 | |||
586 | /* Read the status of the flash device through CDSN IO register | ||
587 | see Software Requirement 11.4 item 5.*/ | ||
588 | DoC_Command(docptr, NAND_CMD_STATUS, CDSN_CTRL_WP); | ||
589 | dummy = ReadDOC(docptr, ReadPipeInit); | ||
590 | DoC_Delay(docptr, 2); | ||
591 | if (ReadDOC(docptr, Mil_CDSN_IO) & 1) { | ||
592 | printk("Error programming flash\n"); | ||
593 | /* Error in programming | ||
594 | FIXME: implement Bad Block Replacement (in nftl.c ??) */ | ||
595 | ret = -EIO; | ||
596 | } | ||
597 | dummy = ReadDOC(docptr, LastDataRead); | ||
598 | |||
599 | /* Let the caller know we completed it */ | ||
600 | *retlen = len; | ||
601 | |||
602 | return ret; | ||
603 | } | ||
604 | |||
605 | static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, | ||
606 | struct mtd_oob_ops *ops) | ||
607 | { | ||
608 | #ifndef USE_MEMCPY | ||
609 | int i; | ||
610 | #endif | ||
611 | volatile char dummy; | ||
612 | struct DiskOnChip *this = mtd->priv; | ||
613 | void __iomem *docptr = this->virtadr; | ||
614 | struct Nand *mychip = &this->chips[ofs >> this->chipshift]; | ||
615 | uint8_t *buf = ops->oobbuf; | ||
616 | size_t len = ops->len; | ||
617 | |||
618 | BUG_ON(ops->mode != MTD_OPS_PLACE_OOB); | ||
619 | |||
620 | ofs += ops->ooboffs; | ||
621 | |||
622 | /* Find the chip which is to be used and select it */ | ||
623 | if (this->curfloor != mychip->floor) { | ||
624 | DoC_SelectFloor(docptr, mychip->floor); | ||
625 | DoC_SelectChip(docptr, mychip->chip); | ||
626 | } else if (this->curchip != mychip->chip) { | ||
627 | DoC_SelectChip(docptr, mychip->chip); | ||
628 | } | ||
629 | this->curfloor = mychip->floor; | ||
630 | this->curchip = mychip->chip; | ||
631 | |||
632 | /* disable the ECC engine */ | ||
633 | WriteDOC (DOC_ECC_RESET, docptr, ECCConf); | ||
634 | WriteDOC (DOC_ECC_DIS, docptr, ECCConf); | ||
635 | |||
636 | /* issue the Read2 command to set the pointer to the Spare Data Area. | ||
637 | Polling the Flash Ready bit after issue 3 bytes address in | ||
638 | Sequence Read Mode, see Software Requirement 11.4 item 1.*/ | ||
639 | DoC_Command(docptr, NAND_CMD_READOOB, CDSN_CTRL_WP); | ||
640 | DoC_Address(docptr, 3, ofs, CDSN_CTRL_WP, 0x00); | ||
641 | DoC_WaitReady(docptr); | ||
642 | |||
643 | /* Read the data out via the internal pipeline through CDSN IO register, | ||
644 | see Pipelined Read Operations 11.3 */ | ||
645 | dummy = ReadDOC(docptr, ReadPipeInit); | ||
646 | #ifndef USE_MEMCPY | ||
647 | for (i = 0; i < len-1; i++) { | ||
648 | /* N.B. you have to increase the source address in this way or the | ||
649 | ECC logic will not work properly */ | ||
650 | buf[i] = ReadDOC(docptr, Mil_CDSN_IO + i); | ||
651 | } | ||
652 | #else | ||
653 | memcpy_fromio(buf, docptr + DoC_Mil_CDSN_IO, len - 1); | ||
654 | #endif | ||
655 | buf[len - 1] = ReadDOC(docptr, LastDataRead); | ||
656 | |||
657 | ops->retlen = len; | ||
658 | |||
659 | return 0; | ||
660 | } | ||
661 | |||
662 | static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, | ||
663 | struct mtd_oob_ops *ops) | ||
664 | { | ||
665 | #ifndef USE_MEMCPY | ||
666 | int i; | ||
667 | #endif | ||
668 | volatile char dummy; | ||
669 | int ret = 0; | ||
670 | struct DiskOnChip *this = mtd->priv; | ||
671 | void __iomem *docptr = this->virtadr; | ||
672 | struct Nand *mychip = &this->chips[ofs >> this->chipshift]; | ||
673 | uint8_t *buf = ops->oobbuf; | ||
674 | size_t len = ops->len; | ||
675 | |||
676 | BUG_ON(ops->mode != MTD_OPS_PLACE_OOB); | ||
677 | |||
678 | ofs += ops->ooboffs; | ||
679 | |||
680 | /* Find the chip which is to be used and select it */ | ||
681 | if (this->curfloor != mychip->floor) { | ||
682 | DoC_SelectFloor(docptr, mychip->floor); | ||
683 | DoC_SelectChip(docptr, mychip->chip); | ||
684 | } else if (this->curchip != mychip->chip) { | ||
685 | DoC_SelectChip(docptr, mychip->chip); | ||
686 | } | ||
687 | this->curfloor = mychip->floor; | ||
688 | this->curchip = mychip->chip; | ||
689 | |||
690 | /* disable the ECC engine */ | ||
691 | WriteDOC (DOC_ECC_RESET, docptr, ECCConf); | ||
692 | WriteDOC (DOC_ECC_DIS, docptr, ECCConf); | ||
693 | |||
694 | /* Reset the chip, see Software Requirement 11.4 item 1. */ | ||
695 | DoC_Command(docptr, NAND_CMD_RESET, CDSN_CTRL_WP); | ||
696 | DoC_WaitReady(docptr); | ||
697 | /* issue the Read2 command to set the pointer to the Spare Data Area. */ | ||
698 | DoC_Command(docptr, NAND_CMD_READOOB, CDSN_CTRL_WP); | ||
699 | |||
700 | /* issue the Serial Data In command to initial the Page Program process */ | ||
701 | DoC_Command(docptr, NAND_CMD_SEQIN, 0x00); | ||
702 | DoC_Address(docptr, 3, ofs, 0x00, 0x00); | ||
703 | |||
704 | /* Write the data via the internal pipeline through CDSN IO register, | ||
705 | see Pipelined Write Operations 11.2 */ | ||
706 | #ifndef USE_MEMCPY | ||
707 | for (i = 0; i < len; i++) { | ||
708 | /* N.B. you have to increase the source address in this way or the | ||
709 | ECC logic will not work properly */ | ||
710 | WriteDOC(buf[i], docptr, Mil_CDSN_IO + i); | ||
711 | } | ||
712 | #else | ||
713 | memcpy_toio(docptr + DoC_Mil_CDSN_IO, buf, len); | ||
714 | #endif | ||
715 | WriteDOC(0x00, docptr, WritePipeTerm); | ||
716 | |||
717 | /* Commit the Page Program command and wait for ready | ||
718 | see Software Requirement 11.4 item 1.*/ | ||
719 | DoC_Command(docptr, NAND_CMD_PAGEPROG, 0x00); | ||
720 | DoC_WaitReady(docptr); | ||
721 | |||
722 | /* Read the status of the flash device through CDSN IO register | ||
723 | see Software Requirement 11.4 item 5.*/ | ||
724 | DoC_Command(docptr, NAND_CMD_STATUS, 0x00); | ||
725 | dummy = ReadDOC(docptr, ReadPipeInit); | ||
726 | DoC_Delay(docptr, 2); | ||
727 | if (ReadDOC(docptr, Mil_CDSN_IO) & 1) { | ||
728 | printk("Error programming oob data\n"); | ||
729 | /* FIXME: implement Bad Block Replacement (in nftl.c ??) */ | ||
730 | ops->retlen = 0; | ||
731 | ret = -EIO; | ||
732 | } | ||
733 | dummy = ReadDOC(docptr, LastDataRead); | ||
734 | |||
735 | ops->retlen = len; | ||
736 | |||
737 | return ret; | ||
738 | } | ||
739 | |||
740 | int doc_erase (struct mtd_info *mtd, struct erase_info *instr) | ||
741 | { | ||
742 | volatile char dummy; | ||
743 | struct DiskOnChip *this = mtd->priv; | ||
744 | __u32 ofs = instr->addr; | ||
745 | __u32 len = instr->len; | ||
746 | void __iomem *docptr = this->virtadr; | ||
747 | struct Nand *mychip = &this->chips[ofs >> this->chipshift]; | ||
748 | |||
749 | if (len != mtd->erasesize) | ||
750 | printk(KERN_WARNING "Erase not right size (%x != %x)n", | ||
751 | len, mtd->erasesize); | ||
752 | |||
753 | /* Find the chip which is to be used and select it */ | ||
754 | if (this->curfloor != mychip->floor) { | ||
755 | DoC_SelectFloor(docptr, mychip->floor); | ||
756 | DoC_SelectChip(docptr, mychip->chip); | ||
757 | } else if (this->curchip != mychip->chip) { | ||
758 | DoC_SelectChip(docptr, mychip->chip); | ||
759 | } | ||
760 | this->curfloor = mychip->floor; | ||
761 | this->curchip = mychip->chip; | ||
762 | |||
763 | instr->state = MTD_ERASE_PENDING; | ||
764 | |||
765 | /* issue the Erase Setup command */ | ||
766 | DoC_Command(docptr, NAND_CMD_ERASE1, 0x00); | ||
767 | DoC_Address(docptr, 2, ofs, 0x00, 0x00); | ||
768 | |||
769 | /* Commit the Erase Start command and wait for ready | ||
770 | see Software Requirement 11.4 item 1.*/ | ||
771 | DoC_Command(docptr, NAND_CMD_ERASE2, 0x00); | ||
772 | DoC_WaitReady(docptr); | ||
773 | |||
774 | instr->state = MTD_ERASING; | ||
775 | |||
776 | /* Read the status of the flash device through CDSN IO register | ||
777 | see Software Requirement 11.4 item 5. | ||
778 | FIXME: it seems that we are not wait long enough, some blocks are not | ||
779 | erased fully */ | ||
780 | DoC_Command(docptr, NAND_CMD_STATUS, CDSN_CTRL_WP); | ||
781 | dummy = ReadDOC(docptr, ReadPipeInit); | ||
782 | DoC_Delay(docptr, 2); | ||
783 | if (ReadDOC(docptr, Mil_CDSN_IO) & 1) { | ||
784 | printk("Error Erasing at 0x%x\n", ofs); | ||
785 | /* There was an error | ||
786 | FIXME: implement Bad Block Replacement (in nftl.c ??) */ | ||
787 | instr->state = MTD_ERASE_FAILED; | ||
788 | } else | ||
789 | instr->state = MTD_ERASE_DONE; | ||
790 | dummy = ReadDOC(docptr, LastDataRead); | ||
791 | |||
792 | mtd_erase_callback(instr); | ||
793 | |||
794 | return 0; | ||
795 | } | ||
796 | |||
797 | /**************************************************************************** | ||
798 | * | ||
799 | * Module stuff | ||
800 | * | ||
801 | ****************************************************************************/ | ||
802 | |||
803 | static void __exit cleanup_doc2001(void) | ||
804 | { | ||
805 | struct mtd_info *mtd; | ||
806 | struct DiskOnChip *this; | ||
807 | |||
808 | while ((mtd=docmillist)) { | ||
809 | this = mtd->priv; | ||
810 | docmillist = this->nextdoc; | ||
811 | |||
812 | mtd_device_unregister(mtd); | ||
813 | |||
814 | iounmap(this->virtadr); | ||
815 | kfree(this->chips); | ||
816 | kfree(mtd); | ||
817 | } | ||
818 | } | ||
819 | |||
820 | module_exit(cleanup_doc2001); | ||
821 | |||
822 | MODULE_LICENSE("GPL"); | ||
823 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org> et al."); | ||
824 | MODULE_DESCRIPTION("Alternative driver for DiskOnChip Millennium"); | ||
diff --git a/drivers/mtd/devices/doc2001plus.c b/drivers/mtd/devices/doc2001plus.c deleted file mode 100644 index 1b0c12f3ec02..000000000000 --- a/drivers/mtd/devices/doc2001plus.c +++ /dev/null | |||
@@ -1,1080 +0,0 @@ | |||
1 | /* | ||
2 | * Linux driver for Disk-On-Chip Millennium Plus | ||
3 | * | ||
4 | * (c) 2002-2003 Greg Ungerer <gerg@snapgear.com> | ||
5 | * (c) 2002-2003 SnapGear Inc | ||
6 | * (c) 1999 Machine Vision Holdings, Inc. | ||
7 | * (c) 1999, 2000 David Woodhouse <dwmw2@infradead.org> | ||
8 | * | ||
9 | * Released under GPL | ||
10 | */ | ||
11 | |||
12 | #include <linux/kernel.h> | ||
13 | #include <linux/module.h> | ||
14 | #include <asm/errno.h> | ||
15 | #include <asm/io.h> | ||
16 | #include <asm/uaccess.h> | ||
17 | #include <linux/delay.h> | ||
18 | #include <linux/slab.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/types.h> | ||
21 | #include <linux/bitops.h> | ||
22 | |||
23 | #include <linux/mtd/mtd.h> | ||
24 | #include <linux/mtd/nand.h> | ||
25 | #include <linux/mtd/doc2000.h> | ||
26 | |||
27 | /* #define ECC_DEBUG */ | ||
28 | |||
29 | /* I have no idea why some DoC chips can not use memcop_form|to_io(). | ||
30 | * This may be due to the different revisions of the ASIC controller built-in or | ||
31 | * simplily a QA/Bug issue. Who knows ?? If you have trouble, please uncomment | ||
32 | * this:*/ | ||
33 | #undef USE_MEMCPY | ||
34 | |||
35 | static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, | ||
36 | size_t *retlen, u_char *buf); | ||
37 | static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, | ||
38 | size_t *retlen, const u_char *buf); | ||
39 | static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, | ||
40 | struct mtd_oob_ops *ops); | ||
41 | static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, | ||
42 | struct mtd_oob_ops *ops); | ||
43 | static int doc_erase (struct mtd_info *mtd, struct erase_info *instr); | ||
44 | |||
45 | static struct mtd_info *docmilpluslist = NULL; | ||
46 | |||
47 | |||
48 | /* Perform the required delay cycles by writing to the NOP register */ | ||
49 | static void DoC_Delay(void __iomem * docptr, int cycles) | ||
50 | { | ||
51 | int i; | ||
52 | |||
53 | for (i = 0; (i < cycles); i++) | ||
54 | WriteDOC(0, docptr, Mplus_NOP); | ||
55 | } | ||
56 | |||
57 | #define CDSN_CTRL_FR_B_MASK (CDSN_CTRL_FR_B0 | CDSN_CTRL_FR_B1) | ||
58 | |||
59 | /* DOC_WaitReady: Wait for RDY line to be asserted by the flash chip */ | ||
60 | static int _DoC_WaitReady(void __iomem * docptr) | ||
61 | { | ||
62 | unsigned int c = 0xffff; | ||
63 | |||
64 | pr_debug("_DoC_WaitReady called for out-of-line wait\n"); | ||
65 | |||
66 | /* Out-of-line routine to wait for chip response */ | ||
67 | while (((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) && --c) | ||
68 | ; | ||
69 | |||
70 | if (c == 0) | ||
71 | pr_debug("_DoC_WaitReady timed out.\n"); | ||
72 | |||
73 | return (c == 0); | ||
74 | } | ||
75 | |||
76 | static inline int DoC_WaitReady(void __iomem * docptr) | ||
77 | { | ||
78 | /* This is inline, to optimise the common case, where it's ready instantly */ | ||
79 | int ret = 0; | ||
80 | |||
81 | /* read form NOP register should be issued prior to the read from CDSNControl | ||
82 | see Software Requirement 11.4 item 2. */ | ||
83 | DoC_Delay(docptr, 4); | ||
84 | |||
85 | if ((ReadDOC(docptr, Mplus_FlashControl) & CDSN_CTRL_FR_B_MASK) != CDSN_CTRL_FR_B_MASK) | ||
86 | /* Call the out-of-line routine to wait */ | ||
87 | ret = _DoC_WaitReady(docptr); | ||
88 | |||
89 | return ret; | ||
90 | } | ||
91 | |||
92 | /* For some reason the Millennium Plus seems to occasionally put itself | ||
93 | * into reset mode. For me this happens randomly, with no pattern that I | ||
94 | * can detect. M-systems suggest always check this on any block level | ||
95 | * operation and setting to normal mode if in reset mode. | ||
96 | */ | ||
97 | static inline void DoC_CheckASIC(void __iomem * docptr) | ||
98 | { | ||
99 | /* Make sure the DoC is in normal mode */ | ||
100 | if ((ReadDOC(docptr, Mplus_DOCControl) & DOC_MODE_NORMAL) == 0) { | ||
101 | WriteDOC((DOC_MODE_NORMAL | DOC_MODE_MDWREN), docptr, Mplus_DOCControl); | ||
102 | WriteDOC(~(DOC_MODE_NORMAL | DOC_MODE_MDWREN), docptr, Mplus_CtrlConfirm); | ||
103 | } | ||
104 | } | ||
105 | |||
106 | /* DoC_Command: Send a flash command to the flash chip through the Flash | ||
107 | * command register. Need 2 Write Pipeline Terminates to complete send. | ||
108 | */ | ||
109 | static void DoC_Command(void __iomem * docptr, unsigned char command, | ||
110 | unsigned char xtraflags) | ||
111 | { | ||
112 | WriteDOC(command, docptr, Mplus_FlashCmd); | ||
113 | WriteDOC(command, docptr, Mplus_WritePipeTerm); | ||
114 | WriteDOC(command, docptr, Mplus_WritePipeTerm); | ||
115 | } | ||
116 | |||
117 | /* DoC_Address: Set the current address for the flash chip through the Flash | ||
118 | * Address register. Need 2 Write Pipeline Terminates to complete send. | ||
119 | */ | ||
120 | static inline void DoC_Address(struct DiskOnChip *doc, int numbytes, | ||
121 | unsigned long ofs, unsigned char xtraflags1, | ||
122 | unsigned char xtraflags2) | ||
123 | { | ||
124 | void __iomem * docptr = doc->virtadr; | ||
125 | |||
126 | /* Allow for possible Mill Plus internal flash interleaving */ | ||
127 | ofs >>= doc->interleave; | ||
128 | |||
129 | switch (numbytes) { | ||
130 | case 1: | ||
131 | /* Send single byte, bits 0-7. */ | ||
132 | WriteDOC(ofs & 0xff, docptr, Mplus_FlashAddress); | ||
133 | break; | ||
134 | case 2: | ||
135 | /* Send bits 9-16 followed by 17-23 */ | ||
136 | WriteDOC((ofs >> 9) & 0xff, docptr, Mplus_FlashAddress); | ||
137 | WriteDOC((ofs >> 17) & 0xff, docptr, Mplus_FlashAddress); | ||
138 | break; | ||
139 | case 3: | ||
140 | /* Send 0-7, 9-16, then 17-23 */ | ||
141 | WriteDOC(ofs & 0xff, docptr, Mplus_FlashAddress); | ||
142 | WriteDOC((ofs >> 9) & 0xff, docptr, Mplus_FlashAddress); | ||
143 | WriteDOC((ofs >> 17) & 0xff, docptr, Mplus_FlashAddress); | ||
144 | break; | ||
145 | default: | ||
146 | return; | ||
147 | } | ||
148 | |||
149 | WriteDOC(0x00, docptr, Mplus_WritePipeTerm); | ||
150 | WriteDOC(0x00, docptr, Mplus_WritePipeTerm); | ||
151 | } | ||
152 | |||
153 | /* DoC_SelectChip: Select a given flash chip within the current floor */ | ||
154 | static int DoC_SelectChip(void __iomem * docptr, int chip) | ||
155 | { | ||
156 | /* No choice for flash chip on Millennium Plus */ | ||
157 | return 0; | ||
158 | } | ||
159 | |||
160 | /* DoC_SelectFloor: Select a given floor (bank of flash chips) */ | ||
161 | static int DoC_SelectFloor(void __iomem * docptr, int floor) | ||
162 | { | ||
163 | WriteDOC((floor & 0x3), docptr, Mplus_DeviceSelect); | ||
164 | return 0; | ||
165 | } | ||
166 | |||
167 | /* | ||
168 | * Translate the given offset into the appropriate command and offset. | ||
169 | * This does the mapping using the 16bit interleave layout defined by | ||
170 | * M-Systems, and looks like this for a sector pair: | ||
171 | * +-----------+-------+-------+-------+--------------+---------+-----------+ | ||
172 | * | 0 --- 511 |512-517|518-519|520-521| 522 --- 1033 |1034-1039|1040 - 1055| | ||
173 | * +-----------+-------+-------+-------+--------------+---------+-----------+ | ||
174 | * | Data 0 | ECC 0 |Flags0 |Flags1 | Data 1 |ECC 1 | OOB 1 + 2 | | ||
175 | * +-----------+-------+-------+-------+--------------+---------+-----------+ | ||
176 | */ | ||
177 | /* FIXME: This lives in INFTL not here. Other users of flash devices | ||
178 | may not want it */ | ||
179 | static unsigned int DoC_GetDataOffset(struct mtd_info *mtd, loff_t *from) | ||
180 | { | ||
181 | struct DiskOnChip *this = mtd->priv; | ||
182 | |||
183 | if (this->interleave) { | ||
184 | unsigned int ofs = *from & 0x3ff; | ||
185 | unsigned int cmd; | ||
186 | |||
187 | if (ofs < 512) { | ||
188 | cmd = NAND_CMD_READ0; | ||
189 | ofs &= 0x1ff; | ||
190 | } else if (ofs < 1014) { | ||
191 | cmd = NAND_CMD_READ1; | ||
192 | ofs = (ofs & 0x1ff) + 10; | ||
193 | } else { | ||
194 | cmd = NAND_CMD_READOOB; | ||
195 | ofs = ofs - 1014; | ||
196 | } | ||
197 | |||
198 | *from = (*from & ~0x3ff) | ofs; | ||
199 | return cmd; | ||
200 | } else { | ||
201 | /* No interleave */ | ||
202 | if ((*from) & 0x100) | ||
203 | return NAND_CMD_READ1; | ||
204 | return NAND_CMD_READ0; | ||
205 | } | ||
206 | } | ||
207 | |||
208 | static unsigned int DoC_GetECCOffset(struct mtd_info *mtd, loff_t *from) | ||
209 | { | ||
210 | unsigned int ofs, cmd; | ||
211 | |||
212 | if (*from & 0x200) { | ||
213 | cmd = NAND_CMD_READOOB; | ||
214 | ofs = 10 + (*from & 0xf); | ||
215 | } else { | ||
216 | cmd = NAND_CMD_READ1; | ||
217 | ofs = (*from & 0xf); | ||
218 | } | ||
219 | |||
220 | *from = (*from & ~0x3ff) | ofs; | ||
221 | return cmd; | ||
222 | } | ||
223 | |||
224 | static unsigned int DoC_GetFlagsOffset(struct mtd_info *mtd, loff_t *from) | ||
225 | { | ||
226 | unsigned int ofs, cmd; | ||
227 | |||
228 | cmd = NAND_CMD_READ1; | ||
229 | ofs = (*from & 0x200) ? 8 : 6; | ||
230 | *from = (*from & ~0x3ff) | ofs; | ||
231 | return cmd; | ||
232 | } | ||
233 | |||
234 | static unsigned int DoC_GetHdrOffset(struct mtd_info *mtd, loff_t *from) | ||
235 | { | ||
236 | unsigned int ofs, cmd; | ||
237 | |||
238 | cmd = NAND_CMD_READOOB; | ||
239 | ofs = (*from & 0x200) ? 24 : 16; | ||
240 | *from = (*from & ~0x3ff) | ofs; | ||
241 | return cmd; | ||
242 | } | ||
243 | |||
244 | static inline void MemReadDOC(void __iomem * docptr, unsigned char *buf, int len) | ||
245 | { | ||
246 | #ifndef USE_MEMCPY | ||
247 | int i; | ||
248 | for (i = 0; i < len; i++) | ||
249 | buf[i] = ReadDOC(docptr, Mil_CDSN_IO + i); | ||
250 | #else | ||
251 | memcpy_fromio(buf, docptr + DoC_Mil_CDSN_IO, len); | ||
252 | #endif | ||
253 | } | ||
254 | |||
255 | static inline void MemWriteDOC(void __iomem * docptr, unsigned char *buf, int len) | ||
256 | { | ||
257 | #ifndef USE_MEMCPY | ||
258 | int i; | ||
259 | for (i = 0; i < len; i++) | ||
260 | WriteDOC(buf[i], docptr, Mil_CDSN_IO + i); | ||
261 | #else | ||
262 | memcpy_toio(docptr + DoC_Mil_CDSN_IO, buf, len); | ||
263 | #endif | ||
264 | } | ||
265 | |||
266 | /* DoC_IdentChip: Identify a given NAND chip given {floor,chip} */ | ||
267 | static int DoC_IdentChip(struct DiskOnChip *doc, int floor, int chip) | ||
268 | { | ||
269 | int mfr, id, i, j; | ||
270 | volatile char dummy; | ||
271 | void __iomem * docptr = doc->virtadr; | ||
272 | |||
273 | /* Page in the required floor/chip */ | ||
274 | DoC_SelectFloor(docptr, floor); | ||
275 | DoC_SelectChip(docptr, chip); | ||
276 | |||
277 | /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */ | ||
278 | WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect); | ||
279 | |||
280 | /* Reset the chip, see Software Requirement 11.4 item 1. */ | ||
281 | DoC_Command(docptr, NAND_CMD_RESET, 0); | ||
282 | DoC_WaitReady(docptr); | ||
283 | |||
284 | /* Read the NAND chip ID: 1. Send ReadID command */ | ||
285 | DoC_Command(docptr, NAND_CMD_READID, 0); | ||
286 | |||
287 | /* Read the NAND chip ID: 2. Send address byte zero */ | ||
288 | DoC_Address(doc, 1, 0x00, 0, 0x00); | ||
289 | |||
290 | WriteDOC(0, docptr, Mplus_FlashControl); | ||
291 | DoC_WaitReady(docptr); | ||
292 | |||
293 | /* Read the manufacturer and device id codes of the flash device through | ||
294 | CDSN IO register see Software Requirement 11.4 item 5.*/ | ||
295 | dummy = ReadDOC(docptr, Mplus_ReadPipeInit); | ||
296 | dummy = ReadDOC(docptr, Mplus_ReadPipeInit); | ||
297 | |||
298 | mfr = ReadDOC(docptr, Mil_CDSN_IO); | ||
299 | if (doc->interleave) | ||
300 | dummy = ReadDOC(docptr, Mil_CDSN_IO); /* 2 way interleave */ | ||
301 | |||
302 | id = ReadDOC(docptr, Mil_CDSN_IO); | ||
303 | if (doc->interleave) | ||
304 | dummy = ReadDOC(docptr, Mil_CDSN_IO); /* 2 way interleave */ | ||
305 | |||
306 | dummy = ReadDOC(docptr, Mplus_LastDataRead); | ||
307 | dummy = ReadDOC(docptr, Mplus_LastDataRead); | ||
308 | |||
309 | /* Disable flash internally */ | ||
310 | WriteDOC(0, docptr, Mplus_FlashSelect); | ||
311 | |||
312 | /* No response - return failure */ | ||
313 | if (mfr == 0xff || mfr == 0) | ||
314 | return 0; | ||
315 | |||
316 | for (i = 0; nand_flash_ids[i].name != NULL; i++) { | ||
317 | if (id == nand_flash_ids[i].dev_id) { | ||
318 | /* Try to identify manufacturer */ | ||
319 | for (j = 0; nand_manuf_ids[j].id != 0x0; j++) { | ||
320 | if (nand_manuf_ids[j].id == mfr) | ||
321 | break; | ||
322 | } | ||
323 | printk(KERN_INFO "Flash chip found: Manufacturer ID: %2.2X, " | ||
324 | "Chip ID: %2.2X (%s:%s)\n", mfr, id, | ||
325 | nand_manuf_ids[j].name, nand_flash_ids[i].name); | ||
326 | doc->mfr = mfr; | ||
327 | doc->id = id; | ||
328 | doc->chipshift = ffs((nand_flash_ids[i].chipsize << 20)) - 1; | ||
329 | doc->erasesize = nand_flash_ids[i].erasesize << doc->interleave; | ||
330 | break; | ||
331 | } | ||
332 | } | ||
333 | |||
334 | if (nand_flash_ids[i].name == NULL) | ||
335 | return 0; | ||
336 | return 1; | ||
337 | } | ||
338 | |||
339 | /* DoC_ScanChips: Find all NAND chips present in a DiskOnChip, and identify them */ | ||
340 | static void DoC_ScanChips(struct DiskOnChip *this) | ||
341 | { | ||
342 | int floor, chip; | ||
343 | int numchips[MAX_FLOORS_MPLUS]; | ||
344 | int ret; | ||
345 | |||
346 | this->numchips = 0; | ||
347 | this->mfr = 0; | ||
348 | this->id = 0; | ||
349 | |||
350 | /* Work out the intended interleave setting */ | ||
351 | this->interleave = 0; | ||
352 | if (this->ChipID == DOC_ChipID_DocMilPlus32) | ||
353 | this->interleave = 1; | ||
354 | |||
355 | /* Check the ASIC agrees */ | ||
356 | if ( (this->interleave << 2) != | ||
357 | (ReadDOC(this->virtadr, Mplus_Configuration) & 4)) { | ||
358 | u_char conf = ReadDOC(this->virtadr, Mplus_Configuration); | ||
359 | printk(KERN_NOTICE "Setting DiskOnChip Millennium Plus interleave to %s\n", | ||
360 | this->interleave?"on (16-bit)":"off (8-bit)"); | ||
361 | conf ^= 4; | ||
362 | WriteDOC(conf, this->virtadr, Mplus_Configuration); | ||
363 | } | ||
364 | |||
365 | /* For each floor, find the number of valid chips it contains */ | ||
366 | for (floor = 0,ret = 1; floor < MAX_FLOORS_MPLUS; floor++) { | ||
367 | numchips[floor] = 0; | ||
368 | for (chip = 0; chip < MAX_CHIPS_MPLUS && ret != 0; chip++) { | ||
369 | ret = DoC_IdentChip(this, floor, chip); | ||
370 | if (ret) { | ||
371 | numchips[floor]++; | ||
372 | this->numchips++; | ||
373 | } | ||
374 | } | ||
375 | } | ||
376 | /* If there are none at all that we recognise, bail */ | ||
377 | if (!this->numchips) { | ||
378 | printk("No flash chips recognised.\n"); | ||
379 | return; | ||
380 | } | ||
381 | |||
382 | /* Allocate an array to hold the information for each chip */ | ||
383 | this->chips = kmalloc(sizeof(struct Nand) * this->numchips, GFP_KERNEL); | ||
384 | if (!this->chips){ | ||
385 | printk("MTD: No memory for allocating chip info structures\n"); | ||
386 | return; | ||
387 | } | ||
388 | |||
389 | /* Fill out the chip array with {floor, chipno} for each | ||
390 | * detected chip in the device. */ | ||
391 | for (floor = 0, ret = 0; floor < MAX_FLOORS_MPLUS; floor++) { | ||
392 | for (chip = 0 ; chip < numchips[floor] ; chip++) { | ||
393 | this->chips[ret].floor = floor; | ||
394 | this->chips[ret].chip = chip; | ||
395 | this->chips[ret].curadr = 0; | ||
396 | this->chips[ret].curmode = 0x50; | ||
397 | ret++; | ||
398 | } | ||
399 | } | ||
400 | |||
401 | /* Calculate and print the total size of the device */ | ||
402 | this->totlen = this->numchips * (1 << this->chipshift); | ||
403 | printk(KERN_INFO "%d flash chips found. Total DiskOnChip size: %ld MiB\n", | ||
404 | this->numchips ,this->totlen >> 20); | ||
405 | } | ||
406 | |||
407 | static int DoCMilPlus_is_alias(struct DiskOnChip *doc1, struct DiskOnChip *doc2) | ||
408 | { | ||
409 | int tmp1, tmp2, retval; | ||
410 | |||
411 | if (doc1->physadr == doc2->physadr) | ||
412 | return 1; | ||
413 | |||
414 | /* Use the alias resolution register which was set aside for this | ||
415 | * purpose. If it's value is the same on both chips, they might | ||
416 | * be the same chip, and we write to one and check for a change in | ||
417 | * the other. It's unclear if this register is usuable in the | ||
418 | * DoC 2000 (it's in the Millennium docs), but it seems to work. */ | ||
419 | tmp1 = ReadDOC(doc1->virtadr, Mplus_AliasResolution); | ||
420 | tmp2 = ReadDOC(doc2->virtadr, Mplus_AliasResolution); | ||
421 | if (tmp1 != tmp2) | ||
422 | return 0; | ||
423 | |||
424 | WriteDOC((tmp1+1) % 0xff, doc1->virtadr, Mplus_AliasResolution); | ||
425 | tmp2 = ReadDOC(doc2->virtadr, Mplus_AliasResolution); | ||
426 | if (tmp2 == (tmp1+1) % 0xff) | ||
427 | retval = 1; | ||
428 | else | ||
429 | retval = 0; | ||
430 | |||
431 | /* Restore register contents. May not be necessary, but do it just to | ||
432 | * be safe. */ | ||
433 | WriteDOC(tmp1, doc1->virtadr, Mplus_AliasResolution); | ||
434 | |||
435 | return retval; | ||
436 | } | ||
437 | |||
438 | /* This routine is found from the docprobe code by symbol_get(), | ||
439 | * which will bump the use count of this module. */ | ||
440 | void DoCMilPlus_init(struct mtd_info *mtd) | ||
441 | { | ||
442 | struct DiskOnChip *this = mtd->priv; | ||
443 | struct DiskOnChip *old = NULL; | ||
444 | |||
445 | /* We must avoid being called twice for the same device. */ | ||
446 | if (docmilpluslist) | ||
447 | old = docmilpluslist->priv; | ||
448 | |||
449 | while (old) { | ||
450 | if (DoCMilPlus_is_alias(this, old)) { | ||
451 | printk(KERN_NOTICE "Ignoring DiskOnChip Millennium " | ||
452 | "Plus at 0x%lX - already configured\n", | ||
453 | this->physadr); | ||
454 | iounmap(this->virtadr); | ||
455 | kfree(mtd); | ||
456 | return; | ||
457 | } | ||
458 | if (old->nextdoc) | ||
459 | old = old->nextdoc->priv; | ||
460 | else | ||
461 | old = NULL; | ||
462 | } | ||
463 | |||
464 | mtd->name = "DiskOnChip Millennium Plus"; | ||
465 | printk(KERN_NOTICE "DiskOnChip Millennium Plus found at " | ||
466 | "address 0x%lX\n", this->physadr); | ||
467 | |||
468 | mtd->type = MTD_NANDFLASH; | ||
469 | mtd->flags = MTD_CAP_NANDFLASH; | ||
470 | mtd->writebufsize = mtd->writesize = 512; | ||
471 | mtd->oobsize = 16; | ||
472 | mtd->ecc_strength = 2; | ||
473 | mtd->owner = THIS_MODULE; | ||
474 | mtd->_erase = doc_erase; | ||
475 | mtd->_read = doc_read; | ||
476 | mtd->_write = doc_write; | ||
477 | mtd->_read_oob = doc_read_oob; | ||
478 | mtd->_write_oob = doc_write_oob; | ||
479 | this->curfloor = -1; | ||
480 | this->curchip = -1; | ||
481 | |||
482 | /* Ident all the chips present. */ | ||
483 | DoC_ScanChips(this); | ||
484 | |||
485 | if (!this->totlen) { | ||
486 | kfree(mtd); | ||
487 | iounmap(this->virtadr); | ||
488 | } else { | ||
489 | this->nextdoc = docmilpluslist; | ||
490 | docmilpluslist = mtd; | ||
491 | mtd->size = this->totlen; | ||
492 | mtd->erasesize = this->erasesize; | ||
493 | mtd_device_register(mtd, NULL, 0); | ||
494 | return; | ||
495 | } | ||
496 | } | ||
497 | EXPORT_SYMBOL_GPL(DoCMilPlus_init); | ||
498 | |||
499 | #if 0 | ||
500 | static int doc_dumpblk(struct mtd_info *mtd, loff_t from) | ||
501 | { | ||
502 | int i; | ||
503 | loff_t fofs; | ||
504 | struct DiskOnChip *this = mtd->priv; | ||
505 | void __iomem * docptr = this->virtadr; | ||
506 | struct Nand *mychip = &this->chips[from >> (this->chipshift)]; | ||
507 | unsigned char *bp, buf[1056]; | ||
508 | char c[32]; | ||
509 | |||
510 | from &= ~0x3ff; | ||
511 | |||
512 | /* Don't allow read past end of device */ | ||
513 | if (from >= this->totlen) | ||
514 | return -EINVAL; | ||
515 | |||
516 | DoC_CheckASIC(docptr); | ||
517 | |||
518 | /* Find the chip which is to be used and select it */ | ||
519 | if (this->curfloor != mychip->floor) { | ||
520 | DoC_SelectFloor(docptr, mychip->floor); | ||
521 | DoC_SelectChip(docptr, mychip->chip); | ||
522 | } else if (this->curchip != mychip->chip) { | ||
523 | DoC_SelectChip(docptr, mychip->chip); | ||
524 | } | ||
525 | this->curfloor = mychip->floor; | ||
526 | this->curchip = mychip->chip; | ||
527 | |||
528 | /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */ | ||
529 | WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect); | ||
530 | |||
531 | /* Reset the chip, see Software Requirement 11.4 item 1. */ | ||
532 | DoC_Command(docptr, NAND_CMD_RESET, 0); | ||
533 | DoC_WaitReady(docptr); | ||
534 | |||
535 | fofs = from; | ||
536 | DoC_Command(docptr, DoC_GetDataOffset(mtd, &fofs), 0); | ||
537 | DoC_Address(this, 3, fofs, 0, 0x00); | ||
538 | WriteDOC(0, docptr, Mplus_FlashControl); | ||
539 | DoC_WaitReady(docptr); | ||
540 | |||
541 | /* disable the ECC engine */ | ||
542 | WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf); | ||
543 | |||
544 | ReadDOC(docptr, Mplus_ReadPipeInit); | ||
545 | ReadDOC(docptr, Mplus_ReadPipeInit); | ||
546 | |||
547 | /* Read the data via the internal pipeline through CDSN IO | ||
548 | register, see Pipelined Read Operations 11.3 */ | ||
549 | MemReadDOC(docptr, buf, 1054); | ||
550 | buf[1054] = ReadDOC(docptr, Mplus_LastDataRead); | ||
551 | buf[1055] = ReadDOC(docptr, Mplus_LastDataRead); | ||
552 | |||
553 | memset(&c[0], 0, sizeof(c)); | ||
554 | printk("DUMP OFFSET=%x:\n", (int)from); | ||
555 | |||
556 | for (i = 0, bp = &buf[0]; (i < 1056); i++) { | ||
557 | if ((i % 16) == 0) | ||
558 | printk("%08x: ", i); | ||
559 | printk(" %02x", *bp); | ||
560 | c[(i & 0xf)] = ((*bp >= 0x20) && (*bp <= 0x7f)) ? *bp : '.'; | ||
561 | bp++; | ||
562 | if (((i + 1) % 16) == 0) | ||
563 | printk(" %s\n", c); | ||
564 | } | ||
565 | printk("\n"); | ||
566 | |||
567 | /* Disable flash internally */ | ||
568 | WriteDOC(0, docptr, Mplus_FlashSelect); | ||
569 | |||
570 | return 0; | ||
571 | } | ||
572 | #endif | ||
573 | |||
574 | static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, | ||
575 | size_t *retlen, u_char *buf) | ||
576 | { | ||
577 | int ret, i; | ||
578 | volatile char dummy; | ||
579 | loff_t fofs; | ||
580 | unsigned char syndrome[6], eccbuf[6]; | ||
581 | struct DiskOnChip *this = mtd->priv; | ||
582 | void __iomem * docptr = this->virtadr; | ||
583 | struct Nand *mychip = &this->chips[from >> (this->chipshift)]; | ||
584 | |||
585 | /* Don't allow a single read to cross a 512-byte block boundary */ | ||
586 | if (from + len > ((from | 0x1ff) + 1)) | ||
587 | len = ((from | 0x1ff) + 1) - from; | ||
588 | |||
589 | DoC_CheckASIC(docptr); | ||
590 | |||
591 | /* Find the chip which is to be used and select it */ | ||
592 | if (this->curfloor != mychip->floor) { | ||
593 | DoC_SelectFloor(docptr, mychip->floor); | ||
594 | DoC_SelectChip(docptr, mychip->chip); | ||
595 | } else if (this->curchip != mychip->chip) { | ||
596 | DoC_SelectChip(docptr, mychip->chip); | ||
597 | } | ||
598 | this->curfloor = mychip->floor; | ||
599 | this->curchip = mychip->chip; | ||
600 | |||
601 | /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */ | ||
602 | WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect); | ||
603 | |||
604 | /* Reset the chip, see Software Requirement 11.4 item 1. */ | ||
605 | DoC_Command(docptr, NAND_CMD_RESET, 0); | ||
606 | DoC_WaitReady(docptr); | ||
607 | |||
608 | fofs = from; | ||
609 | DoC_Command(docptr, DoC_GetDataOffset(mtd, &fofs), 0); | ||
610 | DoC_Address(this, 3, fofs, 0, 0x00); | ||
611 | WriteDOC(0, docptr, Mplus_FlashControl); | ||
612 | DoC_WaitReady(docptr); | ||
613 | |||
614 | /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/ | ||
615 | WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf); | ||
616 | WriteDOC(DOC_ECC_EN, docptr, Mplus_ECCConf); | ||
617 | |||
618 | /* Let the caller know we completed it */ | ||
619 | *retlen = len; | ||
620 | ret = 0; | ||
621 | |||
622 | ReadDOC(docptr, Mplus_ReadPipeInit); | ||
623 | ReadDOC(docptr, Mplus_ReadPipeInit); | ||
624 | |||
625 | /* Read the data via the internal pipeline through CDSN IO | ||
626 | register, see Pipelined Read Operations 11.3 */ | ||
627 | MemReadDOC(docptr, buf, len); | ||
628 | |||
629 | /* Read the ECC data following raw data */ | ||
630 | MemReadDOC(docptr, eccbuf, 4); | ||
631 | eccbuf[4] = ReadDOC(docptr, Mplus_LastDataRead); | ||
632 | eccbuf[5] = ReadDOC(docptr, Mplus_LastDataRead); | ||
633 | |||
634 | /* Flush the pipeline */ | ||
635 | dummy = ReadDOC(docptr, Mplus_ECCConf); | ||
636 | dummy = ReadDOC(docptr, Mplus_ECCConf); | ||
637 | |||
638 | /* Check the ECC Status */ | ||
639 | if (ReadDOC(docptr, Mplus_ECCConf) & 0x80) { | ||
640 | int nb_errors; | ||
641 | /* There was an ECC error */ | ||
642 | #ifdef ECC_DEBUG | ||
643 | printk("DiskOnChip ECC Error: Read at %lx\n", (long)from); | ||
644 | #endif | ||
645 | /* Read the ECC syndrome through the DiskOnChip ECC logic. | ||
646 | These syndrome will be all ZERO when there is no error */ | ||
647 | for (i = 0; i < 6; i++) | ||
648 | syndrome[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i); | ||
649 | |||
650 | nb_errors = doc_decode_ecc(buf, syndrome); | ||
651 | #ifdef ECC_DEBUG | ||
652 | printk("ECC Errors corrected: %x\n", nb_errors); | ||
653 | #endif | ||
654 | if (nb_errors < 0) { | ||
655 | /* We return error, but have actually done the | ||
656 | read. Not that this can be told to user-space, via | ||
657 | sys_read(), but at least MTD-aware stuff can know | ||
658 | about it by checking *retlen */ | ||
659 | #ifdef ECC_DEBUG | ||
660 | printk("%s(%d): Millennium Plus ECC error (from=0x%x:\n", | ||
661 | __FILE__, __LINE__, (int)from); | ||
662 | printk(" syndrome= %*phC\n", 6, syndrome); | ||
663 | printk(" eccbuf= %*phC\n", 6, eccbuf); | ||
664 | #endif | ||
665 | ret = -EIO; | ||
666 | } | ||
667 | } | ||
668 | |||
669 | #ifdef PSYCHO_DEBUG | ||
670 | printk("ECC DATA at %lx: %*ph\n", (long)from, 6, eccbuf); | ||
671 | #endif | ||
672 | /* disable the ECC engine */ | ||
673 | WriteDOC(DOC_ECC_DIS, docptr , Mplus_ECCConf); | ||
674 | |||
675 | /* Disable flash internally */ | ||
676 | WriteDOC(0, docptr, Mplus_FlashSelect); | ||
677 | |||
678 | return ret; | ||
679 | } | ||
680 | |||
681 | static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, | ||
682 | size_t *retlen, const u_char *buf) | ||
683 | { | ||
684 | int i, before, ret = 0; | ||
685 | loff_t fto; | ||
686 | volatile char dummy; | ||
687 | char eccbuf[6]; | ||
688 | struct DiskOnChip *this = mtd->priv; | ||
689 | void __iomem * docptr = this->virtadr; | ||
690 | struct Nand *mychip = &this->chips[to >> (this->chipshift)]; | ||
691 | |||
692 | /* Don't allow writes which aren't exactly one block (512 bytes) */ | ||
693 | if ((to & 0x1ff) || (len != 0x200)) | ||
694 | return -EINVAL; | ||
695 | |||
696 | /* Determine position of OOB flags, before or after data */ | ||
697 | before = (this->interleave && (to & 0x200)); | ||
698 | |||
699 | DoC_CheckASIC(docptr); | ||
700 | |||
701 | /* Find the chip which is to be used and select it */ | ||
702 | if (this->curfloor != mychip->floor) { | ||
703 | DoC_SelectFloor(docptr, mychip->floor); | ||
704 | DoC_SelectChip(docptr, mychip->chip); | ||
705 | } else if (this->curchip != mychip->chip) { | ||
706 | DoC_SelectChip(docptr, mychip->chip); | ||
707 | } | ||
708 | this->curfloor = mychip->floor; | ||
709 | this->curchip = mychip->chip; | ||
710 | |||
711 | /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */ | ||
712 | WriteDOC(DOC_FLASH_CE, docptr, Mplus_FlashSelect); | ||
713 | |||
714 | /* Reset the chip, see Software Requirement 11.4 item 1. */ | ||
715 | DoC_Command(docptr, NAND_CMD_RESET, 0); | ||
716 | DoC_WaitReady(docptr); | ||
717 | |||
718 | /* Set device to appropriate plane of flash */ | ||
719 | fto = to; | ||
720 | WriteDOC(DoC_GetDataOffset(mtd, &fto), docptr, Mplus_FlashCmd); | ||
721 | |||
722 | /* On interleaved devices the flags for 2nd half 512 are before data */ | ||
723 | if (before) | ||
724 | fto -= 2; | ||
725 | |||
726 | /* issue the Serial Data In command to initial the Page Program process */ | ||
727 | DoC_Command(docptr, NAND_CMD_SEQIN, 0x00); | ||
728 | DoC_Address(this, 3, fto, 0x00, 0x00); | ||
729 | |||
730 | /* Disable the ECC engine */ | ||
731 | WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf); | ||
732 | |||
733 | if (before) { | ||
734 | /* Write the block status BLOCK_USED (0x5555) */ | ||
735 | WriteDOC(0x55, docptr, Mil_CDSN_IO); | ||
736 | WriteDOC(0x55, docptr, Mil_CDSN_IO); | ||
737 | } | ||
738 | |||
739 | /* init the ECC engine, see Reed-Solomon EDC/ECC 11.1 .*/ | ||
740 | WriteDOC(DOC_ECC_EN | DOC_ECC_RW, docptr, Mplus_ECCConf); | ||
741 | |||
742 | MemWriteDOC(docptr, (unsigned char *) buf, len); | ||
743 | |||
744 | /* Write ECC data to flash, the ECC info is generated by | ||
745 | the DiskOnChip ECC logic see Reed-Solomon EDC/ECC 11.1 */ | ||
746 | DoC_Delay(docptr, 3); | ||
747 | |||
748 | /* Read the ECC data through the DiskOnChip ECC logic */ | ||
749 | for (i = 0; i < 6; i++) | ||
750 | eccbuf[i] = ReadDOC(docptr, Mplus_ECCSyndrome0 + i); | ||
751 | |||
752 | /* disable the ECC engine */ | ||
753 | WriteDOC(DOC_ECC_DIS, docptr, Mplus_ECCConf); | ||
754 | |||
755 | /* Write the ECC data to flash */ | ||
756 | MemWriteDOC(docptr, eccbuf, 6); | ||
757 | |||
758 | if (!before) { | ||
759 | /* Write the block status BLOCK_USED (0x5555) */ | ||
760 | WriteDOC(0x55, docptr, Mil_CDSN_IO+6); | ||
761 | WriteDOC(0x55, docptr, Mil_CDSN_IO+7); | ||
762 | } | ||
763 | |||
764 | #ifdef PSYCHO_DEBUG | ||
765 | printk("OOB data at %lx is %2.2X %2.2X %2.2X %2.2X %2.2X %2.2X\n", | ||
766 | (long) to, eccbuf[0], eccbuf[1], eccbuf[2], eccbuf[3], | ||
767 | eccbuf[4], eccbuf[5]); | ||
768 | #endif | ||
769 | |||
770 | WriteDOC(0x00, docptr, Mplus_WritePipeTerm); | ||
771 | WriteDOC(0x00, docptr, Mplus_WritePipeTerm); | ||
772 | |||
773 | /* Commit the Page Program command and wait for ready | ||
774 | see Software Requirement 11.4 item 1.*/ | ||
775 | DoC_Command(docptr, NAND_CMD_PAGEPROG, 0x00); | ||
776 | DoC_WaitReady(docptr); | ||
777 | |||
778 | /* Read the status of the flash device through CDSN IO register | ||
779 | see Software Requirement 11.4 item 5.*/ | ||
780 | DoC_Command(docptr, NAND_CMD_STATUS, 0); | ||
781 | dummy = ReadDOC(docptr, Mplus_ReadPipeInit); | ||
782 | dummy = ReadDOC(docptr, Mplus_ReadPipeInit); | ||
783 | DoC_Delay(docptr, 2); | ||
784 | if ((dummy = ReadDOC(docptr, Mplus_LastDataRead)) & 1) { | ||
785 | printk("MTD: Error 0x%x programming at 0x%x\n", dummy, (int)to); | ||
786 | /* Error in programming | ||
787 | FIXME: implement Bad Block Replacement (in nftl.c ??) */ | ||
788 | ret = -EIO; | ||
789 | } | ||
790 | dummy = ReadDOC(docptr, Mplus_LastDataRead); | ||
791 | |||
792 | /* Disable flash internally */ | ||
793 | WriteDOC(0, docptr, Mplus_FlashSelect); | ||
794 | |||
795 | /* Let the caller know we completed it */ | ||
796 | *retlen = len; | ||
797 | |||
798 | return ret; | ||
799 | } | ||
800 | |||
801 | static int doc_read_oob(struct mtd_info *mtd, loff_t ofs, | ||
802 | struct mtd_oob_ops *ops) | ||
803 | { | ||
804 | loff_t fofs, base; | ||
805 | struct DiskOnChip *this = mtd->priv; | ||
806 | void __iomem * docptr = this->virtadr; | ||
807 | struct Nand *mychip = &this->chips[ofs >> this->chipshift]; | ||
808 | size_t i, size, got, want; | ||
809 | uint8_t *buf = ops->oobbuf; | ||
810 | size_t len = ops->len; | ||
811 | |||
812 | BUG_ON(ops->mode != MTD_OPS_PLACE_OOB); | ||
813 | |||
814 | ofs += ops->ooboffs; | ||
815 | |||
816 | DoC_CheckASIC(docptr); | ||
817 | |||
818 | /* Find the chip which is to be used and select it */ | ||
819 | if (this->curfloor != mychip->floor) { | ||
820 | DoC_SelectFloor(docptr, mychip->floor); | ||
821 | DoC_SelectChip(docptr, mychip->chip); | ||
822 | } else if (this->curchip != mychip->chip) { | ||
823 | DoC_SelectChip(docptr, mychip->chip); | ||
824 | } | ||
825 | this->curfloor = mychip->floor; | ||
826 | this->curchip = mychip->chip; | ||
827 | |||
828 | /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */ | ||
829 | WriteDOC((DOC_FLASH_CE | DOC_FLASH_WP), docptr, Mplus_FlashSelect); | ||
830 | |||
831 | /* disable the ECC engine */ | ||
832 | WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf); | ||
833 | DoC_WaitReady(docptr); | ||
834 | |||
835 | /* Maximum of 16 bytes in the OOB region, so limit read to that */ | ||
836 | if (len > 16) | ||
837 | len = 16; | ||
838 | got = 0; | ||
839 | want = len; | ||
840 | |||
841 | for (i = 0; ((i < 3) && (want > 0)); i++) { | ||
842 | /* Figure out which region we are accessing... */ | ||
843 | fofs = ofs; | ||
844 | base = ofs & 0xf; | ||
845 | if (!this->interleave) { | ||
846 | DoC_Command(docptr, NAND_CMD_READOOB, 0); | ||
847 | size = 16 - base; | ||
848 | } else if (base < 6) { | ||
849 | DoC_Command(docptr, DoC_GetECCOffset(mtd, &fofs), 0); | ||
850 | size = 6 - base; | ||
851 | } else if (base < 8) { | ||
852 | DoC_Command(docptr, DoC_GetFlagsOffset(mtd, &fofs), 0); | ||
853 | size = 8 - base; | ||
854 | } else { | ||
855 | DoC_Command(docptr, DoC_GetHdrOffset(mtd, &fofs), 0); | ||
856 | size = 16 - base; | ||
857 | } | ||
858 | if (size > want) | ||
859 | size = want; | ||
860 | |||
861 | /* Issue read command */ | ||
862 | DoC_Address(this, 3, fofs, 0, 0x00); | ||
863 | WriteDOC(0, docptr, Mplus_FlashControl); | ||
864 | DoC_WaitReady(docptr); | ||
865 | |||
866 | ReadDOC(docptr, Mplus_ReadPipeInit); | ||
867 | ReadDOC(docptr, Mplus_ReadPipeInit); | ||
868 | MemReadDOC(docptr, &buf[got], size - 2); | ||
869 | buf[got + size - 2] = ReadDOC(docptr, Mplus_LastDataRead); | ||
870 | buf[got + size - 1] = ReadDOC(docptr, Mplus_LastDataRead); | ||
871 | |||
872 | ofs += size; | ||
873 | got += size; | ||
874 | want -= size; | ||
875 | } | ||
876 | |||
877 | /* Disable flash internally */ | ||
878 | WriteDOC(0, docptr, Mplus_FlashSelect); | ||
879 | |||
880 | ops->retlen = len; | ||
881 | return 0; | ||
882 | } | ||
883 | |||
884 | static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, | ||
885 | struct mtd_oob_ops *ops) | ||
886 | { | ||
887 | volatile char dummy; | ||
888 | loff_t fofs, base; | ||
889 | struct DiskOnChip *this = mtd->priv; | ||
890 | void __iomem * docptr = this->virtadr; | ||
891 | struct Nand *mychip = &this->chips[ofs >> this->chipshift]; | ||
892 | size_t i, size, got, want; | ||
893 | int ret = 0; | ||
894 | uint8_t *buf = ops->oobbuf; | ||
895 | size_t len = ops->len; | ||
896 | |||
897 | BUG_ON(ops->mode != MTD_OPS_PLACE_OOB); | ||
898 | |||
899 | ofs += ops->ooboffs; | ||
900 | |||
901 | DoC_CheckASIC(docptr); | ||
902 | |||
903 | /* Find the chip which is to be used and select it */ | ||
904 | if (this->curfloor != mychip->floor) { | ||
905 | DoC_SelectFloor(docptr, mychip->floor); | ||
906 | DoC_SelectChip(docptr, mychip->chip); | ||
907 | } else if (this->curchip != mychip->chip) { | ||
908 | DoC_SelectChip(docptr, mychip->chip); | ||
909 | } | ||
910 | this->curfloor = mychip->floor; | ||
911 | this->curchip = mychip->chip; | ||
912 | |||
913 | /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */ | ||
914 | WriteDOC(DOC_FLASH_CE, docptr, Mplus_FlashSelect); | ||
915 | |||
916 | |||
917 | /* Maximum of 16 bytes in the OOB region, so limit write to that */ | ||
918 | if (len > 16) | ||
919 | len = 16; | ||
920 | got = 0; | ||
921 | want = len; | ||
922 | |||
923 | for (i = 0; ((i < 3) && (want > 0)); i++) { | ||
924 | /* Reset the chip, see Software Requirement 11.4 item 1. */ | ||
925 | DoC_Command(docptr, NAND_CMD_RESET, 0); | ||
926 | DoC_WaitReady(docptr); | ||
927 | |||
928 | /* Figure out which region we are accessing... */ | ||
929 | fofs = ofs; | ||
930 | base = ofs & 0x0f; | ||
931 | if (!this->interleave) { | ||
932 | WriteDOC(NAND_CMD_READOOB, docptr, Mplus_FlashCmd); | ||
933 | size = 16 - base; | ||
934 | } else if (base < 6) { | ||
935 | WriteDOC(DoC_GetECCOffset(mtd, &fofs), docptr, Mplus_FlashCmd); | ||
936 | size = 6 - base; | ||
937 | } else if (base < 8) { | ||
938 | WriteDOC(DoC_GetFlagsOffset(mtd, &fofs), docptr, Mplus_FlashCmd); | ||
939 | size = 8 - base; | ||
940 | } else { | ||
941 | WriteDOC(DoC_GetHdrOffset(mtd, &fofs), docptr, Mplus_FlashCmd); | ||
942 | size = 16 - base; | ||
943 | } | ||
944 | if (size > want) | ||
945 | size = want; | ||
946 | |||
947 | /* Issue the Serial Data In command to initial the Page Program process */ | ||
948 | DoC_Command(docptr, NAND_CMD_SEQIN, 0x00); | ||
949 | DoC_Address(this, 3, fofs, 0, 0x00); | ||
950 | |||
951 | /* Disable the ECC engine */ | ||
952 | WriteDOC(DOC_ECC_RESET, docptr, Mplus_ECCConf); | ||
953 | |||
954 | /* Write the data via the internal pipeline through CDSN IO | ||
955 | register, see Pipelined Write Operations 11.2 */ | ||
956 | MemWriteDOC(docptr, (unsigned char *) &buf[got], size); | ||
957 | WriteDOC(0x00, docptr, Mplus_WritePipeTerm); | ||
958 | WriteDOC(0x00, docptr, Mplus_WritePipeTerm); | ||
959 | |||
960 | /* Commit the Page Program command and wait for ready | ||
961 | see Software Requirement 11.4 item 1.*/ | ||
962 | DoC_Command(docptr, NAND_CMD_PAGEPROG, 0x00); | ||
963 | DoC_WaitReady(docptr); | ||
964 | |||
965 | /* Read the status of the flash device through CDSN IO register | ||
966 | see Software Requirement 11.4 item 5.*/ | ||
967 | DoC_Command(docptr, NAND_CMD_STATUS, 0x00); | ||
968 | dummy = ReadDOC(docptr, Mplus_ReadPipeInit); | ||
969 | dummy = ReadDOC(docptr, Mplus_ReadPipeInit); | ||
970 | DoC_Delay(docptr, 2); | ||
971 | if ((dummy = ReadDOC(docptr, Mplus_LastDataRead)) & 1) { | ||
972 | printk("MTD: Error 0x%x programming oob at 0x%x\n", | ||
973 | dummy, (int)ofs); | ||
974 | /* FIXME: implement Bad Block Replacement */ | ||
975 | ops->retlen = 0; | ||
976 | ret = -EIO; | ||
977 | } | ||
978 | dummy = ReadDOC(docptr, Mplus_LastDataRead); | ||
979 | |||
980 | ofs += size; | ||
981 | got += size; | ||
982 | want -= size; | ||
983 | } | ||
984 | |||
985 | /* Disable flash internally */ | ||
986 | WriteDOC(0, docptr, Mplus_FlashSelect); | ||
987 | |||
988 | ops->retlen = len; | ||
989 | return ret; | ||
990 | } | ||
991 | |||
992 | int doc_erase(struct mtd_info *mtd, struct erase_info *instr) | ||
993 | { | ||
994 | volatile char dummy; | ||
995 | struct DiskOnChip *this = mtd->priv; | ||
996 | __u32 ofs = instr->addr; | ||
997 | __u32 len = instr->len; | ||
998 | void __iomem * docptr = this->virtadr; | ||
999 | struct Nand *mychip = &this->chips[ofs >> this->chipshift]; | ||
1000 | |||
1001 | DoC_CheckASIC(docptr); | ||
1002 | |||
1003 | if (len != mtd->erasesize) | ||
1004 | printk(KERN_WARNING "MTD: Erase not right size (%x != %x)n", | ||
1005 | len, mtd->erasesize); | ||
1006 | |||
1007 | /* Find the chip which is to be used and select it */ | ||
1008 | if (this->curfloor != mychip->floor) { | ||
1009 | DoC_SelectFloor(docptr, mychip->floor); | ||
1010 | DoC_SelectChip(docptr, mychip->chip); | ||
1011 | } else if (this->curchip != mychip->chip) { | ||
1012 | DoC_SelectChip(docptr, mychip->chip); | ||
1013 | } | ||
1014 | this->curfloor = mychip->floor; | ||
1015 | this->curchip = mychip->chip; | ||
1016 | |||
1017 | instr->state = MTD_ERASE_PENDING; | ||
1018 | |||
1019 | /* Millennium Plus bus cycle sequence as per figure 2, section 2.4 */ | ||
1020 | WriteDOC(DOC_FLASH_CE, docptr, Mplus_FlashSelect); | ||
1021 | |||
1022 | DoC_Command(docptr, NAND_CMD_RESET, 0x00); | ||
1023 | DoC_WaitReady(docptr); | ||
1024 | |||
1025 | DoC_Command(docptr, NAND_CMD_ERASE1, 0); | ||
1026 | DoC_Address(this, 2, ofs, 0, 0x00); | ||
1027 | DoC_Command(docptr, NAND_CMD_ERASE2, 0); | ||
1028 | DoC_WaitReady(docptr); | ||
1029 | instr->state = MTD_ERASING; | ||
1030 | |||
1031 | /* Read the status of the flash device through CDSN IO register | ||
1032 | see Software Requirement 11.4 item 5. */ | ||
1033 | DoC_Command(docptr, NAND_CMD_STATUS, 0); | ||
1034 | dummy = ReadDOC(docptr, Mplus_ReadPipeInit); | ||
1035 | dummy = ReadDOC(docptr, Mplus_ReadPipeInit); | ||
1036 | if ((dummy = ReadDOC(docptr, Mplus_LastDataRead)) & 1) { | ||
1037 | printk("MTD: Error 0x%x erasing at 0x%x\n", dummy, ofs); | ||
1038 | /* FIXME: implement Bad Block Replacement (in nftl.c ??) */ | ||
1039 | instr->state = MTD_ERASE_FAILED; | ||
1040 | } else { | ||
1041 | instr->state = MTD_ERASE_DONE; | ||
1042 | } | ||
1043 | dummy = ReadDOC(docptr, Mplus_LastDataRead); | ||
1044 | |||
1045 | /* Disable flash internally */ | ||
1046 | WriteDOC(0, docptr, Mplus_FlashSelect); | ||
1047 | |||
1048 | mtd_erase_callback(instr); | ||
1049 | |||
1050 | return 0; | ||
1051 | } | ||
1052 | |||
1053 | /**************************************************************************** | ||
1054 | * | ||
1055 | * Module stuff | ||
1056 | * | ||
1057 | ****************************************************************************/ | ||
1058 | |||
1059 | static void __exit cleanup_doc2001plus(void) | ||
1060 | { | ||
1061 | struct mtd_info *mtd; | ||
1062 | struct DiskOnChip *this; | ||
1063 | |||
1064 | while ((mtd=docmilpluslist)) { | ||
1065 | this = mtd->priv; | ||
1066 | docmilpluslist = this->nextdoc; | ||
1067 | |||
1068 | mtd_device_unregister(mtd); | ||
1069 | |||
1070 | iounmap(this->virtadr); | ||
1071 | kfree(this->chips); | ||
1072 | kfree(mtd); | ||
1073 | } | ||
1074 | } | ||
1075 | |||
1076 | module_exit(cleanup_doc2001plus); | ||
1077 | |||
1078 | MODULE_LICENSE("GPL"); | ||
1079 | MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com> et al."); | ||
1080 | MODULE_DESCRIPTION("Driver for DiskOnChip Millennium Plus"); | ||
diff --git a/drivers/mtd/devices/docecc.c b/drivers/mtd/devices/docecc.c deleted file mode 100644 index 4a1c39b6f37d..000000000000 --- a/drivers/mtd/devices/docecc.c +++ /dev/null | |||
@@ -1,521 +0,0 @@ | |||
1 | /* | ||
2 | * ECC algorithm for M-systems disk on chip. We use the excellent Reed | ||
3 | * Solmon code of Phil Karn (karn@ka9q.ampr.org) available under the | ||
4 | * GNU GPL License. The rest is simply to convert the disk on chip | ||
5 | * syndrome into a standard syndome. | ||
6 | * | ||
7 | * Author: Fabrice Bellard (fabrice.bellard@netgem.com) | ||
8 | * Copyright (C) 2000 Netgem S.A. | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License as published by | ||
12 | * the Free Software Foundation; either version 2 of the License, or | ||
13 | * (at your option) any later version. | ||
14 | * | ||
15 | * This program is distributed in the hope that it will be useful, | ||
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
18 | * GNU General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
23 | */ | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/module.h> | ||
26 | #include <asm/errno.h> | ||
27 | #include <asm/io.h> | ||
28 | #include <asm/uaccess.h> | ||
29 | #include <linux/delay.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/init.h> | ||
32 | #include <linux/types.h> | ||
33 | |||
34 | #include <linux/mtd/mtd.h> | ||
35 | #include <linux/mtd/doc2000.h> | ||
36 | |||
37 | #define DEBUG_ECC 0 | ||
38 | /* need to undef it (from asm/termbits.h) */ | ||
39 | #undef B0 | ||
40 | |||
41 | #define MM 10 /* Symbol size in bits */ | ||
42 | #define KK (1023-4) /* Number of data symbols per block */ | ||
43 | #define B0 510 /* First root of generator polynomial, alpha form */ | ||
44 | #define PRIM 1 /* power of alpha used to generate roots of generator poly */ | ||
45 | #define NN ((1 << MM) - 1) | ||
46 | |||
47 | typedef unsigned short dtype; | ||
48 | |||
49 | /* 1+x^3+x^10 */ | ||
50 | static const int Pp[MM+1] = { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 }; | ||
51 | |||
52 | /* This defines the type used to store an element of the Galois Field | ||
53 | * used by the code. Make sure this is something larger than a char if | ||
54 | * if anything larger than GF(256) is used. | ||
55 | * | ||
56 | * Note: unsigned char will work up to GF(256) but int seems to run | ||
57 | * faster on the Pentium. | ||
58 | */ | ||
59 | typedef int gf; | ||
60 | |||
61 | /* No legal value in index form represents zero, so | ||
62 | * we need a special value for this purpose | ||
63 | */ | ||
64 | #define A0 (NN) | ||
65 | |||
66 | /* Compute x % NN, where NN is 2**MM - 1, | ||
67 | * without a slow divide | ||
68 | */ | ||
69 | static inline gf | ||
70 | modnn(int x) | ||
71 | { | ||
72 | while (x >= NN) { | ||
73 | x -= NN; | ||
74 | x = (x >> MM) + (x & NN); | ||
75 | } | ||
76 | return x; | ||
77 | } | ||
78 | |||
79 | #define CLEAR(a,n) {\ | ||
80 | int ci;\ | ||
81 | for(ci=(n)-1;ci >=0;ci--)\ | ||
82 | (a)[ci] = 0;\ | ||
83 | } | ||
84 | |||
85 | #define COPY(a,b,n) {\ | ||
86 | int ci;\ | ||
87 | for(ci=(n)-1;ci >=0;ci--)\ | ||
88 | (a)[ci] = (b)[ci];\ | ||
89 | } | ||
90 | |||
91 | #define COPYDOWN(a,b,n) {\ | ||
92 | int ci;\ | ||
93 | for(ci=(n)-1;ci >=0;ci--)\ | ||
94 | (a)[ci] = (b)[ci];\ | ||
95 | } | ||
96 | |||
97 | #define Ldec 1 | ||
98 | |||
99 | /* generate GF(2**m) from the irreducible polynomial p(X) in Pp[0]..Pp[m] | ||
100 | lookup tables: index->polynomial form alpha_to[] contains j=alpha**i; | ||
101 | polynomial form -> index form index_of[j=alpha**i] = i | ||
102 | alpha=2 is the primitive element of GF(2**m) | ||
103 | HARI's COMMENT: (4/13/94) alpha_to[] can be used as follows: | ||
104 | Let @ represent the primitive element commonly called "alpha" that | ||
105 | is the root of the primitive polynomial p(x). Then in GF(2^m), for any | ||
106 | 0 <= i <= 2^m-2, | ||
107 | @^i = a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1) | ||
108 | where the binary vector (a(0),a(1),a(2),...,a(m-1)) is the representation | ||
109 | of the integer "alpha_to[i]" with a(0) being the LSB and a(m-1) the MSB. Thus for | ||
110 | example the polynomial representation of @^5 would be given by the binary | ||
111 | representation of the integer "alpha_to[5]". | ||
112 | Similarly, index_of[] can be used as follows: | ||
113 | As above, let @ represent the primitive element of GF(2^m) that is | ||
114 | the root of the primitive polynomial p(x). In order to find the power | ||
115 | of @ (alpha) that has the polynomial representation | ||
116 | a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1) | ||
117 | we consider the integer "i" whose binary representation with a(0) being LSB | ||
118 | and a(m-1) MSB is (a(0),a(1),...,a(m-1)) and locate the entry | ||
119 | "index_of[i]". Now, @^index_of[i] is that element whose polynomial | ||
120 | representation is (a(0),a(1),a(2),...,a(m-1)). | ||
121 | NOTE: | ||
122 | The element alpha_to[2^m-1] = 0 always signifying that the | ||
123 | representation of "@^infinity" = 0 is (0,0,0,...,0). | ||
124 | Similarly, the element index_of[0] = A0 always signifying | ||
125 | that the power of alpha which has the polynomial representation | ||
126 | (0,0,...,0) is "infinity". | ||
127 | |||
128 | */ | ||
129 | |||
130 | static void | ||
131 | generate_gf(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1]) | ||
132 | { | ||
133 | register int i, mask; | ||
134 | |||
135 | mask = 1; | ||
136 | Alpha_to[MM] = 0; | ||
137 | for (i = 0; i < MM; i++) { | ||
138 | Alpha_to[i] = mask; | ||
139 | Index_of[Alpha_to[i]] = i; | ||
140 | /* If Pp[i] == 1 then, term @^i occurs in poly-repr of @^MM */ | ||
141 | if (Pp[i] != 0) | ||
142 | Alpha_to[MM] ^= mask; /* Bit-wise EXOR operation */ | ||
143 | mask <<= 1; /* single left-shift */ | ||
144 | } | ||
145 | Index_of[Alpha_to[MM]] = MM; | ||
146 | /* | ||
147 | * Have obtained poly-repr of @^MM. Poly-repr of @^(i+1) is given by | ||
148 | * poly-repr of @^i shifted left one-bit and accounting for any @^MM | ||
149 | * term that may occur when poly-repr of @^i is shifted. | ||
150 | */ | ||
151 | mask >>= 1; | ||
152 | for (i = MM + 1; i < NN; i++) { | ||
153 | if (Alpha_to[i - 1] >= mask) | ||
154 | Alpha_to[i] = Alpha_to[MM] ^ ((Alpha_to[i - 1] ^ mask) << 1); | ||
155 | else | ||
156 | Alpha_to[i] = Alpha_to[i - 1] << 1; | ||
157 | Index_of[Alpha_to[i]] = i; | ||
158 | } | ||
159 | Index_of[0] = A0; | ||
160 | Alpha_to[NN] = 0; | ||
161 | } | ||
162 | |||
163 | /* | ||
164 | * Performs ERRORS+ERASURES decoding of RS codes. bb[] is the content | ||
165 | * of the feedback shift register after having processed the data and | ||
166 | * the ECC. | ||
167 | * | ||
168 | * Return number of symbols corrected, or -1 if codeword is illegal | ||
169 | * or uncorrectable. If eras_pos is non-null, the detected error locations | ||
170 | * are written back. NOTE! This array must be at least NN-KK elements long. | ||
171 | * The corrected data are written in eras_val[]. They must be xor with the data | ||
172 | * to retrieve the correct data : data[erase_pos[i]] ^= erase_val[i] . | ||
173 | * | ||
174 | * First "no_eras" erasures are declared by the calling program. Then, the | ||
175 | * maximum # of errors correctable is t_after_eras = floor((NN-KK-no_eras)/2). | ||
176 | * If the number of channel errors is not greater than "t_after_eras" the | ||
177 | * transmitted codeword will be recovered. Details of algorithm can be found | ||
178 | * in R. Blahut's "Theory ... of Error-Correcting Codes". | ||
179 | |||
180 | * Warning: the eras_pos[] array must not contain duplicate entries; decoder failure | ||
181 | * will result. The decoder *could* check for this condition, but it would involve | ||
182 | * extra time on every decoding operation. | ||
183 | * */ | ||
184 | static int | ||
185 | eras_dec_rs(dtype Alpha_to[NN + 1], dtype Index_of[NN + 1], | ||
186 | gf bb[NN - KK + 1], gf eras_val[NN-KK], int eras_pos[NN-KK], | ||
187 | int no_eras) | ||
188 | { | ||
189 | int deg_lambda, el, deg_omega; | ||
190 | int i, j, r,k; | ||
191 | gf u,q,tmp,num1,num2,den,discr_r; | ||
192 | gf lambda[NN-KK + 1], s[NN-KK + 1]; /* Err+Eras Locator poly | ||
193 | * and syndrome poly */ | ||
194 | gf b[NN-KK + 1], t[NN-KK + 1], omega[NN-KK + 1]; | ||
195 | gf root[NN-KK], reg[NN-KK + 1], loc[NN-KK]; | ||
196 | int syn_error, count; | ||
197 | |||
198 | syn_error = 0; | ||
199 | for(i=0;i<NN-KK;i++) | ||
200 | syn_error |= bb[i]; | ||
201 | |||
202 | if (!syn_error) { | ||
203 | /* if remainder is zero, data[] is a codeword and there are no | ||
204 | * errors to correct. So return data[] unmodified | ||
205 | */ | ||
206 | count = 0; | ||
207 | goto finish; | ||
208 | } | ||
209 | |||
210 | for(i=1;i<=NN-KK;i++){ | ||
211 | s[i] = bb[0]; | ||
212 | } | ||
213 | for(j=1;j<NN-KK;j++){ | ||
214 | if(bb[j] == 0) | ||
215 | continue; | ||
216 | tmp = Index_of[bb[j]]; | ||
217 | |||
218 | for(i=1;i<=NN-KK;i++) | ||
219 | s[i] ^= Alpha_to[modnn(tmp + (B0+i-1)*PRIM*j)]; | ||
220 | } | ||
221 | |||
222 | /* undo the feedback register implicit multiplication and convert | ||
223 | syndromes to index form */ | ||
224 | |||
225 | for(i=1;i<=NN-KK;i++) { | ||
226 | tmp = Index_of[s[i]]; | ||
227 | if (tmp != A0) | ||
228 | tmp = modnn(tmp + 2 * KK * (B0+i-1)*PRIM); | ||
229 | s[i] = tmp; | ||
230 | } | ||
231 | |||
232 | CLEAR(&lambda[1],NN-KK); | ||
233 | lambda[0] = 1; | ||
234 | |||
235 | if (no_eras > 0) { | ||
236 | /* Init lambda to be the erasure locator polynomial */ | ||
237 | lambda[1] = Alpha_to[modnn(PRIM * eras_pos[0])]; | ||
238 | for (i = 1; i < no_eras; i++) { | ||
239 | u = modnn(PRIM*eras_pos[i]); | ||
240 | for (j = i+1; j > 0; j--) { | ||
241 | tmp = Index_of[lambda[j - 1]]; | ||
242 | if(tmp != A0) | ||
243 | lambda[j] ^= Alpha_to[modnn(u + tmp)]; | ||
244 | } | ||
245 | } | ||
246 | #if DEBUG_ECC >= 1 | ||
247 | /* Test code that verifies the erasure locator polynomial just constructed | ||
248 | Needed only for decoder debugging. */ | ||
249 | |||
250 | /* find roots of the erasure location polynomial */ | ||
251 | for(i=1;i<=no_eras;i++) | ||
252 | reg[i] = Index_of[lambda[i]]; | ||
253 | count = 0; | ||
254 | for (i = 1,k=NN-Ldec; i <= NN; i++,k = modnn(NN+k-Ldec)) { | ||
255 | q = 1; | ||
256 | for (j = 1; j <= no_eras; j++) | ||
257 | if (reg[j] != A0) { | ||
258 | reg[j] = modnn(reg[j] + j); | ||
259 | q ^= Alpha_to[reg[j]]; | ||
260 | } | ||
261 | if (q != 0) | ||
262 | continue; | ||
263 | /* store root and error location number indices */ | ||
264 | root[count] = i; | ||
265 | loc[count] = k; | ||
266 | count++; | ||
267 | } | ||
268 | if (count != no_eras) { | ||
269 | printf("\n lambda(x) is WRONG\n"); | ||
270 | count = -1; | ||
271 | goto finish; | ||
272 | } | ||
273 | #if DEBUG_ECC >= 2 | ||
274 | printf("\n Erasure positions as determined by roots of Eras Loc Poly:\n"); | ||
275 | for (i = 0; i < count; i++) | ||
276 | printf("%d ", loc[i]); | ||
277 | printf("\n"); | ||
278 | #endif | ||
279 | #endif | ||
280 | } | ||
281 | for(i=0;i<NN-KK+1;i++) | ||
282 | b[i] = Index_of[lambda[i]]; | ||
283 | |||
284 | /* | ||
285 | * Begin Berlekamp-Massey algorithm to determine error+erasure | ||
286 | * locator polynomial | ||
287 | */ | ||
288 | r = no_eras; | ||
289 | el = no_eras; | ||
290 | while (++r <= NN-KK) { /* r is the step number */ | ||
291 | /* Compute discrepancy at the r-th step in poly-form */ | ||
292 | discr_r = 0; | ||
293 | for (i = 0; i < r; i++){ | ||
294 | if ((lambda[i] != 0) && (s[r - i] != A0)) { | ||
295 | discr_r ^= Alpha_to[modnn(Index_of[lambda[i]] + s[r - i])]; | ||
296 | } | ||
297 | } | ||
298 | discr_r = Index_of[discr_r]; /* Index form */ | ||
299 | if (discr_r == A0) { | ||
300 | /* 2 lines below: B(x) <-- x*B(x) */ | ||
301 | COPYDOWN(&b[1],b,NN-KK); | ||
302 | b[0] = A0; | ||
303 | } else { | ||
304 | /* 7 lines below: T(x) <-- lambda(x) - discr_r*x*b(x) */ | ||
305 | t[0] = lambda[0]; | ||
306 | for (i = 0 ; i < NN-KK; i++) { | ||
307 | if(b[i] != A0) | ||
308 | t[i+1] = lambda[i+1] ^ Alpha_to[modnn(discr_r + b[i])]; | ||
309 | else | ||
310 | t[i+1] = lambda[i+1]; | ||
311 | } | ||
312 | if (2 * el <= r + no_eras - 1) { | ||
313 | el = r + no_eras - el; | ||
314 | /* | ||
315 | * 2 lines below: B(x) <-- inv(discr_r) * | ||
316 | * lambda(x) | ||
317 | */ | ||
318 | for (i = 0; i <= NN-KK; i++) | ||
319 | b[i] = (lambda[i] == 0) ? A0 : modnn(Index_of[lambda[i]] - discr_r + NN); | ||
320 | } else { | ||
321 | /* 2 lines below: B(x) <-- x*B(x) */ | ||
322 | COPYDOWN(&b[1],b,NN-KK); | ||
323 | b[0] = A0; | ||
324 | } | ||
325 | COPY(lambda,t,NN-KK+1); | ||
326 | } | ||
327 | } | ||
328 | |||
329 | /* Convert lambda to index form and compute deg(lambda(x)) */ | ||
330 | deg_lambda = 0; | ||
331 | for(i=0;i<NN-KK+1;i++){ | ||
332 | lambda[i] = Index_of[lambda[i]]; | ||
333 | if(lambda[i] != A0) | ||
334 | deg_lambda = i; | ||
335 | } | ||
336 | /* | ||
337 | * Find roots of the error+erasure locator polynomial by Chien | ||
338 | * Search | ||
339 | */ | ||
340 | COPY(®[1],&lambda[1],NN-KK); | ||
341 | count = 0; /* Number of roots of lambda(x) */ | ||
342 | for (i = 1,k=NN-Ldec; i <= NN; i++,k = modnn(NN+k-Ldec)) { | ||
343 | q = 1; | ||
344 | for (j = deg_lambda; j > 0; j--){ | ||
345 | if (reg[j] != A0) { | ||
346 | reg[j] = modnn(reg[j] + j); | ||
347 | q ^= Alpha_to[reg[j]]; | ||
348 | } | ||
349 | } | ||
350 | if (q != 0) | ||
351 | continue; | ||
352 | /* store root (index-form) and error location number */ | ||
353 | root[count] = i; | ||
354 | loc[count] = k; | ||
355 | /* If we've already found max possible roots, | ||
356 | * abort the search to save time | ||
357 | */ | ||
358 | if(++count == deg_lambda) | ||
359 | break; | ||
360 | } | ||
361 | if (deg_lambda != count) { | ||
362 | /* | ||
363 | * deg(lambda) unequal to number of roots => uncorrectable | ||
364 | * error detected | ||
365 | */ | ||
366 | count = -1; | ||
367 | goto finish; | ||
368 | } | ||
369 | /* | ||
370 | * Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo | ||
371 | * x**(NN-KK)). in index form. Also find deg(omega). | ||
372 | */ | ||
373 | deg_omega = 0; | ||
374 | for (i = 0; i < NN-KK;i++){ | ||
375 | tmp = 0; | ||
376 | j = (deg_lambda < i) ? deg_lambda : i; | ||
377 | for(;j >= 0; j--){ | ||
378 | if ((s[i + 1 - j] != A0) && (lambda[j] != A0)) | ||
379 | tmp ^= Alpha_to[modnn(s[i + 1 - j] + lambda[j])]; | ||
380 | } | ||
381 | if(tmp != 0) | ||
382 | deg_omega = i; | ||
383 | omega[i] = Index_of[tmp]; | ||
384 | } | ||
385 | omega[NN-KK] = A0; | ||
386 | |||
387 | /* | ||
388 | * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 = | ||
389 | * inv(X(l))**(B0-1) and den = lambda_pr(inv(X(l))) all in poly-form | ||
390 | */ | ||
391 | for (j = count-1; j >=0; j--) { | ||
392 | num1 = 0; | ||
393 | for (i = deg_omega; i >= 0; i--) { | ||
394 | if (omega[i] != A0) | ||
395 | num1 ^= Alpha_to[modnn(omega[i] + i * root[j])]; | ||
396 | } | ||
397 | num2 = Alpha_to[modnn(root[j] * (B0 - 1) + NN)]; | ||
398 | den = 0; | ||
399 | |||
400 | /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */ | ||
401 | for (i = min(deg_lambda,NN-KK-1) & ~1; i >= 0; i -=2) { | ||
402 | if(lambda[i+1] != A0) | ||
403 | den ^= Alpha_to[modnn(lambda[i+1] + i * root[j])]; | ||
404 | } | ||
405 | if (den == 0) { | ||
406 | #if DEBUG_ECC >= 1 | ||
407 | printf("\n ERROR: denominator = 0\n"); | ||
408 | #endif | ||
409 | /* Convert to dual- basis */ | ||
410 | count = -1; | ||
411 | goto finish; | ||
412 | } | ||
413 | /* Apply error to data */ | ||
414 | if (num1 != 0) { | ||
415 | eras_val[j] = Alpha_to[modnn(Index_of[num1] + Index_of[num2] + NN - Index_of[den])]; | ||
416 | } else { | ||
417 | eras_val[j] = 0; | ||
418 | } | ||
419 | } | ||
420 | finish: | ||
421 | for(i=0;i<count;i++) | ||
422 | eras_pos[i] = loc[i]; | ||
423 | return count; | ||
424 | } | ||
425 | |||
426 | /***************************************************************************/ | ||
427 | /* The DOC specific code begins here */ | ||
428 | |||
429 | #define SECTOR_SIZE 512 | ||
430 | /* The sector bytes are packed into NB_DATA MM bits words */ | ||
431 | #define NB_DATA (((SECTOR_SIZE + 1) * 8 + 6) / MM) | ||
432 | |||
433 | /* | ||
434 | * Correct the errors in 'sector[]' by using 'ecc1[]' which is the | ||
435 | * content of the feedback shift register applyied to the sector and | ||
436 | * the ECC. Return the number of errors corrected (and correct them in | ||
437 | * sector), or -1 if error | ||
438 | */ | ||
439 | int doc_decode_ecc(unsigned char sector[SECTOR_SIZE], unsigned char ecc1[6]) | ||
440 | { | ||
441 | int parity, i, nb_errors; | ||
442 | gf bb[NN - KK + 1]; | ||
443 | gf error_val[NN-KK]; | ||
444 | int error_pos[NN-KK], pos, bitpos, index, val; | ||
445 | dtype *Alpha_to, *Index_of; | ||
446 | |||
447 | /* init log and exp tables here to save memory. However, it is slower */ | ||
448 | Alpha_to = kmalloc((NN + 1) * sizeof(dtype), GFP_KERNEL); | ||
449 | if (!Alpha_to) | ||
450 | return -1; | ||
451 | |||
452 | Index_of = kmalloc((NN + 1) * sizeof(dtype), GFP_KERNEL); | ||
453 | if (!Index_of) { | ||
454 | kfree(Alpha_to); | ||
455 | return -1; | ||
456 | } | ||
457 | |||
458 | generate_gf(Alpha_to, Index_of); | ||
459 | |||
460 | parity = ecc1[1]; | ||
461 | |||
462 | bb[0] = (ecc1[4] & 0xff) | ((ecc1[5] & 0x03) << 8); | ||
463 | bb[1] = ((ecc1[5] & 0xfc) >> 2) | ((ecc1[2] & 0x0f) << 6); | ||
464 | bb[2] = ((ecc1[2] & 0xf0) >> 4) | ((ecc1[3] & 0x3f) << 4); | ||
465 | bb[3] = ((ecc1[3] & 0xc0) >> 6) | ((ecc1[0] & 0xff) << 2); | ||
466 | |||
467 | nb_errors = eras_dec_rs(Alpha_to, Index_of, bb, | ||
468 | error_val, error_pos, 0); | ||
469 | if (nb_errors <= 0) | ||
470 | goto the_end; | ||
471 | |||
472 | /* correct the errors */ | ||
473 | for(i=0;i<nb_errors;i++) { | ||
474 | pos = error_pos[i]; | ||
475 | if (pos >= NB_DATA && pos < KK) { | ||
476 | nb_errors = -1; | ||
477 | goto the_end; | ||
478 | } | ||
479 | if (pos < NB_DATA) { | ||
480 | /* extract bit position (MSB first) */ | ||
481 | pos = 10 * (NB_DATA - 1 - pos) - 6; | ||
482 | /* now correct the following 10 bits. At most two bytes | ||
483 | can be modified since pos is even */ | ||
484 | index = (pos >> 3) ^ 1; | ||
485 | bitpos = pos & 7; | ||
486 | if ((index >= 0 && index < SECTOR_SIZE) || | ||
487 | index == (SECTOR_SIZE + 1)) { | ||
488 | val = error_val[i] >> (2 + bitpos); | ||
489 | parity ^= val; | ||
490 | if (index < SECTOR_SIZE) | ||
491 | sector[index] ^= val; | ||
492 | } | ||
493 | index = ((pos >> 3) + 1) ^ 1; | ||
494 | bitpos = (bitpos + 10) & 7; | ||
495 | if (bitpos == 0) | ||
496 | bitpos = 8; | ||
497 | if ((index >= 0 && index < SECTOR_SIZE) || | ||
498 | index == (SECTOR_SIZE + 1)) { | ||
499 | val = error_val[i] << (8 - bitpos); | ||
500 | parity ^= val; | ||
501 | if (index < SECTOR_SIZE) | ||
502 | sector[index] ^= val; | ||
503 | } | ||
504 | } | ||
505 | } | ||
506 | |||
507 | /* use parity to test extra errors */ | ||
508 | if ((parity & 0xff) != 0) | ||
509 | nb_errors = -1; | ||
510 | |||
511 | the_end: | ||
512 | kfree(Alpha_to); | ||
513 | kfree(Index_of); | ||
514 | return nb_errors; | ||
515 | } | ||
516 | |||
517 | EXPORT_SYMBOL_GPL(doc_decode_ecc); | ||
518 | |||
519 | MODULE_LICENSE("GPL"); | ||
520 | MODULE_AUTHOR("Fabrice Bellard <fabrice.bellard@netgem.com>"); | ||
521 | MODULE_DESCRIPTION("ECC code for correcting errors detected by DiskOnChip 2000 and Millennium ECC hardware"); | ||
diff --git a/drivers/mtd/devices/docprobe.c b/drivers/mtd/devices/docprobe.c deleted file mode 100644 index 88b3fd3e18a7..000000000000 --- a/drivers/mtd/devices/docprobe.c +++ /dev/null | |||
@@ -1,325 +0,0 @@ | |||
1 | |||
2 | /* Linux driver for Disk-On-Chip devices */ | ||
3 | /* Probe routines common to all DoC devices */ | ||
4 | /* (C) 1999 Machine Vision Holdings, Inc. */ | ||
5 | /* (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> */ | ||
6 | |||
7 | |||
8 | /* DOC_PASSIVE_PROBE: | ||
9 | In order to ensure that the BIOS checksum is correct at boot time, and | ||
10 | hence that the onboard BIOS extension gets executed, the DiskOnChip | ||
11 | goes into reset mode when it is read sequentially: all registers | ||
12 | return 0xff until the chip is woken up again by writing to the | ||
13 | DOCControl register. | ||
14 | |||
15 | Unfortunately, this means that the probe for the DiskOnChip is unsafe, | ||
16 | because one of the first things it does is write to where it thinks | ||
17 | the DOCControl register should be - which may well be shared memory | ||
18 | for another device. I've had machines which lock up when this is | ||
19 | attempted. Hence the possibility to do a passive probe, which will fail | ||
20 | to detect a chip in reset mode, but is at least guaranteed not to lock | ||
21 | the machine. | ||
22 | |||
23 | If you have this problem, uncomment the following line: | ||
24 | #define DOC_PASSIVE_PROBE | ||
25 | */ | ||
26 | |||
27 | |||
28 | /* DOC_SINGLE_DRIVER: | ||
29 | Millennium driver has been merged into DOC2000 driver. | ||
30 | |||
31 | The old Millennium-only driver has been retained just in case there | ||
32 | are problems with the new code. If the combined driver doesn't work | ||
33 | for you, you can try the old one by undefining DOC_SINGLE_DRIVER | ||
34 | below and also enabling it in your configuration. If this fixes the | ||
35 | problems, please send a report to the MTD mailing list at | ||
36 | <linux-mtd@lists.infradead.org>. | ||
37 | */ | ||
38 | #define DOC_SINGLE_DRIVER | ||
39 | |||
40 | #include <linux/kernel.h> | ||
41 | #include <linux/module.h> | ||
42 | #include <asm/errno.h> | ||
43 | #include <asm/io.h> | ||
44 | #include <linux/delay.h> | ||
45 | #include <linux/slab.h> | ||
46 | #include <linux/init.h> | ||
47 | #include <linux/types.h> | ||
48 | |||
49 | #include <linux/mtd/mtd.h> | ||
50 | #include <linux/mtd/nand.h> | ||
51 | #include <linux/mtd/doc2000.h> | ||
52 | |||
53 | |||
54 | static unsigned long doc_config_location = CONFIG_MTD_DOCPROBE_ADDRESS; | ||
55 | module_param(doc_config_location, ulong, 0); | ||
56 | MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip"); | ||
57 | |||
58 | static unsigned long __initdata doc_locations[] = { | ||
59 | #if defined (__alpha__) || defined(__i386__) || defined(__x86_64__) | ||
60 | #ifdef CONFIG_MTD_DOCPROBE_HIGH | ||
61 | 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000, | ||
62 | 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000, | ||
63 | 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000, | ||
64 | 0xfffe0000, 0xfffe2000, 0xfffe4000, 0xfffe6000, | ||
65 | 0xfffe8000, 0xfffea000, 0xfffec000, 0xfffee000, | ||
66 | #else /* CONFIG_MTD_DOCPROBE_HIGH */ | ||
67 | 0xc8000, 0xca000, 0xcc000, 0xce000, | ||
68 | 0xd0000, 0xd2000, 0xd4000, 0xd6000, | ||
69 | 0xd8000, 0xda000, 0xdc000, 0xde000, | ||
70 | 0xe0000, 0xe2000, 0xe4000, 0xe6000, | ||
71 | 0xe8000, 0xea000, 0xec000, 0xee000, | ||
72 | #endif /* CONFIG_MTD_DOCPROBE_HIGH */ | ||
73 | #endif | ||
74 | 0xffffffff }; | ||
75 | |||
76 | /* doccheck: Probe a given memory window to see if there's a DiskOnChip present */ | ||
77 | |||
78 | static inline int __init doccheck(void __iomem *potential, unsigned long physadr) | ||
79 | { | ||
80 | void __iomem *window=potential; | ||
81 | unsigned char tmp, tmpb, tmpc, ChipID; | ||
82 | #ifndef DOC_PASSIVE_PROBE | ||
83 | unsigned char tmp2; | ||
84 | #endif | ||
85 | |||
86 | /* Routine copied from the Linux DOC driver */ | ||
87 | |||
88 | #ifdef CONFIG_MTD_DOCPROBE_55AA | ||
89 | /* Check for 0x55 0xAA signature at beginning of window, | ||
90 | this is no longer true once we remove the IPL (for Millennium */ | ||
91 | if (ReadDOC(window, Sig1) != 0x55 || ReadDOC(window, Sig2) != 0xaa) | ||
92 | return 0; | ||
93 | #endif /* CONFIG_MTD_DOCPROBE_55AA */ | ||
94 | |||
95 | #ifndef DOC_PASSIVE_PROBE | ||
96 | /* It's not possible to cleanly detect the DiskOnChip - the | ||
97 | * bootup procedure will put the device into reset mode, and | ||
98 | * it's not possible to talk to it without actually writing | ||
99 | * to the DOCControl register. So we store the current contents | ||
100 | * of the DOCControl register's location, in case we later decide | ||
101 | * that it's not a DiskOnChip, and want to put it back how we | ||
102 | * found it. | ||
103 | */ | ||
104 | tmp2 = ReadDOC(window, DOCControl); | ||
105 | |||
106 | /* Reset the DiskOnChip ASIC */ | ||
107 | WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, | ||
108 | window, DOCControl); | ||
109 | WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_RESET, | ||
110 | window, DOCControl); | ||
111 | |||
112 | /* Enable the DiskOnChip ASIC */ | ||
113 | WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, | ||
114 | window, DOCControl); | ||
115 | WriteDOC(DOC_MODE_CLR_ERR | DOC_MODE_MDWREN | DOC_MODE_NORMAL, | ||
116 | window, DOCControl); | ||
117 | #endif /* !DOC_PASSIVE_PROBE */ | ||
118 | |||
119 | /* We need to read the ChipID register four times. For some | ||
120 | newer DiskOnChip 2000 units, the first three reads will | ||
121 | return the DiskOnChip Millennium ident. Don't ask. */ | ||
122 | ChipID = ReadDOC(window, ChipID); | ||
123 | |||
124 | switch (ChipID) { | ||
125 | case DOC_ChipID_Doc2k: | ||
126 | /* Check the TOGGLE bit in the ECC register */ | ||
127 | tmp = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT; | ||
128 | tmpb = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT; | ||
129 | tmpc = ReadDOC(window, 2k_ECCStatus) & DOC_TOGGLE_BIT; | ||
130 | if (tmp != tmpb && tmp == tmpc) | ||
131 | return ChipID; | ||
132 | break; | ||
133 | |||
134 | case DOC_ChipID_DocMil: | ||
135 | /* Check for the new 2000 with Millennium ASIC */ | ||
136 | ReadDOC(window, ChipID); | ||
137 | ReadDOC(window, ChipID); | ||
138 | if (ReadDOC(window, ChipID) != DOC_ChipID_DocMil) | ||
139 | ChipID = DOC_ChipID_Doc2kTSOP; | ||
140 | |||
141 | /* Check the TOGGLE bit in the ECC register */ | ||
142 | tmp = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT; | ||
143 | tmpb = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT; | ||
144 | tmpc = ReadDOC(window, ECCConf) & DOC_TOGGLE_BIT; | ||
145 | if (tmp != tmpb && tmp == tmpc) | ||
146 | return ChipID; | ||
147 | break; | ||
148 | |||
149 | case DOC_ChipID_DocMilPlus16: | ||
150 | case DOC_ChipID_DocMilPlus32: | ||
151 | case 0: | ||
152 | /* Possible Millennium+, need to do more checks */ | ||
153 | #ifndef DOC_PASSIVE_PROBE | ||
154 | /* Possibly release from power down mode */ | ||
155 | for (tmp = 0; (tmp < 4); tmp++) | ||
156 | ReadDOC(window, Mplus_Power); | ||
157 | |||
158 | /* Reset the DiskOnChip ASIC */ | ||
159 | tmp = DOC_MODE_RESET | DOC_MODE_MDWREN | DOC_MODE_RST_LAT | | ||
160 | DOC_MODE_BDECT; | ||
161 | WriteDOC(tmp, window, Mplus_DOCControl); | ||
162 | WriteDOC(~tmp, window, Mplus_CtrlConfirm); | ||
163 | |||
164 | mdelay(1); | ||
165 | /* Enable the DiskOnChip ASIC */ | ||
166 | tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT | | ||
167 | DOC_MODE_BDECT; | ||
168 | WriteDOC(tmp, window, Mplus_DOCControl); | ||
169 | WriteDOC(~tmp, window, Mplus_CtrlConfirm); | ||
170 | mdelay(1); | ||
171 | #endif /* !DOC_PASSIVE_PROBE */ | ||
172 | |||
173 | ChipID = ReadDOC(window, ChipID); | ||
174 | |||
175 | switch (ChipID) { | ||
176 | case DOC_ChipID_DocMilPlus16: | ||
177 | case DOC_ChipID_DocMilPlus32: | ||
178 | /* Check the TOGGLE bit in the toggle register */ | ||
179 | tmp = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT; | ||
180 | tmpb = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT; | ||
181 | tmpc = ReadDOC(window, Mplus_Toggle) & DOC_TOGGLE_BIT; | ||
182 | if (tmp != tmpb && tmp == tmpc) | ||
183 | return ChipID; | ||
184 | default: | ||
185 | break; | ||
186 | } | ||
187 | /* FALL TRHU */ | ||
188 | |||
189 | default: | ||
190 | |||
191 | #ifdef CONFIG_MTD_DOCPROBE_55AA | ||
192 | printk(KERN_DEBUG "Possible DiskOnChip with unknown ChipID %2.2X found at 0x%lx\n", | ||
193 | ChipID, physadr); | ||
194 | #endif | ||
195 | #ifndef DOC_PASSIVE_PROBE | ||
196 | /* Put back the contents of the DOCControl register, in case it's not | ||
197 | * actually a DiskOnChip. | ||
198 | */ | ||
199 | WriteDOC(tmp2, window, DOCControl); | ||
200 | #endif | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | printk(KERN_WARNING "DiskOnChip failed TOGGLE test, dropping.\n"); | ||
205 | |||
206 | #ifndef DOC_PASSIVE_PROBE | ||
207 | /* Put back the contents of the DOCControl register: it's not a DiskOnChip */ | ||
208 | WriteDOC(tmp2, window, DOCControl); | ||
209 | #endif | ||
210 | return 0; | ||
211 | } | ||
212 | |||
213 | static int docfound; | ||
214 | |||
215 | extern void DoC2k_init(struct mtd_info *); | ||
216 | extern void DoCMil_init(struct mtd_info *); | ||
217 | extern void DoCMilPlus_init(struct mtd_info *); | ||
218 | |||
219 | static void __init DoC_Probe(unsigned long physadr) | ||
220 | { | ||
221 | void __iomem *docptr; | ||
222 | struct DiskOnChip *this; | ||
223 | struct mtd_info *mtd; | ||
224 | int ChipID; | ||
225 | char namebuf[15]; | ||
226 | char *name = namebuf; | ||
227 | void (*initroutine)(struct mtd_info *) = NULL; | ||
228 | |||
229 | docptr = ioremap(physadr, DOC_IOREMAP_LEN); | ||
230 | |||
231 | if (!docptr) | ||
232 | return; | ||
233 | |||
234 | if ((ChipID = doccheck(docptr, physadr))) { | ||
235 | if (ChipID == DOC_ChipID_Doc2kTSOP) { | ||
236 | /* Remove this at your own peril. The hardware driver works but nothing prevents you from erasing bad blocks */ | ||
237 | printk(KERN_NOTICE "Refusing to drive DiskOnChip 2000 TSOP until Bad Block Table is correctly supported by INFTL\n"); | ||
238 | iounmap(docptr); | ||
239 | return; | ||
240 | } | ||
241 | docfound = 1; | ||
242 | mtd = kzalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL); | ||
243 | if (!mtd) { | ||
244 | printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n"); | ||
245 | iounmap(docptr); | ||
246 | return; | ||
247 | } | ||
248 | |||
249 | this = (struct DiskOnChip *)(&mtd[1]); | ||
250 | mtd->priv = this; | ||
251 | this->virtadr = docptr; | ||
252 | this->physadr = physadr; | ||
253 | this->ChipID = ChipID; | ||
254 | sprintf(namebuf, "with ChipID %2.2X", ChipID); | ||
255 | |||
256 | switch(ChipID) { | ||
257 | case DOC_ChipID_Doc2kTSOP: | ||
258 | name="2000 TSOP"; | ||
259 | initroutine = symbol_request(DoC2k_init); | ||
260 | break; | ||
261 | |||
262 | case DOC_ChipID_Doc2k: | ||
263 | name="2000"; | ||
264 | initroutine = symbol_request(DoC2k_init); | ||
265 | break; | ||
266 | |||
267 | case DOC_ChipID_DocMil: | ||
268 | name="Millennium"; | ||
269 | #ifdef DOC_SINGLE_DRIVER | ||
270 | initroutine = symbol_request(DoC2k_init); | ||
271 | #else | ||
272 | initroutine = symbol_request(DoCMil_init); | ||
273 | #endif /* DOC_SINGLE_DRIVER */ | ||
274 | break; | ||
275 | |||
276 | case DOC_ChipID_DocMilPlus16: | ||
277 | case DOC_ChipID_DocMilPlus32: | ||
278 | name="MillenniumPlus"; | ||
279 | initroutine = symbol_request(DoCMilPlus_init); | ||
280 | break; | ||
281 | } | ||
282 | |||
283 | if (initroutine) { | ||
284 | (*initroutine)(mtd); | ||
285 | symbol_put_addr(initroutine); | ||
286 | return; | ||
287 | } | ||
288 | printk(KERN_NOTICE "Cannot find driver for DiskOnChip %s at 0x%lX\n", name, physadr); | ||
289 | kfree(mtd); | ||
290 | } | ||
291 | iounmap(docptr); | ||
292 | } | ||
293 | |||
294 | |||
295 | /**************************************************************************** | ||
296 | * | ||
297 | * Module stuff | ||
298 | * | ||
299 | ****************************************************************************/ | ||
300 | |||
301 | static int __init init_doc(void) | ||
302 | { | ||
303 | int i; | ||
304 | |||
305 | if (doc_config_location) { | ||
306 | printk(KERN_INFO "Using configured DiskOnChip probe address 0x%lx\n", doc_config_location); | ||
307 | DoC_Probe(doc_config_location); | ||
308 | } else { | ||
309 | for (i=0; (doc_locations[i] != 0xffffffff); i++) { | ||
310 | DoC_Probe(doc_locations[i]); | ||
311 | } | ||
312 | } | ||
313 | /* No banner message any more. Print a message if no DiskOnChip | ||
314 | found, so the user knows we at least tried. */ | ||
315 | if (!docfound) | ||
316 | printk(KERN_INFO "No recognised DiskOnChip devices found\n"); | ||
317 | return -EAGAIN; | ||
318 | } | ||
319 | |||
320 | module_init(init_doc); | ||
321 | |||
322 | MODULE_LICENSE("GPL"); | ||
323 | MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); | ||
324 | MODULE_DESCRIPTION("Probe code for DiskOnChip 2000 and Millennium devices"); | ||
325 | |||