From 7693fb37564422b2e0ec9717deab7ca51a093f4e Mon Sep 17 00:00:00 2001 From: Jagan Teki Date: Wed, 4 Nov 2015 13:01:59 +0530 Subject: sf: Remove eeprom_m95xxx test driver The relevent boards which used this driver got zapped in previous release and the driver is never used in the code and also it doesn't use/do any spi-flash operations. Commit details for relevent removed boards: "ARM: at91: remove non-generic boards" (sha1: f6b42c140387589ded24749781ce565571092eac) Cc: Tom Rini Cc: Albin Tonnerre Signed-off-by: Jagan Teki --- drivers/mtd/spi/Makefile | 1 - drivers/mtd/spi/eeprom_m95xxx.c | 111 ---------------------------------------- 2 files changed, 112 deletions(-) delete mode 100644 drivers/mtd/spi/eeprom_m95xxx.c (limited to 'drivers/mtd/spi') diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile index ff48b25..cf4e7e1 100644 --- a/drivers/mtd/spi/Makefile +++ b/drivers/mtd/spi/Makefile @@ -20,4 +20,3 @@ obj-$(CONFIG_SPI_FLASH) += sf_ops.o sf_params.o obj-$(CONFIG_SPI_FLASH_DATAFLASH) += sf_dataflash.o obj-$(CONFIG_SPI_FLASH_MTD) += sf_mtd.o obj-$(CONFIG_SPI_FLASH_SANDBOX) += sandbox.o -obj-$(CONFIG_SPI_M95XXX) += eeprom_m95xxx.o diff --git a/drivers/mtd/spi/eeprom_m95xxx.c b/drivers/mtd/spi/eeprom_m95xxx.c deleted file mode 100644 index a019939..0000000 --- a/drivers/mtd/spi/eeprom_m95xxx.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2009 - * Albin Tonnerre, Free Electrons - * - * SPDX-License-Identifier: GPL-2.0+ - */ - -#include -#include - -#define SPI_EEPROM_WREN 0x06 -#define SPI_EEPROM_RDSR 0x05 -#define SPI_EEPROM_READ 0x03 -#define SPI_EEPROM_WRITE 0x02 - -#ifndef CONFIG_DEFAULT_SPI_BUS -#define CONFIG_DEFAULT_SPI_BUS 0 -#endif - -#ifndef CONFIG_DEFAULT_SPI_MODE -#define CONFIG_DEFAULT_SPI_MODE SPI_MODE_0 -#endif - -#ifndef CONFIG_SYS_SPI_WRITE_TOUT -#define CONFIG_SYS_SPI_WRITE_TOUT (5 * CONFIG_SYS_HZ) -#endif - -ssize_t spi_read(uchar *addr, int alen, uchar *buffer, int len) -{ - struct spi_slave *slave; - u8 cmd = SPI_EEPROM_READ; - - slave = spi_setup_slave(CONFIG_DEFAULT_SPI_BUS, 1, 1000000, - CONFIG_DEFAULT_SPI_MODE); - if (!slave) - return 0; - - spi_claim_bus(slave); - - /* command */ - if (spi_xfer(slave, 8, &cmd, NULL, SPI_XFER_BEGIN)) - return -1; - - /* - * if alen == 3, addr[0] is the block number, we never use it here. - * All we need are the lower 16 bits. - */ - if (alen == 3) - addr++; - - /* address, and data */ - if (spi_xfer(slave, 16, addr, NULL, 0)) - return -1; - if (spi_xfer(slave, 8 * len, NULL, buffer, SPI_XFER_END)) - return -1; - - spi_release_bus(slave); - spi_free_slave(slave); - return len; -} - -ssize_t spi_write(uchar *addr, int alen, uchar *buffer, int len) -{ - struct spi_slave *slave; - char buf[3]; - ulong start; - - slave = spi_setup_slave(CONFIG_DEFAULT_SPI_BUS, 1, 1000000, - CONFIG_DEFAULT_SPI_MODE); - if (!slave) - return 0; - - spi_claim_bus(slave); - - buf[0] = SPI_EEPROM_WREN; - if (spi_xfer(slave, 8, buf, NULL, SPI_XFER_BEGIN | SPI_XFER_END)) - return -1; - - buf[0] = SPI_EEPROM_WRITE; - - /* As for reading, drop addr[0] if alen is 3 */ - if (alen == 3) { - alen--; - addr++; - } - - memcpy(buf + 1, addr, alen); - /* command + addr, then data */ - if (spi_xfer(slave, 24, buf, NULL, SPI_XFER_BEGIN)) - return -1; - if (spi_xfer(slave, len * 8, buffer, NULL, SPI_XFER_END)) - return -1; - - start = get_timer(0); - do { - buf[0] = SPI_EEPROM_RDSR; - buf[1] = 0; - spi_xfer(slave, 16, buf, buf, SPI_XFER_BEGIN | SPI_XFER_END); - - if (!(buf[1] & 1)) - break; - - } while (get_timer(start) < CONFIG_SYS_SPI_WRITE_TOUT); - - if (buf[1] & 1) - printf("*** spi_write: Timeout while writing!\n"); - - spi_release_bus(slave); - spi_free_slave(slave); - return len; -} -- cgit v1.1 From 5168721e584e1fc104ccc3b1a027e8973a18f65b Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Tue, 17 Nov 2015 16:50:53 -0200 Subject: sf: Add lock ops for SST SPI NOR flash SST SPI NOR flash has the same locking programming bits as ST Micro - added support for it. Signed-off-by: Fabio Estevam [Minor change on commit message] Signed-off-by: Jagan Teki Reviewed-by: Jagan Teki --- drivers/mtd/spi/sf_internal.h | 1 + drivers/mtd/spi/sf_ops.c | 4 ++-- drivers/mtd/spi/sf_probe.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'drivers/mtd/spi') diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h index 8793f18..85c8a89 100644 --- a/drivers/mtd/spi/sf_internal.h +++ b/drivers/mtd/spi/sf_internal.h @@ -64,6 +64,7 @@ enum spi_nor_option_flags { #define SPI_FLASH_CFI_MFR_SPANSION 0x01 #define SPI_FLASH_CFI_MFR_STMICRO 0x20 #define SPI_FLASH_CFI_MFR_MACRONIX 0xc2 +#define SPI_FLASH_CFI_MFR_SST 0xbf #define SPI_FLASH_CFI_MFR_WINBOND 0xef /* Erase commands */ diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c index 384224d..4065520 100644 --- a/drivers/mtd/spi/sf_ops.c +++ b/drivers/mtd/spi/sf_ops.c @@ -583,7 +583,7 @@ int sst_write_bp(struct spi_flash *flash, u32 offset, size_t len, } #endif -#ifdef CONFIG_SPI_FLASH_STMICRO +#if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST) static void stm_get_locked_range(struct spi_flash *flash, u8 sr, loff_t *ofs, u32 *len) { @@ -750,4 +750,4 @@ int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len) return 0; } -#endif /* CONFIG_SPI_FLASH_STMICRO */ +#endif diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index bc05d30..52dace4 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -184,8 +184,9 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, /* lock hooks are flash specific - assign them based on idcode0 */ switch (idcode[0]) { -#ifdef CONFIG_SPI_FLASH_STMICRO +#if defined(CONFIG_SPI_FLASH_STMICRO) || defined(CONFIG_SPI_FLASH_SST) case SPI_FLASH_CFI_MFR_STMICRO: + case SPI_FLASH_CFI_MFR_SST: flash->flash_lock = stm_lock; flash->flash_unlock = stm_unlock; flash->flash_is_locked = stm_is_locked; -- cgit v1.1 From a668a164ffb73db6f566f50e9440c872d5293742 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Tue, 17 Nov 2015 17:13:33 -0200 Subject: spi: sf_ops: Check the return value from spi_flash_cmd_read_status() We should check the return value from spi_flash_cmd_read_status() and propagate it in the case of error. This fixes a defect caught by Coverity. Reported-by: Tom Rini Signed-off-by: Fabio Estevam Reviewed-by: Jagan Teki --- drivers/mtd/spi/sf_ops.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'drivers/mtd/spi') diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c index 4065520..3a56d7f 100644 --- a/drivers/mtd/spi/sf_ops.c +++ b/drivers/mtd/spi/sf_ops.c @@ -663,8 +663,11 @@ int stm_lock(struct spi_flash *flash, u32 ofs, size_t len) u8 status_old, status_new; u8 mask = SR_BP2 | SR_BP1 | SR_BP0; u8 shift = ffs(mask) - 1, pow, val; + int ret; - spi_flash_cmd_read_status(flash, &status_old); + ret = spi_flash_cmd_read_status(flash, &status_old); + if (ret < 0) + return ret; /* SPI NOR always locks to the end */ if (ofs + len != flash->size) { @@ -714,8 +717,11 @@ int stm_unlock(struct spi_flash *flash, u32 ofs, size_t len) uint8_t status_old, status_new; u8 mask = SR_BP2 | SR_BP1 | SR_BP0; u8 shift = ffs(mask) - 1, pow, val; + int ret; - spi_flash_cmd_read_status(flash, &status_old); + ret = spi_flash_cmd_read_status(flash, &status_old); + if (ret < 0) + return ret; /* Cannot unlock; would unlock larger region than requested */ if (stm_is_locked_sr(flash, status_old, ofs - flash->erase_size, -- cgit v1.1 From 3e56ecec435d30e25fcffb971f8c9627e85ac1df Mon Sep 17 00:00:00 2001 From: Bin Meng Date: Sun, 15 Nov 2015 19:31:37 -0800 Subject: sf: Correct flash->flags for SST flash flash->flags for SST flash should be updated for both DM and non-DM flash drivers. Signed-off-by: Bin Meng Reviewed-by: Jagan Teki --- drivers/mtd/spi/sf_probe.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'drivers/mtd/spi') diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 52dace4..a619182 100644 --- a/drivers/mtd/spi/sf_probe.c +++ b/drivers/mtd/spi/sf_probe.c @@ -164,14 +164,15 @@ static int spi_flash_validate_params(struct spi_slave *spi, u8 *idcode, flash->memory_map = spi->memory_map; flash->dual_flash = flash->spi->option; + /* Assign spi flash flags */ + if (params->flags & SST_WR) + flash->flags |= SNOR_F_SST_WR; + /* Assign spi_flash ops */ #ifndef CONFIG_DM_SPI_FLASH flash->write = spi_flash_cmd_write_ops; #if defined(CONFIG_SPI_FLASH_SST) - if (params->flags & SST_WR) - flash->flags |= SNOR_F_SST_WR; - - if (params->flags & SNOR_F_SST_WR) { + if (flash->flags & SNOR_F_SST_WR) { if (flash->spi->op_mode_tx & SPI_OPM_TX_BP) flash->write = sst_write_bp; else -- cgit v1.1