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 | * |
| 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 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 23 | #include <common.h> |
| 24 | #include <asm/processor.h> |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 25 | #include <asm/io.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 26 | #include <command.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 27 | #include <malloc.h> |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 28 | #include <net.h> |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 29 | #include <pci.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 30 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 33 | extern int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]); |
| 34 | extern void __ft_board_setup(void *blob, bd_t *bd); |
| 35 | |
| 36 | #undef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 37 | |
| 38 | /* fpga configuration data - generated by bin2cc */ |
| 39 | const unsigned char fpgadata[] = |
| 40 | { |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 41 | #if defined(CONFIG_CPCI405_VER2) |
| 42 | # if defined(CONFIG_CPCI405AB) |
stroese | d4629c8 | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 43 | # include "fpgadata_cpci405ab.c" |
| 44 | # else |
| 45 | # include "fpgadata_cpci4052.c" |
| 46 | # endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 47 | #else |
| 48 | # include "fpgadata_cpci405.c" |
| 49 | #endif |
| 50 | }; |
| 51 | |
| 52 | /* |
| 53 | * include common fpga code (for esd boards) |
| 54 | */ |
| 55 | #include "../common/fpga.c" |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 56 | #include "../common/auto_update.h" |
| 57 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 58 | #if defined(CONFIG_CPCI405AB) |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 59 | au_image_t au_image[] = { |
| 60 | {"cpci405ab/preinst.img", 0, -1, AU_SCRIPT}, |
| 61 | {"cpci405ab/pImage", 0xffc00000, 0x000c0000, AU_NOR}, |
| 62 | {"cpci405ab/pImage.initrd", 0xffcc0000, 0x00300000, AU_NOR}, |
| 63 | {"cpci405ab/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE}, |
| 64 | {"cpci405ab/postinst.img", 0, 0, AU_SCRIPT}, |
| 65 | }; |
| 66 | #else |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 67 | #if defined(CONFIG_CPCI405_VER2) |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 68 | au_image_t au_image[] = { |
| 69 | {"cpci4052/preinst.img", 0, -1, AU_SCRIPT}, |
| 70 | {"cpci4052/pImage", 0xffc00000, 0x000c0000, AU_NOR}, |
| 71 | {"cpci4052/pImage.initrd", 0xffcc0000, 0x00300000, AU_NOR}, |
| 72 | {"cpci4052/u-boot.img", 0xfffc0000, 0x00040000, AU_FIRMWARE}, |
| 73 | {"cpci4052/postinst.img", 0, 0, AU_SCRIPT}, |
| 74 | }; |
| 75 | #else |
| 76 | au_image_t au_image[] = { |
| 77 | {"cpci405/preinst.img", 0, -1, AU_SCRIPT}, |
| 78 | {"cpci405/pImage", 0xffc00000, 0x000c0000, AU_NOR}, |
| 79 | {"cpci405/pImage.initrd", 0xffcc0000, 0x00310000, AU_NOR}, |
| 80 | {"cpci405/u-boot.img", 0xfffd0000, 0x00030000, AU_FIRMWARE}, |
| 81 | {"cpci405/postinst.img", 0, 0, AU_SCRIPT}, |
| 82 | }; |
| 83 | #endif |
| 84 | #endif |
| 85 | |
| 86 | int N_AU_IMAGES = (sizeof(au_image) / sizeof(au_image[0])); |
| 87 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 88 | /* Prototypes */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 89 | int cpci405_version(void); |
wdenk | eedcd07 | 2004-09-08 22:03:11 +0000 | [diff] [blame] | 90 | int gunzip(void *, int, unsigned char *, unsigned long *); |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 91 | void lxt971_no_sleep(void); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 92 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 93 | int board_early_init_f(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 94 | { |
| 95 | #ifndef CONFIG_CPCI405_VER2 |
| 96 | int index, len, i; |
| 97 | int status; |
| 98 | #endif |
| 99 | |
| 100 | #ifdef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 101 | /* set up serial port with default baudrate */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 102 | (void)get_clocks(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 103 | gd->baudrate = CONFIG_BAUDRATE; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 104 | serial_init(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 105 | console_init_f(); |
| 106 | #endif |
| 107 | |
| 108 | /* |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 109 | * First pull fpga-prg pin low, |
| 110 | * to disable fpga logic (on version 2 board) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 111 | */ |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 112 | out32(GPIO0_ODR, 0x00000000); /* no open drain pins */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 113 | out32(GPIO0_TCR, CONFIG_SYS_FPGA_PRG); /* setup for output */ |
| 114 | out32(GPIO0_OR, CONFIG_SYS_FPGA_PRG); /* set output pins to high */ |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 115 | out32(GPIO0_OR, 0); /* pull prg low */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 116 | |
| 117 | /* |
| 118 | * Boot onboard FPGA |
| 119 | */ |
| 120 | #ifndef CONFIG_CPCI405_VER2 |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 121 | if (cpci405_version() == 1) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 122 | status = fpga_boot((unsigned char *)fpgadata, sizeof(fpgadata)); |
| 123 | if (status != 0) { |
| 124 | /* booting FPGA failed */ |
| 125 | #ifndef FPGA_DEBUG |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 126 | /* set up serial port with default baudrate */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 127 | (void)get_clocks(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 128 | gd->baudrate = CONFIG_BAUDRATE; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 129 | serial_init(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 130 | console_init_f(); |
| 131 | #endif |
| 132 | printf("\nFPGA: Booting failed "); |
| 133 | switch (status) { |
| 134 | case ERROR_FPGA_PRG_INIT_LOW: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 135 | printf("(Timeout: INIT not low after " |
| 136 | "asserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 137 | break; |
| 138 | case ERROR_FPGA_PRG_INIT_HIGH: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 139 | printf("(Timeout: INIT not high after " |
| 140 | "deasserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 141 | break; |
| 142 | case ERROR_FPGA_PRG_DONE: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 143 | printf("(Timeout: DONE not high after " |
| 144 | "programming FPGA)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 145 | break; |
| 146 | } |
| 147 | |
| 148 | /* display infos on fpgaimage */ |
| 149 | index = 15; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 150 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 151 | len = fpgadata[index]; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 152 | printf("FPGA: %s\n", &(fpgadata[index + 1])); |
| 153 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 154 | } |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 155 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 156 | /* delayed reboot */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 157 | for (i = 20; i > 0; i--) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 158 | printf("Rebooting in %2d seconds \r",i); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 159 | for (index = 0; index < 1000; index++) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 160 | udelay(1000); |
| 161 | } |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 162 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 163 | do_reset(NULL, 0, 0, NULL); |
| 164 | } |
| 165 | } |
| 166 | #endif /* !CONFIG_CPCI405_VER2 */ |
| 167 | |
| 168 | /* |
| 169 | * IRQ 0-15 405GP internally generated; active high; level sensitive |
| 170 | * IRQ 16 405GP internally generated; active low; level sensitive |
| 171 | * IRQ 17-24 RESERVED |
| 172 | * IRQ 25 (EXT IRQ 0) CAN0; active low; level sensitive |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 173 | * IRQ 26 (EXT IRQ 1) CAN1 (+FPGA on CPCI4052); active low; level sens. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 174 | * IRQ 27 (EXT IRQ 2) PCI SLOT 0; active low; level sensitive |
| 175 | * IRQ 28 (EXT IRQ 3) PCI SLOT 1; active low; level sensitive |
| 176 | * IRQ 29 (EXT IRQ 4) PCI SLOT 2; active low; level sensitive |
| 177 | * IRQ 30 (EXT IRQ 5) PCI SLOT 3; active low; level sensitive |
| 178 | * IRQ 31 (EXT IRQ 6) COMPACT FLASH; active high; level sensitive |
| 179 | */ |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 180 | mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */ |
| 181 | mtdcr(uicer, 0x00000000); /* disable all ints */ |
| 182 | mtdcr(uiccr, 0x00000000); /* set all to be non-critical*/ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 183 | #if defined(CONFIG_CPCI405_6U) |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 184 | if (cpci405_version() == 3) { |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 185 | mtdcr(uicpr, 0xFFFFFF99); /* set int polarities */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 186 | } else { |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 187 | mtdcr(uicpr, 0xFFFFFF81); /* set int polarities */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 188 | } |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 189 | #else |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 190 | mtdcr(uicpr, 0xFFFFFF81); /* set int polarities */ |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 191 | #endif |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 192 | mtdcr(uictr, 0x10000000); /* set int trigger levels */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 193 | mtdcr(uicvcr, 0x00000001); /* set vect base=0, |
| 194 | * INT0 highest priority */ |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 195 | mtdcr(uicsr, 0xFFFFFFFF); /* clear all ints */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 196 | |
| 197 | return 0; |
| 198 | } |
| 199 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 200 | int ctermm2(void) |
| 201 | { |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 202 | #if defined(CONFIG_CPCI405_VER2) |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 203 | return 0; /* no, board is cpci405 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 204 | #else |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 205 | if ((in_8((void*)0xf0000400) == 0x00) && |
| 206 | (in_8((void*)0xf0000401) == 0x01)) |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 207 | return 0; /* no, board is cpci405 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 208 | else |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 209 | return -1; /* yes, board is cterm-m2 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 210 | #endif |
| 211 | } |
| 212 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 213 | int cpci405_host(void) |
| 214 | { |
| 215 | if (mfdcr(strap) & PSR_PCI_ARBIT_EN) |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 216 | return -1; /* yes, board is cpci405 host */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 217 | else |
Wolfgang Denk | 4ef218f | 2007-07-10 00:01:28 +0200 | [diff] [blame] | 218 | return 0; /* no, board is cpci405 adapter */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 219 | } |
| 220 | |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 221 | int cpci405_version(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 222 | { |
| 223 | unsigned long cntrl0Reg; |
| 224 | unsigned long value; |
| 225 | |
| 226 | /* |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 227 | * Setup GPIO pins (CS2/GPIO11 and CS3/GPIO12 as GPIO) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 228 | */ |
| 229 | cntrl0Reg = mfdcr(cntrl0); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 230 | mtdcr(cntrl0, cntrl0Reg | 0x03000000); |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 231 | out_be32((void*)GPIO0_ODR, in_be32((void*)GPIO0_ODR) & ~0x00180000); |
| 232 | out_be32((void*)GPIO0_TCR, in_be32((void*)GPIO0_TCR) & ~0x00180000); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 233 | udelay(1000); /* wait some time before reading input */ |
| 234 | value = in_be32((void*)GPIO0_IR) & 0x00180000; /* get config bits */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 235 | |
| 236 | /* |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 237 | * Restore GPIO settings |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 238 | */ |
| 239 | mtdcr(cntrl0, cntrl0Reg); |
| 240 | |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 241 | switch (value) { |
| 242 | case 0x00180000: |
| 243 | /* CS2==1 && CS3==1 -> version 1 */ |
| 244 | return 1; |
| 245 | case 0x00080000: |
| 246 | /* CS2==0 && CS3==1 -> version 2 */ |
| 247 | return 2; |
| 248 | case 0x00100000: |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 249 | /* CS2==1 && CS3==0 -> version 3 or 6U board */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 250 | return 3; |
| 251 | case 0x00000000: |
| 252 | /* CS2==0 && CS3==0 -> version 4 */ |
| 253 | return 4; |
| 254 | default: |
| 255 | /* should not be reached! */ |
| 256 | return 2; |
| 257 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 258 | } |
| 259 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 260 | int misc_init_r (void) |
| 261 | { |
stroese | afcc4a7 | 2003-04-04 16:52:57 +0000 | [diff] [blame] | 262 | unsigned long cntrl0Reg; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 263 | |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 264 | /* adjust flash start and offset */ |
| 265 | gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize; |
| 266 | gd->bd->bi_flashoffset = 0; |
| 267 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 268 | #if defined(CONFIG_CPCI405_VER2) |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 269 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 270 | unsigned char *dst; |
| 271 | ulong len = sizeof(fpgadata); |
| 272 | int status; |
| 273 | int index; |
| 274 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 275 | |
| 276 | /* |
| 277 | * On CPCI-405 version 2 the environment is saved in eeprom! |
| 278 | * FPGA can be gzip compressed (malloc) and booted this late. |
| 279 | */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 280 | if (cpci405_version() >= 2) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 281 | /* |
| 282 | * Setup GPIO pins (CS6+CS7 as GPIO) |
| 283 | */ |
| 284 | cntrl0Reg = mfdcr(cntrl0); |
| 285 | mtdcr(cntrl0, cntrl0Reg | 0x00300000); |
| 286 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 287 | dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 288 | if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE, |
| 289 | (uchar *)fpgadata, &len) != 0) { |
| 290 | printf("GUNZIP ERROR - must RESET board to recover\n"); |
| 291 | do_reset(NULL, 0, 0, NULL); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | status = fpga_boot(dst, len); |
| 295 | if (status != 0) { |
| 296 | printf("\nFPGA: Booting failed "); |
| 297 | switch (status) { |
| 298 | case ERROR_FPGA_PRG_INIT_LOW: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 299 | printf("(Timeout: INIT not low after " |
| 300 | "asserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 301 | break; |
| 302 | case ERROR_FPGA_PRG_INIT_HIGH: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 303 | printf("(Timeout: INIT not high after " |
| 304 | "deasserting PROGRAM*)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 305 | break; |
| 306 | case ERROR_FPGA_PRG_DONE: |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 307 | printf("(Timeout: DONE not high after " |
| 308 | "programming FPGA)\n "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 309 | break; |
| 310 | } |
| 311 | |
| 312 | /* display infos on fpgaimage */ |
| 313 | index = 15; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 314 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 315 | len = dst[index]; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 316 | printf("FPGA: %s\n", &(dst[index + 1])); |
| 317 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 318 | } |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 319 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 320 | /* delayed reboot */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 321 | for (i = 20; i > 0; i--) { |
| 322 | printf("Rebooting in %2d seconds \r", i); |
| 323 | for (index = 0; index < 1000; index++) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 324 | udelay(1000); |
| 325 | } |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 326 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 327 | do_reset(NULL, 0, 0, NULL); |
| 328 | } |
| 329 | |
| 330 | /* restore gpio/cs settings */ |
| 331 | mtdcr(cntrl0, cntrl0Reg); |
| 332 | |
| 333 | puts("FPGA: "); |
| 334 | |
| 335 | /* display infos on fpgaimage */ |
| 336 | index = 15; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 337 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 338 | len = dst[index]; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 339 | printf("%s ", &(dst[index + 1])); |
| 340 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 341 | } |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 342 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 343 | |
| 344 | free(dst); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 345 | |
| 346 | /* |
| 347 | * Reset FPGA via FPGA_DATA pin |
| 348 | */ |
| 349 | SET_FPGA(FPGA_PRG | FPGA_CLK); |
| 350 | udelay(1000); /* wait 1ms */ |
| 351 | SET_FPGA(FPGA_PRG | FPGA_CLK | FPGA_DATA); |
| 352 | udelay(1000); /* wait 1ms */ |
| 353 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 354 | #if defined(CONFIG_CPCI405_6U) |
| 355 | #error HIER GETH ES WEITER MIT IO ACCESSORS |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 356 | if (cpci405_version() == 3) { |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 357 | /* |
| 358 | * Enable outputs in fpga on version 3 board |
| 359 | */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 360 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 361 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) | |
| 362 | CONFIG_SYS_FPGA_MODE_ENABLE_OUTPUT); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 363 | |
| 364 | /* |
| 365 | * Set outputs to 0 |
| 366 | */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 367 | out_8((void*)CONFIG_SYS_LED_ADDR, 0x00); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 368 | |
| 369 | /* |
| 370 | * Reset external DUART |
| 371 | */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 372 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 373 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) | |
| 374 | CONFIG_SYS_FPGA_MODE_DUART_RESET); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 375 | udelay(100); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 376 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 377 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) & |
| 378 | ~CONFIG_SYS_FPGA_MODE_DUART_RESET); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 379 | } |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 380 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 381 | } |
| 382 | else { |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 383 | puts("\n*** U-Boot Version does not match Board Version!\n"); |
| 384 | puts("*** CPCI-405 Version 1.x detected!\n"); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 385 | puts("*** Please use correct U-Boot version " |
| 386 | "(CPCI405 instead of CPCI4052)!\n\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 387 | } |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 388 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 389 | #else /* CONFIG_CPCI405_VER2 */ |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 390 | if (cpci405_version() >= 2) { |
| 391 | puts("\n*** U-Boot Version does not match Board Version!\n"); |
| 392 | puts("*** CPCI-405 Board Version 2.x detected!\n"); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 393 | puts("*** Please use correct U-Boot version " |
| 394 | "(CPCI4052 instead of CPCI405)!\n\n"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 395 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 396 | #endif /* CONFIG_CPCI405_VER2 */ |
| 397 | |
| 398 | /* |
stroese | afcc4a7 | 2003-04-04 16:52:57 +0000 | [diff] [blame] | 399 | * Select cts (and not dsr) on uart1 |
| 400 | */ |
| 401 | cntrl0Reg = mfdcr(cntrl0); |
| 402 | mtdcr(cntrl0, cntrl0Reg | 0x00001000); |
| 403 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 404 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 405 | } |
| 406 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 407 | /* |
| 408 | * Check Board Identity: |
| 409 | */ |
| 410 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 411 | int checkboard(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 412 | { |
| 413 | #ifndef CONFIG_CPCI405_VER2 |
| 414 | int index; |
| 415 | int len; |
| 416 | #endif |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 417 | char str[64]; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 418 | int i = getenv_r("serial#", str, sizeof(str)); |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 419 | unsigned short ver; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 420 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 421 | puts("Board: "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 422 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 423 | if (i == -1) |
| 424 | puts("### No HW ID - assuming CPCI405"); |
| 425 | else |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 426 | puts(str); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 427 | |
stroese | 6f4474e | 2003-03-20 15:31:19 +0000 | [diff] [blame] | 428 | ver = cpci405_version(); |
| 429 | printf(" (Ver %d.x, ", ver); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 430 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 431 | if (ctermm2()) { |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 432 | char str[4]; |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 433 | |
| 434 | /* |
| 435 | * Read board-id and save in env-variable |
| 436 | */ |
| 437 | sprintf(str, "%d", *(unsigned char *)0xf0000400); |
| 438 | setenv("boardid", str); |
| 439 | printf("CTERM-M2 - Id=%s)", str); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 440 | } else { |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 441 | if (cpci405_host()) |
| 442 | puts("PCI Host Version)"); |
| 443 | else |
| 444 | puts("PCI Adapter Version)"); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | #ifndef CONFIG_CPCI405_VER2 |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 448 | puts("\nFPGA: "); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 449 | |
| 450 | /* display infos on fpgaimage */ |
| 451 | index = 15; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 452 | for (i = 0; i < 4; i++) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 453 | len = fpgadata[index]; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 454 | printf("%s ", &(fpgadata[index + 1])); |
| 455 | index += len + 3; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 456 | } |
| 457 | #endif |
| 458 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 459 | putc('\n'); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 460 | return 0; |
| 461 | } |
| 462 | |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 463 | void reset_phy(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 464 | { |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 465 | #if defined(CONFIG_LXT971_NO_SLEEP) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 466 | |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 467 | /* |
| 468 | * Disable sleep mode in LXT971 |
| 469 | */ |
| 470 | lxt971_no_sleep(); |
| 471 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 474 | #if defined(CONFIG_CPCI405_VER2) && defined (CONFIG_IDE_RESET) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 475 | void ide_set_reset(int on) |
| 476 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 477 | /* |
| 478 | * Assert or deassert CompactFlash Reset Pin |
| 479 | */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 480 | if (on) { /* assert RESET */ |
| 481 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 482 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) & |
| 483 | ~CONFIG_SYS_FPGA_MODE_CF_RESET); |
| 484 | } else { /* release RESET */ |
| 485 | out_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR, |
| 486 | in_be16((void*)CONFIG_SYS_FPGA_BASE_ADDR) | |
| 487 | CONFIG_SYS_FPGA_MODE_CF_RESET); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 491 | #endif /* CONFIG_IDE_RESET && CONFIG_CPCI405_VER2 */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 492 | |
Stefan Roese | 466fff1 | 2007-06-25 15:57:39 +0200 | [diff] [blame] | 493 | #if defined(CONFIG_PCI) |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 494 | void cpci405_pci_fixup_irq(struct pci_controller *hose, pci_dev_t dev) |
| 495 | { |
| 496 | unsigned char int_line = 0xff; |
| 497 | |
| 498 | /* |
| 499 | * Write pci interrupt line register (cpci405 specific) |
| 500 | */ |
| 501 | switch (PCI_DEV(dev) & 0x03) { |
| 502 | case 0: |
| 503 | int_line = 27 + 2; |
| 504 | break; |
| 505 | case 1: |
| 506 | int_line = 27 + 3; |
| 507 | break; |
| 508 | case 2: |
| 509 | int_line = 27 + 0; |
| 510 | break; |
| 511 | case 3: |
| 512 | int_line = 27 + 1; |
| 513 | break; |
| 514 | } |
| 515 | |
| 516 | pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, int_line); |
| 517 | } |
| 518 | |
| 519 | int pci_pre_init(struct pci_controller *hose) |
| 520 | { |
| 521 | hose->fixup_irq = cpci405_pci_fixup_irq; |
| 522 | return 1; |
| 523 | } |
Stefan Roese | 466fff1 | 2007-06-25 15:57:39 +0200 | [diff] [blame] | 524 | #endif /* defined(CONFIG_PCI) */ |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 525 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 526 | #if defined(CONFIG_CPCI405AB) |
| 527 | #define ONE_WIRE_CLEAR out_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + \ |
| 528 | CONFIG_SYS_FPGA_MODE), \ |
| 529 | in_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + \ |
| 530 | CONFIG_SYS_FPGA_MODE)) | \ |
| 531 | CONFIG_SYS_FPGA_MODE_1WIRE_DIR) |
Matthias Fuchs | 6f35c53 | 2007-06-24 17:41:21 +0200 | [diff] [blame] | 532 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 533 | #define ONE_WIRE_SET out_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + \ |
| 534 | CONFIG_SYS_FPGA_MODE), \ |
| 535 | in_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + \ |
| 536 | CONFIG_SYS_FPGA_MODE)) & \ |
| 537 | ~CONFIG_SYS_FPGA_MODE_1WIRE_DIR) |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 538 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 539 | #define ONE_WIRE_GET (in_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + \ |
| 540 | CONFIG_SYS_FPGA_STATUS)) & \ |
| 541 | CONFIG_SYS_FPGA_MODE_1WIRE) |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 542 | |
| 543 | /* |
| 544 | * Generate a 1-wire reset, return 1 if no presence detect was found, |
| 545 | * return 0 otherwise. |
| 546 | * (NOTE: Does not handle alarm presence from DS2404/DS1994) |
| 547 | */ |
| 548 | int OWTouchReset(void) |
stroese | d4629c8 | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 549 | { |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 550 | int result; |
stroese | d4629c8 | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 551 | |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 552 | ONE_WIRE_CLEAR; |
| 553 | udelay(480); |
| 554 | ONE_WIRE_SET; |
| 555 | udelay(70); |
stroese | d4629c8 | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 556 | |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 557 | result = ONE_WIRE_GET; |
| 558 | |
| 559 | udelay(410); |
| 560 | return result; |
stroese | d4629c8 | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 561 | } |
| 562 | |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 563 | /* |
| 564 | * Send 1 a 1-wire write bit. |
| 565 | * Provide 10us recovery time. |
| 566 | */ |
| 567 | void OWWriteBit(int bit) |
stroese | d4629c8 | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 568 | { |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 569 | if (bit) { |
| 570 | /* |
| 571 | * write '1' bit |
| 572 | */ |
| 573 | ONE_WIRE_CLEAR; |
| 574 | udelay(6); |
| 575 | ONE_WIRE_SET; |
| 576 | udelay(64); |
| 577 | } else { |
| 578 | /* |
| 579 | * write '0' bit |
| 580 | */ |
| 581 | ONE_WIRE_CLEAR; |
| 582 | udelay(60); |
| 583 | ONE_WIRE_SET; |
| 584 | udelay(10); |
stroese | d4629c8 | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 585 | } |
stroese | d4629c8 | 2003-05-23 11:30:39 +0000 | [diff] [blame] | 586 | } |
| 587 | |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 588 | /* |
| 589 | * Read a bit from the 1-wire bus and return it. |
| 590 | * Provide 10us recovery time. |
| 591 | */ |
| 592 | int OWReadBit(void) |
| 593 | { |
| 594 | int result; |
| 595 | |
| 596 | ONE_WIRE_CLEAR; |
| 597 | udelay(6); |
| 598 | ONE_WIRE_SET; |
| 599 | udelay(9); |
| 600 | |
| 601 | result = ONE_WIRE_GET; |
| 602 | |
| 603 | udelay(55); |
| 604 | return result; |
| 605 | } |
| 606 | |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 607 | void OWWriteByte(int data) |
| 608 | { |
| 609 | int loop; |
| 610 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 611 | for (loop = 0; loop < 8; loop++) { |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 612 | OWWriteBit(data & 0x01); |
| 613 | data >>= 1; |
| 614 | } |
| 615 | } |
| 616 | |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 617 | int OWReadByte(void) |
| 618 | { |
| 619 | int loop, result = 0; |
| 620 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 621 | for (loop = 0; loop < 8; loop++) { |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 622 | result >>= 1; |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 623 | if (OWReadBit()) |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 624 | result |= 0x80; |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | return result; |
| 628 | } |
| 629 | |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 630 | int do_onewire(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 631 | { |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 632 | unsigned short val; |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 633 | int result; |
| 634 | int i; |
| 635 | unsigned char ow_id[6]; |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 636 | char str[32]; |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 637 | unsigned char ow_crc; |
| 638 | |
| 639 | /* |
| 640 | * Clear 1-wire bit (open drain with pull-up) |
| 641 | */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 642 | val = in_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + |
| 643 | CONFIG_SYS_FPGA_MODE)); |
| 644 | val &= ~CONFIG_SYS_FPGA_MODE_1WIRE; /* clear 1-wire bit */ |
| 645 | out_be16((void*)(CONFIG_SYS_FPGA_BASE_ADDR + |
| 646 | CONFIG_SYS_FPGA_MODE), val); |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 647 | |
| 648 | result = OWTouchReset(); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 649 | if (result != 0) |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 650 | puts("No 1-wire device detected!\n"); |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 651 | |
| 652 | OWWriteByte(0x33); /* send read rom command */ |
| 653 | OWReadByte(); /* skip family code ( == 0x01) */ |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 654 | for (i = 0; i < 6; i++) |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 655 | ow_id[i] = OWReadByte(); |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 656 | ow_crc = OWReadByte(); /* read crc */ |
| 657 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 658 | sprintf(str, "%08X%04X", |
| 659 | *(unsigned int *)&ow_id[0], |
| 660 | *(unsigned short *)&ow_id[4]); |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 661 | printf("Setting environment variable 'ow_id' to %s\n", str); |
| 662 | setenv("ow_id", str); |
| 663 | |
| 664 | return 0; |
| 665 | } |
| 666 | U_BOOT_CMD( |
| 667 | onewire, 1, 1, do_onewire, |
| 668 | "onewire - Read 1-write ID\n", |
| 669 | NULL |
| 670 | ); |
| 671 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 672 | #define CONFIG_SYS_I2C_EEPROM_ADDR_2 0x51 /* EEPROM CAT24WC32 */ |
| 673 | #define CONFIG_ENV_SIZE_2 0x800 /* 2048 bytes may be used for env vars */ |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 674 | |
| 675 | /* |
| 676 | * Write backplane ip-address... |
| 677 | */ |
| 678 | int do_get_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 679 | { |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 680 | bd_t *bd = gd->bd; |
| 681 | char *buf; |
| 682 | ulong crc; |
| 683 | char str[32]; |
| 684 | char *ptr; |
| 685 | IPaddr_t ipaddr; |
| 686 | |
Jean-Christophe PLAGNIOL-VILLARD | 0e8d158 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 687 | buf = malloc(CONFIG_ENV_SIZE_2); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 688 | if (eeprom_read(CONFIG_SYS_I2C_EEPROM_ADDR_2, 0, |
| 689 | (uchar *)buf, CONFIG_ENV_SIZE_2)) |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 690 | puts("\nError reading backplane EEPROM!\n"); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 691 | else { |
| 692 | crc = crc32(0, (uchar *)(buf+4), CONFIG_ENV_SIZE_2 - 4); |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 693 | if (crc != *(ulong *)buf) { |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 694 | printf("ERROR: crc mismatch %08lx %08lx\n", |
| 695 | crc, *(ulong *)buf); |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 696 | return -1; |
| 697 | } |
| 698 | |
| 699 | /* |
| 700 | * Find bp_ip |
| 701 | */ |
| 702 | ptr = strstr(buf+4, "bp_ip="); |
| 703 | if (ptr == NULL) { |
| 704 | printf("ERROR: bp_ip not found!\n"); |
| 705 | return -1; |
| 706 | } |
| 707 | ptr += 6; |
| 708 | ipaddr = string_to_ip(ptr); |
| 709 | |
| 710 | /* |
| 711 | * Update whole ip-addr |
| 712 | */ |
| 713 | bd->bi_ip_addr = ipaddr; |
| 714 | sprintf(str, "%ld.%ld.%ld.%ld", |
| 715 | (bd->bi_ip_addr & 0xff000000) >> 24, |
| 716 | (bd->bi_ip_addr & 0x00ff0000) >> 16, |
| 717 | (bd->bi_ip_addr & 0x0000ff00) >> 8, |
| 718 | (bd->bi_ip_addr & 0x000000ff)); |
| 719 | setenv("ipaddr", str); |
| 720 | printf("Updated ip_addr from bp_eeprom to %s!\n", str); |
| 721 | } |
| 722 | |
| 723 | free(buf); |
| 724 | |
| 725 | return 0; |
| 726 | } |
| 727 | U_BOOT_CMD( |
| 728 | getbpip, 1, 1, do_get_bpip, |
| 729 | "getbpip - Update IP-Address with Backplane IP-Address\n", |
| 730 | NULL |
| 731 | ); |
| 732 | |
| 733 | /* |
| 734 | * Set and print backplane ip... |
| 735 | */ |
| 736 | int do_set_bpip(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 737 | { |
| 738 | char *buf; |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 739 | char str[32]; |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 740 | ulong crc; |
| 741 | |
| 742 | if (argc < 2) { |
| 743 | puts("ERROR!\n"); |
| 744 | return -1; |
| 745 | } |
| 746 | |
| 747 | printf("Setting bp_ip to %s\n", argv[1]); |
Jean-Christophe PLAGNIOL-VILLARD | 0e8d158 | 2008-09-10 22:48:06 +0200 | [diff] [blame] | 748 | buf = malloc(CONFIG_ENV_SIZE_2); |
| 749 | memset(buf, 0, CONFIG_ENV_SIZE_2); |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 750 | sprintf(str, "bp_ip=%s", argv[1]); |
| 751 | strcpy(buf+4, str); |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 752 | crc = crc32(0, (uchar *)(buf+4), CONFIG_ENV_SIZE_2 - 4); |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 753 | *(ulong *)buf = crc; |
| 754 | |
Matthias Fuchs | f6a1f49 | 2009-01-02 12:17:36 +0100 | [diff] [blame^] | 755 | if (eeprom_write(CONFIG_SYS_I2C_EEPROM_ADDR_2, |
| 756 | 0, (uchar *)buf, CONFIG_ENV_SIZE_2)) |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 757 | puts("\nError writing backplane EEPROM!\n"); |
stroese | 87663b1 | 2004-12-16 18:27:05 +0000 | [diff] [blame] | 758 | |
| 759 | free(buf); |
| 760 | |
| 761 | return 0; |
| 762 | } |
| 763 | U_BOOT_CMD( |
| 764 | setbpip, 2, 1, do_set_bpip, |
| 765 | "setbpip - Write Backplane IP-Address\n", |
| 766 | NULL |
| 767 | ); |
| 768 | |
stroese | 1b55440 | 2003-09-12 08:44:46 +0000 | [diff] [blame] | 769 | #endif /* CONFIG_CPCI405AB */ |