blob: e87489505772621e275650232c81b8a0af0a674e [file] [log] [blame]
Kyungmin Parkcd5f6342005-07-11 11:41:53 +01001/*
2 * linux/drivers/mtd/onenand/onenand_base.c
3 *
4 * Copyright (C) 2005 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/kernel.h>
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/mtd/mtd.h>
16#include <linux/mtd/onenand.h>
17#include <linux/mtd/partitions.h>
18
19#include <asm/io.h>
20
21/**
22 * onenand_oob_64 - oob info for large (2KB) page
23 */
24static struct nand_oobinfo onenand_oob_64 = {
25 .useecc = MTD_NANDECC_AUTOPLACE,
26 .eccbytes = 20,
27 .eccpos = {
28 8, 9, 10, 11, 12,
29 24, 25, 26, 27, 28,
30 40, 41, 42, 43, 44,
31 56, 57, 58, 59, 60,
32 },
33 .oobfree = {
34 {2, 3}, {14, 2}, {18, 3}, {30, 2},
35 {24, 3}, {46, 2}, {40, 3}, {62, 2} }
36};
37
38/**
39 * onenand_oob_32 - oob info for middle (1KB) page
40 */
41static struct nand_oobinfo onenand_oob_32 = {
42 .useecc = MTD_NANDECC_AUTOPLACE,
43 .eccbytes = 10,
44 .eccpos = {
45 8, 9, 10, 11, 12,
46 24, 25, 26, 27, 28,
47 },
48 .oobfree = { {2, 3}, {14, 2}, {18, 3}, {30, 2} }
49};
50
51static const unsigned char ffchars[] = {
52 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
53 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 16 */
54 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
55 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 32 */
56 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
57 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 48 */
58 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
59 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* 64 */
60};
61
62/**
63 * onenand_readw - [OneNAND Interface] Read OneNAND register
64 * @param addr address to read
65 *
66 * Read OneNAND register
67 */
68static unsigned short onenand_readw(void __iomem *addr)
69{
70 return readw(addr);
71}
72
73/**
74 * onenand_writew - [OneNAND Interface] Write OneNAND register with value
75 * @param value value to write
76 * @param addr address to write
77 *
78 * Write OneNAND register with value
79 */
80static void onenand_writew(unsigned short value, void __iomem *addr)
81{
82 writew(value, addr);
83}
84
85/**
86 * onenand_block_address - [DEFAULT] Get block address
87 * @param device the device id
88 * @param block the block
89 * @return translated block address if DDP, otherwise same
90 *
91 * Setup Start Address 1 Register (F100h)
92 */
93static int onenand_block_address(int device, int block)
94{
95 if (device & ONENAND_DEVICE_IS_DDP) {
96 /* Device Flash Core select, NAND Flash Block Address */
97 int dfs = 0, density, mask;
98
99 density = device >> ONENAND_DEVICE_DENSITY_SHIFT;
100 mask = (1 << (density + 6));
101
102 if (block & mask)
103 dfs = 1;
104
105 return (dfs << ONENAND_DDP_SHIFT) | (block & (mask - 1));
106 }
107
108 return block;
109}
110
111/**
112 * onenand_bufferram_address - [DEFAULT] Get bufferram address
113 * @param device the device id
114 * @param block the block
115 * @return set DBS value if DDP, otherwise 0
116 *
117 * Setup Start Address 2 Register (F101h) for DDP
118 */
119static int onenand_bufferram_address(int device, int block)
120{
121 if (device & ONENAND_DEVICE_IS_DDP) {
122 /* Device BufferRAM Select */
123 int dbs = 0, density, mask;
124
125 density = device >> ONENAND_DEVICE_DENSITY_SHIFT;
126 mask = (1 << (density + 6));
127
128 if (block & mask)
129 dbs = 1;
130
131 return (dbs << ONENAND_DDP_SHIFT);
132 }
133
134 return 0;
135}
136
137/**
138 * onenand_page_address - [DEFAULT] Get page address
139 * @param page the page address
140 * @param sector the sector address
141 * @return combined page and sector address
142 *
143 * Setup Start Address 8 Register (F107h)
144 */
145static int onenand_page_address(int page, int sector)
146{
147 /* Flash Page Address, Flash Sector Address */
148 int fpa, fsa;
149
150 fpa = page & ONENAND_FPA_MASK;
151 fsa = sector & ONENAND_FSA_MASK;
152
153 return ((fpa << ONENAND_FPA_SHIFT) | fsa);
154}
155
156/**
157 * onenand_buffer_address - [DEFAULT] Get buffer address
158 * @param dataram1 DataRAM index
159 * @param sectors the sector address
160 * @param count the number of sectors
161 * @return the start buffer value
162 *
163 * Setup Start Buffer Register (F200h)
164 */
165static int onenand_buffer_address(int dataram1, int sectors, int count)
166{
167 int bsa, bsc;
168
169 /* BufferRAM Sector Address */
170 bsa = sectors & ONENAND_BSA_MASK;
171
172 if (dataram1)
173 bsa |= ONENAND_BSA_DATARAM1; /* DataRAM1 */
174 else
175 bsa |= ONENAND_BSA_DATARAM0; /* DataRAM0 */
176
177 /* BufferRAM Sector Count */
178 bsc = count & ONENAND_BSC_MASK;
179
180 return ((bsa << ONENAND_BSA_SHIFT) | bsc);
181}
182
183/**
184 * onenand_command - [DEFAULT] Send command to OneNAND device
185 * @param mtd MTD device structure
186 * @param cmd the command to be sent
187 * @param addr offset to read from or write to
188 * @param len number of bytes to read or write
189 *
190 * Send command to OneNAND device. This function is used for middle/large page
191 * devices (1KB/2KB Bytes per page)
192 */
193static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t len)
194{
195 struct onenand_chip *this = mtd->priv;
196 int value, readcmd = 0;
197 int block, page;
198 /* Now we use page size operation */
199 int sectors = 4, count = 4;
200
201 /* Address translation */
202 switch (cmd) {
203 case ONENAND_CMD_UNLOCK:
204 case ONENAND_CMD_LOCK:
205 case ONENAND_CMD_LOCK_TIGHT:
206 block = -1;
207 page = -1;
208 break;
209
210 case ONENAND_CMD_ERASE:
211 case ONENAND_CMD_BUFFERRAM:
212 block = (int) (addr >> this->erase_shift);
213 page = -1;
214 break;
215
216 default:
217 block = (int) (addr >> this->erase_shift);
218 page = (int) (addr >> this->page_shift);
219 page &= this->page_mask;
220 break;
221 }
222
223 /* NOTE: The setting order of the registers is very important! */
224 if (cmd == ONENAND_CMD_BUFFERRAM) {
225 /* Select DataRAM for DDP */
226 value = onenand_bufferram_address(this->device_id, block);
227 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2);
228
229 /* Switch to the next data buffer */
230 ONENAND_SET_NEXT_BUFFERRAM(this);
231
232 return 0;
233 }
234
235 if (block != -1) {
236 /* Write 'DFS, FBA' of Flash */
237 value = onenand_block_address(this->device_id, block);
238 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1);
239 }
240
241 if (page != -1) {
242 int dataram;
243
244 switch (cmd) {
245 case ONENAND_CMD_READ:
246 case ONENAND_CMD_READOOB:
247 dataram = ONENAND_SET_NEXT_BUFFERRAM(this);
248 readcmd = 1;
249 break;
250
251 default:
252 dataram = ONENAND_CURRENT_BUFFERRAM(this);
253 break;
254 }
255
256 /* Write 'FPA, FSA' of Flash */
257 value = onenand_page_address(page, sectors);
258 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS8);
259
260 /* Write 'BSA, BSC' of DataRAM */
261 value = onenand_buffer_address(dataram, sectors, count);
262 this->write_word(value, this->base + ONENAND_REG_START_BUFFER);
263
264 if (readcmd) {
265 /* Select DataRAM for DDP */
266 value = onenand_bufferram_address(this->device_id, block);
267 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2);
268 }
269 }
270
271 /* Interrupt clear */
272 this->write_word(ONENAND_INT_CLEAR, this->base + ONENAND_REG_INTERRUPT);
273
274 /* Write command */
275 this->write_word(cmd, this->base + ONENAND_REG_COMMAND);
276
277 return 0;
278}
279
280/**
281 * onenand_wait - [DEFAULT] wait until the command is done
282 * @param mtd MTD device structure
283 * @param state state to select the max. timeout value
284 *
285 * Wait for command done. This applies to all OneNAND command
286 * Read can take up to 30us, erase up to 2ms and program up to 350us
287 * according to general OneNAND specs
288 */
289static int onenand_wait(struct mtd_info *mtd, int state)
290{
291 struct onenand_chip * this = mtd->priv;
292 unsigned long timeout;
293 unsigned int flags = ONENAND_INT_MASTER;
294 unsigned int interrupt = 0;
295 unsigned int ctrl, ecc;
296
297 /* The 20 msec is enough */
298 timeout = jiffies + msecs_to_jiffies(20);
299 while (time_before(jiffies, timeout)) {
300 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
301
302 if (interrupt & flags)
303 break;
304
305 if (state != FL_READING)
306 cond_resched();
307 }
308 /* To get correct interrupt status in timeout case */
309 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT);
310
311 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS);
312
313 if (ctrl & ONENAND_CTRL_ERROR) {
314 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: controller error = 0x%04x", ctrl);
315 return -EIO;
316 }
317
318 if (ctrl & ONENAND_CTRL_LOCK) {
319 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: it's locked error = 0x%04x", ctrl);
320 return -EIO;
321 }
322
323 if (interrupt & ONENAND_INT_READ) {
324 ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS);
325 if (ecc & ONENAND_ECC_2BIT_ALL) {
326 DEBUG(MTD_DEBUG_LEVEL0, "onenand_wait: ECC error = 0x%04x", ecc);
327 return -EBADMSG;
328 }
329 }
330
331 return 0;
332}
333
334/**
335 * onenand_bufferram_offset - [DEFAULT] BufferRAM offset
336 * @param mtd MTD data structure
337 * @param area BufferRAM area
338 * @return offset given area
339 *
340 * Return BufferRAM offset given area
341 */
342static inline int onenand_bufferram_offset(struct mtd_info *mtd, int area)
343{
344 struct onenand_chip *this = mtd->priv;
345
346 if (ONENAND_CURRENT_BUFFERRAM(this)) {
347 if (area == ONENAND_DATARAM)
348 return mtd->oobblock;
349 if (area == ONENAND_SPARERAM)
350 return mtd->oobsize;
351 }
352
353 return 0;
354}
355
356/**
357 * onenand_read_bufferram - [OneNAND Interface] Read the bufferram area
358 * @param mtd MTD data structure
359 * @param area BufferRAM area
360 * @param buffer the databuffer to put/get data
361 * @param offset offset to read from or write to
362 * @param count number of bytes to read/write
363 *
364 * Read the BufferRAM area
365 */
366static int onenand_read_bufferram(struct mtd_info *mtd, int area,
367 unsigned char *buffer, int offset, size_t count)
368{
369 struct onenand_chip *this = mtd->priv;
370 void __iomem *bufferram;
371
372 bufferram = this->base + area;
373
374 bufferram += onenand_bufferram_offset(mtd, area);
375
376 memcpy(buffer, bufferram + offset, count);
377
378 return 0;
379}
380
381/**
Kyungmin Park52b0eea2005-09-03 07:07:19 +0100382 * onenand_sync_read_bufferram - [OneNAND Interface] Read the bufferram area with Sync. Burst mode
383 * @param mtd MTD data structure
384 * @param area BufferRAM area
385 * @param buffer the databuffer to put/get data
386 * @param offset offset to read from or write to
387 * @param count number of bytes to read/write
388 *
389 * Read the BufferRAM area with Sync. Burst Mode
390 */
391static int onenand_sync_read_bufferram(struct mtd_info *mtd, int area,
392 unsigned char *buffer, int offset, size_t count)
393{
394 struct onenand_chip *this = mtd->priv;
395 void __iomem *bufferram;
396
397 bufferram = this->base + area;
398
399 bufferram += onenand_bufferram_offset(mtd, area);
400
401 this->mmcontrol(mtd, ONENAND_SYS_CFG1_SYNC_READ);
402
403 memcpy(buffer, bufferram + offset, count);
404
405 this->mmcontrol(mtd, 0);
406
407 return 0;
408}
409
410/**
Kyungmin Parkcd5f6342005-07-11 11:41:53 +0100411 * onenand_write_bufferram - [OneNAND Interface] Write the bufferram area
412 * @param mtd MTD data structure
413 * @param area BufferRAM area
414 * @param buffer the databuffer to put/get data
415 * @param offset offset to read from or write to
416 * @param count number of bytes to read/write
417 *
418 * Write the BufferRAM area
419 */
420static int onenand_write_bufferram(struct mtd_info *mtd, int area,
421 const unsigned char *buffer, int offset, size_t count)
422{
423 struct onenand_chip *this = mtd->priv;
424 void __iomem *bufferram;
425
426 bufferram = this->base + area;
427
428 bufferram += onenand_bufferram_offset(mtd, area);
429
430 memcpy(bufferram + offset, buffer, count);
431
432 return 0;
433}
434
435/**
436 * onenand_check_bufferram - [GENERIC] Check BufferRAM information
437 * @param mtd MTD data structure
438 * @param addr address to check
439 * @return 1 if there are valid data, otherwise 0
440 *
441 * Check bufferram if there is data we required
442 */
443static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr)
444{
445 struct onenand_chip *this = mtd->priv;
446 int block, page;
447 int i;
448
449 block = (int) (addr >> this->erase_shift);
450 page = (int) (addr >> this->page_shift);
451 page &= this->page_mask;
452
453 i = ONENAND_CURRENT_BUFFERRAM(this);
454
455 /* Is there valid data? */
456 if (this->bufferram[i].block == block &&
457 this->bufferram[i].page == page &&
458 this->bufferram[i].valid)
459 return 1;
460
461 return 0;
462}
463
464/**
465 * onenand_update_bufferram - [GENERIC] Update BufferRAM information
466 * @param mtd MTD data structure
467 * @param addr address to update
468 * @param valid valid flag
469 *
470 * Update BufferRAM information
471 */
472static int onenand_update_bufferram(struct mtd_info *mtd, loff_t addr,
473 int valid)
474{
475 struct onenand_chip *this = mtd->priv;
476 int block, page;
477 int i;
478
479 block = (int) (addr >> this->erase_shift);
480 page = (int) (addr >> this->page_shift);
481 page &= this->page_mask;
482
483 /* Invalidate BufferRAM */
484 for (i = 0; i < MAX_BUFFERRAM; i++) {
485 if (this->bufferram[i].block == block &&
486 this->bufferram[i].page == page)
487 this->bufferram[i].valid = 0;
488 }
489
490 /* Update BufferRAM */
491 i = ONENAND_CURRENT_BUFFERRAM(this);
492 this->bufferram[i].block = block;
493 this->bufferram[i].page = page;
494 this->bufferram[i].valid = valid;
495
496 return 0;
497}
498
499/**
500 * onenand_get_device - [GENERIC] Get chip for selected access
501 * @param mtd MTD device structure
502 * @param new_state the state which is requested
503 *
504 * Get the device and lock it for exclusive access
505 */
506static void onenand_get_device(struct mtd_info *mtd, int new_state)
507{
508 struct onenand_chip *this = mtd->priv;
509 DECLARE_WAITQUEUE(wait, current);
510
511 /*
512 * Grab the lock and see if the device is available
513 */
514 while (1) {
515 spin_lock(&this->chip_lock);
516 if (this->state == FL_READY) {
517 this->state = new_state;
518 spin_unlock(&this->chip_lock);
519 break;
520 }
521 set_current_state(TASK_UNINTERRUPTIBLE);
522 add_wait_queue(&this->wq, &wait);
523 spin_unlock(&this->chip_lock);
524 schedule();
525 remove_wait_queue(&this->wq, &wait);
526 }
527}
528
529/**
530 * onenand_release_device - [GENERIC] release chip
531 * @param mtd MTD device structure
532 *
533 * Deselect, release chip lock and wake up anyone waiting on the device
534 */
535static void onenand_release_device(struct mtd_info *mtd)
536{
537 struct onenand_chip *this = mtd->priv;
538
539 /* Release the chip */
540 spin_lock(&this->chip_lock);
541 this->state = FL_READY;
542 wake_up(&this->wq);
543 spin_unlock(&this->chip_lock);
544}
545
546/**
547 * onenand_read_ecc - [MTD Interface] Read data with ECC
548 * @param mtd MTD device structure
549 * @param from offset to read from
550 * @param len number of bytes to read
551 * @param retlen pointer to variable to store the number of read bytes
552 * @param buf the databuffer to put data
553 * @param oob_buf filesystem supplied oob data buffer
554 * @param oobsel oob selection structure
555 *
556 * OneNAND read with ECC
557 */
558static int onenand_read_ecc(struct mtd_info *mtd, loff_t from, size_t len,
559 size_t *retlen, u_char *buf,
560 u_char *oob_buf, struct nand_oobinfo *oobsel)
561{
562 struct onenand_chip *this = mtd->priv;
563 int read = 0, column;
564 int thislen;
565 int ret = 0;
566
567 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read_ecc: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
568
569 /* Do not allow reads past end of device */
570 if ((from + len) > mtd->size) {
571 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_ecc: Attempt read beyond end of device\n");
572 *retlen = 0;
573 return -EINVAL;
574 }
575
576 /* Grab the lock and see if the device is available */
577 onenand_get_device(mtd, FL_READING);
578
579 /* TODO handling oob */
580
581 while (read < len) {
582 thislen = min_t(int, mtd->oobblock, len - read);
583
584 column = from & (mtd->oobblock - 1);
585 if (column + thislen > mtd->oobblock)
586 thislen = mtd->oobblock - column;
587
588 if (!onenand_check_bufferram(mtd, from)) {
589 this->command(mtd, ONENAND_CMD_READ, from, mtd->oobblock);
590
591 ret = this->wait(mtd, FL_READING);
592 /* First copy data and check return value for ECC handling */
593 onenand_update_bufferram(mtd, from, 1);
594 }
595
596 this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen);
597
598 read += thislen;
599
600 if (read == len)
601 break;
602
603 if (ret) {
604 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_ecc: read failed = %d\n", ret);
605 goto out;
606 }
607
608 from += thislen;
609 buf += thislen;
610 }
611
612out:
613 /* Deselect and wake up anyone waiting on the device */
614 onenand_release_device(mtd);
615
616 /*
617 * Return success, if no ECC failures, else -EBADMSG
618 * fs driver will take care of that, because
619 * retlen == desired len and result == -EBADMSG
620 */
621 *retlen = read;
622 return ret;
623}
624
625/**
626 * onenand_read - [MTD Interface] MTD compability function for onenand_read_ecc
627 * @param mtd MTD device structure
628 * @param from offset to read from
629 * @param len number of bytes to read
630 * @param retlen pointer to variable to store the number of read bytes
631 * @param buf the databuffer to put data
632 *
633 * This function simply calls onenand_read_ecc with oob buffer and oobsel = NULL
634*/
635static int onenand_read(struct mtd_info *mtd, loff_t from, size_t len,
636 size_t *retlen, u_char *buf)
637{
638 return onenand_read_ecc(mtd, from, len, retlen, buf, NULL, NULL);
639}
640
641/**
642 * onenand_read_oob - [MTD Interface] OneNAND read out-of-band
643 * @param mtd MTD device structure
644 * @param from offset to read from
645 * @param len number of bytes to read
646 * @param retlen pointer to variable to store the number of read bytes
647 * @param buf the databuffer to put data
648 *
649 * OneNAND read out-of-band data from the spare area
650 */
651static int onenand_read_oob(struct mtd_info *mtd, loff_t from, size_t len,
652 size_t *retlen, u_char *buf)
653{
654 struct onenand_chip *this = mtd->priv;
655 int read = 0, thislen, column;
656 int ret = 0;
657
658 DEBUG(MTD_DEBUG_LEVEL3, "onenand_read_oob: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len);
659
660 /* Initialize return length value */
661 *retlen = 0;
662
663 /* Do not allow reads past end of device */
664 if (unlikely((from + len) > mtd->size)) {
665 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: Attempt read beyond end of device\n");
666 return -EINVAL;
667 }
668
669 /* Grab the lock and see if the device is available */
670 onenand_get_device(mtd, FL_READING);
671
672 column = from & (mtd->oobsize - 1);
673
674 while (read < len) {
675 thislen = mtd->oobsize - column;
676 thislen = min_t(int, thislen, len);
677
678 this->command(mtd, ONENAND_CMD_READOOB, from, mtd->oobsize);
679
680 onenand_update_bufferram(mtd, from, 0);
681
682 ret = this->wait(mtd, FL_READING);
683 /* First copy data and check return value for ECC handling */
684
685 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
686
687 read += thislen;
688
689 if (read == len)
690 break;
691
692 if (ret) {
693 DEBUG(MTD_DEBUG_LEVEL0, "onenand_read_oob: read failed = %d\n", ret);
694 goto out;
695 }
696
697 buf += thislen;
698
699 /* Read more? */
700 if (read < len) {
701 /* Page size */
702 from += mtd->oobblock;
703 column = 0;
704 }
705 }
706
707out:
708 /* Deselect and wake up anyone waiting on the device */
709 onenand_release_device(mtd);
710
711 *retlen = read;
712 return ret;
713}
714
715#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
716/**
717 * onenand_verify_page - [GENERIC] verify the chip contents after a write
718 * @param mtd MTD device structure
719 * @param buf the databuffer to verify
720 * @param block block address
721 * @param page page address
722 *
723 * Check DataRAM area directly
724 */
725static int onenand_verify_page(struct mtd_info *mtd, u_char *buf,
726 loff_t addr, int block, int page)
727{
728 struct onenand_chip *this = mtd->priv;
729 void __iomem *dataram0, *dataram1;
730 int ret = 0;
731
732 this->command(mtd, ONENAND_CMD_READ, addr, mtd->oobblock);
733
734 ret = this->wait(mtd, FL_READING);
735 if (ret)
736 return ret;
737
738 onenand_update_bufferram(mtd, addr, 1);
739
740 /* Check, if the two dataram areas are same */
741 dataram0 = this->base + ONENAND_DATARAM;
742 dataram1 = dataram0 + mtd->oobblock;
743
744 if (memcmp(dataram0, dataram1, mtd->oobblock))
745 return -EBADMSG;
746
747 return 0;
748}
749#else
750#define onenand_verify_page(...) (0)
751#endif
752
753#define NOTALIGNED(x) ((x & (mtd->oobblock - 1)) != 0)
754
755/**
756 * onenand_write_ecc - [MTD Interface] OneNAND write with ECC
757 * @param mtd MTD device structure
758 * @param to offset to write to
759 * @param len number of bytes to write
760 * @param retlen pointer to variable to store the number of written bytes
761 * @param buf the data to write
762 * @param eccbuf filesystem supplied oob data buffer
763 * @param oobsel oob selection structure
764 *
765 * OneNAND write with ECC
766 */
767static int onenand_write_ecc(struct mtd_info *mtd, loff_t to, size_t len,
768 size_t *retlen, const u_char *buf,
769 u_char *eccbuf, struct nand_oobinfo *oobsel)
770{
771 struct onenand_chip *this = mtd->priv;
772 int written = 0;
773 int ret = 0;
774
775 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_ecc: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
776
777 /* Initialize retlen, in case of early exit */
778 *retlen = 0;
779
780 /* Do not allow writes past end of device */
781 if (unlikely((to + len) > mtd->size)) {
782 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_ecc: Attempt write to past end of device\n");
783 return -EINVAL;
784 }
785
786 /* Reject writes, which are not page aligned */
787 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) {
788 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_ecc: Attempt to write not page aligned data\n");
789 return -EINVAL;
790 }
791
792 /* Grab the lock and see if the device is available */
793 onenand_get_device(mtd, FL_WRITING);
794
795 /* Loop until all data write */
796 while (written < len) {
797 int thislen = min_t(int, mtd->oobblock, len - written);
798
799 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobblock);
800
801 this->write_bufferram(mtd, ONENAND_DATARAM, buf, 0, thislen);
802 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
803
804 this->command(mtd, ONENAND_CMD_PROG, to, mtd->oobblock);
805
806 onenand_update_bufferram(mtd, to, 1);
807
808 ret = this->wait(mtd, FL_WRITING);
809 if (ret) {
810 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_ecc: write filaed %d\n", ret);
811 goto out;
812 }
813
814 written += thislen;
815
816 /* Only check verify write turn on */
817 ret = onenand_verify_page(mtd, (u_char *) buf, to, block, page);
818 if (ret) {
819 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_ecc: verify failed %d\n", ret);
820 goto out;
821 }
822
823 if (written == len)
824 break;
825
826 to += thislen;
827 buf += thislen;
828 }
829
830out:
831 /* Deselect and wake up anyone waiting on the device */
832 onenand_release_device(mtd);
833
834 *retlen = written;
835
836 return ret;
837}
838
839/**
840 * onenand_write - [MTD Interface] compability function for onenand_write_ecc
841 * @param mtd MTD device structure
842 * @param to offset to write to
843 * @param len number of bytes to write
844 * @param retlen pointer to variable to store the number of written bytes
845 * @param buf the data to write
846 *
847 * This function simply calls onenand_write_ecc
848 * with oob buffer and oobsel = NULL
849 */
850static int onenand_write(struct mtd_info *mtd, loff_t to, size_t len,
851 size_t *retlen, const u_char *buf)
852{
853 return onenand_write_ecc(mtd, to, len, retlen, buf, NULL, NULL);
854}
855
856/**
857 * onenand_write_oob - [MTD Interface] OneNAND write out-of-band
858 * @param mtd MTD device structure
859 * @param to offset to write to
860 * @param len number of bytes to write
861 * @param retlen pointer to variable to store the number of written bytes
862 * @param buf the data to write
863 *
864 * OneNAND write out-of-band
865 */
866static int onenand_write_oob(struct mtd_info *mtd, loff_t to, size_t len,
867 size_t *retlen, const u_char *buf)
868{
869 struct onenand_chip *this = mtd->priv;
870 int column, status;
871 int written = 0;
872
873 DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_oob: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len);
874
875 /* Initialize retlen, in case of early exit */
876 *retlen = 0;
877
878 /* Do not allow writes past end of device */
879 if (unlikely((to + len) > mtd->size)) {
880 DEBUG(MTD_DEBUG_LEVEL0, "onenand_write_oob: Attempt write to past end of device\n");
881 return -EINVAL;
882 }
883
884 /* Grab the lock and see if the device is available */
885 onenand_get_device(mtd, FL_WRITING);
886
887 /* Loop until all data write */
888 while (written < len) {
889 int thislen = min_t(int, mtd->oobsize, len - written);
890
891 column = to & (mtd->oobsize - 1);
892
893 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize);
894
895 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
896 this->write_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen);
897
898 this->command(mtd, ONENAND_CMD_PROGOOB, to, mtd->oobsize);
899
900 onenand_update_bufferram(mtd, to, 0);
901
902 status = this->wait(mtd, FL_WRITING);
903 if (status)
904 goto out;
905
906 written += thislen;
907
908 if (written == len)
909 break;
910
911 to += thislen;
912 buf += thislen;
913 }
914
915out:
916 /* Deselect and wake up anyone waiting on the device */
917 onenand_release_device(mtd);
918
919 *retlen = written;
920
921 return 0;
922}
923
924/**
925 * onenand_writev_ecc - [MTD Interface] write with iovec with ecc
926 * @param mtd MTD device structure
927 * @param vecs the iovectors to write
928 * @param count number of vectors
929 * @param to offset to write to
930 * @param retlen pointer to variable to store the number of written bytes
931 * @param eccbuf filesystem supplied oob data buffer
932 * @param oobsel oob selection structure
933 *
934 * OneNAND write with iovec with ecc
935 */
936static int onenand_writev_ecc(struct mtd_info *mtd, const struct kvec *vecs,
937 unsigned long count, loff_t to, size_t *retlen,
938 u_char *eccbuf, struct nand_oobinfo *oobsel)
939{
940 struct onenand_chip *this = mtd->priv;
941 unsigned char buffer[mtd->oobblock], *pbuf;
942 size_t total_len, len;
943 int i, written = 0;
944 int ret = 0;
945
946 /* Preset written len for early exit */
947 *retlen = 0;
948
949 /* Calculate total length of data */
950 total_len = 0;
951 for (i = 0; i < count; i++)
952 total_len += vecs[i].iov_len;
953
954 DEBUG(MTD_DEBUG_LEVEL3, "onenand_writev_ecc: to = 0x%08x, len = %i, count = %ld\n", (unsigned int) to, (unsigned int) total_len, count);
955
956 /* Do not allow write past end of the device */
957 if (unlikely((to + total_len) > mtd->size)) {
958 DEBUG(MTD_DEBUG_LEVEL0, "onenand_writev_ecc: Attempted write past end of device\n");
959 return -EINVAL;
960 }
961
962 /* Reject writes, which are not page aligned */
963 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(total_len))) {
964 DEBUG(MTD_DEBUG_LEVEL0, "onenand_writev_ecc: Attempt to write not page aligned data\n");
965 return -EINVAL;
966 }
967
968 /* Grab the lock and see if the device is available */
969 onenand_get_device(mtd, FL_WRITING);
970
971 /* TODO handling oob */
972
973 /* Loop until all keve's data has been written */
974 len = 0;
975 while (count) {
976 pbuf = buffer;
977 /*
978 * If the given tuple is >= pagesize then
979 * write it out from the iov
980 */
981 if ((vecs->iov_len - len) >= mtd->oobblock) {
982 pbuf = vecs->iov_base + len;
983
984 len += mtd->oobblock;
985
986 /* Check, if we have to switch to the next tuple */
987 if (len >= (int) vecs->iov_len) {
988 vecs++;
989 len = 0;
990 count--;
991 }
992 } else {
993 int cnt = 0, thislen;
994 while (cnt < mtd->oobblock) {
995 thislen = min_t(int, mtd->oobblock - cnt, vecs->iov_len - len);
996 memcpy(buffer + cnt, vecs->iov_base + len, thislen);
997 cnt += thislen;
998 len += thislen;
999
1000 /* Check, if we have to switch to the next tuple */
1001 if (len >= (int) vecs->iov_len) {
1002 vecs++;
1003 len = 0;
1004 count--;
1005 }
1006 }
1007 }
1008
1009 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobblock);
1010
1011 this->write_bufferram(mtd, ONENAND_DATARAM, pbuf, 0, mtd->oobblock);
1012 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize);
1013
1014 this->command(mtd, ONENAND_CMD_PROG, to, mtd->oobblock);
1015
1016 onenand_update_bufferram(mtd, to, 1);
1017
1018 ret = this->wait(mtd, FL_WRITING);
1019 if (ret) {
1020 DEBUG(MTD_DEBUG_LEVEL0, "onenand_writev_ecc: write failed %d\n", ret);
1021 goto out;
1022 }
1023
1024
1025 /* Only check verify write turn on */
1026 ret = onenand_verify_page(mtd, (u_char *) pbuf, to, block, page);
1027 if (ret) {
1028 DEBUG(MTD_DEBUG_LEVEL0, "onenand_writev_ecc: verify failed %d\n", ret);
1029 goto out;
1030 }
1031
1032 written += mtd->oobblock;
1033
1034 to += mtd->oobblock;
1035 }
1036
1037out:
1038 /* Deselect and wakt up anyone waiting on the device */
1039 onenand_release_device(mtd);
1040
1041 *retlen = written;
1042
1043 return 0;
1044}
1045
1046/**
1047 * onenand_writev - [MTD Interface] compabilty function for onenand_writev_ecc
1048 * @param mtd MTD device structure
1049 * @param vecs the iovectors to write
1050 * @param count number of vectors
1051 * @param to offset to write to
1052 * @param retlen pointer to variable to store the number of written bytes
1053 *
1054 * OneNAND write with kvec. This just calls the ecc function
1055 */
1056static int onenand_writev(struct mtd_info *mtd, const struct kvec *vecs,
1057 unsigned long count, loff_t to, size_t *retlen)
1058{
1059 return onenand_writev_ecc(mtd, vecs, count, to, retlen, NULL, NULL);
1060}
1061
1062/**
1063 * onenand_erase - [MTD Interface] erase block(s)
1064 * @param mtd MTD device structure
1065 * @param instr erase instruction
1066 *
1067 * Erase one ore more blocks
1068 */
1069static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr)
1070{
1071 struct onenand_chip *this = mtd->priv;
1072 unsigned int block_size;
1073 loff_t addr;
1074 int len;
1075 int ret = 0;
1076
1077 DEBUG(MTD_DEBUG_LEVEL3, "onenand_erase: start = 0x%08x, len = %i\n", (unsigned int) instr->addr, (unsigned int) instr->len);
1078
1079 block_size = (1 << this->erase_shift);
1080
1081 /* Start address must align on block boundary */
1082 if (unlikely(instr->addr & (block_size - 1))) {
1083 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Unaligned address\n");
1084 return -EINVAL;
1085 }
1086
1087 /* Length must align on block boundary */
1088 if (unlikely(instr->len & (block_size - 1))) {
1089 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Length not block aligned\n");
1090 return -EINVAL;
1091 }
1092
1093 /* Do not allow erase past end of device */
1094 if (unlikely((instr->len + instr->addr) > mtd->size)) {
1095 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Erase past end of device\n");
1096 return -EINVAL;
1097 }
1098
1099 instr->fail_addr = 0xffffffff;
1100
1101 /* Grab the lock and see if the device is available */
1102 onenand_get_device(mtd, FL_ERASING);
1103
1104 /* Loop throught the pages */
1105 len = instr->len;
1106 addr = instr->addr;
1107
1108 instr->state = MTD_ERASING;
1109
1110 while (len) {
1111
1112 /* TODO Check badblock */
1113
1114 this->command(mtd, ONENAND_CMD_ERASE, addr, block_size);
1115
1116 ret = this->wait(mtd, FL_ERASING);
1117 /* Check, if it is write protected */
1118 if (ret) {
1119 if (ret == -EPERM)
1120 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Device is write protected!!!\n");
1121 else
1122 DEBUG(MTD_DEBUG_LEVEL0, "onenand_erase: Failed erase, block %d\n", (unsigned) (addr >> this->erase_shift));
1123 instr->state = MTD_ERASE_FAILED;
1124 instr->fail_addr = addr;
1125 goto erase_exit;
1126 }
1127
1128 len -= block_size;
1129 addr += block_size;
1130 }
1131
1132 instr->state = MTD_ERASE_DONE;
1133
1134erase_exit:
1135
1136 ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO;
1137 /* Do call back function */
1138 if (!ret)
1139 mtd_erase_callback(instr);
1140
1141 /* Deselect and wake up anyone waiting on the device */
1142 onenand_release_device(mtd);
1143
1144 return ret;
1145}
1146
1147/**
1148 * onenand_sync - [MTD Interface] sync
1149 * @param mtd MTD device structure
1150 *
1151 * Sync is actually a wait for chip ready function
1152 */
1153static void onenand_sync(struct mtd_info *mtd)
1154{
1155 DEBUG(MTD_DEBUG_LEVEL3, "onenand_sync: called\n");
1156
1157 /* Grab the lock and see if the device is available */
1158 onenand_get_device(mtd, FL_SYNCING);
1159
1160 /* Release it and go back */
1161 onenand_release_device(mtd);
1162}
1163
1164/**
1165 * onenand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad
1166 * @param mtd MTD device structure
1167 * @param ofs offset relative to mtd start
1168 */
1169static int onenand_block_isbad(struct mtd_info *mtd, loff_t ofs)
1170{
1171 /*
1172 * TODO
1173 * 1. Bad block table (BBT)
1174 * -> using NAND BBT to support JFFS2
1175 * 2. Bad block management (BBM)
1176 * -> bad block replace scheme
1177 *
1178 * Currently we do nothing
1179 */
1180 return 0;
1181}
1182
1183/**
1184 * onenand_block_markbad - [MTD Interface] Mark the block at the given offset as bad
1185 * @param mtd MTD device structure
1186 * @param ofs offset relative to mtd start
1187 */
1188static int onenand_block_markbad(struct mtd_info *mtd, loff_t ofs)
1189{
1190 /* see above */
1191 return 0;
1192}
1193
1194/**
1195 * onenand_unlock - [MTD Interface] Unlock block(s)
1196 * @param mtd MTD device structure
1197 * @param ofs offset relative to mtd start
1198 * @param len number of bytes to unlock
1199 *
1200 * Unlock one or more blocks
1201 */
1202static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
1203{
1204 struct onenand_chip *this = mtd->priv;
1205 int start, end, block, value, status;
1206
1207 start = ofs >> this->erase_shift;
1208 end = len >> this->erase_shift;
1209
1210 /* Continuous lock scheme */
1211 if (this->options & ONENAND_CONT_LOCK) {
1212 /* Set start block address */
1213 this->write_word(start, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1214 /* Set end block address */
1215 this->write_word(end - 1, this->base + ONENAND_REG_END_BLOCK_ADDRESS);
1216 /* Write unlock command */
1217 this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0);
1218
1219 /* There's no return value */
1220 this->wait(mtd, FL_UNLOCKING);
1221
1222 /* Sanity check */
1223 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
1224 & ONENAND_CTRL_ONGO)
1225 continue;
1226
1227 /* Check lock status */
1228 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
1229 if (!(status & ONENAND_WP_US))
1230 printk(KERN_ERR "wp status = 0x%x\n", status);
1231
1232 return 0;
1233 }
1234
1235 /* Block lock scheme */
1236 for (block = start; block < end; block++) {
1237 /* Set start block address */
1238 this->write_word(block, this->base + ONENAND_REG_START_BLOCK_ADDRESS);
1239 /* Write unlock command */
1240 this->command(mtd, ONENAND_CMD_UNLOCK, 0, 0);
1241
1242 /* There's no return value */
1243 this->wait(mtd, FL_UNLOCKING);
1244
1245 /* Sanity check */
1246 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS)
1247 & ONENAND_CTRL_ONGO)
1248 continue;
1249
1250 /* Set block address for read block status */
1251 value = onenand_block_address(this->device_id, block);
1252 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1);
1253
1254 /* Check lock status */
1255 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
1256 if (!(status & ONENAND_WP_US))
1257 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status);
1258 }
1259
1260 return 0;
1261}
1262
1263/**
1264 * onenand_print_device_info - Print device ID
1265 * @param device device ID
1266 *
1267 * Print device ID
1268 */
1269static void onenand_print_device_info(int device)
1270{
1271 int vcc, demuxed, ddp, density;
1272
1273 vcc = device & ONENAND_DEVICE_VCC_MASK;
1274 demuxed = device & ONENAND_DEVICE_IS_DEMUX;
1275 ddp = device & ONENAND_DEVICE_IS_DDP;
1276 density = device >> ONENAND_DEVICE_DENSITY_SHIFT;
1277 printk(KERN_INFO "%sOneNAND%s %dMB %sV 16-bit (0x%02x)\n",
1278 demuxed ? "" : "Muxed ",
1279 ddp ? "(DDP)" : "",
1280 (16 << density),
1281 vcc ? "2.65/3.3" : "1.8",
1282 device);
1283}
1284
1285static const struct onenand_manufacturers onenand_manuf_ids[] = {
1286 {ONENAND_MFR_SAMSUNG, "Samsung"},
1287 {ONENAND_MFR_UNKNOWN, "Unknown"}
1288};
1289
1290/**
1291 * onenand_check_maf - Check manufacturer ID
1292 * @param manuf manufacturer ID
1293 *
1294 * Check manufacturer ID
1295 */
1296static int onenand_check_maf(int manuf)
1297{
1298 int i;
1299
1300 for (i = 0; onenand_manuf_ids[i].id; i++) {
1301 if (manuf == onenand_manuf_ids[i].id)
1302 break;
1303 }
1304
Kyungmin Park52b0eea2005-09-03 07:07:19 +01001305 printk(KERN_DEBUG "OneNAND Manufacturer: %s (0x%0x)\n",
1306 onenand_manuf_ids[i].name, manuf);
Kyungmin Parkcd5f6342005-07-11 11:41:53 +01001307
1308 return (i != ONENAND_MFR_UNKNOWN);
1309}
1310
1311/**
1312 * onenand_probe - [OneNAND Interface] Probe the OneNAND device
1313 * @param mtd MTD device structure
1314 *
1315 * OneNAND detection method:
1316 * Compare the the values from command with ones from register
1317 */
1318static int onenand_probe(struct mtd_info *mtd)
1319{
1320 struct onenand_chip *this = mtd->priv;
1321 int bram_maf_id, bram_dev_id, maf_id, dev_id;
1322 int version_id;
1323 int density;
1324
1325 /* Send the command for reading device ID from BootRAM */
1326 this->write_word(ONENAND_CMD_READID, this->base + ONENAND_BOOTRAM);
1327
1328 /* Read manufacturer and device IDs from BootRAM */
1329 bram_maf_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x0);
1330 bram_dev_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x2);
1331
1332 /* Check manufacturer ID */
1333 if (onenand_check_maf(bram_maf_id))
1334 return -ENXIO;
1335
1336 /* Reset OneNAND to read default register values */
1337 this->write_word(ONENAND_CMD_RESET, this->base + ONENAND_BOOTRAM);
1338
1339 /* Read manufacturer and device IDs from Register */
1340 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID);
1341 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID);
1342
1343 /* Check OneNAND device */
1344 if (maf_id != bram_maf_id || dev_id != bram_dev_id)
1345 return -ENXIO;
1346
1347 /* Flash device information */
1348 onenand_print_device_info(dev_id);
1349 this->device_id = dev_id;
1350
1351 density = dev_id >> ONENAND_DEVICE_DENSITY_SHIFT;
1352 this->chipsize = (16 << density) << 20;
1353
1354 /* OneNAND page size & block size */
1355 /* The data buffer size is equal to page size */
1356 mtd->oobblock = this->read_word(this->base + ONENAND_REG_DATA_BUFFER_SIZE);
1357 mtd->oobsize = mtd->oobblock >> 5;
1358 /* Pagers per block is always 64 in OneNAND */
1359 mtd->erasesize = mtd->oobblock << 6;
1360
1361 this->erase_shift = ffs(mtd->erasesize) - 1;
1362 this->page_shift = ffs(mtd->oobblock) - 1;
1363 this->ppb_shift = (this->erase_shift - this->page_shift);
1364 this->page_mask = (mtd->erasesize / mtd->oobblock) - 1;
1365
1366 /* REVIST: Multichip handling */
1367
1368 mtd->size = this->chipsize;
1369
1370 /* Version ID */
1371 version_id = this->read_word(this->base + ONENAND_REG_VERSION_ID);
1372 printk(KERN_DEBUG "OneNAND version = 0x%04x\n", version_id);
1373
1374 /* Lock scheme */
1375 if (density <= ONENAND_DEVICE_DENSITY_512Mb &&
1376 !(version_id >> ONENAND_VERSION_PROCESS_SHIFT)) {
1377 printk(KERN_INFO "Lock scheme is Continues Lock\n");
1378 this->options |= ONENAND_CONT_LOCK;
1379 }
1380
1381 return 0;
1382}
1383
1384
1385/**
1386 * onenand_scan - [OneNAND Interface] Scan for the OneNAND device
1387 * @param mtd MTD device structure
1388 * @param maxchips Number of chips to scan for
1389 *
1390 * This fills out all the not initialized function pointers
1391 * with the defaults.
1392 * The flash ID is read and the mtd/chip structures are
1393 * filled with the appropriate values.
1394 */
1395int onenand_scan(struct mtd_info *mtd, int maxchips)
1396{
1397 struct onenand_chip *this = mtd->priv;
1398
1399 if (!this->read_word)
1400 this->read_word = onenand_readw;
1401 if (!this->write_word)
1402 this->write_word = onenand_writew;
1403
1404 if (!this->command)
1405 this->command = onenand_command;
1406 if (!this->wait)
1407 this->wait = onenand_wait;
1408
1409 if (!this->read_bufferram)
1410 this->read_bufferram = onenand_read_bufferram;
1411 if (!this->write_bufferram)
1412 this->write_bufferram = onenand_write_bufferram;
1413
1414 if (onenand_probe(mtd))
1415 return -ENXIO;
1416
Kyungmin Park52b0eea2005-09-03 07:07:19 +01001417 /* Set Sync. Burst Read after probing */
1418 if (this->mmcontrol) {
1419 printk(KERN_INFO "OneNAND Sync. Burst Read support\n");
1420 this->read_bufferram = onenand_sync_read_bufferram;
1421 }
1422
Kyungmin Parkcd5f6342005-07-11 11:41:53 +01001423 this->state = FL_READY;
1424 init_waitqueue_head(&this->wq);
1425 spin_lock_init(&this->chip_lock);
1426
1427 switch (mtd->oobsize) {
1428 case 64:
1429 this->autooob = &onenand_oob_64;
1430 break;
1431
1432 case 32:
1433 this->autooob = &onenand_oob_32;
1434 break;
1435
1436 default:
1437 printk(KERN_WARNING "No OOB scheme defined for oobsize %d\n",
1438 mtd->oobsize);
1439 /* To prevent kernel oops */
1440 this->autooob = &onenand_oob_32;
1441 break;
1442 }
1443
1444 memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo));
1445
1446 /* Fill in remaining MTD driver data */
1447 mtd->type = MTD_NANDFLASH;
1448 mtd->flags = MTD_CAP_NANDFLASH | MTD_ECC;
1449 mtd->ecctype = MTD_ECC_SW;
1450 mtd->erase = onenand_erase;
1451 mtd->point = NULL;
1452 mtd->unpoint = NULL;
1453 mtd->read = onenand_read;
1454 mtd->write = onenand_write;
1455 mtd->read_ecc = onenand_read_ecc;
1456 mtd->write_ecc = onenand_write_ecc;
1457 mtd->read_oob = onenand_read_oob;
1458 mtd->write_oob = onenand_write_oob;
1459 mtd->readv = NULL;
1460 mtd->readv_ecc = NULL;
1461 mtd->writev = onenand_writev;
1462 mtd->writev_ecc = onenand_writev_ecc;
1463 mtd->sync = onenand_sync;
1464 mtd->lock = NULL;
1465 mtd->unlock = onenand_unlock;
1466 mtd->suspend = NULL;
1467 mtd->resume = NULL;
1468 mtd->block_isbad = onenand_block_isbad;
1469 mtd->block_markbad = onenand_block_markbad;
1470 mtd->owner = THIS_MODULE;
1471
1472 /* Unlock whole block */
1473 mtd->unlock(mtd, 0x0, this->chipsize);
1474
1475 return 0;
1476}
1477
1478/**
1479 * onenand_release - [OneNAND Interface] Free resources held by the OneNAND device
1480 * @param mtd MTD device structure
1481 */
1482void onenand_release(struct mtd_info *mtd)
1483{
1484#ifdef CONFIG_MTD_PARTITIONS
1485 /* Deregister partitions */
1486 del_mtd_partitions (mtd);
1487#endif
1488 /* Deregister the device */
1489 del_mtd_device (mtd);
1490}
1491
1492EXPORT_SYMBOL_GPL(onenand_scan);
1493EXPORT_SYMBOL_GPL(onenand_release);
1494
1495MODULE_LICENSE("GPL");
1496MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
1497MODULE_DESCRIPTION("Generic OneNAND flash driver code");