kernel: bump 6.1 to 6.1.63
[openwrt/openwrt.git] / target / linux / generic / pending-6.1 / 487-mtd-spinand-Add-support-for-Etron-EM73D044VCx.patch
1 From f32085fc0b87049491b07e198d924d738a1a2834 Mon Sep 17 00:00:00 2001
2 From: Daniel Danzberger <daniel@dd-wrt.com>
3 Date: Wed, 3 Aug 2022 17:31:03 +0200
4 Subject: [PATCH] mtd: spinand: Add support for Etron EM73D044VCx
5
6 Airoha is a new ARM platform based on Cortex-A53 which has recently been
7 merged into linux-next.
8
9 Due to BootROM limitations on this platform, the Cortex-A53 can't run in
10 Aarch64 mode and code must be compiled for 32-Bit ARM.
11
12 This support is based mostly on those linux-next commits backported
13 for kernel 5.15.
14
15 Patches:
16 1 - platform support = linux-next
17 2 - clock driver = linux-next
18 3 - gpio driver = linux-next
19 4 - linux,usable-memory-range dts support = linux-next
20 5 - mtd spinand driver
21 6 - spi driver
22 7 - pci driver (kconfig only, uses mediatek PCI) = linux-next
23
24 Still missing:
25 - Ethernet driver
26 - Sysupgrade support
27
28 A.t.m there exists one subtarget EN7523 with only one evaluation
29 board.
30
31 The initramfs can be run with the following commands from u-boot:
32 -
33 u-boot> setenv bootfile \
34 openwrt-airoha-airoha_en7523-evb-initramfs-kernel.bin
35 u-boot> tftpboot
36 u-boot> bootm 0x81800000
37 -
38
39 Submitted-by: Daniel Danzberger <daniel@dd-wrt.com>
40
41 --- a/drivers/mtd/nand/spi/Makefile
42 +++ b/drivers/mtd/nand/spi/Makefile
43 @@ -1,3 +1,3 @@
44 # SPDX-License-Identifier: GPL-2.0
45 -spinand-objs := core.o ato.o esmt.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
46 +spinand-objs := core.o ato.o esmt.o etron.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
47 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
48 --- a/drivers/mtd/nand/spi/core.c
49 +++ b/drivers/mtd/nand/spi/core.c
50 @@ -939,6 +939,7 @@ static const struct nand_ops spinand_ops
51 static const struct spinand_manufacturer *spinand_manufacturers[] = {
52 &ato_spinand_manufacturer,
53 &esmt_c8_spinand_manufacturer,
54 + &etron_spinand_manufacturer,
55 &gigadevice_spinand_manufacturer,
56 &macronix_spinand_manufacturer,
57 &micron_spinand_manufacturer,
58 --- /dev/null
59 +++ b/drivers/mtd/nand/spi/etron.c
60 @@ -0,0 +1,98 @@
61 +// SPDX-License-Identifier: GPL-2.0
62 +
63 +#include <linux/device.h>
64 +#include <linux/kernel.h>
65 +#include <linux/mtd/spinand.h>
66 +
67 +#define SPINAND_MFR_ETRON 0xd5
68 +
69 +
70 +static SPINAND_OP_VARIANTS(read_cache_variants,
71 + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, NULL, 0),
72 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
73 + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
74 + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
75 + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
76 + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
77 +
78 +static SPINAND_OP_VARIANTS(write_cache_variants,
79 + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
80 + SPINAND_PROG_LOAD(true, 0, NULL, 0));
81 +
82 +static SPINAND_OP_VARIANTS(update_cache_variants,
83 + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
84 + SPINAND_PROG_LOAD(false, 0, NULL, 0));
85 +
86 +static int etron_ooblayout_ecc(struct mtd_info *mtd, int section,
87 + struct mtd_oob_region *oobregion)
88 +{
89 + if (section)
90 + return -ERANGE;
91 +
92 + oobregion->offset = 72;
93 + oobregion->length = 56;
94 +
95 + return 0;
96 +}
97 +
98 +static int etron_ooblayout_free(struct mtd_info *mtd, int section,
99 + struct mtd_oob_region *oobregion)
100 +{
101 + if (section)
102 + return -ERANGE;
103 +
104 + oobregion->offset = 1;
105 + oobregion->length = 71;
106 +
107 + return 0;
108 +}
109 +
110 +static int etron_ecc_get_status(struct spinand_device *spinand, u8 status)
111 +{
112 + switch (status & STATUS_ECC_MASK) {
113 + case STATUS_ECC_NO_BITFLIPS:
114 + return 0;
115 +
116 + case STATUS_ECC_HAS_BITFLIPS:
117 + /* Between 1-7 bitflips were corrected */
118 + return 7;
119 +
120 + case STATUS_ECC_MASK:
121 + /* Maximum bitflips were corrected */
122 + return 8;
123 +
124 + case STATUS_ECC_UNCOR_ERROR:
125 + return -EBADMSG;
126 + }
127 +
128 + return -EINVAL;
129 +}
130 +
131 +static const struct mtd_ooblayout_ops etron_ooblayout = {
132 + .ecc = etron_ooblayout_ecc,
133 + .free = etron_ooblayout_free,
134 +};
135 +
136 +static const struct spinand_info etron_spinand_table[] = {
137 + SPINAND_INFO("EM73D044VCx",
138 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x1f),
139 + // bpc, pagesize, oobsize, pagesperblock, bperlun, maxbadplun, ppl, lpt, #t
140 + NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 1, 1, 1),
141 + NAND_ECCREQ(8, 512),
142 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
143 + &write_cache_variants,
144 + &update_cache_variants),
145 + SPINAND_HAS_QE_BIT,
146 + SPINAND_ECCINFO(&etron_ooblayout, etron_ecc_get_status)),
147 +};
148 +
149 +static const struct spinand_manufacturer_ops etron_spinand_manuf_ops = {
150 +};
151 +
152 +const struct spinand_manufacturer etron_spinand_manufacturer = {
153 + .id = SPINAND_MFR_ETRON,
154 + .name = "Etron",
155 + .chips = etron_spinand_table,
156 + .nchips = ARRAY_SIZE(etron_spinand_table),
157 + .ops = &etron_spinand_manuf_ops,
158 +};
159 --- a/include/linux/mtd/spinand.h
160 +++ b/include/linux/mtd/spinand.h
161 @@ -262,6 +262,7 @@ struct spinand_manufacturer {
162 /* SPI NAND manufacturers */
163 extern const struct spinand_manufacturer ato_spinand_manufacturer;
164 extern const struct spinand_manufacturer esmt_c8_spinand_manufacturer;
165 +extern const struct spinand_manufacturer etron_spinand_manufacturer;
166 extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
167 extern const struct spinand_manufacturer macronix_spinand_manufacturer;
168 extern const struct spinand_manufacturer micron_spinand_manufacturer;