]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/v38b/v38b.c
Coding Style cleanup.
[karo-tx-uboot.git] / board / v38b / v38b.c
1 /*
2  * (C) Copyright 2003-2006
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * (C) Copyright 2004
6  * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
7  *
8  * See file CREDITS for list of people who contributed to this
9  * project.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of
14  * the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24  * MA 02111-1307 USA
25  */
26
27 #include <common.h>
28 #include <mpc5xxx.h>
29 #include <asm/processor.h>
30
31 #ifndef CFG_RAMBOOT
32 static void sdram_start(int hi_addr)
33 {
34         long hi_addr_bit = hi_addr ? 0x01000000 : 0;
35
36         /* unlock mode register */
37         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
38         __asm__ volatile ("sync");
39
40         /* precharge all banks */
41         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
42         __asm__ volatile ("sync");
43
44 #if SDRAM_DDR
45         /* set mode register: extended mode */
46         *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
47         __asm__ volatile ("sync");
48
49         /* set mode register: reset DLL */
50         *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
51         __asm__ volatile ("sync");
52 #endif /* SDRAM_DDR */
53
54         /* precharge all banks */
55         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
56         __asm__ volatile ("sync");
57
58         /* auto refresh */
59         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
60         __asm__ volatile ("sync");
61
62         /* set mode register */
63         *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
64         __asm__ volatile ("sync");
65
66         /* normal operation */
67         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
68         __asm__ volatile ("sync");
69 }
70 #endif /* !CFG_RAMBOOT */
71
72
73 long int initdram(int board_type)
74 {
75         ulong dramsize = 0;
76         ulong dramsize2 = 0;
77         uint svr, pvr;
78
79 #ifndef CFG_RAMBOOT
80         ulong test1, test2;
81
82         /* setup SDRAM chip selects */
83         *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e;  /* 2G at 0x0 */
84         *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000;  /* disabled */
85         __asm__ volatile ("sync");
86
87         /* setup config registers */
88         *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
89         *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
90         __asm__ volatile ("sync");
91
92 #if SDRAM_DDR
93         /* set tap delay */
94         *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
95         __asm__ volatile ("sync");
96 #endif /* SDRAM_DDR */
97
98         /* find RAM size using SDRAM CS0 only */
99         sdram_start(0);
100         test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
101         sdram_start(1);
102         test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
103         if (test1 > test2) {
104                 sdram_start(0);
105                 dramsize = test1;
106         } else
107                 dramsize = test2;
108
109         /* memory smaller than 1MB is impossible */
110         if (dramsize < (1 << 20))
111                 dramsize = 0;
112
113         /* set SDRAM CS0 size according to the amount of RAM found */
114         if (dramsize > 0)
115                 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 + __builtin_ffs(dramsize >> 20) - 1;
116         else
117                 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
118
119         /* let SDRAM CS1 start right after CS0 */
120         *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize + 0x0000001e;/* 2G */
121
122         /* find RAM size using SDRAM CS1 only */
123         if (!dramsize)
124                 sdram_start(0);
125         test2 = test1 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
126         if (!dramsize) {
127                 sdram_start(1);
128                 test2 = get_ram_size((long *)(CFG_SDRAM_BASE + dramsize), 0x80000000);
129         }
130         if (test1 > test2) {
131                 sdram_start(0);
132                 dramsize2 = test1;
133         } else
134                 dramsize2 = test2;
135
136         /* memory smaller than 1MB is impossible */
137         if (dramsize2 < (1 << 20))
138                 dramsize2 = 0;
139
140         /* set SDRAM CS1 size according to the amount of RAM found */
141         if (dramsize2 > 0)
142                 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize
143                         | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1);
144         else
145                 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
146
147 #else /* CFG_RAMBOOT */
148
149         /* retrieve size of memory connected to SDRAM CS0 */
150         dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
151         if (dramsize >= 0x13)
152                 dramsize = (1 << (dramsize - 0x13)) << 20;
153         else
154                 dramsize = 0;
155
156         /* retrieve size of memory connected to SDRAM CS1 */
157         dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
158         if (dramsize2 >= 0x13)
159                 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
160         else
161                 dramsize2 = 0;
162
163 #endif /* CFG_RAMBOOT */
164
165         /*
166          * On MPC5200B we need to set the special configuration delay in the
167          * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
168          * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
169          *
170          * "The SDelay should be written to a value of 0x00000004. It is
171          * required to account for changes caused by normal wafer processing
172          * parameters."
173          */
174         svr = get_svr();
175         pvr = get_pvr();
176         if ((SVR_MJREV(svr) >= 2) &&
177                 (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
178
179                 *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
180                 __asm__ volatile ("sync");
181         }
182
183         return dramsize + dramsize2;
184 }
185
186
187 int checkboard (void)
188 {
189         puts("Board: MarelV38B\n");
190         return 0;
191 }
192
193
194 int board_early_init_r(void)
195 {
196         /*
197          * Now, when we are in RAM, enable flash write access for detection process.
198          * Note that CS_BOOT cannot be cleared when executing in flash.
199          */
200         *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
201         return 0;
202 }
203
204
205 #if defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET)
206
207 #define GPIO_PSC1_4     0x01000000UL
208
209 void init_ide_reset(void)
210 {
211         debug("init_ide_reset\n");
212
213         /* Configure PSC1_4 as GPIO output for ATA reset */
214         *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
215         *(vu_long *) MPC5XXX_WU_GPIO_DIR    |= GPIO_PSC1_4;
216         /* Deassert reset */
217         *(vu_long *) MPC5XXX_WU_GPIO_DATA   |= GPIO_PSC1_4;
218 }
219
220
221 void ide_set_reset(int idereset)
222 {
223         debug("ide_reset(%d)\n", idereset);
224
225         if (idereset) {
226                 *(vu_long *) MPC5XXX_WU_GPIO_DATA &= ~GPIO_PSC1_4;
227                 /* Make a delay. MPC5200 spec says 25 usec min */
228                 udelay(500000);
229         } else
230                 *(vu_long *) MPC5XXX_WU_GPIO_DATA |=  GPIO_PSC1_4;
231 }
232 #endif /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */
233
234
235 void led_d4_on(void)
236 {
237         /* TIMER7 as GPIO output low */
238         *(vu_long *) (MPC5XXX_GPT + 0x70) |= 0x24;
239 }
240
241
242 void led_d4_off(void)
243 {
244         /* TIMER7 as GPIO output high */
245         *(vu_long *) (MPC5XXX_GPT + 0x70) |= 0x34;
246 }
247
248
249 void hw_watchdog_reset(void)
250 {
251 /* TODO fill this in */
252 }