Skip to content

Commit f447318

Browse files
m-kurbanovmiquelraynal
authored andcommitted
mtd: spinand: add support for FORESEE F35SQA002G
Add support for FORESEE F35SQA002G SPI NAND. Datasheet: https://www.longsys.com/uploads/LM-00006FORESEEF35SQA002GDatasheet_1650183701.pdf Signed-off-by: Martin Kurbanov <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent 1cfa2f7 commit f447318

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-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
2-
spinand-objs := core.o alliancememory.o ato.o esmt.o gigadevice.o macronix.o
2+
spinand-objs := core.o alliancememory.o ato.o esmt.o foresee.o gigadevice.o macronix.o
33
spinand-objs += micron.o paragon.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
@@ -940,6 +940,7 @@ static const struct spinand_manufacturer *spinand_manufacturers[] = {
940940
&alliancememory_spinand_manufacturer,
941941
&ato_spinand_manufacturer,
942942
&esmt_c8_spinand_manufacturer,
943+
&foresee_spinand_manufacturer,
943944
&gigadevice_spinand_manufacturer,
944945
&macronix_spinand_manufacturer,
945946
&micron_spinand_manufacturer,

drivers/mtd/nand/spi/foresee.c

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2+
/*
3+
* Copyright (c) 2023, SberDevices. All Rights Reserved.
4+
*
5+
* Author: Martin Kurbanov <[email protected]>
6+
*/
7+
8+
#include <linux/device.h>
9+
#include <linux/kernel.h>
10+
#include <linux/mtd/spinand.h>
11+
12+
#define SPINAND_MFR_FORESEE 0xCD
13+
14+
static SPINAND_OP_VARIANTS(read_cache_variants,
15+
SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
16+
SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
17+
SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
18+
SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
19+
20+
static SPINAND_OP_VARIANTS(write_cache_variants,
21+
SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
22+
SPINAND_PROG_LOAD(true, 0, NULL, 0));
23+
24+
static SPINAND_OP_VARIANTS(update_cache_variants,
25+
SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
26+
SPINAND_PROG_LOAD(false, 0, NULL, 0));
27+
28+
static int f35sqa002g_ooblayout_ecc(struct mtd_info *mtd, int section,
29+
struct mtd_oob_region *region)
30+
{
31+
return -ERANGE;
32+
}
33+
34+
static int f35sqa002g_ooblayout_free(struct mtd_info *mtd, int section,
35+
struct mtd_oob_region *region)
36+
{
37+
if (section)
38+
return -ERANGE;
39+
40+
/* Reserve 2 bytes for the BBM. */
41+
region->offset = 2;
42+
region->length = 62;
43+
44+
return 0;
45+
}
46+
47+
static const struct mtd_ooblayout_ops f35sqa002g_ooblayout = {
48+
.ecc = f35sqa002g_ooblayout_ecc,
49+
.free = f35sqa002g_ooblayout_free,
50+
};
51+
52+
static int f35sqa002g_ecc_get_status(struct spinand_device *spinand, u8 status)
53+
{
54+
struct nand_device *nand = spinand_to_nand(spinand);
55+
56+
switch (status & STATUS_ECC_MASK) {
57+
case STATUS_ECC_NO_BITFLIPS:
58+
return 0;
59+
60+
case STATUS_ECC_HAS_BITFLIPS:
61+
return nanddev_get_ecc_conf(nand)->strength;
62+
63+
default:
64+
break;
65+
}
66+
67+
/* More than 1-bit error was detected in one or more sectors and
68+
* cannot be corrected.
69+
*/
70+
return -EBADMSG;
71+
}
72+
73+
static const struct spinand_info foresee_spinand_table[] = {
74+
SPINAND_INFO("F35SQA002G",
75+
SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x72, 0x72),
76+
NAND_MEMORG(1, 2048, 64, 64, 2048, 40, 1, 1, 1),
77+
NAND_ECCREQ(1, 512),
78+
SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
79+
&write_cache_variants,
80+
&update_cache_variants),
81+
SPINAND_HAS_QE_BIT,
82+
SPINAND_ECCINFO(&f35sqa002g_ooblayout,
83+
f35sqa002g_ecc_get_status)),
84+
};
85+
86+
static const struct spinand_manufacturer_ops foresee_spinand_manuf_ops = {
87+
};
88+
89+
const struct spinand_manufacturer foresee_spinand_manufacturer = {
90+
.id = SPINAND_MFR_FORESEE,
91+
.name = "FORESEE",
92+
.chips = foresee_spinand_table,
93+
.nchips = ARRAY_SIZE(foresee_spinand_table),
94+
.ops = &foresee_spinand_manuf_ops,
95+
};

include/linux/mtd/spinand.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,7 @@ struct spinand_manufacturer {
263263
extern const struct spinand_manufacturer alliancememory_spinand_manufacturer;
264264
extern const struct spinand_manufacturer ato_spinand_manufacturer;
265265
extern const struct spinand_manufacturer esmt_c8_spinand_manufacturer;
266+
extern const struct spinand_manufacturer foresee_spinand_manufacturer;
266267
extern const struct spinand_manufacturer gigadevice_spinand_manufacturer;
267268
extern const struct spinand_manufacturer macronix_spinand_manufacturer;
268269
extern const struct spinand_manufacturer micron_spinand_manufacturer;

0 commit comments

Comments
 (0)