Skip to content

Commit 15bce40

Browse files
David WoodhouseDavid Woodhouse
authored andcommitted
[MTD] Restore suspend/resume support for mtd devices
This is intended to suspend/resume the _chip_, while we leave board drivers to handle their own suspend/resume for the controller. Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent d694846 commit 15bce40

1 file changed

Lines changed: 37 additions & 10 deletions

File tree

‎drivers/mtd/mtdcore.c‎

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@
2323

2424
#include "mtdcore.h"
2525

26-
27-
static struct class *mtd_class;
26+
static int mtd_cls_suspend(struct device *dev, pm_message_t state);
27+
static int mtd_cls_resume(struct device *dev);
28+
29+
static struct class mtd_class = {
30+
.name = "mtd",
31+
.owner = THIS_MODULE,
32+
.suspend = mtd_cls_suspend,
33+
.resume = mtd_cls_resume,
34+
};
2835

2936
/* These are exported solely for the purpose of mtd_blkdevs.c. You
3037
should not use them for _anything_ else */
@@ -52,7 +59,26 @@ static void mtd_release(struct device *dev)
5259

5360
/* remove /dev/mtdXro node if needed */
5461
if (index)
55-
device_destroy(mtd_class, index + 1);
62+
device_destroy(&mtd_class, index + 1);
63+
}
64+
65+
static int mtd_cls_suspend(struct device *dev, pm_message_t state)
66+
{
67+
struct mtd_info *mtd = dev_to_mtd(dev);
68+
69+
if (mtd->suspend)
70+
return mtd->suspend(mtd);
71+
else
72+
return 0;
73+
}
74+
75+
static int mtd_cls_resume(struct device *dev)
76+
{
77+
struct mtd_info *mtd = dev_to_mtd(dev);
78+
79+
if (mtd->resume)
80+
mtd->resume(mtd);
81+
return 0;
5682
}
5783

5884
static ssize_t mtd_type_show(struct device *dev,
@@ -269,7 +295,7 @@ int add_mtd_device(struct mtd_info *mtd)
269295
* physical device.
270296
*/
271297
mtd->dev.type = &mtd_devtype;
272-
mtd->dev.class = mtd_class;
298+
mtd->dev.class = &mtd_class;
273299
mtd->dev.devt = MTD_DEVT(i);
274300
dev_set_name(&mtd->dev, "mtd%d", i);
275301
if (device_register(&mtd->dev) != 0) {
@@ -278,7 +304,7 @@ int add_mtd_device(struct mtd_info *mtd)
278304
}
279305

280306
if (MTD_DEVT(i))
281-
device_create(mtd_class, mtd->dev.parent,
307+
device_create(&mtd_class, mtd->dev.parent,
282308
MTD_DEVT(i) + 1,
283309
NULL, "mtd%dro", i);
284310

@@ -604,11 +630,12 @@ static int mtd_read_proc (char *page, char **start, off_t off, int count,
604630

605631
static int __init init_mtd(void)
606632
{
607-
mtd_class = class_create(THIS_MODULE, "mtd");
633+
int ret;
634+
ret = class_register(&mtd_class);
608635

609-
if (IS_ERR(mtd_class)) {
610-
pr_err("Error creating mtd class.\n");
611-
return PTR_ERR(mtd_class);
636+
if (ret) {
637+
pr_err("Error registering mtd class: %d\n", ret);
638+
return ret;
612639
}
613640
#ifdef CONFIG_PROC_FS
614641
if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
@@ -623,7 +650,7 @@ static void __exit cleanup_mtd(void)
623650
if (proc_mtd)
624651
remove_proc_entry( "mtd", NULL);
625652
#endif /* CONFIG_PROC_FS */
626-
class_destroy(mtd_class);
653+
class_unregister(&mtd_class);
627654
}
628655

629656
module_init(init_mtd);

0 commit comments

Comments
 (0)