📄 m512_mtd.c
字号:
else
{
DBG_PRINT_FLOW_PRM(FLZONE_MTD,(FLTXT("setBusType: Invalid if_cfg/interleave %u/%u.\r\n"),(FLWord)bIF_CFG,(FLWord)bInterleave));
return FALSE;
}
/*** We always work as INTERLEAVE-2 which means that if we write 16 bit ***/
/*** the LSB and the MSB bytes needed to be written to the flash ***/
dBusConfig |= FL_16BIT_FLASH_ACCESS ;
if(setBusTypeOfFlash(volume,dBusConfig) != flOK)
return FALSE;
else
{
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: setBusType exited .\r\n");
return TRUE;
}
}
#endif
/************************************************************************
* Name : initMedia *
* Initialize the MTD_VARS struct and the vol struct with M512 *
* flash parameters. *
* Parameters: *
* flashPtr : Pointer identifying drive *
* *
* Returns: *
* FLStatus : flOK on success, *
* flUnknownMedia : Media is not recognized *
************************************************************************/
static FLStatus M512_initMedia(FLFlash *flashPtr)
{
FLByte bProductType ;
FLStatus status ;
MTD_VARS->wPagesPerBlockBits = 6 ;
MTD_VARS->bPlaneArraysInChip = 1 ;
MTD_VARS->bNoOfPlanesBits = 1 ;
MTD_VARS->wPageAreaSize = 256 ;
MTD_VARS->bPageSizeBits = 9 ;
MTD_VARS->wPageSize = 1<<MTD_VARS->bPageSizeBits ;
MTD_VARS->wPageTailSize = 16 ;
MTD_VARS->dwUnitSize = 1L << (FLDword)(MTD_VARS->wPagesPerBlockBits + MTD_VARS->bPageSizeBits) ;
flashPtr->noOfPlanes = 1<<MTD_VARS->bNoOfPlanesBits ;
flashPtr->type = TC58512_FLASH ;
flashPtr->maxEraseCycles = 100000L ;
flashPtr->evenPagePPP = 1 ;
flashPtr->oddPagePPP = 1 ;
flashPtr->averageErase = 2500 ; /* us typical for MLC mode */
flashPtr->averageRead = 50 ; /* ns typical for MLC mode */
/*********** MDOC-512 Family ******************/
if (M512_ReadChipID (flashPtr)==M512_CHIP_ID)
{ /*** MDOC_512 ASIC is detected ***/
MTD_VARS->wMakerCode = 0x98 ;
MTD_VARS->wDeviceCode = 0x76 ;
MTD_VARS->wUnitsInChip = 2048 ;
MTD_VARS->bAddressBytes = 4 ;
/*** Read the product type ***/
status = M512_ReadProductType (flashPtr,&bProductType) ;
if (status)
{
DBG_PRINT_WRN (FLZONE_MTD,"initMedia:M512_ReadProductType failed \r\n");
return flUnknownMedia ;
}
#ifdef FPGA_SIM
/*** The FPGA emulates M512 only => we force M512 product type ***/
bProductType = 0xFF ;
#endif
if (bProductType==0xFF)
{ /*** MDOC_512 G3 chip ***/
DBG_PRINT_WRN (FLZONE_MTD,"MDOC 512Mbit G3 MLC was detected.\r\n");
MTD_VARS->bFlashType = M512_MLC_TYPE ;
flashPtr->erasableBlockSize = MTD_VARS->dwUnitSize << (FLDword)MTD_VARS->bNoOfPlanesBits ;
flashPtr->mediaType = M512_G3_TYPE ;
flashPtr->averageWrite = 800 ; /* us typical for MLC mode */
}
else
{ /*** MDOC_256 P3 chip ***/
DBG_PRINT_WRN (FLZONE_MTD,"MDOC 256Mbit P3 was detected.\r\n");
MTD_VARS->bFlashType = M512_SLC_TYPE ;
flashPtr->erasableBlockSize = (MTD_VARS->dwUnitSize << (FLDword)MTD_VARS->bNoOfPlanesBits)>>1 ;
flashPtr->mediaType = M256_P3_TYPE ;
flashPtr->averageWrite = 300 ; /* us typical for P3 device */
}
}
/*********** MDOC-256 Family ******************/
else if (M512_ReadChipID (flashPtr)==M256_CHIP_ID)
{ /* MDOC_256 G3 ASIC is detected */
MTD_VARS->wMakerCode = 0x98 ;
MTD_VARS->wDeviceCode = 0x75 ;
MTD_VARS->wUnitsInChip = 512 ;
MTD_VARS->bAddressBytes = 3 ;
/*** Read the product type ***/
status = M512_ReadProductType (flashPtr,&bProductType) ;
if (status)
{
DBG_PRINT_WRN (FLZONE_MTD,"initMedia:M512_ReadProductType failed \r\n");
return flUnknownMedia ;
}
#ifdef FPGA_SIM
/*** The FPGA emulates M512 only => we force M512 product type ***/
bProductType = 0xff ;
#endif
if (bProductType==0xFF)
{ /*** MDOC_256 G3 chip ***/
DBG_PRINT_WRN (FLZONE_MTD,"MDOC 256Mbit G3 MLC was detected.\r\n");
MTD_VARS->bFlashType = M512_MLC_TYPE ;
flashPtr->erasableBlockSize = MTD_VARS->dwUnitSize << (FLDword)MTD_VARS->bNoOfPlanesBits ;
flashPtr->mediaType = M256_G3_TYPE ;
}
else
{ /*** MDOC_128 P3 chip ***/
DBG_PRINT_WRN (FLZONE_MTD,"MDOC 128Mbit P3 was detected.\r\n");
MTD_VARS->bFlashType = M512_SLC_TYPE ;
flashPtr->erasableBlockSize = (MTD_VARS->dwUnitSize << (FLDword)MTD_VARS->bNoOfPlanesBits)>>1 ;
flashPtr->mediaType = M128_P3_TYPE ;
}
}
/*********** MDOC-1G Family ******************/
else if (M512_ReadChipID (flashPtr)==M1G_CHIP_ID)
{ /* MDOC_256 G3 ASIC is detected */
MTD_VARS->wMakerCode = 0x98 ;
MTD_VARS->wDeviceCode = 0x76 ;
MTD_VARS->wUnitsInChip = 4096 ;
MTD_VARS->bAddressBytes = 4 ;
/*** Read the product type ***/
status = M512_ReadProductType (flashPtr,&bProductType) ;
if (status)
{
DBG_PRINT_WRN (FLZONE_MTD,"initMedia:M512_ReadProductType failed \r\n");
return flUnknownMedia ;
}
#ifdef FPGA_SIM
/*** The FPGA emulates M512 only => we force M512 product type ***/
bProductType = 0xff ;
#endif
if (bProductType==0xFF)
{ /*** MDOC_256 G3 chip ***/
DBG_PRINT_WRN (FLZONE_MTD,"MDOC 1GBit G3 MLC was detected.\r\n");
MTD_VARS->bFlashType = M512_MLC_TYPE ;
flashPtr->erasableBlockSize = MTD_VARS->dwUnitSize << (FLDword)MTD_VARS->bNoOfPlanesBits ;
flashPtr->mediaType = M1G_G3_TYPE ;
}
else
{ /*** MDOC_128 P3 chip ***/
DBG_PRINT_WRN (FLZONE_MTD,"MDOC 1/2Gbit P3 was detected.\r\n");
MTD_VARS->bFlashType = M512_SLC_TYPE ;
flashPtr->erasableBlockSize = (MTD_VARS->dwUnitSize << (FLDword)MTD_VARS->bNoOfPlanesBits)>>1 ;
flashPtr->mediaType = M512_P3_TYPE ;
}
}
else
return flUnknownMedia ;
MTD_VARS->dwChipSize = (FLDword)MTD_VARS->wUnitsInChip * (FLDword)MTD_VARS->dwUnitSize ;
DBG_PRINT_FLOW(FLZONE_MTD,"Flow: initMedia Exited.\r\n");
return flOK ;
}
/************************************************************************
************************** Asic functions **************************
************************************************************************/
/***********************************************************************
* Name : M512_FlashDataRegReadBuffer
* Read buffer from FLASH_DATA_REG
*
* Parameters:
* flashPtr: The flash struct.
* bufPtr: The data would be written to this buffer
* wNoOfBytes: Number of bytes to read
*
* Returns one of the following values:
* Note : The routine reads in a multiple of 4 because if memcpy
* reads dwords and the remider it reads in bytes
***********************************************************************/
void M512_FlashDataRegReadBuffer (FLFlash *flashPtr,
FLByte FAR1 *bufPtr,
FLWord wNoOfBytes)
{
FLByte bReminder ;
/* Write the address of register to M512_READ_ADDRESS_REG */
M512_Write16BitReg (flashPtr,M512_READ_ADDRESS_REG,M512_FLASH_DATA_REG_ALIASED) ;
bReminder = wNoOfBytes & 3 ;
if ((bReminder) && (flashPtr->if_cfg==16))
{
/*** 1. Read in a multiple of 4 ***/
if (wNoOfBytes-bReminder)
M512_ReadEvenNumberOfBytes (flashPtr,M512_FLASH_DATA_REG_ALIASED,bufPtr,(FLWord)(wNoOfBytes-bReminder)) ;
/*** Now the MTD needs to read only one byte in the following way: ***/
/*** We set the ONE_BYTE bit indicating that in the next write to the ***/
/*** FLASH_DATA_REG we would read the last data byte from the LSB byte ***/
while (bReminder)
{
M512_Write16BitReg (flashPtr,M512_READ_ADDRESS_REG,(FLWord)(M512_FLASH_DATA_REG_ALIASED|M512_ADDR_ACCESS_ONE_BYTE)) ;
bufPtr[wNoOfBytes-bReminder] = M512_DirectRead8BitReg (flashPtr,M512_FLASH_DATA_REG_ALIASED) ;
bReminder-- ;
}
}
else
{
M512_ReadEvenNumberOfBytes (flashPtr,M512_FLASH_DATA_REG_ALIASED,bufPtr,wNoOfBytes) ;
}
}
/***********************************************************************
* Name : M512_FlashDataRegWriteBuffer
* write buffer to FLASH_DATA_REG
*
* Parameters:
* flashPtr: The flash struct.
* wOffset: The offset of the FLASH_DATA_REGISTER
* bufPtr: Holds the DATA that would be written to the FLASH
* wNoOfBytes: Number of bytes to write
*
* Returns one of the following values:
* DOWNLOAD_OK - IPL download was O.K
* DOWNLOAD_ERROR - IPL download failed.
* DOWNLOAD_MAIN_UNIT_ERROR - IPL download error from main unit
***********************************************************************/
void M512_FlashDataRegWriteBuffer(FLFlash *flashPtr,
FLByte FAR1 *bufPtr,
FLWord wNoOfBytes)
{
FLByte bReminder ;
/* Write the address of register to M512_READ_ADDRESS_REG */
M512_Write16BitReg (flashPtr,M512_READ_ADDRESS_REG,M512_FLASH_DATA_REG_ALIASED) ;
bReminder = wNoOfBytes & 3 ;
if ((bReminder) && (flashPtr->if_cfg==16))
{
if (wNoOfBytes-bReminder)
M512_WriteEvenNumberOfBytes (flashPtr,M512_FLASH_DATA_REG_ALIASED,bufPtr,(FLWord)(wNoOfBytes-bReminder)) ;
/*** Now the MTD needs to read only one byte in the following way: ***/
/*** We set the ONE_BYTE bit indicating that in the next write to the ***/
/*** FLASH_DATA_REG we would write the last data byte from the LSB byte ***/
while (bReminder)
{
M512_Write8BitToDataReg (flashPtr,bufPtr[wNoOfBytes-bReminder]) ;
bReminder-- ;
}
}
else
{
M512_WriteEvenNumberOfBytes (flashPtr,M512_FLASH_DATA_REG_ALIASED,bufPtr,wNoOfBytes) ;
}
}
/***********************************************************************
* Name: M512_AsicSetFloor
*
* Write to DeviceSelector register to set the desired floor .
*
* Parameters:
* flashPtr : Pointer identifying drive
* bFloor : The selected Floor (0,1,2,3)
***********************************************************************/
void M512_AsicSetFloor (FLFlash *flashPtr, FLByte bFloor)
{
volatile FLByte bTemp ;
/* Set the Floor */
M512_Write8BitReg(flashPtr,M512_DEVICE_ID_SELECT_REG,bFloor) ;
bTemp = M512_Read8BitReg (flashPtr,M512_FLASH_CONTROL_REG) ;
/* Remove the WP */
bTemp &= ~(M512_FWP_SIGNAL_ACTIVE) ;
/* set FCE_SIGNAL_ACTIVE */
bTemp |= M512_FCE_SIGNAL_ACTIVE ;
M512_Write8BitReg (flashPtr,M512_FLASH_CONTROL_REG,bTemp) ;
}
/***********************************************************************
* Name: M512_asicSetMode
*
* Set the controller (ASIC) operation mode.
*
* Paramete
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -