2 * NAND Flash Controller Device Driver
3 * Copyright (c) 2009 - 2010, Intel Corporation and its suppliers.
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.
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
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.
23 #include <linux/mtd/nand.h>
25 #define DEVICE_RESET 0x0
26 #define DEVICE_RESET__BANK0 0x0001
27 #define DEVICE_RESET__BANK1 0x0002
28 #define DEVICE_RESET__BANK2 0x0004
29 #define DEVICE_RESET__BANK3 0x0008
31 #define TRANSFER_SPARE_REG 0x10
32 #define TRANSFER_SPARE_REG__FLAG 0x0001
34 #define LOAD_WAIT_CNT 0x20
35 #define LOAD_WAIT_CNT__VALUE 0xffff
37 #define PROGRAM_WAIT_CNT 0x30
38 #define PROGRAM_WAIT_CNT__VALUE 0xffff
40 #define ERASE_WAIT_CNT 0x40
41 #define ERASE_WAIT_CNT__VALUE 0xffff
43 #define INT_MON_CYCCNT 0x50
44 #define INT_MON_CYCCNT__VALUE 0xffff
46 #define RB_PIN_ENABLED 0x60
47 #define RB_PIN_ENABLED__BANK0 0x0001
48 #define RB_PIN_ENABLED__BANK1 0x0002
49 #define RB_PIN_ENABLED__BANK2 0x0004
50 #define RB_PIN_ENABLED__BANK3 0x0008
52 #define MULTIPLANE_OPERATION 0x70
53 #define MULTIPLANE_OPERATION__FLAG 0x0001
55 #define MULTIPLANE_READ_ENABLE 0x80
56 #define MULTIPLANE_READ_ENABLE__FLAG 0x0001
58 #define COPYBACK_DISABLE 0x90
59 #define COPYBACK_DISABLE__FLAG 0x0001
61 #define CACHE_WRITE_ENABLE 0xa0
62 #define CACHE_WRITE_ENABLE__FLAG 0x0001
64 #define CACHE_READ_ENABLE 0xb0
65 #define CACHE_READ_ENABLE__FLAG 0x0001
67 #define PREFETCH_MODE 0xc0
68 #define PREFETCH_MODE__PREFETCH_EN 0x0001
69 #define PREFETCH_MODE__PREFETCH_BURST_LENGTH 0xfff0
71 #define CHIP_ENABLE_DONT_CARE 0xd0
72 #define CHIP_EN_DONT_CARE__FLAG 0x01
74 #define ECC_ENABLE 0xe0
75 #define ECC_ENABLE__FLAG 0x0001
77 #define GLOBAL_INT_ENABLE 0xf0
78 #define GLOBAL_INT_EN_FLAG 0x01
81 #define WE_2_RE__VALUE 0x003f
83 #define ADDR_2_DATA 0x110
84 #define ADDR_2_DATA__VALUE 0x003f
87 #define RE_2_WE__VALUE 0x003f
89 #define ACC_CLKS 0x130
90 #define ACC_CLKS__VALUE 0x000f
92 #define NUMBER_OF_PLANES 0x140
93 #define NUMBER_OF_PLANES__VALUE 0x0007
95 #define PAGES_PER_BLOCK 0x150
96 #define PAGES_PER_BLOCK__VALUE 0xffff
98 #define DEVICE_WIDTH 0x160
99 #define DEVICE_WIDTH__VALUE 0x0003
101 #define DEVICE_MAIN_AREA_SIZE 0x170
102 #define DEVICE_MAIN_AREA_SIZE__VALUE 0xffff
104 #define DEVICE_SPARE_AREA_SIZE 0x180
105 #define DEVICE_SPARE_AREA_SIZE__VALUE 0xffff
107 #define TWO_ROW_ADDR_CYCLES 0x190
108 #define TWO_ROW_ADDR_CYCLES__FLAG 0x0001
110 #define MULTIPLANE_ADDR_RESTRICT 0x1a0
111 #define MULTIPLANE_ADDR_RESTRICT__FLAG 0x0001
113 #define ECC_CORRECTION 0x1b0
114 #define ECC_CORRECTION__VALUE 0x001f
116 #define READ_MODE 0x1c0
117 #define READ_MODE__VALUE 0x000f
119 #define WRITE_MODE 0x1d0
120 #define WRITE_MODE__VALUE 0x000f
122 #define COPYBACK_MODE 0x1e0
123 #define COPYBACK_MODE__VALUE 0x000f
125 #define RDWR_EN_LO_CNT 0x1f0
126 #define RDWR_EN_LO_CNT__VALUE 0x001f
128 #define RDWR_EN_HI_CNT 0x200
129 #define RDWR_EN_HI_CNT__VALUE 0x001f
131 #define MAX_RD_DELAY 0x210
132 #define MAX_RD_DELAY__VALUE 0x000f
134 #define CS_SETUP_CNT 0x220
135 #define CS_SETUP_CNT__VALUE 0x001f
137 #define SPARE_AREA_SKIP_BYTES 0x230
138 #define SPARE_AREA_SKIP_BYTES__VALUE 0x003f
140 #define SPARE_AREA_MARKER 0x240
141 #define SPARE_AREA_MARKER__VALUE 0xffff
143 #define DEVICES_CONNECTED 0x250
144 #define DEVICES_CONNECTED__VALUE 0x0007
146 #define DIE_MASK 0x260
147 #define DIE_MASK__VALUE 0x00ff
149 #define FIRST_BLOCK_OF_NEXT_PLANE 0x270
150 #define FIRST_BLOCK_OF_NEXT_PLANE__VALUE 0xffff
152 #define WRITE_PROTECT 0x280
153 #define WRITE_PROTECT__FLAG 0x0001
155 #define RE_2_RE 0x290
156 #define RE_2_RE__VALUE 0x003f
158 #define MANUFACTURER_ID 0x300
159 #define MANUFACTURER_ID__VALUE 0x00ff
161 #define DEVICE_ID 0x310
162 #define DEVICE_ID__VALUE 0x00ff
164 #define DEVICE_PARAM_0 0x320
165 #define DEVICE_PARAM_0__VALUE 0x00ff
167 #define DEVICE_PARAM_1 0x330
168 #define DEVICE_PARAM_1__VALUE 0x00ff
170 #define DEVICE_PARAM_2 0x340
171 #define DEVICE_PARAM_2__VALUE 0x00ff
173 #define LOGICAL_PAGE_DATA_SIZE 0x350
174 #define LOGICAL_PAGE_DATA_SIZE__VALUE 0xffff
176 #define LOGICAL_PAGE_SPARE_SIZE 0x360
177 #define LOGICAL_PAGE_SPARE_SIZE__VALUE 0xffff
179 #define REVISION 0x370
180 #define REVISION__VALUE 0xffff
182 #define ONFI_DEVICE_FEATURES 0x380
183 #define ONFI_DEVICE_FEATURES__VALUE 0x003f
185 #define ONFI_OPTIONAL_COMMANDS 0x390
186 #define ONFI_OPTIONAL_COMMANDS__VALUE 0x003f
188 #define ONFI_TIMING_MODE 0x3a0
189 #define ONFI_TIMING_MODE__VALUE 0x003f
191 #define ONFI_PGM_CACHE_TIMING_MODE 0x3b0
192 #define ONFI_PGM_CACHE_TIMING_MODE__VALUE 0x003f
194 #define ONFI_DEVICE_NO_OF_LUNS 0x3c0
195 #define ONFI_DEVICE_NO_OF_LUNS__NO_OF_LUNS 0x00ff
196 #define ONFI_DEVICE_NO_OF_LUNS__ONFI_DEVICE 0x0100
198 #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L 0x3d0
199 #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_L__VALUE 0xffff
201 #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U 0x3e0
202 #define ONFI_DEVICE_NO_OF_BLOCKS_PER_LUN_U__VALUE 0xffff
204 #define FEATURES 0x3f0
205 #define FEATURES__N_BANKS 0x0003
206 #define FEATURES__ECC_MAX_ERR 0x003c
207 #define FEATURES__DMA 0x0040
208 #define FEATURES__CMD_DMA 0x0080
209 #define FEATURES__PARTITION 0x0100
210 #define FEATURES__XDMA_SIDEBAND 0x0200
211 #define FEATURES__GPREG 0x0400
212 #define FEATURES__INDEX_ADDR 0x0800
214 #define TRANSFER_MODE 0x400
215 #define TRANSFER_MODE__VALUE 0x0003
217 #define INTR_STATUS(__bank) (0x410 + ((__bank) * 0x50))
218 #define INTR_EN(__bank) (0x420 + ((__bank) * 0x50))
220 #define INTR_STATUS__ECC_TRANSACTION_DONE 0x0001
221 #define INTR_STATUS__ECC_ERR 0x0002
222 #define INTR_STATUS__DMA_CMD_COMP 0x0004
223 #define INTR_STATUS__TIME_OUT 0x0008
224 #define INTR_STATUS__PROGRAM_FAIL 0x0010
225 #define INTR_STATUS__ERASE_FAIL 0x0020
226 #define INTR_STATUS__LOAD_COMP 0x0040
227 #define INTR_STATUS__PROGRAM_COMP 0x0080
228 #define INTR_STATUS__ERASE_COMP 0x0100
229 #define INTR_STATUS__PIPE_CPYBCK_CMD_COMP 0x0200
230 #define INTR_STATUS__LOCKED_BLK 0x0400
231 #define INTR_STATUS__UNSUP_CMD 0x0800
232 #define INTR_STATUS__INT_ACT 0x1000
233 #define INTR_STATUS__RST_COMP 0x2000
234 #define INTR_STATUS__PIPE_CMD_ERR 0x4000
235 #define INTR_STATUS__PAGE_XFER_INC 0x8000
237 #define INTR_EN__ECC_TRANSACTION_DONE 0x0001
238 #define INTR_EN__ECC_ERR 0x0002
239 #define INTR_EN__DMA_CMD_COMP 0x0004
240 #define INTR_EN__TIME_OUT 0x0008
241 #define INTR_EN__PROGRAM_FAIL 0x0010
242 #define INTR_EN__ERASE_FAIL 0x0020
243 #define INTR_EN__LOAD_COMP 0x0040
244 #define INTR_EN__PROGRAM_COMP 0x0080
245 #define INTR_EN__ERASE_COMP 0x0100
246 #define INTR_EN__PIPE_CPYBCK_CMD_COMP 0x0200
247 #define INTR_EN__LOCKED_BLK 0x0400
248 #define INTR_EN__UNSUP_CMD 0x0800
249 #define INTR_EN__INT_ACT 0x1000
250 #define INTR_EN__RST_COMP 0x2000
251 #define INTR_EN__PIPE_CMD_ERR 0x4000
252 #define INTR_EN__PAGE_XFER_INC 0x8000
254 #define PAGE_CNT(__bank) (0x430 + ((__bank) * 0x50))
255 #define ERR_PAGE_ADDR(__bank) (0x440 + ((__bank) * 0x50))
256 #define ERR_BLOCK_ADDR(__bank) (0x450 + ((__bank) * 0x50))
258 #define DATA_INTR 0x550
259 #define DATA_INTR__WRITE_SPACE_AV 0x0001
260 #define DATA_INTR__READ_DATA_AV 0x0002
262 #define DATA_INTR_EN 0x560
263 #define DATA_INTR_EN__WRITE_SPACE_AV 0x0001
264 #define DATA_INTR_EN__READ_DATA_AV 0x0002
266 #define GPREG_0 0x570
267 #define GPREG_0__VALUE 0xffff
269 #define GPREG_1 0x580
270 #define GPREG_1__VALUE 0xffff
272 #define GPREG_2 0x590
273 #define GPREG_2__VALUE 0xffff
275 #define GPREG_3 0x5a0
276 #define GPREG_3__VALUE 0xffff
278 #define ECC_THRESHOLD 0x600
279 #define ECC_THRESHOLD__VALUE 0x03ff
281 #define ECC_ERROR_BLOCK_ADDRESS 0x610
282 #define ECC_ERROR_BLOCK_ADDRESS__VALUE 0xffff
284 #define ECC_ERROR_PAGE_ADDRESS 0x620
285 #define ECC_ERROR_PAGE_ADDRESS__VALUE 0x0fff
286 #define ECC_ERROR_PAGE_ADDRESS__BANK 0xf000
288 #define ECC_ERROR_ADDRESS 0x630
289 #define ECC_ERROR_ADDRESS__OFFSET 0x0fff
290 #define ECC_ERROR_ADDRESS__SECTOR_NR 0xf000
292 #define ERR_CORRECTION_INFO 0x640
293 #define ERR_CORRECTION_INFO__BYTEMASK 0x00ff
294 #define ERR_CORRECTION_INFO__DEVICE_NR 0x0f00
295 #define ERR_CORRECTION_INFO__ERROR_TYPE 0x4000
296 #define ERR_CORRECTION_INFO__LAST_ERR_INFO 0x8000
298 #define DMA_ENABLE 0x700
299 #define DMA_ENABLE__FLAG 0x0001
301 #define IGNORE_ECC_DONE 0x710
302 #define IGNORE_ECC_DONE__FLAG 0x0001
304 #define DMA_INTR 0x720
305 #define DMA_INTR__TARGET_ERROR 0x0001
306 #define DMA_INTR__DESC_COMP_CHANNEL0 0x0002
307 #define DMA_INTR__DESC_COMP_CHANNEL1 0x0004
308 #define DMA_INTR__DESC_COMP_CHANNEL2 0x0008
309 #define DMA_INTR__DESC_COMP_CHANNEL3 0x0010
310 #define DMA_INTR__MEMCOPY_DESC_COMP 0x0020
312 #define DMA_INTR_EN 0x730
313 #define DMA_INTR_EN__TARGET_ERROR 0x0001
314 #define DMA_INTR_EN__DESC_COMP_CHANNEL0 0x0002
315 #define DMA_INTR_EN__DESC_COMP_CHANNEL1 0x0004
316 #define DMA_INTR_EN__DESC_COMP_CHANNEL2 0x0008
317 #define DMA_INTR_EN__DESC_COMP_CHANNEL3 0x0010
318 #define DMA_INTR_EN__MEMCOPY_DESC_COMP 0x0020
320 #define TARGET_ERR_ADDR_LO 0x740
321 #define TARGET_ERR_ADDR_LO__VALUE 0xffff
323 #define TARGET_ERR_ADDR_HI 0x750
324 #define TARGET_ERR_ADDR_HI__VALUE 0xffff
326 #define CHNL_ACTIVE 0x760
327 #define CHNL_ACTIVE__CHANNEL0 0x0001
328 #define CHNL_ACTIVE__CHANNEL1 0x0002
329 #define CHNL_ACTIVE__CHANNEL2 0x0004
330 #define CHNL_ACTIVE__CHANNEL3 0x0008
332 #define ACTIVE_SRC_ID 0x800
333 #define ACTIVE_SRC_ID__VALUE 0x00ff
335 #define PTN_INTR 0x810
336 #define PTN_INTR__CONFIG_ERROR 0x0001
337 #define PTN_INTR__ACCESS_ERROR_BANK0 0x0002
338 #define PTN_INTR__ACCESS_ERROR_BANK1 0x0004
339 #define PTN_INTR__ACCESS_ERROR_BANK2 0x0008
340 #define PTN_INTR__ACCESS_ERROR_BANK3 0x0010
341 #define PTN_INTR__REG_ACCESS_ERROR 0x0020
343 #define PTN_INTR_EN 0x820
344 #define PTN_INTR_EN__CONFIG_ERROR 0x0001
345 #define PTN_INTR_EN__ACCESS_ERROR_BANK0 0x0002
346 #define PTN_INTR_EN__ACCESS_ERROR_BANK1 0x0004
347 #define PTN_INTR_EN__ACCESS_ERROR_BANK2 0x0008
348 #define PTN_INTR_EN__ACCESS_ERROR_BANK3 0x0010
349 #define PTN_INTR_EN__REG_ACCESS_ERROR 0x0020
351 #define PERM_SRC_ID(__bank) (0x830 + ((__bank) * 0x40))
352 #define PERM_SRC_ID__SRCID 0x00ff
353 #define PERM_SRC_ID__DIRECT_ACCESS_ACTIVE 0x0800
354 #define PERM_SRC_ID__WRITE_ACTIVE 0x2000
355 #define PERM_SRC_ID__READ_ACTIVE 0x4000
356 #define PERM_SRC_ID__PARTITION_VALID 0x8000
358 #define MIN_BLK_ADDR(__bank) (0x840 + ((__bank) * 0x40))
359 #define MIN_BLK_ADDR__VALUE 0xffff
361 #define MAX_BLK_ADDR(__bank) (0x850 + ((__bank) * 0x40))
362 #define MAX_BLK_ADDR__VALUE 0xffff
364 #define MIN_MAX_BANK(__bank) (0x860 + ((__bank) * 0x40))
365 #define MIN_MAX_BANK__MIN_VALUE 0x0003
366 #define MIN_MAX_BANK__MAX_VALUE 0x000c
370 #define CLEAR 0 /*use this to clear a field instead of "fail"*/
371 #define SET 1 /*use this to set a field instead of "pass"*/
372 #define FAIL 1 /*failed flag*/
373 #define PASS 0 /*success flag*/
374 #define ERR -1 /*error flag*/
378 #define DEFECTIVE_BLOCK 1
384 /* spectraswconfig.h */
387 #define SPECTRA_PARTITION_ID 0
388 /**** Block Table and Reserved Block Parameters *****/
389 #define SPECTRA_START_BLOCK 3
390 #define NUM_FREE_BLOCKS_GATE 30
392 /* KBV - Updated to LNW scratch register address */
393 #define SCRATCH_REG_ADDR CONFIG_MTD_NAND_DENALI_SCRATCH_REG_ADDR
394 #define SCRATCH_REG_SIZE 64
396 #define GLOB_HWCTL_DEFAULT_BLKS 2048
398 #define SUPPORT_15BITECC 1
399 #define SUPPORT_8BITECC 1
401 #define CUSTOM_CONF_PARAMS 0
403 #define ONFI_BLOOM_TIME 1
404 #define MODE5_WORKAROUND 0
407 #define MODE_00 0x00000000
408 #define MODE_01 0x04000000
409 #define MODE_10 0x08000000
410 #define MODE_11 0x0C000000
413 #define DATA_TRANSFER_MODE 0
414 #define PROTECTION_PER_BLOCK 1
415 #define LOAD_WAIT_COUNT 2
416 #define PROGRAM_WAIT_COUNT 3
417 #define ERASE_WAIT_COUNT 4
418 #define INT_MONITOR_CYCLE_COUNT 5
419 #define READ_BUSY_PIN_ENABLED 6
420 #define MULTIPLANE_OPERATION_SUPPORT 7
421 #define PRE_FETCH_MODE 8
422 #define CE_DONT_CARE_SUPPORT 9
423 #define COPYBACK_SUPPORT 10
424 #define CACHE_WRITE_SUPPORT 11
425 #define CACHE_READ_SUPPORT 12
426 #define NUM_PAGES_IN_BLOCK 13
427 #define ECC_ENABLE_SELECT 14
428 #define WRITE_ENABLE_2_READ_ENABLE 15
429 #define ADDRESS_2_DATA 16
430 #define READ_ENABLE_2_WRITE_ENABLE 17
431 #define TWO_ROW_ADDRESS_CYCLES 18
432 #define MULTIPLANE_ADDRESS_RESTRICT 19
433 #define ACC_CLOCKS 20
434 #define READ_WRITE_ENABLE_LOW_COUNT 21
435 #define READ_WRITE_ENABLE_HIGH_COUNT 22
437 #define ECC_SECTOR_SIZE 512
446 #define INTEL_CE4100 1
450 struct denali_nand_info
{
452 struct nand_chip nand
;
453 int flash_bank
; /* currently selected chip */
458 int total_used_banks
;
459 uint32_t block
; /* stored for future use */
461 void __iomem
*flash_reg
; /* Mapped io reg base address */
462 void __iomem
*flash_mem
; /* Mapped io reg base address */
464 /* elements used by ISR */
465 struct completion complete
;
468 int irq_debug_array
[32];
472 uint32_t devnum
; /* represent how many nands connected */
473 uint32_t fwblks
; /* represent how many blocks FW used */
475 uint32_t blksperchip
;
476 uint32_t bbtskipbytes
;
480 extern int denali_init(struct denali_nand_info
*denali
);
481 extern void denali_remove(struct denali_nand_info
*denali
);
483 #endif /* __DENALI_H__ */