Lines Matching +full:mtd +full:- +full:ram
1 // SPDX-License-Identifier: GPL-2.0
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/onenand.h>
20 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
38 for (i = 0; i < td->len; i++) { in check_short_pattern()
39 if (p[i] != td->pattern[i]) in check_short_pattern()
40 return -1; in check_short_pattern()
46 * create_bbt - [GENERIC] Create a bad block table by scanning the device
47 * @mtd: MTD device structure
50 * @chip: create the table for a specific chip, -1 read all chips.
56 static int create_bbt(struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip) in create_bbt() argument
58 struct onenand_chip *this = mtd->priv; in create_bbt()
59 struct bbm_info *bbm = this->bbm; in create_bbt()
73 readlen = bd->len; in create_bbt()
75 /* chip == -1 case only */ in create_bbt()
79 numblocks = this->chipsize >> (bbm->bbt_erase_shift - 1); in create_bbt()
94 ret = onenand_bbt_read_oob(mtd, in create_bbt()
95 from + j * this->writesize + bd->offs, &ops); in create_bbt()
99 return -EIO; in create_bbt()
102 scanlen, this->writesize, bd)) { in create_bbt()
103 bbm->bbt[i >> 3] |= 0x03 << (i & 0x6); in create_bbt()
106 mtd->ecc_stats.badblocks++; in create_bbt()
113 rgn = flexonenand_region(mtd, from); in create_bbt()
114 from += mtd->eraseregions[rgn].erasesize; in create_bbt()
116 from += (1 << bbm->bbt_erase_shift); in create_bbt()
124 * onenand_memory_bbt - [GENERIC] create a memory based bad block table
125 * @mtd: MTD device structure
131 static inline int onenand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) in onenand_memory_bbt() argument
133 struct onenand_chip *this = mtd->priv; in onenand_memory_bbt()
135 return create_bbt(mtd, this->page_buf, bd, -1); in onenand_memory_bbt()
139 * onenand_isbad_bbt - [OneNAND Interface] Check if a block is bad
140 * @mtd: MTD device structure
144 static int onenand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) in onenand_isbad_bbt() argument
146 struct onenand_chip *this = mtd->priv; in onenand_isbad_bbt()
147 struct bbm_info *bbm = this->bbm; in onenand_isbad_bbt()
153 res = (bbm->bbt[block >> 3] >> (block & 0x06)) & 0x03; in onenand_isbad_bbt()
168 * onenand_scan_bbt - [OneNAND Interface] scan, find, read and maybe create bad block table(s)
169 * @mtd: MTD device structure
181 static int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd) in onenand_scan_bbt() argument
183 struct onenand_chip *this = mtd->priv; in onenand_scan_bbt()
184 struct bbm_info *bbm = this->bbm; in onenand_scan_bbt()
187 len = this->chipsize >> (this->erase_shift + 2); in onenand_scan_bbt()
189 bbm->bbt = kzalloc(len, GFP_KERNEL); in onenand_scan_bbt()
190 if (!bbm->bbt) in onenand_scan_bbt()
191 return -ENOMEM; in onenand_scan_bbt()
194 bbm->bbt_erase_shift = this->erase_shift; in onenand_scan_bbt()
196 if (!bbm->isbad_bbt) in onenand_scan_bbt()
197 bbm->isbad_bbt = onenand_isbad_bbt; in onenand_scan_bbt()
200 if ((ret = onenand_memory_bbt(mtd, bd))) { in onenand_scan_bbt()
201 printk(KERN_ERR "onenand_scan_bbt: Can't scan flash and build the RAM-based BBT\n"); in onenand_scan_bbt()
202 kfree(bbm->bbt); in onenand_scan_bbt()
203 bbm->bbt = NULL; in onenand_scan_bbt()
223 * onenand_default_bbt - [OneNAND Interface] Select a default bad block table for the device
224 * @mtd: MTD device structure
229 int onenand_default_bbt(struct mtd_info *mtd) in onenand_default_bbt() argument
231 struct onenand_chip *this = mtd->priv; in onenand_default_bbt()
234 this->bbm = kzalloc(sizeof(struct bbm_info), GFP_KERNEL); in onenand_default_bbt()
235 if (!this->bbm) in onenand_default_bbt()
236 return -ENOMEM; in onenand_default_bbt()
238 bbm = this->bbm; in onenand_default_bbt()
241 if (!bbm->badblock_pattern) in onenand_default_bbt()
242 bbm->badblock_pattern = &largepage_memorybased; in onenand_default_bbt()
244 return onenand_scan_bbt(mtd, bbm->badblock_pattern); in onenand_default_bbt()