1
2
3
4
5
6
7
8
9 #ifndef __LINUX_MTD_ONENAND_H
10 #define __LINUX_MTD_ONENAND_H
11
12 #include <linux/spinlock.h>
13 #include <linux/completion.h>
14 #include <linux/mtd/flashchip.h>
15 #include <linux/mtd/onenand_regs.h>
16 #include <linux/mtd/bbm.h>
17
18 #define MAX_DIES 2
19 #define MAX_BUFFERRAM 2
20
21
22 extern int onenand_scan(struct mtd_info *mtd, int max_chips);
23
24 extern void onenand_release(struct mtd_info *mtd);
25
26
27
28
29
30 struct onenand_bufferram {
31 int blockpage;
32 };
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 struct onenand_chip {
84 void __iomem *base;
85 unsigned dies;
86 unsigned boundary[MAX_DIES];
87 loff_t diesize[MAX_DIES];
88 unsigned int chipsize;
89 unsigned int device_id;
90 unsigned int version_id;
91 unsigned int technology;
92 unsigned int density_mask;
93 unsigned int options;
94 unsigned int badblockpos;
95
96 unsigned int erase_shift;
97 unsigned int page_shift;
98 unsigned int page_mask;
99 unsigned int writesize;
100
101 unsigned int bufferram_index;
102 struct onenand_bufferram bufferram[MAX_BUFFERRAM];
103
104 int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
105 int (*wait)(struct mtd_info *mtd, int state);
106 int (*bbt_wait)(struct mtd_info *mtd, int state);
107 void (*unlock_all)(struct mtd_info *mtd);
108 int (*read_bufferram)(struct mtd_info *mtd, int area,
109 unsigned char *buffer, int offset, size_t count);
110 int (*write_bufferram)(struct mtd_info *mtd, int area,
111 const unsigned char *buffer, int offset, size_t count);
112 unsigned short (*read_word)(void __iomem *addr);
113 void (*write_word)(unsigned short value, void __iomem *addr);
114 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
115 int (*chip_probe)(struct mtd_info *mtd);
116 int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
117 int (*scan_bbt)(struct mtd_info *mtd);
118 int (*enable)(struct mtd_info *mtd);
119 int (*disable)(struct mtd_info *mtd);
120
121 struct completion complete;
122 int irq;
123
124 spinlock_t chip_lock;
125 wait_queue_head_t wq;
126 flstate_t state;
127 unsigned char *page_buf;
128 unsigned char *oob_buf;
129 #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
130 unsigned char *verify_buf;
131 #endif
132
133 int subpagesize;
134
135 void *bbm;
136
137 void *priv;
138
139
140
141
142
143
144
145 unsigned int ongoing;
146 };
147
148
149
150
151 #define ONENAND_PAGES_PER_BLOCK (1<<6)
152
153 #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
154 #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
155 #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
156 #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
157 #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
158 #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
159
160 #define FLEXONENAND(this) \
161 (this->device_id & DEVICE_IS_FLEXONENAND)
162 #define ONENAND_GET_SYS_CFG1(this) \
163 (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
164 #define ONENAND_SET_SYS_CFG1(v, this) \
165 (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
166
167 #define ONENAND_IS_DDP(this) \
168 (this->device_id & ONENAND_DEVICE_IS_DDP)
169
170 #define ONENAND_IS_MLC(this) \
171 (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
172
173 #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
174 #define ONENAND_IS_2PLANE(this) \
175 (this->options & ONENAND_HAS_2PLANE)
176 #else
177 #define ONENAND_IS_2PLANE(this) (0)
178 #endif
179
180 #define ONENAND_IS_CACHE_PROGRAM(this) \
181 (this->options & ONENAND_HAS_CACHE_PROGRAM)
182
183 #define ONENAND_IS_NOP_1(this) \
184 (this->options & ONENAND_HAS_NOP_1)
185
186
187 #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
188
189 #define ONENAND_BADBLOCK_POS 0
190
191
192
193
194 #define ONENAND_HAS_CONT_LOCK (0x0001)
195 #define ONENAND_HAS_UNLOCK_ALL (0x0002)
196 #define ONENAND_HAS_2PLANE (0x0004)
197 #define ONENAND_HAS_4KB_PAGE (0x0008)
198 #define ONENAND_HAS_CACHE_PROGRAM (0x0010)
199 #define ONENAND_HAS_NOP_1 (0x0020)
200 #define ONENAND_SKIP_UNLOCK_CHECK (0x0100)
201 #define ONENAND_PAGEBUF_ALLOC (0x1000)
202 #define ONENAND_OOBBUF_ALLOC (0x2000)
203 #define ONENAND_SKIP_INITIAL_UNLOCKING (0x4000)
204
205 #define ONENAND_IS_4KB_PAGE(this) \
206 (this->options & ONENAND_HAS_4KB_PAGE)
207
208
209
210
211 #define ONENAND_MFR_SAMSUNG 0xec
212 #define ONENAND_MFR_NUMONYX 0x20
213
214
215
216
217
218
219 struct onenand_manufacturers {
220 int id;
221 char *name;
222 };
223
224 int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
225 struct mtd_oob_ops *ops);
226 unsigned onenand_block(struct onenand_chip *this, loff_t addr);
227 loff_t onenand_addr(struct onenand_chip *this, int block);
228 int flexonenand_region(struct mtd_info *mtd, loff_t addr);
229
230 struct mtd_partition;
231
232 struct onenand_platform_data {
233 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
234 int (*read_bufferram)(struct mtd_info *mtd, int area,
235 unsigned char *buffer, int offset, size_t count);
236 struct mtd_partition *parts;
237 unsigned int nr_parts;
238 };
239
240 #endif