MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / mtd / maps / w311.c
blob8fc6d6bf029d478e525f0bd9a3a103d1c4cc40c8
1 /*
2 * History:
3 * Date Author Comment
4 * 11-15-2005 Victor Yu. Create it.
5 */
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>
21 #include <asm/io.h>
23 static struct map_info mcpu_map_flash = {
24 .name = "W311",
25 .bankwidth = 2,
26 .phys = CPE_FLASH_BASE,
27 .size = CPE_FLASH_SZ,
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[] = {
38 .name = "BootLoader",
39 .size = BOOT_LOADER_SIZE,/* hopefully Moxa boot will stay 128k + 128*/
40 .offset = 0,
41 //.mask_flags = MTD_WRITEABLE, /* force read-only */
42 }, {
43 .name = "Kernel",
44 .size = KERNEL_SIZE,
45 .offset = MTDPART_OFS_APPEND,
46 //.mask_flags = MTD_WRITEABLE, /* force read-only */
47 }, {
48 .name = "RootDisk",
49 .size = ROOT_DISK_SIZE,
50 .offset = MTDPART_OFS_APPEND,
51 //.mask_flags = MTD_WRITEABLE, /* force read-only */
52 }, {
53 .name = "UserDisk",
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)
63 return NOTIFY_DONE;
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;
68 return NOTIFY_DONE;
71 static struct notifier_block mtd_notifier = {
72 notifier_call: mtd_reboot,
73 next: NULL,
74 priority: 0
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);
94 if (!flash_mtd)
95 return -ENXIO;
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)
103 int status;
105 if ((status = init_flash())) {
106 printk(KERN_ERR "Flash: unable to init map for flash\n");
107 } else {
108 register_reboot_notifier(&mtd_notifier);
110 return status;
113 static void __exit mcpu_mtd_cleanup(void)
115 if (flash_mtd) {
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");