1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2020-2021 Rockchip Electronics Co., Ltd
4 *
5 * Authors:
6 * Dingqiang Lin <jon.lin@rock-chips.com>
7 */
8
9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/mtd/spinand.h>
12
13 #define SPINAND_MFR_FMSH 0xA1
14
15 static SPINAND_OP_VARIANTS(read_cache_variants,
16 SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
17 SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
18 SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
19 SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
20 SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
21 SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
22
23 static SPINAND_OP_VARIANTS(write_cache_variants,
24 SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
25 SPINAND_PROG_LOAD(true, 0, NULL, 0));
26
27 static SPINAND_OP_VARIANTS(update_cache_variants,
28 SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
29 SPINAND_PROG_LOAD(false, 0, NULL, 0));
30
fm25s01a_ooblayout_ecc(struct mtd_info * mtd,int section,struct mtd_oob_region * region)31 static int fm25s01a_ooblayout_ecc(struct mtd_info *mtd, int section,
32 struct mtd_oob_region *region)
33 {
34 return -ERANGE;
35 }
36
fm25s01a_ooblayout_free(struct mtd_info * mtd,int section,struct mtd_oob_region * region)37 static int fm25s01a_ooblayout_free(struct mtd_info *mtd, int section,
38 struct mtd_oob_region *region)
39 {
40 if (section)
41 return -ERANGE;
42
43 region->offset = 2;
44 region->length = 62;
45
46 return 0;
47 }
48
49 static const struct mtd_ooblayout_ops fm25s01a_ooblayout = {
50 .ecc = fm25s01a_ooblayout_ecc,
51 .free = fm25s01a_ooblayout_free,
52 };
53
fm25s01_ooblayout_ecc(struct mtd_info * mtd,int section,struct mtd_oob_region * region)54 static int fm25s01_ooblayout_ecc(struct mtd_info *mtd, int section,
55 struct mtd_oob_region *region)
56 {
57 if (section)
58 return -ERANGE;
59
60 region->offset = 64;
61 region->length = 64;
62
63 return 0;
64 }
65
fm25s01_ooblayout_free(struct mtd_info * mtd,int section,struct mtd_oob_region * region)66 static int fm25s01_ooblayout_free(struct mtd_info *mtd, int section,
67 struct mtd_oob_region *region)
68 {
69 if (section)
70 return -ERANGE;
71
72 region->offset = 2;
73 region->length = 62;
74
75 return 0;
76 }
77
78 static const struct mtd_ooblayout_ops fm25s01_ooblayout = {
79 .ecc = fm25s01_ooblayout_ecc,
80 .free = fm25s01_ooblayout_free,
81 };
82
83 /*
84 * ecc bits: 0xC0[4,6]
85 * [0b000], No bit errors were detected;
86 * [0b001] and [0b011], 1~6 Bit errors were detected and corrected. Not
87 * reach Flipping Bits;
88 * [0b101], Bit error count equals the bit flip
89 * detection threshold
90 * [0b010], Multiple bit errors were detected and
91 * not corrected.
92 * others, Reserved.
93 */
fm25s01bi3_ecc_ecc_get_status(struct spinand_device * spinand,u8 status)94 static int fm25s01bi3_ecc_ecc_get_status(struct spinand_device *spinand,
95 u8 status)
96 {
97 struct nand_device *nand = spinand_to_nand(spinand);
98 u8 eccsr = (status & GENMASK(6, 4)) >> 4;
99
100 if (eccsr <= 1 || eccsr == 3)
101 return eccsr;
102 else if (eccsr == 5)
103 return nanddev_get_ecc_requirements(nand)->strength;
104 else
105 return -EBADMSG;
106 }
107
108 static const struct spinand_info fmsh_spinand_table[] = {
109 SPINAND_INFO("FM25S01A",
110 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE4),
111 NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
112 NAND_ECCREQ(1, 512),
113 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
114 &write_cache_variants,
115 &update_cache_variants),
116 0,
117 SPINAND_ECCINFO(&fm25s01a_ooblayout, NULL)),
118 SPINAND_INFO("FM25S02A",
119 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE5),
120 NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 2, 1, 1),
121 NAND_ECCREQ(1, 512),
122 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
123 &write_cache_variants,
124 &update_cache_variants),
125 SPINAND_HAS_QE_BIT,
126 SPINAND_ECCINFO(&fm25s01a_ooblayout, NULL)),
127 SPINAND_INFO("FM25S01",
128 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xA1),
129 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
130 NAND_ECCREQ(1, 512),
131 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
132 &write_cache_variants,
133 &update_cache_variants),
134 0,
135 SPINAND_ECCINFO(&fm25s01_ooblayout, NULL)),
136 SPINAND_INFO("FM25LS01",
137 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xA5),
138 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
139 NAND_ECCREQ(1, 512),
140 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
141 &write_cache_variants,
142 &update_cache_variants),
143 0,
144 SPINAND_ECCINFO(&fm25s01_ooblayout, NULL)),
145 SPINAND_INFO("FM25S01BI3",
146 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xD4),
147 NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
148 NAND_ECCREQ(8, 512),
149 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
150 &write_cache_variants,
151 &update_cache_variants),
152 SPINAND_HAS_QE_BIT,
153 SPINAND_ECCINFO(&fm25s01_ooblayout, fm25s01bi3_ecc_ecc_get_status)),
154 };
155
156 static const struct spinand_manufacturer_ops fmsh_spinand_manuf_ops = {
157 };
158
159 const struct spinand_manufacturer fmsh_spinand_manufacturer = {
160 .id = SPINAND_MFR_FMSH,
161 .name = "FMSH",
162 .chips = fmsh_spinand_table,
163 .nchips = ARRAY_SIZE(fmsh_spinand_table),
164 .ops = &fmsh_spinand_manuf_ops,
165 };
166