2 * $Id: nora.c,v 1.11 2000/07/04 16:42:50 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
= {
77 static int nora_mtd_read (struct mtd_info
*mtd
, loff_t from
, size_t len
, size_t *retlen
, u_char
*buf
)
79 return mymtd
->read(mymtd
, from
+ (unsigned long)mtd
->priv
, len
, retlen
, buf
);
82 static int nora_mtd_write(struct mtd_info
*mtd
, loff_t to
, size_t len
, size_t *retlen
, const u_char
*buf
)
84 return mymtd
->write(mymtd
, to
+ (unsigned long)mtd
->priv
, len
, retlen
, buf
);
87 static int nora_mtd_erase (struct mtd_info
*mtd
, struct erase_info
*instr
)
89 instr
->addr
+= (unsigned long)mtd
->priv
;
90 return mymtd
->erase(mymtd
, instr
);
93 static void nora_mtd_sync (struct mtd_info
*mtd
)
98 static int nora_mtd_suspend (struct mtd_info
*mtd
)
100 return mymtd
->suspend(mymtd
);
103 static void nora_mtd_resume (struct mtd_info
*mtd
)
105 mymtd
->resume(mymtd
);
109 static struct mtd_info nora_mtds
[4] = { /* boot, kernel, ramdisk, fs */
112 flags
: MTD_CAP_NORFLASH
,
115 name
: "NORA boot firmware",
117 erase
: nora_mtd_erase
,
119 write
: nora_mtd_write
,
120 suspend
: nora_mtd_suspend
,
121 resume
: nora_mtd_resume
,
127 flags
: MTD_CAP_NORFLASH
,
132 erase
: nora_mtd_erase
,
134 write
: nora_mtd_write
,
135 suspend
: nora_mtd_suspend
,
136 resume
: nora_mtd_resume
,
138 priv
: (void *)0x60000
142 flags
: MTD_CAP_NORFLASH
,
145 name
: "NORA ramdisk",
147 erase
: nora_mtd_erase
,
149 write
: nora_mtd_write
,
150 suspend
: nora_mtd_suspend
,
151 resume
: nora_mtd_resume
,
153 priv
: (void *)0x200000
157 flags
: MTD_CAP_NORFLASH
,
160 name
: "NORA filesystem",
162 erase
: nora_mtd_erase
,
164 write
: nora_mtd_write
,
165 suspend
: nora_mtd_suspend
,
166 resume
: nora_mtd_resume
,
168 priv
: (void *)0x1000000
172 #if LINUX_VERSION_CODE < 0x20300
174 #define init_nora init_module
175 #define cleanup_nora cleanup_module
179 int __init
init_nora(void)
181 printk(KERN_NOTICE
"nora flash device: %x at %x\n", WINDOW_SIZE
, WINDOW_ADDR
);
183 mymtd
= do_cfi_probe(&nora_map
);
186 mymtd
->module
= &__this_module
;
189 add_mtd_device(&nora_mtds
[3]);
190 add_mtd_device(&nora_mtds
[0]);
191 add_mtd_device(&nora_mtds
[1]);
192 add_mtd_device(&nora_mtds
[2]);
199 static void __exit
cleanup_nora(void)
202 del_mtd_device(&nora_mtds
[2]);
203 del_mtd_device(&nora_mtds
[1]);
204 del_mtd_device(&nora_mtds
[0]);
205 del_mtd_device(&nora_mtds
[3]);