import PULS_20160108
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / arm / mach-mt8127 / include / mach / bmt.h
1 #ifndef __BMT_H__
2 #define __BMT_H__
3
4 #include <linux/mtd/mtd.h>
5 #include <linux/mtd/nand.h>
6 #include <mach/mtk_nand.h>
7
8 #define MAX_BMT_SIZE (0x200) //0x80
9 #define BMT_VERSION (1) // initial version
10
11 #define MAIN_SIGNATURE_OFFSET (0)
12 #define OOB_SIGNATURE_OFFSET (1)
13 #define OOB_INDEX_OFFSET (29)
14 #define OOB_INDEX_SIZE (2)
15 #define FAKE_INDEX (0xAAAA)
16
17 typedef struct _bmt_entry_
18 {
19 u16 bad_index; // bad block index
20 u16 mapped_index; // mapping block index in the replace pool
21 } bmt_entry;
22
23 typedef enum
24 {
25 UPDATE_ERASE_FAIL,
26 UPDATE_WRITE_FAIL,
27 UPDATE_UNMAPPED_BLOCK,
28 UPDATE_REASON_COUNT,
29 } update_reason_t;
30
31 typedef struct
32 {
33 bmt_entry table[MAX_BMT_SIZE];
34 u8 version;
35 u8 mapped_count; // mapped block count in pool
36 u8 bad_count; // bad block count in pool. Not used in V1
37 } bmt_struct;
38
39 /***************************************************************
40 * *
41 * Interface BMT need to use *
42 * *
43 ***************************************************************/
44 //extern bool mtk_nand_exec_read_page(struct mtd_info *mtd, u32 row, u32 page_size, u8 * dat, u8 * oob);
45 extern int mtk_nand_exec_read_page(struct mtd_info *mtd, u32 u4RowAddr, u32 u4PageSize, u8 * pPageBuf, u8 * pFDMBuf);
46 extern int mtk_nand_block_bad_hw(struct mtd_info *mtd, loff_t ofs);
47 extern int mtk_nand_erase_hw(struct mtd_info *mtd, int page);
48 extern int mtk_nand_block_markbad_hw(struct mtd_info *mtd, loff_t ofs);
49 extern int mtk_nand_exec_write_page(struct mtd_info *mtd, u32 row, u32 page_size, u8 * dat, u8 * oob);
50
51
52 /***************************************************************
53 * *
54 * Different function interface for preloader/uboot/kernel *
55 * *
56 ***************************************************************/
57 void set_bad_index_to_oob(u8 * oob, u16 index);
58
59
60 bmt_struct *init_bmt(struct nand_chip *nand, int size);
61 bool update_bmt(u64 offset, update_reason_t reason, u8 * dat, u8 * oob);
62 unsigned short get_mapping_block_index(int index);
63
64 #endif // #ifndef __BMT_H__