From patchwork Mon Sep 11 09:42:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bin Meng X-Patchwork-Id: 812292 X-Patchwork-Delegate: cyrille.pitchen@atmel.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=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="lxz6NT4x"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BW5MI5pt"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 3xrNXR3bKrz9s7G for ; Mon, 11 Sep 2017 19:53:11 +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: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=mam5s1pkyCwRzV1jQX+7ZtDKfVtBfa0ylEokwM1ROJk=; b=lxz6NT4xT+JQOdlpbDuWEeZcUO igXuvahYDY/CpyiQIPYSUNGv5+rdTX9RJr+psuRRxV7dsv7fMxJiCe/osqNr5MMeHKzw2q/owDqaR Pp49xwXHv2SatYx3+feiU/uGQGi/p7CCJILUPJSN57BpVBZnulqSuF+G8/TzRXDiHkLaUD8RKoLcm jhiyPDR19WNXHN3d1lovCefBqZaAkSG2TMW+VxABN/dfUX01OFFxpyqpjxnp83I28qANUNXuBTjtb tNkuI9YVliesoxGkyGlE27lhuT1wGuSLZ2/THiLXjnNrPfKiIc5I8CvtqV5RRu6Ml+Hw5q7ibqD0A fWq51Z+g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1drLOs-000840-AR; Mon, 11 Sep 2017 09:53:06 +0000 Received: from mail-io0-x243.google.com ([2607:f8b0:4001:c06::243]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1drLAX-0006DN-6u for linux-mtd@lists.infradead.org; Mon, 11 Sep 2017 09:38:19 +0000 Received: by mail-io0-x243.google.com with SMTP id j141so4119570ioj.5 for ; Mon, 11 Sep 2017 02:37:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nO7tkNSnE4kDX2xNGYFdszsbJOrKUMxzGoXfU0C2iwQ=; b=BW5MI5ptNVZz9iBeeGmuT3p7WstCYN5NDrcwLDdI+tLGwUSmutnx1Z+YEp3nDcDhHt /8pLYWfOrKG8CVKssGzNGbyRQrEYIMjlu8B65QCR/oYydn55PcFqCu4RKW2wU4s2gYUk z/Rej+38UKsvUmai6ujpuVcEHqqUe4vbvrnmjkduwJDEzquJkKXdrv19JMJ5CysZLNIl XT+imJa/zp5gSGg2SNgdTTHOtjoUTLPDPGcIMd2Bt+IyFJeq6Yv0x7mLNy62ngovEu88 /SikzFIADhMeCF9gFfDf+6+EsMtEKQFW57mcXvkmLJ/4wr2RwV/E3K3vl4ZN8tBTXe2A dI7w== 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=nO7tkNSnE4kDX2xNGYFdszsbJOrKUMxzGoXfU0C2iwQ=; b=RoPFe7BiBEUa+ebUvyyeyE2E399cLJD6JU/4UkYq4qQONUsH+Nx/Prgf906Y5SbEaG iIB0eY6vFHPfwWn7zB4DjQzHt5lM0e/+9g0gFDHrfq6W0YsAprXUZa9dXIBCxowj71xU lcGUJQNCuuYpFPZPL1lsFKWJLD9fUizQ5vNOgJhb/jiqiPijazs752gi0YLOtuDGiiwS u0Rml6o2DsQrxIWRj/Z7z5KjNDQb8C1Nq2PzqG58qa0s21tOO8Ba7LLGHD63B61K1V9Z miypQ29+nqCHE4iB2ZVSAzwmgZ/fdLWinRP6JN4SZ/1fwvhCKA0GuVCd4eOJ/yV6Hyhb HWpA== X-Gm-Message-State: AHPjjUjEcQY2EIcqcF9parQWucFQ+1DheN3mQgF8GbXJd1007Zr0spne rQaUKQpqAYluCA== X-Google-Smtp-Source: AOwi7QAU+kDZHyhuAycUhYA2iua+PKPdFkBg0qSMNEctubwy82XwHuYUuxHNR121692L2k7TtbvA1g== X-Received: by 10.107.154.71 with SMTP id c68mr15252768ioe.95.1505122678578; Mon, 11 Sep 2017 02:37:58 -0700 (PDT) Received: from ala-d2121-lx1.wrs.com (unknown-156-139.windriver.com. [147.11.156.139]) by smtp.gmail.com with ESMTPSA id s2sm4121069ioa.2.2017.09.11.02.37.56 (version=TLS1_1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 11 Sep 2017 02:37:57 -0700 (PDT) From: Bin Meng To: Mika Westerberg , Cyrille Pitchen , Marek Vasut , Boris Brezillon , Brian Norris , Richard Weinberger , David Woodhouse , linux-mtd , linux-kernel Subject: [PATCH v2 10/10] spi-nor: intel-spi: Fall back to use SW sequencer to erase Date: Mon, 11 Sep 2017 02:42:00 -0700 Message-Id: <1505122921-5534-11-git-send-email-bmeng.cn@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1505122921-5534-1-git-send-email-bmeng.cn@gmail.com> References: <1505122921-5534-1-git-send-email-bmeng.cn@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170911_023817_403544_F1DC0528 X-CRM114-Status: GOOD ( 18.00 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2607:f8b0:4001:c06:0:0:0:243 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (bmeng.cn[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -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: Stefan Roese MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org According to the datasheet, the HW sequencer has a predefined list of opcodes, with only the erase opcode being programmable in LVSCC and UVSCC registers. If these registers don't contain a valid erase opcode (eg: BIOS does not program it), erase cannot be done using the HW sequencer, even though the erase operation does not report any error, the flash remains not erased. If such register setting is detected, let's fall back to use the SW sequencer to erase instead. Signed-off-by: Bin Meng Acked-by: Mika Westerberg --- Changes in v2: - Fix typo of 'operatoin' drivers/mtd/spi-nor/intel-spi.c | 50 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/intel-spi.c b/drivers/mtd/spi-nor/intel-spi.c index 5e7a389..ef034d8 100644 --- a/drivers/mtd/spi-nor/intel-spi.c +++ b/drivers/mtd/spi-nor/intel-spi.c @@ -111,6 +111,13 @@ #define BXT_FREG_NUM 12 #define BXT_PR_NUM 6 +#define LVSCC 0xc4 +#define UVSCC 0xc8 +#define ERASE_OPCODE_SHIFT 8 +#define ERASE_OPCODE_MASK (0xff << ERASE_OPCODE_SHIFT) +#define ERASE_64K_OPCODE_SHIFT 16 +#define ERASE_64K_OPCODE_MASK (0xff << ERASE_OPCODE_SHIFT) + #define INTEL_SPI_TIMEOUT 5000 /* ms */ #define INTEL_SPI_FIFO_SZ 64 @@ -127,6 +134,7 @@ * @writeable: Is the chip writeable * @locked: Is SPI setting locked * @swseq_reg: Use SW sequencer in register reads/writes + * @swseq_erase: Use SW sequencer in erase operation * @erase_64k: 64k erase supported * @opcodes: Opcodes which are supported. This are programmed by BIOS * before it locks down the controller. @@ -144,6 +152,7 @@ struct intel_spi { bool writeable; bool locked; bool swseq_reg; + bool swseq_erase; bool erase_64k; u8 opcodes[8]; u8 preopcodes[2]; @@ -191,6 +200,9 @@ static void intel_spi_dump_regs(struct intel_spi *ispi) if (ispi->info->type == INTEL_SPI_BYT) dev_dbg(ispi->dev, "BCR=0x%08x\n", readl(ispi->base + BYT_BCR)); + dev_dbg(ispi->dev, "LVSCC=0x%08x\n", readl(ispi->base + LVSCC)); + dev_dbg(ispi->dev, "UVSCC=0x%08x\n", readl(ispi->base + UVSCC)); + dev_dbg(ispi->dev, "Protected regions:\n"); for (i = 0; i < ispi->pr_num; i++) { u32 base, limit; @@ -225,6 +237,8 @@ static void intel_spi_dump_regs(struct intel_spi *ispi) dev_dbg(ispi->dev, "Using %cW sequencer for register access\n", ispi->swseq_reg ? 'S' : 'H'); + dev_dbg(ispi->dev, "Using %cW sequencer for erase operation\n", + ispi->swseq_erase ? 'S' : 'H'); } /* Reads max INTEL_SPI_FIFO_SZ bytes from the device fifo */ @@ -288,7 +302,7 @@ static int intel_spi_wait_sw_busy(struct intel_spi *ispi) static int intel_spi_init(struct intel_spi *ispi) { - u32 opmenu0, opmenu1, val; + u32 opmenu0, opmenu1, lvscc, uvscc, val; int i; switch (ispi->info->type) { @@ -339,6 +353,24 @@ static int intel_spi_init(struct intel_spi *ispi) writel(val, ispi->base + HSFSTS_CTL); /* + * Determine whether erase operation should use HW or SW sequencer. + * + * The HW sequencer has a predefined list of opcodes, with only the + * erase opcode being programmable in LVSCC and UVSCC registers. + * If these registers don't contain a valid erase opcode, erase + * cannot be done using HW sequencer. + */ + lvscc = readl(ispi->base + LVSCC); + uvscc = readl(ispi->base + UVSCC); + if (!(lvscc & ERASE_OPCODE_MASK) || !(uvscc & ERASE_OPCODE_MASK)) + ispi->swseq_erase = true; + /* SPI controller on Intel BXT supports 64K erase opcode */ + if (ispi->info->type == INTEL_SPI_BXT && !ispi->swseq_erase) + if (!(lvscc & ERASE_64K_OPCODE_MASK) || + !(uvscc & ERASE_64K_OPCODE_MASK)) + ispi->erase_64k = false; + + /* * Some controllers can only do basic operations using hardware * sequencer. All other operations are supposed to be carried out * using software sequencer. @@ -665,6 +697,22 @@ static int intel_spi_erase(struct spi_nor *nor, loff_t offs) erase_size = SZ_4K; } + if (ispi->swseq_erase) { + while (len > 0) { + writel(offs, ispi->base + FADDR); + + ret = intel_spi_sw_cycle(ispi, nor->erase_opcode, + 0, OPTYPE_WRITE_WITH_ADDR); + if (ret) + return ret; + + offs += erase_size; + len -= erase_size; + } + + return 0; + } + while (len > 0) { writel(offs, ispi->base + FADDR);