]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/mtd/maps/plat-ram.c
usb gadget serial: split out generic serial function
[linux-2.6-omap-h63xx.git] / drivers / mtd / maps / plat-ram.c
index 2b6504ecbbd16a362331000f501ee5371f5ed862..3eb2643b232875cea389ed0cfb45a55147eb898b 100644 (file)
@@ -47,6 +47,7 @@ struct platram_info {
        struct mtd_info         *mtd;
        struct map_info          map;
        struct mtd_partition    *partitions;
+       bool                    free_partitions;
        struct resource         *area;
        struct platdata_mtd_ram *pdata;
 };
@@ -98,7 +99,8 @@ static int platram_remove(struct platform_device *pdev)
 #ifdef CONFIG_MTD_PARTITIONS
                if (info->partitions) {
                        del_mtd_partitions(info->mtd);
-                       kfree(info->partitions);
+                       if (info->free_partitions)
+                               kfree(info->partitions);
                }
 #endif
                del_mtd_device(info->mtd);
@@ -169,13 +171,15 @@ static int platram_probe(struct platform_device *pdev)
                goto exit_free;
        }
 
-       dev_dbg(&pdev->dev, "got platform resource %p (0x%lx)\n", res, res->start);
+       dev_dbg(&pdev->dev, "got platform resource %p (0x%llx)\n", res,
+               (unsigned long long)res->start);
 
        /* setup map parameters */
 
        info->map.phys = res->start;
        info->map.size = (res->end - res->start) + 1;
-       info->map.name = pdata->mapname != NULL ? pdata->mapname : (char *)pdev->name;
+       info->map.name = pdata->mapname != NULL ?
+                       (char *)pdata->mapname : (char *)pdev->name;
        info->map.bankwidth = pdata->bankwidth;
 
        /* register our usage of the memory area */
@@ -202,9 +206,19 @@ static int platram_probe(struct platform_device *pdev)
 
        dev_dbg(&pdev->dev, "initialised map, probing for mtd\n");
 
-       /* probe for the right mtd map driver */
+       /* probe for the right mtd map driver
+        * supplied by the platform_data struct */
+
+       if (pdata->map_probes) {
+               const char **map_probes = pdata->map_probes;
+
+               for ( ; !info->mtd && *map_probes; map_probes++)
+                       info->mtd = do_map_probe(*map_probes , &info->map);
+       }
+       /* fallback to map_ram */
+       else
+               info->mtd = do_map_probe("map_ram", &info->map);
 
-       info->mtd = do_map_probe("map_ram" , &info->map);
        if (info->mtd == NULL) {
                dev_err(&pdev->dev, "failed to probe for map_ram\n");
                err = -ENOMEM;
@@ -219,19 +233,21 @@ static int platram_probe(struct platform_device *pdev)
         * to add this device whole */
 
 #ifdef CONFIG_MTD_PARTITIONS
-       if (pdata->nr_partitions > 0) {
-               const char **probes = { NULL };
-
-               if (pdata->probes)
-                       probes = (const char **)pdata->probes;
-
-               err = parse_mtd_partitions(info->mtd, probes,
+       if (!pdata->nr_partitions) {
+               /* try to probe using the supplied probe type */
+               if (pdata->probes) {
+                       err = parse_mtd_partitions(info->mtd, pdata->probes,
                                           &info->partitions, 0);
-               if (err > 0) {
-                       err = add_mtd_partitions(info->mtd, info->partitions,
-                                                err);
+                       info->free_partitions = 1;
+                       if (err > 0)
+                               err = add_mtd_partitions(info->mtd,
+                                       info->partitions, err);
                }
        }
+       /* use the static mapping */
+       else
+               err = add_mtd_partitions(info->mtd, pdata->partitions,
+                               pdata->nr_partitions);
 #endif /* CONFIG_MTD_PARTITIONS */
 
        if (add_mtd_device(info->mtd)) {
@@ -239,7 +255,9 @@ static int platram_probe(struct platform_device *pdev)
                err = -ENOMEM;
        }
 
-       dev_info(&pdev->dev, "registered mtd device\n");
+       if (!err)
+               dev_info(&pdev->dev, "registered mtd device\n");
+
        return err;
 
  exit_free:
@@ -250,6 +268,9 @@ static int platram_probe(struct platform_device *pdev)
 
 /* device driver info */
 
+/* work with hotplug and coldplug */
+MODULE_ALIAS("platform:mtd-ram");
+
 static struct platform_driver platram_driver = {
        .probe          = platram_probe,
        .remove         = platram_remove,