xref: /OK3568_Linux_fs/kernel/drivers/mtd/nand/spi/gsto.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2023 Rockchip Electronics Co., Ltd
4  *
5  * Authors:
6  *	Dingqiang Lin <jon.lin@rock-chips.com>
7  */
8 
9 #include <linux/device.h>
10 #include <linux/kernel.h>
11 #include <linux/mtd/spinand.h>
12 
13 #define SPINAND_MFR_GSTO		0x52
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 
gss0xgsak1_ooblayout_ecc(struct mtd_info * mtd,int section,struct mtd_oob_region * region)31 static int gss0xgsak1_ooblayout_ecc(struct mtd_info *mtd, int section,
32 				 struct mtd_oob_region *region)
33 {
34 	if (section)
35 		return -ERANGE;
36 
37 	region->offset = 32;
38 	region->length = 32;
39 
40 	return 0;
41 }
42 
gss0xgsak1_ooblayout_free(struct mtd_info * mtd,int section,struct mtd_oob_region * region)43 static int gss0xgsak1_ooblayout_free(struct mtd_info *mtd, int section,
44 				  struct mtd_oob_region *region)
45 {
46 	if (section)
47 		return -ERANGE;
48 
49 	region->offset = 2;
50 	region->length = 30;
51 
52 	return 0;
53 }
54 
55 static const struct mtd_ooblayout_ops gss0xgsak1_ooblayout = {
56 	.ecc = gss0xgsak1_ooblayout_ecc,
57 	.free = gss0xgsak1_ooblayout_free,
58 };
59 
60 static const struct spinand_info gsto_spinand_table[] = {
61 	SPINAND_INFO("GSS01GSAK1",
62 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBA, 0x13),
63 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 10, 1, 1, 1),
64 		     NAND_ECCREQ(4, 512),
65 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
66 					      &write_cache_variants,
67 					      &update_cache_variants),
68 		     0,
69 		     SPINAND_ECCINFO(&gss0xgsak1_ooblayout, NULL)),
70 	SPINAND_INFO("GSS02GSAK1",
71 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xBA, 0x23),
72 		     NAND_MEMORG(1, 2048, 64, 64, 2048, 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(&gss0xgsak1_ooblayout, NULL)),
79 };
80 
81 static const struct spinand_manufacturer_ops gsto_spinand_manuf_ops = {
82 };
83 
84 const struct spinand_manufacturer gsto_spinand_manufacturer = {
85 	.id = SPINAND_MFR_GSTO,
86 	.name = "GSTO",
87 	.chips = gsto_spinand_table,
88 	.nchips = ARRAY_SIZE(gsto_spinand_table),
89 	.ops = &gsto_spinand_manuf_ops,
90 };
91