Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / mtd / maps / physmap.c
index 5c505fb..f49ebc3 100644 (file)
@@ -1,7 +1,12 @@
 /*
- * $Id: physmap.c,v 1.29 2003/05/29 09:24:10 dwmw2 Exp $
+ * $Id: physmap.c,v 1.39 2005/11/29 14:49:36 gleixner Exp $
  *
  * Normal mappings of chips in physical memory
+ *
+ * Copyright (C) 2003 MontaVista Software Inc.
+ * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
+ *
+ * 031022 - [jsun] add run-time configure and partition setup
  */
 
 #include <linux/module.h>
 #include <linux/mtd/map.h>
 #include <linux/config.h>
 #include <linux/mtd/partitions.h>
-
-#define WINDOW_ADDR CONFIG_MTD_PHYSMAP_START
-#define WINDOW_SIZE CONFIG_MTD_PHYSMAP_LEN
-#define BUSWIDTH CONFIG_MTD_PHYSMAP_BUSWIDTH
+#include <linux/mtd/physmap.h>
 
 static struct mtd_info *mymtd;
 
-
 struct map_info physmap_map = {
-       .name = "Physically mapped flash",
-       .size = WINDOW_SIZE,
-       .buswidth = BUSWIDTH,
-       .phys = WINDOW_ADDR,
+       .name = "phys_mapped_flash",
+       .phys = CONFIG_MTD_PHYSMAP_START,
+       .size = CONFIG_MTD_PHYSMAP_LEN,
+       .bankwidth = CONFIG_MTD_PHYSMAP_BANKWIDTH,
 };
 
 #ifdef CONFIG_MTD_PARTITIONS
 static struct mtd_partition *mtd_parts;
 static int                   mtd_parts_nb;
 
-static struct mtd_partition physmap_partitions[] = {
-#if 0
-/* Put your own partition definitions here */
-       {
-               .name =         "bootROM",
-               .size =         0x80000,
-               .offset =       0,
-               .mask_flags =   MTD_WRITEABLE,  /* force read-only */
-       }, {
-               .name =         "zImage",
-               .size =         0x100000,
-               .offset =       MTDPART_OFS_APPEND,
-               .mask_flags =   MTD_WRITEABLE,  /* force read-only */
-       }, {
-               .name =         "ramdisk.gz",
-               .size =         0x300000,
-               .offset =       MTDPART_OFS_APPEND,
-               .mask_flags =   MTD_WRITEABLE,  /* force read-only */
-       }, {
-               .name =         "User FS",
-               .size =         MTDPART_SIZ_FULL,
-               .offset =       MTDPART_OFS_APPEND,
-       }
-#endif
-};
+static int num_physmap_partitions;
+static struct mtd_partition *physmap_partitions;
 
-#define NUM_PARTITIONS (sizeof(physmap_partitions)/sizeof(struct mtd_partition))
-const char *part_probes[] = {"cmdlinepart", "RedBoot", NULL};
+static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL};
 
+void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
+{
+       physmap_partitions=parts;
+       num_physmap_partitions=num_parts;
+}
 #endif /* CONFIG_MTD_PARTITIONS */
 
-int __init init_physmap(void)
+static int __init init_physmap(void)
 {
-       static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", 0 };
+       static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
        const char **type;
 
-               printk(KERN_NOTICE "physmap flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR);
-       physmap_map.virt = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
+               printk(KERN_NOTICE "physmap flash device: %lx at %lx\n", physmap_map.size, physmap_map.phys);
+       physmap_map.virt = ioremap(physmap_map.phys, physmap_map.size);
 
        if (!physmap_map.virt) {
                printk("Failed to ioremap\n");
@@ -79,7 +61,7 @@ int __init init_physmap(void)
 
        simple_map_init(&physmap_map);
 
-       mymtd = 0;
+       mymtd = NULL;
        type = rom_probe_types;
        for(; !mymtd && *type; type++) {
                mymtd = do_map_probe(*type, &physmap_map);
@@ -88,7 +70,7 @@ int __init init_physmap(void)
                mymtd->owner = THIS_MODULE;
 
 #ifdef CONFIG_MTD_PARTITIONS
-               mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes, 
+               mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes,
                                                    &mtd_parts, 0);
 
                if (mtd_parts_nb > 0)
@@ -97,11 +79,11 @@ int __init init_physmap(void)
                        return 0;
                }
 
-               if (NUM_PARTITIONS != 0) 
+               if (num_physmap_partitions != 0)
                {
-                       printk(KERN_NOTICE 
+                       printk(KERN_NOTICE
                               "Using physmap partition definition\n");
-                       add_mtd_partitions (mymtd, physmap_partitions, NUM_PARTITIONS);
+                       add_mtd_partitions (mymtd, physmap_partitions, num_physmap_partitions);
                        return 0;
                }
 
@@ -111,7 +93,7 @@ int __init init_physmap(void)
                return 0;
        }
 
-       iounmap((void *)physmap_map.virt);
+       iounmap(physmap_map.virt);
        return -ENXIO;
 }
 
@@ -121,7 +103,7 @@ static void __exit cleanup_physmap(void)
        if (mtd_parts_nb) {
                del_mtd_partitions(mymtd);
                kfree(mtd_parts);
-       } else if (NUM_PARTITIONS) {
+       } else if (num_physmap_partitions) {
                del_mtd_partitions(mymtd);
        } else {
                del_mtd_device(mymtd);
@@ -131,8 +113,8 @@ static void __exit cleanup_physmap(void)
 #endif
        map_destroy(mymtd);
 
-       iounmap((void *)physmap_map.virt);
-       physmap_map.virt = 0;
+       iounmap(physmap_map.virt);
+       physmap_map.virt = NULL;
 }
 
 module_init(init_physmap);