提交 fd2bf3c4 编写于 作者: C Chuanhong Guo 提交者: Yongqiang Liu

mtd: rawnand: fix ecc parameters for mt7622

stable inclusion
from stable-4.19.242
commit bf9fe6ecb19ae11159fcc4f48be9f4b7d62f55bd
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5A6BA
CVE: NA

--------------------------------

[ Upstream commit 9fe4e0d3 ]

According to the datasheet, mt7622 only has 5 ECC capabilities instead
of 7, and the decoding error register is arranged  as follows:
+------+---------+---------+---------+---------+
| Bits |  19:15  |  14:10  |   9:5   |   4:0   |
+------+---------+---------+---------+---------+
| Name | ERRNUM3 | ERRNUM2 | ERRNUM1 | ERRNUM0 |
+------+---------+---------+---------+---------+
This means err_mask should be 0x1f instead of 0x3f and the number of
bits shifted in mtk_ecc_get_stats should be 5 instead of 8.

This commit introduces err_shift for the difference in this register
and fix other existing parameters.

Public MT7622 reference manual can be found on [0] and the info this
commit is based on is from page 656 and page 660.

[0]: https://wiki.banana-pi.org/Banana_Pi_BPI-R64#Documents

Fixes: 98dea8d7 ("mtd: nand: mtk: Support MT7622 NAND flash controller.")
Signed-off-by: NChuanhong Guo <gch981213@gmail.com>
Signed-off-by: NMiquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220402160315.919094-1-gch981213@gmail.comSigned-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYongqiang Liu <liuyongqiang13@huawei.com>
上级 3b523a1d
...@@ -51,6 +51,7 @@ ...@@ -51,6 +51,7 @@
struct mtk_ecc_caps { struct mtk_ecc_caps {
u32 err_mask; u32 err_mask;
u32 err_shift;
const u8 *ecc_strength; const u8 *ecc_strength;
const u32 *ecc_regs; const u32 *ecc_regs;
u8 num_ecc_strength; u8 num_ecc_strength;
...@@ -84,7 +85,7 @@ static const u8 ecc_strength_mt2712[] = { ...@@ -84,7 +85,7 @@ static const u8 ecc_strength_mt2712[] = {
}; };
static const u8 ecc_strength_mt7622[] = { static const u8 ecc_strength_mt7622[] = {
4, 6, 8, 10, 12, 14, 16 4, 6, 8, 10, 12
}; };
enum mtk_ecc_regs { enum mtk_ecc_regs {
...@@ -229,7 +230,7 @@ void mtk_ecc_get_stats(struct mtk_ecc *ecc, struct mtk_ecc_stats *stats, ...@@ -229,7 +230,7 @@ void mtk_ecc_get_stats(struct mtk_ecc *ecc, struct mtk_ecc_stats *stats,
for (i = 0; i < sectors; i++) { for (i = 0; i < sectors; i++) {
offset = (i >> 2) << 2; offset = (i >> 2) << 2;
err = readl(ecc->regs + ECC_DECENUM0 + offset); err = readl(ecc->regs + ECC_DECENUM0 + offset);
err = err >> ((i % 4) * 8); err = err >> ((i % 4) * ecc->caps->err_shift);
err &= ecc->caps->err_mask; err &= ecc->caps->err_mask;
if (err == ecc->caps->err_mask) { if (err == ecc->caps->err_mask) {
/* uncorrectable errors */ /* uncorrectable errors */
...@@ -453,6 +454,7 @@ EXPORT_SYMBOL(mtk_ecc_get_parity_bits); ...@@ -453,6 +454,7 @@ EXPORT_SYMBOL(mtk_ecc_get_parity_bits);
static const struct mtk_ecc_caps mtk_ecc_caps_mt2701 = { static const struct mtk_ecc_caps mtk_ecc_caps_mt2701 = {
.err_mask = 0x3f, .err_mask = 0x3f,
.err_shift = 8,
.ecc_strength = ecc_strength_mt2701, .ecc_strength = ecc_strength_mt2701,
.ecc_regs = mt2701_ecc_regs, .ecc_regs = mt2701_ecc_regs,
.num_ecc_strength = 20, .num_ecc_strength = 20,
...@@ -463,6 +465,7 @@ static const struct mtk_ecc_caps mtk_ecc_caps_mt2701 = { ...@@ -463,6 +465,7 @@ static const struct mtk_ecc_caps mtk_ecc_caps_mt2701 = {
static const struct mtk_ecc_caps mtk_ecc_caps_mt2712 = { static const struct mtk_ecc_caps mtk_ecc_caps_mt2712 = {
.err_mask = 0x7f, .err_mask = 0x7f,
.err_shift = 8,
.ecc_strength = ecc_strength_mt2712, .ecc_strength = ecc_strength_mt2712,
.ecc_regs = mt2712_ecc_regs, .ecc_regs = mt2712_ecc_regs,
.num_ecc_strength = 23, .num_ecc_strength = 23,
...@@ -472,10 +475,11 @@ static const struct mtk_ecc_caps mtk_ecc_caps_mt2712 = { ...@@ -472,10 +475,11 @@ static const struct mtk_ecc_caps mtk_ecc_caps_mt2712 = {
}; };
static const struct mtk_ecc_caps mtk_ecc_caps_mt7622 = { static const struct mtk_ecc_caps mtk_ecc_caps_mt7622 = {
.err_mask = 0x3f, .err_mask = 0x1f,
.err_shift = 5,
.ecc_strength = ecc_strength_mt7622, .ecc_strength = ecc_strength_mt7622,
.ecc_regs = mt7622_ecc_regs, .ecc_regs = mt7622_ecc_regs,
.num_ecc_strength = 7, .num_ecc_strength = 5,
.ecc_mode_shift = 4, .ecc_mode_shift = 4,
.parity_bits = 13, .parity_bits = 13,
.pg_irq_sel = 0, .pg_irq_sel = 0,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册