Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp1104635ybx; Tue, 5 Nov 2019 10:22:22 -0800 (PST) X-Google-Smtp-Source: APXvYqzXnVkgvMADbwl0pKlVBw8S8nWaf6GqakS6qOi4UdZ6UrFJT9w2faP4jpqUq+v3SzBDBogw X-Received: by 2002:a17:906:f756:: with SMTP id jp22mr17068368ejb.234.1572978142386; Tue, 05 Nov 2019 10:22:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1572978142; cv=none; d=google.com; s=arc-20160816; b=J9zdEPeyrudqE3zAsjffwFRQ7NRxtHh46X7HQLDi5twcwvO5SJlhVvGBMWG42B3mSs bQwItDPYN+20JobgSDcYmjmc9spyV4G/ADYoXFQUCEKCmAm4xq2r5Si8MJ4KK0dUz1uj V3GREG6/maN1VKemqVqdDtN6DoFEjfN8/f9gJlN+jhmAjK/dAJmEhPBswyMsiQ6dFpj2 QzAJMM3ongUUNmaGsz+PBv53Coi0o9azL4KgVC+8/wiYtP9zxGTybRr7exIR8sv6l9P5 kQ87ApPmV2C9mCqdKHc4eaZt0fYIDehUz5Z9wyzBDACuNNtXA7uqXrJAnfCEM3a2oLKU E64A== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=pXDsdgyMSljUayXKybgckt2Arfy2VrNTR3UwuHilfqQ=; b=fUJDS5+qxLFdv9aLRaah63Gn3GazT6jtvV5dnPif1qinOlw+IRe/Z/dX+f8+ROBQCA G4FXZkEGurBPuVd9uoFx+kAd4qdgoBCRcm2v3x3kj3WNN5GjoALWMdNfxtpkdNYPQLW0 1+FrawOHC4Qu7a6sHtwfE+vJQEnc6GSaMRUu7rKh/JepuF1t9rXATv8ItrRpZVqTiAYY NQCejLEXphm4DL+KgvpFjfQtmWSaWaMdW2q+MSiDYmX0SofN534RrF36NoKi1LCVIztr v0BCMcFV9Zfw2ClmJRVXfG4PdIgg7t93proMFpiiM2BAilaIwSpAH9ZBwqVcXzMn6++t MXMw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jz15si12598036ejb.94.2019.11.05.10.21.58; Tue, 05 Nov 2019 10:22:22 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390792AbfKESUi convert rfc822-to-8bit (ORCPT + 99 others); Tue, 5 Nov 2019 13:20:38 -0500 Received: from relay12.mail.gandi.net ([217.70.178.232]:40383 "EHLO relay12.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389356AbfKESUi (ORCPT ); Tue, 5 Nov 2019 13:20:38 -0500 Received: from xps13 (unknown [91.224.148.103]) (Authenticated sender: miquel.raynal@bootlin.com) by relay12.mail.gandi.net (Postfix) with ESMTPSA id B6C1820000A; Tue, 5 Nov 2019 18:20:32 +0000 (UTC) Date: Tue, 5 Nov 2019 19:20:31 +0100 From: Miquel Raynal To: Boris Brezillon Cc: Chuanhong Guo , linux-mtd@lists.infradead.org, Jeff Kletsky , Richard Weinberger , David Woodhouse , Brian Norris , Vignesh Raghavendra , Frieder Schrempf , Boris Brezillon , Stefan Roese , open list Subject: Re: [PATCH][RFC] mtd: spinand: fix detection of GD5FxGQ4xA flash Message-ID: <20191105192031.2847438c@xps13> In-Reply-To: <20191103142741.7b2a2bf0@collabora.com> References: <20191016013845.23508-1-gch981213@gmail.com> <20191028174131.65c3d580@xps13> <20191103142741.7b2a2bf0@collabora.com> Organization: Bootlin X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Boris, Boris Brezillon wrote on Sun, 3 Nov 2019 14:27:41 +0100: > On Sun, 3 Nov 2019 20:03:21 +0800 > Chuanhong Guo wrote: > > > Hi! > > > > On Tue, Oct 29, 2019 at 12:41 AM Miquel Raynal > > wrote: > > > > > > Hello, > > > > > > Chuanhong Guo wrote on Wed, 16 Oct 2019 09:38:24 > > > +0800: > > > > > > > GD5FxGQ4xA didn't follow the SPI spec to keep MISO low while slave is > > > > reading, and instead MISO is kept high. As a result, the first byte > > > > of id becomes 0xFF. > > > > Since the first byte isn't supposed to be checked at all, this patch > > > > just removed that check. > > > > > > > > While at it, redo the comment above to better explain what's happening. > > > > > > > > Fixes: cfd93d7c908e ("mtd: spinand: Add support for GigaDevice GD5F1GQ4UFxxG") > > > > Signed-off-by: Chuanhong Guo > > > > CC: Jeff Kletsky > > > > --- > > > > RFC: > > > > I doubt whether this patch is a proper fix for the underlying problem: > > > > The actual problem is that we have two different implementation of read id > > > > command: One replies immediately after master sending 0x9f and the other > > > > need to send 0x9f and an offset byte (found in winbond and early GD flashes.) > > > > Correction: Only early GigaDevice nand chips uses this implementation. > > Winbond chips uses a dummy byte instead of an address byte so there's > > no problem for Winbond chips. > > > > > > Current code only works if SPI master is properly implemented (i.e. keep MOSI > > > > low while reading.) > > > > > > I am not entirely against the fix, but this is a SPI host controller > > > issue, right? Can you try to fix the controller driver instead? > > > > I think this is a spi nand framework issue. GigaDevice uses an unusual > > READ ID implementation, and as a result, both host controller and chip > > are reading during the first byte after 0x9f command: chip is reading > > the address/offset byte and host is expecting the first ID byte. > > Here lies two problems: > > 1. According to the sequence diagram in their datasheet, MISO pin is > > in High-Z state during the 0x9f command and the offset byte, and host > > could read anything during this time instead of a fixed 0x0 or 0xff > > byte, so the check of first byte should be removed. This is what this > > patch is doing. > > 2. If there's a buggy SPI host controller that didn't keep MOSI low > > during reading operation, the chip will get 0xff as ID offset, causing > > the read vendor/device ID to be swapped. I never met such a controller > > so far, but if there is one, it will be a silicon bug that can't be > > fixed by software. To fix this one, we'll have to make a second > > read-id implementation in spi nand framework. > > I realize how fragile this ID-based detection is when manufacturers > decide to not follow the standard READID semantic (one 0x9f command byte > followed by 1 or more input cycles encoding the ID). Let's imagine you > have a valid manuf ID byte in ID[0], and the device ID (ID[1]) matches > the Winbond or Gigadevice manufacturer ID, and ID[3] (extended Device ID > byte?) matches a valid Winbond/Gigadevice device ID. If you skip the > check on ID[0] you might erroneously detect a Winbond or Gigadevice > NAND, while it's actually something else. > > Note that I don't really have a solution to make this detection more > robust. > > > > > The second problem only exist in theory, so my preference is to apply > > this patch and fix only the first problem for now. > > I think we should fix that problem now. Maybe by doing a 3 steps > detection: > > 1/ READID + ID[] > 2/ READID + DUMMY + ID[] > 3/ READID + ADDR + ID[] > > At each step we would check if the returned ID matches a valid NAND, > and if it does, stop there. I like the idea. That will be way more robust. Thanks, Miquèl