Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
onenand.h
Go to the documentation of this file.
1 /*
2  * linux/include/linux/mtd/onenand.h
3  *
4  * Copyright © 2005-2009 Samsung Electronics
5  * Kyungmin Park <[email protected]>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
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 /* Scan and identify a OneNAND device */
25 extern int onenand_scan(struct mtd_info *mtd, int max_chips);
26 /* Free resources held by the OneNAND device */
27 extern void onenand_release(struct mtd_info *mtd);
28 
34  int blockpage;
35 };
36 
87 struct onenand_chip {
88  void __iomem *base;
89  unsigned dies;
90  unsigned boundary[MAX_DIES];
91  loff_t diesize[MAX_DIES];
92  unsigned int chipsize;
93  unsigned int device_id;
94  unsigned int version_id;
95  unsigned int technology;
96  unsigned int density_mask;
97  unsigned int options;
98 
99  unsigned int erase_shift;
100  unsigned int page_shift;
101  unsigned int page_mask;
102  unsigned int writesize;
103 
104  unsigned int bufferram_index;
106 
107  int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
108  int (*wait)(struct mtd_info *mtd, int state);
109  int (*bbt_wait)(struct mtd_info *mtd, int state);
110  void (*unlock_all)(struct mtd_info *mtd);
111  int (*read_bufferram)(struct mtd_info *mtd, int area,
112  unsigned char *buffer, int offset, size_t count);
113  int (*write_bufferram)(struct mtd_info *mtd, int area,
114  const unsigned char *buffer, int offset, size_t count);
115  unsigned short (*read_word)(void __iomem *addr);
116  void (*write_word)(unsigned short value, void __iomem *addr);
117  void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
118  int (*chip_probe)(struct mtd_info *mtd);
119  int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
120  int (*scan_bbt)(struct mtd_info *mtd);
121  int (*enable)(struct mtd_info *mtd);
122  int (*disable)(struct mtd_info *mtd);
123 
125  int irq;
126 
130  unsigned char *page_buf;
131  unsigned char *oob_buf;
132 #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
133  unsigned char *verify_buf;
134 #endif
135 
138 
139  void *bbm;
140 
141  void *priv;
142 
143  /*
144  * Shows that the current operation is composed
145  * of sequence of commands. For example, cache program.
146  * Such command status OnGo bit is checked at the end of
147  * sequence.
148  */
149  unsigned int ongoing;
150 };
151 
152 /*
153  * Helper macros
154  */
155 #define ONENAND_PAGES_PER_BLOCK (1<<6)
156 
157 #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
158 #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
159 #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
160 #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
161 #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0)
162 #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1)
163 
164 #define FLEXONENAND(this) \
165  (this->device_id & DEVICE_IS_FLEXONENAND)
166 #define ONENAND_GET_SYS_CFG1(this) \
167  (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
168 #define ONENAND_SET_SYS_CFG1(v, this) \
169  (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
170 
171 #define ONENAND_IS_DDP(this) \
172  (this->device_id & ONENAND_DEVICE_IS_DDP)
173 
174 #define ONENAND_IS_MLC(this) \
175  (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
176 
177 #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
178 #define ONENAND_IS_2PLANE(this) \
179  (this->options & ONENAND_HAS_2PLANE)
180 #else
181 #define ONENAND_IS_2PLANE(this) (0)
182 #endif
183 
184 #define ONENAND_IS_CACHE_PROGRAM(this) \
185  (this->options & ONENAND_HAS_CACHE_PROGRAM)
186 
187 #define ONENAND_IS_NOP_1(this) \
188  (this->options & ONENAND_HAS_NOP_1)
189 
190 /* Check byte access in OneNAND */
191 #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
192 
193 /*
194  * Options bits
195  */
196 #define ONENAND_HAS_CONT_LOCK (0x0001)
197 #define ONENAND_HAS_UNLOCK_ALL (0x0002)
198 #define ONENAND_HAS_2PLANE (0x0004)
199 #define ONENAND_HAS_4KB_PAGE (0x0008)
200 #define ONENAND_HAS_CACHE_PROGRAM (0x0010)
201 #define ONENAND_HAS_NOP_1 (0x0020)
202 #define ONENAND_SKIP_UNLOCK_CHECK (0x0100)
203 #define ONENAND_PAGEBUF_ALLOC (0x1000)
204 #define ONENAND_OOBBUF_ALLOC (0x2000)
205 #define ONENAND_SKIP_INITIAL_UNLOCKING (0x4000)
206 
207 #define ONENAND_IS_4KB_PAGE(this) \
208  (this->options & ONENAND_HAS_4KB_PAGE)
209 
210 /*
211  * OneNAND Flash Manufacturer ID Codes
212  */
213 #define ONENAND_MFR_SAMSUNG 0xec
214 #define ONENAND_MFR_NUMONYX 0x20
215 
222  int id;
223  char *name;
224 };
225 
226 int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
227  struct mtd_oob_ops *ops);
228 unsigned onenand_block(struct onenand_chip *this, loff_t addr);
229 loff_t onenand_addr(struct onenand_chip *this, int block);
230 int flexonenand_region(struct mtd_info *mtd, loff_t addr);
231 
232 struct mtd_partition;
233 
235  void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
236  int (*read_bufferram)(struct mtd_info *mtd, int area,
237  unsigned char *buffer, int offset, size_t count);
239  unsigned int nr_parts;
240 };
241 
242 #endif /* __LINUX_MTD_ONENAND_H */