blob: 8faebeeebec308d043ade17e761c72407d43cebf [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
Andre Schwarz2a293292008-07-09 18:30:44 +020012 */
13
14#include <common.h>
15#include <mpc5xxx.h>
16#include <malloc.h>
17#include <pci.h>
18#include <i2c.h>
Stefan Roese37628252008-08-06 14:05:38 +020019#include <fpga.h>
Andre Schwarz2a293292008-07-09 18:30:44 +020020#include <environment.h>
21#include <fdt_support.h>
Ben Warrencba88512008-08-31 10:39:12 -070022#include <netdev.h>
Andre Schwarz2a293292008-07-09 18:30:44 +020023#include <asm/io.h>
24#include "fpga.h"
25#include "mvbc_p.h"
André Schwarza8e1d952009-08-27 14:48:35 +020026#include "../common/mv_common.h"
Andre Schwarz2a293292008-07-09 18:30:44 +020027
28#define SDRAM_MODE 0x00CD0000
29#define SDRAM_CONTROL 0x504F0000
30#define SDRAM_CONFIG1 0xD2322800
31#define SDRAM_CONFIG2 0x8AD70000
32
33DECLARE_GLOBAL_DATA_PTR;
34
35static void sdram_start (int hi_addr)
36{
37 long hi_bit = hi_addr ? 0x01000000 : 0;
38
39 /* unlock mode register */
40 out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000000 | hi_bit);
41
42 /* precharge all banks */
43 out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit);
44
45 /* precharge all banks */
46 out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit);
47
48 /* auto refresh */
49 out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000004 | hi_bit);
50
51 /* set mode register */
52 out_be32((u32*)MPC5XXX_SDRAM_MODE, SDRAM_MODE);
53
54 /* normal operation */
55 out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | hi_bit);
56}
57
58phys_addr_t initdram (int board_type)
59{
60 ulong dramsize = 0;
61 ulong test1,
62 test2;
63
64 /* setup SDRAM chip selects */
65 out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x0000001e);
66
67 /* setup config registers */
68 out_be32((u32*)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
69 out_be32((u32*)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
70
71 /* find RAM size using SDRAM CS0 only */
72 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020073 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
Andre Schwarz2a293292008-07-09 18:30:44 +020074 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020075 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000);
Andre Schwarz2a293292008-07-09 18:30:44 +020076 if (test1 > test2) {
77 sdram_start(0);
78 dramsize = test1;
79 } else
80 dramsize = test2;
81
82 if (dramsize < (1 << 20))
83 dramsize = 0;
84
85 if (dramsize > 0)
86 out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x13 +
87 __builtin_ffs(dramsize >> 20) - 1);
88 else
89 out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0);
90
91 return dramsize;
92}
93
94void mvbc_init_gpio(void)
95{
96 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
97
98 printf("Ports : 0x%08x\n", gpio->port_config);
Stefan Roese37628252008-08-06 14:05:38 +020099 printf("PORCFG: 0x%08lx\n", *(vu_long*)MPC5XXX_CDM_PORCFG);
Andre Schwarz2a293292008-07-09 18:30:44 +0200100
101 out_be32(&gpio->simple_ddr, SIMPLE_DDR);
102 out_be32(&gpio->simple_dvo, SIMPLE_DVO);
103 out_be32(&gpio->simple_ode, SIMPLE_ODE);
104 out_be32(&gpio->simple_gpioe, SIMPLE_GPIOEN);
105
Andre Schwarzf6f431d2008-08-18 12:02:51 +0200106 out_8(&gpio->sint_ode, SINT_ODE);
107 out_8(&gpio->sint_ddr, SINT_DDR);
108 out_8(&gpio->sint_dvo, SINT_DVO);
109 out_8(&gpio->sint_inten, SINT_INTEN);
110 out_be16(&gpio->sint_itype, SINT_ITYPE);
111 out_8(&gpio->sint_gpioe, SINT_GPIOEN);
Andre Schwarz2a293292008-07-09 18:30:44 +0200112
113 out_8((u8*)MPC5XXX_WU_GPIO_ODE, WKUP_ODE);
114 out_8((u8*)MPC5XXX_WU_GPIO_DIR, WKUP_DIR);
115 out_8((u8*)MPC5XXX_WU_GPIO_DATA_O, WKUP_DO);
116 out_8((u8*)MPC5XXX_WU_GPIO_ENABLE, WKUP_EN);
117
118 printf("simple_gpioe: 0x%08x\n", gpio->simple_gpioe);
119 printf("sint_gpioe : 0x%08x\n", gpio->sint_gpioe);
120}
121
Andre Schwarz2a293292008-07-09 18:30:44 +0200122int misc_init_r(void)
123{
124 char *s = getenv("reset_env");
125
126 if (!s) {
127 if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
128 return 0;
129 udelay(50000);
130 if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
131 return 0;
132 udelay(50000);
133 if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6)
134 return 0;
135 }
136 printf(" === FACTORY RESET ===\n");
André Schwarza8e1d952009-08-27 14:48:35 +0200137 mv_reset_environment();
Andre Schwarz2a293292008-07-09 18:30:44 +0200138 saveenv();
139
140 return -1;
141}
142
143int checkboard(void)
144{
145 mvbc_init_gpio();
146 printf("Board: Matrix Vision mvBlueCOUGAR-P\n");
147
148 return 0;
149}
150
151void flash_preinit(void)
152{
153 /*
154 * Now, when we are in RAM, enable flash write
155 * access for detection process.
156 * Note that CS_BOOT cannot be cleared when
157 * executing in flash.
158 */
159 clrbits_be32((u32*)MPC5XXX_BOOTCS_CFG, 0x1);
160}
161
162void flash_afterinit(ulong size)
163{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200164 out_be32((u32*)MPC5XXX_BOOTCS_START, START_REG(CONFIG_SYS_BOOTCS_START |
Andre Schwarz2a293292008-07-09 18:30:44 +0200165 size));
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200166 out_be32((u32*)MPC5XXX_CS0_START, START_REG(CONFIG_SYS_BOOTCS_START |
Andre Schwarz2a293292008-07-09 18:30:44 +0200167 size));
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200168 out_be32((u32*)MPC5XXX_BOOTCS_STOP, STOP_REG(CONFIG_SYS_BOOTCS_START | size,
Andre Schwarz2a293292008-07-09 18:30:44 +0200169 size));
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200170 out_be32((u32*)MPC5XXX_CS0_STOP, STOP_REG(CONFIG_SYS_BOOTCS_START | size,
Andre Schwarz2a293292008-07-09 18:30:44 +0200171 size));
172}
173
174void pci_mvbc_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
175{
176 unsigned char line = 0xff;
André Schwarza8e1d952009-08-27 14:48:35 +0200177 char *s = getenv("pci_latency");
Andre Schwarz2a293292008-07-09 18:30:44 +0200178 u32 base;
André Schwarza8e1d952009-08-27 14:48:35 +0200179 u8 val = 0;
180
181 if (s)
182 val = simple_strtoul(s, NULL, 16);
Andre Schwarz2a293292008-07-09 18:30:44 +0200183
184 if (PCI_BUS(dev) == 0) {
185 switch (PCI_DEV (dev)) {
186 case 0xa: /* FPGA */
187 line = 3;
188 pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &base);
André Schwarza8e1d952009-08-27 14:48:35 +0200189 printf("found FPGA - enable arbitration\n");
Andre Schwarz2a293292008-07-09 18:30:44 +0200190 writel(0x03, (u32*)(base + 0x80c0));
191 writel(0xf0, (u32*)(base + 0x8080));
André Schwarza8e1d952009-08-27 14:48:35 +0200192 if (val)
193 pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, val);
Andre Schwarz2a293292008-07-09 18:30:44 +0200194 break;
195 case 0xb: /* LAN */
196 line = 2;
André Schwarza8e1d952009-08-27 14:48:35 +0200197 if (val)
198 pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, val);
Andre Schwarz2a293292008-07-09 18:30:44 +0200199 break;
200 case 0x1a:
201 break;
202 default:
203 printf ("***pci_scan: illegal dev = 0x%08x\n", PCI_DEV (dev));
204 break;
205 }
206 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, line);
207 }
208}
209
210struct pci_controller hose = {
211 fixup_irq:pci_mvbc_fixup_irq
212};
213
Andre Schwarz2a293292008-07-09 18:30:44 +0200214extern void pci_mpc5xxx_init(struct pci_controller *);
215
216void pci_init_board(void)
217{
Andre Schwarz2a293292008-07-09 18:30:44 +0200218 mvbc_p_init_fpga();
André Schwarza8e1d952009-08-27 14:48:35 +0200219 mv_load_fpga();
Andre Schwarz2a293292008-07-09 18:30:44 +0200220 pci_mpc5xxx_init(&hose);
221}
222
Andre Schwarz2a293292008-07-09 18:30:44 +0200223void show_boot_progress(int val)
224{
225 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO;
226
227 switch(val) {
Simon Glass53624e02012-01-14 15:24:47 +0000228 case BOOTSTAGE_ID_START: /* FPGA ok */
André Schwarza8e1d952009-08-27 14:48:35 +0200229 setbits_be32(&gpio->simple_dvo, LED_G0);
Andre Schwarz2a293292008-07-09 18:30:44 +0200230 break;
Simon Glass964d1d42012-01-14 15:24:52 +0000231 case BOOTSTAGE_ID_NET_ETH_INIT:
André Schwarza8e1d952009-08-27 14:48:35 +0200232 setbits_be32(&gpio->simple_dvo, LED_G1);
Andre Schwarz2a293292008-07-09 18:30:44 +0200233 break;
Simon Glass3038f802011-12-10 11:07:57 +0000234 case BOOTSTAGE_ID_COPY_RAMDISK:
André Schwarza8e1d952009-08-27 14:48:35 +0200235 setbits_be32(&gpio->simple_dvo, LED_Y);
Andre Schwarz2a293292008-07-09 18:30:44 +0200236 break;
Simon Glass29395642011-12-10 11:07:54 +0000237 case BOOTSTAGE_ID_RUN_OS:
André Schwarza8e1d952009-08-27 14:48:35 +0200238 setbits_be32(&gpio->simple_dvo, LED_R);
Andre Schwarz2a293292008-07-09 18:30:44 +0200239 break;
240 default:
241 break;
242 }
243
244}
245
246void ft_board_setup(void *blob, bd_t *bd)
247{
248 ft_cpu_setup(blob, bd);
Andre Schwarz2a293292008-07-09 18:30:44 +0200249}
Ben Warrencba88512008-08-31 10:39:12 -0700250
251int board_eth_init(bd_t *bis)
252{
Ben Warren050019d2008-08-31 10:44:19 -0700253 cpu_eth_init(bis); /* Built in FEC comes first */
254 return pci_eth_init(bis);
Ben Warrencba88512008-08-31 10:39:12 -0700255}