From patchwork Mon May 2 22:42:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Guinot X-Patchwork-Id: 93723 X-Patchwork-Delegate: vapier@gentoo.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 3098A1007DE for ; Tue, 3 May 2011 08:43:08 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 341CD2817E; Tue, 3 May 2011 00:42:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LdqeRxxubV4G; Tue, 3 May 2011 00:42:49 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 412A52819A; Tue, 3 May 2011 00:42:36 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9D8AC28187 for ; Tue, 3 May 2011 00:42:32 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PqzMtW-7zhMI for ; Tue, 3 May 2011 00:42:32 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from ns39351.ovh.net (ns39351.ovh.net [91.121.21.191]) by theia.denx.de (Postfix) with ESMTP id 00A352817E for ; Tue, 3 May 2011 00:42:30 +0200 (CEST) Received: from localhost (87-98-128-90.ovh.net [87.98.128.90]) by ns39351.ovh.net (Postfix) with ESMTPSA id B97F524DCB; Tue, 3 May 2011 00:42:29 +0200 (CEST) From: Simon Guinot To: Prafulla Wadaskar , Albert ARIBAUD , Wolfgang Denk , Mike Frysinger Date: Tue, 3 May 2011 00:42:24 +0200 Message-Id: <1304376148-6332-2-git-send-email-simon.guinot@sequanux.org> X-Mailer: git-send-email 1.6.3.1 In-Reply-To: References: Cc: u-boot@lists.denx.de, Simon Guinot Subject: [U-Boot] [PATCH v5 1/5] sf: disable write protection for Macronix flash X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Simon Guinot Signed-off-by: Simon Guinot --- Changes for v2: none Changes for v3: - rewrite patch using the common spi flash code Changes for v4: - use spi_flash_cmd_write_enable() Changes for v5: none drivers/mtd/spi/macronix.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 42 insertions(+), 0 deletions(-) diff --git a/drivers/mtd/spi/macronix.c b/drivers/mtd/spi/macronix.c index 96fd5f0..dacbc28 100644 --- a/drivers/mtd/spi/macronix.c +++ b/drivers/mtd/spi/macronix.c @@ -117,6 +117,45 @@ static const struct macronix_spi_flash_params macronix_spi_flash_table[] = { }, }; +static int macronix_write_status(struct spi_flash *flash, u8 sr) +{ + u8 cmd; + int ret; + + ret = spi_flash_cmd_write_enable(flash); + if (ret < 0) { + debug("SF: enabling write failed\n"); + return ret; + } + + cmd = CMD_MX25XX_WRSR; + ret = spi_flash_cmd_write(flash->spi, &cmd, 1, &sr, 1); + if (ret) { + debug("SF: fail to write status register\n"); + return ret; + } + + ret = spi_flash_cmd_wait_ready(flash, SPI_FLASH_PROG_TIMEOUT); + if (ret < 0) { + debug("SF: write status register timed out\n"); + return ret; + } + + return 0; +} + +static int macronix_unlock(struct spi_flash *flash) +{ + int ret; + + /* Enable status register writing and clear BP# bits */ + ret = macronix_write_status(flash, 0); + if (ret) + debug("SF: fail to disable write protection\n"); + + return ret; +} + static int macronix_erase(struct spi_flash *flash, u32 offset, size_t len) { return spi_flash_cmd_erase(flash, CMD_MX25XX_BE, offset, len); @@ -157,5 +196,8 @@ struct spi_flash *spi_flash_probe_macronix(struct spi_slave *spi, u8 *idcode) * params->sectors_per_block; flash->size = flash->sector_size * params->nr_blocks; + /* Clear BP# bits for read-only flash */ + macronix_unlock(flash); + return flash; }