blob: 14e13f13e3ec9540dd14244b1ffdc90dd74f01d9 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (C) 2021 ASR Micro Limited
4 *
5 * Authors:
6 * Fei Lv <feilv@asrmicro.com>
7 */
8
9#include <linux/device.h>
10#include <linux/kernel.h>
11#include <linux/mtd/spinand.h>
12
13#define SPINAND_MFR_SILICONGO 0xEA
14
15static 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
23static SPINAND_OP_VARIANTS(write_cache_variants,
24 SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
25 SPINAND_PROG_LOAD(true, 0, NULL, 0));
26
27static SPINAND_OP_VARIANTS(update_cache_variants,
28 SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
29 SPINAND_PROG_LOAD(false, 0, NULL, 0));
30
31static int sgm7000i_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
43static int sgm7000i_ooblayout_free(struct mtd_info *mtd, int section,
44 struct mtd_oob_region *region)
45{
46 return -ERANGE;
47}
48
49static const struct mtd_ooblayout_ops sgm7000i_ooblayout = {
50 .ecc = sgm7000i_ooblayout_ecc,
51 .free = sgm7000i_ooblayout_free,
52};
53
54static const struct spinand_info silicongo_spinand_table[] = {
55 SPINAND_INFO("SGM7000I-S24W1GH", 0xC1,
56 NAND_MEMORG(1, 2048, 64, 64, 1024, 20, 1, 1, 1),
57 NAND_ECCREQ(4, 512),
58 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
59 &write_cache_variants,
60 &update_cache_variants),
61 0,
62 SPINAND_ECCINFO(&sgm7000i_ooblayout, NULL)),
63 SPINAND_INFO("SGM7000I-S24W1GH", 0xC2,
64 NAND_MEMORG(1, 2048, 64, 64, 2048, 20, 1, 1, 1),
65 NAND_ECCREQ(4, 512),
66 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
67 &write_cache_variants,
68 &update_cache_variants),
69 0,
70 SPINAND_ECCINFO(&sgm7000i_ooblayout, NULL)),
71 SPINAND_INFO("SGM7000I-S25W4GH", 0xC4,
72 NAND_MEMORG(1, 2048, 64, 64, 4096, 20, 1, 1, 1),
73 NAND_ECCREQ(4, 512),
74 SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
75 &write_cache_variants,
76 &update_cache_variants),
77 0,
78 SPINAND_ECCINFO(&sgm7000i_ooblayout, NULL)),
79};
80
81/**
82 * silicongo_spinand_detect - initialize device related part in spinand_device
83 * struct if it is a Winbond device.
84 * @spinand: SPI NAND device structure
85 */
86static int silicongo_spinand_detect(struct spinand_device *spinand)
87{
88 u8 *id = spinand->id.data;
89 int ret;
90
91 /*
92 * Winbond SPI NAND read ID need a dummy byte,
93 * so the first byte in raw_id is dummy.
94 */
95 if (id[1] != SPINAND_MFR_SILICONGO)
96 return 0;
97
98 ret = spinand_match_and_init(spinand, silicongo_spinand_table,
99 ARRAY_SIZE(silicongo_spinand_table), id[2]);
100 if (ret)
101 return ret;
102
103 return 1;
104}
105
106static const struct spinand_manufacturer_ops silicongo_spinand_manuf_ops = {
107 .detect = silicongo_spinand_detect,
108};
109
110const struct spinand_manufacturer silicongo_spinand_manufacturer = {
111 .id = SPINAND_MFR_SILICONGO,
112 .name = "SiliconGo",
113 .ops = &silicongo_spinand_manuf_ops,
114};