Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 62B8BC433F5 for ; Wed, 15 Sep 2021 17:56:16 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 85288610E9 for ; Wed, 15 Sep 2021 17:56:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 85288610E9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 40D4582D52; Wed, 15 Sep 2021 19:56:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=konsulko.com header.i=@konsulko.com header.b="EHkSXKbx"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7834482D52; Wed, 15 Sep 2021 19:56:05 +0200 (CEST) Received: from mail-qv1-xf30.google.com (mail-qv1-xf30.google.com [IPv6:2607:f8b0:4864:20::f30]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8A9FA82C2B for ; Wed, 15 Sep 2021 19:55:59 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=konsulko.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=trini@konsulko.com Received: by mail-qv1-xf30.google.com with SMTP id 62so2396043qvb.11 for ; Wed, 15 Sep 2021 10:55:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=W+XNh2qJHcJZXVK/YcDtFFXX2cy5a8nloafYdxE0n1I=; b=EHkSXKbxPRwdlUw04GEyCoI1JdQCMh9KFSsbinl/TtzjMj1rJLdMoF14XTIMQ9UnOk fj3g/izGdHFhekmiFqh/5FsJ3wneIg7JbcTWTyrlk8X4thsPUWeyU/2o3zd5jm5srQes 4ARhryt/3HFyX6ChuYHyZxQqgxyWK5DNBzHzE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=W+XNh2qJHcJZXVK/YcDtFFXX2cy5a8nloafYdxE0n1I=; b=Cm8Nn7hpsNmPgccG+Kt1r/O2OQ26N9VLbGY0mWKzb58N5hoIZfq436ZWKBPJ6RigPG EtmJJDxgQyKOuZLy+SBv7K9R+/cUOrPY0hi0aMJ7PJosCTycexcq5mSlCNyNDOMuw4/z tJtu9RTaS0PjnbCuThbxjwKWINGdoazE5LnsFN13E4fMP+jA17uV1pflZijEDaItadw1 wxNnywYtQaF0x/M4901f8redcTE+4eA5bMUZYhab/0gio9IUgPTeRZ/5v79ePMNaT8+b ujKKgd35xc//KpjZwZHgM4acQl1UBFjMia81sPF/u+Y6j3mQvDXi2+Ff5/AtY1VveGSF 2aRw== X-Gm-Message-State: AOAM533VekjrnA6vFto5TZvbNfPIHsOYScW2Ngc0dav3d5btoCzN2YDs vGEyAfslOYpWaRgF4GZlzNTW+g== X-Google-Smtp-Source: ABdhPJy9HawRCAW/WNgTALArmxp8SXbMlpym8ik873gPw2obAZRffe+ZzlWDT1/FjzSF2sTyQQQlrQ== X-Received: by 2002:a0c:9146:: with SMTP id q64mr1046436qvq.38.1631728558078; Wed, 15 Sep 2021 10:55:58 -0700 (PDT) Received: from bill-the-cat (2603-6081-7b01-cbda-682c-a086-e3f8-65b4.res6.spectrum.com. [2603:6081:7b01:cbda:682c:a086:e3f8:65b4]) by smtp.gmail.com with ESMTPSA id d13sm412086qtm.32.2021.09.15.10.55.56 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 15 Sep 2021 10:55:56 -0700 (PDT) Date: Wed, 15 Sep 2021 13:55:54 -0400 From: Tom Rini To: Marek Vasut Cc: u-boot@lists.denx.de, Aleksandar Gerasimovski , Andreas Biessmann , Eugen Hristev , Michal Simek , Patrice Chotard , Patrick Delaunay , Peng Fan , Siew Chin Lim , Valentin Longchamp , Vignesh Raghavendra Subject: Re: [RFC][PATCH] mtd: spi: Set CONFIG_SF_DEFAULT_MODE default to 0 Message-ID: <20210915175554.GY12964@bill-the-cat> References: <20210914182824.139667-1-marex@denx.de> <20210914191942.GJ12964@bill-the-cat> <895ddad9-92e8-1940-be1d-8d55fb1c6008@denx.de> <20210914204531.GK12964@bill-the-cat> <4d242cc1-9f48-7dec-9edf-9c6121b4d1d0@denx.de> <20210914214425.GL12964@bill-the-cat> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="M5bOZW4AjlnlH/us" Content-Disposition: inline In-Reply-To: <20210914214425.GL12964@bill-the-cat> X-Clacks-Overhead: GNU Terry Pratchett User-Agent: Mutt/1.9.4 (2018-02-28) X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean --M5bOZW4AjlnlH/us Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Sep 14, 2021 at 05:44:25PM -0400, Tom Rini wrote: > On Tue, Sep 14, 2021 at 11:30:01PM +0200, Marek Vasut wrote: > > On 9/14/21 10:45 PM, Tom Rini wrote: > > > On Tue, Sep 14, 2021 at 10:10:22PM +0200, Marek Vasut wrote: > > > > On 9/14/21 9:19 PM, Tom Rini wrote: > > > > > On Tue, Sep 14, 2021 at 08:28:24PM +0200, Marek Vasut wrote: > > > > >=20 > > > > > > Before e2e95e5e254 ("spi: Update speed/mode on change") most sy= stems > > > > > > silently defaulted to SF bus mode 0. Now the mode is always upd= ated, > > > > > > which causes breakage. It seems most SF which are used as boot = media > > > > > > operate in bus mode 0, so switch that as the default. > > > > > >=20 > > > > > > This should fix booting at least on Altera SoCFPGA, ST STM32, X= ilinx > > > > > > ZynqMP, NXP iMX and Rockchip SoCs, which recently ran into trou= ble > > > > > > with mode 3. Marvell Kirkwood and Xilinx microblaze need to be = checked > > > > > > as those might need mode 3. > > > > > >=20 > > > > > > Signed-off-by: Marek Vasut > > > > > > Cc: Aleksandar Gerasimovski > > > > > > Cc: Andreas Biessmann > > > > > > Cc: Eugen Hristev > > > > > > Cc: Michal Simek > > > > > > Cc: Patrice Chotard > > > > > > Cc: Patrick Delaunay > > > > > > Cc: Peng Fan > > > > > > Cc: Siew Chin Lim > > > > > > Cc: Tom Rini > > > > > > Cc: Valentin Longchamp > > > > > > Cc: Vignesh Raghavendra > > > > >=20 > > > > > So, some background. With commit 88e34e5ff76b ("spl: replace > > > > > CONFIG_SPL_SPI_* with CONFIG_SF_DEFAULT_*") CONFIG_SF_DEFAULT_MOD= E and > > > > > related moved from having their default value of SPI_MODE_3 (which > > > > > evaluates to 3) be defined in common/cmd_sf.c if not otherwise de= fined, > > > > > to include/spi_flash.h, and a more visible global default than it= was > > > > > before. At that time, the following platforms either set or impl= ied > > > > > SPI_MODE_3 should be used: > > > > > alt am335x_boneblack am335x_boneblack_vboot am335x_evm_norboot > > > > > am335x_evm_nor am335x_evm am335x_evm_spiboot am335x_evm_usbspl > > > > > am43xx_evm am43xx_evm_qspiboot at91sam9n12ek_mmc at91sam9n12ek_na= ndflash > > > > > at91sam9n12ek_spiflash at91sam9x5ek_dataflash at91sam9x5ek_mmc > > > > > at91sam9x5ek_nandflash at91sam9x5ek_spiflash atstk1004 bf506f-ezk= it > > > > > bf537-stamp cam_enc_4xx coreboot-x86 d2net_v2 da830evm da850_am18= xxevm > > > > > da850evm_direct_nor da850evm dra7xx_evm dra7xx_evm_qspiboot > > > > > dra7xx_evm_uart3 draco dreamplug dxr2 ea20 ecovec ethernut5 gplugd > > > > > inetspace_v2 k2e_evm k2hk_evm kmcoge5un km_kirkwood_128m16 > > > > > km_kirkwood_pci km_kirkwood kmnusa kmsugp1 kmsuv31 koelsch lager = lschlv2 > > > > > lsxhl M53017EVB M54455EVB mgcoge3un mv88f6281gtw_ge net2big_v2 > > > > > netspace_lite_v2 netspace_max_v2 netspace_mini_v2 netspace_v2 > > > > > nios2-generic pcm051_rev1 pcm051_rev3 portl2 pxm2 rut sama5d3xek_= mmc > > > > > sama5d3xek_nandflash sama5d3xek_spiflash sh7785lcr tseries_spi vf= 610twr > > > > > zynq_zc770_xm010 > > > > >=20 > > > > > Of those platforms, I have handy dra7xx_evm (also am335x_evm but = that > > > > > needs flipping some DIP switches) which has SPI flash by default.= With > > > > > current tip of tree, I did "sf probe 0 76800000 3" and a few cycl= es of > > > > > reading the whole of flash and crc32'ing it, and getting the same= result > > > > > back. So, SPI_MODE_3 seems correct / function here, and likely s= o on > > > > > the rest of the TI platforms listed above. > > > > >=20 > > > > > With commit 14453fbfadc2 ("Convert CONFIG_SF_DEFAULT_* to Kconfig= ") we > > > > > migrate these values to Kconfig, and a quick spot-check shows tha= t yes, > > > > > the migration did not change any values. > > > > >=20 > > > > > A big change between 88e34e5ff76b and 14453fbfadc2 is that a ton = of > > > > > platforms have been added (it was 5 years, after all) and those > > > > > platforms seem to be where the problems reside. I'm not sure if = or why > > > > > SPI_MODE_3 doesn't work on so many new platforms, but I would pre= fer to > > > > > see "default 0 if ARCH_SOCFPGA || ARCH_STM32 || .." as needed to = switch > > > > > the default to SPI_MODE_0 if there's not a more fundamental probl= em to > > > > > solve on some platforms such that SPI_MODE_3 could / should be en= abled. > > > >=20 > > > > I rather suspect mode 3 is special case for atmel/am335x and co. an= d maybe > > > > marvell kirkwood from the list above. So shouldn't we default to 0 = and > > > > special-case the two or three instead ? > > >=20 > > > I guess my question boils down to why is that the right default? My > > > argument that 3 is the right default is that it's what it was in > > > introduction back in b6368467e6a9 ("SPI Flash: Add "sf" command"). B= ut > > > references to something else such as the Linux Kernel defaults to mod= e 0 > > > or some SPI specs saying you should default to mode 0 or something el= se > > > would be much appreciated. > >=20 > > Probably check a couple of board schematics and SoC datasheets to build= up > > your own statistics ? In Linux it is 0 because that's likely what most = of > > the systems expect it to be, and the few odd ones just set it to 3 > > explicitly there (or enable CPOL/CPHA as needed). My statistics indicat= es > > that I keep running into "oh, here it is also 3, and it should be 0" > > recently. > >=20 > > I don't have any of the am335x/atmel boards easily available, so I cann= ot > > check those, hence the CC list. >=20 > Sigh, OK. Lets look at the kernel and there instead of SPI_MODE_N we > have spi-cpol and spi-cpha as properties. A quick git grep -l spi-cp > arch/arm arch/arm64 shows where we likely do and do not need to use > something other than mode 0. So yes, mode 0 as a default makes sense, > so long as we also don't break the easily found boards that do need mode > 3 (or, mode 1 or 2, as of v5.19 it is true there's 59 matches for each > property, but it's not always both, sometimes it's one or the other). So, what we need to do is for U-Boot itself, never reference CONFIG_SF_DEFAULT_MODE (and probably none of the other SF_DEFAULT_.. values) as DM handles this correctly via the device tree. That leaves common/spl/spl_spi.c to be handled. If the value is set wrong, we aren't going to be able to have booted via SPL on SPI. So, I'm agreeable to changing the default, so long as we also stop referencing the default in full U-Boot. We've already gone past the DM_SPI convert or be removed release. --=20 Tom --M5bOZW4AjlnlH/us Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQGzBAABCgAdFiEEGjx/cOCPqxcHgJu/FHw5/5Y0tywFAmFCM6YACgkQFHw5/5Y0 tywB6wwArlEqeMVmRoxb29kOF0FWnORGwjm45H2tx4Wqxpt0PXVYRcTfNRZnw2Mb 2/LZ3/itsVi/BL+m2HXI8HpHL+cQqQX+/eQtndPrnesGug6R1BVqGPR22DR0Obbz xQslf0A2TQKDWVT34oy4e77qqIznnJzjGXiynbZi4rKO8AvcQr3h3aSH1ZGb1PWT ihwPYlJtjmCivikLJ+Ar0mkMmLHugnhQcGYR+13h1yh7r3jWpDsg9MWwgufVz6e5 rCP+kitAw3wNBGfUQamLWrn9pSIAkAOH8QUJb8FWPXdtrM99A7AylLapRVQ1obzh 7X7DVD7Ag6F/LNjJ9U5idLA5rwfRS2wSQkDs21hhH5BoDAftpUavucEmixZXZcOV nSomvnRw9WB9hT11uuYDDW4FKsDM+l4wU5pdWX3qRqufRfqQ8zjJ2qH+iuhlv/QY m8T46bBKDbs1JGoDp3O5OKA9Btu42lrlxzqcqNKjAQ+A0XpsLzbnh0pALbRGGusr HbietbuY =6i1C -----END PGP SIGNATURE----- --M5bOZW4AjlnlH/us--