1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2006-2023 CS GROUP France
*/
#include <command.h>
#include <common.h>
#include <dm.h>
#include <env.h>
#include <env_internal.h>
#include <eeprom.h>
#include <fdt_support.h>
#include <hang.h>
#include <ioports.h>
#include <mpc83xx.h>
#include <netdev.h>
#include <spi.h>
#include <stdarg.h>
#include <stdlib.h>
#include <linux/delay.h>
#include <linux/immap_qe.h>
#include <linux/libfdt.h>
#include <linux/log2.h>
#include <linux/sizes.h>
#include <asm/io.h>
#include <asm/global_data.h>
#include <asm/mmu.h>
#include <u-boot/crc.h>
#include "../common/common.h"
DECLARE_GLOBAL_DATA_PTR;
#define ADDR_FPGA_BASE ((unsigned char __iomem *)CONFIG_CPLD_BASE)
#define ADDR_FPGA_RESET_G (ADDR_FPGA_BASE + 0x40)
#define ADDR_FPGA_REG_ETAT (ADDR_FPGA_BASE + 0x42)
#define R_ETAT_PRES_BASE 0x01
#define RESET_G_OK 0x08
/* SPI EEPROM parameters */
#define MAX_SPI_BYTES 0x28
#define EE_OFF_MAC1 0x10
#define EE_OFF_MAC2 0x16
#define EE_OFF_MAC3 0x1C
static uint upma_table[] = {
/* Read Single-Beat (RSS) */
0x00AC0C00, 0x00FC1C40, 0x30FCE045, 0xFFFF0C00,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
/* Read Burst (RBS) */
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
/* Write Single-Beat (WSS) */
0x00A30C00, 0x00F31C40, 0x3FF3C045, 0xFFFF0C00,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
/* Write Burst (WBS) */
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
/* Refresh Timer (RTS) */
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0x00000000, 0x00000000,
/* Exception Condition (EXS) */
0xFFFF0C01, 0xFFFF0C01, 0xFFFF0C01, 0xFFFF0C01,
};
const qe_iop_conf_t qe_iop_conf_tab[] = {
/* ETH3 */
{1, 0, 1, 0, 1}, /* TxD0 */
{1, 1, 1, 0, 1}, /* TxD1 */
{1, 2, 1, 0, 1}, /* TxD2 */
{1, 3, 1, 0, 1}, /* TxD3 */
{1, 9, 1, 0, 1}, /* TxER */
{1, 12, 1, 0, 1}, /* TxEN */
{3, 24, 2, 0, 1}, /* TxCLK->CLK10 */
{1, 4, 2, 0, 1}, /* RxD0 */
{1, 5, 2, 0, 1}, /* RxD1 */
{1, 6, 2, 0, 1}, /* RxD2 */
{1, 7, 2, 0, 1}, /* RxD3 */
{1, 8, 2, 0, 1}, /* RxER */
{1, 10, 2, 0, 1}, /* RxDV */
{0, 13, 2, 0, 1}, /* RxCLK->CLK9 */
{1, 11, 2, 0, 1}, /* COL */
{1, 13, 2, 0, 1}, /* CRS */
/* ETH4 */
{1, 18, 1, 0, 1}, /* TxD0 */
{1, 19, 1, 0, 1}, /* TxD1 */
{1, 20, 1, 0, 1}, /* TxD2 */
{1, 21, 1, 0, 1}, /* TxD3 */
{1, 27, 1, 0, 1}, /* TxER */
{1, 30, 1, 0, 1}, /* TxEN */
{3, 6, 2, 0, 1}, /* TxCLK->CLK8 */
{1, 22, 2, 0, 1}, /* RxD0 */
{1, 23, 2, 0, 1}, /* RxD1 */
{1, 24, 2, 0, 1}, /* RxD2 */
{1, 25, 2, 0, 1}, /* RxD3 */
{1, 26, 1, 0, 1}, /* RxER */
{1, 28, 2, 0, 1}, /* Rx_DV */
{3, 31, 2, 0, 1}, /* RxCLK->CLK7 */
{1, 29, 2, 0, 1}, /* COL */
{1, 31, 2, 0, 1}, /* CRS */
{3, 4, 3, 0, 2}, /* MDIO */
{3, 5, 1, 0, 2}, /* MDC */
{0, 0, 0, 0, QE_IOP_TAB_END}, /* END of table */
};
void iop_setup_miae(void)
{
immap_t __iomem *im = (immap_t *)CONFIG_SYS_IMMR;
/* PORTA configuration */
out_be32(&im->qepio.ioport[0].pdat, 0x00808000);
out_be32(&im->qepio.ioport[0].podr, 0x00008000);
out_be32(&im->qepio.ioport[0].dir1, 0x40800968);
out_be32(&im->qepio.ioport[0].dir2, 0x650A0896);
out_be32(&im->qepio.ioport[0].ppar1, 0x40400204);
out_be32(&im->qepio.ioport[0].ppar2, 0x05050464);
/* PORTB configuration */
out_be32(&im->qepio.ioport[1].pdat, 0x00018000);
out_be32(&im->qepio.ioport[1].podr, 0x00000000);
out_be32(&im->qepio.ioport[1].dir1, 0x50A08949);
out_be32(&im->qepio.ioport[1].dir2, 0x5C0C6890);
out_be32(&im->qepio.ioport[1].ppar1, 0x50504644);
out_be32(&im->qepio.ioport[1].ppar2, 0x080800A0);
/* PORTC configuration */
out_be32(&im->qepio.ioport[2].pdat, 0x3D000108);
out_be32(&im->qepio.ioport[2].podr, 0x00000000);
out_be32(&im->qepio.ioport[2].dir1, 0x45518000);
out_be32(&im->qepio.ioport[2].dir2, 0xA8119561);
out_be32(&im->qepio.ioport[2].ppar1, 0x80008000);
out_be32(&im->qepio.ioport[2].ppar2, 0x00000000);
/* PORTD configuration */
out_be32(&im->qepio.ioport[3].pdat, 0x1000E000);
out_be32(&im->qepio.ioport[3].podr, 0x0000E000);
out_be32(&im->qepio.ioport[3].dir1, 0xFDD20800);
out_be32(&im->qepio.ioport[3].dir2, 0x54155228);
out_be32(&im->qepio.ioport[3].ppar1, 0x54A30C00);
out_be32(&im->qepio.ioport[3].ppar2, 0x00000100);
}
void iop_setup_mcr(void)
{
immap_t __iomem *im = (immap_t *)CONFIG_SYS_IMMR;
/* PORTA configuration */
out_be32(&im->qepio.ioport[0].pdat, 0x00808004);
out_be32(&im->qepio.ioport[0].podr, 0x00000000);
out_be32(&im->qepio.ioport[0].dir1, 0x40800A68);
out_be32(&im->qepio.ioport[0].dir2, 0x650A0896);
out_be32(&im->qepio.ioport[0].ppar1, 0x40400004);
out_be32(&im->qepio.ioport[0].ppar2, 0x05050444);
/* PORTB configuration */
out_be32(&im->qepio.ioport[1].pdat, 0x00008000);
out_be32(&im->qepio.ioport[1].podr, 0x00000004);
out_be32(&im->qepio.ioport[1].dir1, 0x50A08A4A);
out_be32(&im->qepio.ioport[1].dir2, 0x5C0C6890);
out_be32(&im->qepio.ioport[1].ppar1, 0x50504444);
out_be32(&im->qepio.ioport[1].ppar2, 0x08080080);
/* PORTC configuration */
out_be32(&im->qepio.ioport[2].pdat, 0x3D000018);
out_be32(&im->qepio.ioport[2].podr, 0x00000400);
out_be32(&im->qepio.ioport[2].dir1, 0x45518000);
out_be32(&im->qepio.ioport[2].dir2, 0xA8129561);
out_be32(&im->qepio.ioport[2].ppar1, 0x80008000);
out_be32(&im->qepio.ioport[2].ppar2, 0x00000000);
/* PORTD configuration */
out_be32(&im->qepio.ioport[3].pdat, 0x1000E000);
out_be32(&im->qepio.ioport[3].podr, 0x0000E000);
out_be32(&im->qepio.ioport[3].dir1, 0xFDD20800);
out_be32(&im->qepio.ioport[3].dir2, 0x54155228);
out_be32(&im->qepio.ioport[3].ppar1, 0x54A30C00);
out_be32(&im->qepio.ioport[3].ppar2, 0x00000100);
}
static void iop_setup_cmpcpro(void)
{
immap_t __iomem *im = (immap_t *)CONFIG_SYS_IMMR;
/* PORTA configuration */
out_be32(&im->qepio.ioport[0].pdat, 0x00000000);
out_be32(&im->qepio.ioport[0].podr, 0x00000000);
out_be32(&im->qepio.ioport[0].dir1, 0x50A84020);
out_be32(&im->qepio.ioport[0].dir2, 0x00000000);
out_be32(&im->qepio.ioport[0].ppar1, 0xF0FCC000);
out_be32(&im->qepio.ioport[0].ppar2, 0x00000000);
/* PORTB configuration */
out_be32(&im->qepio.ioport[1].pdat, 0x00000000);
out_be32(&im->qepio.ioport[1].podr, 0x00000000);
out_be32(&im->qepio.ioport[1].dir1, 0x00000000);
out_be32(&im->qepio.ioport[1].dir2, 0x00006800);
out_be32(&im->qepio.ioport[1].ppar1, 0x00000000);
out_be32(&im->qepio.ioport[1].ppar2, 0x00000000);
/* PORTC configuration */
out_be32(&im->qepio.ioport[2].pdat, 0x19000000);
out_be32(&im->qepio.ioport[2].podr, 0x00000000);
out_be32(&im->qepio.ioport[2].dir1, 0x01410000);
out_be32(&im->qepio.ioport[2].dir2, 0xA8009400);
out_be32(&im->qepio.ioport[2].ppar1, 0x00000000);
out_be32(&im->qepio.ioport[2].ppar2, 0x00000000);
/* PORTD configuration */
out_be32(&im->qepio.ioport[3].pdat, 0x1000E000);
out_be32(&im->qepio.ioport[3].podr, 0x0000E000);
out_be32(&im->qepio.ioport[3].dir1, 0xFD020000);
out_be32(&im->qepio.ioport[3].dir2, 0x54055000);
out_be32(&im->qepio.ioport[3].ppar1, 0x54030000);
out_be32(&im->qepio.ioport[3].ppar2, 0x00000000);
}
int board_early_init_r(void)
{
immap_t __iomem *im = (immap_t *)CONFIG_SYS_IMMR;
fsl_lbc_t *lbus = &im->im_lbc;
upmconfig(UPMA, upma_table, ARRAY_SIZE(upma_table));
out_be32(&lbus->mamr, 0x00044440);
/* configure LBCR register */
out_be32(&lbus->lbcr, 0x00000500);
sync();
if (in_8(ADDR_FPGA_REG_ETAT) & R_ETAT_PRES_BASE) {
int i;
/* Initialize signal PROG_FPGA_FIRMWARE */
setbits_be32(&im->qepio.ioport[0].pdat, 0x00008000);
setbits_be32(&im->qepio.ioport[0].dir2, 0x60000002);
setbits_be32(&im->qepio.ioport[0].podr, 0x00008000);
mdelay(1);
/* Now read CPDATA[31] to check if FPGA is loaded */
if (!in_be32(&im->qepio.ioport[0].pdat) & 0x00000001) {
printf("Reloading FPGA firmware.\n");
clrbits_be32(&im->qepio.ioport[0].pdat, 0x00008000);
udelay(1);
setbits_be32(&im->qepio.ioport[0].pdat, 0x00008000);
/* Wait 200 msec and check DONE_FPGA_FIRMWARE */
mdelay(200);
if (!(in_be32(&im->qepio.ioport[0].pdat) & 0x00000001)) {
for (;;) {
printf("error loading firmware.\n");
mdelay(500);
}
}
/* Send a reset signal and wait for 20 msec */
out_8(ADDR_FPGA_RESET_G, in_8(ADDR_FPGA_RESET_G) | RESET_G_OK);
mdelay(20);
out_8(ADDR_FPGA_RESET_G, in_8(ADDR_FPGA_RESET_G) & ~RESET_G_OK);
}
/* Wait 300 msec and check the reset state */
mdelay(300);
for (i = 0; !(in_8(ADDR_FPGA_REG_ETAT) & RESET_G_OK); i++) {
for (;;) {
printf("Could not reset FPGA.\n");
mdelay(500);
}
}
iop_setup_common();
/* clocks configuration */
out_be32(&qe_immr->qmx.cmxsi1cr_l, 0x00040004);
out_be32(&qe_immr->qmx.cmxsi1syr, 0x00000000);
} else {
iop_setup_cmpcpro();
}
return 0;
}
int dram_init(int board_type)
{
immap_t __iomem *im = (immap_t __iomem *)CONFIG_SYS_IMMR;
out_be32(&im->sysconf.ddrlaw[0].bar, CFG_SYS_DDR_SDRAM_BASE & LAWBAR_BAR);
out_be32(&im->sysconf.ddrlaw[0].ar, LAWAR_EN | ((ilog2(SZ_512M) - 1) & LAWAR_SIZE));
out_be32(&im->ddr.sdram_clk_cntl, CFG_SYS_DDR_CLK_CNTL);
out_be32(&im->ddr.csbnds[0].csbnds, CFG_SYS_DDR_CS0_BNDS);
out_be32(&im->ddr.cs_config[0], CFG_SYS_DDR_CS0_CONFIG);
out_be32(&im->ddr.timing_cfg_0, CFG_SYS_DDR_TIMING_0);
out_be32(&im->ddr.timing_cfg_1, CFG_SYS_DDR_TIMING_1);
out_be32(&im->ddr.timing_cfg_2, CFG_SYS_DDR_TIMING_2);
out_be32(&im->ddr.timing_cfg_3, CFG_SYS_DDR_TIMING_3);
out_be32(&im->ddr.sdram_cfg, CFG_SYS_DDR_SDRAM_CFG);
out_be32(&im->ddr.sdram_cfg2, CFG_SYS_DDR_SDRAM_CFG2);
out_be32(&im->ddr.sdram_mode, CFG_SYS_DDR_MODE);
out_be32(&im->ddr.sdram_mode2, CFG_SYS_DDR_MODE2);
out_be32(&im->ddr.sdram_interval, CFG_SYS_DDR_INTERVAL);
udelay(200);
setbits_be32(&im->ddr.sdram_cfg, SDRAM_CFG_MEM_EN);
gd->ram_size = SZ_512M;
return 0;
}
int checkboard(void)
{
printf("Board: ");
/* Is a motherboard present ? */
if (in_8(ADDR_FPGA_REG_ETAT) & R_ETAT_PRES_BASE)
return checkboard_common();
printf("CMPCPRO (CS GROUP)\n");
return 0;
}
/* Reads MAC addresses from SPI EEPROM */
static int setup_mac(void)
{
uchar din[MAX_SPI_BYTES];
int ret;
unsigned long ident = 0x08005120;
ret = read_eeprom(din, sizeof(din));
if (ret)
return ret;
if (memcmp(din + EE_OFF_MAC1, &ident, sizeof(ident)) == 0) {
eth_env_set_enetaddr("ethaddr", din + EE_OFF_MAC1);
eth_env_set_enetaddr("eth3addr", din + EE_OFF_MAC1);
}
if (memcmp(din + EE_OFF_MAC2, &ident, sizeof(ident)) == 0)
eth_env_set_enetaddr("eth1addr", din + EE_OFF_MAC2);
if (memcmp(din + EE_OFF_MAC3, &ident, sizeof(ident)) == 0)
eth_env_set_enetaddr("eth2addr", din + EE_OFF_MAC3);
return 0;
}
int misc_init_r(void)
{
/* we do not modify environment variable area if CRC is false */
/* Verify if mother board is present */
if (in_8(ADDR_FPGA_REG_ETAT) & R_ETAT_PRES_BASE) {
misc_init_r_common();
} else {
env_set("config", CFG_BOARD_CMPCXXX);
env_set("hostname", CFG_BOARD_CMPCXXX);
}
if (setup_mac())
printf("Error retrieving mac addresses\n");
return 0;
}
int ft_board_setup(void *blob, struct bd_info *bd)
{
ft_cpu_setup(blob, bd);
/* MIAE only */
if (!(in_8(ADDR_FPGA_REG_ETAT) & R_ETAT_PRES_BASE))
return 0;
return ft_board_setup_common(blob);
}
void ft_board_setup_phy3(void)
{
/* switch to phy3 with gpio, we'll only use phy3 */
immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
setbits_be32(&immr->qepio.ioport[2].pdat, 0x00000400);
}
|