xref: /rk3399_rockchip-uboot/drivers/rkflash/flash.h (revision e7b5bb3cc9527752c2c01acb4325fc0721fb75aa)
1 /*
2  * Copyright (c) 2018 Fuzhou Rockchip Electronics Co., Ltd
3  *
4  * SPDX-License-Identifier:	GPL-2.0
5  */
6 
7 #ifndef __FLASH_H
8 #define __FLASH_H
9 
10 #include "typedef.h"
11 
12 #ifndef BIT
13 #define BIT(nr)			(1 << (nr))
14 #endif
15 
16 #define MAX_FLASH_NUM			2
17 #define MAX_IDB_RESERVED_BLOCK		12
18 
19 #define NAND_CACHE_READ_EN		BIT(0)
20 #define NAND_CACHE_RANDOM_READ_EN	BIT(1)
21 #define NAND_CACHE_PROG_EN		BIT(2)
22 #define NAND_MULTI_READ_EN		BIT(3)
23 
24 #define NAND_MULTI_PROG_EN		BIT(4)
25 #define NAND_INTERLEAVE_EN		BIT(5)
26 #define NAND_READ_RETRY_EN		BIT(6)
27 #define NAND_RANDOMIZER_EN		BIT(7)
28 
29 #define NAND_INTER_MODE_OFFSET		(0x8)
30 #define NAND_INTER_MODE_MARK		(0x07)
31 #define NAND_INTER_SDR_EN		BIT(0)
32 #define NAND_INTER_ONFI_EN		BIT(1)
33 #define NAND_INTER_TOGGLE_EN		BIT(2)
34 
35 #define NAND_SDR_EN			BIT(8)
36 #define NAND_ONFI_EN			BIT(9)
37 #define NAND_TOGGLE_EN			BIT(10)
38 #define NAND_UNIQUE_ID_EN		BIT(11)
39 
40 #define RESET_CMD		0xff
41 #define READ_ID_CMD		0x90
42 #define READ_STATUS_CMD		0x70
43 #define PAGE_PROG_CMD		0x8010
44 #define BLOCK_ERASE_CMD		0x60d0
45 #define READ_CMD		0x0030
46 #define READ_DP_OUT_CMD		0x05E0
47 
48 #define SAMSUNG			0x00	/* SAMSUNG */
49 #define TOSHIBA			0x01	/* TOSHIBA */
50 #define HYNIX			0x02	/* HYNIX */
51 #define INFINEON		0x03	/* INFINEON */
52 #define MICRON			0x04	/* MICRON */
53 #define RENESAS			0x05	/* RENESAS */
54 #define ST			0x06	/* ST */
55 #define INTEL			0x07	/* intel */
56 #define Sandisk			0x08	/* Sandisk */
57 
58 #define RR_NONE			0x00
59 #define RR_HY_1			0x01	/* hynix H27UCG8T2M */
60 #define RR_HY_2			0x02	/* hynix H27UBG08U0B */
61 #define RR_HY_3			0x03	/* hynix H27UCG08U0B H27UBG08U0C */
62 #define RR_HY_4                 0x04	/* hynix H27UCG8T2A */
63 #define RR_HY_5                 0x05	/* hynix H27UCG8T2E */
64 #define RR_HY_6                 0x06	/* hynix H27QCG8T2F5R-BCG */
65 #define RR_MT_1                 0x11	/* micron */
66 #define RR_MT_2                 0x12	/* micron L94C L95B */
67 #define RR_TH_1                 0x21	/* toshiba */
68 #define RR_TH_2                 0x22	/* toshiba */
69 #define RR_TH_3                 0x23	/* toshiba */
70 #define RR_SS_1                 0x31	/* samsung */
71 #define RR_SD_1                 0x41	/* Sandisk */
72 #define RR_SD_2                 0x42	/* Sandisk */
73 #define RR_SD_3                 0x43	/* Sandisk */
74 #define RR_SD_4                 0x44	/* Sandisk */
75 
76 /*  0 1 2 3 4 5 6 7 8 9 slc */
77 #define LSB_0	0
78 /*  0 1 2 3 6 7 A B E F hynix, micron 74A */
79 #define LSB_1	1
80 /*  0 1 3 5 7 9 B D toshiba samsung sandisk */
81 #define LSB_2	2
82 /*  0 1 2 3 4 5 8 9 C D 10 11 micron 84A */
83 #define LSB_3	3
84 /*  0 1 2 3 4 5 7 8 A B E F micron L95B */
85 #define LSB_4	4
86 /*  0 1 2 3 4 5 8 9 14 15 20 21 26 27 micron B74A TLC */
87 #define LSB_6	6
88 /*  0 3 6 9 C F 12 15 18 15 1B 1E 21 24 K9ABGD8U0C TLC */
89 #define LSB_7	7
90 
91 /* BadBlockFlagMode */
92 /* first spare @ first page of each blocks */
93 #define BBF_1	1
94 /* first spare @ last page of each blocks */
95 #define BBF_2	2
96 /* first spare @ first and last page of each blocks */
97 #define BBF_11	3
98 /* sandisk 15nm flash prog first page without data and check status */
99 #define BBF_3	4
100 
101 #define MPM_0	0	/* block 0 ~ 1 */
102 #define MPM_1	1	/* block 0 ~ 2048... */
103 
104 struct NAND_PARA_INFO_T {
105 	u8	id_bytes;
106 	u8	nand_id[6];
107 	u8	vendor;
108 	u8	die_per_chip;
109 	u8	sec_per_page;
110 	u16	page_per_blk;
111 	u8	cell;	/* 1 slc , 2 mlc , 3 tlc */
112 	u8	plane_per_die;
113 	u16	 blk_per_plane;
114 	u16	operation_opt;
115 	u8	lsb_mode;
116 	u8	read_retry_mode;
117 	u8	ecc_bits;
118 	u8	access_freq;
119 	u8	opt_mode;
120 	u8	die_gap;
121 	u8	bad_block_mode;
122 	u8	multi_plane_mode;
123 	u8	reversd2[6];	/* 32 bytes */
124 };
125 
126 struct FLASH_INFO_T {
127 	u16	block_size;
128 	u8	ecc_bits;
129 	u32	flash_size;
130 	u16	page_size;
131 	u8	access_time;
132 	u8	manufacturer_name;
133 	u8	flash_mask;
134 };
135 
136 extern struct nand_phy_info	g_nand_phy_info;
137 extern struct nand_ops		g_nand_ops;
138 extern void __iomem *nandc_base;
139 
140 void nandc_flash_get_id(u8 cs, void *buf);
141 void nandc_flash_reset(u8 chip_sel);
142 u32 nandc_flash_init(void __iomem *nandc_addr);
143 u32 nandc_flash_deinit(void);
144 
145 #endif
146