diff options
author | Josh Wu <josh.wu@atmel.com> | 2012-06-29 05:47:54 -0400 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2012-07-06 13:21:09 -0400 |
commit | a41b51a1f7c15a1b00f30a3ad2d0373ad51b883d (patch) | |
tree | 790b3b90ac66aa8dca295f3ec45ea49b05f3de6a /drivers | |
parent | fae255253b393d5e4f0d77d5afa103bfc8b47a97 (diff) |
mtd: at91: add dt parameters for Atmel PMECC
Add DT support for PMECC parameters.
Signed-off-by: Hong Xu <hong.xu@atmel.com>
Signed-off-by: Josh Wu <josh.wu@atmel.com>
Acked-by: Nicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/mtd/nand/atmel_nand.c | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c index 7a41a04beb87..b97ad9f78d39 100644 --- a/drivers/mtd/nand/atmel_nand.c +++ b/drivers/mtd/nand/atmel_nand.c | |||
@@ -93,6 +93,11 @@ struct atmel_nand_host { | |||
93 | 93 | ||
94 | struct completion comp; | 94 | struct completion comp; |
95 | struct dma_chan *dma_chan; | 95 | struct dma_chan *dma_chan; |
96 | |||
97 | bool has_pmecc; | ||
98 | u8 pmecc_corr_cap; | ||
99 | u16 pmecc_sector_size; | ||
100 | u32 pmecc_lookup_table_offset; | ||
96 | }; | 101 | }; |
97 | 102 | ||
98 | static int cpu_has_dma(void) | 103 | static int cpu_has_dma(void) |
@@ -481,7 +486,8 @@ static void atmel_nand_hwctl(struct mtd_info *mtd, int mode) | |||
481 | static int __devinit atmel_of_init_port(struct atmel_nand_host *host, | 486 | static int __devinit atmel_of_init_port(struct atmel_nand_host *host, |
482 | struct device_node *np) | 487 | struct device_node *np) |
483 | { | 488 | { |
484 | u32 val; | 489 | u32 val, table_offset; |
490 | u32 offset[2]; | ||
485 | int ecc_mode; | 491 | int ecc_mode; |
486 | struct atmel_nand_data *board = &host->board; | 492 | struct atmel_nand_data *board = &host->board; |
487 | enum of_gpio_flags flags; | 493 | enum of_gpio_flags flags; |
@@ -517,6 +523,50 @@ static int __devinit atmel_of_init_port(struct atmel_nand_host *host, | |||
517 | board->enable_pin = of_get_gpio(np, 1); | 523 | board->enable_pin = of_get_gpio(np, 1); |
518 | board->det_pin = of_get_gpio(np, 2); | 524 | board->det_pin = of_get_gpio(np, 2); |
519 | 525 | ||
526 | host->has_pmecc = of_property_read_bool(np, "atmel,has-pmecc"); | ||
527 | |||
528 | if (!(board->ecc_mode == NAND_ECC_HW) || !host->has_pmecc) | ||
529 | return 0; /* Not using PMECC */ | ||
530 | |||
531 | /* use PMECC, get correction capability, sector size and lookup | ||
532 | * table offset. | ||
533 | */ | ||
534 | if (of_property_read_u32(np, "atmel,pmecc-cap", &val) != 0) { | ||
535 | dev_err(host->dev, "Cannot decide PMECC Capability\n"); | ||
536 | return -EINVAL; | ||
537 | } else if ((val != 2) && (val != 4) && (val != 8) && (val != 12) && | ||
538 | (val != 24)) { | ||
539 | dev_err(host->dev, | ||
540 | "Unsupported PMECC correction capability: %d; should be 2, 4, 8, 12 or 24\n", | ||
541 | val); | ||
542 | return -EINVAL; | ||
543 | } | ||
544 | host->pmecc_corr_cap = (u8)val; | ||
545 | |||
546 | if (of_property_read_u32(np, "atmel,pmecc-sector-size", &val) != 0) { | ||
547 | dev_err(host->dev, "Cannot decide PMECC Sector Size\n"); | ||
548 | return -EINVAL; | ||
549 | } else if ((val != 512) && (val != 1024)) { | ||
550 | dev_err(host->dev, | ||
551 | "Unsupported PMECC sector size: %d; should be 512 or 1024 bytes\n", | ||
552 | val); | ||
553 | return -EINVAL; | ||
554 | } | ||
555 | host->pmecc_sector_size = (u16)val; | ||
556 | |||
557 | if (of_property_read_u32_array(np, "atmel,pmecc-lookup-table-offset", | ||
558 | offset, 2) != 0) { | ||
559 | dev_err(host->dev, "Cannot get PMECC lookup table offset\n"); | ||
560 | return -EINVAL; | ||
561 | } | ||
562 | table_offset = host->pmecc_sector_size == 512 ? offset[0] : offset[1]; | ||
563 | |||
564 | if (!table_offset) { | ||
565 | dev_err(host->dev, "Invalid PMECC lookup table offset\n"); | ||
566 | return -EINVAL; | ||
567 | } | ||
568 | host->pmecc_lookup_table_offset = table_offset; | ||
569 | |||
520 | return 0; | 570 | return 0; |
521 | } | 571 | } |
522 | #else | 572 | #else |