xref: /rk3399_rockchip-uboot/include/mtd/mtd-abi.h (revision dfe64e2c89731a3f9950d7acd8681b68df2bae03)
1*dfe64e2cSSergey Lapin /*
2*dfe64e2cSSergey Lapin  * $Id: mtd-abi.h,v 1.13 2005/11/07 11:14:56 gleixner Exp $
3*dfe64e2cSSergey Lapin  *
4*dfe64e2cSSergey Lapin  * Portions of MTD ABI definition which are shared by kernel and user space
5*dfe64e2cSSergey Lapin  */
6*dfe64e2cSSergey Lapin 
7*dfe64e2cSSergey Lapin #ifndef __MTD_ABI_H__
8*dfe64e2cSSergey Lapin #define __MTD_ABI_H__
9*dfe64e2cSSergey Lapin 
10*dfe64e2cSSergey Lapin #if 1
11*dfe64e2cSSergey Lapin #include <linux/compat.h>
12*dfe64e2cSSergey Lapin #endif
13*dfe64e2cSSergey Lapin 
14*dfe64e2cSSergey Lapin #include <linux/compiler.h>
15*dfe64e2cSSergey Lapin 
16*dfe64e2cSSergey Lapin struct erase_info_user {
17*dfe64e2cSSergey Lapin 	uint32_t start;
18*dfe64e2cSSergey Lapin 	uint32_t length;
19*dfe64e2cSSergey Lapin };
20*dfe64e2cSSergey Lapin 
21*dfe64e2cSSergey Lapin struct mtd_oob_buf {
22*dfe64e2cSSergey Lapin 	uint32_t start;
23*dfe64e2cSSergey Lapin 	uint32_t length;
24*dfe64e2cSSergey Lapin 	unsigned char __user *ptr;
25*dfe64e2cSSergey Lapin };
26*dfe64e2cSSergey Lapin 
27*dfe64e2cSSergey Lapin /*
28*dfe64e2cSSergey Lapin  * MTD operation modes
29*dfe64e2cSSergey Lapin  *
30*dfe64e2cSSergey Lapin  * @MTD_OPS_PLACE_OOB:	OOB data are placed at the given offset (default)
31*dfe64e2cSSergey Lapin  * @MTD_OPS_AUTO_OOB:	OOB data are automatically placed at the free areas
32*dfe64e2cSSergey Lapin  *			which are defined by the internal ecclayout
33*dfe64e2cSSergey Lapin  * @MTD_OPS_RAW:	data are transferred as-is, with no error correction;
34*dfe64e2cSSergey Lapin  *			this mode implies %MTD_OPS_PLACE_OOB
35*dfe64e2cSSergey Lapin  *
36*dfe64e2cSSergey Lapin  * These modes can be passed to ioctl(MEMWRITE) and are also used internally.
37*dfe64e2cSSergey Lapin  * See notes on "MTD file modes" for discussion on %MTD_OPS_RAW vs.
38*dfe64e2cSSergey Lapin  * %MTD_FILE_MODE_RAW.
39*dfe64e2cSSergey Lapin  */
40*dfe64e2cSSergey Lapin enum {
41*dfe64e2cSSergey Lapin 	MTD_OPS_PLACE_OOB = 0,
42*dfe64e2cSSergey Lapin 	MTD_OPS_AUTO_OOB = 1,
43*dfe64e2cSSergey Lapin 	MTD_OPS_RAW = 2,
44*dfe64e2cSSergey Lapin };
45*dfe64e2cSSergey Lapin 
46*dfe64e2cSSergey Lapin #define MTD_ABSENT		0
47*dfe64e2cSSergey Lapin #define MTD_RAM			1
48*dfe64e2cSSergey Lapin #define MTD_ROM			2
49*dfe64e2cSSergey Lapin #define MTD_NORFLASH		3
50*dfe64e2cSSergey Lapin #define MTD_NANDFLASH		4
51*dfe64e2cSSergey Lapin #define MTD_DATAFLASH		6
52*dfe64e2cSSergey Lapin #define MTD_UBIVOLUME		7
53*dfe64e2cSSergey Lapin 
54*dfe64e2cSSergey Lapin #define MTD_WRITEABLE		0x400	/* Device is writeable */
55*dfe64e2cSSergey Lapin #define MTD_BIT_WRITEABLE	0x800	/* Single bits can be flipped */
56*dfe64e2cSSergey Lapin #define MTD_NO_ERASE		0x1000	/* No erase necessary */
57*dfe64e2cSSergey Lapin #define MTD_STUPID_LOCK		0x2000	/* Always locked after reset */
58*dfe64e2cSSergey Lapin 
59*dfe64e2cSSergey Lapin /* Some common devices / combinations of capabilities */
60*dfe64e2cSSergey Lapin #define MTD_CAP_ROM		0
61*dfe64e2cSSergey Lapin #define MTD_CAP_RAM		(MTD_WRITEABLE | MTD_BIT_WRITEABLE | MTD_NO_ERASE)
62*dfe64e2cSSergey Lapin #define MTD_CAP_NORFLASH	(MTD_WRITEABLE | MTD_BIT_WRITEABLE)
63*dfe64e2cSSergey Lapin #define MTD_CAP_NANDFLASH	(MTD_WRITEABLE)
64*dfe64e2cSSergey Lapin 
65*dfe64e2cSSergey Lapin /* ECC byte placement */
66*dfe64e2cSSergey Lapin #define MTD_NANDECC_OFF		0	/* Switch off ECC (Not recommended) */
67*dfe64e2cSSergey Lapin #define MTD_NANDECC_PLACE	1	/* Use the given placement in the structure (YAFFS1 legacy mode) */
68*dfe64e2cSSergey Lapin #define MTD_NANDECC_AUTOPLACE	2	/* Use the default placement scheme */
69*dfe64e2cSSergey Lapin #define MTD_NANDECC_PLACEONLY	3	/* Use the given placement in the structure (Do not store ecc result on read) */
70*dfe64e2cSSergey Lapin #define MTD_NANDECC_AUTOPL_USR	4	/* Use the given autoplacement scheme rather than using the default */
71*dfe64e2cSSergey Lapin 
72*dfe64e2cSSergey Lapin /* OTP mode selection */
73*dfe64e2cSSergey Lapin #define MTD_OTP_OFF		0
74*dfe64e2cSSergey Lapin #define MTD_OTP_FACTORY		1
75*dfe64e2cSSergey Lapin #define MTD_OTP_USER		2
76*dfe64e2cSSergey Lapin 
77*dfe64e2cSSergey Lapin struct mtd_info_user {
78*dfe64e2cSSergey Lapin 	uint8_t type;
79*dfe64e2cSSergey Lapin 	uint32_t flags;
80*dfe64e2cSSergey Lapin 	uint32_t size;			/* Total size of the MTD */
81*dfe64e2cSSergey Lapin 	uint32_t erasesize;
82*dfe64e2cSSergey Lapin 	uint32_t writesize;
83*dfe64e2cSSergey Lapin 	uint32_t oobsize;		/* Amount of OOB data per block (e.g. 16) */
84*dfe64e2cSSergey Lapin 	/* The below two fields are obsolete and broken, do not use them
85*dfe64e2cSSergey Lapin 	 * (TODO: remove at some point) */
86*dfe64e2cSSergey Lapin 	uint32_t ecctype;
87*dfe64e2cSSergey Lapin 	uint32_t eccsize;
88*dfe64e2cSSergey Lapin };
89*dfe64e2cSSergey Lapin 
90*dfe64e2cSSergey Lapin struct region_info_user {
91*dfe64e2cSSergey Lapin 	uint32_t offset;		/* At which this region starts,
92*dfe64e2cSSergey Lapin 					 * from the beginning of the MTD */
93*dfe64e2cSSergey Lapin 	uint32_t erasesize;		/* For this region */
94*dfe64e2cSSergey Lapin 	uint32_t numblocks;		/* Number of blocks in this region */
95*dfe64e2cSSergey Lapin 	uint32_t regionindex;
96*dfe64e2cSSergey Lapin };
97*dfe64e2cSSergey Lapin 
98*dfe64e2cSSergey Lapin struct otp_info {
99*dfe64e2cSSergey Lapin 	uint32_t start;
100*dfe64e2cSSergey Lapin 	uint32_t length;
101*dfe64e2cSSergey Lapin 	uint32_t locked;
102*dfe64e2cSSergey Lapin };
103*dfe64e2cSSergey Lapin 
104*dfe64e2cSSergey Lapin /* Get basic MTD characteristics info (better to use sysfs) */
105*dfe64e2cSSergey Lapin #define MEMGETINFO		_IOR('M', 1, struct mtd_info_user)
106*dfe64e2cSSergey Lapin /* Erase segment of MTD */
107*dfe64e2cSSergey Lapin #define MEMERASE		_IOW('M', 2, struct erase_info_user)
108*dfe64e2cSSergey Lapin /* Write out-of-band data from MTD */
109*dfe64e2cSSergey Lapin #define MEMWRITEOOB		_IOWR('M', 3, struct mtd_oob_buf)
110*dfe64e2cSSergey Lapin /* Read out-of-band data from MTD */
111*dfe64e2cSSergey Lapin #define MEMREADOOB		_IOWR('M', 4, struct mtd_oob_buf)
112*dfe64e2cSSergey Lapin /* Lock a chip (for MTD that supports it) */
113*dfe64e2cSSergey Lapin #define MEMLOCK			_IOW('M', 5, struct erase_info_user)
114*dfe64e2cSSergey Lapin /* Unlock a chip (for MTD that supports it) */
115*dfe64e2cSSergey Lapin #define MEMUNLOCK		_IOW('M', 6, struct erase_info_user)
116*dfe64e2cSSergey Lapin /* Get the number of different erase regions */
117*dfe64e2cSSergey Lapin #define MEMGETREGIONCOUNT	_IOR('M', 7, int)
118*dfe64e2cSSergey Lapin /* Get information about the erase region for a specific index */
119*dfe64e2cSSergey Lapin #define MEMGETREGIONINFO	_IOWR('M', 8, struct region_info_user)
120*dfe64e2cSSergey Lapin /* Get info about OOB modes (e.g., RAW, PLACE, AUTO) - legacy interface */
121*dfe64e2cSSergey Lapin #define MEMSETOOBSEL		_IOW('M', 9, struct nand_oobinfo)
122*dfe64e2cSSergey Lapin #define MEMGETOOBSEL		_IOR('M', 10, struct nand_oobinfo)
123*dfe64e2cSSergey Lapin /* Check if an eraseblock is bad */
124*dfe64e2cSSergey Lapin #define MEMGETBADBLOCK		_IOW('M', 11, loff_t)
125*dfe64e2cSSergey Lapin /* Mark an eraseblock as bad */
126*dfe64e2cSSergey Lapin #define MEMSETBADBLOCK		_IOW('M', 12, loff_t)
127*dfe64e2cSSergey Lapin /* Set OTP (One-Time Programmable) mode (factory vs. user) */
128*dfe64e2cSSergey Lapin #define OTPSELECT		_IOR('M', 13, int)
129*dfe64e2cSSergey Lapin /* Get number of OTP (One-Time Programmable) regions */
130*dfe64e2cSSergey Lapin #define OTPGETREGIONCOUNT	_IOW('M', 14, int)
131*dfe64e2cSSergey Lapin /* Get all OTP (One-Time Programmable) info about MTD */
132*dfe64e2cSSergey Lapin #define OTPGETREGIONINFO	_IOW('M', 15, struct otp_info)
133*dfe64e2cSSergey Lapin /* Lock a given range of user data (must be in mode %MTD_FILE_MODE_OTP_USER) */
134*dfe64e2cSSergey Lapin #define OTPLOCK			_IOR('M', 16, struct otp_info)
135*dfe64e2cSSergey Lapin /* Get ECC layout (deprecated) */
136*dfe64e2cSSergey Lapin #define ECCGETLAYOUT		_IOR('M', 17, struct nand_ecclayout)
137*dfe64e2cSSergey Lapin /* Get statistics about corrected/uncorrected errors */
138*dfe64e2cSSergey Lapin #define ECCGETSTATS		_IOR('M', 18, struct mtd_ecc_stats)
139*dfe64e2cSSergey Lapin /* Set MTD mode on a per-file-descriptor basis (see "MTD file modes") */
140*dfe64e2cSSergey Lapin #define MTDFILEMODE		_IO('M', 19)
141*dfe64e2cSSergey Lapin 
142*dfe64e2cSSergey Lapin /*
143*dfe64e2cSSergey Lapin  * Obsolete legacy interface. Keep it in order not to break userspace
144*dfe64e2cSSergey Lapin  * interfaces
145*dfe64e2cSSergey Lapin  */
146*dfe64e2cSSergey Lapin struct nand_oobinfo {
147*dfe64e2cSSergey Lapin 	uint32_t useecc;
148*dfe64e2cSSergey Lapin 	uint32_t eccbytes;
149*dfe64e2cSSergey Lapin 	uint32_t oobfree[8][2];
150*dfe64e2cSSergey Lapin 	uint32_t eccpos[48];
151*dfe64e2cSSergey Lapin };
152*dfe64e2cSSergey Lapin 
153*dfe64e2cSSergey Lapin struct nand_oobfree {
154*dfe64e2cSSergey Lapin 	uint32_t offset;
155*dfe64e2cSSergey Lapin 	uint32_t length;
156*dfe64e2cSSergey Lapin };
157*dfe64e2cSSergey Lapin 
158*dfe64e2cSSergey Lapin #define MTD_MAX_OOBFREE_ENTRIES	8
159*dfe64e2cSSergey Lapin /*
160*dfe64e2cSSergey Lapin  * ECC layout control structure. Exported to userspace for
161*dfe64e2cSSergey Lapin  * diagnosis and to allow creation of raw images
162*dfe64e2cSSergey Lapin  */
163*dfe64e2cSSergey Lapin struct nand_ecclayout {
164*dfe64e2cSSergey Lapin 	uint32_t eccbytes;
165*dfe64e2cSSergey Lapin 	uint32_t eccpos[128];
166*dfe64e2cSSergey Lapin 	uint32_t oobavail;
167*dfe64e2cSSergey Lapin 	struct nand_oobfree oobfree[MTD_MAX_OOBFREE_ENTRIES];
168*dfe64e2cSSergey Lapin };
169*dfe64e2cSSergey Lapin 
170*dfe64e2cSSergey Lapin /**
171*dfe64e2cSSergey Lapin  * struct mtd_ecc_stats - error correction stats
172*dfe64e2cSSergey Lapin  *
173*dfe64e2cSSergey Lapin  * @corrected:	number of corrected bits
174*dfe64e2cSSergey Lapin  * @failed:	number of uncorrectable errors
175*dfe64e2cSSergey Lapin  * @badblocks:	number of bad blocks in this partition
176*dfe64e2cSSergey Lapin  * @bbtblocks:	number of blocks reserved for bad block tables
177*dfe64e2cSSergey Lapin  */
178*dfe64e2cSSergey Lapin struct mtd_ecc_stats {
179*dfe64e2cSSergey Lapin 	uint32_t corrected;
180*dfe64e2cSSergey Lapin 	uint32_t failed;
181*dfe64e2cSSergey Lapin 	uint32_t badblocks;
182*dfe64e2cSSergey Lapin 	uint32_t bbtblocks;
183*dfe64e2cSSergey Lapin };
184*dfe64e2cSSergey Lapin 
185*dfe64e2cSSergey Lapin /*
186*dfe64e2cSSergey Lapin  * MTD file modes - for read/write access to MTD
187*dfe64e2cSSergey Lapin  *
188*dfe64e2cSSergey Lapin  * @MTD_FILE_MODE_NORMAL:	OTP disabled, ECC enabled
189*dfe64e2cSSergey Lapin  * @MTD_FILE_MODE_OTP_FACTORY:	OTP enabled in factory mode
190*dfe64e2cSSergey Lapin  * @MTD_FILE_MODE_OTP_USER:	OTP enabled in user mode
191*dfe64e2cSSergey Lapin  * @MTD_FILE_MODE_RAW:		OTP disabled, ECC disabled
192*dfe64e2cSSergey Lapin  *
193*dfe64e2cSSergey Lapin  * These modes can be set via ioctl(MTDFILEMODE). The mode mode will be retained
194*dfe64e2cSSergey Lapin  * separately for each open file descriptor.
195*dfe64e2cSSergey Lapin  *
196*dfe64e2cSSergey Lapin  * Note: %MTD_FILE_MODE_RAW provides the same functionality as %MTD_OPS_RAW -
197*dfe64e2cSSergey Lapin  * raw access to the flash, without error correction or autoplacement schemes.
198*dfe64e2cSSergey Lapin  * Wherever possible, the MTD_OPS_* mode will override the MTD_FILE_MODE_* mode
199*dfe64e2cSSergey Lapin  * (e.g., when using ioctl(MEMWRITE)), but in some cases, the MTD_FILE_MODE is
200*dfe64e2cSSergey Lapin  * used out of necessity (e.g., `write()', ioctl(MEMWRITEOOB64)).
201*dfe64e2cSSergey Lapin  */
202*dfe64e2cSSergey Lapin enum mtd_file_modes {
203*dfe64e2cSSergey Lapin 	MTD_MODE_NORMAL = MTD_OTP_OFF,
204*dfe64e2cSSergey Lapin 	MTD_MODE_OTP_FACTORY = MTD_OTP_FACTORY,
205*dfe64e2cSSergey Lapin 	MTD_MODE_OTP_USER = MTD_OTP_USER,
206*dfe64e2cSSergey Lapin 	MTD_MODE_RAW,
207*dfe64e2cSSergey Lapin };
208*dfe64e2cSSergey Lapin 
209*dfe64e2cSSergey Lapin #endif /* __MTD_ABI_H__ */
210