source: umon/ports/beagleboneblack/cpuio.c @ 04903c8

Last change on this file since 04903c8 was 04903c8, checked in by Jarielle Catbagan <jcatbagan93@…>, on Aug 4, 2015 at 6:03:23 PM

BBB: cpuio.c: Configure pins used by MMC1

  • Property mode set to 100644
File size: 15.9 KB
Line 
1#include "config.h"
2#include "stddefs.h"
3#include "cpuio.h"
4#include "genlib.h"
5#include "cache.h"
6#include "warmstart.h"
7#include "timer.h"
8#include "am335x.h"
9#include "uart16550.h"
10#include "cli.h"
11
12int
13getUartDivisor(int baud, unsigned char *hi, unsigned char *lo)
14{
15        *lo = ((48000000/16)/baud) & 0x00ff;
16        *hi = (((48000000/16)/baud) & 0xff00) >> 8;
17        return(0);
18}
19
20/* devInit():
21 * As a bare minimum, initialize the console UART here using the
22 * incoming 'baud' value as the baud rate.
23 */
24int
25devInit(int baud)
26{
27        return(0);
28}
29
30/* ConsoleBaudSet():
31 * Provide a means to change the baud rate of the running
32 * console interface.  If the incoming value is not a valid
33 * baud rate, then default to 9600.
34 * In the early stages of a new port this can be left empty.
35 * Return 0 if successful; else -1.
36 */
37/*int
38ConsoleBaudSet(int baud)
39{
40        // ADD_CODE_HERE
41        return(0);
42}*/
43
44/* target_console_empty():
45 * Target-specific portion of flush_console() in chario.c.
46 * This function returns 1 if there are no characters waiting to
47 * be put out on the UART; else return 0 indicating that the UART
48 * is still busy outputting characters from its FIFO.
49 * In the early stages of a new port this can simply return 1.
50 */
51/*int
52target_console_empty(void)
53{
54        // if (UART_OUTPUT_BUFFER_IS_EMPTY())  <- FIX CODE HERE
55                return(0);
56        return(1);
57}*/
58
59/* intsoff():
60 * Disable all system interrupts here and return a value that can
61 * be used by intsrestore() (later) to restore the interrupt state.
62 */
63ulong
64intsoff(void)
65{
66        ulong status = 0;
67
68        /* ADD_CODE_HERE */
69        return(status);
70}
71
72/* intsrestore():
73 * Re-establish system interrupts here by using the status value
74 * that was returned by an earlier call to intsoff().
75 */
76void
77intsrestore(ulong status)
78{
79        /* ADD_CODE_HERE */
80}
81
82/* cacheInitForTarget():
83 * Establish target specific function pointers and
84 * enable i-cache...
85 * Refer to $core/cache.c for a description of the function pointers.
86 * NOTE:
87 * If cache (either I or D or both) is enabled, then it is important
88 * that the appropriate cacheflush/invalidate function be established.
89 * This is very important because programs (i.e. cpu instructions) are
90 * transferred to memory using data memory accesses and could
91 * potentially result in cache coherency problems.
92 */
93void
94cacheInitForTarget(void)
95{
96        /* ADD_CODE_HERE */
97}
98
99/* target_reset():
100 * The default (absolute minimum) action to be taken by this function
101 * is to call monrestart(INITIALIZE).  It would be better if there was
102 * some target-specific function that would really cause the target
103 * to reset...
104 */
105void
106target_reset(void)
107{
108//      flushDcache(0,0);
109//      disableDcache();
110//      invalidateIcache(0,0);
111//      disableIcache();
112        monrestart(INITIALIZE);
113}
114
115/* Override the default exception handlers provided by the AM335x
116 * internal ROM code with uMon's custom exception handlers
117 */
118void
119ram_vector_install(void)
120{
121        extern unsigned long abort_data;
122        extern unsigned long abort_prefetch;
123        extern unsigned long undefined_instruction;
124        extern unsigned long software_interrupt;
125        extern unsigned long interrupt_request;
126        extern unsigned long fast_interrupt_request;
127        extern unsigned long not_assigned;
128
129        *(ulong **)0x4030ce24 = &undefined_instruction;
130        *(ulong **)0x4030ce28 = &software_interrupt;
131        *(ulong **)0x4030ce2c = &abort_prefetch;
132        *(ulong **)0x4030ce30 = &abort_data;
133        *(ulong **)0x4030ce34 = &not_assigned;
134        *(ulong **)0x4030ce38 = &interrupt_request;
135        *(ulong **)0x4030ce3c = &fast_interrupt_request;
136}
137
138void
139pinMuxInit(void)
140{
141        // Set pin mux configuration for UART0 RX/TX pins
142        CNTL_MODULE_REG(CONF_UART0_RXD) = SLEWSLOW | RX_ON |
143                PULL_OFF | MUXMODE_0;
144        CNTL_MODULE_REG(CONF_UART0_TXD) = SLEWSLOW | RX_OFF |
145                PULL_OFF | MUXMODE_0;
146
147        // Configure GPIO pins tied to four USR LEDS...
148        // GPIO1_21: USER0 LED (D2)
149        CNTL_MODULE_REG(CONF_GPMC_A5) = SLEWSLOW | RX_ON |
150                PULL_OFF | MUXMODE_7;
151        // GPIO1_22: USER1 LED (D3)
152        CNTL_MODULE_REG(CONF_GPMC_A6) = SLEWSLOW | RX_ON |
153                PULL_OFF | MUXMODE_7;
154        // GPIO1_23: USER2 LED (D4)
155        CNTL_MODULE_REG(CONF_GPMC_A7) = SLEWSLOW | RX_ON |
156                PULL_OFF | MUXMODE_7;
157        // GPIO1_24: USER3 LED (D5)
158        CNTL_MODULE_REG(CONF_GPMC_A8) = SLEWSLOW | RX_ON |
159                PULL_OFF | MUXMODE_7;
160
161        // Configure the pins for the MMC0 interface
162        CNTL_MODULE_REG(CONF_MMC0_DAT0) = RX_ON | PULL_ON |
163                PULLUP | MUXMODE_0;
164        CNTL_MODULE_REG(CONF_MMC0_DAT1) = RX_ON | PULL_ON |
165                PULLUP | MUXMODE_0;
166        CNTL_MODULE_REG(CONF_MMC0_DAT2) = RX_ON | PULL_ON |
167                PULLUP | MUXMODE_0;
168        CNTL_MODULE_REG(CONF_MMC0_DAT3) = RX_ON | PULL_ON |
169                PULLUP | MUXMODE_0;
170        CNTL_MODULE_REG(CONF_MMC0_CLK) = RX_ON | PULL_OFF |
171                MUXMODE_0;
172        CNTL_MODULE_REG(CONF_MMC0_CMD) = RX_ON | PULL_ON |
173                PULLUP | MUXMODE_0;
174        CNTL_MODULE_REG(CONF_SPI0_CS1) = RX_ON | PULL_ON |
175                PULLUP | MUXMODE_5;
176
177        // Configure the pins for the MMC1 interface
178        /* MMC1_DAT0 */
179        CNTL_MODULE_REG(CONF_GPMC_AD0) = RX_ON | PULL_ON |
180                PULLUP | MUXMODE_1;
181        /* MMC1_DAT1 */
182        CNTL_MODULE_REG(CONF_GPMC_AD1) = RX_ON | PULL_ON |
183                PULLUP | MUXMODE_1;
184        /* MMC1_DAT2 */
185        CNTL_MODULE_REG(CONF_GPMC_AD2) = RX_ON | PULL_ON |
186                PULLUP | MUXMODE_1;
187        /* MMC1_DAT3 */
188        CNTL_MODULE_REG(CONF_GPMC_AD3) = RX_ON | PULL_ON |
189                PULLUP | MUXMODE_1;
190        /* MMC1_DAT4 */
191        CNTL_MODULE_REG(CONF_GPMC_AD4) = RX_ON | PULL_ON |
192                PULLUP | MUXMODE_1;
193        /* MMC1_DAT5 */
194        CNTL_MODULE_REG(CONF_GPMC_AD5) = RX_ON | PULL_ON |
195                PULLUP | MUXMODE_1;
196        /* MMC1_DAT6 */
197        CNTL_MODULE_REG(CONF_GPMC_AD6) = RX_ON | PULL_ON |
198                PULLUP | MUXMODE_1;
199        /* MMC1_DAT7 */
200        CNTL_MODULE_REG(CONF_GPMC_AD7) = RX_ON | PULL_ON |
201                PULLUP | MUXMODE_1;
202        /* MMC1_CLK */
203        CNTL_MODULE_REG(CONF_GPMC_CSN1) = RX_ON | PULL_OFF |
204                MUXMODE_2;
205        /* MMC1_CMD */
206        CNTL_MODULE_REG(CONF_GPMC_CSN2) = RX_ON | PULL_ON |
207                PULLUP | MUXMODE_2;
208}
209
210void
211InitGPIO1(void)
212{
213        // GPIO_CTRL: Enable GPIO1 module
214        GPIO1_REG(0x130) = 0;
215
216        // GPIO_OE: 25-24 are outputs...
217        GPIO1_REG(0x134) &= ~(USR0_LED | USR1_LED | USR2_LED | USR3_LED);
218
219        // All LEDs off...
220        GPIO1_REG(0x13c) &= ~(USR0_LED | USR1_LED | USR2_LED | USR3_LED);
221}
222
223/* If any CPU IO wasn't initialized in reset.S, do it here...
224 * This just provides a "C-level" IO init opportunity.
225 */
226void
227initCPUio(void)
228{
229        ram_vector_install();
230
231        // Enable the control module:
232        CM_WKUP_REG(CM_WKUP_CONTROL_CLKCTRL) |= 2;
233
234        // Enable clock for UART0:
235        CM_WKUP_REG(CM_WKUP_UART0_CLKCTRL) |= 2;
236
237        // Enable clock for GPIO1:
238        CM_PER_REG(CM_PER_GPIO1_CLKCTRL) |= 2;
239
240        /* Enable MMC0 clocks */
241        CM_PER_REG(CM_PER_MMC0_CLKCTRL) |= CM_PER_MMC0_CLKCTRL_MODULEMODE_ENABLE;
242        while (CM_PER_REG(CM_PER_MMC0_CLKCTRL) & CM_PER_MMC0_CLKCTRL_IDLEST);
243
244        pinMuxInit();
245
246        InitUART(DEFAULT_BAUD_RATE);
247        InitGPIO1();
248
249        // Set UART0 mode to 16x
250        UART0_REG(UART_MDR1) &= ~7;
251}
252
253int
254led(int num, int on)
255{
256        unsigned long bit;
257
258        switch(num) {
259                case 0: // D0
260                        bit = USR0_LED;
261                        break;
262                case 1: // D1
263                        bit = USR1_LED;
264                        break;
265                case 2: // D2
266                        bit = USR2_LED;
267                        break;
268                case 3: // D3
269                        bit = USR3_LED;
270                        break;
271                default:
272                        return(-1);
273        }
274
275        // GPIO21-24:
276        if (on)
277            GPIO1_REG(0x13c) |= bit;
278        else
279            GPIO1_REG(0x13c) &= ~bit;
280        return(0);
281}
282
283void
284target_blinkled(void)
285{
286#if INCLUDE_BLINKLED
287        static uint8_t ledstate;
288        static struct elapsed_tmr tmr;
289
290#define STATLED_ON()    led(0,1)
291#define STATLED_OFF()   led(0,0)
292#ifndef BLINKON_MSEC
293#define BLINKON_MSEC 10000
294#define BLINKOFF_MSEC 10000
295#endif
296
297        switch(ledstate) {
298                case 0:
299                        startElapsedTimer(&tmr,BLINKON_MSEC);
300                        STATLED_ON();
301                        ledstate = 1;
302                        break;
303                case 1:
304                        if(msecElapsed(&tmr)) {
305                                STATLED_OFF();
306                                ledstate = 2;
307                                startElapsedTimer(&tmr,BLINKOFF_MSEC);
308                        }
309                        break;
310                case 2:
311                        if(msecElapsed(&tmr)) {
312                                STATLED_ON();
313                                ledstate = 1;
314                                startElapsedTimer(&tmr,BLINKON_MSEC);
315                        }
316                        break;
317        }
318#endif
319}
320
321void
322mpu_pll_init(void)
323{
324        uint32_t cm_clkmode_dpll_mpu;
325        uint32_t cm_clksel_dpll_mpu;
326        uint32_t cm_div_m2_dpll_mpu;
327
328        // Put MPU PLL in MN Bypass mode
329        cm_clkmode_dpll_mpu = CM_WKUP_REG(CM_CLKMODE_DPLL_MPU);
330        cm_clkmode_dpll_mpu &= ~0x00000007;
331        cm_clkmode_dpll_mpu |= 0x00000004;
332        CM_WKUP_REG(CM_CLKMODE_DPLL_MPU) = cm_clkmode_dpll_mpu;
333        // Wait for MPU PLL to enter MN Bypass mode
334        while ((CM_WKUP_REG(CM_IDLEST_DPLL_MPU) & 0x00000101) != 0x00000100);
335
336        // Set the ARM core frequency to 1 GHz
337        cm_clksel_dpll_mpu = CM_WKUP_REG(CM_CLKSEL_DPLL_MPU);
338        cm_clksel_dpll_mpu &= ~0x0007FF7F;
339        cm_clksel_dpll_mpu |= 1000 << 8;
340        cm_clksel_dpll_mpu |= 23;
341        CM_WKUP_REG(CM_CLKSEL_DPLL_MPU) = cm_clksel_dpll_mpu;
342        cm_div_m2_dpll_mpu = CM_WKUP_REG(CM_DIV_M2_DPLL_MPU);
343        cm_div_m2_dpll_mpu &= ~0x0000001F;
344        cm_div_m2_dpll_mpu |= 0x00000001;
345        CM_WKUP_REG(CM_DIV_M2_DPLL_MPU) = cm_div_m2_dpll_mpu;
346
347        // Lock MPU PLL
348        cm_clkmode_dpll_mpu = CM_WKUP_REG(CM_CLKMODE_DPLL_MPU);
349        cm_clkmode_dpll_mpu &= ~0x00000007;
350        cm_clkmode_dpll_mpu |= 0x00000007;
351        CM_WKUP_REG(CM_CLKMODE_DPLL_MPU) = cm_clkmode_dpll_mpu;
352        // Wait for MPU PLL to lock
353        while ((CM_WKUP_REG(CM_IDLEST_DPLL_MPU) & 0x00000001) != 0x00000001);
354}
355
356void
357core_pll_init(void)
358{
359        uint32_t cm_clkmode_dpll_core;
360        uint32_t cm_clksel_dpll_core;
361        uint32_t cm_div_m4_dpll_core;
362        uint32_t cm_div_m5_dpll_core;
363        uint32_t cm_div_m6_dpll_core;
364
365        // Put Core PLL in MN Bypass mode
366        cm_clkmode_dpll_core = CM_WKUP_REG(CM_CLKMODE_DPLL_CORE);
367        cm_clkmode_dpll_core &= ~0x00000007;
368        cm_clkmode_dpll_core |= 0x00000004;
369        CM_WKUP_REG(CM_CLKMODE_DPLL_CORE) = cm_clkmode_dpll_core;
370        // Wait for Core PLL to enter MN Bypass mode
371        while ((CM_WKUP_REG(CM_IDLEST_DPLL_CORE) & 0x00000101) != 0x00000100);
372
373        // Configure the multiplier and divider
374        cm_clksel_dpll_core = CM_WKUP_REG(CM_CLKSEL_DPLL_CORE);
375        cm_clksel_dpll_core &= ~0x0007FF7F;
376        cm_clksel_dpll_core |= 1000 << 8;
377        cm_clksel_dpll_core |= 23;
378        CM_WKUP_REG(CM_CLKSEL_DPLL_CORE) = cm_clksel_dpll_core;
379        // Configure the M4, M5, and M6 dividers
380        cm_div_m4_dpll_core = CM_WKUP_REG(CM_DIV_M4_DPLL_CORE);
381        cm_div_m4_dpll_core &= ~0x0000001F;
382        cm_div_m4_dpll_core |= 10;
383        CM_WKUP_REG(CM_DIV_M4_DPLL_CORE) = cm_div_m4_dpll_core;
384        cm_div_m5_dpll_core = CM_WKUP_REG(CM_DIV_M5_DPLL_CORE);
385        cm_div_m5_dpll_core &= ~0x0000001F;
386        cm_div_m5_dpll_core |= 8;
387        CM_WKUP_REG(CM_DIV_M5_DPLL_CORE) = cm_div_m5_dpll_core;
388        cm_div_m6_dpll_core = CM_WKUP_REG(CM_DIV_M6_DPLL_CORE);
389        cm_div_m6_dpll_core &= ~0x0000001F;
390        cm_div_m6_dpll_core |= 4;
391        CM_WKUP_REG(CM_DIV_M6_DPLL_CORE) = cm_div_m6_dpll_core;
392
393        // Lock Core PLL
394        cm_clkmode_dpll_core = CM_WKUP_REG(CM_CLKMODE_DPLL_CORE);
395        cm_clkmode_dpll_core &= ~0x00000007;
396        cm_clkmode_dpll_core |= 0x00000007;
397        CM_WKUP_REG(CM_CLKMODE_DPLL_CORE) = cm_clkmode_dpll_core;
398        // Wait for Core PLL to lock
399        while ((CM_WKUP_REG(CM_IDLEST_DPLL_CORE) & 0x00000001) != 0x00000001);
400}
401
402void
403ddr_pll_init(void)
404{
405        uint32_t cm_clkmode_dpll_ddr;
406        uint32_t cm_clksel_dpll_ddr;
407        uint32_t cm_div_m2_dpll_ddr;
408
409        // Put DDR PLL in MN Bypass mode
410        cm_clkmode_dpll_ddr = CM_WKUP_REG(CM_CLKMODE_DPLL_DDR);
411        cm_clkmode_dpll_ddr &= ~0x00000007;
412        cm_clkmode_dpll_ddr |= 0x00000004;
413        CM_WKUP_REG(CM_CLKMODE_DPLL_DDR) = cm_clkmode_dpll_ddr;
414        // Wait for DDR PLL to enter MN Bypass mode
415        while ((CM_WKUP_REG(CM_IDLEST_DPLL_DDR) & 0x00000101) != 0x00000100);
416
417        // Set the DDR frequency to 400 MHz
418        cm_clksel_dpll_ddr = CM_WKUP_REG(CM_CLKSEL_DPLL_DDR);
419        cm_clksel_dpll_ddr &= ~0x0007FF7F;
420        cm_clksel_dpll_ddr |= 400 << 8;
421        cm_clksel_dpll_ddr |= 23;
422        CM_WKUP_REG(CM_CLKSEL_DPLL_DDR) = cm_clksel_dpll_ddr;
423        // Set M2 divider
424        cm_div_m2_dpll_ddr = CM_WKUP_REG(CM_DIV_M2_DPLL_DDR);
425        cm_div_m2_dpll_ddr &= ~0x0000001F;
426        cm_div_m2_dpll_ddr |= 1;
427        CM_WKUP_REG(CM_DIV_M2_DPLL_DDR) = cm_div_m2_dpll_ddr;
428
429        // Lock the DDR PLL
430        cm_clkmode_dpll_ddr = CM_WKUP_REG(CM_CLKMODE_DPLL_DDR);
431        cm_clkmode_dpll_ddr &= ~0x00000007;
432        cm_clkmode_dpll_ddr |= 0x00000007;
433        CM_WKUP_REG(CM_CLKMODE_DPLL_DDR) = cm_clkmode_dpll_ddr;
434        // Wait for DDR PLL to lock
435        while ((CM_WKUP_REG(CM_IDLEST_DPLL_DDR) & 0x00000001) != 0x00000001);
436}
437
438void
439per_pll_init(void)
440{
441        uint32_t cm_clkmode_dpll_per;
442        uint32_t cm_clksel_dpll_per;
443        uint32_t cm_div_m2_dpll_per;
444
445        // Put Per PLL in MN Bypass mode
446        cm_clkmode_dpll_per = CM_WKUP_REG(CM_CLKMODE_DPLL_PER);
447        cm_clkmode_dpll_per &= ~0x00000007;
448        cm_clkmode_dpll_per |= 0x00000004;
449        CM_WKUP_REG(CM_CLKMODE_DPLL_PER) = cm_clkmode_dpll_per;
450        // Wait for Per PLL to enter MN Bypass mode
451        while ((CM_WKUP_REG(CM_IDLEST_DPLL_PER) & 0x00000101) != 0x00000100);
452
453        // Configure the multiplier and divider
454        cm_clksel_dpll_per = CM_WKUP_REG(CM_CLKSEL_DPLL_PER);
455        cm_clksel_dpll_per &= ~0xFF0FFFFF;
456        cm_clksel_dpll_per |= CM_CLKSEL_DPLL_PER_DPLL_SD_DIV | CM_CLKSEL_DPLL_PER_DPLL_MULT |
457                CM_CLKSEL_DPLL_PER_DPLL_DIV;
458        CM_WKUP_REG(CM_CLKSEL_DPLL_PER) = cm_clksel_dpll_per;
459        // Set M2 divider
460        cm_div_m2_dpll_per = CM_WKUP_REG(CM_DIV_M2_DPLL_PER);
461        cm_div_m2_dpll_per &= ~0x0000007F;
462        cm_div_m2_dpll_per |= 5;
463        CM_WKUP_REG(CM_DIV_M2_DPLL_PER) = cm_div_m2_dpll_per;
464
465        // Lock the Per PLL
466        cm_clkmode_dpll_per = CM_WKUP_REG(CM_CLKMODE_DPLL_PER);
467        cm_clkmode_dpll_per &= ~0x00000007;
468        cm_clkmode_dpll_per |= 0x00000007;
469        CM_WKUP_REG(CM_CLKMODE_DPLL_PER) = cm_clkmode_dpll_per;
470        // Wait for Per PLL to lock
471        while ((CM_WKUP_REG(CM_IDLEST_DPLL_PER) & 0x00000001) != 0x00000001);
472}
473
474void
475pll_init(void)
476{
477        mpu_pll_init();
478        core_pll_init();
479        ddr_pll_init();
480        per_pll_init();
481}
482
483void
484ddr_init(void)
485{
486        uint32_t reg;
487
488        // Enable the control module:
489        CM_WKUP_REG(CM_WKUP_CONTROL_CLKCTRL) |= 2;
490
491        // Enable EMIF module
492        reg = CM_PER_REG(CM_PER_EMIF_CLKCTRL);
493        reg &= ~3;
494        reg |= 2;
495        CM_PER_REG(CM_PER_EMIF_CLKCTRL) = reg;
496        while ((CM_PER_REG(CM_PER_L3_CLKSTCTRL) & 0x00000004) != 0x00000004);
497
498        // Configure VTP control
499        CNTL_MODULE_REG(VTP_CTRL) |= 0x00000040;
500        CNTL_MODULE_REG(VTP_CTRL) &= ~1;
501        CNTL_MODULE_REG(VTP_CTRL) |= 1;
502        // Wait for VTP control to be ready
503        while ((CNTL_MODULE_REG(VTP_CTRL) & 0x00000020) != 0x00000020);
504
505        // Configure the DDR PHY CMDx/DATAx registers
506        DDR_PHY_REG(CMD0_REG_PHY_CTRL_SLAVE_RATIO_0) = 0x80;
507        DDR_PHY_REG(CMD0_REG_PHY_INVERT_CLKOUT_0) = 0;
508        DDR_PHY_REG(CMD1_REG_PHY_CTRL_SLAVE_RATIO_0) = 0x80;
509        DDR_PHY_REG(CMD1_REG_PHY_INVERT_CLKOUT_0) = 0;
510        DDR_PHY_REG(CMD2_REG_PHY_CTRL_SLAVE_RATIO_0) = 0x80;
511        DDR_PHY_REG(CMD2_REG_PHY_INVERT_CLKOUT_0) = 0;
512
513        DDR_PHY_REG(DATA0_REG_PHY_RD_DQS_SLAVE_RATIO_0) = 0x3A;
514        DDR_PHY_REG(DATA0_REG_PHY_WR_DQS_SLAVE_RATIO_0) = 0x45;
515        DDR_PHY_REG(DATA0_REG_PHY_WR_DATA_SLAVE_RATIO_0) = 0x7C;
516        DDR_PHY_REG(DATA0_REG_PHY_FIFO_WE_SLAVE_RATIO_0) = 0x96;
517
518        DDR_PHY_REG(DATA1_REG_PHY_RD_DQS_SLAVE_RATIO_0) = 0x3A;
519        DDR_PHY_REG(DATA1_REG_PHY_WR_DQS_SLAVE_RATIO_0) = 0x45;
520        DDR_PHY_REG(DATA1_REG_PHY_WR_DATA_SLAVE_RATIO_0) = 0x7C;
521        DDR_PHY_REG(DATA1_REG_PHY_FIFO_WE_SLAVE_RATIO_0) = 0x96;
522
523        CNTL_MODULE_REG(DDR_CMD0_IOCTRL) = 0x018B;
524        CNTL_MODULE_REG(DDR_CMD1_IOCTRL) = 0x018B;
525        CNTL_MODULE_REG(DDR_CMD2_IOCTRL) = 0x018B;
526        CNTL_MODULE_REG(DDR_DATA0_IOCTRL) = 0x018B;
527        CNTL_MODULE_REG(DDR_DATA1_IOCTRL) = 0x018B;
528
529        CNTL_MODULE_REG(DDR_IO_CTRL) &= ~0x10000000;
530
531        CNTL_MODULE_REG(DDR_CKE_CTRL) |= 0x00000001;
532
533        // Enable dynamic power down when no read is being performed and set read latency
534        // to CAS Latency + 2 - 1
535        EMIF0_REG(DDR_PHY_CTRL_1) = 0x00100007;
536        EMIF0_REG(DDR_PHY_CTRL_1_SHDW) = 0x00100007;
537
538        // Configure the AC timing characteristics
539        EMIF0_REG(SDRAM_TIM_1) = 0x0AAAD4DB;
540        EMIF0_REG(SDRAM_TIM_1_SHDW) = 0x0AAAD4DB;
541        EMIF0_REG(SDRAM_TIM_2) = 0x266B7FDA;
542        EMIF0_REG(SDRAM_TIM_2_SHDW) = 0x266B7FDA;
543        EMIF0_REG(SDRAM_TIM_3) = 0x501F867F;
544        EMIF0_REG(SDRAM_TIM_3_SHDW) = 0x501F867F;
545
546        // Set the refresh rate, 400,000,000 * 7.8 * 10^-6 = 3120 = 0x0C30
547        EMIF0_REG(SDRAM_REF_CTRL) = 0x00000C30;
548        // set the referesh rate shadow register to the same value as previous
549        EMIF0_REG(SDRAM_REF_CTRL_SHDW) = 0x00000C30;
550
551        // Configure the ZQ Calibration
552        EMIF0_REG(ZQ_CONFIG) = 0x50074BE4;
553
554        // Configure the SDRAM characteristics
555        reg |= SDRAM_CONFIG_REG_SDRAM_TYPE_DDR3 | SDRAM_CONFIG_REG_IBANK_POS_0 |
556                SDRAM_CONFIG_REG_DDR_TERM_DDR3_RZQ_4 | SDRAM_CONFIG_REG_DDR2_DDQS_DIFF_DQS |
557                SDRAM_CONFIG_REG_DYN_ODT_RZQ_2 | SDRAM_CONFIG_REG_DDR_DISABLE_DLL_ENABLE |
558                SDRAM_CONFIG_REG_SDRAM_DRIVE_RZQ_6 | SDRAM_CONFIG_REG_CAS_WR_LATENCY_5 |
559                SDRAM_CONFIG_REG_NARROW_MODE_16BIT | SDRAM_CONFIG_REG_CAS_LATENCY_6 |
560                SDRAM_CONFIG_REG_ROWSIZE_15BIT | SDRAM_CONFIG_REG_IBANK_8 |
561                SDRAM_CONFIG_REG_EBANK_1 | SDRAM_CONFIG_REG_PAGESIZE_1024_WORD;
562        EMIF0_REG(SDRAM_CONFIG) = reg;
563        CNTL_MODULE_REG(CONTROL_EMIF_SDRAM_CONFIG) = reg;
564
565        // Set the external bank position to 0
566        EMIF0_REG(SDRAM_CONFIG_2) |= SDRAM_CONFIG_2_REG_EBANK_POS_0;
567}
Note: See TracBrowser for help on using the repository browser.