blob: 4af5d53b1e0beb4923d4b22e6206bccc5884458e [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/*
2 * NAND Flash Controller Device Driver
3 * Copyright (c) 2009 - 2010, Intel Corporation and its suppliers.
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
17 *
18 */
19
20#include <linux/mtd/nand.h>
21
22#define DEVICE_RESET 0x0
23#define DEVICE_RESET__BANK0 0x0001
24#define DEVICE_RESET__BANK1 0x0002
25#define DEVICE_RESET__BANK2 0x0004
26#define DEVICE_RESET__BANK3 0x0008
27
28#define TRANSFER_SPARE_REG 0x10
29#define TRANSFER_SPARE_REG__FLAG 0x0001
30
31#define LOAD_WAIT_CNT 0x20
32#define LOAD_WAIT_CNT__VALUE 0xffff
33
34#define PROGRAM_WAIT_CNT 0x30
35#define PROGRAM_WAIT_CNT__VALUE 0xffff
36
37#define ERASE_WAIT_CNT 0x40
38#define ERASE_WAIT_CNT__VALUE 0xffff
39
40#define INT_MON_CYCCNT 0x50
41#define INT_MON_CYCCNT__VALUE 0xffff
42
43#define RB_PIN_ENABLED 0x60
44#define RB_PIN_ENABLED__BANK0 0x0001
45#define RB_PIN_ENABLED__BANK1 0x0002
46#define RB_PIN_ENABLED__BANK2 0x0004
47#define RB_PIN_ENABLED__BANK3 0x0008
48
49#define MULTIPLANE_OPERATION 0x70
50#define MULTIPLANE_OPERATION__FLAG 0x0001
51
52#define MULTIPLANE_READ_ENABLE 0x80
53#define MULTIPLANE_READ_ENABLE__FLAG 0x0001
54
55#define COPYBACK_DISABLE 0x90
56#define COPYBACK_DISABLE__FLAG 0x0001
57
58#define CACHE_WRITE_ENABLE 0xa0
59#define CACHE_WRITE_ENABLE__FLAG 0x0001
60
61#define CACHE_READ_ENABLE 0xb0
62#define CACHE_READ_ENABLE__FLAG 0x0001
63
64#define PREFETCH_MODE 0xc0
65#define PREFETCH_MODE__PREFETCH_EN 0x0001
66#define PREFETCH_MODE__PREFETCH_BURST_LENGTH 0xfff0
67
68#define CHIP_ENABLE_DONT_CARE 0xd0
69#define CHIP_EN_DONT_CARE__FLAG 0x01
70
71#define ECC_ENABLE 0xe0
72#define ECC_ENABLE__FLAG 0x0001
73
74#define GLOBAL_INT_ENABLE 0xf0
75#define GLOBAL_INT_EN_FLAG 0x01
76
77#define WE_2_RE 0x100
78#define WE_2_RE__VALUE 0x003f
79
80#define ADDR_2_DATA 0x110
81#define ADDR_2_DATA__VALUE 0x003f
82
83#define RE_2_WE 0x120
84#define RE_2_WE__VALUE 0x003f
85
86#define ACC_CLKS 0x130
87#define ACC_CLKS__VALUE 0x000f
88
89#define NUMBER_OF_PLANES 0x140
90#define NUMBER_OF_PLANES__VALUE 0x0007
91
92#define PAGES_PER_BLOCK 0x150
93#define PAGES_PER_BLOCK__VALUE 0xffff
94
95#define DEVICE_WIDTH 0x160
96#define DEVICE_WIDTH__VALUE 0x0003
97
98#define DEVICE_MAIN_AREA_SIZE 0x170
99#define DEVICE_MAIN_AREA_SIZE__VALUE 0xffff
100
101#define DEVICE_SPARE_AREA_SIZE 0x180
102#define DEVICE_SPARE_AREA_SIZE__VALUE 0xffff
103
104#define TWO_ROW_ADDR_CYCLES 0x190
105#define TWO_ROW_ADDR_CYCLES__FLAG 0x0001
106
107#define MULTIPLANE_ADDR_RESTRICT 0x1a0
108#define MULTIPLANE_ADDR_RESTRICT__FLAG 0x0001
109
110#define ECC_CORRECTION 0x1b0
111#define ECC_CORRECTION__VALUE 0x001f
112
113#define READ_MODE 0x1c0
114#define READ_MODE__VALUE 0x000f
115
116#define WRITE_MODE 0x1d0
117#define WRITE_MODE__VALUE 0x000f
118
119#define COPYBACK_MODE 0x1e0
120#define COPYBACK_MODE__VALUE 0x000f
121
122#define RDWR_EN_LO_CNT 0x1f0
123#define RDWR_EN_LO_CNT__VALUE 0x001f
124
125#define RDWR_EN_HI_CNT 0x200
126#define RDWR_EN_HI_CNT__VALUE 0x001f
127
128#define MAX_RD_DELAY 0x210
129#define MAX_RD_DELAY__VALUE 0x000f
130
131#define CS_SETUP_CNT 0x220
132#define CS_SETUP_CNT__VALUE 0x001f
133
134#define SPARE_AREA_SKIP_BYTES 0x230
135#define SPARE_AREA_SKIP_BYTES__VALUE 0x003f
136
137#define SPARE_AREA_MARKER 0x240
138#define SPARE_AREA_MARKER__VALUE 0xffff
139
140#define DEVICES_CONNECTED 0x250
141#define DEVICES_CONNECTED__VALUE 0x0007
142
143#define DIE_MASK 0x260
144#define DIE_MASK__VALUE 0x00ff
145
146#define FIRST_BLOCK_OF_NEXT_PLANE 0x270
147#define FIRST_BLOCK_OF_NEXT_PLANE__VALUE 0xffff
148
149#define WRITE_PROTECT 0x280
150#define WRITE_PROTECT__FLAG 0x0001
151
152#define RE_2_RE 0x290
153#define RE_2_RE__VALUE 0x003f
154
155#define POR_RESET_COUNT 0x2a0
156
157#define WATCHDOG_RESET_COUNT 0x2b0
158
159#define MANUFACTURER_ID 0x300
160#define MANUFACTURER_ID__VALUE 0x00ff
161
162#define DEVICE_ID 0x310
163#define DEVICE_ID__VALUE 0x00ff
164
165#define DEVICE_PARAM_0 0x320
166#define DEVICE_PARAM_0__VALUE 0x00ff
167
168#define DEVICE_PARAM_1 0x330
169#define DEVICE_PARAM_1__VALUE 0x00ff
170
171#define DEVICE_PARAM_2 0x340
172#define DEVICE_PARAM_2__VALUE 0x00ff
173
174#define LOGICAL_PAGE_DATA_SIZE 0x350
175#define LOGICAL_PAGE_DATA_SIZE__VALUE 0xffff
176
177#define LOGICAL_PAGE_SPARE_SIZE 0x360
178#define LOGICAL_PAGE_SPARE_SIZE__VALUE 0xffff
179
180#define REVISION 0x370
181#define REVISION__VALUE 0xffff
182
183#define ONFI_DEVICE_FEATURES 0x380
184#define ONFI_DEVICE_FEATURES__VALUE 0x003f
185
186#define ONFI_OPTIONAL_COMMANDS 0x390
187#define ONFI_OPTIONAL_COMMANDS__VALUE 0x003f
188
189#define ONFI_TIMING_MODE 0x3a0
190#define ONFI_TIMING_MODE__VALUE 0x003f
191
192#define ONFI_PGM_CACHE_TIMING_MODE 0x3b0
193#define ONFI_PGM_CACHE_TIMING_MODE__VALUE 0x003f
194
195#define ONFI_DEVICE_NO_OF_LUNS 0x3c0
196#define ONFI_DEVICE_NO_OF_LUNS__NO_OF_LUNS 0x00ff
197#define ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE 0x0100
198
199#define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L 0x3d0
200#define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L__VALUE 0xffff
201
202#define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U 0x3e0
203#define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U__VALUE 0xffff
204
205#define FEATURES 0x3f0
206#define FEATURES__N_BANKS 0x0003
207#define FEATURES__ECC_MAX_ERR 0x003c
208#define FEATURES__DMA 0x0040
209#define FEATURES__CMD_DMA 0x0080
210#define FEATURES__PARTITION 0x0100
211#define FEATURES__XDMA_SIDEBAND 0x0200
212#define FEATURES__GPREG 0x0400
213#define FEATURES__INDEX_ADDR 0x0800
214
215#define TRANSFER_MODE 0x400
216#define TRANSFER_MODE__VALUE 0x0003
217
218#define INTR_STATUS(__bank) (0x410 + ((__bank) * 0x50))
219#define INTR_EN(__bank) (0x420 + ((__bank) * 0x50))
220
221#define INTR_STATUS__ECC_ERR 0x0001
222#define INTR_STATUS__ECC_TRANSACTION_DONE 0x0002 /*zx297510 dont support*/
223#define INTR_STATUS__DMA_CMD_COMP 0x0004
224#define INTR_STATUS__TIME_OUT 0x0008
225#define INTR_STATUS__PROGRAM_FAIL 0x0010
226#define INTR_STATUS__ERASE_FAIL 0x0020
227#define INTR_STATUS__LOAD_COMP 0x0040
228#define INTR_STATUS__PROGRAM_COMP 0x0080
229#define INTR_STATUS__ERASE_COMP 0x0100
230#define INTR_STATUS__PIPE_CPYBCK_CMD_COMP 0x0200
231#define INTR_STATUS__LOCKED_BLK 0x0400
232#define INTR_STATUS__UNSUP_CMD 0x0800
233#define INTR_STATUS__INT_ACT 0x1000
234#define INTR_STATUS__RST_COMP 0x2000
235#define INTR_STATUS__PIPE_CMD_ERR 0x4000
236#define INTR_STATUS__PAGE_XFER_INC 0x8000
237
238#define INTR_EN__ECC_ERR 0x0001
239#define INTR_EN__ECC_TRANSACTION_DONE 0x0002 /*zx297510 dont support*/
240#define INTR_EN__DMA_CMD_COMP 0x0004
241#define INTR_EN__TIME_OUT 0x0008
242#define INTR_EN__PROGRAM_FAIL 0x0010
243#define INTR_EN__ERASE_FAIL 0x0020
244#define INTR_EN__LOAD_COMP 0x0040
245#define INTR_EN__PROGRAM_COMP 0x0080
246#define INTR_EN__ERASE_COMP 0x0100
247#define INTR_EN__PIPE_CPYBCK_CMD_COMP 0x0200
248#define INTR_EN__LOCKED_BLK 0x0400
249#define INTR_EN__UNSUP_CMD 0x0800
250#define INTR_EN__INT_ACT 0x1000
251#define INTR_EN__RST_COMP 0x2000
252#define INTR_EN__PIPE_CMD_ERR 0x4000
253#define INTR_EN__PAGE_XFER_INC 0x8000
254
255#define PAGE_CNT(__bank) (0x430 + ((__bank) * 0x50))
256#define ERR_PAGE_ADDR(__bank) (0x440 + ((__bank) * 0x50))
257#define ERR_BLOCK_ADDR(__bank) (0x450 + ((__bank) * 0x50))
258
259#define DATA_INTR 0x550
260#define DATA_INTR__WRITE_SPACE_AV 0x0001
261#define DATA_INTR__READ_DATA_AV 0x0002
262
263#define DATA_INTR_EN 0x560
264#define DATA_INTR_EN__WRITE_SPACE_AV 0x0001
265#define DATA_INTR_EN__READ_DATA_AV 0x0002
266
267#define GPREG_0 0x570
268#define GPREG_0__VALUE 0xffff
269
270#define GPREG_1 0x580
271#define GPREG_1__VALUE 0xffff
272
273#define GPREG_2 0x590
274#define GPREG_2__VALUE 0xffff
275
276#define GPREG_3 0x5a0
277#define GPREG_3__VALUE 0xffff
278
279#define ECC_THRESHOLD 0x600
280#define ECC_THRESHOLD__VALUE 0x03ff
281
282#define ECC_ERROR_BLOCK_ADDRESS 0x610
283#define ECC_ERROR_BLOCK_ADDRESS__VALUE 0xffff
284
285#define ECC_ERROR_PAGE_ADDRESS 0x620
286#define ECC_ERROR_PAGE_ADDRESS__VALUE 0x0fff
287#define ECC_ERROR_PAGE_ADDRESS__BANK 0xf000
288
289#define ECC_ERROR_ADDRESS 0x630
290#define ECC_ERROR_ADDRESS__OFFSET 0x0fff
291#define ECC_ERROR_ADDRESS__SECTOR_NR 0xf000
292
293#define ERR_CORRECTION_INFO_B01 0x650
294#define ERR_CORRECTION_INFO__BYTEMASK 0x00ff
295#define ERR_CORRECTION_INFO__DEVICE_NR 0x0f00
296#define ERR_CORRECTION_INFO__ERROR_TYPE 0x4000
297#define ERR_CORRECTION_INFO__LAST_ERR_INFO 0x8000
298#define ERR_CORRECTION_INFO_B01__MAX_ERRORS_B0 0x007f
299#define ERR_CORRECTION_INFO_B01__MAX_ERRORS_B1 0x7f00
300
301#define ERR_CORRECTION_INFO_B23 0x660
302#define ERR_CORRECTION_INFO_B01__MAX_ERRORS_B2 0x007f
303#define ERR_CORRECTION_INFO_B01__MAX_ERRORS_B3 0x7f00
304
305
306
307#define DMA_ENABLE 0x700
308#define DMA_ENABLE__FLAG 0x0001
309
310#define IGNORE_ECC_DONE 0x710
311#define IGNORE_ECC_DONE__FLAG 0x0001
312
313#define DMA_INTR 0x720
314#define DMA_INTR__TARGET_ERROR 0x0001
315#define DMA_INTR__DESC_COMP_CHANNEL0 0x0002
316#define DMA_INTR__DESC_COMP_CHANNEL1 0x0004
317#define DMA_INTR__DESC_COMP_CHANNEL2 0x0008
318#define DMA_INTR__DESC_COMP_CHANNEL3 0x0010
319#define DMA_INTR__MEMCOPY_DESC_COMP 0x0020
320
321#define DMA_INTR_EN 0x730
322#define DMA_INTR_EN__TARGET_ERROR 0x0001
323#define DMA_INTR_EN__DESC_COMP_CHANNEL0 0x0002
324#define DMA_INTR_EN__DESC_COMP_CHANNEL1 0x0004
325#define DMA_INTR_EN__DESC_COMP_CHANNEL2 0x0008
326#define DMA_INTR_EN__DESC_COMP_CHANNEL3 0x0010
327#define DMA_INTR_EN__MEMCOPY_DESC_COMP 0x0020
328
329#define TARGET_ERR_ADDR_LO 0x740
330#define TARGET_ERR_ADDR_LO__VALUE 0xffff
331
332#define TARGET_ERR_ADDR_HI 0x750
333#define TARGET_ERR_ADDR_HI__VALUE 0xffff
334
335#define CHNL_ACTIVE 0x760
336#define CHNL_ACTIVE__CHANNEL0 0x0001
337#define CHNL_ACTIVE__CHANNEL1 0x0002
338#define CHNL_ACTIVE__CHANNEL2 0x0004
339#define CHNL_ACTIVE__CHANNEL3 0x0008
340
341#define FLASH_BURST_LENGTH 0x770
342
343#define ACTIVE_SRC_ID 0x800
344#define ACTIVE_SRC_ID__VALUE 0x00ff
345
346#define PTN_INTR 0x810
347#define PTN_INTR__CONFIG_ERROR 0x0001
348#define PTN_INTR__ACCESS_ERROR_BANK0 0x0002
349#define PTN_INTR__ACCESS_ERROR_BANK1 0x0004
350#define PTN_INTR__ACCESS_ERROR_BANK2 0x0008
351#define PTN_INTR__ACCESS_ERROR_BANK3 0x0010
352#define PTN_INTR__REG_ACCESS_ERROR 0x0020
353
354#define PTN_INTR_EN 0x820
355#define PTN_INTR_EN__CONFIG_ERROR 0x0001
356#define PTN_INTR_EN__ACCESS_ERROR_BANK0 0x0002
357#define PTN_INTR_EN__ACCESS_ERROR_BANK1 0x0004
358#define PTN_INTR_EN__ACCESS_ERROR_BANK2 0x0008
359#define PTN_INTR_EN__ACCESS_ERROR_BANK3 0x0010
360#define PTN_INTR_EN__REG_ACCESS_ERROR 0x0020
361
362#define PERM_SRC_ID(__bank) (0x830 + ((__bank) * 0x40))
363#define PERM_SRC_ID__SRCID 0x00ff
364#define PERM_SRC_ID__DIRECT_ACCESS_ACTIVE 0x0800
365#define PERM_SRC_ID__WRITE_ACTIVE 0x2000
366#define PERM_SRC_ID__READ_ACTIVE 0x4000
367#define PERM_SRC_ID__PARTITION_VALID 0x8000
368
369#define MIN_BLK_ADDR(__bank) (0x840 + ((__bank) * 0x40))
370#define MIN_BLK_ADDR__VALUE 0xffff
371
372#define MAX_BLK_ADDR(__bank) (0x850 + ((__bank) * 0x40))
373#define MAX_BLK_ADDR__VALUE 0xffff
374
375#define MIN_MAX_BANK(__bank) (0x860 + ((__bank) * 0x40))
376#define MIN_MAX_BANK__MIN_VALUE 0x0003
377#define MIN_MAX_BANK__MAX_VALUE 0x000c
378
379
380/* ffsdefs.h */
381#define CLEAR 0 /*use this to clear a field instead of "fail"*/
382#define SET 1 /*use this to set a field instead of "pass"*/
383#define FAIL 1 /*failed flag*/
384#define PASS 0 /*success flag*/
385#define ERR -1 /*error flag*/
386
387/* lld.h */
388#define GOOD_BLOCK 0
389#define DEFECTIVE_BLOCK 1
390#define READ_ERROR 2
391
392#define CLK_X 5
393#define CLK_MULTI 4
394
395/* spectraswconfig.h */
396#define CMD_DMA 0
397
398#define SPECTRA_PARTITION_ID 0
399/**** Block Table and Reserved Block Parameters *****/
400#define SPECTRA_START_BLOCK 3
401#define NUM_FREE_BLOCKS_GATE 30
402
403/* KBV - Updated to LNW scratch register address */
404#define SCRATCH_REG_ADDR CONFIG_MTD_NAND_DENALI_SCRATCH_REG_ADDR
405#define SCRATCH_REG_SIZE 64
406
407#define GLOB_HWCTL_DEFAULT_BLKS 2048
408
409#define SUPPORT_15BITECC 1
410#define SUPPORT_8BITECC 1
411
412#define CUSTOM_CONF_PARAMS 0
413
414#define ONFI_BLOOM_TIME 1
415#define MODE5_WORKAROUND 0
416
417/* lld_nand.h */
418/*
419 * NAND Flash Controller Device Driver
420 * Copyright (c) 2009, Intel Corporation and its suppliers.
421 *
422 * This program is free software; you can redistribute it and/or modify it
423 * under the terms and conditions of the GNU General Public License,
424 * version 2, as published by the Free Software Foundation.
425 *
426 * This program is distributed in the hope it will be useful, but WITHOUT
427 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
428 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
429 * more details.
430 *
431 * You should have received a copy of the GNU General Public License along with
432 * this program; if not, write to the Free Software Foundation, Inc.,
433 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
434 *
435 */
436
437#ifndef _LLD_NAND_
438#define _LLD_NAND_
439
440#define MODE_00 0x00000000
441#define MODE_01 0x04000000
442#define MODE_10 0x08000000
443#define MODE_11 0x0C000000
444
445
446#define DATA_TRANSFER_MODE 0
447#define PROTECTION_PER_BLOCK 1
448#define LOAD_WAIT_COUNT 2
449#define PROGRAM_WAIT_COUNT 3
450#define ERASE_WAIT_COUNT 4
451#define INT_MONITOR_CYCLE_COUNT 5
452#define READ_BUSY_PIN_ENABLED 6
453#define MULTIPLANE_OPERATION_SUPPORT 7
454#define PRE_FETCH_MODE 8
455#define CE_DONT_CARE_SUPPORT 9
456#define COPYBACK_SUPPORT 10
457#define CACHE_WRITE_SUPPORT 11
458#define CACHE_READ_SUPPORT 12
459#define NUM_PAGES_IN_BLOCK 13
460#define ECC_ENABLE_SELECT 14
461#define WRITE_ENABLE_2_READ_ENABLE 15
462#define ADDRESS_2_DATA 16
463#define READ_ENABLE_2_WRITE_ENABLE 17
464#define TWO_ROW_ADDRESS_CYCLES 18
465#define MULTIPLANE_ADDRESS_RESTRICT 19
466#define ACC_CLOCKS 20
467#define READ_WRITE_ENABLE_LOW_COUNT 21
468#define READ_WRITE_ENABLE_HIGH_COUNT 22
469
470#define ECC_SECTOR_SIZE 512
471
472#define DENALI_BUF_SIZE (NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE)
473
474struct nand_buf {
475 int head;
476 int tail;
477 uint8_t buf[DENALI_BUF_SIZE];
478 dma_addr_t dma_buf;
479};
480
481#define INTEL_CE4100 1
482#define INTEL_MRST 2
483#define ZX7510 3
484
485struct denali_nand_info {
486 struct mtd_info mtd;
487 struct nand_chip nand;
488 int flash_bank; /* currently selected chip */
489 int status;
490 int platform;
491 struct nand_buf buf;
492 struct device *dev;
493 int total_used_banks;
494 uint32_t block; /* stored for future use */
495 //uint16_t page;
496 uint32_t page;
497 void __iomem *flash_reg; /* Mapped io reg base address */
498 void __iomem *flash_mem; /* Mapped io reg base address */
499
500 /* elements used by ISR */
501 struct completion complete;
502 spinlock_t irq_lock;
503 uint32_t irq_status;
504 int irq_debug_array[32];
505 int idx;
506 int irq;
507
508 uint32_t devnum; /* represent how many nands connected */
509 uint32_t fwblks; /* represent how many blocks FW used */
510 uint32_t totalblks;
511 uint32_t blksperchip;
512 uint32_t bbtskipbytes;
513 uint32_t max_banks;
514};
515
516void denali_nand_lock(struct mtd_info *mtd);
517void denali_nand_unlock(struct mtd_info *mtd);
518
519#endif /*_LLD_NAND_*/