blob: 4f41f1d76d75512e36b8d6184874089c5335eb8e [file] [log] [blame]
Heiko Schocherde044362008-11-20 09:57:47 +01001/*
2 * Copyright (C) 2006 Freescale Semiconductor, Inc.
3 * Dave Liu <daveliu@freescale.com>
4 *
5 * Copyright (C) 2007 Logic Product Development, Inc.
6 * Peter Barada <peterb@logicpd.com>
7 *
8 * Copyright (C) 2007 MontaVista Software, Inc.
9 * Anton Vorontsov <avorontsov@ru.mvista.com>
10 *
11 * (C) Copyright 2008
12 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
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
20#include <common.h>
21#include <ioports.h>
22#include <mpc83xx.h>
23#include <i2c.h>
24#include <miiphy.h>
25#include <asm/io.h>
26#include <asm/mmu.h>
27#include <pci.h>
28#include <libfdt.h>
29
Heiko Schocher210c8c02008-11-21 08:29:40 +010030#include "../common/common.h"
31
Heiko Schocher118cbe32009-02-24 11:30:40 +010032extern void disable_addr_trans (void);
33extern void enable_addr_trans (void);
Heiko Schocherde044362008-11-20 09:57:47 +010034const qe_iop_conf_t qe_iop_conf_tab[] = {
35 /* port pin dir open_drain assign */
36
37 /* MDIO */
38 {0, 1, 3, 0, 2}, /* MDIO */
39 {0, 2, 1, 0, 1}, /* MDC */
40
41 /* UCC4 - UEC */
42 {1, 14, 1, 0, 1}, /* TxD0 */
43 {1, 15, 1, 0, 1}, /* TxD1 */
44 {1, 20, 2, 0, 1}, /* RxD0 */
45 {1, 21, 2, 0, 1}, /* RxD1 */
46 {1, 18, 1, 0, 1}, /* TX_EN */
47 {1, 26, 2, 0, 1}, /* RX_DV */
48 {1, 27, 2, 0, 1}, /* RX_ER */
49 {1, 24, 2, 0, 1}, /* COL */
50 {1, 25, 2, 0, 1}, /* CRS */
51 {2, 15, 2, 0, 1}, /* TX_CLK - CLK16 */
52 {2, 16, 2, 0, 1}, /* RX_CLK - CLK17 */
53
54 /* DUART - UART2 */
55 {5, 0, 1, 0, 2}, /* UART2_SOUT */
56 {5, 2, 1, 0, 1}, /* UART2_RTS */
57 {5, 3, 2, 0, 2}, /* UART2_SIN */
58 {5, 1, 2, 0, 3}, /* UART2_CTS */
59
60 /* END of table */
61 {0, 0, 0, 0, QE_IOP_TAB_END},
62};
63
Heiko Schocher19f0e932009-02-24 11:30:34 +010064static int board_init_i2c_busses (void)
65{
66 I2C_MUX_DEVICE *dev = NULL;
67 uchar *buf;
68
69 /* Set up the Bus for the DTTs */
70 buf = (unsigned char *) getenv ("dtt_bus");
71 if (buf != NULL)
72 dev = i2c_mux_ident_muxstring (buf);
73 if (dev == NULL) {
74 printf ("Error couldn't add Bus for DTT\n");
75 printf ("please setup dtt_bus to where your\n");
76 printf ("DTT is found.\n");
77 }
78 return 0;
79}
80
Heiko Schocherde044362008-11-20 09:57:47 +010081int board_early_init_r (void)
82{
83 void *reg = (void *)(CONFIG_SYS_IMMR + 0x14a8);
84 u32 val;
85
86 /*
87 * Because of errata in the UCCs, we have to write to the reserved
88 * registers to slow the clocks down.
89 */
90 val = in_be32 (reg);
91 /* UCC1 */
92 val |= 0x00003000;
93 /* UCC2 */
94 val |= 0x0c000000;
95 out_be32 (reg, val);
96 /* enable the PHY on the PIGGY */
97 setbits (8, (void *)(CONFIG_SYS_PIGGY_BASE + 0x10003), 0x01);
98
99 return 0;
100}
101
Heiko Schocher19f0e932009-02-24 11:30:34 +0100102int misc_init_r (void)
103{
104 /* add board specific i2c busses */
105 board_init_i2c_busses ();
106 return 0;
107}
108
Heiko Schocherde044362008-11-20 09:57:47 +0100109int fixed_sdram(void)
110{
111 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
112 u32 msize = 0;
113 u32 ddr_size;
114 u32 ddr_size_log2;
115
Heiko Schocher118cbe32009-02-24 11:30:40 +0100116 im->sysconf.ddrlaw[0].ar = LAWAR_EN | 0x1e;
Heiko Schocherde044362008-11-20 09:57:47 +0100117 im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
118 im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
119 im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
120 im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
121 im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
122 im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
123 im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
124 im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
125 im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
126 im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
127 im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
128 im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
129 udelay (200);
130 im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
131
Heiko Schocher118cbe32009-02-24 11:30:40 +0100132 msize = CONFIG_SYS_DDR_SIZE << 20;
133 disable_addr_trans ();
134 msize = get_ram_size (CONFIG_SYS_DDR_BASE, msize);
135 enable_addr_trans ();
136 msize /= (1024 * 1024);
137 if (CONFIG_SYS_DDR_SIZE != msize) {
138 for (ddr_size = msize << 20, ddr_size_log2 = 0;
139 (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++)
140 if (ddr_size & 1)
141 return -1;
142 im->sysconf.ddrlaw[0].ar =
143 LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
144 im->ddr.csbnds[0].csbnds = (((msize / 16) - 1) & 0xff);
145 }
146
Heiko Schocherde044362008-11-20 09:57:47 +0100147 return msize;
148}
149
150phys_size_t initdram (int board_type)
151{
152#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
153 extern void ddr_enable_ecc (unsigned int dram_size);
154#endif
155 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
156 u32 msize = 0;
157
158 if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
159 return -1;
160
161 /* DDR SDRAM - Main SODIMM */
162 im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
163 msize = fixed_sdram ();
164
165#if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
166 /*
167 * Initialize DDR ECC byte
168 */
169 ddr_enable_ecc (msize * 1024 * 1024);
170#endif
171
172 /* return total bus SDRAM size(bytes) -- DDR */
173 return (msize * 1024 * 1024);
174}
175
176int checkboard (void)
177{
Heiko Schocher210c8c02008-11-21 08:29:40 +0100178 puts ("Board: Keymile kmeter1");
179 if (ethernet_present ())
180 puts (" with PIGGY.");
181 puts ("\n");
Heiko Schocherde044362008-11-20 09:57:47 +0100182 return 0;
183}
184
185#if defined(CONFIG_OF_BOARD_SETUP)
186void ft_board_setup (void *blob, bd_t *bd)
187{
188 ft_cpu_setup (blob, bd);
189}
190#endif
Heiko Schocher19f0e932009-02-24 11:30:34 +0100191
192#if defined(CONFIG_HUSH_INIT_VAR)
193extern int ivm_read_eeprom (void);
194int hush_init_var (void)
195{
196 ivm_read_eeprom ();
197 return 0;
198}
199#endif