+int __init init_adm5120_map(void)
+{
+ size_t size;
+ int ret = 0;
+#if defined (CONFIG_MTD_PARTITIONS) || (CONFIG_MTD_MYLOADER_PARTS)
+ struct mtd_partition *parts;
+ int i, parsed_nr_parts = 0;
+#endif
+
+ if (adm5120_nand_boot)
+ return -ENODEV;
+
+ printk("adm5120 : flash init : 0x%08x 0x%08x\n", WINDOW_ADDR, adm5120_board.flash0_size);
+ adm5120_map.virt = ioremap_nocache(WINDOW_ADDR, adm5120_board.flash0_size);
+
+ if (!adm5120_map.virt) {
+ printk("Failed to ioremap\n");
+ return -EIO;
+ }
+ simple_map_init(&adm5120_map);
+ adm5120_map.read = adm5120_map_read;
+ adm5120_map.write = adm5120_map_write;
+ adm5120_map.copy_from = adm5120_map_copy_from;
+
+ if (!(adm5120_mtd = do_map_probe("cfi_probe", &adm5120_map))) {
+ printk("Failed to do_map_probe\n");
+ iounmap((void *)adm5120_map.virt);
+ return -ENXIO;
+ }
+
+ adm5120_mtd->owner = THIS_MODULE;
+
+ size = adm5120_mtd->size;
+
+ printk(KERN_NOTICE "Flash device: 0x%x at 0x%x\n", size, WINDOW_ADDR);
+
+#ifdef CONFIG_MTD_PARTITIONS
+
+ if (adm5120_boot_loader == BOOT_LOADER_CFE || adm5120_boot_loader == BOOT_LOADER_UNKNOWN)
+ {
+ printk(KERN_NOTICE "adm5120 : using CFE flash mapping\n");
+ parts = init_mtd_partitions(adm5120_mtd, size);
+
+ for (i = 0; parts[i].name; i++);
+ ret = add_mtd_partitions(adm5120_mtd, parts, i);
+
+ if (ret) {
+ printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
+ goto fail;
+ }
+ }
+#endif
+#ifdef CONFIG_MTD_MYLOADER_PARTS
+ if (adm5120_boot_loader == BOOT_LOADER_MYLOADER)
+ {
+ printk(KERN_NOTICE "adm5120 : using MyLoader flash mapping\n");
+ char *part_type;
+
+ if (parsed_nr_parts == 0) {
+ ret = parse_myloader_partitions(adm5120_mtd, &parts, 0);
+
+ if (ret > 0) {
+ part_type ="MyLoader";
+ parsed_nr_parts = ret;
+ }
+ }
+ ret = add_mtd_partitions(adm5120_mtd, parts, parsed_nr_parts);
+
+ if (ret) {
+ printk(KERN_ERR "Flash: add_mtd_partitions failed\n");
+ goto fail;
+ }
+ }
+#endif
+ return 0;
+
+ fail:
+ if (adm5120_mtd)
+ map_destroy(adm5120_mtd);
+ if (adm5120_map.virt)
+ iounmap((void *)adm5120_map.virt);
+ adm5120_map.virt = 0;
+ return ret;
+}
+
+void __exit cleanup_adm5120_map(void)
+{
+#ifdef CONFIG_MTD_PARTITIONS
+ del_mtd_partitions(adm5120_mtd);
+#endif
+ map_destroy(adm5120_mtd);
+ iounmap((void *)adm5120_map.virt);
+}