xref: /openbmc/u-boot/include/linux/mtd/onenand.h (revision 6e80f5aa)
1 /*
2  *  linux/include/linux/mtd/onenand.h
3  *
4  *  Copyright (C) 2005-2007 Samsung Electronics
5  *  Kyungmin Park <kyungmin.park@samsung.com>
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/mtd/onenand_regs.h>
16 
17 /* Note: The header order is impoertant */
18 #include <onenand_uboot.h>
19 
20 #include <linux/mtd/compat.h>
21 #include <linux/mtd/bbm.h>
22 
23 #define MAX_BUFFERRAM		2
24 #define MAX_ONENAND_PAGESIZE	(2048 + 64)
25 
26 /* Scan and identify a OneNAND device */
27 extern int onenand_scan (struct mtd_info *mtd, int max_chips);
28 /* Free resources held by the OneNAND device */
29 extern void onenand_release (struct mtd_info *mtd);
30 
31 /**
32  * struct onenand_bufferram - OneNAND BufferRAM Data
33  * @param block		block address in BufferRAM
34  * @param page		page address in BufferRAM
35  * @param valid		valid flag
36  */
37 struct onenand_bufferram {
38 	int block;
39 	int page;
40 	int valid;
41 };
42 
43 /**
44  * struct onenand_chip - OneNAND Private Flash Chip Data
45  * @param base		[BOARDSPECIFIC] address to access OneNAND
46  * @param chipsize	[INTERN] the size of one chip for multichip arrays
47  * @param device_id	[INTERN] device ID
48  * @param verstion_id	[INTERN] version ID
49  * @param options	[BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about
50  * @param erase_shift	[INTERN] number of address bits in a block
51  * @param page_shift	[INTERN] number of address bits in a page
52  * @param ppb_shift	[INTERN] number of address bits in a pages per block
53  * @param page_mask	[INTERN] a page per block mask
54  * @param writesize	[INTERN] a real page size
55  * @param bufferam_index	[INTERN] BufferRAM index
56  * @param bufferam	[INTERN] BufferRAM info
57  * @param readw		[REPLACEABLE] hardware specific function for read short
58  * @param writew	[REPLACEABLE] hardware specific function for write short
59  * @param command	[REPLACEABLE] hardware specific function for writing commands to the chip
60  * @param wait		[REPLACEABLE] hardware specific function for wait on ready
61  * @param read_bufferram	[REPLACEABLE] hardware specific function for BufferRAM Area
62  * @param write_bufferram	[REPLACEABLE] hardware specific function for BufferRAM Area
63  * @param chip_lock	[INTERN] spinlock used to protect access to this structure and the chip
64  * @param wq		[INTERN] wait queue to sleep on if a OneNAND operation is in progress
65  * @param state		[INTERN] the current state of the OneNAND device
66  * @param autooob	[REPLACEABLE] the default (auto)placement scheme
67  * @param priv		[OPTIONAL] pointer to private chip date
68  */
69 struct onenand_chip {
70 	void __iomem *base;
71 	unsigned int chipsize;
72 	unsigned int device_id;
73 	unsigned int options;
74 
75 	unsigned int erase_shift;
76 	unsigned int page_shift;
77 	unsigned int ppb_shift;	/* Pages per block shift */
78 	unsigned int page_mask;
79 	unsigned int writesize;
80 
81 	unsigned int bufferram_index;
82 	struct onenand_bufferram bufferram[MAX_BUFFERRAM];
83 
84 	int (*command) (struct mtd_info * mtd, int cmd, loff_t address,
85 			size_t len);
86 	int (*wait) (struct mtd_info * mtd, int state);
87 	int (*read_bufferram) (struct mtd_info * mtd, int area,
88 			       unsigned char *buffer, int offset, size_t count);
89 	int (*write_bufferram) (struct mtd_info * mtd, int area,
90 				const unsigned char *buffer, int offset,
91 				size_t count);
92 	unsigned short (*read_word) (void __iomem * addr);
93 	void (*write_word) (unsigned short value, void __iomem * addr);
94 	void (*mmcontrol) (struct mtd_info * mtd, int sync_read);
95 	int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
96 	int (*scan_bbt)(struct mtd_info *mtd);
97 
98 	int state;
99 	unsigned char *page_buf;
100 	unsigned char *oob_buf;
101 
102 	struct nand_oobinfo *autooob;
103 	struct nand_ecclayout *ecclayout;
104 
105 	void *bbm;
106 
107 	void *priv;
108 };
109 
110 /*
111  * Helper macros
112  */
113 #define ONENAND_CURRENT_BUFFERRAM(this)		(this->bufferram_index)
114 #define ONENAND_NEXT_BUFFERRAM(this)		(this->bufferram_index ^ 1)
115 #define ONENAND_SET_NEXT_BUFFERRAM(this)	(this->bufferram_index ^= 1)
116 #define ONENAND_SET_PREV_BUFFERRAM(this)	(this->bufferram_index ^= 1)
117 #define ONENAND_SET_BUFFERRAM0(this)		(this->bufferram_index = 0)
118 #define ONENAND_SET_BUFFERRAM1(this)		(this->bufferram_index = 1)
119 
120 #define ONENAND_IS_DDP(this)						\
121 	(this->device_id & ONENAND_DEVICE_IS_DDP)
122 
123 #define ONENAND_IS_2PLANE(this)			(0)
124 
125 /*
126  * Options bits
127  */
128 #define ONENAND_CONT_LOCK		(0x0001)
129 #define ONENAND_PAGEBUF_ALLOC		(0x1000)
130 #define ONENAND_OOBBUF_ALLOC		(0x2000)
131 
132 /*
133  * OneNAND Flash Manufacturer ID Codes
134  */
135 #define ONENAND_MFR_SAMSUNG	0xec
136 #define ONENAND_MFR_UNKNOWN	0x00
137 
138 /**
139  * struct nand_manufacturers - NAND Flash Manufacturer ID Structure
140  * @param name:		Manufacturer name
141  * @param id:		manufacturer ID code of device.
142 */
143 struct onenand_manufacturers {
144 	int id;
145 	char *name;
146 };
147 
148 int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
149 			struct mtd_oob_ops *ops);
150 
151 #endif				/* __LINUX_MTD_ONENAND_H */
152