]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sf: Discover read dummy_byte
authorJagannadha Sutradharudu Teki <jaganna@xilinx.com>
Sat, 11 Jan 2014 11:20:45 +0000 (16:50 +0530)
committerJagannadha Sutradharudu Teki <jaganna@xilinx.com>
Sat, 11 Jan 2014 11:20:45 +0000 (16:50 +0530)
Discovered the read dummy_byte based on the
configured read command.

Signed-off-by: Jagannadha Sutradharudu Teki <jaganna@xilinx.com>
drivers/mtd/spi/sf_internal.h
drivers/mtd/spi/sf_ops.c
drivers/mtd/spi/sf_probe.c
include/spi_flash.h

index 7be02925c865e76935249d36aa104061499882a1..a9f5a8111bea1eba1719246086d65b9e1cccf7aa 100644 (file)
@@ -10,6 +10,8 @@
 #ifndef _SF_INTERNAL_H_
 #define _SF_INTERNAL_H_
 
+#define SPI_FLASH_3B_ADDR_LEN          3
+#define SPI_FLASH_CMD_LEN              (1 + SPI_FLASH_3B_ADDR_LEN)
 #define SPI_FLASH_16MB_BOUN            0x1000000
 
 /* CFI Manufacture ID's */
index 827f71912d26cf105ff339fd08dd4b6c9faa670d..6adee325cb2cb45c3be81c786624d43f52aef84b 100644 (file)
@@ -9,6 +9,7 @@
  */
 
 #include <common.h>
+#include <malloc.h>
 #include <spi.h>
 #include <spi_flash.h>
 #include <watchdog.h>
@@ -216,7 +217,7 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
 int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
 {
        u32 erase_size;
-       u8 cmd[4];
+       u8 cmd[SPI_FLASH_CMD_LEN];
        int ret = -1;
 
        erase_size = flash->erase_size;
@@ -255,7 +256,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
 {
        unsigned long byte_addr, page_size;
        size_t chunk_len, actual;
-       u8 cmd[4];
+       u8 cmd[SPI_FLASH_CMD_LEN];
        int ret = -1;
 
        page_size = flash->page_size;
@@ -317,7 +318,7 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
 int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
                size_t len, void *data)
 {
-       u8 cmd[5], bank_sel = 0;
+       u8 *cmd, cmdsz, bank_sel = 0;
        u32 remain_len, read_len;
        int ret = -1;
 
@@ -335,9 +336,11 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
                return 0;
        }
 
-       cmd[0] = flash->read_cmd;
-       cmd[4] = 0x00;
+       cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte;
+       cmd = malloc(cmdsz);
+       memset(cmd, 0, cmdsz);
 
+       cmd[0] = flash->read_cmd;
        while (len) {
 #ifdef CONFIG_SPI_FLASH_BAR
                bank_sel = offset / SPI_FLASH_16MB_BOUN;
@@ -356,8 +359,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
 
                spi_flash_addr(offset, cmd);
 
-               ret = spi_flash_read_common(flash, cmd, sizeof(cmd),
-                                                       data, read_len);
+               ret = spi_flash_read_common(flash, cmd, cmdsz, data, read_len);
                if (ret < 0) {
                        debug("SF: read failed\n");
                        break;
index a049e729a18b6fc59e9d902d69229469def3fe2a..8bd06eea62385d671002c850dc50422a78ca566e 100644 (file)
@@ -140,6 +140,25 @@ static struct spi_flash *spi_flash_validate_params(struct spi_slave *spi,
                }
        }
 
+       /* Read dummy_byte: dummy byte is determined based on the
+        * dummy cycles of a particular command.
+        * Fast commands - dummy_byte = dummy_cycles/8
+        * I/O commands- dummy_byte = (dummy_cycles * no.of lines)/8
+        * For I/O commands except cmd[0] everything goes on no.of lines
+        * based on particular command but incase of fast commands except
+        * data all go on single line irrespective of command.
+        */
+       switch (flash->read_cmd) {
+       case CMD_READ_QUAD_IO_FAST:
+               flash->dummy_byte = 2;
+               break;
+       case CMD_READ_ARRAY_SLOW:
+               flash->dummy_byte = 0;
+               break;
+       default:
+               flash->dummy_byte = 1;
+       }
+
        /* Poll cmd seclection */
        flash->poll_cmd = CMD_READ_STATUS;
 #ifdef CONFIG_SPI_FLASH_STMICRO
index 99724a0d3ef35640bccde7fe8116d5781944ec3a..437937cfc6b7412266a42c351e3b03d1d2623ca0 100644 (file)
@@ -72,6 +72,7 @@ extern const struct spi_flash_params spi_flash_params_table[];
  * @erase_cmd:         Erase cmd 4K, 32K, 64K
  * @read_cmd:          Read cmd - Array Fast, Extn read and quad read.
  * @write_cmd:         Write cmd - page and quad program.
+ * @dummy_byte:                Dummy cycles for read operation.
  * @memory_map:                Address of read-only SPI flash access
  * @read:              Flash read ops: Read len bytes at offset into buf
  *                     Supported cmds: Fast Array Read
@@ -98,6 +99,7 @@ struct spi_flash {
        u8 erase_cmd;
        u8 read_cmd;
        u8 write_cmd;
+       u8 dummy_byte;
 
        void *memory_map;
        int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);