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 14932394acSWolfgang Denk #ifndef _NAND_H_ 15932394acSWolfgang Denk #define _NAND_H_ 16932394acSWolfgang Denk 17c1783474SScott Wood #include <config.h> 18c1783474SScott Wood 19c1783474SScott Wood /* 20c1783474SScott Wood * All boards using a given driver must convert to self-init 21c1783474SScott Wood * at the same time, so do it here. When all drivers are 22c1783474SScott Wood * converted, this will go away. 23c1783474SScott Wood */ 240b0b4f59SBo Shen #ifdef CONFIG_SPL_BUILD 250b0b4f59SBo Shen #if defined(CONFIG_NAND_FSL_ELBC) || defined(CONFIG_NAND_FSL_IFC) 260b0b4f59SBo Shen #define CONFIG_SYS_NAND_SELF_INIT 270b0b4f59SBo Shen #endif 280b0b4f59SBo Shen #else 29a1b81ab2SPrabhakar Kushwaha #if defined(CONFIG_NAND_FSL_ELBC) || defined(CONFIG_NAND_ATMEL)\ 30a1b81ab2SPrabhakar Kushwaha || defined(CONFIG_NAND_FSL_IFC) 31c1783474SScott Wood #define CONFIG_SYS_NAND_SELF_INIT 32c1783474SScott Wood #endif 330b0b4f59SBo Shen #endif 34c1783474SScott Wood 359d2e3947SScott Wood extern void nand_init(void); 369d2e3947SScott Wood 377b15e2bbSMike Frysinger #include <linux/compat.h> 38932394acSWolfgang Denk #include <linux/mtd/mtd.h> 39932394acSWolfgang Denk #include <linux/mtd/nand.h> 40932394acSWolfgang Denk 41578931b3SScott Wood #ifdef CONFIG_SYS_NAND_SELF_INIT 42578931b3SScott Wood void board_nand_init(void); 43578931b3SScott Wood int nand_register(int devnum); 44578931b3SScott Wood #else 4569fb8be4SMike Frysinger extern int board_nand_init(struct nand_chip *nand); 46578931b3SScott Wood #endif 4769fb8be4SMike Frysinger 48932394acSWolfgang Denk typedef struct mtd_info nand_info_t; 49932394acSWolfgang Denk 50932394acSWolfgang Denk extern int nand_curr_device; 51932394acSWolfgang Denk extern nand_info_t nand_info[]; 52932394acSWolfgang Denk 53378adfcdSJean-Christophe PLAGNIOL-VILLARD static inline int nand_read(nand_info_t *info, loff_t ofs, size_t *len, u_char *buf) 54932394acSWolfgang Denk { 55dfe64e2cSSergey Lapin return mtd_read(info, ofs, *len, (size_t *)len, buf); 56932394acSWolfgang Denk } 57932394acSWolfgang Denk 58378adfcdSJean-Christophe PLAGNIOL-VILLARD static inline int nand_write(nand_info_t *info, loff_t ofs, size_t *len, u_char *buf) 59932394acSWolfgang Denk { 60dfe64e2cSSergey Lapin return mtd_write(info, ofs, *len, (size_t *)len, buf); 61932394acSWolfgang Denk } 62932394acSWolfgang Denk 63378adfcdSJean-Christophe PLAGNIOL-VILLARD static inline int nand_block_isbad(nand_info_t *info, loff_t ofs) 64932394acSWolfgang Denk { 65dfe64e2cSSergey Lapin return mtd_block_isbad(info, ofs); 66932394acSWolfgang Denk } 67932394acSWolfgang Denk 68378adfcdSJean-Christophe PLAGNIOL-VILLARD static inline int nand_erase(nand_info_t *info, loff_t off, size_t size) 69932394acSWolfgang Denk { 708e9655f8SWolfgang Denk struct erase_info instr; 718e9655f8SWolfgang Denk 728e9655f8SWolfgang Denk instr.mtd = info; 738e9655f8SWolfgang Denk instr.addr = off; 748e9655f8SWolfgang Denk instr.len = size; 758e9655f8SWolfgang Denk instr.callback = 0; 768e9655f8SWolfgang Denk 77dfe64e2cSSergey Lapin return mtd_erase(info, &instr); 78932394acSWolfgang Denk } 79932394acSWolfgang Denk 802255b2d2SStefan Roese 812255b2d2SStefan Roese /***************************************************************************** 822255b2d2SStefan Roese * declarations from nand_util.c 832255b2d2SStefan Roese ****************************************************************************/ 842255b2d2SStefan Roese 85cfa460adSWilliam Juul typedef struct mtd_oob_ops mtd_oob_ops_t; 862255b2d2SStefan Roese 872255b2d2SStefan Roese struct nand_erase_options { 8830486322SScott Wood loff_t length; /* number of bytes to erase */ 8930486322SScott Wood loff_t offset; /* first address in NAND to erase */ 902255b2d2SStefan Roese int quiet; /* don't display progress messages */ 912255b2d2SStefan Roese int jffs2; /* if true: format for jffs2 usage 922255b2d2SStefan Roese * (write appropriate cleanmarker blocks) */ 932255b2d2SStefan Roese int scrub; /* if true, really clean NAND by erasing 942255b2d2SStefan Roese * bad blocks (UNSAFE) */ 9530486322SScott Wood 9630486322SScott Wood /* Don't include skipped bad blocks in size to be erased */ 9730486322SScott Wood int spread; 98a67cc37eSHeiko Schocher /* maximum size that actual may be in order to not exceed the buf */ 99a67cc37eSHeiko Schocher loff_t lim; 1002255b2d2SStefan Roese }; 1012255b2d2SStefan Roese 1022255b2d2SStefan Roese typedef struct nand_erase_options nand_erase_options_t; 1032255b2d2SStefan Roese 104378adfcdSJean-Christophe PLAGNIOL-VILLARD int nand_read_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, 105c39d6a0eSTom Rini size_t *actual, loff_t lim, u_char *buffer); 106a6c9aa1fSBen Gardiner 107*004a1fdbSPeter Tyser #define WITH_DROP_FFS (1 << 0) /* drop trailing all-0xff pages */ 108*004a1fdbSPeter Tyser #define WITH_WR_VERIFY (1 << 1) /* verify data was written correctly */ 109a6c9aa1fSBen Gardiner 110378adfcdSJean-Christophe PLAGNIOL-VILLARD int nand_write_skip_bad(nand_info_t *nand, loff_t offset, size_t *length, 111c39d6a0eSTom Rini size_t *actual, loff_t lim, u_char *buffer, int flags); 1122255b2d2SStefan Roese int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t *opts); 1133287f6d3SBenoît Thébaudeau int nand_torture(nand_info_t *nand, loff_t offset); 11459b5a2adSPeter Tyser int nand_verify_page_oob(nand_info_t *nand, struct mtd_oob_ops *ops, 11559b5a2adSPeter Tyser loff_t ofs); 11659b5a2adSPeter Tyser int nand_verify(nand_info_t *nand, loff_t ofs, size_t len, u_char *buf); 1172255b2d2SStefan Roese 1182255b2d2SStefan Roese #define NAND_LOCK_STATUS_TIGHT 0x01 1192255b2d2SStefan Roese #define NAND_LOCK_STATUS_UNLOCK 0x04 1202255b2d2SStefan Roese 1212255b2d2SStefan Roese int nand_lock(nand_info_t *meminfo, int tight); 122e331ab2eSJoe Hershberger int nand_unlock(nand_info_t *meminfo, loff_t start, size_t length, 123e331ab2eSJoe Hershberger int allexcept); 124378adfcdSJean-Christophe PLAGNIOL-VILLARD int nand_get_lock_status(nand_info_t *meminfo, loff_t offset); 1252255b2d2SStefan Roese 12612c2f1eeSSimon Schwarz int nand_spl_load_image(uint32_t offs, unsigned int size, void *dst); 127bb085b87SSimon Schwarz void nand_deselect(void); 128bb085b87SSimon Schwarz 1296d0f6bcfSJean-Christophe PLAGNIOL-VILLARD #ifdef CONFIG_SYS_NAND_SELECT_DEVICE 13043a2b0e7SStefan Roese void board_nand_select_device(struct nand_chip *nand, int chip); 13143a2b0e7SStefan Roese #endif 13243a2b0e7SStefan Roese 133e4c09508SScott Wood __attribute__((noreturn)) void nand_boot(void); 134e4c09508SScott Wood 135932394acSWolfgang Denk #endif 136c9f7351bSBen Gardiner 137c9f7351bSBen Gardiner #ifdef CONFIG_ENV_OFFSET_OOB 138c9f7351bSBen Gardiner #define ENV_OOB_MARKER 0x30425645 /*"EVB0" in little-endian -- offset is stored 139c9f7351bSBen Gardiner as block number*/ 140c9f7351bSBen Gardiner #define ENV_OOB_MARKER_OLD 0x30564e45 /*"ENV0" in little-endian -- offset is 141c9f7351bSBen Gardiner stored as byte number */ 142c9f7351bSBen Gardiner #define ENV_OFFSET_SIZE 8 143c9f7351bSBen Gardiner int get_nand_env_oob(nand_info_t *nand, unsigned long *result); 144c9f7351bSBen Gardiner #endif 1454dfd3605SHeiko Schocher int spl_nand_erase_one(int block, int page); 146