[processor-sdk/pdk.git] / packages / ti / boot / sbl / tools / omapl13x_boot_utils / OMAP-L138 / GNU / AISUtils / AISextra / src / aisextra.c
1 /* --------------------------------------------------------------------------
2 FILE : aisxtra.c
3 PURPOSE : AIS Extra commands for use in AIS Scripts
4 PROJECT : TI Boot and Flash Utilities
5 AUTHOR : Daniel Allred
6 ----------------------------------------------------------------------------- */
8 /************************************************************
9 * Include Files *
10 ************************************************************/
12 #include "tistdtypes.h"
13 #include "device.h"
16 /************************************************************
17 * Explicit External Declarations *
18 ************************************************************/
20 extern __FAR__ Uint32 EXTERNAL_RAM_START;
23 /************************************************************
24 * Local Macro Declarations *
25 ************************************************************/
28 /************************************************************
29 * Local Typedef Declarations *
30 ************************************************************/
33 /************************************************************
34 * Local Function Declarations *
35 ************************************************************/
38 /************************************************************
39 * Local Variable Definitions *
40 ************************************************************/
43 /************************************************************
44 * Global Variable Definitions *
45 ************************************************************/
46 #if defined(__TMS320C6X__)
48 #pragma DATA_SECTION(paramTable,".params")
49 Uint32 paramTable[16];
51 #elif defined(__GNUC__)
52 Uint32 paramTable[16] __attribute__((,section(".params")));
53 #endif
55 /************************************************************
56 * Global Function Definitions *
57 ************************************************************/
59 #if defined(__TMS320C6X__)
60 #pragma CODE_SECTION(PatchDDRConfig,".text")
61 void PatchDDRConfig() {
62 #elif defined(__GNUC__)
63 void PatchDDRConfig() __attribute__((,section(".text")));
64 void PatchDDRConfig() {
65 #endif
67 VUint32 data_tmp;
68 VUint32 *DDRStart = (VUint32 *) ((Uint32 *) EXTERNAL_RAM_START);
69 Uint32 ddrphycr = paramTable[0];
70 Uint32 sdcr = paramTable[1];
71 Uint32 sdtimr = paramTable[2];
72 Uint32 sdtimr2 = paramTable[3];
73 Uint32 sdrcr = paramTable[4];
74 Uint32 sdcr2 = paramTable[5];
76 // Set the DDR2 to enable
77 {
78 // Wait for any outstanding transition to complete
79 while ( (PSC1->PTSTAT) & (0x00000001 << PD0) );
81 // If we are already in that state, just return
82 if (((PSC1->MDSTAT[LPSC_EMIFB]) & 0x1F) == PSC_ENABLE) return;
84 // Perform transition
85 PSC1->MDCTL[LPSC_EMIFB] = ((PSC1->MDCTL[LPSC_EMIFB]) & (0xFFFFFFE0)) | (PSC_ENABLE);
86 PSC1->PTCMD |= (0x00000001 << PD0);
88 // Wait for transition to complete
89 while ( (PSC1->PTSTAT) & (0x00000001 << PD0) );
91 // Wait and verify the state
92 while (((PSC1->MDSTAT[LPSC_EMIFB]) & 0x1F) != PSC_ENABLE);
93 }
95 // Begin VTP Calibration
96 // If VTP claiberation enabled, then skip the VTP calibration
97 if (SUBCHIPCFG->VTPIO_CTL & 0x00000040)
98 {
99 SUBCHIPCFG->VTPIO_CTL |= DEVICE_VTPIO_CTL_IOPWRDN_MASK; // Set IOPWRDN bit to enable input buffer powerdown enable mode
100 SUBCHIPCFG->VTPIO_CTL &= ~(DEVICE_VTPIO_CTL_POWERDN_MASK); // Clear POWERDN bit (enable VTP)
102 SUBCHIPCFG->VTPIO_CTL &= ~(DEVICE_VTPIO_CTL_LOCK_MASK); // Clear LOCK bit
104 // Pulse (low) CLRZ to initiate VTP IO Calibration
105 SUBCHIPCFG->VTPIO_CTL |= DEVICE_VTPIO_CTL_CLKRZ_MASK; // Set CLRZ bit
106 SUBCHIPCFG->VTPIO_CTL &= ~(DEVICE_VTPIO_CTL_CLKRZ_MASK); // Clear CLRZ bit (CLRZ should be low for at least 2ns)
107 SUBCHIPCFG->VTPIO_CTL |= DEVICE_VTPIO_CTL_CLKRZ_MASK; // Set CLRZ bit
109 // Polling READY bit to see when VTP calibration is done
110 while(!((SUBCHIPCFG->VTPIO_CTL & DEVICE_VTPIO_CTL_READY_MASK)>>DEVICE_VTPIO_CTL_READY_SHIFT));
112 SUBCHIPCFG->VTPIO_CTL |= DEVICE_VTPIO_CTL_LOCK_MASK; // Set LOCK bit for static mode
113 SUBCHIPCFG->VTPIO_CTL |= DEVICE_VTPIO_CTL_PWRSAVE_MASK; // Set PWRSAVE bit to save power
114 }
115 // End VTP Calibration
117 // Config DDR timings
118 EMIF3A->DDRPHYC1R = ddrphycr;
120 // Clear the unlock bits (in case user accidentally set them)
121 sdcr = sdcr & (~DEVICE_SDCR_BOOTUNLOCK_MASK) & (~DEVICE_SDCR_TIMUNLOCK_MASK);
123 // Set SDCR with BOOTUNLOCK Set and TIMUNLOCK cleared
124 EMIF3A->SDCR = sdcr | ((0x1 << DEVICE_SDCR_BOOTUNLOCK_SHIFT) & DEVICE_SDCR_BOOTUNLOCK_MASK);
126 // Set SDCR with BOOTUNLOCK cleared and TIMUNLOCK set
127 EMIF3A->SDCR = sdcr | ((0x1 << DEVICE_SDCR_TIMUNLOCK_SHIFT) & DEVICE_SDCR_TIMUNLOCK_MASK);
129 // Check if this init is for mDDR
130 if (sdcr & DEVICE_SDCR_MSDRAMEN_MASK)
131 {
132 // If it is, set SDCR2 with PASR and ROWSIZE PARAMS
133 EMIF3A->SDCR2 = sdcr2;
134 }
136 EMIF3A->SDTIMR = sdtimr;
137 EMIF3A->SDTIMR2 = sdtimr2;
139 // Clear TIMUNLOCK bit
140 EMIF3A->SDCR &= (~DEVICE_SDCR_TIMUNLOCK_MASK);
141 EMIF3A->SDRCR = sdrcr;
143 // Set the DDR2 to syncreset
144 {
145 EMIF3A->SDRCR |= 0xC0000000; // Set to self-refresh, enable mclkstop
146 // Wait for any outstanding transition to complete
147 while ( (PSC1->PTSTAT) & (0x00000001 << PD0) );
149 // If we are already in that state, just return
150 if (((PSC1->MDSTAT[LPSC_EMIFB]) & 0x1F) == PSC_SYNCRESET) return;
152 // Perform transition
153 PSC1->MDCTL[LPSC_EMIFB] = ((PSC1->MDCTL[LPSC_EMIFB]) & (0xFFFFFFE0)) | (PSC_SYNCRESET);
154 PSC1->PTCMD |= (0x00000001 << PD0);
156 // Wait for transition to complete
157 while ( (PSC1->PTSTAT) & (0x00000001 << PD0) );
159 // Wait and verify the state
160 while (((PSC1->MDSTAT[LPSC_EMIFB]) & 0x1F) != PSC_SYNCRESET);
161 }
163 // Set the DDR2 to enable
164 {
165 // Wait for any outstanding transition to complete
166 while ( (PSC1->PTSTAT) & (0x00000001 << PD0) );
168 // If we are already in that state, just return
169 if (((PSC1->MDSTAT[LPSC_EMIFB]) & 0x1F) == PSC_ENABLE) return;
171 // Perform transition
172 PSC1->MDCTL[LPSC_EMIFB] = ((PSC1->MDCTL[LPSC_EMIFB]) & (0xFFFFFFE0)) | (PSC_ENABLE);
173 PSC1->PTCMD |= (0x00000001 << PD0);
175 // Wait for transition to complete
176 while ( (PSC1->PTSTAT) & (0x00000001 << PD0) );
178 // Wait and verify the state
179 while (((PSC1->MDSTAT[LPSC_EMIFB]) & 0x1F) != PSC_ENABLE);
180 EMIF3A->SDRCR &= ~(0xC0000000); // disable self-refresh
181 }
183 // Dummy write/read to apply timing settings
184 *DDRStart = 0xA55AA55A; // write
185 data_tmp = *DDRStart; // read
186 *DDRStart = data_tmp;
187 }