Root/
Source at commit 1c406da created 12 years 7 months ago. By Xiangfu Liu, ben nanonote: forward patches to linux-3.0 | |
---|---|
1 | From e4e1ca7caccf399366d8dbbf6539217e2c7ea852 Mon Sep 17 00:00:00 2001 |
2 | From: Xiangfu Liu <xiangfu@macbook.(none)> |
3 | Date: Fri, 19 Aug 2011 15:45:59 +0800 |
4 | Subject: [PATCH 20/29] 903-NAND-Add-support-for-subpage-reads-for-NAND_ECC_HW_O.patch |
5 | |
6 | --- |
7 | drivers/mtd/nand/nand_base.c | 78 ++++++++++++++++++++++++++++++++++++++++-- |
8 | include/linux/mtd/nand.h | 8 ++-- |
9 | 2 files changed, 79 insertions(+), 7 deletions(-) |
10 | |
11 | diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c |
12 | index a9afe23..f1214af 100644 |
13 | --- a/drivers/mtd/nand/nand_base.c |
14 | +++ b/drivers/mtd/nand/nand_base.c |
15 | @@ -1156,7 +1156,7 @@ static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, |
16 | * @bufpoi: buffer to store read data |
17 | */ |
18 | static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, |
19 | - uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi) |
20 | + uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi, int page) |
21 | { |
22 | int start_step, end_step, num_steps; |
23 | uint32_t *eccpos = chip->ecc.layout->eccpos; |
24 | @@ -1334,6 +1334,75 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd, |
25 | return 0; |
26 | } |
27 | |
28 | + /** |
29 | + * nand_read_subpage_hwecc_oob_first - [REPLACABLE] hw ecc based sub-page read function |
30 | + * @mtd: mtd info structure |
31 | + * @chip: nand chip info structure |
32 | + * @data_offs: offset of requested data within the page |
33 | + * @readlen: data length |
34 | + * @bufpoi: buffer to store read data |
35 | + * @page: page number to read |
36 | + * |
37 | + * Hardware ECC for large page chips, require OOB to be read first. |
38 | + * For this ECC mode, the write_page method is re-used from ECC_HW. |
39 | + * These methods read/write ECC from the OOB area, unlike the |
40 | + * ECC_HW_SYNDROME support with multiple ECC steps, follows the |
41 | + * "infix ECC" scheme and reads/writes ECC from the data area, by |
42 | + * overwriting the NAND manufacturer bad block markings. |
43 | + */ |
44 | +static int nand_read_subpage_hwecc_oob_first(struct mtd_info *mtd, struct nand_chip *chip, |
45 | + uint32_t data_offs, uint32_t readlen, uint8_t *bufpoi, int page) |
46 | +{ |
47 | + int start_step, end_step, num_steps; |
48 | + uint32_t *eccpos = chip->ecc.layout->eccpos; |
49 | + uint8_t *p; |
50 | + int data_col_addr; |
51 | + int eccsize = chip->ecc.size; |
52 | + int eccbytes = chip->ecc.bytes; |
53 | + uint8_t *ecc_code = chip->buffers->ecccode; |
54 | + uint8_t *ecc_calc = chip->buffers->ecccalc; |
55 | + int i; |
56 | + |
57 | + /* Column address wihin the page aligned to ECC size */ |
58 | + start_step = data_offs / chip->ecc.size; |
59 | + end_step = (data_offs + readlen - 1) / chip->ecc.size; |
60 | + num_steps = end_step - start_step + 1; |
61 | + |
62 | + data_col_addr = start_step * chip->ecc.size; |
63 | + |
64 | + /* Read the OOB area first */ |
65 | + if (mtd->writesize > 512) { |
66 | + chip->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page); |
67 | + chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); |
68 | + chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_col_addr, -1); |
69 | + } else { |
70 | + chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page); |
71 | + chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); |
72 | + chip->cmdfunc(mtd, NAND_CMD_READ0, data_col_addr, page); |
73 | + } |
74 | + |
75 | + for (i = 0; i < chip->ecc.total; i++) |
76 | + ecc_code[i] = chip->oob_poi[eccpos[i]]; |
77 | + |
78 | + p = bufpoi + data_col_addr; |
79 | + |
80 | + for (i = eccbytes * start_step; num_steps; num_steps--, i += eccbytes, p += eccsize) { |
81 | + int stat; |
82 | + |
83 | + chip->ecc.hwctl(mtd, NAND_ECC_READ); |
84 | + chip->read_buf(mtd, p, eccsize); |
85 | + chip->ecc.calculate(mtd, p, &ecc_calc[i]); |
86 | + |
87 | + stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL); |
88 | + if (stat < 0) |
89 | + mtd->ecc_stats.failed++; |
90 | + else |
91 | + mtd->ecc_stats.corrected += stat; |
92 | + } |
93 | + |
94 | + return 0; |
95 | +} |
96 | + |
97 | /** |
98 | * nand_read_page_syndrome - [REPLACABLE] hardware ecc syndrom based page read |
99 | * @mtd: mtd info structure |
100 | @@ -1494,7 +1563,7 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, |
101 | bufpoi, page); |
102 | else if (!aligned && NAND_SUBPAGE_READ(chip) && !oob) |
103 | ret = chip->ecc.read_subpage(mtd, chip, |
104 | - col, bytes, bufpoi); |
105 | + col, bytes, bufpoi, page); |
106 | else |
107 | ret = chip->ecc.read_page(mtd, chip, bufpoi, |
108 | page); |
109 | @@ -3286,8 +3355,11 @@ int nand_scan_tail(struct mtd_info *mtd) |
110 | "Hardware ECC not possible\n"); |
111 | BUG(); |
112 | } |
113 | - if (!chip->ecc.read_page) |
114 | + if (!chip->ecc.read_page) { |
115 | chip->ecc.read_page = nand_read_page_hwecc_oob_first; |
116 | + if (!chip->ecc.read_subpage) |
117 | + chip->ecc.read_subpage = nand_read_subpage_hwecc_oob_first; |
118 | + } |
119 | |
120 | case NAND_ECC_HW: |
121 | /* Use standard hwecc read page function ? */ |
122 | diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h |
123 | index c2b9ac4..85e8847 100644 |
124 | --- a/include/linux/mtd/nand.h |
125 | +++ b/include/linux/mtd/nand.h |
126 | @@ -211,9 +211,9 @@ typedef enum { |
127 | #define NAND_MUST_PAD(chip) (!(chip->options & NAND_NO_PADDING)) |
128 | #define NAND_HAS_CACHEPROG(chip) ((chip->options & NAND_CACHEPRG)) |
129 | #define NAND_HAS_COPYBACK(chip) ((chip->options & NAND_COPYBACK)) |
130 | -/* Large page NAND with SOFT_ECC should support subpage reads */ |
131 | -#define NAND_SUBPAGE_READ(chip) ((chip->ecc.mode == NAND_ECC_SOFT) \ |
132 | - && (chip->page_shift > 9)) |
133 | +/* Large page NAND with read_subpage should support subpage reads */ |
134 | +#define NAND_SUBPAGE_READ(chip) (((chip)->ecc.read_subpage) \ |
135 | + && ((chip)->page_shift > 9)) |
136 | |
137 | /* Mask to zero out the chip options, which come from the id table */ |
138 | #define NAND_CHIPOPTIONS_MSK (0x0000ffff & ~NAND_NO_AUTOINCR) |
139 | @@ -377,7 +377,7 @@ struct nand_ecc_ctrl { |
140 | int (*read_page)(struct mtd_info *mtd, struct nand_chip *chip, |
141 | uint8_t *buf, int page); |
142 | int (*read_subpage)(struct mtd_info *mtd, struct nand_chip *chip, |
143 | - uint32_t offs, uint32_t len, uint8_t *buf); |
144 | + uint32_t offs, uint32_t len, uint8_t *buf, int page); |
145 | void (*write_page)(struct mtd_info *mtd, struct nand_chip *chip, |
146 | const uint8_t *buf); |
147 | int (*read_oob)(struct mtd_info *mtd, struct nand_chip *chip, int page, |
148 | -- |
149 | 1.7.4.1 |
150 | |
151 |