xref: /rk3399_rockchip-uboot/drivers/rkflash/sfc_nand.h (revision 2ba7147f8008e675b31a0a5c13b8366431ea09ae)
1 /*
2  * Copyright (c) 2018 Fuzhou Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:	GPL-2.0
5  */
6 
7 #ifndef __SFC_NAND_H
8 #define __SFC_NAND_H
9 
10 #define SFC_NAND_STRESS_TEST_EN		0
11 
12 #define SFC_NAND_PROG_ERASE_ERROR	-2
13 #define SFC_NAND_HW_ERROR		-1
14 #define SFC_NAND_ECC_ERROR		NAND_ERROR
15 #define SFC_NAND_ECC_REFRESH		NAND_STS_REFRESH
16 #define SFC_NAND_ECC_OK			NAND_STS_OK
17 
18 #define SFC_NAND_PAGE_MAX_SIZE		4224
19 #define SFC_NAND_SECTOR_FULL_SIZE	528
20 
21 #define FEA_READ_STATUE_MASK    (0x3 << 0)
22 #define FEA_STATUE_MODE1        0
23 #define FEA_STATUE_MODE2        1
24 #define FEA_4BIT_READ           BIT(2)
25 #define FEA_4BIT_PROG           BIT(3)
26 #define FEA_4BYTE_ADDR          BIT(4)
27 #define FEA_4BYTE_ADDR_MODE	BIT(5)
28 #define FEA_SOFT_QOP_BIT	BIT(6)
29 
30 #define MID_WINBOND             0xEF
31 #define MID_GIGADEV             0xC8
32 #define MID_MICRON              0x2C
33 #define MID_MACRONIX            0xC2
34 #define MID_SPANSION            0x01
35 #define MID_EON                 0x1C
36 #define MID_ST                  0x20
37 
38 /* Command Set */
39 #define CMD_READ_JEDECID        (0x9F)
40 #define CMD_READ_DATA           (0x03)
41 #define CMD_READ_STATUS         (0x05)
42 #define CMD_WRITE_STATUS        (0x01)
43 #define CMD_PAGE_PROG           (0x02)
44 #define CMD_SECTOR_ERASE        (0x20)
45 #define CMD_BLK64K_ERASE        (0xD8)
46 #define CMD_BLK32K_ERASE        (0x52)
47 #define CMD_CHIP_ERASE          (0xC7)
48 #define CMD_WRITE_EN            (0x06)
49 #define CMD_WRITE_DIS           (0x04)
50 #define CMD_PAGE_READ           (0x13)
51 #define CMD_GET_FEATURE         (0x0F)
52 #define CMD_SET_FEATURE         (0x1F)
53 #define CMD_PROG_LOAD           (0x02)
54 #define CMD_PROG_EXEC           (0x10)
55 #define CMD_BLOCK_ERASE         (0xD8)
56 #define CMD_READ_DATA_X2        (0x3B)
57 #define CMD_READ_DATA_X4        (0x6B)
58 #define CMD_PROG_LOAD_X4        (0x32)
59 #define CMD_READ_STATUS2        (0x35)
60 #define CMD_READ_STATUS3        (0x15)
61 #define CMD_WRITE_STATUS2       (0x31)
62 #define CMD_WRITE_STATUS3       (0x11)
63 #define CMD_FAST_READ_X1        (0x0B)  /* X1 cmd, X1 addr, X1 data */
64 #define CMD_FAST_READ_X2        (0x3B)  /* X1 cmd, X1 addr, X2 data */
65 /* X1 cmd, X1 addr, X4 data SUPPORT GD MARCONIX WINBOND */
66 #define CMD_FAST_READ_X4        (0x6B)
67 /* X1 cmd, X1 addr, X4 data SUPPORT GD MARCONIX WINBOND */
68 #define CMD_FAST_4READ_X4       (0x6C)
69 /* X1 cmd, X4 addr, X4 data SUPPORT EON GD MARCONIX WINBOND */
70 #define CMD_FAST_READ_A4        (0xEB)
71 /* X1 cmd, X1 addr, X4 data, SUPPORT GD WINBOND */
72 #define CMD_PAGE_PROG_X4        (0x32)
73 /* X1 cmd, X4 addr, X4 data, SUPPORT MARCONIX */
74 #define CMD_PAGE_PROG_A4        (0x38)
75 #define CMD_RESET_NAND          (0xFF)
76 
77 #define CMD_ENTER_4BYTE_MODE    (0xB7)
78 #define CMD_EXIT_4BYTE_MODE     (0xE9)
79 #define CMD_ENABLE_RESER	(0x66)
80 #define CMD_RESET_DEVICE	(0x99)
81 
82 struct SFNAND_DEV {
83 	u32 capacity;
84 	u32 block_size;
85 	u16 page_size;
86 	u8 manufacturer;
87 	u8 mem_type;
88 	u8 read_lines;
89 	u8 prog_lines;
90 	u8 page_read_cmd;
91 	u8 page_prog_cmd;
92 };
93 
94 struct nand_info {
95 	u32 id;
96 
97 	u16 sec_per_page;
98 	u16 page_per_blk;
99 	u16 plane_per_die;
100 	u16 blk_per_plane;
101 
102 	u8 page_read_cmd;
103 	u8 page_prog_cmd;
104 	u8 read_cache_cmd_1;
105 	u8 prog_cache_cmd_1;
106 
107 	u8 read_cache_cmd_4;
108 	u8 prog_cache_cmd_4;
109 	u8 block_erase_cmd;
110 	u8 feature;
111 
112 	u8 density;  /* (1 << density) sectors*/
113 	u8 max_ecc_bits;
114 	u8 QE_address;
115 	u8 QE_bits;
116 
117 	u8 spare_offs_1;	/* 4/8 bytes for 2KB/4KB page size flash */
118 	u8 spare_offs_2;	/* 4/8 bytes for 2KB/4KB page size flash */
119 	u32 (*ecc_status)(void);
120 };
121 
122 extern struct nand_phy_info	g_nand_phy_info;
123 extern struct nand_ops		g_nand_ops;
124 
125 u32 sfc_nand_init(void);
126 void sfc_nand_deinit(void);
127 int sfc_nand_read_id(u8 *buf);
128 u32 sfc_nand_ecc_status_sp1(void);
129 u32 sfc_nand_ecc_status_sp3(void);
130 u32 sfc_nand_ecc_status_sp4(void);
131 u32 sfc_nand_ecc_status_sp5(void);
132 
133 #endif
134