wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000, 2001 |
| 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 | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include "du405.h" |
| 10 | #include <asm/processor.h> |
Stefan Roese | b36df56 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 11 | #include <asm/ppc4xx.h> |
| 12 | #include <asm/ppc4xx-i2c.h> |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 13 | #include <command.h> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 14 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
stroese | ab379df | 2004-12-16 18:36:28 +0000 | [diff] [blame] | 17 | extern void lxt971_no_sleep(void); |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 18 | |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 19 | |
| 20 | #if 0 |
| 21 | #define FPGA_DEBUG |
| 22 | #endif |
| 23 | |
| 24 | #if 0 |
| 25 | #define FPGA_DEBUG2 |
| 26 | #endif |
| 27 | |
| 28 | /* fpga configuration data - generated by bin2cc */ |
| 29 | const unsigned char fpgadata[] = { |
| 30 | #include "fpgadata.c" |
| 31 | }; |
| 32 | |
| 33 | /* |
| 34 | * include common fpga code (for esd boards) |
| 35 | */ |
| 36 | #include "../common/fpga.c" |
| 37 | |
| 38 | |
wdenk | c837dcb | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 39 | int board_early_init_f (void) |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 40 | { |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 41 | int index, len, i; |
| 42 | int status; |
| 43 | |
| 44 | #ifdef FPGA_DEBUG |
| 45 | /* set up serial port with default baudrate */ |
| 46 | (void) get_clocks (); |
| 47 | gd->baudrate = CONFIG_BAUDRATE; |
| 48 | serial_init (); |
| 49 | console_init_f (); |
| 50 | #endif |
| 51 | |
| 52 | /* |
| 53 | * Boot onboard FPGA |
| 54 | */ |
| 55 | status = fpga_boot ((unsigned char *) fpgadata, sizeof (fpgadata)); |
| 56 | if (status != 0) { |
| 57 | /* booting FPGA failed */ |
| 58 | #ifndef FPGA_DEBUG |
| 59 | /* set up serial port with default baudrate */ |
| 60 | (void) get_clocks (); |
| 61 | gd->baudrate = CONFIG_BAUDRATE; |
| 62 | serial_init (); |
| 63 | console_init_f (); |
| 64 | #endif |
| 65 | printf ("\nFPGA: Booting failed "); |
| 66 | switch (status) { |
| 67 | case ERROR_FPGA_PRG_INIT_LOW: |
| 68 | printf ("(Timeout: INIT not low after asserting PROGRAM*)\n "); |
| 69 | break; |
| 70 | case ERROR_FPGA_PRG_INIT_HIGH: |
| 71 | printf ("(Timeout: INIT not high after deasserting PROGRAM*)\n "); |
| 72 | break; |
| 73 | case ERROR_FPGA_PRG_DONE: |
| 74 | printf ("(Timeout: DONE not high after programming FPGA)\n "); |
| 75 | break; |
| 76 | } |
| 77 | |
| 78 | /* display infos on fpgaimage */ |
| 79 | index = 15; |
| 80 | for (i = 0; i < 4; i++) { |
| 81 | len = fpgadata[index]; |
| 82 | printf ("FPGA: %s\n", &(fpgadata[index + 1])); |
| 83 | index += len + 3; |
| 84 | } |
| 85 | putc ('\n'); |
| 86 | /* delayed reboot */ |
| 87 | for (i = 20; i > 0; i--) { |
| 88 | printf ("Rebooting in %2d seconds \r", i); |
| 89 | for (index = 0; index < 1000; index++) |
| 90 | udelay (1000); |
| 91 | } |
| 92 | putc ('\n'); |
| 93 | do_reset (NULL, 0, 0, NULL); |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * IRQ 0-15 405GP internally generated; active high; level sensitive |
| 98 | * IRQ 16 405GP internally generated; active low; level sensitive |
| 99 | * IRQ 17-24 RESERVED |
| 100 | * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive |
| 101 | * IRQ 26 (EXT IRQ 1) DUART_A; active high; level sensitive |
| 102 | * IRQ 27 (EXT IRQ 2) DUART_B; active high; level sensitive |
| 103 | * IRQ 28 (EXT IRQ 3) unused; active low; level sensitive |
| 104 | * IRQ 29 (EXT IRQ 4) unused; active low; level sensitive |
| 105 | * IRQ 30 (EXT IRQ 5) unused; active low; level sensitive |
| 106 | * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive |
| 107 | */ |
Stefan Roese | 952e776 | 2009-09-24 09:55:50 +0200 | [diff] [blame] | 108 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
| 109 | mtdcr (UIC0ER, 0x00000000); /* disable all ints */ |
| 110 | mtdcr (UIC0CR, 0x00000000); /* set all to be non-critical */ |
| 111 | mtdcr (UIC0PR, 0xFFFFFFB1); /* set int polarities */ |
| 112 | mtdcr (UIC0TR, 0x10000000); /* set int trigger levels */ |
| 113 | mtdcr (UIC0VCR, 0x00000001); /* set vect base=0,INT0 highest priority */ |
| 114 | mtdcr (UIC0SR, 0xFFFFFFFF); /* clear all ints */ |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 115 | |
| 116 | /* |
| 117 | * EBC Configuration Register: set ready timeout to 100 us |
| 118 | */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 119 | mtebc (EBC0_CFG, 0xb8400000); |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | |
Stefan Roese | 82f4c6a | 2005-08-12 16:52:47 +0200 | [diff] [blame] | 125 | int misc_init_r (void) |
| 126 | { |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 127 | unsigned long CPC0_CR0Reg; |
Stefan Roese | 82f4c6a | 2005-08-12 16:52:47 +0200 | [diff] [blame] | 128 | |
| 129 | /* |
| 130 | * Setup UART1 handshaking: use CTS instead of DSR |
| 131 | */ |
Stefan Roese | d1c3b27 | 2009-09-09 16:25:29 +0200 | [diff] [blame] | 132 | CPC0_CR0Reg = mfdcr(CPC0_CR0); |
| 133 | mtdcr(CPC0_CR0, CPC0_CR0Reg | 0x00001000); |
Stefan Roese | 82f4c6a | 2005-08-12 16:52:47 +0200 | [diff] [blame] | 134 | |
| 135 | return (0); |
| 136 | } |
| 137 | |
| 138 | |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 139 | /* |
| 140 | * Check Board Identity: |
| 141 | */ |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 142 | int checkboard (void) |
| 143 | { |
| 144 | int index; |
| 145 | int len; |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 146 | char str[64]; |
Wolfgang Denk | cdb7497 | 2010-07-24 21:55:43 +0200 | [diff] [blame] | 147 | int i = getenv_f("serial#", str, sizeof (str)); |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 148 | |
| 149 | puts ("Board: "); |
| 150 | |
| 151 | if (i == -1) { |
| 152 | puts ("### No HW ID - assuming DU405"); |
| 153 | } else { |
| 154 | puts (str); |
| 155 | } |
| 156 | |
| 157 | puts ("\nFPGA: "); |
| 158 | |
| 159 | /* display infos on fpgaimage */ |
| 160 | index = 15; |
| 161 | for (i = 0; i < 4; i++) { |
| 162 | len = fpgadata[index]; |
| 163 | printf ("%s ", &(fpgadata[index + 1])); |
| 164 | index += len + 3; |
| 165 | } |
| 166 | |
| 167 | putc ('\n'); |
| 168 | |
| 169 | /* |
| 170 | * Reset external DUART via FPGA |
| 171 | */ |
Matthias Fuchs | bb57ad4 | 2009-02-20 10:19:19 +0100 | [diff] [blame] | 172 | out_8((void *)FPGA_MODE_REG, 0xff); /* reset high active */ |
| 173 | out_8((void *)FPGA_MODE_REG, 0x00); /* low again */ |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 174 | |
Matthias Fuchs | 09db8f4 | 2009-02-20 10:19:15 +0100 | [diff] [blame] | 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | void reset_phy(void) |
| 179 | { |
| 180 | #if defined(CONFIG_LXT971_NO_SLEEP) |
| 181 | |
stroese | ab379df | 2004-12-16 18:36:28 +0000 | [diff] [blame] | 182 | /* |
| 183 | * Disable sleep mode in LXT971 |
| 184 | */ |
| 185 | lxt971_no_sleep(); |
Matthias Fuchs | 09db8f4 | 2009-02-20 10:19:15 +0100 | [diff] [blame] | 186 | #endif |
wdenk | 153d511 | 2002-08-30 11:07:04 +0000 | [diff] [blame] | 187 | } |