Received: by 10.192.165.148 with SMTP id m20csp742151imm; Fri, 20 Apr 2018 15:00:48 -0700 (PDT) X-Google-Smtp-Source: AIpwx49dFFxJKAyfiZFuY3AWZlzw2R007FQvoHecdJ45j6RKr3Hmi7TShly7Ho5TuwPUXxX3fGzc X-Received: by 10.98.92.129 with SMTP id q123mr11167914pfb.252.1524261648611; Fri, 20 Apr 2018 15:00:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524261648; cv=none; d=google.com; s=arc-20160816; b=DAoqxZb5iSgtmjDCGvyB4EdcUWUQ6s+vjPlskLlAHHrdG/6h5Rj469XlBQOL0PFooC ahaglm7qLzdwv/rTytyWZ/usMempf8MeYbs1Gn4K1ekZR5klvWVTj+/Fsna+EG/rUKYs x3q/CM7+dHVfaJmMoXO1ZeloBgcfdCALv75CMjFGfS8U7APsVoO1cfnkul0B6vRoQKhu NNb4k8aU35W28tXPK/wosWmJ5rm/nxTZ9eHM2ap6VaGHuGCx22nznw8h4hVdwu3BC6qR vGEMOjpFwFmIq1apA52kipxtCwlnJXbLHzhmZCWmIEZkCkx59dUK30PO0aLTC4UfoFyH 24dg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:to:subject:dkim-signature :arc-authentication-results; bh=ZaEuB7S7FKRxafe4Nq7MwME5Zqe+IchxjuOmryrISBs=; b=Wym+K5cFm5I+HoDjVFvY7AjUO4mNwIhF8JFwSpz1FOwRlXl4tDGdP0Hx7fgIGPfuOR qH+tUOClS69hXZLDHmWd87bNzpkPbpTsskpFSL5BtC+dl3VgBP7Nc+lXohndD2p4wMpb /DSyJmEZKEPfnCoWujN8LjwccipPZ9oG/rAEsTZUY3Gc96yPulLRd3rpIy+VOB7IPhto G7ZIB59JtHi+h7silDquliQEX7mvpLib014c7m6HvhexIKakgfVE941+bcaIjOeiIoCv jZWZ8YKkliMVhNWHiWWvQMf3N8nqKJMVYJqLF3ZipPD8ue5+NmvlJkVWEtZWy/0GCoO5 IIdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PPIxdsbM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q13si5553977pgr.405.2018.04.20.15.00.10; Fri, 20 Apr 2018 15:00:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PPIxdsbM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752686AbeDTV5e (ORCPT + 99 others); Fri, 20 Apr 2018 17:57:34 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:32769 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751227AbeDTV52 (ORCPT ); Fri, 20 Apr 2018 17:57:28 -0400 Received: by mail-wr0-f193.google.com with SMTP id z73-v6so26456419wrb.0 for ; Fri, 20 Apr 2018 14:57:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=ZaEuB7S7FKRxafe4Nq7MwME5Zqe+IchxjuOmryrISBs=; b=PPIxdsbMIrMwCHRpLYs210Jk2Z6Liw41QJDrwDeVblq8uNqPoF46TpCyBcMvMUmV7C T6p1RIRF7D7AT2piv2pqL9GixZeDbVa/Ovw9WCSg0QWvs/WS31CjNuWs6WUQLHBis1IT gv//AcWJ2B0Gxouw936qQOw57yPeuUQmbm6qZiiftMswIKjtUxRpW4kxwA5ANJYotprD LCO09304qSFD6M3uyF/oSdRagw/SyKsvRnLUIZ4nwl2KYi2F3gBJjwV2fndNrLrDWkZC XR/6pUT8dtqGl521fwQjOJE2LfXeDNkbfj1p6qaOqOAU5jmyR+x8WvBZdpBCTElcAL8v C7yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=ZaEuB7S7FKRxafe4Nq7MwME5Zqe+IchxjuOmryrISBs=; b=GJVrPr5VT83rks8KC3flV8jDlyIZwFNsmHuv8VTmBkMhbg1B4FipNdLofLcyJSy/2P ShthIT7LupD133vNjL8OhXPNvwR3qcuIjtkqamCl+wMBHlo0WQho+E8OKUzYK8uivRgh 5T0c+WhgjGEUO1SWbUhBDmF4Qqmg8y9PreGaRgMIxgKUE0dJv7r8M7918Pcb7j37ydQn yCMyyKHz8Qnx4JGTXa2DhV8f8UTAB+QEzHsfJ0kqeJbPVoVDQhpJ+pBR1ACjj9O0jwHU J31kIxAcGe5VnizAnemVLchaZMWTSPUifP52TB1re2DHdm+E+CgenTDjBajA+dtqQUOd WywQ== X-Gm-Message-State: ALQs6tB1a9cNtJ8/yQ3SlKahspVSk2KKo1tv9bMFPPOJrSClgJ0UDPqH motr24q4z5zEQEhLUNnVneCfFQnU X-Received: by 10.80.246.149 with SMTP id d21mr9368957edn.142.1524261446685; Fri, 20 Apr 2018 14:57:26 -0700 (PDT) Received: from [192.168.1.4] (ip-86-49-107-50.net.upcbroadband.cz. [86.49.107.50]) by smtp.gmail.com with ESMTPSA id a7sm4135376edl.11.2018.04.20.14.57.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Apr 2018 14:57:26 -0700 (PDT) Subject: Re: [PATCH v3] mtd: spi-nor: clear Winbond Extended Address Reg on switch to 3-byte addressing. To: NeilBrown , Boris Brezillon , Cyrille Pitchen , David Woodhouse , Brian Norris , Boris Brezillon , Richard Weinberger , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org References: <874lkmw54j.fsf@notabene.neil.brown.name> <87sh7wrq8p.fsf@notabene.neil.brown.name> <20180420215440.7b078f6c@bbrezillon> <87h8o5po1h.fsf@notabene.neil.brown.name> From: Marek Vasut Message-ID: <967de310-3b9a-1853-3377-71f71fd8ac27@gmail.com> Date: Fri, 20 Apr 2018 23:57:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <87h8o5po1h.fsf@notabene.neil.brown.name> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 04/20/2018 11:26 PM, NeilBrown wrote: > > Winbond spi-nor flash 32MB and larger have an 'Extended Address > Register' as one option for addressing beyond 16MB (Macronix > has the same concept, Spansion has EXTADD bits in the Bank Address > Register). > > According to section > 8.2.7 Write Extended Address Register (C5h) > > of the Winbond W25Q256FV data sheet (256M-BIT SPI flash) > > The Extended Address Register is only effective when the device is > in the 3-Byte Address Mode. When the device operates in the 4-Byte > Address Mode (ADS=1), any command with address input of A31-A24 > will replace the Extended Address Register values. It is > recommended to check and update the Extended Address Register if > necessary when the device is switched from 4-Byte to 3-Byte Address > Mode. > > So the documentation suggests clearing the EAR after switching to > 3-byte mode. Experimentation shows that the EAR is *always* one after > the switch to 3-byte mode, so clearing the EAR is mandatory at > shutdown for a subsequent 3-byte-addressed reboot to work. > > Note that some SOCs (e.g. MT7621) do not assert a reset line at normal > reboot, so we cannot rely on hardware reset. The MT7621 does assert a > reset line at watchdog-reset. > > This problem is not a regression. However the commit identified below > added support for resetting an spi-nor chip at shutdown, but didn't > achieve the goal for all spi-nor chips. So this patch can be seen as > fixing that one. > > Fixes: 59b356ffd0b0 ("mtd: m25p80: restore the status of SPI flash when exiting") > Cc: stable@vger.kernel.org (v4.16) > Signed-off-by: NeilBrown Acked-by: Marek Vasut > --- > drivers/mtd/spi-nor/spi-nor.c | 14 ++++++++++++++ > include/linux/mtd/spi-nor.h | 2 ++ > 2 files changed, 16 insertions(+) > > diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c > index 5bfa36e95f35..42ae9a1529bb 100644 > --- a/drivers/mtd/spi-nor/spi-nor.c > +++ b/drivers/mtd/spi-nor/spi-nor.c > @@ -284,6 +284,20 @@ static inline int set_4byte(struct spi_nor *nor, const struct flash_info *info, > if (need_wren) > write_disable(nor); > > + if (!status && !enable && > + JEDEC_MFR(info) == SNOR_MFR_WINBOND) { > + /* > + * On Winbond W25Q256FV, leaving 4byte mode causes > + * the Extended Address Register to be set to 1, so all > + * 3-byte-address reads come from the second 16M. > + * We must clear the register to enable normal behavior. > + */ > + write_enable(nor); > + nor->cmd_buf[0] = 0; > + nor->write_reg(nor, SPINOR_OP_WREAR, nor->cmd_buf, 1); > + write_disable(nor); > + } > + > return status; > default: > /* Spansion style */ > diff --git a/include/linux/mtd/spi-nor.h b/include/linux/mtd/spi-nor.h > index de36969eb359..e60da0d34cc1 100644 > --- a/include/linux/mtd/spi-nor.h > +++ b/include/linux/mtd/spi-nor.h > @@ -62,6 +62,8 @@ > #define SPINOR_OP_RDCR 0x35 /* Read configuration register */ > #define SPINOR_OP_RDFSR 0x70 /* Read flag status register */ > #define SPINOR_OP_CLFSR 0x50 /* Clear flag status register */ > +#define SPINOR_OP_RDEAR 0xc8 /* Read Extended Address Register */ > +#define SPINOR_OP_WREAR 0xc5 /* Write Extended Address Register */ > > /* 4-byte address opcodes - used on Spansion and some Macronix flashes. */ > #define SPINOR_OP_READ_4B 0x13 /* Read data bytes (low frequency) */ > -- Best regards, Marek Vasut