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