/*************************************************************************** * print sizes as "xxx kB", "xxx.y kB", "xxx MB" or "xxx.y MB" as needed; * allow for optional trailing string (like "\n") ***************************************************************************/ static MV_VOID sizePrint (MV_U32 size, MV_U8 *s) { MV_U32 m, n; MV_U32 d = 1 << 20; /* 1 MB */ MV_U8 c = 'M'; if (size < d) { /* print in kB */ c = 'k'; d = 1 << 10; } n = size / d; m = (10 * (size - (n * d)) + (d / 2) ) / d; if (m >= 10) { m -= 10; n += 1; } mvOsOutput ("%2d", n); if (m) { mvOsOutput (".%d", m); } mvOsOutput (" %cB%s", c, s); }
/******************************************************************************* * mvCpuIfAddDecShow - Print the CPU address decode map. * * DESCRIPTION: * This function print the CPU address decode map. * * INPUT: * None. * * OUTPUT: * None. * * RETURN: * None. * *******************************************************************************/ MV_VOID mvCpuIfAddDecShow(MV_VOID) { MV_CPU_DEC_WIN win; MV_U32 target; mvOsOutput( "\n" ); mvOsOutput( "CPU Interface\n" ); mvOsOutput( "-------------\n" ); for( target = 0; target < MAX_TARGETS; target++ ) { memset( &win, 0, sizeof(MV_CPU_DEC_WIN) ); mvOsOutput( "%s ",mvCtrlTargetNameGet(target)); mvOsOutput( "...." ); if( mvCpuIfTargetWinGet( target, &win ) == MV_OK ) { if( win.enable ) { mvOsOutput( "base %08x, ", win.addrWin.baseLow ); mvSizePrint( win.addrWin.size ); mvOsOutput( "\n" ); } else mvOsOutput( "disable\n" ); } else if( mvCpuIfTargetWinGet( target, &win ) == MV_NO_SUCH ) { mvOsOutput( "no such\n" ); } } }
/******************************************************************************* * mvEthPhyDisableAN - Disable Phy Auto-Negotiation and set forced Speed and Duplex * * DESCRIPTION: * This function disable AN and set duplex and speed. * * INPUT: * phyAddr - Phy address. * speed - port speed. 0 - 10 Mbps, 1-100 Mbps, 2 - 1000 Mbps * duplex - port duplex. 0 - Half duplex, 1 - Full duplex * * OUTPUT: * None. * * RETURN: MV_OK - Success * MV_FAIL - Failure * *******************************************************************************/ MV_STATUS mvEthPhyDisableAN(MV_U32 phyAddr, int speed, int duplex) { MV_U16 phyRegData; if(mvEthPhyRegRead (phyAddr, ETH_PHY_CTRL_REG, &phyRegData) != MV_OK) return MV_FAIL; switch(speed) { case 0: /* 10 Mbps */ phyRegData &= ~ETH_PHY_CTRL_SPEED_LSB_MASK; phyRegData &= ~ETH_PHY_CTRL_SPEED_MSB_MASK; break; case 1: /* 100 Mbps */ phyRegData |= ETH_PHY_CTRL_SPEED_LSB_MASK; phyRegData &= ~ETH_PHY_CTRL_SPEED_MSB_MASK; break; case 2: /* 1000 Mbps */ phyRegData &= ~ETH_PHY_CTRL_SPEED_LSB_MASK; phyRegData |= ETH_PHY_CTRL_SPEED_MSB_MASK; break; default: mvOsOutput("Unexpected speed = %d\n", speed); return MV_FAIL; } switch(duplex) { case 0: /* half duplex */ phyRegData &= ~ETH_PHY_CTRL_DUPLEX_MASK; break; case 1: /* full duplex */ phyRegData |= ETH_PHY_CTRL_DUPLEX_MASK; break; default: mvOsOutput("Unexpected duplex = %d\n", duplex); } /* Clear bit 12 to Disable autonegotiation of the PHY */ phyRegData &= ~ETH_PHY_CTRL_AN_ENABLE_MASK; /* Clear bit 9 to DISABLE, Restart autonegotiation of the PHY */ phyRegData &= ~ETH_PHY_CTRL_AN_RESTART_MASK; mvEthPhyRegWrite(phyAddr, ETH_PHY_CTRL_REG, phyRegData); return MV_OK; }
/******************************************************************************* * mvEthAddrDecShow - Print the Etherent address decode map. * * DESCRIPTION: * This function print the Etherent address decode map. * * INPUT: * None. * * OUTPUT: * None. * * RETURN: * None. * *******************************************************************************/ void mvEthPortAddrDecShow(int port) { MV_ETH_DEC_WIN win; int i; mvOsOutput( "\n" ); mvOsOutput( "ETH #%d:\n", port ); mvOsOutput( "----\n" ); for( i = 0; i < ETH_MAX_DECODE_WIN; i++ ) { memset( &win, 0, sizeof(ETH_MAX_DECODE_WIN) ); mvOsOutput( "win%d - ", i ); if( mvEthWinGet(port, i, &win ) == MV_OK ) { if( win.enable ) { mvOsOutput( "%s base %08x, ", mvCtrlTargetNameGet(win.target), win.addrWin.baseLow ); mvOsOutput( "...." ); mvSizePrint( win.addrWin.size ); mvOsOutput( "\n" ); } else mvOsOutput( "disable\n" ); } } return; }
/******************************************************************************* * mvAhbToMbusAddDecShow - Print the AHB to MBus bridge address decode map. * * DESCRIPTION: * This function print the CPU address decode map. * * INPUT: * None. * * OUTPUT: * None. * * RETURN: * None. * *******************************************************************************/ MV_VOID mvAhbToMbusAddDecShow(MV_VOID) { MV_AHB_TO_MBUS_DEC_WIN win; MV_U32 winNum; mvOsOutput( "\n" ); mvOsOutput( "AHB To MBUS Bridge:\n" ); mvOsOutput( "-------------------\n" ); for( winNum = 0; winNum < MAX_AHB_TO_MBUS_WINS; winNum++ ) { memset( &win, 0, sizeof(MV_AHB_TO_MBUS_DEC_WIN) ); mvOsOutput( "win%d - ", winNum ); if( mvAhbToMbusWinGet( winNum, &win ) == MV_OK ) { if( win.enable ) { mvOsOutput( "%s base %08x, ", mvCtrlTargetNameGet(win.target), win.addrWin.baseLow ); mvOsOutput( "...." ); mvSizePrint( win.addrWin.size ); mvOsOutput( "\n" ); } else mvOsOutput( "disable\n" ); } } }
/******************************************************************************* * mvSizePrint - Print the given size with size unit description. * * DESCRIPTION: * This function print the given size with size unit description. * FOr example when size paramter is 0x180000, the function prints: * "size 1MB+500KB" * * INPUT: * size - Size in bytes. * * OUTPUT: * None. * * RETURN: * None. * *******************************************************************************/ MV_VOID mvSizePrint(MV_U32 size) { mvOsOutput("size "); if (size >= _1G) { mvOsOutput("%3dGB ", size / _1G); size %= _1G; if (size) mvOsOutput("+"); } if (size >= _1M) { mvOsOutput("%3dMB ", size / _1M); size %= _1M; if (size) mvOsOutput("+"); } if (size >= _1K) { mvOsOutput("%3dKB ", size / _1K); size %= _1K; if (size) mvOsOutput("+"); } if (size > 0) mvOsOutput("%3dB ", size); }
/******************************************************************************* * mvAudioAddrDecShow - Print the AUDIO address decode map. * * DESCRIPTION: * This function print the AUDIO address decode map. * * INPUT: * None. * * OUTPUT: * None. * * RETURN: * None. * *******************************************************************************/ MV_VOID mvAudioUnitAddrDecShow(int unit) { MV_AUDIO_DEC_WIN win; int i; mvOsOutput( "\n" ); mvOsOutput( "AUDIO:\n" ); mvOsOutput( "----\n" ); for( i = 0; i < MV_AUDIO_MAX_ADDR_DECODE_WIN; i++ ) { memset( &win, 0, sizeof(MV_AUDIO_DEC_WIN) ); mvOsOutput( "win%d - ", i ); if( mvAudioWinGet(unit, i, &win) == MV_OK ) { if( win.enable ) { mvOsOutput( "%s base %08x, ", mvCtrlTargetNameGet(win.target), win.addrWin.baseLow ); mvOsOutput( "...." ); mvSizePrint( win.addrWin.size ); mvOsOutput( "\n" ); } else mvOsOutput( "disable\n" ); } } }
MV_VOID mvTdmAddrDecShow(MV_VOID) { MV_TDM_DEC_WIN win; int i; mvOsOutput( "\n" ); mvOsOutput( "TDM:\n" ); mvOsOutput( "----\n" ); for( i = 0; i < TDM_MBUS_MAX_WIN; i++ ) { memset( &win, 0, sizeof(MV_TDM_DEC_WIN) ); mvOsOutput( "win%d - ", i ); if (mvTdmWinGet(i, &win ) == MV_OK ) { if( win.enable ) { mvOsOutput( "%s base %08x, ", mvCtrlTargetNameGet(win.target), win.addrWin.baseLow); mvOsOutput( "...." ); mvSizePrint( win.addrWin.size ); mvOsOutput( "\n" ); } else mvOsOutput( "disable\n" ); } } }
static MV_STATUS configPixelFormat(MV_CAM_SENSOR *pCamSensor, int formatIdx) { OV7680_INFO *pInfo = (OV7680_INFO *)pCamSensor->pInfo; /* if the new format the same as the current format*/ if(pInfo->pixFormat->id == supportedFormats[formatIdx].id) return MV_OK; pInfo->pixFormat = supportedFormats + formatIdx; switch(pInfo->pixFormat->id) { case MV_PIX_FORMAT_ID_RGB444: return ovRGB444Set(pCamSensor); case MV_PIX_FORMAT_ID_RGB555: return ovRGB555Set(pCamSensor); case MV_PIX_FORMAT_ID_RGB565: return ovRGB565Set(pCamSensor); case MV_PIX_FORMAT_ID_YUV422: return ovYUV422Set(pCamSensor); case MV_PIX_FORMAT_ID_RAW_BAYER: return ovRawBayerSet(pCamSensor); default: mvOsOutput("configPixelFormat: fatal error: unkown format id (0x%x)\n", pInfo->pixFormat->id); return MV_NOT_SUPPORTED; } return MV_OK; }
/******************************************************************************* * mvEthPhyPrintStatus - * * DESCRIPTION: * print port Speed, Duplex, Auto-negotiation, Link. * * INPUT: * phyAddr - Phy address. * * OUTPUT: * None. * * RETURN: 16bit phy register value, or 0xffff on error * *******************************************************************************/ MV_STATUS mvEthPhyPrintStatus( MV_U32 phyAddr ) { MV_U16 val; /* read control reg */ if( mvEthPhyRegRead( phyAddr, ETH_PHY_CTRL_REG, &val) != MV_OK ) return MV_ERROR; if( val & ETH_PHY_CTRL_AN_ENABLE_MASK ) mvOsOutput( "Auto negotiation: Enabled\n" ); else mvOsOutput( "Auto negotiation: Disabled\n" ); /* read specific status reg */ if( mvEthPhyRegRead( phyAddr, ETH_PHY_SPEC_STATUS_REG, &val) != MV_OK ) return MV_ERROR; switch (val & ETH_PHY_SPEC_STATUS_SPEED_MASK) { case ETH_PHY_SPEC_STATUS_SPEED_1000MBPS: mvOsOutput( "Speed: 1000 Mbps\n" ); break; case ETH_PHY_SPEC_STATUS_SPEED_100MBPS: mvOsOutput( "Speed: 100 Mbps\n" ); break; case ETH_PHY_SPEC_STATUS_SPEED_10MBPS: mvOsOutput( "Speed: 10 Mbps\n" ); default: mvOsOutput( "Speed: Uknown\n" ); break; } if( val & ETH_PHY_SPEC_STATUS_DUPLEX_MASK ) mvOsOutput( "Duplex: Full\n" ); else mvOsOutput( "Duplex: Half\n" ); if( val & ETH_PHY_SPEC_STATUS_LINK_MASK ) mvOsOutput("Link: up\n"); else mvOsOutput("Link: down\n"); return MV_OK; }
static MV_VOID mvXorAddrDecShowUnit(MV_U32 unit) { MV_XOR_DEC_WIN win; int i; mvOsOutput( "\n" ); mvOsOutput( "XOR %d:\n", unit ); mvOsOutput( "----\n" ); for( i = 0; i < XOR_MAX_ADDR_DEC_WIN; i++ ) { memset( &win, 0, sizeof(MV_XOR_DEC_WIN) ); mvOsOutput( "win%d - ", i ); if( mvXorTargetWinGet(unit, i, &win ) == MV_OK ) { if( win.enable ) { mvOsOutput( "%s base %x, ", mvCtrlTargetNameGet(win.target), win.addrWin.baseLow ); mvSizePrint( win.addrWin.size ); mvOsOutput( "\n" ); } else mvOsOutput( "disable\n" ); } } }
/******************************************************************************* * mvCamSensorReset - request from Camera Sensor to reset itself * * DESCRIPTION: * * INPUT: * Pointer to Camera Sensor Data structure. * * OUTPUT: * None * RETURN: * MV_BAD_PTR: if Sensor data structure is invalid * MV_ERROR: I2C failure * MV_ERROR: if senser reports failure * MV_OK otherwise *******************************************************************************/ MV_STATUS mvCamSensorReset(MV_CAM_SENSOR *pCamSensor) { mvOsOutput("mvCamSensorReset\n"); if(!pCamSensor) { mvOsPrintf("mvCamSensorReset: Bad Input\n"); return MV_BAD_PTR; } return resetSensor(pCamSensor); }
static MV_STATUS configResolution(MV_CAM_SENSOR * pCamSensor, int resIdx) { OV7680_INFO *pInfo = (OV7680_INFO *)pCamSensor->pInfo; /* if the new resolution the same as the current*/ if((pInfo->resolution->height == supportedResolutions[resIdx].height) && (pInfo->resolution->width == supportedResolutions[resIdx].width)) return MV_OK; mvOsOutput("configResolution: fatal error: unkown resolution (%s)\n", supportedResolutions[resIdx].name); return MV_NOT_SUPPORTED; }
/******************************************************************************* * mvSataAddrDecShow - Print the SATA address decode map. * * DESCRIPTION: * This function print the SATA address decode map. * * INPUT: * None. * * OUTPUT: * None. * * RETURN: * None. * *******************************************************************************/ MV_VOID mvSataAddrDecShow(MV_VOID) { MV_SATA_DEC_WIN win; int i,j; for( j = 0; j < MV_SATA_MAX_CHAN; j++ ) { if (MV_FALSE == mvCtrlPwrClckGet(SATA_UNIT_ID, j)) return; mvOsOutput( "\n" ); mvOsOutput( "SATA %d:\n", j ); mvOsOutput( "----\n" ); for( i = 0; i < MV_SATA_MAX_ADDR_DECODE_WIN; i++ ) { memset( &win, 0, sizeof(MV_SATA_DEC_WIN) ); mvOsOutput( "win%d - ", i ); if( mvSataWinGet(j, i, &win ) == MV_OK ) { if( win.enable ) { mvOsOutput( "%s base %08x, ", mvCtrlTargetNameGet(win.target), win.addrWin.baseLow ); mvOsOutput( "...." ); mvSizePrint( win.addrWin.size ); mvOsOutput( "\n" ); } else mvOsOutput( "disable\n" ); } } } }
static MV_VOID mvXorAddrDecShowUnit(MV_U32 unit) { MV_UNIT_WIN_INFO win; int i; mvOsOutput( "\n" ); mvOsOutput( "XOR %d:\n", unit ); mvOsOutput( "----\n" ); for( i = 0; i < XOR_MAX_ADDR_DEC_WIN; i++ ) { memset( &win, 0, sizeof(MV_UNIT_WIN_INFO) ); mvOsOutput( "win%d - ", i ); if( mvXorTargetWinRead(unit, i, &win ) == MV_OK ) { if( win.enable ) { /* In MV88F6781 there is no differentiation between different DRAM Chip Selects, */ /* they all use the same target ID and attributes. So in order to print correctly */ /* we use i as the target. When i is 1 it is SDRAM_CS1 etc. */ if (mvCtrlTargetByWinInfoGet(&win) != SDRAM_CS0) { mvOsOutput( "%s base %08x, ", mvCtrlTargetNameGet(mvCtrlTargetByWinInfoGet(&win)), win.addrWin.baseLow); } else { mvOsOutput( "%s base %08x, ", mvCtrlTargetNameGet(i), win.addrWin.baseLow); } mvSizePrint( win.addrWin.size ); mvOsOutput( "\n" ); } else mvOsOutput( "disable\n" ); } } }
/******************************************************************************* * mvAhbToMbusAddDecShow - Print the Ahb to MBus bridge address decode map. * * DESCRIPTION: * This function print the CPU address decode map. * * INPUT: * cpu - CPU id * * OUTPUT: * None. * * RETURN: * None. * *******************************************************************************/ MV_VOID mvAhbToMbusAddDecShow(MV_U32 cpu) { MV_AHB_TO_MBUS_DEC_WIN win; MV_U32 winNum; /* Check parameters */ if (cpu >= MV_MAX_CPU) { mvOsPrintf("mvAhbToMbusAddDecShow: ERR. Invalid cpu %d\n", cpu); return; } mvOsOutput( "\n" ); mvOsOutput( "CPU %d, AHB To MBUS Bridge:\n", cpu); mvOsOutput( "-------------------\n" ); for( winNum = 0; winNum < MAX_AHB_TO_MBUS_WINS; winNum++ ) { memset( &win, 0, sizeof(MV_AHB_TO_MBUS_DEC_WIN) ); mvOsOutput( "win%d - ", winNum ); if( mvAhbToMbusWinGet(cpu, winNum, &win ) == MV_OK ) { if( win.enable ) { mvOsOutput( "%s base %08x, ", mvCtrlTargetNameGet(win.target), win.addrWin.baseLow ); mvOsOutput( "...." ); mvSizePrint( win.addrWin.size ); mvOsOutput( "\n" ); } else mvOsOutput( "disable\n" ); } } }
/******************************************************************************* * mvTsuAddrDecShow * * DESCRIPTION: * Print the TSU address decode map. * * INPUT: * None. * * OUTPUT: * None. * * RETURN: * None. * *******************************************************************************/ void mvTsuAddrDecShow(void) { MV_TSU_DEC_WIN win; int i; if (MV_FALSE == mvCtrlPwrClckGet(TS_UNIT_ID, 0)) return; mvOsOutput( "\n" ); mvOsOutput( "TSU:\n"); mvOsOutput( "----\n" ); for(i = 0; i < TSU_MAX_DECODE_WIN; i++) { memset(&win, 0, sizeof(TSU_MAX_DECODE_WIN)); mvOsOutput( "win%d - ", i ); if(mvTsuWinGet(i, &win ) == MV_OK ) { if(win.enable == MV_TRUE) { mvOsOutput("%s base %08x, ", mvCtrlTargetNameGet(win.target), win.addrWin.baseLow); mvOsOutput( "...." ); mvSizePrint(win.addrWin.size ); mvOsOutput( "\n" ); } else { mvOsOutput( "disable\n" ); } } } return; }
/******************************************************************************* * mvCamSensorInit - Initialize the Camera Sensor * * DESCRIPTION: * this function does the following: * 1. Initializes the internal fields of the data stucture. * 2. initialize the sensor and loads default values. * 3. checks if the senser id match the support device * * INPUT: * Pointer to Camera Sensor Data structure, this sturcture must be allocated * by callee. * OUTPUT: * None * RETURN: * MV_BAD_PTR: if data structure not allocated or have bad external field * MV_FAIL: failed to allocate memory * MV_NOT_FOUND: if sensor id doesn't match * MV_ERROR: I2C failure transaction failure or if the senser reports failure * MV_OK otherwise *******************************************************************************/ MV_STATUS mvCamSensorInit(MV_CAM_SENSOR *pCamSensor) { OV7680_INFO *pInfo; mvOsOutput("mvCamSensorInit\n"); if(!pCamSensor) { mvOsPrintf("mvCamSensorInit: Bad Input\n"); return MV_BAD_PTR; } pInfo = mvOsMalloc(sizeof(OV7680_INFO)); pCamSensor->pInfo = pInfo; if(!pCamSensor->pInfo) { mvOsPrintf("mvCamSensorInit: failed to allocate memory\n"); return MV_FAIL; } pInfo->pixFormat = supportedFormats; pInfo->resolution = supportedResolutions; /* reset */ if (resetSensor(pCamSensor) != MV_OK) { mvOsPrintf("mvCamSensorInit: sensor reset failed\n"); return MV_ERROR; } /*load defaults*/ if(sensorRegsWrite(pCamSensor, ov7680_default_settings, sizeof(ov7680_default_settings)/sizeof(sensorReg_t)) != MV_OK){ mvOsPrintf("mvCamSensorInit: sensor default registers loading failed\n"); return MV_ERROR; } return isOV7680(pCamSensor); }
/******************************************************************************* * flashPrint - Print flash information structure. * * DESCRIPTION: * Prints all the feilds in the flash info structure. * * INPUT: * pFlash - Flash information. * * OUTPUT: * None * * RETURN: * None * *******************************************************************************/ MV_VOID flashPrint(MV_FLASH_INFO *pFlash) { MV_U32 i; if ((NULL == pFlash) || (mvFlashVenIdGet(pFlash) == 0)) { mvOsOutput ("missing or unknown FLASH type\n"); return; } switch (mvFlashVenIdGet(pFlash)) { case STM_MANUF: mvOsOutput ("STM "); break; case AMD_MANUF: mvOsOutput ("AMD "); break; case FUJ_MANUF: mvOsOutput ("FUJITSU "); break; case INTEL_MANUF: mvOsOutput ("INTEL "); break; case SST_MANUF: mvOsOutput ("SST "); break; case MX_MANUF: mvOsOutput ("MX "); break; default: mvOsOutput ("Unknown Vendor 0x%x",mvFlashVenIdGet(pFlash)); break; } switch (mvFlashDevIdGet(pFlash)) { case AMD_FID_LV040B: mvOsOutput ("AM29LV040B (4 Mbit, bottom boot sect)"); break; case AMD_FID_LV400B: mvOsOutput ("AM29LV400B (4 Mbit, bottom boot sect)"); break; case AMD_FID_LV400T: mvOsOutput ("AM29LV400T (4 Mbit, top boot sector)"); break; case AMD_FID_LV800B: mvOsOutput ("AM29LV800B (8 Mbit, bottom boot sect)"); break; case AMD_FID_LV800T: mvOsOutput ("AM29LV800T (8 Mbit, top boot sector)"); break; case AMD_FID_LV160B: mvOsOutput ("AM29LV160B (16 Mbit, bottom boot sect)"); break; case AMD_FID_LV160T: mvOsOutput ("AM29LV160T (16 Mbit, top boot sector)"); break; case AMD_FID_LV320B: mvOsOutput ("AM29LV320B (32 Mbit, bottom boot sect)"); break; case AMD_FID_LV320T: mvOsOutput ("AM29LV320T (32 Mbit, top boot sector)"); break; case STM_FID_29W040B: mvOsOutput ("M29W040B (4Mbit = 512K x 8) "); break; case INTEL_FID_28F320J3A: mvOsOutput ("28F320J3A (32 Mbit)"); break; case INTEL_FID_28F640J3A: mvOsOutput ("28F640J3A (64 Mbit)"); break; case INTEL_FID_28F128J3A: mvOsOutput ("28F128J3A (128 Mbit)"); break; case INTEL_FID_28F128P30T: mvOsOutput ("28F128P30 TOP (128 Mbit)"); break; case INTEL_FID_28F128P30B: mvOsOutput ("28F128P30 BOTTOM (128 Mbit)"); break; case INTEL_FID_28F256P30T: mvOsOutput ("28F256P30 TOP (256 Mbit)"); break; #if defined (DB_88F1281) case INTEL_FID_28F256P30B: mvOsOutput ("28F256P30 BOTTOM (128 Mbit)"); break; #else case INTEL_FID_28F256P30B: mvOsOutput ("28F256P30 BOTTOM (256 Mbit)"); break; #endif case SST_39VF_020: mvOsOutput ("SST39VF020 (2 Mbit)"); break; default: mvOsOutput ("Unknown Chip Type id 0x%x",mvFlashDevIdGet(pFlash)); break; } if(mvFlashNumOfDevGet(pFlash) > 1) mvOsOutput(" X %d",mvFlashNumOfDevGet(pFlash)); mvOsOutput("\nSize: "); sizePrint(mvFlashSizeGet(pFlash)," in "); mvOsOutput("%d Sectors\n",mvFlashNumOfSecsGet(pFlash)); mvOsOutput("Bus Width: %dbit, device Width: %dbit, type: ", (8 * mvFlashBusWidthGet(pFlash)), (8 * mvFlashDevWidthGet(pFlash))); switch (mvFlashSecTypeGet(pFlash)) { case TOP: mvOsOutput ("TOP"); break; case BOTTOM: mvOsOutput ("BOTTOM"); break; case REGULAR: mvOsOutput ("REGULAR"); break; default: mvOsOutput ("Unknown Type"); break; } mvOsOutput(".\n"); mvOsOutput (" Sector Start Addresses:"); for (i=0; i<mvFlashNumOfSecsGet(pFlash); ++i) { if ((i % 5) == 0) mvOsOutput ("\n "); mvOsOutput (" %08lX%s", (mvFlashSecOffsGet(pFlash, i) + mvFlashBaseAddrGet(pFlash)), mvFlashSecLockGet(pFlash,i) ? " (RO)" : " " ); } mvOsOutput("\n"); return; }
/******************************************************************************* * mvDramIfDetect - Prepare DRAM interface configuration values. * * DESCRIPTION: * This function implements the full DRAM detection and timing * configuration for best system performance. * Since this routine runs from a ROM device (Boot Flash), its stack * resides on RAM, that might be the system DRAM. Changing DRAM * configuration values while keeping vital data in DRAM is risky. That * is why the function does not preform the configuration setting but * prepare those in predefined 32bit registers (in this case IDMA * registers are used) for other routine to perform the settings. * The function will call for board DRAM SPD information for each DRAM * chip select. The function will then analyze those SPD parameters of * all DRAM banks in order to decide on DRAM configuration compatible * for all DRAM banks. * The function will set the CPU DRAM address decode registers. * Note: This routine prepares values that will overide configuration of * mvDramBasicAsmInit(). * * INPUT: * forcedCl - Forced CAL Latency. If equal to zero, do not force. * * OUTPUT: * None. * * RETURN: * None. * *******************************************************************************/ MV_STATUS mvDramIfDetect(MV_U32 forcedCl) { MV_U32 retVal = MV_OK; /* return value */ MV_DRAM_BANK_INFO bankInfo[MV_DRAM_MAX_CS]; MV_U32 busClk, size, base = 0, i, temp, deviceW, dimmW; MV_U8 minCas; MV_DRAM_DEC_WIN dramDecWin; dramDecWin.addrWin.baseHigh = 0; busClk = mvBoardSysClkGet(); if (0 == busClk) { mvOsPrintf("Dram: ERR. Can't detect system clock! \n"); return MV_ERROR; } /* Close DRAM banks except bank 0 (in case code is excecuting from it...) */ for(i= SDRAM_CS1; i <= SDRAM_CS3; i++) mvCpuIfTargetWinEnable(i, MV_FALSE); /* we will use bank 0 as the representative of the all the DRAM banks, */ /* since bank 0 must exist. */ for(i = 0; i < MV_DRAM_MAX_CS; i++) { /* if Bank exist */ if(MV_OK == mvDramBankInfoGet(i, &bankInfo[i])) { /* check it isn't SDRAM */ if(bankInfo[i].memoryType == MEM_TYPE_SDRAM) { mvOsPrintf("Dram: ERR. SDRAM type not supported !!!\n"); return MV_ERROR; } /* All banks must support registry in order to activate it */ if(bankInfo[i].registeredAddrAndControlInputs != bankInfo[0].registeredAddrAndControlInputs) { mvOsPrintf("Dram: ERR. different Registered settings !!!\n"); return MV_ERROR; } /* Init the CPU window decode */ /* Note that the size in Bank info is in MB units */ /* Note that the Dimm width might be different then the device DRAM width */ temp = MV_REG_READ(SDRAM_CONFIG_REG); deviceW = ((temp & SDRAM_DWIDTH_MASK) == SDRAM_DWIDTH_16BIT )? 16 : 32; dimmW = bankInfo[0].dataWidth - (bankInfo[0].dataWidth % 16); size = ((bankInfo[i].size << 20) / (dimmW/deviceW)); /* We can not change DRAM window settings while excecuting */ /* code from it. That is why we skip the DRAM CS[0], saving */ /* it to the ROM configuration routine */ if(i == SDRAM_CS0) { MV_U32 sizeToReg; /* Translate the given window size to register format */ sizeToReg = ctrlSizeToReg(size, SCSR_SIZE_ALIGNMENT); /* Size parameter validity check. */ if (-1 == sizeToReg) { mvOsPrintf("mvCtrlAddrDecToReg: ERR. Win %d size invalid.\n" ,i); return MV_BAD_PARAM; } /* Size is located at upper 16 bits */ sizeToReg <<= SCSR_SIZE_OFFS; /* enable it */ sizeToReg |= SCSR_WIN_EN; MV_REG_WRITE(DRAM_BUF_REG0, sizeToReg); } else { dramDecWin.addrWin.baseLow = base; dramDecWin.addrWin.size = size; dramDecWin.enable = MV_TRUE; if (MV_OK != mvDramIfWinSet(SDRAM_CS0 + i, &dramDecWin)) { mvOsPrintf("Dram: ERR. Fail to set bank %d!!!\n", SDRAM_CS0 + i); return MV_ERROR; } } base += size; /* update the suportedCasLatencies mask */ bankInfo[0].suportedCasLatencies &= bankInfo[i].suportedCasLatencies; } else { if( i == 0 ) /* bank 0 doesn't exist */ { mvOsPrintf("Dram: ERR. Fail to detect bank 0 !!!\n"); return MV_ERROR; } else { DB(mvOsPrintf("Dram: Could not find bank %d\n", i)); bankInfo[i].size = 0; /* Mark this bank as non exist */ } } } /* calculate minimum CAS */ minCas = minCasCalc(&bankInfo[0], busClk, forcedCl); if (0 == minCas) { mvOsOutput("Dram: Warn: Could not find CAS compatible to SysClk %dMhz\n", (busClk / 1000000)); if (MV_REG_READ(SDRAM_CONFIG_REG) & SDRAM_DTYPE_DDR2) { minCas = DDR2_CL_4; /* Continue with this CAS */ mvOsPrintf("Set default CAS latency 4\n"); } else { minCas = DDR1_CL_3; /* Continue with this CAS */ mvOsPrintf("Set default CAS latency 3\n"); } } /* calc SDRAM_CONFIG_REG and save it to temp register */ temp = sdramConfigRegCalc(&bankInfo[0], busClk); if(-1 == temp) { mvOsPrintf("Dram: ERR. sdramConfigRegCalc failed !!!\n"); return MV_ERROR; } MV_REG_WRITE(DRAM_BUF_REG1, temp); /* calc SDRAM_MODE_REG and save it to temp register */ temp = sdramModeRegCalc(minCas); if(-1 == temp) { mvOsPrintf("Dram: ERR. sdramModeRegCalc failed !!!\n"); return MV_ERROR; } MV_REG_WRITE(DRAM_BUF_REG2, temp); /* calc SDRAM_EXTENDED_MODE_REG and save it to temp register */ temp = sdramExtModeRegCalc(&bankInfo[0]); if(-1 == temp) { mvOsPrintf("Dram: ERR. sdramModeRegCalc failed !!!\n"); return MV_ERROR; } MV_REG_WRITE(DRAM_BUF_REG10, temp); /* calc D_UNIT_CONTROL_LOW and save it to temp register */ temp = dunitCtrlLowRegCalc(&bankInfo[0], minCas); if(-1 == temp) { mvOsPrintf("Dram: ERR. dunitCtrlLowRegCalc failed !!!\n"); return MV_ERROR; } MV_REG_WRITE(DRAM_BUF_REG3, temp); /* calc SDRAM_ADDR_CTRL_REG and save it to temp register */ temp = sdramAddrCtrlRegCalc(&bankInfo[0]); if(-1 == temp) { mvOsPrintf("Dram: ERR. sdramAddrCtrlRegCalc failed !!!\n"); return MV_ERROR; } MV_REG_WRITE(DRAM_BUF_REG4, temp); /* calc SDRAM_TIMING_CTRL_LOW_REG and save it to temp register */ temp = sdramTimeCtrlLowRegCalc(&bankInfo[0], minCas, busClk); if(-1 == temp) { mvOsPrintf("Dram: ERR. sdramTimeCtrlLowRegCalc failed !!!\n"); return MV_ERROR; } MV_REG_WRITE(DRAM_BUF_REG5, temp); /* calc SDRAM_TIMING_CTRL_HIGH_REG and save it to temp register */ temp = sdramTimeCtrlHighRegCalc(&bankInfo[0], busClk); if(-1 == temp) { mvOsPrintf("Dram: ERR. sdramTimeCtrlHighRegCalc failed !!!\n"); return MV_ERROR; } MV_REG_WRITE(DRAM_BUF_REG6, temp); /* Config DDR2 On Die Termination (ODT) registers */ if (MV_REG_READ(SDRAM_CONFIG_REG) & SDRAM_DTYPE_DDR2) { sdramDDr2OdtConfig(bankInfo); } /* Note that DDR SDRAM Address/Control and Data pad calibration */ /* settings is done in mvSdramIfConfig.s */ return retVal; }
/******************************************************************************* * mvNflashPrint - Print NAND flash information structure. * * DESCRIPTION: * Prints all the feilds in the NAND flash info structure. * * INPUT: * pFlash - Flash information. * * OUTPUT: * None * * RETURN: * None * *******************************************************************************/ MV_VOID mvNflashPrint(MV_NFLASH_INFO *pFlash) { int i, lockedBlocksFound = 0; NFLASH_LOCK_MODE lockMode; if (NULL == pFlash) { mvOsOutput ("Missing or unknown FLASH type\n"); return; } mvOsOutput ("NAND Flash information:\n"); mvOsOutput ("Manufacture: "); switch (pFlash->pNflashStruct->devVen) { case SAMSUNG_MANUF: mvOsOutput ("SAMSUNG\n"); break; default: mvOsOutput ("Unknown Vendor 0x%x\n", pFlash->pNflashStruct->devVen); break; } mvOsOutput ("Flash Type : "); switch (pFlash->pNflashStruct->devId) { case K9F5608Q0C: mvOsOutput ("K9F5608Q0C (x8-bit)\n"); break; case K9F5608D0C: mvOsOutput ("K9F5608D0C or K9F5608U0C(x8-bit)\n"); break; case K9F5616Q0C: mvOsOutput ("K9F5616Q0C (x16-bit)\n"); break; case K9F5616D0C: mvOsOutput ("K9F5616D0C or K9F5616U0C(x16-bit)\n"); break; default: mvOsOutput ("Unknown device id 0x%x\n", pFlash->pNflashStruct->devId); break; } mvOsOutput("Flash "); mvSizePrint(pFlash->pNflashStruct->size); mvOsOutput ("\n"); mvOsOutput("Flash base Address: 0x%x\n",pFlash->baseAddr); mvOsOutput("Flash device Width: %d.\n", pFlash->devWidth); mvOsOutput("Number of blocks: %d\n", pFlash->pNflashStruct->blockNum); mvOsOutput ("Block Start Addresses:"); for (i = 0; i < pFlash->pNflashStruct->blockNum; ++i) { lockMode = mvNflashBlockLockStsGet(pFlash,i); if (BLOCK_UNLOCK == lockMode) { continue; } lockedBlocksFound++; if ((i % 5) == 0) mvOsOutput ("\n "); mvOsOutput (" %08x %s", mvNflashBlkOffsGet(pFlash, i), (lockMode == BLOCK_LOCK) ? "Lock" : "Tight"); } mvOsOutput("\n"); mvOsOutput("Found %d Read only blocks\n", lockedBlocksFound); return; }
/******************************************************************************* * mvFlashInit - Initialize a flash descriptor structure. * * DESCRIPTION: * This function intialize flash info struct with specified flash * parameters. This structure is used to identify the target flash the * function refers to. This allow the use of the same API for multiple * flash devices. * * * INPUT: * pFlash->baseAddr - Flash base address. * pFlash->busWidth - Flash bus width (8, 16, 32 bit). * pFlash->devWidth - Flash device width (8 or 16 bit). * * OUTPUT: * pFlash - Flash identifier structure. * * RETURN: * 32bit describing flash size. * In case of any error, it returns 0. * *******************************************************************************/ MV_U32 mvFlashInit(MV_FLASH_INFO *pFlash) { MV_U32 manu = 0, id = 0; if(NULL == pFlash) return 0; DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n", pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth)); /* must init first sector base, before calling flashCmdSet */ pFlash->sector[0].baseOffs = 0; /* reset flash 0xf0(AMD) 0xff (Intel) */ flashCmdSet(pFlash, 0, 0, 0xf0); flashCmdSet(pFlash, 0, 0, 0xff); /* Write auto select command: read Manufacturer ID */ /* AMD seq is: 0x555 0xAA -> 0x2AA 0x55 -> 0x555 0x90 */ /* INTEL seq is dc 0x90 */ flashCmdSet(pFlash, 0x555, 0, 0xAA); flashCmdSet(pFlash, 0x2AA, 0, 0x55); flashCmdSet(pFlash, 0x555, 0, 0x90); /* Write auto select command: read Manufacturer ID */ /* SST seq is: 0x5555 0xAA -> 0x2AAA 0x55 -> 0x5555 0x90 */ flashCmdSet(pFlash, 0x5555, 0, 0xAA); flashCmdSet(pFlash, 0x2AAA, 0, 0x55); flashCmdSet(pFlash, 0x5555, 0, 0x90); DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n", pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth)); /* get flash Manufactor and Id */ manu = flashBusWidthRd(pFlash, mvFlashBaseAddrGet(pFlash)); DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n", pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth)); /* Some Micron flashes don't use A0 address for Identifier and Lock information, so in order to read Identifier and lock information properly we will do the following workarround: If our device width is 1 (x8) then if address 0 equal to address 1 and address 2 equal to address 3 ,then we have this case (A0 is not used) and then we will issue the address without A0 to read the Identifier and lock information properly*/ DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n", pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth)); if ((pFlash->devWidth == 1) && ((flashBusWidthRd(pFlash, flashAddrExt(pFlash, 0, 0)) == flashBusWidthRd(pFlash, flashAddrExt(pFlash, 1, 0)))&& (flashBusWidthRd(pFlash, flashAddrExt(pFlash, 2, 0)) == flashBusWidthRd(pFlash, flashAddrExt(pFlash, 3, 0))))) { id = flashBusWidthRd(pFlash, flashAddrExt(pFlash, 2, 0)); } else id = flashBusWidthRd(pFlash, flashAddrExt(pFlash, 1, 0)); /* check if this flash is Supported, and Init the pFlash flash feild */ if( MV_OK != flashStructGet(pFlash, manu, id ) ) { mvOsPrintf("%s: Flash ISN'T supported: manufactor-0x%x, id-0x%x\n", __FUNCTION__, manu, id); return 0; } DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n", pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth)); /* Init pFlash sectors */ if(MV_OK != flashSecsInit(pFlash)) { mvOsPrintf("Flash: ERROR mvFlashInit flashSecsInit failed \n"); return 0; } DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n", pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth)); /* print all flash information */ DB(flashPrint(pFlash)); /* reset the Flash */ flashReset(pFlash); DB(mvOsOutput("Flash: mvFlashInit base 0x%x devW %d busW %d\n", pFlash->baseAddr, pFlash->devWidth, pFlash->busWidth)); return mvFlashSizeGet(pFlash); }
/******************************************************************************* * mvUsbAddrDecShow - Print the USB address decode map. * * DESCRIPTION: * This function print the USB address decode map. * * INPUT: * None. * * OUTPUT: * None. * * RETURN: * None. * *******************************************************************************/ MV_VOID mvUsbAddrDecShow(MV_VOID) { MV_UNIT_WIN_INFO addrDecWin; int i, winNum; mvOsOutput( "\n" ); mvOsOutput( "USB:\n" ); mvOsOutput( "----\n" ); for(i=0; i<mvCtrlUsbMaxGet(); i++) { mvOsOutput( "Device %d:\n", i); for(winNum = 0; winNum < MV_USB_MAX_ADDR_DECODE_WIN; winNum++) { memset(&addrDecWin, 0, sizeof(MV_DEC_WIN) ); mvOsOutput( "win%d - ", winNum ); if( mvUsbWinRead(i, winNum, &addrDecWin ) == MV_OK ) { if( addrDecWin.enable ) { /* In MV88F6781 there is no differentiation between different DRAM Chip Selects, */ /* they all use the same target ID and attributes. So in order to print correctly */ /* we use i as the target. When i is 1 it is SDRAM_CS1 etc. */ if (mvCtrlTargetByWinInfoGet(&addrDecWin) != SDRAM_CS0) { mvOsOutput( "%s base %08x, ", mvCtrlTargetNameGet(mvCtrlTargetByWinInfoGet(&addrDecWin)), addrDecWin.addrWin.baseLow ); } else { mvOsOutput( "%s base %08x, ", mvCtrlTargetNameGet(winNum), addrDecWin.addrWin.baseLow); } mvSizePrint( addrDecWin.addrWin.size ); #if defined(MV645xx) || defined(MV646xx) switch( addrDecWin.addrWinAttr.swapType) { case MV_BYTE_SWAP: mvOsOutput( "BYTE_SWAP, " ); break; case MV_NO_SWAP: mvOsOutput( "NO_SWAP , " ); break; case MV_BYTE_WORD_SWAP: mvOsOutput( "BYTE_WORD_SWAP, " ); break; case MV_WORD_SWAP: mvOsOutput( "WORD_SWAP, " ); break; default: mvOsOutput( "SWAP N/A , " ); } switch( addrDecWin.addrWinAttr.cachePolicy ) { case NO_COHERENCY: mvOsOutput( "NO_COHERENCY , " ); break; case WT_COHERENCY: mvOsOutput( "WT_COHERENCY , " ); break; case WB_COHERENCY: mvOsOutput( "WB_COHERENCY , " ); break; default: mvOsOutput( "COHERENCY N/A, " ); } switch( addrDecWin.addrWinAttr.pcixNoSnoop ) { case 0: mvOsOutput( "PCI-X NS inactive, " ); break; case 1: mvOsOutput( "PCI-X NS active , " ); break; default: mvOsOutput( "PCI-X NS N/A , " ); } switch( addrDecWin.addrWinAttr.p2pReq64 ) { case 0: mvOsOutput( "REQ64 force" ); break; case 1: mvOsOutput( "REQ64 detect" ); break; default: mvOsOutput( "REQ64 N/A" ); } #endif /* MV645xx || MV646xx */ mvOsOutput( "\n" ); } else mvOsOutput( "disable\n" ); } } } }