Switch mtd to new power management.
Signed-off-by: Pavel Machek <[email protected]>
---
commit c608c935000f919426316a2f76084e31cab0171b
tree e5bbc83aac75f5916cf79f7e531530c9655e38c6
parent 81a2889a21eb2bfdf8b242f2cc2cc1d6ad424ea2
author <pavel@amd.(none)> Fri, 30 Sep 2005 00:19:32 +0200
committer <pavel@amd.(none)> Fri, 30 Sep 2005 00:19:32 +0200
drivers/mtd/mtdcore.c | 68 ++++++++++++++++++++++++++++++++-----------------
1 files changed, 44 insertions(+), 24 deletions(-)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -19,6 +19,7 @@
#include <linux/ioctl.h>
#include <linux/init.h>
#include <linux/mtd/compatmac.h>
+#include <linux/sysdev.h>
#ifdef CONFIG_PROC_FS
#include <linux/proc_fs.h>
#endif
@@ -80,6 +81,7 @@ int add_mtd_device(struct mtd_info *mtd)
return 1;
}
+
/**
* del_mtd_device - unregister an MTD device
* @mtd: pointer to MTD device info structure
@@ -303,30 +305,59 @@ EXPORT_SYMBOL(default_mtd_readv);
#include <linux/pm.h>
-static struct pm_dev *mtd_pm_dev = NULL;
+static int mtd_resume(struct sys_device *dev)
+{
+ int ret = 0, i;
-static int mtd_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
+ if (down_trylock(&mtd_table_mutex))
+ return -EAGAIN;
+
+ for (i = MAX_MTD_DEVICES-1; i >= 0; i--) {
+ if (mtd_table[i] && mtd_table[i]->resume)
+ mtd_table[i]->resume(mtd_table[i]);
+ }
+
+ up(&mtd_table_mutex);
+ return ret;
+}
+
+static int mtd_suspend(struct sys_device *dev, pm_message_t state)
{
int ret = 0, i;
if (down_trylock(&mtd_table_mutex))
return -EAGAIN;
- if (rqst == PM_SUSPEND) {
- for (i = 0; ret == 0 && i < MAX_MTD_DEVICES; i++) {
- if (mtd_table[i] && mtd_table[i]->suspend)
- ret = mtd_table[i]->suspend(mtd_table[i]);
- }
- } else i = MAX_MTD_DEVICES-1;
- if (rqst == PM_RESUME || ret) {
- for ( ; i >= 0; i--) {
- if (mtd_table[i] && mtd_table[i]->resume)
- mtd_table[i]->resume(mtd_table[i]);
- }
+ for (i = 0; ret == 0 && i < MAX_MTD_DEVICES; i++) {
+ if (mtd_table[i] && mtd_table[i]->suspend)
+ ret = mtd_table[i]->suspend(mtd_table[i]);
}
+
up(&mtd_table_mutex);
return ret;
}
+
+static struct sysdev_class mtd_sysdev_class = {
+ set_kset_name("mtd"),
+ .suspend = mtd_suspend,
+ .resume = mtd_resume,
+};
+
+static struct sys_device device_mtd = {
+ .id = 0,
+ .cls = &mtd_sysdev_class,
+};
+
+static int __init mtd_init_sysfs(void)
+{
+ int error = sysdev_class_register(&mtd_sysdev_class);
+ if (!error)
+ error = sysdev_register(&device_mtd);
+ return error;
+}
+
+device_initcall(mtd_init_sysfs);
+
#endif
/*====================================================================*/
@@ -388,22 +419,11 @@ static int __init init_mtd(void)
if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
proc_mtd->read_proc = mtd_read_proc;
#endif
-
-#ifdef CONFIG_PM
- mtd_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, mtd_pm_callback);
-#endif
return 0;
}
static void __exit cleanup_mtd(void)
{
-#ifdef CONFIG_PM
- if (mtd_pm_dev) {
- pm_unregister(mtd_pm_dev);
- mtd_pm_dev = NULL;
- }
-#endif
-
#ifdef CONFIG_PROC_FS
if (proc_mtd)
remove_proc_entry( "mtd", NULL);
!-------------------------------------------------------------flip-
Kill useless ifdefs from mtd.
---
commit b6ee6a389e7679a4f81e61a4c1ce84232df1a6f5
tree b71d9dbd8d035ef167134b88e67ed1d662b43146
parent c608c935000f919426316a2f76084e31cab0171b
author <pavel@amd.(none)> Fri, 30 Sep 2005 00:20:52 +0200
committer <pavel@amd.(none)> Fri, 30 Sep 2005 00:20:52 +0200
drivers/mtd/mtdcore.c | 6 ------
1 files changed, 0 insertions(+), 6 deletions(-)
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -20,9 +20,7 @@
#include <linux/init.h>
#include <linux/mtd/compatmac.h>
#include <linux/sysdev.h>
-#ifdef CONFIG_PROC_FS
#include <linux/proc_fs.h>
-#endif
#include <linux/mtd/mtd.h>
@@ -415,19 +413,15 @@ done:
static int __init init_mtd(void)
{
-#ifdef CONFIG_PROC_FS
if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
proc_mtd->read_proc = mtd_read_proc;
-#endif
return 0;
}
static void __exit cleanup_mtd(void)
{
-#ifdef CONFIG_PROC_FS
if (proc_mtd)
remove_proc_entry( "mtd", NULL);
-#endif
}
module_init(init_mtd);
!-------------------------------------------------------------flip-
--
if you have sharp zaurus hardware you don't need... you know my address
On Fri, Sep 30, 2005 at 02:17:41PM +0200, Pavel Machek wrote:
> Switch mtd to new power management.
You don't need to do it this way - and this will probably mess up the
SA1100 suspend code. MTD map drivers should probably be converted to
the driver model rather than the core so that the PM ordering can be
correctly handled.
(Consider the case where there's flash on a daughter board accessed
over some kind of bridge.)
--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core
Hi Pavel,
it looks like your patch is not against the latest linux-mtd CVS sources
since there's no such things as mtd_pm_dev in the current one. Please
correct me if I'm mistaken.
Vitaly
Pavel Machek wrote:
>Switch mtd to new power management.
>
>Signed-off-by: Pavel Machek <[email protected]>
>
>---
>commit c608c935000f919426316a2f76084e31cab0171b
>tree e5bbc83aac75f5916cf79f7e531530c9655e38c6
>parent 81a2889a21eb2bfdf8b242f2cc2cc1d6ad424ea2
>author <pavel@amd.(none)> Fri, 30 Sep 2005 00:19:32 +0200
>committer <pavel@amd.(none)> Fri, 30 Sep 2005 00:19:32 +0200
>
> drivers/mtd/mtdcore.c | 68 ++++++++++++++++++++++++++++++++-----------------
> 1 files changed, 44 insertions(+), 24 deletions(-)
>
>diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
>--- a/drivers/mtd/mtdcore.c
>+++ b/drivers/mtd/mtdcore.c
>@@ -19,6 +19,7 @@
> #include <linux/ioctl.h>
> #include <linux/init.h>
> #include <linux/mtd/compatmac.h>
>+#include <linux/sysdev.h>
> #ifdef CONFIG_PROC_FS
> #include <linux/proc_fs.h>
> #endif
>@@ -80,6 +81,7 @@ int add_mtd_device(struct mtd_info *mtd)
> return 1;
> }
>
>+
> /**
> * del_mtd_device - unregister an MTD device
> * @mtd: pointer to MTD device info structure
>@@ -303,30 +305,59 @@ EXPORT_SYMBOL(default_mtd_readv);
>
> #include <linux/pm.h>
>
>-static struct pm_dev *mtd_pm_dev = NULL;
>+static int mtd_resume(struct sys_device *dev)
>+{
>+ int ret = 0, i;
>
>-static int mtd_pm_callback(struct pm_dev *dev, pm_request_t rqst, void *data)
>+ if (down_trylock(&mtd_table_mutex))
>+ return -EAGAIN;
>+
>+ for (i = MAX_MTD_DEVICES-1; i >= 0; i--) {
>+ if (mtd_table[i] && mtd_table[i]->resume)
>+ mtd_table[i]->resume(mtd_table[i]);
>+ }
>+
>+ up(&mtd_table_mutex);
>+ return ret;
>+}
>+
>+static int mtd_suspend(struct sys_device *dev, pm_message_t state)
> {
> int ret = 0, i;
>
> if (down_trylock(&mtd_table_mutex))
> return -EAGAIN;
>- if (rqst == PM_SUSPEND) {
>- for (i = 0; ret == 0 && i < MAX_MTD_DEVICES; i++) {
>- if (mtd_table[i] && mtd_table[i]->suspend)
>- ret = mtd_table[i]->suspend(mtd_table[i]);
>- }
>- } else i = MAX_MTD_DEVICES-1;
>
>- if (rqst == PM_RESUME || ret) {
>- for ( ; i >= 0; i--) {
>- if (mtd_table[i] && mtd_table[i]->resume)
>- mtd_table[i]->resume(mtd_table[i]);
>- }
>+ for (i = 0; ret == 0 && i < MAX_MTD_DEVICES; i++) {
>+ if (mtd_table[i] && mtd_table[i]->suspend)
>+ ret = mtd_table[i]->suspend(mtd_table[i]);
> }
>+
> up(&mtd_table_mutex);
> return ret;
> }
>+
>+static struct sysdev_class mtd_sysdev_class = {
>+ set_kset_name("mtd"),
>+ .suspend = mtd_suspend,
>+ .resume = mtd_resume,
>+};
>+
>+static struct sys_device device_mtd = {
>+ .id = 0,
>+ .cls = &mtd_sysdev_class,
>+};
>+
>+static int __init mtd_init_sysfs(void)
>+{
>+ int error = sysdev_class_register(&mtd_sysdev_class);
>+ if (!error)
>+ error = sysdev_register(&device_mtd);
>+ return error;
>+}
>+
>+device_initcall(mtd_init_sysfs);
>+
> #endif
>
> /*====================================================================*/
>@@ -388,22 +419,11 @@ static int __init init_mtd(void)
> if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
> proc_mtd->read_proc = mtd_read_proc;
> #endif
>-
>-#ifdef CONFIG_PM
>- mtd_pm_dev = pm_register(PM_UNKNOWN_DEV, 0, mtd_pm_callback);
>-#endif
> return 0;
> }
>
> static void __exit cleanup_mtd(void)
> {
>-#ifdef CONFIG_PM
>- if (mtd_pm_dev) {
>- pm_unregister(mtd_pm_dev);
>- mtd_pm_dev = NULL;
>- }
>-#endif
>-
> #ifdef CONFIG_PROC_FS
> if (proc_mtd)
> remove_proc_entry( "mtd", NULL);
>
>
>
>!-------------------------------------------------------------flip-
>
>
>Kill useless ifdefs from mtd.
>
>---
>commit b6ee6a389e7679a4f81e61a4c1ce84232df1a6f5
>tree b71d9dbd8d035ef167134b88e67ed1d662b43146
>parent c608c935000f919426316a2f76084e31cab0171b
>author <pavel@amd.(none)> Fri, 30 Sep 2005 00:20:52 +0200
>committer <pavel@amd.(none)> Fri, 30 Sep 2005 00:20:52 +0200
>
> drivers/mtd/mtdcore.c | 6 ------
> 1 files changed, 0 insertions(+), 6 deletions(-)
>
>diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
>--- a/drivers/mtd/mtdcore.c
>+++ b/drivers/mtd/mtdcore.c
>@@ -20,9 +20,7 @@
> #include <linux/init.h>
> #include <linux/mtd/compatmac.h>
> #include <linux/sysdev.h>
>-#ifdef CONFIG_PROC_FS
> #include <linux/proc_fs.h>
>-#endif
>
> #include <linux/mtd/mtd.h>
>
>@@ -415,19 +413,15 @@ done:
>
> static int __init init_mtd(void)
> {
>-#ifdef CONFIG_PROC_FS
> if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
> proc_mtd->read_proc = mtd_read_proc;
>-#endif
> return 0;
> }
>
> static void __exit cleanup_mtd(void)
> {
>-#ifdef CONFIG_PROC_FS
> if (proc_mtd)
> remove_proc_entry( "mtd", NULL);
>-#endif
> }
>
> module_init(init_mtd);
>
>
>
>!-------------------------------------------------------------flip-
>
>
>
>
>
On Fri, 2005-09-30 at 18:14 +0400, Vitaly Wool wrote:
> Hi Pavel,
>
> it looks like your patch is not against the latest linux-mtd CVS sources
> since there's no such things as mtd_pm_dev in the current one. Please
> correct me if I'm mistaken.
I'm assuming Pavel is just fixing up what's in the mainline kernel.
This happens quite often, since MTD doesn't sync all too much for
various reasons.
When a sync is done, stuff like this usually gets picked up in some form
for the MTD CVS tree. See the commit messages that say things like
"Merge with upstream".
josh
As far as I've heard, there's gonna be a megre quite soon... :)
Anyway, I guess it'd be better if Pavel ntroduced the new patch against
the latest linux-mtd code.
Best regards,
Vitaly
Josh Boyer wrote:
>On Fri, 2005-09-30 at 18:14 +0400, Vitaly Wool wrote:
>
>
>>Hi Pavel,
>>
>>it looks like your patch is not against the latest linux-mtd CVS sources
>>since there's no such things as mtd_pm_dev in the current one. Please
>>correct me if I'm mistaken.
>>
>>
>
>I'm assuming Pavel is just fixing up what's in the mainline kernel.
>This happens quite often, since MTD doesn't sync all too much for
>various reasons.
>
>When a sync is done, stuff like this usually gets picked up in some form
>for the MTD CVS tree. See the commit messages that say things like
>"Merge with upstream".
>
>josh
>
>
>
>
On Fri, Sep 30, 2005 at 10:12:32PM +0400, Vitaly Wool wrote:
> As far as I've heard, there's gonna be a megre quite soon... :)
> Anyway, I guess it'd be better if Pavel ntroduced the new patch against
> the latest linux-mtd code.
I don't think it's required. The SA1100 map driver handles the PM
already, as I'm sure the PXA map driver will also.
All it takes is for the other map drivers to be converted and hey
presto, the MTD subsystem has power management support done the
right way.
--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 Serial core