kernel: refresh patches
[openwrt/openwrt.git] / target / linux / generic / pending-5.15 / 487-mtd-spinand-Add-support-for-Etron-EM73D044VCx.patch
1 --- a/drivers/mtd/nand/spi/Makefile
2 +++ b/drivers/mtd/nand/spi/Makefile
3 @@ -1,3 +1,3 @@
4 # SPDX-License-Identifier: GPL-2.0
5 -spinand-objs := core.o esmt.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
6 +spinand-objs := core.o esmt.o etron.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
7 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
8 --- a/drivers/mtd/nand/spi/core.c
9 +++ b/drivers/mtd/nand/spi/core.c
10 @@ -898,6 +898,7 @@ static const struct nand_ops spinand_ops
11 static const struct spinand_manufacturer *spinand_manufacturers[] = {
12 &esmt_c8_spinand_manufacturer,
13 &gigadevice_spinand_manufacturer,
14 + &etron_spinand_manufacturer,
15 &macronix_spinand_manufacturer,
16 &micron_spinand_manufacturer,
17 &paragon_spinand_manufacturer,
18 --- /dev/null
19 +++ b/drivers/mtd/nand/spi/etron.c
20 @@ -0,0 +1,98 @@
21 +// SPDX-License-Identifier: GPL-2.0
22 +
23 +#include <linux/device.h>
24 +#include <linux/kernel.h>
25 +#include <linux/mtd/spinand.h>
26 +
27 +#define SPINAND_MFR_ETRON 0xd5
28 +
29 +
30 +static SPINAND_OP_VARIANTS(read_cache_variants,
31 + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
32 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
33 + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
34 + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
35 + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
36 + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
37 +
38 +static SPINAND_OP_VARIANTS(write_cache_variants,
39 + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
40 + SPINAND_PROG_LOAD(true, 0, NULL, 0));
41 +
42 +static SPINAND_OP_VARIANTS(update_cache_variants,
43 + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
44 + SPINAND_PROG_LOAD(false, 0, NULL, 0));
45 +
46 +static int etron_ooblayout_ecc(struct mtd_info *mtd, int section,
47 + struct mtd_oob_region *oobregion)
48 +{
49 + if (section)
50 + return -ERANGE;
51 +
52 + oobregion->offset = 72;
53 + oobregion->length = 56;
54 +
55 + return 0;
56 +}
57 +
58 +static int etron_ooblayout_free(struct mtd_info *mtd, int section,
59 + struct mtd_oob_region *oobregion)
60 +{
61 + if (section)
62 + return -ERANGE;
63 +
64 + oobregion->offset = 1;
65 + oobregion->length = 71;
66 +
67 + return 0;
68 +}
69 +
70 +static int etron_ecc_get_status(struct spinand_device *spinand, u8 status)
71 +{
72 + switch (status & STATUS_ECC_MASK) {
73 + case STATUS_ECC_NO_BITFLIPS:
74 + return 0;
75 +
76 + case STATUS_ECC_HAS_BITFLIPS:
77 + /* Between 1-7 bitflips were corrected */
78 + return 7;
79 +
80 + case STATUS_ECC_MASK:
81 + /* Maximum bitflips were corrected */
82 + return 8;
83 +
84 + case STATUS_ECC_UNCOR_ERROR:
85 + return -EBADMSG;
86 + }
87 +
88 + return -EINVAL;
89 +}
90 +
91 +static const struct mtd_ooblayout_ops etron_ooblayout = {
92 + .ecc = etron_ooblayout_ecc,
93 + .free = etron_ooblayout_free,
94 +};
95 +
96 +static const struct spinand_info etron_spinand_table[] = {
97 + SPINAND_INFO("EM73D044VCx",
98 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x1f),
99 + // bpc, pagesize, oobsize, pagesperblock, bperlun, maxbadplun, ppl, lpt, #t
100 + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
101 + NAND_ECCREQ(8, 512),
102 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
103 + &write_cache_variants,
104 + &update_cache_variants),
105 + SPINAND_HAS_QE_BIT,
106 + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
107 +};
108 +
109 +static const struct spinand_manufacturer_ops etron_spinand_manuf_ops = {
110 +};
111 +
112 +const struct spinand_manufacturer etron_spinand_manufacturer = {
113 + .id = SPINAND_MFR_ETRON,
114 + .name = "Etron",
115 + .chips = etron_spinand_table,
116 + .nchips = ARRAY_SIZE(etron_spinand_table),
117 + .ops = &etron_spinand_manuf_ops,
118 +};
119 --- a/include/linux/mtd/spinand.h
120 +++ b/include/linux/mtd/spinand.h
121 @@ -261,6 +261,7 @@ struct spinand_manufacturer {
122
123 /* SPI NAND manufacturers */
124 extern const struct spinand_manufacturer esmt_c8_spinand_manufacturer;
125 +extern const struct spinand_manufacturer etron_spinand_manufacturer;
126 extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
127 extern const struct spinand_manufacturer macronix_spinand_manufacturer;
128 extern const struct spinand_manufacturer micron_spinand_manufacturer;