raw_nand.h 4.77 KB
Newer Older
Lionel Debieve's avatar
Lionel Debieve committed
1
/*
2
 * Copyright (c) 2019-2020, STMicroelectronics - All Rights Reserved
Lionel Debieve's avatar
Lionel Debieve committed
3
4
5
6
7
8
9
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef DRIVERS_RAW_NAND_H
#define DRIVERS_RAW_NAND_H

10
#include <cdefs.h>
Lionel Debieve's avatar
Lionel Debieve committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <stdint.h>

#include <drivers/nand.h>

/* NAND ONFI default value mode 0 in picosecond */
#define NAND_TADL_MIN			400000UL
#define NAND_TALH_MIN			20000UL
#define NAND_TALS_MIN			50000UL
#define NAND_TAR_MIN			25000UL
#define NAND_TCCS_MIN			500000UL
#define NAND_TCEA_MIN			100000UL
#define NAND_TCEH_MIN			20000UL
#define NAND_TCH_MIN			20000UL
#define NAND_TCHZ_MAX			100000UL
#define NAND_TCLH_MIN			20000UL
#define NAND_TCLR_MIN			20000UL
#define NAND_TCLS_MIN			50000UL
#define NAND_TCOH_MIN			0UL
#define NAND_TCS_MIN			70000UL
#define NAND_TDH_MIN			20000UL
#define NAND_TDS_MIN			40000UL
#define NAND_TFEAT_MAX			1000000UL
#define NAND_TIR_MIN			10000UL
#define NAND_TITC_MIN			1000000UL
#define NAND_TR_MAX			200000000UL
#define NAND_TRC_MIN			100000UL
#define NAND_TREA_MAX			40000UL
#define NAND_TREH_MIN			30000UL
#define NAND_TRHOH_MIN			0UL
#define NAND_TRHW_MIN			200000UL
#define NAND_TRHZ_MAX			200000UL
#define NAND_TRLOH_MIN			0UL
#define NAND_TRP_MIN			50000UL
#define NAND_TRR_MIN			40000UL
#define NAND_TRST_MAX			250000000000ULL
#define NAND_TWB_MAX			200000UL
#define NAND_TWC_MIN			100000UL
#define NAND_TWH_MIN			30000UL
#define NAND_TWHR_MIN			120000UL
#define NAND_TWP_MIN			50000UL
#define NAND_TWW_MIN			100000UL

/* NAND request types */
#define NAND_REQ_CMD			0x0000U
#define NAND_REQ_ADDR			0x1000U
#define NAND_REQ_DATAIN			0x2000U
#define NAND_REQ_DATAOUT		0x3000U
#define NAND_REQ_WAIT			0x4000U
#define NAND_REQ_MASK			GENMASK(14, 12)
#define NAND_REQ_BUS_WIDTH_8		BIT(15)

#define PARAM_PAGE_SIZE			256

/* NAND ONFI commands */
#define NAND_CMD_READ_1ST		0x00U
#define NAND_CMD_CHANGE_1ST		0x05U
#define NAND_CMD_READID_SIG_ADDR	0x20U
#define NAND_CMD_READ_2ND		0x30U
#define NAND_CMD_STATUS			0x70U
#define NAND_CMD_READID			0x90U
#define NAND_CMD_CHANGE_2ND		0xE0U
#define NAND_CMD_READ_PARAM_PAGE	0xECU
#define NAND_CMD_RESET			0xFFU

#define ONFI_REV_21			BIT(3)
#define ONFI_FEAT_BUS_WIDTH_16		BIT(0)
#define ONFI_FEAT_EXTENDED_PARAM	BIT(7)

/* NAND ECC type */
#define NAND_ECC_NONE			U(0)
#define NAND_ECC_HW			U(1)
#define NAND_ECC_ONDIE			U(2)

/* NAND bus width */
#define NAND_BUS_WIDTH_8		U(0)
#define NAND_BUS_WIDTH_16		U(1)

struct nand_req {
	struct nand_device *nand;
	uint16_t type;
	uint8_t *addr;
	unsigned int length;
	unsigned int delay_ms;
	unsigned int inst_delay;
};

struct nand_param_page {
	/* Rev information and feature block */
	uint32_t page_sig;
	uint16_t rev;
	uint16_t features;
	uint16_t opt_cmd;
	uint8_t jtg;
	uint8_t train_cmd;
	uint16_t ext_param_length;
	uint8_t nb_param_pages;
	uint8_t reserved1[17];
	/* Manufacturer information */
	uint8_t manufacturer[12];
	uint8_t model[20];
	uint8_t manufacturer_id;
	uint16_t data_code;
	uint8_t reserved2[13];
	/* Memory organization */
	uint32_t bytes_per_page;
	uint16_t spare_per_page;
	uint32_t bytes_per_partial;
	uint16_t spare_per_partial;
	uint32_t num_pages_per_blk;
	uint32_t num_blk_in_lun;
	uint8_t num_lun;
	uint8_t num_addr_cycles;
	uint8_t bit_per_cell;
	uint16_t max_bb_per_lun;
	uint16_t blk_endur;
	uint8_t valid_blk_begin;
	uint16_t blk_enbur_valid;
	uint8_t nb_prog_page;
	uint8_t partial_prog_attr;
	uint8_t nb_ecc_bits;
	uint8_t plane_addr;
	uint8_t mplanes_ops;
	uint8_t ez_nand;
	uint8_t reserved3[12];
	/* Electrical parameters */
	uint8_t io_pin_cap_max;
	uint16_t sdr_timing_mode;
	uint16_t sdr_prog_cache_timing;
	uint16_t tprog;
	uint16_t tbers;
	uint16_t tr;
	uint16_t tccs;
	uint8_t nvddr_timing_mode;
	uint8_t nvddr2_timing_mode;
	uint8_t nvddr_features;
	uint16_t clk_input_cap_typ;
	uint16_t io_pin_cap_typ;
	uint16_t input_pin_cap_typ;
	uint8_t input_pin_cap_max;
	uint8_t drv_strength_support;
	uint16_t tr_max;
	uint16_t tadl;
	uint16_t tr_typ;
	uint8_t reserved4[6];
	/* Vendor block */
	uint16_t vendor_revision;
	uint8_t vendor[88];
	uint16_t crc16;
} __packed;

struct nand_ctrl_ops {
	int (*exec)(struct nand_req *req);
	void (*setup)(struct nand_device *nand);
};

struct rawnand_device {
	struct nand_device *nand_dev;
	const struct nand_ctrl_ops *ops;
};

int nand_raw_init(unsigned long long *size, unsigned int *erase_size);
172
int nand_wait_ready(unsigned int delay_ms);
Lionel Debieve's avatar
Lionel Debieve committed
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
int nand_read_page_cmd(unsigned int page, unsigned int offset,
		       uintptr_t buffer, unsigned int len);
int nand_change_read_column_cmd(unsigned int offset, uintptr_t buffer,
				unsigned int len);
void nand_raw_ctrl_init(const struct nand_ctrl_ops *ops);

/*
 * Platform can implement this to override default raw NAND instance
 * configuration.
 *
 * @device: target raw NAND instance.
 * Return 0 on success, negative value otherwise.
 */
int plat_get_raw_nand_data(struct rawnand_device *device);

#endif	/* DRIVERS_RAW_NAND_H */