kernel: backport MEMREAD ioctl
[openwrt/staging/dedeckeh.git] / target / linux / generic / pending-5.15 / 486-01-mtd-spinand-add-support-for-ESMT-F50x1G41LB.patch
1 From a43b844cb40bf1b783055fdc81b7f991e21e7e76 Mon Sep 17 00:00:00 2001
2 From: Chuanhong Guo <gch981213@gmail.com>
3 Date: Wed, 13 Apr 2022 11:58:17 +0800
4 Subject: [PATCH] mtd: spinand: add support for ESMT F50x1G41LB
5
6 This patch adds support for ESMT F50L1G41LB and F50D1G41LB.
7 It seems that ESMT likes to use random JEDEC ID from other vendors.
8 Their 1G chips uses 0xc8 from GigaDevice and 2G/4G chips uses 0x2c from
9 Micron. For this reason, the ESMT entry is named esmt_c8 with explicit
10 JEDEC ID in variable name.
11
12 Datasheets:
13 https://www.esmt.com.tw/upload/pdf/ESMT/datasheets/F50L1G41LB(2M).pdf
14 https://www.esmt.com.tw/upload/pdf/ESMT/datasheets/F50D1G41LB(2M).pdf
15
16 Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
17 ---
18 drivers/mtd/nand/spi/Makefile | 2 +-
19 drivers/mtd/nand/spi/core.c | 1 +
20 drivers/mtd/nand/spi/esmt.c | 89 +++++++++++++++++++++++++++++++++++
21 include/linux/mtd/spinand.h | 1 +
22 4 files changed, 92 insertions(+), 1 deletion(-)
23 create mode 100644 drivers/mtd/nand/spi/esmt.c
24
25 --- a/drivers/mtd/nand/spi/Makefile
26 +++ b/drivers/mtd/nand/spi/Makefile
27 @@ -1,3 +1,3 @@
28 # SPDX-License-Identifier: GPL-2.0
29 -spinand-objs := core.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
30 +spinand-objs := core.o esmt.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
31 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
32 --- a/drivers/mtd/nand/spi/core.c
33 +++ b/drivers/mtd/nand/spi/core.c
34 @@ -906,6 +906,7 @@ static const struct nand_ops spinand_ops
35 };
36
37 static const struct spinand_manufacturer *spinand_manufacturers[] = {
38 + &esmt_c8_spinand_manufacturer,
39 &gigadevice_spinand_manufacturer,
40 &macronix_spinand_manufacturer,
41 &micron_spinand_manufacturer,
42 --- /dev/null
43 +++ b/drivers/mtd/nand/spi/esmt.c
44 @@ -0,0 +1,89 @@
45 +// SPDX-License-Identifier: GPL-2.0
46 +/*
47 + * Author:
48 + * Chuanhong Guo <gch981213@gmail.com>
49 + */
50 +
51 +#include <linux/device.h>
52 +#include <linux/kernel.h>
53 +#include <linux/mtd/spinand.h>
54 +
55 +/* ESMT uses GigaDevice 0xc8 JECDEC ID on some SPI NANDs */
56 +#define SPINAND_MFR_ESMT_C8 0xc8
57 +
58 +static SPINAND_OP_VARIANTS(read_cache_variants,
59 + SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
60 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
61 + SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
62 + SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
63 + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
64 + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
65 +
66 +static SPINAND_OP_VARIANTS(write_cache_variants,
67 + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
68 + SPINAND_PROG_LOAD(true, 0, NULL, 0));
69 +
70 +static SPINAND_OP_VARIANTS(update_cache_variants,
71 + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
72 + SPINAND_PROG_LOAD(false, 0, NULL, 0));
73 +
74 +static int f50l1g41lb_ooblayout_ecc(struct mtd_info *mtd, int section,
75 + struct mtd_oob_region *region)
76 +{
77 + if (section > 3)
78 + return -ERANGE;
79 +
80 + region->offset = 16 * section + 8;
81 + region->length = 8;
82 +
83 + return 0;
84 +}
85 +
86 +static int f50l1g41lb_ooblayout_free(struct mtd_info *mtd, int section,
87 + struct mtd_oob_region *region)
88 +{
89 + if (section > 3)
90 + return -ERANGE;
91 +
92 + region->offset = 16 * section + 2;
93 + region->length = 6;
94 +
95 + return 0;
96 +}
97 +
98 +static const struct mtd_ooblayout_ops f50l1g41lb_ooblayout = {
99 + .ecc = f50l1g41lb_ooblayout_ecc,
100 + .free = f50l1g41lb_ooblayout_free,
101 +};
102 +
103 +static const struct spinand_info esmt_c8_spinand_table[] = {
104 + SPINAND_INFO("F50L1G41LB",
105 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x01),
106 + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
107 + NAND_ECCREQ(1, 512),
108 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
109 + &write_cache_variants,
110 + &update_cache_variants),
111 + 0,
112 + SPINAND_ECCINFO(&f50l1g41lb_ooblayout, NULL)),
113 + SPINAND_INFO("F50D1G41LB",
114 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_ADDR, 0x11),
115 + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
116 + NAND_ECCREQ(1, 512),
117 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
118 + &write_cache_variants,
119 + &update_cache_variants),
120 + 0,
121 + SPINAND_ECCINFO(&f50l1g41lb_ooblayout, NULL)),
122 +};
123 +
124 +static const struct spinand_manufacturer_ops esmt_spinand_manuf_ops = {
125 +};
126 +
127 +const struct spinand_manufacturer esmt_c8_spinand_manufacturer = {
128 + .id = SPINAND_MFR_ESMT_C8,
129 + .name = "ESMT",
130 + .chips = esmt_c8_spinand_table,
131 + .nchips = ARRAY_SIZE(esmt_c8_spinand_table),
132 + .ops = &esmt_spinand_manuf_ops,
133 +};
134 --- a/include/linux/mtd/spinand.h
135 +++ b/include/linux/mtd/spinand.h
136 @@ -260,6 +260,7 @@ struct spinand_manufacturer {
137 };
138
139 /* SPI NAND manufacturers */
140 +extern const struct spinand_manufacturer esmt_c8_spinand_manufacturer;
141 extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
142 extern const struct spinand_manufacturer macronix_spinand_manufacturer;
143 extern const struct spinand_manufacturer micron_spinand_manufacturer;