2 * YAFFS: Yet another FFS. A NAND-flash specific file system.
3 * yaffs_mtdif.c NAND mtd wrapper functions.
5 * Copyright (C) 2002 Aleph One Ltd.
6 * for Toby Churchill Ltd and Brightstar Engineering
8 * Created by Charles Manning <charles@aleph1.co.uk>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
16 const char *yaffs_mtdif_c_version = "$Id: yaffs_mtdif.c,v 1.8 2005-08-02 19:17:55 luc Exp $";
20 #ifdef CONFIG_YAFFS_YAFFS1
22 #include "yaffs_mtdif.h"
24 #include "linux/mtd/mtd.h"
25 #include "linux/types.h"
26 #include "linux/time.h"
27 #include "linux/mtd/nand.h"
29 static struct nand_oobinfo yaffs_oobinfo = {
31 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,8))
34 .eccpos = {8, 9, 10, 13, 14, 15}
37 static struct nand_oobinfo yaffs_noeccinfo = {
42 int nandmtd_WriteChunkToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, const yaffs_Spare *spare)
44 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
48 loff_t addr = ((loff_t)chunkInNAND) * dev->nBytesPerChunk;
50 __u8 *spareAsBytes = (__u8 *)spare;
55 mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_oobinfo);
57 mtd->write_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_noeccinfo);
62 retval = mtd->write(mtd,addr,dev->nBytesPerChunk,&dummy,data);
64 retval = mtd->write_oob(mtd,addr,YAFFS_BYTES_PER_SPARE,&dummy,spareAsBytes);
73 int nandmtd_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare)
75 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
79 loff_t addr = ((loff_t)chunkInNAND) * dev->nBytesPerChunk;
81 __u8 *spareAsBytes = (__u8 *)spare;
86 { // Careful, this call adds 2 ints to the end of the spare data. Calling function should
87 // allocate enough memory for spare, i.e. [YAFFS_BYTES_PER_SPARE+2*sizeof(int)].
88 retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_oobinfo);
92 retval = mtd->read_ecc(mtd,addr,dev->nBytesPerChunk,&dummy,data,spareAsBytes,&yaffs_noeccinfo);
98 retval = mtd->read(mtd,addr,dev->nBytesPerChunk,&dummy,data);
100 retval = mtd->read_oob(mtd,addr,YAFFS_BYTES_PER_SPARE,&dummy,spareAsBytes);
109 // Callback not needed for NAND
111 static void nandmtd_EraseCallback(struct erase_info *ei)
113 yaffs_Device *dev = (yaffs_Device *)ei->priv;
119 int nandmtd_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
121 struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
122 __u32 addr = ((loff_t) blockNumber) * dev->nBytesPerChunk * dev->nChunksPerBlock;
123 struct erase_info ei;
128 ei.len = dev->nBytesPerChunk * dev->nChunksPerBlock;
132 ei.priv = (u_long)dev;
134 // Todo finish off the ei if required
136 sema_init(&dev->sem,0);
138 retval = mtd->erase(mtd,&ei);
140 //No need for callback
141 // down(&dev->sem); // Wait for the erasure to complete
149 int nandmtd_InitialiseNAND(yaffs_Device *dev)
154 #endif // CONFIG_YAFFS_YAFFS1