aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/mtd/mtd.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/mtd/mtd.h')
-rw-r--r--include/linux/mtd/mtd.h97
1 files changed, 64 insertions, 33 deletions
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index b6f2fdae65c6..e1d2a3d56546 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -56,18 +56,69 @@ struct mtd_erase_region_info {
56 u_int32_t numblocks; /* Number of blocks of erasesize in this region */ 56 u_int32_t numblocks; /* Number of blocks of erasesize in this region */
57}; 57};
58 58
59/*
60 * oob operation modes
61 *
62 * MTD_OOB_PLACE: oob data are placed at the given offset
63 * MTD_OOB_AUTO: oob data are automatically placed at the free areas
64 * which are defined by the ecclayout
65 * MTD_OOB_RAW: mode to read raw data+oob in one chunk. The oob data
66 * is inserted into the data. Thats a raw image of the
67 * flash contents.
68 */
69typedef enum {
70 MTD_OOB_PLACE,
71 MTD_OOB_AUTO,
72 MTD_OOB_RAW,
73} mtd_oob_mode_t;
74
75/**
76 * struct mtd_oob_ops - oob operation operands
77 * @mode: operation mode
78 *
79 * @len: number of bytes to write/read. When a data buffer is given
80 * (datbuf != NULL) this is the number of data bytes. When
81 + no data buffer is available this is the number of oob bytes.
82 *
83 * @retlen: number of bytes written/read. When a data buffer is given
84 * (datbuf != NULL) this is the number of data bytes. When
85 + no data buffer is available this is the number of oob bytes.
86 *
87 * @ooblen: number of oob bytes per page
88 * @ooboffs: offset of oob data in the oob area (only relevant when
89 * mode = MTD_OOB_PLACE)
90 * @datbuf: data buffer - if NULL only oob data are read/written
91 * @oobbuf: oob data buffer
92 */
93struct mtd_oob_ops {
94 mtd_oob_mode_t mode;
95 size_t len;
96 size_t retlen;
97 size_t ooblen;
98 uint32_t ooboffs;
99 uint8_t *datbuf;
100 uint8_t *oobbuf;
101};
102
59struct mtd_info { 103struct mtd_info {
60 u_char type; 104 u_char type;
61 u_int32_t flags; 105 u_int32_t flags;
62 u_int32_t size; // Total size of the MTD 106 u_int32_t size; // Total size of the MTD
63 107
64 /* "Major" erase size for the device. Naïve users may take this 108 /* "Major" erase size for the device. Naïve users may take this
65 * to be the only erase size available, or may use the more detailed 109 * to be the only erase size available, or may use the more detailed
66 * information below if they desire 110 * information below if they desire
67 */ 111 */
68 u_int32_t erasesize; 112 u_int32_t erasesize;
113 /* Minimal writable flash unit size. In case of NOR flash it is 1 (even
114 * though individual bits can be cleared), in case of NAND flash it is
115 * one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR
116 * it is of ECC block size, etc. It is illegal to have writesize = 0.
117 * Any driver registering a struct mtd_info must ensure a writesize of
118 * 1 or larger.
119 */
120 u_int32_t writesize;
69 121
70 u_int32_t oobblock; // Size of OOB blocks (e.g. 512)
71 u_int32_t oobsize; // Amount of OOB data per block (e.g. 16) 122 u_int32_t oobsize; // Amount of OOB data per block (e.g. 16)
72 u_int32_t ecctype; 123 u_int32_t ecctype;
73 u_int32_t eccsize; 124 u_int32_t eccsize;
@@ -79,7 +130,6 @@ struct mtd_info {
79 * MTD_PROGRAM_REGIONS flag is set. 130 * MTD_PROGRAM_REGIONS flag is set.
80 * (Maybe we should have an union for those?) 131 * (Maybe we should have an union for those?)
81 */ 132 */
82#define MTD_PROGREGION_SIZE(mtd) (mtd)->oobblock
83#define MTD_PROGREGION_CTRLMODE_VALID(mtd) (mtd)->oobsize 133#define MTD_PROGREGION_CTRLMODE_VALID(mtd) (mtd)->oobsize
84#define MTD_PROGREGION_CTRLMODE_INVALID(mtd) (mtd)->ecctype 134#define MTD_PROGREGION_CTRLMODE_INVALID(mtd) (mtd)->ecctype
85 135
@@ -87,9 +137,8 @@ struct mtd_info {
87 char *name; 137 char *name;
88 int index; 138 int index;
89 139
90 // oobinfo is a nand_oobinfo structure, which can be set by iotcl (MEMSETOOBINFO) 140 /* ecc layout structure pointer - read only ! */
91 struct nand_oobinfo oobinfo; 141 struct nand_ecclayout *ecclayout;
92 u_int32_t oobavail; // Number of bytes in OOB area available for fs
93 142
94 /* Data for variable erase regions. If numeraseregions is zero, 143 /* Data for variable erase regions. If numeraseregions is zero,
95 * it means that the whole device has erasesize as given above. 144 * it means that the whole device has erasesize as given above.
@@ -112,11 +161,10 @@ struct mtd_info {
112 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 161 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
113 int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); 162 int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
114 163
115 int (*read_ecc) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel); 164 int (*read_oob) (struct mtd_info *mtd, loff_t from,
116 int (*write_ecc) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf, u_char *eccbuf, struct nand_oobinfo *oobsel); 165 struct mtd_oob_ops *ops);
117 166 int (*write_oob) (struct mtd_info *mtd, loff_t to,
118 int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 167 struct mtd_oob_ops *ops);
119 int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
120 168
121 /* 169 /*
122 * Methods to access the protection register area, present in some 170 * Methods to access the protection register area, present in some
@@ -130,17 +178,11 @@ struct mtd_info {
130 int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 178 int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
131 int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len); 179 int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len);
132 180
133 /* kvec-based read/write methods. We need these especially for NAND flash, 181 /* kvec-based read/write methods.
134 with its limited number of write cycles per erase.
135 NB: The 'count' parameter is the number of _vectors_, each of 182 NB: The 'count' parameter is the number of _vectors_, each of
136 which contains an (ofs, len) tuple. 183 which contains an (ofs, len) tuple.
137 */ 184 */
138 int (*readv) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from, size_t *retlen);
139 int (*readv_ecc) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from,
140 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
141 int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen); 185 int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
142 int (*writev_ecc) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to,
143 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
144 186
145 /* Sync */ 187 /* Sync */
146 void (*sync) (struct mtd_info *mtd); 188 void (*sync) (struct mtd_info *mtd);
@@ -159,6 +201,9 @@ struct mtd_info {
159 201
160 struct notifier_block reboot_notifier; /* default mode before reboot */ 202 struct notifier_block reboot_notifier; /* default mode before reboot */
161 203
204 /* ECC status information */
205 struct mtd_ecc_stats ecc_stats;
206
162 void *priv; 207 void *priv;
163 208
164 struct module *owner; 209 struct module *owner;
@@ -192,20 +237,6 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
192int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs, 237int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
193 unsigned long count, loff_t from, size_t *retlen); 238 unsigned long count, loff_t from, size_t *retlen);
194 239
195#define MTD_ERASE(mtd, args...) (*(mtd->erase))(mtd, args)
196#define MTD_POINT(mtd, a,b,c,d) (*(mtd->point))(mtd, a,b,c, (u_char **)(d))
197#define MTD_UNPOINT(mtd, arg) (*(mtd->unpoint))(mtd, (u_char *)arg)
198#define MTD_READ(mtd, args...) (*(mtd->read))(mtd, args)
199#define MTD_WRITE(mtd, args...) (*(mtd->write))(mtd, args)
200#define MTD_READV(mtd, args...) (*(mtd->readv))(mtd, args)
201#define MTD_WRITEV(mtd, args...) (*(mtd->writev))(mtd, args)
202#define MTD_READECC(mtd, args...) (*(mtd->read_ecc))(mtd, args)
203#define MTD_WRITEECC(mtd, args...) (*(mtd->write_ecc))(mtd, args)
204#define MTD_READOOB(mtd, args...) (*(mtd->read_oob))(mtd, args)
205#define MTD_WRITEOOB(mtd, args...) (*(mtd->write_oob))(mtd, args)
206#define MTD_SYNC(mtd) do { if (mtd->sync) (*(mtd->sync))(mtd); } while (0)
207
208
209#ifdef CONFIG_MTD_PARTITIONS 240#ifdef CONFIG_MTD_PARTITIONS
210void mtd_erase_callback(struct erase_info *instr); 241void mtd_erase_callback(struct erase_info *instr);
211#else 242#else
@@ -226,7 +257,7 @@ static inline void mtd_erase_callback(struct erase_info *instr)
226 257
227#ifdef CONFIG_MTD_DEBUG 258#ifdef CONFIG_MTD_DEBUG
228#define DEBUG(n, args...) \ 259#define DEBUG(n, args...) \
229 do { \ 260 do { \
230 if (n <= CONFIG_MTD_DEBUG_VERBOSE) \ 261 if (n <= CONFIG_MTD_DEBUG_VERBOSE) \
231 printk(KERN_INFO args); \ 262 printk(KERN_INFO args); \
232 } while(0) 263 } while(0)