denali.h 10.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * NAND Flash Controller Device Driver
 * Copyright (c) 2009 - 2010, Intel Corporation and its suppliers.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */

20 21 22
#ifndef __DENALI_H__
#define __DENALI_H__

23
#include <linux/bitops.h>
24
#include <linux/completion.h>
25
#include <linux/mtd/rawnand.h>
26 27
#include <linux/spinlock_types.h>
#include <linux/types.h>
28 29

#define DEVICE_RESET				0x0
30
#define     DEVICE_RESET__BANK(bank)			BIT(bank)
31 32

#define TRANSFER_SPARE_REG			0x10
33
#define     TRANSFER_SPARE_REG__FLAG			BIT(0)
34 35

#define LOAD_WAIT_CNT				0x20
36
#define     LOAD_WAIT_CNT__VALUE			GENMASK(15, 0)
37 38

#define PROGRAM_WAIT_CNT			0x30
39
#define     PROGRAM_WAIT_CNT__VALUE			GENMASK(15, 0)
40 41

#define ERASE_WAIT_CNT				0x40
42
#define     ERASE_WAIT_CNT__VALUE			GENMASK(15, 0)
43 44

#define INT_MON_CYCCNT				0x50
45
#define     INT_MON_CYCCNT__VALUE			GENMASK(15, 0)
46 47

#define RB_PIN_ENABLED				0x60
48
#define     RB_PIN_ENABLED__BANK(bank)			BIT(bank)
49 50

#define MULTIPLANE_OPERATION			0x70
51
#define     MULTIPLANE_OPERATION__FLAG			BIT(0)
52 53

#define MULTIPLANE_READ_ENABLE			0x80
54
#define     MULTIPLANE_READ_ENABLE__FLAG		BIT(0)
55 56

#define COPYBACK_DISABLE			0x90
57
#define     COPYBACK_DISABLE__FLAG			BIT(0)
58 59

#define CACHE_WRITE_ENABLE			0xa0
60
#define     CACHE_WRITE_ENABLE__FLAG			BIT(0)
61 62

#define CACHE_READ_ENABLE			0xb0
63
#define     CACHE_READ_ENABLE__FLAG			BIT(0)
64 65

#define PREFETCH_MODE				0xc0
66 67
#define     PREFETCH_MODE__PREFETCH_EN			BIT(0)
#define     PREFETCH_MODE__PREFETCH_BURST_LENGTH	GENMASK(15, 4)
68 69

#define CHIP_ENABLE_DONT_CARE			0xd0
70
#define     CHIP_EN_DONT_CARE__FLAG			BIT(0)
71 72

#define ECC_ENABLE				0xe0
73
#define     ECC_ENABLE__FLAG				BIT(0)
74 75

#define GLOBAL_INT_ENABLE			0xf0
76
#define     GLOBAL_INT_EN_FLAG				BIT(0)
77

78 79 80
#define TWHR2_AND_WE_2_RE			0x100
#define     TWHR2_AND_WE_2_RE__WE_2_RE			GENMASK(5, 0)
#define     TWHR2_AND_WE_2_RE__TWHR2			GENMASK(13, 8)
81

82 83 84 85
#define TCWAW_AND_ADDR_2_DATA			0x110
/* The width of ADDR_2_DATA is 6 bit for old IP, 7 bit for new IP */
#define     TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA		GENMASK(6, 0)
#define     TCWAW_AND_ADDR_2_DATA__TCWAW		GENMASK(13, 8)
86 87

#define RE_2_WE					0x120
88
#define     RE_2_WE__VALUE				GENMASK(5, 0)
89

90
#define ACC_CLKS				0x130
91
#define     ACC_CLKS__VALUE				GENMASK(3, 0)
92 93

#define NUMBER_OF_PLANES			0x140
94
#define     NUMBER_OF_PLANES__VALUE			GENMASK(2, 0)
95 96

#define PAGES_PER_BLOCK				0x150
97
#define     PAGES_PER_BLOCK__VALUE			GENMASK(15, 0)
98 99

#define DEVICE_WIDTH				0x160
100
#define     DEVICE_WIDTH__VALUE				GENMASK(1, 0)
101 102

#define DEVICE_MAIN_AREA_SIZE			0x170
103
#define     DEVICE_MAIN_AREA_SIZE__VALUE		GENMASK(15, 0)
104 105

#define DEVICE_SPARE_AREA_SIZE			0x180
106
#define     DEVICE_SPARE_AREA_SIZE__VALUE		GENMASK(15, 0)
107 108

#define TWO_ROW_ADDR_CYCLES			0x190
109
#define     TWO_ROW_ADDR_CYCLES__FLAG			BIT(0)
110 111

#define MULTIPLANE_ADDR_RESTRICT		0x1a0
112
#define     MULTIPLANE_ADDR_RESTRICT__FLAG		BIT(0)
113 114

#define ECC_CORRECTION				0x1b0
115
#define     ECC_CORRECTION__VALUE			GENMASK(4, 0)
116
#define     ECC_CORRECTION__ERASE_THRESHOLD		GENMASK(31, 16)
117 118

#define READ_MODE				0x1c0
119
#define     READ_MODE__VALUE				GENMASK(3, 0)
120 121

#define WRITE_MODE				0x1d0
122
#define     WRITE_MODE__VALUE				GENMASK(3, 0)
123 124

#define COPYBACK_MODE				0x1e0
125
#define     COPYBACK_MODE__VALUE			GENMASK(3, 0)
126 127

#define RDWR_EN_LO_CNT				0x1f0
128
#define     RDWR_EN_LO_CNT__VALUE			GENMASK(4, 0)
129 130

#define RDWR_EN_HI_CNT				0x200
131
#define     RDWR_EN_HI_CNT__VALUE			GENMASK(4, 0)
132 133

#define MAX_RD_DELAY				0x210
134
#define     MAX_RD_DELAY__VALUE				GENMASK(3, 0)
135 136

#define CS_SETUP_CNT				0x220
137
#define     CS_SETUP_CNT__VALUE				GENMASK(4, 0)
138
#define     CS_SETUP_CNT__TWB				GENMASK(17, 12)
139 140

#define SPARE_AREA_SKIP_BYTES			0x230
141
#define     SPARE_AREA_SKIP_BYTES__VALUE		GENMASK(5, 0)
142 143

#define SPARE_AREA_MARKER			0x240
144
#define     SPARE_AREA_MARKER__VALUE			GENMASK(15, 0)
145 146

#define DEVICES_CONNECTED			0x250
147
#define     DEVICES_CONNECTED__VALUE			GENMASK(2, 0)
148

149
#define DIE_MASK				0x260
150
#define     DIE_MASK__VALUE				GENMASK(7, 0)
151 152

#define FIRST_BLOCK_OF_NEXT_PLANE		0x270
153
#define     FIRST_BLOCK_OF_NEXT_PLANE__VALUE		GENMASK(15, 0)
154 155

#define WRITE_PROTECT				0x280
156
#define     WRITE_PROTECT__FLAG				BIT(0)
157 158

#define RE_2_RE					0x290
159
#define     RE_2_RE__VALUE				GENMASK(5, 0)
160

161
#define MANUFACTURER_ID				0x300
162
#define     MANUFACTURER_ID__VALUE			GENMASK(7, 0)
163 164

#define DEVICE_ID				0x310
165
#define     DEVICE_ID__VALUE				GENMASK(7, 0)
166 167

#define DEVICE_PARAM_0				0x320
168
#define     DEVICE_PARAM_0__VALUE			GENMASK(7, 0)
169 170

#define DEVICE_PARAM_1				0x330
171
#define     DEVICE_PARAM_1__VALUE			GENMASK(7, 0)
172 173

#define DEVICE_PARAM_2				0x340
174
#define     DEVICE_PARAM_2__VALUE			GENMASK(7, 0)
175 176

#define LOGICAL_PAGE_DATA_SIZE			0x350
177
#define     LOGICAL_PAGE_DATA_SIZE__VALUE		GENMASK(15, 0)
178 179

#define LOGICAL_PAGE_SPARE_SIZE			0x360
180
#define     LOGICAL_PAGE_SPARE_SIZE__VALUE		GENMASK(15, 0)
181

182
#define REVISION				0x370
183
#define     REVISION__VALUE				GENMASK(15, 0)
184 185

#define ONFI_DEVICE_FEATURES			0x380
186
#define     ONFI_DEVICE_FEATURES__VALUE			GENMASK(5, 0)
187

188
#define ONFI_OPTIONAL_COMMANDS			0x390
189
#define     ONFI_OPTIONAL_COMMANDS__VALUE		GENMASK(5, 0)
190 191

#define ONFI_TIMING_MODE			0x3a0
192
#define     ONFI_TIMING_MODE__VALUE			GENMASK(5, 0)
193 194

#define ONFI_PGM_CACHE_TIMING_MODE		0x3b0
195
#define     ONFI_PGM_CACHE_TIMING_MODE__VALUE		GENMASK(5, 0)
196 197

#define ONFI_DEVICE_NO_OF_LUNS			0x3c0
198 199
#define     ONFI_DEVICE_NO_OF_LUNS__NO_OF_LUNS		GENMASK(7, 0)
#define     ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE		BIT(8)
200 201

#define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L	0x3d0
202
#define     ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L__VALUE	GENMASK(15, 0)
203 204

#define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U	0x3e0
205 206 207 208 209 210 211 212 213 214 215
#define     ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U__VALUE	GENMASK(15, 0)

#define FEATURES				0x3f0
#define     FEATURES__N_BANKS				GENMASK(1, 0)
#define     FEATURES__ECC_MAX_ERR			GENMASK(5, 2)
#define     FEATURES__DMA				BIT(6)
#define     FEATURES__CMD_DMA				BIT(7)
#define     FEATURES__PARTITION				BIT(8)
#define     FEATURES__XDMA_SIDEBAND			BIT(9)
#define     FEATURES__GPREG				BIT(10)
#define     FEATURES__INDEX_ADDR			BIT(11)
216 217

#define TRANSFER_MODE				0x400
218
#define     TRANSFER_MODE__VALUE			GENMASK(1, 0)
219

220 221
#define INTR_STATUS(bank)			(0x410 + (bank) * 0x50)
#define INTR_EN(bank)				(0x420 + (bank) * 0x50)
222
/* bit[1:0] is used differently depending on IP version */
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
#define     INTR__ECC_UNCOR_ERR				BIT(0)	/* new IP */
#define     INTR__ECC_TRANSACTION_DONE			BIT(0)	/* old IP */
#define     INTR__ECC_ERR				BIT(1)	/* old IP */
#define     INTR__DMA_CMD_COMP				BIT(2)
#define     INTR__TIME_OUT				BIT(3)
#define     INTR__PROGRAM_FAIL				BIT(4)
#define     INTR__ERASE_FAIL				BIT(5)
#define     INTR__LOAD_COMP				BIT(6)
#define     INTR__PROGRAM_COMP				BIT(7)
#define     INTR__ERASE_COMP				BIT(8)
#define     INTR__PIPE_CPYBCK_CMD_COMP			BIT(9)
#define     INTR__LOCKED_BLK				BIT(10)
#define     INTR__UNSUP_CMD				BIT(11)
#define     INTR__INT_ACT				BIT(12)
#define     INTR__RST_COMP				BIT(13)
#define     INTR__PIPE_CMD_ERR				BIT(14)
#define     INTR__PAGE_XFER_INC				BIT(15)
240
#define     INTR__ERASED_PAGE				BIT(16)
241 242 243 244

#define PAGE_CNT(bank)				(0x430 + (bank) * 0x50)
#define ERR_PAGE_ADDR(bank)			(0x440 + (bank) * 0x50)
#define ERR_BLOCK_ADDR(bank)			(0x450 + (bank) * 0x50)
245 246

#define ECC_THRESHOLD				0x600
247
#define     ECC_THRESHOLD__VALUE			GENMASK(9, 0)
248

249
#define ECC_ERROR_BLOCK_ADDRESS			0x610
250
#define     ECC_ERROR_BLOCK_ADDRESS__VALUE		GENMASK(15, 0)
251 252

#define ECC_ERROR_PAGE_ADDRESS			0x620
253 254
#define     ECC_ERROR_PAGE_ADDRESS__VALUE		GENMASK(11, 0)
#define     ECC_ERROR_PAGE_ADDRESS__BANK		GENMASK(15, 12)
255 256

#define ECC_ERROR_ADDRESS			0x630
257
#define     ECC_ERROR_ADDRESS__OFFSET			GENMASK(11, 0)
258
#define     ECC_ERROR_ADDRESS__SECTOR			GENMASK(15, 12)
259 260

#define ERR_CORRECTION_INFO			0x640
261 262 263 264
#define     ERR_CORRECTION_INFO__BYTE			GENMASK(7, 0)
#define     ERR_CORRECTION_INFO__DEVICE			GENMASK(11, 8)
#define     ERR_CORRECTION_INFO__UNCOR			BIT(14)
#define     ERR_CORRECTION_INFO__LAST_ERR		BIT(15)
265

266 267
#define ECC_COR_INFO(bank)			(0x650 + (bank) / 2 * 0x10)
#define     ECC_COR_INFO__SHIFT(bank)			((bank) % 2 * 8)
268 269
#define     ECC_COR_INFO__MAX_ERRORS			GENMASK(6, 0)
#define     ECC_COR_INFO__UNCOR_ERR			BIT(7)
270

271 272 273 274 275 276 277 278
#define CFG_DATA_BLOCK_SIZE			0x6b0

#define CFG_LAST_DATA_BLOCK_SIZE		0x6c0

#define CFG_NUM_DATA_BLOCKS			0x6d0

#define CFG_META_DATA_SIZE			0x6e0

279
#define DMA_ENABLE				0x700
280
#define     DMA_ENABLE__FLAG				BIT(0)
281 282

#define IGNORE_ECC_DONE				0x710
283
#define     IGNORE_ECC_DONE__FLAG			BIT(0)
284 285

#define DMA_INTR				0x720
286
#define DMA_INTR_EN				0x730
287 288 289 290 291 292
#define     DMA_INTR__TARGET_ERROR			BIT(0)
#define     DMA_INTR__DESC_COMP_CHANNEL0		BIT(1)
#define     DMA_INTR__DESC_COMP_CHANNEL1		BIT(2)
#define     DMA_INTR__DESC_COMP_CHANNEL2		BIT(3)
#define     DMA_INTR__DESC_COMP_CHANNEL3		BIT(4)
#define     DMA_INTR__MEMCOPY_DESC_COMP			BIT(5)
293 294

#define TARGET_ERR_ADDR_LO			0x740
295
#define     TARGET_ERR_ADDR_LO__VALUE			GENMASK(15, 0)
296 297

#define TARGET_ERR_ADDR_HI			0x750
298
#define     TARGET_ERR_ADDR_HI__VALUE			GENMASK(15, 0)
299 300

#define CHNL_ACTIVE				0x760
301 302 303 304
#define     CHNL_ACTIVE__CHANNEL0			BIT(0)
#define     CHNL_ACTIVE__CHANNEL1			BIT(1)
#define     CHNL_ACTIVE__CHANNEL2			BIT(2)
#define     CHNL_ACTIVE__CHANNEL3			BIT(3)
305 306 307

struct denali_nand_info {
	struct nand_chip nand;
308
	unsigned long clk_x_rate;	/* bus interface clock rate */
309
	int active_bank;		/* currently selected bank */
310
	struct device *dev;
311 312
	void __iomem *reg;		/* Register Interface */
	void __iomem *host;		/* Host Data/Command Interface */
313 314 315 316

	/* elements used by ISR */
	struct completion complete;
	spinlock_t irq_lock;
317
	uint32_t irq_mask;
318
	uint32_t irq_status;
319
	int irq;
320

321 322
	void *buf;
	dma_addr_t dma_addr;
323
	int dma_avail;
324 325
	int devs_per_cs;		/* devices connected in parallel */
	int oob_skip_bytes;
326
	int max_banks;
327
	unsigned int revision;
328
	unsigned int caps;
329
	const struct nand_ecc_caps *ecc_caps;
330 331
};

332
#define DENALI_CAP_HW_ECC_FIXUP			BIT(0)
333
#define DENALI_CAP_DMA_64BIT			BIT(1)
334

335
int denali_calc_ecc_bytes(int step_size, int strength);
336 337 338
extern int denali_init(struct denali_nand_info *denali);
extern void denali_remove(struct denali_nand_info *denali);

339
#endif /* __DENALI_H__ */