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
);
28 unsigned char *bbt_buf
;
29 unsigned char *data_buf
;
31 int (*_read_oob
) (struct mtd_info
*mtd
, loff_t from
,
32 struct mtd_oob_ops
*ops
);
33 int (*_write_oob
) (struct mtd_info
*mtd
, loff_t to
,
34 struct mtd_oob_ops
*ops
);
35 int (*_erase
) (struct mtd_info
*mtd
, struct erase_info
*instr
);
36 int (*_block_isbad
) (struct mtd_info
*mtd
, loff_t ofs
);
37 int (*_block_markbad
) (struct mtd_info
*mtd
, loff_t ofs
);
39 const struct mtk_bmt_ops
*ops
;
43 struct dentry
*debugfs_dir
;
50 /* bbt logical address */
52 /* bbt physical address */
54 /* Maximum count of bad blocks that the vendor guaranteed */
56 /* Total blocks of the Nand Chip */
58 /* The block(n) BMT is located at (bmt_tbl[n]) */
60 /* How many pages needs to store 'struct bbbt' */
63 const __be32
*remap_range
;
66 /* to compensate for driver level remapping */
70 extern struct bmt_desc bmtd
;
71 extern const struct mtk_bmt_ops mtk_bmt_v2_ops
;
72 extern const struct mtk_bmt_ops mtk_bmt_bbt_ops
;
74 static inline u32
blk_pg(u16 block
)
76 return (u32
)(block
<< (bmtd
.blk_shift
- bmtd
.pg_shift
));
80 bbt_nand_read(u32 page
, unsigned char *dat
, int dat_len
,
81 unsigned char *fdm
, int fdm_len
)
83 struct mtd_oob_ops ops
= {
84 .mode
= MTD_OPS_PLACE_OOB
,
85 .ooboffs
= bmtd
.oob_offset
,
92 return bmtd
._read_oob(bmtd
.mtd
, page
<< bmtd
.pg_shift
, &ops
);
95 static inline int bbt_nand_erase(u16 block
)
97 struct mtd_info
*mtd
= bmtd
.mtd
;
98 struct erase_info instr
= {
99 .addr
= (loff_t
)block
<< bmtd
.blk_shift
,
100 .len
= bmtd
.blk_size
,
103 return bmtd
._erase(mtd
, &instr
);
106 static inline int write_bmt(u16 block
, unsigned char *dat
)
108 struct mtd_oob_ops ops
= {
109 .mode
= MTD_OPS_PLACE_OOB
,
110 .ooboffs
= OOB_SIGNATURE_OFFSET
+ bmtd
.oob_offset
,
111 .oobbuf
= bmtd
.ops
->sig
,
112 .ooblen
= bmtd
.ops
->sig_len
,
114 .len
= bmtd
.bmt_pgs
<< bmtd
.pg_shift
,
116 loff_t addr
= (loff_t
)block
<< bmtd
.blk_shift
;
118 return bmtd
._write_oob(bmtd
.mtd
, addr
, &ops
);
121 int bbt_nand_copy(u16 dest_blk
, u16 src_blk
, loff_t max_offset
);
122 bool mapping_block_in_range(int block
, int *start
, int *end
);