~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/drivers/mtd/nora.c

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * $Id: nora.c,v 1.17 2000/12/03 19:32:21 dwmw2 Exp $
  3  *
  4  * This is so simple I love it.
  5  */
  6 
  7 #include <linux/module.h>
  8 #include <linux/types.h>
  9 #include <linux/kernel.h>
 10 
 11 #include <linux/mtd/mtd.h>
 12 #include <linux/mtd/map.h>
 13 
 14 
 15 #define WINDOW_ADDR 0xd0000000
 16 #define WINDOW_SIZE 0x04000000
 17 
 18 static struct mtd_info *mymtd;
 19 
 20 __u8 nora_read8(struct map_info *map, unsigned long ofs)
 21 {
 22   return *(__u8 *)(WINDOW_ADDR + ofs);
 23 }
 24 
 25 __u16 nora_read16(struct map_info *map, unsigned long ofs)
 26 {
 27   return *(__u16 *)(WINDOW_ADDR + ofs);
 28 }
 29 
 30 __u32 nora_read32(struct map_info *map, unsigned long ofs)
 31 {
 32   return *(__u32 *)(WINDOW_ADDR + ofs);
 33 }
 34 
 35 void nora_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
 36 {
 37   memcpy(to, (void *)(WINDOW_ADDR + from), len);
 38 }
 39 
 40 void nora_write8(struct map_info *map, __u8 d, unsigned long adr)
 41 {
 42   *(__u8 *)(WINDOW_ADDR + adr) = d;
 43 }
 44 
 45 void nora_write16(struct map_info *map, __u16 d, unsigned long adr)
 46 {
 47   *(__u16 *)(WINDOW_ADDR + adr) = d;
 48 }
 49 
 50 void nora_write32(struct map_info *map, __u32 d, unsigned long adr)
 51 {
 52   *(__u32 *)(WINDOW_ADDR + adr) = d;
 53 }
 54 
 55 void nora_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
 56 {
 57   memcpy((void *)(WINDOW_ADDR + to), from, len);
 58 }
 59 
 60 struct map_info nora_map = {
 61         name: "NORA",
 62         size: WINDOW_SIZE,
 63         buswidth: 2,
 64         read8: nora_read8,
 65         read16: nora_read16,
 66         read32: nora_read32,
 67         copy_from: nora_copy_from,
 68         write8: nora_write8,
 69         write16: nora_write16,
 70         write32: nora_write32,
 71         copy_to: nora_copy_to
 72 };
 73 
 74 
 75 static int nora_mtd_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
 76 {
 77         return mymtd->read(mymtd, from + (unsigned long)mtd->priv, len, retlen, buf);
 78 }
 79 
 80 static int nora_mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf)
 81 {
 82         return mymtd->write(mymtd, to + (unsigned long)mtd->priv, len, retlen, buf);
 83 }
 84 
 85 static int nora_mtd_erase (struct mtd_info *mtd, struct erase_info *instr)
 86 {
 87         instr->addr += (unsigned long)mtd->priv;
 88         return mymtd->erase(mymtd, instr);
 89 }
 90 
 91 static void nora_mtd_sync (struct mtd_info *mtd)
 92 {
 93         mymtd->sync(mymtd);
 94 }
 95 
 96 static int nora_mtd_suspend (struct mtd_info *mtd)
 97 {
 98         return mymtd->suspend(mymtd);
 99 }
100 
101 static void nora_mtd_resume (struct mtd_info *mtd)
102 {
103         mymtd->resume(mymtd);
104 }
105 
106 
107 static struct mtd_info nora_mtds[4] = {  /* boot, kernel, ramdisk, fs */
108         {
109                 type: MTD_NORFLASH,
110                 flags: MTD_CAP_NORFLASH,
111                 size: 0x60000,
112                 erasesize: 0x20000,
113                 name: "NORA boot firmware",
114                 module: THIS_MODULE,
115                 erase: nora_mtd_erase,
116                 read: nora_mtd_read,
117                 write: nora_mtd_write,
118                 suspend: nora_mtd_suspend,
119                 resume: nora_mtd_resume,
120                 sync: nora_mtd_sync,
121                 priv: (void *)0
122         },
123         {
124                 type: MTD_NORFLASH,
125                 flags: MTD_CAP_NORFLASH,
126                 size: 0x0a0000,
127                 erasesize: 0x20000,
128                 name: "NORA kernel",
129                 module: THIS_MODULE,
130                 erase: nora_mtd_erase,
131                 read: nora_mtd_read,
132                 write: nora_mtd_write,
133                 suspend: nora_mtd_suspend,
134                 resume: nora_mtd_resume,
135                 sync: nora_mtd_sync,
136                 priv: (void *)0x60000
137         },
138         {
139                 type: MTD_NORFLASH,
140                 flags: MTD_CAP_NORFLASH,
141                 size: 0x900000,
142                 erasesize: 0x20000,
143                 name: "NORA root filesystem",
144                 module: THIS_MODULE,
145                 erase: nora_mtd_erase,
146                 read: nora_mtd_read,
147                 write: nora_mtd_write,
148                 suspend: nora_mtd_suspend,
149                 resume: nora_mtd_resume,
150                 sync: nora_mtd_sync,
151                 priv: (void *)0x100000
152         },
153         {
154                 type: MTD_NORFLASH,
155                 flags: MTD_CAP_NORFLASH,
156                 size: 0x1600000,
157                 erasesize: 0x20000,
158                 name: "NORA second filesystem",
159                 module: THIS_MODULE,
160                 erase: nora_mtd_erase,
161                 read: nora_mtd_read,
162                 write: nora_mtd_write,
163                 suspend: nora_mtd_suspend,
164                 resume: nora_mtd_resume,
165                 sync: nora_mtd_sync,
166                 priv: (void *)0xa00000
167         }
168 };
169 
170 
171 #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
172 #define init_nora init_module
173 #define cleanup_nora cleanup_module
174 #endif
175 
176 int __init init_nora(void)
177 {
178         printk(KERN_NOTICE "nora flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
179 
180         mymtd = do_cfi_probe(&nora_map);
181         if (mymtd) {
182 #ifdef MODULE
183                 mymtd->module = &__this_module;
184 #endif
185                 
186                 add_mtd_device(&nora_mtds[2]);
187                 add_mtd_device(&nora_mtds[0]);
188                 add_mtd_device(&nora_mtds[1]);
189                 add_mtd_device(&nora_mtds[3]);
190                 return 0;
191         }
192 
193         return -ENXIO;
194 }
195 
196 static void __exit cleanup_nora(void)
197 {
198         if (mymtd) {
199                 del_mtd_device(&nora_mtds[3]);
200                 del_mtd_device(&nora_mtds[1]);
201                 del_mtd_device(&nora_mtds[0]);
202                 del_mtd_device(&nora_mtds[2]);
203                 map_destroy(mymtd);
204         }
205 }
206 
207 module_init(init_nora);
208 module_exit(cleanup_nora);
209 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.