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
6 Datasheet: http://www.hobos.com.cn/upload/datasheet/DS35X1GAXXX_100_rev00.pdf
8 Signed-off-by: Davide Fioravanti <pantanastyle@gmail.com>
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
17 --- a/drivers/mtd/nand/spi/Makefile
18 +++ b/drivers/mtd/nand/spi/Makefile
20 # SPDX-License-Identifier: GPL-2.0
21 -spinand-objs := core.o alliancememory.o ato.o esmt.o etron.o gigadevice.o
22 +spinand-objs := core.o alliancememory.o ato.o esmt.o etron.o fidelix.o gigadevice.o
23 spinand-objs += macronix.o micron.o paragon.o toshiba.o winbond.o xtx.o
24 obj-$(CONFIG_MTD_SPI_NAND) += spinand.o
25 --- a/drivers/mtd/nand/spi/core.c
26 +++ b/drivers/mtd/nand/spi/core.c
27 @@ -941,6 +941,7 @@ static const struct spinand_manufacturer
28 &alliancememory_spinand_manufacturer,
29 &ato_spinand_manufacturer,
30 &esmt_c8_spinand_manufacturer,
31 + &fidelix_spinand_manufacturer,
32 &etron_spinand_manufacturer,
33 &gigadevice_spinand_manufacturer,
34 ¯onix_spinand_manufacturer,
36 +++ b/drivers/mtd/nand/spi/fidelix.c
38 +// SPDX-License-Identifier: GPL-2.0
40 + * Copyright (c) 2020 Davide Fioravanti <pantanastyle@gmail.com>
43 +#include <linux/device.h>
44 +#include <linux/kernel.h>
45 +#include <linux/mtd/spinand.h>
47 +#define SPINAND_MFR_FIDELIX 0xE5
48 +#define FIDELIX_ECCSR_MASK 0x0F
50 +static SPINAND_OP_VARIANTS(read_cache_variants,
51 + SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
52 + SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
53 + SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
55 +static SPINAND_OP_VARIANTS(write_cache_variants,
56 + SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
57 + SPINAND_PROG_LOAD(true, 0, NULL, 0));
59 +static SPINAND_OP_VARIANTS(update_cache_variants,
60 + SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
61 + SPINAND_PROG_LOAD(false, 0, NULL, 0));
63 +static int fm35x1ga_ooblayout_ecc(struct mtd_info *mtd, int section,
64 + struct mtd_oob_region *region)
69 + region->offset = (16 * section) + 8;
75 +static int fm35x1ga_ooblayout_free(struct mtd_info *mtd, int section,
76 + struct mtd_oob_region *region)
81 + region->offset = (16 * section) + 2;
87 +static const struct mtd_ooblayout_ops fm35x1ga_ooblayout = {
88 + .ecc = fm35x1ga_ooblayout_ecc,
89 + .free = fm35x1ga_ooblayout_free,
92 +static const struct spinand_info fidelix_spinand_table[] = {
93 + SPINAND_INFO("FM35X1GA",
94 + SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x71),
95 + NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
96 + NAND_ECCREQ(4, 512),
97 + SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
98 + &write_cache_variants,
99 + &update_cache_variants),
100 + SPINAND_HAS_QE_BIT,
101 + SPINAND_ECCINFO(&fm35x1ga_ooblayout, NULL)),
104 +static const struct spinand_manufacturer_ops fidelix_spinand_manuf_ops = {
107 +const struct spinand_manufacturer fidelix_spinand_manufacturer = {
108 + .id = SPINAND_MFR_FIDELIX,
110 + .chips = fidelix_spinand_table,
111 + .nchips = ARRAY_SIZE(fidelix_spinand_table),
112 + .ops = &fidelix_spinand_manuf_ops,
114 --- a/include/linux/mtd/spinand.h
115 +++ b/include/linux/mtd/spinand.h
116 @@ -264,6 +264,7 @@ extern const struct spinand_manufacturer
117 extern const struct spinand_manufacturer ato_spinand_manufacturer;
118 extern const struct spinand_manufacturer esmt_c8_spinand_manufacturer;
119 extern const struct spinand_manufacturer etron_spinand_manufacturer;
120 +extern const struct spinand_manufacturer fidelix_spinand_manufacturer;
121 extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
122 extern const struct spinand_manufacturer macronix_spinand_manufacturer;
123 extern const struct spinand_manufacturer micron_spinand_manufacturer;