initfuncs.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:54k
- /****************************************************************************
- File Name : initfuncs.c
- Description : Initialization functions, used incase of Boot from Flash.
- Copyright (C) 2004, ST Microelectronics
- ****************************************************************************/
- /* Includes ----------------------------------------------------------- */
- #include <initfuncs.h>
- #include "stsys.h"
- /*#include "reg.h"*/
- /* Private Types ------------------------------------------------------ */
- /* Private Constants -------------------------------------------------- */
- /* Private Variables -------------------------------------------------- */
- /* Private Macros ----------------------------------------------------- */
- /* --- TMTM needed to set options --->----------------------------------- */
- /*
- DDR = 133, CAS20
- = 166, CAS25
- SDR = 166, CAS30
- */
- #ifdef SELECT_DEVICE_STB5118
- #define SDRAM_CAS_3_0
- #define SDRAM_FREQ_CONFIG_166
- #define SDRAM_64MB
- #else
- #define DDR_SDRAM //undef means SDR_SDRAM
- #define SDRAM_CAS_2_0
- #define SDRAM_FREQ_CONFIG_133
- #define SDRAM_256MB
- #endif
- //TMTM choose ONLY 1
- //#define SDRAM_64MB
- //#define SDRAM_128MB
- //#define SDRAM_256MB
- //#define SDRAM_512MB
- /* <--- TMTM needed to set options --------------------------------------- */
- #define INPUT_CLOCK_FREQUENCY 27000 /* Input clock frequency in KHz */
- #define MIN_PLL_FREQUENCY 10000 /* Value minimum of PLL Frequency in KHz */
- #define MAX_PLL_FREQUENCY 6800000 /* Value maximum of PLL Frequency in KHz */
- #define PLL_A 0
- #define PLL_B 1
- #define PLL_A_FREQUENCY 400000
- //TMTM for 133sdram #define PLL_B_FREQUENCY 533000 //TMTM 592000
- #ifdef SDRAM_FREQ_CONFIG_133
- #define PLL_B_FREQUENCY 533000
- #elif defined (SDRAM_FREQ_CONFIG_120)
- #define PLL_B_FREQUENCY 480000
- #elif defined (SDRAM_FREQ_CONFIG_166)
- #define PLL_B_FREQUENCY 664000 //TMTM 600000
- #endif
- #define CPU_DIV 2
- #define LMI_DIV 4
- #ifdef SELECT_DEVICE_CUT3_0 //KCY 060823
- #define BLITTER_DIV 3 //Blitter clock change back to 133Mhz
- #else
- #define BLITTER_DIV 4 //KCY 060622 Blitter clock 100MHz To fix OSD garbage/white spot noise issue
- #endif
- #define FDMA_DIV 2
- #define SYSTEM_DIV 4
- #define AUDIO_VIDEO_DIV 8
- #define FLASH_DIV 4 /* FLASH source is the same as LS_INTERCONECT */
- #define CPU_SOURCE PLL_A
- #define LMI_SOURCE PLL_B
- #define BLITTER_SOURCE PLL_A
- #define FDMA_SOURCE PLL_A
- #define SYSTEM_SOURCE PLL_A
- #define AUDIO_VIDEO_SOURCE PLL_A
- #define SYS_SERVICES_BASE_ADDRESS 0x20F00000
- #define CKG_PLLA_CONFIG0 (SYS_SERVICES_BASE_ADDRESS + 0x00)
- #define CKG_PLLA_CONFIG1 (SYS_SERVICES_BASE_ADDRESS + 0x04)
- #define CKG_PLLB_CONFIG0 (SYS_SERVICES_BASE_ADDRESS + 0x08)
- #define CKG_PLLB_CONFIG1 (SYS_SERVICES_BASE_ADDRESS + 0x0C)
- #define CKG_FSA_SETUP (SYS_SERVICES_BASE_ADDRESS + 0x10)
- #define CKG_PCM_CLK_SETUP0 (SYS_SERVICES_BASE_ADDRESS + 0x20)
- #define CKG_PCM_CLK_SETUP1 (SYS_SERVICES_BASE_ADDRESS + 0x24)
- #define CKG_SPDIF_CLK_SETUP0 (SYS_SERVICES_BASE_ADDRESS + 0x30)
- #define CKG_SPDIF_CLK_SETUP1 (SYS_SERVICES_BASE_ADDRESS + 0x34)
- #define CKG_SC_CLK_SETUP0 (SYS_SERVICES_BASE_ADDRESS + 0x40)
- #define CKG_SC_CLK_SETUP1 (SYS_SERVICES_BASE_ADDRESS + 0x44)
- #define CKG_PIX_CLK_SETUP0 (SYS_SERVICES_BASE_ADDRESS + 0x54)
- #define CKG_PIX_CLK_SETUP1 (SYS_SERVICES_BASE_ADDRESS + 0x58)
- #define CKG_FDMA_CLK_SETUP0 (SYS_SERVICES_BASE_ADDRESS + 0x70)
- #define CKG_FDMA_CLK_SETUP1 (SYS_SERVICES_BASE_ADDRESS + 0x74)
- #define CKG_AUX_CLK_SETUP0 (SYS_SERVICES_BASE_ADDRESS + 0x70)
- #define CKG_AUX_CLK_SETUP1 (SYS_SERVICES_BASE_ADDRESS + 0x74)
- #define CKG_MODE_CONTROL (SYS_SERVICES_BASE_ADDRESS + 0x110)
- #define CKG_CLOCK_SELECT_CFG (SYS_SERVICES_BASE_ADDRESS + 0x180)
- #define CKG_REGISTER_LOCK_CFG (SYS_SERVICES_BASE_ADDRESS + 0x300)
- #define CKG_OBSERVATION_CFG_AUX (SYS_SERVICES_BASE_ADDRESS + 0x188)
- #define CKG_FSB_SETUP (SYS_SERVICES_BASE_ADDRESS + 0x050)
- /* kc-060112am */
- #define REDUCED_POWER_CTRL (SYS_SERVICES_BASE_ADDRESS + 0x114)
- #define LP_MODE_DIS0 (SYS_SERVICES_BASE_ADDRESS + 0x118)
- #define LP_MODE_DIS1 (SYS_SERVICES_BASE_ADDRESS + 0x11C)
- #define LP_MODE_COUNTER_CFG0 (SYS_SERVICES_BASE_ADDRESS + 0x120)
- #define LP_MODE_COUNTER_CFG1 (SYS_SERVICES_BASE_ADDRESS + 0x124)
- #define WATCHDOG_COUNTER_CFG0 (SYS_SERVICES_BASE_ADDRESS + 0x130)
- #define WATCHDOG_COUNTER_CFG1 (SYS_SERVICES_BASE_ADDRESS + 0x134)
- #define CKG_RESET_STATUS (SYS_SERVICES_BASE_ADDRESS + 0x140)
- #define CPU 1
- #define LMI 2
- #define BLITTER 3
- #define SYSTEM 4
- #define FDMA 5
- #define AUDIO_VIDEO 6
- #define FLASH 8
- #define HALF_VALUE 1
- #define WHOLE_VALUE 0
- #define LMI_BASE_ADDRESS 0xC0000000
- #define LMICONFIG_BASE_ADDRESS 0xE0000000
- #define LMI_VCR0 (LMICONFIG_BASE_ADDRESS + 0x00)
- #define LMI_VCR1 (LMICONFIG_BASE_ADDRESS + 0x04)
- #define LMI_MIM (LMICONFIG_BASE_ADDRESS + 0x08)
- #define LMI_SCR (LMICONFIG_BASE_ADDRESS + 0x10)
- #define LMI_STR (LMICONFIG_BASE_ADDRESS + 0x18)
- #define LMI_PBS (LMICONFIG_BASE_ADDRESS + 0x20)
- #define LMI_COC_LOWER (LMICONFIG_BASE_ADDRESS + 0x28)
- #define LMI_COC_UPPER (LMICONFIG_BASE_ADDRESS + 0x2C)
- #define LMI_CIC (LMICONFIG_BASE_ADDRESS + 0x40)
- #define LMI_SDRA0 (LMICONFIG_BASE_ADDRESS + 0x30)
- #define LMI_SDRA1 (LMICONFIG_BASE_ADDRESS + 0x38)
- #define LMI_SDMR0 (LMICONFIG_BASE_ADDRESS + 0x48)
- #define LMI_SDMR1 (LMICONFIG_BASE_ADDRESS + 0x50)
- #define FMICONFIG_BASE_ADDRESS (0x20200000)
- #define FMICONFIG_BUFFER_BASE_ADDRESS (0x202FF800)
- #define FMICONFIGDATA0_BANK0 (FMICONFIG_BASE_ADDRESS + 0x100)
- #define FMICONFIGDATA1_BANK0 (FMICONFIG_BASE_ADDRESS + 0X108)
- #define FMICONFIGDATA2_BANK0 (FMICONFIG_BASE_ADDRESS + 0X110)
- #define FMICONFIGDATA3_BANK0 (FMICONFIG_BASE_ADDRESS + 0X118)
- #define FMICONFIGDATA0_BANK1 (FMICONFIG_BASE_ADDRESS + 0X140)
- #define FMICONFIGDATA1_BANK1 (FMICONFIG_BASE_ADDRESS + 0X148)
- #define FMICONFIGDATA2_BANK1 (FMICONFIG_BASE_ADDRESS + 0X150)
- #define FMICONFIGDATA3_BANK1 (FMICONFIG_BASE_ADDRESS + 0X158)
- #define FMICONFIGDATA0_BANK2 (FMICONFIG_BASE_ADDRESS + 0X180)
- #define FMICONFIGDATA1_BANK2 (FMICONFIG_BASE_ADDRESS + 0X188)
- #define FMICONFIGDATA2_BANK2 (FMICONFIG_BASE_ADDRESS + 0X190)
- #define FMICONFIGDATA3_BANK2 (FMICONFIG_BASE_ADDRESS + 0X198)
- #define FMICONFIGDATA0_BANK3 (FMICONFIG_BASE_ADDRESS + 0X1C0)
- #define FMICONFIGDATA1_BANK3 (FMICONFIG_BASE_ADDRESS + 0X1C8)
- #define FMICONFIGDATA2_BANK3 (FMICONFIG_BASE_ADDRESS + 0X1D0)
- #define FMICONFIGDATA3_BANK3 (FMICONFIG_BASE_ADDRESS + 0X1D8)
- #define FMI_STATUSCFG (FMICONFIG_BASE_ADDRESS + 0X010)
- #define FMI_STATUSLOCK (FMICONFIG_BASE_ADDRESS + 0X018)
- #define FMI_LOCK (FMICONFIG_BASE_ADDRESS + 0X020)
- #define FMI_GENCFG (FMICONFIG_BASE_ADDRESS + 0X028)
- #define FMI_FLASHCLKSEL (FMICONFIG_BASE_ADDRESS + 0X050)
- #define FMI_CLKENABLE (FMICONFIG_BASE_ADDRESS + 0X068)
- #define BANK_0_TOP_ADDRESS (FMICONFIG_BUFFER_BASE_ADDRESS + 0x20)
- #define BANK_1_TOP_ADDRESS (FMICONFIG_BUFFER_BASE_ADDRESS + 0x30)
- #define BANK_2_TOP_ADDRESS (FMICONFIG_BUFFER_BASE_ADDRESS + 0x40)
- #define BANK_3_TOP_ADDRESS (FMICONFIG_BUFFER_BASE_ADDRESS + 0x50)
- #define BANKS_ENABLED (FMICONFIG_BUFFER_BASE_ADDRESS + 0x60)
- #define FLASH_EPLD_FLASH 0x45200000
- #define CONFIG_CONTROL_BASEADDRESS (0x20402000)
- #define CONFIG_CONTROL_C (CONFIG_CONTROL_BASEADDRESS+0x0)
- #define CONFIG_CONTROL_D (CONFIG_CONTROL_BASEADDRESS+0X4)
- #define CONFIG_CONTROL_E (CONFIG_CONTROL_BASEADDRESS+0x8)
- #define CONFIG_CONTROL_F (CONFIG_CONTROL_BASEADDRESS+0XC)
- #define CONFIG_CONTROL_G (CONFIG_CONTROL_BASEADDRESS+0X10)
- #define CONFIG_CONTROL_H (CONFIG_CONTROL_BASEADDRESS+0X14)
- /* Private Function prototypes ---------------------------------------- */
- /* Functions ---------------------------------------------------------- */
- static void Simudelay(int);
- #pragma ST_nolink(Simudelay)
- static void ST_5105_InitClocks(void);
- #pragma ST_nolink(ST_5105_InitClocks)
- static void ST_5105_InitPLLFrequency(U32 PLLFrequency, U32 PLLSource);
- #pragma ST_nolink(ST_5105_InitPLLFrequency)
- static void ST_5105_SetupDividers(void);
- #pragma ST_nolink(ST_5105_SetupDividers)
- static void ST_5105_SetupFrequencySynthesizer(void);
- #pragma ST_nolink(ST_5105_SetupFrequencySynthesizer)
- static void ST_5105_SetPLLClockDivider(U32 clock, U32 div, U32 half, U32 source, S32 phase);
- #pragma ST_nolink(ST_5105_SetPLLClockDivider)
- static void ST_5105_IniLMI_Cas20(void);
- #pragma ST_nolink(ST_5105_IniLMI_Cas20)
- static void ST_5105_IniLMI_Cas25(void);
- #pragma ST_nolink(ST_5105_IniLMI_Cas25)
- static void ST_5105_InitFMI(void);
- #pragma ST_nolink(ST_5105_InitFMI)
- /****leslie***/
- static void ST_5105_IniLMI_PC_SDRAM(void);
- #pragma ST_nolink(ST_5105_IniLMI_PC_SDRAM)
- static void ST_5105_IniLMI_Reg(void);
#pragma ST_nolink(ST_5105_IniLMI_Reg)
- /*****************/
- /* Functions -------------------------------------------------------------- */
- /*-------------------------------------------------------------------------
- * Function : PostPokeLoopCallback
- * Input : None
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- void PostPokeLoopCallback(void)
- {
- }
- /*-------------------------------------------------------------------------
- * Function : PrePokeLoopCallback
- * Input : None
- * Output :
- * Return : None
- * Comment : Function automatically called after the poke loop
- * ----------------------------------------------------------------------*/
- void PrePokeLoopCallback(void)
- {
- volatile U32 x;
- /* Set up the PLL's */
- ST_5105_InitClocks ();
- #ifdef DDR_SDRAM
- #ifdef SDRAM_CAS_2_0
- ST_5105_IniLMI_Cas20 ();
- #else //assume CAS25
- ST_5105_IniLMI_Cas25 ();
- #endif
- #else
- ST_5105_IniLMI_PC_SDRAM ();
- #endif
- /* Configure FMI */
- ST_5105_InitFMI ();
- /* Default setup for configuration registers */
- x = STSYS_ReadRegDev32LE(CONFIG_CONTROL_D);
- #if 1 /* KCY 060912 */
- STSYS_WriteRegDev32LE(CONFIG_CONTROL_D, ((x) & 0xFCFFE1FF));
- #else
- STSYS_WriteRegDev32LE(CONFIG_CONTROL_D, ((x) & 0xFFFFE1FF));
- #endif
- x = STSYS_ReadRegDev32LE(CONFIG_CONTROL_H);
- STSYS_WriteRegDev32LE(CONFIG_CONTROL_H, ((x) | 0x0C000000));
-
- }
- /*-------------------------------------------------------------------------
- * Function : Simudelay
- * Input : delay
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void Simudelay(int delay)
- {
- volatile int j,dummy;
- for ( j = 0 ; j < delay ; j ++ )
- dummy = STSYS_ReadRegDev32LE(0x007C);
- }
- /*-------------------------------------------------------------------------
- * Function : ST_5105_InitClocks
- * Input : None
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void ST_5105_InitClocks (void)
- {
- volatile U32 Source,
- LockA,
- LockB,
- count = 0,
- x,y;
- x = STSYS_ReadRegDev32LE(CKG_MODE_CONTROL);
- x = STSYS_ReadRegDev32LE(CKG_PLLA_CONFIG0);
- x = STSYS_ReadRegDev32LE(CKG_PLLB_CONFIG0);
- /* Starting clock generator setup */
- /* Unlock clockgen registers */
- STSYS_WriteRegDev32LE(CKG_REGISTER_LOCK_CFG, 0x00F0);
- STSYS_WriteRegDev32LE(CKG_REGISTER_LOCK_CFG, 0x000F);
- /* Setup the PLL sources for clock */
- Source = (AUDIO_VIDEO_SOURCE << 7) | (LMI_SOURCE << 6) | (FDMA_SOURCE << 5);
- Source = (Source) | (SYSTEM_SOURCE << 4) | (BLITTER_SOURCE << 3) | (LMI_SOURCE << 2);
- Source = (Source) | (CPU_SOURCE << 1);
- STSYS_WriteRegDev32LE(CKG_CLOCK_SELECT_CFG, Source);
- #if 0
- /* Setup PLL_A and PLL_B */
- ST_5105_InitPLLFrequency(PLL_A_FREQUENCY, PLL_A);
- ST_5105_InitPLLFrequency(PLL_B_FREQUENCY, PLL_B);
- /* set FS post divider to further reduce pll op
- ** poke 0x20013004 0x00002938
- */
- /* wait for PLL to settle and lock*/
- Simudelay (100000);
- #else
- /* GNBvd42626 Resolution : Booting time would be
- reduced from 13-14 seconds to 5-6sec/133*/
- #ifdef SDRAM_FREQ_CONFIG_133
- STSYS_WriteRegDev32LE(CKG_PLLA_CONFIG0,0x02404);
- STSYS_WriteRegDev32LE(CKG_PLLA_CONFIG1,0x04838);
- Simudelay (1000);
- STSYS_WriteRegDev32LE(CKG_PLLB_CONFIG0,0x04406);
- STSYS_WriteRegDev32LE(CKG_PLLB_CONFIG1,0x04838);
- Simudelay (200000);
- #elif defined (SDRAM_FREQ_CONFIG_166) /*3-4sec*/
- STSYS_WriteRegDev32LE(CKG_PLLA_CONFIG0,0x02404);
- STSYS_WriteRegDev32LE(CKG_PLLA_CONFIG1,0x04838);
- Simudelay (1000);
- STSYS_WriteRegDev32LE(CKG_PLLB_CONFIG0,0x05506); //0x0AC07;0x0b80f
- STSYS_WriteRegDev32LE(CKG_PLLB_CONFIG1,0x04838); //9
- Simudelay (200000);
- #endif
- #endif
- ST_5105_SetupDividers();
- ST_5105_SetupFrequencySynthesizer();
- /* Check PLL_A and PLL_B has locked*/
- LockA = 0;
- LockB = 0;
- count = 0;
- if (count == 0)
- {
- while (count < 20 && ((LockA == 0) || (LockB == 0)))
- {
- x = STSYS_ReadRegDev32LE(CKG_PLLA_CONFIG1);
- y = STSYS_ReadRegDev32LE(CKG_PLLB_CONFIG1);
- if ((x & 0x4000) == 0x4000) LockA = 1; /* Check for PLL_A Lock */
- if ((y & 0x4000) == 0x4000) LockB = 1; /* Check for PLL_B Lock */
- count++;
- }
- if (LockA == 0)
- {
- /* write PLL_A failed to LOCK! */
- return;
- }
- if (LockB == 0)
- {
- /* write PLL_B failed to LOCK! */
- return;
- }
- }
- Simudelay (1000);
- /* Now Transistion to programmed mode */
- STSYS_WriteRegDev32LE(CKG_MODE_CONTROL, 0x02);
- Simudelay (1000);
- /* Lock Clock Generator registers */
- STSYS_WriteRegDev32LE(CKG_OBSERVATION_CFG_AUX, 0x20);
- }
- /*-------------------------------------------------------------------------
- * Function : ST_5105_InitPLLFrequency
- * Input : PLLFrequency, PLLSource
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void ST_5105_InitPLLFrequency ( U32 PLLFrequency, U32 PLLSource )
- {
- volatile U32 Pfactor,
- Divider,
- Reminder,
- StoredReminder,
- Index,
- IndexMax,
- tmp,
- Nfactor,
- Mfactor,
- tmp1,
- tmp2;
- if ((PLLFrequency < MIN_PLL_FREQUENCY) || (PLLFrequency > MAX_PLL_FREQUENCY))
- {
- /* --> Invalid PLL Frequency : (PLLFrequency) Mhz */
- return;
- }
- if ((MIN_PLL_FREQUENCY <= PLLFrequency) && (PLLFrequency <=300000))
- {
- /*
- ** Pfactor = 1, Fvco = 2 * Fpll
- ** in this case Fpll = (Nfactor/Mfactor) * Fclockin (Fclockin is 27 MHz)
- ** so Nfactor = (Fpll * Mfactor) / Fclockin
- */
- Pfactor = 1;
- Divider = 1;
- }
- if ((300000 <= PLLFrequency) && (PLLFrequency <= MAX_PLL_FREQUENCY))
- {
- /*
- ** Pfactor = 0, Fvco = Fpll
- ** in this case Fpll = (2*Nfactor/Mfactor) * Fclockin (Fclockin is 27 MHz)
- ** so Nfactor = (Fpll * Mfactor) / (2*Fclockin)
- */
- Pfactor = 0;
- Divider = 2;
- }
- StoredReminder = 100000;
- IndexMax = 27;
- for(Index = 5; Index <= IndexMax; Index++)
- {
- #if 0
- Reminder = (PLLFrequency*Index) % (INPUT_CLOCK_FREQUENCY*Divider);
- tmp = (PLLFrequency*Index) / (INPUT_CLOCK_FREQUENCY*Divider);
- #else
- tmp = 0;
- Reminder = (PLLFrequency*Index);
- while(Reminder > (INPUT_CLOCK_FREQUENCY*Divider))
- {
- Reminder = Reminder - (INPUT_CLOCK_FREQUENCY*Divider);
- tmp = tmp + 1;
- }
- #endif
- if ((Reminder == 0) && (tmp < 126))
- {
- Mfactor = Index;
- Nfactor = tmp;
- Index = 100;
- }
- if (Reminder > Index)
- {
- if ((Reminder - Index < StoredReminder) && (tmp < 126) && (Reminder != 0))
- {
- StoredReminder = Reminder;
- Mfactor = Index;
- Nfactor = tmp;
- }
- }
- else
- {
- if ((Index - Reminder < StoredReminder) && (tmp < 126) && (Reminder != 0))
- {
- StoredReminder = Reminder;
- Mfactor = Index;
- Nfactor = tmp;
- }
- }
- }
- #if 0
- PLLFrequency = (Divider*Nfactor*INPUT_CLOCK_FREQUENCY)/Mfactor;
- #else
- tmp1 = 0;
- tmp2 = (Divider*Nfactor*INPUT_CLOCK_FREQUENCY);
- while (tmp2 > 1000000)
- {
- tmp2 = tmp2- Mfactor;
- tmp1++;
- }
- PLLFrequency = tmp1;
- #endif
- if (PLLSource == PLL_A)
- {
- STSYS_WriteRegDev32LE(CKG_PLLA_CONFIG0, (((Nfactor-1)<<8) | (Mfactor-1)));
- STSYS_WriteRegDev32LE(CKG_PLLA_CONFIG1, (0x4838 | Pfactor));
- }
- if (PLLSource == PLL_B)
- {
- STSYS_WriteRegDev32LE(CKG_PLLB_CONFIG0, (((Nfactor-1)<<8) | (Mfactor-1)));
- STSYS_WriteRegDev32LE(CKG_PLLB_CONFIG1, (0x4838 | Pfactor));
- }
- Simudelay (50);
- }
- /*-------------------------------------------------------------------------
- * Function : ST_5105_SetupDividers
- * Input : None
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void ST_5105_SetupDividers(void)
- {
- /* Setup PLL dividers for STi5100 chip */
- ST_5105_SetPLLClockDivider(CPU, CPU_DIV, WHOLE_VALUE, CPU_SOURCE, 0);
- ST_5105_SetPLLClockDivider(LMI, LMI_DIV, WHOLE_VALUE, LMI_SOURCE, 0);
- ST_5105_SetPLLClockDivider(BLITTER, BLITTER_DIV, WHOLE_VALUE, BLITTER_SOURCE, 0);
- ST_5105_SetPLLClockDivider(SYSTEM, SYSTEM_DIV, WHOLE_VALUE, SYSTEM_SOURCE, 0);
- ST_5105_SetPLLClockDivider(FDMA, FDMA_DIV, WHOLE_VALUE, FDMA_SOURCE, 0);
- ST_5105_SetPLLClockDivider(AUDIO_VIDEO, AUDIO_VIDEO_DIV, WHOLE_VALUE, AUDIO_VIDEO_SOURCE, 0);
- ST_5105_SetPLLClockDivider(FLASH, FLASH_DIV, WHOLE_VALUE, SYSTEM_SOURCE, 0);
- }
- /*-------------------------------------------------------------------------
- * Function : ST_5105_SetupFrequencySynthesizer
- * Input : None
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void ST_5105_SetupFrequencySynthesizer(void)
- {
- volatile U32 x,
- MD,SDIV,PE,EN_PRG;
- /* Setup PLL Frequency Synthesizers for STi5100 chip */
- STSYS_WriteRegDev32LE(CKG_FSA_SETUP, 0xc); /*For abnormal audio upon power up*/
- STSYS_WriteRegDev32LE(CKG_FSA_SETUP, 0x4);
- MD = 0x1f;
- SDIV = 0x2;
- PE = 0x0000;
- EN_PRG = 0x1;
- /* Pixel clock = 27 MHz */
- STSYS_WriteRegDev32LE(CKG_PIX_CLK_SETUP0, (0xE00 | (SDIV)<<6 | (EN_PRG<<5) | (MD)));
- STSYS_WriteRegDev32LE(CKG_PIX_CLK_SETUP1, (PE));
- x = STSYS_ReadRegDev32LE (CKG_PIX_CLK_SETUP0);
- /* PCM clock = 24.576 MHz */
- STSYS_WriteRegDev32LE(CKG_PCM_CLK_SETUP0, 0x0ef1);
- STSYS_WriteRegDev32LE(CKG_PCM_CLK_SETUP1, 0x3600);
- /* SPDIF clock = 27 MHz */
- STSYS_WriteRegDev32LE(CKG_SPDIF_CLK_SETUP0, 0x0EBF);
- STSYS_WriteRegDev32LE(CKG_SPDIF_CLK_SETUP1, 0x0000);
- /* Smart Card clock = 27 MHz */
- STSYS_WriteRegDev32LE(CKG_SC_CLK_SETUP0, 0x0EBF);
- STSYS_WriteRegDev32LE(CKG_SC_CLK_SETUP1, 0x0000);
- /* AUX clock = 27 MHz */
- STSYS_WriteRegDev32LE(CKG_AUX_CLK_SETUP0, 0x0EBF);
- STSYS_WriteRegDev32LE(CKG_AUX_CLK_SETUP1, 0x0000);
- /*FSB setup to toggle the power up and power down on FSB PLL*/
- STSYS_WriteRegDev32LE(CKG_FSB_SETUP, 0xc);
- STSYS_WriteRegDev32LE(CKG_FSB_SETUP, 0x4);
- }
- /*-------------------------------------------------------------------------
- * Function : ST_5105_SetPLLClockDivider
- * Input : None
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void ST_5105_SetPLLClockDivider( U32 clock, U32 div, U32 half, U32 source, S32 phase )
- {
- volatile U32 PLL,
- config_0,
- config_1,
- config_2,
- PLL_MHz_x10,
- div_x10,
- depth,
- pattern,
- bpat,
- temptoppat,
- newpat,
- offset,
- tmp1,
- tmp2;
- /*
- * If phase is not passed in Function Call it must be Zero
- * phase=0; Handled in Fn Call itself
- */
- if (source == PLL_A)
- {
- PLL = PLL_A_FREQUENCY*1000;
- }
- else
- {
- PLL = PLL_B_FREQUENCY*1000;
- }
- offset = (clock * 0x10);
- config_0 = 0;
- config_1 = 0;
- config_2 = 0;
- switch ( div )
- {
- case 2:
- if (half==WHOLE_VALUE) /* divide by 2 */
- {
- config_0 = 0x0AAA;
- config_2 = 0x0071;
- }
- else if (half==HALF_VALUE) /* divide by 2.5 */
- {
- config_0 = 0x5AD6;
- config_2 = 0x0054;
- }
- break;
- case 3:
- if (half==WHOLE_VALUE) /* divide by 3 */
- {
- config_0 = 0x0DB6;
- config_2 = 0x0011;
- }
- else if (half==HALF_VALUE) /* divide by 3.5 */
- {
- config_0 = 0x366C;
- config_2 = 0x0053;
- }
- break;
- case 4:
- if (half==WHOLE_VALUE) /* divide by 4 */
- {
- config_0 = 0xCCCC;
- config_2 = 0x0075;
- }
- else if (half==HALF_VALUE) /* divide by 4.5 */
- {
- config_0 = 0x399C;
- config_1 = 0x0003;
- config_2 = 0x0057;
- }
- break;
- case 5:
- if (half==WHOLE_VALUE) /* divide by 5 */
- {
- config_0 = 0x739c;
- config_2 = 0x0014;
- }
- else if (half==HALF_VALUE) /* divide by 5.5 */
- {
- config_0 = 0x071C;
- config_2 = 0x0050;
- }
- break;
- case 6:
- if (half==WHOLE_VALUE) /* divide by 6 */
- {
- config_0 = 0x0E38;
- config_2 = 0x0071;
- }
- else if (half==HALF_VALUE) /* divide by 6.5 */
- {
- config_0 = 0x1C78;
- config_2 = 0x0052;
- }
- break;
- case 7:
- if (half==WHOLE_VALUE) /* divide by 7 */
- {
- config_0 = 0x3C78;
- config_2 = 0x0013;
- }
- else if (half==HALF_VALUE) /* divide by 7.5 */
- {
- config_0 = 0x7878;
- config_2 = 0x0054;
- }
- break;
- case 8:
- if (half==WHOLE_VALUE) /* divide by 8 */
- {
- config_0 = 0xF0F0;
- config_2 = 0x0075;
- }
- else if (half==HALF_VALUE) /* divide by 8.5 */
- {
- config_0 = 0xE1F0;
- config_1 = 0x0001;
- config_2 = 0x0056;
- }
- break;
- case 9:
- if (half==WHOLE_VALUE) /* divide by 9 */
- {
- config_0 = 0xE1F0;
- config_1 = 0x0003;
- config_2 = 0x0017;
- }
- else if (half==HALF_VALUE) /* divide by 9.5 */
- {
- config_0 = 0xC1F0;
- config_1 = 0x0007;
- config_2 = 0x0058;
- }
- break;
- case 10:
- if (half==WHOLE_VALUE) /* divide by 10 */
- {
- config_0 = 0x83e0;
- config_1 = 0x000f;
- config_2 = 0x0079;
- }
- break;
- case 11:
- if (half==WHOLE_VALUE) /* divide by 11 */
- {
- config_0 = 0x07e0;
- config_2 = 0x0010;
- }
- break;
- case 12:
- if (half==WHOLE_VALUE) /* divide by 12 */
- {
- config_0 = 0x0fc0;
- config_2 = 0x0071;
- }
- break;
- case 13:
- if (half==WHOLE_VALUE) /* divide by 13 */
- {
- config_0 = 0x1FC0;
- config_2 = 0x0012;
- }
- break;
- case 14:
- if (half==WHOLE_VALUE) /* divide by 14 */
- {
- config_0 = 0x3F80;
- config_2 = 0x0073;
- }
- break;
- case 15:
- if (half==WHOLE_VALUE) /* divide by 15 */
- {
- config_0 = 0x7F80;
- config_2 = 0x0014;
- }
- break;
- case 16:
- if (half==WHOLE_VALUE) /* divide by 16 */
- {
- config_0 = 0xFF00;
- config_1 = 0x0000;
- config_2 = 0x0015;
- }
- break;
- case 17:
- if (half==WHOLE_VALUE) /* divide by 17 */
- {
- config_0 = 0xFF00;
- config_1 = 0x0001;
- config_2 = 0x0016;
- }
- break;
- case 18:
- if (half==WHOLE_VALUE) /* divide by 18 */
- {
- config_0 = 0xFE00;
- config_1 = 0x0003;
- config_2 = 0x0077;
- }
- break;
- case 19:
- if (half==WHOLE_VALUE) /* divide by 19 */
- {
- config_0 = 0xFE00;
- config_1 = 0x0007;
- config_2 = 0x0018;
- }
- break;
- case 20:
- if (half==WHOLE_VALUE) /* divide by 20 */
- {
- config_0 = 0xFC00;
- config_1 = 0x000F;
- config_2 = 0x0019;
- }
- break;
- }
- if (config_0 == 0)
- {
- /* Divider value (div) not supported for module (names[clock]) */
- return;
- }
- /*write (names[clock]) = (PLL / ( div)) Hz*/
- /* Re-adjust PLL and div to allow for half value division using integers. */
- #if 0
- PLL_MHz_x10 = (PLL / 1000000) * 10;
- #else
- tmp1 = 0;
- tmp2 = PLL;
- while (tmp2 > 1000000)
- {
- tmp2 = tmp2- 1000000;
- tmp1++;
- }
- PLL_MHz_x10 = (tmp1) * 10;
- #endif
- if (half==(WHOLE_VALUE))
- {
- div_x10 = div * 10; /* whole value x10 */
- }
- else
- {
- div_x10 = (div * 10) + 5; /* half value x10 */
- }
- if (phase > 0)
- {
- /* Calculate the depth of the pattern */
- depth = (config_2 & 0x0f) + 11;
- /* 32-bit field pattern */
- pattern = config_0 | (config_1 << 16);
- /* Shifted Pattern */
- bpat = pattern >> phase;
- /* Bits of the pattern needed to be rapped */
- temptoppat = pattern & ((1 << phase)-1);
- newpat = bpat | (temptoppat << (depth - phase));
- config_0 = newpat & 0xffff;
- config_1 = newpat >> 16;
- }
- else if (phase < 0)
- {
- phase = 0-phase;
- /* Calculate the depth of the pattern */
- depth = (config_2 & 0x0f) + 11;
- /* 32-bit field pattern */
- pattern = config_0 | (config_1 << 16);
- /* Shifted Pattern */
- bpat = (pattern << phase) & ((1 << depth)-1);
- /* Bits of the pattern needed to be rapped */
- temptoppat = pattern >> (depth - phase);
- newpat = bpat | temptoppat;
- config_0 = newpat & 0xffff;
- config_1 = newpat >> 16;
- }
- STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x80 + offset, config_0);
- STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x84 + offset, config_1);
- STSYS_WriteRegDev32LE(SYS_SERVICES_BASE_ADDRESS + 0x88 + offset, config_2);
- }
- /*-------------------------------------------------------------------------
- * Function : ST_5105_IniLMI_Cas20
- * Input : None
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void ST_5105_IniLMI_Cas20(void)
- {
- volatile U32 data;
- /* "n Configuring LMI for 16-bit data CAS 2.0 @ 133MHz " */
- /* Set LMI_COC_UPPER Register, bits [63:32] (LMI Pad logic) */
- STSYS_WriteRegDev32LE(LMI_COC_UPPER, 0x000C6750);
- /* Even Though its a 64 bit register the upper 32 bits are reserved and therefore no need to fill*/
- /* Set LMI_COC_LOWER Register, bits [31:0] (LMI Pad logic)
- ** Bits [19:18] Compensation mode DDR
- ** Bits [17:16] Pad strenght (0x0:5pF, 0x1:15pF, 0x2:25pF, Ox3:35pF)
- ** Bits [15:14] output Impedance (0x0:25Ohm, 0x1:40Ohm, 0x2:55Ohm, Ox3:70Ohm)
- ** Bit [13] DLL preset reset value enable
- */
- STSYS_WriteRegDev32LE(LMI_COC_LOWER, 0x00002000);
- data = STSYS_ReadRegDev32LE(LMI_COC_LOWER);
- data = (data | 0x0<<16 | 0x0<<14);
- STSYS_WriteRegDev32LE(LMI_COC_LOWER, data);
- /* SDRAM Mode Register
- ** Set Refresh Interval, Enable Refresh, 16-bit bus,
- ** Grouping Disabled, DDR-SDRAM, Enable.
- ** Bits[27:16]: Refresh Interval = 7.8 microseconds (8K/64ms)
- ** @ 50MHz = 390 clk cycles -> 0x186
- ** @ 75MHz = 585 clk cycles -> 0x249
- ** @ 100MHz = 780 clk cycles -> 0x30C
- ** @ 125MHz = 975 clk cycles -> 0x3CF
- ** @ 133MHz = 1040 clk cycles -> 0x410 <--
- ** @ 166MHz = 1300 clk cycles -> 0x514
- */
- #if defined( SDRAM_512MB ) || defined(SDRAM_256MB)
- STSYS_WriteRegDev32LE(LMI_MIM, 0x04100203);
- #elif defined(SDRAM_128MB) || defined(SDRAM_64MB)
- STSYS_WriteRegDev32LE(LMI_MIM, 0x08200203);
- #endif
- /* SDRAM Timing Register
- ** For 133MHz (7.5ns) operation:
- ** 3 clks RAS_precharge, Trp;
- ** 3 clks RAS_to_CAS_delay, Trcd-r;
- ** 8 clks RAS cycle time, Trc;
- ** 6 clks RAS Active time, Tras;
- ** 2 clks RAS_to_RAS_Active_delay, Trrd;
- ** 2 clks Last write to PRE/PALL period SDRAM, Twr;
- ** 2 clks CAS Latency;
- ** 10 clks Auto Refresh RAS cycle time, Trfc;
- ** Enable Write to Read interruption;
- ** 1 clk Write to Read interruption, Twtr;
- ** 3 clks RAS_to_CAS_delay, Trcd-w;
- ** (200/16)=3 clks Exit self-refresh to next command, Tsxsr;
- */
- STSYS_WriteRegDev32LE(LMI_STR, 0x35085235);
- /* SDRAM Row Attribute 0 & 1 Registers
- ** UBA = 32MB + Base Adr, Quad-bank, Shape 13x9,
- ** Bank Remapping Disabled
- **
- ** LMI base address 0xC0000000
- ** Memory size 32MB 0x02000000
- ** Row UBA value 0xC200
- */
- #ifdef SDRAM_64MB
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC0801400);
- #elif defined (SDRAM_128MB)
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC1001500);
- #elif defined(SDRAM_256MB)
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC2001900);
- #elif defined(SDRAM_512MB)
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC4001a00);
- #endif
- /* We just have one Row connected to cs0, so we must program UBA0 = UBA1,
- ** following LMI specification
- */
- #ifdef SDRAM_64MB
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC0801400);
- #elif defined (SDRAM_128MB)
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC1001500);
- #elif defined(SDRAM_256MB)
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC2001900);
- #elif defined(SDRAM_512MB)
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC4001a00);
- #endif
- /*---------------------------------------------------------------------------
- ** Initialisation Sequence for LMI & DDR-SDRAM Device
- **---------------------------------------------------------------------------
- ** 200 microseconds to settle clocks
- */
- Simudelay (100);
- /* SDRAM Control Register */
- /* Clock enable */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x3);
- /* NOP enable */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x1);
- /* Precharge all banks */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x2);
- /* LMI_SDRAM_ROW_MODE0 & LMI_SDRAM_ROW_MODE1 Registers */
- /* EMRS Row 0 & 1: Weak Drive : Enable DLL */
- STSYS_WriteRegDev32LE(LMI_SDMR0, 0x0402);
- STSYS_WriteRegDev32LE(LMI_SDMR1, 0x0402);
- Simudelay (100);
- /* MRS Row 0 & 1 : Reset DLL - /CAS = 2.0, Mode Sequential, Burst Length 8 */
- STSYS_WriteRegDev32LE(LMI_SDMR0, 0x0123);
- STSYS_WriteRegDev32LE(LMI_SDMR1, 0x0123);
- /* 200 clock cycles required to lock DLL */
- Simudelay (100);
- /* Precharge all banks */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x2);
- /* CBR enable (auto-refresh) */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- /* LMI_SDRAM_ROW_MODE0 & 1 Registers */
- /* MRS Row 0 & 1 : Normal - /CAS = 2.0, Mode Sequential, Burst Length 8 */
- STSYS_WriteRegDev32LE(LMI_SDMR0, 0x0023);
- STSYS_WriteRegDev32LE(LMI_SDMR1, 0x0023);
- /* Normal SDRAM operation, No burst Refresh after standby */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x0);
- }
- /*-------------------------------------------------------------------------
- * Function : ST_5105_IniLMI_Cas25
- * Input : None
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void ST_5105_IniLMI_Cas25(void)
- {
- volatile U32 data;
- /* "n Configuring LMI for 16-bit data CAS 2.5 @ 166MHz " */
- /* Set LMI_COC_UPPER Register, bits [63:32] (LMI Pad logic) */
- STSYS_WriteRegDev32LE(LMI_COC_UPPER, 0x000C6750);
- /* Even Though its a 64 bit register the upper 32 bits are reserved and therefore no need to fill*/
- /* Set LMI_COC_LOWER Register, bits [31:0] (LMI Pad logic)
- ** Bits [19:18] Compensation mode DDR
- ** Bits [17:16] Pad strenght (0x0:5pF, 0x1:15pF, 0x2:25pF, Ox3:35pF)
- ** Bits [15:14] output Impedance (0x0:25Ohm, 0x1:40Ohm, 0x2:55Ohm, Ox3:70Ohm)
- ** Bit [13] DLL preset reset value enable
- */
- STSYS_WriteRegDev32LE(LMI_COC_LOWER, 0x00002000);
- data = STSYS_ReadRegDev32LE(LMI_COC_LOWER);
- data = (data | 0x0<<16 | 0x0<<14);
- STSYS_WriteRegDev32LE(LMI_COC_LOWER, data);
- /* SDRAM Mode Register
- ** Set Refresh Interval, Enable Refresh, 16-bit bus,
- ** Grouping Disabled, DDR-SDRAM, Enable.
- ** Bits[27:16]: Refresh Interval = 7.8 microseconds (8K/64ms)
- ** @ 50MHz = 390 clk cycles -> 0x186
- ** @ 75MHz = 585 clk cycles -> 0x249
- ** @ 100MHz = 780 clk cycles -> 0x30C
- ** @ 125MHz = 975 clk cycles -> 0x3CF
- ** @ 133MHz = 1040 clk cycles -> 0x410
- ** @ 166MHz = 1300 clk cycles -> 0x514 <--
- */
- #if defined( SDRAM_512MB ) || defined(SDRAM_256MB)
- STSYS_WriteRegDev32LE(LMI_MIM, 0x50F0203);
- #elif defined(SDRAM_128MB) || defined(SDRAM_64MB)
- STSYS_WriteRegDev32LE(LMI_MIM, 0x0A1E0203);
- #endif
- /* SDRAM Timing Register
- ** For 133MHz (7.5ns) operation:
- ** 3 clks RAS_precharge, Trp;
- ** 3 clks RAS_to_CAS_delay, Trcd-r;
- ** 8 clks RAS cycle time, Trc;
- ** 6 clks RAS Active time, Tras;
- ** 2 clks RAS_to_RAS_Active_delay, Trrd;
- ** 2 clks Last write to PRE/PALL period SDRAM, Twr;
- ** 2 clks CAS Latency;
- ** 10 clks Auto Refresh RAS cycle time, Trfc;
- ** Enable Write to Read interruption;
- ** 1 clk Write to Read interruption, Twtr;
- ** 3 clks RAS_to_CAS_delay, Trcd-w;
- ** (200/16)=3 clks Exit self-refresh to next command, Tsxsr;
- */
- STSYS_WriteRegDev32LE(LMI_STR, 0x352D4345);
- /* SDRAM Row Attribute 0 & 1 Registers
- ** UBA = 32MB + Base Adr, Quad-bank, Shape 13x9,
- ** Bank Remapping Disabled
- **
- ** LMI base address 0xC0000000
- ** Memory size 32MB 0x02000000
- ** Row UBA value 0xC200
- */
- #ifdef SDRAM_64MB
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC0801400);
- #elif defined (SDRAM_128MB)
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC1001500);
- #elif defined(SDRAM_256MB)
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC2001900);
- #elif defined(SDRAM_512MB)
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC4001a00);
- #endif
- /* We just have one Row connected to cs0, so we must program UBA0 = UBA1,
- ** following LMI specification
- */
- #ifdef SDRAM_64MB
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC0801400);
- #elif defined (SDRAM_128MB)
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC1001500);
- #elif defined(SDRAM_256MB)
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC2001900);
- #elif defined(SDRAM_512MB)
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC4001a00);
- #endif
- /*---------------------------------------------------------------------------
- ** Initialisation Sequence for LMI & DDR-SDRAM Device
- **---------------------------------------------------------------------------
- ** 200 microseconds to settle clocks
- */
- Simudelay (100);
- /* SDRAM Control Register */
- /* Clock enable */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x3);
- /* NOP enable */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x1);
- /* Precharge all banks */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x2);
- /* LMI_SDRAM_ROW_MODE0 & LMI_SDRAM_ROW_MODE1 Registers */
- /* EMRS Row 0 & 1: Weak Drive : Enable DLL */
- STSYS_WriteRegDev32LE(LMI_SDMR0, 0x0402);
- STSYS_WriteRegDev32LE(LMI_SDMR1, 0x0402);
- //Simudelay (100);
- /* MRS Row 0 & 1 : Reset DLL - /CAS = 2.5, Mode Sequential, Burst Length 8 */
- STSYS_WriteRegDev32LE(LMI_SDMR0, 0x0163);
- STSYS_WriteRegDev32LE(LMI_SDMR1, 0x0163);
- /* 200 clock cycles required to lock DLL */
- Simudelay (100);
- /* Precharge all banks */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x2);
- /* CBR enable (auto-refresh) */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- /* LMI_SDRAM_ROW_MODE0 & 1 Registers */
- /* MRS Row 0 & 1 : Normal - /CAS = 2.5, Mode Sequential, Burst Length 8 */
- STSYS_WriteRegDev32LE(LMI_SDMR0, 0x0063);
- STSYS_WriteRegDev32LE(LMI_SDMR1, 0x0063);
- /* Normal SDRAM operation, No burst Refresh after standby */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x0);
- }
- /*-------------------------------------------------------------------------
- * Function : ST_5105_InitFMI
- * Input : None
- * Output :
- * Return : None
- * ----------------------------------------------------------------------*/
- static void ST_5105_InitFMI(void)
- {
- /* Ensure all FMI control registers are unlocked */
- /* at reset the state of these regs is 'undefined' */
- STSYS_WriteRegDev32LE(FMI_LOCK, 0x00000000);
- STSYS_WriteRegDev32LE(FMI_STATUSLOCK, 0x00000000); /*~!@#$%^&*()*/
- /* Number of FMI Banks : Enable all banks */
- STSYS_WriteRegDev32LE(BANKS_ENABLED, 0x00000004);
- /* FMI Bank base addresses
- ** NOTE: bits [0,7] define bottom address bits [22,29] of bank
- ** Bank 0 - 16MBytes Atapi Configured as 16-bit peripheral
- */
- STSYS_WriteRegDev32LE(BANK_0_TOP_ADDRESS, 0x00000003); /* 0x40000000 - 0x40FFFFFF */
- /* Bank 1 - 32MBytes Stem0/DVBCI/EPLD Configured as 16-bit peripheral */
- STSYS_WriteRegDev32LE(BANK_1_TOP_ADDRESS, 0x0000000B); /* 0x41000000 - 0x42FFFFFF */
- /* Bank 2 - 32MBytes Stem1 Configured as 16-bit peripheral */
- STSYS_WriteRegDev32LE(BANK_2_TOP_ADDRESS, 0x00000013); /* 0x43000000 - 0x44FFFFFF */
- /* Bank 3 - 8MBytes ST M58LW064D Flash */
- STSYS_WriteRegDev32LE(BANK_3_TOP_ADDRESS, 0x00000017); /* 0x45000000 - 0x45FFFFFF */
- /*------------------------------------------------------------------------------
- ## Program bank functions
- ##------------------------------------------------------------------------------
- ##------------------------------------------------------------------------------
- ## Bank 0 - 16MBytes Atapi Configured as 16-bit peripheral
- ##------------------------------------------------------------------------------
- ## Parameters: -weuseoeconfig 0 -waitpolarity 0 -latchpoint 16 -datadrivedelay 31
- ## -busreleasetime 0 -csactive 3 -oeactive 3 -beactive 0 -portsize 16
- ## -devicetype 1
- ## -cyclenotphaseread 1 -accesstimeread 62 -cse1timeread 0
- ## -cse2timeread 2 -oee1timeread 8 -oee2timeread 15 -bee1timeread 2
- ## -bee2timeread 1
- ## -cyclenotphasewrite 1 -accesstimewrite 62 -cse1timewrite 0
- ## -cse2timewrite 2 -oee1timewrite 8 -oee2timewrite 15 -bee1timewrite 2
- ## -bee2timewrite 2
- ## -strobeonfalling 0 -burstsize 2 -datalatency 2 -dataholddelay 2
- ## -burstmode 0
- */
- #ifdef M29W320DB
- STSYS_WriteRegDev32LE(FMICONFIGDATA0_BANK0, 0x001016D1);
- #else //TMTM 1MB type
- STSYS_WriteRegDev32LE(FMICONFIGDATA0_BANK0, 0x041016D1);
- #endif
- //KCY 060921 STSYS_WriteRegDev32LE(FMICONFIGDATA1_BANK0, 0x9d200000);
- STSYS_WriteRegDev32LE(FMICONFIGDATA1_BANK0, 0x0c000000);
- STSYS_WriteRegDev32LE(FMICONFIGDATA2_BANK0, 0x9d220000);
- STSYS_WriteRegDev32LE(FMICONFIGDATA3_BANK0, 0x00000000);
- /*------------------------------------------------------------------------------
- ## Bank 1 - 32MBytes Stem0/DVBCI/EPLD Configured as 16-bit peripheral
- ##------------------------------------------------------------------------------
- ## Parameters: -weuseoeconfig 0 -waitpolarity 0 -latchpoint 1 -datadrivedelay 0
- ## -busreleasetime 2 -csactive 3 -oeactive 1 -beactive 2 -portsize 16
- ## -devicetype 1
- ## -cyclenotphaseread 1 -accesstimeread 1d -cse1timeread 2
- ## -cse2timeread 0 -oee1timeread 0 -oee2timeread 0 -bee1timeread 0
- ## -bee2timeread 0
- ## -cyclenotphasewrite 1 -accesstimewrite 1d -cse1timewrite 2
- ## -cse2timewrite 2 -oee1timewrite 0 -oee2timewrite 0 -bee1timewrite 0
- ## -bee2timewrite 0
- ## -strobeonfalling 0 -burstsize 0 -datalatency 0 -dataholddelay 0
- ## -burstmode 0
- */
- //STSYS_WriteRegDev32LE(FMICONFIGDATA0_BANK1, 0x00101699); /*BE not active during rd */
- //STSYS_WriteRegDev32LE(FMICONFIGDATA1_BANK1, 0xBE426200);
- //STSYS_WriteRegDev32LE(FMICONFIGDATA2_BANK1, 0xBE426200);
- //STSYS_WriteRegDev32LE(FMICONFIGDATA3_BANK1, 0x00000000);
- STSYS_WriteRegDev32LE(FMICONFIGDATA0_BANK1, 0x05001ed1); /*BE not active during rd */
- STSYS_WriteRegDev32LE(FMICONFIGDATA1_BANK1, 0xa0000000);
- STSYS_WriteRegDev32LE(FMICONFIGDATA2_BANK1, 0xa0000000);
- STSYS_WriteRegDev32LE(FMICONFIGDATA3_BANK1, 0x00000000);
- /*------------------------------------------------------------------------------
- ## Bank 2 - 32MBytes Stem1 Configured as 16-bit peripheral
- ##------------------------------------------------------------------------------
- ## Parameters: -weuseoeconfig 0 -waitpolarity 0 -latchpoint 1 -datadrivedelay 0
- ## -busreleasetime 2 -csactive 3 -oeactive 1 -beactive 2 -portsize 16
- ## -devicetype 1
- ## -cyclenotphaseread 1 -accesstimeread 1d -cse1timeread 2
- ## -cse2timeread 0 -oee1timeread 0 -oee2timeread 0 -bee1timeread 0
- ## -bee2timeread 0
- ## -cyclenotphasewrite 1 -accesstimewrite 1d -cse1timewrite 2
- ## -cse2timewrite 2 -oee1timewrite 0 -oee2timewrite 0 -bee1timewrite 0
- ## -bee2timewrite 0
- ## -strobeonfalling 0 -burstsize 0 -datalatency 0 -dataholddelay 0
- ## -burstmode 0
- */
- STSYS_WriteRegDev32LE(FMICONFIGDATA0_BANK2, 0x001016D1); /* BE not active during rd */
- STSYS_WriteRegDev32LE(FMICONFIGDATA1_BANK2, 0x9d200000);
- STSYS_WriteRegDev32LE(FMICONFIGDATA2_BANK2, 0x9d220000);
- STSYS_WriteRegDev32LE(FMICONFIGDATA3_BANK2, 0x00000000);
- /* FMI Bank 3 8MBytes ST M58LW064D Flash - ONLY 8MBytes FLASH ON BOARD THIS MAY BE WRONG!
- ##------------------------------------------------------------------------------
- ## Bank 3 - 8MBytes ST M58LW064D Flash
- ##------------------------------------------------------------------------------
- ## Parameters: -weuseoeconfig 0 -waitpolarity 0 -latchpoint 1 -datadrivedelay 0
- ## -busreleasetime 2 -csactive 3 -oeactive 1 -beactive 2 -portsize 16
- ## -devicetype 1
- ## -cyclenotphaseread 1 -accesstimeread 1d -cse1timeread 2
- ## -cse2timeread 0 -oee1timeread 0 -oee2timeread 0 -bee1timeread 0
- ## -bee2timeread 0
- ## -cyclenotphasewrite 1 -accesstimewrite 1d -cse1timewrite 2
- ## -cse2timewrite 2 -oee1timewrite 0 -oee2timewrite 0 -bee1timewrite 0
- ## -bee2timewrite 0
- ## -strobeonfalling 0 -burstsize 0 -datalatency 0 -dataholddelay 0
- ## -burstmode 0
- */
- STSYS_WriteRegDev32LE(FMICONFIGDATA0_BANK3, 0x01008791);
- STSYS_WriteRegDev32LE(FMICONFIGDATA1_BANK3, 0x44618f00);
- STSYS_WriteRegDev32LE(FMICONFIGDATA2_BANK3, 0x44618f00);
- STSYS_WriteRegDev32LE(FMICONFIGDATA3_BANK3, 0x0000000A);
- /* ------- Program Other FMI Registers --------
- ** sdram refresh bank 5
- ** flash runs @ 1/3 bus clk
- ** sdram runs @ bus clk
- */
- STSYS_WriteRegDev32LE(FMI_GENCFG, 0x00000000);
- STSYS_WriteRegDev32LE(FMI_FLASHCLKSEL, 0x00000002);
- /*STSYS_WriteRegDev32LE(FMI_CLKENABLE, 0x00000000);*/
- #if 0
- /* Reset flash Banks */
- STSYS_WriteRegMem32LE(FLASH_EPLD_FLASH, 0x00000000);
- STSYS_WriteRegMem32LE(FLASH_EPLD_FLASH, 0x03030303);
- #endif
- }
- /***leslie----------------------------------------------------------------------------
## Procedure Name : ST_5105_IniLMI_Reg
## Purpose : Initialisation Registers of LMI
## Note :
##
## (LMI Spec: ADCS 7483542)
##---------------------------------------------------------------------------- ***/
static void ST_5105_IniLMI_Reg(void)
- {
volatile U32 data;
- volatile U8 tRP, tRCDR, tRC, tRAS, tRRD, tWR, tRFC, tWTR, tRCDW, tSXSR, sCL;
- STSYS_WriteRegDev32LE(LMI_COC_UPPER, 0x000C6750);
- STSYS_WriteRegDev32LE(LMI_COC_LOWER, 0x00002000);
- data = STSYS_ReadRegDev32LE(LMI_COC_LOWER);
- data = (data | 0x0<<16 | 0x0<<14);
- STSYS_WriteRegDev32LE(LMI_COC_LOWER, data);
- #if 0 //TMTM original
- STSYS_WriteRegDev32LE(LMI_MIM, 0x8200201); /* 64ms/4K cycle */
- STSYS_WriteRegDev32LE(LMI_STR, 0x35085235);
- #ifdef SDARM_64MB
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC0801400); /* 64MB */
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC0801400); /* 64MB */
- #else
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC1001500); /* 128MB */
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC1001500); /*128MBDDR */
- #endif
- #else
- #ifdef DDR_SDRAM //TMTM
- data = 2;
- #else
- data = 0;
- #endif
- #ifdef SDRAM_FREQ_CONFIG_133
- STSYS_WriteRegDev32LE(LMI_MIM, 0x08200201 |data); /* 64ms/4K cycle */
- tRP = 1; //0b01; // 3 clocks, 18ns -- , RAS_precharge
- tRCDR = 1; //0b01; // 3 clocks, 18ns -- , RAS_to_CAS_delay
- tRC = 3; //0b0011; // 9 cloks, 60ns -- , RAS cycle time
- tRAS = 2; //0b010; // 6 clocks, 42ns -- 120000ns , RAS Active time
- tRRD = 0; // 2 clocks, 12ns -- , RAS_to_RAS_Active_delay
- tWR = 1; //0b01; // 2 clocks, 15ns -- , Last write to PRE/PALL period SDRAM
- tRFC = 4; //0b100; // 10 clocks,72ns -- , Auto Refresh RAS cycle time
- tWTR = 0; // 1 clock, 1ns -- , Write to Read interruption, Twtr
- tRCDW = 1; //0b01; // 3 clocks, 18ns -- , RAS_to_CAS_delay
- tSXSR = 13; // 200ns/16 , Exit self-refresh to next command
- #elif defined (SDRAM_FREQ_CONFIG_120)
- STSYS_WriteRegDev32LE(LMI_MIM, 0x07A10201 |data); /* 64ms/4K cycle */
- tRP = 1; //0b01; // 3 clocks, 18ns -- , RAS_precharge
- tRCDR = 1; //0b01; // 3 clocks, 18ns -- , RAS_to_CAS_delay
- tRC = 2; //0b0010; // 8 cloks, 60ns -- , RAS cycle time
- tRAS = 3; //0b011; // 7 clocks, 42ns -- 120000ns , RAS Active time
- tRRD = 0; // 2 clocks, 12ns -- , RAS_to_RAS_Active_delay
- tWR = 1; //0b01; // 2 clocks, 15ns -- , Last write to PRE/PALL period SDRAM
- tRFC = 4; //0b100; // 10 clocks,72ns -- , Auto Refresh RAS cycle time
- tWTR = 0; // 1 clock, 1ns -- , Write to Read interruption, Twtr
- tRCDW = 1; //0b01; // 2 clocks, 18ns -- , RAS_to_CAS_delay
- tSXSR = 13; // 200ns/16 , Exit self-refresh to next command
- #elif defined (SDRAM_FREQ_CONFIG_166)
- #if defined( SDRAM_512MB ) || defined(SDRAM_256MB)
- STSYS_WriteRegDev32LE(LMI_MIM, 0x50F0201 | data);
- #elif defined(SDRAM_128MB) || defined(SDRAM_64MB)
- STSYS_WriteRegDev32LE(LMI_MIM, 0x0A220201 | data);
- /*STSYS_WriteRegDev32LE(LMI_MIM, 0x0A1E0201 | data);*/
- #endif
- #if 0
- tRP = 1; //0b01; // 3 clocks, 18ns -- , RAS_precharge
- tRCDR = 1; //0b01; // 3 clocks, 18ns -- , RAS_to_CAS_delay
- tRC = 3; //0b0011; // 9 cloks, 60ns -- , RAS cycle time
- tRAS = 3; //0b011; // 7 clocks, 42ns -- 120000ns , RAS Active time
- tRRD = 0; // 2 clocks, 12ns -- , RAS_to_RAS_Active_delay
- tWR = 2; //0b10; // 3 clocks, 15ns -- , Last write to PRE/PALL period SDRAM
- tRFC = 6; //0b110; // 12 clocks,72ns -- , Auto Refresh RAS cycle time
- tWTR = 0; // 1 clock, 1ns -- , Write to Read interruption, Twtr
- tRCDW = 1; //0b01; // 3 clocks, 18ns -- , RAS_to_CAS_delay
- tSXSR = 13; // 200ns/16 , Exit self-refresh to next command
- #endif
- #ifdef SDRAM_CAS_2_0
- sCL = 2; //0b0010; // 2 clocks, CAS Latency
- #elif defined (SDRAM_CAS_2_5)
- sCL = 0xA; //0b1010; // 2.5 clocks, CAS Latency
- #elif defined (SDRAM_CAS_3_0)
- sCL = 0x3; //0b0011; // 3 clocks, CAS Latency
- #endif
- data = (tRP<<0) | (tRCDR<<2) | (tRC<<4) | (tRAS<<8) | (tRRD<<11) | ( (tWR&1) <<12) | (sCL<<13) | (tRFC<<17) | ( ((tWR&2)>>1) <<21) | (tWTR<<23) | (tRCDW<<24) | (tSXSR<<26) ;
- data = data | (1 << 22) ; // Enable Write to Read interruption
- STSYS_WriteRegDev32LE(LMI_STR, data);
- #endif
- //STSYS_WriteRegDev32LE(LMI_STR, 0x30087345);
- STSYS_WriteRegDev32LE(LMI_STR, 0x35087345);
- #ifdef SDRAM_64MB
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC0801400); /* 64MB */
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC0801400); /* 64MB */
- #elif defined (SDRAM_128MB)
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC1001500); /* 128MB */
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC1001500); /* 128MB */
- #elif defined (SDRAM_256MB)
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC2001900); /* 256Mb */
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC2001900); /* 256Mb */
- #elif defined (SDRAM_256MB)
- STSYS_WriteRegDev32LE(LMI_SDRA0, 0xC4001a00); /* 512Mb */
- STSYS_WriteRegDev32LE(LMI_SDRA1, 0xC4001a00); /* 512Mb */
- #endif
- #endif
- }
- /*##----------------------------------------------------------------------------
## Procedure Name : ST_5105_IniLMI_PC_SDRAM
## Purpose : Initialisation of LMI for the PC SDRAM on MB400 board
## Note :
##
## (LMI Spec: ADCS 7483542)
##----------------------------------------------------------------------------*/
static void ST_5105_IniLMI_PC_SDRAM(void)
- {
/*** Initialisation Registers of LMI***/
ST_5105_IniLMI_Reg();
/*---------------------------------------------------------------------------
- ** Initialisation Sequence for LMI & DDR-SDRAM Device
- **---------------------------------------------------------------------------
- ** 200 microseconds to settle clocks
- */
- Simudelay (100);
- /* SDRAM Control Register */
- /* Clock enable */
- STSYS_WriteRegDev32LE(LMI_SCR, 0x3);
-
- Simudelay (100);
-
- STSYS_WriteRegDev32LE(LMI_SCR, 0x2);
-
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
- STSYS_WriteRegDev32LE(LMI_SCR, 0x4);
-
- #ifdef SDRAM_CAS_2_0
- // MRS Row 0 & 1 : Reset DLL - /CAS = 2.0, Mode Sequential, Burst Length 8
- STSYS_WriteRegDev32LE(LMI_SDMR0, 0x0023);
- STSYS_WriteRegDev32LE(LMI_SDMR1, 0x0023);
- #elif defined (SDRAM_CAS_2_5)
- //MRS Row 0 & 1 : Reset DLL - /CAS = 2.5, Mode Sequential, Burst Length 8
- STSYS_WriteRegDev32LE(LMI_SDMR0, 0x0063);
- STSYS_WriteRegDev32LE(LMI_SDMR1, 0x0063);
- #else //SDRAM_CAS_3_0
- //MRS Row 0 & 1 : Reset DLL - /CAS = 3.0, Mode Sequential, Burst Length 8
- STSYS_WriteRegDev32LE(LMI_SDMR0, 0x0033);
- STSYS_WriteRegDev32LE(LMI_SDMR1, 0x0033);
- #endif
-
- }
/**##################leslie################**/
- /* EOF --------------------------------------------------------------------- */