661243f488ada2f7a2c239ece9d59709317ffd8a
[openwrt/staging/neocturne.git] /
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
5 QSPI
6
7 => sf probe 1:0
8 SF: Detected N25Q128A with page size 256 Bytes, erase size 64 KiB, total
9 16 MiB
10 => mw.l 80000000 55555555 1100
11 => mw.l 80020000 aaaaaaaa 1100
12 => sf erase 0 +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
23
24 Signed-off-by: Yunhui Cui <yunhui.cui@nxp.com>
25 ---
26 drivers/mtd/spi/spi_flash.c | 21 +++++++++++++++------
27 1 file changed, 15 insertions(+), 6 deletions(-)
28
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)
34 return -EINVAL;
35 }
36 }
37 + if (flash->size > SPI_FLASH_16MB_BOUN)
38 + cmdsz = SPI_FLASH_CMD_LEN_EXT + flash->dummy_byte;
39 + else
40 + cmdsz = SPI_FLASH_CMD_LEN;
41
42 - cmdsz = SPI_FLASH_CMD_LEN_EXT + flash->dummy_byte;
43 cmd = calloc(1, cmdsz);
44 if (!cmd) {
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);
49
50 - ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);
51 + ret = spi_flash_write_common(flash, cmd, cmdsz, NULL, 0);
52 if (ret < 0) {
53 debug("SF: erase failed\n");
54 break;
55 @@ -385,8 +388,10 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
56 return -EINVAL;
57 }
58 }
59 -
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;
63 + else
64 + cmdsz = SPI_FLASH_CMD_LEN;
65 cmd = calloc(1, cmdsz);
66 if (!cmd) {
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);
71
72 - ret = spi_flash_write_common(flash, cmd, sizeof(cmd),
73 + ret = spi_flash_write_common(flash, cmd, cmdsz,
74 buf + actual, chunk_len);
75 if (ret < 0) {
76 debug("SF: write failed\n");
77 @@ -482,7 +487,11 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
78 return 0;
79 }
80
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;
84 + else
85 + cmdsz = SPI_FLASH_CMD_LEN + flash->dummy_byte;
86 +
87 cmd = calloc(1, cmdsz);
88 if (!cmd) {
89 debug("SF: Failed to allocate cmd\n");
90 --
91 1.7.9.5
92