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