*** empty log message ***
[yaffs/.git] / yaffs_mtdif.c
1 /*
2  * YAFFS: Yet another FFS. A NAND-flash specific file system. 
3  * yaffs_mtdif.c  NAND mtd wrapper functions.
4  *
5  * Copyright (C) 2002 Aleph One Ltd.
6  *   for Toby Churchill Ltd and Brightstar Engineering
7  *
8  * Created by Charles Manning <charles@aleph1.co.uk>
9  *
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.
13  *
14  */
15
16 const char *yaffs_mtdif_c_version = "$Id: yaffs_mtdif.c,v 1.3 2002-09-27 20:50:50 charles Exp $";
17
18 #ifdef CONFIG_YAFFS_MTD_ENABLED
19  
20 #include "yportenv.h"
21
22 #include "yaffs_mtdif.h"
23
24 #include "linux/mtd/mtd.h"
25 #include "linux/types.h"
26
27
28 int nandmtd_WriteChunkToNAND(yaffs_Device *dev,int chunkInNAND,const __u8 *data, yaffs_Spare *spare)
29 {
30         struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
31         size_t dummy;
32         
33         loff_t addr = ((loff_t)chunkInNAND) * YAFFS_BYTES_PER_CHUNK;
34         
35         
36         __u8 *spareAsBytes = (__u8 *)spare;
37         
38         if(data)
39                 mtd->write(mtd,addr,YAFFS_BYTES_PER_CHUNK,&dummy,data);
40         if(spare)
41                 mtd->write_oob(mtd,addr,YAFFS_BYTES_PER_SPARE,&dummy,spareAsBytes);
42
43         return YAFFS_OK;
44 }
45
46
47 int nandmtd_ReadChunkFromNAND(yaffs_Device *dev,int chunkInNAND, __u8 *data, yaffs_Spare *spare)
48 {
49         struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
50         size_t dummy;
51         
52         loff_t addr = ((loff_t)chunkInNAND) * YAFFS_BYTES_PER_CHUNK;
53         
54         __u8 *spareAsBytes = (__u8 *)spare;
55         
56         if(data)
57                 mtd->read(mtd,addr,YAFFS_BYTES_PER_CHUNK,&dummy,data);
58         if(spare)
59                 mtd->read_oob(mtd,addr,YAFFS_BYTES_PER_SPARE,&dummy,spareAsBytes);
60
61         return YAFFS_OK;
62 }
63
64
65 static void nandmtd_EraseCallback(struct erase_info *ei)
66 {
67         yaffs_Device *dev = (yaffs_Device *)ei->priv;   
68         up(&dev->sem);
69 }
70
71
72 int nandmtd_EraseBlockInNAND(yaffs_Device *dev, int blockNumber)
73 {
74         
75         struct mtd_info *mtd = (struct mtd_info *)(dev->genericDevice);
76         __u32 addr = ((loff_t) blockNumber) * YAFFS_BYTES_PER_BLOCK;
77         struct erase_info ei;
78         
79         ei.mtd = mtd;
80         ei.addr = addr;
81         ei.len = YAFFS_BYTES_PER_BLOCK;
82         ei.time = 1000;
83         ei.retries = 2;
84         ei.callback = nandmtd_EraseCallback;
85         ei.priv = (u_long)dev;
86         
87         // Todo finish off the ei if required
88         
89         sema_init(&dev->sem,0);
90
91         mtd->erase(mtd,&ei);
92         
93         
94         down(&dev->sem); // Wait for the erasure to complete
95                         
96         //Todo, check result of erasure
97         
98         return YAFFS_OK;
99 }
100
101 int nandmtd_InitialiseNAND(yaffs_Device *dev)
102 {
103         return YAFFS_OK;
104 }
105
106 #endif // CONFIG_YAFFS_MTD_ENABLED
107