wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * Matthias Fuchs, esd gmbh germany, matthias.fuchs@esd-electronics.com |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include "canbt.h" |
| 26 | #include <asm/processor.h> |
Matthias Fuchs | 049216f | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 27 | #include <asm/io.h> |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 28 | #include <command.h> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 29 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 30 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 31 | |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 32 | /* ------------------------------------------------------------------------- */ |
| 33 | |
| 34 | #if 0 |
| 35 | #define FPGA_DEBUG |
| 36 | #endif |
| 37 | |
| 38 | /* fpga configuration data */ |
| 39 | const unsigned char fpgadata[] = { |
| 40 | #include "fpgadata.c" |
| 41 | }; |
| 42 | |
| 43 | /* |
| 44 | * include common fpga code (for esd boards) |
| 45 | */ |
| 46 | #include "../common/fpga.c" |
| 47 | |
| 48 | |
wdenk | c837dcb | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 49 | int board_early_init_f (void) |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 50 | { |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 51 | unsigned long CPC0_CR0Reg; |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 52 | int index, len, i; |
| 53 | int status; |
| 54 | |
| 55 | /* |
| 56 | * Setup GPIO pins |
| 57 | */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 58 | CPC0_CR0Reg = mfdcr (CPC0_CR0) & 0xf0001fff; |
| 59 | CPC0_CR0Reg |= 0x0070f000; |
| 60 | mtdcr (CPC0_CR0, CPC0_CR0Reg); |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 61 | |
| 62 | #ifdef FPGA_DEBUG |
| 63 | /* set up serial port with default baudrate */ |
| 64 | (void) get_clocks (); |
| 65 | gd->baudrate = CONFIG_BAUDRATE; |
| 66 | serial_init (); |
| 67 | console_init_f (); |
| 68 | #endif |
| 69 | |
| 70 | /* |
| 71 | * Boot onboard FPGA |
| 72 | */ |
| 73 | status = fpga_boot ((unsigned char *) fpgadata, sizeof (fpgadata)); |
| 74 | if (status != 0) { |
| 75 | /* booting FPGA failed */ |
| 76 | #ifndef FPGA_DEBUG |
| 77 | /* set up serial port with default baudrate */ |
| 78 | (void) get_clocks (); |
| 79 | gd->baudrate = CONFIG_BAUDRATE; |
| 80 | serial_init (); |
| 81 | console_init_f (); |
| 82 | #endif |
| 83 | printf ("\nFPGA: Booting failed "); |
| 84 | switch (status) { |
| 85 | case ERROR_FPGA_PRG_INIT_LOW: |
| 86 | printf ("(Timeout: INIT not low after asserting PROGRAM*)\n "); |
| 87 | break; |
| 88 | case ERROR_FPGA_PRG_INIT_HIGH: |
| 89 | printf ("(Timeout: INIT not high after deasserting PROGRAM*)\n "); |
| 90 | break; |
| 91 | case ERROR_FPGA_PRG_DONE: |
| 92 | printf ("(Timeout: DONE not high after programming FPGA)\n "); |
| 93 | break; |
| 94 | } |
| 95 | |
| 96 | /* display infos on fpgaimage */ |
| 97 | index = 15; |
| 98 | for (i = 0; i < 4; i++) { |
| 99 | len = fpgadata[index]; |
| 100 | printf ("FPGA: %s\n", &(fpgadata[index + 1])); |
| 101 | index += len + 3; |
| 102 | } |
| 103 | putc ('\n'); |
| 104 | /* delayed reboot */ |
| 105 | for (i = 20; i > 0; i--) { |
| 106 | printf ("Rebooting in %2d seconds \r", i); |
| 107 | for (index = 0; index < 1000; index++) |
| 108 | udelay (1000); |
| 109 | } |
| 110 | putc ('\n'); |
| 111 | do_reset (NULL, 0, 0, NULL); |
| 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Setup port pins for normal operation |
| 116 | */ |
Matthias Fuchs | 049216f | 2009-02-20 10:19:18 +0100 | [diff] [blame] | 117 | out_be32 ((void *)GPIO0_ODR, 0x00000000); /* no open drain pins */ |
| 118 | out_be32 ((void *)GPIO0_TCR, 0x07038100); /* setup for output */ |
| 119 | out_be32 ((void *)GPIO0_OR, 0x07030100); /* set output pins to high (default) */ |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * IRQ 0-15 405GP internally generated; active high; level sensitive |
| 123 | * IRQ 16 405GP internally generated; active low; level sensitive |
| 124 | * IRQ 17-24 RESERVED |
| 125 | * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive |
| 126 | * IRQ 26 (EXT IRQ 1) CAN1; active low; level sensitive |
| 127 | * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive |
| 128 | * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive |
| 129 | * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive |
| 130 | * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive |
| 131 | * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive |
| 132 | */ |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 133 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 134 | mtdcr (UIC0ER, 0x00000000); /* disable all ints */ |
| 135 | mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical */ |
| 136 | mtdcr (UIC0PR, 0xFFFFFF81); /* set int polarities */ |
| 137 | mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */ |
| 138 | mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority */ |
| 139 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | /* ------------------------------------------------------------------------- */ |
| 146 | |
| 147 | /* |
| 148 | * Check Board Identity: |
| 149 | */ |
| 150 | |
| 151 | int checkboard (void) |
| 152 | { |
| 153 | int index; |
| 154 | int len; |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 155 | char str[64]; |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 156 | int i = getenv_f("serial#", str, sizeof (str)); |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 157 | |
| 158 | puts ("Board: "); |
| 159 | |
| 160 | if (!i || strncmp (str, "CANBT", 5)) { |
| 161 | puts ("### No HW ID - assuming CANBT\n"); |
| 162 | return (0); |
| 163 | } |
| 164 | |
| 165 | puts (str); |
| 166 | |
| 167 | puts ("\nFPGA: "); |
| 168 | |
| 169 | /* display infos on fpgaimage */ |
| 170 | index = 15; |
| 171 | for (i = 0; i < 4; i++) { |
| 172 | len = fpgadata[index]; |
| 173 | printf ("%s ", &(fpgadata[index + 1])); |
| 174 | index += len + 3; |
| 175 | } |
| 176 | |
| 177 | putc ('\n'); |
| 178 | |
| 179 | return 0; |
| 180 | } |