/*
* $Log: P:/user/amir/lite/vcs/nfdc2148.c_v $
*
* Rev 1.23 25 Mar 1998 15:10:00 Andray, Hdei
* Added two parameters, startAddr and endAddr, to windowBaseAddr().
*
* Rev 1.23 23 Sep 1997 18:52:16 danig
* Initialize junk
*
* Rev 1.22 18 Sep 1997 10:12:08 danig
* Warnings
*
* Rev 1.21 10 Sep 1997 16:14:30 danig
* Got rid of generic names
*
* Rev 1.20 08 Sep 1997 18:10:48 danig
* Fixed setAddress for big-endian
*
* Rev 1.19 04 Sep 1997 19:30:40 danig
* Debug messages
*
* Rev 1.18 04 Sep 1997 14:30:58 DIMITRY
* Add Reset in 'windowBase' function +
* Set 0-floor after floor identification
*
* Rev 1.17 04 Sep 1997 10:04:02 DIMITRY
* ECC/EDC in hardware
*
* Rev 1.16 31 Aug 1997 15:02:34 danig
* Registration routine return status
*
* Rev 1.15 28 Aug 1997 16:56:50 danig
* Buffer and remapped per drive
*
* Rev 1.14 31 Jul 1997 14:23:22 danig
* Changed junk and zeroes to be local variables
*
* Rev 1.13 28 Jul 1997 15:33:54 danig
* Moved standard typedefs to flbase.h
*
* Rev 1.12 27 Jul 1997 14:06:14 danig
* FAR -> FAR0, physicalToPointer, no fltimer.h
*
* Rev 1.11 24 Jul 1997 16:42:30 danig
* Reset before Erase ( for Toshiba 8 Mb )
*
* Rev 1.10 21 Jul 1997 18:56:22 danig
* nandBuffer static
*
* Rev 1.9 15 Jul 1997 16:17:40 danig
* Ver 2.0
*
* Rev 1.8 13 Jul 1997 18:08:04 danig
* Initialize totalFloors & floorSize
*
* Rev 1.7 30 Jun 1997 15:00:08 DIMITRY
* Always init MTD with noOfUnits = 0.
*
* Rev 1.6 22 Jun 1997 15:18:16 danig
* No header file, moved page flags to flash.h
*
* Rev 1.5 22 Jun 1997 14:13:04 danig
* Documentation
*
* Rev 1.4 18 Jun 1997 16:25:22 DIMITRY
*
* Rev 1.3 17 Jun 1997 17:22:28 DIMITRY
* Major code reorg + fast Toshiba ( AmirBan )
*
* Rev 1.2 25 May 1997 19:20:24 danig
* Changes in EDC & media size calculation in doc2Erase
*
* Rev 1.1 25 May 1997 14:47:06 danig
* Changed writeOneSector for Toshiba 2M, and fixed noOfBlocks bug
*
* Rev 1.0 20 May 1997 13:11:50 danig
* Initial revision.
*/
/************************************************************************/
/* */
/* FAT-FTL Lite Software Development Kit */
/* Copyright (C) M-Systems Ltd. 1995-1997 */
/* */
/************************************************************************/
#include "flflash.h"
#include "reedsol.h"
/*闈�����������
� Feature list �
������������*/
/* #define MULTI_ERASE */ /* use multiple block erase feature */
/* #define VERIFY_ERASE */ /* read after erase and verify */
/* #define VERIFY_WRITE */ /* read back and verify write */
/* #define WIN_FROM_SS */ /* call Socket Services to get window location */
#define CHIP_ID 0x20
#define BUSY_DELAY 30000
#define EXTRA_LEN 8 /* size of extra area */
#define SYNDROM_BYTES 6 /* Number of syndrom bytes: 5 + 1 parity */
#define PAGES_PER_BLOCK 16 /* 16 pages per block on a single chip */
/* miscellaneous limits */
#define MAX_FLASH_DEVICES 16
#define MAX_FLOORS 4
/* Flash IDs*/
#define KM29N16000_FLASH 0xec64
#define KM29N32000_FLASH 0xece5
#define KM29V64000_FLASH 0xece6
#define KM29V128000_FLASH 0xec73
#define NM29N16_FLASH 0x8f64
#define NM29N32_FLASH 0x8fe5
#define NM29N64_FLASH 0x8fe6
#define TC5816_FLASH 0x9864
#define TC5832_FLASH 0x98e5
#define TC5864_FLASH 0x98e6
/* Flash commands */
#define SERIAL_DATA_INPUT 0x80
#define READ_MODE 0x00
#define READ_MODE_2 0x50
#define RESET_FLASH 0xff
#define SETUP_WRITE 0x10
#define SETUP_ERASE 0x60
#define CONFIRM_ERASE 0xd0
#define READ_STATUS 0x70
#define READ_ID 0x90
#define SUSPEND_ERASE 0xb0
#define REGISTER_READ 0xe0
/* commands for moving flash pointer to areeas A,B or C of page */
typedef enum { AREA_A = READ_MODE, AREA_B = 0x1, AREA_C = READ_MODE_2 } PointerOp;
#define FAIL 0x01 /* error in block erase */
/*闈�����������������鱷
� Definition for writing boot image �
�������������������*/
#define SPL_SIZE 0x2000 /* 8 KBytes */
#define MAX_CODE_MODULES 6 /* max number of code modules in boot area (incl. SPL) */
/*闈��������������������
� Definition of DOC 2000 memory window �
���������������������*/
/*
DOC 2000 memory window layout :
0000 .... 003F IPL ROM ( part 1 )
0040 .... 07FF (aliased 20H times)
0800 .... 083F IPL ROM ( part 2 )
0840 .... 0FFF (aliased 20H times)
1000 Chip Id
1001 DOC_Status_reg
1002 DOC_Control_reg
1003 ASIC_Control_reg
CDSN window -----> 1004 CDSN_Control_reg
1005 CDSN_Device_Selector
1006 ECC_Config_reg
1007 ECC_Status_reg
1008 .... 100C Test registers [5]
100D CDSN_Slow_IO_reg
100E .... 100F reserved ( 2 bytes )
1010 .... 1015 ECC_Syndrom [6]
1016 .... 17FF reserved ( 2027 bytes )
1800 .... 1FFF CDSN_IO (aliased 800H times)
*/
typedef struct /* represents DOC 2000 memory window */
{
unsigned char IPLpart1[0x800] ; /* read not used here */
unsigned char IPLpart2[0x800] ; /* read not used here */
volatile unsigned char chipId ; /* read */
volatile unsigned char DOCstatus ; /* read */
volatile unsigned char DOCcontrol ; /* write */
volatile unsigned char ASICselect ; /* read write */
volatile unsigned char signals ; /* read write */
volatile unsigned char deviceSelector ; /* read write */
volatile unsigned char ECCconfig ; /* write */
volatile unsigned char ECCstatus ; /* read */
volatile unsigned char test[5] ; /* not used here */
volatile unsigned char slowIO ; /* read write */
unsigned char filler1[2] ; /* -- -- */
volatile unsigned char syndrom[6] ; /* read */
unsigned char filler2[0x800 - 0x16] ; /* -- -- */
volatile unsigned char io[0x800] ; /* read write */
} DOC2window;
/* bits for writing to DOC2window.DOCcontrol reg */
#define ASIC_NORMAL_MODE 0x85
#define ASIC_RESET_MODE 0
/* bits for writing to DOC2window.signals ( CDSN_Control reg ) */
#define CE 0x01 /* 1 - Chip Enable */
#define CLE 0x02 /* 1 - Command Latch Enable */
#define ALE 0x04 /* 1 - Address Latch Enable */
#define WP 0x08 /* 1 - Write-Protect flash */
#define FLASH_IO 0x10
#define ECC_IO 0x20 /* 1 - turn ECC on */
#define PWDO 0x40
/* bits for reading from DOC2window.signals ( CDSN_Control reg ) */
#define RB 0x80 /* 1 - ready */
/* bits for writing to DOC2window.ECCconfig */
#define ECC_RESERVED 0x02 /* reserved bits */
#define ECC_EN (0x08 | ECC_RESERVED) /* 1 - enable ECC */
#define ECC_RW (0x20 | ECC_RESERVED) /* 1 - write mode, 0 - read mode */
/* bits for reading from DOC2window.ECCstatus */
#define ECC_ERROR 0x80
#define TOGGLE 0x04 /* used for DOC 2000 detection */
#define SLOW_IO 0x04 /* requires access to