All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Cédric Cano" <ccano@interfaceconcept.com>
To: linux-mtd@lists.infradead.org
Subject: [PATCH 2/2] drivers/mtd/devices/m25p80.c: Fix whole device erase
Date: Mon, 03 Sep 2012 18:19:27 +0200	[thread overview]
Message-ID: <5044D88F.2060003@ic.fr> (raw)

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 ends. 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>
---

--- linux-3.5.3/drivers/mtd/devices/m25p80.c    2012-09-03 
18:03:35.787723207 +0200
+++ linux-3.5.3/drivers/mtd/devices/m25p80.c    2012-09-03 
18:01:17.455724709 +0200
@@ -202,31 +202,6 @@
      return -EBUSY;
  }

-/*
- * 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] */
@@ -301,33 +276,17 @@

      mutex_lock(&flash->lock);

-    /* whole-chip erase? */
-    if (len == flash->mtd.size) {
-        ret = erase_chip(flash);
+    /* "sector"-at-a-time erase */
+    while (len) {
+        ret = erase_sector(flash, addr);
          if (ret) {
              instr->state = MTD_ERASE_FAILED;
              mutex_unlock(&flash->lock);
              return ret;
          }

-    /* 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) {
-            ret = erase_sector(flash, addr)
-            if (ret) {
-                instr->state = MTD_ERASE_FAILED;
-                mutex_unlock(&flash->lock);
-                return ret;
-            }
-
-            addr += mtd->erasesize;
-            len -= mtd->erasesize;
-        }
+        addr += mtd->erasesize;
+        len -= mtd->erasesize;
      }

      mutex_unlock(&flash->lock);
---

             reply	other threads:[~2012-09-03 16:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-03 16:19 Cédric Cano [this message]
2012-09-21 11:44 ` [PATCH 2/2] drivers/mtd/devices/m25p80.c: Fix whole device erase Artem Bityutskiy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5044D88F.2060003@ic.fr \
    --to=ccano@interfaceconcept.com \
    --cc=linux-mtd@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.