0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef __LINUX_MTD_ONENAND_H
0010 #define __LINUX_MTD_ONENAND_H
0011
0012 #include <linux/spinlock.h>
0013 #include <linux/completion.h>
0014 #include <linux/mtd/flashchip.h>
0015 #include <linux/mtd/onenand_regs.h>
0016 #include <linux/mtd/bbm.h>
0017
0018 #define MAX_DIES 2
0019 #define MAX_BUFFERRAM 2
0020
0021
0022 extern int onenand_scan(struct mtd_info *mtd, int max_chips);
0023
0024 extern void onenand_release(struct mtd_info *mtd);
0025
0026
0027
0028
0029
0030 struct onenand_bufferram {
0031 int blockpage;
0032 };
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083 struct onenand_chip {
0084 void __iomem *base;
0085 unsigned dies;
0086 unsigned boundary[MAX_DIES];
0087 loff_t diesize[MAX_DIES];
0088 unsigned int chipsize;
0089 unsigned int device_id;
0090 unsigned int version_id;
0091 unsigned int technology;
0092 unsigned int density_mask;
0093 unsigned int options;
0094 unsigned int badblockpos;
0095
0096 unsigned int erase_shift;
0097 unsigned int page_shift;
0098 unsigned int page_mask;
0099 unsigned int writesize;
0100
0101 unsigned int bufferram_index;
0102 struct onenand_bufferram bufferram[MAX_BUFFERRAM];
0103
0104 int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
0105 int (*wait)(struct mtd_info *mtd, int state);
0106 int (*bbt_wait)(struct mtd_info *mtd, int state);
0107 void (*unlock_all)(struct mtd_info *mtd);
0108 int (*read_bufferram)(struct mtd_info *mtd, int area,
0109 unsigned char *buffer, int offset, size_t count);
0110 int (*write_bufferram)(struct mtd_info *mtd, int area,
0111 const unsigned char *buffer, int offset, size_t count);
0112 unsigned short (*read_word)(void __iomem *addr);
0113 void (*write_word)(unsigned short value, void __iomem *addr);
0114 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
0115 int (*chip_probe)(struct mtd_info *mtd);
0116 int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
0117 int (*scan_bbt)(struct mtd_info *mtd);
0118 int (*enable)(struct mtd_info *mtd);
0119 int (*disable)(struct mtd_info *mtd);
0120
0121 struct completion complete;
0122 int irq;
0123
0124 spinlock_t chip_lock;
0125 wait_queue_head_t wq;
0126 flstate_t state;
0127 unsigned char *page_buf;
0128 unsigned char *oob_buf;
0129 #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
0130 unsigned char *verify_buf;
0131 #endif
0132
0133 int subpagesize;
0134
0135 void *bbm;
0136
0137 void *priv;
0138
0139
0140
0141
0142
0143
0144
0145 unsigned int ongoing;
0146 };
0147
0148
0149
0150
0151 #define ONENAND_PAGES_PER_BLOCK (1<<6)
0152
0153 #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
0154 #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
0155 #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
0156 #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
0157 #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
0158 #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
0159
0160 #define FLEXONENAND(this) \
0161 (this->device_id & DEVICE_IS_FLEXONENAND)
0162 #define ONENAND_GET_SYS_CFG1(this) \
0163 (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
0164 #define ONENAND_SET_SYS_CFG1(v, this) \
0165 (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
0166
0167 #define ONENAND_IS_DDP(this) \
0168 (this->device_id & ONENAND_DEVICE_IS_DDP)
0169
0170 #define ONENAND_IS_MLC(this) \
0171 (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
0172
0173 #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
0174 #define ONENAND_IS_2PLANE(this) \
0175 (this->options & ONENAND_HAS_2PLANE)
0176 #else
0177 #define ONENAND_IS_2PLANE(this) (0)
0178 #endif
0179
0180 #define ONENAND_IS_CACHE_PROGRAM(this) \
0181 (this->options & ONENAND_HAS_CACHE_PROGRAM)
0182
0183 #define ONENAND_IS_NOP_1(this) \
0184 (this->options & ONENAND_HAS_NOP_1)
0185
0186
0187 #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
0188
0189 #define ONENAND_BADBLOCK_POS 0
0190
0191
0192
0193
0194 #define ONENAND_HAS_CONT_LOCK (0x0001)
0195 #define ONENAND_HAS_UNLOCK_ALL (0x0002)
0196 #define ONENAND_HAS_2PLANE (0x0004)
0197 #define ONENAND_HAS_4KB_PAGE (0x0008)
0198 #define ONENAND_HAS_CACHE_PROGRAM (0x0010)
0199 #define ONENAND_HAS_NOP_1 (0x0020)
0200 #define ONENAND_SKIP_UNLOCK_CHECK (0x0100)
0201 #define ONENAND_PAGEBUF_ALLOC (0x1000)
0202 #define ONENAND_OOBBUF_ALLOC (0x2000)
0203 #define ONENAND_SKIP_INITIAL_UNLOCKING (0x4000)
0204
0205 #define ONENAND_IS_4KB_PAGE(this) \
0206 (this->options & ONENAND_HAS_4KB_PAGE)
0207
0208
0209
0210
0211 #define ONENAND_MFR_SAMSUNG 0xec
0212 #define ONENAND_MFR_NUMONYX 0x20
0213
0214
0215
0216
0217
0218
0219 struct onenand_manufacturers {
0220 int id;
0221 char *name;
0222 };
0223
0224 int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
0225 struct mtd_oob_ops *ops);
0226 unsigned onenand_block(struct onenand_chip *this, loff_t addr);
0227 loff_t onenand_addr(struct onenand_chip *this, int block);
0228 int flexonenand_region(struct mtd_info *mtd, loff_t addr);
0229
0230 struct mtd_partition;
0231
0232 struct onenand_platform_data {
0233 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
0234 int (*read_bufferram)(struct mtd_info *mtd, int area,
0235 unsigned char *buffer, int offset, size_t count);
0236 struct mtd_partition *parts;
0237 unsigned int nr_parts;
0238 };
0239
0240 #endif