From patchwork Tue Aug 7 19:40:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 954667 X-Patchwork-Delegate: tudor.ambarus@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="dk/8cS1m"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="dk6htlvc"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41lPzV26Tnz9rvt for ; Wed, 8 Aug 2018 05:41:58 +1000 (AEST) 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:To:From:References: In-Reply-To:Message-Id:Date:Subject:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=N+i70nTIqTKFL40F4JGhgd3pVy2kZpFZE/GfDMU60Ao=; b=dk/8cS1mOTFumM 2OT/4VSvUxT2yvFc9zSPECJg7Sw3JbhabyafhlI5ABehhK9UjUPs0ZGaJKG2/0xbfqKcBhEinZc0r ZdoLE46+y9LB4F2Hhfaw7APeuGiSew10bDr/PWP731oskY5aDOg0Kf+v+k2LCZB2XkK4+M6Qg6Ej9 wrXexiD/4EohUH3d4+RhXahKawSddfCcGAajr67gIoWcVrpUukLurxTHftcUox06Ky5HWVg30ukyA V/DnSNZ2Ciz/exq3n656Tnf9VWikqXNFB2NdxlvWcxmMBVF/Is+Yp1sKelXLimRWEQdTU6OWksrqy wN8w13H1NtZwqz6ZgnYw==; 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 1fn7ra-0008SL-51; Tue, 07 Aug 2018 19:41:50 +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 1fn7rS-0008Hm-3G for linux-mtd@lists.infradead.org; Tue, 07 Aug 2018 19:41:43 +0000 Received: by mail-pf1-x442.google.com with SMTP id l9-v6so9067269pff.9 for ; Tue, 07 Aug 2018 12:41:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=subject:date:message-id:in-reply-to:references:cc:from:to; bh=kstVtcNsgZUc7SUcEaqzSqyeXb2OI35+ht6gHHiQd4s=; b=dk6htlvcsBfYKJvo2GORRneAM9nEVg+3EsBct41gVKWSEFTp4SvZ7/JAVUr0P8YeMc fbJM5qgvqgCyvb8YsD0q1V4/dCqaB0utrIFPNuQ+sFqkznkzufkpmVtiWK0BqdB1Uk9b jd6ngZEelng44LAW7J6zAp4WLZ8h3Oj1TD7cdz0ffdWmsLPkqLhQspx3zAczIVLQ6fm/ uuStoEQaxKz2hcF5wC7jxgalt6MyN+5wDdFJxcWzr0h+gMT+XUYqgontK1m1FS9NbflH vD3BqAVAWJ4eTjowic/mYba+BfwkhXkLVRjLNPZ0l1UKLVnr1VaMcv+f2kPEERL1vCPy ElJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :cc:from:to; bh=kstVtcNsgZUc7SUcEaqzSqyeXb2OI35+ht6gHHiQd4s=; b=FJApCkdh98zDO7SWC2UEGDH5hAKWaptKjxksKsT6ylWzhpOvrPoqJSRHgLY3p9Z6CJ mDKA5QXZAJIrBwVw7+1OKkJUY9duBaobNroePTzqGLz6CPq0Wb15HwYF8PTjMMLoBzta Y05mBc0gh2E0IFoMvk1wzsiyYTUGntiMFo7/crd9VxBfRzWLcaApEgcOoRB83EO7tAdq rQMp8A+B93x+lJ9tMehYz/ZfGNSBw/2wX8x9mo8T2C8L0OPRPQUKH1HIueucMXFdpJ7Q ldIi5lb8wI0PBIv5ikWRSXygX/k5jjZ19mY5h9fSnbgZIlkY8ye2beDFVXecyq7Zdkhh udrA== X-Gm-Message-State: AOUpUlFHPOho2EpPLvjps+f27kCCGsfPNvhR/95kIM7+BzaxgH8M+YVQ iSJ8OlueS8atRTDH0nk6jaGgXw== X-Google-Smtp-Source: AAOMgpe1EmQw2jycLEktKzbWRZqnoAcfpEn0offwE/+WE41mU8pgIw04AzgLps+RqlCB8GUN0+iDRw== X-Received: by 2002:a63:ae02:: with SMTP id q2-v6mr19563048pgf.189.1533670891483; Tue, 07 Aug 2018 12:41:31 -0700 (PDT) Received: from localhost ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id 16-v6sm3668860pfp.6.2018.08.07.12.41.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Aug 2018 12:41:30 -0700 (PDT) Subject: [PATCH v2 1/2] spi-nor: add support for ISSI's block unlocking scheme Date: Tue, 7 Aug 2018 12:40:58 -0700 Message-Id: <20180807194059.26348-2-palmer@sifive.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180807194059.26348-1-palmer@sifive.com> References: <20180807194059.26348-1-palmer@sifive.com> From: Palmer Dabbelt To: marek.vasut@gmail.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180807_124142_138361_1B9F7AA8 X-CRM114-Status: GOOD ( 20.88 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:442 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Wesley W. Terpstra" , richard@nod.at, Palmer Dabbelt , linux-kernel@vger.kernel.org, boris.brezillon@bootlin.com, linux-mtd@lists.infradead.org, Paul Walmsley , computersforpeace@gmail.com, dwmw2@infradead.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: "Wesley W. Terpstra" ISSI uses a non-standard scheme to control block protection, with bit 5 of the status registerr controlling an additional block protection bit. This patch disables all the block protection bits whenever an ISSI chip is seen. We might also want to trigger an error when writing SR_TB to these chips, as it aliases with this extra protection bit in the status register. It looks like that's always conditional on SNOR_F_HAS_SR_TB, so at least what's there is safe. Signed-off-by: Wesley W. Terpstra Signed-off-by: Palmer Dabbelt --- drivers/mtd/spi-nor/spi-nor.c | 43 ++++++++++++++++++++++++++++++++++++++++++- include/linux/mtd/spi-nor.h | 2 ++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index d9c368c44194..aab93463a5e7 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1515,6 +1515,44 @@ static int macronix_quad_enable(struct spi_nor *nor) return 0; } +/** + * issi_unlock() - clear BP[0123] write-protection. + * @nor: pointer to a 'struct spi_nor' + * + * 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) +{ + 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)) { + return 0; + } else { + dev_err(nor->dev, "ISSI Block Protection Bits not cleared\n"); + return -EINVAL; + } +} + /* * Write status Register and configuration register with 2 bytes * The first byte will be written to the status register, while the @@ -2747,6 +2785,9 @@ static int spi_nor_init(struct spi_nor *nor) spi_nor_wait_till_ready(nor); } + if (JEDEC_MFR(nor->info) == SNOR_MFR_ISSI) + issi_unlock(nor); + if (nor->quad_enable) { err = nor->quad_enable(nor); if (err) { @@ -2926,7 +2967,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 e60da0d34cc1..da422a37d383 100644 --- a/include/linux/mtd/spi-nor.h +++ b/include/linux/mtd/spi-nor.h @@ -23,6 +23,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 #define SNOR_MFR_MICRON CFI_MFR_ST /* ST Micro <--> Micron */ #define SNOR_MFR_MACRONIX CFI_MFR_MACRONIX #define SNOR_MFR_SPANSION CFI_MFR_AMD @@ -121,6 +122,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 (on ISSI chips) */ #define SR_TB BIT(5) /* Top/Bottom protect */ #define SR_SRWD BIT(7) /* SR write protect */ /* Spansion/Cypress specific status bits */ From patchwork Tue Aug 7 19:40:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 954669 X-Patchwork-Delegate: tudor.ambarus@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="j69fZGuc"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="AHpGt3Ah"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41lPzd73zVz9rvt for ; Wed, 8 Aug 2018 05:42:05 +1000 (AEST) 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:To:From:References: In-Reply-To:Message-Id:Date:Subject:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9bUHJWFn3lUe+J0u1goSgYfLss3HQCIUUfAR4sC61xs=; b=j69fZGuciK1/EV 1MrF/2Ee9Vthu1M+/K6A/YR7JqNomlnl66ewTpefUC4JWu12BVSxhbs9nvDHE/nZPCv0oo3Bw4gvE CaDKE9XF5ZVld3huJ7TD7XXLT8XrIcrf6MPn6paIKzDEiuOabiIIcE5Sf9IwyOVnKsI5Gwcv0Tla3 zlvyg/RpqUpKy5l0zIUXWox+bJEfYA0FATXSHwp0lN8YMivAKu6DWXL+uBlmVMkIIxJYrq6LZxxan gz90Xr2feW8ph5/XkjwK6lktg29Qz4pjAZNlAkvb9SrifdtlaBjId6uClHEdRleUsNoD57CJgi16l Cm0jI4HpKrEQR0Xk9HsQ==; 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 1fn7rj-0000EH-7A; Tue, 07 Aug 2018 19:41:59 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fn7rT-0008Hn-TL for linux-mtd@lists.infradead.org; Tue, 07 Aug 2018 19:41:47 +0000 Received: by mail-pg1-x544.google.com with SMTP id r1-v6so8298137pgp.11 for ; Tue, 07 Aug 2018 12:41:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=subject:date:message-id:in-reply-to:references:cc:from:to; bh=cJYdTOP/lqwDsHAxF8UDrfGAeqPoLuDCk7YQyzrU52s=; b=AHpGt3AhilFWVhJNdg18KKB3HXOqkXc1wFe1lY42UeCFUuovGCSsDMzDMulovCt79g C/BPFKXTRey/1anJnuAzM5Q6OsSLgnrJXJM77WYDv7ZQLBhZXShaM8FJ6KAQi1qjVmER FWMdwG2NDcLAIEOjxf/uD51SmxoIjxCIFPbnNa62Ruk/2oPrJ2kcSP2+vxUvnBqOSTc8 pcIETcvOeXLlHTqBNgAcDU4AqBf9gDIdmAKfuBS2tIxBfzj2NX1z2cK0COIsOmJrbs2P c2iB2p4lZO7uvz7T90udRvBFxeQceFWkklgGc1Rklb5nOySXs+k42KmM3oefLXsm1BaB LXBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:date:message-id:in-reply-to:references :cc:from:to; bh=cJYdTOP/lqwDsHAxF8UDrfGAeqPoLuDCk7YQyzrU52s=; b=jFyXVtN05plru2crcnEBESnh3sVLNx+3DJUKdAe8IP9AllrRiW3GCmuF+ZH7wr6Tl6 Uflfokj7876z9Bya84hecUDmPc8XjVSZMN5khKHTR/cmqwieZpX+VsKVy9HtTC83OEGX UYbvJHisGxSn00fDJ8iUxEtpm3uWqNJDcAFfLRgDRJXak5grb7Jkd39vCb05xQw8uTVO +g87Jv0G3aoo1BBXd/oYC20IexWwenm8xEcO0WF3DOtoVaOsYSFvg5kRGZqQDq7fSmSl ZICqapYIBhoWLvRQMPt2Ig7ySdCPg4GKCMP4nuIUjPajkqbvkVTq0XmpHMqB/MW6SJWp YVgg== X-Gm-Message-State: AOUpUlG8AysaFb2/BuL1RssIzdUe5wzN7gEzyQmZgb4o0rBGXjHTu1C1 fXMCoPd4dj0HAmU5EzYWw7YXvQ== X-Google-Smtp-Source: AAOMgpeZPLkVdWoHsLaB9Dqnq+CCdP2fNVpefWeZL2hcLF6Q2Ya/0gGckuRQtP088ltM5qEC+Hx7tg== X-Received: by 2002:a62:2646:: with SMTP id m67-v6mr23301211pfm.254.1533670893342; Tue, 07 Aug 2018 12:41:33 -0700 (PDT) Received: from localhost ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id s184-v6sm3451747pfb.56.2018.08.07.12.41.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Aug 2018 12:41:32 -0700 (PDT) Subject: [PATCH v2 2/2] spi-nor: add support for is25wp256 Date: Tue, 7 Aug 2018 12:40:59 -0700 Message-Id: <20180807194059.26348-3-palmer@sifive.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180807194059.26348-1-palmer@sifive.com> References: <20180807194059.26348-1-palmer@sifive.com> From: Palmer Dabbelt To: marek.vasut@gmail.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180807_124144_163817_82AEA5DC X-CRM114-Status: GOOD ( 11.97 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Wesley W. Terpstra" , richard@nod.at, Palmer Dabbelt , linux-kernel@vger.kernel.org, boris.brezillon@bootlin.com, linux-mtd@lists.infradead.org, Paul Walmsley , computersforpeace@gmail.com, dwmw2@infradead.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: "Wesley W. Terpstra" This is used of the HiFive Unleashed development board, and follows the pattern of similar ISSI devices already listed. Signed-off-by: Wesley W. Terpstra Signed-off-by: Palmer Dabbelt --- drivers/mtd/spi-nor/spi-nor.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index aab93463a5e7..f10017b4543d 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1072,6 +1072,8 @@ static const struct flash_info spi_nor_ids[] = { 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, 512, + SECT_4K | SPI_NOR_DUAL_READ | SPI_NOR_QUAD_READ) }, /* Macronix */ { "mx25l512e", INFO(0xc22010, 0, 64 * 1024, 1, SECT_4K) },