blob: 3332f5aca6348ea45184ba95b4e4c3efafd40e15 [file] [log] [blame]
Andre Schwarz2a293292008-07-09 18:30:44 +02001/*
2 * (C) Copyright 2003
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 2005-2007
9 * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.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 <malloc.h>
33#include <pci.h>
34#include <i2c.h>
Stefan Roese37628252008-08-06 14:05:38 +020035#include <fpga.h>
Andre Schwarz2a293292008-07-09 18:30:44 +020036#include <environment.h>
37#include <fdt_support.h>
38#include <asm/io.h>
39#include "fpga.h"
40#include "mvbc_p.h"
41
42#define SDRAM_MODE 0x00CD0000
43#define SDRAM_CONTROL 0x504F0000
44#define SDRAM_CONFIG1 0xD2322800
45#define SDRAM_CONFIG2 0x8AD70000
46
47DECLARE_GLOBAL_DATA_PTR;
48
49static void sdram_start (int hi_addr)
50{
51 long hi_bit = hi_addr ? 0x01000000 : 0;
52
53 /* unlock mode register */
54 out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000000 | hi_bit);
55
56 /* precharge all banks */
57 out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit);
58
59 /* precharge all banks */
60 out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit);
61
62 /* auto refresh */
63 out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000004 | hi_bit);
64
65 /* set mode register */
66 out_be32((u32*)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
67
68 /* normal operation */
69 out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | hi_bit);
70}
71
72phys_addr_t initdram (int board_type)
73{
74 ulong dramsize = 0;
75 ulong test1,
76 test2;
77
78 /* setup SDRAM chip selects */
79 out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x0000001e);
80
81 /* setup config registers */
82 out_be32((u32*)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
83 out_be32((u32*)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
84
85 /* find RAM size using SDRAM CS0 only */
86 sdram_start(0);
87 test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
88 sdram_start(1);
89 test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000);
90 if (test1 > test2) {
91 sdram_start(0);
92 dramsize = test1;
93 } else
94 dramsize = test2;
95
96 if (dramsize < (1 << 20))
97 dramsize = 0;
98
99 if (dramsize > 0)
100 out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x13 +
101 __builtin_ffs(dramsize >> 20) - 1);
102 else
103 out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0);
104
105 return dramsize;
106}
107
108void mvbc_init_gpio(void)
109{
110 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
111
112 printf("Ports : 0x%08x\n", gpio->port_config);
Stefan Roese37628252008-08-06 14:05:38 +0200113 printf("PORCFG: 0x%08lx\n", *(vu_long*)MPC5XXX_CDM_PORCFG);
Andre Schwarz2a293292008-07-09 18:30:44 +0200114
115 out_be32(&gpio->simple_ddr, SIMPLE_DDR);
116 out_be32(&gpio->simple_dvo, SIMPLE_DVO);
117 out_be32(&gpio->simple_ode, SIMPLE_ODE);
118 out_be32(&gpio->simple_gpioe, SIMPLE_GPIOEN);
119
Andre Schwarzf6f431d2008-08-18 12:02:51 +0200120 out_8(&gpio->sint_ode, SINT_ODE);
121 out_8(&gpio->sint_ddr, SINT_DDR);
122 out_8(&gpio->sint_dvo, SINT_DVO);
123 out_8(&gpio->sint_inten, SINT_INTEN);
124 out_be16(&gpio->sint_itype, SINT_ITYPE);
125 out_8(&gpio->sint_gpioe, SINT_GPIOEN);
Andre Schwarz2a293292008-07-09 18:30:44 +0200126
127 out_8((u8*)MPC5XXX_WU_GPIO_ODE, WKUP_ODE);
128 out_8((u8*)MPC5XXX_WU_GPIO_DIR, WKUP_DIR);
129 out_8((u8*)MPC5XXX_WU_GPIO_DATA_O, WKUP_DO);
130 out_8((u8*)MPC5XXX_WU_GPIO_ENABLE, WKUP_EN);
131
132 printf("simple_gpioe: 0x%08x\n", gpio->simple_gpioe);
133 printf("sint_gpioe : 0x%08x\n", gpio->sint_gpioe);
134}
135
136void reset_environment(void)
137{
138 char *s, sernr[64];
139
140 printf("\n*** RESET ENVIRONMENT ***\n");
141 memset(sernr, 0, sizeof(sernr));
142 s = getenv("serial#");
143 if (s) {
144 printf("found serial# : %s\n", s);
145 strncpy(sernr, s, 64);
146 }
147 gd->env_valid = 0;
148 env_relocate();
149 if (s)
150 setenv("serial#", sernr);
151}
152
153int misc_init_r(void)
154{
155 char *s = getenv("reset_env");
156
157 if (!s) {
158 if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
159 return 0;
160 udelay(50000);
161 if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
162 return 0;
163 udelay(50000);
164 if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
165 return 0;
166 }
167 printf(" === FACTORY RESET ===\n");
168 reset_environment();
169 saveenv();
170
171 return -1;
172}
173
174int checkboard(void)
175{
176 mvbc_init_gpio();
177 printf("Board: Matrix Vision mvBlueCOUGAR-P\n");
178
179 return 0;
180}
181
182void flash_preinit(void)
183{
184 /*
185 * Now, when we are in RAM, enable flash write
186 * access for detection process.
187 * Note that CS_BOOT cannot be cleared when
188 * executing in flash.
189 */
190 clrbits_be32((u32*)MPC5XXX_BOOTCS_CFG, 0x1);
191}
192
193void flash_afterinit(ulong size)
194{
195 out_be32((u32*)MPC5XXX_BOOTCS_START, START_REG(CFG_BOOTCS_START |
196 size));
197 out_be32((u32*)MPC5XXX_CS0_START, START_REG(CFG_BOOTCS_START |
198 size));
199 out_be32((u32*)MPC5XXX_BOOTCS_STOP, STOP_REG(CFG_BOOTCS_START | size,
200 size));
201 out_be32((u32*)MPC5XXX_CS0_STOP, STOP_REG(CFG_BOOTCS_START | size,
202 size));
203}
204
205void pci_mvbc_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
206{
207 unsigned char line = 0xff;
208 u32 base;
209
210 if (PCI_BUS(dev) == 0) {
211 switch (PCI_DEV (dev)) {
212 case 0xa: /* FPGA */
213 line = 3;
214 pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &base);
215 printf("found FPA - enable arbitration\n");
216 writel(0x03, (u32*)(base + 0x80c0));
217 writel(0xf0, (u32*)(base + 0x8080));
218 break;
219 case 0xb: /* LAN */
220 line = 2;
221 break;
222 case 0x1a:
223 break;
224 default:
225 printf ("***pci_scan: illegal dev = 0x%08x\n", PCI_DEV (dev));
226 break;
227 }
228 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, line);
229 }
230}
231
232struct pci_controller hose = {
233 fixup_irq:pci_mvbc_fixup_irq
234};
235
236int mvbc_p_load_fpga(void)
237{
238 size_t data_size = 0;
239 void *fpga_data = NULL;
240 char *datastr = getenv("fpgadata");
241 char *sizestr = getenv("fpgadatasize");
242
243 if (datastr)
244 fpga_data = (void *)simple_strtoul(datastr, NULL, 16);
245 if (sizestr)
246 data_size = (size_t)simple_strtoul(sizestr, NULL, 16);
247
248 return fpga_load(0, fpga_data, data_size);
249}
250
251extern void pci_mpc5xxx_init(struct pci_controller *);
252
253void pci_init_board(void)
254{
255 char *s;
256 int load_fpga = 1;
257
258 mvbc_p_init_fpga();
259 s = getenv("skip_fpga");
260 if (s) {
261 printf("found 'skip_fpga' -> FPGA _not_ loaded !\n");
262 load_fpga = 0;
263 }
264 if (load_fpga) {
265 printf("loading FPGA ... ");
266 mvbc_p_load_fpga();
267 printf("done\n");
268 }
269 pci_mpc5xxx_init(&hose);
270}
271
272u8 *dhcp_vendorex_prep(u8 *e)
273{
274 char *ptr;
275
276 /* DHCP vendor-class-identifier = 60 */
277 if ((ptr = getenv("dhcp_vendor-class-identifier"))) {
278 *e++ = 60;
279 *e++ = strlen(ptr);
280 while (*ptr)
281 *e++ = *ptr++;
282 }
283 /* DHCP_CLIENT_IDENTIFIER = 61 */
284 if ((ptr = getenv("dhcp_client_id"))) {
285 *e++ = 61;
286 *e++ = strlen(ptr);
287 while (*ptr)
288 *e++ = *ptr++;
289 }
290
291 return e;
292}
293
294u8 *dhcp_vendorex_proc (u8 *popt)
295{
296 return NULL;
297}
298
299void show_boot_progress(int val)
300{
301 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
302
303 switch(val) {
304 case 0: /* FPGA ok */
305 setbits_be32(&gpio->simple_dvo, 0x80);
306 break;
307 case 1:
308 setbits_be32(&gpio->simple_dvo, 0x40);
309 break;
310 case 12:
311 setbits_be32(&gpio->simple_dvo, 0x20);
312 break;
313 case 15:
314 setbits_be32(&gpio->simple_dvo, 0x10);
315 break;
316 default:
317 break;
318 }
319
320}
321
322void ft_board_setup(void *blob, bd_t *bd)
323{
324 ft_cpu_setup(blob, bd);
325 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
326}