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