blob: dd7d8236d5742b6101a41d31bbb5958ac49e697c [file] [log] [blame]
Heiko Schocher30c0feb2008-01-11 01:12:06 +01001/*
2 * (C) Copyright 2007
3 * Heiko Schocher, DENX Software Engineering, hs@denx.de.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24#if 0
25#define DEBUG
26#endif
27
28#include <common.h>
29#include <mpc8xx.h>
30
31#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
32#include <libfdt.h>
33#endif
34
35DECLARE_GLOBAL_DATA_PTR;
36
37const uint sdram_table[] =
38{
39 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x0ff77c00,
40 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04,
41 /* 0x08 Burst Read */
42 0x0f07fc04, 0x0ffffc04, 0x00bdfc04, 0x00fffc00,
43 0x00fffc00, 0x00fffc00, 0x0ff77c00, 0x1ffffc05,
44 /* 0x10 Load mode register */
45 0x0ffffc34, 0x0ff57c04, 0x0ffffc04, 0x1ffffc05,
46 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
47 /* 0x18 Single Write */
48 0x0f07fc04, 0x0ffffc00, 0x00bd7c04, 0x0ffffc04,
49 0x0ff77c04, 0x1ffffc05, 0xfffffc04, 0xfffffc04,
50 /* 0x20 Burst Write */
51 0x0f07fc04, 0x0ffffc00, 0x00bd7c00, 0x00fffc00,
52 0x00fffc00, 0x00fffc04, 0x0ffffc04, 0x0ff77c04,
53 0x1ffffc05, 0xfffffc04, 0xfffffc04, 0xfffffc04,
54 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
55 /* 0x30 Precharge all and Refresh */
56 0x0ff77c04, 0x0ffffc04, 0x0ff5fc84, 0x0ffffc04,
57 0x0ffffc04, 0x0ffffc84, 0x1ffffc05, 0xfffffc04,
58 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04,
59 /* 0x3C Exception */
60 0x7ffffc04, 0xfffffc07, 0xfffffc04, 0xfffffc04,
61};
62
63int checkboard (void)
64{
65 puts ("Board: Keymile mgsuvd\n");
66 return (0);
67}
68
69long int initdram (int board_type)
70{
71 volatile immap_t *immap = (immap_t *) CFG_IMMR;
72 volatile memctl8xx_t *memctl = &immap->im_memctl;
73 long int size;
74
75 upmconfig (UPMB, (uint *) sdram_table,
76 sizeof (sdram_table) / sizeof (uint));
77
78 /*
79 * Preliminary prescaler for refresh (depends on number of
80 * banks): This value is selected for four cycles every 62.4 us
81 * with two SDRAM banks or four cycles every 31.2 us with one
82 * bank. It will be adjusted after memory sizing.
83 */
84 memctl->memc_mptpr = CFG_MPTPR;
85
86 /*
87 * The following value is used as an address (i.e. opcode) for
88 * the LOAD MODE REGISTER COMMAND during SDRAM initialisation. If
89 * the port size is 32bit the SDRAM does NOT "see" the lower two
90 * address lines, i.e. mar=0x00000088 -> opcode=0x00000022 for
91 * MICRON SDRAMs:
92 * -> 0 00 010 0 010
93 * | | | | +- Burst Length = 4
94 * | | | +----- Burst Type = Sequential
95 * | | +------- CAS Latency = 2
96 * | +----------- Operating Mode = Standard
97 * +-------------- Write Burst Mode = Programmed Burst Length
98 */
99 memctl->memc_mar = CFG_MAR;
100
101 /*
102 * Map controller banks 1 to the SDRAM banks 1 at
103 * preliminary addresses - these have to be modified after the
104 * SDRAM size has been determined.
105 */
106 memctl->memc_or1 = CFG_OR1_PRELIM;
107 memctl->memc_br1 = CFG_BR1_PRELIM;
108
109 memctl->memc_mbmr = CFG_MBMR & (~(MBMR_PTBE)); /* no refresh yet */
110
111 udelay (200);
112
113 /* perform SDRAM initializsation sequence */
114
115 memctl->memc_mcr = 0x80802830; /* SDRAM bank 0 */
116 udelay (1);
117 memctl->memc_mcr = 0x80802110; /* SDRAM bank 0 - execute twice */
118 udelay (1);
119
120 memctl->memc_mbmr |= MBMR_PTBE; /* enable refresh */
121
122 udelay (1000);
123
124 /*
125 * Check Bank 0 Memory Size for re-configuration
126 *
127 */
128 size = get_ram_size(SDRAM_BASE1_PRELIM, SDRAM_MAX_SIZE);
129
130 udelay (1000);
131
132 debug ("SDRAM Bank 0: %ld MB\n", size >> 20);
133
134 return (size);
135}
136
137#if defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT)
138/*
139 * update "memory" property in the blob
140 */
141void ft_blob_update(void *blob, bd_t *bd)
142{
143 int ret, nodeoffset = 0;
144 ulong brg_data[1] = {0};
145 ulong memory_data[2] = {0};
146 ulong flash_data[4] = {0};
147
148 memory_data[0] = cpu_to_be32(bd->bi_memstart);
149 memory_data[1] = cpu_to_be32(bd->bi_memsize);
150
151 nodeoffset = fdt_path_offset (blob, "/memory");
152 if (nodeoffset >= 0) {
153 ret = fdt_setprop(blob, nodeoffset, "reg", memory_data,
154 sizeof(memory_data));
155 if (ret < 0)
156 printf("ft_blob_update): cannot set /memory/reg "
157 "property err:%s\n", fdt_strerror(ret));
158 }
159 else {
160 /* memory node is required in dts */
161 printf("ft_blob_update(): cannot find /memory node "
162 "err:%s\n", fdt_strerror(nodeoffset));
163 }
164
165 flash_data[2] = cpu_to_be32(bd->bi_flashstart);
166 flash_data[3] = cpu_to_be32(bd->bi_flashsize);
167 nodeoffset = fdt_path_offset (blob, "/localbus");
168 if (nodeoffset >= 0) {
169 ret = fdt_setprop(blob, nodeoffset, "ranges", flash_data,
170 sizeof(flash_data));
171 if (ret < 0)
172 printf("ft_blob_update): cannot set /localbus/ranges "
173 "property err:%s\n", fdt_strerror(ret));
174 }
175 else {
176 /* memory node is required in dts */
177 printf("ft_blob_update(): cannot find /localbus node "
178 "err:%s\n", fdt_strerror(nodeoffset));
179 }
180 /* BRG */
181 brg_data[0] = cpu_to_be32(bd->bi_busfreq);
182 nodeoffset = fdt_path_offset (blob, "/soc866/cpm");
183 if (nodeoffset >= 0) {
184 ret = fdt_setprop(blob, nodeoffset, "brg-frequency", brg_data,
185 sizeof(brg_data));
186 if (ret < 0)
187 printf("ft_blob_update): cannot set /soc866/cpm/brg-frequency "
188 "property err:%s\n", fdt_strerror(ret));
189 }
190 else {
191 /* memory node is required in dts */
192 printf("ft_blob_update(): cannot find /localbus node "
193 "err:%s\n", fdt_strerror(nodeoffset));
194 }
195 /* MAC Adresse */
196 nodeoffset = fdt_path_offset (blob, "/soc866/cpm/scc");
197 if (nodeoffset >= 0) {
198 ret = fdt_setprop(blob, nodeoffset, "mac-address", bd->bi_enetaddr,
199 sizeof(uchar) * 6);
200 if (ret < 0)
201 printf("ft_blob_update): cannot set /soc866/cpm/scc/mac-address "
202 "property err:%s\n", fdt_strerror(ret));
203 }
204 else {
205 /* memory node is required in dts */
206 printf("ft_blob_update(): cannot find /localbus node "
207 "err:%s\n", fdt_strerror(nodeoffset));
208 }
209}
210
211void ft_board_setup(void *blob, bd_t *bd)
212{
213 ft_cpu_setup( blob, bd);
214 ft_blob_update(blob, bd);
215}
216#endif /* defined(CONFIG_OF_BOARD_SETUP) && defined(CONFIG_OF_LIBFDT) */