From patchwork Sat Aug 4 01:49:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Palmer Dabbelt X-Patchwork-Id: 953402 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="NozHMLas"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.b="Ejs5dVIF"; 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 41j6Lc3hhbz9ryn for ; Sat, 4 Aug 2018 11:50:30 +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:Message-Id: Date:Subject: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=NMt7wLHbNoBi7yAKXwKfVvMKwxC1BXS+DXiY6ubfetU=; b=NozHMLas9hgqrb C46lBNT3mtJSW7GbEq5MYDV95Gp7SrdjjjGeTcxHxY21IdDK3i15YJliWTEpY+tlS7TtpyGUj6lNH Fywr8spFxf16n5uoEgKS98WTotVFmZu2/Vp+nifKTSd+ZoHG3gezJoeVZXSLpahqppdtEFpIoqpr3 aftbS+MvZrcajyvZ4ozkP+FWZuGdqADoyHwIw+gWvhPmbVsYSsAH0iLsOUTinw/1iUsfCGVsmX7VX KWa82AUZlGQZYoKnvFYOy4Nz3loIhts4EX06GqsVc2IhYqbli4s3U/2w3rkKqDFSBIiIwRQ06KnTA PWSjCBEAXUyKZ6E0TmIw==; 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 1flli3-00060Y-1M; Sat, 04 Aug 2018 01:50:23 +0000 Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fllhu-0004yG-4Z for linux-mtd@lists.infradead.org; Sat, 04 Aug 2018 01:50:15 +0000 Received: by mail-pg1-x541.google.com with SMTP id h12-v6so3632125pgs.3 for ; Fri, 03 Aug 2018 18:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=subject:date:message-id:cc:from:to; bh=tQtY9Y39XTaQW+2EzTmwnC+CoPrvK+Z5UtDsqEnm6hI=; b=Ejs5dVIFsWvXi7FSqa0iOSJLvGgteZv/r+ubTb3cRAWod2lSwyEPUMm+xWsOO6dceN vUHAtYpyRhjiHZ+pTWyhiqsKAQJcdtv5Mj9A3OvAVch9yE4LMr15VrYRmdwsdVefUqA8 KGVhOrZ8Wt+j7XEuWAOzarkxY9CTHFM2juyRrxCbbwDuTuIPeZZyyOVPNHVBVSjuVHN3 Mwgmv0Yd/hLUUxko65+vN3Q5gbY7hnQd09DyUL7g9GSnJf/X0nII5XLxmlwTJcAMnRDP Bp+615a+CPLkKSIxEGkTjFtTXSsnyZ0MD0nC0wLifVUv4bSLYZoy1MAKDRNKbBZsvEcq ab4w== 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:cc:from:to; bh=tQtY9Y39XTaQW+2EzTmwnC+CoPrvK+Z5UtDsqEnm6hI=; b=G9/VpNBEx4nBinADoT0PPsceBWhMHldYUf6zPzFvyno97JefaJNJUkwFjBT3FTmWoZ 8ZSYl8QJBsidGQ6ygDrBK78mR/hX/jxq+vGv9GhxnZyIp3WrPUZr1P+WUmGvNR+U4Q97 n1KJGrCh7/b6hpi7TCEHW/BZEmTXYCMBQ1BUaG7CUoQbO7IN8kpryTt6I3RXcVrwpiYP wbfPQs+KNF5+6oEe8BoF2JCCQvSoYuDMLuvr+u94lRqoMsP5GuI6y/1YmeYjFpQNy7Xq FzArTsjBc/jlm5RHODRY3yDP9W9jYQts4aGX4q4Mcl41vmd+xnbgLUH4fZSZiYd4Fzj9 mCXA== X-Gm-Message-State: AOUpUlEH6x+8UEmKH+F9aq+dlqRMAPR+Be/hYsdiUqWfw/0hBfCN0VF9 x+Kvg3Ao6mpV6NuudPRJIYdskQ== X-Google-Smtp-Source: AAOMgpejsuC9kuEVmLkhYXw753sFWQXEcbCVWyPKNwIZ2li6CQMNpM8wd9wXXcbs09VwTfpXxm5BUQ== X-Received: by 2002:a62:4083:: with SMTP id f3-v6mr7021533pfd.229.1533347403360; Fri, 03 Aug 2018 18:50:03 -0700 (PDT) Received: from localhost ([12.206.222.5]) by smtp.gmail.com with ESMTPSA id o27-v6sm9146360pfj.35.2018.08.03.18.50.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Aug 2018 18:50:02 -0700 (PDT) Subject: [PATCH] spi-nor: add support for is25wp256d Date: Fri, 3 Aug 2018 18:49:47 -0700 Message-Id: <20180804014947.24601-1-palmer@sifive.com> X-Mailer: git-send-email 2.16.4 From: Palmer Dabbelt To: linux-mtd@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180803_185014_187293_56D684DC X-CRM114-Status: GOOD ( 18.40 ) 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:541 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -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: boris.brezillon@bootlin.com, richard@nod.at, Palmer Dabbelt , linux-kernel@vger.kernel.org, marek.vasut@gmail.com, "Wesley W. Terpstra" , 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. Signed-off-by: Wesley W. Terpstra Signed-off-by: Palmer Dabbelt --- drivers/mtd/spi-nor/spi-nor.c | 47 ++++++++++++++++++++++++++++++++++++++++++- include/linux/mtd/spi-nor.h | 2 ++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c index d9c368c44194..e9a3557a3c23 100644 --- a/drivers/mtd/spi-nor/spi-nor.c +++ b/drivers/mtd/spi-nor/spi-nor.c @@ -1072,6 +1072,9 @@ 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) }, + { "is25wp256d", INFO(0x9d7019, 0, 32 * 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) }, @@ -1515,6 +1518,45 @@ 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)) { + dev_info(nor->dev, "ISSI Block Protection Bits cleared\n"); + 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 +2789,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 +2971,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 */