xburst: Add 3.10 support
[openwrt/svn-archive/archive.git] / target / linux / xburst / patches-3.10 / 003-NAND-Add-support-for-subpage-reads-for-NAND_ECC_HW_O.patch
1 From 90e325c5e16db262818bca442b00f5ac10b9c852 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Tue, 15 Mar 2011 12:33:41 +0100
4 Subject: [PATCH 03/16] NAND: Add support for subpage reads for
5 NAND_ECC_HW_OOB_FIRST
6
7 Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
8 ---
9 drivers/mtd/nand/nand_base.c | 80 ++++++++++++++++++++++++++++++++++++++++--
10 include/linux/mtd/nand.h | 2 +-
11 2 files changed, 78 insertions(+), 4 deletions(-)
12
13 diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
14 index 287c433..0fd6f2e 100644
15 --- a/drivers/mtd/nand/nand_base.c
16 +++ b/drivers/mtd/nand/nand_base.c
17 @@ -1118,7 +1118,7 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip,
18 * @bufpoi: buffer to store read data
19 */
20 static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
21 - uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi)
22 + uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi, int page)
23 {
24 int start_step, end_step, num_steps;
25 uint32_t *eccpos = chip->ecc.layout->eccpos;
26 @@ -1311,6 +1311,75 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,
27 }
28
29 /**
30 + * nand_read_subpage_hwecc_oob_first - [REPLACABLE] hw ecc based sub-page read function
31 + * @mtd: mtd info structure
32 + * @chip: nand chip info structure
33 + * @data_offs: offset of requested data within the page
34 + * @readlen: data length
35 + * @bufpoi: buffer to store read data
36 + * @page: page number to read
37 + *
38 + * Hardware ECC for large page chips, require OOB to be read first.
39 + * For this ECC mode, the write_page method is re-used from ECC_HW.
40 + * These methods read/write ECC from the OOB area, unlike the
41 + * ECC_HW_SYNDROME support with multiple ECC steps, follows the
42 + * "infix ECC" scheme and reads/writes ECC from the data area, by
43 + * overwriting the NAND manufacturer bad block markings.
44 + */
45 +static int nand_read_subpage_hwecc_oob_first(struct mtd_info *mtd, struct nand_chip *chip,
46 + uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi, int page)
47 +{
48 + int start_step, end_step, num_steps;
49 + uint32_t *eccpos = chip->ecc.layout->eccpos;
50 + uint8_t *p;
51 + int data_col_addr;
52 + int eccsize = chip->ecc.size;
53 + int eccbytes = chip->ecc.bytes;
54 + uint8_t *ecc_code = chip->buffers->ecccode;
55 + uint8_t *ecc_calc = chip->buffers->ecccalc;
56 + int i;
57 +
58 + /* Column address wihin the page aligned to ECC size */
59 + start_step = data_offs / chip->ecc.size;
60 + end_step = (data_offs + readlen - 1) / chip->ecc.size;
61 + num_steps = end_step - start_step + 1;
62 +
63 + data_col_addr = start_step * chip->ecc.size;
64 +
65 + /* Read the OOB area first */
66 + if (mtd->writesize > 512) {
67 + chip->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page);
68 + chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
69 + chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_col_addr, -1);
70 + } else {
71 + chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
72 + chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
73 + chip->cmdfunc(mtd, NAND_CMD_READ0, data_col_addr, page);
74 + }
75 +
76 + for (i = 0; i < chip->ecc.total; i++)
77 + ecc_code[i] = chip->oob_poi[eccpos[i]];
78 +
79 + p = bufpoi + data_col_addr;
80 +
81 + for (i = eccbytes * start_step; num_steps; num_steps--, i += eccbytes, p += eccsize) {
82 + int stat;
83 +
84 + chip->ecc.hwctl(mtd, NAND_ECC_READ);
85 + chip->read_buf(mtd, p, eccsize);
86 + chip->ecc.calculate(mtd, p, &ecc_calc[i]);
87 +
88 + stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL);
89 + if (stat < 0)
90 + mtd->ecc_stats.failed++;
91 + else
92 + mtd->ecc_stats.corrected += stat;
93 + }
94 +
95 + return 0;
96 +}
97 +
98 +/**
99 * nand_read_page_syndrome - [REPLACEABLE] hardware ECC syndrome based page read
100 * @mtd: mtd info structure
101 * @chip: nand chip info structure
102 @@ -1477,7 +1546,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from,
103 else if (!aligned && NAND_HAS_SUBPAGE_READ(chip) &&
104 !oob)
105 ret = chip->ecc.read_subpage(mtd, chip,
106 - col, bytes, bufpoi);
107 + col, bytes, bufpoi, page);
108 else
109 ret = chip->ecc.read_page(mtd, chip, bufpoi,
110 oob_required, page);
111 @@ -3475,8 +3544,13 @@ int nand_scan_tail(struct mtd_info *mtd)
112 "hardware ECC not possible\n");
113 BUG();
114 }
115 - if (!chip->ecc.read_page)
116 + if (!chip->ecc.read_page) {
117 chip->ecc.read_page = nand_read_page_hwecc_oob_first;
118 + if (!chip->ecc.read_subpage) {
119 + chip->ecc.read_subpage = nand_read_subpage_hwecc_oob_first;
120 + chip->options |= NAND_SUBPAGE_READ;
121 + }
122 + }
123
124 case NAND_ECC_HW:
125 /* Use standard hwecc read page function? */
126 diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
127 index ab63634..ff5b62e 100644
128 --- a/include/linux/mtd/nand.h
129 +++ b/include/linux/mtd/nand.h
130 @@ -349,7 +349,7 @@ struct nand_ecc_ctrl {
131 int (*read_page)(struct mtd_info *mtd, struct nand_chip *chip,
132 uint8_t *buf, int oob_required, int page);
133 int (*read_subpage)(struct mtd_info *mtd, struct nand_chip *chip,
134 - uint32_t offs, uint32_t len, uint8_t *buf);
135 + uint32_t offs, uint32_t len, uint8_t *buf, int page);
136 int (*write_subpage)(struct mtd_info *mtd, struct nand_chip *chip,
137 uint32_t offset, uint32_t data_len,
138 const uint8_t *data_buf, int oob_required);
139 --
140 1.7.10.4
141