MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / mtd / maps / ia241_32128.c
blob707b724fb52789781b4e16d7360b2b5a9118e28f
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_flash1 = {
24 .name = "IA241-32128-1",
25 .bankwidth = 2,
26 .phys = CPE_FLASH_BASE,
27 .size = CPE_FLASH_SZ,
28 .virt = CPE_FLASH_VA_BASE,
31 static struct map_info mcpu_map_flash2 = {
32 .name = "IA241-32128-2",
33 .bankwidth = 2,
34 .phys = CPE_FLASH_BASE2,
35 .size = CPE_FLASH_SZ,
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[] = {
46 .name = "BootLoader",
47 .size = BOOT_LOADER_SIZE,/* hopefully Moxa boot will stay 128k + 128*/
48 .offset = 0,
49 //.mask_flags = MTD_WRITEABLE, /* force read-only */
50 }, {
51 .name = "Kernel",
52 .size = KERNEL_SIZE,
53 .offset = MTDPART_OFS_APPEND,
54 //.mask_flags = MTD_WRITEABLE, /* force read-only */
55 }, {
56 .name = "RootDisk",
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[] = {
64 .name = "UserDisk",
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)
74 return NOTIFY_DONE;
76 *( u16 *)(CPE_FLASH_VA_BASE + (0x55 * 2)) = 0xff;
77 return NOTIFY_DONE;
80 static struct notifier_block mtd_notifier = {
81 notifier_call: mtd_reboot,
82 next: NULL,
83 priority: 0
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);
105 if (!flash_mtd1)
106 return -ENXIO;
107 flash_mtd2 = do_map_probe("cfi_probe", &mcpu_map_flash2);
108 if (!flash_mtd2)
109 return -ENXIO;
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)
118 int status;
120 if (status == init_flash()) {
121 printk(KERN_ERR "Flash: unable to init map for flash\n");
122 } else {
123 register_reboot_notifier(&mtd_notifier);
125 return status;
128 static void __exit mcpu_mtd_cleanup(void)
130 if (flash_mtd1) {
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");