1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Copyright (c) 2020 Grandstream Networks, Inc
4 *
5 * Authors:
6 * Carl <xjxia@grandstream.cn>
7 */
8
9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/mtd/spinand.h>
12
13 #define SPINAND_MFR_ESMT 0xC8
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
f50lxx41x_ooblayout_ecc(struct mtd_info * mtd,int section,struct mtd_oob_region * region)31 static int f50lxx41x_ooblayout_ecc(struct mtd_info *mtd, int section,
32 struct mtd_oob_region *region)
33 {
34 if (section > 3)
35 return -ERANGE;
36
37 region->offset = (16 * section) + 8;
38 region->length = 8;
39
40 return 0;
41 }
42
f50lxx41x_ooblayout_free(struct mtd_info * mtd,int section,struct mtd_oob_region * region)43 static int f50lxx41x_ooblayout_free(struct mtd_info *mtd, int section,
44 struct mtd_oob_region *region)
45 {
46 if (section > 3)
47 return -ERANGE;
48
49 region->offset = (16 * section) + 2;
50 region->length = 6;
51
52 return 0;
53 }
54
55 static const struct mtd_ooblayout_ops f50lxx41x_ooblayout = {
56 .ecc = f50lxx41x_ooblayout_ecc,
57 .free = f50lxx41x_ooblayout_free,
58 };
59
60 static const struct spinand_info esmt_spinand_table[] = {
61 SPINAND_INFO("F50L1G41LB",
62 SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0x01),
63 NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
64 NAND_ECCREQ(1, 512),
65 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
66 &write_cache_variants,
67 &update_cache_variants),
68 0,
69 SPINAND_ECCINFO(&f50lxx41x_ooblayout, NULL)),
70 };
71
72 static const struct spinand_manufacturer_ops esmt_spinand_manuf_ops = {
73 };
74
75 const struct spinand_manufacturer esmt_spinand_manufacturer = {
76 .id = SPINAND_MFR_ESMT,
77 .name = "esmt",
78 .chips = esmt_spinand_table,
79 .nchips = ARRAY_SIZE(esmt_spinand_table),
80 .ops = &esmt_spinand_manuf_ops,
81 };
82