Lines Matching refs:mtd
66 static int flexonenand_ooblayout_ecc(struct mtd_info *mtd, int section, in flexonenand_ooblayout_ecc() argument
78 static int flexonenand_ooblayout_free(struct mtd_info *mtd, int section, in flexonenand_ooblayout_free() argument
102 static int onenand_ooblayout_128_ecc(struct mtd_info *mtd, int section, in onenand_ooblayout_128_ecc() argument
114 static int onenand_ooblayout_128_free(struct mtd_info *mtd, int section, in onenand_ooblayout_128_free() argument
138 static int onenand_ooblayout_32_64_ecc(struct mtd_info *mtd, int section, in onenand_ooblayout_32_64_ecc() argument
150 static int onenand_ooblayout_32_64_free(struct mtd_info *mtd, int section, in onenand_ooblayout_32_64_free() argument
153 int sections = (mtd->oobsize / 32) * 2; in onenand_ooblayout_32_64_free()
377 int flexonenand_region(struct mtd_info *mtd, loff_t addr) in flexonenand_region() argument
381 for (i = 0; i < mtd->numeraseregions; i++) in flexonenand_region()
382 if (addr < mtd->eraseregions[i].offset) in flexonenand_region()
398 static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t len) in onenand_command() argument
400 struct onenand_chip *this = mtd->priv; in onenand_command()
553 static int onenand_wait(struct mtd_info *mtd, int state) in onenand_wait() argument
555 struct onenand_chip * this = mtd->priv; in onenand_wait()
588 mtd->ecc_stats.failed++; in onenand_wait()
593 mtd->ecc_stats.corrected++; in onenand_wait()
651 static int onenand_interrupt_wait(struct mtd_info *mtd, int state) in onenand_interrupt_wait() argument
653 struct onenand_chip *this = mtd->priv; in onenand_interrupt_wait()
657 return onenand_wait(mtd, state); in onenand_interrupt_wait()
667 static int onenand_try_interrupt_wait(struct mtd_info *mtd, int state) in onenand_try_interrupt_wait() argument
669 struct onenand_chip *this = mtd->priv; in onenand_try_interrupt_wait()
687 return onenand_wait(mtd, state); in onenand_try_interrupt_wait()
698 static void onenand_setup_wait(struct mtd_info *mtd) in onenand_setup_wait() argument
700 struct onenand_chip *this = mtd->priv; in onenand_setup_wait()
733 static inline int onenand_bufferram_offset(struct mtd_info *mtd, int area) in onenand_bufferram_offset() argument
735 struct onenand_chip *this = mtd->priv; in onenand_bufferram_offset()
742 return mtd->oobsize; in onenand_bufferram_offset()
758 static int onenand_read_bufferram(struct mtd_info *mtd, int area, in onenand_read_bufferram() argument
761 struct onenand_chip *this = mtd->priv; in onenand_read_bufferram()
766 bufferram += onenand_bufferram_offset(mtd, area); in onenand_read_bufferram()
794 static int onenand_sync_read_bufferram(struct mtd_info *mtd, int area, in onenand_sync_read_bufferram() argument
797 struct onenand_chip *this = mtd->priv; in onenand_sync_read_bufferram()
802 bufferram += onenand_bufferram_offset(mtd, area); in onenand_sync_read_bufferram()
804 this->mmcontrol(mtd, ONENAND_SYS_CFG1_SYNC_READ); in onenand_sync_read_bufferram()
819 this->mmcontrol(mtd, 0); in onenand_sync_read_bufferram()
834 static int onenand_write_bufferram(struct mtd_info *mtd, int area, in onenand_write_bufferram() argument
837 struct onenand_chip *this = mtd->priv; in onenand_write_bufferram()
842 bufferram += onenand_bufferram_offset(mtd, area); in onenand_write_bufferram()
873 static int onenand_get_2x_blockpage(struct mtd_info *mtd, loff_t addr) in onenand_get_2x_blockpage() argument
875 struct onenand_chip *this = mtd->priv; in onenand_get_2x_blockpage()
897 static int onenand_check_bufferram(struct mtd_info *mtd, loff_t addr) in onenand_check_bufferram() argument
899 struct onenand_chip *this = mtd->priv; in onenand_check_bufferram()
904 blockpage = onenand_get_2x_blockpage(mtd, addr); in onenand_check_bufferram()
939 static void onenand_update_bufferram(struct mtd_info *mtd, loff_t addr, in onenand_update_bufferram() argument
942 struct onenand_chip *this = mtd->priv; in onenand_update_bufferram()
947 blockpage = onenand_get_2x_blockpage(mtd, addr); in onenand_update_bufferram()
972 static void onenand_invalidate_bufferram(struct mtd_info *mtd, loff_t addr, in onenand_invalidate_bufferram() argument
975 struct onenand_chip *this = mtd->priv; in onenand_invalidate_bufferram()
994 static int onenand_get_device(struct mtd_info *mtd, int new_state) in onenand_get_device() argument
996 struct onenand_chip *this = mtd->priv; in onenand_get_device()
1008 this->enable(mtd); in onenand_get_device()
1031 static void onenand_release_device(struct mtd_info *mtd) in onenand_release_device() argument
1033 struct onenand_chip *this = mtd->priv; in onenand_release_device()
1036 this->disable(mtd); in onenand_release_device()
1051 static int onenand_transfer_auto_oob(struct mtd_info *mtd, uint8_t *buf, int column, in onenand_transfer_auto_oob() argument
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()
1075 static int onenand_recover_lsb(struct mtd_info *mtd, loff_t addr, int status) in onenand_recover_lsb() argument
1077 struct onenand_chip *this = mtd->priv; in onenand_recover_lsb()
1089 i = flexonenand_region(mtd, addr); in onenand_recover_lsb()
1090 if (mtd->eraseregions[i].erasesize < (1 << this->erase_shift)) 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()
1114 static int onenand_mlc_read_ops_nolock(struct mtd_info *mtd, loff_t from, in onenand_mlc_read_ops_nolock() argument
1117 struct onenand_chip *this = mtd->priv; in onenand_mlc_read_ops_nolock()
1131 oobsize = mtd_oobavail(mtd, ops); 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()
1143 stats = mtd->ecc_stats; in onenand_mlc_read_ops_nolock()
1154 if (!onenand_check_bufferram(mtd, from)) { 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()
1159 ret = onenand_recover_lsb(mtd, from, ret); in onenand_mlc_read_ops_nolock()
1160 onenand_update_bufferram(mtd, from, !ret); in onenand_mlc_read_ops_nolock()
1167 this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen); in onenand_mlc_read_ops_nolock()
1173 onenand_transfer_auto_oob(mtd, oobbuf, oobcolumn, thisooblen); in onenand_mlc_read_ops_nolock()
1175 this->read_bufferram(mtd, ONENAND_SPARERAM, oobbuf, oobcolumn, thisooblen); in onenand_mlc_read_ops_nolock()
1200 if (mtd->ecc_stats.failed - stats.failed) in onenand_mlc_read_ops_nolock()
1204 return mtd->ecc_stats.corrected != stats.corrected ? 1 : 0; in onenand_mlc_read_ops_nolock()
1215 static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from, in onenand_read_ops_nolock() argument
1218 struct onenand_chip *this = mtd->priv; in onenand_read_ops_nolock()
1232 oobsize = mtd_oobavail(mtd, ops); 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()
1244 stats = mtd->ecc_stats; in onenand_read_ops_nolock()
1250 if (!onenand_check_bufferram(mtd, from)) { 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()
1253 onenand_update_bufferram(mtd, from, !ret); in onenand_read_ops_nolock()
1268 this->command(mtd, ONENAND_CMD_READ, from, writesize); in onenand_read_ops_nolock()
1283 this->read_bufferram(mtd, ONENAND_DATARAM, buf, column, thislen); in onenand_read_ops_nolock()
1291 onenand_transfer_auto_oob(mtd, oobbuf, oobcolumn, thisooblen); in onenand_read_ops_nolock()
1293 this->read_bufferram(mtd, ONENAND_SPARERAM, oobbuf, oobcolumn, thisooblen); in onenand_read_ops_nolock()
1312 ret = this->wait(mtd, FL_READING); in onenand_read_ops_nolock()
1313 onenand_update_bufferram(mtd, from, !ret); in onenand_read_ops_nolock()
1329 if (mtd->ecc_stats.failed - stats.failed) in onenand_read_ops_nolock()
1333 return mtd->ecc_stats.corrected != stats.corrected ? 1 : 0; in onenand_read_ops_nolock()
1344 static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from, in onenand_read_oob_nolock() argument
1347 struct onenand_chip *this = mtd->priv; 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()
1376 stats = mtd->ecc_stats; in onenand_read_oob_nolock()
1386 this->command(mtd, readcmd, from, mtd->oobsize); in onenand_read_oob_nolock()
1388 onenand_update_bufferram(mtd, from, 0); in onenand_read_oob_nolock()
1390 ret = this->wait(mtd, FL_READING); in onenand_read_oob_nolock()
1392 ret = onenand_recover_lsb(mtd, from, ret); in onenand_read_oob_nolock()
1401 onenand_transfer_auto_oob(mtd, buf, column, thislen); in onenand_read_oob_nolock()
1403 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen); in onenand_read_oob_nolock()
1415 from += mtd->writesize; in onenand_read_oob_nolock()
1425 if (mtd->ecc_stats.failed - stats.failed) in onenand_read_oob_nolock()
1439 static int onenand_read_oob(struct mtd_info *mtd, loff_t from, in onenand_read_oob() argument
1442 struct onenand_chip *this = mtd->priv; in onenand_read_oob()
1456 onenand_get_device(mtd, FL_READING); in onenand_read_oob()
1458 old_stats = mtd->ecc_stats; in onenand_read_oob()
1462 onenand_mlc_read_ops_nolock(mtd, from, ops) : in onenand_read_oob()
1463 onenand_read_ops_nolock(mtd, from, ops); in onenand_read_oob()
1465 ret = onenand_read_oob_nolock(mtd, from, ops); in onenand_read_oob()
1469 mtd->ecc_stats.failed - old_stats.failed; in onenand_read_oob()
1471 mtd->ecc_stats.corrected - old_stats.corrected; in onenand_read_oob()
1474 onenand_release_device(mtd); in onenand_read_oob()
1486 static int onenand_bbt_wait(struct mtd_info *mtd, int state) in onenand_bbt_wait() argument
1488 struct onenand_chip *this = mtd->priv; in onenand_bbt_wait()
1538 int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from, in onenand_bbt_read_oob() argument
1541 struct onenand_chip *this = mtd->priv; in onenand_bbt_read_oob()
1554 if (unlikely((from + len) > mtd->size)) { in onenand_bbt_read_oob()
1561 onenand_get_device(mtd, FL_READING); in onenand_bbt_read_oob()
1563 column = from & (mtd->oobsize - 1); 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()
1575 onenand_update_bufferram(mtd, from, 0); in onenand_bbt_read_oob()
1577 ret = this->bbt_wait(mtd, FL_READING); in onenand_bbt_read_oob()
1579 ret = onenand_recover_lsb(mtd, from, ret); in onenand_bbt_read_oob()
1584 this->read_bufferram(mtd, ONENAND_SPARERAM, buf, column, thislen); in onenand_bbt_read_oob()
1600 onenand_release_device(mtd); in onenand_bbt_read_oob()
1613 static int onenand_verify_oob(struct mtd_info *mtd, const u_char *buf, loff_t to) in onenand_verify_oob() argument
1615 struct onenand_chip *this = mtd->priv; in onenand_verify_oob()
1621 this->command(mtd, readcmd, to, mtd->oobsize); in onenand_verify_oob()
1622 onenand_update_bufferram(mtd, to, 0); 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()
1642 static int onenand_verify(struct mtd_info *mtd, const u_char *buf, loff_t addr, size_t len) in onenand_verify() argument
1644 struct onenand_chip *this = mtd->priv; in onenand_verify()
1653 this->command(mtd, ONENAND_CMD_READ, addr, this->writesize); in onenand_verify()
1655 onenand_update_bufferram(mtd, addr, 0); in onenand_verify()
1657 ret = this->wait(mtd, FL_READING); in onenand_verify()
1661 onenand_update_bufferram(mtd, addr, 1); in onenand_verify()
1663 this->read_bufferram(mtd, ONENAND_DATARAM, this->verify_buf, 0, mtd->writesize); in onenand_verify()
1683 static void onenand_panic_wait(struct mtd_info *mtd) in onenand_panic_wait() argument
1685 struct onenand_chip *this = mtd->priv; in onenand_panic_wait()
1707 static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len, in onenand_panic_write() argument
1710 struct onenand_chip *this = mtd->priv; in onenand_panic_write()
1718 onenand_panic_wait(mtd); 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()
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()
1752 onenand_panic_wait(mtd); in onenand_panic_write()
1755 onenand_update_bufferram(mtd, to, !subpage); in onenand_panic_write()
1758 onenand_update_bufferram(mtd, to + this->writesize, !subpage); in onenand_panic_write()
1783 static int onenand_fill_auto_oob(struct mtd_info *mtd, u_char *oob_buf, in onenand_fill_auto_oob() argument
1786 return mtd_ooblayout_set_databytes(mtd, buf, oob_buf, column, thislen); in onenand_fill_auto_oob()
1797 static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to, in onenand_write_ops_nolock() argument
1800 struct onenand_chip *this = mtd->priv; in onenand_write_ops_nolock()
1828 oobsize = mtd_oobavail(mtd, ops); 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()
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()
1853 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, mtd->writesize); in onenand_write_ops_nolock()
1860 memset(oobbuf, 0xff, mtd->oobsize); in onenand_write_ops_nolock()
1862 onenand_fill_auto_oob(mtd, oobbuf, oob, oobcolumn, thisooblen); in onenand_write_ops_nolock()
1872 this->write_bufferram(mtd, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize); in onenand_write_ops_nolock()
1883 ret = this->wait(mtd, FL_WRITING); in onenand_write_ops_nolock()
1886 onenand_update_bufferram(mtd, prev, !ret && !prev_subpage); in onenand_write_ops_nolock()
1896 ret = onenand_verify(mtd, buf - len, to - len, len); in onenand_write_ops_nolock()
1918 this->command(mtd, cmd, to, mtd->writesize); in onenand_write_ops_nolock()
1924 ret = this->wait(mtd, FL_WRITING); in onenand_write_ops_nolock()
1927 onenand_update_bufferram(mtd, to, !ret && !subpage); in onenand_write_ops_nolock()
1935 ret = onenand_verify(mtd, buf, to, thislen); in onenand_write_ops_nolock()
1961 onenand_invalidate_bufferram(mtd, 0, -1); in onenand_write_ops_nolock()
1978 static int onenand_write_oob_nolock(struct mtd_info *mtd, loff_t to, in onenand_write_oob_nolock() argument
1981 struct onenand_chip *this = mtd->priv; 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()
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()
2033 onenand_fill_auto_oob(mtd, oobbuf, buf, column, thislen); 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()
2047 onenand_update_bufferram(mtd, to, 0); 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()
2059 ret = onenand_verify_oob(mtd, oobbuf, to); in onenand_write_oob_nolock()
2070 to += mtd->writesize; in onenand_write_oob_nolock()
2086 static int onenand_write_oob(struct mtd_info *mtd, loff_t to, in onenand_write_oob() argument
2101 onenand_get_device(mtd, FL_WRITING); in onenand_write_oob()
2103 ret = onenand_write_ops_nolock(mtd, to, ops); in onenand_write_oob()
2105 ret = onenand_write_oob_nolock(mtd, to, ops); in onenand_write_oob()
2106 onenand_release_device(mtd); in onenand_write_oob()
2120 static int onenand_block_isbad_nolock(struct mtd_info *mtd, loff_t ofs, int allowbbt) in onenand_block_isbad_nolock() argument
2122 struct onenand_chip *this = mtd->priv; in onenand_block_isbad_nolock()
2126 return bbm->isbad_bbt(mtd, ofs, allowbbt); in onenand_block_isbad_nolock()
2130 static int onenand_multiblock_erase_verify(struct mtd_info *mtd, in onenand_multiblock_erase_verify() argument
2133 struct onenand_chip *this = mtd->priv; 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()
2162 static int onenand_multiblock_erase(struct mtd_info *mtd, in onenand_multiblock_erase() argument
2166 struct onenand_chip *this = mtd->priv; in onenand_multiblock_erase()
2182 if (onenand_block_isbad_nolock(mtd, addr, 0)) { in onenand_multiblock_erase()
2216 this->command(mtd, ONENAND_CMD_MULTIBLOCK_ERASE, in onenand_multiblock_erase()
2218 onenand_invalidate_bufferram(mtd, addr, block_size); in onenand_multiblock_erase()
2220 ret = this->wait(mtd, FL_PREPARING_ERASE); in onenand_multiblock_erase()
2236 this->command(mtd, ONENAND_CMD_ERASE, addr, block_size); in onenand_multiblock_erase()
2237 onenand_invalidate_bufferram(mtd, addr, block_size); in onenand_multiblock_erase()
2239 ret = this->wait(mtd, FL_ERASING); in onenand_multiblock_erase()
2254 if (onenand_multiblock_erase_verify(mtd, &verify_instr)) { in onenand_multiblock_erase()
2273 static int onenand_block_by_block_erase(struct mtd_info *mtd, in onenand_block_by_block_erase() argument
2278 struct onenand_chip *this = mtd->priv; in onenand_block_by_block_erase()
2294 if (onenand_block_isbad_nolock(mtd, addr, 0)) { in onenand_block_by_block_erase()
2301 this->command(mtd, ONENAND_CMD_ERASE, addr, block_size); in onenand_block_by_block_erase()
2303 onenand_invalidate_bufferram(mtd, addr, block_size); in onenand_block_by_block_erase()
2305 ret = this->wait(mtd, FL_ERASING); in onenand_block_by_block_erase()
2343 static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) in onenand_erase() argument
2345 struct onenand_chip *this = mtd->priv; in onenand_erase()
2359 int i = flexonenand_region(mtd, addr); in onenand_erase()
2361 region = &mtd->eraseregions[i]; in onenand_erase()
2384 onenand_get_device(mtd, FL_ERASING); in onenand_erase()
2389 ret = onenand_block_by_block_erase(mtd, instr, in onenand_erase()
2392 ret = onenand_multiblock_erase(mtd, instr, block_size); in onenand_erase()
2396 onenand_release_device(mtd); in onenand_erase()
2407 static void onenand_sync(struct mtd_info *mtd) in onenand_sync() argument
2412 onenand_get_device(mtd, FL_SYNCING); in onenand_sync()
2415 onenand_release_device(mtd); in onenand_sync()
2425 static int onenand_block_isbad(struct mtd_info *mtd, loff_t ofs) in onenand_block_isbad() argument
2429 onenand_get_device(mtd, FL_READING); in onenand_block_isbad()
2430 ret = onenand_block_isbad_nolock(mtd, ofs, 0); in onenand_block_isbad()
2431 onenand_release_device(mtd); in onenand_block_isbad()
2443 static int onenand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) in onenand_default_block_markbad() argument
2445 struct onenand_chip *this = mtd->priv; in onenand_default_block_markbad()
2462 ofs += mtd->oobsize + (this->badblockpos & ~0x01); in onenand_default_block_markbad()
2467 return onenand_write_oob_nolock(mtd, ofs, &ops); in onenand_default_block_markbad()
2477 static int onenand_block_markbad(struct mtd_info *mtd, loff_t ofs) in onenand_block_markbad() argument
2479 struct onenand_chip *this = mtd->priv; in onenand_block_markbad()
2482 ret = onenand_block_isbad(mtd, ofs); in onenand_block_markbad()
2490 onenand_get_device(mtd, FL_WRITING); in onenand_block_markbad()
2491 ret = this->block_markbad(mtd, ofs); in onenand_block_markbad()
2492 onenand_release_device(mtd); in onenand_block_markbad()
2505 static int onenand_do_lock_cmd(struct mtd_info *mtd, loff_t ofs, size_t len, int cmd) in onenand_do_lock_cmd() argument
2507 struct onenand_chip *this = mtd->priv; 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()
2556 this->command(mtd, cmd, 0, 0); in onenand_do_lock_cmd()
2559 this->wait(mtd, FL_LOCKING); in onenand_do_lock_cmd()
2584 static int onenand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) in onenand_lock() argument
2588 onenand_get_device(mtd, FL_LOCKING); in onenand_lock()
2589 ret = onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_LOCK); in onenand_lock()
2590 onenand_release_device(mtd); in onenand_lock()
2602 static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) in onenand_unlock() argument
2606 onenand_get_device(mtd, FL_LOCKING); in onenand_unlock()
2607 ret = onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_UNLOCK); in onenand_unlock()
2608 onenand_release_device(mtd); in onenand_unlock()
2652 static void onenand_unlock_all(struct mtd_info *mtd) in onenand_unlock_all() argument
2654 struct onenand_chip *this = mtd->priv; in onenand_unlock_all()
2656 loff_t len = mtd->size; 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()
2688 onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_UNLOCK); in onenand_unlock_all()
2700 static int onenand_otp_command(struct mtd_info *mtd, int cmd, loff_t addr, in onenand_otp_command() argument
2703 struct onenand_chip *this = mtd->priv; in onenand_otp_command()
2776 static int onenand_otp_write_oob_nolock(struct mtd_info *mtd, loff_t to, in onenand_otp_write_oob_nolock() argument
2779 struct onenand_chip *this = mtd->priv; 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()
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()
2844 onenand_update_bufferram(mtd, to, 0); 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()
2883 to += mtd->writesize; in onenand_otp_write_oob_nolock()
2894 typedef int (*otp_op_t)(struct mtd_info *mtd, loff_t form, size_t len,
2907 static int do_otp_read(struct mtd_info *mtd, loff_t from, size_t len, in do_otp_read() argument
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()
2924 onenand_mlc_read_ops_nolock(mtd, from, &ops) : in do_otp_read()
2925 onenand_read_ops_nolock(mtd, from, &ops); 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()
2944 static int do_otp_write(struct mtd_info *mtd, loff_t to, size_t len, in do_otp_write() argument
2947 struct onenand_chip *this = mtd->priv; in do_otp_write()
2953 if (len < mtd->writesize) { in do_otp_write()
2955 memset(this->page_buf + len, 0xff, mtd->writesize - len); 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()
2968 ret = onenand_write_ops_nolock(mtd, to, &ops); 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()
2988 static int do_otp_lock(struct mtd_info *mtd, loff_t from, size_t len, in do_otp_lock() argument
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()
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()
3019 ret = onenand_otp_write_oob_nolock(mtd, from, &ops); in do_otp_lock()
3038 static int onenand_otp_walk(struct mtd_info *mtd, loff_t from, size_t len, in onenand_otp_walk() argument
3042 struct onenand_chip *this = mtd->priv; in onenand_otp_walk()
3056 from += mtd->writesize * 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()
3069 onenand_get_device(mtd, FL_OTPING); in onenand_otp_walk()
3082 otpinfo->length = mtd->writesize; in onenand_otp_walk()
3085 from += mtd->writesize; in onenand_otp_walk()
3091 ret = action(mtd, from, len, &tmp_retlen, buf); in onenand_otp_walk()
3102 onenand_release_device(mtd); in onenand_otp_walk()
3116 static int onenand_get_fact_prot_info(struct mtd_info *mtd, size_t len, in onenand_get_fact_prot_info() argument
3119 return onenand_otp_walk(mtd, 0, len, retlen, (u_char *) buf, NULL, in onenand_get_fact_prot_info()
3133 static int onenand_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, in onenand_read_fact_prot_reg() argument
3136 return onenand_otp_walk(mtd, from, len, retlen, buf, do_otp_read, MTD_OTP_FACTORY); in onenand_read_fact_prot_reg()
3148 static int onenand_get_user_prot_info(struct mtd_info *mtd, size_t len, in onenand_get_user_prot_info() argument
3151 return onenand_otp_walk(mtd, 0, len, retlen, (u_char *) buf, NULL, in onenand_get_user_prot_info()
3165 static int onenand_read_user_prot_reg(struct mtd_info *mtd, loff_t from, in onenand_read_user_prot_reg() argument
3168 return onenand_otp_walk(mtd, from, len, retlen, buf, do_otp_read, MTD_OTP_USER); in onenand_read_user_prot_reg()
3181 static int onenand_write_user_prot_reg(struct mtd_info *mtd, loff_t from, in onenand_write_user_prot_reg() argument
3184 return onenand_otp_walk(mtd, from, len, retlen, (u_char *)buf, in onenand_write_user_prot_reg()
3196 static int onenand_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, in onenand_lock_user_prot_reg() argument
3199 struct onenand_chip *this = mtd->priv; in onenand_lock_user_prot_reg()
3206 : mtd->oobsize); in onenand_lock_user_prot_reg()
3215 len = FLEXONENAND(this) ? mtd->writesize : 16; in onenand_lock_user_prot_reg()
3236 ret = onenand_otp_walk(mtd, from, len, &retlen, buf, do_otp_lock, MTD_OTP_USER); in onenand_lock_user_prot_reg()
3251 static void onenand_check_features(struct mtd_info *mtd) in onenand_check_features() argument
3253 struct onenand_chip *this = mtd->priv; in onenand_check_features()
3394 static int flexonenand_get_boundary(struct mtd_info *mtd) in flexonenand_get_boundary() argument
3396 struct onenand_chip *this = mtd->priv; 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()
3418 this->command(mtd, ONENAND_CMD_RESET, 0, 0); in flexonenand_get_boundary()
3419 this->wait(mtd, FL_RESETTING); in flexonenand_get_boundary()
3435 static void flexonenand_get_size(struct mtd_info *mtd) in flexonenand_get_size() argument
3437 struct onenand_chip *this = mtd->priv; in flexonenand_get_size()
3448 mtd->numeraseregions = this->dies << 1; in flexonenand_get_size()
3451 flexonenand_get_boundary(mtd); 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()
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()
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()
3475 ofs += mtd->eraseregions[i].numblocks << 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()
3498 mtd->size += this->diesize[die]; in flexonenand_get_size()
3516 static int flexonenand_check_blocks_erased(struct mtd_info *mtd, int start, int end) in flexonenand_check_blocks_erased() argument
3518 struct onenand_chip *this = mtd->priv; in flexonenand_check_blocks_erased()
3524 .ooblen = mtd->oobsize, in flexonenand_check_blocks_erased()
3534 if (onenand_block_isbad_nolock(mtd, addr, 0)) in flexonenand_check_blocks_erased()
3541 ret = onenand_read_oob_nolock(mtd, addr, &ops); in flexonenand_check_blocks_erased()
3545 for (i = 0; i < mtd->oobsize; i++) in flexonenand_check_blocks_erased()
3549 if (i != mtd->oobsize) { in flexonenand_check_blocks_erased()
3562 static int flexonenand_set_boundary(struct mtd_info *mtd, int die, in flexonenand_set_boundary() argument
3565 struct onenand_chip *this = mtd->priv; in flexonenand_set_boundary()
3590 ret = flexonenand_check_blocks_erased(mtd, min(old, new) + 1, max(old, new)); 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()
3619 this->command(mtd, ONENAND_CMD_ERASE, addr, 0); in flexonenand_set_boundary()
3620 ret = this->wait(mtd, FL_ERASING); 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()
3640 this->wait(mtd, FL_RESETTING); in flexonenand_set_boundary()
3643 flexonenand_get_size(mtd); in flexonenand_set_boundary()
3655 static int onenand_chip_probe(struct mtd_info *mtd) in onenand_chip_probe() argument
3657 struct onenand_chip *this = mtd->priv; in onenand_chip_probe()
3676 this->wait(mtd, FL_RESETTING); in onenand_chip_probe()
3700 static int onenand_probe(struct mtd_info *mtd) in onenand_probe() argument
3702 struct onenand_chip *this = mtd->priv; in onenand_probe()
3707 ret = this->chip_probe(mtd); in onenand_probe()
3722 onenand_check_features(mtd); in onenand_probe()
3728 mtd->numeraseregions = this->dies << 1; in onenand_probe()
3729 mtd->eraseregions = in onenand_probe()
3733 if (!mtd->eraseregions) 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()
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()
3768 this->writesize = mtd->writesize; in onenand_probe()
3773 flexonenand_get_size(mtd); in onenand_probe()
3775 mtd->size = this->chipsize; in onenand_probe()
3784 mtd->writesize <<= 1; in onenand_probe()
3785 mtd->erasesize <<= 1; in onenand_probe()
3795 static int onenand_suspend(struct mtd_info *mtd) in onenand_suspend() argument
3797 return onenand_get_device(mtd, FL_PM_SUSPENDED); in onenand_suspend()
3804 static void onenand_resume(struct mtd_info *mtd) in onenand_resume() argument
3806 struct onenand_chip *this = mtd->priv; in onenand_resume()
3809 onenand_release_device(mtd); in onenand_resume()
3825 int onenand_scan(struct mtd_info *mtd, int maxchips) in onenand_scan() argument
3828 struct onenand_chip *this = mtd->priv; in onenand_scan()
3838 onenand_setup_wait(mtd); in onenand_scan()
3857 if (onenand_probe(mtd)) in onenand_scan()
3868 this->page_buf = kzalloc(mtd->writesize, GFP_KERNEL); in onenand_scan()
3872 this->verify_buf = kzalloc(mtd->writesize, GFP_KERNEL); in onenand_scan()
3881 this->oob_buf = kzalloc(mtd->oobsize, GFP_KERNEL); in onenand_scan()
3902 switch (mtd->oobsize) { in onenand_scan()
3905 mtd_set_ooblayout(mtd, &flexonenand_ooblayout_ops); in onenand_scan()
3906 mtd->subpage_sft = 0; in onenand_scan()
3908 mtd_set_ooblayout(mtd, &onenand_oob_128_ooblayout_ops); in onenand_scan()
3909 mtd->subpage_sft = 2; in onenand_scan()
3912 mtd->subpage_sft = 0; in onenand_scan()
3915 mtd_set_ooblayout(mtd, &onenand_oob_32_64_ooblayout_ops); in onenand_scan()
3916 mtd->subpage_sft = 2; in onenand_scan()
3920 mtd_set_ooblayout(mtd, &onenand_oob_32_64_ooblayout_ops); 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()
3929 mtd_set_ooblayout(mtd, &onenand_oob_32_64_ooblayout_ops); in onenand_scan()
3933 this->subpagesize = mtd->writesize >> mtd->subpage_sft; in onenand_scan()
3939 ret = mtd_ooblayout_count_freebytes(mtd); 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()
3976 this->unlock_all(mtd); in onenand_scan()
3981 ret = this->scan_bbt(mtd); in onenand_scan()
3987 flexonenand_set_boundary(mtd, i, flex_bdry[2 * i], in onenand_scan()
3997 void onenand_release(struct mtd_info *mtd) in onenand_release() argument
3999 struct onenand_chip *this = mtd->priv; in onenand_release()
4002 mtd_device_unregister(mtd); in onenand_release()
4019 kfree(mtd->eraseregions); in onenand_release()