From 857db48e5f6372eead8a32469d981801e775ee48 Mon Sep 17 00:00:00 2001 From: Vignesh R Date: Tue, 10 Nov 2015 11:52:10 +0530 Subject: spi: ti_qspi: Add dummy readl for bus sync Add dummy readl after invalidating cmd field of QSPI_CMD_REG to ensure bus sync. Without this device's CS is not deactivated reliably leading to failure to enumerate flash or failure to set quad enable bit on Macronix flash present on am437x-sk and am437x-idk evms. Signed-off-by: Vignesh R Reviewed-by: Mugunthan V N Reviewed-by: Jagan Teki --- drivers/spi/ti_qspi.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/spi/ti_qspi.c b/drivers/spi/ti_qspi.c index ecd9d78ae3..646dd899d3 100644 --- a/drivers/spi/ti_qspi.c +++ b/drivers/spi/ti_qspi.c @@ -170,6 +170,8 @@ void spi_cs_deactivate(struct spi_slave *slave) debug("spi_cs_deactivate: 0x%08x\n", (u32)slave); writel(qslave->cmd | QSPI_INVAL, &qslave->base->cmd); + /* dummy readl to ensure bus sync */ + readl(&qslave->base->cmd); } void spi_init(void) -- cgit 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') diff --git a/drivers/mtd/spi/Makefile b/drivers/mtd/spi/Makefile index ff48b25f6f..cf4e7e1f42 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 a019939b8b..0000000000 --- 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 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') diff --git a/drivers/mtd/spi/sf_internal.h b/drivers/mtd/spi/sf_internal.h index 8793f1865a..85c8a89cee 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 384224d75a..4065520726 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 bc05d30221..52dace42ee 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 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') diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c index 4065520726..3a56d7f55c 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 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') diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c index 52dace42ee..a619182a75 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