Lines Matching refs:this
166 static int read_bbt(struct nand_chip *this, uint8_t *buf, int page, int num, in read_bbt() argument
169 struct mtd_info *mtd = nand_to_mtd(this); in read_bbt()
180 from = ((loff_t)page) << this->page_shift; in read_bbt()
183 len = min(totlen, (size_t)(1 << this->bbt_erase_shift)); in read_bbt()
219 this->bbt_erase_shift); in read_bbt()
220 bbt_mark_entry(this, offs + act, in read_bbt()
231 this->bbt_erase_shift); in read_bbt()
234 bbt_mark_entry(this, offs + act, in read_bbt()
237 bbt_mark_entry(this, offs + act, in read_bbt()
259 static int read_abs_bbt(struct nand_chip *this, uint8_t *buf, in read_abs_bbt() argument
262 struct mtd_info *mtd = nand_to_mtd(this); in read_abs_bbt()
263 u64 targetsize = nanddev_target_size(&this->base); in read_abs_bbt()
268 for (i = 0; i < nanddev_ntargets(&this->base); i++) { in read_abs_bbt()
270 res = read_bbt(this, buf, td->pages[i], in read_abs_bbt()
271 targetsize >> this->bbt_erase_shift, in read_abs_bbt()
275 offs += targetsize >> this->bbt_erase_shift; in read_abs_bbt()
278 res = read_bbt(this, buf, td->pages[0], in read_abs_bbt()
279 mtd->size >> this->bbt_erase_shift, td, 0); in read_abs_bbt()
287 static int scan_read_data(struct nand_chip *this, uint8_t *buf, loff_t offs, in scan_read_data() argument
290 struct mtd_info *mtd = nand_to_mtd(this); in scan_read_data()
312 static int scan_read_oob(struct nand_chip *this, uint8_t *buf, loff_t offs, in scan_read_oob() argument
315 struct mtd_info *mtd = nand_to_mtd(this); in scan_read_oob()
343 static int scan_read(struct nand_chip *this, uint8_t *buf, loff_t offs, in scan_read() argument
347 return scan_read_data(this, buf, offs, td); in scan_read()
349 return scan_read_oob(this, buf, offs, len); in scan_read()
353 static int scan_write_bbt(struct nand_chip *this, loff_t offs, size_t len, in scan_write_bbt() argument
356 struct mtd_info *mtd = nand_to_mtd(this); in scan_write_bbt()
369 static u32 bbt_get_ver_offs(struct nand_chip *this, struct nand_bbt_descr *td) in bbt_get_ver_offs() argument
371 struct mtd_info *mtd = nand_to_mtd(this); in bbt_get_ver_offs()
389 static void read_abs_bbts(struct nand_chip *this, uint8_t *buf, in read_abs_bbts() argument
392 struct mtd_info *mtd = nand_to_mtd(this); in read_abs_bbts()
396 scan_read(this, buf, (loff_t)td->pages[0] << this->page_shift, in read_abs_bbts()
398 td->version[0] = buf[bbt_get_ver_offs(this, td)]; in read_abs_bbts()
405 scan_read(this, buf, (loff_t)md->pages[0] << this->page_shift, in read_abs_bbts()
407 md->version[0] = buf[bbt_get_ver_offs(this, md)]; in read_abs_bbts()
414 static int scan_block_fast(struct nand_chip *this, struct nand_bbt_descr *bd, in scan_block_fast() argument
417 struct mtd_info *mtd = nand_to_mtd(this); in scan_block_fast()
428 page_offset = nand_bbm_get_next_page(this, 0); in scan_block_fast()
444 page_offset = nand_bbm_get_next_page(this, page_offset + 1); in scan_block_fast()
461 static int create_bbt(struct nand_chip *this, uint8_t *buf, in create_bbt() argument
464 u64 targetsize = nanddev_target_size(&this->base); in create_bbt()
465 struct mtd_info *mtd = nand_to_mtd(this); in create_bbt()
472 numblocks = mtd->size >> this->bbt_erase_shift; in create_bbt()
476 if (chip >= nanddev_ntargets(&this->base)) { in create_bbt()
478 chip + 1, nanddev_ntargets(&this->base)); in create_bbt()
481 numblocks = targetsize >> this->bbt_erase_shift; in create_bbt()
484 from = (loff_t)startblock << this->bbt_erase_shift; in create_bbt()
492 ret = scan_block_fast(this, bd, from, buf); in create_bbt()
497 bbt_mark_entry(this, i, BBT_BLOCK_FACTORY_BAD); in create_bbt()
503 from += (1 << this->bbt_erase_shift); in create_bbt()
523 static int search_bbt(struct nand_chip *this, uint8_t *buf, in search_bbt() argument
526 u64 targetsize = nanddev_target_size(&this->base); in search_bbt()
527 struct mtd_info *mtd = nand_to_mtd(this); in search_bbt()
532 int blocktopage = this->bbt_erase_shift - this->page_shift; in search_bbt()
536 startblock = (mtd->size >> this->bbt_erase_shift) - 1; in search_bbt()
545 chips = nanddev_ntargets(&this->base); in search_bbt()
546 bbtblocks = targetsize >> this->bbt_erase_shift; in search_bbt()
550 bbtblocks = mtd->size >> this->bbt_erase_shift; in search_bbt()
561 loff_t offs = (loff_t)actblock << this->bbt_erase_shift; in search_bbt()
564 scan_read(this, buf, offs, mtd->writesize, td); in search_bbt()
568 offs = bbt_get_ver_offs(this, td); in search_bbt()
574 startblock += targetsize >> this->bbt_erase_shift; in search_bbt()
596 static void search_read_bbts(struct nand_chip *this, uint8_t *buf, in search_read_bbts() argument
601 search_bbt(this, buf, td); in search_read_bbts()
605 search_bbt(this, buf, md); in search_read_bbts()
621 static int get_bbt_block(struct nand_chip *this, struct nand_bbt_descr *td, in get_bbt_block() argument
624 u64 targetsize = nanddev_target_size(&this->base); in get_bbt_block()
634 (this->bbt_erase_shift - this->page_shift); in get_bbt_block()
636 numblocks = (int)(targetsize >> this->bbt_erase_shift); in get_bbt_block()
638 numblocks *= nanddev_ntargets(&this->base); in get_bbt_block()
656 switch (bbt_get_entry(this, block)) { in get_bbt_block()
662 page = block << (this->bbt_erase_shift - this->page_shift); in get_bbt_block()
684 static void mark_bbt_block_bad(struct nand_chip *this, in mark_bbt_block_bad() argument
691 bbt_mark_entry(this, block, BBT_BLOCK_WORN); in mark_bbt_block_bad()
693 to = (loff_t)block << this->bbt_erase_shift; in mark_bbt_block_bad()
694 res = nand_markbad_bbm(this, to); in mark_bbt_block_bad()
712 static int write_bbt(struct nand_chip *this, uint8_t *buf, in write_bbt() argument
716 u64 targetsize = nanddev_target_size(&this->base); in write_bbt()
717 struct mtd_info *mtd = nand_to_mtd(this); in write_bbt()
737 numblocks = (int)(targetsize >> this->bbt_erase_shift); in write_bbt()
740 nrchips = nanddev_ntargets(&this->base); in write_bbt()
746 numblocks = (int)(mtd->size >> this->bbt_erase_shift); in write_bbt()
754 block = get_bbt_block(this, td, md, chip); in write_bbt()
765 page = block << (this->bbt_erase_shift - this->page_shift); in write_bbt()
786 to = ((loff_t)page) << this->page_shift; in write_bbt()
791 to &= ~(((loff_t)1 << this->bbt_erase_shift) - 1); in write_bbt()
792 len = 1 << this->bbt_erase_shift; in write_bbt()
802 ops.ooblen = (len >> this->page_shift) * mtd->oobsize; in write_bbt()
809 pageoffs = page - (int)(to >> this->page_shift); in write_bbt()
810 offs = pageoffs << this->page_shift; in write_bbt()
837 (len >> this->page_shift)* mtd->oobsize); in write_bbt()
851 dat = bbt_get_entry(this, chip * numblocks + i); in write_bbt()
858 einfo.len = 1 << this->bbt_erase_shift; in write_bbt()
859 res = nand_erase_nand(this, &einfo, 1); in write_bbt()
863 mark_bbt_block_bad(this, td, chip, block); in write_bbt()
867 res = scan_write_bbt(this, to, len, buf, in write_bbt()
873 mark_bbt_block_bad(this, td, chip, block); in write_bbt()
898 static inline int nand_memory_bbt(struct nand_chip *this, in nand_memory_bbt() argument
901 u8 *pagebuf = nand_get_data_buf(this); in nand_memory_bbt()
903 return create_bbt(this, pagebuf, bd, -1); in nand_memory_bbt()
917 static int check_create(struct nand_chip *this, uint8_t *buf, in check_create() argument
921 struct nand_bbt_descr *td = this->bbt_td; in check_create()
922 struct nand_bbt_descr *md = this->bbt_md; in check_create()
927 chips = nanddev_ntargets(&this->base); in check_create()
976 if (!(this->bbt_options & NAND_BBT_CREATE_EMPTY)) in check_create()
977 create_bbt(this, buf, bd, chipsel); in check_create()
986 res = read_abs_bbt(this, buf, rd, chipsel); in check_create()
997 res2 = read_abs_bbt(this, buf, rd2, chipsel); in check_create()
1019 res = write_bbt(this, buf, td, md, chipsel); in check_create()
1026 res = write_bbt(this, buf, md, td, chipsel); in check_create()
1041 static int nand_update_bbt(struct nand_chip *this, loff_t offs) in nand_update_bbt() argument
1043 struct mtd_info *mtd = nand_to_mtd(this); in nand_update_bbt()
1047 struct nand_bbt_descr *td = this->bbt_td; in nand_update_bbt()
1048 struct nand_bbt_descr *md = this->bbt_md; in nand_update_bbt()
1050 if (!this->bbt || !td) in nand_update_bbt()
1054 len = (1 << this->bbt_erase_shift); in nand_update_bbt()
1055 len += (len >> this->page_shift) * mtd->oobsize; in nand_update_bbt()
1062 chip = (int)(offs >> this->chip_shift); in nand_update_bbt()
1075 res = write_bbt(this, buf, td, md, chipsel); in nand_update_bbt()
1081 res = write_bbt(this, buf, md, td, chipsel); in nand_update_bbt()
1097 static void mark_bbt_region(struct nand_chip *this, struct nand_bbt_descr *td) in mark_bbt_region() argument
1099 u64 targetsize = nanddev_target_size(&this->base); in mark_bbt_region()
1100 struct mtd_info *mtd = nand_to_mtd(this); in mark_bbt_region()
1106 chips = nanddev_ntargets(&this->base); in mark_bbt_region()
1107 nrblocks = (int)(targetsize >> this->bbt_erase_shift); in mark_bbt_region()
1110 nrblocks = (int)(mtd->size >> this->bbt_erase_shift); in mark_bbt_region()
1118 block = td->pages[i] >> (this->bbt_erase_shift - this->page_shift); in mark_bbt_region()
1119 oldval = bbt_get_entry(this, block); in mark_bbt_region()
1120 bbt_mark_entry(this, block, BBT_BLOCK_RESERVED); in mark_bbt_region()
1123 nand_update_bbt(this, (loff_t)block << in mark_bbt_region()
1124 this->bbt_erase_shift); in mark_bbt_region()
1133 oldval = bbt_get_entry(this, block); in mark_bbt_region()
1134 bbt_mark_entry(this, block, BBT_BLOCK_RESERVED); in mark_bbt_region()
1145 nand_update_bbt(this, (loff_t)(block - 1) << in mark_bbt_region()
1146 this->bbt_erase_shift); in mark_bbt_region()
1158 static void verify_bbt_descr(struct nand_chip *this, struct nand_bbt_descr *bd) in verify_bbt_descr() argument
1160 u64 targetsize = nanddev_target_size(&this->base); in verify_bbt_descr()
1161 struct mtd_info *mtd = nand_to_mtd(this); in verify_bbt_descr()
1172 BUG_ON((this->bbt_options & NAND_BBT_NO_OOB) && in verify_bbt_descr()
1173 !(this->bbt_options & NAND_BBT_USE_FLASH)); in verify_bbt_descr()
1180 BUG_ON(!(this->bbt_options & NAND_BBT_USE_FLASH)); in verify_bbt_descr()
1181 BUG_ON(!(this->bbt_options & NAND_BBT_NO_OOB)); in verify_bbt_descr()
1189 table_size = targetsize >> this->bbt_erase_shift; in verify_bbt_descr()
1191 table_size = mtd->size >> this->bbt_erase_shift; in verify_bbt_descr()
1196 BUG_ON(table_size > (1 << this->bbt_erase_shift)); in verify_bbt_descr()
1211 static int nand_scan_bbt(struct nand_chip *this, struct nand_bbt_descr *bd) in nand_scan_bbt() argument
1213 struct mtd_info *mtd = nand_to_mtd(this); in nand_scan_bbt()
1216 struct nand_bbt_descr *td = this->bbt_td; in nand_scan_bbt()
1217 struct nand_bbt_descr *md = this->bbt_md; in nand_scan_bbt()
1219 len = (mtd->size >> (this->bbt_erase_shift + 2)) ? : 1; in nand_scan_bbt()
1224 this->bbt = kzalloc(len, GFP_KERNEL); in nand_scan_bbt()
1225 if (!this->bbt) in nand_scan_bbt()
1233 if ((res = nand_memory_bbt(this, bd))) { in nand_scan_bbt()
1239 verify_bbt_descr(this, td); in nand_scan_bbt()
1240 verify_bbt_descr(this, md); in nand_scan_bbt()
1243 len = (1 << this->bbt_erase_shift); in nand_scan_bbt()
1244 len += (len >> this->page_shift) * mtd->oobsize; in nand_scan_bbt()
1253 read_abs_bbts(this, buf, td, md); in nand_scan_bbt()
1256 search_read_bbts(this, buf, td, md); in nand_scan_bbt()
1259 res = check_create(this, buf, bd); in nand_scan_bbt()
1264 mark_bbt_region(this, td); in nand_scan_bbt()
1266 mark_bbt_region(this, md); in nand_scan_bbt()
1274 kfree(this->bbt); in nand_scan_bbt()
1275 this->bbt = NULL; in nand_scan_bbt()
1339 static int nand_create_badblock_pattern(struct nand_chip *this) in nand_create_badblock_pattern() argument
1342 if (this->badblock_pattern) { in nand_create_badblock_pattern()
1349 bd->options = this->bbt_options & BADBLOCK_SCAN_MASK; in nand_create_badblock_pattern()
1350 bd->offs = this->badblockpos; in nand_create_badblock_pattern()
1351 bd->len = (this->options & NAND_BUSWIDTH_16) ? 2 : 1; in nand_create_badblock_pattern()
1354 this->badblock_pattern = bd; in nand_create_badblock_pattern()
1365 int nand_create_bbt(struct nand_chip *this) in nand_create_bbt() argument
1370 if (this->bbt_options & NAND_BBT_USE_FLASH) { in nand_create_bbt()
1372 if (!this->bbt_td) { in nand_create_bbt()
1373 if (this->bbt_options & NAND_BBT_NO_OOB) { in nand_create_bbt()
1374 this->bbt_td = &bbt_main_no_oob_descr; in nand_create_bbt()
1375 this->bbt_md = &bbt_mirror_no_oob_descr; in nand_create_bbt()
1377 this->bbt_td = &bbt_main_descr; in nand_create_bbt()
1378 this->bbt_md = &bbt_mirror_descr; in nand_create_bbt()
1382 this->bbt_td = NULL; in nand_create_bbt()
1383 this->bbt_md = NULL; in nand_create_bbt()
1386 if (!this->badblock_pattern) { in nand_create_bbt()
1387 ret = nand_create_badblock_pattern(this); in nand_create_bbt()
1392 return nand_scan_bbt(this, this->badblock_pattern); in nand_create_bbt()
1401 int nand_isreserved_bbt(struct nand_chip *this, loff_t offs) in nand_isreserved_bbt() argument
1405 block = (int)(offs >> this->bbt_erase_shift); in nand_isreserved_bbt()
1406 return bbt_get_entry(this, block) == BBT_BLOCK_RESERVED; in nand_isreserved_bbt()
1415 int nand_isbad_bbt(struct nand_chip *this, loff_t offs, int allowbbt) in nand_isbad_bbt() argument
1419 block = (int)(offs >> this->bbt_erase_shift); in nand_isbad_bbt()
1420 res = bbt_get_entry(this, block); in nand_isbad_bbt()
1441 int nand_markbad_bbt(struct nand_chip *this, loff_t offs) in nand_markbad_bbt() argument
1445 block = (int)(offs >> this->bbt_erase_shift); in nand_markbad_bbt()
1448 bbt_mark_entry(this, block, BBT_BLOCK_WORN); in nand_markbad_bbt()
1451 if (this->bbt_options & NAND_BBT_USE_FLASH) in nand_markbad_bbt()
1452 ret = nand_update_bbt(this, offs); in nand_markbad_bbt()