wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@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 <config.h> |
| 25 | #include <common.h> |
| 26 | #include <command.h> |
| 27 | #include <asm/io.h> |
| 28 | #include <linux/mtd/doc2000.h> |
| 29 | #include <watchdog.h> |
| 30 | #include <pci.h> |
Ben Warren | 840f8a5 | 2008-08-31 10:45:44 -0700 | [diff] [blame] | 31 | #include <netdev.h> |
Marek Vasut | d9c6449 | 2012-10-06 14:07:02 +0000 | [diff] [blame] | 32 | #include <serial.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 33 | |
| 34 | #include "hardware.h" |
| 35 | #include "pcippc2.h" |
| 36 | #include "sconsole.h" |
| 37 | #include "fpga_serial.h" |
| 38 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 41 | #if defined(CONFIG_WATCHDOG) |
| 42 | |
| 43 | static int pcippc2_wdt_init_done = 0; |
| 44 | |
| 45 | void pcippc2_wdt_init (void); |
| 46 | |
| 47 | #endif |
| 48 | |
| 49 | /* Check board identity |
| 50 | */ |
| 51 | int checkboard (void) |
| 52 | { |
| 53 | #ifdef CONFIG_PCIPPC2 |
| 54 | puts ("Board: Gespac PCIPPC-2\n"); |
| 55 | #else |
| 56 | puts ("Board: Gespac PCIPPC-6\n"); |
| 57 | #endif |
| 58 | return 0; |
| 59 | } |
| 60 | |
| 61 | /* RAM size is stored in CPC0_RGBAN1 |
| 62 | */ |
| 63 | u32 pcippc2_sdram_size (void) |
| 64 | { |
| 65 | return in32 (REG (CPC0, RGBAN1)); |
| 66 | } |
| 67 | |
Becky Bruce | bd99ae7 | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 68 | phys_size_t initdram (int board_type) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 69 | { |
| 70 | return cpc710_ram_init (); |
| 71 | } |
| 72 | |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 73 | int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 74 | { |
| 75 | out32 (REG (CPC0, SPOR), 0); |
| 76 | iobarrier_rw (); |
| 77 | while (1); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 78 | /* notreached */ |
| 79 | return (-1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 80 | } |
| 81 | |
wdenk | da55c6e | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 82 | int board_early_init_f (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 83 | { |
| 84 | out32 (REG (CPC0, RSTR), 0xC0000000); |
| 85 | iobarrier_rw (); |
| 86 | |
| 87 | out32 (REG (CPC0, RSTR), 0xF0000000); |
| 88 | iobarrier_rw (); |
| 89 | |
| 90 | out32 (REG (CPC0, UCTL), 0x00F80000); |
| 91 | |
| 92 | out32 (REG (CPC0, SIOC0), 0x30000000); |
| 93 | |
| 94 | out32 (REG (CPC0, ABCNTL), 0x00000000); |
| 95 | |
| 96 | out32 (REG (CPC0, SESR), 0x00000000); |
| 97 | out32 (REG (CPC0, SEAR), 0x00000000); |
| 98 | |
| 99 | /* Detect IBM Avignon CPC710 Revision */ |
| 100 | if ((in32 (REG (CPC0, UCTL)) & 0x000000F0) == CPC710_TYPE_100P) |
| 101 | out32 (REG (CPC0, PGCHP), 0xA0000040); |
| 102 | else |
| 103 | out32 (REG (CPC0, PGCHP), 0x80800040); |
| 104 | |
| 105 | |
| 106 | out32 (REG (CPC0, ATAS), 0x709C2508); |
| 107 | |
| 108 | iobarrier_rw (); |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | void after_reloc (ulong dest_addr) |
| 114 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 115 | /* Jump to the main U-Boot board init code |
| 116 | */ |
wdenk | 874ac26 | 2003-07-24 23:38:38 +0000 | [diff] [blame] | 117 | board_init_r ((gd_t *)gd, dest_addr); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | int misc_init_r (void) |
| 121 | { |
| 122 | pcippc2_fpga_init (); |
| 123 | |
wdenk | e95b61c | 2002-11-04 16:02:40 +0000 | [diff] [blame] | 124 | pcippc2_cpci3264_init (); |
| 125 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 126 | #if defined(CONFIG_WATCHDOG) |
| 127 | pcippc2_wdt_init (); |
| 128 | #endif |
| 129 | |
| 130 | fpga_serial_init (sconsole_get_baudrate ()); |
| 131 | |
| 132 | sconsole_putc = fpga_serial_putc; |
Marek Vasut | d9c6449 | 2012-10-06 14:07:02 +0000 | [diff] [blame] | 133 | sconsole_puts = default_serial_puts; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 134 | sconsole_getc = fpga_serial_getc; |
| 135 | sconsole_tstc = fpga_serial_tstc; |
| 136 | sconsole_setbrg = fpga_serial_setbrg; |
| 137 | |
| 138 | sconsole_flush (); |
| 139 | return (0); |
| 140 | } |
| 141 | |
stroese | f5dd410 | 2003-02-14 11:21:23 +0000 | [diff] [blame] | 142 | void pci_init_board (void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 143 | { |
| 144 | cpc710_pci_init (); |
| 145 | |
| 146 | /* FPGA requires no retry timeouts to be enabled |
| 147 | */ |
| 148 | cpc710_pci_enable_timeout (); |
| 149 | } |
| 150 | |
Wolfgang Denk | 21a51f0 | 2009-07-19 19:37:24 +0200 | [diff] [blame] | 151 | #ifdef CONFIG_CMD_DOC |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 152 | void doc_init (void) |
| 153 | { |
| 154 | doc_probe (pcippc2_fpga1_phys + HW_FPGA1_DOC); |
| 155 | } |
Wolfgang Denk | 21a51f0 | 2009-07-19 19:37:24 +0200 | [diff] [blame] | 156 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 157 | |
wdenk | e95b61c | 2002-11-04 16:02:40 +0000 | [diff] [blame] | 158 | void pcippc2_cpci3264_init (void) |
| 159 | { |
| 160 | pci_dev_t bdf = pci_find_device(FPGA_VENDOR_ID, FPGA_DEVICE_ID, 0); |
| 161 | |
| 162 | if (bdf == -1) |
| 163 | { |
| 164 | puts("Unable to find FPGA !\n"); |
| 165 | hang(); |
| 166 | } |
| 167 | |
| 168 | if((in32(pcippc2_fpga0_phys + HW_FPGA0_BOARD) & 0x01000000) == 0x01000000) |
| 169 | /* 32-bits Compact PCI bus - LSB bit */ |
| 170 | { |
| 171 | iobarrier_rw(); |
| 172 | out32(BRIDGE(CPCI, PCIDG), 0x40000000); /* 32-bits bridge, Pipeline */ |
| 173 | iobarrier_rw(); |
| 174 | } |
| 175 | } |
| 176 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 177 | #if defined(CONFIG_WATCHDOG) |
| 178 | |
| 179 | void pcippc2_wdt_init (void) |
| 180 | { |
| 181 | out16r (FPGA (WDT, PROG), 0xffff); |
| 182 | out8 (FPGA (WDT, CTRL), 0x1); |
| 183 | |
| 184 | pcippc2_wdt_init_done = 1; |
| 185 | } |
| 186 | |
| 187 | void pcippc2_wdt_done (void) |
| 188 | { |
| 189 | out8 (FPGA (WDT, CTRL), 0x0); |
| 190 | |
| 191 | pcippc2_wdt_init_done = 0; |
| 192 | } |
| 193 | |
| 194 | void pcippc2_wdt_reset (void) |
| 195 | { |
| 196 | if (pcippc2_wdt_init_done == 1) |
| 197 | out8 (FPGA (WDT, REFRESH), 0x56); |
| 198 | } |
| 199 | |
| 200 | void watchdog_reset (void) |
| 201 | { |
| 202 | int re_enable = disable_interrupts (); |
| 203 | |
| 204 | pcippc2_wdt_reset (); |
| 205 | if (re_enable) |
| 206 | enable_interrupts (); |
| 207 | } |
| 208 | |
Jon Loeliger | 145318c | 2007-07-09 18:38:39 -0500 | [diff] [blame] | 209 | #if defined(CONFIG_CMD_BSP) |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 210 | int do_wd (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 211 | { |
| 212 | switch (argc) { |
| 213 | case 1: |
| 214 | printf ("Watchdog timer status is %s\n", |
| 215 | pcippc2_wdt_init_done == 1 ? "on" : "off"); |
| 216 | |
| 217 | return 0; |
| 218 | case 2: |
| 219 | if (!strcmp(argv[1],"on")) { |
| 220 | pcippc2_wdt_init(); |
| 221 | printf("Watchdog timer now is on\n"); |
| 222 | |
| 223 | return 0; |
| 224 | |
| 225 | } else if (!strcmp(argv[1],"off")) { |
| 226 | pcippc2_wdt_done(); |
| 227 | printf("Watchdog timer now is off\n"); |
| 228 | |
| 229 | return 0; |
| 230 | |
| 231 | } else |
| 232 | break; |
| 233 | default: |
| 234 | break; |
| 235 | } |
Wolfgang Denk | 3b68311 | 2010-07-17 01:06:04 +0200 | [diff] [blame] | 236 | return cmd_usage(cmdtp); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 237 | } |
| 238 | |
wdenk | f287a24 | 2003-07-01 21:06:45 +0000 | [diff] [blame] | 239 | U_BOOT_CMD( |
| 240 | wd, 2, 1, do_wd, |
Peter Tyser | dfb72b8 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 241 | "check and set watchdog", |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 242 | "on - switch watchDog on\n" |
| 243 | "wd off - switch watchdog off\n" |
Wolfgang Denk | c54781c | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 244 | "wd - print current status" |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 245 | ); |
| 246 | |
Jon Loeliger | 761ea74 | 2007-07-10 10:48:22 -0500 | [diff] [blame] | 247 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 248 | #endif /* CONFIG_WATCHDOG */ |
Ben Warren | 840f8a5 | 2008-08-31 10:45:44 -0700 | [diff] [blame] | 249 | |
| 250 | int board_eth_init(bd_t *bis) |
| 251 | { |
| 252 | return pci_eth_init(bis); |
| 253 | } |