* [PATCH 1/1] drivers/mtd/devices/m25p80.c: Fix whole device erase
@ 2012-09-04 8:32 Cédric Cano
2012-09-21 12:39 ` Fwd: " Cédric Cano
0 siblings, 1 reply; 3+ messages in thread
From: Cédric Cano @ 2012-09-04 8:32 UTC (permalink / raw)
To: linux-mtd
From: Cédric Cano<ccano@interfaceconcept.com>
There are two ways to erase SPI Flash devices: sector per sector or the
entire Flash (used when MTD partition is the whole Flash).
When the whole Flash is erased, the SPI command is sent to the device
and the erase function exits. Then, when another access (read, write or
erase) is done, a wait of busy is performed that fails because of Flash
erase time (can be more than 30s in case of whole erase).
This patch removes chip erase and use only sector per sector erase to
erase the chip. When erase is performed, Flash accesses can be done.
C. Cano
Signed-off-by: Cédric Cano<ccano@interfaceconcept.com>
---
drivers/mtd/devices/m25p80.c | 50 +++++-------------------------------------
1 file changed, 5 insertions(+), 45 deletions(-)
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 5257345..b8956df 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -202,31 +202,6 @@ static int wait_till_ready(struct m25p *flash)
return 1;
}
-/*
- * Erase the whole flash memory
- *
- * Returns 0 if successful, non-zero otherwise.
- */
-static int erase_chip(struct m25p *flash)
-{
- pr_debug("%s: %s %lldKiB\n", dev_name(&flash->spi->dev), __func__,
- (long long)(flash->mtd.size >> 10));
-
- /* Wait until finished previous write command. */
- if (wait_till_ready(flash))
- return 1;
-
- /* Send write enable, then erase commands. */
- write_enable(flash);
-
- /* Set up command buffer. */
- flash->command[0] = OPCODE_CHIP_ERASE;
-
- spi_write(flash->spi, flash->command, 1);
-
- return 0;
-}
-
static void m25p_addr2cmd(struct m25p *flash, unsigned int addr, u8 *cmd)
{
/* opcode is in cmd[0] */
@@ -297,31 +272,16 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
mutex_lock(&flash->lock);
- /* whole-chip erase? */
- if (len == flash->mtd.size) {
- if (erase_chip(flash)) {
+ /* "sector"-at-a-time erase */
+ while (len) {
+ if (erase_sector(flash, addr)) {
instr->state = MTD_ERASE_FAILED;
mutex_unlock(&flash->lock);
return -EIO;
}
- /* REVISIT in some cases we could speed up erasing large regions
- * by using OPCODE_SE instead of OPCODE_BE_4K. We may have set up
- * to use "small sector erase", but that's not always optimal.
- */
-
- /* "sector"-at-a-time erase */
- } else {
- while (len) {
- if (erase_sector(flash, addr)) {
- instr->state = MTD_ERASE_FAILED;
- mutex_unlock(&flash->lock);
- return -EIO;
- }
-
- addr += mtd->erasesize;
- len -= mtd->erasesize;
- }
+ addr += mtd->erasesize;
+ len -= mtd->erasesize;
}
mutex_unlock(&flash->lock);
--
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Fwd: [PATCH 1/1] drivers/mtd/devices/m25p80.c: Fix whole device erase
2012-09-04 8:32 [PATCH 1/1] drivers/mtd/devices/m25p80.c: Fix whole device erase Cédric Cano
@ 2012-09-21 12:39 ` Cédric Cano
2012-09-21 13:42 ` Artem Bityutskiy
0 siblings, 1 reply; 3+ messages in thread
From: Cédric Cano @ 2012-09-21 12:39 UTC (permalink / raw)
To: linux-mtd
From: Cédric Cano<ccano@interfaceconcept.com>
When the whole SPI Flash is erased, the chip erase command is sent to the
device without waiting for end of erase. So next read/write accesses are
in failure.
This patch removes chip erase to use only sector per sector erase for
whole Flash too. When chip erase is done, Flash can be accessed without
error.
C. Cano
Signed-off-by: Cédric Cano<ccano@interfaceconcept.com>
---
drivers/mtd/devices/m25p80.c | 50 +++++-------------------------------------
1 file changed, 5 insertions(+), 45 deletions(-)
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 5257345..b8956df 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -202,31 +202,6 @@ static int wait_till_ready(struct m25p *flash)
return 1;
}
-/*
- * Erase the whole flash memory
- *
- * Returns 0 if successful, non-zero otherwise.
- */
-static int erase_chip(struct m25p *flash)
-{
- pr_debug("%s: %s %lldKiB\n", dev_name(&flash->spi->dev), __func__,
- (long long)(flash->mtd.size >> 10));
-
- /* Wait until finished previous write command. */
- if (wait_till_ready(flash))
- return 1;
-
- /* Send write enable, then erase commands. */
- write_enable(flash);
-
- /* Set up command buffer. */
- flash->command[0] = OPCODE_CHIP_ERASE;
-
- spi_write(flash->spi, flash->command, 1);
-
- return 0;
-}
-
static void m25p_addr2cmd(struct m25p *flash, unsigned int addr, u8 *cmd)
{
/* opcode is in cmd[0] */
@@ -297,31 +272,16 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
mutex_lock(&flash->lock);
- /* whole-chip erase? */
- if (len == flash->mtd.size) {
- if (erase_chip(flash)) {
+ /* "sector"-at-a-time erase */
+ while (len) {
+ if (erase_sector(flash, addr)) {
instr->state = MTD_ERASE_FAILED;
mutex_unlock(&flash->lock);
return -EIO;
}
- /* REVISIT in some cases we could speed up erasing large regions
- * by using OPCODE_SE instead of OPCODE_BE_4K. We may have set up
- * to use "small sector erase", but that's not always optimal.
- */
-
- /* "sector"-at-a-time erase */
- } else {
- while (len) {
- if (erase_sector(flash, addr)) {
- instr->state = MTD_ERASE_FAILED;
- mutex_unlock(&flash->lock);
- return -EIO;
- }
-
- addr += mtd->erasesize;
- len -= mtd->erasesize;
- }
+ addr += mtd->erasesize;
+ len -= mtd->erasesize;
}
mutex_unlock(&flash->lock);
--
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: Fwd: [PATCH 1/1] drivers/mtd/devices/m25p80.c: Fix whole device erase
2012-09-21 12:39 ` Fwd: " Cédric Cano
@ 2012-09-21 13:42 ` Artem Bityutskiy
0 siblings, 0 replies; 3+ messages in thread
From: Artem Bityutskiy @ 2012-09-21 13:42 UTC (permalink / raw)
To: Cédric Cano; +Cc: linux-mtd
[-- Attachment #1: Type: text/plain, Size: 561 bytes --]
On Fri, 2012-09-21 at 14:39 +0200, Cédric Cano wrote:
> From: Cédric Cano<ccano@interfaceconcept.com>
>
> When the whole SPI Flash is erased, the chip erase command is sent to the
> device without waiting for end of erase. So next read/write accesses are
> in failure.
Can you wait while the chip erase to finish?
> This patch removes chip erase to use only sector per sector erase for
> whole Flash too. When chip erase is done, Flash can be accessed without
> error.
How much slower is this method?
--
Best Regards,
Artem Bityutskiy
[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-09-21 13:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-04 8:32 [PATCH 1/1] drivers/mtd/devices/m25p80.c: Fix whole device erase Cédric Cano
2012-09-21 12:39 ` Fwd: " Cédric Cano
2012-09-21 13:42 ` Artem Bityutskiy
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).