| Date: | 2010-06-28 00:05:15 (13 years 5 months ago) |
|---|---|
| Author: | Lars C. |
| Commit: | 1e2d11fda4717094823d225377e84aebbedd6d79 |
| Message: | MTD: NAND: jz4740: Minor cleanups |
| Files: |
drivers/mtd/nand/jz4740_nand.c (8 diffs) |
Change Details
| drivers/mtd/nand/jz4740_nand.c | ||
|---|---|---|
| 1 | 1 | /* |
| 2 | 2 | * Copyright (C) 2009-2010, Lars-Peter Clausen <lars@metafoo.de> |
| 3 | * JZ4740 SoC NAND controller driver | |
| 3 | * JZ4740 SoC NAND controller driver | |
| 4 | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it | |
| 6 | * under the terms of the GNU General Public License as published by the | |
| 7 | * Free Software Foundation; either version 2 of the License, or (at your | |
| 5 | * This program is free software; you can redistribute it and/or modify it | |
| 6 | * under the terms of the GNU General Public License as published by the | |
| 7 | * Free Software Foundation; either version 2 of the License, or (at your | |
| 8 | 8 | * option) any later version. |
| 9 | 9 | * |
| 10 | * You should have received a copy of the GNU General Public License along | |
| 11 | * with this program; if not, write to the Free Software Foundation, Inc., | |
| 10 | * You should have received a copy of the GNU General Public License along | |
| 11 | * with this program; if not, write to the Free Software Foundation, Inc., | |
| 12 | 12 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
| 13 | 13 | * |
| 14 | 14 | */ |
| ... | ... | |
| 108 | 108 | struct jz_nand *nand = mtd_to_jz_nand(mtd); |
| 109 | 109 | uint32_t reg; |
| 110 | 110 | |
| 111 | ||
| 112 | 111 | writel(0, nand->base + JZ_REG_NAND_IRQ_STAT); |
| 113 | 112 | reg = readl(nand->base + JZ_REG_NAND_ECC_CTRL); |
| 114 | 113 | |
| ... | ... | |
| 132 | 131 | writel(reg, nand->base + JZ_REG_NAND_ECC_CTRL); |
| 133 | 132 | } |
| 134 | 133 | |
| 135 | ||
| 136 | 134 | static int jz_nand_calculate_ecc_rs(struct mtd_info *mtd, const uint8_t *dat, |
| 137 | 135 | uint8_t *ecc_code) |
| 138 | 136 | { |
| ... | ... | |
| 164 | 162 | return 0; |
| 165 | 163 | } |
| 166 | 164 | |
| 167 | /*#define printkd printk*/ | |
| 168 | #define printkd(...) | |
| 169 | ||
| 170 | 165 | static void correct_data(uint8_t *dat, int index, int mask) |
| 171 | 166 | { |
| 172 | 167 | int offset = index & 0x7; |
| 173 | 168 | uint16_t data; |
| 174 | printkd("correct: "); | |
| 175 | 169 | |
| 176 | 170 | index += (index >> 3); |
| 177 | 171 | |
| 178 | 172 | data = dat[index]; |
| 179 | 173 | data |= dat[index+1] << 8; |
| 180 | 174 | |
| 181 | printkd("0x%x -> ", data); | |
| 182 | ||
| 183 | 175 | mask ^= (data >> offset) & 0x1ff; |
| 184 | 176 | data &= ~(0x1ff << offset); |
| 185 | 177 | data |= (mask << offset); |
| 186 | 178 | |
| 187 | printkd("0x%x\n", data); | |
| 188 | ||
| 189 | 179 | dat[index] = data & 0xff; |
| 190 | 180 | dat[index+1] = (data >> 8) & 0xff; |
| 191 | 181 | } |
| ... | ... | |
| 232 | 222 | writel(reg, nand->base + JZ_REG_NAND_ECC_CTRL); |
| 233 | 223 | |
| 234 | 224 | if (status & JZ_NAND_STATUS_ERROR) { |
| 235 | if (status & JZ_NAND_STATUS_UNCOR_ERROR) { | |
| 236 | printkd("uncorrectable ecc:"); | |
| 237 | for (i = 0; i < 9; ++i) | |
| 238 | printkd(" 0x%x", read_ecc[i]); | |
| 239 | printkd("\n"); | |
| 240 | printkd("uncorrectable data:"); | |
| 241 | for (i = 0; i < 32; ++i) | |
| 242 | printkd(" 0x%x", dat[i]); | |
| 243 | printkd("\n"); | |
| 225 | if (status & JZ_NAND_STATUS_UNCOR_ERROR) | |
| 244 | 226 | return -1; |
| 245 | } | |
| 246 | 227 | |
| 247 | 228 | error_count = (status & JZ_NAND_STATUS_ERR_COUNT) >> 29; |
| 248 | 229 | |
| 249 | printkd("error_count: %d %x\n", error_count, status); | |
| 250 | ||
| 251 | 230 | for (i = 0; i < error_count; ++i) { |
| 252 | 231 | error = readl(nand->base + JZ_REG_NAND_ERR(i)); |
| 253 | 232 | index = ((error >> 16) & 0x1ff) - 1; |
| ... | ... | |
| 294 | 273 | |
| 295 | 274 | nand->mem = request_mem_region(nand->mem->start, |
| 296 | 275 | resource_size(nand->mem), pdev->name); |
| 297 | ||
| 298 | 276 | if (!nand->mem) { |
| 299 | 277 | dev_err(&pdev->dev, "Failed to request mmio memory region\n"); |
| 300 | 278 | ret = -EBUSY; |
| ... | ... | |
| 302 | 280 | } |
| 303 | 281 | |
| 304 | 282 | nand->base = ioremap(nand->mem->start, resource_size(nand->mem)); |
| 305 | ||
| 306 | 283 | if (!nand->base) { |
| 307 | 284 | dev_err(&pdev->dev, "Failed to ioremap mmio memory region\n"); |
| 308 | 285 | ret = -EBUSY; |
| ... | ... | |
| 401 | 378 | return ret; |
| 402 | 379 | } |
| 403 | 380 | |
| 404 | static void __devexit jz_nand_remove(struct platform_device *pdev) | |
| 381 | static int __devexit jz_nand_remove(struct platform_device *pdev) | |
| 405 | 382 | { |
| 406 | 383 | struct jz_nand *nand = platform_get_drvdata(pdev); |
| 407 | 384 | |
| 408 | 385 | nand_release(&nand->mtd); |
| 409 | 386 | |
| 410 | 387 | iounmap(nand->base); |
| 411 | ||
| 412 | 388 | release_mem_region(nand->mem->start, resource_size(nand->mem)); |
| 413 | 389 | |
| 414 | 390 | platform_set_drvdata(pdev, NULL); |
| 415 | 391 | kfree(nand); |
| 392 | ||
| 393 | return 0; | |
| 416 | 394 | } |
| 417 | 395 | |
| 418 | 396 | struct platform_driver jz_nand_driver = { |
| 419 | 397 | .probe = jz_nand_probe, |
| 420 | .remove = __devexit_p(jz_nand_probe), | |
| 398 | .remove = __devexit_p(jz_nand_remove), | |
| 421 | 399 | .driver = { |
| 422 | 400 | .name = "jz4740-nand", |
| 423 | 401 | .owner = THIS_MODULE, |
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
