mtd/include/linux/mtd nand.h,1.48,1.49

gleixner at infradead.org gleixner at infradead.org
Wed May 26 09:34:53 EDT 2004


Update of /home/cvs/mtd/include/linux/mtd
In directory phoenix.infradead.org:/tmp/cvs-serv11130

Modified Files:
	nand.h 
Log Message:
Clean up structure docs. Add bad block table support. Signed-off-by: Thomas Gleixner <tglx at linutronix.de>

Index: nand.h
===================================================================
RCS file: /home/cvs/mtd/include/linux/mtd/nand.h,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- nand.h	19 May 2004 20:12:52 -0000	1.48
+++ nand.h	26 May 2004 13:34:50 -0000	1.49
@@ -46,6 +46,8 @@
  *			Split manufacturer and device ID structures 
  *
  *  02-08-2004 tglx 	added option field to nand structure for chip anomalities
+ *  05-25-2004 tglx 	added bad block table support, ST-MICRO manufacturer id
+ *			update of nand_chip structure description
  */
 #ifndef __LINUX_MTD_NAND_H
 #define __LINUX_MTD_NAND_H
@@ -55,10 +57,17 @@
 #include <linux/spinlock.h>
 
 struct mtd_info;
-/*
- * Searches for a NAND device
- */
+/* Scan and identify a NAND device */
 extern int nand_scan (struct mtd_info *mtd, int max_chips);
+/* Free resources held by the NAND device */
+extern void nand_release (struct mtd_info *mtd);
+
+/* Read raw data from the device without ECC */
+extern int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, size_t len);
+
+
+/* The maximum number of NAND chips in an array */
+#define NAND_MAX_CHIPS		8
 
 /* This constant declares the max. oobsize / page, which
  * is supported now. If you add a chip with bigger oobsize/page
@@ -145,7 +154,7 @@
 /* Chip has a array of 4 pages which can be read without
  * additional ready /busy waits */
 #define NAND_4PAGE_ARRAY	0x00000040 
- 
+
 /* Options valid for Samsung large page devices */
 #define NAND_SAMSUNG_LP_OPTIONS \
 	(NAND_NO_PADDING | NAND_CACHEPRG | NAND_COPYBACK)
@@ -156,6 +165,21 @@
 #define NAND_HAS_CACHEPROG(chip) ((chip->options & NAND_CACHEPRG))
 #define NAND_HAS_COPYBACK(chip) ((chip->options & NAND_COPYBACK))
 
+/* Mask to zero out the chip options, which come from the id table */
+#define NAND_CHIPOPTIONS_MSK	0x0000ffff
+
+/* Non chip related options */
+/* Call bad block table scan after chip scan */
+#define NAND_USE_BBT		0x00010000
+/* Use a flash based bad block table. This option is passed to the
+ * default bad block table function. */
+#define NAND_USE_FLASH_BBT	0x00020000
+
+/* Options set by nand scan */
+/* Nand scan has allocated oob_buf */
+#define NAND_OOBBUF_ALLOC	0x40000000
+/* Nand scan has allocated data_buf */
+#define NAND_DATABUF_ALLOC	0x80000000
 /*
  * Enumeration for NAND flash chip state
  */
@@ -174,43 +198,51 @@
  *
  * Structure overview:
  *
- *  IO_ADDR_R - address to read the 8 I/O lines of the flash device 
- *
- *  IO_ADDR_W - address to write the 8 I/O lines of the flash device 
- *
- *  hwcontrol - hardwarespecific function for accesing control-lines
- *
- *  dev_ready - hardwarespecific function for accesing device ready/busy line
- *
- *  waitfunc - hardwarespecific function for wait on ready
- *
- *  calculate_ecc - function for ecc calculation or readback from ecc hardware
- *
- *  correct_data - function for ecc correction, matching to ecc generator (sw/hw)
- *
- *  enable_hwecc - function to enable (reset) hardware ecc generator
- *
- *  eccmod - mode of ecc: see constants
- *
- *  eccsize - databytes used per ecc-calculation
- *
- *  chip_delay - chip dependent delay for transfering data from array to read regs (tR)
- *
- *  chip_lock - spinlock used to protect access to this structure
- *
- *  wq - wait queue to sleep on if a NAND operation is in progress
- *
- *  state - give the current state of the NAND device
- *
- *  page_shift - number of address bits in a page (column address bits)
- *
- *  data_buf - data buffer passed to/from MTD user modules
- *
- *  data_cache - data cache for redundant page access and shadow for
- *		 ECC failure
- *
- *  cache_page - number of last valid page in page_cache 
+ * IO_ADDR_R 		address to read the 8 I/O lines of the flash device 
+ * IO_ADDR_W		address to write the 8 I/O lines of the flash device 
+ * read_byte		read one byte from the chip
+ * write_byte		wrtie one byte to the chip
+ * read_word		read one word from the chip
+ * write_word		write one word to the chip
+ * write_buf		write data from the buffer to the chip
+ * read_buf		read data from the chip into the buffer
+ * verify_buf		verify buffer contents against the chip data
+ * select_chip		select chip nr
+ * block_bad		check, if the block is bad
+ * block_markbad	mark the block bad
+ * hwcontrol 		hardwarespecific function for accesing control-lines
+ * dev_ready		hardwarespecific function for accesing device ready/busy line
+ * waitfunc 		hardwarespecific function for wait on ready
+ * calculate_ecc 	function for ecc calculation or readback from ecc hardware
+ * correct_data		function for ecc correction, matching to ecc generator (sw/hw)
+ * enable_hwecc		function to enable (reset) hardware ecc generator
+ * erase_cmd		erease command write function
+ * scan_bbt		function to scan bad block table
+ * eccmod 		mode of ecc, see defines above
+ * eccsize 		databytes used per ecc-calculation
+ * chip_delay		chip dependent delay for transfering data from array to read regs (tR)
+ * chip_lock		spinlock used to protect access to this structure and the chip
+ * wq			wait queue to sleep on if a NAND operation is in progress
+ * state 		the current state of the NAND device
+ * page_shift 		number of address bits in a page (column address bits)
+ * erase_shift		number of address bits in an eraseblock
+ * data_buf		internal buffer for one page + oob 
+ * oob_buf		oob buffer for one eraseblock
+ * oobdirty		indicates that oob_buf must be reinitialized
+ * data_poi		pointer to a data buffer
+ * options		various chip options
+ * badblockpos		position of the bad block marker in the oob area
+ * numchips		number of physical chips
+ * pagemask		page number mask = number of (pages / chip) - 1
+ * pagebuf		holds the pagenumber which is currently in data_buf
+ * autooob		the default (auto)placement scheme
+ * bbt			bad block table pointer
+ * bbt_td		bad block table descriptor for flash lookup
+ * bbt_md		bad block table mirror descriptor
+ * bbt_size		chip size reserved for the bbt tables 
+ * priv			pointer to private chip date
  */
+ 
 struct nand_chip {
 	unsigned long 	IO_ADDR_R;
 	unsigned long 	IO_ADDR_W;
@@ -234,6 +266,7 @@
 	int 		(*correct_data)(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc);
 	void		(*enable_hwecc)(struct mtd_info *mtd, int mode);
 	void		(*erase_cmd)(struct mtd_info *mtd, int page);
+	int		(*scan_bbt)(struct mtd_info *mtd);
 	int		eccmode;
 	int		eccsize;
 	int		eccsteps;
@@ -254,6 +287,10 @@
 	int		pagemask;
 	int		pagebuf;
 	struct nand_oobinfo	*autooob;
+	uint8_t		*bbt;
+	struct nand_bbt_descr	*bbt_td;
+	struct nand_bbt_descr	*bbt_md;
+	unsigned long	bbt_size;
 	void		*priv;
 };
 
@@ -265,6 +302,7 @@
 #define NAND_MFR_FUJITSU	0x04
 #define NAND_MFR_NATIONAL	0x8f
 #define NAND_MFR_RENESAS	0x07
+#define NAND_MFR_STMICRO	0x20
 
 /*
  * NAND Flash Device ID Structure
@@ -303,6 +341,69 @@
 extern struct nand_flash_dev nand_flash_ids[];
 extern struct nand_manufacturers nand_manuf_ids[];
 
+/* Descriptor for the bad block table marker and the descriptor for the 
+ * pattern which identifies good and bad blocks.
+ *
+ * options	options for this descriptor
+ * pages	the page(s) where we find the bbt, used with option BBT_ABSPAGE
+ *		when bbt is searched, then we store the found bbts pages here
+ *		Its an array and supports up to 8 chips now
+ * offs		offset of the pattern in the oob area of the page
+ * veroffs	offset of the bbt version counter in the oob are of the page
+ * version	version read from the bbt page during scan
+ * len		length of the pattern, if 0 no pattern check is performed
+ * maxblock	maximum number of blocks to search for a bbt
+ * pattern	pattern to identify bad block table or factory marked good / 
+ *		bad blocks, can be NULL, if len = 0
+*/
+struct nand_bbt_descr {
+	int	options;
+	int	pages[NAND_MAX_CHIPS];
+	int	offs;
+	int	veroffs;
+	int	version;
+	int	len;
+	int 	maxblocks;
+	uint8_t	*pattern;
+};
+
+/* Options for the bad block table descriptors */
+
+/* The number of bits used per block in the bbt on the device */
+#define NAND_BBT_NRBITS_MSK	0x0000000F
+#define NAND_BBT_1BIT		0x00000001
+#define NAND_BBT_2BIT		0x00000002
+#define NAND_BBT_4BIT		0x00000004
+#define NAND_BBT_8BIT		0x00000008
+/* The bad block table is in the last good block of the device */
+#define	NAND_BBT_LASTBLOCK	0x00000010
+/* The bbt is at the given page, else we must scan for the bbt */
+#define NAND_BBT_ABSPAGE	0x00000020
+/* The bbt is at the given page, else we must scan for the bbt */
+#define NAND_BBT_SEARCH		0x00000040
+/* bbt is stored per chip on multichip devices */
+#define NAND_BBT_PERCHIP	0x00000080
+/* bbt has a version counter at offset veroffs */
+#define NAND_BBT_VERSION	0x00000100
+/* Create a bbt if none axists */
+#define NAND_BBT_CREATE		0x00000200
+/* Search good / bad pattern through all pages of a block */
+#define NAND_BBT_SCANALLPAGES	0x00000400
+/* Scan block empty during good / bad block scan */
+#define NAND_BBT_SCANEMPTY	0x00000800
+/* Write bbt if neccecary */
+#define NAND_BBT_WRITE		0x00001000
+/* Read and write back block contents when writing bbt */
+#define NAND_BBT_SAVECONTENT	0x00002000
+/* Automatically reduce device size if last block based bbts are used */
+#define NAND_BBT_REDUCESIZE	0x00004000
+
+/* The maximum number of blocks to scan for a bbt */
+#define NAND_BBT_SCAN_MAXBLOCKS	4
+
+extern int nand_scan_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd);
+extern int nand_update_bbt (struct mtd_info *mtd);
+extern int nand_default_bbt (struct mtd_info *mtd);
 /*
 * Constants for oob configuration
 */





More information about the linux-mtd-cvs mailing list