xref: /rk3399_rockchip-uboot/drivers/mtd/nand/spi/zbit.c (revision 13ceb2afdcb6f5114908e39f0d2453728eb24e0f)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2024 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_ZBIT		0x5E
16 
17 static SPINAND_OP_VARIANTS(read_cache_variants,
18 		SPINAND_PAGE_READ_FROM_CACHE_QUADIO_OP(0, 1, 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 zb35q01b_ooblayout_ecc(struct mtd_info *mtd, int section,
34 				  struct mtd_oob_region *region)
35 {
36 	return -ERANGE;
37 }
38 
39 static int zb35q01b_ooblayout_free(struct mtd_info *mtd, int section,
40 				   struct mtd_oob_region *region)
41 {
42 	if (section)
43 		return -ERANGE;
44 
45 	/* Reserve 2 bytes for the BBM. */
46 	region->offset = 2;
47 	region->length = mtd->oobsize - 2;
48 
49 	return 0;
50 }
51 
52 static const struct mtd_ooblayout_ops zb35q01b_ooblayout = {
53 	.ecc = zb35q01b_ooblayout_ecc,
54 	.rfree = zb35q01b_ooblayout_free,
55 };
56 
57 static const struct spinand_info zbit_spinand_table[] = {
58 	SPINAND_INFO("ZB35Q01BYIG",
59 		     SPINAND_ID(SPINAND_READID_METHOD_OPCODE_DUMMY, 0xA1),
60 		     NAND_MEMORG(1, 2048, 128, 64, 1024, 1, 1, 1),
61 		     NAND_ECCREQ(8, 512),
62 		     SPINAND_INFO_OP_VARIANTS(&read_cache_variants,
63 					      &write_cache_variants,
64 					      &update_cache_variants),
65 		     0,
66 		     SPINAND_ECCINFO(&zb35q01b_ooblayout, NULL)),
67 };
68 
69 static const struct spinand_manufacturer_ops zbit_spinand_manuf_ops = {
70 };
71 
72 const struct spinand_manufacturer zbit_spinand_manufacturer = {
73 	.id = SPINAND_MFR_ZBIT,
74 	.name = "ZBIT",
75 	.chips = zbit_spinand_table,
76 	.nchips = ARRAY_SIZE(zbit_spinand_table),
77 	.ops = &zbit_spinand_manuf_ops,
78 };
79