4 * 11-15-2005 Victor Yu. Create it.
7 #include <linux/config.h>
8 #include <linux/module.h>
9 #include <linux/types.h>
10 #include <linux/kernel.h>
12 #include <linux/errno.h>
13 #include <linux/init.h>
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/map.h>
17 #include <linux/mtd/partitions.h>
18 #include <linux/reboot.h>
20 #include <asm/hardware.h>
23 static struct map_info mcpu_map_flash1
= {
24 .name
= "IA241-32128-1",
26 .phys
= CPE_FLASH_BASE
,
28 .virt
= CPE_FLASH_VA_BASE
,
31 static struct map_info mcpu_map_flash2
= {
32 .name
= "IA241-32128-2",
34 .phys
= CPE_FLASH_BASE2
,
36 .virt
= CPE_FLASH_VA_BASE2
,
39 #define BOOT_LOADER_SIZE 0x40000
40 #define KERNEL_BOOT_LOADER_SIZE 0x300000
41 #define KERNEL_SIZE (KERNEL_BOOT_LOADER_SIZE-BOOT_LOADER_SIZE)
42 #define ROOT_DISK_SIZE 0xd00000
43 #define USER_DISK_SIZE CPE_FLASH_SZ
44 static struct mtd_partition mcpu_flash_partitions1
[] = {
47 .size
= BOOT_LOADER_SIZE
,/* hopefully Moxa boot will stay 128k + 128*/
49 //.mask_flags = MTD_WRITEABLE, /* force read-only */
53 .offset
= MTDPART_OFS_APPEND
,
54 //.mask_flags = MTD_WRITEABLE, /* force read-only */
57 .size
= ROOT_DISK_SIZE
,
58 .offset
= MTDPART_OFS_APPEND
,
59 //.mask_flags = MTD_WRITEABLE, /* force read-only */
62 static struct mtd_partition mcpu_flash_partitions2
[] = {
65 .size
= USER_DISK_SIZE
,
66 .offset
= MTDPART_OFS_APPEND
,
67 //.mask_flags = MTD_WRITEABLE,
71 static int mtd_reboot(struct notifier_block
*n
, unsigned long code
, void *p
)
73 if(code
!= SYS_RESTART
)
76 *( u16
*)(CPE_FLASH_VA_BASE
+ (0x55 * 2)) = 0xff;
80 static struct notifier_block mtd_notifier
= {
81 notifier_call
: mtd_reboot
,
86 static struct mtd_info
*flash_mtd1
;
87 static struct mtd_info
*flash_mtd2
;
89 static int __init
init_flash (void)
93 * Static partition definition selection
95 simple_map_init(&mcpu_map_flash1
);
96 simple_map_init(&mcpu_map_flash2
);
99 * Now let's probe for the actual flash. Do it here since
100 * specific machine settings might have been set above.
102 printk(KERN_NOTICE
"Moxa CPU flash: probing %d-bit flash bus\n",
103 mcpu_map_flash1
.bankwidth
*8);
104 flash_mtd1
= do_map_probe("cfi_probe", &mcpu_map_flash1
);
107 flash_mtd2
= do_map_probe("cfi_probe", &mcpu_map_flash2
);
111 printk(KERN_NOTICE
"Using static partition definition\n");
112 add_mtd_partitions(flash_mtd1
, mcpu_flash_partitions1
, ARRAY_SIZE(mcpu_flash_partitions1
));
113 return add_mtd_partitions(flash_mtd2
, mcpu_flash_partitions2
, ARRAY_SIZE(mcpu_flash_partitions2
));
116 int __init
mcpu_mtd_init(void)
120 if (status
== init_flash()) {
121 printk(KERN_ERR
"Flash: unable to init map for flash\n");
123 register_reboot_notifier(&mtd_notifier
);
128 static void __exit
mcpu_mtd_cleanup(void)
131 unregister_reboot_notifier(&mtd_notifier
);
132 del_mtd_partitions(flash_mtd1
);
133 map_destroy(flash_mtd1
);
134 del_mtd_partitions(flash_mtd2
);
135 map_destroy(flash_mtd2
);
139 module_init(mcpu_mtd_init
);
140 module_exit(mcpu_mtd_cleanup
);
142 MODULE_AUTHOR("Victor Yu.");
143 MODULE_DESCRIPTION("Moxa CPU board MTD device driver");
144 MODULE_LICENSE("GPL");