1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2006 Freescale Semiconductor, Inc.
4 * Dave Liu <daveliu@freescale.com>
6 * Copyright (C) 2007 Logic Product Development, Inc.
7 * Peter Barada <peterb@logicpd.com>
9 * Copyright (C) 2007 MontaVista Software, Inc.
10 * Anton Vorontsov <avorontsov@ru.mvista.com>
12 * (C) Copyright 2008 - 2010
13 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
18 #include <fdt_support.h>
27 #include <asm/processor.h>
29 #include <linux/delay.h>
30 #include <linux/libfdt.h>
33 #include "../common/common.h"
35 DECLARE_GLOBAL_DATA_PTR;
37 static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
39 const qe_iop_conf_t qe_iop_conf_tab[] = {
40 /* port pin dir open_drain assign */
41 #if defined(CONFIG_ARCH_MPC8360)
43 {0, 1, 3, 0, 2}, /* MDIO */
44 {0, 2, 1, 0, 1}, /* MDC */
47 {1, 14, 1, 0, 1}, /* TxD0 */
48 {1, 15, 1, 0, 1}, /* TxD1 */
49 {1, 20, 2, 0, 1}, /* RxD0 */
50 {1, 21, 2, 0, 1}, /* RxD1 */
51 {1, 18, 1, 0, 1}, /* TX_EN */
52 {1, 26, 2, 0, 1}, /* RX_DV */
53 {1, 27, 2, 0, 1}, /* RX_ER */
54 {1, 24, 2, 0, 1}, /* COL */
55 {1, 25, 2, 0, 1}, /* CRS */
56 {2, 15, 2, 0, 1}, /* TX_CLK - CLK16 */
57 {2, 16, 2, 0, 1}, /* RX_CLK - CLK17 */
60 {5, 0, 1, 0, 2}, /* UART2_SOUT */
61 {5, 2, 1, 0, 1}, /* UART2_RTS */
62 {5, 3, 2, 0, 2}, /* UART2_SIN */
63 {5, 1, 2, 0, 3}, /* UART2_CTS */
64 #elif !defined(CONFIG_ARCH_MPC8309)
66 {0, 16, 1, 0, 3}, /* LA00 */
67 {0, 17, 1, 0, 3}, /* LA01 */
68 {0, 18, 1, 0, 3}, /* LA02 */
69 {0, 19, 1, 0, 3}, /* LA03 */
70 {0, 20, 1, 0, 3}, /* LA04 */
71 {0, 21, 1, 0, 3}, /* LA05 */
72 {0, 22, 1, 0, 3}, /* LA06 */
73 {0, 23, 1, 0, 3}, /* LA07 */
74 {0, 24, 1, 0, 3}, /* LA08 */
75 {0, 25, 1, 0, 3}, /* LA09 */
76 {0, 26, 1, 0, 3}, /* LA10 */
77 {0, 27, 1, 0, 3}, /* LA11 */
78 {0, 28, 1, 0, 3}, /* LA12 */
79 {0, 29, 1, 0, 3}, /* LA13 */
80 {0, 30, 1, 0, 3}, /* LA14 */
81 {0, 31, 1, 0, 3}, /* LA15 */
84 {3, 4, 3, 0, 2}, /* MDIO */
85 {3, 5, 1, 0, 2}, /* MDC */
88 {1, 18, 1, 0, 1}, /* TxD0 */
89 {1, 19, 1, 0, 1}, /* TxD1 */
90 {1, 22, 2, 0, 1}, /* RxD0 */
91 {1, 23, 2, 0, 1}, /* RxD1 */
92 {1, 26, 2, 0, 1}, /* RxER */
93 {1, 28, 2, 0, 1}, /* Rx_DV */
94 {1, 30, 1, 0, 1}, /* TxEN */
95 {1, 31, 2, 0, 1}, /* CRS */
96 {3, 10, 2, 0, 3}, /* TxCLK->CLK17 */
100 {0, 0, 0, 0, QE_IOP_TAB_END},
103 static int piggy_present(void)
105 struct km_bec_fpga __iomem *base =
106 (struct km_bec_fpga __iomem *)CONFIG_SYS_KMBEC_FPGA_BASE;
108 return in_8(&base->bprth) & PIGGY_PRESENT;
111 int ethernet_present(void)
113 return piggy_present();
116 int board_early_init_r(void)
118 struct km_bec_fpga *base =
119 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
121 #if defined(CONFIG_ARCH_MPC8360)
124 * Because of errata in the UCCs, we have to write to the reserved
125 * registers to slow the clocks down.
127 svid = SVR_REV(mfspr(SVR));
131 * MPC8360ECE.pdf QE_ENET10 table 4:
132 * IMMR + 0x14A8[4:5] = 11 (clk delay for UCC 2)
133 * IMMR + 0x14A8[18:19] = 11 (clk delay for UCC 1)
135 setbits_be32((void *)(CONFIG_SYS_IMMR + 0x14a8), 0x0c003000);
139 * MPC8360ECE.pdf QE_ENET10 table 4:
140 * IMMR + 0x14AC[24:27] = 1010
142 clrsetbits_be32((void *)(CONFIG_SYS_IMMR + 0x14ac),
143 0x00000050, 0x000000a0);
148 /* enable the PHY on the PIGGY */
149 setbits_8(&base->pgy_eth, 0x01);
150 /* enable the Unit LED (green) */
151 setbits_8(&base->oprth, WRL_BOOT);
152 /* enable Application Buffer */
153 setbits_8(&base->oprtl, OPRTL_XBUFENA);
158 int misc_init_r(void)
160 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
161 CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
165 int last_stage_init(void)
167 #if defined(CONFIG_TARGET_KMCOGE5NE)
168 struct bfticu_iomap *base =
169 (struct bfticu_iomap *)CONFIG_SYS_BFTIC3_BASE;
170 u8 dip_switch = in_8((u8 *)&(base->mswitch)) & BFTICU_DIPSWITCH_MASK;
172 if (dip_switch != 0) {
173 /* start bootloader */
174 puts("DIP: Enabled\n");
175 env_set("actual_bank", "0");
182 static int fixed_sdram(void)
184 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
189 out_be32(&im->sysconf.ddrlaw[0].ar, (LAWAR_EN | 0x1e));
190 out_be32(&im->ddr.csbnds[0].csbnds, (CONFIG_SYS_DDR_CS0_BNDS) | 0x7f);
191 out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
192 out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
193 out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
194 out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
195 out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
196 out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
197 out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_DDR_SDRAM_CFG2);
198 out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
199 out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE2);
200 out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
201 out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_CLK_CNTL);
203 setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
205 msize = CONFIG_SYS_DDR_SIZE << 20;
206 disable_addr_trans();
207 msize = get_ram_size(CONFIG_SYS_SDRAM_BASE, msize);
209 msize /= (1024 * 1024);
210 if (CONFIG_SYS_DDR_SIZE != msize) {
211 for (ddr_size = msize << 20, ddr_size_log2 = 0;
213 ddr_size = ddr_size >> 1, ddr_size_log2++)
216 out_be32(&im->sysconf.ddrlaw[0].ar,
217 (LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE)));
218 out_be32(&im->ddr.csbnds[0].csbnds,
219 (((msize / 16) - 1) & 0xff));
227 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
230 if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im)
233 out_be32(&im->sysconf.ddrlaw[0].bar,
234 CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR);
235 msize = fixed_sdram();
237 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
239 * Initialize DDR ECC byte
241 ddr_enable_ecc(msize * 1024 * 1024);
244 /* return total bus SDRAM size(bytes) -- DDR */
245 gd->ram_size = msize * 1024 * 1024;
252 puts("Board: ABB " CONFIG_SYS_CONFIG_NAME);
255 puts(" with PIGGY.");
260 int ft_board_setup(void *blob, bd_t *bd)
262 ft_cpu_setup(blob, bd);
267 #if defined(CONFIG_HUSH_INIT_VAR)
268 int hush_init_var(void)
270 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
275 #if defined(CONFIG_POST)
276 int post_hotkeys_pressed(void)
279 struct km_bec_fpga *base =
280 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
281 int testpin_reg = in_8(&base->CONFIG_TESTPIN_REG);
282 testpin = (testpin_reg & CONFIG_TESTPIN_MASK) != 0;
283 debug("post_hotkeys_pressed: %d\n", !testpin);
287 ulong post_word_load(void)
289 void* addr = (ulong *) (CPM_POST_WORD_ADDR);
290 debug("post_word_load 0x%08lX: 0x%08X\n", (ulong)addr, in_le32(addr));
291 return in_le32(addr);
294 void post_word_store(ulong value)
296 void* addr = (ulong *) (CPM_POST_WORD_ADDR);
297 debug("post_word_store 0x%08lX: 0x%08lX\n", (ulong)addr, value);
298 out_le32(addr, value);
301 int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
304 * These match CONFIG_SYS_MEMTEST_START and
305 * (CONFIG_SYS_MEMTEST_END - CONFIG_SYS_MEMTEST_START)
307 *vstart = 0x00100000;
309 debug("arch_memory_test_prepare 0x%08X 0x%08X\n", *vstart, *size);