blob: 748ad7cec61c234472c8c07227c282b1264cb5c3 [file] [log] [blame]
Stefan Roeseabbd0da2009-06-09 11:50:40 +02001/*
2 * (C) Copyright 2009 Wolfgang Denk <wd@denx.de>
3 * (C) Copyright 2009 Dave Srl www.dave.eu
4 * (C) Copyright 2009 Stefan Roese <sr@denx.de>
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 *
24 */
25
26#include <common.h>
27#include <asm/bitops.h>
28#include <command.h>
29#include <asm/io.h>
30#include <asm/processor.h>
Wolfgang Denk1d7cc1e2009-06-14 20:58:47 +020031#include <asm/mpc512x.h>
Stefan Roeseabbd0da2009-06-09 11:50:40 +020032#include <fdt_support.h>
33
34DECLARE_GLOBAL_DATA_PTR;
35
36/* Clocks in use */
37#define SCCR1_CLOCKS_EN (CLOCK_SCCR1_CFG_EN | \
38 CLOCK_SCCR1_LPC_EN | \
39 CLOCK_SCCR1_PSC_EN(CONFIG_PSC_CONSOLE) | \
40 CLOCK_SCCR1_PSCFIFO_EN | \
41 CLOCK_SCCR1_DDR_EN | \
42 CLOCK_SCCR1_FEC_EN | \
43 CLOCK_SCCR1_NFC_EN | \
44 CLOCK_SCCR1_PCI_EN | \
45 CLOCK_SCCR1_TPR_EN)
46
47#define SCCR2_CLOCKS_EN (CLOCK_SCCR2_MEM_EN | \
48 CLOCK_SCCR2_I2C_EN)
49
Stefan Roeseabbd0da2009-06-09 11:50:40 +020050int eeprom_write_enable(unsigned dev_addr, int state)
51{
52 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
53
54 if (dev_addr != CONFIG_SYS_I2C_EEPROM_ADDR)
55 return -1;
56
57 if (state == 0)
58 setbits_be32(&im->gpio.gpdat, 0x00100000);
59 else
60 clrbits_be32(&im->gpio.gpdat, 0x00100000);
61
Wolfgang Denk1d7cc1e2009-06-14 20:58:47 +020062 return 0;
Stefan Roeseabbd0da2009-06-09 11:50:40 +020063}
64
65int board_early_init_f(void)
66{
67 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
68 u32 spridr;
Wolfgang Denk19443512009-06-14 20:58:46 +020069 int i;
Stefan Roeseabbd0da2009-06-09 11:50:40 +020070
71 /*
72 * Initialize Local Window for NOR FLASH access
73 */
74 out_be32(&im->sysconf.lpcs0aw,
75 CSAW_START(CONFIG_SYS_FLASH_BASE) |
76 CSAW_STOP(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE));
77 sync_law(&im->sysconf.lpcs0aw);
78
79 /*
80 * Initialize Local Window for boot access
81 */
82 out_be32(&im->sysconf.lpbaw,
83 CSAW_START(0xffb00000) | CSAW_STOP(0xffb00000, 0x00010000));
84 sync_law(&im->sysconf.lpbaw);
85
86 /*
87 * Initialize Local Window for VPC3 access
88 */
89 out_be32(&im->sysconf.lpcs1aw,
90 CSAW_START(CONFIG_SYS_VPC3_BASE) |
91 CSAW_STOP(CONFIG_SYS_VPC3_BASE, CONFIG_SYS_VPC3_SIZE));
92 sync_law(&im->sysconf.lpcs1aw);
93
94 /*
95 * Configure Flash Speed
96 */
97 out_be32(&im->lpc.cs_cfg[0], CONFIG_SYS_CS0_CFG);
98
99 /*
100 * Configure VPC3 Speed
101 */
102 out_be32(&im->lpc.cs_cfg[1], CONFIG_SYS_CS1_CFG);
103
104 spridr = in_be32(&im->sysconf.spridr);
105 if (SVR_MJREV(spridr) >= 2)
106 out_be32(&im->lpc.altr, CONFIG_SYS_CS_ALETIMING);
107
108 /*
109 * Enable clocks
110 */
111 out_be32(&im->clk.sccr[0], SCCR1_CLOCKS_EN);
112 out_be32(&im->clk.sccr[1], SCCR2_CLOCKS_EN);
113#if defined(CONFIG_IIM) || defined(CONFIG_CMD_FUSE)
114 setbits_be32(&im->clk.sccr[1], CLOCK_SCCR2_IIM_EN);
115#endif
116
117 /*
118 * Configure MSCAN clocks
119 */
Wolfgang Denk19443512009-06-14 20:58:46 +0200120 for (i=0; i<4; ++i) {
121 out_be32(&im->clk.msccr[i], 0x00300000);
122 out_be32(&im->clk.msccr[i], 0x00310000);
123 }
Stefan Roeseabbd0da2009-06-09 11:50:40 +0200124
125 /*
126 * Configure GPIO's
127 */
128 clrbits_be32(&im->gpio.gpodr, 0x000000e0);
129 clrbits_be32(&im->gpio.gpdir, 0x00ef0000);
130 setbits_be32(&im->gpio.gpdir, 0x001000e0);
131 setbits_be32(&im->gpio.gpdat, 0x00100000);
132
133 return 0;
134}
135
Stefan Roeseabbd0da2009-06-09 11:50:40 +0200136phys_size_t initdram(int board_type)
137{
Martha M Stanc12ecae2009-09-21 14:07:14 -0400138 return get_ram_size(0, fixed_sdram(NULL, NULL, 0));
Stefan Roeseabbd0da2009-06-09 11:50:40 +0200139}
140
141int misc_init_r(void)
142{
143 volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
144 u32 val;
145
146 /*
147 * Optimize access to profibus chip (VPC3) on the local bus
148 */
149
150 /*
151 * Select 1:1 for LPC_DIV
152 */
153 val = in_be32(&im->clk.scfr[0]) & ~SCFR1_LPC_DIV_MASK;
154 out_be32(&im->clk.scfr[0], val | (0x1 << SCFR1_LPC_DIV_SHIFT));
155
156 /*
157 * Configure LPC Chips Select Deadcycle Control Register
158 * CS0 - device can drive data 2 clock cycle(s) after CS deassertion
159 * CS1 - device can drive data 1 clock cycle(s) after CS deassertion
160 */
161 clrbits_be32(&im->lpc.cs_dccr, 0x000000ff);
162 setbits_be32(&im->lpc.cs_dccr, (0x00 << 4) | (0x01 << 0));
163
164 /*
165 * Configure LPC Chips Select Holdcycle Control Register
166 * CS0 - data is valid 2 clock cycle(s) after CS deassertion
167 * CS1 - data is valid 1 clock cycle(s) after CS deassertion
168 */
169 clrbits_be32(&im->lpc.cs_hccr, 0x000000ff);
170 setbits_be32(&im->lpc.cs_hccr, (0x00 << 4) | (0x01 << 0));
171
172 return 0;
173}
174
175static iopin_t ioregs_init[] = {
176 /* FUNC1=FEC_RX_DV Sets Next 3 to FEC pads */
177 {
178 offsetof(struct ioctrl512x, io_control_spdif_txclk), 3, 0,
179 IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
180 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
181 },
182 /* FUNC1=FEC_COL Sets Next 15 to FEC pads */
183 {
184 offsetof(struct ioctrl512x, io_control_psc0_0), 15, 0,
185 IO_PIN_FMUX(1) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
186 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
187 },
188 /* FUNC1=SELECT LPC_CS1 */
189 {
190 offsetof(struct ioctrl512x, io_control_lpc_cs1), 1, 0,
191 IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
192 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
193 },
194 /* FUNC3=SELECT PSC5_2 */
195 {
196 offsetof(struct ioctrl512x, io_control_psc5_2), 1, 0,
197 IO_PIN_FMUX(2) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
198 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
199 },
200 /* FUNC3=SELECT PSC5_3 */
201 {
202 offsetof(struct ioctrl512x, io_control_psc5_3), 1, 0,
203 IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
204 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
205 },
206 /* FUNC3=SELECT PSC7_3 */
207 {
208 offsetof(struct ioctrl512x, io_control_psc7_3), 1, 0,
209 IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
210 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
211 },
212 /* FUNC3=SELECT PSC9_0 */
213 {
214 offsetof(struct ioctrl512x, io_control_psc9_0), 3, 0,
215 IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
216 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
217 },
218 /* FUNC3=SELECT PSC10_0 */
219 {
220 offsetof(struct ioctrl512x, io_control_psc10_0), 3, 0,
221 IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
222 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
223 },
224 /* FUNC3=SELECT PSC10_3 */
225 {
226 offsetof(struct ioctrl512x, io_control_psc10_3), 1, 0,
227 IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
228 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
229 },
230 /* FUNC3=SELECT PSC11_0 */
231 {
232 offsetof(struct ioctrl512x, io_control_psc11_0), 4, 0,
233 IO_PIN_FMUX(3) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
234 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
235 },
236 /* FUNC0=SELECT IRQ0 */
237 {
238 offsetof(struct ioctrl512x, io_control_irq0), 4, 0,
239 IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_PUD(0) |
240 IO_PIN_PUE(0) | IO_PIN_ST(0) | IO_PIN_DS(3)
241 }
242};
243
244static iopin_t rev2_silicon_pci_ioregs_init[] = {
245 /* FUNC0=PCI Sets next 54 to PCI pads */
246 {
247 offsetof(struct ioctrl512x, io_control_pci_ad31), 54, 0,
248 IO_PIN_FMUX(0) | IO_PIN_HOLD(0) | IO_PIN_DS(0)
249 }
250};
251
252int checkboard(void)
253{
254 volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
255 u32 spridr;
256
257 puts("Board: MECP_5123\n");
258
259 /*
260 * Initialize function mux & slew rate IO inter alia on IO
261 * Pins
262 */
263 iopin_initialize(ioregs_init, ARRAY_SIZE(ioregs_init));
264
265 spridr = in_be32(&im->sysconf.spridr);
266 if (SVR_MJREV(spridr) >= 2)
267 iopin_initialize(rev2_silicon_pci_ioregs_init, 1);
268
269 return 0;
270}
271
272#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
273void ft_board_setup(void *blob, bd_t *bd)
274{
275 ft_cpu_setup(blob, bd);
Stefan Roeseabbd0da2009-06-09 11:50:40 +0200276}
277#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */