blob: 29514d8363987334cc239da7eac6c3b507450865 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Heiko Schocherde044362008-11-20 09:57:47 +01002/*
3 * Copyright (C) 2006 Freescale Semiconductor, Inc.
4 * Dave Liu <daveliu@freescale.com>
5 *
6 * Copyright (C) 2007 Logic Product Development, Inc.
7 * Peter Barada <peterb@logicpd.com>
8 *
9 * Copyright (C) 2007 MontaVista Software, Inc.
10 * Anton Vorontsov <avorontsov@ru.mvista.com>
11 *
Heiko Schocher62ddcf02010-02-18 08:08:25 +010012 * (C) Copyright 2008 - 2010
Heiko Schocherde044362008-11-20 09:57:47 +010013 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
Heiko Schocherde044362008-11-20 09:57:47 +010014 */
15
16#include <common.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060017#include <env.h>
Simon Glass807765b2019-12-28 10:44:54 -070018#include <fdt_support.h>
Simon Glass52559322019-11-14 12:57:46 -070019#include <init.h>
Heiko Schocherde044362008-11-20 09:57:47 +010020#include <ioports.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060021#include <log.h>
Heiko Schocherde044362008-11-20 09:57:47 +010022#include <mpc83xx.h>
23#include <i2c.h>
24#include <miiphy.h>
25#include <asm/io.h>
26#include <asm/mmu.h>
Heiko Schocher1e7ed252009-02-24 11:30:48 +010027#include <asm/processor.h>
Heiko Schocherde044362008-11-20 09:57:47 +010028#include <pci.h>
Simon Glassc05ed002020-05-10 11:40:11 -060029#include <linux/delay.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090030#include <linux/libfdt.h>
Thomas Herzmann95209b62012-05-04 10:55:56 +020031#include <post.h>
Heiko Schocherde044362008-11-20 09:57:47 +010032
Heiko Schocher210c8c02008-11-21 08:29:40 +010033#include "../common/common.h"
34
Simon Glass088454c2017-03-31 08:40:25 -060035DECLARE_GLOBAL_DATA_PTR;
36
Valentin Longchampf32b3d32015-02-10 17:10:16 +010037static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
38
Holger Bruncka3b88122013-07-04 15:37:31 +020039const qe_iop_conf_t qe_iop_conf_tab[] = {
Heiko Schocherde044362008-11-20 09:57:47 +010040 /* port pin dir open_drain assign */
Mario Six61abced2019-01-21 09:17:28 +010041#if defined(CONFIG_ARCH_MPC8360)
Heiko Schocherde044362008-11-20 09:57:47 +010042 /* MDIO */
43 {0, 1, 3, 0, 2}, /* MDIO */
44 {0, 2, 1, 0, 1}, /* MDC */
45
46 /* UCC4 - UEC */
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 */
58
59 /* DUART - UART2 */
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 */
Mario Six4bc97a32019-01-21 09:17:24 +010064#elif !defined(CONFIG_ARCH_MPC8309)
Heiko Schocher62ddcf02010-02-18 08:08:25 +010065 /* Local Bus */
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 */
82
83 /* MDIO */
84 {3, 4, 3, 0, 2}, /* MDIO */
85 {3, 5, 1, 0, 2}, /* MDC */
86
87 /* UCC4 - UEC */
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 */
97#endif
Heiko Schocherde044362008-11-20 09:57:47 +010098
99 /* END of table */
100 {0, 0, 0, 0, QE_IOP_TAB_END},
101};
102
Heiko Schocher62ddcf02010-02-18 08:08:25 +0100103#if defined(CONFIG_SUVD3)
104const uint upma_table[] = {
105 0x1ffedc00, 0x0ffcdc80, 0x0ffcdc80, 0x0ffcdc04, /* Words 0 to 3 */
106 0x0ffcdc00, 0xffffcc00, 0xffffcc01, 0xfffffc01, /* Words 4 to 7 */
107 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 8 to 11 */
108 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 12 to 15 */
109 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 16 to 19 */
110 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 20 to 23 */
111 0x9cfffc00, 0x00fffc80, 0x00fffc80, 0x00fffc00, /* Words 24 to 27 */
112 0xffffec04, 0xffffec01, 0xfffffc01, 0xfffffc01, /* Words 28 to 31 */
113 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 32 to 35 */
114 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 36 to 39 */
115 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 40 to 43 */
116 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 44 to 47 */
117 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 48 to 51 */
118 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 52 to 55 */
119 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 56 to 59 */
120 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01 /* Words 60 to 63 */
121};
122#endif
123
Karlheinz Jerg1eb95eb2013-01-21 03:55:16 +0000124static int piggy_present(void)
125{
126 struct km_bec_fpga __iomem *base =
127 (struct km_bec_fpga __iomem *)CONFIG_SYS_KMBEC_FPGA_BASE;
128
129 return in_8(&base->bprth) & PIGGY_PRESENT;
130}
131
Karlheinz Jerg1eb95eb2013-01-21 03:55:16 +0000132int ethernet_present(void)
133{
134 return piggy_present();
135}
Karlheinz Jerg1eb95eb2013-01-21 03:55:16 +0000136
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100137int board_early_init_r(void)
Heiko Schocherde044362008-11-20 09:57:47 +0100138{
Heiko Schocher8ed74342011-03-08 10:47:39 +0100139 struct km_bec_fpga *base =
140 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
Heiko Schocher62ddcf02010-02-18 08:08:25 +0100141#if defined(CONFIG_SUVD3)
142 immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
143 fsl_lbc_t *lbc = &immap->im_lbc;
144 u32 *mxmr = &lbc->mamr;
145#endif
Heiko Schocherde044362008-11-20 09:57:47 +0100146
Mario Six61abced2019-01-21 09:17:28 +0100147#if defined(CONFIG_ARCH_MPC8360)
Heiko Schocher62ddcf02010-02-18 08:08:25 +0100148 unsigned short svid;
Heiko Schocherde044362008-11-20 09:57:47 +0100149 /*
150 * Because of errata in the UCCs, we have to write to the reserved
151 * registers to slow the clocks down.
152 */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100153 svid = SVR_REV(mfspr(SVR));
Heiko Schocher1e7ed252009-02-24 11:30:48 +0100154 switch (svid) {
155 case 0x0020:
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100156 /*
157 * MPC8360ECE.pdf QE_ENET10 table 4:
158 * IMMR + 0x14A8[4:5] = 11 (clk delay for UCC 2)
159 * IMMR + 0x14A8[18:19] = 11 (clk delay for UCC 1)
160 */
Heiko Schocher1e7ed252009-02-24 11:30:48 +0100161 setbits_be32((void *)(CONFIG_SYS_IMMR + 0x14a8), 0x0c003000);
162 break;
163 case 0x0021:
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100164 /*
165 * MPC8360ECE.pdf QE_ENET10 table 4:
166 * IMMR + 0x14AC[24:27] = 1010
167 */
Heiko Schocher1e7ed252009-02-24 11:30:48 +0100168 clrsetbits_be32((void *)(CONFIG_SYS_IMMR + 0x14ac),
169 0x00000050, 0x000000a0);
170 break;
171 }
Heiko Schocher62ddcf02010-02-18 08:08:25 +0100172#endif
173
Heiko Schocherde044362008-11-20 09:57:47 +0100174 /* enable the PHY on the PIGGY */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100175 setbits_8(&base->pgy_eth, 0x01);
Heiko Schocher4897ee32010-01-07 08:55:50 +0100176 /* enable the Unit LED (green) */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100177 setbits_8(&base->oprth, WRL_BOOT);
Stefan Bigler5758dd72012-05-04 10:55:55 +0200178 /* enable Application Buffer */
179 setbits_8(&base->oprtl, OPRTL_XBUFENA);
Heiko Schocherde044362008-11-20 09:57:47 +0100180
Heiko Schocher62ddcf02010-02-18 08:08:25 +0100181#if defined(CONFIG_SUVD3)
182 /* configure UPMA for APP1 */
183 upmconfig(UPMA, (uint *) upma_table,
184 sizeof(upma_table) / sizeof(uint));
185 out_be32(mxmr, CONFIG_SYS_MAMR);
186#endif
Heiko Schocherde044362008-11-20 09:57:47 +0100187 return 0;
188}
189
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100190int misc_init_r(void)
Heiko Schocher19f0e932009-02-24 11:30:34 +0100191{
Holger Brunckfd7c4002019-11-25 17:24:14 +0100192 ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN,
193 CONFIG_PIGGY_MAC_ADDRESS_OFFSET);
Heiko Schocher19f0e932009-02-24 11:30:34 +0100194 return 0;
195}
196
Heiko Schocherf1fef1d2010-04-26 13:07:28 +0200197int last_stage_init(void)
198{
Mario Six009c87a2019-01-21 09:17:35 +0100199#if defined(CONFIG_TARGET_KMCOGE5NE)
Thomas Herzmann13fff222012-05-04 10:55:57 +0200200 struct bfticu_iomap *base =
201 (struct bfticu_iomap *)CONFIG_SYS_BFTIC3_BASE;
202 u8 dip_switch = in_8((u8 *)&(base->mswitch)) & BFTICU_DIPSWITCH_MASK;
203
204 if (dip_switch != 0) {
205 /* start bootloader */
206 puts("DIP: Enabled\n");
Simon Glass382bee52017-08-03 12:22:09 -0600207 env_set("actual_bank", "0");
Thomas Herzmann13fff222012-05-04 10:55:57 +0200208 }
209#endif
Heiko Schocherf1fef1d2010-04-26 13:07:28 +0200210 set_km_env();
211 return 0;
212}
213
Holger Brunck283857d2013-05-06 15:02:40 +0200214static int fixed_sdram(void)
Heiko Schocherde044362008-11-20 09:57:47 +0100215{
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100216 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Heiko Schocherde044362008-11-20 09:57:47 +0100217 u32 msize = 0;
218 u32 ddr_size;
219 u32 ddr_size_log2;
220
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100221 out_be32(&im->sysconf.ddrlaw[0].ar, (LAWAR_EN | 0x1e));
Christian Herzig43afc172012-03-21 13:42:43 +0100222 out_be32(&im->ddr.csbnds[0].csbnds, (CONFIG_SYS_DDR_CS0_BNDS) | 0x7f);
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100223 out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
224 out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
225 out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
226 out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
227 out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
228 out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
229 out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_DDR_SDRAM_CFG2);
230 out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
231 out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE2);
232 out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
233 out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_CLK_CNTL);
234 udelay(200);
Andreas Huber55449a02011-11-10 15:52:43 +0100235 setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
Heiko Schocherde044362008-11-20 09:57:47 +0100236
Heiko Schocher118cbe32009-02-24 11:30:40 +0100237 msize = CONFIG_SYS_DDR_SIZE << 20;
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100238 disable_addr_trans();
Mario Six8a81bfd2019-01-21 09:18:15 +0100239 msize = get_ram_size(CONFIG_SYS_SDRAM_BASE, msize);
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100240 enable_addr_trans();
Heiko Schocher118cbe32009-02-24 11:30:40 +0100241 msize /= (1024 * 1024);
242 if (CONFIG_SYS_DDR_SIZE != msize) {
243 for (ddr_size = msize << 20, ddr_size_log2 = 0;
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100244 (ddr_size > 1);
245 ddr_size = ddr_size >> 1, ddr_size_log2++)
Heiko Schocher118cbe32009-02-24 11:30:40 +0100246 if (ddr_size & 1)
247 return -1;
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100248 out_be32(&im->sysconf.ddrlaw[0].ar,
249 (LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE)));
250 out_be32(&im->ddr.csbnds[0].csbnds,
251 (((msize / 16) - 1) & 0xff));
Heiko Schocher118cbe32009-02-24 11:30:40 +0100252 }
253
Heiko Schocherde044362008-11-20 09:57:47 +0100254 return msize;
255}
256
Simon Glassf1683aa2017-04-06 12:47:05 -0600257int dram_init(void)
Heiko Schocherde044362008-11-20 09:57:47 +0100258{
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100259 immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
Heiko Schocherde044362008-11-20 09:57:47 +0100260 u32 msize = 0;
261
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100262 if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im)
Simon Glass088454c2017-03-31 08:40:25 -0600263 return -ENXIO;
Heiko Schocherde044362008-11-20 09:57:47 +0100264
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100265 out_be32(&im->sysconf.ddrlaw[0].bar,
Mario Six8a81bfd2019-01-21 09:18:15 +0100266 CONFIG_SYS_SDRAM_BASE & LAWBAR_BAR);
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100267 msize = fixed_sdram();
Heiko Schocherde044362008-11-20 09:57:47 +0100268
Peter Tyser9adda542009-06-30 17:15:50 -0500269#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
Heiko Schocherde044362008-11-20 09:57:47 +0100270 /*
271 * Initialize DDR ECC byte
272 */
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100273 ddr_enable_ecc(msize * 1024 * 1024);
Heiko Schocherde044362008-11-20 09:57:47 +0100274#endif
275
276 /* return total bus SDRAM size(bytes) -- DDR */
Simon Glass088454c2017-03-31 08:40:25 -0600277 gd->ram_size = msize * 1024 * 1024;
278
279 return 0;
Heiko Schocherde044362008-11-20 09:57:47 +0100280}
281
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100282int checkboard(void)
Heiko Schocherde044362008-11-20 09:57:47 +0100283{
Holger Brunckaeda1232019-11-26 19:09:02 +0100284 puts("Board: ABB " CONFIG_SYS_CONFIG_NAME);
Heiko Schocher62ddcf02010-02-18 08:08:25 +0100285
Karlheinz Jerg1eb95eb2013-01-21 03:55:16 +0000286 if (piggy_present())
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100287 puts(" with PIGGY.");
288 puts("\n");
Heiko Schocherde044362008-11-20 09:57:47 +0100289 return 0;
290}
291
Valentin Longchamp89127c52015-11-17 10:53:38 +0100292int ft_board_setup(void *blob, bd_t *bd)
Heiko Schocherde044362008-11-20 09:57:47 +0100293{
Heiko Schocher62ddcf02010-02-18 08:08:25 +0100294 ft_cpu_setup(blob, bd);
Simon Glasse895a4b2014-10-23 18:58:47 -0600295
296 return 0;
Heiko Schocherde044362008-11-20 09:57:47 +0100297}
Heiko Schocher19f0e932009-02-24 11:30:34 +0100298
299#if defined(CONFIG_HUSH_INIT_VAR)
Heiko Schocherb11f53f2011-03-15 16:52:29 +0100300int hush_init_var(void)
Heiko Schocher19f0e932009-02-24 11:30:34 +0100301{
Valentin Longchampf32b3d32015-02-10 17:10:16 +0100302 ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
Heiko Schocher19f0e932009-02-24 11:30:34 +0100303 return 0;
304}
305#endif
Thomas Herzmann95209b62012-05-04 10:55:56 +0200306
307#if defined(CONFIG_POST)
308int post_hotkeys_pressed(void)
309{
310 int testpin = 0;
311 struct km_bec_fpga *base =
312 (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
313 int testpin_reg = in_8(&base->CONFIG_TESTPIN_REG);
314 testpin = (testpin_reg & CONFIG_TESTPIN_MASK) != 0;
315 debug("post_hotkeys_pressed: %d\n", !testpin);
316 return testpin;
317}
318
319ulong post_word_load(void)
320{
321 void* addr = (ulong *) (CPM_POST_WORD_ADDR);
322 debug("post_word_load 0x%08lX: 0x%08X\n", (ulong)addr, in_le32(addr));
323 return in_le32(addr);
324
325}
326void post_word_store(ulong value)
327{
328 void* addr = (ulong *) (CPM_POST_WORD_ADDR);
329 debug("post_word_store 0x%08lX: 0x%08lX\n", (ulong)addr, value);
330 out_le32(addr, value);
331}
332
333int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
334{
Ashok Reddy Soma702de892020-05-04 15:26:21 +0200335 /*
336 * These match CONFIG_SYS_MEMTEST_START and
337 * (CONFIG_SYS_MEMTEST_END - CONFIG_SYS_MEMTEST_START)
338 */
339 *vstart = 0x00100000;
340 *size = 0xe00000;
Thomas Herzmann95209b62012-05-04 10:55:56 +0200341 debug("arch_memory_test_prepare 0x%08X 0x%08X\n", *vstart, *size);
342
343 return 0;
344}
345#endif