ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / linux / mtd / nand.h
1 /*
2  *  linux/include/linux/mtd/nand.h
3  *
4  *  Copyright (c) 2000 David Woodhouse <dwmw2@mvhi.com>
5  *                     Steven J. Hill <sjhill@realitydiluted.com>
6  *                     Thomas Gleixner <tglx@linutronix.de>
7  *
8  * $Id: nand.h,v 1.25 2003/05/21 15:15:02 dwmw2 Exp $
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License version 2 as
12  * published by the Free Software Foundation.
13  *
14  *  Info:
15  *   Contains standard defines and IDs for NAND flash devices
16  *
17  *  Changelog:
18  *   01-31-2000 DMW     Created
19  *   09-18-2000 SJH     Moved structure out of the Disk-On-Chip drivers
20  *                      so it can be used by other NAND flash device
21  *                      drivers. I also changed the copyright since none
22  *                      of the original contents of this file are specific
23  *                      to DoC devices. David can whack me with a baseball
24  *                      bat later if I did something naughty.
25  *   10-11-2000 SJH     Added private NAND flash structure for driver
26  *   10-24-2000 SJH     Added prototype for 'nand_scan' function
27  *   10-29-2001 TG      changed nand_chip structure to support 
28  *                      hardwarespecific function for accessing control lines
29  *   02-21-2002 TG      added support for different read/write adress and
30  *                      ready/busy line access function
31  *   02-26-2002 TG      added chip_delay to nand_chip structure to optimize
32  *                      command delay times for different chips
33  *   04-28-2002 TG      OOB config defines moved from nand.c to avoid duplicate
34  *                      defines in jffs2/wbuf.c
35  *   08-07-2002 TG      forced bad block location to byte 5 of OOB, even if
36  *                      CONFIG_MTD_NAND_ECC_JFFS2 is not set
37  *   08-10-2002 TG      extensions to nand_chip structure to support HW-ECC
38  *
39  *   08-29-2002 tglx    nand_chip structure: data_poi for selecting 
40  *                      internal / fs-driver buffer
41  *                      support for 6byte/512byte hardware ECC
42  *                      read_ecc, write_ecc extended for different oob-layout
43  *                      oob layout selections: NAND_NONE_OOB, NAND_JFFS2_OOB,
44  *                      NAND_YAFFS_OOB
45  *  11-25-2002 tglx     Added Manufacturer code FUJITSU, NATIONAL
46  *                      Split manufacturer and device ID structures 
47  */
48 #ifndef __LINUX_MTD_NAND_H
49 #define __LINUX_MTD_NAND_H
50
51 #include <linux/config.h>
52 #include <linux/wait.h>
53 #include <linux/spinlock.h>
54
55 struct mtd_info;
56 /*
57  * Searches for a NAND device
58  */
59 extern int nand_scan (struct mtd_info *mtd);
60
61 /*
62  * Constants for hardware specific CLE/ALE/NCE function
63 */
64 #define NAND_CTL_SETNCE         1
65 #define NAND_CTL_CLRNCE         2
66 #define NAND_CTL_SETCLE         3
67 #define NAND_CTL_CLRCLE         4
68 #define NAND_CTL_SETALE         5
69 #define NAND_CTL_CLRALE         6
70
71 /*
72  * Standard NAND flash commands
73  */
74 #define NAND_CMD_READ0          0
75 #define NAND_CMD_READ1          1
76 #define NAND_CMD_PAGEPROG       0x10
77 #define NAND_CMD_READOOB        0x50
78 #define NAND_CMD_ERASE1         0x60
79 #define NAND_CMD_STATUS         0x70
80 #define NAND_CMD_SEQIN          0x80
81 #define NAND_CMD_READID         0x90
82 #define NAND_CMD_ERASE2         0xd0
83 #define NAND_CMD_RESET          0xff
84
85 /* 
86  * Constants for ECC_MODES
87  *
88  * NONE:        No ECC
89  * SOFT:        Software ECC 3 byte ECC per 256 Byte data
90  * HW3_256:     Hardware ECC 3 byte ECC per 256 Byte data
91  * HW3_512:     Hardware ECC 3 byte ECC per 512 Byte data
92  *
93  *
94 */
95 #define NAND_ECC_NONE           0
96 #define NAND_ECC_SOFT           1
97 #define NAND_ECC_HW3_256        2
98 #define NAND_ECC_HW3_512        3
99 #define NAND_ECC_HW6_512        4
100 #define NAND_ECC_DISKONCHIP     5
101
102 /*
103  * Constants for Hardware ECC
104 */
105 #define NAND_ECC_READ           0
106 #define NAND_ECC_WRITE          1
107         
108 /*
109  * Enumeration for NAND flash chip state
110  */
111 typedef enum {
112         FL_READY,
113         FL_READING,
114         FL_WRITING,
115         FL_ERASING,
116         FL_SYNCING
117 } nand_state_t;
118
119
120 /*
121  * NAND Private Flash Chip Data
122  *
123  * Structure overview:
124  *
125  *  IO_ADDR_R - address to read the 8 I/O lines of the flash device 
126  *
127  *  IO_ADDR_W - address to write the 8 I/O lines of the flash device 
128  *
129  *  hwcontrol - hardwarespecific function for accesing control-lines
130  *
131  *  dev_ready - hardwarespecific function for accesing device ready/busy line
132  *
133  *  waitfunc - hardwarespecific function for wait on ready
134  *
135  *  calculate_ecc - function for ecc calculation or readback from ecc hardware
136  *
137  *  correct_data - function for ecc correction, matching to ecc generator (sw/hw)
138  *
139  *  enable_hwecc - function to enable (reset) hardware ecc generator
140  *
141  *  eccmod - mode of ecc: see constants
142  *
143  *  eccsize - databytes used per ecc-calculation
144  *
145  *  chip_delay - chip dependent delay for transfering data from array to read regs (tR)
146  *
147  *  chip_lock - spinlock used to protect access to this structure
148  *
149  *  wq - wait queue to sleep on if a NAND operation is in progress
150  *
151  *  state - give the current state of the NAND device
152  *
153  *  page_shift - number of address bits in a page (column address bits)
154  *
155  *  data_buf - data buffer passed to/from MTD user modules
156  *
157  *  data_cache - data cache for redundant page access and shadow for
158  *               ECC failure
159  *
160  *  cache_page - number of last valid page in page_cache 
161  */
162 struct nand_chip {
163         unsigned long   IO_ADDR_R;
164         unsigned long   IO_ADDR_W;
165         void            (*hwcontrol)(int cmd);
166         int             (*dev_ready)(void);
167         void            (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column, int page_addr);
168         int             (*waitfunc)(struct mtd_info *mtd, struct nand_chip *this, int state);
169         void            (*calculate_ecc)(const u_char *dat, u_char *ecc_code);
170         int             (*correct_data)(u_char *dat, u_char *read_ecc, u_char *calc_ecc);
171         void            (*enable_hwecc)(int mode);
172         int             eccmode;
173         int             eccsize;
174         int             chip_delay;
175         spinlock_t      chip_lock;
176         wait_queue_head_t wq;
177         nand_state_t    state;
178         int             page_shift;
179         u_char          *data_buf;
180         u_char          *data_poi;
181 };
182
183 /*
184  * NAND Flash Manufacturer ID Codes
185  */
186 #define NAND_MFR_TOSHIBA        0x98
187 #define NAND_MFR_SAMSUNG        0xec
188 #define NAND_MFR_FUJITSU        0x04
189 #define NAND_MFR_NATIONAL       0x8f
190
191 /*
192  * NAND Flash Device ID Structure
193  *
194  * Structure overview:
195  *
196  *  name - Identify the device type
197  *
198  *  id -  device ID code
199  *
200  *  chipshift - total number of address bits for the device which
201  *              is used to calculate address offsets and the total
202  *              number of bytes the device is capable of.
203  *
204  *  page256 - denotes if flash device has 256 byte pages or not.
205  *
206  *  pageadrlen - number of bytes minus one needed to hold the
207  *               complete address into the flash array. Keep in
208  *               mind that when a read or write is done to a
209  *               specific address, the address is input serially
210  *               8 bits at a time. This structure member is used
211  *               by the read/write routines as a loop index for
212  *               shifting the address out 8 bits at a time.
213  *
214  *  erasesize - size of an erase block in the flash device.
215  */
216 struct nand_flash_dev {
217         char * name;
218         int id;
219         int chipshift;
220         unsigned long erasesize;
221         char page256;
222 };
223
224 /*
225  * NAND Flash Manufacturer ID Structure
226  *
227  *  name - Manufacturer name
228  *
229  *  id - manufacturer ID code of device.
230 */
231 struct nand_manufacturers {
232         int id;
233         char * name;
234 };
235
236 extern struct nand_flash_dev nand_flash_ids[];
237 extern struct nand_manufacturers nand_manuf_ids[];
238
239 /*
240 * Constants for oob configuration
241 */
242 #define NAND_BADBLOCK_POS               5
243
244 #endif /* __LINUX_MTD_NAND_H */