1 From 0ff26c3761e5a17d21e7ee0bd9a2068f55c84d55 Mon Sep 17 00:00:00 2001
2 From: Yunhui Cui <yunhui.cui@nxp.com>
3 Date: Wed, 15 Jun 2016 14:57:08 +0800
4 Subject: [PATCH 57/93] driver: spi: Fix DSPI bug after adding exceed 16MB for
8 SF: Detected N25Q128A with page size 256 Bytes, erase size 64 KiB, total
10 => mw.l 80000000 55555555 1100
11 => mw.l 80020000 aaaaaaaa 1100
13 SF: 65536 bytes @ 0x0 Erased: OK
14 => sf write 80020000 0 1100
15 device 0 offset 0x0, size 0x1100
16 SF: 4352 bytes @ 0x0 Written: OK
17 => sf read 80000000 0 1100
18 device 0 offset 0x0, size 0x1100
19 SF: 4352 bytes @ 0x0 Read: OK
20 => cmp.b 80000000 80020000 1100
21 byte at 0x00000000800010fe (0xff) != byte at 0x00000000800210fe (0xaa)
22 Total of 4350 byte(s) were the same
24 Signed-off-by: Yunhui Cui <yunhui.cui@nxp.com>
26 drivers/mtd/spi/spi_flash.c | 21 +++++++++++++++------
27 1 file changed, 15 insertions(+), 6 deletions(-)
29 diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c
30 index b0f09ab..e04bd55 100644
31 --- a/drivers/mtd/spi/spi_flash.c
32 +++ b/drivers/mtd/spi/spi_flash.c
33 @@ -326,8 +326,11 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
37 + if (flash->size > SPI_FLASH_16MB_BOUN)
38 + cmdsz = SPI_FLASH_CMD_LEN_EXT + flash->dummy_byte;
40 + cmdsz = SPI_FLASH_CMD_LEN;
42 - cmdsz = SPI_FLASH_CMD_LEN_EXT + flash->dummy_byte;
43 cmd = calloc(1, cmdsz);
45 debug("SF: Failed to allocate cmd\n");
46 @@ -353,7 +356,7 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
47 debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
48 cmd[2], cmd[3], erase_addr);
50 - ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);
51 + ret = spi_flash_write_common(flash, cmd, cmdsz, NULL, 0);
53 debug("SF: erase failed\n");
55 @@ -385,8 +388,10 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
60 - cmdsz = SPI_FLASH_CMD_LEN_EXT + flash->dummy_byte;
61 + if (flash->size > SPI_FLASH_16MB_BOUN)
62 + cmdsz = SPI_FLASH_CMD_LEN_EXT + flash->dummy_byte;
64 + cmdsz = SPI_FLASH_CMD_LEN;
65 cmd = calloc(1, cmdsz);
67 debug("SF: Failed to allocate cmd\n");
68 @@ -418,7 +423,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
69 debug("SF: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n",
70 buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len);
72 - ret = spi_flash_write_common(flash, cmd, sizeof(cmd),
73 + ret = spi_flash_write_common(flash, cmd, cmdsz,
74 buf + actual, chunk_len);
76 debug("SF: write failed\n");
77 @@ -482,7 +487,11 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
81 - cmdsz = SPI_FLASH_CMD_LEN_EXT + flash->dummy_byte;
82 + if (flash->size > SPI_FLASH_16MB_BOUN)
83 + cmdsz = SPI_FLASH_CMD_LEN_EXT + flash->dummy_byte;
85 + cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte;
87 cmd = calloc(1, cmdsz);
89 debug("SF: Failed to allocate cmd\n");