blob: 23d0f56bd625a20ed1a1daa47904d6c14dee7527 [file] [log] [blame]
Heiko Schocher23cd0b12008-01-11 15:15:14 +01001/*
2 * (C) Copyright 2007
3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Heiko Schocher23cd0b12008-01-11 15:15:14 +01006 */
7
8#include <common.h>
9#include <mpc5xxx.h>
10#include <pci.h>
11
12#include "mt48lc16m16a2-75.h"
13
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020014#ifndef CONFIG_SYS_RAMBOOT
Heiko Schocher23cd0b12008-01-11 15:15:14 +010015static void sdram_start (int hi_addr)
16{
17 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
18
19 /* unlock mode register */
20 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
21 __asm__ volatile ("sync");
22
23 /* precharge all banks */
24 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
25 __asm__ volatile ("sync");
26
27#if SDRAM_DDR
28 /* set mode register: extended mode */
29 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
30 __asm__ volatile ("sync");
31
32 /* set mode register: reset DLL */
33 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
34 __asm__ volatile ("sync");
35#endif
36
37 /* precharge all banks */
38 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
39 __asm__ volatile ("sync");
40
41 /* auto refresh */
42 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
43 __asm__ volatile ("sync");
44
45 /* set mode register */
46 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
47 __asm__ volatile ("sync");
48
49 /* normal operation */
50 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
51 __asm__ volatile ("sync");
52}
53#endif
54
55/*
56 * ATTENTION: Although partially referenced initdram does NOT make real use
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020057 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
Heiko Schocher23cd0b12008-01-11 15:15:14 +010058 * is something else than 0x00000000.
59 */
60
Becky Brucebd99ae72008-06-09 16:03:40 -050061phys_size_t initdram (int board_type)
Heiko Schocher23cd0b12008-01-11 15:15:14 +010062{
63 ulong dramsize = 0;
64 ulong dramsize2 = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020065#ifndef CONFIG_SYS_RAMBOOT
Heiko Schocher23cd0b12008-01-11 15:15:14 +010066 ulong test1, test2;
67
68 /* setup SDRAM chip selects */
69 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001b;/* 256MB at 0x0 */
70 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x10000000;/* disabled */
71 __asm__ volatile ("sync");
72
73 /* setup config registers */
74 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
75 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
76 __asm__ volatile ("sync");
77
78#if SDRAM_DDR && SDRAM_TAPDELAY
79 /* set tap delay */
80 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
81 __asm__ volatile ("sync");
82#endif
83
84 /* find RAM size using SDRAM CS0 only */
85 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020086 test1 = (ulong )get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x10000000);
Heiko Schocher23cd0b12008-01-11 15:15:14 +010087 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020088 test2 = (ulong )get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x10000000);
Heiko Schocher23cd0b12008-01-11 15:15:14 +010089 if (test1 > test2) {
90 sdram_start(0);
91 dramsize = test1;
92 } else {
93 dramsize = test2;
94 }
95
96 /* memory smaller than 1MB is impossible */
97 if (dramsize < (1 << 20)) {
98 dramsize = 0;
99 }
100
101 /* set SDRAM CS0 size according to the amount of RAM found */
102 if (dramsize > 0) {
103 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
104 } else {
105 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
106 }
107
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200108#else /* CONFIG_SYS_RAMBOOT */
Heiko Schocher23cd0b12008-01-11 15:15:14 +0100109
110 /* retrieve size of memory connected to SDRAM CS0 */
111 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
112 if (dramsize >= 0x13) {
113 dramsize = (1 << (dramsize - 0x13)) << 20;
114 } else {
115 dramsize = 0;
116 }
117
118 /* retrieve size of memory connected to SDRAM CS1 */
119 dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
120 if (dramsize2 >= 0x13) {
121 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
122 } else {
123 dramsize2 = 0;
124 }
125
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200126#endif /* CONFIG_SYS_RAMBOOT */
Heiko Schocher23cd0b12008-01-11 15:15:14 +0100127
128 return dramsize + dramsize2;
129}
130
131int checkboard (void)
132{
133 puts ("Board: MUNICes\n");
134 return 0;
135}
136
137#ifdef CONFIG_PCI
138static struct pci_controller hose;
139
140extern void pci_mpc5xxx_init(struct pci_controller *);
141
142void pci_init_board(void)
143{
144 pci_mpc5xxx_init(&hose);
145}
146#endif
147
148#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Simon Glass2aec3cc2014-10-23 18:58:47 -0600149int ft_board_setup(void *blob, bd_t *bd)
Heiko Schocher23cd0b12008-01-11 15:15:14 +0100150{
151 ft_cpu_setup(blob, bd);
Simon Glass2aec3cc2014-10-23 18:58:47 -0600152
153 return 0;
Heiko Schocher23cd0b12008-01-11 15:15:14 +0100154}
155#endif