uboot-lantiq: update to v2013.10
[openwrt/svn-archive/archive.git] / package / boot / uboot-lantiq / patches / 0005-sf-make-calculatiom-of-address-bytes-completely-conf.patch
1 From 6fb5f86b094756d94de8abe7425e3d290ff22dd2 Mon Sep 17 00:00:00 2001
2 From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
3 Date: Sun, 13 Oct 2013 15:09:28 +0200
4 Subject: sf: make calculatiom of address bytes completely configurable
5
6 Signed-off-by: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
7
8 diff --git a/drivers/mtd/spi/sf_ops.c b/drivers/mtd/spi/sf_ops.c
9 index d34747b..207adf5 100644
10 --- a/drivers/mtd/spi/sf_ops.c
11 +++ b/drivers/mtd/spi/sf_ops.c
12 @@ -15,12 +15,17 @@
13
14 #include "sf_internal.h"
15
16 -static void spi_flash_addr(u32 addr, u8 *cmd)
17 +static void spi_flash_addr(const struct spi_flash *flash, u32 addr, u8 *cmd)
18 {
19 /* cmd[0] is actual command */
20 - cmd[1] = addr >> 16;
21 - cmd[2] = addr >> 8;
22 - cmd[3] = addr >> 0;
23 + cmd[1] = addr >> (flash->addr_width * 8 - 8);
24 + cmd[2] = addr >> (flash->addr_width * 8 - 16);
25 + cmd[3] = addr >> (flash->addr_width * 8 - 24);
26 +}
27 +
28 +static int spi_flash_cmdsz(const struct spi_flash *flash)
29 +{
30 + return 1 + flash->addr_width;
31 }
32
33 int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr)
34 @@ -158,7 +163,7 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
35 int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
36 {
37 u32 erase_size;
38 - u8 cmd[4];
39 + u8 cmd[4], cmd_len;
40 int ret = -1;
41
42 erase_size = flash->erase_size;
43 @@ -180,12 +185,13 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
44 if (ret < 0)
45 goto done;
46 #endif
47 - spi_flash_addr(offset, cmd);
48 + spi_flash_addr(flash, offset, cmd);
49 + cmd_len = spi_flash_cmdsz(flash);
50
51 debug("SF: erase %2x %2x %2x %2x (%x)\n", cmd[0], cmd[1],
52 cmd[2], cmd[3], offset);
53
54 - ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);
55 + ret = spi_flash_write_common(flash, cmd, cmd_len, NULL, 0);
56 if (ret < 0) {
57 debug("SF: erase failed\n");
58 goto done;
59 @@ -206,7 +212,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
60 {
61 unsigned long byte_addr, page_size;
62 size_t chunk_len, actual;
63 - u8 cmd[4];
64 + u8 cmd[4], cmd_len;
65 int ret = -1;
66
67 ret = spi_claim_bus(flash->spi);
68 @@ -230,12 +236,13 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
69 if (flash->spi->max_write_size)
70 chunk_len = min(chunk_len, flash->spi->max_write_size);
71
72 - spi_flash_addr(offset, cmd);
73 + spi_flash_addr(flash, offset, cmd);
74 + cmd_len = spi_flash_cmdsz(flash);
75
76 debug("PP: 0x%p => cmd = { 0x%02x 0x%02x%02x%02x } chunk_len = %zu\n",
77 buf + actual, cmd[0], cmd[1], cmd[2], cmd[3], chunk_len);
78
79 - ret = spi_flash_write_common(flash, cmd, sizeof(cmd),
80 + ret = spi_flash_write_common(flash, cmd, cmd_len,
81 buf + actual, chunk_len);
82 if (ret < 0) {
83 debug("SF: write failed\n");
84 @@ -269,7 +276,7 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
85 int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
86 size_t len, void *data)
87 {
88 - u8 cmd[5], bank_sel = 0;
89 + u8 cmd[5], cmd_len, bank_sel = 0;
90 u32 remain_len, read_len;
91 int ret = -1;
92
93 @@ -288,7 +295,6 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
94 }
95
96 cmd[0] = CMD_READ_ARRAY_FAST;
97 - cmd[4] = 0x00;
98
99 while (len) {
100 #ifdef CONFIG_SPI_FLASH_BAR
101 @@ -306,9 +312,11 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
102 else
103 read_len = remain_len;
104
105 - spi_flash_addr(offset, cmd);
106 + spi_flash_addr(flash, offset, cmd);
107 + cmd_len = spi_flash_cmdsz(flash);
108 + cmd[cmd_len] = 0x00;
109
110 - ret = spi_flash_read_common(flash, cmd, sizeof(cmd),
111 + ret = spi_flash_read_common(flash, cmd, cmd_len + 1,
112 data, read_len);
113 if (ret < 0) {
114 debug("SF: read failed\n");
115 diff --git a/drivers/mtd/spi/sf_probe.c b/drivers/mtd/spi/sf_probe.c
116 index 380aa09..84289db 100644
117 --- a/drivers/mtd/spi/sf_probe.c
118 +++ b/drivers/mtd/spi/sf_probe.c
119 @@ -218,6 +218,9 @@ static int spi_flash_validate_params(struct spi_flash *flash,
120 flash->poll_cmd = CMD_FLAG_STATUS;
121 #endif
122
123 + /* Configure default 3-byte addressing */
124 + flash->addr_width = 3;
125 +
126 /* Configure the BAR - discover bank cmds and read current bank */
127 #ifdef CONFIG_SPI_FLASH_BAR
128 u8 curr_bank = 0;
129 diff --git a/include/spi_flash.h b/include/spi_flash.h
130 index 411dd1b..cc9398b 100644
131 --- a/include/spi_flash.h
132 +++ b/include/spi_flash.h
133 @@ -57,6 +57,7 @@ struct spi_flash {
134 #endif
135 u8 poll_cmd;
136 u8 erase_cmd;
137 + u8 addr_width;
138
139 void *memory_map;
140 int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf);
141 --
142 1.8.3.2
143