Skip to content

Commit efebdf4

Browse files
committed
Merge tag 'nand/for-6.18' into mtd/next
* Raw NAND: - Add support for Loongson-2K1000 and Loongson-2K0500 NAND controllers, including extra features, such as chip select and 6-byte NAND ID reading support. - Drop the s3c2410 driver. * SPI NAND: - Important SPI NAND continuous read improvements and fixes. - Add support for FudanMicro FM25S01A. - Add support for continuous reads in Gigadevice vendor driver. * ECC: - Add support for the Realtek ECC engine. This PR comes with the usual amount of various miscellaneous fixes. Signed-off-by: Miquel Raynal <[email protected]>
2 parents 0473d5b + 1001cc1 commit efebdf4

31 files changed

+2033
-2424
lines changed

Documentation/devicetree/bindings/mtd/loongson,ls1b-nand-controller.yaml

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
$id: http://devicetree.org/schemas/mtd/loongson,ls1b-nand-controller.yaml#
55
$schema: http://devicetree.org/meta-schemas/core.yaml#
66

7-
title: Loongson-1 NAND Controller
7+
title: Loongson NAND Controller
88

99
maintainers:
1010
- Keguang Zhang <[email protected]>
11+
- Binbin Zhou <[email protected]>
1112

1213
description:
13-
The Loongson-1 NAND controller abstracts all supported operations,
14+
The Loongson NAND controller abstracts all supported operations,
1415
meaning it does not support low-level access to raw NAND flash chips.
1516
Moreover, the controller is paired with the DMA engine to perform
1617
READ and PROGRAM functions.
@@ -24,18 +25,23 @@ properties:
2425
- enum:
2526
- loongson,ls1b-nand-controller
2627
- loongson,ls1c-nand-controller
28+
- loongson,ls2k0500-nand-controller
29+
- loongson,ls2k1000-nand-controller
2730
- items:
2831
- enum:
2932
- loongson,ls1a-nand-controller
3033
- const: loongson,ls1b-nand-controller
3134

3235
reg:
33-
maxItems: 2
36+
minItems: 2
37+
maxItems: 3
3438

3539
reg-names:
40+
minItems: 2
3641
items:
3742
- const: nand
3843
- const: nand-dma
44+
- const: dma-config
3945

4046
dmas:
4147
maxItems: 1
@@ -52,6 +58,27 @@ required:
5258

5359
unevaluatedProperties: false
5460

61+
if:
62+
properties:
63+
compatible:
64+
contains:
65+
enum:
66+
- loongson,ls2k1000-nand-controller
67+
68+
then:
69+
properties:
70+
reg:
71+
minItems: 3
72+
reg-names:
73+
minItems: 3
74+
75+
else:
76+
properties:
77+
reg:
78+
maxItems: 2
79+
reg-names:
80+
maxItems: 2
81+
5582
examples:
5683
- |
5784
nand-controller@1fe78000 {
@@ -70,3 +97,26 @@ examples:
7097
nand-ecc-algo = "hamming";
7198
};
7299
};
100+
101+
- |
102+
nand-controller@1fe26000 {
103+
compatible = "loongson,ls2k1000-nand-controller";
104+
reg = <0x1fe26000 0x24>,
105+
<0x1fe26040 0x4>,
106+
<0x1fe00438 0x8>;
107+
reg-names = "nand", "nand-dma", "dma-config";
108+
dmas = <&apbdma0 0>;
109+
dma-names = "rxtx";
110+
111+
#address-cells = <1>;
112+
#size-cells = <0>;
113+
114+
nand@0 {
115+
reg = <0>;
116+
label = "ls2k1000-nand";
117+
nand-use-soft-ecc-engine;
118+
nand-ecc-algo = "bch";
119+
nand-ecc-strength = <8>;
120+
nand-ecc-step-size = <512>;
121+
};
122+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/mtd/realtek,rtl9301-ecc.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Realtek SoCs NAND ECC engine
8+
9+
maintainers:
10+
- Markus Stockhausen <[email protected]>
11+
12+
properties:
13+
compatible:
14+
const: realtek,rtl9301-ecc
15+
16+
reg:
17+
maxItems: 1
18+
19+
clocks:
20+
maxItems: 1
21+
22+
interrupts:
23+
maxItems: 1
24+
25+
required:
26+
- compatible
27+
- reg
28+
29+
additionalProperties: false
30+
31+
examples:
32+
- |
33+
soc {
34+
#address-cells = <1>;
35+
#size-cells = <1>;
36+
37+
ecc0: ecc@1a600 {
38+
compatible = "realtek,rtl9301-ecc";
39+
reg = <0x1a600 0x54>;
40+
};
41+
};

Documentation/devicetree/bindings/mtd/samsung-s3c2410.txt

Lines changed: 0 additions & 56 deletions
This file was deleted.

MAINTAINERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16992,7 +16992,7 @@ F: Documentation/devicetree/bindings/*/loongson,ls1*.yaml
1699216992
F: arch/mips/include/asm/mach-loongson32/
1699316993
F: arch/mips/loongson32/
1699416994
F: drivers/*/*loongson1*
16995-
F: drivers/mtd/nand/raw/loongson1-nand-controller.c
16995+
F: drivers/mtd/nand/raw/loongson-nand-controller.c
1699616996
F: drivers/net/ethernet/stmicro/stmmac/dwmac-loongson1.c
1699716997
F: sound/soc/loongson/loongson1_ac97.c
1699816998

drivers/mtd/nand/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ config MTD_NAND_ECC_MEDIATEK
6161
help
6262
This enables support for the hardware ECC engine from Mediatek.
6363

64+
config MTD_NAND_ECC_REALTEK
65+
tristate "Realtek RTL93xx hardware ECC engine"
66+
depends on HAS_IOMEM
67+
depends on MACH_REALTEK_RTL || COMPILE_TEST
68+
select MTD_NAND_ECC
69+
help
70+
This enables support for the hardware ECC engine from Realtek.
71+
6472
endmenu
6573

6674
endmenu

drivers/mtd/nand/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
nandcore-objs := core.o bbt.o
44
obj-$(CONFIG_MTD_NAND_CORE) += nandcore.o
55
obj-$(CONFIG_MTD_NAND_ECC_MEDIATEK) += ecc-mtk.o
6+
obj-$(CONFIG_MTD_NAND_ECC_REALTEK) += ecc-realtek.o
67
obj-$(CONFIG_SPI_QPIC_SNAND) += qpic_common.o
78
obj-$(CONFIG_MTD_NAND_QCOM) += qpic_common.o
89
obj-y += onenand/

drivers/mtd/nand/core.c

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,137 @@
1212
#include <linux/module.h>
1313
#include <linux/mtd/nand.h>
1414

15+
/**
16+
* nand_check_erased_buf - check if a buffer contains (almost) only 0xff data
17+
* @buf: buffer to test
18+
* @len: buffer length
19+
* @bitflips_threshold: maximum number of bitflips
20+
*
21+
* Check if a buffer contains only 0xff, which means the underlying region
22+
* has been erased and is ready to be programmed.
23+
* The bitflips_threshold specify the maximum number of bitflips before
24+
* considering the region is not erased.
25+
* Note: The logic of this function has been extracted from the memweight
26+
* implementation, except that nand_check_erased_buf function exit before
27+
* testing the whole buffer if the number of bitflips exceed the
28+
* bitflips_threshold value.
29+
*
30+
* Returns a positive number of bitflips less than or equal to
31+
* bitflips_threshold, or -ERROR_CODE for bitflips in excess of the
32+
* threshold.
33+
*/
34+
static int nand_check_erased_buf(void *buf, int len, int bitflips_threshold)
35+
{
36+
const unsigned char *bitmap = buf;
37+
int bitflips = 0;
38+
int weight;
39+
40+
for (; len && ((uintptr_t)bitmap) % sizeof(long);
41+
len--, bitmap++) {
42+
weight = hweight8(*bitmap);
43+
bitflips += BITS_PER_BYTE - weight;
44+
if (unlikely(bitflips > bitflips_threshold))
45+
return -EBADMSG;
46+
}
47+
48+
for (; len >= sizeof(long);
49+
len -= sizeof(long), bitmap += sizeof(long)) {
50+
unsigned long d = *((unsigned long *)bitmap);
51+
if (d == ~0UL)
52+
continue;
53+
weight = hweight_long(d);
54+
bitflips += BITS_PER_LONG - weight;
55+
if (unlikely(bitflips > bitflips_threshold))
56+
return -EBADMSG;
57+
}
58+
59+
for (; len > 0; len--, bitmap++) {
60+
weight = hweight8(*bitmap);
61+
bitflips += BITS_PER_BYTE - weight;
62+
if (unlikely(bitflips > bitflips_threshold))
63+
return -EBADMSG;
64+
}
65+
66+
return bitflips;
67+
}
68+
69+
/**
70+
* nand_check_erased_ecc_chunk - check if an ECC chunk contains (almost) only
71+
* 0xff data
72+
* @data: data buffer to test
73+
* @datalen: data length
74+
* @ecc: ECC buffer
75+
* @ecclen: ECC length
76+
* @extraoob: extra OOB buffer
77+
* @extraooblen: extra OOB length
78+
* @bitflips_threshold: maximum number of bitflips
79+
*
80+
* Check if a data buffer and its associated ECC and OOB data contains only
81+
* 0xff pattern, which means the underlying region has been erased and is
82+
* ready to be programmed.
83+
* The bitflips_threshold specify the maximum number of bitflips before
84+
* considering the region as not erased.
85+
*
86+
* Note:
87+
* 1/ ECC algorithms are working on pre-defined block sizes which are usually
88+
* different from the NAND page size. When fixing bitflips, ECC engines will
89+
* report the number of errors per chunk, and the NAND core infrastructure
90+
* expect you to return the maximum number of bitflips for the whole page.
91+
* This is why you should always use this function on a single chunk and
92+
* not on the whole page. After checking each chunk you should update your
93+
* max_bitflips value accordingly.
94+
* 2/ When checking for bitflips in erased pages you should not only check
95+
* the payload data but also their associated ECC data, because a user might
96+
* have programmed almost all bits to 1 but a few. In this case, we
97+
* shouldn't consider the chunk as erased, and checking ECC bytes prevent
98+
* this case.
99+
* 3/ The extraoob argument is optional, and should be used if some of your OOB
100+
* data are protected by the ECC engine.
101+
* It could also be used if you support subpages and want to attach some
102+
* extra OOB data to an ECC chunk.
103+
*
104+
* Returns a positive number of bitflips less than or equal to
105+
* bitflips_threshold, or -ERROR_CODE for bitflips in excess of the
106+
* threshold. In case of success, the passed buffers are filled with 0xff.
107+
*/
108+
int nand_check_erased_ecc_chunk(void *data, int datalen,
109+
void *ecc, int ecclen,
110+
void *extraoob, int extraooblen,
111+
int bitflips_threshold)
112+
{
113+
int data_bitflips = 0, ecc_bitflips = 0, extraoob_bitflips = 0;
114+
115+
data_bitflips = nand_check_erased_buf(data, datalen,
116+
bitflips_threshold);
117+
if (data_bitflips < 0)
118+
return data_bitflips;
119+
120+
bitflips_threshold -= data_bitflips;
121+
122+
ecc_bitflips = nand_check_erased_buf(ecc, ecclen, bitflips_threshold);
123+
if (ecc_bitflips < 0)
124+
return ecc_bitflips;
125+
126+
bitflips_threshold -= ecc_bitflips;
127+
128+
extraoob_bitflips = nand_check_erased_buf(extraoob, extraooblen,
129+
bitflips_threshold);
130+
if (extraoob_bitflips < 0)
131+
return extraoob_bitflips;
132+
133+
if (data_bitflips)
134+
memset(data, 0xff, datalen);
135+
136+
if (ecc_bitflips)
137+
memset(ecc, 0xff, ecclen);
138+
139+
if (extraoob_bitflips)
140+
memset(extraoob, 0xff, extraooblen);
141+
142+
return data_bitflips + ecc_bitflips + extraoob_bitflips;
143+
}
144+
EXPORT_SYMBOL(nand_check_erased_ecc_chunk);
145+
15146
/**
16147
* nanddev_isbad() - Check if a block is bad
17148
* @nand: NAND device

drivers/mtd/nand/ecc-mxic.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -322,14 +322,14 @@ static int mxic_ecc_init_ctx(struct nand_device *nand, struct device *dev)
322322
sg_init_table(ctx->sg, 2);
323323

324324
/* Configuration dump and sanity checks */
325-
dev_err(dev, "DPE version number: %d\n",
325+
dev_dbg(dev, "DPE version number: %d\n",
326326
readl(mxic->regs + DP_VER) >> DP_VER_OFFSET);
327-
dev_err(dev, "Chunk size: %d\n", readl(mxic->regs + CHUNK_SIZE));
328-
dev_err(dev, "Main size: %d\n", readl(mxic->regs + MAIN_SIZE));
329-
dev_err(dev, "Spare size: %d\n", SPARE_SZ(spare_reg));
330-
dev_err(dev, "Rsv size: %ld\n", RSV_SZ(spare_reg));
331-
dev_err(dev, "Parity size: %d\n", ctx->parity_sz);
332-
dev_err(dev, "Meta size: %d\n", ctx->meta_sz);
327+
dev_dbg(dev, "Chunk size: %d\n", readl(mxic->regs + CHUNK_SIZE));
328+
dev_dbg(dev, "Main size: %d\n", readl(mxic->regs + MAIN_SIZE));
329+
dev_dbg(dev, "Spare size: %d\n", SPARE_SZ(spare_reg));
330+
dev_dbg(dev, "Rsv size: %ld\n", RSV_SZ(spare_reg));
331+
dev_dbg(dev, "Parity size: %d\n", ctx->parity_sz);
332+
dev_dbg(dev, "Meta size: %d\n", ctx->meta_sz);
333333

334334
if ((ctx->meta_sz + ctx->parity_sz + RSV_SZ(spare_reg)) !=
335335
SPARE_SZ(spare_reg)) {

0 commit comments

Comments
 (0)