blob: bf5a4cb682430225a989a5be73934d117418099b [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
stroese6f4474e2003-03-20 15:31:19 +00002 * (C) Copyright 2001-2003
wdenkc6097192002-11-03 00:24:07 +00003 * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com
4 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
wdenkc6097192002-11-03 00:24:07 +00007#include <common.h>
Matthias Fuchs600fe462009-01-02 12:18:12 +01008#include <libfdt.h>
9#include <fdt_support.h>
wdenkc6097192002-11-03 00:24:07 +000010#include <asm/processor.h>
Matthias Fuchs6f35c532007-06-24 17:41:21 +020011#include <asm/io.h>
wdenkc6097192002-11-03 00:24:07 +000012#include <command.h>
wdenkc6097192002-11-03 00:24:07 +000013#include <malloc.h>
stroese87663b12004-12-16 18:27:05 +000014#include <net.h>
Matthias Fuchs6f35c532007-06-24 17:41:21 +020015#include <pci.h>
wdenkc6097192002-11-03 00:24:07 +000016
Wolfgang Denkd87080b2006-03-31 18:32:53 +020017DECLARE_GLOBAL_DATA_PTR;
18
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010019extern void __ft_board_setup(void *blob, bd_t *bd);
20
21#undef FPGA_DEBUG
wdenkc6097192002-11-03 00:24:07 +000022
23/* fpga configuration data - generated by bin2cc */
24const unsigned char fpgadata[] =
25{
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010026#if defined(CONFIG_CPCI405_VER2)
Matthias Fuchs7eaeb082015-01-12 22:47:31 +010027# include "fpgadata_cpci4052.c"
wdenkc6097192002-11-03 00:24:07 +000028#endif
29};
30
31/*
32 * include common fpga code (for esd boards)
33 */
34#include "../common/fpga.c"
stroese87663b12004-12-16 18:27:05 +000035
wdenkc6097192002-11-03 00:24:07 +000036/* Prototypes */
stroese6f4474e2003-03-20 15:31:19 +000037int cpci405_version(void);
stroese87663b12004-12-16 18:27:05 +000038void lxt971_no_sleep(void);
wdenkc6097192002-11-03 00:24:07 +000039
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010040int board_early_init_f(void)
wdenkc6097192002-11-03 00:24:07 +000041{
42#ifndef CONFIG_CPCI405_VER2
43 int index, len, i;
44 int status;
45#endif
46
47#ifdef FPGA_DEBUG
wdenkc6097192002-11-03 00:24:07 +000048 /* set up serial port with default baudrate */
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010049 (void)get_clocks();
wdenkc6097192002-11-03 00:24:07 +000050 gd->baudrate = CONFIG_BAUDRATE;
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010051 serial_init();
wdenkc6097192002-11-03 00:24:07 +000052 console_init_f();
53#endif
54
55 /*
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010056 * First pull fpga-prg pin low,
57 * to disable fpga logic (on version 2 board)
wdenkc6097192002-11-03 00:24:07 +000058 */
Matthias Fuchs049216f2009-02-20 10:19:18 +010059 out_be32((void *)GPIO0_ODR, 0x00000000); /* no open drain pins */
60 out_be32((void *)GPIO0_TCR, CONFIG_SYS_FPGA_PRG); /* setup for output */
61 out_be32((void *)GPIO0_OR, CONFIG_SYS_FPGA_PRG); /* set output pins to high */
62 out_be32((void *)GPIO0_OR, 0); /* pull prg low */
wdenkc6097192002-11-03 00:24:07 +000063
64 /*
65 * Boot onboard FPGA
66 */
67#ifndef CONFIG_CPCI405_VER2
stroese6f4474e2003-03-20 15:31:19 +000068 if (cpci405_version() == 1) {
wdenkc6097192002-11-03 00:24:07 +000069 status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata));
70 if (status != 0) {
71 /* booting FPGA failed */
72#ifndef FPGA_DEBUG
wdenkc6097192002-11-03 00:24:07 +000073 /* set up serial port with default baudrate */
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010074 (void)get_clocks();
wdenkc6097192002-11-03 00:24:07 +000075 gd->baudrate = CONFIG_BAUDRATE;
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010076 serial_init();
wdenkc6097192002-11-03 00:24:07 +000077 console_init_f();
78#endif
79 printf("\nFPGA: Booting failed ");
80 switch (status) {
81 case ERROR_FPGA_PRG_INIT_LOW:
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010082 printf("(Timeout: INIT not low after "
83 "asserting PROGRAM*)\n ");
wdenkc6097192002-11-03 00:24:07 +000084 break;
85 case ERROR_FPGA_PRG_INIT_HIGH:
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010086 printf("(Timeout: INIT not high after "
87 "deasserting PROGRAM*)\n ");
wdenkc6097192002-11-03 00:24:07 +000088 break;
89 case ERROR_FPGA_PRG_DONE:
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010090 printf("(Timeout: DONE not high after "
91 "programming FPGA)\n ");
wdenkc6097192002-11-03 00:24:07 +000092 break;
93 }
94
95 /* display infos on fpgaimage */
96 index = 15;
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010097 for (i = 0; i < 4; i++) {
wdenkc6097192002-11-03 00:24:07 +000098 len = fpgadata[index];
Matthias Fuchsf6a1f492009-01-02 12:17:36 +010099 printf("FPGA: %s\n", &(fpgadata[index + 1]));
100 index += len + 3;
wdenkc6097192002-11-03 00:24:07 +0000101 }
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100102 putc('\n');
wdenkc6097192002-11-03 00:24:07 +0000103 /* delayed reboot */
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100104 for (i = 20; i > 0; i--) {
wdenkc6097192002-11-03 00:24:07 +0000105 printf("Rebooting in %2d seconds \r",i);
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100106 for (index = 0; index < 1000; index++)
wdenkc6097192002-11-03 00:24:07 +0000107 udelay(1000);
108 }
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100109 putc('\n');
wdenkc6097192002-11-03 00:24:07 +0000110 do_reset(NULL, 0, 0, NULL);
111 }
112 }
113#endif /* !CONFIG_CPCI405_VER2 */
114
115 /*
116 * IRQ 0-15 405GP internally generated; active high; level sensitive
117 * IRQ 16 405GP internally generated; active low; level sensitive
118 * IRQ 17-24 RESERVED
119 * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100120 * IRQ 26 (EXT IRQ 1) CAN1 (+FPGA on CPCI4052); active low; level sens.
wdenkc6097192002-11-03 00:24:07 +0000121 * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive
122 * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive
123 * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive
124 * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive
125 * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive
126 */
Stefan Roese952e7762009-09-24 09:55:50 +0200127 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
128 mtdcr(UIC0ER, 0x00000000); /* disable all ints */
129 mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100130#if defined(CONFIG_CPCI405_6U)
stroese6f4474e2003-03-20 15:31:19 +0000131 if (cpci405_version() == 3) {
Stefan Roese952e7762009-09-24 09:55:50 +0200132 mtdcr(UIC0PR, 0xFFFFFF99); /* set int polarities */
stroese6f4474e2003-03-20 15:31:19 +0000133 } else {
Stefan Roese952e7762009-09-24 09:55:50 +0200134 mtdcr(UIC0PR, 0xFFFFFF81); /* set int polarities */
stroese6f4474e2003-03-20 15:31:19 +0000135 }
Matthias Fuchs6f35c532007-06-24 17:41:21 +0200136#else
Stefan Roese952e7762009-09-24 09:55:50 +0200137 mtdcr(UIC0PR, 0xFFFFFF81); /* set int polarities */
Matthias Fuchs6f35c532007-06-24 17:41:21 +0200138#endif
Stefan Roese952e7762009-09-24 09:55:50 +0200139 mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */
140 mtdcr(UIC0VCR, 0x00000001); /* set vect base=0,
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100141 * INT0 highest priority */
Stefan Roese952e7762009-09-24 09:55:50 +0200142 mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */
wdenkc6097192002-11-03 00:24:07 +0000143
144 return 0;
145}
146
wdenkc6097192002-11-03 00:24:07 +0000147int ctermm2(void)
148{
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100149#if defined(CONFIG_CPCI405_VER2)
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200150 return 0; /* no, board is cpci405 */
wdenkc6097192002-11-03 00:24:07 +0000151#else
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100152 if ((in_8((void*)0xf0000400) == 0x00) &&
153 (in_8((void*)0xf0000401) == 0x01))
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200154 return 0; /* no, board is cpci405 */
wdenkc6097192002-11-03 00:24:07 +0000155 else
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200156 return -1; /* yes, board is cterm-m2 */
wdenkc6097192002-11-03 00:24:07 +0000157#endif
158}
159
wdenkc6097192002-11-03 00:24:07 +0000160int cpci405_host(void)
161{
Stefan Roesed1c3b272009-09-09 16:25:29 +0200162 if (mfdcr(CPC0_PSR) & PSR_PCI_ARBIT_EN)
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200163 return -1; /* yes, board is cpci405 host */
wdenkc6097192002-11-03 00:24:07 +0000164 else
Wolfgang Denk4ef218f2007-07-10 00:01:28 +0200165 return 0; /* no, board is cpci405 adapter */
wdenkc6097192002-11-03 00:24:07 +0000166}
167
stroese6f4474e2003-03-20 15:31:19 +0000168int cpci405_version(void)
wdenkc6097192002-11-03 00:24:07 +0000169{
Stefan Roesed1c3b272009-09-09 16:25:29 +0200170 unsigned long CPC0_CR0Reg;
wdenkc6097192002-11-03 00:24:07 +0000171 unsigned long value;
172
173 /*
stroese6f4474e2003-03-20 15:31:19 +0000174 * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO)
wdenkc6097192002-11-03 00:24:07 +0000175 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200176 CPC0_CR0Reg = mfdcr(CPC0_CR0);
177 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x03000000);
Matthias Fuchs6f35c532007-06-24 17:41:21 +0200178 out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x00180000);
179 out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x00180000);
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100180 udelay(1000); /* wait some time before reading input */
181 value = in_be32((void*)GPIO0_IR) & 0x00180000; /* get config bits */
wdenkc6097192002-11-03 00:24:07 +0000182
183 /*
stroese6f4474e2003-03-20 15:31:19 +0000184 * Restore GPIO settings
wdenkc6097192002-11-03 00:24:07 +0000185 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200186 mtdcr(CPC0_CR0, CPC0_CR0Reg);
wdenkc6097192002-11-03 00:24:07 +0000187
stroese6f4474e2003-03-20 15:31:19 +0000188 switch (value) {
189 case 0x00180000:
190 /* CS2==1 && CS3==1 -> version 1 */
191 return 1;
192 case 0x00080000:
193 /* CS2==0 && CS3==1 -> version 2 */
194 return 2;
195 case 0x00100000:
Matthias Fuchs6f35c532007-06-24 17:41:21 +0200196 /* CS2==1 && CS3==0 -> version 3 or 6U board */
stroese6f4474e2003-03-20 15:31:19 +0000197 return 3;
198 case 0x00000000:
199 /* CS2==0 && CS3==0 -> version 4 */
200 return 4;
201 default:
202 /* should not be reached! */
203 return 2;
204 }
wdenkc6097192002-11-03 00:24:07 +0000205}
206
wdenkc6097192002-11-03 00:24:07 +0000207int misc_init_r (void)
208{
Stefan Roesed1c3b272009-09-09 16:25:29 +0200209 unsigned long CPC0_CR0Reg;
wdenkc6097192002-11-03 00:24:07 +0000210
stroese87663b12004-12-16 18:27:05 +0000211 /* adjust flash start and offset */
212 gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
213 gd->bd->bi_flashoffset = 0;
214
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100215#if defined(CONFIG_CPCI405_VER2)
stroese87663b12004-12-16 18:27:05 +0000216 {
wdenkc6097192002-11-03 00:24:07 +0000217 unsigned char *dst;
218 ulong len = sizeof(fpgadata);
219 int status;
220 int index;
221 int i;
wdenkc6097192002-11-03 00:24:07 +0000222
223 /*
224 * On CPCI-405 version 2 the environment is saved in eeprom!
225 * FPGA can be gzip compressed (malloc) and booted this late.
226 */
stroese6f4474e2003-03-20 15:31:19 +0000227 if (cpci405_version() >= 2) {
wdenkc6097192002-11-03 00:24:07 +0000228 /*
229 * Setup GPIO pins (CS6+CS7 as GPIO)
230 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200231 CPC0_CR0Reg = mfdcr(CPC0_CR0);
232 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000);
wdenkc6097192002-11-03 00:24:07 +0000233
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200234 dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE);
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100235 if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE,
236 (uchar *)fpgadata, &len) != 0) {
237 printf("GUNZIP ERROR - must RESET board to recover\n");
238 do_reset(NULL, 0, 0, NULL);
wdenkc6097192002-11-03 00:24:07 +0000239 }
240
241 status = fpga_boot(dst, len);
242 if (status != 0) {
243 printf("\nFPGA: Booting failed ");
244 switch (status) {
245 case ERROR_FPGA_PRG_INIT_LOW:
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100246 printf("(Timeout: INIT not low after "
247 "asserting PROGRAM*)\n ");
wdenkc6097192002-11-03 00:24:07 +0000248 break;
249 case ERROR_FPGA_PRG_INIT_HIGH:
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100250 printf("(Timeout: INIT not high after "
251 "deasserting PROGRAM*)\n ");
wdenkc6097192002-11-03 00:24:07 +0000252 break;
253 case ERROR_FPGA_PRG_DONE:
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100254 printf("(Timeout: DONE not high after "
255 "programming FPGA)\n ");
wdenkc6097192002-11-03 00:24:07 +0000256 break;
257 }
258
259 /* display infos on fpgaimage */
260 index = 15;
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100261 for (i = 0; i < 4; i++) {
wdenkc6097192002-11-03 00:24:07 +0000262 len = dst[index];
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100263 printf("FPGA: %s\n", &(dst[index + 1]));
264 index += len + 3;
wdenkc6097192002-11-03 00:24:07 +0000265 }
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100266 putc('\n');
wdenkc6097192002-11-03 00:24:07 +0000267 /* delayed reboot */
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100268 for (i = 20; i > 0; i--) {
269 printf("Rebooting in %2d seconds \r", i);
270 for (index = 0; index < 1000; index++)
wdenkc6097192002-11-03 00:24:07 +0000271 udelay(1000);
272 }
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100273 putc('\n');
wdenkc6097192002-11-03 00:24:07 +0000274 do_reset(NULL, 0, 0, NULL);
275 }
276
277 /* restore gpio/cs settings */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200278 mtdcr(CPC0_CR0, CPC0_CR0Reg);
wdenkc6097192002-11-03 00:24:07 +0000279
280 puts("FPGA: ");
281
282 /* display infos on fpgaimage */
283 index = 15;
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100284 for (i = 0; i < 4; i++) {
wdenkc6097192002-11-03 00:24:07 +0000285 len = dst[index];
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100286 printf("%s ", &(dst[index + 1]));
287 index += len + 3;
wdenkc6097192002-11-03 00:24:07 +0000288 }
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100289 putc('\n');
wdenkc6097192002-11-03 00:24:07 +0000290
291 free(dst);
stroese6f4474e2003-03-20 15:31:19 +0000292
293 /*
294 * Reset FPGA via FPGA_DATA pin
295 */
296 SET_FPGA(FPGA_PRG | FPGA_CLK);
297 udelay(1000); /* wait 1ms */
298 SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA);
299 udelay(1000); /* wait 1ms */
300
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100301#if defined(CONFIG_CPCI405_6U)
302#error HIER GETH ES WEITER MIT IO ACCESSORS
stroese6f4474e2003-03-20 15:31:19 +0000303 if (cpci405_version() == 3) {
stroese6f4474e2003-03-20 15:31:19 +0000304 /*
305 * Enable outputs in fpga on version 3 board
306 */
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100307 out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR,
308 in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) |
309 CONFIG_SYS_FPGA_MODE_ENABLE_OUTPUT);
stroese6f4474e2003-03-20 15:31:19 +0000310
311 /*
312 * Set outputs to 0
313 */
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100314 out_8((void*)CONFIG_SYS_LED_ADDR, 0x00);
stroese6f4474e2003-03-20 15:31:19 +0000315
316 /*
317 * Reset external DUART
318 */
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100319 out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR,
320 in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) |
321 CONFIG_SYS_FPGA_MODE_DUART_RESET);
stroese6f4474e2003-03-20 15:31:19 +0000322 udelay(100);
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100323 out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR,
324 in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) &
325 ~CONFIG_SYS_FPGA_MODE_DUART_RESET);
stroese6f4474e2003-03-20 15:31:19 +0000326 }
Matthias Fuchs6f35c532007-06-24 17:41:21 +0200327#endif
wdenkc6097192002-11-03 00:24:07 +0000328 }
329 else {
stroese6f4474e2003-03-20 15:31:19 +0000330 puts("\n*** U-Boot Version does not match Board Version!\n");
331 puts("*** CPCI-405 Version 1.x detected!\n");
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100332 puts("*** Please use correct U-Boot version "
333 "(CPCI405 instead of CPCI4052)!\n\n");
wdenkc6097192002-11-03 00:24:07 +0000334 }
stroese87663b12004-12-16 18:27:05 +0000335 }
wdenkc6097192002-11-03 00:24:07 +0000336#else /* CONFIG_CPCI405_VER2 */
stroese6f4474e2003-03-20 15:31:19 +0000337 if (cpci405_version() >= 2) {
338 puts("\n*** U-Boot Version does not match Board Version!\n");
339 puts("*** CPCI-405 Board Version 2.x detected!\n");
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100340 puts("*** Please use correct U-Boot version "
341 "(CPCI4052 instead of CPCI405)!\n\n");
wdenkc6097192002-11-03 00:24:07 +0000342 }
wdenkc6097192002-11-03 00:24:07 +0000343#endif /* CONFIG_CPCI405_VER2 */
344
345 /*
stroeseafcc4a72003-04-04 16:52:57 +0000346 * Select cts (and not dsr) on uart1
347 */
Stefan Roesed1c3b272009-09-09 16:25:29 +0200348 CPC0_CR0Reg = mfdcr(CPC0_CR0);
349 mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00001000);
stroeseafcc4a72003-04-04 16:52:57 +0000350
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100351 return 0;
wdenkc6097192002-11-03 00:24:07 +0000352}
353
wdenkc6097192002-11-03 00:24:07 +0000354/*
355 * Check Board Identity:
356 */
357
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100358int checkboard(void)
wdenkc6097192002-11-03 00:24:07 +0000359{
360#ifndef CONFIG_CPCI405_VER2
361 int index;
362 int len;
363#endif
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200364 char str[64];
Wolfgang Denkcdb74972010-07-24 21:55:43 +0200365 int i = getenv_f("serial#", str, sizeof(str));
stroese6f4474e2003-03-20 15:31:19 +0000366 unsigned short ver;
wdenkc6097192002-11-03 00:24:07 +0000367
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100368 puts("Board: ");
wdenkc6097192002-11-03 00:24:07 +0000369
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100370 if (i == -1)
371 puts("### No HW ID - assuming CPCI405");
372 else
wdenkc6097192002-11-03 00:24:07 +0000373 puts(str);
wdenkc6097192002-11-03 00:24:07 +0000374
stroese6f4474e2003-03-20 15:31:19 +0000375 ver = cpci405_version();
376 printf(" (Ver %d.x, ", ver);
wdenkc6097192002-11-03 00:24:07 +0000377
wdenkc6097192002-11-03 00:24:07 +0000378 if (ctermm2()) {
Wolfgang Denk77ddac92005-10-13 16:45:02 +0200379 char str[4];
stroese1b554402003-09-12 08:44:46 +0000380
381 /*
382 * Read board-id and save in env-variable
383 */
384 sprintf(str, "%d", *(unsigned char *)0xf0000400);
385 setenv("boardid", str);
386 printf("CTERM-M2 - Id=%s)", str);
wdenkc6097192002-11-03 00:24:07 +0000387 } else {
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100388 if (cpci405_host())
389 puts("PCI Host Version)");
390 else
391 puts("PCI Adapter Version)");
wdenkc6097192002-11-03 00:24:07 +0000392 }
393
394#ifndef CONFIG_CPCI405_VER2
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100395 puts("\nFPGA: ");
wdenkc6097192002-11-03 00:24:07 +0000396
397 /* display infos on fpgaimage */
398 index = 15;
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100399 for (i = 0; i < 4; i++) {
wdenkc6097192002-11-03 00:24:07 +0000400 len = fpgadata[index];
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100401 printf("%s ", &(fpgadata[index + 1]));
402 index += len + 3;
wdenkc6097192002-11-03 00:24:07 +0000403 }
404#endif
405
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100406 putc('\n');
wdenkc6097192002-11-03 00:24:07 +0000407 return 0;
408}
409
Matthias Fuchs6f35c532007-06-24 17:41:21 +0200410void reset_phy(void)
wdenkc6097192002-11-03 00:24:07 +0000411{
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100412#if defined(CONFIG_LXT971_NO_SLEEP)
wdenkc6097192002-11-03 00:24:07 +0000413
Matthias Fuchs6f35c532007-06-24 17:41:21 +0200414 /*
415 * Disable sleep mode in LXT971
416 */
417 lxt971_no_sleep();
418#endif
wdenkc6097192002-11-03 00:24:07 +0000419}
420
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100421#if defined(CONFIG_CPCI405_VER2) && defined (CONFIG_IDE_RESET)
wdenkc6097192002-11-03 00:24:07 +0000422void ide_set_reset(int on)
423{
wdenkc6097192002-11-03 00:24:07 +0000424 /*
425 * Assert or deassert CompactFlash Reset Pin
426 */
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100427 if (on) { /* assert RESET */
428 out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR,
429 in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) &
430 ~CONFIG_SYS_FPGA_MODE_CF_RESET);
431 } else { /* release RESET */
432 out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR,
433 in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) |
434 CONFIG_SYS_FPGA_MODE_CF_RESET);
wdenkc6097192002-11-03 00:24:07 +0000435 }
436}
437
Matthias Fuchsf6a1f492009-01-02 12:17:36 +0100438#endif /* CONFIG_IDE_RESET && CONFIG_CPCI405_VER2 */
wdenkc6097192002-11-03 00:24:07 +0000439
Stefan Roese466fff12007-06-25 15:57:39 +0200440#if defined(CONFIG_PCI)
Matthias Fuchs6f35c532007-06-24 17:41:21 +0200441void cpci405_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev)
442{
443 unsigned char int_line = 0xff;
444
445 /*
446 * Write pci interrupt line register (cpci405 specific)
447 */
448 switch (PCI_DEV(dev) & 0x03) {
449 case 0:
450 int_line = 27 + 2;
451 break;
452 case 1:
453 int_line = 27 + 3;
454 break;
455 case 2:
456 int_line = 27 + 0;
457 break;
458 case 3:
459 int_line = 27 + 1;
460 break;
461 }
462
463 pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line);
464}
465
466int pci_pre_init(struct pci_controller *hose)
467{
468 hose->fixup_irq = cpci405_pci_fixup_irq;
469 return 1;
470}
Stefan Roese466fff12007-06-25 15:57:39 +0200471#endif /* defined(CONFIG_PCI) */
Matthias Fuchs6f35c532007-06-24 17:41:21 +0200472
Matthias Fuchs600fe462009-01-02 12:18:12 +0100473#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Simon Glasse895a4b2014-10-23 18:58:47 -0600474int ft_board_setup(void *blob, bd_t *bd)
Matthias Fuchs600fe462009-01-02 12:18:12 +0100475{
476 int rc;
477
478 __ft_board_setup(blob, bd);
479
480 /*
481 * Disable PCI in adapter mode.
482 */
483 if (!cpci405_host()) {
484 rc = fdt_find_and_setprop(blob, "/plb/pci@ec000000", "status",
485 "disabled", sizeof("disabled"), 1);
486 if (rc) {
487 printf("Unable to update property status in PCI node, "
488 "err=%s\n",
489 fdt_strerror(rc));
490 }
491 }
Simon Glasse895a4b2014-10-23 18:58:47 -0600492
493 return 0;
Matthias Fuchs600fe462009-01-02 12:18:12 +0100494}
495#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */