xref: /rk3399_rockchip-uboot/include/nand.h (revision 578931b34d0a26974f14640fa4ec3aadeb2145cd)
1932394acSWolfgang Denk /*
2932394acSWolfgang Denk  * (C) Copyright 2005
3932394acSWolfgang Denk  * 2N Telekomunikace, a.s. <www.2n.cz>
4932394acSWolfgang Denk  * Ladislav Michl <michl@2n.cz>
5932394acSWolfgang Denk  *
6932394acSWolfgang Denk  * See file CREDITS for list of people who contributed to this
7932394acSWolfgang Denk  * project.
8932394acSWolfgang Denk  *
9932394acSWolfgang Denk  * This program is free software; you can redistribute it and/or
10932394acSWolfgang Denk  * modify it under the terms of the GNU General Public License
11932394acSWolfgang Denk  * version 2 as published by the Free Software Foundation.
12932394acSWolfgang Denk  *
13932394acSWolfgang Denk  * This program is distributed in the hope that it will be useful,
14932394acSWolfgang Denk  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15932394acSWolfgang Denk  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
16932394acSWolfgang Denk  * GNU General Public License for more details.
17932394acSWolfgang Denk  *
18932394acSWolfgang Denk  * You should have received a copy of the GNU General Public License
19932394acSWolfgang Denk  * along with this program; if not, write to the Free Software
20932394acSWolfgang Denk  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21932394acSWolfgang Denk  * MA 02111-1307 USA
22932394acSWolfgang Denk  */
23932394acSWolfgang Denk 
24932394acSWolfgang Denk #ifndef _NAND_H_
25932394acSWolfgang Denk #define _NAND_H_
26932394acSWolfgang Denk 
279d2e3947SScott Wood extern void nand_init(void);
289d2e3947SScott Wood 
29ac7eb8a3SWolfgang Denk #include <linux/mtd/compat.h>
30932394acSWolfgang Denk #include <linux/mtd/mtd.h>
31932394acSWolfgang Denk #include <linux/mtd/nand.h>
32932394acSWolfgang Denk 
33*578931b3SScott Wood #ifdef CONFIG_SYS_NAND_SELF_INIT
34*578931b3SScott Wood void board_nand_init(void);
35*578931b3SScott Wood int nand_register(int devnum);
36*578931b3SScott Wood #else
3769fb8be4SMike Frysinger extern int board_nand_init(struct nand_chip *nand);
38*578931b3SScott Wood #endif
3969fb8be4SMike Frysinger 
40932394acSWolfgang Denk typedef struct mtd_info nand_info_t;
41932394acSWolfgang Denk 
42932394acSWolfgang Denk extern int nand_curr_device;
43932394acSWolfgang Denk extern nand_info_t nand_info[];
44932394acSWolfgang Denk 
45378adfcdSJean-Christophe PLAGNIOL-VILLARD static inline int nand_read(nand_info_t *info, loff_t ofs, size_t *len, u_char *buf)
46932394acSWolfgang Denk {
47038ccac5SBartlomiej Sieka 	return info->read(info, ofs, *len, (size_t *)len, buf);
48932394acSWolfgang Denk }
49932394acSWolfgang Denk 
50378adfcdSJean-Christophe PLAGNIOL-VILLARD static inline int nand_write(nand_info_t *info, loff_t ofs, size_t *len, u_char *buf)
51932394acSWolfgang Denk {
52038ccac5SBartlomiej Sieka 	return info->write(info, ofs, *len, (size_t *)len, buf);
53932394acSWolfgang Denk }
54932394acSWolfgang Denk 
55378adfcdSJean-Christophe PLAGNIOL-VILLARD static inline int nand_block_isbad(nand_info_t *info, loff_t ofs)
56932394acSWolfgang Denk {
57932394acSWolfgang Denk 	return info->block_isbad(info, ofs);
58932394acSWolfgang Denk }
59932394acSWolfgang Denk 
60378adfcdSJean-Christophe PLAGNIOL-VILLARD static inline int nand_erase(nand_info_t *info, loff_t off, size_t size)
61932394acSWolfgang Denk {
628e9655f8SWolfgang Denk 	struct erase_info instr;
638e9655f8SWolfgang Denk 
648e9655f8SWolfgang Denk 	instr.mtd = info;
658e9655f8SWolfgang Denk 	instr.addr = off;
668e9655f8SWolfgang Denk 	instr.len = size;
678e9655f8SWolfgang Denk 	instr.callback = 0;
688e9655f8SWolfgang Denk 
698e9655f8SWolfgang Denk 	return info->erase(info, &instr);
70932394acSWolfgang Denk }
71932394acSWolfgang Denk 
722255b2d2SStefan Roese 
732255b2d2SStefan Roese /*****************************************************************************
742255b2d2SStefan Roese  * declarations from nand_util.c
752255b2d2SStefan Roese  ****************************************************************************/
762255b2d2SStefan Roese 
772255b2d2SStefan Roese struct nand_write_options {
782255b2d2SStefan Roese 	u_char *buffer;		/* memory block containing image to write */
792255b2d2SStefan Roese 	ulong length;		/* number of bytes to write */
802255b2d2SStefan Roese 	ulong offset;		/* start address in NAND */
812255b2d2SStefan Roese 	int quiet;		/* don't display progress messages */
822255b2d2SStefan Roese 	int autoplace;		/* if true use auto oob layout */
832255b2d2SStefan Roese 	int forcejffs2;		/* force jffs2 oob layout */
842255b2d2SStefan Roese 	int forceyaffs;		/* force yaffs oob layout */
852255b2d2SStefan Roese 	int noecc;		/* write without ecc */
862255b2d2SStefan Roese 	int writeoob;		/* image contains oob data */
872255b2d2SStefan Roese 	int pad;		/* pad to page size */
882255b2d2SStefan Roese 	int blockalign;		/* 1|2|4 set multiple of eraseblocks
892255b2d2SStefan Roese 				 * to align to */
902255b2d2SStefan Roese };
912255b2d2SStefan Roese 
922255b2d2SStefan Roese typedef struct nand_write_options nand_write_options_t;
93cfa460adSWilliam Juul typedef struct mtd_oob_ops mtd_oob_ops_t;
942255b2d2SStefan Roese 
952255b2d2SStefan Roese struct nand_read_options {
962255b2d2SStefan Roese 	u_char *buffer;		/* memory block in which read image is written*/
972255b2d2SStefan Roese 	ulong length;		/* number of bytes to read */
982255b2d2SStefan Roese 	ulong offset;		/* start address in NAND */
992255b2d2SStefan Roese 	int quiet;		/* don't display progress messages */
1002255b2d2SStefan Roese 	int readoob;		/* put oob data in image */
1012255b2d2SStefan Roese };
1022255b2d2SStefan Roese 
1032255b2d2SStefan Roese typedef struct nand_read_options nand_read_options_t;
1042255b2d2SStefan Roese 
1052255b2d2SStefan Roese struct nand_erase_options {
10630486322SScott Wood 	loff_t length;		/* number of bytes to erase */
10730486322SScott Wood 	loff_t offset;		/* first address in NAND to erase */
1082255b2d2SStefan Roese 	int quiet;		/* don't display progress messages */
1092255b2d2SStefan Roese 	int jffs2;		/* if true: format for jffs2 usage
1102255b2d2SStefan Roese 				 * (write appropriate cleanmarker blocks) */
1112255b2d2SStefan Roese 	int scrub;		/* if true, really clean NAND by erasing
1122255b2d2SStefan Roese 				 * bad blocks (UNSAFE) */
11330486322SScott Wood 
11430486322SScott Wood 	/* Don't include skipped bad blocks in size to be erased */
11530486322SScott Wood 	int spread;
1162255b2d2SStefan Roese };
1172255b2d2SStefan Roese 
1182255b2d2SStefan Roese typedef struct nand_erase_options nand_erase_options_t;
1192255b2d2SStefan Roese 
120378adfcdSJean-Christophe PLAGNIOL-VILLARD int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
121dfbf617fSScott Wood 		       u_char *buffer);
122a6c9aa1fSBen Gardiner 
123c135456fSBen Gardiner #define WITH_YAFFS_OOB	(1 << 0) /* whether write with yaffs format. This flag
124c135456fSBen Gardiner 				  * is a 'mode' meaning it cannot be mixed with
125c135456fSBen Gardiner 				  * other flags */
126169d54d8SBen Gardiner #define WITH_DROP_FFS	(1 << 1) /* drop trailing all-0xff pages */
127a6c9aa1fSBen Gardiner 
128378adfcdSJean-Christophe PLAGNIOL-VILLARD int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length,
129a6c9aa1fSBen Gardiner 			u_char *buffer, int flags);
1302255b2d2SStefan Roese int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t *opts);
1312255b2d2SStefan Roese 
1322255b2d2SStefan Roese #define NAND_LOCK_STATUS_TIGHT	0x01
1332255b2d2SStefan Roese #define NAND_LOCK_STATUS_LOCK	0x02
1342255b2d2SStefan Roese #define NAND_LOCK_STATUS_UNLOCK 0x04
1352255b2d2SStefan Roese 
1362255b2d2SStefan Roese int nand_lock( nand_info_t *meminfo, int tight );
1372255b2d2SStefan Roese int nand_unlock( nand_info_t *meminfo, ulong start, ulong length );
138378adfcdSJean-Christophe PLAGNIOL-VILLARD int nand_get_lock_status(nand_info_t *meminfo, loff_t offset);
1392255b2d2SStefan Roese 
14012c2f1eeSSimon Schwarz int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst);
141bb085b87SSimon Schwarz void nand_deselect(void);
142bb085b87SSimon Schwarz 
1436d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_NAND_SELECT_DEVICE
14443a2b0e7SStefan Roese void board_nand_select_device(struct nand_chip *nand, int chip);
14543a2b0e7SStefan Roese #endif
14643a2b0e7SStefan Roese 
147e4c09508SScott Wood __attribute__((noreturn)) void nand_boot(void);
148e4c09508SScott Wood 
149932394acSWolfgang Denk #endif
150c9f7351bSBen Gardiner 
151c9f7351bSBen Gardiner #ifdef CONFIG_ENV_OFFSET_OOB
152c9f7351bSBen Gardiner #define ENV_OOB_MARKER 0x30425645 /*"EVB0" in little-endian -- offset is stored
153c9f7351bSBen Gardiner 				    as block number*/
154c9f7351bSBen Gardiner #define ENV_OOB_MARKER_OLD 0x30564e45 /*"ENV0" in little-endian -- offset is
155c9f7351bSBen Gardiner 					stored as byte number */
156c9f7351bSBen Gardiner #define ENV_OFFSET_SIZE 8
157c9f7351bSBen Gardiner int get_nand_env_oob(nand_info_t *nand, unsigned long *result);
158c9f7351bSBen Gardiner #endif
159