From patchwork Tue Jul 2 18:39:02 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: 11028531 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 E8893112C for ; Tue, 2 Jul 2019 18:40:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF59628678 for ; Tue, 2 Jul 2019 18:40:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2F2B2883A; Tue, 2 Jul 2019 18:40:44 +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 6C5D1288F8 for ; Tue, 2 Jul 2019 18:40:44 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=36PUPNbl6dmFkd/7RyDbcxbNWvVwr4TdoDzVyD2liRw=; b=nFu2XViuy5Hl4+jbBu08moHpOV 1zIyplykU3R3LhvLqSFRWGC5e9j624L0XF9qLQMGw/IJ4n+5HqgFOFEc2WiO05MZYbasCafbzQlpS vFGRfi22Dv+F2uWIUTJYim/QJnCyUmUzhEsFIRtpsAZu8AaXZSIEIgJLRYncFTVw6DguEUp4IDgnG c823jMr5PMeBtVM+8Y+yCri1pya8kufQxCNlCMHUwmbKMsN2kcDCpclriazkc0+vV8SbgTcphsM5a PU/PRt+WeZ6KLB8FHYpKJkrC3Q5sir8bHNXcqgI0NJi/m6ESR52kTYlzK/ldeo9Dtf3LrUh/jMU/0 HQVsu7fA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hiNho-0004IG-4Y; Tue, 02 Jul 2019 18:40:40 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hiNhQ-0003g9-5Z for linux-riscv@lists.infradead.org; Tue, 02 Jul 2019 18:40:18 +0000 Received: by mail-pf1-x444.google.com with SMTP id r1so8681705pfq.12 for ; Tue, 02 Jul 2019 11:40:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Y+CmxvfTHNmkdcHZerrxb2wPdBc38Gq6FdKZioHxbqE=; b=kP2+RMySSYi0s9bLP+JPIjdlGB7GP0IyPMEzIP3Nw8BtM33CdAP+p6Xn577lTaKdlp V+w3kPeb5i+UGKJakJaQOQVeum5kY/mqq6YHOduVMyUHDmWPutdGc233cDaOEIVLqvfP 7rqMmNJlpWAzrndk+vQFCzTnq/8RJ1BWWLOR6qdg5VOAK7H//4nxXEYWAzm8ya9l2TxX HC2zk1EAPyr93XGjNK/kAyFGXQYgubDB5b6TZ5Z3U1fXC/ygMrr6LgOA0DoIrxaw0NmS eU9yK8CmXKmxzJ26PaclixrkwaWWf8W0UdGbk3wJXKRICVUR2zQqDB2OwmCXDVkGQ/ip XvDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Y+CmxvfTHNmkdcHZerrxb2wPdBc38Gq6FdKZioHxbqE=; b=Gm6pdY0ty0+NekAup0Ky4Ad3WjuVO4OSLjuDKGiSVs03SlTwwjEfWkexHj+/qlSPLF jvULmLLkNSmjfZ7JU9q8HuGiSI39taQrQQoFIFOUVmHRAOptFGULK2oP2trDO4FggiyB Ho/OLKzkIsz6OFoMFVlKFFBgySjT+HqeFLaePH3iojSPKJKcujjwWzSPeCn8DaDjK4kE sholjNq03c72RrrmXqxyIWKS5kRb7W5k/4vUHVZHR99PPS0mOezgP9ARdiWET1vHr5bE 9Z5adPiS8oVLCRshXoI063c5nzKRL6Qt9Dcx3OvEJc93GICVdx5z43QODOywY5aqVXHe lYuQ== X-Gm-Message-State: APjAAAVrYZ6Um2Xd4Y+EGFLPCiXqfa29XRP9U+5tOLzAC5rCBvgy1NVD nxnrEuaP4eZ2N87XJ1hXLer/aA== X-Google-Smtp-Source: APXvYqwGMFL+2bJhWMoeLMIUPikC9EIj+4FMNu3+vEguV2Ru2oTeOyZJqNVCOTuD3VLHeGb+B2sKMg== X-Received: by 2002:a63:dc50:: with SMTP id f16mr32511540pgj.447.1562092811827; Tue, 02 Jul 2019 11:40:11 -0700 (PDT) Received: from buildserver-90.open-silicon.com ([114.143.65.226]) by smtp.googlemail.com with ESMTPSA id e10sm15065327pfi.173.2019.07.02.11.40.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jul 2019 11:40:11 -0700 (PDT) From: Sagar Shrikant Kadam To: marek.vasut@gmail.com, tudor.ambarus@microchip.com, dwmw2@infradead.org, computersforpeace@gmail.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com Subject: [PATCH v7 1/4] mtd: spi-nor: add support for is25wp256 Date: Wed, 3 Jul 2019 00:09:02 +0530 Message-Id: <1562092745-11541-2-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1562092745-11541-1-git-send-email-sagar.kadam@sifive.com> References: <1562092745-11541-1-git-send-email-sagar.kadam@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190702_114016_226684_F55B64B6 X-CRM114-Status: GOOD ( 12.02 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aou@eecs.berkeley.edu, palmer@sifive.com, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Sagar Shrikant Kadam , paul.walmsley@sifive.com, linux-riscv@lists.infradead.org MIME-Version: 1.0 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 Reviewed-by: Vignesh Raghavendra --- drivers/mtd/spi-nor/spi-nor.c | 9 ++++++++- include/linux/mtd/spi-nor.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index e3a28c0..971f0f3 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1857,7 +1857,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) }, { "mx25l2005a", INFO(0xc22012, 0, 64 * 1024, 4, SECT_4K) }, @@ -3687,6 +3690,10 @@ static int spi_nor_init_params(struct spi_nor *nor, case SNOR_MFR_ST: case SNOR_MFR_MICRON: break; + case SNOR_MFR_ISSI: + params->quad_enable = macronix_quad_enable; + break; + default: /* Kept only for backward compatibility purpose. */ diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index b3d360b..b0e42b3 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -21,6 +21,7 @@ #define SNOR_MFR_INTEL CFI_MFR_INTEL #define SNOR_MFR_ST CFI_MFR_ST /* ST Micro */ #define SNOR_MFR_MICRON CFI_MFR_MICRON /* Micron */ +#define SNOR_MFR_ISSI 0x9d /* ISSI */ #define SNOR_MFR_MACRONIX CFI_MFR_MACRONIX #define SNOR_MFR_SPANSION CFI_MFR_AMD #define SNOR_MFR_SST CFI_MFR_SST From patchwork Tue Jul 2 18:39:03 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: 11028533 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 179831510 for ; Tue, 2 Jul 2019 18:41:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2ED8286D4 for ; Tue, 2 Jul 2019 18:41:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E6E3C2896A; Tue, 2 Jul 2019 18:41:03 +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 92DDF286D4 for ; Tue, 2 Jul 2019 18:41:03 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Km2i3bIqbiDowXvjb5NiUXepcMRpqSKzWs7AaZeUAFs=; b=nhzYsKRT4qjqDxKQK9glA3helW owVwRuuS4UqwS3q3hb8MQuGncYCAkyykuYiUi7v+Zj0PzIgxVwuKVfztFizWmHPDUQFMkWoqq1Ldf 3Mmwg5zpmR8sxPwHj/xRMdnoMoSOAEsrqj9azwtl87K0LTGD3egRleLGjeBj783dOzYz68GQ/QaSS 41wm3jwAbWFLgpHijg8v4nQUONT5P4N93wX2vWWVkJf0ON18BD6/SZprMrFj3+Tht11n+EPaMLnkj 2CQP7KgcY73RxHEFnn4WnTOiU5US9TeVG3JrX2wlmWkdGVQcb0zqs51cqE6q3YG1u4uXsn2MhT3mE uHYF9M4Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hiNi7-0004Zn-Qj; Tue, 02 Jul 2019 18:41:00 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hiNhS-0003nP-FJ for linux-riscv@lists.infradead.org; Tue, 02 Jul 2019 18:40:19 +0000 Received: by mail-pf1-x444.google.com with SMTP id d126so8694322pfd.2 for ; Tue, 02 Jul 2019 11:40:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0sF1tajbszgBkWrij+qh2Snun7Hdtkh6IqSmd5cLEoI=; b=DtHMYn33VMItS9Mqb2A54QLPgAHX3jNXlN2eS6J91/O6uY1z5UrJtJLI0XK57V19bz ndWySJwRfhNNtwkOkV5slrphsfMsZDy9Ei8txwVJgxuU60vPZIrno2FdLdyFXDLNcE6E 5N6i/WXXz/+a37iqGWmZFlMhdyuWuV43td52R4cIU2sNVxvvg35pGctcBOI6Vpu4nZRb c9QBstZskl4Uu34b8ec+cRPQod7wIw9rN5xvDbD6o13VJ1ssJBLUUelzdmj9qc0wOOK3 f7SpWpXVUGyQuWX/0bw/cpN/xiuYaC0qTsm/sPgKvO0jueJtIhCE9W/pr28seC2qlEId kfNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=0sF1tajbszgBkWrij+qh2Snun7Hdtkh6IqSmd5cLEoI=; b=XvMrLr/0gjP8l1Dh5FDogpyVTGJ4sYYH6diT5hCMFFs4Lm063B0H9C7kYvktfQkUxJ WbOKL3nT+CjeTgE7ggcrp/bRtgZ48tZq14Xh8xHteaJU6YufEZD3NMMoFH1gbow2wFHW Mes3RsN7G+HqpXHr1IY1Lqp8gUx/GH634CHr4cQvey/iAMsuikWI+SosWF8tk5cyNlKe iyVvqQqM3NjUvBfmApa0LyJEjaBp2PkiMOxO9eIAdUA6CxVee40hVa/taNwMGLgz22fp +ni4JHc5+eCf6ZFMxWLVKY+F0OmDbwaZIEpvkPeZLZWPxO0NbKFDSUPR/hH1wQu45POE 7aHQ== X-Gm-Message-State: APjAAAUzxG+ML/sS2UFw5d8JXw2xxtaibUNTbeymHrom+UyKXZrenA+F 5f3znZCWzF/9u7AFZVBGMHzzyA== X-Google-Smtp-Source: APXvYqzBLTVQUac6Xd9mE/tyVVz8vJIhTDTtyInPwU1KgqLrBTp0CAZs3Cu/UvLMDc9hMl7J+7xLzQ== X-Received: by 2002:a63:610e:: with SMTP id v14mr32174956pgb.221.1562092818008; Tue, 02 Jul 2019 11:40:18 -0700 (PDT) Received: from buildserver-90.open-silicon.com ([114.143.65.226]) by smtp.googlemail.com with ESMTPSA id e10sm15065327pfi.173.2019.07.02.11.40.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jul 2019 11:40:17 -0700 (PDT) From: Sagar Shrikant Kadam To: marek.vasut@gmail.com, tudor.ambarus@microchip.com, dwmw2@infradead.org, computersforpeace@gmail.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com Subject: [PATCH v7 2/4] mtd: spi-nor: fix nor->addr_width for is25wp256 Date: Wed, 3 Jul 2019 00:09:03 +0530 Message-Id: <1562092745-11541-3-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1562092745-11541-1-git-send-email-sagar.kadam@sifive.com> References: <1562092745-11541-1-git-send-email-sagar.kadam@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190702_114018_595779_BD4495E3 X-CRM114-Status: GOOD ( 11.76 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aou@eecs.berkeley.edu, palmer@sifive.com, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Sagar Shrikant Kadam , paul.walmsley@sifive.com, linux-riscv@lists.infradead.org MIME-Version: 1.0 Sender: "linux-riscv" Errors-To: linux-riscv-bounces+patchwork-linux-riscv=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Use the post bfpt fixup hook for the is25wp256 device as done for is25lp256 device to overwrite the address width advertised by BFPT. For instance the standard devices eg: IS25WP256D-JMLE where J stands for "standard" does not support SFDP. Signed-off-by: Sagar Shrikant Kadam Reviewed-by: Vignesh Raghavendra --- drivers/mtd/spi-nor/spi-nor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 971f0f3..315eeec 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1860,7 +1860,7 @@ static int sr2_bit7_quad_enable(struct spi_nor *nor) { "is25wp256", INFO(0x9d7019, 0, 64 * 1024, 1024, SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ | SPI_NOR_4B_OPCODES) - }, + .fixups = &is25lp256_fixups }, /* Macronix */ { "mx25l512e", INFO(0xc22010, 0, 64 * 1024, 1, SECT_4K) }, { "mx25l2005a", INFO(0xc22012, 0, 64 * 1024, 4, SECT_4K) }, From patchwork Tue Jul 2 18:39:04 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: 11028535 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 4AB94112C for ; Tue, 2 Jul 2019 18:41:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 321642867C for ; Tue, 2 Jul 2019 18:41:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2587B28979; Tue, 2 Jul 2019 18:41:23 +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 93F592867C for ; Tue, 2 Jul 2019 18:41:22 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=B+2PvCUc13byEwpzzd3njEmklKZeJP8eQdm93+Yov3A=; b=VYJte+6Wm86foXURZlQjLdTwyz zN8Epi4gXQretdwZIwc3VXCStkVOGDJ/REJGJns6Iu4Q6HK/sv6M5kVo6b6S3wQPSER6SxcuXfvNU haSTxt6J7dDOf9cp58yTcujnibPOUwLcd28bcqfSCLKCv3Vj4kKtWtk6cz39usoB+2GYi7hrp+vRk +t+CxA1sOY2NZK65Av+gbrz8PB477LK0yK5TXy47MdGvSRKBCyHLsjyiBBHLKLKrdj02va6AGh+N3 MH8L2zwiYnCiXTLRqBLEq5cZyRZ/RKzpchPSPM+k6Kb5ILnyq6YjqY5272qj9Je6iRmGSTPtxj8VO F1hfX2KQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hiNiQ-0004qU-Ln; Tue, 02 Jul 2019 18:41:18 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hiNhY-0003yo-P9 for linux-riscv@lists.infradead.org; Tue, 02 Jul 2019 18:40:27 +0000 Received: by mail-pf1-x444.google.com with SMTP id p184so8686684pfp.7 for ; Tue, 02 Jul 2019 11:40:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=HLwmzLi1yfKWX7bsvh9XjKbOb6xGSrI3n8VIDgMLyvM=; b=DhIW6pr0vFkNlDLyEZAN6uefpAl5PITwPdIKPacB4h2bOS6eUWkq5WYjyfo1gfJZb8 FNN46uUqM6JBsXb5907IBastGSfKZzbIfgs5CX2EInHtZnLurHEzdreJSz0R4rFRkaHI 6ZDH/R7PlUPzLjfhcRHmIYEz9EXHa/Pw632YYrZPNL3TB0PVvVI3Wr71FQKG1t+ppWwY ulSiEtqANx53KjSAPAoEzBvrSht9UKTzXBJgmJ+P+A6fCx44uYyAKMZbSrIXUNZ6NRRl JZQRIYR5WDD1SJSXJibVV1bh3rO3qg8U6wJDChIeVrI1s/BllN1JwYmZbUo9bRbRRp7C oDpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=HLwmzLi1yfKWX7bsvh9XjKbOb6xGSrI3n8VIDgMLyvM=; b=APLFnmG8ZCyMuiS4SJ4B14y6UIS5/vW0DM7EGhbuNSDCoVo5pxmG080tPNEuvUNnue 6tLeF0RQtih4RU31LMbGy7oP0B+6BIs6nX2XF3BNZGmh65gsX6l+z3WAmvswTgOfK3pO K2PTItKC91edTUCsjQM+vCIyGQ9aH01AvMg8DdPOB0N4lTwbh8uiXONLR8AksGArO98T i9VQbGWellTRg54cD0HJ88u48/Hh5mnW3WbKqkUJPzo5/rayGZPorvDOK/4KCi7Ky0Tq lhkud8hNGXI78A8dpMoPYd1IijAr/Zixk7rM7JbBfkd+gZKs3lwgkOUi2j4iylAx5RUX TyLA== X-Gm-Message-State: APjAAAVPWfdiH4+nL25oMwNmtC0ollvm3QVAhHdaV6tvsUuGQCNuqvaP OzPmGdXS2aX3HcgIacnOK20/2A== X-Google-Smtp-Source: APXvYqw0SDghowWJigY8inIjqR03Te8MELhI4tmCPOYVFG2+hjsLypcXBgsFvLL9Lp0iyasIniV3QQ== X-Received: by 2002:a17:90a:77c5:: with SMTP id e5mr6978722pjs.109.1562092824249; Tue, 02 Jul 2019 11:40:24 -0700 (PDT) Received: from buildserver-90.open-silicon.com ([114.143.65.226]) by smtp.googlemail.com with ESMTPSA id e10sm15065327pfi.173.2019.07.02.11.40.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jul 2019 11:40:23 -0700 (PDT) From: Sagar Shrikant Kadam To: marek.vasut@gmail.com, tudor.ambarus@microchip.com, dwmw2@infradead.org, computersforpeace@gmail.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com Subject: [PATCH v7 3/4] mtd: spi-nor: add support to unlock the flash device Date: Wed, 3 Jul 2019 00:09:04 +0530 Message-Id: <1562092745-11541-4-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1562092745-11541-1-git-send-email-sagar.kadam@sifive.com> References: <1562092745-11541-1-git-send-email-sagar.kadam@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190702_114024_901764_04224505 X-CRM114-Status: GOOD ( 17.99 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aou@eecs.berkeley.edu, palmer@sifive.com, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Sagar Shrikant Kadam , paul.walmsley@sifive.com, linux-riscv@lists.infradead.org MIME-Version: 1.0 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]. Add an identifier within the flash info structure to indicate that a particular flash device has the fourth block protect bit (SPI_NOR_HAS_BP3). Increase size of flash_info flags from u16 to u32 to avoid flag overflow due SPI_NOR_HAS_BP3. Clear block protection bits unlocks the flash memory regions. Based on code developed by Wesley Terpstra and/or Palmer Dabbelt . https://github.com/riscv/riscv-linux/commit/c94e267766d62bc9a669611c3d0c8ed5ea26569b spell correction: "Configuration" in spansion_quad_enable function description. Signed-off-by: Sagar Shrikant Kadam --- drivers/mtd/spi-nor/spi-nor.c | 72 ++++++++++++++++++++++++++++++++++++++++--- include/linux/mtd/spi-nor.h | 2 ++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 315eeec..4ed241d 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -250,7 +250,7 @@ struct flash_info { u16 page_size; u16 addr_width; - u16 flags; + u32 flags; #define SECT_4K BIT(0) /* SPINOR_OP_BE_4K works uniformly */ #define SPI_NOR_NO_ERASE BIT(1) /* No erase command needed */ #define SST_WRITE BIT(2) /* use SST byte programming */ @@ -279,6 +279,13 @@ struct flash_info { #define SPI_NOR_SKIP_SFDP BIT(13) /* Skip parsing of SFDP tables */ #define USE_CLSR BIT(14) /* use CLSR command */ #define SPI_NOR_OCTAL_READ BIT(15) /* Flash supports Octal Read */ +#define SPI_NOR_HAS_BP3 BIT(16) /* + * Flash SR has block protect bits + * for lock/unlock purpose, few support + * BP0-BP2 while few support BP0-BP3. + * This flag identifies devices that + * support BP3 bit. + */ /* Part specific fixup hooks. */ const struct spi_nor_fixups *fixups; @@ -1461,7 +1468,55 @@ static int macronix_quad_enable(struct spi_nor *nor) } /** - * spansion_quad_enable() - set QE bit in Configuraiton Register. + * 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; + + if (nor->flags & SNOR_F_HAS_BP3) + mask = SR_BP3 | SR_BP2 | SR_BP1 | SR_BP0; + else + mask = SR_BP2 | SR_BP1 | SR_BP0; + + 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 protect bits cleared SR: 0x%x\n", + ret); + ret = 0; + } else { + dev_err(nor->dev, "ISSI block protect bits not cleared\n"); + ret = -EINVAL; + } + return ret; +} + +/** + * spansion_quad_enable() - set QE bit in Configuration Register. * @nor: pointer to a 'struct spi_nor' * * Set the Quad Enable (QE) bit in the Configuration Register. @@ -1859,8 +1914,10 @@ 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) - .fixups = &is25lp256_fixups }, + SPI_NOR_4B_OPCODES | SPI_NOR_HAS_LOCK | SPI_NOR_HAS_TB | + SPI_NOR_HAS_BP3) + .fixups = &is25lp256_fixups + }, /* Macronix */ { "mx25l512e", INFO(0xc22010, 0, 64 * 1024, 1, SECT_4K) }, { "mx25l2005a", INFO(0xc22012, 0, 64 * 1024, 4, SECT_4K) }, @@ -4110,6 +4167,13 @@ 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 && + info->flags & SPI_NOR_HAS_BP3) { + 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 b0e42b3..f6fa70f 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 */ #define SR_TB BIT(5) /* Top/Bottom protect */ #define SR_SRWD BIT(7) /* SR write protect */ /* Spansion/Cypress specific status bits */ @@ -244,6 +245,7 @@ enum spi_nor_option_flags { SNOR_F_BROKEN_RESET = BIT(6), SNOR_F_4B_OPCODES = BIT(7), SNOR_F_HAS_4BAIT = BIT(8), + SNOR_F_HAS_BP3 = BIT(9), }; /** From patchwork Tue Jul 2 18:39:05 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: 11028537 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 349EC1510 for ; Tue, 2 Jul 2019 18:41:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B74B2897B for ; Tue, 2 Jul 2019 18:41:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F00C2897C; Tue, 2 Jul 2019 18:41:35 +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 24F8128985 for ; Tue, 2 Jul 2019 18:41:34 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=rdZ59eWX2HhQKnQq52X+2o+QbU58qBJAsj+fhxltWHY=; b=D08QnhfempOxWSfMLWTgiv52WI g6jP9ODiId1/gkBYPm5mqvf04B6YTOS0nPeguXqTAfbj/IE5LNuVktiaE4UnR2Xc9j7tvEqw6jJCx 0ThoND/mbrog6HaqsYTL1dPxWsCUE3QQhEaagFt34Hco4zkGn6B6jVjIt8Q6mlt9o+pr+8e1z6pYk 0cpEqoXAjWStU77Ib0vKR5GLgKuMZJVct8zLeptVY5UgKxlyRbq2j6Fd1dbo0rSBC7trQZJENHzK2 oG3b5Emq1S8waPWzyg6A3irLaAVlonG8YRHaxk6FV9/+tc69rx2vsy2BRCEIRcvBe+TGuUdYo/Ohr Go+OVT0A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hiNic-0004y7-43; Tue, 02 Jul 2019 18:41:30 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hiNhe-00049S-Tc for linux-riscv@lists.infradead.org; Tue, 02 Jul 2019 18:40:33 +0000 Received: by mail-pl1-x643.google.com with SMTP id b7so834967pls.6 for ; Tue, 02 Jul 2019 11:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SHKZ+Dr78ZBjglrjMyozIE7l6kXYnfw/Tzo8w3y20N0=; b=QBuDtgrC2mwIvF5/O5BK3KQHUEiyvhQDjZgxc0hVaG/uIwS17fWsDgukQHxEQFEdG/ oXd0eROGRjTOyCFD1loF9qknq4pSWoT5umVmgRDsi0kLZcZg6Lw0P9Qe8bkQjSbrLvqE gkz2kPltbl2Hb1q6Ws26BXQ8SZTxL9jnQGp7CQqR16VVgBVhXwd2xg3Yge+oV5YzKYtz MVfRkHJXR4apm/LfSD2srrnB8Zi88asK1MxYyJ+oousqNuDHV03fOzygA8s90C6oZdfB oRx85XNYmsyKY68Y+Fg8U0E0jxyYMl1vClubuhTE7Mi0mplnT+8vbj9ZPPDyVUx1bo17 FTBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SHKZ+Dr78ZBjglrjMyozIE7l6kXYnfw/Tzo8w3y20N0=; b=HSvRvrhXBhmxhYi80NWX6/O5ghRBP0Anvea6WcI1icFGifPN3LSfUBVCUqF5ojlXmr 2LWBQaFyhbEB7tN/KyFVla/InihKF/t4TOpYFWccQgm79j+W1KHSOBlRJbole/bKL7tJ /5yvsbK+axqNN8n28yiIAO+/EvCull0mlrDQ/roqCeaLXmny0JrSZv3K1P1m7lG57Tep yit+9pXVQrh7aROwoTbdkQAsptfKxYDE4k0m/KgaWQ7ixJUxbc1H7dnAbEPvdKpMTA9z UUvaaASJpxWPZrl7Hf+shAVBnF+y65Hmed911VA0cZHrw+SYZ7oCG6UcpmJXXCDNMEtL Z7Zw== X-Gm-Message-State: APjAAAUjOr2qHs4kvxEvniNez5MqVq4M3wjBZPNMUtx++dO52Lj7otTy wj4E4abb8M+B1FMrNpx9Y+Yg7Q== X-Google-Smtp-Source: APXvYqyEKlTlCDkC6AYXm5ThpPHjdbK2woGxSlp4pDfcIrFIUsML6hBX5Pwj9rLEXBq5AYCZWq8Grg== X-Received: by 2002:a17:902:ba8e:: with SMTP id k14mr36841380pls.256.1562092830223; Tue, 02 Jul 2019 11:40:30 -0700 (PDT) Received: from buildserver-90.open-silicon.com ([114.143.65.226]) by smtp.googlemail.com with ESMTPSA id e10sm15065327pfi.173.2019.07.02.11.40.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 Jul 2019 11:40:29 -0700 (PDT) From: Sagar Shrikant Kadam To: marek.vasut@gmail.com, tudor.ambarus@microchip.com, dwmw2@infradead.org, computersforpeace@gmail.com, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com Subject: [PATCH v7 4/4] mtd: spi-nor: add locking support for is25wp256 device Date: Wed, 3 Jul 2019 00:09:05 +0530 Message-Id: <1562092745-11541-5-git-send-email-sagar.kadam@sifive.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1562092745-11541-1-git-send-email-sagar.kadam@sifive.com> References: <1562092745-11541-1-git-send-email-sagar.kadam@sifive.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190702_114031_115913_C659718C X-CRM114-Status: GOOD ( 24.57 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: aou@eecs.berkeley.edu, palmer@sifive.com, linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org, Sagar Shrikant Kadam , paul.walmsley@sifive.com, linux-riscv@lists.infradead.org MIME-Version: 1.0 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 locking scheme for ISSI devices based on the stm_lock scheme. The is25wp256 device has 4 bits for selecting the range of blocks to be locked/protected from erase/write operations and function register gives feasibility to select the top / bottom area for protection. Added opcode to read and write function registers. The current implementation enables block protection as per the table defined in the datasheet for the is25wp256 device having erase size of 0x1000. ISSI and stm devices differ in terms of TBS (top/bottom area protection) bits. In case of issi this bit is in Function register and is OTP memory, so once FR bits are programmed cannot be modified. Some common code from stm_lock/unlock implementation is extracted so that it can be re-used for issi devices. The locking scheme has been tested on HiFive Unleashed board Rev A00 having is25wp256 flash memory. Signed-off-by: Sagar Shrikant Kadam --- drivers/mtd/spi-nor/spi-nor.c | 266 ++++++++++++++++++++++++++++++++++-------- include/linux/mtd/spi-nor.h | 5 + 2 files changed, 223 insertions(+), 48 deletions(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index 4ed241d..847a848 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -295,6 +295,29 @@ struct flash_info { #define JEDEC_MFR(info) ((info)->id[0]) +/** + * spi_nor_read_fr() - read function register + * @nor: pointer to a 'struct spi_nor'. + * + * ISSI devices have top/bottom area protection bits selection into function + * reg. The bits in FR are OTP. So once it's written, it cannot be changed. + * + * Return: Value in function register or negative if error. + */ +static int spi_nor_read_fr(struct spi_nor *nor) +{ + int ret; + u8 val; + + ret = nor->read_reg(nor, SPINOR_OP_RDFR, &val, 1); + if (ret < 0) { + pr_err("error %d reading FR\n", ret); + return ret; + } + + return val; +} + /* * Read the status register, returning its value in the location * Return the status register value. @@ -1095,10 +1118,18 @@ static void stm_get_locked_range(struct spi_nor *nor, u8 sr, loff_t *ofs, uint64_t *len) { struct mtd_info *mtd = &nor->mtd; - u8 mask = SR_BP2 | SR_BP1 | SR_BP0; - int shift = ffs(mask) - 1; + u8 mask = 0; + u8 fr = 0; + int shift = 0; int pow; + if (nor->flags & SNOR_F_HAS_BP3) + mask = SR_BP3 | SR_BP2 | SR_BP1 | SR_BP0; + else + mask = SR_BP2 | SR_BP1 | SR_BP0; + + shift = ffs(mask) - 1; + if (!(sr & mask)) { /* No protection */ *ofs = 0; @@ -1106,10 +1137,19 @@ static void stm_get_locked_range(struct spi_nor *nor, u8 sr, loff_t *ofs, } else { pow = ((sr & mask) ^ mask) >> shift; *len = mtd->size >> pow; - if (nor->flags & SNOR_F_HAS_SR_TB && sr & SR_TB) - *ofs = 0; - else - *ofs = mtd->size - *len; + /* ISSI device's have top/bottom select bit in func reg */ + if (JEDEC_MFR(nor->info) == SNOR_MFR_ISSI) { + fr = spi_nor_read_fr(nor); + if (nor->flags & SNOR_F_HAS_SR_TB && fr & FR_TB) + *ofs = 0; + else + *ofs = mtd->size - *len; + } else { + if (nor->flags & SNOR_F_HAS_SR_TB && sr & SR_TB) + *ofs = 0; + else + *ofs = mtd->size - *len; + } } } @@ -1136,18 +1176,108 @@ static int stm_check_lock_status_sr(struct spi_nor *nor, loff_t ofs, uint64_t le return (ofs >= lock_offs + lock_len) || (ofs + len <= lock_offs); } -static int stm_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len, - u8 sr) +/* + * check if memory region is locked + * + * Returns false if region is locked 0 otherwise. + */ +static int spi_nor_is_locked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len, + u8 sr) { return stm_check_lock_status_sr(nor, ofs, len, sr, true); } -static int stm_is_unlocked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len, - u8 sr) +/* + * check if memory region is unlocked + * + * Returns false if region is locked 0 otherwise. + */ +static int spi_nor_is_unlocked_sr(struct spi_nor *nor, loff_t ofs, uint64_t len, + u8 sr) { return stm_check_lock_status_sr(nor, ofs, len, sr, false); } +/** + * spi_nor_select_zone() - Select top area or bottom area to lock/unlock + * @nor: pointer to a 'struct spi_nor'. + * @ofs: offset from which to lock memory. + * @len: number of bytes to unlock. + * @sr: status register + * @tb: pointer to top/bottom bool used in caller function + * @op: zone selection is for lock/unlock operation. 1: lock 0:unlock + * + * Select the top area / bottom area pattern to protect memory blocks. + * + * Returns negative on errors, 0 on success. + */ +static int spi_nor_select_zone(struct spi_nor *nor, loff_t ofs, uint64_t len, + u8 sr, bool *tb, bool op) +{ + int retval; + bool can_be_top = true, can_be_bottom = nor->flags & SNOR_F_HAS_SR_TB; + + if (op) { + /* Select for lock zone operation */ + + /* + * If nothing in our range is unlocked, we don't need + * to do anything. + */ + if (spi_nor_is_locked_sr(nor, ofs, len, sr)) + return 0; + + /* + * If anything below us is unlocked, we can't use 'bottom' + * protection. + */ + if (!spi_nor_is_locked_sr(nor, 0, ofs, sr)) + can_be_bottom = false; + + /* + * If anything above us is unlocked, we can't use 'top' + * protection. + */ + if (!spi_nor_is_locked_sr(nor, ofs + len, + nor->mtd.size - (ofs + len), sr)) + can_be_top = false; + } else { + /* Select unlock zone */ + + /* + * If nothing in our range is locked, we don't need to + * do anything. + */ + if (spi_nor_is_unlocked_sr(nor, ofs, len, sr)) + return 0; + + /* + * If anything below us is locked, we can't use 'top' + * protection + */ + if (!spi_nor_is_unlocked_sr(nor, 0, ofs, sr)) + can_be_top = false; + + /* + * If anything above us is locked, we can't use 'bottom' + * protection + */ + if (!spi_nor_is_unlocked_sr(nor, ofs + len, + nor->mtd.size - (ofs + len), sr)) + can_be_bottom = false; + } + + if (!can_be_bottom && !can_be_top) { + retval = -EINVAL; + } else { + /* Prefer top, if both are valid */ + *tb = can_be_top; + retval = 1; + } + + return retval; +} + /* * Lock a region of the flash. Compatible with ST Micro and similar flash. * Supports the block protection bits BP{0,1,2} in the status register @@ -1185,33 +1315,20 @@ static int stm_lock(struct spi_nor *nor, loff_t ofs, uint64_t len) struct mtd_info *mtd = &nor->mtd; int status_old, status_new; u8 mask = SR_BP2 | SR_BP1 | SR_BP0; - u8 shift = ffs(mask) - 1, pow, val; + u8 shift = ffs(mask) - 1, pow, val, ret; loff_t lock_len; - bool can_be_top = true, can_be_bottom = nor->flags & SNOR_F_HAS_SR_TB; bool use_top; status_old = read_sr(nor); if (status_old < 0) return status_old; - /* If nothing in our range is unlocked, we don't need to do anything */ - if (stm_is_locked_sr(nor, ofs, len, status_old)) + ret = spi_nor_select_zone(nor, ofs, len, status_old, &use_top, 1); + if (!ret) return 0; + else if (ret < 0) + return ret; - /* If anything below us is unlocked, we can't use 'bottom' protection */ - if (!stm_is_locked_sr(nor, 0, ofs, status_old)) - can_be_bottom = false; - - /* If anything above us is unlocked, we can't use 'top' protection */ - if (!stm_is_locked_sr(nor, ofs + len, mtd->size - (ofs + len), - status_old)) - can_be_top = false; - - if (!can_be_bottom && !can_be_top) - return -EINVAL; - - /* Prefer top, if both are valid */ - use_top = can_be_top; /* lock_len: length of region that should end up locked */ if (use_top) @@ -1265,33 +1382,19 @@ static int stm_unlock(struct spi_nor *nor, loff_t ofs, uint64_t len) struct mtd_info *mtd = &nor->mtd; int status_old, status_new; u8 mask = SR_BP2 | SR_BP1 | SR_BP0; - u8 shift = ffs(mask) - 1, pow, val; loff_t lock_len; - bool can_be_top = true, can_be_bottom = nor->flags & SNOR_F_HAS_SR_TB; + u8 shift = ffs(mask) - 1, pow, val, ret; bool use_top; status_old = read_sr(nor); if (status_old < 0) return status_old; - /* If nothing in our range is locked, we don't need to do anything */ - if (stm_is_unlocked_sr(nor, ofs, len, status_old)) + ret = spi_nor_select_zone(nor, ofs, len, status_old, &use_top, 0); + if (!ret) return 0; - - /* If anything below us is locked, we can't use 'top' protection */ - if (!stm_is_unlocked_sr(nor, 0, ofs, status_old)) - can_be_top = false; - - /* If anything above us is locked, we can't use 'bottom' protection */ - if (!stm_is_unlocked_sr(nor, ofs + len, mtd->size - (ofs + len), - status_old)) - can_be_bottom = false; - - if (!can_be_bottom && !can_be_top) - return -EINVAL; - - /* Prefer top, if both are valid */ - use_top = can_be_top; + else if (ret < 0) + return ret; /* lock_len: length of region that should remain locked */ if (use_top) @@ -1353,7 +1456,7 @@ static int stm_is_locked(struct spi_nor *nor, loff_t ofs, uint64_t len) if (status < 0) return status; - return stm_is_locked_sr(nor, ofs, len, status); + return spi_nor_is_locked_sr(nor, ofs, len, status); } static int spi_nor_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) @@ -1468,6 +1571,70 @@ static int macronix_quad_enable(struct spi_nor *nor) } /** + * 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 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; + u8 shift; + u8 pow, ret, func_reg; + bool use_top; + loff_t lock_len; + + if (nor->flags & SNOR_F_HAS_BP3) + mask = SR_BP3 | SR_BP2 | SR_BP1 | SR_BP0; + else + mask = SR_BP2 | SR_BP1 | SR_BP0; + + shift = ffs(mask) - 1; + + 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, + "SR is write protected, can't update BP bits...\n"); + return -EINVAL; + } + + ret = spi_nor_select_zone(nor, ofs, len, status_old, &use_top, 1); + if (!ret) + /* Older protected blocks include the new requested block's */ + return 0; + else if (ret < 0) + return ret; + + func_reg = spi_nor_read_fr(nor); + /* lock_len: length of region that should end up locked */ + if (use_top) + lock_len = nor->mtd.size - ofs; + else + lock_len = ofs + len; + + pow = order_base_2(lock_len); + blk_prot = mask & (((pow + 1) & 0xf) << shift); + if (lock_len <= 0) { + dev_err(nor->dev, "invalid Length to protect"); + return -EINVAL; + } + + 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. * @nor: pointer to a 'struct spi_nor'. * @ofs: offset from which to unlock memory. @@ -4171,6 +4338,7 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, if (JEDEC_MFR(info) == SNOR_MFR_ISSI && info->flags & SPI_NOR_HAS_LOCK && info->flags & SPI_NOR_HAS_BP3) { + nor->flash_lock = issi_lock; nor->flash_unlock = issi_unlock; } @@ -4194,6 +4362,8 @@ int spi_nor_scan(struct spi_nor *nor, const char *name, nor->flags |= SNOR_F_NO_OP_CHIP_ERASE; if (info->flags & USE_CLSR) nor->flags |= SNOR_F_USE_CLSR; + if (info->flags & SPI_NOR_HAS_BP3) + nor->flags |= SNOR_F_HAS_BP3; if (info->flags & SPI_NOR_NO_ERASE) mtd->flags |= MTD_NO_ERASE; diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h index f6fa70f..26dbf48 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -40,6 +40,8 @@ #define SPINOR_OP_RDSR 0x05 /* Read status register */ #define SPINOR_OP_WRSR 0x01 /* Write status register 1 byte */ #define SPINOR_OP_RDSR2 0x3f /* Read status register 2 */ +#define SPINOR_OP_RDFR 0x48 /* Read Function register */ +#define SPINOR_OP_WRFR 0x42 /* Write Function register 1 byte */ #define SPINOR_OP_WRSR2 0x3e /* Write status register 2 */ #define SPINOR_OP_READ 0x03 /* Read data bytes (low frequency) */ #define SPINOR_OP_READ_FAST 0x0b /* Read data bytes (high frequency) */ @@ -139,6 +141,9 @@ /* Enhanced Volatile Configuration Register bits */ #define EVCR_QUAD_EN_MICRON BIT(7) /* Micron Quad I/O */ +/*Function register bit */ +#define FR_TB BIT(1) /*ISSI: Top/Bottom protect */ + /* Flag Status Register bits */ #define FSR_READY BIT(7) /* Device status, 0 = Busy, 1 = Ready */ #define FSR_E_ERR BIT(5) /* Erase operation status */