Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934588AbdC3S7H (ORCPT ); Thu, 30 Mar 2017 14:59:07 -0400 Received: from 20.mo4.mail-out.ovh.net ([46.105.33.73]:54364 "EHLO 20.mo4.mail-out.ovh.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933406AbdC3S7F (ORCPT ); Thu, 30 Mar 2017 14:59:05 -0400 X-Greylist: delayed 4715 seconds by postgrey-1.27 at vger.kernel.org; Thu, 30 Mar 2017 14:59:05 EDT Subject: Re: [PATCH V1 1/1] mtd: mtk-nor: set controller to 4B mode with large capacity flash To: Guochun Mao , Boris Brezillon , Marek Vasut References: <1490862222-723-1-git-send-email-guochun.mao@mediatek.com> <1490862222-723-2-git-send-email-guochun.mao@mediatek.com> Cc: Mark Rutland , devicetree@vger.kernel.org, Richard Weinberger , Russell King , linux-kernel@vger.kernel.org, Rob Herring , linux-mtd@lists.infradead.org, Matthias Brugger , linux-mediatek@lists.infradead.org, Cyrille Pitchen , David Woodhouse , linux-arm-kernel@lists.infradead.org From: Cyrille Pitchen Message-ID: <24d60072-4124-7ec4-6cd3-fd70f4f6b10a@wedev4u.fr> Date: Thu, 30 Mar 2017 19:40:09 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <1490862222-723-2-git-send-email-guochun.mao@mediatek.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 8bit X-Ovh-Tracer-Id: 4830955029484034044 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeelhedrkeelgdduudejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2065 Lines: 56 Hi Guochun, Le 30/03/2017 ? 10:23, Guochun Mao a ?crit : > when nor's size larger than 16MByte, nor and controller should > enter 4Byte mode simultaneously. > > Signed-off-by: Guochun Mao > --- > drivers/mtd/spi-nor/mtk-quadspi.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/drivers/mtd/spi-nor/mtk-quadspi.c b/drivers/mtd/spi-nor/mtk-quadspi.c > index e661877..05cd8a8 100644 > --- a/drivers/mtd/spi-nor/mtk-quadspi.c > +++ b/drivers/mtd/spi-nor/mtk-quadspi.c > @@ -369,6 +369,13 @@ static int mt8173_nor_write_reg(struct spi_nor *nor, u8 opcode, u8 *buf, > /* We only handle 1 byte */ > ret = mt8173_nor_wr_sr(mt8173_nor, *buf); > break; > + case SPINOR_OP_EN4B: > + /* Set nor controller to 4-byte address mode, > + * and simultaneously set nor flash. > + * This case should cooperate with default operation. > + */ > + writeb(readb(mt8173_nor->base + MTK_NOR_DUAL_REG) | 0x10, > + mt8173_nor->base + MTK_NOR_DUAL_REG); This is not good: you should check in both mt8173_nor_read() and mt8173_nor_write() whether nor->addr_width is either 3 or 4. from include/linux/mtd/spi-nor.h: * @addr_width: number of address bytes Besides SPI commands using an op code from 4-byte address instruction set always carry a 4-byte address. They can be used directly, without sending the SPINOR_OP_EN4B before. So you cannot assume that addresses will be 4-byte long only if your SPI controller driver has seen a SPINOR_OP_EN4B command before. This assumption is wrong. SPI controller driver should never check SPINOR_OP_* op codes like this. Then, testing SPINOR_OP_RDSR from mt8173_nor_read_reg() or SPINOR_OP_WRSR from mt8173_nor_write_reg() is not a good practice too: op codes may change depending on the memory manufacturer. So testing op code values like you do can work with some memories but maybe not all. Finally, don't use 0x10, please define a macro instead. Best regards, Cyrille > default: > ret = mt8173_nor_do_tx_rx(mt8173_nor, opcode, buf, len, NULL, 0); > if (ret) >