wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
stroese | 6f4474e | 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 | 1a45966 | 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> |
Matthias Fuchs | 600fe46 | 2009-01-02 12:18:12 +0100 | [diff] [blame] | 8 | #include <libfdt.h> |
| 9 | #include <fdt_support.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 10 | #include <asm/processor.h> |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 11 | #include <asm/io.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 12 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 13 | #include <malloc.h> |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 14 | #include <net.h> |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 15 | #include <pci.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 16 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 19 | extern void __ft_board_setup(void *blob, bd_t *bd); |
| 20 | |
| 21 | #undef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 22 | |
| 23 | /* fpga configuration data - generated by bin2cc */ |
| 24 | const unsigned char fpgadata[] = |
| 25 | { |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 26 | #if defined(CONFIG_CPCI405_VER2) |
Matthias Fuchs | 7eaeb08 | 2015-01-12 22:47:31 +0100 | [diff] [blame] | 27 | # include "fpgadata_cpci4052.c" |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 28 | #endif |
| 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * include common fpga code (for esd boards) |
| 33 | */ |
| 34 | #include "../common/fpga.c" |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 35 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 36 | /* Prototypes */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 37 | int cpci405_version(void); |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 38 | void lxt971_no_sleep(void); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 39 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 40 | int board_early_init_f(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 41 | { |
| 42 | #ifndef CONFIG_CPCI405_VER2 |
| 43 | int index, len, i; |
| 44 | int status; |
| 45 | #endif |
| 46 | |
| 47 | #ifdef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 48 | /* set up serial port with default baudrate */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 49 | (void)get_clocks(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 50 | gd->baudrate = CONFIG_BAUDRATE; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 51 | serial_init(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 52 | console_init_f(); |
| 53 | #endif |
| 54 | |
| 55 | /* |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 56 | * First pull fpga-prg pin low, |
| 57 | * to disable fpga logic (on version 2 board) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 58 | */ |
Matthias Fuchs | 049216f | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 59 | 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 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * Boot onboard FPGA |
| 66 | */ |
| 67 | #ifndef CONFIG_CPCI405_VER2 |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 68 | if (cpci405_version() == 1) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 69 | status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata)); |
| 70 | if (status != 0) { |
| 71 | /* booting FPGA failed */ |
| 72 | #ifndef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 73 | /* set up serial port with default baudrate */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 74 | (void)get_clocks(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 75 | gd->baudrate = CONFIG_BAUDRATE; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 76 | serial_init(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 77 | console_init_f(); |
| 78 | #endif |
| 79 | printf("\nFPGA: Booting failed "); |
| 80 | switch (status) { |
| 81 | case ERROR_FPGA_PRG_INIT_LOW: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 82 | printf("(Timeout: INIT not low after " |
| 83 | "asserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 84 | break; |
| 85 | case ERROR_FPGA_PRG_INIT_HIGH: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 86 | printf("(Timeout: INIT not high after " |
| 87 | "deasserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 88 | break; |
| 89 | case ERROR_FPGA_PRG_DONE: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 90 | printf("(Timeout: DONE not high after " |
| 91 | "programming FPGA)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 92 | break; |
| 93 | } |
| 94 | |
| 95 | /* display infos on fpgaimage */ |
| 96 | index = 15; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 97 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 98 | len = fpgadata[index]; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 99 | printf("FPGA: %s\n", &(fpgadata[index + 1])); |
| 100 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | } |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 102 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | /* delayed reboot */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 104 | for (i = 20; i > 0; i--) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 105 | printf("Rebooting in %2d seconds \r",i); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 106 | for (index = 0; index < 1000; index++) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 107 | udelay(1000); |
| 108 | } |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 109 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 110 | 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 Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 120 | * IRQ 26 (EXT IRQ 1) CAN1 (+FPGA on CPCI4052); active low; level sens. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 121 | * 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 Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 127 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 128 | mtdcr(UIC0ER, 0x00000000); /* disable all ints */ |
| 129 | mtdcr(UIC0CR, 0x00000000); /* set all to be non-critical*/ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 130 | #if defined(CONFIG_CPCI405_6U) |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 131 | if (cpci405_version() == 3) { |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 132 | mtdcr(UIC0PR, 0xFFFFFF99); /* set int polarities */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 133 | } else { |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 134 | mtdcr(UIC0PR, 0xFFFFFF81); /* set int polarities */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 135 | } |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 136 | #else |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 137 | mtdcr(UIC0PR, 0xFFFFFF81); /* set int polarities */ |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 138 | #endif |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 139 | mtdcr(UIC0TR, 0x10000000); /* set int trigger levels */ |
| 140 | mtdcr(UIC0VCR, 0x00000001); /* set vect base=0, |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 141 | * INT0 highest priority */ |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 142 | mtdcr(UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 143 | |
| 144 | return 0; |
| 145 | } |
| 146 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 147 | int ctermm2(void) |
| 148 | { |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 149 | #if defined(CONFIG_CPCI405_VER2) |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 150 | return 0; /* no, board is cpci405 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 151 | #else |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 152 | if ((in_8((void*)0xf0000400) == 0x00) && |
| 153 | (in_8((void*)0xf0000401) == 0x01)) |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 154 | return 0; /* no, board is cpci405 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 155 | else |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 156 | return -1; /* yes, board is cterm-m2 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 157 | #endif |
| 158 | } |
| 159 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 160 | int cpci405_host(void) |
| 161 | { |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 162 | if (mfdcr(CPC0_PSR) & PSR_PCI_ARBIT_EN) |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 163 | return -1; /* yes, board is cpci405 host */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 164 | else |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 165 | return 0; /* no, board is cpci405 adapter */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 166 | } |
| 167 | |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 168 | int cpci405_version(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 169 | { |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 170 | unsigned long CPC0_CR0Reg; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 171 | unsigned long value; |
| 172 | |
| 173 | /* |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 174 | * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 175 | */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 176 | CPC0_CR0Reg = mfdcr(CPC0_CR0); |
| 177 | mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x03000000); |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 178 | out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x00180000); |
| 179 | out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x00180000); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 180 | udelay(1000); /* wait some time before reading input */ |
| 181 | value = in_be32((void*)GPIO0_IR) & 0x00180000; /* get config bits */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 182 | |
| 183 | /* |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 184 | * Restore GPIO settings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 185 | */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 186 | mtdcr(CPC0_CR0, CPC0_CR0Reg); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 187 | |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 188 | 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 Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 196 | /* CS2==1 && CS3==0 -> version 3 or 6U board */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 197 | 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 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 205 | } |
| 206 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 207 | int misc_init_r (void) |
| 208 | { |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 209 | unsigned long CPC0_CR0Reg; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 210 | |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 211 | /* adjust flash start and offset */ |
| 212 | gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize; |
| 213 | gd->bd->bi_flashoffset = 0; |
| 214 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 215 | #if defined(CONFIG_CPCI405_VER2) |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 216 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 217 | unsigned char *dst; |
| 218 | ulong len = sizeof(fpgadata); |
| 219 | int status; |
| 220 | int index; |
| 221 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 222 | |
| 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 | */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 227 | if (cpci405_version() >= 2) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 228 | /* |
| 229 | * Setup GPIO pins (CS6+CS7 as GPIO) |
| 230 | */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 231 | CPC0_CR0Reg = mfdcr(CPC0_CR0); |
| 232 | mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00300000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 233 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 234 | dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 235 | 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); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 239 | } |
| 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 Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 246 | printf("(Timeout: INIT not low after " |
| 247 | "asserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 248 | break; |
| 249 | case ERROR_FPGA_PRG_INIT_HIGH: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 250 | printf("(Timeout: INIT not high after " |
| 251 | "deasserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 252 | break; |
| 253 | case ERROR_FPGA_PRG_DONE: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 254 | printf("(Timeout: DONE not high after " |
| 255 | "programming FPGA)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 256 | break; |
| 257 | } |
| 258 | |
| 259 | /* display infos on fpgaimage */ |
| 260 | index = 15; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 261 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 262 | len = dst[index]; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 263 | printf("FPGA: %s\n", &(dst[index + 1])); |
| 264 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 265 | } |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 266 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 267 | /* delayed reboot */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 268 | for (i = 20; i > 0; i--) { |
| 269 | printf("Rebooting in %2d seconds \r", i); |
| 270 | for (index = 0; index < 1000; index++) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 271 | udelay(1000); |
| 272 | } |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 273 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 274 | do_reset(NULL, 0, 0, NULL); |
| 275 | } |
| 276 | |
| 277 | /* restore gpio/cs settings */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 278 | mtdcr(CPC0_CR0, CPC0_CR0Reg); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 279 | |
| 280 | puts("FPGA: "); |
| 281 | |
| 282 | /* display infos on fpgaimage */ |
| 283 | index = 15; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 284 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 285 | len = dst[index]; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 286 | printf("%s ", &(dst[index + 1])); |
| 287 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 288 | } |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 289 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 290 | |
| 291 | free(dst); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 292 | |
| 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 Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 301 | #if defined(CONFIG_CPCI405_6U) |
| 302 | #error HIER GETH ES WEITER MIT IO ACCESSORS |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 303 | if (cpci405_version() == 3) { |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 304 | /* |
| 305 | * Enable outputs in fpga on version 3 board |
| 306 | */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 307 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 308 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) | |
| 309 | CONFIG_SYS_FPGA_MODE_ENABLE_OUTPUT); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 310 | |
| 311 | /* |
| 312 | * Set outputs to 0 |
| 313 | */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 314 | out_8((void*)CONFIG_SYS_LED_ADDR, 0x00); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 315 | |
| 316 | /* |
| 317 | * Reset external DUART |
| 318 | */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 319 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 320 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) | |
| 321 | CONFIG_SYS_FPGA_MODE_DUART_RESET); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 322 | udelay(100); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 323 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 324 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) & |
| 325 | ~CONFIG_SYS_FPGA_MODE_DUART_RESET); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 326 | } |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 327 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 328 | } |
| 329 | else { |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 330 | puts("\n*** U-Boot Version does not match Board Version!\n"); |
| 331 | puts("*** CPCI-405 Version 1.x detected!\n"); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 332 | puts("*** Please use correct U-Boot version " |
| 333 | "(CPCI405 instead of CPCI4052)!\n\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 334 | } |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 335 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 336 | #else /* CONFIG_CPCI405_VER2 */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 337 | 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 Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 340 | puts("*** Please use correct U-Boot version " |
| 341 | "(CPCI4052 instead of CPCI405)!\n\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 342 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 343 | #endif /* CONFIG_CPCI405_VER2 */ |
| 344 | |
| 345 | /* |
stroese | afcc4a7 | 2003-04-04 16:52:57 +0000 | [diff] [blame] | 346 | * Select cts (and not dsr) on uart1 |
| 347 | */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 348 | CPC0_CR0Reg = mfdcr(CPC0_CR0); |
| 349 | mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00001000); |
stroese | afcc4a7 | 2003-04-04 16:52:57 +0000 | [diff] [blame] | 350 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 351 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 352 | } |
| 353 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 354 | /* |
| 355 | * Check Board Identity: |
| 356 | */ |
| 357 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 358 | int checkboard(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 359 | { |
| 360 | #ifndef CONFIG_CPCI405_VER2 |
| 361 | int index; |
| 362 | int len; |
| 363 | #endif |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 364 | char str[64]; |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 365 | int i = getenv_f("serial#", str, sizeof(str)); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 366 | unsigned short ver; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 367 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 368 | puts("Board: "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 369 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 370 | if (i == -1) |
| 371 | puts("### No HW ID - assuming CPCI405"); |
| 372 | else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 373 | puts(str); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 374 | |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 375 | ver = cpci405_version(); |
| 376 | printf(" (Ver %d.x, ", ver); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 377 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 378 | if (ctermm2()) { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 379 | char str[4]; |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 380 | |
| 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); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 387 | } else { |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 388 | if (cpci405_host()) |
| 389 | puts("PCI Host Version)"); |
| 390 | else |
| 391 | puts("PCI Adapter Version)"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | #ifndef CONFIG_CPCI405_VER2 |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 395 | puts("\nFPGA: "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 396 | |
| 397 | /* display infos on fpgaimage */ |
| 398 | index = 15; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 399 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 400 | len = fpgadata[index]; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 401 | printf("%s ", &(fpgadata[index + 1])); |
| 402 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 403 | } |
| 404 | #endif |
| 405 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 406 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 407 | return 0; |
| 408 | } |
| 409 | |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 410 | void reset_phy(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 411 | { |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 412 | #if defined(CONFIG_LXT971_NO_SLEEP) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 413 | |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 414 | /* |
| 415 | * Disable sleep mode in LXT971 |
| 416 | */ |
| 417 | lxt971_no_sleep(); |
| 418 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 419 | } |
| 420 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 421 | #if defined(CONFIG_CPCI405_VER2) && defined (CONFIG_IDE_RESET) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 422 | void ide_set_reset(int on) |
| 423 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 424 | /* |
| 425 | * Assert or deassert CompactFlash Reset Pin |
| 426 | */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 427 | 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); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame] | 438 | #endif /* CONFIG_IDE_RESET && CONFIG_CPCI405_VER2 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 439 | |
Stefan Roese | 466fff1 | 2007-06-25 15:57:39 +0200 | [diff] [blame] | 440 | #if defined(CONFIG_PCI) |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 441 | void 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 | |
| 466 | int pci_pre_init(struct pci_controller *hose) |
| 467 | { |
| 468 | hose->fixup_irq = cpci405_pci_fixup_irq; |
| 469 | return 1; |
| 470 | } |
Stefan Roese | 466fff1 | 2007-06-25 15:57:39 +0200 | [diff] [blame] | 471 | #endif /* defined(CONFIG_PCI) */ |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 472 | |
Matthias Fuchs | 600fe46 | 2009-01-02 12:18:12 +0100 | [diff] [blame] | 473 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Simon Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 474 | int ft_board_setup(void *blob, bd_t *bd) |
Matthias Fuchs | 600fe46 | 2009-01-02 12:18:12 +0100 | [diff] [blame] | 475 | { |
| 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 Glass | e895a4b | 2014-10-23 18:58:47 -0600 | [diff] [blame] | 492 | |
| 493 | return 0; |
Matthias Fuchs | 600fe46 | 2009-01-02 12:18:12 +0100 | [diff] [blame] | 494 | } |
| 495 | #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */ |