2 * $Id: nora.c,v 1.17 2000/12/03 19:32:21 dwmw2 Exp $
4 * This is so simple I love it.
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
11 #include <linux/mtd/mtd.h>
12 #include <linux/mtd/map.h>
15 #define WINDOW_ADDR 0xd0000000
16 #define WINDOW_SIZE 0x04000000
18 static struct mtd_info
*mymtd
;
20 __u8
nora_read8(struct map_info
*map
, unsigned long ofs
)
22 return *(__u8
*)(WINDOW_ADDR
+ ofs
);
25 __u16
nora_read16(struct map_info
*map
, unsigned long ofs
)
27 return *(__u16
*)(WINDOW_ADDR
+ ofs
);
30 __u32
nora_read32(struct map_info
*map
, unsigned long ofs
)
32 return *(__u32
*)(WINDOW_ADDR
+ ofs
);
35 void nora_copy_from(struct map_info
*map
, void *to
, unsigned long from
, ssize_t len
)
37 memcpy(to
, (void *)(WINDOW_ADDR
+ from
), len
);
40 void nora_write8(struct map_info
*map
, __u8 d
, unsigned long adr
)
42 *(__u8
*)(WINDOW_ADDR
+ adr
) = d
;
45 void nora_write16(struct map_info
*map
, __u16 d
, unsigned long adr
)
47 *(__u16
*)(WINDOW_ADDR
+ adr
) = d
;
50 void nora_write32(struct map_info
*map
, __u32 d
, unsigned long adr
)
52 *(__u32
*)(WINDOW_ADDR
+ adr
) = d
;
55 void nora_copy_to(struct map_info
*map
, unsigned long to
, const void *from
, ssize_t len
)
57 memcpy((void *)(WINDOW_ADDR
+ to
), from
, len
);
60 struct map_info nora_map
= {
67 copy_from
: nora_copy_from
,
69 write16
: nora_write16
,
70 write32
: nora_write32
,
75 static int nora_mtd_read (struct mtd_info
*mtd
, loff_t from
, size_t len
, size_t *retlen
, u_char
*buf
)
77 return mymtd
->read(mymtd
, from
+ (unsigned long)mtd
->priv
, len
, retlen
, buf
);
80 static int nora_mtd_write(struct mtd_info
*mtd
, loff_t to
, size_t len
, size_t *retlen
, const u_char
*buf
)
82 return mymtd
->write(mymtd
, to
+ (unsigned long)mtd
->priv
, len
, retlen
, buf
);
85 static int nora_mtd_erase (struct mtd_info
*mtd
, struct erase_info
*instr
)
87 instr
->addr
+= (unsigned long)mtd
->priv
;
88 return mymtd
->erase(mymtd
, instr
);
91 static void nora_mtd_sync (struct mtd_info
*mtd
)
96 static int nora_mtd_suspend (struct mtd_info
*mtd
)
98 return mymtd
->suspend(mymtd
);
101 static void nora_mtd_resume (struct mtd_info
*mtd
)
103 mymtd
->resume(mymtd
);
107 static struct mtd_info nora_mtds
[4] = { /* boot, kernel, ramdisk, fs */
110 flags
: MTD_CAP_NORFLASH
,
113 name
: "NORA boot firmware",
115 erase
: nora_mtd_erase
,
117 write
: nora_mtd_write
,
118 suspend
: nora_mtd_suspend
,
119 resume
: nora_mtd_resume
,
125 flags
: MTD_CAP_NORFLASH
,
130 erase
: nora_mtd_erase
,
132 write
: nora_mtd_write
,
133 suspend
: nora_mtd_suspend
,
134 resume
: nora_mtd_resume
,
136 priv
: (void *)0x60000
140 flags
: MTD_CAP_NORFLASH
,
143 name
: "NORA root filesystem",
145 erase
: nora_mtd_erase
,
147 write
: nora_mtd_write
,
148 suspend
: nora_mtd_suspend
,
149 resume
: nora_mtd_resume
,
151 priv
: (void *)0x100000
155 flags
: MTD_CAP_NORFLASH
,
158 name
: "NORA second filesystem",
160 erase
: nora_mtd_erase
,
162 write
: nora_mtd_write
,
163 suspend
: nora_mtd_suspend
,
164 resume
: nora_mtd_resume
,
166 priv
: (void *)0xa00000
171 #if LINUX_VERSION_CODE < 0x20212 && defined(MODULE)
172 #define init_nora init_module
173 #define cleanup_nora cleanup_module
176 int __init
init_nora(void)
178 printk(KERN_NOTICE
"nora flash device: %x at %x\n", WINDOW_SIZE
, WINDOW_ADDR
);
180 mymtd
= do_cfi_probe(&nora_map
);
183 mymtd
->module
= &__this_module
;
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]);
196 static void __exit
cleanup_nora(void)
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]);
207 module_init(init_nora
);
208 module_exit(cleanup_nora
);