1
2
3
4
5
6
7#ifndef __MTD_MTD_H__
8#define __MTD_MTD_H__
9
10#include <linux/types.h>
11#include <div64.h>
12#include <linux/mtd/mtd-abi.h>
13
14#define MTD_CHAR_MAJOR 90
15#define MTD_BLOCK_MAJOR 31
16#define MAX_MTD_DEVICES 32
17
18#define MTD_ERASE_PENDING 0x01
19#define MTD_ERASING 0x02
20#define MTD_ERASE_SUSPEND 0x04
21#define MTD_ERASE_DONE 0x08
22#define MTD_ERASE_FAILED 0x10
23
24#define MTD_FAIL_ADDR_UNKNOWN -1LL
25
26
27
28
29enum {
30 FL_READY,
31 FL_READING,
32 FL_WRITING,
33 FL_ERASING,
34 FL_SYNCING,
35 FL_CACHEDPRG,
36 FL_RESETING,
37 FL_UNLOCKING,
38 FL_LOCKING,
39 FL_PM_SUSPENDED,
40};
41
42
43
44
45struct erase_info {
46 struct mtd_info *mtd;
47 uint64_t addr;
48 uint64_t len;
49 uint64_t fail_addr;
50 u_long time;
51 u_long retries;
52 u_int dev;
53 u_int cell;
54 void (*callback) (struct erase_info *self);
55 u_long priv;
56 u_char state;
57 struct erase_info *next;
58};
59
60struct mtd_erase_region_info {
61 uint64_t offset;
62 u_int32_t erasesize;
63 u_int32_t numblocks;
64 unsigned long *lockmap;
65};
66
67
68
69
70
71
72
73
74
75
76
77typedef enum {
78 MTD_OOB_PLACE,
79 MTD_OOB_AUTO,
80 MTD_OOB_RAW,
81} mtd_oob_mode_t;
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102struct mtd_oob_ops {
103 mtd_oob_mode_t mode;
104 size_t len;
105 size_t retlen;
106 size_t ooblen;
107 size_t oobretlen;
108 uint32_t ooboffs;
109 uint8_t *datbuf;
110 uint8_t *oobbuf;
111};
112
113struct mtd_info {
114 u_char type;
115 u_int32_t flags;
116 uint64_t size;
117
118
119
120
121
122 u_int32_t erasesize;
123
124
125
126
127
128
129
130 u_int32_t writesize;
131
132 u_int32_t oobsize;
133 u_int32_t oobavail;
134
135
136 const char *name;
137 int index;
138
139
140 struct nand_ecclayout *ecclayout;
141
142
143
144
145 int numeraseregions;
146 struct mtd_erase_region_info *eraseregions;
147
148
149
150
151
152
153
154
155 int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
156
157
158
159 int (*point) (struct mtd_info *mtd, loff_t from, size_t len,
160 size_t *retlen, void **virt, phys_addr_t *phys);
161
162
163 void (*unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
164
165
166 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
167 int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
168
169
170
171
172
173
174
175
176 int (*panic_write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
177
178 int (*read_oob) (struct mtd_info *mtd, loff_t from,
179 struct mtd_oob_ops *ops);
180 int (*write_oob) (struct mtd_info *mtd, loff_t to,
181 struct mtd_oob_ops *ops);
182
183
184
185
186
187
188 int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
189 int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
190 int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
191 int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
192 int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
193 int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len);
194
195
196#if 0
197
198
199
200
201 int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
202#endif
203
204
205 void (*sync) (struct mtd_info *mtd);
206
207
208 int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
209 int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
210
211
212 int (*block_isbad) (struct mtd_info *mtd, loff_t ofs);
213 int (*block_markbad) (struct mtd_info *mtd, loff_t ofs);
214
215
216#if 0
217 struct notifier_block reboot_notifier;
218#endif
219
220
221 struct mtd_ecc_stats ecc_stats;
222
223 int subpage_sft;
224
225 void *priv;
226
227 struct module *owner;
228 int usecount;
229
230
231
232
233
234 int (*get_device) (struct mtd_info *mtd);
235 void (*put_device) (struct mtd_info *mtd);
236};
237
238static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
239{
240 do_div(sz, mtd->erasesize);
241 return sz;
242}
243
244static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd)
245{
246 return do_div(sz, mtd->erasesize);
247}
248
249
250
251extern int add_mtd_device(struct mtd_info *mtd);
252extern int del_mtd_device (struct mtd_info *mtd);
253
254extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
255extern struct mtd_info *get_mtd_device_nm(const char *name);
256
257extern void put_mtd_device(struct mtd_info *mtd);
258extern void mtd_get_len_incl_bad(struct mtd_info *mtd, uint64_t offset,
259 const uint64_t length, uint64_t *len_incl_bad,
260 int *truncated);
261
262#if 0
263struct mtd_notifier {
264 void (*add)(struct mtd_info *mtd);
265 void (*remove)(struct mtd_info *mtd);
266 struct list_head list;
267};
268
269extern void register_mtd_user (struct mtd_notifier *new);
270extern int unregister_mtd_user (struct mtd_notifier *old);
271
272int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
273 unsigned long count, loff_t to, size_t *retlen);
274
275int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
276 unsigned long count, loff_t from, size_t *retlen);
277#endif
278
279#ifdef CONFIG_MTD_PARTITIONS
280void mtd_erase_callback(struct erase_info *instr);
281#else
282static inline void mtd_erase_callback(struct erase_info *instr)
283{
284 if (instr->callback)
285 instr->callback(instr);
286}
287#endif
288
289
290
291
292#define MTD_DEBUG_LEVEL0 (0)
293#define MTD_DEBUG_LEVEL1 (1)
294#define MTD_DEBUG_LEVEL2 (2)
295#define MTD_DEBUG_LEVEL3 (3)
296
297#ifdef CONFIG_MTD_DEBUG
298#define MTDDEBUG(n, args...) \
299 do { \
300 if (n <= CONFIG_MTD_DEBUG_VERBOSE) \
301 printk(KERN_INFO args); \
302 } while(0)
303#else
304#define MTDDEBUG(n, args...) \
305 do { \
306 if (0) \
307 printk(KERN_INFO args); \
308 } while(0)
309#endif
310
311#endif
312