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