Rather than having every map/mtd driver doing the same sequence of
registering partitions and/or devices, implement common parse_mtd().
Signed-off-by: Mike Frysinger <[email protected]>
---
v2:
- ifdef parsers in parse_mtd()
- add "always_whole" to parse_mtd()
- add unparse_mtd()
drivers/mtd/mtdcore.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
include/linux/mtd/mtd.h | 5 ++++
2 files changed, 65 insertions(+), 0 deletions(-)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index a9d2469..2e91785 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -292,6 +292,66 @@ void put_mtd_device(struct mtd_info *mtd)
module_put(mtd->owner);
}
+#include <linux/mtd/partitions.h>
+
+/**
+ * parse_mtd - add partitions / devices
+ *
+ * If partitioning support is enabled, attempt to call parse_mtd_partitions()
+ * and add_mtd_partitions() with all available parsers. Otherwise just add
+ * the MTD device.
+ */
+
+int parse_mtd(struct mtd_info *mtd, const char **probe_types,
+ struct mtd_partition *parts, int nr_parts, bool always_whole)
+{
+ int ret;
+#ifdef CONFIG_MTD_PARTITIONS
+ const char *default_part_probe_types[] = {
+# ifdef CONFIG_MTD_CMDLINE_PARTS
+ "cmdlinepart",
+# endif
+# ifdef CONFIG_MTD_REDBOOT_PARTS
+ "RedBoot",
+# endif
+ NULL
+ };
+
+ if (!probe_types)
+ probe_types = default_part_probe_types;
+
+ ret = parse_mtd_partitions(mtd, probe_types, &parts, 0);
+ if (ret > 0) {
+ ret = add_mtd_partitions(mtd, parts, ret);
+ kfree(parts);
+ } else if (nr_parts)
+ ret = add_mtd_partitions(mtd, parts, nr_parts);
+#else
+ always_whole = true;
+#endif
+
+ if (always_whole)
+ ret = add_mtd_device(mtd);
+
+ return ret;
+}
+EXPORT_SYMBOL(parse_mtd);
+
+/**
+ * unparse_mtd - remove partitions / devices
+ *
+ * Undo the parse_mtd() steps -- so unregister all partitions and devices.
+ */
+
+void unparse_mtd(struct mtd_info *mtd)
+{
+#ifdef CONFIG_MTD_PARTITIONS
+ del_mtd_partitions(mtd);
+#endif
+ del_mtd_device(mtd);
+}
+EXPORT_SYMBOL(unparse_mtd);
+
/* default_mtd_writev - default mtd writev method for MTD devices that
* don't implement their own
*/
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index eae26bb..68ceaab 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -232,6 +232,11 @@ extern struct mtd_info *get_mtd_device_nm(const char *name);
extern void put_mtd_device(struct mtd_info *mtd);
+struct mtd_partition;
+extern int parse_mtd(struct mtd_info *mtd, const char **probe_types,
+ struct mtd_partition *parts, int nr_parts,
+ bool always_whole);
+extern void unparse_mtd(struct mtd_info *mtd);
struct mtd_notifier {
void (*add)(struct mtd_info *mtd);
--
1.6.0.3
Call parse_mtd() to handle partition/device registration rather than doing
it all ourself.
Signed-off-by: Mike Frysinger <[email protected]>
---
v2:
- call unparse_mtd()
- delete local nr_parts/parts in physmap_flash_info
drivers/mtd/maps/physmap.c | 39 +++------------------------------------
1 files changed, 3 insertions(+), 36 deletions(-)
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index 42d844f..d0e11b5 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -28,10 +28,6 @@ struct physmap_flash_info {
struct mtd_info *cmtd;
struct map_info map[MAX_RESOURCES];
struct resource *res;
-#ifdef CONFIG_MTD_PARTITIONS
- int nr_parts;
- struct mtd_partition *parts;
-#endif
};
static int physmap_flash_remove(struct platform_device *dev)
@@ -56,18 +52,7 @@ static int physmap_flash_remove(struct platform_device *dev)
for (i = 0; i < MAX_RESOURCES; i++) {
if (info->mtd[i] != NULL) {
-#ifdef CONFIG_MTD_PARTITIONS
- if (info->nr_parts) {
- del_mtd_partitions(info->mtd[i]);
- kfree(info->parts);
- } else if (physmap_data->nr_parts) {
- del_mtd_partitions(info->mtd[i]);
- } else {
- del_mtd_device(info->mtd[i]);
- }
-#else
- del_mtd_device(info->mtd[i]);
-#endif
+ unparse_mtd(info->mtd[i]);
map_destroy(info->mtd[i]);
}
@@ -84,9 +69,6 @@ static int physmap_flash_remove(struct platform_device *dev)
}
static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
-#ifdef CONFIG_MTD_PARTITIONS
-static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
-#endif
static int physmap_flash_probe(struct platform_device *dev)
{
@@ -170,23 +152,8 @@ static int physmap_flash_probe(struct platform_device *dev)
if (err)
goto err_out;
-#ifdef CONFIG_MTD_PARTITIONS
- err = parse_mtd_partitions(info->cmtd, part_probe_types, &info->parts, 0);
- if (err > 0) {
- add_mtd_partitions(info->cmtd, info->parts, err);
- return 0;
- }
-
- if (physmap_data->nr_parts) {
- printk(KERN_NOTICE "Using physmap partition information\n");
- add_mtd_partitions(info->cmtd, physmap_data->parts,
- physmap_data->nr_parts);
- return 0;
- }
-#endif
-
- add_mtd_device(info->cmtd);
- return 0;
+ return parse_mtd(info->cmtd, NULL, physmap_data->parts,
+ physmap_data->nr_parts, false);
err_out:
physmap_flash_remove(dev);
--
1.6.0.3
Call parse_mtd() to handle partition/device registration rather than doing
it all ourself.
Signed-off-by: Mike Frysinger <[email protected]>
---
v2:
- call unparse_mtd()
drivers/mtd/maps/bfin-async-flash.c | 32 ++++----------------------------
1 files changed, 4 insertions(+), 28 deletions(-)
diff --git a/drivers/mtd/maps/bfin-async-flash.c b/drivers/mtd/maps/bfin-async-flash.c
index 6fec86a..e432f94 100644
--- a/drivers/mtd/maps/bfin-async-flash.c
+++ b/drivers/mtd/maps/bfin-async-flash.c
@@ -120,13 +120,8 @@ static void bfin_copy_to(struct map_info *map, unsigned long to, const void *fro
switch_back(state);
}
-#ifdef CONFIG_MTD_PARTITIONS
-static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
-#endif
-
static int __devinit bfin_flash_probe(struct platform_device *pdev)
{
- int ret;
struct physmap_flash_data *pdata = pdev->dev.platform_data;
struct resource *memory = platform_get_resource(pdev, IORESOURCE_MEM, 0);
struct resource *flash_ambctl = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -150,6 +145,8 @@ static int __devinit bfin_flash_probe(struct platform_device *pdev)
state->flash_ambctl0 = flash_ambctl->start;
state->flash_ambctl1 = flash_ambctl->end;
+ platform_set_drvdata(pdev, state);
+
if (gpio_request(state->enet_flash_pin, DRIVER_NAME)) {
pr_devinit(KERN_ERR DRIVER_NAME ": Failed to request gpio %d\n", state->enet_flash_pin);
return -EBUSY;
@@ -161,35 +158,14 @@ static int __devinit bfin_flash_probe(struct platform_device *pdev)
if (!state->mtd)
return -ENXIO;
-#ifdef CONFIG_MTD_PARTITIONS
- ret = parse_mtd_partitions(state->mtd, part_probe_types, &pdata->parts, 0);
- if (ret > 0) {
- pr_devinit(KERN_NOTICE DRIVER_NAME ": Using commandline partition definition\n");
- add_mtd_partitions(state->mtd, pdata->parts, ret);
-
- } else if (pdata->nr_parts) {
- pr_devinit(KERN_NOTICE DRIVER_NAME ": Using board partition definition\n");
- add_mtd_partitions(state->mtd, pdata->parts, pdata->nr_parts);
-
- } else
-#endif
- {
- pr_devinit(KERN_NOTICE DRIVER_NAME ": no partition info available, registering whole flash at once\n");
- add_mtd_device(state->mtd);
- }
-
- platform_set_drvdata(pdev, state);
-
- return 0;
+ return parse_mtd(state->mtd, NULL, pdata->parts, pdata->nr_parts, false);
}
static int __devexit bfin_flash_remove(struct platform_device *pdev)
{
struct async_state *state = platform_get_drvdata(pdev);
gpio_free(state->enet_flash_pin);
-#ifdef CONFIG_MTD_PARTITIONS
- del_mtd_partitions(state->mtd);
-#endif
+ unparse_mtd(state->mtd);
map_destroy(state->mtd);
kfree(state);
return 0;
--
1.6.0.3
On Fri, 14 Nov 2008 07:22:31 -0500, Mike Frysinger <[email protected]> wrote:
> Rather than having every map/mtd driver doing the same sequence of
> registering partitions and/or devices, implement common parse_mtd().
>
> Signed-off-by: Mike Frysinger <[email protected]>
> ---
> v2:
> - ifdef parsers in parse_mtd()
> - add "always_whole" to parse_mtd()
> - add unparse_mtd()
>
> drivers/mtd/mtdcore.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
> include/linux/mtd/mtd.h | 5 ++++
> 2 files changed, 65 insertions(+), 0 deletions(-)
Though not tested yet on real hardware, all patches looks OK for me.
Thanks!
---
Atsushi Nemoto
On Fri, Nov 14, 2008 at 09:27, Atsushi Nemoto wrote:
> On Fri, 14 Nov 2008 07:22:31 -0500, Mike Frysinger wrote:
>> Rather than having every map/mtd driver doing the same sequence of
>> registering partitions and/or devices, implement common parse_mtd().
>>
>> Signed-off-by: Mike Frysinger <[email protected]>
>> ---
>> v2:
>> - ifdef parsers in parse_mtd()
>> - add "always_whole" to parse_mtd()
>> - add unparse_mtd()
>>
>> drivers/mtd/mtdcore.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
>> include/linux/mtd/mtd.h | 5 ++++
>> 2 files changed, 65 insertions(+), 0 deletions(-)
>
> Though not tested yet on real hardware, all patches looks OK for me.
ive tested the various code paths with physmap on my BF548-EZKIT ...
seemed to work OK ...
-mike