From a0dd6f4332542fb72ed525a201fbd6b549fba3e8 Mon Sep 17 00:00:00 2001 From: Santan Kumar Date: Wed, 7 Feb 2018 18:29:52 +0530 Subject: [PATCH] qca: spi-nor: Store the probe information to avoid unnecessary probes Change-Id: If7260e4a4065d6406d9a8554f43853663f0e8f3b Signed-off-by: Santan Kumar --- common/cmd_sf.c | 3 +-- common/env_sf.c | 3 --- drivers/mtd/spi/sf_probe.c | 20 ++++++++++++++++---- include/spi_flash.h | 2 ++ 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/common/cmd_sf.c b/common/cmd_sf.c index 42862d9d92..7815bdc269 100644 --- a/common/cmd_sf.c +++ b/common/cmd_sf.c @@ -135,8 +135,7 @@ static int do_spi_flash_probe(int argc, char * const argv[]) flash = dev_get_uclass_priv(new); #else - if (flash) - spi_flash_free(flash); + spi_flash_free(flash); new = spi_flash_probe(bus, cs, speed, mode); flash = new; diff --git a/common/env_sf.c b/common/env_sf.c index 8463f261b8..d079aaf085 100644 --- a/common/env_sf.c +++ b/common/env_sf.c @@ -214,8 +214,6 @@ void sf_env_relocate_spec(void) } err_read: - spi_flash_free(env_flash); - env_flash = NULL; out: free(tmp_env1); free(tmp_env2); @@ -316,7 +314,6 @@ void sf_env_relocate_spec(void) if (ret) gd->env_valid = 1; out: - spi_flash_free(env_flash); if (buf) free(buf); env_flash = NULL; diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 0cafc29123..071c42d236 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -17,6 +17,8 @@ #include "sf_internal.h" +struct spi_flash *spi_flash_ptr[MAX_SF_BUS_NUM][MAX_SF_CS_NUM] = {NULL}; + /** * spi_flash_probe_slave() - Probe for a SPI flash device on a bus * @@ -83,10 +85,16 @@ struct spi_flash *spi_flash_probe(unsigned int busnum, unsigned int cs, { struct spi_slave *bus; + if (spi_flash_ptr[busnum][cs] != NULL) + return spi_flash_ptr[busnum][cs]; + bus = spi_setup_slave(busnum, cs, max_hz, spi_mode); if (!bus) return NULL; - return spi_flash_probe_tail(bus); + + spi_flash_ptr[busnum][cs] = spi_flash_probe_tail(bus); + + return spi_flash_ptr[busnum][cs]; } #ifdef CONFIG_OF_SPI_FLASH @@ -104,11 +112,15 @@ struct spi_flash *spi_flash_probe_fdt(const void *blob, int slave_node, void spi_flash_free(struct spi_flash *flash) { + if (flash) { #ifdef CONFIG_SPI_FLASH_MTD - spi_flash_mtd_unregister(); + spi_flash_mtd_unregister(); #endif - spi_free_slave(flash->spi); - free(flash); + spi_free_slave(flash->spi); + free(flash); + } + + memset(spi_flash_ptr, NULL, sizeof(spi_flash_ptr)); } #else /* defined CONFIG_DM_SPI_FLASH */ diff --git a/include/spi_flash.h b/include/spi_flash.h index 4a51b5f441..995d1232fb 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -30,6 +30,8 @@ #ifndef CONFIG_SF_DEFAULT_BUS # define CONFIG_SF_DEFAULT_BUS 0 #endif +#define MAX_SF_BUS_NUM 5 +#define MAX_SF_CS_NUM 5 struct spi_slave;