From 6748bfddac5665ea3b82f1e6ecf29f21e67c5332 Mon Sep 17 00:00:00 2001 From: Russell King Date: Sat, 13 Nov 2004 00:46:52 +0000 Subject: [PATCH] [MTD] sa1100: more driver model integration and consolidation. - combine sa1100_locate_partitions with sa1100_mtd_probe. - set device driver data in the probe method, and use this to get at our driver private information in the other methods. --- drivers/mtd/maps/sa1100-flash.c | 53 ++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c index 452e00fcb9ee..aac2c3cf6582 100644 --- a/drivers/mtd/maps/sa1100-flash.c +++ b/drivers/mtd/maps/sa1100-flash.c @@ -1267,13 +1267,25 @@ static int __init sa1100_locate_flash(struct sa_info *info) return nr; } -const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL }; +static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL }; -static void __init sa1100_locate_partitions(struct sa_info *info) +static struct sa_info sa_info; + +static int __init sa1100_mtd_probe(struct device *dev) { struct mtd_partition *parts; const char *part_type = NULL; - int nr_parts = 0; + struct sa_info *info = &sa_info; + int err, nr_parts = 0; + int nr; + + nr = sa1100_locate_flash(info); + if (nr < 0) + return nr; + + err = sa1100_setup_mtd(info, nr); + if (err != 0) + goto out; /* * Partition selection stuff. @@ -1300,40 +1312,39 @@ static void __init sa1100_locate_partitions(struct sa_info *info) add_mtd_partitions(info->mtd, parts, nr_parts); } - /* Always succeeds. */ -} - -static struct sa_info sa_info; - -static int __init sa1100_mtd_probe(struct device *dev) -{ - int err; - int nr; - - nr = sa1100_locate_flash(&sa_info); - if (nr < 0) - return nr; - - err = sa1100_setup_mtd(&sa_info, nr); - if (err == 0) - sa1100_locate_partitions(&sa_info); + dev_set_drvdata(dev, info); + err = 0; + out: return err; } static int __exit sa1100_mtd_remove(struct device *dev) { - sa1100_destroy(&sa_info); + struct sa_info *info = dev_get_drvdata(dev); + dev_set_drvdata(dev, NULL); + sa1100_destroy(info); return 0; } #ifdef CONFIG_PM static int sa1100_mtd_suspend(struct device *dev, u32 state, u32 level) { + struct sa_info *info = dev_get_drvdata(dev); + int ret = 0; + + if (info && level == SUSPEND_SAVE_STATE) + ret = info->mtd->suspend(info->mtd); + + return ret; } static int sa1100_mtd_resume(struct device *dev, u32 level) { + struct sa_info *info = dev_get_drvdata(dev); + if (info && level == RESUME_RESTORE_STATE) + info->mtd->resume(info->mtd); + return 0; } #else #define sa1100_mtd_suspend NULL -- 2.39.5