mtd: nand: edit macro flag for BBT scan of last page in block
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / mtd / bbm.h
1 /*
2 * linux/include/linux/mtd/bbm.h
3 *
4 * NAND family Bad Block Management (BBM) header file
5 * - Bad Block Table (BBT) implementation
6 *
7 * Copyright (c) 2005 Samsung Electronics
8 * Kyungmin Park <kyungmin.park@samsung.com>
9 *
10 * Copyright (c) 2000-2005
11 * Thomas Gleixner <tglx@linuxtronix.de>
12 *
13 */
14 #ifndef __LINUX_MTD_BBM_H
15 #define __LINUX_MTD_BBM_H
16
17 /* The maximum number of NAND chips in an array */
18 #define NAND_MAX_CHIPS 8
19
20 /**
21 * struct nand_bbt_descr - bad block table descriptor
22 * @options: options for this descriptor
23 * @pages: the page(s) where we find the bbt, used with option BBT_ABSPAGE
24 * when bbt is searched, then we store the found bbts pages here.
25 * Its an array and supports up to 8 chips now
26 * @offs: offset of the pattern in the oob area of the page
27 * @veroffs: offset of the bbt version counter in the oob are of the page
28 * @version: version read from the bbt page during scan
29 * @len: length of the pattern, if 0 no pattern check is performed
30 * @maxblocks: maximum number of blocks to search for a bbt. This number of
31 * blocks is reserved at the end of the device where the tables are
32 * written.
33 * @reserved_block_code: if non-0, this pattern denotes a reserved (rather than
34 * bad) block in the stored bbt
35 * @pattern: pattern to identify bad block table or factory marked good /
36 * bad blocks, can be NULL, if len = 0
37 *
38 * Descriptor for the bad block table marker and the descriptor for the
39 * pattern which identifies good and bad blocks. The assumption is made
40 * that the pattern and the version count are always located in the oob area
41 * of the first block.
42 */
43 struct nand_bbt_descr {
44 int options;
45 int pages[NAND_MAX_CHIPS];
46 int offs;
47 int veroffs;
48 uint8_t version[NAND_MAX_CHIPS];
49 int len;
50 int maxblocks;
51 int reserved_block_code;
52 uint8_t *pattern;
53 };
54
55 /* Options for the bad block table descriptors */
56
57 /* The number of bits used per block in the bbt on the device */
58 #define NAND_BBT_NRBITS_MSK 0x0000000F
59 #define NAND_BBT_1BIT 0x00000001
60 #define NAND_BBT_2BIT 0x00000002
61 #define NAND_BBT_4BIT 0x00000004
62 #define NAND_BBT_8BIT 0x00000008
63 /* The bad block table is in the last good block of the device */
64 #define NAND_BBT_LASTBLOCK 0x00000010
65 /* The bbt is at the given page, else we must scan for the bbt */
66 #define NAND_BBT_ABSPAGE 0x00000020
67 /* The bbt is at the given page, else we must scan for the bbt */
68 #define NAND_BBT_SEARCH 0x00000040
69 /* bbt is stored per chip on multichip devices */
70 #define NAND_BBT_PERCHIP 0x00000080
71 /* bbt has a version counter at offset veroffs */
72 #define NAND_BBT_VERSION 0x00000100
73 /* Create a bbt if none axists */
74 #define NAND_BBT_CREATE 0x00000200
75 /* Search good / bad pattern through all pages of a block */
76 #define NAND_BBT_SCANALLPAGES 0x00000400
77 /* Scan block empty during good / bad block scan */
78 #define NAND_BBT_SCANEMPTY 0x00000800
79 /* Write bbt if neccecary */
80 #define NAND_BBT_WRITE 0x00001000
81 /* Read and write back block contents when writing bbt */
82 #define NAND_BBT_SAVECONTENT 0x00002000
83 /* Search good / bad pattern on the first and the second page */
84 #define NAND_BBT_SCAN2NDPAGE 0x00004000
85 /* Search good / bad pattern on the last page of the eraseblock */
86 #define NAND_BBT_SCANLASTPAGE 0x00008000
87
88 /* The maximum number of blocks to scan for a bbt */
89 #define NAND_BBT_SCAN_MAXBLOCKS 4
90
91 /*
92 * Constants for oob configuration
93 */
94 #define NAND_SMALL_BADBLOCK_POS 5
95 #define NAND_LARGE_BADBLOCK_POS 0
96 #define ONENAND_BADBLOCK_POS 0
97
98 /*
99 * Bad block scanning errors
100 */
101 #define ONENAND_BBT_READ_ERROR 1
102 #define ONENAND_BBT_READ_ECC_ERROR 2
103 #define ONENAND_BBT_READ_FATAL_ERROR 4
104
105 /**
106 * struct bbm_info - [GENERIC] Bad Block Table data structure
107 * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
108 * @badblockpos: [INTERN] position of the bad block marker in the oob area
109 * @options: options for this descriptor
110 * @bbt: [INTERN] bad block table pointer
111 * @isbad_bbt: function to determine if a block is bad
112 * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for
113 * initial bad block scan
114 * @priv: [OPTIONAL] pointer to private bbm date
115 */
116 struct bbm_info {
117 int bbt_erase_shift;
118 int badblockpos;
119 int options;
120
121 uint8_t *bbt;
122
123 int (*isbad_bbt)(struct mtd_info *mtd, loff_t ofs, int allowbbt);
124
125 /* TODO Add more NAND specific fileds */
126 struct nand_bbt_descr *badblock_pattern;
127
128 void *priv;
129 };
130
131 /* OneNAND BBT interface */
132 extern int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
133 extern int onenand_default_bbt(struct mtd_info *mtd);
134
135 #endif /* __LINUX_MTD_BBM_H */