* [PATCH] power management for NAND flash
@ 2005-09-12 11:12 Vitaly Wool
2005-09-12 15:24 ` Martin Waitz
0 siblings, 1 reply; 4+ messages in thread
From: Vitaly Wool @ 2005-09-12 11:12 UTC (permalink / raw)
To: linux-mtd
Greetings,
the patch inlined below allows to suspend/resume NAND flash.
It's similar to what is implemented for NOR flashes in cfi_cmdset_0001.c/cfi_cmdset_0002.c.
It's based on 2.6.10 kernel but applies to the current CVS snapshot.
Best regards,
Vitaly
Index: linux-2.6.10/include/linux/mtd/nand.h
===================================================================
--- linux-2.6.10.orig/include/linux/mtd/nand.h
+++ linux-2.6.10/include/linux/mtd/nand.h
@@ -244,6 +244,7 @@
FL_ERASING,
FL_SYNCING,
FL_CACHEDPRG,
+ FL_PM_SUSPENDED,
} nand_state_t;
/* Keep gcc happy */
Index: linux-2.6.10/drivers/mtd/nand/nand_base.c
===================================================================
--- linux-2.6.10.orig/drivers/mtd/nand/nand_base.c
+++ linux-2.6.10/drivers/mtd/nand/nand_base.c
@@ -46,6 +46,8 @@
* perform extra error status checks on erase and write failures. This required
* adding a wrapper function for nand_read_ecc.
*
+ * 08-20-2005 vwool: suspend/resume added
+ *
* Credits:
* David Woodhouse for adding multichip support
*
@@ -153,7 +155,7 @@
#define nand_verify_pages(...) (0)
#endif
-static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state);
+static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state);
/**
* nand_release_device - [GENERIC] release chip
@@ -755,7 +757,7 @@
*
* Get the device and lock it for exclusive access
*/
-static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state)
+static int nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state)
{
struct nand_chip *active;
spinlock_t *lock;
@@ -778,7 +780,11 @@
if (active == this && this->state == FL_READY) {
this->state = new_state;
spin_unlock(lock);
- return;
+ return 0;
+ }
+ if (new_state == FL_PM_SUSPENDED) {
+ spin_unlock(lock);
+ return (this->state == FL_PM_SUSPENDED) ? 0 : -EAGAIN;
}
set_current_state(TASK_UNINTERRUPTIBLE);
add_wait_queue(wq, &wait);
@@ -2284,6 +2290,34 @@
}
/**
+ * nand_suspend - [MTD Interface] Suspend the NAND flash
+ * @mtd: MTD device structure
+ */
+static int nand_suspend(struct mtd_info *mtd)
+{
+ struct nand_chip *this = mtd->priv;
+
+ return nand_get_device (this, mtd, FL_PM_SUSPENDED);
+}
+
+/**
+ * nand_resume - [MTD Interface] Resume the NAND flash
+ * @mtd: MTD device structure
+ */
+static void nand_resume(struct mtd_info *mtd)
+{
+ struct nand_chip *this = mtd->priv;
+
+ if (this->state == FL_PM_SUSPENDED)
+ nand_release_device(mtd);
+ else
+ printk(KERN_ERR "resume() called for the chip which is not "
+ "in suspended state\n");
+
+}
+
+
+/**
* nand_scan - [NAND Interface] Scan for the NAND device
* @mtd: MTD device structure
* @maxchips: Number of chips to scan for
@@ -2642,8 +2676,8 @@
mtd->sync = nand_sync;
mtd->lock = NULL;
mtd->unlock = NULL;
- mtd->suspend = NULL;
- mtd->resume = NULL;
+ mtd->suspend = nand_suspend;
+ mtd->resume = nand_resume;
mtd->block_isbad = nand_block_isbad;
mtd->block_markbad = nand_block_markbad;
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] power management for NAND flash
2005-09-12 11:12 [PATCH] power management for NAND flash Vitaly Wool
@ 2005-09-12 15:24 ` Martin Waitz
2005-09-12 16:08 ` Vitaly Wool
0 siblings, 1 reply; 4+ messages in thread
From: Martin Waitz @ 2005-09-12 15:24 UTC (permalink / raw)
To: Vitaly Wool; +Cc: linux-mtd
[-- Attachment #1: Type: text/plain, Size: 262 bytes --]
hoi :)
On Mon, Sep 12, 2005 at 03:12:44PM +0400, Vitaly Wool wrote:
> the patch inlined below allows to suspend/resume NAND flash.
shouldn't we call the board driver while suspending,
to allow to actually power down the NAND flash?
--
Martin Waitz
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] power management for NAND flash
2005-09-12 15:24 ` Martin Waitz
@ 2005-09-12 16:08 ` Vitaly Wool
2005-09-12 18:39 ` Martin Waitz
0 siblings, 1 reply; 4+ messages in thread
From: Vitaly Wool @ 2005-09-12 16:08 UTC (permalink / raw)
To: Martin Waitz; +Cc: linux-mtd
Hi Martin,
Exactly. We should.
But prior to shut off the clock/power down the flash we need to put the
flash driver into the corresponding state (suspended).
Thus, a typical suspend (pseudo) code for NAND flash will look the
following way:
static int chip_nand_suspend(struct device *dev, u32 state, u32 level)
{
int retval = 0;
#ifdef CONFIG_PM
struct mtd_info *mtd = dev_get_drvdata(dev);
if (mtd && mtd->suspend && level == SUSPEND_SAVE_STATE) {
retval = mtd->suspend(mtd);
if (retval == 0) {
/* shut off the clocks and power down the
controller here */
}
}
#endif
return retval;
}
with a resume routine doing just the oppsite.
Hope that clarifies the whole thing :)
Best regards,
Vitaly
Martin Waitz wrote:
>hoi :)
>
>On Mon, Sep 12, 2005 at 03:12:44PM +0400, Vitaly Wool wrote:
>
>
>>the patch inlined below allows to suspend/resume NAND flash.
>>
>>
>
>shouldn't we call the board driver while suspending,
>to allow to actually power down the NAND flash?
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2005-09-12 18:39 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-12 11:12 [PATCH] power management for NAND flash Vitaly Wool
2005-09-12 15:24 ` Martin Waitz
2005-09-12 16:08 ` Vitaly Wool
2005-09-12 18:39 ` Martin Waitz
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox