kernel: backport MEMREAD ioctl
[openwrt/staging/dedeckeh.git] / target / linux / mediatek / patches-5.15 / 340-mtd-spinand-Add-support-for-the-Fidelix-FM35X1GA.patch
1 From 5f49a5c9b16330e0df8f639310e4715dcad71947 Mon Sep 17 00:00:00 2001
2 From: Davide Fioravanti <pantanastyle@gmail.com>
3 Date: Fri, 8 Jan 2021 15:35:24 +0100
4 Subject: [PATCH] mtd: spinand: Add support for the Fidelix FM35X1GA
5
6 Datasheet: http://www.hobos.com.cn/upload/datasheet/DS35X1GAXXX_100_rev00.pdf
7
8 Signed-off-by: Davide Fioravanti <pantanastyle@gmail.com>
9 ---
10 drivers/mtd/nand/spi/Makefile | 2 +-
11 drivers/mtd/nand/spi/core.c | 1 +
12 drivers/mtd/nand/spi/fidelix.c | 76 ++++++++++++++++++++++++++++++++++
13 include/linux/mtd/spinand.h | 1 +
14 4 files changed, 79 insertions(+), 1 deletion(-)
15 create mode 100644 drivers/mtd/nand/spi/fidelix.c
16
17 --- a/drivers/mtd/nand/spi/Makefile
18 +++ b/drivers/mtd/nand/spi/Makefile
19 @@ -1,3 +1,3 @@
20 # SPDX-License-Identifier: GPL-2.0
21 -spinand-objs := core.o esmt.o etron.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
22 +spinand-objs := core.o esmt.o etron.o fidelix.o gigadevice.o macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
23 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
24 --- a/drivers/mtd/nand/spi/core.c
25 +++ b/drivers/mtd/nand/spi/core.c
26 @@ -939,6 +939,7 @@ static const struct nand_ops spinand_ops
27
28 static const struct spinand_manufacturer *spinand_manufacturers[] = {
29 &esmt_c8_spinand_manufacturer,
30 + &fidelix_spinand_manufacturer,
31 &gigadevice_spinand_manufacturer,
32 &etron_spinand_manufacturer,
33 &macronix_spinand_manufacturer,
34 --- /dev/null
35 +++ b/drivers/mtd/nand/spi/fidelix.c
36 @@ -0,0 +1,76 @@
37 +// SPDX-License-Identifier: GPL-2.0
38 +/*
39 + * Copyright (c) 2020 Davide Fioravanti <pantanastyle@gmail.com>
40 + */
41 +
42 +#include <linux/device.h>
43 +#include <linux/kernel.h>
44 +#include <linux/mtd/spinand.h>
45 +
46 +#define SPINAND_MFR_FIDELIX 0xE5
47 +#define FIDELIX_ECCSR_MASK 0x0F
48 +
49 +static SPINAND_OP_VARIANTS(read_cache_variants,
50 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
51 + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
52 + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
53 +
54 +static SPINAND_OP_VARIANTS(write_cache_variants,
55 + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
56 + SPINAND_PROG_LOAD(true, 0, NULL, 0));
57 +
58 +static SPINAND_OP_VARIANTS(update_cache_variants,
59 + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
60 + SPINAND_PROG_LOAD(false, 0, NULL, 0));
61 +
62 +static int fm35x1ga_ooblayout_ecc(struct mtd_info *mtd, int section,
63 + struct mtd_oob_region *region)
64 +{
65 + if (section > 3)
66 + return -ERANGE;
67 +
68 + region->offset = (16 * section) + 8;
69 + region->length = 8;
70 +
71 + return 0;
72 +}
73 +
74 +static int fm35x1ga_ooblayout_free(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) + 2;
81 + region->length = 6;
82 +
83 + return 0;
84 +}
85 +
86 +static const struct mtd_ooblayout_ops fm35x1ga_ooblayout = {
87 + .ecc = fm35x1ga_ooblayout_ecc,
88 + .free = fm35x1ga_ooblayout_free,
89 +};
90 +
91 +static const struct spinand_info fidelix_spinand_table[] = {
92 + SPINAND_INFO("FM35X1GA",
93 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x71),
94 + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
95 + NAND_ECCREQ(4, 512),
96 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
97 + &write_cache_variants,
98 + &update_cache_variants),
99 + SPINAND_HAS_QE_BIT,
100 + SPINAND_ECCINFO(&fm35x1ga_ooblayout, NULL)),
101 +};
102 +
103 +static const struct spinand_manufacturer_ops fidelix_spinand_manuf_ops = {
104 +};
105 +
106 +const struct spinand_manufacturer fidelix_spinand_manufacturer = {
107 + .id = SPINAND_MFR_FIDELIX,
108 + .name = "Fidelix",
109 + .chips = fidelix_spinand_table,
110 + .nchips = ARRAY_SIZE(fidelix_spinand_table),
111 + .ops = &fidelix_spinand_manuf_ops,
112 +};
113 --- a/include/linux/mtd/spinand.h
114 +++ b/include/linux/mtd/spinand.h
115 @@ -262,6 +262,7 @@ struct spinand_manufacturer {
116 /* SPI NAND manufacturers */
117 extern const struct spinand_manufacturer esmt_c8_spinand_manufacturer;
118 extern const struct spinand_manufacturer etron_spinand_manufacturer;
119 +extern const struct spinand_manufacturer fidelix_spinand_manufacturer;
120 extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
121 extern const struct spinand_manufacturer macronix_spinand_manufacturer;
122 extern const struct spinand_manufacturer micron_spinand_manufacturer;