1
2
3
4
5
6
7
8
9
10
11
12#ifndef __LINUX_MTD_ONENAND_H
13#define __LINUX_MTD_ONENAND_H
14
15#include <linux/spinlock.h>
16#include <linux/completion.h>
17#include <linux/mtd/flashchip.h>
18#include <linux/mtd/onenand_regs.h>
19#include <linux/mtd/bbm.h>
20
21#define MAX_DIES 2
22#define MAX_BUFFERRAM 2
23
24
25extern int onenand_scan(struct mtd_info *mtd, int max_chips);
26
27extern void onenand_release(struct mtd_info *mtd);
28
29
30
31
32
33struct onenand_bufferram {
34 int blockpage;
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
84
85
86struct onenand_chip {
87 void __iomem *base;
88 unsigned dies;
89 unsigned boundary[MAX_DIES];
90 loff_t diesize[MAX_DIES];
91 unsigned int chipsize;
92 unsigned int device_id;
93 unsigned int version_id;
94 unsigned int technology;
95 unsigned int density_mask;
96 unsigned int options;
97
98 unsigned int erase_shift;
99 unsigned int page_shift;
100 unsigned int page_mask;
101 unsigned int writesize;
102
103 unsigned int bufferram_index;
104 struct onenand_bufferram bufferram[MAX_BUFFERRAM];
105
106 int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
107 int (*wait)(struct mtd_info *mtd, int state);
108 int (*bbt_wait)(struct mtd_info *mtd, int state);
109 void (*unlock_all)(struct mtd_info *mtd);
110 int (*read_bufferram)(struct mtd_info *mtd, int area,
111 unsigned char *buffer, int offset, size_t count);
112 int (*write_bufferram)(struct mtd_info *mtd, int area,
113 const unsigned char *buffer, int offset, size_t count);
114 unsigned short (*read_word)(void __iomem *addr);
115 void (*write_word)(unsigned short value, void __iomem *addr);
116 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
117 int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
118 int (*scan_bbt)(struct mtd_info *mtd);
119
120 struct completion complete;
121 int irq;
122
123 spinlock_t chip_lock;
124 wait_queue_head_t wq;
125 flstate_t state;
126 unsigned char *page_buf;
127 unsigned char *oob_buf;
128#ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
129 unsigned char *verify_buf;
130#endif
131
132 int subpagesize;
133 struct nand_ecclayout *ecclayout;
134
135 void *bbm;
136
137 void *priv;
138};
139
140
141
142
143#define ONENAND_PAGES_PER_BLOCK (1<<6)
144
145#define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
146#define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
147#define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
148#define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
149#define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
150#define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
151
152#define FLEXONENAND(this) \
153 (this->device_id & DEVICE_IS_FLEXONENAND)
154#define ONENAND_GET_SYS_CFG1(this) \
155 (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
156#define ONENAND_SET_SYS_CFG1(v, this) \
157 (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
158
159#define ONENAND_IS_DDP(this) \
160 (this->device_id & ONENAND_DEVICE_IS_DDP)
161
162#define ONENAND_IS_MLC(this) \
163 (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
164
165#ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
166#define ONENAND_IS_2PLANE(this) \
167 (this->options & ONENAND_HAS_2PLANE)
168#else
169#define ONENAND_IS_2PLANE(this) (0)
170#endif
171
172
173#define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
174
175
176
177
178#define ONENAND_HAS_CONT_LOCK (0x0001)
179#define ONENAND_HAS_UNLOCK_ALL (0x0002)
180#define ONENAND_HAS_2PLANE (0x0004)
181#define ONENAND_HAS_4KB_PAGE (0x0008)
182#define ONENAND_SKIP_UNLOCK_CHECK (0x0100)
183#define ONENAND_PAGEBUF_ALLOC (0x1000)
184#define ONENAND_OOBBUF_ALLOC (0x2000)
185
186#define ONENAND_IS_4KB_PAGE(this) \
187 (this->options & ONENAND_HAS_4KB_PAGE)
188
189
190
191
192#define ONENAND_MFR_SAMSUNG 0xec
193#define ONENAND_MFR_NUMONYX 0x20
194
195
196
197
198
199
200struct onenand_manufacturers {
201 int id;
202 char *name;
203};
204
205int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
206 struct mtd_oob_ops *ops);
207unsigned onenand_block(struct onenand_chip *this, loff_t addr);
208loff_t onenand_addr(struct onenand_chip *this, int block);
209int flexonenand_region(struct mtd_info *mtd, loff_t addr);
210
211struct mtd_partition;
212
213struct onenand_platform_data {
214 void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
215 int (*read_bufferram)(struct mtd_info *mtd, int area,
216 unsigned char *buffer, int offset, size_t count);
217 struct mtd_partition *parts;
218 unsigned int nr_parts;
219};
220
221#endif
222