7dbcf2fcdaf9ac64045128bb6241e084c046ba07
[openwrt/openwrt.git] / target / linux / mediatek / patches-5.15 / 120-10-v5.18-mtd-nand-fix-ecc-parameters-for-mt7622.patch
1 From 41825166744c6e5664281611f5e6d9a2e9333c2b Mon Sep 17 00:00:00 2001
2 From: Chuanhong Guo <gch981213@gmail.com>
3 Date: Sat, 2 Apr 2022 22:31:20 +0800
4 Subject: [PATCH 10/15] mtd: nand: fix ecc parameters for mt7622
5
6 According to the datasheet, mt7622 only has 5 ECC capabilities instead
7 of 7, and the decoding error register is arranged as follows:
8 +------+---------+---------+---------+---------+
9 | Bits | 19:15 | 14:10 | 9:5 | 4:0 |
10 +------+---------+---------+---------+---------+
11 | Name | ERRNUM3 | ERRNUM2 | ERRNUM1 | ERRNUM0 |
12 +------+---------+---------+---------+---------+
13 This means err_mask should be 0x1f instead of 0x3f and the number of
14 bits shifted in mtk_ecc_get_stats should be 5 instead of 8.
15
16 This commit introduces err_shift for the difference in this register
17 and fix other existing parameters.
18
19 Public MT7622 reference manual can be found on [0] and the info this
20 commit is based on is from page 656 and page 660.
21
22 [0]: https://wiki.banana-pi.org/Banana_Pi_BPI-R64#Documents
23
24 Fixes: 98dea8d71931 ("mtd: nand: mtk: Support MT7622 NAND flash controller.")
25 Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
26 (cherry picked from commit 088b769abd1bd21753002b17b696ae1778b16e8c)
27 ---
28 drivers/mtd/nand/raw/mtk_ecc.c | 12 ++++++++----
29 1 file changed, 8 insertions(+), 4 deletions(-)
30
31 diff --git a/drivers/mtd/nand/raw/mtk_ecc.c b/drivers/mtd/nand/raw/mtk_ecc.c
32 index c437d97debb8..ec9d1fb07006 100644
33 --- a/drivers/mtd/nand/raw/mtk_ecc.c
34 +++ b/drivers/mtd/nand/raw/mtk_ecc.c
35 @@ -43,6 +43,7 @@
36
37 struct mtk_ecc_caps {
38 u32 err_mask;
39 + u32 err_shift;
40 const u8 *ecc_strength;
41 const u32 *ecc_regs;
42 u8 num_ecc_strength;
43 @@ -76,7 +77,7 @@ static const u8 ecc_strength_mt2712[] = {
44 };
45
46 static const u8 ecc_strength_mt7622[] = {
47 - 4, 6, 8, 10, 12, 14, 16
48 + 4, 6, 8, 10, 12
49 };
50
51 enum mtk_ecc_regs {
52 @@ -221,7 +222,7 @@ void mtk_ecc_get_stats(struct mtk_ecc *ecc, struct mtk_ecc_stats *stats,
53 for (i = 0; i < sectors; i++) {
54 offset = (i >> 2) << 2;
55 err = readl(ecc->regs + ECC_DECENUM0 + offset);
56 - err = err >> ((i % 4) * 8);
57 + err = err >> ((i % 4) * ecc->caps->err_shift);
58 err &= ecc->caps->err_mask;
59 if (err == ecc->caps->err_mask) {
60 /* uncorrectable errors */
61 @@ -449,6 +450,7 @@ EXPORT_SYMBOL(mtk_ecc_get_parity_bits);
62
63 static const struct mtk_ecc_caps mtk_ecc_caps_mt2701 = {
64 .err_mask = 0x3f,
65 + .err_shift = 8,
66 .ecc_strength = ecc_strength_mt2701,
67 .ecc_regs = mt2701_ecc_regs,
68 .num_ecc_strength = 20,
69 @@ -459,6 +461,7 @@ static const struct mtk_ecc_caps mtk_ecc_caps_mt2701 = {
70
71 static const struct mtk_ecc_caps mtk_ecc_caps_mt2712 = {
72 .err_mask = 0x7f,
73 + .err_shift = 8,
74 .ecc_strength = ecc_strength_mt2712,
75 .ecc_regs = mt2712_ecc_regs,
76 .num_ecc_strength = 23,
77 @@ -468,10 +471,11 @@ static const struct mtk_ecc_caps mtk_ecc_caps_mt2712 = {
78 };
79
80 static const struct mtk_ecc_caps mtk_ecc_caps_mt7622 = {
81 - .err_mask = 0x3f,
82 + .err_mask = 0x1f,
83 + .err_shift = 5,
84 .ecc_strength = ecc_strength_mt7622,
85 .ecc_regs = mt7622_ecc_regs,
86 - .num_ecc_strength = 7,
87 + .num_ecc_strength = 5,
88 .ecc_mode_shift = 4,
89 .parity_bits = 13,
90 .pg_irq_sel = 0,
91 --
92 2.35.1
93