wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 2 | * (C) Copyright 2001-2003 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 3 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 4 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 6 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 7 | #include <common.h> |
Simon Glass | a73bda4 | 2015-11-08 23:47:45 -0700 | [diff] [blame] | 8 | #include <console.h> |
Matthias Fuchs | d51776a | 2009-01-02 12:18:12 +0100 | [diff] [blame] | 9 | #include <libfdt.h> |
| 10 | #include <fdt_support.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 11 | #include <asm/processor.h> |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 12 | #include <asm/io.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 13 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 14 | #include <malloc.h> |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 15 | #include <net.h> |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 16 | #include <pci.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 17 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 20 | extern void __ft_board_setup(void *blob, bd_t *bd); |
| 21 | |
| 22 | #undef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 23 | |
| 24 | /* fpga configuration data - generated by bin2cc */ |
| 25 | const unsigned char fpgadata[] = |
| 26 | { |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 27 | #if defined(CONFIG_CPCI405_VER2) |
Matthias Fuchs | 0021e4a | 2015-01-12 22:47:31 +0100 | [diff] [blame] | 28 | # include "fpgadata_cpci4052.c" |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 29 | #endif |
| 30 | }; |
| 31 | |
| 32 | /* |
| 33 | * include common fpga code (for esd boards) |
| 34 | */ |
| 35 | #include "../common/fpga.c" |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 36 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 37 | /* Prototypes */ |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 38 | int cpci405_version(void); |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 39 | void lxt971_no_sleep(void); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 40 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 41 | int board_early_init_f(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 42 | { |
| 43 | #ifndef CONFIG_CPCI405_VER2 |
| 44 | int index, len, i; |
| 45 | int status; |
| 46 | #endif |
| 47 | |
| 48 | #ifdef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 49 | /* set up serial port with default baudrate */ |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 50 | (void)get_clocks(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 51 | gd->baudrate = CONFIG_BAUDRATE; |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 52 | serial_init(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 53 | console_init_f(); |
| 54 | #endif |
| 55 | |
| 56 | /* |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 57 | * First pull fpga-prg pin low, |
| 58 | * to disable fpga logic (on version 2 board) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 59 | */ |
Matthias Fuchs | faac743 | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 60 | out_be32((void *)GPIO0_ODR, 0x00000000); /* no open drain pins */ |
| 61 | out_be32((void *)GPIO0_TCR, CONFIG_SYS_FPGA_PRG); /* setup for output */ |
| 62 | out_be32((void *)GPIO0_OR, CONFIG_SYS_FPGA_PRG); /* set output pins to high */ |
| 63 | out_be32((void *)GPIO0_OR, 0); /* pull prg low */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Boot onboard FPGA |
| 67 | */ |
| 68 | #ifndef CONFIG_CPCI405_VER2 |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 69 | if (cpci405_version() == 1) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 70 | status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata)); |
| 71 | if (status != 0) { |
| 72 | /* booting FPGA failed */ |
| 73 | #ifndef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 74 | /* set up serial port with default baudrate */ |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 75 | (void)get_clocks(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 76 | gd->baudrate = CONFIG_BAUDRATE; |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 77 | serial_init(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 78 | console_init_f(); |
| 79 | #endif |
| 80 | printf("\nFPGA: Booting failed "); |
| 81 | switch (status) { |
| 82 | case ERROR_FPGA_PRG_INIT_LOW: |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 83 | printf("(Timeout: INIT not low after " |
| 84 | "asserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 85 | break; |
| 86 | case ERROR_FPGA_PRG_INIT_HIGH: |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 87 | printf("(Timeout: INIT not high after " |
| 88 | "deasserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 89 | break; |
| 90 | case ERROR_FPGA_PRG_DONE: |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 91 | printf("(Timeout: DONE not high after " |
| 92 | "programming FPGA)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 93 | break; |
| 94 | } |
| 95 | |
| 96 | /* display infos on fpgaimage */ |
| 97 | index = 15; |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 98 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 99 | len = fpgadata[index]; |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 100 | printf("FPGA: %s\n", &(fpgadata[index + 1])); |
| 101 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 102 | } |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 103 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 104 | /* delayed reboot */ |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 105 | for (i = 20; i > 0; i--) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 106 | printf("Rebooting in %2d seconds \r",i); |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 107 | for (index = 0; index < 1000; index++) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 108 | udelay(1000); |
| 109 | } |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 110 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 111 | do_reset(NULL, 0, 0, NULL); |
| 112 | } |
| 113 | } |
| 114 | #endif /* !CONFIG_CPCI405_VER2 */ |
| 115 | |
| 116 | /* |
| 117 | * IRQ 0-15 405GP internally generated; active high; level sensitive |
| 118 | * IRQ 16 405GP internally generated; active low; level sensitive |
| 119 | * IRQ 17-24 RESERVED |
| 120 | * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 121 | * IRQ 26 (EXT IRQ 1) CAN1 (+FPGA on CPCI4052); active low; level sens. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 122 | * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive |
| 123 | * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive |
| 124 | * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive |
| 125 | * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive |
| 126 | * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive |
| 127 | */ |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 128 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 129 | mtdcr(UIC0ER, 0x00000000); /* disable all ints */ |
| 130 | mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/ |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 131 | #if defined(CONFIG_CPCI405_6U) |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 132 | if (cpci405_version() == 3) { |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 133 | mtdcr(UIC0PR, 0xFFFFFF99); /* set int polarities */ |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 134 | } else { |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 135 | mtdcr(UIC0PR, 0xFFFFFF81); /* set int polarities */ |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 136 | } |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 137 | #else |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 138 | mtdcr(UIC0PR, 0xFFFFFF81); /* set int polarities */ |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 139 | #endif |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 140 | mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */ |
| 141 | mtdcr(UIC0VCR, 0x00000001); /* set vect base=0, |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 142 | * INT0 highest priority */ |
Stefan Roese | 707fd36 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 143 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 144 | |
| 145 | return 0; |
| 146 | } |
| 147 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 148 | int ctermm2(void) |
| 149 | { |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 150 | #if defined(CONFIG_CPCI405_VER2) |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 151 | return 0; /* no, board is cpci405 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 152 | #else |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 153 | if ((in_8((void*)0xf0000400) == 0x00) && |
| 154 | (in_8((void*)0xf0000401) == 0x01)) |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 155 | return 0; /* no, board is cpci405 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 156 | else |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 157 | return -1; /* yes, board is cterm-m2 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 158 | #endif |
| 159 | } |
| 160 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 161 | int cpci405_host(void) |
| 162 | { |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 163 | if (mfdcr(CPC0_PSR) & PSR_PCI_ARBIT_EN) |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 164 | return -1; /* yes, board is cpci405 host */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 165 | else |
Wolfgang Denk | a0453aa | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 166 | return 0; /* no, board is cpci405 adapter */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 167 | } |
| 168 | |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 169 | int cpci405_version(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 170 | { |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 171 | unsigned long CPC0_CR0Reg; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 172 | unsigned long value; |
| 173 | |
| 174 | /* |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 175 | * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 176 | */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 177 | CPC0_CR0Reg = mfdcr(CPC0_CR0); |
| 178 | mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x03000000); |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 179 | out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x00180000); |
| 180 | out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x00180000); |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 181 | udelay(1000); /* wait some time before reading input */ |
| 182 | value = in_be32((void*)GPIO0_IR) & 0x00180000; /* get config bits */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 183 | |
| 184 | /* |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 185 | * Restore GPIO settings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 186 | */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 187 | mtdcr(CPC0_CR0, CPC0_CR0Reg); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 188 | |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 189 | switch (value) { |
| 190 | case 0x00180000: |
| 191 | /* CS2==1 && CS3==1 -> version 1 */ |
| 192 | return 1; |
| 193 | case 0x00080000: |
| 194 | /* CS2==0 && CS3==1 -> version 2 */ |
| 195 | return 2; |
| 196 | case 0x00100000: |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 197 | /* CS2==1 && CS3==0 -> version 3 or 6U board */ |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 198 | return 3; |
| 199 | case 0x00000000: |
| 200 | /* CS2==0 && CS3==0 -> version 4 */ |
| 201 | return 4; |
| 202 | default: |
| 203 | /* should not be reached! */ |
| 204 | return 2; |
| 205 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 206 | } |
| 207 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 208 | int misc_init_r (void) |
| 209 | { |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 210 | unsigned long CPC0_CR0Reg; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 211 | |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 212 | /* adjust flash start and offset */ |
| 213 | gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize; |
| 214 | gd->bd->bi_flashoffset = 0; |
| 215 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 216 | #if defined(CONFIG_CPCI405_VER2) |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 217 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 218 | unsigned char *dst; |
| 219 | ulong len = sizeof(fpgadata); |
| 220 | int status; |
| 221 | int index; |
| 222 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 223 | |
| 224 | /* |
| 225 | * On CPCI-405 version 2 the environment is saved in eeprom! |
| 226 | * FPGA can be gzip compressed (malloc) and booted this late. |
| 227 | */ |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 228 | if (cpci405_version() >= 2) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 229 | /* |
| 230 | * Setup GPIO pins (CS6+CS7 as GPIO) |
| 231 | */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 232 | CPC0_CR0Reg = mfdcr(CPC0_CR0); |
| 233 | mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 234 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 235 | dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE); |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 236 | if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE, |
| 237 | (uchar *)fpgadata, &len) != 0) { |
| 238 | printf("GUNZIP ERROR - must RESET board to recover\n"); |
| 239 | do_reset(NULL, 0, 0, NULL); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | status = fpga_boot(dst, len); |
| 243 | if (status != 0) { |
| 244 | printf("\nFPGA: Booting failed "); |
| 245 | switch (status) { |
| 246 | case ERROR_FPGA_PRG_INIT_LOW: |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 247 | printf("(Timeout: INIT not low after " |
| 248 | "asserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 249 | break; |
| 250 | case ERROR_FPGA_PRG_INIT_HIGH: |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 251 | printf("(Timeout: INIT not high after " |
| 252 | "deasserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 253 | break; |
| 254 | case ERROR_FPGA_PRG_DONE: |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 255 | printf("(Timeout: DONE not high after " |
| 256 | "programming FPGA)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 257 | break; |
| 258 | } |
| 259 | |
| 260 | /* display infos on fpgaimage */ |
| 261 | index = 15; |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 262 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 263 | len = dst[index]; |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 264 | printf("FPGA: %s\n", &(dst[index + 1])); |
| 265 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 266 | } |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 267 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 268 | /* delayed reboot */ |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 269 | for (i = 20; i > 0; i--) { |
| 270 | printf("Rebooting in %2d seconds \r", i); |
| 271 | for (index = 0; index < 1000; index++) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 272 | udelay(1000); |
| 273 | } |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 274 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 275 | do_reset(NULL, 0, 0, NULL); |
| 276 | } |
| 277 | |
| 278 | /* restore gpio/cs settings */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 279 | mtdcr(CPC0_CR0, CPC0_CR0Reg); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 280 | |
| 281 | puts("FPGA: "); |
| 282 | |
| 283 | /* display infos on fpgaimage */ |
| 284 | index = 15; |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 285 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 286 | len = dst[index]; |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 287 | printf("%s ", &(dst[index + 1])); |
| 288 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 289 | } |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 290 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 291 | |
| 292 | free(dst); |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 293 | |
| 294 | /* |
| 295 | * Reset FPGA via FPGA_DATA pin |
| 296 | */ |
| 297 | SET_FPGA(FPGA_PRG | FPGA_CLK); |
| 298 | udelay(1000); /* wait 1ms */ |
| 299 | SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); |
| 300 | udelay(1000); /* wait 1ms */ |
| 301 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 302 | #if defined(CONFIG_CPCI405_6U) |
| 303 | #error HIER GETH ES WEITER MIT IO ACCESSORS |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 304 | if (cpci405_version() == 3) { |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 305 | /* |
| 306 | * Enable outputs in fpga on version 3 board |
| 307 | */ |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 308 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 309 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) | |
| 310 | CONFIG_SYS_FPGA_MODE_ENABLE_OUTPUT); |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 311 | |
| 312 | /* |
| 313 | * Set outputs to 0 |
| 314 | */ |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 315 | out_8((void*)CONFIG_SYS_LED_ADDR, 0x00); |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 316 | |
| 317 | /* |
| 318 | * Reset external DUART |
| 319 | */ |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 320 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 321 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) | |
| 322 | CONFIG_SYS_FPGA_MODE_DUART_RESET); |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 323 | udelay(100); |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 324 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 325 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) & |
| 326 | ~CONFIG_SYS_FPGA_MODE_DUART_RESET); |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 327 | } |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 328 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 329 | } |
| 330 | else { |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 331 | puts("\n*** U-Boot Version does not match Board Version!\n"); |
| 332 | puts("*** CPCI-405 Version 1.x detected!\n"); |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 333 | puts("*** Please use correct U-Boot version " |
| 334 | "(CPCI405 instead of CPCI4052)!\n\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 335 | } |
stroese | 9b115e9 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 336 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 337 | #else /* CONFIG_CPCI405_VER2 */ |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 338 | if (cpci405_version() >= 2) { |
| 339 | puts("\n*** U-Boot Version does not match Board Version!\n"); |
| 340 | puts("*** CPCI-405 Board Version 2.x detected!\n"); |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 341 | puts("*** Please use correct U-Boot version " |
| 342 | "(CPCI4052 instead of CPCI405)!\n\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 343 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 344 | #endif /* CONFIG_CPCI405_VER2 */ |
| 345 | |
| 346 | /* |
stroese | 67cb27d | 2003-04-04 16:52:57 +0000 | [diff] [blame] | 347 | * Select cts (and not dsr) on uart1 |
| 348 | */ |
Stefan Roese | 918010a | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 349 | CPC0_CR0Reg = mfdcr(CPC0_CR0); |
| 350 | mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00001000); |
stroese | 67cb27d | 2003-04-04 16:52:57 +0000 | [diff] [blame] | 351 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 352 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 353 | } |
| 354 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 355 | /* |
| 356 | * Check Board Identity: |
| 357 | */ |
| 358 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 359 | int checkboard(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 360 | { |
| 361 | #ifndef CONFIG_CPCI405_VER2 |
| 362 | int index; |
| 363 | int len; |
| 364 | #endif |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 365 | char str[64]; |
Wolfgang Denk | 76af278 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 366 | int i = getenv_f("serial#", str, sizeof(str)); |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 367 | unsigned short ver; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 368 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 369 | puts("Board: "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 370 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 371 | if (i == -1) |
| 372 | puts("### No HW ID - assuming CPCI405"); |
| 373 | else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 374 | puts(str); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 375 | |
stroese | 768eb2d | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 376 | ver = cpci405_version(); |
| 377 | printf(" (Ver %d.x, ", ver); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 378 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 379 | if (ctermm2()) { |
Wolfgang Denk | 7fb5266 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 380 | char str[4]; |
stroese | c8065c9 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 381 | |
| 382 | /* |
| 383 | * Read board-id and save in env-variable |
| 384 | */ |
| 385 | sprintf(str, "%d", *(unsigned char *)0xf0000400); |
| 386 | setenv("boardid", str); |
| 387 | printf("CTERM-M2 - Id=%s)", str); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 388 | } else { |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 389 | if (cpci405_host()) |
| 390 | puts("PCI Host Version)"); |
| 391 | else |
| 392 | puts("PCI Adapter Version)"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | #ifndef CONFIG_CPCI405_VER2 |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 396 | puts("\nFPGA: "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 397 | |
| 398 | /* display infos on fpgaimage */ |
| 399 | index = 15; |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 400 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 401 | len = fpgadata[index]; |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 402 | printf("%s ", &(fpgadata[index + 1])); |
| 403 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 404 | } |
| 405 | #endif |
| 406 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 407 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 408 | return 0; |
| 409 | } |
| 410 | |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 411 | void reset_phy(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 412 | { |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 413 | #if defined(CONFIG_LXT971_NO_SLEEP) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 414 | |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 415 | /* |
| 416 | * Disable sleep mode in LXT971 |
| 417 | */ |
| 418 | lxt971_no_sleep(); |
| 419 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 420 | } |
| 421 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 422 | #if defined(CONFIG_CPCI405_VER2) && defined (CONFIG_IDE_RESET) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 423 | void ide_set_reset(int on) |
| 424 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 425 | /* |
| 426 | * Assert or deassert CompactFlash Reset Pin |
| 427 | */ |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 428 | if (on) { /* assert RESET */ |
| 429 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 430 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) & |
| 431 | ~CONFIG_SYS_FPGA_MODE_CF_RESET); |
| 432 | } else { /* release RESET */ |
| 433 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 434 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) | |
| 435 | CONFIG_SYS_FPGA_MODE_CF_RESET); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 436 | } |
| 437 | } |
| 438 | |
Matthias Fuchs | 59e94ba | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 439 | #endif /* CONFIG_IDE_RESET && CONFIG_CPCI405_VER2 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 440 | |
Stefan Roese | 54ef7fd | 2007-06-25 15:57:39 +0200 | [diff] [blame] | 441 | #if defined(CONFIG_PCI) |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 442 | void cpci405_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev) |
| 443 | { |
| 444 | unsigned char int_line = 0xff; |
| 445 | |
| 446 | /* |
| 447 | * Write pci interrupt line register (cpci405 specific) |
| 448 | */ |
| 449 | switch (PCI_DEV(dev) & 0x03) { |
| 450 | case 0: |
| 451 | int_line = 27 + 2; |
| 452 | break; |
| 453 | case 1: |
| 454 | int_line = 27 + 3; |
| 455 | break; |
| 456 | case 2: |
| 457 | int_line = 27 + 0; |
| 458 | break; |
| 459 | case 3: |
| 460 | int_line = 27 + 1; |
| 461 | break; |
| 462 | } |
| 463 | |
| 464 | pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line); |
| 465 | } |
| 466 | |
| 467 | int pci_pre_init(struct pci_controller *hose) |
| 468 | { |
| 469 | hose->fixup_irq = cpci405_pci_fixup_irq; |
| 470 | return 1; |
| 471 | } |
Stefan Roese | 54ef7fd | 2007-06-25 15:57:39 +0200 | [diff] [blame] | 472 | #endif /* defined(CONFIG_PCI) */ |
Matthias Fuchs | 196088b | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 473 | |
Robert P. J. Day | 3c75700 | 2016-05-19 15:23:12 -0400 | [diff] [blame] | 474 | #ifdef CONFIG_OF_BOARD_SETUP |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 475 | int ft_board_setup(void *blob, bd_t *bd) |
Matthias Fuchs | d51776a | 2009-01-02 12:18:12 +0100 | [diff] [blame] | 476 | { |
| 477 | int rc; |
| 478 | |
| 479 | __ft_board_setup(blob, bd); |
| 480 | |
| 481 | /* |
| 482 | * Disable PCI in adapter mode. |
| 483 | */ |
| 484 | if (!cpci405_host()) { |
| 485 | rc = fdt_find_and_setprop(blob, "/plb/pci@ec000000", "status", |
| 486 | "disabled", sizeof("disabled"), 1); |
| 487 | if (rc) { |
| 488 | printf("Unable to update property status in PCI node, " |
| 489 | "err=%s\n", |
| 490 | fdt_strerror(rc)); |
| 491 | } |
| 492 | } |
Simon Glass | 2aec3cc | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 493 | |
| 494 | return 0; |
Matthias Fuchs | d51776a | 2009-01-02 12:18:12 +0100 | [diff] [blame] | 495 | } |
Robert P. J. Day | 3c75700 | 2016-05-19 15:23:12 -0400 | [diff] [blame] | 496 | #endif /* CONFIG_OF_BOARD_SETUP */ |