1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
262ddcf05SHeiko Schocher /*
362ddcf05SHeiko Schocher * Copyright (C) 2006 Freescale Semiconductor, Inc.
462ddcf05SHeiko Schocher * Dave Liu <daveliu@freescale.com>
562ddcf05SHeiko Schocher *
662ddcf05SHeiko Schocher * Copyright (C) 2007 Logic Product Development, Inc.
762ddcf05SHeiko Schocher * Peter Barada <peterb@logicpd.com>
862ddcf05SHeiko Schocher *
962ddcf05SHeiko Schocher * Copyright (C) 2007 MontaVista Software, Inc.
1062ddcf05SHeiko Schocher * Anton Vorontsov <avorontsov@ru.mvista.com>
1162ddcf05SHeiko Schocher *
1262ddcf05SHeiko Schocher * (C) Copyright 2008 - 2010
1362ddcf05SHeiko Schocher * Heiko Schocher, DENX Software Engineering, hs@denx.de.
1462ddcf05SHeiko Schocher */
1562ddcf05SHeiko Schocher
1662ddcf05SHeiko Schocher #include <common.h>
1762ddcf05SHeiko Schocher #include <ioports.h>
1862ddcf05SHeiko Schocher #include <mpc83xx.h>
1962ddcf05SHeiko Schocher #include <i2c.h>
2062ddcf05SHeiko Schocher #include <miiphy.h>
2162ddcf05SHeiko Schocher #include <asm/io.h>
2262ddcf05SHeiko Schocher #include <asm/mmu.h>
2362ddcf05SHeiko Schocher #include <asm/processor.h>
2462ddcf05SHeiko Schocher #include <pci.h>
25b08c8c48SMasahiro Yamada #include <linux/libfdt.h>
2695209b66SThomas Herzmann #include <post.h>
2762ddcf05SHeiko Schocher
2862ddcf05SHeiko Schocher #include "../common/common.h"
2962ddcf05SHeiko Schocher
30088454cdSSimon Glass DECLARE_GLOBAL_DATA_PTR;
31088454cdSSimon Glass
32f32b3d3fSValentin Longchamp static uchar ivm_content[CONFIG_SYS_IVM_EEPROM_MAX_LEN];
33f32b3d3fSValentin Longchamp
34a3b88121SHolger Brunck const qe_iop_conf_t qe_iop_conf_tab[] = {
3562ddcf05SHeiko Schocher /* port pin dir open_drain assign */
360f2b721cSHolger Brunck #if defined(CONFIG_MPC8360)
3762ddcf05SHeiko Schocher /* MDIO */
3862ddcf05SHeiko Schocher {0, 1, 3, 0, 2}, /* MDIO */
3962ddcf05SHeiko Schocher {0, 2, 1, 0, 1}, /* MDC */
4062ddcf05SHeiko Schocher
4162ddcf05SHeiko Schocher /* UCC4 - UEC */
4262ddcf05SHeiko Schocher {1, 14, 1, 0, 1}, /* TxD0 */
4362ddcf05SHeiko Schocher {1, 15, 1, 0, 1}, /* TxD1 */
4462ddcf05SHeiko Schocher {1, 20, 2, 0, 1}, /* RxD0 */
4562ddcf05SHeiko Schocher {1, 21, 2, 0, 1}, /* RxD1 */
4662ddcf05SHeiko Schocher {1, 18, 1, 0, 1}, /* TX_EN */
4762ddcf05SHeiko Schocher {1, 26, 2, 0, 1}, /* RX_DV */
4862ddcf05SHeiko Schocher {1, 27, 2, 0, 1}, /* RX_ER */
4962ddcf05SHeiko Schocher {1, 24, 2, 0, 1}, /* COL */
5062ddcf05SHeiko Schocher {1, 25, 2, 0, 1}, /* CRS */
5162ddcf05SHeiko Schocher {2, 15, 2, 0, 1}, /* TX_CLK - CLK16 */
5262ddcf05SHeiko Schocher {2, 16, 2, 0, 1}, /* RX_CLK - CLK17 */
5362ddcf05SHeiko Schocher
5462ddcf05SHeiko Schocher /* DUART - UART2 */
5562ddcf05SHeiko Schocher {5, 0, 1, 0, 2}, /* UART2_SOUT */
5662ddcf05SHeiko Schocher {5, 2, 1, 0, 1}, /* UART2_RTS */
5762ddcf05SHeiko Schocher {5, 3, 2, 0, 2}, /* UART2_SIN */
5862ddcf05SHeiko Schocher {5, 1, 2, 0, 3}, /* UART2_CTS */
596967840bSGerlando Falauto #elif !defined(CONFIG_MPC8309)
6062ddcf05SHeiko Schocher /* Local Bus */
6162ddcf05SHeiko Schocher {0, 16, 1, 0, 3}, /* LA00 */
6262ddcf05SHeiko Schocher {0, 17, 1, 0, 3}, /* LA01 */
6362ddcf05SHeiko Schocher {0, 18, 1, 0, 3}, /* LA02 */
6462ddcf05SHeiko Schocher {0, 19, 1, 0, 3}, /* LA03 */
6562ddcf05SHeiko Schocher {0, 20, 1, 0, 3}, /* LA04 */
6662ddcf05SHeiko Schocher {0, 21, 1, 0, 3}, /* LA05 */
6762ddcf05SHeiko Schocher {0, 22, 1, 0, 3}, /* LA06 */
6862ddcf05SHeiko Schocher {0, 23, 1, 0, 3}, /* LA07 */
6962ddcf05SHeiko Schocher {0, 24, 1, 0, 3}, /* LA08 */
7062ddcf05SHeiko Schocher {0, 25, 1, 0, 3}, /* LA09 */
7162ddcf05SHeiko Schocher {0, 26, 1, 0, 3}, /* LA10 */
7262ddcf05SHeiko Schocher {0, 27, 1, 0, 3}, /* LA11 */
7362ddcf05SHeiko Schocher {0, 28, 1, 0, 3}, /* LA12 */
7462ddcf05SHeiko Schocher {0, 29, 1, 0, 3}, /* LA13 */
7562ddcf05SHeiko Schocher {0, 30, 1, 0, 3}, /* LA14 */
7662ddcf05SHeiko Schocher {0, 31, 1, 0, 3}, /* LA15 */
7762ddcf05SHeiko Schocher
7862ddcf05SHeiko Schocher /* MDIO */
7962ddcf05SHeiko Schocher {3, 4, 3, 0, 2}, /* MDIO */
8062ddcf05SHeiko Schocher {3, 5, 1, 0, 2}, /* MDC */
8162ddcf05SHeiko Schocher
8262ddcf05SHeiko Schocher /* UCC4 - UEC */
8362ddcf05SHeiko Schocher {1, 18, 1, 0, 1}, /* TxD0 */
8462ddcf05SHeiko Schocher {1, 19, 1, 0, 1}, /* TxD1 */
8562ddcf05SHeiko Schocher {1, 22, 2, 0, 1}, /* RxD0 */
8662ddcf05SHeiko Schocher {1, 23, 2, 0, 1}, /* RxD1 */
8762ddcf05SHeiko Schocher {1, 26, 2, 0, 1}, /* RxER */
8862ddcf05SHeiko Schocher {1, 28, 2, 0, 1}, /* Rx_DV */
8962ddcf05SHeiko Schocher {1, 30, 1, 0, 1}, /* TxEN */
9062ddcf05SHeiko Schocher {1, 31, 2, 0, 1}, /* CRS */
9162ddcf05SHeiko Schocher {3, 10, 2, 0, 3}, /* TxCLK->CLK17 */
9262ddcf05SHeiko Schocher #endif
9362ddcf05SHeiko Schocher
9462ddcf05SHeiko Schocher /* END of table */
9562ddcf05SHeiko Schocher {0, 0, 0, 0, QE_IOP_TAB_END},
9662ddcf05SHeiko Schocher };
9762ddcf05SHeiko Schocher
9862ddcf05SHeiko Schocher #if defined(CONFIG_SUVD3)
9962ddcf05SHeiko Schocher const uint upma_table[] = {
10062ddcf05SHeiko Schocher 0x1ffedc00, 0x0ffcdc80, 0x0ffcdc80, 0x0ffcdc04, /* Words 0 to 3 */
10162ddcf05SHeiko Schocher 0x0ffcdc00, 0xffffcc00, 0xffffcc01, 0xfffffc01, /* Words 4 to 7 */
10262ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 8 to 11 */
10362ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 12 to 15 */
10462ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 16 to 19 */
10562ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 20 to 23 */
10662ddcf05SHeiko Schocher 0x9cfffc00, 0x00fffc80, 0x00fffc80, 0x00fffc00, /* Words 24 to 27 */
10762ddcf05SHeiko Schocher 0xffffec04, 0xffffec01, 0xfffffc01, 0xfffffc01, /* Words 28 to 31 */
10862ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 32 to 35 */
10962ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 36 to 39 */
11062ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 40 to 43 */
11162ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 44 to 47 */
11262ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 48 to 51 */
11362ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 52 to 55 */
11462ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01, /* Words 56 to 59 */
11562ddcf05SHeiko Schocher 0xfffffc01, 0xfffffc01, 0xfffffc01, 0xfffffc01 /* Words 60 to 63 */
11662ddcf05SHeiko Schocher };
11762ddcf05SHeiko Schocher #endif
11862ddcf05SHeiko Schocher
piggy_present(void)1191eb95ebeSKarlheinz Jerg static int piggy_present(void)
1201eb95ebeSKarlheinz Jerg {
1211eb95ebeSKarlheinz Jerg struct km_bec_fpga __iomem *base =
1221eb95ebeSKarlheinz Jerg (struct km_bec_fpga __iomem *)CONFIG_SYS_KMBEC_FPGA_BASE;
1231eb95ebeSKarlheinz Jerg
1241eb95ebeSKarlheinz Jerg return in_8(&base->bprth) & PIGGY_PRESENT;
1251eb95ebeSKarlheinz Jerg }
1261eb95ebeSKarlheinz Jerg
1271eb95ebeSKarlheinz Jerg #if defined(CONFIG_KMVECT1)
ethernet_present(void)1281eb95ebeSKarlheinz Jerg int ethernet_present(void)
1291eb95ebeSKarlheinz Jerg {
1301eb95ebeSKarlheinz Jerg /* ethernet port connected to simple switch without piggy */
1311eb95ebeSKarlheinz Jerg return 1;
1321eb95ebeSKarlheinz Jerg }
1331eb95ebeSKarlheinz Jerg #else
ethernet_present(void)1341eb95ebeSKarlheinz Jerg int ethernet_present(void)
1351eb95ebeSKarlheinz Jerg {
1361eb95ebeSKarlheinz Jerg return piggy_present();
1371eb95ebeSKarlheinz Jerg }
1381eb95ebeSKarlheinz Jerg #endif
1391eb95ebeSKarlheinz Jerg
1401eb95ebeSKarlheinz Jerg
board_early_init_r(void)14162ddcf05SHeiko Schocher int board_early_init_r(void)
14262ddcf05SHeiko Schocher {
1438ed74341SHeiko Schocher struct km_bec_fpga *base =
1448ed74341SHeiko Schocher (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
14562ddcf05SHeiko Schocher #if defined(CONFIG_SUVD3)
14662ddcf05SHeiko Schocher immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
14762ddcf05SHeiko Schocher fsl_lbc_t *lbc = &immap->im_lbc;
14862ddcf05SHeiko Schocher u32 *mxmr = &lbc->mamr;
14962ddcf05SHeiko Schocher #endif
15062ddcf05SHeiko Schocher
15162ddcf05SHeiko Schocher #if defined(CONFIG_MPC8360)
15262ddcf05SHeiko Schocher unsigned short svid;
15362ddcf05SHeiko Schocher /*
15462ddcf05SHeiko Schocher * Because of errata in the UCCs, we have to write to the reserved
15562ddcf05SHeiko Schocher * registers to slow the clocks down.
15662ddcf05SHeiko Schocher */
15762ddcf05SHeiko Schocher svid = SVR_REV(mfspr(SVR));
15862ddcf05SHeiko Schocher switch (svid) {
15962ddcf05SHeiko Schocher case 0x0020:
16062ddcf05SHeiko Schocher /*
16162ddcf05SHeiko Schocher * MPC8360ECE.pdf QE_ENET10 table 4:
16262ddcf05SHeiko Schocher * IMMR + 0x14A8[4:5] = 11 (clk delay for UCC 2)
16362ddcf05SHeiko Schocher * IMMR + 0x14A8[18:19] = 11 (clk delay for UCC 1)
16462ddcf05SHeiko Schocher */
16562ddcf05SHeiko Schocher setbits_be32((void *)(CONFIG_SYS_IMMR + 0x14a8), 0x0c003000);
16662ddcf05SHeiko Schocher break;
16762ddcf05SHeiko Schocher case 0x0021:
16862ddcf05SHeiko Schocher /*
16962ddcf05SHeiko Schocher * MPC8360ECE.pdf QE_ENET10 table 4:
17062ddcf05SHeiko Schocher * IMMR + 0x14AC[24:27] = 1010
17162ddcf05SHeiko Schocher */
17262ddcf05SHeiko Schocher clrsetbits_be32((void *)(CONFIG_SYS_IMMR + 0x14ac),
17362ddcf05SHeiko Schocher 0x00000050, 0x000000a0);
17462ddcf05SHeiko Schocher break;
17562ddcf05SHeiko Schocher }
17662ddcf05SHeiko Schocher #endif
17762ddcf05SHeiko Schocher
17862ddcf05SHeiko Schocher /* enable the PHY on the PIGGY */
17962ddcf05SHeiko Schocher setbits_8(&base->pgy_eth, 0x01);
18062ddcf05SHeiko Schocher /* enable the Unit LED (green) */
18162ddcf05SHeiko Schocher setbits_8(&base->oprth, WRL_BOOT);
1825758dd76SStefan Bigler /* enable Application Buffer */
1835758dd76SStefan Bigler setbits_8(&base->oprtl, OPRTL_XBUFENA);
18462ddcf05SHeiko Schocher
18562ddcf05SHeiko Schocher #if defined(CONFIG_SUVD3)
18662ddcf05SHeiko Schocher /* configure UPMA for APP1 */
18762ddcf05SHeiko Schocher upmconfig(UPMA, (uint *) upma_table,
18862ddcf05SHeiko Schocher sizeof(upma_table) / sizeof(uint));
18962ddcf05SHeiko Schocher out_be32(mxmr, CONFIG_SYS_MAMR);
19062ddcf05SHeiko Schocher #endif
19162ddcf05SHeiko Schocher return 0;
19262ddcf05SHeiko Schocher }
19362ddcf05SHeiko Schocher
misc_init_r(void)19462ddcf05SHeiko Schocher int misc_init_r(void)
19562ddcf05SHeiko Schocher {
19660c4ae00SValentin Longchamp ivm_read_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
19762ddcf05SHeiko Schocher return 0;
19862ddcf05SHeiko Schocher }
19962ddcf05SHeiko Schocher
2005bcd64cfSKarlheinz Jerg #if defined(CONFIG_KMVECT1)
2015bcd64cfSKarlheinz Jerg #include <mv88e6352.h>
2025bcd64cfSKarlheinz Jerg /* Marvell MV88E6122 switch configuration */
2035bcd64cfSKarlheinz Jerg static struct mv88e_sw_reg extsw_conf[] = {
2045bcd64cfSKarlheinz Jerg /* port 1, FRONT_MDI, autoneg */
2055bcd64cfSKarlheinz Jerg { PORT(1), PORT_PHY, NO_SPEED_FOR },
2065bcd64cfSKarlheinz Jerg { PORT(1), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
2075bcd64cfSKarlheinz Jerg { PHY(1), PHY_1000_CTRL, NO_ADV },
2085bcd64cfSKarlheinz Jerg { PHY(1), PHY_SPEC_CTRL, AUTO_MDIX_EN },
2095bcd64cfSKarlheinz Jerg { PHY(1), PHY_CTRL, PHY_100_MBPS | AUTONEG_EN | AUTONEG_RST |
2105bcd64cfSKarlheinz Jerg FULL_DUPLEX },
2115bcd64cfSKarlheinz Jerg /* port 2, unused */
2125bcd64cfSKarlheinz Jerg { PORT(2), PORT_CTRL, PORT_DIS },
2135bcd64cfSKarlheinz Jerg { PHY(2), PHY_CTRL, PHY_PWR_DOWN },
2145bcd64cfSKarlheinz Jerg { PHY(2), PHY_SPEC_CTRL, SPEC_PWR_DOWN },
2155bcd64cfSKarlheinz Jerg /* port 3, BP_MII (CPU), PHY mode, 100BASE */
2165bcd64cfSKarlheinz Jerg { PORT(3), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
2175bcd64cfSKarlheinz Jerg /* port 4, ESTAR to slot 11, SerDes, 1000BASE-X */
2185bcd64cfSKarlheinz Jerg { PORT(4), PORT_STATUS, NO_PHY_DETECT },
2195bcd64cfSKarlheinz Jerg { PORT(4), PORT_PHY, SPEED_1000_FOR },
2205bcd64cfSKarlheinz Jerg { PORT(4), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
2215bcd64cfSKarlheinz Jerg /* port 5, ESTAR to slot 13, SerDes, 1000BASE-X */
2225bcd64cfSKarlheinz Jerg { PORT(5), PORT_STATUS, NO_PHY_DETECT },
2235bcd64cfSKarlheinz Jerg { PORT(5), PORT_PHY, SPEED_1000_FOR },
2245bcd64cfSKarlheinz Jerg { PORT(5), PORT_CTRL, FORWARDING | EGRS_FLD_ALL },
2255bcd64cfSKarlheinz Jerg /*
2265bcd64cfSKarlheinz Jerg * Errata Fix: 1.9V Output from Internal 1.8V Regulator,
2275bcd64cfSKarlheinz Jerg * acc . MV-S300889-00D.pdf , clause 4.5
2285bcd64cfSKarlheinz Jerg */
2295bcd64cfSKarlheinz Jerg { PORT(5), 0x1A, 0xADB1 },
2305bcd64cfSKarlheinz Jerg /* port 6, unused, this port has no phy */
2315bcd64cfSKarlheinz Jerg { PORT(6), PORT_CTRL, PORT_DIS },
2321ca899c7SHolger Brunck /*
2331ca899c7SHolger Brunck * Errata Fix: 1.9V Output from Internal 1.8V Regulator,
2341ca899c7SHolger Brunck * acc . MV-S300889-00D.pdf , clause 4.5
2351ca899c7SHolger Brunck */
2361ca899c7SHolger Brunck { PORT(5), 0x1A, 0xADB1 },
2375bcd64cfSKarlheinz Jerg };
2385bcd64cfSKarlheinz Jerg #endif
2395bcd64cfSKarlheinz Jerg
last_stage_init(void)240f1fef1d8SHeiko Schocher int last_stage_init(void)
241f1fef1d8SHeiko Schocher {
2425bcd64cfSKarlheinz Jerg #if defined(CONFIG_KMVECT1)
2435bcd64cfSKarlheinz Jerg struct km_bec_fpga __iomem *base =
2445bcd64cfSKarlheinz Jerg (struct km_bec_fpga __iomem *)CONFIG_SYS_KMBEC_FPGA_BASE;
2455bcd64cfSKarlheinz Jerg u8 tmp_reg;
2465bcd64cfSKarlheinz Jerg
2475bcd64cfSKarlheinz Jerg /* Release mv88e6122 from reset */
2485bcd64cfSKarlheinz Jerg tmp_reg = in_8(&base->res1[0]) | 0x10; /* DIRECT3 register */
2495bcd64cfSKarlheinz Jerg out_8(&base->res1[0], tmp_reg); /* GP28 as output */
2505bcd64cfSKarlheinz Jerg tmp_reg = in_8(&base->gprt3) | 0x10; /* GP28 to high */
2515bcd64cfSKarlheinz Jerg out_8(&base->gprt3, tmp_reg);
2525bcd64cfSKarlheinz Jerg
2535bcd64cfSKarlheinz Jerg /* configure MV88E6122 switch */
2545bcd64cfSKarlheinz Jerg char *name = "UEC2";
2555bcd64cfSKarlheinz Jerg
2565bcd64cfSKarlheinz Jerg if (miiphy_set_current_dev(name))
2575bcd64cfSKarlheinz Jerg return 0;
2585bcd64cfSKarlheinz Jerg
2595bcd64cfSKarlheinz Jerg mv88e_sw_program(name, CONFIG_KM_MVEXTSW_ADDR, extsw_conf,
2605bcd64cfSKarlheinz Jerg ARRAY_SIZE(extsw_conf));
2615bcd64cfSKarlheinz Jerg
2625bcd64cfSKarlheinz Jerg mv88e_sw_reset(name, CONFIG_KM_MVEXTSW_ADDR);
2635bcd64cfSKarlheinz Jerg
2645bcd64cfSKarlheinz Jerg if (piggy_present()) {
265382bee57SSimon Glass env_set("ethact", "UEC2");
266382bee57SSimon Glass env_set("netdev", "eth1");
2675bcd64cfSKarlheinz Jerg puts("using PIGGY for network boot\n");
2685bcd64cfSKarlheinz Jerg } else {
269382bee57SSimon Glass env_set("netdev", "eth0");
2705bcd64cfSKarlheinz Jerg puts("using frontport for network boot\n");
2715bcd64cfSKarlheinz Jerg }
2725bcd64cfSKarlheinz Jerg #endif
2735bcd64cfSKarlheinz Jerg
27413fff222SThomas Herzmann #if defined(CONFIG_KMCOGE5NE)
27513fff222SThomas Herzmann struct bfticu_iomap *base =
27613fff222SThomas Herzmann (struct bfticu_iomap *)CONFIG_SYS_BFTIC3_BASE;
27713fff222SThomas Herzmann u8 dip_switch = in_8((u8 *)&(base->mswitch)) & BFTICU_DIPSWITCH_MASK;
27813fff222SThomas Herzmann
27913fff222SThomas Herzmann if (dip_switch != 0) {
28013fff222SThomas Herzmann /* start bootloader */
28113fff222SThomas Herzmann puts("DIP: Enabled\n");
282382bee57SSimon Glass env_set("actual_bank", "0");
28313fff222SThomas Herzmann }
28413fff222SThomas Herzmann #endif
285f1fef1d8SHeiko Schocher set_km_env();
286f1fef1d8SHeiko Schocher return 0;
287f1fef1d8SHeiko Schocher }
288f1fef1d8SHeiko Schocher
fixed_sdram(void)289283857daSHolger Brunck static int fixed_sdram(void)
29062ddcf05SHeiko Schocher {
29162ddcf05SHeiko Schocher immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
29262ddcf05SHeiko Schocher u32 msize = 0;
29362ddcf05SHeiko Schocher u32 ddr_size;
29462ddcf05SHeiko Schocher u32 ddr_size_log2;
29562ddcf05SHeiko Schocher
29662ddcf05SHeiko Schocher out_be32(&im->sysconf.ddrlaw[0].ar, (LAWAR_EN | 0x1e));
29743afc17fSChristian Herzig out_be32(&im->ddr.csbnds[0].csbnds, (CONFIG_SYS_DDR_CS0_BNDS) | 0x7f);
29862ddcf05SHeiko Schocher out_be32(&im->ddr.cs_config[0], CONFIG_SYS_DDR_CS0_CONFIG);
29962ddcf05SHeiko Schocher out_be32(&im->ddr.timing_cfg_0, CONFIG_SYS_DDR_TIMING_0);
30062ddcf05SHeiko Schocher out_be32(&im->ddr.timing_cfg_1, CONFIG_SYS_DDR_TIMING_1);
30162ddcf05SHeiko Schocher out_be32(&im->ddr.timing_cfg_2, CONFIG_SYS_DDR_TIMING_2);
30262ddcf05SHeiko Schocher out_be32(&im->ddr.timing_cfg_3, CONFIG_SYS_DDR_TIMING_3);
30362ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_cfg, CONFIG_SYS_DDR_SDRAM_CFG);
30462ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_cfg2, CONFIG_SYS_DDR_SDRAM_CFG2);
30562ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_mode, CONFIG_SYS_DDR_MODE);
30662ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_mode2, CONFIG_SYS_DDR_MODE2);
30762ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_interval, CONFIG_SYS_DDR_INTERVAL);
30862ddcf05SHeiko Schocher out_be32(&im->ddr.sdram_clk_cntl, CONFIG_SYS_DDR_CLK_CNTL);
30962ddcf05SHeiko Schocher udelay(200);
31055449a0dSAndreas Huber setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
31162ddcf05SHeiko Schocher
31262ddcf05SHeiko Schocher msize = CONFIG_SYS_DDR_SIZE << 20;
31362ddcf05SHeiko Schocher disable_addr_trans();
31462ddcf05SHeiko Schocher msize = get_ram_size(CONFIG_SYS_DDR_BASE, msize);
31562ddcf05SHeiko Schocher enable_addr_trans();
31662ddcf05SHeiko Schocher msize /= (1024 * 1024);
31762ddcf05SHeiko Schocher if (CONFIG_SYS_DDR_SIZE != msize) {
31862ddcf05SHeiko Schocher for (ddr_size = msize << 20, ddr_size_log2 = 0;
31962ddcf05SHeiko Schocher (ddr_size > 1);
32062ddcf05SHeiko Schocher ddr_size = ddr_size >> 1, ddr_size_log2++)
32162ddcf05SHeiko Schocher if (ddr_size & 1)
32262ddcf05SHeiko Schocher return -1;
32362ddcf05SHeiko Schocher out_be32(&im->sysconf.ddrlaw[0].ar,
32462ddcf05SHeiko Schocher (LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE)));
32562ddcf05SHeiko Schocher out_be32(&im->ddr.csbnds[0].csbnds,
32662ddcf05SHeiko Schocher (((msize / 16) - 1) & 0xff));
32762ddcf05SHeiko Schocher }
32862ddcf05SHeiko Schocher
32962ddcf05SHeiko Schocher return msize;
33062ddcf05SHeiko Schocher }
33162ddcf05SHeiko Schocher
dram_init(void)332f1683aa7SSimon Glass int dram_init(void)
33362ddcf05SHeiko Schocher {
33462ddcf05SHeiko Schocher immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
33562ddcf05SHeiko Schocher u32 msize = 0;
33662ddcf05SHeiko Schocher
33762ddcf05SHeiko Schocher if ((in_be32(&im->sysconf.immrbar) & IMMRBAR_BASE_ADDR) != (u32)im)
338088454cdSSimon Glass return -ENXIO;
33962ddcf05SHeiko Schocher
34062ddcf05SHeiko Schocher out_be32(&im->sysconf.ddrlaw[0].bar,
34162ddcf05SHeiko Schocher CONFIG_SYS_DDR_BASE & LAWBAR_BAR);
34262ddcf05SHeiko Schocher msize = fixed_sdram();
34362ddcf05SHeiko Schocher
34462ddcf05SHeiko Schocher #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER)
34562ddcf05SHeiko Schocher /*
34662ddcf05SHeiko Schocher * Initialize DDR ECC byte
34762ddcf05SHeiko Schocher */
34862ddcf05SHeiko Schocher ddr_enable_ecc(msize * 1024 * 1024);
34962ddcf05SHeiko Schocher #endif
35062ddcf05SHeiko Schocher
35162ddcf05SHeiko Schocher /* return total bus SDRAM size(bytes) -- DDR */
352088454cdSSimon Glass gd->ram_size = msize * 1024 * 1024;
353088454cdSSimon Glass
354088454cdSSimon Glass return 0;
35562ddcf05SHeiko Schocher }
35662ddcf05SHeiko Schocher
checkboard(void)35762ddcf05SHeiko Schocher int checkboard(void)
35862ddcf05SHeiko Schocher {
35962ddcf05SHeiko Schocher puts("Board: Keymile " CONFIG_KM_BOARD_NAME);
36062ddcf05SHeiko Schocher
3611eb95ebeSKarlheinz Jerg if (piggy_present())
36262ddcf05SHeiko Schocher puts(" with PIGGY.");
36362ddcf05SHeiko Schocher puts("\n");
36462ddcf05SHeiko Schocher return 0;
36562ddcf05SHeiko Schocher }
36662ddcf05SHeiko Schocher
ft_board_setup(void * blob,bd_t * bd)36789127c53SValentin Longchamp int ft_board_setup(void *blob, bd_t *bd)
36862ddcf05SHeiko Schocher {
36962ddcf05SHeiko Schocher ft_cpu_setup(blob, bd);
370e895a4b0SSimon Glass
371e895a4b0SSimon Glass return 0;
37262ddcf05SHeiko Schocher }
37362ddcf05SHeiko Schocher
37462ddcf05SHeiko Schocher #if defined(CONFIG_HUSH_INIT_VAR)
hush_init_var(void)37562ddcf05SHeiko Schocher int hush_init_var(void)
37662ddcf05SHeiko Schocher {
377f32b3d3fSValentin Longchamp ivm_analyze_eeprom(ivm_content, CONFIG_SYS_IVM_EEPROM_MAX_LEN);
37862ddcf05SHeiko Schocher return 0;
37962ddcf05SHeiko Schocher }
38062ddcf05SHeiko Schocher #endif
38195209b66SThomas Herzmann
38295209b66SThomas Herzmann #if defined(CONFIG_POST)
post_hotkeys_pressed(void)38395209b66SThomas Herzmann int post_hotkeys_pressed(void)
38495209b66SThomas Herzmann {
38595209b66SThomas Herzmann int testpin = 0;
38695209b66SThomas Herzmann struct km_bec_fpga *base =
38795209b66SThomas Herzmann (struct km_bec_fpga *)CONFIG_SYS_KMBEC_FPGA_BASE;
38895209b66SThomas Herzmann int testpin_reg = in_8(&base->CONFIG_TESTPIN_REG);
38995209b66SThomas Herzmann testpin = (testpin_reg & CONFIG_TESTPIN_MASK) != 0;
39095209b66SThomas Herzmann debug("post_hotkeys_pressed: %d\n", !testpin);
39195209b66SThomas Herzmann return testpin;
39295209b66SThomas Herzmann }
39395209b66SThomas Herzmann
post_word_load(void)39495209b66SThomas Herzmann ulong post_word_load(void)
39595209b66SThomas Herzmann {
39695209b66SThomas Herzmann void* addr = (ulong *) (CPM_POST_WORD_ADDR);
39795209b66SThomas Herzmann debug("post_word_load 0x%08lX: 0x%08X\n", (ulong)addr, in_le32(addr));
39895209b66SThomas Herzmann return in_le32(addr);
39995209b66SThomas Herzmann
40095209b66SThomas Herzmann }
post_word_store(ulong value)40195209b66SThomas Herzmann void post_word_store(ulong value)
40295209b66SThomas Herzmann {
40395209b66SThomas Herzmann void* addr = (ulong *) (CPM_POST_WORD_ADDR);
40495209b66SThomas Herzmann debug("post_word_store 0x%08lX: 0x%08lX\n", (ulong)addr, value);
40595209b66SThomas Herzmann out_le32(addr, value);
40695209b66SThomas Herzmann }
40795209b66SThomas Herzmann
arch_memory_test_prepare(u32 * vstart,u32 * size,phys_addr_t * phys_offset)40895209b66SThomas Herzmann int arch_memory_test_prepare(u32 *vstart, u32 *size, phys_addr_t *phys_offset)
40995209b66SThomas Herzmann {
41095209b66SThomas Herzmann *vstart = CONFIG_SYS_MEMTEST_START;
41195209b66SThomas Herzmann *size = CONFIG_SYS_MEMTEST_END - CONFIG_SYS_MEMTEST_START;
41295209b66SThomas Herzmann debug("arch_memory_test_prepare 0x%08X 0x%08X\n", *vstart, *size);
41395209b66SThomas Herzmann
41495209b66SThomas Herzmann return 0;
41595209b66SThomas Herzmann }
41695209b66SThomas Herzmann #endif
417