xref: /openbmc/u-boot/include/nand.h (revision e8f80a5a)
1*83d290c5STom Rini /* SPDX-License-Identifier: GPL-2.0 */
2932394acSWolfgang Denk /*
3932394acSWolfgang Denk  * (C) Copyright 2005
4932394acSWolfgang Denk  * 2N Telekomunikace, a.s. <www.2n.cz>
5932394acSWolfgang Denk  * Ladislav Michl <michl@2n.cz>
6932394acSWolfgang Denk  */
7932394acSWolfgang Denk 
8932394acSWolfgang Denk #ifndef _NAND_H_
9932394acSWolfgang Denk #define _NAND_H_
10932394acSWolfgang Denk 
11c1783474SScott Wood #include <config.h>
12c1783474SScott Wood 
13c1783474SScott Wood /*
14c1783474SScott Wood  * All boards using a given driver must convert to self-init
15c1783474SScott Wood  * at the same time, so do it here.  When all drivers are
16c1783474SScott Wood  * converted, this will go away.
17c1783474SScott Wood  */
180b0b4f59SBo Shen #ifdef CONFIG_SPL_BUILD
190b0b4f59SBo Shen #if defined(CONFIG_NAND_FSL_ELBC) || defined(CONFIG_NAND_FSL_IFC)
200b0b4f59SBo Shen #define CONFIG_SYS_NAND_SELF_INIT
210b0b4f59SBo Shen #endif
220b0b4f59SBo Shen #else
23a1b81ab2SPrabhakar Kushwaha #if defined(CONFIG_NAND_FSL_ELBC) || defined(CONFIG_NAND_ATMEL)\
24a1b81ab2SPrabhakar Kushwaha 	|| defined(CONFIG_NAND_FSL_IFC)
25c1783474SScott Wood #define CONFIG_SYS_NAND_SELF_INIT
26c1783474SScott Wood #endif
270b0b4f59SBo Shen #endif
28c1783474SScott Wood 
299d2e3947SScott Wood extern void nand_init(void);
30203db38aSHou Zhiqiang unsigned long nand_size(void);
319d2e3947SScott Wood 
327b15e2bbSMike Frysinger #include <linux/compat.h>
33932394acSWolfgang Denk #include <linux/mtd/mtd.h>
346ae3900aSMasahiro Yamada #include <linux/mtd/rawnand.h>
35932394acSWolfgang Denk 
36b616d9b0SScott Wood int nand_mtd_to_devnum(struct mtd_info *mtd);
37b616d9b0SScott Wood 
38578931b3SScott Wood #ifdef CONFIG_SYS_NAND_SELF_INIT
39578931b3SScott Wood void board_nand_init(void);
40b616d9b0SScott Wood int nand_register(int devnum, struct mtd_info *mtd);
41578931b3SScott Wood #else
4269fb8be4SMike Frysinger extern int board_nand_init(struct nand_chip *nand);
43578931b3SScott Wood #endif
4469fb8be4SMike Frysinger 
45932394acSWolfgang Denk extern int nand_curr_device;
46932394acSWolfgang Denk 
nand_read(struct mtd_info * info,loff_t ofs,size_t * len,u_char * buf)47151c06ecSScott Wood static inline int nand_read(struct mtd_info *info, loff_t ofs, size_t *len,
48151c06ecSScott Wood 			    u_char *buf)
49932394acSWolfgang Denk {
50dfe64e2cSSergey Lapin 	return mtd_read(info, ofs, *len, (size_t *)len, buf);
51932394acSWolfgang Denk }
52932394acSWolfgang Denk 
nand_write(struct mtd_info * info,loff_t ofs,size_t * len,u_char * buf)53151c06ecSScott Wood static inline int nand_write(struct mtd_info *info, loff_t ofs, size_t *len,
54151c06ecSScott Wood 			     u_char *buf)
55932394acSWolfgang Denk {
56dfe64e2cSSergey Lapin 	return mtd_write(info, ofs, *len, (size_t *)len, buf);
57932394acSWolfgang Denk }
58932394acSWolfgang Denk 
nand_block_isbad(struct mtd_info * info,loff_t ofs)59151c06ecSScott Wood static inline int nand_block_isbad(struct mtd_info *info, loff_t ofs)
60932394acSWolfgang Denk {
61dfe64e2cSSergey Lapin 	return mtd_block_isbad(info, ofs);
62932394acSWolfgang Denk }
63932394acSWolfgang Denk 
nand_erase(struct mtd_info * info,loff_t off,size_t size)64151c06ecSScott Wood static inline int nand_erase(struct mtd_info *info, loff_t off, size_t size)
65932394acSWolfgang Denk {
668e9655f8SWolfgang Denk 	struct erase_info instr;
678e9655f8SWolfgang Denk 
688e9655f8SWolfgang Denk 	instr.mtd = info;
698e9655f8SWolfgang Denk 	instr.addr = off;
708e9655f8SWolfgang Denk 	instr.len = size;
718e9655f8SWolfgang Denk 	instr.callback = 0;
728e9655f8SWolfgang Denk 
73dfe64e2cSSergey Lapin 	return mtd_erase(info, &instr);
74932394acSWolfgang Denk }
75932394acSWolfgang Denk 
762255b2d2SStefan Roese 
772255b2d2SStefan Roese /*****************************************************************************
782255b2d2SStefan Roese  * declarations from nand_util.c
792255b2d2SStefan Roese  ****************************************************************************/
802255b2d2SStefan Roese 
81cfa460adSWilliam Juul typedef struct mtd_oob_ops mtd_oob_ops_t;
822255b2d2SStefan Roese 
832255b2d2SStefan Roese struct nand_erase_options {
8430486322SScott Wood 	loff_t length;		/* number of bytes to erase */
8530486322SScott Wood 	loff_t offset;		/* first address in NAND to erase */
862255b2d2SStefan Roese 	int quiet;		/* don't display progress messages */
872255b2d2SStefan Roese 	int jffs2;		/* if true: format for jffs2 usage
882255b2d2SStefan Roese 				 * (write appropriate cleanmarker blocks) */
892255b2d2SStefan Roese 	int scrub;		/* if true, really clean NAND by erasing
902255b2d2SStefan Roese 				 * bad blocks (UNSAFE) */
9130486322SScott Wood 
9230486322SScott Wood 	/* Don't include skipped bad blocks in size to be erased */
9330486322SScott Wood 	int spread;
94a67cc37eSHeiko Schocher 	/* maximum size that actual may be in order to not exceed the buf */
95a67cc37eSHeiko Schocher 	loff_t lim;
962255b2d2SStefan Roese };
972255b2d2SStefan Roese 
982255b2d2SStefan Roese typedef struct nand_erase_options nand_erase_options_t;
992255b2d2SStefan Roese 
100151c06ecSScott Wood int nand_read_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length,
101c39d6a0eSTom Rini 		       size_t *actual, loff_t lim, u_char *buffer);
102a6c9aa1fSBen Gardiner 
103004a1fdbSPeter Tyser #define WITH_DROP_FFS	(1 << 0) /* drop trailing all-0xff pages */
104004a1fdbSPeter Tyser #define WITH_WR_VERIFY	(1 << 1) /* verify data was written correctly */
105a6c9aa1fSBen Gardiner 
106151c06ecSScott Wood int nand_write_skip_bad(struct mtd_info *mtd, loff_t offset, size_t *length,
107c39d6a0eSTom Rini 			size_t *actual, loff_t lim, u_char *buffer, int flags);
108151c06ecSScott Wood int nand_erase_opts(struct mtd_info *mtd,
109151c06ecSScott Wood 		    const nand_erase_options_t *opts);
110151c06ecSScott Wood int nand_torture(struct mtd_info *mtd, loff_t offset);
111151c06ecSScott Wood int nand_verify_page_oob(struct mtd_info *mtd, struct mtd_oob_ops *ops,
11259b5a2adSPeter Tyser 			 loff_t ofs);
113151c06ecSScott Wood int nand_verify(struct mtd_info *mtd, loff_t ofs, size_t len, u_char *buf);
1142255b2d2SStefan Roese 
1152255b2d2SStefan Roese #define NAND_LOCK_STATUS_TIGHT	0x01
1162255b2d2SStefan Roese #define NAND_LOCK_STATUS_UNLOCK 0x04
1172255b2d2SStefan Roese 
118151c06ecSScott Wood int nand_lock(struct mtd_info *mtd, int tight);
119151c06ecSScott Wood int nand_unlock(struct mtd_info *mtd, loff_t start, size_t length,
120e331ab2eSJoe Hershberger 		int allexcept);
121151c06ecSScott Wood int nand_get_lock_status(struct mtd_info *mtd, loff_t offset);
1222255b2d2SStefan Roese 
12312c2f1eeSSimon Schwarz int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst);
124e1a89e93SThomas Gleixner int nand_spl_read_block(int block, int offset, int len, void *dst);
125bb085b87SSimon Schwarz void nand_deselect(void);
126bb085b87SSimon Schwarz 
1276d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
12843a2b0e7SStefan Roese void board_nand_select_device(struct nand_chip *nand, int chip);
12943a2b0e7SStefan Roese #endif
13043a2b0e7SStefan Roese 
131e4c09508SScott Wood __attribute__((noreturn)) void nand_boot(void);
132e4c09508SScott Wood 
133c9f7351bSBen Gardiner #ifdef CONFIG_ENV_OFFSET_OOB
134c9f7351bSBen Gardiner #define ENV_OOB_MARKER 0x30425645 /*"EVB0" in little-endian -- offset is stored
135c9f7351bSBen Gardiner 				    as block number*/
136c9f7351bSBen Gardiner #define ENV_OOB_MARKER_OLD 0x30564e45 /*"ENV0" in little-endian -- offset is
137c9f7351bSBen Gardiner 					stored as byte number */
138c9f7351bSBen Gardiner #define ENV_OFFSET_SIZE 8
139151c06ecSScott Wood int get_nand_env_oob(struct mtd_info *mtd, unsigned long *result);
140c9f7351bSBen Gardiner #endif
1414dfd3605SHeiko Schocher int spl_nand_erase_one(int block, int page);
1424ccae81cSBoris Brezillon 
1434ccae81cSBoris Brezillon /* platform specific init functions */
1444ccae81cSBoris Brezillon void sunxi_nand_init(void);
1452afc741aSMugunthan V N 
146ad92dff2SMugunthan V N /*
147ad92dff2SMugunthan V N  * get_nand_dev_by_index - Get the nand info based in index.
148ad92dff2SMugunthan V N  *
149ad92dff2SMugunthan V N  * @dev - index to the nand device.
150ad92dff2SMugunthan V N  *
151ad92dff2SMugunthan V N  * returns pointer to the nand device info structure or NULL on failure.
152ad92dff2SMugunthan V N  */
153ad92dff2SMugunthan V N struct mtd_info *get_nand_dev_by_index(int dev);
154ad92dff2SMugunthan V N 
1552afc741aSMugunthan V N #endif /* _NAND_H_ */
156