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