xref: /rk3399_rockchip-uboot/drivers/mtd/nand/spi/fmsh.c (revision 70ad550d6f37befbc82a8e5e7c7753be83ff08b1)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2020-2021 Rockchip Electronics Co., Ltd
4  *
5  * Authors:
6  *	Dingqiang Lin <jon.lin@rock-chips.com>
7  */
8 
9 #ifndef __UBOOT__
10 #include <linux/device.h>
11 #include <linux/kernel.h>
12 #endif
13 #include <linux/mtd/spinand.h>
14 
15 #define SPINAND_MFR_FMSH		0xA1
16 
17 static SPINAND_OP_VARIANTS(read_cache_variants,
18 		SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 2, NULL, 0),
19 		SPINAND_PAGE_READ_FROM_CACHE_X4_OP(0, 1, NULL, 0),
20 		SPINAND_PAGE_READ_FROM_CACHE_DUALIO_OP(0, 1, NULL, 0),
21 		SPINAND_PAGE_READ_FROM_CACHE_X2_OP(0, 1, NULL, 0),
22 		SPINAND_PAGE_READ_FROM_CACHE_OP(true, 0, 1, NULL, 0),
23 		SPINAND_PAGE_READ_FROM_CACHE_OP(false, 0, 1, NULL, 0));
24 
25 static SPINAND_OP_VARIANTS(write_cache_variants,
26 		SPINAND_PROG_LOAD_X4(true, 0, NULL, 0),
27 		SPINAND_PROG_LOAD(true, 0, NULL, 0));
28 
29 static SPINAND_OP_VARIANTS(update_cache_variants,
30 		SPINAND_PROG_LOAD_X4(false, 0, NULL, 0),
31 		SPINAND_PROG_LOAD(false, 0, NULL, 0));
32 
33 static int fm25s01a_ooblayout_ecc(struct mtd_info *mtd, int section,
34 				  struct mtd_oob_region *region)
35 {
36 	return -ERANGE;
37 }
38 
39 static int fm25s01a_ooblayout_free(struct mtd_info *mtd, int section,
40 				   struct mtd_oob_region *region)
41 {
42 	if (section)
43 		return -ERANGE;
44 
45 	region->offset = 2;
46 	region->length = 62;
47 
48 	return 0;
49 }
50 
51 static const struct mtd_ooblayout_ops fm25s01a_ooblayout = {
52 	.ecc = fm25s01a_ooblayout_ecc,
53 	.rfree = fm25s01a_ooblayout_free,
54 };
55 
56 static int fm25s01_ooblayout_ecc(struct mtd_info *mtd, int section,
57 				 struct mtd_oob_region *region)
58 {
59 	if (section)
60 		return -ERANGE;
61 
62 	region->offset = 64;
63 	region->length = 64;
64 
65 	return 0;
66 }
67 
68 static int fm25s01_ooblayout_free(struct mtd_info *mtd, int section,
69 				  struct mtd_oob_region *region)
70 {
71 	if (section)
72 		return -ERANGE;
73 
74 	region->offset = 2;
75 	region->length = 62;
76 
77 	return 0;
78 }
79 
80 static const struct mtd_ooblayout_ops fm25s01_ooblayout = {
81 	.ecc = fm25s01_ooblayout_ecc,
82 	.rfree = fm25s01_ooblayout_free,
83 };
84 
85 static const struct spinand_info fmsh_spinand_table[] = {
86 	SPINAND_INFO("FM25S01A",
87 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE4),
88 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
89 		     NAND_ECCREQ(1, 512),
90 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
91 					      &write_cache_variants,
92 					      &update_cache_variants),
93 		     0,
94 		     SPINAND_ECCINFO(&fm25s01a_ooblayout, NULL)),
95 	SPINAND_INFO("FM25S02A",
96 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xE5),
97 		     NAND_MEMORG(1, 2048, 64, 64, 2048, 2, 1, 1),
98 		     NAND_ECCREQ(1, 512),
99 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
100 					      &write_cache_variants,
101 					      &update_cache_variants),
102 		     1,
103 		     SPINAND_ECCINFO(&fm25s01a_ooblayout, NULL)),
104 	SPINAND_INFO("FM25S01",
105 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xA1),
106 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
107 		     NAND_ECCREQ(1, 512),
108 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
109 					      &write_cache_variants,
110 					      &update_cache_variants),
111 		     0,
112 		     SPINAND_ECCINFO(&fm25s01_ooblayout, NULL)),
113 	SPINAND_INFO("FM25LS01",
114 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xA5),
115 		     NAND_MEMORG(1, 2048, 64, 64, 1024, 1, 1, 1),
116 		     NAND_ECCREQ(1, 512),
117 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
118 					      &write_cache_variants,
119 					      &update_cache_variants),
120 		     0,
121 		     SPINAND_ECCINFO(&fm25s01_ooblayout, NULL)),
122 };
123 
124 static const struct spinand_manufacturer_ops fmsh_spinand_manuf_ops = {
125 };
126 
127 const struct spinand_manufacturer fmsh_spinand_manufacturer = {
128 	.id = SPINAND_MFR_FMSH,
129 	.name = "FMSH",
130 	.chips = fmsh_spinand_table,
131 	.nchips = ARRAY_SIZE(fmsh_spinand_table),
132 	.ops = &fmsh_spinand_manuf_ops,
133 };
134