xref: /openbmc/linux/include/linux/mtd/mtd.h (revision a1452a37)
11da177e4SLinus Torvalds /*
2a1452a37SDavid Woodhouse  * Copyright © 1999-2010 David Woodhouse <dwmw2@infradead.org> et al.
31da177e4SLinus Torvalds  *
4a1452a37SDavid Woodhouse  * This program is free software; you can redistribute it and/or modify
5a1452a37SDavid Woodhouse  * it under the terms of the GNU General Public License as published by
6a1452a37SDavid Woodhouse  * the Free Software Foundation; either version 2 of the License, or
7a1452a37SDavid Woodhouse  * (at your option) any later version.
8a1452a37SDavid Woodhouse  *
9a1452a37SDavid Woodhouse  * This program is distributed in the hope that it will be useful,
10a1452a37SDavid Woodhouse  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11a1452a37SDavid Woodhouse  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12a1452a37SDavid Woodhouse  * GNU General Public License for more details.
13a1452a37SDavid Woodhouse  *
14a1452a37SDavid Woodhouse  * You should have received a copy of the GNU General Public License
15a1452a37SDavid Woodhouse  * along with this program; if not, write to the Free Software
16a1452a37SDavid Woodhouse  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17a1452a37SDavid Woodhouse  *
181da177e4SLinus Torvalds  */
191da177e4SLinus Torvalds 
201da177e4SLinus Torvalds #ifndef __MTD_MTD_H__
211da177e4SLinus Torvalds #define __MTD_MTD_H__
221da177e4SLinus Torvalds 
231da177e4SLinus Torvalds #include <linux/types.h>
241da177e4SLinus Torvalds #include <linux/module.h>
251da177e4SLinus Torvalds #include <linux/uio.h>
26963a6fb0SNicolas Pitre #include <linux/notifier.h>
271f24b5a8SDavid Brownell #include <linux/device.h>
281da177e4SLinus Torvalds 
291da177e4SLinus Torvalds #include <linux/mtd/compatmac.h>
301da177e4SLinus Torvalds #include <mtd/mtd-abi.h>
311da177e4SLinus Torvalds 
3269423d99SAdrian Hunter #include <asm/div64.h>
3369423d99SAdrian Hunter 
341da177e4SLinus Torvalds #define MTD_CHAR_MAJOR 90
351da177e4SLinus Torvalds #define MTD_BLOCK_MAJOR 31
361da177e4SLinus Torvalds 
371da177e4SLinus Torvalds #define MTD_ERASE_PENDING      	0x01
381da177e4SLinus Torvalds #define MTD_ERASING		0x02
391da177e4SLinus Torvalds #define MTD_ERASE_SUSPEND	0x04
401da177e4SLinus Torvalds #define MTD_ERASE_DONE          0x08
411da177e4SLinus Torvalds #define MTD_ERASE_FAILED        0x10
421da177e4SLinus Torvalds 
4369423d99SAdrian Hunter #define MTD_FAIL_ADDR_UNKNOWN -1LL
44bb0eb217SAdrian Hunter 
451da177e4SLinus Torvalds /* If the erase fails, fail_addr might indicate exactly which block failed.  If
46bb0eb217SAdrian Hunter    fail_addr = MTD_FAIL_ADDR_UNKNOWN, the failure was not at the device level or was not
471da177e4SLinus Torvalds    specific to any particular block. */
481da177e4SLinus Torvalds struct erase_info {
491da177e4SLinus Torvalds 	struct mtd_info *mtd;
5069423d99SAdrian Hunter 	uint64_t addr;
5169423d99SAdrian Hunter 	uint64_t len;
5269423d99SAdrian Hunter 	uint64_t fail_addr;
531da177e4SLinus Torvalds 	u_long time;
541da177e4SLinus Torvalds 	u_long retries;
5526cdb67cSDavid Woodhouse 	unsigned dev;
5626cdb67cSDavid Woodhouse 	unsigned cell;
571da177e4SLinus Torvalds 	void (*callback) (struct erase_info *self);
581da177e4SLinus Torvalds 	u_long priv;
591da177e4SLinus Torvalds 	u_char state;
601da177e4SLinus Torvalds 	struct erase_info *next;
611da177e4SLinus Torvalds };
621da177e4SLinus Torvalds 
631da177e4SLinus Torvalds struct mtd_erase_region_info {
6469423d99SAdrian Hunter 	uint64_t offset;			/* At which this region starts, from the beginning of the MTD */
6526cdb67cSDavid Woodhouse 	uint32_t erasesize;		/* For this region */
6626cdb67cSDavid Woodhouse 	uint32_t numblocks;		/* Number of blocks of erasesize in this region */
670ecbc81aSRodolfo Giometti 	unsigned long *lockmap;		/* If keeping bitmap of locks */
681da177e4SLinus Torvalds };
691da177e4SLinus Torvalds 
708593fbc6SThomas Gleixner /*
718593fbc6SThomas Gleixner  * oob operation modes
728593fbc6SThomas Gleixner  *
738593fbc6SThomas Gleixner  * MTD_OOB_PLACE:	oob data are placed at the given offset
748593fbc6SThomas Gleixner  * MTD_OOB_AUTO:	oob data are automatically placed at the free areas
758593fbc6SThomas Gleixner  *			which are defined by the ecclayout
76b64d39d8SMaxim Levitsky  * MTD_OOB_RAW:		mode to read oob and data without doing ECC checking
778593fbc6SThomas Gleixner  */
788593fbc6SThomas Gleixner typedef enum {
798593fbc6SThomas Gleixner 	MTD_OOB_PLACE,
808593fbc6SThomas Gleixner 	MTD_OOB_AUTO,
818593fbc6SThomas Gleixner 	MTD_OOB_RAW,
828593fbc6SThomas Gleixner } mtd_oob_mode_t;
838593fbc6SThomas Gleixner 
848593fbc6SThomas Gleixner /**
858593fbc6SThomas Gleixner  * struct mtd_oob_ops - oob operation operands
868593fbc6SThomas Gleixner  * @mode:	operation mode
878593fbc6SThomas Gleixner  *
887014568bSVitaly Wool  * @len:	number of data bytes to write/read
898593fbc6SThomas Gleixner  *
907014568bSVitaly Wool  * @retlen:	number of data bytes written/read
918593fbc6SThomas Gleixner  *
927014568bSVitaly Wool  * @ooblen:	number of oob bytes to write/read
937014568bSVitaly Wool  * @oobretlen:	number of oob bytes written/read
948593fbc6SThomas Gleixner  * @ooboffs:	offset of oob data in the oob area (only relevant when
958593fbc6SThomas Gleixner  *		mode = MTD_OOB_PLACE)
968593fbc6SThomas Gleixner  * @datbuf:	data buffer - if NULL only oob data are read/written
978593fbc6SThomas Gleixner  * @oobbuf:	oob data buffer
9873a4421cSArtem Bityutskiy  *
99025dfdafSFrederik Schwarzer  * Note, it is allowed to read more than one OOB area at one go, but not write.
10073a4421cSArtem Bityutskiy  * The interface assumes that the OOB write requests program only one page's
10173a4421cSArtem Bityutskiy  * OOB area.
1028593fbc6SThomas Gleixner  */
1038593fbc6SThomas Gleixner struct mtd_oob_ops {
1048593fbc6SThomas Gleixner 	mtd_oob_mode_t	mode;
1058593fbc6SThomas Gleixner 	size_t		len;
1068593fbc6SThomas Gleixner 	size_t		retlen;
1078593fbc6SThomas Gleixner 	size_t		ooblen;
1087014568bSVitaly Wool 	size_t		oobretlen;
1098593fbc6SThomas Gleixner 	uint32_t	ooboffs;
1108593fbc6SThomas Gleixner 	uint8_t		*datbuf;
1118593fbc6SThomas Gleixner 	uint8_t		*oobbuf;
1128593fbc6SThomas Gleixner };
1138593fbc6SThomas Gleixner 
1141da177e4SLinus Torvalds struct mtd_info {
1151da177e4SLinus Torvalds 	u_char type;
11626cdb67cSDavid Woodhouse 	uint32_t flags;
11769423d99SAdrian Hunter 	uint64_t size;	 // Total size of the MTD
1181da177e4SLinus Torvalds 
119151e7659SDavid Woodhouse 	/* "Major" erase size for the device. Naïve users may take this
1201da177e4SLinus Torvalds 	 * to be the only erase size available, or may use the more detailed
1211da177e4SLinus Torvalds 	 * information below if they desire
1221da177e4SLinus Torvalds 	 */
12326cdb67cSDavid Woodhouse 	uint32_t erasesize;
124783ed81fSArtem B. Bityutskiy 	/* Minimal writable flash unit size. In case of NOR flash it is 1 (even
125783ed81fSArtem B. Bityutskiy 	 * though individual bits can be cleared), in case of NAND flash it is
126783ed81fSArtem B. Bityutskiy 	 * one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR
127783ed81fSArtem B. Bityutskiy 	 * it is of ECC block size, etc. It is illegal to have writesize = 0.
128783ed81fSArtem B. Bityutskiy 	 * Any driver registering a struct mtd_info must ensure a writesize of
129783ed81fSArtem B. Bityutskiy 	 * 1 or larger.
13028318776SJoern Engel 	 */
13126cdb67cSDavid Woodhouse 	uint32_t writesize;
1321da177e4SLinus Torvalds 
13326cdb67cSDavid Woodhouse 	uint32_t oobsize;   // Amount of OOB data per block (e.g. 16)
13426cdb67cSDavid Woodhouse 	uint32_t oobavail;  // Available OOB bytes per block
1351da177e4SLinus Torvalds 
13669423d99SAdrian Hunter 	/*
13769423d99SAdrian Hunter 	 * If erasesize is a power of 2 then the shift is stored in
13869423d99SAdrian Hunter 	 * erasesize_shift otherwise erasesize_shift is zero. Ditto writesize.
13969423d99SAdrian Hunter 	 */
14069423d99SAdrian Hunter 	unsigned int erasesize_shift;
14169423d99SAdrian Hunter 	unsigned int writesize_shift;
14269423d99SAdrian Hunter 	/* Masks based on erasesize_shift and writesize_shift */
14369423d99SAdrian Hunter 	unsigned int erasesize_mask;
14469423d99SAdrian Hunter 	unsigned int writesize_mask;
1451da177e4SLinus Torvalds 
1461da177e4SLinus Torvalds 	// Kernel-only stuff starts here.
147eadcf0d7SGreg Kroah-Hartman 	const char *name;
1481da177e4SLinus Torvalds 	int index;
1491da177e4SLinus Torvalds 
1505bd34c09SThomas Gleixner 	/* ecc layout structure pointer - read only ! */
1515bd34c09SThomas Gleixner 	struct nand_ecclayout *ecclayout;
1521da177e4SLinus Torvalds 
1531da177e4SLinus Torvalds 	/* Data for variable erase regions. If numeraseregions is zero,
1541da177e4SLinus Torvalds 	 * it means that the whole device has erasesize as given above.
1551da177e4SLinus Torvalds 	 */
1561da177e4SLinus Torvalds 	int numeraseregions;
1571da177e4SLinus Torvalds 	struct mtd_erase_region_info *eraseregions;
1581da177e4SLinus Torvalds 
159b38178eeSJörn Engel 	/*
160b38178eeSJörn Engel 	 * Erase is an asynchronous operation.  Device drivers are supposed
161b38178eeSJörn Engel 	 * to call instr->callback() whenever the operation completes, even
162b38178eeSJörn Engel 	 * if it completes with a failure.
163b38178eeSJörn Engel 	 * Callers are supposed to pass a callback function and wait for it
164b38178eeSJörn Engel 	 * to be called before writing to the block.
165b38178eeSJörn Engel 	 */
1661da177e4SLinus Torvalds 	int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
1671da177e4SLinus Torvalds 
1681da177e4SLinus Torvalds 	/* This stuff for eXecute-In-Place */
169a98889f3SJared Hulbert 	/* phys is optional and may be set to NULL */
170a98889f3SJared Hulbert 	int (*point) (struct mtd_info *mtd, loff_t from, size_t len,
171a98889f3SJared Hulbert 			size_t *retlen, void **virt, resource_size_t *phys);
1721da177e4SLinus Torvalds 
1731da177e4SLinus Torvalds 	/* We probably shouldn't allow XIP if the unpoint isn't a NULL */
174a98889f3SJared Hulbert 	void (*unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
1751da177e4SLinus Torvalds 
176402d3265SDavid Howells 	/* Allow NOMMU mmap() to directly map the device (if not NULL)
177402d3265SDavid Howells 	 * - return the address to which the offset maps
178402d3265SDavid Howells 	 * - return -ENOSYS to indicate refusal to do the mapping
179402d3265SDavid Howells 	 */
180402d3265SDavid Howells 	unsigned long (*get_unmapped_area) (struct mtd_info *mtd,
181402d3265SDavid Howells 					    unsigned long len,
182402d3265SDavid Howells 					    unsigned long offset,
183402d3265SDavid Howells 					    unsigned long flags);
184402d3265SDavid Howells 
185402d3265SDavid Howells 	/* Backing device capabilities for this device
186402d3265SDavid Howells 	 * - provides mmap capabilities
187402d3265SDavid Howells 	 */
188402d3265SDavid Howells 	struct backing_dev_info *backing_dev_info;
189402d3265SDavid Howells 
1901da177e4SLinus Torvalds 
1911da177e4SLinus Torvalds 	int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
1921da177e4SLinus Torvalds 	int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
1931da177e4SLinus Torvalds 
194388bbb09SRichard Purdie 	/* In blackbox flight recorder like scenarios we want to make successful
195388bbb09SRichard Purdie 	   writes in interrupt context. panic_write() is only intended to be
196388bbb09SRichard Purdie 	   called when its known the kernel is about to panic and we need the
197388bbb09SRichard Purdie 	   write to succeed. Since the kernel is not going to be running for much
198388bbb09SRichard Purdie 	   longer, this function can break locks and delay to ensure the write
199388bbb09SRichard Purdie 	   succeeds (but not sleep). */
200388bbb09SRichard Purdie 
201388bbb09SRichard Purdie 	int (*panic_write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
202388bbb09SRichard Purdie 
2038593fbc6SThomas Gleixner 	int (*read_oob) (struct mtd_info *mtd, loff_t from,
2048593fbc6SThomas Gleixner 			 struct mtd_oob_ops *ops);
2058593fbc6SThomas Gleixner 	int (*write_oob) (struct mtd_info *mtd, loff_t to,
2068593fbc6SThomas Gleixner 			 struct mtd_oob_ops *ops);
2071da177e4SLinus Torvalds 
2081da177e4SLinus Torvalds 	/*
2091da177e4SLinus Torvalds 	 * Methods to access the protection register area, present in some
2101da177e4SLinus Torvalds 	 * flash devices. The user data is one time programmable but the
2111da177e4SLinus Torvalds 	 * factory data is read only.
2121da177e4SLinus Torvalds 	 */
213f77814ddSNicolas Pitre 	int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
2141da177e4SLinus Torvalds 	int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
215f77814ddSNicolas Pitre 	int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
216f77814ddSNicolas Pitre 	int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
2171da177e4SLinus Torvalds 	int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
218f77814ddSNicolas Pitre 	int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len);
2191da177e4SLinus Torvalds 
2202528e8cdSThomas Gleixner 	/* kvec-based read/write methods.
2211da177e4SLinus Torvalds 	   NB: The 'count' parameter is the number of _vectors_, each of
2221da177e4SLinus Torvalds 	   which contains an (ofs, len) tuple.
2231da177e4SLinus Torvalds 	*/
2241da177e4SLinus Torvalds 	int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
2251da177e4SLinus Torvalds 
2261da177e4SLinus Torvalds 	/* Sync */
2271da177e4SLinus Torvalds 	void (*sync) (struct mtd_info *mtd);
2281da177e4SLinus Torvalds 
2291da177e4SLinus Torvalds 	/* Chip-supported device locking */
23069423d99SAdrian Hunter 	int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
23169423d99SAdrian Hunter 	int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
2329938424fSRichard Cochran 	int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len);
2331da177e4SLinus Torvalds 
2341da177e4SLinus Torvalds 	/* Power Management functions */
2351da177e4SLinus Torvalds 	int (*suspend) (struct mtd_info *mtd);
2361da177e4SLinus Torvalds 	void (*resume) (struct mtd_info *mtd);
2371da177e4SLinus Torvalds 
2381da177e4SLinus Torvalds 	/* Bad block management functions */
2391da177e4SLinus Torvalds 	int (*block_isbad) (struct mtd_info *mtd, loff_t ofs);
2401da177e4SLinus Torvalds 	int (*block_markbad) (struct mtd_info *mtd, loff_t ofs);
2411da177e4SLinus Torvalds 
242963a6fb0SNicolas Pitre 	struct notifier_block reboot_notifier;  /* default mode before reboot */
243963a6fb0SNicolas Pitre 
2447fac4648SThomas Gleixner 	/* ECC status information */
2457fac4648SThomas Gleixner 	struct mtd_ecc_stats ecc_stats;
24629072b96SThomas Gleixner 	/* Subpage shift (NAND) */
24729072b96SThomas Gleixner 	int subpage_sft;
2487fac4648SThomas Gleixner 
2491da177e4SLinus Torvalds 	void *priv;
2501da177e4SLinus Torvalds 
2511da177e4SLinus Torvalds 	struct module *owner;
2521f24b5a8SDavid Brownell 	struct device dev;
2531da177e4SLinus Torvalds 	int usecount;
2549fe912ceSArtem Bityutskiy 
2559fe912ceSArtem Bityutskiy 	/* If the driver is something smart, like UBI, it may need to maintain
2569fe912ceSArtem Bityutskiy 	 * its own reference counting. The below functions are only for driver.
2579fe912ceSArtem Bityutskiy 	 * The driver may register its callbacks. These callbacks are not
2589fe912ceSArtem Bityutskiy 	 * supposed to be called by MTD users */
2599fe912ceSArtem Bityutskiy 	int (*get_device) (struct mtd_info *mtd);
2609fe912ceSArtem Bityutskiy 	void (*put_device) (struct mtd_info *mtd);
2611da177e4SLinus Torvalds };
2621da177e4SLinus Torvalds 
2631f24b5a8SDavid Brownell static inline struct mtd_info *dev_to_mtd(struct device *dev)
2641f24b5a8SDavid Brownell {
2656afc4fdbSSaeed Bishara 	return dev ? dev_get_drvdata(dev) : NULL;
2661f24b5a8SDavid Brownell }
2671f24b5a8SDavid Brownell 
26826cdb67cSDavid Woodhouse static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
26969423d99SAdrian Hunter {
27069423d99SAdrian Hunter 	if (mtd->erasesize_shift)
27169423d99SAdrian Hunter 		return sz >> mtd->erasesize_shift;
27269423d99SAdrian Hunter 	do_div(sz, mtd->erasesize);
27369423d99SAdrian Hunter 	return sz;
27469423d99SAdrian Hunter }
27569423d99SAdrian Hunter 
27626cdb67cSDavid Woodhouse static inline uint32_t mtd_mod_by_eb(uint64_t sz, struct mtd_info *mtd)
27769423d99SAdrian Hunter {
27869423d99SAdrian Hunter 	if (mtd->erasesize_shift)
27969423d99SAdrian Hunter 		return sz & mtd->erasesize_mask;
28069423d99SAdrian Hunter 	return do_div(sz, mtd->erasesize);
28169423d99SAdrian Hunter }
28269423d99SAdrian Hunter 
28326cdb67cSDavid Woodhouse static inline uint32_t mtd_div_by_ws(uint64_t sz, struct mtd_info *mtd)
28469423d99SAdrian Hunter {
28569423d99SAdrian Hunter 	if (mtd->writesize_shift)
28669423d99SAdrian Hunter 		return sz >> mtd->writesize_shift;
28769423d99SAdrian Hunter 	do_div(sz, mtd->writesize);
28869423d99SAdrian Hunter 	return sz;
28969423d99SAdrian Hunter }
29069423d99SAdrian Hunter 
29126cdb67cSDavid Woodhouse static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd)
29269423d99SAdrian Hunter {
29369423d99SAdrian Hunter 	if (mtd->writesize_shift)
29469423d99SAdrian Hunter 		return sz & mtd->writesize_mask;
29569423d99SAdrian Hunter 	return do_div(sz, mtd->writesize);
29669423d99SAdrian Hunter }
2971da177e4SLinus Torvalds 
2981da177e4SLinus Torvalds 	/* Kernel-side ioctl definitions */
2991da177e4SLinus Torvalds 
3001da177e4SLinus Torvalds extern int add_mtd_device(struct mtd_info *mtd);
3011da177e4SLinus Torvalds extern int del_mtd_device (struct mtd_info *mtd);
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
3043bd45657SMaxim Levitsky extern int __get_mtd_device(struct mtd_info *mtd);
3053bd45657SMaxim Levitsky extern void __put_mtd_device(struct mtd_info *mtd);
3067799308fSArtem Bityutskiy extern struct mtd_info *get_mtd_device_nm(const char *name);
3071da177e4SLinus Torvalds extern void put_mtd_device(struct mtd_info *mtd);
3081da177e4SLinus Torvalds 
3091da177e4SLinus Torvalds 
3101da177e4SLinus Torvalds struct mtd_notifier {
3111da177e4SLinus Torvalds 	void (*add)(struct mtd_info *mtd);
3121da177e4SLinus Torvalds 	void (*remove)(struct mtd_info *mtd);
3131da177e4SLinus Torvalds 	struct list_head list;
3141da177e4SLinus Torvalds };
3151da177e4SLinus Torvalds 
3161da177e4SLinus Torvalds 
3171da177e4SLinus Torvalds extern void register_mtd_user (struct mtd_notifier *new);
3181da177e4SLinus Torvalds extern int unregister_mtd_user (struct mtd_notifier *old);
3191da177e4SLinus Torvalds 
3201da177e4SLinus Torvalds int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
3211da177e4SLinus Torvalds 		       unsigned long count, loff_t to, size_t *retlen);
3221da177e4SLinus Torvalds 
3231da177e4SLinus Torvalds int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
3241da177e4SLinus Torvalds 		      unsigned long count, loff_t from, size_t *retlen);
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds #ifdef CONFIG_MTD_PARTITIONS
3271da177e4SLinus Torvalds void mtd_erase_callback(struct erase_info *instr);
3281da177e4SLinus Torvalds #else
3291da177e4SLinus Torvalds static inline void mtd_erase_callback(struct erase_info *instr)
3301da177e4SLinus Torvalds {
3311da177e4SLinus Torvalds 	if (instr->callback)
3321da177e4SLinus Torvalds 		instr->callback(instr);
3331da177e4SLinus Torvalds }
3341da177e4SLinus Torvalds #endif
3351da177e4SLinus Torvalds 
3361da177e4SLinus Torvalds /*
3371da177e4SLinus Torvalds  * Debugging macro and defines
3381da177e4SLinus Torvalds  */
3391da177e4SLinus Torvalds #define MTD_DEBUG_LEVEL0	(0)	/* Quiet   */
3401da177e4SLinus Torvalds #define MTD_DEBUG_LEVEL1	(1)	/* Audible */
3411da177e4SLinus Torvalds #define MTD_DEBUG_LEVEL2	(2)	/* Loud    */
3421da177e4SLinus Torvalds #define MTD_DEBUG_LEVEL3	(3)	/* Noisy   */
3431da177e4SLinus Torvalds 
3441da177e4SLinus Torvalds #ifdef CONFIG_MTD_DEBUG
3451da177e4SLinus Torvalds #define DEBUG(n, args...)				\
3461da177e4SLinus Torvalds 	do {						\
3471da177e4SLinus Torvalds 		if (n <= CONFIG_MTD_DEBUG_VERBOSE)	\
3481da177e4SLinus Torvalds 			printk(KERN_INFO args);		\
3491da177e4SLinus Torvalds 	} while(0)
3501da177e4SLinus Torvalds #else /* CONFIG_MTD_DEBUG */
35195b1bc20SDavid Brownell #define DEBUG(n, args...)				\
35295b1bc20SDavid Brownell 	do {						\
35395b1bc20SDavid Brownell 		if (0)					\
35495b1bc20SDavid Brownell 			printk(KERN_INFO args);		\
35595b1bc20SDavid Brownell 	} while(0)
3561da177e4SLinus Torvalds 
3571da177e4SLinus Torvalds #endif /* CONFIG_MTD_DEBUG */
3581da177e4SLinus Torvalds 
3591da177e4SLinus Torvalds #endif /* __MTD_MTD_H__ */
360