uboot-lantiq: update to v2013.10
[openwrt/svn-archive/archive.git] / package / boot / uboot-lantiq / patches / 0001-sf-fix-out-of-order-calls-for-spi_claim_bus-and-spi_.patch
1 From 909840ef844013379e5ec399c1e76c65d1a6eb1d Mon Sep 17 00:00:00 2001
2 From: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
3 Date: Sat, 12 Oct 2013 21:09:47 +0200
4 Subject: sf: fix out-of-order calls for spi_claim_bus and spi_release_bus
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 108665f..d34747b 100644
10 --- a/drivers/mtd/spi/sf_ops.c
11 +++ b/drivers/mtd/spi/sf_ops.c
12 @@ -132,12 +132,6 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
13 if (buf == NULL)
14 timeout = SPI_FLASH_PAGE_ERASE_TIMEOUT;
15
16 - ret = spi_claim_bus(flash->spi);
17 - if (ret) {
18 - debug("SF: unable to claim SPI bus\n");
19 - return ret;
20 - }
21 -
22 ret = spi_flash_cmd_write_enable(flash);
23 if (ret < 0) {
24 debug("SF: enabling write failed\n");
25 @@ -158,8 +152,6 @@ int spi_flash_write_common(struct spi_flash *flash, const u8 *cmd,
26 return ret;
27 }
28
29 - spi_release_bus(spi);
30 -
31 return ret;
32 }
33
34 @@ -175,12 +167,18 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
35 return -1;
36 }
37
38 + ret = spi_claim_bus(flash->spi);
39 + if (ret) {
40 + debug("SF: unable to claim SPI bus\n");
41 + return ret;
42 + }
43 +
44 cmd[0] = flash->erase_cmd;
45 while (len) {
46 #ifdef CONFIG_SPI_FLASH_BAR
47 ret = spi_flash_bank(flash, offset);
48 if (ret < 0)
49 - return ret;
50 + goto done;
51 #endif
52 spi_flash_addr(offset, cmd);
53
54 @@ -190,13 +188,16 @@ int spi_flash_cmd_erase_ops(struct spi_flash *flash, u32 offset, size_t len)
55 ret = spi_flash_write_common(flash, cmd, sizeof(cmd), NULL, 0);
56 if (ret < 0) {
57 debug("SF: erase failed\n");
58 - break;
59 + goto done;
60 }
61
62 offset += erase_size;
63 len -= erase_size;
64 }
65
66 +done:
67 + spi_release_bus(flash->spi);
68 +
69 return ret;
70 }
71
72 @@ -208,6 +209,12 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
73 u8 cmd[4];
74 int ret = -1;
75
76 + ret = spi_claim_bus(flash->spi);
77 + if (ret) {
78 + debug("SF: unable to claim SPI bus\n");
79 + return ret;
80 + }
81 +
82 page_size = flash->page_size;
83
84 cmd[0] = CMD_PAGE_PROGRAM;
85 @@ -215,7 +222,7 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
86 #ifdef CONFIG_SPI_FLASH_BAR
87 ret = spi_flash_bank(flash, offset);
88 if (ret < 0)
89 - return ret;
90 + goto done;
91 #endif
92 byte_addr = offset % page_size;
93 chunk_len = min(len - actual, page_size - byte_addr);
94 @@ -232,12 +239,15 @@ int spi_flash_cmd_write_ops(struct spi_flash *flash, u32 offset,
95 buf + actual, chunk_len);
96 if (ret < 0) {
97 debug("SF: write failed\n");
98 - break;
99 + goto done;
100 }
101
102 offset += chunk_len;
103 }
104
105 +done:
106 + spi_release_bus(flash->spi);
107 +
108 return ret;
109 }
110
111 @@ -247,20 +257,12 @@ int spi_flash_read_common(struct spi_flash *flash, const u8 *cmd,
112 struct spi_slave *spi = flash->spi;
113 int ret;
114
115 - ret = spi_claim_bus(flash->spi);
116 - if (ret) {
117 - debug("SF: unable to claim SPI bus\n");
118 - return ret;
119 - }
120 -
121 ret = spi_flash_cmd_read(spi, cmd, cmd_len, data, data_len);
122 if (ret < 0) {
123 debug("SF: read cmd failed\n");
124 return ret;
125 }
126
127 - spi_release_bus(spi);
128 -
129 return ret;
130 }
131
132 @@ -271,6 +273,12 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
133 u32 remain_len, read_len;
134 int ret = -1;
135
136 + ret = spi_claim_bus(flash->spi);
137 + if (ret) {
138 + debug("SF: unable to claim SPI bus\n");
139 + return ret;
140 + }
141 +
142 /* Handle memory-mapped SPI */
143 if (flash->memory_map) {
144 spi_xfer(flash->spi, 0, NULL, NULL, SPI_XFER_MMAP);
145 @@ -289,7 +297,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
146 ret = spi_flash_cmd_bankaddr_write(flash, bank_sel);
147 if (ret) {
148 debug("SF: fail to set bank%d\n", bank_sel);
149 - return ret;
150 + goto done;
151 }
152 #endif
153 remain_len = (SPI_FLASH_16MB_BOUN * (bank_sel + 1)) - offset;
154 @@ -304,7 +312,7 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
155 data, read_len);
156 if (ret < 0) {
157 debug("SF: read failed\n");
158 - break;
159 + goto done;
160 }
161
162 offset += read_len;
163 @@ -312,6 +320,9 @@ int spi_flash_cmd_read_ops(struct spi_flash *flash, u32 offset,
164 data += read_len;
165 }
166
167 +done:
168 + spi_release_bus(flash->spi);
169 +
170 return ret;
171 }
172
173 --
174 1.8.3.2
175