From patchwork Wed May 18 06:46:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Patrice CHOTARD X-Patchwork-Id: 1632627 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.a=rsa-sha256 header.s=selector1 header.b=ZS0+0bYo; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L33T61YTDz9sBF for ; Wed, 18 May 2022 16:47:38 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A6AB884286; Wed, 18 May 2022 08:47:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=foss.st.com header.i=@foss.st.com header.b="ZS0+0bYo"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id AD47F84278; Wed, 18 May 2022 08:47:13 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mx07-00178001.pphosted.com (mx08-00178001.pphosted.com [91.207.212.93]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C614C83C96 for ; Wed, 18 May 2022 08:47:04 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=foss.st.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=11372af201=patrice.chotard@foss.st.com Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24I3T7qM017719; Wed, 18 May 2022 08:46:53 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type : content-transfer-encoding; s=selector1; bh=ACG9z3qVS3vJxrw8fXYoo9xdmfwsH8faEQ0tNRImbYA=; b=ZS0+0bYodxki1i9UtiXdMOh85Z/JrraVbD2D40N8ERGHkIHNnpfmG1KdoWA04Sms19dK NMKuBYFg5JLqCuh77nVEK9zj/vvuZMVFlvHFO+LY/4HTGmK+lHKArtDnVNdrh6bci9hd UXneRgFO5Hfydz/4hA3T8NU+onGW9HOzxPPF6BtmLjrm+BkcML6pHOo50oDlgIM3GERA 9kL6iANo0Q5xTj5KoHm5YGdo5X5o+ZNzCgIuNGn8mCdYFckmwBlX+i0gzXsEhMFAzMmH H00RqYpGcUrtw3d06nh9yk3v4qs+4b7ufS9y0/KY87a9f1VabMAmwYP/AFpn2m3vqgKJ tw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com (PPS) with ESMTPS id 3g21j8yc4n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 18 May 2022 08:46:53 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id B9617100038; Wed, 18 May 2022 08:46:51 +0200 (CEST) Received: from Webmail-eu.st.com (shfdag1node1.st.com [10.75.129.69]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id AD0A120FA5A; Wed, 18 May 2022 08:46:51 +0200 (CEST) Received: from localhost (10.75.127.45) by SHFDAG1NODE1.st.com (10.75.129.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Wed, 18 May 2022 08:46:51 +0200 From: Patrice Chotard To: CC: Patrice CHOTARD , Patrick DELAUNAY , U-Boot STM32 , Marek Behun , Jagan Teki , Vignesh R , Joe Hershberger , Ramon Fried , Lukasz Majewski , Marek Vasut , Wolfgang Denk , Simon Glass , Stefan Roese , =?utf-8?q?Pali_R?= =?utf-8?q?oh=C3=A1r?= , Konstantin Porotchkin , Igal Liberman , Bin Meng , Pratyush Yadav , Sean Anderson , Anji J , Biwen Li , Priyanka Jain , Chaitanya Sakinam , Heinrich Schuchardt , Jassi Brar Subject: [RESEND PATCH v4 2/3] spi: spi_flash_probe_bus_cs() rely on DT for spi speed and mode Date: Wed, 18 May 2022 08:46:47 +0200 Message-ID: <20220518064648.1843664-3-patrice.chotard@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220518064648.1843664-1-patrice.chotard@foss.st.com> References: <20220518064648.1843664-1-patrice.chotard@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SHFDAG1NODE1.st.com (10.75.129.69) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-18_02,2022-05-17_02,2022-02-23_01 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 at phobos.denx.de X-Virus-Status: Clean Now, spi_flash_probe_bus_cs() relies on DT for spi speed and mode and logically calls spi_get_bus_and_cs(). In case spi mode and speed are not read from DT, make usage of spi_flash_probe() instead. To sum-up: - Previous call tree was: spi_flash_probe() -> spi_flash_probe_bus_cs() -> spi_get_bus_and_cs() - Current call tree is: spi_flash_probe() -> _spi_get_bus_and_cs() spi_flash_probe_bus_cs() -> spi_get_bus_and_cs() This patch impacts the following : - cmd/sf.c: if spi mode and/or speed is passed in argument of do_spi_flash_probe(), call spi_flash_probe() otherwise call spi_flash_probe_bus_cs(). - drivers/net/fm/fm.c: as by default spi speed and mode was set to 0 and a comment indicates that speed and mode are read from DT, use spi_flash_probe_bus_cs(). - drivers/net/pfe_eth/pfe_firmware.c: spi speed and mode are not read from DT by all platforms using this driver, so keep legacy and replace spi_flash_probe_bus_cs() by spi_flash_probe(); - drivers/net/sni_netsec.c : spi speed and mode are not read from DT, so replace spi_flash_probe_bus_cs() by spi_flash_probe(). - drivers/usb/gadget/max3420_udc.c: Can't find any platform which make usage of this driver, nevertheless, keep legacy and replace spi_get_bus_and_cs() by _spi_get_bus_and_cs(). - env/sf.c: a comment indicates that speed and mode are read from DT. So use spi_flash_probe_bus_cs(). Signed-off-by: Patrice Chotard Cc: Marek Behun Cc: Jagan Teki Cc: Vignesh R Cc: Joe Hershberger Cc: Ramon Fried Cc: Lukasz Majewski Cc: Marek Vasut Cc: Wolfgang Denk Cc: Simon Glass Cc: Stefan Roese Cc: "Pali Rohár" Cc: Konstantin Porotchkin Cc: Igal Liberman Cc: Bin Meng Cc: Pratyush Yadav Cc: Sean Anderson Cc: Anji J Cc: Biwen Li Cc: Priyanka Jain Cc: Chaitanya Sakinam --- Changes in v4: - Split previous series in 3 patches - Update commit message with additionnal information Changes in v3: - Update commit header to reflect what the patch really do. - Rename legacy spi_get_bus_and_cs() to _spi_get_bus_and_cs(). - New spi_get_bus_and_cs() rely on DT for spi speed and mode values. - spi_flash_probe_bus_cs() rely also on DT for spi and mode values. Changes in v2: - add spi_flash_probe_bus_cs_default() which calls spi_get_bus_and_cs() with "use_dt" param set to true, whereas spi_flash_probe_bus_cs() calls spi_get_bus_and_cs() with "use_dt" param set to true. cmd/sf.c | 15 ++++++++++---- drivers/mtd/spi/sf-uclass.c | 33 +++++++++++++++--------------- drivers/net/fm/fm.c | 4 ++-- drivers/net/pfe_eth/pfe_firmware.c | 19 ++++------------- drivers/net/sni_netsec.c | 6 ++---- env/sf.c | 1 - include/spi_flash.h | 1 - 7 files changed, 36 insertions(+), 43 deletions(-) diff --git a/cmd/sf.c b/cmd/sf.c index 8bdebd9fd8..8713736b2a 100644 --- a/cmd/sf.c +++ b/cmd/sf.c @@ -91,6 +91,7 @@ static int do_spi_flash_probe(int argc, char *const argv[]) unsigned int speed = CONFIG_SF_DEFAULT_SPEED; unsigned int mode = CONFIG_SF_DEFAULT_MODE; char *endp; + bool use_dt = true; #if CONFIG_IS_ENABLED(DM_SPI_FLASH) struct udevice *new, *bus_dev; int ret; @@ -117,11 +118,13 @@ static int do_spi_flash_probe(int argc, char *const argv[]) speed = simple_strtoul(argv[2], &endp, 0); if (*argv[2] == 0 || *endp != 0) return -1; + use_dt = false; } if (argc >= 4) { mode = hextoul(argv[3], &endp); if (*argv[3] == 0 || *endp != 0) return -1; + use_dt = false; } #if CONFIG_IS_ENABLED(DM_SPI_FLASH) @@ -131,14 +134,18 @@ static int do_spi_flash_probe(int argc, char *const argv[]) device_remove(new, DM_REMOVE_NORMAL); } flash = NULL; - ret = spi_flash_probe_bus_cs(bus, cs, speed, mode, &new); - if (ret) { + if (use_dt) { + spi_flash_probe_bus_cs(bus, cs, &new); + flash = dev_get_uclass_priv(new); + } else { + flash = spi_flash_probe(bus, cs, speed, mode); + } + + if (!flash) { printf("Failed to initialize SPI flash at %u:%u (error %d)\n", bus, cs, ret); return 1; } - - flash = dev_get_uclass_priv(new); #else if (flash) spi_flash_free(flash); diff --git a/drivers/mtd/spi/sf-uclass.c b/drivers/mtd/spi/sf-uclass.c index b45ba54ebf..e6e650ef8c 100644 --- a/drivers/mtd/spi/sf-uclass.c +++ b/drivers/mtd/spi/sf-uclass.c @@ -46,25 +46,12 @@ int spl_flash_get_sw_write_prot(struct udevice *dev) * TODO(sjg@chromium.org): This is an old-style function. We should remove * it when all SPI flash drivers use dm */ -struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, +struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs, unsigned int max_hz, unsigned int spi_mode) -{ - struct udevice *dev; - - if (spi_flash_probe_bus_cs(bus, cs, max_hz, spi_mode, &dev)) - return NULL; - - return dev_get_uclass_priv(dev); -} - -int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode, - struct udevice **devp) { struct spi_slave *slave; struct udevice *bus; char *str; - int ret; #if defined(CONFIG_SPL_BUILD) && CONFIG_IS_ENABLED(USE_TINY_PRINTF) str = "spi_flash"; @@ -74,8 +61,22 @@ int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, snprintf(name, sizeof(name), "spi_flash@%d:%d", busnum, cs); str = strdup(name); #endif - ret = _spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode, - "jedec_spi_nor", str, &bus, &slave); + + if (_spi_get_bus_and_cs(busnum, cs, max_hz, spi_mode, + "jedec_spi_nor", str, &bus, &slave)) + return NULL; + + return dev_get_uclass_priv(slave->dev); +} + +int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, + struct udevice **devp) +{ + struct spi_slave *slave; + struct udevice *bus; + int ret; + + ret = spi_get_bus_and_cs(busnum, cs, &bus, &slave); if (ret) return ret; diff --git a/drivers/net/fm/fm.c b/drivers/net/fm/fm.c index f825612640..d0b492b5a1 100644 --- a/drivers/net/fm/fm.c +++ b/drivers/net/fm/fm.c @@ -388,7 +388,7 @@ int fm_init_common(int index, struct ccsr_fman *reg) /* speed and mode will be read from DT */ ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, - CONFIG_SF_DEFAULT_CS, 0, 0, &new); + CONFIG_SF_DEFAULT_CS, &new); ucode_flash = dev_get_uclass_priv(new); #else @@ -475,7 +475,7 @@ int fm_init_common(int index, struct ccsr_fman *reg) /* speed and mode will be read from DT */ ret = spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, - 0, 0, &new); + &new); ucode_flash = dev_get_uclass_priv(new); #else diff --git a/drivers/net/pfe_eth/pfe_firmware.c b/drivers/net/pfe_eth/pfe_firmware.c index 6669048181..82a4aa89a4 100644 --- a/drivers/net/pfe_eth/pfe_firmware.c +++ b/drivers/net/pfe_eth/pfe_firmware.c @@ -172,31 +172,20 @@ static int pfe_fit_check(void) int pfe_spi_flash_init(void) { struct spi_flash *pfe_flash; - struct udevice *new; int ret = 0; void *addr = malloc(CONFIG_SYS_LS_PFE_FW_LENGTH); if (!addr) return -ENOMEM; - ret = spi_flash_probe_bus_cs(CONFIG_SYS_FSL_PFE_SPI_BUS, - CONFIG_SYS_FSL_PFE_SPI_CS, - CONFIG_SYS_FSL_PFE_SPI_MAX_HZ, - CONFIG_SYS_FSL_PFE_SPI_MODE, - &new); - if (ret) { - printf("SF: failed to probe spi\n"); - free(addr); - device_remove(new, DM_REMOVE_NORMAL); - return ret; - } - + pfe_flash = spi_flash_probe(CONFIG_SYS_FSL_PFE_SPI_BUS, + CONFIG_SYS_FSL_PFE_SPI_CS, + CONFIG_SYS_FSL_PFE_SPI_MAX_HZ, + CONFIG_SYS_FSL_PFE_SPI_MODE); - pfe_flash = dev_get_uclass_priv(new); if (!pfe_flash) { printf("SF: probe for pfe failed\n"); free(addr); - device_remove(new, DM_REMOVE_NORMAL); return -ENODEV; } diff --git a/drivers/net/sni_netsec.c b/drivers/net/sni_netsec.c index 24caacf847..9780f2092b 100644 --- a/drivers/net/sni_netsec.c +++ b/drivers/net/sni_netsec.c @@ -621,12 +621,10 @@ static int netsec_stop_gmac(struct netsec_priv *priv) static void netsec_spi_read(char *buf, loff_t len, loff_t offset) { - struct udevice *new; struct spi_flash *flash; - spi_flash_probe_bus_cs(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, - CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE, &new); - flash = dev_get_uclass_priv(new); + flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS, CONFIG_SF_DEFAULT_CS, + CONFIG_SF_DEFAULT_SPEED, CONFIG_SF_DEFAULT_MODE); spi_flash_read(flash, offset, len, buf); } diff --git a/env/sf.c b/env/sf.c index d2c07cd716..4b768542c1 100644 --- a/env/sf.c +++ b/env/sf.c @@ -48,7 +48,6 @@ static int setup_flash_device(struct spi_flash **env_flash) /* speed and mode will be read from DT */ ret = spi_flash_probe_bus_cs(CONFIG_ENV_SPI_BUS, CONFIG_ENV_SPI_CS, - CONFIG_ENV_SPI_MAX_HZ, CONFIG_ENV_SPI_MODE, &new); if (ret) { env_set_default("spi_flash_probe_bus_cs() failed", 0); diff --git a/include/spi_flash.h b/include/spi_flash.h index d33d0dd46a..10d19fd4b1 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -102,7 +102,6 @@ int spl_flash_get_sw_write_prot(struct udevice *dev); int spi_flash_std_probe(struct udevice *dev); int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, - unsigned int max_hz, unsigned int spi_mode, struct udevice **devp); /* Compatibility function - this is the old U-Boot API */