Merge branch 'master' into next
[platform/kernel/u-boot.git] / board / keymile / kmeter1 / kmeter1.c
1 /*
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
30 #include "../common/common.h"
31
32 const qe_iop_conf_t qe_iop_conf_tab[] = {
33         /* port pin dir open_drain assign */
34
35         /* MDIO */
36         {0,  1, 3, 0, 2}, /* MDIO */
37         {0,  2, 1, 0, 1}, /* MDC */
38
39         /* UCC4 - UEC */
40         {1, 14, 1, 0, 1}, /* TxD0 */
41         {1, 15, 1, 0, 1}, /* TxD1 */
42         {1, 20, 2, 0, 1}, /* RxD0 */
43         {1, 21, 2, 0, 1}, /* RxD1 */
44         {1, 18, 1, 0, 1}, /* TX_EN */
45         {1, 26, 2, 0, 1}, /* RX_DV */
46         {1, 27, 2, 0, 1}, /* RX_ER */
47         {1, 24, 2, 0, 1}, /* COL */
48         {1, 25, 2, 0, 1}, /* CRS */
49         {2, 15, 2, 0, 1}, /* TX_CLK - CLK16 */
50         {2, 16, 2, 0, 1}, /* RX_CLK - CLK17 */
51
52         /* DUART - UART2 */
53         {5,  0, 1, 0, 2}, /* UART2_SOUT */
54         {5,  2, 1, 0, 1}, /* UART2_RTS */
55         {5,  3, 2, 0, 2}, /* UART2_SIN */
56         {5,  1, 2, 0, 3}, /* UART2_CTS */
57
58         /* END of table */
59         {0,  0, 0, 0, QE_IOP_TAB_END},
60 };
61
62 int board_early_init_r (void)
63 {
64         void *reg = (void *)(CONFIG_SYS_IMMR + 0x14a8);
65         u32 val;
66
67         /*
68          * Because of errata in the UCCs, we have to write to the reserved
69          * registers to slow the clocks down.
70          */
71         val = in_be32 (reg);
72         /* UCC1 */
73         val |= 0x00003000;
74         /* UCC2 */
75         val |= 0x0c000000;
76         out_be32 (reg, val);
77         /* enable the PHY on the PIGGY */
78         setbits (8, (void *)(CONFIG_SYS_PIGGY_BASE + 0x10003), 0x01);
79
80         return 0;
81 }
82
83 int fixed_sdram(void)
84 {
85         volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
86         u32 msize = 0;
87         u32 ddr_size;
88         u32 ddr_size_log2;
89
90         msize = CONFIG_SYS_DDR_SIZE;
91         for (ddr_size = msize << 20, ddr_size_log2 = 0;
92              (ddr_size > 1); ddr_size = ddr_size >> 1, ddr_size_log2++) {
93                 if (ddr_size & 1)
94                         return -1;
95         }
96
97         im->sysconf.ddrlaw[0].ar =
98             LAWAR_EN | ((ddr_size_log2 - 1) & LAWAR_SIZE);
99
100         im->ddr.csbnds[0].csbnds = CONFIG_SYS_DDR_CS0_BNDS;
101         im->ddr.cs_config[0] = CONFIG_SYS_DDR_CS0_CONFIG;
102         im->ddr.timing_cfg_0 = CONFIG_SYS_DDR_TIMING_0;
103         im->ddr.timing_cfg_1 = CONFIG_SYS_DDR_TIMING_1;
104         im->ddr.timing_cfg_2 = CONFIG_SYS_DDR_TIMING_2;
105         im->ddr.timing_cfg_3 = CONFIG_SYS_DDR_TIMING_3;
106         im->ddr.sdram_cfg = CONFIG_SYS_DDR_SDRAM_CFG;
107         im->ddr.sdram_cfg2 = CONFIG_SYS_DDR_SDRAM_CFG2;
108         im->ddr.sdram_mode = CONFIG_SYS_DDR_MODE;
109         im->ddr.sdram_mode2 = CONFIG_SYS_DDR_MODE2;
110         im->ddr.sdram_interval = CONFIG_SYS_DDR_INTERVAL;
111         im->ddr.sdram_clk_cntl = CONFIG_SYS_DDR_CLK_CNTL;
112         udelay (200);
113         im->ddr.sdram_cfg |= SDRAM_CFG_MEM_EN;
114
115         return msize;
116 }
117
118 phys_size_t initdram (int board_type)
119 {
120 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
121         extern void ddr_enable_ecc (unsigned int dram_size);
122 #endif
123         volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
124         u32 msize = 0;
125
126         if ((im->sysconf.immrbar & IMMRBAR_BASE_ADDR) != (u32)im)
127                 return -1;
128
129         /* DDR SDRAM - Main SODIMM */
130         im->sysconf.ddrlaw[0].bar = CONFIG_SYS_DDR_BASE & LAWBAR_BAR;
131         msize = fixed_sdram ();
132
133 #if defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRC)
134         /*
135          * Initialize DDR ECC byte
136          */
137         ddr_enable_ecc (msize * 1024 * 1024);
138 #endif
139
140         /* return total bus SDRAM size(bytes)  -- DDR */
141         return (msize * 1024 * 1024);
142 }
143
144 int checkboard (void)
145 {
146         puts ("Board: Keymile kmeter1");
147         if (ethernet_present ())
148                 puts (" with PIGGY.");
149         puts ("\n");
150         return 0;
151 }
152
153 #if defined(CONFIG_OF_BOARD_SETUP)
154 void ft_board_setup (void *blob, bd_t *bd)
155 {
156         ft_cpu_setup (blob, bd);
157 }
158 #endif