1 --- a/drivers/mtd/nand/Kconfig
2 +++ b/drivers/mtd/nand/Kconfig
3 @@ -15,6 +15,10 @@ config MTD_NAND_ECC
5 depends on MTD_NAND_CORE
7 +config MTD_NAND_MTK_BMT
8 + bool "Support MediaTek NAND Bad-block Management Table"
14 --- a/drivers/mtd/nand/Makefile
15 +++ b/drivers/mtd/nand/Makefile
18 nandcore-objs := core.o bbt.o
19 obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
20 +obj-$(CONFIG_MTD_NAND_MTK_BMT) += mtk_bmt.o
25 +++ b/drivers/mtd/nand/mtk_bmt.c
28 + * Copyright (c) 2017 MediaTek Inc.
29 + * Author: Xiangsheng Hou <xiangsheng.hou@mediatek.com>
30 + * Copyright (c) 2020 Felix Fietkau <nbd@nbd.name>
32 + * This program is free software; you can redistribute it and/or modify
33 + * it under the terms of the GNU General Public License version 2 as
34 + * published by the Free Software Foundation.
36 + * This program is distributed in the hope that it will be useful,
37 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
38 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39 + * GNU General Public License for more details.
42 +#include <linux/slab.h>
43 +#include <linux/gfp.h>
44 +#include <linux/kernel.h>
45 +#include <linux/of.h>
46 +#include <linux/mtd/nand.h>
47 +#include <linux/mtd/partitions.h>
48 +#include <linux/mtd/mtk_bmt.h>
49 +#include <linux/module.h>
50 +#include <linux/debugfs.h>
52 +#define MAIN_SIGNATURE_OFFSET 0
53 +#define OOB_SIGNATURE_OFFSET 1
54 +#define BBPOOL_RATIO 2
56 +#define BBT_LOG(fmt, ...) pr_debug("[BBT][%s|%d] "fmt"\n", __func__, __LINE__, ##__VA_ARGS__)
58 +/* Maximum 8k blocks */
59 +#define BB_TABLE_MAX 0x2000U
60 +#define BMT_TABLE_MAX (BB_TABLE_MAX * BBPOOL_RATIO / 100)
61 +#define BMT_TBL_DEF_VAL 0x0
64 + * Burner Bad Block Table
65 + * --------- Only support SLC Nand Chips!!!!!!!!!!! ----------
70 + /* This version is used to distinguish the legacy and new algorithm */
71 +#define BBMT_VERSION 2
72 + unsigned char version;
73 + /* Below 2 tables will be written in SLC */
74 + u16 bb_tbl[BB_TABLE_MAX];
78 +#define NORMAL_MAPPED 1
81 + } bmt_tbl[BMT_TABLE_MAX];
84 +static struct bmt_desc {
85 + struct mtd_info *mtd;
87 + int (*_read_oob) (struct mtd_info *mtd, loff_t from,
88 + struct mtd_oob_ops *ops);
89 + int (*_write_oob) (struct mtd_info *mtd, loff_t to,
90 + struct mtd_oob_ops *ops);
91 + const struct nand_ops *nand_ops;
95 + struct dentry *debugfs_dir;
101 + /* bbt logical address */
103 + /* bbt physical address */
105 + /* Maximum count of bad blocks that the vendor guaranteed */
107 + /* Total blocks of the Nand Chip */
109 + /* The block(n) BMT is located at (bmt_tbl[n]) */
111 + /* How many pages needs to store 'struct bbbt' */
114 + /* to compensate for driver level remapping */
118 +static unsigned char *nand_bbt_buf;
119 +static unsigned char *nand_data_buf;
121 +/* -------- Unit conversions -------- */
122 +static inline u32 blk_pg(u16 block)
124 + return (u32)(block << (bmtd.blk_shift - bmtd.pg_shift));
127 +/* -------- Nand operations wrapper -------- */
129 +bbt_nand_read(u32 page, unsigned char *dat, int dat_len,
130 + unsigned char *fdm, int fdm_len)
132 + struct mtd_oob_ops ops = {
133 + .mode = MTD_OPS_PLACE_OOB,
134 + .ooboffs = bmtd.oob_offset,
141 + return bmtd._read_oob(bmtd.mtd, page << bmtd.pg_shift, &ops);
144 +static inline int bbt_nand_erase(u16 block)
146 + struct nand_device *nand = mtd_to_nanddev(bmtd.mtd);
147 + loff_t addr = (loff_t)block << bmtd.blk_shift;
148 + struct nand_pos pos;
150 + nanddev_offs_to_pos(nand, addr, &pos);
151 + return bmtd.nand_ops->erase(nand, &pos);
154 +/* -------- Bad Blocks Management -------- */
156 +read_bmt(u16 block, unsigned char *dat, unsigned char *fdm, int fdm_len)
158 + u32 len = bmtd.bmt_pgs << bmtd.pg_shift;
160 + return bbt_nand_read(blk_pg(block), dat, len, fdm, fdm_len);
163 +static int write_bmt(u16 block, unsigned char *dat)
165 + struct mtd_oob_ops ops = {
166 + .mode = MTD_OPS_PLACE_OOB,
167 + .ooboffs = OOB_SIGNATURE_OFFSET + bmtd.oob_offset,
171 + .len = bmtd.bmt_pgs << bmtd.pg_shift,
173 + loff_t addr = (loff_t)block << bmtd.blk_shift;
175 + return bmtd._write_oob(bmtd.mtd, addr, &ops);
178 +static u16 find_valid_block(u16 block)
185 + if (block >= bmtd.total_blks)
188 + ret = bbt_nand_read(blk_pg(block), nand_data_buf, bmtd.pg_size,
190 + /* Read the 1st byte of FDM to judge whether it's a bad
193 + if (ret || fdm[0] != 0xff) {
194 + pr_info("nand: found bad block 0x%x\n", block);
195 + if (loop >= bmtd.bb_max) {
196 + pr_info("nand: FATAL ERR: too many bad blocks!!\n");
208 +/* Find out all bad blocks, and fill in the mapping table */
209 +static int scan_bad_blocks(struct bbbt *bbt)
214 + /* First time download, the block0 MUST NOT be a bad block,
215 + * this is guaranteed by vendor
217 + bbt->bb_tbl[0] = 0;
220 + * Construct the mapping table of Normal data area(non-PMT/BMTPOOL)
221 + * G - Good block; B - Bad block
222 + * ---------------------------
223 + * physical |G|G|B|G|B|B|G|G|G|G|B|G|B|
224 + * ---------------------------
225 + * What bb_tbl[i] looks like:
226 + * physical block(i):
227 + * 0 1 2 3 4 5 6 7 8 9 a b c
228 + * mapped block(bb_tbl[i]):
229 + * 0 1 3 6 7 8 9 b ......
231 + * If new bad block ocurred(n), search bmt_tbl to find
232 + * a available block(x), and fill in the bb_tbl[n] = x;
234 + for (i = 1; i < bmtd.pool_lba; i++) {
235 + bbt->bb_tbl[i] = find_valid_block(bbt->bb_tbl[i - 1] + 1);
236 + BBT_LOG("bb_tbl[0x%x] = 0x%x", i, bbt->bb_tbl[i]);
237 + if (bbt->bb_tbl[i] == 0)
241 + /* Physical Block start Address of BMT pool */
242 + bmtd.pool_pba = bbt->bb_tbl[i - 1] + 1;
243 + if (bmtd.pool_pba >= bmtd.total_blks - 2) {
244 + pr_info("nand: FATAL ERR: Too many bad blocks!!\n");
248 + BBT_LOG("pool_pba=0x%x", bmtd.pool_pba);
250 + block = bmtd.pool_pba;
252 + * The bmt table is used for runtime bad block mapping
253 + * G - Good block; B - Bad block
254 + * ---------------------------
255 + * physical |G|G|B|G|B|B|G|G|G|G|B|G|B|
256 + * ---------------------------
257 + * block: 0 1 2 3 4 5 6 7 8 9 a b c
258 + * What bmt_tbl[i] looks like in initial state:
261 + * bmt_tbl[i].block:
263 + * bmt_tbl[i].mapped:
265 + * N - Not mapped(Available)
269 + * BMT always in the last valid block in pool
271 + while ((block = find_valid_block(block)) != 0) {
272 + bbt->bmt_tbl[i].block = block;
273 + bbt->bmt_tbl[i].mapped = NO_MAPPED;
274 + BBT_LOG("bmt_tbl[%d].block = 0x%x", i, block);
279 + /* i - How many available blocks in pool, which is the length of bmt_tbl[]
280 + * bmtd.bmt_blk_idx - bmt_tbl[bmtd.bmt_blk_idx].block => the BMT block
282 + bmtd.bmt_blk_idx = i - 1;
283 + bbt->bmt_tbl[bmtd.bmt_blk_idx].mapped = BMT_MAPPED;
286 + pr_info("nand: FATAL ERR: no space to store BMT!!\n");
290 + pr_info("[BBT] %d available blocks in BMT pool\n", i);
295 +static bool is_valid_bmt(unsigned char *buf, unsigned char *fdm)
297 + struct bbbt *bbt = (struct bbbt *)buf;
298 + u8 *sig = (u8*)bbt->signature + MAIN_SIGNATURE_OFFSET;
301 + if (memcmp(bbt->signature + MAIN_SIGNATURE_OFFSET, "BMT", 3) == 0 &&
302 + memcmp(fdm + OOB_SIGNATURE_OFFSET, "bmt", 3) == 0) {
303 + if (bbt->version == BBMT_VERSION)
306 + BBT_LOG("[BBT] BMT Version not match,upgrage preloader and uboot please! sig=%02x%02x%02x, fdm=%02x%02x%02x",
307 + sig[0], sig[1], sig[2],
308 + fdm[1], fdm[2], fdm[3]);
312 +static u16 get_bmt_index(struct bbmt *bmt)
316 + while (bmt[i].block != BMT_TBL_DEF_VAL) {
317 + if (bmt[i].mapped == BMT_MAPPED)
324 +static struct bbbt *scan_bmt(u16 block)
328 + if (block < bmtd.pool_lba)
331 + if (read_bmt(block, nand_bbt_buf, fdm, sizeof(fdm)))
332 + return scan_bmt(block - 1);
334 + if (is_valid_bmt(nand_bbt_buf, fdm)) {
335 + bmtd.bmt_blk_idx = get_bmt_index(((struct bbbt *)nand_bbt_buf)->bmt_tbl);
336 + if (bmtd.bmt_blk_idx == 0) {
337 + pr_info("[BBT] FATAL ERR: bmt block index is wrong!\n");
340 + pr_info("[BBT] BMT.v2 is found at 0x%x\n", block);
341 + return (struct bbbt *)nand_bbt_buf;
343 + return scan_bmt(block - 1);
346 +/* Write the Burner Bad Block Table to Nand Flash
347 + * n - write BMT to bmt_tbl[n]
349 +static u16 upload_bmt(struct bbbt *bbt, int n)
354 + if (n < 0 || bbt->bmt_tbl[n].mapped == NORMAL_MAPPED) {
355 + pr_info("nand: FATAL ERR: no space to store BMT!\n");
359 + block = bbt->bmt_tbl[n].block;
360 + BBT_LOG("n = 0x%x, block = 0x%x", n, block);
361 + if (bbt_nand_erase(block)) {
362 + bbt->bmt_tbl[n].block = 0;
363 + /* erase failed, try the previous block: bmt_tbl[n - 1].block */
368 + /* The signature offset is fixed set to 0,
369 + * oob signature offset is fixed set to 1
371 + memcpy(bbt->signature + MAIN_SIGNATURE_OFFSET, "BMT", 3);
372 + bbt->version = BBMT_VERSION;
374 + if (write_bmt(block, (unsigned char *)bbt)) {
375 + bbt->bmt_tbl[n].block = 0;
377 + /* write failed, try the previous block in bmt_tbl[n - 1] */
382 + /* Return the current index(n) of BMT pool (bmt_tbl[n]) */
386 +static u16 find_valid_block_in_pool(struct bbbt *bbt)
390 + if (bmtd.bmt_blk_idx == 0)
393 + for (i = 0; i < bmtd.bmt_blk_idx; i++) {
394 + if (bbt->bmt_tbl[i].block != 0 && bbt->bmt_tbl[i].mapped == NO_MAPPED) {
395 + bbt->bmt_tbl[i].mapped = NORMAL_MAPPED;
396 + return bbt->bmt_tbl[i].block;
401 + pr_info("nand: FATAL ERR: BMT pool is run out!\n");
405 +/* We met a bad block, mark it as bad and map it to a valid block in pool,
406 + * if it's a write failure, we need to write the data to mapped block
408 +static bool update_bmt(u16 block)
414 + mapped_blk = find_valid_block_in_pool(bbt);
415 + if (mapped_blk == 0)
418 + /* Map new bad block to available block in pool */
419 + bbt->bb_tbl[block] = mapped_blk;
420 + bmtd.bmt_blk_idx = upload_bmt(bbt, bmtd.bmt_blk_idx);
425 +u16 get_mapping_block_index(int block)
429 + if (block < bmtd.pool_lba)
430 + mapping_block = bmtd.bbt->bb_tbl[block];
432 + mapping_block = block;
433 + BBT_LOG("0x%x mapped to 0x%x", block, mapping_block);
435 + return mapping_block;
439 +mtk_bmt_read(struct mtd_info *mtd, loff_t from,
440 + struct mtd_oob_ops *ops)
442 + struct mtd_oob_ops cur_ops = *ops;
443 + int retry_count = 0;
448 + ops->oobretlen = 0;
450 + while (ops->retlen < ops->len || ops->oobretlen < ops->ooblen) {
451 + u32 offset = from & (bmtd.blk_size - 1);
452 + u32 block = from >> bmtd.blk_shift;
455 + cur_block = get_mapping_block_index(block);
456 + cur_from = ((loff_t)cur_block << bmtd.blk_shift) + offset;
458 + cur_ops.oobretlen = 0;
459 + cur_ops.retlen = 0;
460 + cur_ops.len = min_t(u32, mtd->erasesize - offset,
461 + ops->len - ops->retlen);
462 + ret = bmtd._read_oob(mtd, cur_from, &cur_ops);
465 + if (retry_count++ < 10)
471 + ops->retlen += cur_ops.retlen;
472 + ops->oobretlen += cur_ops.oobretlen;
474 + cur_ops.datbuf += cur_ops.retlen;
475 + cur_ops.oobbuf += cur_ops.oobretlen;
476 + cur_ops.ooblen -= cur_ops.oobretlen;
479 + cur_ops.len = mtd->erasesize - offset;
481 + from += cur_ops.len;
489 +mtk_bmt_write(struct mtd_info *mtd, loff_t to,
490 + struct mtd_oob_ops *ops)
492 + struct mtd_oob_ops cur_ops = *ops;
493 + int retry_count = 0;
498 + ops->oobretlen = 0;
500 + while (ops->retlen < ops->len || ops->oobretlen < ops->ooblen) {
501 + u32 offset = to & (bmtd.blk_size - 1);
502 + u32 block = to >> bmtd.blk_shift;
505 + cur_block = get_mapping_block_index(block);
506 + cur_to = ((loff_t)cur_block << bmtd.blk_shift) + offset;
508 + cur_ops.oobretlen = 0;
509 + cur_ops.retlen = 0;
510 + cur_ops.len = min_t(u32, bmtd.blk_size - offset,
511 + ops->len - ops->retlen);
512 + ret = bmtd._write_oob(mtd, cur_to, &cur_ops);
515 + if (retry_count++ < 10)
521 + ops->retlen += cur_ops.retlen;
522 + ops->oobretlen += cur_ops.oobretlen;
524 + cur_ops.datbuf += cur_ops.retlen;
525 + cur_ops.oobbuf += cur_ops.oobretlen;
526 + cur_ops.ooblen -= cur_ops.oobretlen;
529 + cur_ops.len = mtd->erasesize - offset;
541 +mtk_bmt_erase(struct nand_device *nand, const struct nand_pos *pos)
543 + struct nand_pos new_pos = *pos;
544 + int retry_count = 0;
548 + new_pos.eraseblock = get_mapping_block_index(pos->eraseblock);
550 + ret = bmtd.nand_ops->erase(nand, &new_pos);
552 + update_bmt(pos->eraseblock);
553 + if (retry_count++ < 10)
561 +mtk_bmt_isbad(struct nand_device *nand, const struct nand_pos *pos)
563 + struct nand_pos new_pos = *pos;
564 + int retry_count = 0;
568 + new_pos.eraseblock = get_mapping_block_index(pos->eraseblock);
570 + ret = bmtd.nand_ops->isbad(nand, &new_pos);
572 + update_bmt(pos->eraseblock);
573 + if (retry_count++ < 10)
581 +mtk_bmt_markbad(struct nand_device *nand, const struct nand_pos *pos)
583 + struct nand_pos new_pos = *pos;
585 + new_pos.eraseblock = get_mapping_block_index(new_pos.eraseblock);
586 + update_bmt(pos->eraseblock);
588 + return bmtd.nand_ops->markbad(nand, &new_pos);
592 +mtk_bmt_replace_ops(struct mtd_info *mtd)
594 + static const struct nand_ops mtk_bmt_nand_ops = {
595 + .erase = mtk_bmt_erase,
596 + .isbad = mtk_bmt_isbad,
597 + .markbad = mtk_bmt_markbad,
599 + struct nand_device *nand = mtd_to_nanddev(mtd);
601 + bmtd.nand_ops = nand->ops;
602 + bmtd._read_oob = mtd->_read_oob;
603 + bmtd._write_oob = mtd->_write_oob;
605 + mtd->_read_oob = mtk_bmt_read;
606 + mtd->_write_oob = mtk_bmt_write;
607 + nand->ops = &mtk_bmt_nand_ops;
610 +static int mtk_bmt_debug_mark_good(void *data, u64 val)
612 + u32 block = val >> bmtd.blk_shift;
614 + bmtd.bbt->bb_tbl[block] = block;
615 + bmtd.bmt_blk_idx = upload_bmt(bmtd.bbt, bmtd.bmt_blk_idx);
620 +static int mtk_bmt_debug_mark_bad(void *data, u64 val)
622 + u32 block = val >> bmtd.blk_shift;
629 +DEFINE_DEBUGFS_ATTRIBUTE(fops_mark_good, NULL, mtk_bmt_debug_mark_good, "%llu\n");
630 +DEFINE_DEBUGFS_ATTRIBUTE(fops_mark_bad, NULL, mtk_bmt_debug_mark_bad, "%llu\n");
633 +mtk_bmt_add_debugfs(void)
635 + struct dentry *dir;
637 + dir = bmtd.debugfs_dir = debugfs_create_dir("mtk-bmt", NULL);
641 + debugfs_create_file_unsafe("mark_good", S_IWUSR, dir, NULL, &fops_mark_good);
642 + debugfs_create_file_unsafe("mark_bad", S_IWUSR, dir, NULL, &fops_mark_bad);
645 +void mtk_bmt_detach(struct mtd_info *mtd)
647 + struct nand_device *nand = mtd_to_nanddev(mtd);
649 + if (bmtd.mtd != mtd)
652 + if (bmtd.debugfs_dir)
653 + debugfs_remove_recursive(bmtd.debugfs_dir);
654 + bmtd.debugfs_dir = NULL;
656 + kfree(nand_bbt_buf);
657 + kfree(nand_data_buf);
659 + mtd->_read_oob = bmtd._read_oob;
660 + mtd->_write_oob = bmtd._write_oob;
661 + mtd->size = bmtd.total_blks << bmtd.blk_shift;
662 + nand->ops = bmtd.nand_ops;
664 + memset(&bmtd, 0, sizeof(bmtd));
667 +/* total_blocks - The total count of blocks that the Nand Chip has */
668 +int mtk_bmt_attach(struct mtd_info *mtd)
670 + struct device_node *np;
674 + u16 total_blocks, pmt_block;
681 + np = mtd_get_of_node(mtd);
685 + if (!of_property_read_bool(np, "mediatek,bmt-v2"))
688 + if (of_property_read_u32(np, "mediatek,bmt-pool-size",
689 + &bmt_pool_size) != 0)
690 + bmt_pool_size = 80;
692 + if (of_property_read_u8(np, "mediatek,bmt-oob-offset",
693 + &bmtd.oob_offset) != 0)
694 + bmtd.oob_offset = 8;
697 + mtk_bmt_replace_ops(mtd);
699 + bmtd.blk_size = mtd->erasesize;
700 + bmtd.blk_shift = ffs(bmtd.blk_size) - 1;
701 + bmtd.pg_size = mtd->writesize;
702 + bmtd.pg_shift = ffs(bmtd.pg_size) - 1;
703 + total_blocks = mtd->size >> bmtd.blk_shift;
704 + pmt_block = total_blocks - bmt_pool_size - 2;
706 + mtd->size = pmt_block << bmtd.blk_shift;
709 + * ---------------------------------------
710 + * | PMT(2blks) | BMT POOL(totalblks * 2%) |
711 + * ---------------------------------------
714 + * pmt_block pmt_block + 2blocks(pool_lba)
717 + * The blocks ahead of the boundary block are stored in bb_tbl
718 + * and blocks behind are stored in bmt_tbl
721 + bmtd.pool_lba = (u16)(pmt_block + 2);
722 + bmtd.total_blks = total_blocks;
723 + bmtd.bb_max = bmtd.total_blks * BBPOOL_RATIO / 100;
725 + /* 3 buffers we need */
726 + bufsz = round_up(sizeof(struct bbbt), bmtd.pg_size);
727 + bmtd.bmt_pgs = bufsz >> bmtd.pg_shift;
729 + nand_bbt_buf = kzalloc(bufsz, GFP_KERNEL);
730 + nand_data_buf = kzalloc(bmtd.pg_size, GFP_KERNEL);
732 + if (!nand_bbt_buf || !nand_data_buf) {
733 + pr_info("nand: FATAL ERR: allocate buffer failed!\n");
738 + memset(nand_bbt_buf, 0xff, bufsz);
739 + memset(nand_data_buf, 0xff, bmtd.pg_size);
741 + BBT_LOG("bbtbuf=0x%p(0x%x) dat=0x%p(0x%x)",
742 + nand_bbt_buf, bufsz, nand_data_buf, bmtd.pg_size);
743 + BBT_LOG("pool_lba=0x%x total_blks=0x%x bb_max=0x%x",
744 + bmtd.pool_lba, bmtd.total_blks, bmtd.bb_max);
746 + /* Scanning start from the first page of the last block
749 + bbt = scan_bmt(bmtd.total_blks - 1);
751 + /* BMT not found */
752 + if (bmtd.total_blks > BB_TABLE_MAX + BMT_TABLE_MAX) {
753 + pr_info("nand: FATAL: Too many blocks, can not support!\n");
758 + bbt = (struct bbbt *)nand_bbt_buf;
759 + memset(bbt->bmt_tbl, BMT_TBL_DEF_VAL, sizeof(bbt->bmt_tbl));
761 + if (scan_bad_blocks(bbt)) {
766 + /* BMT always in the last valid block in pool */
767 + bmtd.bmt_blk_idx = upload_bmt(bbt, bmtd.bmt_blk_idx);
768 + block = bbt->bmt_tbl[bmtd.bmt_blk_idx].block;
769 + pr_notice("[BBT] BMT.v2 is written into PBA:0x%x\n", block);
771 + if (bmtd.bmt_blk_idx == 0)
772 + pr_info("nand: Warning: no available block in BMT pool!\n");
773 + else if (bmtd.bmt_blk_idx == (u16)-1) {
778 + mtk_bmt_add_debugfs();
784 + mtk_bmt_detach(mtd);
789 +MODULE_LICENSE("GPL");
790 +MODULE_AUTHOR("Xiangsheng Hou <xiangsheng.hou@mediatek.com>, Felix Fietkau <nbd@nbd.name>");
791 +MODULE_DESCRIPTION("Bad Block mapping management v2 for MediaTek NAND Flash Driver");
793 --- a/drivers/mtd/nand/spi/core.c
794 +++ b/drivers/mtd/nand/spi/core.c
796 #include <linux/string.h>
797 #include <linux/spi/spi.h>
798 #include <linux/spi/spi-mem.h>
799 +#include <linux/mtd/mtk_bmt.h>
801 static int spinand_read_reg_op(struct spinand_device *spinand, u8 reg, u8 *val)
803 @@ -1139,6 +1140,8 @@ static int spinand_probe(struct spi_mem
807 + mtk_bmt_attach(mtd);
809 ret = mtd_device_register(mtd, NULL, 0);
811 goto err_spinand_cleanup;
812 @@ -1164,6 +1167,7 @@ static int spinand_remove(struct spi_mem
816 + mtk_bmt_detach(mtd);
817 spinand_cleanup(spinand);
821 +++ b/include/linux/mtd/mtk_bmt.h
826 +#ifdef CONFIG_MTD_NAND_MTK_BMT
827 +int mtk_bmt_attach(struct mtd_info *mtd);
828 +void mtk_bmt_detach(struct mtd_info *mtd);
830 +static inline int mtk_bmt_attach(struct mtd_info *mtd)
835 +static inline void mtk_bmt_detach(struct mtd_info *mtd)