From patchwork Tue May 7 15:59:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagar Shrikant Kadam X-Patchwork-Id: 10933201 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4D98F933 for ; Tue, 7 May 2019 16:00:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3175728715 for ; Tue, 7 May 2019 16:00:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 256B0287F9; Tue, 7 May 2019 16:00:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B541C287DE for ; Tue, 7 May 2019 16:00:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Message-Id:Date:Subject:To:From: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=PgQeao6BvDbpSrLviqLWpeWwyLHywQzM/L8sgEzwm3g=; b=M2B/Nw2Bvle2BQ K70V0VPWFd10R3k+WmlkHk62cO58Fs8ADXn8Tp0gFzt35r/2SvlRG95hMZIHtmEGveshBsc8eOmBC Wshibmhfwm98U7qmQJVzLyn0qujZje9b0lG9DNF1+i70V7wvzHqlQMoh0+B2lXD1rrXH3/5v38tFf NvLn34F4ULId6cBPqoIznlfnG9varcR0pNiaLr7uE0vteIsPHZrk9bfZbd/fLtLkSRjXmy7uqviZd XFaSqX/z6nXkjUnjn3hD+p5nPsOT+cl16qked82D4sBposiAvxRI482QGtOMqI+WupZUfxUzO0cW4 Nt5ew/BO8Rmc5FrUuaag==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hO2VY-0008LL-O5; Tue, 07 May 2019 15:59:56 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hO2VS-0008A6-KH for linux-riscv@lists.infradead.org; Tue, 07 May 2019 15:59:55 +0000 Received: by mail-pl1-x644.google.com with SMTP id g9so989428plm.6 for ; Tue, 07 May 2019 08:59:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:from:to:cc:subject:date:message-id; bh=Jk4l4aIhsSS1QaMGb/xfaCHwS6DqaTwgoIuoYji1K5w=; b=MIaRFN3fv3+GWWwZnBAErq1T33G8rzvbl422n5Qc2yFfjz++rNY//jxFv5G8+cbVGQ qyeY4WCPn7hxzv86c9HWZEWHxzzxQoHAFjjxfZE+1aEcjFLFH4mN/wDg4dw9MM3CQItK vZzfjNK5gcbQ8n+9E5LUpqiywcxxVNOOSihLlQd1KqJQt6Iaem9CcHh3nbMXqsIfxXkI t5IxN7pdYihTH8VdxjCB4Ckeyma451Dmjhvdq7V86U/X4I4ZXAIiYG0O5Vc3G0dJPFy7 eTEgNQSBRY4U0BofW4a6Me1G3BmxKOEr5do0Qog9ddXygfCoU8OIYYuQqz+wCjKEBzw0 QO6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=mime-version:x-gm-message-state:from:to:cc:subject:date:message-id; bh=Jk4l4aIhsSS1QaMGb/xfaCHwS6DqaTwgoIuoYji1K5w=; b=q+khrwFw1zRGkJorpjUqa8fU8nUobpdbYugrNn8vL/5xXPo8719RqzEgMCifF1qq39 RM70Z4FP02j5HC3s7Y/7ACjIah9rwRtgKEQoipSmQgC4mWeG+0mWu6dmf33ssDsH5iRk dfvOlFWmYqtiXn4gWzfmegc/D3+FFt85KM1vU/pI8/6wNJl1ucfSwVHlrHxrWuq4dDPP CL5QmMCsWj3l6lN00HLDrj3EdwYtzKdNqpc7vcEzR/c1cHHLD5304n5C4ZFyq9G5nw/5 txcw29nhbtcnZtmlmxQuXONeffuh5W6Bi+6322x1yM/w0HAE8mZsfRDRHNMF7i9dsdPj PLKg== MIME-Version: 1.0 X-Gm-Message-State: APjAAAUKBmyWJkB7psW7yWHBzTAqeDxR38m+NYW+WsSXmZtlQN8q/xwz 1nbjS3FeswnD/iWIToqP27BXwZXnzzRMZP4OJ+f91zBDEZYGnOdL4D9krAazw0tfgvaErQHfX8l I99WamFG/RZiqeF9SOsYT+A== X-Google-Smtp-Source: APXvYqzjuXzlJfYmm6OQjWmSFkfZp7p5+/RBKtyuW9GmAw6VaX33RD5pvt2FRSYs/l0C4jzCq+840g== X-Received: by 2002:a17:902:9a03:: with SMTP id v3mr42085296plp.27.1557244789768; Tue, 07 May 2019 08:59:49 -0700 (PDT) Received: from buildserver-90.open-silicon.com ([114.143.65.226]) by smtp.googlemail.com with ESMTPSA id h187sm22543540pfc.52.2019.05.07.08.59.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 May 2019 08:59:49 -0700 (PDT) From: Sagar Shrikant Kadam To: marek.vasut@gmail.com, tudor.ambarus@microchip.com, dwmw2@infradead.org, computersforpeace@gmail.com, bbrezillon@kernel.org, richard@nod.at, palmer@sifive.com, aou@eecs.berkeley.edu, paul.walmsley@sifive.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v3 v3 1/3] mtd: spi-nor: add support for is25wp256 Date: Tue, 7 May 2019 21:29:33 +0530 Message-Id: <1557244775-14206-1-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190507_085951_038661_BA1F6753 X-CRM114-Status: GOOD ( 12.39 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sagar Shrikant Kadam Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Update spi_nor_id table for is25wp256 (32MB)device from ISSI, present on HiFive Unleashed dev board (Rev: A00). Set method to enable quad mode for ISSI device in flash parameters table. Based on code originally written by Wesley Terpstra and/or Palmer Dabbelt https://github.com/riscv/riscv-linux/commit/c94e267766d62bc9a669611c3d0c8ed5ea26569b Signed-off-by: Sagar Shrikant Kadam --- drivers/mtd/spi-nor/spi-nor.c | 10 +++++++++- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index fae1474..c5408ed 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1834,6 +1834,10 @@ static int sr2_bit7_quad_enable(struct spi_nor *nor) SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, { "is25wp128", INFO(0x9d7018, 0, 64 * 1024, 256, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, + { "is25wp256", INFO(0x9d7019, 0, 64 * 1024, 1024, + SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | + SPI_NOR_4B_OPCODES) + }, /* Macronix */ { "mx25l512e", INFO(0xc22010, 0, 64 * 1024, 1, SECT_4K) }, @@ -3650,6 +3654,10 @@ static int spi_nor_init_params(struct spi_nor *nor, case SNOR_MFR_MACRONIX: params->quad_enable = macronix_quad_enable; break; + case SNOR_MFR_ISSI: + params->quad_enable = macronix_quad_enable; + break; + case SNOR_MFR_ST: case SNOR_MFR_MICRON: @@ -4127,7 +4135,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (ret) return ret; - if (nor->addr_width) { + if (nor->addr_width && JEDEC_MFR(info) != SNOR_MFR_ISSI) { /* already configured from SFDP */ } else if (info->addr_width) { nor->addr_width = info->addr_width; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index b3d360b..ff13297 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -19,6 +19,7 @@ #define SNOR_MFR_ATMEL CFI_MFR_ATMEL #define SNOR_MFR_GIGADEVICE 0xc8 #define SNOR_MFR_INTEL CFI_MFR_INTEL +#define SNOR_MFR_ISSI 0x9d /* ISSI */ #define SNOR_MFR_ST CFI_MFR_ST /* ST Micro */ #define SNOR_MFR_MICRON CFI_MFR_MICRON /* Micron */ #define SNOR_MFR_MACRONIX CFI_MFR_MACRONIX From patchwork Tue May 7 15:59:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagar Shrikant Kadam X-Patchwork-Id: 10933203 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 905691390 for ; Tue, 7 May 2019 16:00:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EBAD289DC for ; Tue, 7 May 2019 16:00:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CB1D28A27; Tue, 7 May 2019 16:00:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 02012289DC for ; Tue, 7 May 2019 16:00:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date: Subject:To:From:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=P/dblxIVFG7TiAvjC1r/s6v0wZIaYYCUvWqZg288hxU=; b=TBoZY3kX2eNiyU mNtXt8OrBoI4e653PClU+cueCTlkzCEIjU0U9klzrYCm41Gpume8rRqXAL+ixYr+camhd7+W/1qUf xcfFOozrIRplc0ZEJlmKSsMcstDlE4TXy1przX/rKyUTNOGwlCkhHzkUCPmW23pMEXSEKCk66l6Ga NONwd8vd1L1aQHiA1J1ljOvJ8XxP4nolWZyprrn5QZ1xl+VjOzjcYFrWIj3G/mQvfAKPtDp2oBhCW ewof1vCO34PiUg+X/NN9Ny39O7GWkXj5O7hpL+pYwNciRSEGmPC/cyaYV9FhPIZ0C+vPqupBx8M7g PMTSqG1uKC86d3F5tC4Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hO2WQ-0001ix-3Q; Tue, 07 May 2019 16:00:50 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hO2WH-0001aT-Mp for linux-riscv@lists.infradead.org; Tue, 07 May 2019 16:00:43 +0000 Received: by mail-pf1-x443.google.com with SMTP id 13so8576248pfw.9 for ; Tue, 07 May 2019 09:00:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4KM0y+VsDRDq1QBsQrOgSVGYr46K10+xwnmF6uVSq4g=; b=NU62BZrN5KCzZX1XVTU3IVHwSAdjJbIyQg4VeugCYGDvtd77Z/gP3F4OUlaR4krlgS o+11XHW0v8kPcVAoScYskKkc+MjQrl0vsScZ73N6pvEcuj8HxFgNDRBLxty7GmXNCwfq 2iJ8x42frxfAT8uV/B3a5kp5QFVhV+yA1MPi+rCejY8Mv1n6HKeW5WkxwkKgtLSEr3Ht mZdGBeuU7a4fbOhLaT5GfGypqZhijSaNbl7f1rYq3I4zNRW4GAnH8lusIdUETxOPJocw 4BHGlYCozYX+kT2gE4i7Kjf/HUnwn+Elr89RC531EOnyNxGdbBN9hT/I85OAyDkqj6wi 5nBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references; bh=4KM0y+VsDRDq1QBsQrOgSVGYr46K10+xwnmF6uVSq4g=; b=oeiBk/5V8oM9IsSwqgL1qe7N1HFLNUZkDYlXCwvTvp6MPSZY07B4H/7yT/d6zavNYz aqxpGCovFAJmkBsIRsPYFj30dn6kxTIkEnaA/E6IIPqd6vilBENARqPhSjHROYg+z1Py eXCQdIo+P0kp2E4MFLjGo/UD5F/Q0ZeGJGgyDBXvYQ08tqmP28Y4ghBjnJRvpgUruWEr GwASkh4g0x+1xhwVySZAo3IaH9kA3kriZELgzV7xWnoJ4I3Ut32oSJRNS3/RXupylA7L jyfKXaQG9wqYLPtf6oZl3OsrVoJYBFcqUiGYEQl44B8Ze033Kk2j8dw9a/jHINPHSZ1w Sc8g== MIME-Version: 1.0 X-Gm-Message-State: APjAAAUQHBreP5tqcar0j8vO3tCr8j9FwjAbGbnPC/Jcam0clT97iW6t P7x2p3Mz21UM7NB+1mM0pguqAu+xGdcQk1DvjMPlpfhveBa/b1MddDJd9rydtU1kaSgF8W9uqkY cXUMvb2yuNHI+HUg09Szu+g== X-Google-Smtp-Source: APXvYqxPnAEc2G3zRVZf6L/0Kdp2TrKypPq94MbRDW4FheSYN1WrKPt1O7GwwpXDKr3U6SEFcuigZw== X-Received: by 2002:a63:3e47:: with SMTP id l68mr40030636pga.85.1557244840952; Tue, 07 May 2019 09:00:40 -0700 (PDT) Received: from buildserver-90.open-silicon.com ([114.143.65.226]) by smtp.googlemail.com with ESMTPSA id h187sm22543540pfc.52.2019.05.07.09.00.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 May 2019 09:00:40 -0700 (PDT) From: Sagar Shrikant Kadam To: marek.vasut@gmail.com, tudor.ambarus@microchip.com, dwmw2@infradead.org, computersforpeace@gmail.com, bbrezillon@kernel.org, richard@nod.at, palmer@sifive.com, aou@eecs.berkeley.edu, paul.walmsley@sifive.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v3 v3 2/3] mtd: spi-nor: add support to unlock flash device. Date: Tue, 7 May 2019 21:29:34 +0530 Message-Id: <1557244775-14206-2-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1557244775-14206-1-git-send-email-sagar.kadam@sifive.com> References: <1557244775-14206-1-git-send-email-sagar.kadam@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190507_090041_742171_69E58ECF X-CRM114-Status: GOOD ( 16.55 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sagar Shrikant Kadam Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Nor device (is25wp256 mounted on HiFive unleashed Rev A00 board) from ISSI have memory blocks guarded by block protection bits BP[0,1,2,3]. Clearing block protection bits,unlocks the flash memory regions The unlock scheme is registered during nor scans. Based on code developed by Wesley Terpstra and/or Palmer Dabbelt . https://github.com/riscv/riscv-linux/commit/c94e267766d62bc9a669611c3d0c8ed5ea26569b Signed-off-by: Sagar Shrikant Kadam --- drivers/mtd/spi-nor/spi-nor.c | 51 ++++++++++++++++++++++++++++++++++++++++++- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index c5408ed..3942b26 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1461,6 +1461,49 @@ static int macronix_quad_enable(struct spi_nor *nor) } /** + * issi_unlock() - clear BP[0123] write-protection. + * @nor: pointer to a 'struct spi_nor'. + * @ofs: offset from which to unlock memory. + * @len: number of bytes to unlock. + * + * Bits [2345] of the Status Register are BP[0123]. + * ISSI chips use a different block protection scheme than other chips. + * Just disable the write-protect unilaterally. + * + * Return: 0 on success, -errno otherwise. + */ +static int issi_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len) +{ + int ret, val; + u8 mask = SR_BP0 | SR_BP1 | SR_BP2 | SR_BP3; + + val = read_sr(nor); + if (val < 0) + return val; + if (!(val & mask)) + return 0; + + write_enable(nor); + + write_sr(nor, val & ~mask); + + ret = spi_nor_wait_till_ready(nor); + if (ret) + return ret; + + ret = read_sr(nor); + if (ret > 0 && !(ret & mask)) { + dev_info(nor->dev, + "ISSI Block Protection Bits cleared SR=0x%x", ret); + ret = 0; + } else { + dev_err(nor->dev, "ISSI Block Protection Bits not cleared\n"); + ret = -EINVAL; + } + return ret; +} + +/** * spansion_quad_enable() - set QE bit in Configuraiton Register. * @nor: pointer to a 'struct spi_nor' * @@ -1836,7 +1879,7 @@ static int sr2_bit7_quad_enable(struct spi_nor *nor) SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, { "is25wp256", INFO(0x9d7019, 0, 64 * 1024, 1024, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | - SPI_NOR_4B_OPCODES) + SPI_NOR_4B_OPCODES | SPI_NOR_HAS_LOCK) }, /* Macronix */ @@ -4078,6 +4121,12 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->flash_is_locked = stm_is_locked; } + /* NOR protection support for ISSI chips */ + if (JEDEC_MFR(info) == SNOR_MFR_ISSI || + info->flags & SPI_NOR_HAS_LOCK) { + nor->flash_unlock = issi_unlock; + + } if (nor->flash_lock && nor->flash_unlock && nor->flash_is_locked) { mtd->_lock = spi_nor_lock; mtd->_unlock = spi_nor_unlock; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index ff13297..9a7d719 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -127,6 +127,7 @@ #define SR_BP0 BIT(2) /* Block protect 0 */ #define SR_BP1 BIT(3) /* Block protect 1 */ #define SR_BP2 BIT(4) /* Block protect 2 */ +#define SR_BP3 BIT(5) /* Block protect 3 for ISSI device*/ #define SR_TB BIT(5) /* Top/Bottom protect */ #define SR_SRWD BIT(7) /* SR write protect */ /* Spansion/Cypress specific status bits */ From patchwork Tue May 7 15:59:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagar Shrikant Kadam X-Patchwork-Id: 10933205 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 586DC112C for ; Tue, 7 May 2019 16:02:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 492B528965 for ; Tue, 7 May 2019 16:02:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D559289BC; Tue, 7 May 2019 16:02:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CA75C28965 for ; Tue, 7 May 2019 16:02:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date: Subject:To:From:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tCNj75i3pCOHghhoxouSYf0u2E2OjY8e+3Tn3hyRBqg=; b=pNn162RhXWvOZr DMvq9fD2BfuAIDg70LLUCZFmgX3BuwBSjgfHsW6WI9IY7Ix+aCuyrOCuCxT3tle5BLQkaf4cJ5mGf heOJYtIvLf7jYFGSHRDMUmV/3wEsrT0hA3FHsPU1s/Z+XisVyz8hHHeBrYmJNeGCJ0njL9Ll+0NK1 U2F4dvBuN7KnB96lxQuL2f/UyWsSvr3k+rAXj9sKnwO8VBITZYt4faLDI5l3QEFwSFf0aWrbxarg6 pqdotl50ubZkmge1+iIouUlvIJQ0U4EnZfpYslsD+RpdLEob/IcRPwMoOdpRxTFzGrn2W8+sS7W/T 9GH2yawpiAi/UfNfIgPg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hO2Xz-0001vw-Nm; Tue, 07 May 2019 16:02:27 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hO2Xw-0001vG-E1 for linux-riscv@lists.infradead.org; Tue, 07 May 2019 16:02:25 +0000 Received: by mail-pf1-x442.google.com with SMTP id c6so3684280pfa.10 for ; Tue, 07 May 2019 09:02:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references; bh=oVg9jhszQTOKPX1D60R98eWmwxuEwcGgeC32BmiCC7A=; b=jCllPuGG8CrK7CTMwCkPKJYL8zWr7vbjz1mIx6XznvK5UfqWJ+oGbQwQ7BrGMxrZdR EMskKWRZWvyoLeA0ZHjTBMw4Ezwyb1li4pFRfnJNzc3Rw9lHnZZMQvT1n72ndA34inD5 rK36vY68JHuoh3mG4Sjo9j1fYBLFwhTB9bvgtVqA/n8zqeMcKFi/esIQxprmjjyg69k1 FLWWsD5XNk2baGjknlh6l96sRSsJ6GTQ8vcfyT/vtJmprBC5zB7GeMn8woGr3+NCdJcf 8rQnyVPK1SqZh42lawjJFYBpMOnwDMNmxamehqpzlhUInJWqRqO9lfzmUA+dTY0AeWKg M5Xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references; bh=oVg9jhszQTOKPX1D60R98eWmwxuEwcGgeC32BmiCC7A=; b=FV30LGRY31MT2vxDx0HtfVy29qSi7qt+o4RSmBqGJSISI38hGqL4mJ1yZS/yDfzFfY ee7C9htnusu4Yv6YXlbT2Tj6XcRUcGwDbbier4ywkP3vHFJifAnoQ83UaMuc+Tb6Cw6S R75xX57sdtEEmGc3DXNG4IlamEBphMmhCXXnQUDi4tvEz5VcerH4tKNYCyX9jD1o/d8k q9/hdotiJc4Bk0an/Z2RMqRWQqcjTT5ai1Yxnp5SRG/TWkW02jMK6TFMCp45a9gaJ+Jk nI0XQ0kCRhEogsy0wtfJ8Zvs/iEagMAnnHv03iYig0HDs9HmiIi0Gz/07YyjrnjsRQ52 2pgg== MIME-Version: 1.0 X-Gm-Message-State: APjAAAUHgPKYp0FzANpL98UUWsbfBLnQ/MxJyW6OwryKjFg12kBs7+ND F5kpXGkYfycspmxy9XzhfNhgaZS1Nkeb5YI3o2O7RZc6mDWVtu5zsFDPzQDdbC7CHKurE5zAbOL le41B+anvs2toJjsC5P3tjQ== X-Google-Smtp-Source: APXvYqxvTAzllwIFd/OziGSwstlA9MxwXjvNPS8YISEepDqnYpycNRekLcN8eZHCxxqH0o+kb7b26Q== X-Received: by 2002:a63:1cf:: with SMTP id 198mr32137329pgb.155.1557244943756; Tue, 07 May 2019 09:02:23 -0700 (PDT) Received: from buildserver-90.open-silicon.com ([114.143.65.226]) by smtp.googlemail.com with ESMTPSA id h187sm22543540pfc.52.2019.05.07.09.02.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 07 May 2019 09:02:22 -0700 (PDT) From: Sagar Shrikant Kadam To: marek.vasut@gmail.com, tudor.ambarus@microchip.com, dwmw2@infradead.org, computersforpeace@gmail.com, bbrezillon@kernel.org, richard@nod.at, palmer@sifive.com, aou@eecs.berkeley.edu, paul.walmsley@sifive.com, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: [PATCH v3 v3 3/3] mtd: spi-nor: add locking support for is25xxxxx device Date: Tue, 7 May 2019 21:29:35 +0530 Message-Id: <1557244775-14206-3-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1557244775-14206-1-git-send-email-sagar.kadam@sifive.com> References: <1557244775-14206-1-git-send-email-sagar.kadam@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190507_090224_477416_6CA0A51B X-CRM114-Status: GOOD ( 14.92 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sagar Shrikant Kadam Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Implement a basic locking scheme for ISSI devices similar to that of stm_lock mechanism. The is25xxxxx devices have 4 bits for selecting the range of blocks to be locked/protected from erase/write. The current implementation enables block protection as per the table defined into datasheet for is25wp256d device. Signed-off-by: Sagar Shrikant Kadam --- drivers/mtd/spi-nor/spi-nor.c | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 3942b26..5986260 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1459,6 +1459,56 @@ static int macronix_quad_enable(struct spi_nor *nor) return 0; } +/** + * issi_lock() - set BP[0123] write-protection. + * @nor: pointer to a 'struct spi_nor'. + * @ofs: offset from which to lock memory. + * @len: number of bytes to unlock. + * + * Lock a region of the flash.Implementation is based on stm_lock + * Supports the block protection bits BP{0,1,2,3} in the status register + * + * Return: 0 on success, -errno otherwise. + */ +static int issi_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) +{ + int status_old, status_new, blk_prot; + u8 mask = SR_BP3 | SR_BP2 | SR_BP1 | SR_BP0; + u8 shift = ffs(mask) - 1; + u8 pow; + loff_t num_blks; + + status_old = read_sr(nor); + + /* if status reg is Write protected don't update bit protection */ + if (status_old & SR_SRWD) { + dev_err(nor->dev, + "Status register is Write Protected, can't lock bit + protection bits...\n"); + return -EINVAL; + } + num_blks = len / nor->info->sector_size; + + pow = order_base_2(num_blks); + + blk_prot = mask & (((pow+1) & 0xf)<> shift) & 0x0f) > blk_prot) { + dev_info(nor->dev, "newly requested blocks are + already protected "); + return 0; + } + + status_new = status_old | blk_prot; + + if (status_old == status_new) + return 0; + + return write_sr_and_check(nor, status_new, mask); +} /** * issi_unlock() - clear BP[0123] write-protection. @@ -4124,6 +4174,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, /* NOR protection support for ISSI chips */ if (JEDEC_MFR(info) == SNOR_MFR_ISSI || info->flags & SPI_NOR_HAS_LOCK) { + nor->flash_lock = issi_lock; nor->flash_unlock = issi_unlock; }