From patchwork Fri Sep 21 12:39:51 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Cano?= X-Patchwork-Id: 185727 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6FD002C0088 for ; Fri, 21 Sep 2012 22:41:11 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TF2WV-0004CX-Pk; Fri, 21 Sep 2012 12:39:59 +0000 Received: from smtp08.msg.oleane.net ([62.161.4.8]) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TF2WT-0004CJ-2c for linux-mtd@lists.infradead.org; Fri, 21 Sep 2012 12:39:58 +0000 Received: from ic.fr (LDijon-156-65-26-47.w80-15.abo.wanadoo.fr [80.15.105.47]) by smtp08.msg.oleane.net (MTA) with ESMTP id q8LCdpcr009455 for ; Fri, 21 Sep 2012 14:39:51 +0200 X-Oleane-Rep: REPA Received: from [192.168.4.56] (unknown [192.168.4.56]) by ic.fr (Postfix) with ESMTPA id 4350F22AD1 for ; Fri, 21 Sep 2012 15:01:45 +0200 (CEST) Message-ID: <505C6017.8060607@ic.fr> Date: Fri, 21 Sep 2012 14:39:51 +0200 From: =?ISO-8859-1?Q?C=E9dric_Cano?= Organization: IC User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 MIME-Version: 1.0 To: linux-mtd@lists.infradead.org Subject: Fwd: [PATCH 1/1] drivers/mtd/devices/m25p80.c: Fix whole device erase References: <5045BCA9.5040401@ic.fr> In-Reply-To: <5045BCA9.5040401@ic.fr> X-Forwarded-Message-Id: <5045BCA9.5040401@ic.fr> X-Spam-Flag: NO X-PMX-Spam: Probability=10% X-PFSI-Info: PMX 5.5.9.395186, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.9.21.121814 (no antivirus check) X-Spam-Note: CRM114 invocation failed X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [62.161.4.8 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Cédric Cano 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 --- 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);