2 * linux/include/linux/mtd/nand.h
4 * Copyright (c) 2000 David Woodhouse <dwmw2@mvhi.com>
5 * Steven J. Hill <sjhill@realitydiluted.com>
6 * Thomas Gleixner <tglx@linutronix.de>
8 * $Id: nand.h,v 1.25 2003/05/21 15:15:02 dwmw2 Exp $
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.
15 * Contains standard defines and IDs for NAND flash devices
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
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,
45 * 11-25-2002 tglx Added Manufacturer code FUJITSU, NATIONAL
46 * Split manufacturer and device ID structures
48 #ifndef __LINUX_MTD_NAND_H
49 #define __LINUX_MTD_NAND_H
51 #include <linux/config.h>
52 #include <linux/wait.h>
53 #include <linux/spinlock.h>
57 * Searches for a NAND device
59 extern int nand_scan (struct mtd_info *mtd);
62 * Constants for hardware specific CLE/ALE/NCE function
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
72 * Standard NAND flash commands
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
86 * Constants for ECC_MODES
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
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
103 * Constants for Hardware ECC
105 #define NAND_ECC_READ 0
106 #define NAND_ECC_WRITE 1
109 * Enumeration for NAND flash chip state
121 * NAND Private Flash Chip Data
123 * Structure overview:
125 * IO_ADDR_R - address to read the 8 I/O lines of the flash device
127 * IO_ADDR_W - address to write the 8 I/O lines of the flash device
129 * hwcontrol - hardwarespecific function for accesing control-lines
131 * dev_ready - hardwarespecific function for accesing device ready/busy line
133 * waitfunc - hardwarespecific function for wait on ready
135 * calculate_ecc - function for ecc calculation or readback from ecc hardware
137 * correct_data - function for ecc correction, matching to ecc generator (sw/hw)
139 * enable_hwecc - function to enable (reset) hardware ecc generator
141 * eccmod - mode of ecc: see constants
143 * eccsize - databytes used per ecc-calculation
145 * chip_delay - chip dependent delay for transfering data from array to read regs (tR)
147 * chip_lock - spinlock used to protect access to this structure
149 * wq - wait queue to sleep on if a NAND operation is in progress
151 * state - give the current state of the NAND device
153 * page_shift - number of address bits in a page (column address bits)
155 * data_buf - data buffer passed to/from MTD user modules
157 * data_cache - data cache for redundant page access and shadow for
160 * cache_page - number of last valid page in page_cache
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);
175 spinlock_t chip_lock;
176 wait_queue_head_t wq;
184 * NAND Flash Manufacturer ID Codes
186 #define NAND_MFR_TOSHIBA 0x98
187 #define NAND_MFR_SAMSUNG 0xec
188 #define NAND_MFR_FUJITSU 0x04
189 #define NAND_MFR_NATIONAL 0x8f
192 * NAND Flash Device ID Structure
194 * Structure overview:
196 * name - Identify the device type
198 * id - device ID code
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.
204 * page256 - denotes if flash device has 256 byte pages or not.
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.
214 * erasesize - size of an erase block in the flash device.
216 struct nand_flash_dev {
220 unsigned long erasesize;
225 * NAND Flash Manufacturer ID Structure
227 * name - Manufacturer name
229 * id - manufacturer ID code of device.
231 struct nand_manufacturers {
236 extern struct nand_flash_dev nand_flash_ids[];
237 extern struct nand_manufacturers nand_manuf_ids[];
240 * Constants for oob configuration
242 #define NAND_BADBLOCK_POS 5
244 #endif /* __LINUX_MTD_NAND_H */