Coding style cleanup
[platform/kernel/u-boot.git] / board / cm1_qp1 / cm1_qp1.c
1 /*
2  * (C) Copyright 2003-2007
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  * (C) Copyright 2004-2005
9  * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
10  *
11  * See file CREDITS for list of people who contributed to this
12  * project.
13  *
14  * This program is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU General Public License as
16  * published by the Free Software Foundation; either version 2 of
17  * the License, or (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27  * MA 02111-1307 USA
28  */
29
30 #include <common.h>
31 #include <mpc5xxx.h>
32 #include <pci.h>
33 #include <asm/processor.h>
34 #include <i2c.h>
35 #ifdef CONFIG_OF_FLAT_TREE
36 #include <ft_build.h>
37 #endif /* CONFIG_OF_FLAT_TREE */
38
39 #include "fwupdate.h"
40
41 #ifndef CFG_RAMBOOT
42 /*
43  * Helper function to initialize SDRAM controller.
44  */
45 static void sdram_start(int hi_addr)
46 {
47         long hi_addr_bit = hi_addr ? 0x01000000 : 0;
48
49         /* unlock mode register */
50         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 |
51                                                 hi_addr_bit;
52
53         /* precharge all banks */
54         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 |
55                                                 hi_addr_bit;
56
57         /* auto refresh */
58         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
59                                                 hi_addr_bit;
60
61         /* auto refresh, second time */
62         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 |
63                                                 hi_addr_bit;
64
65         /* set mode register */
66         *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
67
68         /* normal operation */
69         *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
70 }
71 #endif /* CFG_RAMBOOT */
72
73 /*
74  * Initalize SDRAM - configure SDRAM controller, detect memory size.
75  */
76 long int initdram(int board_type)
77 {
78         ulong dramsize = 0;
79 #ifndef CFG_RAMBOOT
80         ulong test1, test2;
81
82         /* configure SDRAM start/end for detection */
83         *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001e; /* 2G at 0x0 */
84
85         /* setup config registers */
86         *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
87         *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
88
89         sdram_start(0);
90         test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
91         sdram_start(1);
92         test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
93         if (test1 > test2) {
94                 sdram_start(0);
95                 dramsize = test1;
96         } else
97                 dramsize = test2;
98
99         /* memory smaller than 1MB is impossible */
100         if (dramsize < (1 << 20))
101                 dramsize = 0;
102
103         /* set SDRAM CS0 size according to the amount of RAM found */
104         if (dramsize > 0) {
105                 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
106                         __builtin_ffs(dramsize >> 20) - 1;
107         } else
108                 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
109 #else /* CFG_RAMBOOT */
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 #endif /* CFG_RAMBOOT */
117
118         /*
119          * On MPC5200B we need to set the special configuration delay in the
120          * DDR controller.  Refer to chapter 8.7.5 SDelay--MBAR + 0x0190 of
121          * the MPC5200B User's Manual.
122          */
123         *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
124         __asm__ volatile ("sync");
125
126         return dramsize;
127 }
128
129
130 int checkboard(void)
131 {
132         puts("Board: CM1.QP1\n");
133         return 0;
134 }
135
136
137 int board_early_init_r(void)
138 {
139         /*
140          * Now, when we are in RAM, enable flash write access for detection
141          * process. Note that CS_BOOT cannot be cleared when executing in
142          * flash.
143          */
144         *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
145         return 0;
146 }
147
148
149 #ifdef CONFIG_POST
150 int post_hotkeys_pressed(void)
151 {
152         return 0;
153 }
154 #endif /* CONFIG_POST */
155
156
157 #if defined(CONFIG_POST) || defined(CONFIG_LOGBUFFER)
158 void post_word_store(ulong a)
159 {
160         vu_long *save_addr = (vu_long *)(MPC5XXX_SRAM + MPC5XXX_SRAM_POST_SIZE);
161         *save_addr = a;
162 }
163
164
165 ulong post_word_load(void)
166 {
167         vu_long *save_addr = (vu_long *)(MPC5XXX_SRAM + MPC5XXX_SRAM_POST_SIZE);
168         return *save_addr;
169 }
170 #endif /* CONFIG_POST || CONFIG_LOGBUFFER */
171
172
173 #ifdef CONFIG_MISC_INIT_R
174 int misc_init_r(void)
175 {
176 #if defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C)
177         uchar buf[6];
178         char str[18];
179
180         /* Read ethaddr from EEPROM */
181         if (i2c_read(CFG_I2C_EEPROM, CONFIG_MAC_OFFSET, 2, buf, 6) == 0) {
182                 sprintf(str, "%02X:%02X:%02X:%02X:%02X:%02X",
183                         buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
184                 /* Check if MAC addr is owned by Schindler */
185                 if (strstr(str, "00:06:C3") != str) {
186                         printf(LOG_PREFIX "Warning - Illegal MAC address (%s)"
187                                 " in EEPROM.\n", str);
188                         printf(LOG_PREFIX "Using MAC from environment\n");
189                 } else {
190                         printf(LOG_PREFIX "Using MAC (%s) from I2C EEPROM\n",
191                                 str);
192                         setenv("ethaddr", str);
193                 }
194         } else {
195                 printf(LOG_PREFIX "Warning - Unable to read MAC from I2C"
196                         " device at address %02X:%04X\n", CFG_I2C_EEPROM,
197                         CONFIG_MAC_OFFSET);
198                 printf(LOG_PREFIX "Using MAC from environment\n");
199         }
200         return 0;
201 #endif /* defined(CONFIG_HARD_I2C) || defined(CONFIG_SOFT_I2C) */
202 }
203 #endif /* CONFIG_MISC_INIT_R */
204
205
206 #ifdef CONFIG_LAST_STAGE_INIT
207 int last_stage_init(void)
208 {
209 #ifdef CONFIG_USB_STORAGE
210         cm1_fwupdate();
211 #endif /* CONFIG_USB_STORAGE */
212         return 0;
213 }
214 #endif /* CONFIG_LAST_STAGE_INIT */
215
216
217 #if defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP)
218 void ft_board_setup(void *blob, bd_t *bd)
219 {
220         ft_cpu_setup(blob, bd);
221 }
222 #endif /* defined(CONFIG_OF_FLAT_TREE) && defined(CONFIG_OF_BOARD_SETUP) */