2 * NAND Flash Controller Device Driver
3 * Copyright (c) 2009, 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.
21 #include <linux/slab.h>
30 u32 valid_banks
[MAX_CHANS
];
34 #define GLOB_LLD_PAGES 64
35 #define GLOB_LLD_PAGE_SIZE (512+16)
36 #define GLOB_LLD_PAGE_DATA_SIZE 512
37 #define GLOB_LLD_BLOCKS 2048
39 #if FLASH_EMU /* This is for entire module */
41 static u8
*flash_memory
[GLOB_LLD_BLOCKS
* GLOB_LLD_PAGES
];
43 /* Read nand emu file and then fill it's content to flash_memory */
44 int emu_load_file_to_mem(void)
47 struct file
*nef_filp
= NULL
;
48 struct inode
*inode
= NULL
;
50 loff_t tmp_file_offset
, file_offset
;
54 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
55 __FILE__
, __LINE__
, __func__
);
60 nef_filp
= filp_open("/root/nand_emu_file", O_RDWR
| O_LARGEFILE
, 0);
61 if (IS_ERR(nef_filp
)) {
62 printk(KERN_ERR
"filp_open error: "
63 "Unable to open nand emu file!\n");
64 return PTR_ERR(nef_filp
);
67 if (nef_filp
->f_path
.dentry
) {
68 inode
= nef_filp
->f_path
.dentry
->d_inode
;
70 printk(KERN_ERR
"Can not get valid inode!\n");
74 nef_size
= i_size_read(inode
->i_mapping
->host
);
76 printk(KERN_ERR
"Invalid nand emu file size: "
77 "0x%llx\n", nef_size
);
80 nand_dbg_print(NAND_DBG_DEBUG
, "nand emu file size: %lld\n",
85 for (i
= 0; i
< GLOB_LLD_BLOCKS
* GLOB_LLD_PAGES
; i
++) {
86 tmp_file_offset
= file_offset
;
87 nread
= vfs_read(nef_filp
,
88 (char __user
*)flash_memory
[i
],
89 GLOB_LLD_PAGE_SIZE
, &tmp_file_offset
);
90 if (nread
< GLOB_LLD_PAGE_SIZE
) {
91 printk(KERN_ERR
"%s, Line %d - "
92 "nand emu file partial read: "
93 "%d bytes\n", __FILE__
, __LINE__
, (int)nread
);
96 file_offset
+= GLOB_LLD_PAGE_SIZE
;
101 filp_close(nef_filp
, current
->files
);
106 /* Write contents of flash_memory to nand emu file */
107 int emu_write_mem_to_file(void)
110 struct file
*nef_filp
= NULL
;
111 struct inode
*inode
= NULL
;
113 loff_t tmp_file_offset
, file_offset
;
117 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
118 __FILE__
, __LINE__
, __func__
);
123 nef_filp
= filp_open("/root/nand_emu_file", O_RDWR
| O_LARGEFILE
, 0);
124 if (IS_ERR(nef_filp
)) {
125 printk(KERN_ERR
"filp_open error: "
126 "Unable to open nand emu file!\n");
127 return PTR_ERR(nef_filp
);
130 if (nef_filp
->f_path
.dentry
) {
131 inode
= nef_filp
->f_path
.dentry
->d_inode
;
133 printk(KERN_ERR
"Invalid " "nef_filp->f_path.dentry value!\n");
137 nef_size
= i_size_read(inode
->i_mapping
->host
);
139 printk(KERN_ERR
"Invalid "
140 "nand emu file size: 0x%llx\n", nef_size
);
143 nand_dbg_print(NAND_DBG_DEBUG
, "nand emu file size: "
148 for (i
= 0; i
< GLOB_LLD_BLOCKS
* GLOB_LLD_PAGES
; i
++) {
149 tmp_file_offset
= file_offset
;
150 nwritten
= vfs_write(nef_filp
,
151 (char __user
*)flash_memory
[i
],
152 GLOB_LLD_PAGE_SIZE
, &tmp_file_offset
);
153 if (nwritten
< GLOB_LLD_PAGE_SIZE
) {
154 printk(KERN_ERR
"%s, Line %d - "
155 "nand emu file partial write: "
156 "%d bytes\n", __FILE__
, __LINE__
, (int)nwritten
);
159 file_offset
+= GLOB_LLD_PAGE_SIZE
;
164 filp_close(nef_filp
, current
->files
);
169 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
170 * Function: emu_Flash_Init
172 * Outputs: PASS=0 (notice 0=ok here)
173 * Description: Creates & initializes the flash RAM array.
175 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
176 u16
emu_Flash_Init(void)
180 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
181 __FILE__
, __LINE__
, __func__
);
183 flash_memory
[0] = vmalloc(GLOB_LLD_PAGE_SIZE
* GLOB_LLD_BLOCKS
*
184 GLOB_LLD_PAGES
* sizeof(u8
));
185 if (!flash_memory
[0]) {
186 printk(KERN_ERR
"Fail to allocate memory "
187 "for nand emulator!\n");
191 memset((char *)(flash_memory
[0]), 0xFF,
192 GLOB_LLD_PAGE_SIZE
* GLOB_LLD_BLOCKS
* GLOB_LLD_PAGES
*
195 for (i
= 1; i
< GLOB_LLD_BLOCKS
* GLOB_LLD_PAGES
; i
++)
196 flash_memory
[i
] = flash_memory
[i
- 1] + GLOB_LLD_PAGE_SIZE
;
198 emu_load_file_to_mem(); /* Load nand emu file to mem */
203 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
204 * Function: emu_Flash_Release
206 * Outputs: PASS=0 (notice 0=ok here)
207 * Description: Releases the flash.
209 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
210 int emu_Flash_Release(void)
212 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
213 __FILE__
, __LINE__
, __func__
);
215 emu_write_mem_to_file(); /* Write back mem to nand emu file */
217 vfree(flash_memory
[0]);
221 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
222 * Function: emu_Read_Device_ID
224 * Outputs: PASS=1 FAIL=0
225 * Description: Reads the info from the controller registers.
226 * Sets up DeviceInfo structure with device parameters
227 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
229 u16
emu_Read_Device_ID(void)
231 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
232 __FILE__
, __LINE__
, __func__
);
234 DeviceInfo
.wDeviceMaker
= 0;
235 DeviceInfo
.wDeviceType
= 8;
236 DeviceInfo
.wSpectraStartBlock
= 36;
237 DeviceInfo
.wSpectraEndBlock
= GLOB_LLD_BLOCKS
- 1;
238 DeviceInfo
.wTotalBlocks
= GLOB_LLD_BLOCKS
;
239 DeviceInfo
.wPagesPerBlock
= GLOB_LLD_PAGES
;
240 DeviceInfo
.wPageSize
= GLOB_LLD_PAGE_SIZE
;
241 DeviceInfo
.wPageDataSize
= GLOB_LLD_PAGE_DATA_SIZE
;
242 DeviceInfo
.wPageSpareSize
= GLOB_LLD_PAGE_SIZE
-
243 GLOB_LLD_PAGE_DATA_SIZE
;
244 DeviceInfo
.wBlockSize
= DeviceInfo
.wPageSize
* GLOB_LLD_PAGES
;
245 DeviceInfo
.wBlockDataSize
= DeviceInfo
.wPageDataSize
* GLOB_LLD_PAGES
;
246 DeviceInfo
.wDataBlockNum
= (u32
) (DeviceInfo
.wSpectraEndBlock
-
247 DeviceInfo
.wSpectraStartBlock
249 DeviceInfo
.MLCDevice
= 1; /* Emulate MLC device */
250 DeviceInfo
.nBitsInPageNumber
=
251 (u8
)GLOB_Calc_Used_Bits(DeviceInfo
.wPagesPerBlock
);
252 DeviceInfo
.nBitsInPageDataSize
=
253 (u8
)GLOB_Calc_Used_Bits(DeviceInfo
.wPageDataSize
);
254 DeviceInfo
.nBitsInBlockDataSize
=
255 (u8
)GLOB_Calc_Used_Bits(DeviceInfo
.wBlockDataSize
);
268 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
269 * Function: emu_Flash_Reset
271 * Outputs: PASS=0 (notice 0=ok here)
272 * Description: Reset the flash
274 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
275 u16
emu_Flash_Reset(void)
277 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
278 __FILE__
, __LINE__
, __func__
);
283 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
284 * Function: emu_Erase_Block
286 * Outputs: PASS=0 (notice 0=ok here)
287 * Description: Erase a block
289 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
290 u16
emu_Erase_Block(u32 block_add
)
294 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
295 __FILE__
, __LINE__
, __func__
);
297 if (block_add
>= DeviceInfo
.wTotalBlocks
) {
298 printk(KERN_ERR
"emu_Erase_Block error! "
299 "Too big block address: %d\n", block_add
);
303 nand_dbg_print(NAND_DBG_DEBUG
, "Erasing block %d\n",
306 for (i
= block_add
* GLOB_LLD_PAGES
;
307 i
< ((block_add
+ 1) * GLOB_LLD_PAGES
); i
++) {
308 if (flash_memory
[i
]) {
309 memset((u8
*)(flash_memory
[i
]), 0xFF,
310 DeviceInfo
.wPageSize
* sizeof(u8
));
317 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
318 * Function: emu_Write_Page_Main
319 * Inputs: Write buffer address pointer
322 * Number of pages to process
323 * Outputs: PASS=0 (notice 0=ok here)
324 * Description: Write the data in the buffer to main area of flash
326 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
327 u16
emu_Write_Page_Main(u8
*write_data
, u32 Block
,
328 u16 Page
, u16 PageCount
)
332 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
333 __FILE__
, __LINE__
, __func__
);
335 if (Block
>= DeviceInfo
.wTotalBlocks
)
338 if (Page
+ PageCount
> DeviceInfo
.wPagesPerBlock
)
341 nand_dbg_print(NAND_DBG_DEBUG
, "emu_Write_Page_Main: "
342 "lba %u Page %u PageCount %u\n",
344 (unsigned int)Page
, (unsigned int)PageCount
);
346 for (i
= 0; i
< PageCount
; i
++) {
347 if (NULL
== flash_memory
[Block
* GLOB_LLD_PAGES
+ Page
]) {
348 printk(KERN_ERR
"Run out of memory\n");
351 memcpy((u8
*) (flash_memory
[Block
* GLOB_LLD_PAGES
+ Page
]),
352 write_data
, DeviceInfo
.wPageDataSize
);
353 write_data
+= DeviceInfo
.wPageDataSize
;
360 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
361 * Function: emu_Read_Page_Main
362 * Inputs: Read buffer address pointer
365 * Number of pages to process
366 * Outputs: PASS=0 (notice 0=ok here)
367 * Description: Read the data from the flash main area to the buffer
369 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
370 u16
emu_Read_Page_Main(u8
*read_data
, u32 Block
,
371 u16 Page
, u16 PageCount
)
375 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
376 __FILE__
, __LINE__
, __func__
);
378 if (Block
>= DeviceInfo
.wTotalBlocks
)
381 if (Page
+ PageCount
> DeviceInfo
.wPagesPerBlock
)
384 nand_dbg_print(NAND_DBG_DEBUG
, "emu_Read_Page_Main: "
385 "lba %u Page %u PageCount %u\n",
387 (unsigned int)Page
, (unsigned int)PageCount
);
389 for (i
= 0; i
< PageCount
; i
++) {
390 if (NULL
== flash_memory
[Block
* GLOB_LLD_PAGES
+ Page
]) {
391 memset(read_data
, 0xFF, DeviceInfo
.wPageDataSize
);
394 (u8
*) (flash_memory
[Block
* GLOB_LLD_PAGES
396 DeviceInfo
.wPageDataSize
);
398 read_data
+= DeviceInfo
.wPageDataSize
;
406 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
407 * Function: emu_Read_Page_Main_Spare
408 * Inputs: Write Buffer
411 * Outputs: PASS=0 (notice 0=ok here)
412 * Description: Read from flash main+spare area
414 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
415 u16
emu_Read_Page_Main_Spare(u8
*read_data
, u32 Block
,
416 u16 Page
, u16 PageCount
)
420 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
421 __FILE__
, __LINE__
, __func__
);
423 if (Block
>= DeviceInfo
.wTotalBlocks
) {
424 printk(KERN_ERR
"Read Page Main+Spare "
425 "Error: Block Address too big\n");
429 if (Page
+ PageCount
> DeviceInfo
.wPagesPerBlock
) {
430 printk(KERN_ERR
"Read Page Main+Spare "
431 "Error: Page number too big\n");
435 nand_dbg_print(NAND_DBG_DEBUG
, "Read Page Main + Spare - "
436 "No. of pages %u block %u start page %u\n",
437 (unsigned int)PageCount
,
438 (unsigned int)Block
, (unsigned int)Page
);
440 for (i
= 0; i
< PageCount
; i
++) {
441 if (NULL
== flash_memory
[Block
* GLOB_LLD_PAGES
+ Page
]) {
442 memset(read_data
, 0xFF, DeviceInfo
.wPageSize
);
444 memcpy(read_data
, (u8
*) (flash_memory
[Block
*
447 DeviceInfo
.wPageSize
);
450 read_data
+= DeviceInfo
.wPageSize
;
457 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
458 * Function: emu_Write_Page_Main_Spare
459 * Inputs: Write buffer
462 * Outputs: PASS=0 (notice 0=ok here)
463 * Description: Write the buffer to main+spare area of flash
465 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
466 u16
emu_Write_Page_Main_Spare(u8
*write_data
, u32 Block
,
467 u16 Page
, u16 page_count
)
471 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
472 __FILE__
, __LINE__
, __func__
);
474 if (Block
>= DeviceInfo
.wTotalBlocks
) {
475 printk(KERN_ERR
"Write Page Main + Spare "
476 "Error: Block Address too big\n");
480 if (Page
+ page_count
> DeviceInfo
.wPagesPerBlock
) {
481 printk(KERN_ERR
"Write Page Main + Spare "
482 "Error: Page number too big\n");
486 nand_dbg_print(NAND_DBG_DEBUG
, "Write Page Main+Spare - "
487 "No. of pages %u block %u start page %u\n",
488 (unsigned int)page_count
,
489 (unsigned int)Block
, (unsigned int)Page
);
491 for (i
= 0; i
< page_count
; i
++) {
492 if (NULL
== flash_memory
[Block
* GLOB_LLD_PAGES
+ Page
]) {
493 printk(KERN_ERR
"Run out of memory!\n");
496 memcpy((u8
*) (flash_memory
[Block
* GLOB_LLD_PAGES
+ Page
]),
497 write_data
, DeviceInfo
.wPageSize
);
498 write_data
+= DeviceInfo
.wPageSize
;
505 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
506 * Function: emu_Write_Page_Spare
507 * Inputs: Write buffer
510 * Outputs: PASS=0 (notice 0=ok here)
511 * Description: Write the buffer in the spare area
513 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
514 u16
emu_Write_Page_Spare(u8
*write_data
, u32 Block
,
515 u16 Page
, u16 PageCount
)
517 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
518 __FILE__
, __LINE__
, __func__
);
520 if (Block
>= DeviceInfo
.wTotalBlocks
) {
521 printk(KERN_ERR
"Read Page Spare Error: "
522 "Block Address too big\n");
526 if (Page
+ PageCount
> DeviceInfo
.wPagesPerBlock
) {
527 printk(KERN_ERR
"Read Page Spare Error: "
528 "Page number too big\n");
532 nand_dbg_print(NAND_DBG_DEBUG
, "Write Page Spare- "
533 "block %u page %u\n",
534 (unsigned int)Block
, (unsigned int)Page
);
536 if (NULL
== flash_memory
[Block
* GLOB_LLD_PAGES
+ Page
]) {
537 printk(KERN_ERR
"Run out of memory!\n");
541 memcpy((u8
*) (flash_memory
[Block
* GLOB_LLD_PAGES
+ Page
] +
542 DeviceInfo
.wPageDataSize
), write_data
,
543 (DeviceInfo
.wPageSize
- DeviceInfo
.wPageDataSize
));
548 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
549 * Function: emu_Read_Page_Spare
550 * Inputs: Write Buffer
553 * Outputs: PASS=0 (notice 0=ok here)
554 * Description: Read data from the spare area
556 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
557 u16
emu_Read_Page_Spare(u8
*write_data
, u32 Block
,
558 u16 Page
, u16 PageCount
)
560 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
561 __FILE__
, __LINE__
, __func__
);
563 if (Block
>= DeviceInfo
.wTotalBlocks
) {
564 printk(KERN_ERR
"Read Page Spare "
565 "Error: Block Address too big\n");
569 if (Page
+ PageCount
> DeviceInfo
.wPagesPerBlock
) {
570 printk(KERN_ERR
"Read Page Spare "
571 "Error: Page number too big\n");
575 nand_dbg_print(NAND_DBG_DEBUG
, "Read Page Spare- "
576 "block %u page %u\n",
577 (unsigned int)Block
, (unsigned int)Page
);
579 if (NULL
== flash_memory
[Block
* GLOB_LLD_PAGES
+ Page
]) {
580 memset(write_data
, 0xFF,
581 (DeviceInfo
.wPageSize
- DeviceInfo
.wPageDataSize
));
584 (u8
*) (flash_memory
[Block
* GLOB_LLD_PAGES
+ Page
]
585 + DeviceInfo
.wPageDataSize
),
586 (DeviceInfo
.wPageSize
- DeviceInfo
.wPageDataSize
));
592 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
593 * Function: emu_Enable_Disable_Interrupts
594 * Inputs: enable or disable
597 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
598 void emu_Enable_Disable_Interrupts(u16 INT_ENABLE
)
600 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
601 __FILE__
, __LINE__
, __func__
);
604 u16
emu_Get_Bad_Block(u32 block
)
610 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
611 * Support for CDMA functions
612 ************************************
613 * emu_CDMA_Flash_Init
614 * CDMA_process_data command (use LLD_CDMA)
615 * CDMA_MemCopy_CMD (use LLD_CDMA)
616 * emu_CDMA_execute all commands
617 * emu_CDMA_Event_Status
618 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
619 u16
emu_CDMA_Flash_Init(void)
623 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
624 __FILE__
, __LINE__
, __func__
);
626 for (i
= 0; i
< MAX_DESCS
+ MAX_CHANS
; i
++) {
627 PendingCMD
[i
].CMD
= 0;
628 PendingCMD
[i
].Tag
= 0;
629 PendingCMD
[i
].DataAddr
= 0;
630 PendingCMD
[i
].Block
= 0;
631 PendingCMD
[i
].Page
= 0;
632 PendingCMD
[i
].PageCount
= 0;
633 PendingCMD
[i
].DataDestAddr
= 0;
634 PendingCMD
[i
].DataSrcAddr
= 0;
635 PendingCMD
[i
].MemCopyByteCnt
= 0;
636 PendingCMD
[i
].ChanSync
[0] = 0;
637 PendingCMD
[i
].ChanSync
[1] = 0;
638 PendingCMD
[i
].ChanSync
[2] = 0;
639 PendingCMD
[i
].ChanSync
[3] = 0;
640 PendingCMD
[i
].ChanSync
[4] = 0;
641 PendingCMD
[i
].Status
= 3;
647 static void emu_isr(int irq
, void *dev_id
)
652 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
653 * Function: CDMA_Execute_CMDs
654 * Inputs: tag_count: the number of pending cmds to do
656 * Description: execute each command in the pending CMD array
657 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
658 u16
emu_CDMA_Execute_CMDs(u16 tag_count
)
661 u8 CMD
; /* cmd parameter */
668 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
669 __FILE__
, __LINE__
, __func__
);
671 nand_dbg_print(NAND_DBG_TRACE
, "At start of Execute CMDs: "
672 "Tag Count %u\n", tag_count
);
674 for (i
= 0; i
< totalUsedBanks
; i
++) {
675 PendingCMD
[i
].CMD
= DUMMY_CMD
;
676 PendingCMD
[i
].Tag
= 0xFF;
677 PendingCMD
[i
].Block
=
678 (DeviceInfo
.wTotalBlocks
/ totalUsedBanks
) * i
;
680 for (j
= 0; j
<= MAX_CHANS
; j
++)
681 PendingCMD
[i
].ChanSync
[j
] = 0;
684 CDMA_Execute_CMDs(tag_count
);
686 print_pending_cmds(tag_count
);
694 i
< tag_count
+ MAX_CHANS
; i
++) {
695 CMD
= PendingCMD
[i
].CMD
;
696 data
= PendingCMD
[i
].DataAddr
;
697 block
= PendingCMD
[i
].Block
;
698 page
= PendingCMD
[i
].Page
;
699 count
= PendingCMD
[i
].PageCount
;
703 emu_Erase_Block(block
);
704 PendingCMD
[i
].Status
= PASS
;
707 emu_Write_Page_Main(data
, block
, page
, count
);
708 PendingCMD
[i
].Status
= PASS
;
710 case WRITE_MAIN_SPARE_CMD
:
711 emu_Write_Page_Main_Spare(data
, block
, page
, count
);
712 PendingCMD
[i
].Status
= PASS
;
715 emu_Read_Page_Main(data
, block
, page
, count
);
716 PendingCMD
[i
].Status
= PASS
;
719 memcpy(PendingCMD
[i
].DataDestAddr
,
720 PendingCMD
[i
].DataSrcAddr
,
721 PendingCMD
[i
].MemCopyByteCnt
);
723 PendingCMD
[i
].Status
= PASS
;
726 PendingCMD
[i
].Status
= FAIL
;
732 * Temperory adding code to reset PendingCMD array for basic testing.
733 * It should be done at the end of event status function.
735 for (i
= tag_count
+ MAX_CHANS
; i
< MAX_DESCS
; i
++) {
736 PendingCMD
[i
].CMD
= 0;
737 PendingCMD
[i
].Tag
= 0;
738 PendingCMD
[i
].DataAddr
= 0;
739 PendingCMD
[i
].Block
= 0;
740 PendingCMD
[i
].Page
= 0;
741 PendingCMD
[i
].PageCount
= 0;
742 PendingCMD
[i
].DataDestAddr
= 0;
743 PendingCMD
[i
].DataSrcAddr
= 0;
744 PendingCMD
[i
].MemCopyByteCnt
= 0;
745 PendingCMD
[i
].ChanSync
[0] = 0;
746 PendingCMD
[i
].ChanSync
[1] = 0;
747 PendingCMD
[i
].ChanSync
[2] = 0;
748 PendingCMD
[i
].ChanSync
[3] = 0;
749 PendingCMD
[i
].ChanSync
[4] = 0;
750 PendingCMD
[i
].Status
= CMD_NOT_DONE
;
753 nand_dbg_print(NAND_DBG_TRACE
, "At end of Execute CMDs.\n");
755 emu_isr(0, 0); /* This is a null isr now. Need fill it in future */
760 /*&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
761 * Function: emu_Event_Status
763 * Outputs: Event_Status code
764 * Description: This function can also be used to force errors
765 *&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&*/
766 u16
emu_CDMA_Event_Status(void)
768 nand_dbg_print(NAND_DBG_TRACE
, "%s, Line %d, Function: %s\n",
769 __FILE__
, __LINE__
, __func__
);
776 #endif /* FLASH_EMU */