1 #ifndef __MTK_BMT_PRIV_H
2 #define __MTK_BMT_PRIV_H
4 #include <linux/kernel.h>
6 #include <linux/mtd/mtd.h>
7 #include <linux/mtd/partitions.h>
8 #include <linux/mtd/mtk_bmt.h>
9 #include <linux/debugfs.h>
11 #define MAIN_SIGNATURE_OFFSET 0
12 #define OOB_SIGNATURE_OFFSET 1
14 #define BBT_LOG(fmt, ...) pr_debug("[BBT][%s|%d] "fmt"\n", __func__, __LINE__, ##__VA_ARGS__)
19 int (*init
)(struct device_node
*np
);
20 bool (*remap_block
)(u16 block
, u16 mapped_block
, int copy_len
);
21 void (*unmap_block
)(u16 block
);
22 int (*get_mapping_block
)(int block
);
23 int (*debug
)(void *data
, u64 val
);
31 unsigned char *bbt_buf
;
32 unsigned char *data_buf
;
34 int (*_read_oob
) (struct mtd_info
*mtd
, loff_t from
,
35 struct mtd_oob_ops
*ops
);
36 int (*_write_oob
) (struct mtd_info
*mtd
, loff_t to
,
37 struct mtd_oob_ops
*ops
);
38 int (*_erase
) (struct mtd_info
*mtd
, struct erase_info
*instr
);
39 int (*_block_isbad
) (struct mtd_info
*mtd
, loff_t ofs
);
40 int (*_block_markbad
) (struct mtd_info
*mtd
, loff_t ofs
);
42 const struct mtk_bmt_ops
*ops
;
46 struct nmbm_instance
*ni
;
49 struct dentry
*debugfs_dir
;
56 /* bbt logical address */
58 /* bbt physical address */
60 /* Maximum count of bad blocks that the vendor guaranteed */
62 /* Total blocks of the Nand Chip */
64 /* The block(n) BMT is located at (bmt_tbl[n]) */
66 /* How many pages needs to store 'struct bbbt' */
69 const __be32
*remap_range
;
72 /* to compensate for driver level remapping */
76 extern struct bmt_desc bmtd
;
77 extern const struct mtk_bmt_ops mtk_bmt_v2_ops
;
78 extern const struct mtk_bmt_ops mtk_bmt_bbt_ops
;
79 extern const struct mtk_bmt_ops mtk_bmt_nmbm_ops
;
81 static inline u32
blk_pg(u16 block
)
83 return (u32
)(block
<< (bmtd
.blk_shift
- bmtd
.pg_shift
));
87 bbt_nand_read(u32 page
, unsigned char *dat
, int dat_len
,
88 unsigned char *fdm
, int fdm_len
)
90 struct mtd_oob_ops ops
= {
91 .mode
= MTD_OPS_PLACE_OOB
,
92 .ooboffs
= bmtd
.oob_offset
,
100 ret
= bmtd
._read_oob(bmtd
.mtd
, page
<< bmtd
.pg_shift
, &ops
);
104 pr_info("%s: %d bitflips\n", __func__
, ret
);
108 static inline int bbt_nand_erase(u16 block
)
110 struct mtd_info
*mtd
= bmtd
.mtd
;
111 struct erase_info instr
= {
112 .addr
= (loff_t
)block
<< bmtd
.blk_shift
,
113 .len
= bmtd
.blk_size
,
116 return bmtd
._erase(mtd
, &instr
);
119 static inline int write_bmt(u16 block
, unsigned char *dat
)
121 struct mtd_oob_ops ops
= {
122 .mode
= MTD_OPS_PLACE_OOB
,
123 .ooboffs
= OOB_SIGNATURE_OFFSET
+ bmtd
.oob_offset
,
124 .oobbuf
= bmtd
.ops
->sig
,
125 .ooblen
= bmtd
.ops
->sig_len
,
127 .len
= bmtd
.bmt_pgs
<< bmtd
.pg_shift
,
129 loff_t addr
= (loff_t
)block
<< bmtd
.blk_shift
;
131 return bmtd
._write_oob(bmtd
.mtd
, addr
, &ops
);
134 int bbt_nand_copy(u16 dest_blk
, u16 src_blk
, loff_t max_offset
);
135 bool mapping_block_in_range(int block
, int *start
, int *end
);