From patchwork Tue Mar 22 07:38:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 600486 X-Patchwork-Delegate: jagannadh.teki@gmail.com 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 3qTlMg1phnz9s9N for ; Tue, 22 Mar 2016 18:54:23 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B0855A7954; Tue, 22 Mar 2016 08:47:34 +0100 (CET) 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 9eLqq-wyKVqG; Tue, 22 Mar 2016 08:47:34 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 49DFCA7816; Tue, 22 Mar 2016 08:47:30 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 009B1A7884 for ; Tue, 22 Mar 2016 08:45:26 +0100 (CET) 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 1CzBYv52QJUA for ; Tue, 22 Mar 2016 08:45:25 +0100 (CET) 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 mail-pf0-f196.google.com (mail-pf0-f196.google.com [209.85.192.196]) by theia.denx.de (Postfix) with ESMTPS id DFD79A7823 for ; Tue, 22 Mar 2016 08:44:35 +0100 (CET) Received: by mail-pf0-f196.google.com with SMTP id n5so34269363pfn.1 for ; Tue, 22 Mar 2016 00:44:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kny9zibSiMFnJJXPDWQE0eibjx0HFSQVP/hVkiDKU/E=; b=GndbV11LaXZ4/i8eLhZp6qPswMylZbwkmsV55GZ3pR8o9AVHJsdrVLqXC5a0h00F0k LEGwVUFkWD9oK74+uKi2pq9Lz2SsQ8TvLBld4Qv+ni5r4GsKBqdycTamzCOanWnl6o1P 1e3IxC5vLhs2/yEucw0ymP0MZ11dKDS2kQFkPzmonDFT3bZZ+RndlxwROe7k0cRKH78w FvT0Y4f2ATV6jVhWfEAh3n9yxgtgF8+I/8usCYbMnG/trYC00JzVeVEVBdw7r/clBGPd YROvfpjLxwwuxhIju8Xsxfy+F9tQGkgpMYqgc1lPYRlfcpwxnjTl1ojYFfvYoGee9fRc BZOg== X-Gm-Message-State: AD7BkJLQMY00ggWpaLtsOoWQnhu6w310lgBLqpgzklvtncp4uV3EEW10v3vnx0nbeuOWuA== X-Received: by 10.66.118.108 with SMTP id kl12mr50023606pab.151.1458632674324; Tue, 22 Mar 2016 00:44:34 -0700 (PDT) Received: from jteki-Latitude-E7450.amcc.com ([182.73.239.130]) by smtp.gmail.com with ESMTPSA id ko9sm45814957pab.37.2016.03.22.00.44.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Mar 2016 00:44:33 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Date: Tue, 22 Mar 2016 13:08:26 +0530 Message-Id: <1458632319-24866-74-git-send-email-jteki@openedev.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458632319-24866-1-git-send-email-jteki@openedev.com> References: <1458632319-24866-1-git-send-email-jteki@openedev.com> Cc: Michal Simek , Siva Durga Prasad Paladugu , Jagan Teki Subject: [U-Boot] [PATCH v7 74/87] mtd: spi-nor: Add erase ops X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Added spi_nor erase ops for m25p80. Cc: Simon Glass Cc: Bin Meng Cc: Mugunthan V N Cc: Michal Simek Cc: Siva Durga Prasad Paladugu Signed-off-by: Jagan Teki --- drivers/mtd/spi-nor/m25p80.c | 27 +++++++++++++++++++++++++++ drivers/mtd/spi-nor/spi-nor.c | 2 +- include/linux/mtd/spi-nor.h | 4 +++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/spi-nor/m25p80.c b/drivers/mtd/spi-nor/m25p80.c index bf9fe02..cf27ba0 100644 --- a/drivers/mtd/spi-nor/m25p80.c +++ b/drivers/mtd/spi-nor/m25p80.c @@ -166,6 +166,32 @@ static int m25p80_write(struct spi_nor *nor, const u8 *cmd, size_t cmd_len, return ret; } +static int m25p80_erase(struct spi_nor *nor, const u8 *cmd, size_t cmd_len) +{ + struct m25p *flash = nor->priv; + struct spi_slave *spi = flash->spi; + int ret; + + ret = spi_claim_bus(spi); + if (ret < 0) { + debug("m25p80: unable to claim SPI bus\n"); + return ret; + } + + if (nor->flags & SNOR_F_U_PAGE) + spi->flags |= SPI_XFER_U_PAGE; + + ret = spi_write_then_read(spi, cmd, cmd_len, NULL, NULL, 0); + if (ret < 0) { + debug("m25p80: error %d writing %x\n", ret, *cmd); + return ret; + } + + spi_release_bus(spi); + + return ret; +} + static int m25p80_spi_nor(struct spi_nor *nor) { struct mtd_info *mtd = nor->mtd; @@ -176,6 +202,7 @@ static int m25p80_spi_nor(struct spi_nor *nor) /* install hooks */ nor->read_mmap = m25p80_read_mmap; nor->read = m25p80_read; + nor->erase = m25p80_erase; nor->write = m25p80_write; nor->read_reg = m25p80_read_reg; nor->write_reg = m25p80_write_reg; diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 1ee1510..befee67 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -526,7 +526,7 @@ static int spi_nor_erase(struct mtd_info *mtd, struct erase_info *instr) write_enable(nor); - ret = nor->write(nor, cmd, sizeof(cmd), NULL, 0); + ret = nor->erase(nor, cmd, sizeof(cmd)); if (ret < 0) goto erase_err; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index 8b46b93..4749ff4 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -191,7 +191,8 @@ extern const struct spi_nor_info spi_nor_ids[]; * @read_mmap: [DRIVER-SPECIFIC] read data from the mmapped SPI NOR * @read: [DRIVER-SPECIFIC] read data from the SPI NOR * @write: [DRIVER-SPECIFIC] write data to the SPI NOR - * @flash_lock: [FLASH-SPECIFIC] lock a region of the SPI NOR + * @erase: [DRIVER-SPECIFIC] erase a sector of the SPI NOR + * @flash_lock: [FLASH-SPECIFIC] unlock a region of the SPI NOR * @flash_unlock: [FLASH-SPECIFIC] unlock a region of the SPI NOR * @flash_is_locked: [FLASH-SPECIFIC] check if a region of the SPI NOR is * @memory_map: address of read-only SPI NOR access @@ -227,6 +228,7 @@ struct spi_nor { void *data, size_t data_len); int (*write)(struct spi_nor *nor, const u8 *cmd, size_t cmd_len, const void *data, size_t data_len); + int (*erase)(struct spi_nor *nor, const u8 *cmd, size_t cmd_len); int (*flash_lock)(struct spi_nor *nor, loff_t ofs, uint64_t len); int (*flash_unlock)(struct spi_nor *nor, loff_t ofs, uint64_t len);