diff options
author | Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> | 2011-03-25 15:26:25 -0400 |
---|---|---|
committer | Artem Bityutskiy <artem.bityutskiy@intel.com> | 2011-09-11 08:02:05 -0400 |
commit | 1c4c215cbdcbfd08183d82b2953591cd00564422 (patch) | |
tree | bb43365c3e16e3634a6f53dab61c2e8e6145563b /drivers/mtd/mtdcore.c | |
parent | 3761a6ddacc83e5a6b4482d98fbf212805381486 (diff) |
mtd: add new API for handling MTD registration
Lots (nearly all) mtd drivers contain nearly the similar code that
calls parse_mtd_partitions, provides some platform-default values, if
parsing fails, and registers mtd device.
This is an aim to provide single implementation of this scenario:
mtd_device_parse_register() which will handle all this parsing and
defaults.
Artem: amended comments
Signed-off-by: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
Signed-off-by: Artem Bityutskiy <Artem.Bityutskiy@nokia.com>
Diffstat (limited to 'drivers/mtd/mtdcore.c')
-rw-r--r-- | drivers/mtd/mtdcore.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index c510aff289a8..13267477e4e9 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 |