+ int cfe_size;
+
+ if ((cfe_size = find_cfe_size(mtd,size)) < 0)
+ return NULL;
+
+ /* boot loader */
+ adm5120_cfe_parts[0].offset = 0;
+ adm5120_cfe_parts[0].size = cfe_size;
+
+ /* nvram */
+ if (cfe_size != 384 * 1024) {
+ adm5120_cfe_parts[3].offset = size - ROUNDUP(NVRAM_SPACE, mtd->erasesize);
+ adm5120_cfe_parts[3].size = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
+ } else {
+ /* nvram (old 128kb config partition on netgear wgt634u) */
+ adm5120_cfe_parts[3].offset = adm5120_cfe_parts[0].size;
+ adm5120_cfe_parts[3].size = ROUNDUP(NVRAM_SPACE, mtd->erasesize);
+ }
+
+ /* linux (kernel and rootfs) */
+ if (cfe_size != 384 * 1024) {
+ adm5120_cfe_parts[1].offset = adm5120_cfe_parts[0].size;
+ adm5120_cfe_parts[1].size = adm5120_cfe_parts[3].offset -
+ adm5120_cfe_parts[1].offset;
+ } else {
+ /* do not count the elf loader, which is on one block */
+ adm5120_cfe_parts[1].offset = adm5120_cfe_parts[0].size +
+ adm5120_cfe_parts[3].size + mtd->erasesize;
+ adm5120_cfe_parts[1].size = size -
+ adm5120_cfe_parts[0].size -
+ (2*adm5120_cfe_parts[3].size) -
+ mtd->erasesize;
+ }
+
+ /* find and size rootfs */
+ find_root(mtd,size,&adm5120_cfe_parts[2]);
+ adm5120_cfe_parts[2].size = size - adm5120_cfe_parts[2].offset - adm5120_cfe_parts[3].size;
+
+ return adm5120_cfe_parts;
+}
+#endif
+
+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
+ 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)
+ {
+ 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;
+ }