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 27ac7eb8a3SWolfgang Denk #include <linux/mtd/compat.h> 28932394acSWolfgang Denk #include <linux/mtd/mtd.h> 29932394acSWolfgang Denk #include <linux/mtd/nand.h> 30932394acSWolfgang Denk 31932394acSWolfgang Denk typedef struct mtd_info nand_info_t; 32932394acSWolfgang Denk 33932394acSWolfgang Denk extern int nand_curr_device; 34932394acSWolfgang Denk extern nand_info_t nand_info[]; 35932394acSWolfgang Denk 36932394acSWolfgang Denk static inline int nand_read(nand_info_t *info, ulong ofs, ulong *len, u_char *buf) 37932394acSWolfgang Denk { 38038ccac5SBartlomiej Sieka return info->read(info, ofs, *len, (size_t *)len, buf); 39932394acSWolfgang Denk } 40932394acSWolfgang Denk 41932394acSWolfgang Denk static inline int nand_write(nand_info_t *info, ulong ofs, ulong *len, u_char *buf) 42932394acSWolfgang Denk { 43038ccac5SBartlomiej Sieka return info->write(info, ofs, *len, (size_t *)len, buf); 44932394acSWolfgang Denk } 45932394acSWolfgang Denk 46932394acSWolfgang Denk static inline int nand_block_isbad(nand_info_t *info, ulong ofs) 47932394acSWolfgang Denk { 48932394acSWolfgang Denk return info->block_isbad(info, ofs); 49932394acSWolfgang Denk } 50932394acSWolfgang Denk 51932394acSWolfgang Denk static inline int nand_erase(nand_info_t *info, ulong off, ulong size) 52932394acSWolfgang Denk { 538e9655f8SWolfgang Denk struct erase_info instr; 548e9655f8SWolfgang Denk 558e9655f8SWolfgang Denk instr.mtd = info; 568e9655f8SWolfgang Denk instr.addr = off; 578e9655f8SWolfgang Denk instr.len = size; 588e9655f8SWolfgang Denk instr.callback = 0; 598e9655f8SWolfgang Denk 608e9655f8SWolfgang Denk return info->erase(info, &instr); 61932394acSWolfgang Denk } 62932394acSWolfgang Denk 63*2255b2d2SStefan Roese 64*2255b2d2SStefan Roese /***************************************************************************** 65*2255b2d2SStefan Roese * declarations from nand_util.c 66*2255b2d2SStefan Roese ****************************************************************************/ 67*2255b2d2SStefan Roese 68*2255b2d2SStefan Roese struct nand_write_options { 69*2255b2d2SStefan Roese u_char *buffer; /* memory block containing image to write */ 70*2255b2d2SStefan Roese ulong length; /* number of bytes to write */ 71*2255b2d2SStefan Roese ulong offset; /* start address in NAND */ 72*2255b2d2SStefan Roese int quiet; /* don't display progress messages */ 73*2255b2d2SStefan Roese int autoplace; /* if true use auto oob layout */ 74*2255b2d2SStefan Roese int forcejffs2; /* force jffs2 oob layout */ 75*2255b2d2SStefan Roese int forceyaffs; /* force yaffs oob layout */ 76*2255b2d2SStefan Roese int noecc; /* write without ecc */ 77*2255b2d2SStefan Roese int writeoob; /* image contains oob data */ 78*2255b2d2SStefan Roese int pad; /* pad to page size */ 79*2255b2d2SStefan Roese int blockalign; /* 1|2|4 set multiple of eraseblocks 80*2255b2d2SStefan Roese * to align to */ 81*2255b2d2SStefan Roese }; 82*2255b2d2SStefan Roese 83*2255b2d2SStefan Roese typedef struct nand_write_options nand_write_options_t; 84*2255b2d2SStefan Roese 85*2255b2d2SStefan Roese struct nand_read_options { 86*2255b2d2SStefan Roese u_char *buffer; /* memory block in which read image is written*/ 87*2255b2d2SStefan Roese ulong length; /* number of bytes to read */ 88*2255b2d2SStefan Roese ulong offset; /* start address in NAND */ 89*2255b2d2SStefan Roese int quiet; /* don't display progress messages */ 90*2255b2d2SStefan Roese int readoob; /* put oob data in image */ 91*2255b2d2SStefan Roese }; 92*2255b2d2SStefan Roese 93*2255b2d2SStefan Roese typedef struct nand_read_options nand_read_options_t; 94*2255b2d2SStefan Roese 95*2255b2d2SStefan Roese struct nand_erase_options { 96*2255b2d2SStefan Roese ulong length; /* number of bytes to erase */ 97*2255b2d2SStefan Roese ulong offset; /* first address in NAND to erase */ 98*2255b2d2SStefan Roese int quiet; /* don't display progress messages */ 99*2255b2d2SStefan Roese int jffs2; /* if true: format for jffs2 usage 100*2255b2d2SStefan Roese * (write appropriate cleanmarker blocks) */ 101*2255b2d2SStefan Roese int scrub; /* if true, really clean NAND by erasing 102*2255b2d2SStefan Roese * bad blocks (UNSAFE) */ 103*2255b2d2SStefan Roese }; 104*2255b2d2SStefan Roese 105*2255b2d2SStefan Roese typedef struct nand_erase_options nand_erase_options_t; 106*2255b2d2SStefan Roese 107*2255b2d2SStefan Roese int nand_write_opts(nand_info_t *meminfo, const nand_write_options_t *opts); 108*2255b2d2SStefan Roese 109*2255b2d2SStefan Roese int nand_read_opts(nand_info_t *meminfo, const nand_read_options_t *opts); 110*2255b2d2SStefan Roese int nand_erase_opts(nand_info_t *meminfo, const nand_erase_options_t *opts); 111*2255b2d2SStefan Roese 112*2255b2d2SStefan Roese #define NAND_LOCK_STATUS_TIGHT 0x01 113*2255b2d2SStefan Roese #define NAND_LOCK_STATUS_LOCK 0x02 114*2255b2d2SStefan Roese #define NAND_LOCK_STATUS_UNLOCK 0x04 115*2255b2d2SStefan Roese 116*2255b2d2SStefan Roese int nand_lock( nand_info_t *meminfo, int tight ); 117*2255b2d2SStefan Roese int nand_unlock( nand_info_t *meminfo, ulong start, ulong length ); 118*2255b2d2SStefan Roese int nand_get_lock_status(nand_info_t *meminfo, ulong offset); 119*2255b2d2SStefan Roese 120932394acSWolfgang Denk #endif 121