?? mvflash.c
字號:
/*******************************************************************************
*
* Copyright 2003,MARVELL SEMICONDUCTOR ISRAEL, LTD.
* THIS CODE CONTAINS CONFIDENTIAL INFORMATION OF MARVELL.
* NO RIGHTS ARE GRANTED HEREIN UNDER ANY PATENT, MASK WORK RIGHT OR COPYRIGHT
* OF MARVELL OR ANY THIRD PARTY. MARVELL RESERVES THE RIGHT AT ITS SOLE
* DISCRETION TO REQUEST THAT THIS CODE BE IMMEDIATELY RETURNED TO MARVELL.
* THIS CODE IS PROVIDED "AS IS". MARVELL MAKES NO WARRANTIES, EXPRESSED,
* IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, COMPLETENESS OR PERFORMANCE.
*
* MARVELL COMPRISES MARVELL TECHNOLOGY GROUP LTD. (MTGL) AND ITS SUBSIDIARIES,
* MARVELL INTERNATIONAL LTD. (MIL), MARVELL TECHNOLOGY, INC. (MTI), MARVELL
* SEMICONDUCTOR, INC. (MSI), MARVELL ASIA PTE LTD. (MAPL), MARVELL JAPAN K.K.
* (MJKK), MARVELL SEMICONDUCTOR ISRAEL. (MSIL), MARVELL TAIWAN, LTD. AND
* SYSKONNECT GMBH.
*
********************************************************************************
* mvFlash.c - FLASH memory functions and definitions for SV use
*
* DESCRIPTION:
* This mvFlash driver gives the user a convenient interface to the FLASH
* memory located on the user`s board, it supports various layout
* configurations such as:
* 1. One pure 8 bit device (Such as AMD`s AM29LV040B).
* 2. 1,2,4 or 8 devices 16 bit wide configured to operate in 8 bit mode.
* 3. 1,2 or 4 devices each 16 bit wide.
* Before using the driver you must call the initialization function at
* least once or when ever you are changing the FLASH base address.
* The list bellow contains the supported FLASH memory devices, new
* devices can be added easily in the future.
*
* DEPENDENCIES:
* None.
*
*******************************************************************************/
/*includes*/
#include "mvFlash.h"
/* locals */
/******************************************************************************
* mvFlashParametrs[] , mvFlashTypes[]
*
* Those two tables contain the supported mvFlash devices information
* needed by the driver:
* The first table "mvFlashParametrs" starts with 10 shared fields
* (currently 6 are reserved):
* index 0 => Pointer to an entry in the second table list
* index 1 => baseAddress - Flash memory device base address.
* index 2 => width - 1, 2, 4 or 8 Bytes.
* index 3 => mode - PURE8, X8 or X16 mvFlash configuration
* (for X16 devices only)
* The second table (mvFlashTypes) contains:
* Entry`s structure:
* Manufacture ID,Device ID,number of sectors,list of sector`s sizes
* (in Kbytes starting with sector number 0).
* The end of the list is pointed with a zero.
******************************************************************************/
static unsigned long mvFlashParametrs[10]; /* 0 Entry pointer */
/* 1 Base address */
/* 2 Width */
/* 3 Mode */
/* 4,5,6,7,8,9, spare entries. */
static unsigned long mvFlashTypes[] = {
/* 0 */ AMD_FLASH,AM29F400BB,11,16,8,8,32,64,64,64,64,64,64,64,
/* 1 */ AMD_FLASH,AM29F400BT,11,64,64,64,64,64,64,64,32,8,8,16,
/* 2 */ ST_FLASH,M29W040 ,8,64,64,64,64,64,64,64,64,
/* 3 */ AMD_FLASH,AM29LV040B,8,64,64,64,64,64,64,64,64,
/* 4 */ AMD_FLASH,AM29LV800BT,19,64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,32,8,8,16,
/* 5 */ INTEL_FLASH,I28F320J3A,32,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,
/* 6 */ INTEL_FLASH,I28F640J3A,64,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,
/* 7 */ INTEL_FLASH,I28F128J3A,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
128,128,128,128,128,128,128,128,128,128,
/* 8 */ AMD_FLASH,AM29LV400BB,11,16,8,8,32,64,64,64,64,64,64,64,
/* 9 */ AMD_FLASH,AM29LV400BT,11,64,64,64,64,64,64,64,32,8,8,16,
/* 10 */ INTEL_FLASH,I28F320B3_T,71,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,8,8,8,8,8,8,8,8,
/* 11 */ INTEL_FLASH,I28F320B3_B,71,8,8,8,8,8,8,8,8,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
/* 12 */ INTEL_FLASH,I28F160B3_B,39,8,8,8,8,8,8,8,8,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,
/* 13 */ INTEL_FLASH,I28F160B3_T,39,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,
64,64,8,8,8,8,8,8,8,8,
/* 14 */ AMD_FLASH,AM29LV160DT,35,64,64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,32,8,8,16,
/* 15 */ AMD_FLASH,AM29LV160DB,35,16,8,8,32,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,64,64,
64,64,64,64,64,64,64,64,64,64,64,64,
/* 16 */ AMD_FLASH,AM29LV001BT,10,16,16,16,16,16,16,16,4,4,8,
/* 17 */ AMD_FLASH,AM29LV001BB,10,8,4,4,16,16,16,16,16,16,16,
/* 18 */ ATMEL_FLASH,AT49LV040,2,16,496,
/* 19 */ SST_FLASH,SST39VF020,64,4,4,4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,4,4,4,
4,4,4,4,4,4,4,4,4,4,4,4,
4,4,4,4,4,
0 /* End of list indicator */
};
/* Local functions */
static unsigned long mvFlashGetSize(void);
static unsigned long mvFlashGetSectorSize(unsigned long);
/* Local Definitions */
#define _1K 0x00000400
/*******************************************************************************
* mvFlashInit - Initializes the FLASH memory driver`s parameters.
*
* DESCRIPTION:
* This function auto detects flash memory which may be present in
* the system according to the flashTypes table defined in
* gtFlash.c and initializes the global internal data structures
* with the flash's base address, width, pointer to flash in the
* flashTypes table and flash mode (PURE8 , X8 , X16) .If the flash
* device was not found in the flashTypes table by this function ,
* the return value will be 0, otherwise the return value will be
* the flash's size that was found. this function must be called
* at least once before using the flash memory. If the flash's base
* address was changed, this function must be called again.
*
* INPUTS:
* flashBaseAddress - The physical base address for the flash
* memory device. For example, if the Flash
* Memory is connected to chip select 0 on the
* device interface of the MV device the value
* for the base address will be 0x1C00:0000.
* flashWidth - The physical width of the flash memory
* as connected to the MV's device interface
* (1,2,4 or 8 bytes).
* flashMode - Two forms of flash memory are supported by this
* driver. Pure 8 bit devices (PURE8), such as boot
* devices, and 16 bit devices which can be configured
* to operate either as 8 bit devices (X8) or as 16 bit
* devices (X16).
*
* OUTPUT:
* None.
*
* RETURN:
* The flash's total size of a successful detection , 0 otherwise .
*
*******************************************************************************/
unsigned long mvFlashInit(unsigned long flashBaseAddress,
unsigned long flashWidth, FLASH_DEV_MODE flashMode)
{
unsigned short mfrId=0;
unsigned short devId = 0xff;
unsigned long FirstAddr, SecondAddr, ThirdAddr;
unsigned long pArray=0;
unsigned long counter;
unsigned long flashSize=0;
/* update the list with relevant parametrs */
mvFlashParametrs[0] = 0; /* Default initialization */
mvFlashParametrs[1] = flashBaseAddress;
mvFlashParametrs[2] = flashWidth;
mvFlashParametrs[3] = flashMode;
/* Get the FLASH`s ID */
switch(FLASH_WIDTH)
{
case 1:
/* AMD or ST ?? **/
if( flashMode == PURE8 ) /* Boot Flash*/
{
FirstAddr = 0x5555;
SecondAddr= 0x2aaa;
ThirdAddr = 0x5555;
}
else /* X16 device configured to 8bit Mode */
{
FirstAddr = 0xaaaa;
SecondAddr= 0x5555;
ThirdAddr = 0xaaaa;
}
mvFlashReset();
MV_WRITE_CHAR(FLASH_BASE_ADDR, FirstAddr,0xAA);
MV_WRITE_CHAR(FLASH_BASE_ADDR, SecondAddr,0x55);
MV_WRITE_CHAR(FLASH_BASE_ADDR, ThirdAddr,0x90);
MV_READ_CHAR(FLASH_BASE_ADDR, 0x0,&mfrId);
printf("Manufacturer Code %x\n",mfrId);
if(mfrId == AMD_FLASH || mfrId == ST_FLASH || mfrId == ATMEL_FLASH || mfrId == SST_FLASH)
{
mvFlashReset();
MV_WRITE_CHAR(FLASH_BASE_ADDR, FirstAddr,0xAA);
MV_WRITE_CHAR(FLASH_BASE_ADDR, SecondAddr,0x55);
MV_WRITE_CHAR(FLASH_BASE_ADDR, ThirdAddr,0x90);
MV_READ_CHAR(FLASH_BASE_ADDR, 0x1,&devId);
printf("Device Code %x\n",devId);
break;
}
/* Micron or Intel ?? **/
MV_WRITE_CHAR(FLASH_BASE_ADDR,0,0xff); /* Read Array */
/* Flash reset for Intel/Micron */
MV_WRITE_CHAR(FLASH_BASE_ADDR,0,0x90); /* IDENTIFY Device */
MV_READ_CHAR(FLASH_BASE_ADDR, 0x0,&mfrId);
/*Address for ManufactureID*/
if(mfrId == INTEL_FLASH || mfrId == MICRON_FLASH)
{
MV_WRITE_CHAR(FLASH_BASE_ADDR,0,0xff); /* Read Array */
/*Flash reset for Intel/Micron*/
MV_WRITE_CHAR(FLASH_BASE_ADDR,0,0x90); /* IDENTIFY Device */
MV_READ_CHAR(FLASH_BASE_ADDR, 0x2,&devId);
/*Address for DeviceID*/
}
break;
case 2:
case 4:
case 8:
/* AMD or ST ??? */
mvFlashReset();
MV_WRITE_SHORT(FLASH_BASE_ADDR, 0x5555 * FLASH_WIDTH,0xaa);
MV_WRITE_SHORT(FLASH_BASE_ADDR, 0x2aaa * FLASH_WIDTH,0x55);
MV_WRITE_SHORT(FLASH_BASE_ADDR, 0x5555 * FLASH_WIDTH,0x90);
MV_READ_SHORT(FLASH_BASE_ADDR,0,&mfrId);
mvFlashReset();
/* Read the device ID */
if(mfrId == AMD_FLASH || mfrId == ST_FLASH || mfrId == ATMEL_FLASH || mfrId == SST_FLASH)
{
MV_WRITE_SHORT(FLASH_BASE_ADDR, 0x5555 * FLASH_WIDTH,0xaa);
MV_WRITE_SHORT(FLASH_BASE_ADDR, 0x2aaa * FLASH_WIDTH,0x55);
MV_WRITE_SHORT(FLASH_BASE_ADDR, 0x5555 * FLASH_WIDTH,0x90);
MV_READ_SHORT(FLASH_BASE_ADDR, 0x1 * FLASH_WIDTH,&devId);
break;
}
/* Micron or Intel ?? **/
mvFlashReset();
MV_WRITE_WORD(FLASH_BASE_ADDR,0,0x00ff00ff);
MV_WRITE_WORD(FLASH_BASE_ADDR,0,0x00900090);
if( (FLASH_WIDTH == 4) || (FLASH_WIDTH == 8) ) /* 32 or 64 bit */
{
MV_READ_SHORT(FLASH_BASE_ADDR,0,&mfrId);
}
else /* FLASH_WIDTH = 2 */
{
MV_READ_SHORT(FLASH_BASE_ADDR,0,&mfrId);
}
if( (mfrId == INTEL_FLASH) || (mfrId == MICRON_FLASH) )
{
/* Flash reset for Intel/Micron */
mvFlashReset();
MV_WRITE_WORD(FLASH_BASE_ADDR,0,0x00ff00ff);
MV_WRITE_WORD(FLASH_BASE_ADDR,0,0x00900090);
if( (FLASH_WIDTH == 2) ||(FLASH_WIDTH == 4) ||
(FLASH_WIDTH == 8) ) /* 32 or 64 bit */
{
MV_READ_SHORT(FLASH_BASE_ADDR, 0x1*FLASH_WIDTH,&devId);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -