Lines Matching +full:wait +full:- +full:on +full:- +full:read
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright © 2005-2009 Samsung Electronics
9 * Adrian Hunter <ext-adrian.hunter@nokia.com>:
10 * auto-placement support, read-while load support, various fixes
13 * Flex-OneNAND support
39 /* Default Flex-OneNAND boundary and lock respectively */
40 static int flex_bdry[MAX_DIES * 2] = { -1, 0, -1, 0 };
43 MODULE_PARM_DESC(flex_bdry, "SLC Boundary information for Flex-OneNAND"
47 " : 0->Set boundary in unlocked status"
48 " : 1->Set boundary in locked status");
50 /* Default OneNAND/Flex-OneNAND OTP options*/
57 " : 0 -> Default (No Blocks Locked)"
58 " : 1 -> OTP Block lock"
59 " : 2 -> 1st Block lock"
60 " : 3 -> BOTH OTP Block and 1st Block lock");
63 * flexonenand_oob_128 - oob info for Flex-Onenand with 4KB page
70 return -ERANGE; in flexonenand_ooblayout_ecc()
72 oobregion->offset = (section * 16) + 6; in flexonenand_ooblayout_ecc()
73 oobregion->length = 10; in flexonenand_ooblayout_ecc()
82 return -ERANGE; in flexonenand_ooblayout_free()
84 oobregion->offset = (section * 16) + 2; in flexonenand_ooblayout_free()
85 oobregion->length = 4; in flexonenand_ooblayout_free()
96 * onenand_oob_128 - oob info for OneNAND with 4KB page
98 * Based on specification:
99 * 4Gb M-die OneNAND Flash (KFM4G16Q4M, KFN8G16Q4M). Rev. 1.3, Apr. 2010
106 return -ERANGE; in onenand_ooblayout_128_ecc()
108 oobregion->offset = (section * 16) + 7; in onenand_ooblayout_128_ecc()
109 oobregion->length = 9; in onenand_ooblayout_128_ecc()
118 return -ERANGE; in onenand_ooblayout_128_free()
124 oobregion->offset = (section * 16) + 2; in onenand_ooblayout_128_free()
125 oobregion->length = 3; in onenand_ooblayout_128_free()
136 * onenand_oob_32_64 - oob info for large (2KB) page
142 return -ERANGE; in onenand_ooblayout_32_64_ecc()
144 oobregion->offset = (section * 16) + 8; in onenand_ooblayout_32_64_ecc()
145 oobregion->length = 5; in onenand_ooblayout_32_64_ecc()
153 int sections = (mtd->oobsize / 32) * 2; in onenand_ooblayout_32_64_free()
156 return -ERANGE; in onenand_ooblayout_32_64_free()
159 oobregion->offset = ((section - 1) * 16) + 14; in onenand_ooblayout_32_64_free()
160 oobregion->length = 2; in onenand_ooblayout_32_64_free()
162 oobregion->offset = (section * 16) + 2; in onenand_ooblayout_32_64_free()
163 oobregion->length = 3; in onenand_ooblayout_32_64_free()
194 * onenand_readw - [OneNAND Interface] Read OneNAND register
195 * @addr: address to read
197 * Read OneNAND register
205 * onenand_writew - [OneNAND Interface] Write OneNAND register with value
217 * onenand_block_address - [DEFAULT] Get block address
227 if (block & this->density_mask) in onenand_block_address()
228 return ONENAND_DDP_CHIP1 | (block ^ this->density_mask); in onenand_block_address()
234 * onenand_bufferram_address - [DEFAULT] Get bufferram address
244 if (block & this->density_mask) in onenand_bufferram_address()
251 * onenand_page_address - [DEFAULT] Get page address
270 * onenand_buffer_address - [DEFAULT] Get buffer address
297 * flexonenand_block- For given address return block number
298 * @this: - OneNAND device structure
299 * @addr: - Address for which block number is needed
305 if (ONENAND_IS_DDP(this) && addr >= this->diesize[0]) { in flexonenand_block()
307 addr -= this->diesize[0]; in flexonenand_block()
310 boundary = this->boundary[die]; in flexonenand_block()
312 blk = addr >> (this->erase_shift - 1); in flexonenand_block()
316 blk += die ? this->density_mask : 0; in flexonenand_block()
323 return addr >> this->erase_shift; in onenand_block()
328 * flexonenand_addr - Return address of the block
330 * @block: Block number on Flex-OneNAND
339 if (ONENAND_IS_DDP(this) && block >= this->density_mask) { in flexonenand_addr()
340 block -= this->density_mask; in flexonenand_addr()
342 ofs = this->diesize[0]; in flexonenand_addr()
345 boundary = this->boundary[die]; in flexonenand_addr()
346 ofs += (loff_t)block << (this->erase_shift - 1); in flexonenand_addr()
348 ofs += (loff_t)(block - boundary - 1) << (this->erase_shift - 1); in flexonenand_addr()
355 return (loff_t)block << this->erase_shift; in onenand_addr()
361 * onenand_get_density - [DEFAULT] Get OneNAND density
373 * flexonenand_region - [Flex-OneNAND] Return erase region of addr
381 for (i = 0; i < mtd->numeraseregions; i++) in flexonenand_region()
382 if (addr < mtd->eraseregions[i].offset) in flexonenand_region()
384 return i - 1; in flexonenand_region()
389 * onenand_command - [DEFAULT] Send command to OneNAND device
392 * @addr: offset to read from or write to
393 * @len: number of bytes to read or write
400 struct onenand_chip *this = mtd->priv; in onenand_command()
409 block = -1; in onenand_command()
410 page = -1; in onenand_command()
415 block = addr * this->density_mask; in onenand_command()
416 page = -1; in onenand_command()
425 page = -1; in onenand_command()
430 block = addr * this->density_mask; in onenand_command()
437 page = (int) (addr - onenand_addr(this, block))>>\ in onenand_command()
438 this->page_shift; in onenand_command()
440 page = (int) (addr >> this->page_shift); in onenand_command()
445 if (addr & this->writesize) in onenand_command()
449 page &= this->page_mask; in onenand_command()
457 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2); in onenand_command()
469 if (block != -1) { in onenand_command()
472 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1); in onenand_command()
476 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2); in onenand_command()
479 if (page != -1) { in onenand_command()
504 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS8); in onenand_command()
508 this->write_word(value, this->base + ONENAND_REG_START_BUFFER); in onenand_command()
512 this->write_word(ONENAND_INT_CLEAR, this->base + ONENAND_REG_INTERRUPT); in onenand_command()
515 this->write_word(cmd, this->base + ONENAND_REG_COMMAND); in onenand_command()
521 * onenand_read_ecc - return ecc status
529 return this->read_word(this->base + ONENAND_REG_ECC_STATUS); in onenand_read_ecc()
532 ecc = this->read_word(this->base + ONENAND_REG_ECC_STATUS + i*2); in onenand_read_ecc()
545 * onenand_wait - [DEFAULT] wait until the command is done
549 * Wait for command done. This applies to all OneNAND command
550 * Read can take up to 30us, erase up to 2ms and program up to 350us
555 struct onenand_chip * this = mtd->priv; in onenand_wait()
564 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT); in onenand_wait()
573 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT); in onenand_wait()
575 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS); in onenand_wait()
580 * power off recovery (POR) test, it should read ECC status first in onenand_wait()
588 mtd->ecc_stats.failed++; in onenand_wait()
589 return -EBADMSG; in onenand_wait()
593 mtd->ecc_stats.corrected++; in onenand_wait()
597 printk(KERN_ERR "%s: read timeout! ctrl=0x%04x intr=0x%04x\n", in onenand_wait()
599 return -EIO; in onenand_wait()
605 return -EIO; in onenand_wait()
611 return -EIO; in onenand_wait()
620 return -EIO; in onenand_wait()
627 * onenand_interrupt - [DEFAULT] onenand interrupt handler
638 if (!this->complete.done) in onenand_interrupt()
639 complete(&this->complete); in onenand_interrupt()
645 * onenand_interrupt_wait - [DEFAULT] wait until the command is done
649 * Wait for command done.
653 struct onenand_chip *this = mtd->priv; in onenand_interrupt_wait()
655 wait_for_completion(&this->complete); in onenand_interrupt_wait()
661 * onenand_try_interrupt_wait - [DEFAULT] try interrupt wait
665 * Try interrupt based wait (It is used one-time)
669 struct onenand_chip *this = mtd->priv; in onenand_try_interrupt_wait()
672 /* We use interrupt wait first */ in onenand_try_interrupt_wait()
673 this->wait = onenand_interrupt_wait; in onenand_try_interrupt_wait()
676 remain = wait_for_completion_timeout(&this->complete, timeout); in onenand_try_interrupt_wait()
679 "We use the normal wait\n"); in onenand_try_interrupt_wait()
682 free_irq(this->irq, this); in onenand_try_interrupt_wait()
684 this->wait = onenand_wait; in onenand_try_interrupt_wait()
691 * onenand_setup_wait - [OneNAND Interface] setup onenand wait method
694 * There's two method to wait onenand work
695 * 1. polling - read interrupt status register
696 * 2. interrupt - use the kernel interrupt method
700 struct onenand_chip *this = mtd->priv; in onenand_setup_wait()
703 init_completion(&this->complete); in onenand_setup_wait()
705 if (this->irq <= 0) { in onenand_setup_wait()
706 this->wait = onenand_wait; in onenand_setup_wait()
710 if (request_irq(this->irq, &onenand_interrupt, in onenand_setup_wait()
712 /* If we can't get irq, use the normal wait */ in onenand_setup_wait()
713 this->wait = onenand_wait; in onenand_setup_wait()
718 syscfg = this->read_word(this->base + ONENAND_REG_SYS_CFG1); in onenand_setup_wait()
720 this->write_word(syscfg, this->base + ONENAND_REG_SYS_CFG1); in onenand_setup_wait()
722 this->wait = onenand_try_interrupt_wait; in onenand_setup_wait()
726 * onenand_bufferram_offset - [DEFAULT] BufferRAM offset
735 struct onenand_chip *this = mtd->priv; in onenand_bufferram_offset()
738 /* Note: the 'this->writesize' is a real page size */ in onenand_bufferram_offset()
740 return this->writesize; in onenand_bufferram_offset()
742 return mtd->oobsize; in onenand_bufferram_offset()
749 * onenand_read_bufferram - [OneNAND Interface] Read the bufferram area
753 * @offset: offset to read from or write to
754 * @count: number of bytes to read/write
756 * Read the BufferRAM area
761 struct onenand_chip *this = mtd->priv; in onenand_read_bufferram()
764 bufferram = this->base + area; in onenand_read_bufferram()
771 /* Align with word(16-bit) size */ in onenand_read_bufferram()
772 count--; in onenand_read_bufferram()
774 /* Read word and save byte */ in onenand_read_bufferram()
775 word = this->read_word(bufferram + offset + count); in onenand_read_bufferram()
785 * onenand_sync_read_bufferram - [OneNAND Interface] Read the bufferram area with Sync. Burst mode
789 * @offset: offset to read from or write to
790 * @count: number of bytes to read/write
792 * Read the BufferRAM area with Sync. Burst Mode
797 struct onenand_chip *this = mtd->priv; in onenand_sync_read_bufferram()
800 bufferram = this->base + area; in onenand_sync_read_bufferram()
804 this->mmcontrol(mtd, ONENAND_SYS_CFG1_SYNC_READ); in onenand_sync_read_bufferram()
809 /* Align with word(16-bit) size */ in onenand_sync_read_bufferram()
810 count--; in onenand_sync_read_bufferram()
812 /* Read word and save byte */ in onenand_sync_read_bufferram()
813 word = this->read_word(bufferram + offset + count); in onenand_sync_read_bufferram()
819 this->mmcontrol(mtd, 0); in onenand_sync_read_bufferram()
825 * onenand_write_bufferram - [OneNAND Interface] Write the bufferram area
829 * @offset: offset to read from or write to
830 * @count: number of bytes to read/write
837 struct onenand_chip *this = mtd->priv; in onenand_write_bufferram()
840 bufferram = this->base + area; in onenand_write_bufferram()
848 /* Align with word(16-bit) size */ in onenand_write_bufferram()
849 count--; in onenand_write_bufferram()
854 /* Read word and save byte */ in onenand_write_bufferram()
855 word = this->read_word(bufferram + byte_offset); in onenand_write_bufferram()
857 this->write_word(word, bufferram + byte_offset); in onenand_write_bufferram()
866 * onenand_get_2x_blockpage - [GENERIC] Get blockpage at 2x program mode
875 struct onenand_chip *this = mtd->priv; in onenand_get_2x_blockpage()
879 block = (int) (addr >> this->erase_shift) & ~1; in onenand_get_2x_blockpage()
881 if (addr & this->writesize) in onenand_get_2x_blockpage()
883 page = (int) (addr >> (this->page_shift + 1)) & this->page_mask; in onenand_get_2x_blockpage()
890 * onenand_check_bufferram - [GENERIC] Check BufferRAM information
899 struct onenand_chip *this = mtd->priv; in onenand_check_bufferram()
906 blockpage = (int) (addr >> this->page_shift); in onenand_check_bufferram()
910 if (this->bufferram[i].blockpage == blockpage) in onenand_check_bufferram()
915 if (this->bufferram[i].blockpage == blockpage) { in onenand_check_bufferram()
925 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2); in onenand_check_bufferram()
932 * onenand_update_bufferram - [GENERIC] Update BufferRAM information
942 struct onenand_chip *this = mtd->priv; in onenand_update_bufferram()
949 blockpage = (int) (addr >> this->page_shift); in onenand_update_bufferram()
953 if (this->bufferram[i].blockpage == blockpage) in onenand_update_bufferram()
954 this->bufferram[i].blockpage = -1; in onenand_update_bufferram()
959 this->bufferram[i].blockpage = blockpage; in onenand_update_bufferram()
961 this->bufferram[i].blockpage = -1; in onenand_update_bufferram()
965 * onenand_invalidate_bufferram - [GENERIC] Invalidate BufferRAM information
975 struct onenand_chip *this = mtd->priv; in onenand_invalidate_bufferram()
981 loff_t buf_addr = this->bufferram[i].blockpage << this->page_shift; in onenand_invalidate_bufferram()
983 this->bufferram[i].blockpage = -1; in onenand_invalidate_bufferram()
988 * onenand_get_device - [GENERIC] Get chip for selected access
996 struct onenand_chip *this = mtd->priv; in onenand_get_device()
997 DECLARE_WAITQUEUE(wait, current); in onenand_get_device()
1003 spin_lock(&this->chip_lock); in onenand_get_device()
1004 if (this->state == FL_READY) { in onenand_get_device()
1005 this->state = new_state; in onenand_get_device()
1006 spin_unlock(&this->chip_lock); in onenand_get_device()
1007 if (new_state != FL_PM_SUSPENDED && this->enable) in onenand_get_device()
1008 this->enable(mtd); in onenand_get_device()
1012 spin_unlock(&this->chip_lock); in onenand_get_device()
1013 return (this->state == FL_PM_SUSPENDED) ? 0 : -EAGAIN; in onenand_get_device()
1016 add_wait_queue(&this->wq, &wait); in onenand_get_device()
1017 spin_unlock(&this->chip_lock); in onenand_get_device()
1019 remove_wait_queue(&this->wq, &wait); in onenand_get_device()
1026 * onenand_release_device - [GENERIC] release chip
1029 * Deselect, release chip lock and wake up anyone waiting on the device
1033 struct onenand_chip *this = mtd->priv; in onenand_release_device()
1035 if (this->state != FL_PM_SUSPENDED && this->disable) in onenand_release_device()
1036 this->disable(mtd); in onenand_release_device()
1038 spin_lock(&this->chip_lock); in onenand_release_device()
1039 this->state = FL_READY; in onenand_release_device()
1040 wake_up(&this->wq); in onenand_release_device()
1041 spin_unlock(&this->chip_lock); in onenand_release_device()
1045 * onenand_transfer_auto_oob - [INTERN] oob auto-placement transfer
1048 * @column: oob offset to read from
1049 * @thislen: oob length to read
1054 struct onenand_chip *this = mtd->priv; in onenand_transfer_auto_oob()
1056 this->read_bufferram(mtd, ONENAND_SPARERAM, this->oob_buf, 0, in onenand_transfer_auto_oob()
1057 mtd->oobsize); in onenand_transfer_auto_oob()
1058 return mtd_ooblayout_get_databytes(mtd, buf, this->oob_buf, in onenand_transfer_auto_oob()
1063 * onenand_recover_lsb - [Flex-OneNAND] Recover LSB page data
1068 * MLC NAND Flash cell has paired pages - LSB page and MSB page. LSB page has
1071 * become corrupt. LSB page recovery read is a way to read LSB page though page
1073 * read after power up, issue LSB page recovery read.
1077 struct onenand_chip *this = mtd->priv; in onenand_recover_lsb()
1080 /* Recovery is only for Flex-OneNAND */ in onenand_recover_lsb()
1090 if (mtd->eraseregions[i].erasesize < (1 << this->erase_shift)) in onenand_recover_lsb()
1094 * which was incremented by onenand_wait due to read failure in onenand_recover_lsb()
1096 printk(KERN_INFO "%s: Attempting to recover from uncorrectable read\n", in onenand_recover_lsb()
1098 mtd->ecc_stats.failed--; in onenand_recover_lsb()
1101 this->command(mtd, FLEXONENAND_CMD_RECOVER_LSB, addr, this->writesize); in onenand_recover_lsb()
1102 return this->wait(mtd, FL_READING); in onenand_recover_lsb()
1106 * onenand_mlc_read_ops_nolock - MLC OneNAND read main and/or out-of-band
1108 * @from: offset to read from
1111 * MLC OneNAND / Flex-OneNAND has 4KB page size and 4KB dataram.
1112 * So, read-while-load is not present.
1117 struct onenand_chip *this = mtd->priv; in onenand_mlc_read_ops_nolock()
1119 size_t len = ops->len; in onenand_mlc_read_ops_nolock()
1120 size_t ooblen = ops->ooblen; in onenand_mlc_read_ops_nolock()
1121 u_char *buf = ops->datbuf; in onenand_mlc_read_ops_nolock()
1122 u_char *oobbuf = ops->oobbuf; in onenand_mlc_read_ops_nolock()
1123 int read = 0, column, thislen; in onenand_mlc_read_ops_nolock() local
1126 int writesize = this->writesize; in onenand_mlc_read_ops_nolock()
1132 oobcolumn = from & (mtd->oobsize - 1); in onenand_mlc_read_ops_nolock()
1135 if (from + len > mtd->size) { in onenand_mlc_read_ops_nolock()
1136 printk(KERN_ERR "%s: Attempt read beyond end of device\n", in onenand_mlc_read_ops_nolock()
1138 ops->retlen = 0; in onenand_mlc_read_ops_nolock()
1139 ops->oobretlen = 0; in onenand_mlc_read_ops_nolock()
1140 return -EINVAL; in onenand_mlc_read_ops_nolock()
1143 stats = mtd->ecc_stats; in onenand_mlc_read_ops_nolock()
1145 while (read < len) { in onenand_mlc_read_ops_nolock()
1148 thislen = min_t(int, writesize, len - read); in onenand_mlc_read_ops_nolock()
1150 column = from & (writesize - 1); in onenand_mlc_read_ops_nolock()
1152 thislen = writesize - column; in onenand_mlc_read_ops_nolock()
1155 this->command(mtd, ONENAND_CMD_READ, from, writesize); in onenand_mlc_read_ops_nolock()
1157 ret = this->wait(mtd, FL_READING); in onenand_mlc_read_ops_nolock()
1167 this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen); in onenand_mlc_read_ops_nolock()
1169 thisooblen = oobsize - oobcolumn; in onenand_mlc_read_ops_nolock()
1170 thisooblen = min_t(int, thisooblen, ooblen - oobread); in onenand_mlc_read_ops_nolock()
1172 if (ops->mode == MTD_OPS_AUTO_OOB) in onenand_mlc_read_ops_nolock()
1175 this->read_bufferram(mtd, ONENAND_SPARERAM, oobbuf, oobcolumn, thisooblen); in onenand_mlc_read_ops_nolock()
1181 read += thislen; in onenand_mlc_read_ops_nolock()
1182 if (read == len) in onenand_mlc_read_ops_nolock()
1190 * Return success, if no ECC failures, else -EBADMSG in onenand_mlc_read_ops_nolock()
1192 * retlen == desired len and result == -EBADMSG in onenand_mlc_read_ops_nolock()
1194 ops->retlen = read; in onenand_mlc_read_ops_nolock()
1195 ops->oobretlen = oobread; in onenand_mlc_read_ops_nolock()
1200 if (mtd->ecc_stats.failed - stats.failed) in onenand_mlc_read_ops_nolock()
1201 return -EBADMSG; in onenand_mlc_read_ops_nolock()
1204 return mtd->ecc_stats.corrected != stats.corrected ? 1 : 0; in onenand_mlc_read_ops_nolock()
1208 * onenand_read_ops_nolock - [OneNAND Interface] OneNAND read main and/or out-of-band
1210 * @from: offset to read from
1213 * OneNAND read main and/or out-of-band data
1218 struct onenand_chip *this = mtd->priv; in onenand_read_ops_nolock()
1220 size_t len = ops->len; in onenand_read_ops_nolock()
1221 size_t ooblen = ops->ooblen; in onenand_read_ops_nolock()
1222 u_char *buf = ops->datbuf; in onenand_read_ops_nolock()
1223 u_char *oobbuf = ops->oobbuf; in onenand_read_ops_nolock()
1224 int read = 0, column, thislen; in onenand_read_ops_nolock() local
1227 int writesize = this->writesize; in onenand_read_ops_nolock()
1233 oobcolumn = from & (mtd->oobsize - 1); in onenand_read_ops_nolock()
1236 if ((from + len) > mtd->size) { in onenand_read_ops_nolock()
1237 printk(KERN_ERR "%s: Attempt read beyond end of device\n", in onenand_read_ops_nolock()
1239 ops->retlen = 0; in onenand_read_ops_nolock()
1240 ops->oobretlen = 0; in onenand_read_ops_nolock()
1241 return -EINVAL; in onenand_read_ops_nolock()
1244 stats = mtd->ecc_stats; in onenand_read_ops_nolock()
1246 /* Read-while-load method */ in onenand_read_ops_nolock()
1249 if (read < len) { in onenand_read_ops_nolock()
1251 this->command(mtd, ONENAND_CMD_READ, from, writesize); in onenand_read_ops_nolock()
1252 ret = this->wait(mtd, FL_READING); in onenand_read_ops_nolock()
1259 thislen = min_t(int, writesize, len - read); in onenand_read_ops_nolock()
1260 column = from & (writesize - 1); in onenand_read_ops_nolock()
1262 thislen = writesize - column; in onenand_read_ops_nolock()
1267 if (read + thislen < len) { in onenand_read_ops_nolock()
1268 this->command(mtd, ONENAND_CMD_READ, from, writesize); in onenand_read_ops_nolock()
1271 * Now we issued chip 1 read and pointed chip 1 in onenand_read_ops_nolock()
1275 unlikely(from == (this->chipsize >> 1))) { in onenand_read_ops_nolock()
1276 this->write_word(ONENAND_DDP_CHIP0, this->base + ONENAND_REG_START_ADDRESS2); in onenand_read_ops_nolock()
1282 /* While load is going, read from last bufferRAM */ in onenand_read_ops_nolock()
1283 this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen); in onenand_read_ops_nolock()
1285 /* Read oob area if needed */ in onenand_read_ops_nolock()
1287 thisooblen = oobsize - oobcolumn; in onenand_read_ops_nolock()
1288 thisooblen = min_t(int, thisooblen, ooblen - oobread); in onenand_read_ops_nolock()
1290 if (ops->mode == MTD_OPS_AUTO_OOB) in onenand_read_ops_nolock()
1293 this->read_bufferram(mtd, ONENAND_SPARERAM, oobbuf, oobcolumn, thisooblen); in onenand_read_ops_nolock()
1300 read += thislen; in onenand_read_ops_nolock()
1301 if (read == len) in onenand_read_ops_nolock()
1303 /* Set up for next read from bufferRAM */ in onenand_read_ops_nolock()
1305 this->write_word(ONENAND_DDP_CHIP1, this->base + ONENAND_REG_START_ADDRESS2); in onenand_read_ops_nolock()
1308 thislen = min_t(int, writesize, len - read); in onenand_read_ops_nolock()
1311 /* Now wait for load */ in onenand_read_ops_nolock()
1312 ret = this->wait(mtd, FL_READING); in onenand_read_ops_nolock()
1319 * Return success, if no ECC failures, else -EBADMSG in onenand_read_ops_nolock()
1321 * retlen == desired len and result == -EBADMSG in onenand_read_ops_nolock()
1323 ops->retlen = read; in onenand_read_ops_nolock()
1324 ops->oobretlen = oobread; in onenand_read_ops_nolock()
1329 if (mtd->ecc_stats.failed - stats.failed) in onenand_read_ops_nolock()
1330 return -EBADMSG; in onenand_read_ops_nolock()
1333 return mtd->ecc_stats.corrected != stats.corrected ? 1 : 0; in onenand_read_ops_nolock()
1337 * onenand_read_oob_nolock - [MTD Interface] OneNAND read out-of-band
1339 * @from: offset to read from
1342 * OneNAND read out-of-band data from the spare area
1347 struct onenand_chip *this = mtd->priv; in onenand_read_oob_nolock()
1349 int read = 0, thislen, column, oobsize; in onenand_read_oob_nolock() local
1350 size_t len = ops->ooblen; in onenand_read_oob_nolock()
1351 unsigned int mode = ops->mode; in onenand_read_oob_nolock()
1352 u_char *buf = ops->oobbuf; in onenand_read_oob_nolock()
1355 from += ops->ooboffs; in onenand_read_oob_nolock()
1361 ops->oobretlen = 0; in onenand_read_oob_nolock()
1364 oobsize = mtd->oobavail; in onenand_read_oob_nolock()
1366 oobsize = mtd->oobsize; in onenand_read_oob_nolock()
1368 column = from & (mtd->oobsize - 1); in onenand_read_oob_nolock()
1371 printk(KERN_ERR "%s: Attempted to start read outside oob\n", in onenand_read_oob_nolock()
1373 return -EINVAL; in onenand_read_oob_nolock()
1376 stats = mtd->ecc_stats; in onenand_read_oob_nolock()
1380 while (read < len) { in onenand_read_oob_nolock()
1383 thislen = oobsize - column; in onenand_read_oob_nolock()
1386 this->command(mtd, readcmd, from, mtd->oobsize); in onenand_read_oob_nolock()
1390 ret = this->wait(mtd, FL_READING); in onenand_read_oob_nolock()
1395 printk(KERN_ERR "%s: read failed = 0x%x\n", in onenand_read_oob_nolock()
1403 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen); in onenand_read_oob_nolock()
1405 read += thislen; in onenand_read_oob_nolock()
1407 if (read == len) in onenand_read_oob_nolock()
1412 /* Read more? */ in onenand_read_oob_nolock()
1413 if (read < len) { in onenand_read_oob_nolock()
1415 from += mtd->writesize; in onenand_read_oob_nolock()
1420 ops->oobretlen = read; in onenand_read_oob_nolock()
1425 if (mtd->ecc_stats.failed - stats.failed) in onenand_read_oob_nolock()
1426 return -EBADMSG; in onenand_read_oob_nolock()
1432 * onenand_read_oob - [MTD Interface] Read main and/or out-of-band
1434 * @from: offset to read from
1437 * Read main and/or out-of-band
1442 struct onenand_chip *this = mtd->priv; in onenand_read_oob()
1446 switch (ops->mode) { in onenand_read_oob()
1453 return -EINVAL; in onenand_read_oob()
1458 old_stats = mtd->ecc_stats; in onenand_read_oob()
1460 if (ops->datbuf) in onenand_read_oob()
1467 if (ops->stats) { in onenand_read_oob()
1468 ops->stats->uncorrectable_errors += in onenand_read_oob()
1469 mtd->ecc_stats.failed - old_stats.failed; in onenand_read_oob()
1470 ops->stats->corrected_bitflips += in onenand_read_oob()
1471 mtd->ecc_stats.corrected - old_stats.corrected; in onenand_read_oob()
1480 * onenand_bbt_wait - [DEFAULT] wait until the command is done
1484 * Wait for command done.
1488 struct onenand_chip *this = mtd->priv; in onenand_bbt_wait()
1495 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT); in onenand_bbt_wait()
1500 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT); in onenand_bbt_wait()
1501 ctrl = this->read_word(this->base + ONENAND_REG_CTRL_STATUS); in onenand_bbt_wait()
1502 addr1 = this->read_word(this->base + ONENAND_REG_START_ADDRESS1); in onenand_bbt_wait()
1503 addr8 = this->read_word(this->base + ONENAND_REG_START_ADDRESS8); in onenand_bbt_wait()
1514 printk(KERN_ERR "%s: read timeout! ctrl 0x%04x " in onenand_bbt_wait()
1531 * onenand_bbt_read_oob - [MTD Interface] OneNAND read out-of-band for bbt scan
1533 * @from: offset to read from
1536 * OneNAND read out-of-band data from the spare area for bbt scan
1541 struct onenand_chip *this = mtd->priv; in onenand_bbt_read_oob()
1542 int read = 0, thislen, column; in onenand_bbt_read_oob() local
1544 size_t len = ops->ooblen; in onenand_bbt_read_oob()
1545 u_char *buf = ops->oobbuf; in onenand_bbt_read_oob()
1551 ops->oobretlen = 0; in onenand_bbt_read_oob()
1554 if (unlikely((from + len) > mtd->size)) { in onenand_bbt_read_oob()
1555 printk(KERN_ERR "%s: Attempt read beyond end of device\n", in onenand_bbt_read_oob()
1563 column = from & (mtd->oobsize - 1); in onenand_bbt_read_oob()
1567 while (read < len) { in onenand_bbt_read_oob()
1570 thislen = mtd->oobsize - column; in onenand_bbt_read_oob()
1573 this->command(mtd, readcmd, from, mtd->oobsize); in onenand_bbt_read_oob()
1577 ret = this->bbt_wait(mtd, FL_READING); in onenand_bbt_read_oob()
1584 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen); in onenand_bbt_read_oob()
1585 read += thislen; in onenand_bbt_read_oob()
1586 if (read == len) in onenand_bbt_read_oob()
1591 /* Read more? */ in onenand_bbt_read_oob()
1592 if (read < len) { in onenand_bbt_read_oob()
1594 from += this->writesize; in onenand_bbt_read_oob()
1599 /* Deselect and wake up anyone waiting on the device */ in onenand_bbt_read_oob()
1602 ops->oobretlen = read; in onenand_bbt_read_oob()
1608 * onenand_verify_oob - [GENERIC] verify the oob contents after a write
1611 * @to: offset to read from
1615 struct onenand_chip *this = mtd->priv; in onenand_verify_oob()
1616 u_char *oob_buf = this->oob_buf; in onenand_verify_oob()
1621 this->command(mtd, readcmd, to, mtd->oobsize); in onenand_verify_oob()
1623 status = this->wait(mtd, FL_READING); in onenand_verify_oob()
1627 this->read_bufferram(mtd, ONENAND_SPARERAM, oob_buf, 0, mtd->oobsize); in onenand_verify_oob()
1628 for (i = 0; i < mtd->oobsize; i++) in onenand_verify_oob()
1630 return -EBADMSG; in onenand_verify_oob()
1636 * onenand_verify - [GENERIC] verify the chip contents after a write
1639 * @addr: offset to read from
1640 * @len: number of bytes to read and compare
1644 struct onenand_chip *this = mtd->priv; in onenand_verify()
1648 column = addr & (this->writesize - 1); in onenand_verify()
1651 thislen = min_t(int, this->writesize - column, len); in onenand_verify()
1653 this->command(mtd, ONENAND_CMD_READ, addr, this->writesize); in onenand_verify()
1657 ret = this->wait(mtd, FL_READING); in onenand_verify()
1663 this->read_bufferram(mtd, ONENAND_DATARAM, this->verify_buf, 0, mtd->writesize); in onenand_verify()
1665 if (memcmp(buf, this->verify_buf + column, thislen)) in onenand_verify()
1666 return -EBADMSG; in onenand_verify()
1668 len -= thislen; in onenand_verify()
1681 #define NOTALIGNED(x) ((x & (this->subpagesize - 1)) != 0)
1685 struct onenand_chip *this = mtd->priv; in onenand_panic_wait()
1690 interrupt = this->read_word(this->base + ONENAND_REG_INTERRUPT); in onenand_panic_wait()
1698 * onenand_panic_write - [MTD Interface] write buffer to FLASH in a panic context
1710 struct onenand_chip *this = mtd->priv; in onenand_panic_write()
1714 if (this->state == FL_PM_SUSPENDED) in onenand_panic_write()
1715 return -EBUSY; in onenand_panic_write()
1717 /* Wait for any existing operation to clear */ in onenand_panic_write()
1727 return -EINVAL; in onenand_panic_write()
1730 column = to & (mtd->writesize - 1); in onenand_panic_write()
1734 int thislen = min_t(int, mtd->writesize - column, len - written); in onenand_panic_write()
1737 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, thislen); in onenand_panic_write()
1740 subpage = thislen < mtd->writesize; in onenand_panic_write()
1742 memset(this->page_buf, 0xff, mtd->writesize); in onenand_panic_write()
1743 memcpy(this->page_buf + column, buf, thislen); in onenand_panic_write()
1744 wbuf = this->page_buf; in onenand_panic_write()
1747 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, mtd->writesize); in onenand_panic_write()
1748 this->write_bufferram(mtd, ONENAND_SPARERAM, ffchars, 0, mtd->oobsize); in onenand_panic_write()
1750 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize); in onenand_panic_write()
1758 onenand_update_bufferram(mtd, to + this->writesize, !subpage); in onenand_panic_write()
1776 * onenand_fill_auto_oob - [INTERN] oob auto-placement transfer
1790 * onenand_write_ops_nolock - [OneNAND Interface] write main and/or out-of-band
1800 struct onenand_chip *this = mtd->priv; in onenand_write_ops_nolock()
1804 size_t len = ops->len; in onenand_write_ops_nolock()
1805 size_t ooblen = ops->ooblen; in onenand_write_ops_nolock()
1806 const u_char *buf = ops->datbuf; in onenand_write_ops_nolock()
1807 const u_char *oob = ops->oobbuf; in onenand_write_ops_nolock()
1815 ops->retlen = 0; in onenand_write_ops_nolock()
1816 ops->oobretlen = 0; in onenand_write_ops_nolock()
1822 return -EINVAL; in onenand_write_ops_nolock()
1829 oobcolumn = to & (mtd->oobsize - 1); in onenand_write_ops_nolock()
1831 column = to & (mtd->writesize - 1); in onenand_write_ops_nolock()
1838 thislen = min_t(int, mtd->writesize - column, len - written); in onenand_write_ops_nolock()
1839 thisooblen = min_t(int, oobsize - oobcolumn, ooblen - oobwritten); in onenand_write_ops_nolock()
1843 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, thislen); in onenand_write_ops_nolock()
1846 subpage = thislen < mtd->writesize; in onenand_write_ops_nolock()
1848 memset(this->page_buf, 0xff, mtd->writesize); in onenand_write_ops_nolock()
1849 memcpy(this->page_buf + column, buf, thislen); in onenand_write_ops_nolock()
1850 wbuf = this->page_buf; in onenand_write_ops_nolock()
1853 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, mtd->writesize); in onenand_write_ops_nolock()
1856 oobbuf = this->oob_buf; in onenand_write_ops_nolock()
1860 memset(oobbuf, 0xff, mtd->oobsize); in onenand_write_ops_nolock()
1861 if (ops->mode == MTD_OPS_AUTO_OOB) in onenand_write_ops_nolock()
1872 this->write_bufferram(mtd, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize); in onenand_write_ops_nolock()
1877 * 2 PLANE, MLC, and Flex-OneNAND do not support in onenand_write_ops_nolock()
1878 * write-while-program feature. in onenand_write_ops_nolock()
1883 ret = this->wait(mtd, FL_WRITING); in onenand_write_ops_nolock()
1888 written -= prevlen; in onenand_write_ops_nolock()
1895 /* Only check verify write turn on */ in onenand_write_ops_nolock()
1896 ret = onenand_verify(mtd, buf - len, to - len, len); in onenand_write_ops_nolock()
1906 this->ongoing = 0; in onenand_write_ops_nolock()
1915 this->ongoing = 1; in onenand_write_ops_nolock()
1918 this->command(mtd, cmd, to, mtd->writesize); in onenand_write_ops_nolock()
1921 * 2 PLANE, MLC, and Flex-OneNAND wait here in onenand_write_ops_nolock()
1924 ret = this->wait(mtd, FL_WRITING); in onenand_write_ops_nolock()
1934 /* Only check verify write turn on */ in onenand_write_ops_nolock()
1961 onenand_invalidate_bufferram(mtd, 0, -1); in onenand_write_ops_nolock()
1963 ops->retlen = written; in onenand_write_ops_nolock()
1964 ops->oobretlen = oobwritten; in onenand_write_ops_nolock()
1971 * onenand_write_oob_nolock - [INTERN] OneNAND write out-of-band
1976 * OneNAND write out-of-band
1981 struct onenand_chip *this = mtd->priv; in onenand_write_oob_nolock()
1985 size_t len = ops->ooblen; in onenand_write_oob_nolock()
1986 const u_char *buf = ops->oobbuf; in onenand_write_oob_nolock()
1987 unsigned int mode = ops->mode; in onenand_write_oob_nolock()
1989 to += ops->ooboffs; in onenand_write_oob_nolock()
1995 ops->oobretlen = 0; in onenand_write_oob_nolock()
1998 oobsize = mtd->oobavail; in onenand_write_oob_nolock()
2000 oobsize = mtd->oobsize; in onenand_write_oob_nolock()
2002 column = to & (mtd->oobsize - 1); in onenand_write_oob_nolock()
2007 return -EINVAL; in onenand_write_oob_nolock()
2014 return -EINVAL; in onenand_write_oob_nolock()
2017 oobbuf = this->oob_buf; in onenand_write_oob_nolock()
2023 int thislen = min_t(int, oobsize, len - written); in onenand_write_oob_nolock()
2027 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, mtd->oobsize); in onenand_write_oob_nolock()
2031 memset(oobbuf, 0xff, mtd->oobsize); in onenand_write_oob_nolock()
2036 this->write_bufferram(mtd, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize); in onenand_write_oob_nolock()
2040 memset(this->page_buf, 0xff, mtd->writesize); in onenand_write_oob_nolock()
2041 this->write_bufferram(mtd, ONENAND_DATARAM, in onenand_write_oob_nolock()
2042 this->page_buf, 0, mtd->writesize); in onenand_write_oob_nolock()
2045 this->command(mtd, oobcmd, to, mtd->oobsize); in onenand_write_oob_nolock()
2050 onenand_update_bufferram(mtd, to + this->writesize, 0); in onenand_write_oob_nolock()
2053 ret = this->wait(mtd, FL_WRITING); in onenand_write_oob_nolock()
2070 to += mtd->writesize; in onenand_write_oob_nolock()
2075 ops->oobretlen = written; in onenand_write_oob_nolock()
2081 * onenand_write_oob - [MTD Interface] NAND write data and/or out-of-band
2091 switch (ops->mode) { in onenand_write_oob()
2098 return -EINVAL; in onenand_write_oob()
2102 if (ops->datbuf) in onenand_write_oob()
2112 * onenand_block_isbad_nolock - [GENERIC] Check if a block is marked bad
2122 struct onenand_chip *this = mtd->priv; in onenand_block_isbad_nolock()
2123 struct bbm_info *bbm = this->bbm; in onenand_block_isbad_nolock()
2126 return bbm->isbad_bbt(mtd, ofs, allowbbt); in onenand_block_isbad_nolock()
2133 struct onenand_chip *this = mtd->priv; in onenand_multiblock_erase_verify()
2134 loff_t addr = instr->addr; in onenand_multiblock_erase_verify()
2135 int len = instr->len; in onenand_multiblock_erase_verify()
2136 unsigned int block_size = (1 << this->erase_shift); in onenand_multiblock_erase_verify()
2140 this->command(mtd, ONENAND_CMD_ERASE_VERIFY, addr, block_size); in onenand_multiblock_erase_verify()
2141 ret = this->wait(mtd, FL_VERIFYING_ERASE); in onenand_multiblock_erase_verify()
2145 instr->fail_addr = addr; in onenand_multiblock_erase_verify()
2146 return -1; in onenand_multiblock_erase_verify()
2148 len -= block_size; in onenand_multiblock_erase_verify()
2155 * onenand_multiblock_erase - [INTERN] erase block(s) using multiblock erase
2166 struct onenand_chip *this = mtd->priv; in onenand_multiblock_erase()
2167 loff_t addr = instr->addr; in onenand_multiblock_erase()
2168 int len = instr->len; in onenand_multiblock_erase()
2174 loff_t bdry_addr = this->chipsize >> 1; in onenand_multiblock_erase()
2176 bdry_block = bdry_addr >> this->erase_shift; in onenand_multiblock_erase()
2179 /* Pre-check bbs */ in onenand_multiblock_erase()
2186 return -EIO; in onenand_multiblock_erase()
2188 len -= block_size; in onenand_multiblock_erase()
2192 len = instr->len; in onenand_multiblock_erase()
2193 addr = instr->addr; in onenand_multiblock_erase()
2205 int this_block = (addr >> this->erase_shift); in onenand_multiblock_erase()
2209 (bdry_block - this_block)); in onenand_multiblock_erase()
2215 while (len > block_size && eb_count < (max_eb_count - 1)) { in onenand_multiblock_erase()
2216 this->command(mtd, ONENAND_CMD_MULTIBLOCK_ERASE, in onenand_multiblock_erase()
2220 ret = this->wait(mtd, FL_PREPARING_ERASE); in onenand_multiblock_erase()
2225 instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; in onenand_multiblock_erase()
2226 return -EIO; in onenand_multiblock_erase()
2229 len -= block_size; in onenand_multiblock_erase()
2234 /* last block of 64-eb series */ in onenand_multiblock_erase()
2236 this->command(mtd, ONENAND_CMD_ERASE, addr, block_size); in onenand_multiblock_erase()
2239 ret = this->wait(mtd, FL_ERASING); in onenand_multiblock_erase()
2244 instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; in onenand_multiblock_erase()
2245 return -EIO; in onenand_multiblock_erase()
2248 len -= block_size; in onenand_multiblock_erase()
2255 instr->fail_addr = verify_instr.fail_addr; in onenand_multiblock_erase()
2256 return -EIO; in onenand_multiblock_erase()
2265 * onenand_block_by_block_erase - [INTERN] erase block(s) using regular erase
2278 struct onenand_chip *this = mtd->priv; in onenand_block_by_block_erase()
2279 loff_t addr = instr->addr; in onenand_block_by_block_erase()
2280 int len = instr->len; in onenand_block_by_block_erase()
2285 /* region is set for Flex-OneNAND */ in onenand_block_by_block_erase()
2286 region_end = region->offset + region->erasesize * region->numblocks; in onenand_block_by_block_erase()
2298 return -EIO; in onenand_block_by_block_erase()
2301 this->command(mtd, ONENAND_CMD_ERASE, addr, block_size); in onenand_block_by_block_erase()
2305 ret = this->wait(mtd, FL_ERASING); in onenand_block_by_block_erase()
2310 instr->fail_addr = addr; in onenand_block_by_block_erase()
2311 return -EIO; in onenand_block_by_block_erase()
2314 len -= block_size; in onenand_block_by_block_erase()
2322 block_size = region->erasesize; in onenand_block_by_block_erase()
2323 region_end = region->offset + region->erasesize * region->numblocks; in onenand_block_by_block_erase()
2325 if (len & (block_size - 1)) { in onenand_block_by_block_erase()
2329 return -EIO; in onenand_block_by_block_erase()
2337 * onenand_erase - [MTD Interface] erase block(s)
2345 struct onenand_chip *this = mtd->priv; in onenand_erase()
2347 loff_t addr = instr->addr; in onenand_erase()
2348 loff_t len = instr->len; in onenand_erase()
2354 (unsigned long long)instr->addr, in onenand_erase()
2355 (unsigned long long)instr->len); in onenand_erase()
2361 region = &mtd->eraseregions[i]; in onenand_erase()
2362 block_size = region->erasesize; in onenand_erase()
2364 /* Start address within region must align on block boundary. in onenand_erase()
2367 region_offset = region->offset; in onenand_erase()
2369 block_size = 1 << this->erase_shift; in onenand_erase()
2371 /* Start address must align on block boundary */ in onenand_erase()
2372 if (unlikely((addr - region_offset) & (block_size - 1))) { in onenand_erase()
2374 return -EINVAL; in onenand_erase()
2377 /* Length must align on block boundary */ in onenand_erase()
2378 if (unlikely(len & (block_size - 1))) { in onenand_erase()
2380 return -EINVAL; in onenand_erase()
2387 instr->len < MB_ERASE_MIN_BLK_COUNT * block_size) { in onenand_erase()
2388 /* region is set for Flex-OneNAND (no mb erase) */ in onenand_erase()
2395 /* Deselect and wake up anyone waiting on the device */ in onenand_erase()
2402 * onenand_sync - [MTD Interface] sync
2405 * Sync is actually a wait for chip ready function
2419 * onenand_block_isbad - [MTD Interface] Check whether the block at the given offset is bad
2436 * onenand_default_block_markbad - [DEFAULT] mark a block bad
2445 struct onenand_chip *this = mtd->priv; in onenand_default_block_markbad()
2446 struct bbm_info *bbm = this->bbm; in onenand_default_block_markbad()
2458 if (bbm->bbt) in onenand_default_block_markbad()
2459 bbm->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); in onenand_default_block_markbad()
2461 /* We write two bytes, so we don't have to mess with 16-bit access */ in onenand_default_block_markbad()
2462 ofs += mtd->oobsize + (this->badblockpos & ~0x01); in onenand_default_block_markbad()
2471 * onenand_block_markbad - [MTD Interface] Mark the block at the given offset as bad
2479 struct onenand_chip *this = mtd->priv; in onenand_block_markbad()
2491 ret = this->block_markbad(mtd, ofs); in onenand_block_markbad()
2497 * onenand_do_lock_cmd - [OneNAND Interface] Lock or unlock block(s)
2507 struct onenand_chip *this = mtd->priv; in onenand_do_lock_cmd()
2512 end = onenand_block(this, ofs + len) - 1; in onenand_do_lock_cmd()
2520 if (this->options & ONENAND_HAS_CONT_LOCK) { in onenand_do_lock_cmd()
2522 this->write_word(start, this->base + ONENAND_REG_START_BLOCK_ADDRESS); in onenand_do_lock_cmd()
2524 this->write_word(end, this->base + ONENAND_REG_END_BLOCK_ADDRESS); in onenand_do_lock_cmd()
2526 this->command(mtd, cmd, 0, 0); in onenand_do_lock_cmd()
2529 this->wait(mtd, FL_LOCKING); in onenand_do_lock_cmd()
2532 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) in onenand_do_lock_cmd()
2537 status = this->read_word(this->base + ONENAND_REG_WP_STATUS); in onenand_do_lock_cmd()
2549 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1); in onenand_do_lock_cmd()
2552 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2); in onenand_do_lock_cmd()
2554 this->write_word(block, this->base + ONENAND_REG_START_BLOCK_ADDRESS); in onenand_do_lock_cmd()
2556 this->command(mtd, cmd, 0, 0); in onenand_do_lock_cmd()
2559 this->wait(mtd, FL_LOCKING); in onenand_do_lock_cmd()
2562 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) in onenand_do_lock_cmd()
2567 status = this->read_word(this->base + ONENAND_REG_WP_STATUS); in onenand_do_lock_cmd()
2577 * onenand_lock - [MTD Interface] Lock block(s)
2595 * onenand_unlock - [MTD Interface] Unlock block(s)
2613 * onenand_check_lock_status - [OneNAND Interface] Check lock status
2623 end = this->chipsize >> this->erase_shift; in onenand_check_lock_status()
2627 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS1); in onenand_check_lock_status()
2630 this->write_word(value, this->base + ONENAND_REG_START_ADDRESS2); in onenand_check_lock_status()
2632 this->write_word(block, this->base + ONENAND_REG_START_BLOCK_ADDRESS); in onenand_check_lock_status()
2635 status = this->read_word(this->base + ONENAND_REG_WP_STATUS); in onenand_check_lock_status()
2647 * onenand_unlock_all - [OneNAND Interface] unlock all blocks
2654 struct onenand_chip *this = mtd->priv; in onenand_unlock_all()
2656 loff_t len = mtd->size; in onenand_unlock_all()
2658 if (this->options & ONENAND_HAS_UNLOCK_ALL) { in onenand_unlock_all()
2660 this->write_word(0, this->base + ONENAND_REG_START_BLOCK_ADDRESS); in onenand_unlock_all()
2662 this->command(mtd, ONENAND_CMD_UNLOCK_ALL, 0, 0); in onenand_unlock_all()
2665 this->wait(mtd, FL_LOCKING); in onenand_unlock_all()
2668 while (this->read_word(this->base + ONENAND_REG_CTRL_STATUS) in onenand_unlock_all()
2673 if (this->options & ONENAND_SKIP_UNLOCK_CHECK) in onenand_unlock_all()
2682 /* All blocks on another chip */ in onenand_unlock_all()
2683 ofs = this->chipsize >> 1; in onenand_unlock_all()
2684 len = this->chipsize >> 1; in onenand_unlock_all()
2694 * onenand_otp_command - Send OTP specific command to OneNAND device
2697 * @addr: offset to read from or write to
2698 * @len: number of bytes to read or write
2703 struct onenand_chip *this = mtd->priv; in onenand_otp_command()
2709 block = (int) (addr >> this->erase_shift); in onenand_otp_command()
2710 page = -1; in onenand_otp_command()
2714 block = (int) (addr >> this->erase_shift); in onenand_otp_command()
2715 page = (int) (addr >> this->page_shift); in onenand_otp_command()
2721 if (addr & this->writesize) in onenand_otp_command()
2725 page &= this->page_mask; in onenand_otp_command()
2729 if (block != -1) { in onenand_otp_command()
2732 this->write_word(value, this->base + in onenand_otp_command()
2736 if (page != -1) { in onenand_otp_command()
2751 this->write_word(value, this->base + in onenand_otp_command()
2756 this->write_word(value, this->base + ONENAND_REG_START_BUFFER); in onenand_otp_command()
2760 this->write_word(ONENAND_INT_CLEAR, this->base + ONENAND_REG_INTERRUPT); in onenand_otp_command()
2763 this->write_word(cmd, this->base + ONENAND_REG_COMMAND); in onenand_otp_command()
2769 * onenand_otp_write_oob_nolock - [INTERN] OneNAND write out-of-band, specific to OTP
2774 * OneNAND write out-of-band only for OTP
2779 struct onenand_chip *this = mtd->priv; in onenand_otp_write_oob_nolock()
2783 size_t len = ops->ooblen; in onenand_otp_write_oob_nolock()
2784 const u_char *buf = ops->oobbuf; in onenand_otp_write_oob_nolock()
2787 to += ops->ooboffs; in onenand_otp_write_oob_nolock()
2790 ops->oobretlen = 0; in onenand_otp_write_oob_nolock()
2792 oobsize = mtd->oobsize; in onenand_otp_write_oob_nolock()
2794 column = to & (mtd->oobsize - 1); in onenand_otp_write_oob_nolock()
2796 oobbuf = this->oob_buf; in onenand_otp_write_oob_nolock()
2800 int thislen = min_t(int, oobsize, len - written); in onenand_otp_write_oob_nolock()
2804 block = (int) (to >> this->erase_shift); in onenand_otp_write_oob_nolock()
2811 this->write_word(value, this->base + in onenand_otp_write_oob_nolock()
2820 this->write_word(value, this->base + in onenand_otp_write_oob_nolock()
2827 this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0); in onenand_otp_write_oob_nolock()
2828 this->wait(mtd, FL_OTPING); in onenand_otp_write_oob_nolock()
2840 this->write_bufferram(mtd, ONENAND_SPARERAM, in onenand_otp_write_oob_nolock()
2841 oobbuf, 0, mtd->oobsize); in onenand_otp_write_oob_nolock()
2843 onenand_otp_command(mtd, ONENAND_CMD_PROGOOB, to, mtd->oobsize); in onenand_otp_write_oob_nolock()
2847 onenand_update_bufferram(mtd, to + this->writesize, 0); in onenand_otp_write_oob_nolock()
2850 ret = this->wait(mtd, FL_WRITING); in onenand_otp_write_oob_nolock()
2857 this->command(mtd, ONENAND_CMD_RESET, 0, 0); in onenand_otp_write_oob_nolock()
2858 this->wait(mtd, FL_RESETTING); in onenand_otp_write_oob_nolock()
2860 status = this->read_word(this->base + ONENAND_REG_CTRL_STATUS); in onenand_otp_write_oob_nolock()
2870 printk(KERN_DEBUG "OTP Block\tUN-LOCKED\n"); in onenand_otp_write_oob_nolock()
2873 printk(KERN_DEBUG "1st Block\tUN-LOCKED\n"); in onenand_otp_write_oob_nolock()
2883 to += mtd->writesize; in onenand_otp_write_oob_nolock()
2888 ops->oobretlen = written; in onenand_otp_write_oob_nolock()
2898 * do_otp_read - [DEFAULT] Read OTP block area
2900 * @from: The offset to read
2901 * @len: number of bytes to read
2905 * Read OTP block area.
2910 struct onenand_chip *this = mtd->priv; in do_otp_read()
2920 this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0); in do_otp_read()
2921 this->wait(mtd, FL_OTPING); in do_otp_read()
2928 this->command(mtd, ONENAND_CMD_RESET, 0, 0); in do_otp_read()
2929 this->wait(mtd, FL_RESETTING); in do_otp_read()
2935 * do_otp_write - [DEFAULT] Write OTP block area
2947 struct onenand_chip *this = mtd->priv; in do_otp_write()
2953 if (len < mtd->writesize) { in do_otp_write()
2954 memcpy(this->page_buf, buf, len); in do_otp_write()
2955 memset(this->page_buf + len, 0xff, mtd->writesize - len); in do_otp_write()
2956 pbuf = this->page_buf; in do_otp_write()
2957 len = mtd->writesize; in do_otp_write()
2961 this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0); in do_otp_write()
2962 this->wait(mtd, FL_OTPING); in do_otp_write()
2972 this->command(mtd, ONENAND_CMD_RESET, 0, 0); in do_otp_write()
2973 this->wait(mtd, FL_RESETTING); in do_otp_write()
2979 * do_otp_lock - [DEFAULT] Lock OTP block area
2991 struct onenand_chip *this = mtd->priv; in do_otp_lock()
2998 this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0); in do_otp_lock()
2999 this->wait(mtd, FL_OTPING); in do_otp_lock()
3001 * For Flex-OneNAND, we write lock mark to 1st word of sector 4 of in do_otp_lock()
3004 ops.len = mtd->writesize; in do_otp_lock()
3008 ret = onenand_write_ops_nolock(mtd, mtd->writesize * 49, &ops); in do_otp_lock()
3012 this->command(mtd, ONENAND_CMD_RESET, 0, 0); in do_otp_lock()
3013 this->wait(mtd, FL_RESETTING); in do_otp_lock()
3027 * onenand_otp_walk - [DEFAULT] Handle OTP operation
3029 * @from: The offset to read/write
3030 * @len: number of bytes to read/write
3031 * @retlen: pointer to variable to store the number of read bytes
3042 struct onenand_chip *this = mtd->priv; in onenand_otp_walk()
3049 density = onenand_get_density(this->device_id); in onenand_otp_walk()
3056 from += mtd->writesize * otp_pages; in onenand_otp_walk()
3057 otp_pages = ONENAND_PAGES_PER_BLOCK - otp_pages; in onenand_otp_walk()
3062 if (mtd->writesize * otp_pages < from + len) in onenand_otp_walk()
3065 if (mtd->writesize * otp_pages < len) in onenand_otp_walk()
3074 len -= sizeof(struct otp_info); in onenand_otp_walk()
3076 ret = -ENOSPC; in onenand_otp_walk()
3081 otpinfo->start = from; in onenand_otp_walk()
3082 otpinfo->length = mtd->writesize; in onenand_otp_walk()
3083 otpinfo->locked = 0; in onenand_otp_walk()
3085 from += mtd->writesize; in onenand_otp_walk()
3096 len -= tmp_retlen; in onenand_otp_walk()
3100 otp_pages--; in onenand_otp_walk()
3108 * onenand_get_fact_prot_info - [MTD Interface] Read factory OTP info
3110 * @len: number of bytes to read
3111 * @retlen: pointer to variable to store the number of read bytes
3114 * Read factory OTP info.
3124 * onenand_read_fact_prot_reg - [MTD Interface] Read factory OTP area
3126 * @from: The offset to read
3127 * @len: number of bytes to read
3128 * @retlen: pointer to variable to store the number of read bytes
3131 * Read factory OTP area.
3140 * onenand_get_user_prot_info - [MTD Interface] Read user OTP info
3142 * @retlen: pointer to variable to store the number of read bytes
3143 * @len: number of bytes to read
3146 * Read user OTP info.
3156 * onenand_read_user_prot_reg - [MTD Interface] Read user OTP area
3158 * @from: The offset to read
3159 * @len: number of bytes to read
3160 * @retlen: pointer to variable to store the number of read bytes
3163 * Read user OTP area.
3172 * onenand_write_user_prot_reg - [MTD Interface] Write user OTP area
3189 * onenand_lock_user_prot_reg - [MTD Interface] Lock user OTP area
3194 * Write lock mark on spare area in page 0 in OTP block
3199 struct onenand_chip *this = mtd->priv; in onenand_lock_user_prot_reg()
3200 u_char *buf = FLEXONENAND(this) ? this->page_buf : this->oob_buf; in onenand_lock_user_prot_reg()
3205 memset(buf, 0xff, FLEXONENAND(this) ? this->writesize in onenand_lock_user_prot_reg()
3206 : mtd->oobsize); in onenand_lock_user_prot_reg()
3210 * For Flex-OneNAND, we write lock mark to 1st word of sector 4 of in onenand_lock_user_prot_reg()
3215 len = FLEXONENAND(this) ? mtd->writesize : 16; in onenand_lock_user_prot_reg()
3244 * onenand_check_features - Check and set OneNAND features
3248 * - lock scheme
3249 * - two plane
3253 struct onenand_chip *this = mtd->priv; in onenand_check_features()
3256 /* Lock scheme depends on density and process */ in onenand_check_features()
3257 density = onenand_get_density(this->device_id); in onenand_check_features()
3258 process = this->version_id >> ONENAND_VERSION_PROCESS_SHIFT; in onenand_check_features()
3259 numbufs = this->read_word(this->base + ONENAND_REG_NUM_BUFFERS) >> 8; in onenand_check_features()
3264 this->options |= ONENAND_HAS_NOP_1; in onenand_check_features()
3268 this->options |= ONENAND_HAS_2PLANE; in onenand_check_features()
3270 this->options |= ONENAND_HAS_4KB_PAGE; in onenand_check_features()
3271 this->options |= ONENAND_HAS_CACHE_PROGRAM; in onenand_check_features()
3283 if ((this->version_id & 0xf) == 0xe) in onenand_check_features()
3284 this->options |= ONENAND_HAS_NOP_1; in onenand_check_features()
3286 this->options |= ONENAND_HAS_UNLOCK_ALL; in onenand_check_features()
3292 this->options |= ONENAND_HAS_2PLANE; in onenand_check_features()
3293 this->options |= ONENAND_HAS_UNLOCK_ALL; in onenand_check_features()
3297 /* A-Die has all block unlock */ in onenand_check_features()
3299 this->options |= ONENAND_HAS_UNLOCK_ALL; in onenand_check_features()
3305 this->options |= ONENAND_HAS_CONT_LOCK; in onenand_check_features()
3311 this->options |= ONENAND_HAS_4KB_PAGE; in onenand_check_features()
3314 this->options &= ~ONENAND_HAS_2PLANE; in onenand_check_features()
3317 this->options &= ~ONENAND_HAS_CONT_LOCK; in onenand_check_features()
3318 this->options |= ONENAND_HAS_UNLOCK_ALL; in onenand_check_features()
3321 if (this->options & ONENAND_HAS_CONT_LOCK) in onenand_check_features()
3323 if (this->options & ONENAND_HAS_UNLOCK_ALL) in onenand_check_features()
3325 if (this->options & ONENAND_HAS_2PLANE) in onenand_check_features()
3327 if (this->options & ONENAND_HAS_4KB_PAGE) in onenand_check_features()
3329 if (this->options & ONENAND_HAS_CACHE_PROGRAM) in onenand_check_features()
3334 * onenand_print_device_info - Print device & version ID
3349 printk(KERN_INFO "%s%sOneNAND%s %dMB %sV 16-bit (0x%02x)\n", in onenand_print_device_info()
3351 flexonenand ? "Flex-" : "", in onenand_print_device_info()
3365 * onenand_check_maf - Check manufacturer ID
3391 * flexonenand_get_boundary - Reads the SLC boundary
3396 struct onenand_chip *this = mtd->priv; in flexonenand_get_boundary()
3401 syscfg = this->read_word(this->base + ONENAND_REG_SYS_CFG1); in flexonenand_get_boundary()
3402 this->write_word((syscfg | 0x0100), this->base + ONENAND_REG_SYS_CFG1); in flexonenand_get_boundary()
3404 for (die = 0; die < this->dies; die++) { in flexonenand_get_boundary()
3405 this->command(mtd, FLEXONENAND_CMD_PI_ACCESS, die, 0); in flexonenand_get_boundary()
3406 this->wait(mtd, FL_SYNCING); in flexonenand_get_boundary()
3408 this->command(mtd, FLEXONENAND_CMD_READ_PI, die, 0); in flexonenand_get_boundary()
3409 this->wait(mtd, FL_READING); in flexonenand_get_boundary()
3411 bdry = this->read_word(this->base + ONENAND_DATARAM); in flexonenand_get_boundary()
3416 this->boundary[die] = bdry & FLEXONENAND_PI_MASK; in flexonenand_get_boundary()
3418 this->command(mtd, ONENAND_CMD_RESET, 0, 0); in flexonenand_get_boundary()
3419 this->wait(mtd, FL_RESETTING); in flexonenand_get_boundary()
3422 this->boundary[die], locked ? "(Locked)" : "(Unlocked)"); in flexonenand_get_boundary()
3426 this->write_word(syscfg, this->base + ONENAND_REG_SYS_CFG1); in flexonenand_get_boundary()
3431 * flexonenand_get_size - Fill up fields in onenand_chip and mtd_info
3432 * boundary[], diesize[], mtd->size, mtd->erasesize
3433 * @mtd: - MTD device structure
3437 struct onenand_chip *this = mtd->priv; in flexonenand_get_size()
3442 density = onenand_get_density(this->device_id); in flexonenand_get_size()
3443 blksperdie = ((loff_t)(16 << density) << 20) >> (this->erase_shift); in flexonenand_get_size()
3445 maxbdry = blksperdie - 1; in flexonenand_get_size()
3446 eraseshift = this->erase_shift - 1; in flexonenand_get_size()
3448 mtd->numeraseregions = this->dies << 1; in flexonenand_get_size()
3453 i = -1; in flexonenand_get_size()
3454 for (; die < this->dies; die++) { in flexonenand_get_size()
3455 if (!die || this->boundary[die-1] != maxbdry) { in flexonenand_get_size()
3457 mtd->eraseregions[i].offset = ofs; in flexonenand_get_size()
3458 mtd->eraseregions[i].erasesize = 1 << eraseshift; in flexonenand_get_size()
3459 mtd->eraseregions[i].numblocks = in flexonenand_get_size()
3460 this->boundary[die] + 1; in flexonenand_get_size()
3461 ofs += mtd->eraseregions[i].numblocks << eraseshift; in flexonenand_get_size()
3464 mtd->numeraseregions -= 1; in flexonenand_get_size()
3465 mtd->eraseregions[i].numblocks += in flexonenand_get_size()
3466 this->boundary[die] + 1; in flexonenand_get_size()
3467 ofs += (this->boundary[die] + 1) << (eraseshift - 1); in flexonenand_get_size()
3469 if (this->boundary[die] != maxbdry) { in flexonenand_get_size()
3471 mtd->eraseregions[i].offset = ofs; in flexonenand_get_size()
3472 mtd->eraseregions[i].erasesize = 1 << eraseshift; in flexonenand_get_size()
3473 mtd->eraseregions[i].numblocks = maxbdry ^ in flexonenand_get_size()
3474 this->boundary[die]; in flexonenand_get_size()
3475 ofs += mtd->eraseregions[i].numblocks << eraseshift; in flexonenand_get_size()
3476 eraseshift--; in flexonenand_get_size()
3478 mtd->numeraseregions -= 1; in flexonenand_get_size()
3482 mtd->erasesize = 1 << this->erase_shift; in flexonenand_get_size()
3483 if (mtd->numeraseregions == 1) in flexonenand_get_size()
3484 mtd->erasesize >>= 1; in flexonenand_get_size()
3486 printk(KERN_INFO "Device has %d eraseregions\n", mtd->numeraseregions); in flexonenand_get_size()
3487 for (i = 0; i < mtd->numeraseregions; i++) in flexonenand_get_size()
3490 (unsigned int) mtd->eraseregions[i].offset, in flexonenand_get_size()
3491 mtd->eraseregions[i].erasesize, in flexonenand_get_size()
3492 mtd->eraseregions[i].numblocks); in flexonenand_get_size()
3494 for (die = 0, mtd->size = 0; die < this->dies; die++) { in flexonenand_get_size()
3495 this->diesize[die] = (loff_t)blksperdie << this->erase_shift; in flexonenand_get_size()
3496 this->diesize[die] -= (loff_t)(this->boundary[die] + 1) in flexonenand_get_size()
3497 << (this->erase_shift - 1); in flexonenand_get_size()
3498 mtd->size += this->diesize[die]; in flexonenand_get_size()
3503 * flexonenand_check_blocks_erased - Check if blocks are erased
3510 * have changed, reads on the block give uncorrectable error.
3518 struct onenand_chip *this = mtd->priv; in flexonenand_check_blocks_erased()
3524 .ooblen = mtd->oobsize, in flexonenand_check_blocks_erased()
3526 .oobbuf = this->oob_buf, in flexonenand_check_blocks_erased()
3545 for (i = 0; i < mtd->oobsize; i++) in flexonenand_check_blocks_erased()
3546 if (this->oob_buf[i] != 0xff) in flexonenand_check_blocks_erased()
3549 if (i != mtd->oobsize) { in flexonenand_check_blocks_erased()
3560 * flexonenand_set_boundary - Writes the SLC boundary
3565 struct onenand_chip *this = mtd->priv; in flexonenand_set_boundary()
3569 /* Change only once for SDP Flex-OneNAND */ in flexonenand_set_boundary()
3573 /* boundary value of -1 indicates no required change */ in flexonenand_set_boundary()
3574 if (boundary < 0 || boundary == this->boundary[die]) in flexonenand_set_boundary()
3577 density = onenand_get_density(this->device_id); in flexonenand_set_boundary()
3578 blksperdie = ((16 << density) << 20) >> this->erase_shift; in flexonenand_set_boundary()
3584 return -EINVAL; in flexonenand_set_boundary()
3588 old = this->boundary[die] + (die * this->density_mask); in flexonenand_set_boundary()
3589 new = boundary + (die * this->density_mask); in flexonenand_set_boundary()
3597 this->command(mtd, FLEXONENAND_CMD_PI_ACCESS, die, 0); in flexonenand_set_boundary()
3598 this->wait(mtd, FL_SYNCING); in flexonenand_set_boundary()
3601 this->command(mtd, FLEXONENAND_CMD_READ_PI, die, 0); in flexonenand_set_boundary()
3602 this->wait(mtd, FL_READING); in flexonenand_set_boundary()
3604 thisboundary = this->read_word(this->base + ONENAND_DATARAM); in flexonenand_set_boundary()
3614 addr = die ? this->diesize[0] : 0; in flexonenand_set_boundary()
3619 this->command(mtd, ONENAND_CMD_ERASE, addr, 0); in flexonenand_set_boundary()
3620 ret = this->wait(mtd, FL_ERASING); in flexonenand_set_boundary()
3627 this->write_word(boundary, this->base + ONENAND_DATARAM); in flexonenand_set_boundary()
3628 this->command(mtd, ONENAND_CMD_PROG, addr, 0); in flexonenand_set_boundary()
3629 ret = this->wait(mtd, FL_WRITING); in flexonenand_set_boundary()
3636 this->command(mtd, FLEXONENAND_CMD_PI_UPDATE, die, 0); in flexonenand_set_boundary()
3637 ret = this->wait(mtd, FL_WRITING); in flexonenand_set_boundary()
3639 this->write_word(ONENAND_CMD_RESET, this->base + ONENAND_REG_COMMAND); in flexonenand_set_boundary()
3640 this->wait(mtd, FL_RESETTING); in flexonenand_set_boundary()
3642 /* Recalculate device size on boundary change*/ in flexonenand_set_boundary()
3649 * onenand_chip_probe - [OneNAND Interface] The generic chip probe
3657 struct onenand_chip *this = mtd->priv; in onenand_chip_probe()
3662 syscfg = this->read_word(this->base + ONENAND_REG_SYS_CFG1); in onenand_chip_probe()
3663 /* Clear Sync. Burst Read mode to read BootRAM */ in onenand_chip_probe()
3664 …this->write_word((syscfg & ~ONENAND_SYS_CFG1_SYNC_READ & ~ONENAND_SYS_CFG1_SYNC_WRITE), this->base… in onenand_chip_probe()
3667 this->write_word(ONENAND_CMD_READID, this->base + ONENAND_BOOTRAM); in onenand_chip_probe()
3669 /* Read manufacturer and device IDs from BootRAM */ in onenand_chip_probe()
3670 bram_maf_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x0); in onenand_chip_probe()
3671 bram_dev_id = this->read_word(this->base + ONENAND_BOOTRAM + 0x2); in onenand_chip_probe()
3673 /* Reset OneNAND to read default register values */ in onenand_chip_probe()
3674 this->write_word(ONENAND_CMD_RESET, this->base + ONENAND_BOOTRAM); in onenand_chip_probe()
3675 /* Wait reset */ in onenand_chip_probe()
3676 this->wait(mtd, FL_RESETTING); in onenand_chip_probe()
3679 this->write_word(syscfg, this->base + ONENAND_REG_SYS_CFG1); in onenand_chip_probe()
3683 return -ENXIO; in onenand_chip_probe()
3685 /* Read manufacturer and device IDs from Register */ in onenand_chip_probe()
3686 maf_id = this->read_word(this->base + ONENAND_REG_MANUFACTURER_ID); in onenand_chip_probe()
3687 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID); in onenand_chip_probe()
3691 return -ENXIO; in onenand_chip_probe()
3697 * onenand_probe - [OneNAND Interface] Probe the OneNAND device
3702 struct onenand_chip *this = mtd->priv; in onenand_probe()
3707 ret = this->chip_probe(mtd); in onenand_probe()
3712 dev_id = this->read_word(this->base + ONENAND_REG_DEVICE_ID); in onenand_probe()
3713 ver_id = this->read_word(this->base + ONENAND_REG_VERSION_ID); in onenand_probe()
3714 this->technology = this->read_word(this->base + ONENAND_REG_TECHNOLOGY); in onenand_probe()
3718 this->device_id = dev_id; in onenand_probe()
3719 this->version_id = ver_id; in onenand_probe()
3726 this->dies = ONENAND_IS_DDP(this) ? 2 : 1; in onenand_probe()
3728 mtd->numeraseregions = this->dies << 1; in onenand_probe()
3729 mtd->eraseregions = in onenand_probe()
3730 kcalloc(this->dies << 1, in onenand_probe()
3733 if (!mtd->eraseregions) in onenand_probe()
3734 return -ENOMEM; in onenand_probe()
3738 * For Flex-OneNAND, chipsize represents maximum possible device size. in onenand_probe()
3739 * mtd->size represents the actual device size. in onenand_probe()
3741 this->chipsize = (16 << density) << 20; in onenand_probe()
3745 mtd->writesize = this->read_word(this->base + ONENAND_REG_DATA_BUFFER_SIZE); in onenand_probe()
3748 mtd->writesize <<= 1; in onenand_probe()
3750 mtd->oobsize = mtd->writesize >> 5; in onenand_probe()
3752 mtd->erasesize = mtd->writesize << 6; in onenand_probe()
3754 * Flex-OneNAND SLC area has 64 pages per block. in onenand_probe()
3755 * Flex-OneNAND MLC area has 128 pages per block. in onenand_probe()
3759 mtd->erasesize <<= 1; in onenand_probe()
3761 this->erase_shift = ffs(mtd->erasesize) - 1; in onenand_probe()
3762 this->page_shift = ffs(mtd->writesize) - 1; in onenand_probe()
3763 this->page_mask = (1 << (this->erase_shift - this->page_shift)) - 1; in onenand_probe()
3766 this->density_mask = this->chipsize >> (this->erase_shift + 1); in onenand_probe()
3768 this->writesize = mtd->writesize; in onenand_probe()
3775 mtd->size = this->chipsize; in onenand_probe()
3780 * It is only valid if you turn on 2X program support, in onenand_probe()
3784 mtd->writesize <<= 1; in onenand_probe()
3785 mtd->erasesize <<= 1; in onenand_probe()
3792 * onenand_suspend - [MTD Interface] Suspend the OneNAND flash
3801 * onenand_resume - [MTD Interface] Resume the OneNAND flash
3806 struct onenand_chip *this = mtd->priv; in onenand_resume()
3808 if (this->state == FL_PM_SUSPENDED) in onenand_resume()
3816 * onenand_scan - [OneNAND Interface] Scan for the OneNAND device
3822 * The flash ID is read and the mtd/chip structures are
3828 struct onenand_chip *this = mtd->priv; in onenand_scan()
3830 if (!this->read_word) in onenand_scan()
3831 this->read_word = onenand_readw; in onenand_scan()
3832 if (!this->write_word) in onenand_scan()
3833 this->write_word = onenand_writew; in onenand_scan()
3835 if (!this->command) in onenand_scan()
3836 this->command = onenand_command; in onenand_scan()
3837 if (!this->wait) in onenand_scan()
3839 if (!this->bbt_wait) in onenand_scan()
3840 this->bbt_wait = onenand_bbt_wait; in onenand_scan()
3841 if (!this->unlock_all) in onenand_scan()
3842 this->unlock_all = onenand_unlock_all; in onenand_scan()
3844 if (!this->chip_probe) in onenand_scan()
3845 this->chip_probe = onenand_chip_probe; in onenand_scan()
3847 if (!this->read_bufferram) in onenand_scan()
3848 this->read_bufferram = onenand_read_bufferram; in onenand_scan()
3849 if (!this->write_bufferram) in onenand_scan()
3850 this->write_bufferram = onenand_write_bufferram; in onenand_scan()
3852 if (!this->block_markbad) in onenand_scan()
3853 this->block_markbad = onenand_default_block_markbad; in onenand_scan()
3854 if (!this->scan_bbt) in onenand_scan()
3855 this->scan_bbt = onenand_default_bbt; in onenand_scan()
3858 return -ENXIO; in onenand_scan()
3860 /* Set Sync. Burst Read after probing */ in onenand_scan()
3861 if (this->mmcontrol) { in onenand_scan()
3862 printk(KERN_INFO "OneNAND Sync. Burst Read support\n"); in onenand_scan()
3863 this->read_bufferram = onenand_sync_read_bufferram; in onenand_scan()
3867 if (!this->page_buf) { in onenand_scan()
3868 this->page_buf = kzalloc(mtd->writesize, GFP_KERNEL); in onenand_scan()
3869 if (!this->page_buf) in onenand_scan()
3870 return -ENOMEM; in onenand_scan()
3872 this->verify_buf = kzalloc(mtd->writesize, GFP_KERNEL); in onenand_scan()
3873 if (!this->verify_buf) { in onenand_scan()
3874 kfree(this->page_buf); in onenand_scan()
3875 return -ENOMEM; in onenand_scan()
3878 this->options |= ONENAND_PAGEBUF_ALLOC; in onenand_scan()
3880 if (!this->oob_buf) { in onenand_scan()
3881 this->oob_buf = kzalloc(mtd->oobsize, GFP_KERNEL); in onenand_scan()
3882 if (!this->oob_buf) { in onenand_scan()
3883 if (this->options & ONENAND_PAGEBUF_ALLOC) { in onenand_scan()
3884 this->options &= ~ONENAND_PAGEBUF_ALLOC; in onenand_scan()
3886 kfree(this->verify_buf); in onenand_scan()
3888 kfree(this->page_buf); in onenand_scan()
3890 return -ENOMEM; in onenand_scan()
3892 this->options |= ONENAND_OOBBUF_ALLOC; in onenand_scan()
3895 this->state = FL_READY; in onenand_scan()
3896 init_waitqueue_head(&this->wq); in onenand_scan()
3897 spin_lock_init(&this->chip_lock); in onenand_scan()
3902 switch (mtd->oobsize) { in onenand_scan()
3906 mtd->subpage_sft = 0; in onenand_scan()
3909 mtd->subpage_sft = 2; in onenand_scan()
3912 mtd->subpage_sft = 0; in onenand_scan()
3916 mtd->subpage_sft = 2; in onenand_scan()
3921 mtd->subpage_sft = 1; in onenand_scan()
3926 __func__, mtd->oobsize); in onenand_scan()
3927 mtd->subpage_sft = 0; in onenand_scan()
3933 this->subpagesize = mtd->writesize >> mtd->subpage_sft; in onenand_scan()
3943 mtd->oobavail = ret; in onenand_scan()
3945 mtd->ecc_strength = 1; in onenand_scan()
3948 mtd->type = ONENAND_IS_MLC(this) ? MTD_MLCNANDFLASH : MTD_NANDFLASH; in onenand_scan()
3949 mtd->flags = MTD_CAP_NANDFLASH; in onenand_scan()
3950 mtd->_erase = onenand_erase; in onenand_scan()
3951 mtd->_point = NULL; in onenand_scan()
3952 mtd->_unpoint = NULL; in onenand_scan()
3953 mtd->_read_oob = onenand_read_oob; in onenand_scan()
3954 mtd->_write_oob = onenand_write_oob; in onenand_scan()
3955 mtd->_panic_write = onenand_panic_write; in onenand_scan()
3957 mtd->_get_fact_prot_info = onenand_get_fact_prot_info; in onenand_scan()
3958 mtd->_read_fact_prot_reg = onenand_read_fact_prot_reg; in onenand_scan()
3959 mtd->_get_user_prot_info = onenand_get_user_prot_info; in onenand_scan()
3960 mtd->_read_user_prot_reg = onenand_read_user_prot_reg; in onenand_scan()
3961 mtd->_write_user_prot_reg = onenand_write_user_prot_reg; in onenand_scan()
3962 mtd->_lock_user_prot_reg = onenand_lock_user_prot_reg; in onenand_scan()
3964 mtd->_sync = onenand_sync; in onenand_scan()
3965 mtd->_lock = onenand_lock; in onenand_scan()
3966 mtd->_unlock = onenand_unlock; in onenand_scan()
3967 mtd->_suspend = onenand_suspend; in onenand_scan()
3968 mtd->_resume = onenand_resume; in onenand_scan()
3969 mtd->_block_isbad = onenand_block_isbad; in onenand_scan()
3970 mtd->_block_markbad = onenand_block_markbad; in onenand_scan()
3971 mtd->owner = THIS_MODULE; in onenand_scan()
3972 mtd->writebufsize = mtd->writesize; in onenand_scan()
3975 if (!(this->options & ONENAND_SKIP_INITIAL_UNLOCKING)) in onenand_scan()
3976 this->unlock_all(mtd); in onenand_scan()
3979 this->badblockpos = ONENAND_BADBLOCK_POS; in onenand_scan()
3981 ret = this->scan_bbt(mtd); in onenand_scan()
3985 /* Change Flex-OneNAND boundaries if required */ in onenand_scan()
3994 * onenand_release - [OneNAND Interface] Free resources held by the OneNAND device
3999 struct onenand_chip *this = mtd->priv; in onenand_release()
4005 if (this->bbm) { in onenand_release()
4006 struct bbm_info *bbm = this->bbm; in onenand_release()
4007 kfree(bbm->bbt); in onenand_release()
4008 kfree(this->bbm); in onenand_release()
4011 if (this->options & ONENAND_PAGEBUF_ALLOC) { in onenand_release()
4012 kfree(this->page_buf); in onenand_release()
4014 kfree(this->verify_buf); in onenand_release()
4017 if (this->options & ONENAND_OOBBUF_ALLOC) in onenand_release()
4018 kfree(this->oob_buf); in onenand_release()
4019 kfree(mtd->eraseregions); in onenand_release()