1 // SPDX-License-Identifier: (GPL-2.0+ OR MIT)
3 * Copyright (c) 2023, SberDevices. All Rights Reserved.
5 * Author: Martin Kurbanov <mmkurbanov@salutedevices.com>
8 #include <linux/device.h>
9 #include <linux/kernel.h>
10 #include <linux/mtd/spinand.h>
12 #define SPINAND_MFR_FORESEE 0xCD
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));
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));
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));
28 static int f35sqa002g_ooblayout_ecc(struct mtd_info
*mtd
, int section
,
29 struct mtd_oob_region
*region
)
34 static int f35sqa002g_ooblayout_free(struct mtd_info
*mtd
, int section
,
35 struct mtd_oob_region
*region
)
40 /* Reserve 2 bytes for the BBM. */
47 static const struct mtd_ooblayout_ops f35sqa002g_ooblayout
= {
48 .ecc
= f35sqa002g_ooblayout_ecc
,
49 .free
= f35sqa002g_ooblayout_free
,
52 static int f35sqa002g_ecc_get_status(struct spinand_device
*spinand
, u8 status
)
54 struct nand_device
*nand
= spinand_to_nand(spinand
);
56 switch (status
& STATUS_ECC_MASK
) {
57 case STATUS_ECC_NO_BITFLIPS
:
60 case STATUS_ECC_HAS_BITFLIPS
:
61 return nanddev_get_ecc_conf(nand
)->strength
;
67 /* More than 1-bit error was detected in one or more sectors and
68 * cannot be corrected.
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),
78 SPINAND_INFO_OP_VARIANTS(&read_cache_variants
,
79 &write_cache_variants
,
80 &update_cache_variants
),
82 SPINAND_ECCINFO(&f35sqa002g_ooblayout
,
83 f35sqa002g_ecc_get_status
)),
86 static const struct spinand_manufacturer_ops foresee_spinand_manuf_ops
= {
89 const struct spinand_manufacturer foresee_spinand_manufacturer
= {
90 .id
= SPINAND_MFR_FORESEE
,
92 .chips
= foresee_spinand_table
,
93 .nchips
= ARRAY_SIZE(foresee_spinand_table
),
94 .ops
= &foresee_spinand_manuf_ops
,