Date: | 2010-07-16 23:42:05 (13 years 4 months ago) |
---|---|
Author: | Lars C. |
Commit: | f42d987a04d6f9366c47edf794f66796151867b9 |
Message: | MTD: NAND: jz4740: Fix potential that can happen when the hardware
is broken |
Files: |
drivers/mtd/nand/jz4740_nand.c (6 diffs) |
Change Details
drivers/mtd/nand/jz4740_nand.c | ||
---|---|---|
164 | 164 | struct jz_nand *nand = mtd_to_jz_nand(mtd); |
165 | 165 | uint32_t reg, status; |
166 | 166 | int i; |
167 | unsigned int timeout = 1000; | |
167 | 168 | static uint8_t empty_block_ecc[] = {0xcd, 0x9d, 0x90, 0x58, 0xf4, |
168 | 169 | 0x8b, 0xff, 0xb7, 0x6f}; |
169 | 170 | |
... | ... | |
172 | 173 | |
173 | 174 | do { |
174 | 175 | status = readl(nand->base + JZ_REG_NAND_IRQ_STAT); |
175 | } while (!(status & JZ_NAND_STATUS_ENC_FINISH)); | |
176 | } while (!(status & JZ_NAND_STATUS_ENC_FINISH) && --timeout); | |
177 | ||
178 | if (timeout == 0) | |
179 | return -1; | |
176 | 180 | |
177 | 181 | reg = readl(nand->base + JZ_REG_NAND_ECC_CTRL); |
178 | 182 | reg &= ~JZ_NAND_ECC_CTRL_ENABLE; |
... | ... | |
189 | 193 | return 0; |
190 | 194 | } |
191 | 195 | |
192 | static void correct_data(uint8_t *dat, int index, int mask) | |
196 | static void jz_nand_correct_data(uint8_t *dat, int index, int mask) | |
193 | 197 | { |
194 | 198 | int offset = index & 0x7; |
195 | 199 | uint16_t data; |
... | ... | |
214 | 218 | int i, error_count, index; |
215 | 219 | uint32_t reg, status, error; |
216 | 220 | uint32_t t; |
221 | unsigned int timeout = 1000; | |
217 | 222 | |
218 | 223 | t = read_ecc[0]; |
219 | 224 | |
... | ... | |
242 | 247 | |
243 | 248 | do { |
244 | 249 | status = readl(nand->base + JZ_REG_NAND_IRQ_STAT); |
245 | } while (!(status & JZ_NAND_STATUS_DEC_FINISH)); | |
250 | } while (!(status & JZ_NAND_STATUS_DEC_FINISH) && --timeout); | |
251 | ||
252 | if (timeout == 0) | |
253 | return -1; | |
246 | 254 | |
247 | 255 | reg = readl(nand->base + JZ_REG_NAND_ECC_CTRL); |
248 | 256 | reg &= ~JZ_NAND_ECC_CTRL_ENABLE; |
... | ... | |
258 | 266 | error = readl(nand->base + JZ_REG_NAND_ERR(i)); |
259 | 267 | index = ((error >> 16) & 0x1ff) - 1; |
260 | 268 | if (index >= 0 && index < 512) |
261 | correct_data(dat, index, error & 0x1ff); | |
269 | jz_nand_correct_data(dat, index, error & 0x1ff); | |
262 | 270 | } |
263 | 271 | |
264 | 272 | return error_count; |
Branches:
ben-wpan
ben-wpan-stefan
5396a9238205f20f811ea57898980d3ca82df0b6
jz-2.6.34
jz-2.6.34-rc5
jz-2.6.34-rc6
jz-2.6.34-rc7
jz-2.6.35
jz-2.6.36
jz-2.6.37
jz-2.6.38
jz-2.6.39
jz-3.0
jz-3.1
jz-3.11
jz-3.12
jz-3.13
jz-3.15
jz-3.16
jz-3.18-dt
jz-3.2
jz-3.3
jz-3.4
jz-3.5
jz-3.6
jz-3.6-rc2-pwm
jz-3.9
jz-3.9-clk
jz-3.9-rc8
jz47xx
jz47xx-2.6.38
master
Tags:
od-2011-09-04
od-2011-09-18
v2.6.34-rc5
v2.6.34-rc6
v2.6.34-rc7
v3.9