aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/nand/nand_base.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/nand/nand_base.c')
-rw-r--r--drivers/mtd/nand/nand_base.c125
1 files changed, 117 insertions, 8 deletions
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 5f71371eb1b0..3d7ed432fa41 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -82,6 +82,20 @@ static struct nand_ecclayout nand_oob_64 = {
82 .length = 38}} 82 .length = 38}}
83}; 83};
84 84
85static struct nand_ecclayout nand_oob_128 = {
86 .eccbytes = 48,
87 .eccpos = {
88 80, 81, 82, 83, 84, 85, 86, 87,
89 88, 89, 90, 91, 92, 93, 94, 95,
90 96, 97, 98, 99, 100, 101, 102, 103,
91 104, 105, 106, 107, 108, 109, 110, 111,
92 112, 113, 114, 115, 116, 117, 118, 119,
93 120, 121, 122, 123, 124, 125, 126, 127},
94 .oobfree = {
95 {.offset = 2,
96 .length = 78}}
97};
98
85static int nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, 99static int nand_get_device(struct nand_chip *chip, struct mtd_info *mtd,
86 int new_state); 100 int new_state);
87 101
@@ -748,6 +762,8 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
748 * @mtd: mtd info structure 762 * @mtd: mtd info structure
749 * @chip: nand chip info structure 763 * @chip: nand chip info structure
750 * @buf: buffer to store read data 764 * @buf: buffer to store read data
765 *
766 * Not for syndrome calculating ecc controllers, which use a special oob layout
751 */ 767 */
752static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 768static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
753 uint8_t *buf) 769 uint8_t *buf)
@@ -758,6 +774,47 @@ static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
758} 774}
759 775
760/** 776/**
777 * nand_read_page_raw_syndrome - [Intern] read raw page data without ecc
778 * @mtd: mtd info structure
779 * @chip: nand chip info structure
780 * @buf: buffer to store read data
781 *
782 * We need a special oob layout and handling even when OOB isn't used.
783 */
784static int nand_read_page_raw_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
785 uint8_t *buf)
786{
787 int eccsize = chip->ecc.size;
788 int eccbytes = chip->ecc.bytes;
789 uint8_t *oob = chip->oob_poi;
790 int steps, size;
791
792 for (steps = chip->ecc.steps; steps > 0; steps--) {
793 chip->read_buf(mtd, buf, eccsize);
794 buf += eccsize;
795
796 if (chip->ecc.prepad) {
797 chip->read_buf(mtd, oob, chip->ecc.prepad);
798 oob += chip->ecc.prepad;
799 }
800
801 chip->read_buf(mtd, oob, eccbytes);
802 oob += eccbytes;
803
804 if (chip->ecc.postpad) {
805 chip->read_buf(mtd, oob, chip->ecc.postpad);
806 oob += chip->ecc.postpad;
807 }
808 }
809
810 size = mtd->oobsize - (oob - chip->oob_poi);
811 if (size)
812 chip->read_buf(mtd, oob, size);
813
814 return 0;
815}
816
817/**
761 * nand_read_page_swecc - [REPLACABLE] software ecc based page read function 818 * nand_read_page_swecc - [REPLACABLE] software ecc based page read function
762 * @mtd: mtd info structure 819 * @mtd: mtd info structure
763 * @chip: nand chip info structure 820 * @chip: nand chip info structure
@@ -1482,6 +1539,8 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from,
1482 * @mtd: mtd info structure 1539 * @mtd: mtd info structure
1483 * @chip: nand chip info structure 1540 * @chip: nand chip info structure
1484 * @buf: data buffer 1541 * @buf: data buffer
1542 *
1543 * Not for syndrome calculating ecc controllers, which use a special oob layout
1485 */ 1544 */
1486static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1545static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1487 const uint8_t *buf) 1546 const uint8_t *buf)
@@ -1491,6 +1550,44 @@ static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1491} 1550}
1492 1551
1493/** 1552/**
1553 * nand_write_page_raw_syndrome - [Intern] raw page write function
1554 * @mtd: mtd info structure
1555 * @chip: nand chip info structure
1556 * @buf: data buffer
1557 *
1558 * We need a special oob layout and handling even when ECC isn't checked.
1559 */
1560static void nand_write_page_raw_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1561 const uint8_t *buf)
1562{
1563 int eccsize = chip->ecc.size;
1564 int eccbytes = chip->ecc.bytes;
1565 uint8_t *oob = chip->oob_poi;
1566 int steps, size;
1567
1568 for (steps = chip->ecc.steps; steps > 0; steps--) {
1569 chip->write_buf(mtd, buf, eccsize);
1570 buf += eccsize;
1571
1572 if (chip->ecc.prepad) {
1573 chip->write_buf(mtd, oob, chip->ecc.prepad);
1574 oob += chip->ecc.prepad;
1575 }
1576
1577 chip->read_buf(mtd, oob, eccbytes);
1578 oob += eccbytes;
1579
1580 if (chip->ecc.postpad) {
1581 chip->write_buf(mtd, oob, chip->ecc.postpad);
1582 oob += chip->ecc.postpad;
1583 }
1584 }
1585
1586 size = mtd->oobsize - (oob - chip->oob_poi);
1587 if (size)
1588 chip->write_buf(mtd, oob, size);
1589}
1590/**
1494 * nand_write_page_swecc - [REPLACABLE] software ecc based page write function 1591 * nand_write_page_swecc - [REPLACABLE] software ecc based page write function
1495 * @mtd: mtd info structure 1592 * @mtd: mtd info structure
1496 * @chip: nand chip info structure 1593 * @chip: nand chip info structure
@@ -1863,7 +1960,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1863 } 1960 }
1864 1961
1865 if (unlikely(ops->ooboffs >= len)) { 1962 if (unlikely(ops->ooboffs >= len)) {
1866 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: " 1963 DEBUG(MTD_DEBUG_LEVEL0, "nand_do_write_oob: "
1867 "Attempt to start write outside oob\n"); 1964 "Attempt to start write outside oob\n");
1868 return -EINVAL; 1965 return -EINVAL;
1869 } 1966 }
@@ -1873,7 +1970,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1873 ops->ooboffs + ops->ooblen > 1970 ops->ooboffs + ops->ooblen >
1874 ((mtd->size >> chip->page_shift) - 1971 ((mtd->size >> chip->page_shift) -
1875 (to >> chip->page_shift)) * len)) { 1972 (to >> chip->page_shift)) * len)) {
1876 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: " 1973 DEBUG(MTD_DEBUG_LEVEL0, "nand_do_write_oob: "
1877 "Attempt write beyond end of device\n"); 1974 "Attempt write beyond end of device\n");
1878 return -EINVAL; 1975 return -EINVAL;
1879 } 1976 }
@@ -1929,8 +2026,8 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
1929 2026
1930 /* Do not allow writes past end of device */ 2027 /* Do not allow writes past end of device */
1931 if (ops->datbuf && (to + ops->len) > mtd->size) { 2028 if (ops->datbuf && (to + ops->len) > mtd->size) {
1932 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: " 2029 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: "
1933 "Attempt read beyond end of device\n"); 2030 "Attempt write beyond end of device\n");
1934 return -EINVAL; 2031 return -EINVAL;
1935 } 2032 }
1936 2033
@@ -2555,6 +2652,9 @@ int nand_scan_tail(struct mtd_info *mtd)
2555 case 64: 2652 case 64:
2556 chip->ecc.layout = &nand_oob_64; 2653 chip->ecc.layout = &nand_oob_64;
2557 break; 2654 break;
2655 case 128:
2656 chip->ecc.layout = &nand_oob_128;
2657 break;
2558 default: 2658 default:
2559 printk(KERN_WARNING "No oob scheme defined for " 2659 printk(KERN_WARNING "No oob scheme defined for "
2560 "oobsize %d\n", mtd->oobsize); 2660 "oobsize %d\n", mtd->oobsize);
@@ -2569,10 +2669,6 @@ int nand_scan_tail(struct mtd_info *mtd)
2569 * check ECC mode, default to software if 3byte/512byte hardware ECC is 2669 * check ECC mode, default to software if 3byte/512byte hardware ECC is
2570 * selected and we have 256 byte pagesize fallback to software ECC 2670 * selected and we have 256 byte pagesize fallback to software ECC
2571 */ 2671 */
2572 if (!chip->ecc.read_page_raw)
2573 chip->ecc.read_page_raw = nand_read_page_raw;
2574 if (!chip->ecc.write_page_raw)
2575 chip->ecc.write_page_raw = nand_write_page_raw;
2576 2672
2577 switch (chip->ecc.mode) { 2673 switch (chip->ecc.mode) {
2578 case NAND_ECC_HW: 2674 case NAND_ECC_HW:
@@ -2581,6 +2677,10 @@ int nand_scan_tail(struct mtd_info *mtd)
2581 chip->ecc.read_page = nand_read_page_hwecc; 2677 chip->ecc.read_page = nand_read_page_hwecc;
2582 if (!chip->ecc.write_page) 2678 if (!chip->ecc.write_page)
2583 chip->ecc.write_page = nand_write_page_hwecc; 2679 chip->ecc.write_page = nand_write_page_hwecc;
2680 if (!chip->ecc.read_page_raw)
2681 chip->ecc.read_page_raw = nand_read_page_raw;
2682 if (!chip->ecc.write_page_raw)
2683 chip->ecc.write_page_raw = nand_write_page_raw;
2584 if (!chip->ecc.read_oob) 2684 if (!chip->ecc.read_oob)
2585 chip->ecc.read_oob = nand_read_oob_std; 2685 chip->ecc.read_oob = nand_read_oob_std;
2586 if (!chip->ecc.write_oob) 2686 if (!chip->ecc.write_oob)
@@ -2602,6 +2702,10 @@ int nand_scan_tail(struct mtd_info *mtd)
2602 chip->ecc.read_page = nand_read_page_syndrome; 2702 chip->ecc.read_page = nand_read_page_syndrome;
2603 if (!chip->ecc.write_page) 2703 if (!chip->ecc.write_page)
2604 chip->ecc.write_page = nand_write_page_syndrome; 2704 chip->ecc.write_page = nand_write_page_syndrome;
2705 if (!chip->ecc.read_page_raw)
2706 chip->ecc.read_page_raw = nand_read_page_raw_syndrome;
2707 if (!chip->ecc.write_page_raw)
2708 chip->ecc.write_page_raw = nand_write_page_raw_syndrome;
2605 if (!chip->ecc.read_oob) 2709 if (!chip->ecc.read_oob)
2606 chip->ecc.read_oob = nand_read_oob_syndrome; 2710 chip->ecc.read_oob = nand_read_oob_syndrome;
2607 if (!chip->ecc.write_oob) 2711 if (!chip->ecc.write_oob)
@@ -2620,6 +2724,8 @@ int nand_scan_tail(struct mtd_info *mtd)
2620 chip->ecc.read_page = nand_read_page_swecc; 2724 chip->ecc.read_page = nand_read_page_swecc;
2621 chip->ecc.read_subpage = nand_read_subpage; 2725 chip->ecc.read_subpage = nand_read_subpage;
2622 chip->ecc.write_page = nand_write_page_swecc; 2726 chip->ecc.write_page = nand_write_page_swecc;
2727 chip->ecc.read_page_raw = nand_read_page_raw;
2728 chip->ecc.write_page_raw = nand_write_page_raw;
2623 chip->ecc.read_oob = nand_read_oob_std; 2729 chip->ecc.read_oob = nand_read_oob_std;
2624 chip->ecc.write_oob = nand_write_oob_std; 2730 chip->ecc.write_oob = nand_write_oob_std;
2625 chip->ecc.size = 256; 2731 chip->ecc.size = 256;
@@ -2632,6 +2738,8 @@ int nand_scan_tail(struct mtd_info *mtd)
2632 chip->ecc.read_page = nand_read_page_raw; 2738 chip->ecc.read_page = nand_read_page_raw;
2633 chip->ecc.write_page = nand_write_page_raw; 2739 chip->ecc.write_page = nand_write_page_raw;
2634 chip->ecc.read_oob = nand_read_oob_std; 2740 chip->ecc.read_oob = nand_read_oob_std;
2741 chip->ecc.read_page_raw = nand_read_page_raw;
2742 chip->ecc.write_page_raw = nand_write_page_raw;
2635 chip->ecc.write_oob = nand_write_oob_std; 2743 chip->ecc.write_oob = nand_write_oob_std;
2636 chip->ecc.size = mtd->writesize; 2744 chip->ecc.size = mtd->writesize;
2637 chip->ecc.bytes = 0; 2745 chip->ecc.bytes = 0;
@@ -2676,6 +2784,7 @@ int nand_scan_tail(struct mtd_info *mtd)
2676 break; 2784 break;
2677 case 4: 2785 case 4:
2678 case 8: 2786 case 8:
2787 case 16:
2679 mtd->subpage_sft = 2; 2788 mtd->subpage_sft = 2;
2680 break; 2789 break;
2681 } 2790 }