diff options
-rw-r--r-- | drivers/mtd/mtdcore.c | 58 | ||||
-rw-r--r-- | include/linux/mtd/mtd.h | 5 |
2 files changed, 63 insertions, 0 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index c510aff289a..13267477e4e 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c | |||
@@ -452,6 +452,64 @@ int mtd_device_register(struct mtd_info *master, | |||
452 | EXPORT_SYMBOL_GPL(mtd_device_register); | 452 | EXPORT_SYMBOL_GPL(mtd_device_register); |
453 | 453 | ||
454 | /** | 454 | /** |
455 | * mtd_device_parse_register - parse partitions and register an MTD device. | ||
456 | * | ||
457 | * @mtd: the MTD device to register | ||
458 | * @types: the list of MTD partition probes to try, see | ||
459 | * 'parse_mtd_partitions()' for more information | ||
460 | * @origin: start address of MTD device, %0 unless you are sure you need this. | ||
461 | * @parts: fallback partition information to register, if parsing fails; | ||
462 | * only valid if %nr_parts > %0 | ||
463 | * @nr_parts: the number of partitions in parts, if zero then the full | ||
464 | * MTD device is registered if no partition info is found | ||
465 | * | ||
466 | * This function aggregates MTD partitions parsing (done by | ||
467 | * 'parse_mtd_partitions()') and MTD device and partitions registering. It | ||
468 | * basically follows the most common pattern found in many MTD drivers: | ||
469 | * | ||
470 | * * It first tries to probe partitions on MTD device @mtd using parsers | ||
471 | * specified in @types (if @types is %NULL, then the default list of parsers | ||
472 | * is used, see 'parse_mtd_partitions()' for more information). If none are | ||
473 | * found this functions tries to fallback to information specified in | ||
474 | * @parts/@nr_parts. | ||
475 | * * If any parititioning info was found, this function registers the found | ||
476 | * partitions. | ||
477 | * * If no partitions were found this function just registers the MTD device | ||
478 | * @mtd and exits. | ||
479 | * | ||
480 | * Returns zero in case of success and a negative error code in case of failure. | ||
481 | */ | ||
482 | int mtd_device_parse_register(struct mtd_info *mtd, const char **types, | ||
483 | unsigned long origin, | ||
484 | const struct mtd_partition *parts, | ||
485 | int nr_parts) | ||
486 | { | ||
487 | int err; | ||
488 | struct mtd_partition *real_parts; | ||
489 | |||
490 | err = parse_mtd_partitions(mtd, types, &real_parts, origin); | ||
491 | if (err <= 0 && nr_parts) { | ||
492 | real_parts = kmemdup(parts, sizeof(*parts) * nr_parts, | ||
493 | GFP_KERNEL); | ||
494 | err = nr_parts; | ||
495 | if (!parts) | ||
496 | err = -ENOMEM; | ||
497 | } | ||
498 | |||
499 | if (err > 0) { | ||
500 | err = add_mtd_partitions(mtd, real_parts, err); | ||
501 | kfree(real_parts); | ||
502 | } else if (err == 0) { | ||
503 | err = add_mtd_device(mtd); | ||
504 | if (err == 1) | ||
505 | err = -ENODEV; | ||
506 | } | ||
507 | |||
508 | return err; | ||
509 | } | ||
510 | EXPORT_SYMBOL_GPL(mtd_device_parse_register); | ||
511 | |||
512 | /** | ||
455 | * mtd_device_unregister - unregister an existing MTD device. | 513 | * mtd_device_unregister - unregister an existing MTD device. |
456 | * | 514 | * |
457 | * @master: the MTD device to unregister. This will unregister both the master | 515 | * @master: the MTD device to unregister. This will unregister both the master |
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 2541fb848da..d28a241e7b5 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h | |||
@@ -327,6 +327,11 @@ struct mtd_partition; | |||
327 | extern int mtd_device_register(struct mtd_info *master, | 327 | extern int mtd_device_register(struct mtd_info *master, |
328 | const struct mtd_partition *parts, | 328 | const struct mtd_partition *parts, |
329 | int nr_parts); | 329 | int nr_parts); |
330 | extern int mtd_device_parse_register(struct mtd_info *mtd, | ||
331 | const char **part_probe_types, | ||
332 | unsigned long origin, | ||
333 | const struct mtd_partition *defparts, | ||
334 | int defnr_parts); | ||
330 | extern int mtd_device_unregister(struct mtd_info *master); | 335 | extern int mtd_device_unregister(struct mtd_info *master); |
331 | extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); | 336 | extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); |
332 | extern int __get_mtd_device(struct mtd_info *mtd); | 337 | extern int __get_mtd_device(struct mtd_info *mtd); |