From e4c0f5d485152f555b4d2109e8aa4691a36eb3f5 Mon Sep 17 00:00:00 2001 From: Jagannadha Sutradharudu Teki Date: Tue, 20 Aug 2013 12:52:26 +0530 Subject: [PATCH] sf: Set quad enable bit support This patch provides support to set the quad enable bit on flash. quad enable bit needs to set before performing any quad IO operations on respective SPI flashes. Signed-off-by: Jagannadha Sutradharudu Teki --- drivers/mtd/spi/spi_flash.c | 32 ++++++++++++++++++++++++++++ drivers/mtd/spi/spi_flash_internal.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index baed29b7957..6c266ac1a36 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -407,6 +407,29 @@ int spi_flash_cmd_write_config(struct spi_flash *flash, u8 cr) return 0; } +int spi_flash_set_qeb(struct spi_flash *flash) +{ + u8 qeb_status, cmd; + int ret; + + cmd = CMD_READ_CONFIG; + ret = spi_flash_read_common(flash, &cmd, 1, &qeb_status, 1); + if (ret < 0) { + debug("SF: fail to read config register\n"); + return ret; + } + + if (qeb_status & STATUS_QEB) { + debug("SF: qeb is already set\n"); + } else { + ret = spi_flash_cmd_write_config(flash, STATUS_QEB); + if (ret < 0) + return ret; + } + + return 0; +} + #ifdef CONFIG_SPI_FLASH_BAR int spi_flash_cmd_bankaddr_write(struct spi_flash *flash, u8 bank_sel) { @@ -624,6 +647,15 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, goto err_manufacturer_probe; #endif + /* set the quad enable bit - only for quad commands */ + if ((flash->read_cmd == CMD_READ_QUAD_OUTPUT_FAST) || + (flash->write_cmd == CMD_QUAD_PAGE_PROGRAM)) { + if (spi_flash_set_qeb(flash)) { + debug("SF: Fail to set qeb\n"); + goto err_manufacturer_probe; + } + } + #ifdef CONFIG_OF_CONTROL if (spi_flash_decode_fdt(gd->fdt_blob, flash)) { debug("SF: FDT decode error\n"); diff --git a/drivers/mtd/spi/spi_flash_internal.h b/drivers/mtd/spi/spi_flash_internal.h index 1f105258b78..4d4442343aa 100644 --- a/drivers/mtd/spi/spi_flash_internal.h +++ b/drivers/mtd/spi/spi_flash_internal.h @@ -22,6 +22,7 @@ #define CMD_PAGE_PROGRAM 0x02 #define CMD_WRITE_DISABLE 0x04 #define CMD_READ_STATUS 0x05 +#define CMD_READ_CONFIG 0x35 #define CMD_FLAG_STATUS 0x70 #define CMD_WRITE_ENABLE 0x06 #define CMD_ERASE_4K 0x20 @@ -46,6 +47,7 @@ /* Common status */ #define STATUS_WIP 0x01 +#define STATUS_QEB 0x02 #define STATUS_PEC 0x80 /* Send a single-byte command to the device and read the response */ -- 2.47.3