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_flash
= {
26 .phys
= CPE_FLASH_BASE
,
28 .virt
= CPE_FLASH_VA_BASE
,
31 #define BOOT_LOADER_SIZE 0x40000
32 #define KERNEL_BOOT_LOADER_SIZE 0x200000
33 #define KERNEL_SIZE (KERNEL_BOOT_LOADER_SIZE-BOOT_LOADER_SIZE)
34 #define ROOT_DISK_SIZE 0x800000
35 #define USER_DISK_SIZE (CPE_FLASH_SZ-KERNEL_BOOT_LOADER_SIZE-ROOT_DISK_SIZE)
36 static struct mtd_partition mcpu_flash_partitions
[] = {
39 .size
= BOOT_LOADER_SIZE
,/* hopefully Moxa boot will stay 128k + 128*/
41 //.mask_flags = MTD_WRITEABLE, /* force read-only */
45 .offset
= MTDPART_OFS_APPEND
,
46 //.mask_flags = MTD_WRITEABLE, /* force read-only */
49 .size
= ROOT_DISK_SIZE
,
50 .offset
= MTDPART_OFS_APPEND
,
51 //.mask_flags = MTD_WRITEABLE, /* force read-only */
54 .size
= USER_DISK_SIZE
,
55 .offset
= MTDPART_OFS_APPEND
,
56 //.mask_flags = MTD_WRITEABLE,
60 static int mtd_reboot(struct notifier_block
*n
, unsigned long code
, void *p
)
62 if(code
!= SYS_RESTART
)
65 //Added by Wade ,06/19/09
66 *( u16
*)(CPE_FLASH_VA_BASE
+ (0x55 * 2)) = 0xb0;
67 *( u16
*)(CPE_FLASH_VA_BASE
+ (0x55 * 2)) = 0xff;
71 static struct notifier_block mtd_notifier
= {
72 notifier_call
: mtd_reboot
,
77 static struct mtd_info
*flash_mtd
;
79 static int __init
init_flash (void)
83 * Static partition definition selection
85 simple_map_init(&mcpu_map_flash
);
88 * Now let's probe for the actual flash. Do it here since
89 * specific machine settings might have been set above.
91 printk(KERN_NOTICE
"Moxa CPU flash: probing %d-bit flash bus\n",
92 mcpu_map_flash
.bankwidth
*8);
93 flash_mtd
= do_map_probe("cfi_probe", &mcpu_map_flash
);
97 printk(KERN_NOTICE
"Using static partition definition\n");
98 return add_mtd_partitions(flash_mtd
, mcpu_flash_partitions
, ARRAY_SIZE(mcpu_flash_partitions
));
101 int __init
mcpu_mtd_init(void)
105 if ((status
= init_flash())) {
106 printk(KERN_ERR
"Flash: unable to init map for flash\n");
108 register_reboot_notifier(&mtd_notifier
);
113 static void __exit
mcpu_mtd_cleanup(void)
116 unregister_reboot_notifier(&mtd_notifier
);
117 del_mtd_partitions(flash_mtd
);
118 map_destroy(flash_mtd
);
122 module_init(mcpu_mtd_init
);
123 module_exit(mcpu_mtd_cleanup
);
125 MODULE_AUTHOR("Victor Yu.");
126 MODULE_DESCRIPTION("Moxa CPU board MTD device driver");
127 MODULE_LICENSE("GPL");