Skip to content

Commit 1a50e36

Browse files
Kuwano-sanmiquelraynal
authored andcommitted
mtd: spinand: Add support for SkyHigh S35ML-3 family
SkyHigh S35ML01G300, S35ML01G301, S35ML02G300, and S35ML04G300 are 1Gb, 2Gb, and 4Gb SLC SPI NAND flash family. This family of devices has on-die ECC which parity bits are stored to hidden area. In this family the on-die ECC cannot be disabled so raw access needs to be prevented. Link: https://www.skyhighmemory.com/download/SPI_S35ML01_04G3_002_19205.pdf?v=P Co-developed-by: KR Kim <[email protected]> Signed-off-by: KR Kim <[email protected]> Signed-off-by: Takahiro Kuwano <[email protected]> Signed-off-by: Miquel Raynal <[email protected]>
1 parent 6d9d6ab commit 1a50e36

File tree

4 files changed

+150
-1
lines changed

4 files changed

+150
-1
lines changed

drivers/mtd/nand/spi/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# SPDX-License-Identifier: GPL-2.0
22
spinand-objs := core.o alliancememory.o ato.o esmt.o foresee.o gigadevice.o macronix.o
3-
spinand-objs += micron.o paragon.o toshiba.o winbond.o xtx.o
3+
spinand-objs += micron.o paragon.o skyhigh.o toshiba.o winbond.o xtx.o
44
obj-$(CONFIG_MTD_SPI_NAND) += spinand.o

drivers/mtd/nand/spi/core.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,6 +1131,7 @@ static const struct spinand_manufacturer *spinand_manufacturers[] = {
11311131
&macronix_spinand_manufacturer,
11321132
&micron_spinand_manufacturer,
11331133
&paragon_spinand_manufacturer,
1134+
&skyhigh_spinand_manufacturer,
11341135
&toshiba_spinand_manufacturer,
11351136
&winbond_spinand_manufacturer,
11361137
&xtx_spinand_manufacturer,

drivers/mtd/nand/spi/skyhigh.c

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2024 SkyHigh Memory Limited
4+
*
5+
* Author: Takahiro Kuwano <[email protected]>
6+
* Co-Author: KR Kim <[email protected]>
7+
*/
8+
9+
#include <linux/device.h>
10+
#include <linux/kernel.h>
11+
#include <linux/mtd/spinand.h>
12+
13+
#define SPINAND_MFR_SKYHIGH 0x01
14+
#define SKYHIGH_STATUS_ECC_1TO2_BITFLIPS (1 << 4)
15+
#define SKYHIGH_STATUS_ECC_3TO6_BITFLIPS (2 << 4)
16+
#define SKYHIGH_STATUS_ECC_UNCOR_ERROR (3 << 4)
17+
#define SKYHIGH_CONFIG_PROTECT_EN BIT(1)
18+
19+
static SPINAND_OP_VARIANTS(read_cache_variants,
20+
SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 4, NULL, 0),
21+
SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
22+
SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 2, NULL, 0),
23+
SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
24+
SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
25+
SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
26+
27+
static SPINAND_OP_VARIANTS(write_cache_variants,
28+
SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
29+
SPINAND_PROG_LOAD(true, 0, NULL, 0));
30+
31+
static SPINAND_OP_VARIANTS(update_cache_variants,
32+
SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
33+
SPINAND_PROG_LOAD(false, 0, NULL, 0));
34+
35+
static int skyhigh_spinand_ooblayout_ecc(struct mtd_info *mtd, int section,
36+
struct mtd_oob_region *region)
37+
{
38+
/* ECC bytes are stored in hidden area. */
39+
return -ERANGE;
40+
}
41+
42+
static int skyhigh_spinand_ooblayout_free(struct mtd_info *mtd, int section,
43+
struct mtd_oob_region *region)
44+
{
45+
if (section)
46+
return -ERANGE;
47+
48+
/* ECC bytes are stored in hidden area. Reserve 2 bytes for the BBM. */
49+
region->offset = 2;
50+
region->length = mtd->oobsize - 2;
51+
52+
return 0;
53+
}
54+
55+
static const struct mtd_ooblayout_ops skyhigh_spinand_ooblayout = {
56+
.ecc = skyhigh_spinand_ooblayout_ecc,
57+
.free = skyhigh_spinand_ooblayout_free,
58+
};
59+
60+
static int skyhigh_spinand_ecc_get_status(struct spinand_device *spinand,
61+
u8 status)
62+
{
63+
switch (status & STATUS_ECC_MASK) {
64+
case STATUS_ECC_NO_BITFLIPS:
65+
return 0;
66+
67+
case SKYHIGH_STATUS_ECC_UNCOR_ERROR:
68+
return -EBADMSG;
69+
70+
case SKYHIGH_STATUS_ECC_1TO2_BITFLIPS:
71+
return 2;
72+
73+
case SKYHIGH_STATUS_ECC_3TO6_BITFLIPS:
74+
return 6;
75+
76+
default:
77+
break;
78+
}
79+
80+
return -EINVAL;
81+
}
82+
83+
static const struct spinand_info skyhigh_spinand_table[] = {
84+
SPINAND_INFO("S35ML01G301",
85+
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x15),
86+
NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
87+
NAND_ECCREQ(6, 32),
88+
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
89+
&write_cache_variants,
90+
&update_cache_variants),
91+
SPINAND_NO_RAW_ACCESS,
92+
SPINAND_ECCINFO(&skyhigh_spinand_ooblayout,
93+
skyhigh_spinand_ecc_get_status)),
94+
SPINAND_INFO("S35ML01G300",
95+
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x14),
96+
NAND_MEMORG(1, 2048, 128, 64, 1024, 20, 1, 1, 1),
97+
NAND_ECCREQ(6, 32),
98+
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
99+
&write_cache_variants,
100+
&update_cache_variants),
101+
SPINAND_NO_RAW_ACCESS,
102+
SPINAND_ECCINFO(&skyhigh_spinand_ooblayout,
103+
skyhigh_spinand_ecc_get_status)),
104+
SPINAND_INFO("S35ML02G300",
105+
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x25),
106+
NAND_MEMORG(1, 2048, 128, 64, 2048, 40, 2, 1, 1),
107+
NAND_ECCREQ(6, 32),
108+
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
109+
&write_cache_variants,
110+
&update_cache_variants),
111+
SPINAND_NO_RAW_ACCESS,
112+
SPINAND_ECCINFO(&skyhigh_spinand_ooblayout,
113+
skyhigh_spinand_ecc_get_status)),
114+
SPINAND_INFO("S35ML04G300",
115+
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x35),
116+
NAND_MEMORG(1, 2048, 128, 64, 4096, 80, 2, 1, 1),
117+
NAND_ECCREQ(6, 32),
118+
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
119+
&write_cache_variants,
120+
&update_cache_variants),
121+
SPINAND_NO_RAW_ACCESS,
122+
SPINAND_ECCINFO(&skyhigh_spinand_ooblayout,
123+
skyhigh_spinand_ecc_get_status)),
124+
};
125+
126+
static int skyhigh_spinand_init(struct spinand_device *spinand)
127+
{
128+
/*
129+
* Config_Protect_En (bit 1 in Block Lock register) must be set to 1
130+
* before writing other bits. Do it here before core unlocks all blocks
131+
* by writing block protection bits.
132+
*/
133+
return spinand_write_reg_op(spinand, REG_BLOCK_LOCK,
134+
SKYHIGH_CONFIG_PROTECT_EN);
135+
}
136+
137+
static const struct spinand_manufacturer_ops skyhigh_spinand_manuf_ops = {
138+
.init = skyhigh_spinand_init,
139+
};
140+
141+
const struct spinand_manufacturer skyhigh_spinand_manufacturer = {
142+
.id = SPINAND_MFR_SKYHIGH,
143+
.name = "SkyHigh",
144+
.chips = skyhigh_spinand_table,
145+
.nchips = ARRAY_SIZE(skyhigh_spinand_table),
146+
.ops = &skyhigh_spinand_manuf_ops,
147+
};

include/linux/mtd/spinand.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
268268
extern const struct spinand_manufacturer macronix_spinand_manufacturer;
269269
extern const struct spinand_manufacturer micron_spinand_manufacturer;
270270
extern const struct spinand_manufacturer paragon_spinand_manufacturer;
271+
extern const struct spinand_manufacturer skyhigh_spinand_manufacturer;
271272
extern const struct spinand_manufacturer toshiba_spinand_manufacturer;
272273
extern const struct spinand_manufacturer winbond_spinand_manufacturer;
273274
extern const struct spinand_manufacturer xtx_spinand_manufacturer;

0 commit comments

Comments
 (0)