Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2006 |
| 3 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 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 <command.h> |
| 26 | #include <malloc.h> |
| 27 | #include <asm/arch/ixp425.h> |
| 28 | |
| 29 | DECLARE_GLOBAL_DATA_PTR; |
| 30 | |
| 31 | /* Prototypes */ |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 32 | int do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 33 | |
| 34 | /* predefine these here for FPGA programming (before including fpga.c) */ |
| 35 | #define SET_FPGA(data) *IXP425_GPIO_GPOUTR = (data) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 36 | #define FPGA_DONE_STATE (*IXP425_GPIO_GPINR & CONFIG_SYS_FPGA_DONE) |
| 37 | #define FPGA_INIT_STATE (*IXP425_GPIO_GPINR & CONFIG_SYS_FPGA_INIT) |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 38 | #define OLD_VAL old_val |
| 39 | |
| 40 | static unsigned long old_val = 0; |
| 41 | |
| 42 | /* |
| 43 | * include common fpga code (for prodrive boards) |
| 44 | */ |
| 45 | #include "../common/fpga.c" |
| 46 | |
| 47 | /* |
| 48 | * Miscelaneous platform dependent initialisations |
| 49 | */ |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 50 | int board_init(void) |
| 51 | { |
| 52 | /* arch number of PDNB3 */ |
| 53 | gd->bd->bi_arch_number = MACH_TYPE_PDNB3; |
| 54 | |
| 55 | /* adress of boot parameters */ |
| 56 | gd->bd->bi_boot_params = 0x00000100; |
| 57 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 58 | GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_FPGA_RESET); |
| 59 | GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_FPGA_RESET); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 60 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 61 | GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_SYS_RUNNING); |
| 62 | GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_SYS_RUNNING); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * Setup GPIO's for FPGA programming |
| 66 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 67 | GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_PRG); |
| 68 | GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_CLK); |
| 69 | GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_DATA); |
| 70 | GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_PRG); |
| 71 | GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_CLK); |
| 72 | GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_DATA); |
| 73 | GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_INIT); |
| 74 | GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_DONE); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * Setup GPIO's for interrupts |
| 78 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 79 | GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_PCI_INTA); |
| 80 | GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_PCI_INTA); |
| 81 | GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_PCI_INTB); |
| 82 | GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_PCI_INTB); |
| 83 | GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_RESTORE_INT); |
| 84 | GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_RESTORE_INT); |
| 85 | GPIO_OUTPUT_DISABLE(CONFIG_SYS_GPIO_RESTART_INT); |
| 86 | GPIO_INT_ACT_LOW_SET(CONFIG_SYS_GPIO_RESTART_INT); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 87 | |
| 88 | /* |
| 89 | * Setup GPIO's for 33MHz clock output |
| 90 | */ |
| 91 | *IXP425_GPIO_GPCLKR = 0x01FF0000; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 92 | GPIO_OUTPUT_ENABLE(CONFIG_SYS_GPIO_CLK_33M); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * Setup other chip select's |
| 96 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 97 | *IXP425_EXP_CS1 = CONFIG_SYS_EXP_CS1; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | /* |
| 103 | * Check Board Identity |
| 104 | */ |
| 105 | int checkboard(void) |
| 106 | { |
| 107 | char *s = getenv("serial#"); |
| 108 | |
| 109 | puts("Board: PDNB3"); |
| 110 | |
| 111 | if (s != NULL) { |
| 112 | puts(", serial# "); |
| 113 | puts(s); |
| 114 | } |
| 115 | putc('\n'); |
| 116 | |
| 117 | return (0); |
| 118 | } |
| 119 | |
| 120 | int dram_init(void) |
| 121 | { |
| 122 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 123 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
| 124 | |
| 125 | return (0); |
| 126 | } |
| 127 | |
| 128 | int do_fpga_boot(unsigned char *fpgadata) |
| 129 | { |
| 130 | unsigned char *dst; |
| 131 | int status; |
| 132 | int index; |
| 133 | int i; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 134 | ulong len = CONFIG_SYS_MALLOC_LEN; |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 135 | |
| 136 | /* |
| 137 | * Setup GPIO's for FPGA programming |
| 138 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 139 | GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_PRG); |
| 140 | GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_CLK); |
| 141 | GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_DATA); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | * Save value so no readback is required upon programming |
| 145 | */ |
| 146 | old_val = *IXP425_GPIO_GPOUTR; |
| 147 | |
| 148 | /* |
| 149 | * First try to decompress fpga image (gzip compressed?) |
| 150 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 151 | dst = malloc(CONFIG_SYS_FPGA_MAX_SIZE); |
| 152 | if (gunzip(dst, CONFIG_SYS_FPGA_MAX_SIZE, (uchar *)fpgadata, &len) != 0) { |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 153 | printf("Error: Image has to be gzipp'ed!\n"); |
| 154 | return -1; |
| 155 | } |
| 156 | |
| 157 | status = fpga_boot(dst, len); |
| 158 | if (status != 0) { |
| 159 | printf("\nFPGA: Booting failed "); |
| 160 | switch (status) { |
| 161 | case ERROR_FPGA_PRG_INIT_LOW: |
| 162 | printf("(Timeout: INIT not low after asserting PROGRAM*)\n "); |
| 163 | break; |
| 164 | case ERROR_FPGA_PRG_INIT_HIGH: |
| 165 | printf("(Timeout: INIT not high after deasserting PROGRAM*)\n "); |
| 166 | break; |
| 167 | case ERROR_FPGA_PRG_DONE: |
| 168 | printf("(Timeout: DONE not high after programming FPGA)\n "); |
| 169 | break; |
| 170 | } |
| 171 | |
| 172 | /* display infos on fpgaimage */ |
| 173 | index = 15; |
| 174 | for (i=0; i<4; i++) { |
| 175 | len = dst[index]; |
| 176 | printf("FPGA: %s\n", &(dst[index+1])); |
| 177 | index += len+3; |
| 178 | } |
| 179 | putc ('\n'); |
| 180 | /* delayed reboot */ |
| 181 | for (i=5; i>0; i--) { |
| 182 | printf("Rebooting in %2d seconds \r",i); |
| 183 | for (index=0;index<1000;index++) |
| 184 | udelay(1000); |
| 185 | } |
| 186 | putc('\n'); |
| 187 | do_reset(NULL, 0, 0, NULL); |
| 188 | } |
| 189 | |
| 190 | puts("FPGA: "); |
| 191 | |
| 192 | /* display infos on fpgaimage */ |
| 193 | index = 15; |
| 194 | for (i=0; i<4; i++) { |
| 195 | len = dst[index]; |
| 196 | printf("%s ", &(dst[index+1])); |
| 197 | index += len+3; |
| 198 | } |
| 199 | putc('\n'); |
| 200 | |
| 201 | free(dst); |
| 202 | |
| 203 | /* |
| 204 | * Reset FPGA |
| 205 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 206 | GPIO_OUTPUT_CLEAR(CONFIG_SYS_GPIO_FPGA_RESET); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 207 | udelay(10); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 208 | GPIO_OUTPUT_SET(CONFIG_SYS_GPIO_FPGA_RESET); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 209 | |
| 210 | return (0); |
| 211 | } |
| 212 | |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 213 | int do_fpga(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 214 | { |
| 215 | ulong addr; |
| 216 | |
Wolfgang Denk | 47e26b1 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 217 | if (argc < 2) |
| 218 | return cmd_usage(cmdtp); |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 219 | |
| 220 | addr = simple_strtoul(argv[1], NULL, 16); |
| 221 | |
| 222 | return do_fpga_boot((unsigned char *)addr); |
| 223 | } |
| 224 | |
| 225 | U_BOOT_CMD( |
| 226 | fpga, 2, 0, do_fpga, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 227 | "boot FPGA", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 228 | "address size\n - boot FPGA with gzipped image at <address>" |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 229 | ); |
| 230 | |
Jon Loeliger | 3fe0010 | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 231 | #if defined(CONFIG_CMD_PCI) || defined(CONFIG_PCI) |
Wolfgang Denk | ba94a1b | 2006-05-30 15:56:48 +0200 | [diff] [blame] | 232 | extern struct pci_controller hose; |
| 233 | extern void pci_ixp_init(struct pci_controller * hose); |
| 234 | |
| 235 | void pci_init_board(void) |
| 236 | { |
| 237 | extern void pci_ixp_init (struct pci_controller *hose); |
| 238 | |
| 239 | pci_ixp_init(&hose); |
| 240 | } |
| 241 | #endif |