00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #ifndef __MTD_MTD_H__
00014 #define __MTD_MTD_H__
00015
00016 #ifndef __KERNEL__
00017 #error This is a kernel header. Perhaps include mtd-user.h instead?
00018 #endif
00019
00020
00021
00022
00023 #if 0
00024 #include <linux/config.h>
00025 #endif
00026 #include <linux/types.h>
00027 #if 0
00028 #include <linux/module.h>
00029 #include <linux/uio.h>
00030 #include <linux/notifier.h>
00031
00032 #include <linux/mtd/compatmac.h>
00033 #include <mtd/mtd-abi.h>
00034 #endif
00035
00036 #include "mtd-abi.h"
00037
00038 #define MTD_CHAR_MAJOR 90
00039 #define MTD_BLOCK_MAJOR 31
00040 #define MAX_MTD_DEVICES 16
00041
00042 #define MTD_ERASE_PENDING 0x01
00043 #define MTD_ERASING 0x02
00044 #define MTD_ERASE_SUSPEND 0x04
00045 #define MTD_ERASE_DONE 0x08
00046 #define MTD_ERASE_FAILED 0x10
00047
00048
00049
00050
00051 struct erase_info {
00052 struct mtd_info *mtd;
00053 u_int32_t addr;
00054 u_int32_t len;
00055 u_int32_t fail_addr;
00056 u_long time;
00057 u_long retries;
00058 u_int dev;
00059 u_int cell;
00060 void (*callback) (struct erase_info *self);
00061 u_long priv;
00062 u_char state;
00063 struct erase_info *next;
00064 };
00065
00066 struct mtd_erase_region_info {
00067 u_int32_t offset;
00068 u_int32_t erasesize;
00069 u_int32_t numblocks;
00070 };
00071
00072 struct mtd_info {
00073 u_char type;
00074 u_int32_t flags;
00075 u_int32_t size;
00076
00077
00078
00079
00080
00081 u_int32_t erasesize;
00082
00083 u_int32_t oobblock;
00084 u_int32_t oobsize;
00085 u_int32_t ecctype;
00086 u_int32_t eccsize;
00087
00088
00089
00090
00091
00092
00093
00094
00095 #define MTD_PROGREGION_SIZE(mtd) (mtd)->oobblock
00096 #define MTD_PROGREGION_CTRLMODE_VALID(mtd) (mtd)->oobsize
00097 #define MTD_PROGREGION_CTRLMODE_INVALID(mtd) (mtd)->ecctype
00098
00099
00100 char *name;
00101 int index;
00102
00103
00104 struct nand_oobinfo oobinfo;
00105 u_int32_t oobavail;
00106
00107
00108
00109
00110 int numeraseregions;
00111 struct mtd_erase_region_info *eraseregions;
00112
00113
00114 u_int32_t bank_size;
00115
00116 int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
00117
00118
00119 int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);
00120
00121
00122 void (*unpoint) (struct mtd_info *mtd, u_char * addr, loff_t from, size_t len);
00123
00124
00125 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
00126 int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
00127
00128 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);
00129 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);
00130
00131 int (*read_oob) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
00132 int (*write_oob) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
00133
00134
00135
00136
00137
00138
00139 int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
00140 int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
00141 int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
00142 int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
00143 int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
00144 int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len);
00145
00146
00147
00148
00149
00150
00151 int (*readv) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from, size_t *retlen);
00152 int (*readv_ecc) (struct mtd_info *mtd, struct kvec *vecs, unsigned long count, loff_t from,
00153 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
00154 int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
00155 int (*writev_ecc) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to,
00156 size_t *retlen, u_char *eccbuf, struct nand_oobinfo *oobsel);
00157
00158
00159 void (*sync) (struct mtd_info *mtd);
00160
00161
00162 int (*lock) (struct mtd_info *mtd, loff_t ofs, size_t len);
00163 int (*unlock) (struct mtd_info *mtd, loff_t ofs, size_t len);
00164
00165
00166 int (*suspend) (struct mtd_info *mtd);
00167 void (*resume) (struct mtd_info *mtd);
00168
00169
00170 int (*block_isbad) (struct mtd_info *mtd, loff_t ofs);
00171 int (*block_markbad) (struct mtd_info *mtd, loff_t ofs);
00172
00173 struct notifier_block reboot_notifier;
00174
00175 void *priv;
00176
00177 struct module *owner;
00178 int usecount;
00179 };
00180
00181
00182
00183
00184 extern int add_mtd_device(struct mtd_info *mtd);
00185 extern int del_mtd_device (struct mtd_info *mtd);
00186
00187 extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
00188
00189 extern void put_mtd_device(struct mtd_info *mtd);
00190
00191
00192 struct mtd_notifier {
00193 void (*add)(struct mtd_info *mtd);
00194 void (*remove)(struct mtd_info *mtd);
00195 struct list_head list;
00196 };
00197
00198
00199 extern void register_mtd_user (struct mtd_notifier *new);
00200 extern int unregister_mtd_user (struct mtd_notifier *old);
00201
00202 int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
00203 unsigned long count, loff_t to, size_t *retlen);
00204
00205 int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
00206 unsigned long count, loff_t from, size_t *retlen);
00207
00208 #define MTD_ERASE(mtd, args...) (*(mtd->erase))(mtd, args)
00209 #define MTD_POINT(mtd, a,b,c,d) (*(mtd->point))(mtd, a,b,c, (u_char **)(d))
00210 #define MTD_UNPOINT(mtd, arg) (*(mtd->unpoint))(mtd, (u_char *)arg)
00211 #define MTD_READ(mtd, args...) (*(mtd->read))(mtd, args)
00212 #define MTD_WRITE(mtd, args...) (*(mtd->write))(mtd, args)
00213 #define MTD_READV(mtd, args...) (*(mtd->readv))(mtd, args)
00214 #define MTD_WRITEV(mtd, args...) (*(mtd->writev))(mtd, args)
00215 #define MTD_READECC(mtd, args...) (*(mtd->read_ecc))(mtd, args)
00216 #define MTD_WRITEECC(mtd, args...) (*(mtd->write_ecc))(mtd, args)
00217 #define MTD_READOOB(mtd, args...) (*(mtd->read_oob))(mtd, args)
00218 #define MTD_WRITEOOB(mtd, args...) (*(mtd->write_oob))(mtd, args)
00219 #define MTD_SYNC(mtd) do { if (mtd->sync) (*(mtd->sync))(mtd); } while (0)
00220
00221
00222 #ifdef CONFIG_MTD_PARTITIONS
00223 void mtd_erase_callback(struct erase_info *instr);
00224 #else
00225 static inline void mtd_erase_callback(struct erase_info *instr)
00226 {
00227 if (instr->callback)
00228 instr->callback(instr);
00229 }
00230 #endif
00231
00232
00233
00234
00235 #define MTD_DEBUG_LEVEL0 (0)
00236 #define MTD_DEBUG_LEVEL1 (1)
00237 #define MTD_DEBUG_LEVEL2 (2)
00238 #define MTD_DEBUG_LEVEL3 (3)
00239
00240 #ifdef CONFIG_MTD_DEBUG
00241 #define DEBUG(n, args...) \
00242 do { \
00243 if (n <= CONFIG_MTD_DEBUG_VERBOSE) \
00244 printk(KERN_INFO args); \
00245 } while(0)
00246 #else
00247 #define DEBUG(n, args...) do { } while(0)
00248
00249 #endif
00250
00251 #endif