Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2008 |
| 3 | * Graeme Russ, graeme.russ@gmail.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 | */ |
| 23 | |
| 24 | #include <common.h> |
| 25 | #include <asm/io.h> |
| 26 | #include <asm/ic/sc520.h> |
Graeme Russ | 8fd8056 | 2010-04-24 00:05:55 +1000 | [diff] [blame] | 27 | #include <net.h> |
| 28 | #include <netdev.h> |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 29 | |
| 30 | #ifdef CONFIG_HW_WATCHDOG |
| 31 | #include <watchdog.h> |
| 32 | #endif |
| 33 | |
| 34 | #include "hardware.h" |
| 35 | |
| 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
| 38 | #undef SC520_CDP_DEBUG |
| 39 | |
| 40 | #ifdef SC520_CDP_DEBUG |
| 41 | #define PRINTF(fmt,args...) printf (fmt ,##args) |
| 42 | #else |
| 43 | #define PRINTF(fmt,args...) |
| 44 | #endif |
| 45 | |
| 46 | unsigned long monitor_flash_len = CONFIG_SYS_MONITOR_LEN; |
| 47 | |
Graeme Russ | 880c59e | 2010-04-24 00:05:58 +1000 | [diff] [blame] | 48 | static void enet_timer_isr(void); |
| 49 | static void enet_toggle_run_led(void); |
Graeme Russ | c083e4b | 2011-02-12 15:11:47 +1100 | [diff] [blame^] | 50 | static void enet_setup_pars(void); |
Graeme Russ | 880c59e | 2010-04-24 00:05:58 +1000 | [diff] [blame] | 51 | |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 52 | /* |
| 53 | * Miscellaneous platform dependent initializations |
| 54 | */ |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 55 | int board_early_init_f(void) |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 56 | { |
Graeme Russ | 420c7c0 | 2011-02-12 15:11:45 +1100 | [diff] [blame] | 57 | u16 pio_out_cfg = 0x0000; |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 58 | |
Graeme Russ | 420c7c0 | 2011-02-12 15:11:45 +1100 | [diff] [blame] | 59 | /* Configure General Purpose Bus timing */ |
| 60 | writeb(CONFIG_SYS_SC520_GPCSRT, &sc520_mmcr->gpcsrt); |
| 61 | writeb(CONFIG_SYS_SC520_GPCSPW, &sc520_mmcr->gpcspw); |
| 62 | writeb(CONFIG_SYS_SC520_GPCSOFF, &sc520_mmcr->gpcsoff); |
| 63 | writeb(CONFIG_SYS_SC520_GPRDW, &sc520_mmcr->gprdw); |
| 64 | writeb(CONFIG_SYS_SC520_GPRDOFF, &sc520_mmcr->gprdoff); |
| 65 | writeb(CONFIG_SYS_SC520_GPWRW, &sc520_mmcr->gpwrw); |
| 66 | writeb(CONFIG_SYS_SC520_GPWROFF, &sc520_mmcr->gpwroff); |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 67 | |
Graeme Russ | 420c7c0 | 2011-02-12 15:11:45 +1100 | [diff] [blame] | 68 | /* Configure Programmable Input/Output Pins */ |
| 69 | writew(CONFIG_SYS_SC520_PIODIR15_0, &sc520_mmcr->piodir15_0); |
| 70 | writew(CONFIG_SYS_SC520_PIODIR31_16, &sc520_mmcr->piodir31_16); |
| 71 | writew(CONFIG_SYS_SC520_PIOPFS31_16, &sc520_mmcr->piopfs31_16); |
| 72 | writew(CONFIG_SYS_SC520_PIOPFS15_0, &sc520_mmcr->piopfs15_0); |
| 73 | writeb(CONFIG_SYS_SC520_CSPFS, &sc520_mmcr->cspfs); |
| 74 | writeb(CONFIG_SYS_SC520_CLKSEL, &sc520_mmcr->clksel); |
| 75 | |
| 76 | /* |
| 77 | * Turn off top board |
| 78 | * Set StrataFlash chips to 16-bit width |
| 79 | * Set StrataFlash chips to normal (non reset/power down) mode |
| 80 | */ |
| 81 | pio_out_cfg |= CONFIG_SYS_ENET_TOP_BRD_PWR; |
| 82 | pio_out_cfg |= CONFIG_SYS_ENET_SF_WIDTH; |
| 83 | pio_out_cfg |= CONFIG_SYS_ENET_SF1_MODE; |
| 84 | pio_out_cfg |= CONFIG_SYS_ENET_SF2_MODE; |
| 85 | writew(pio_out_cfg, &sc520_mmcr->pioset15_0); |
| 86 | |
| 87 | /* Turn off auxiliary power output */ |
| 88 | writew(CONFIG_SYS_ENET_AUX_PWR, &sc520_mmcr->pioclr15_0); |
| 89 | |
| 90 | /* Clear FPGA program mode */ |
| 91 | writew(CONFIG_SYS_ENET_FPGA_PROG, &sc520_mmcr->pioset31_16); |
| 92 | |
Graeme Russ | c083e4b | 2011-02-12 15:11:47 +1100 | [diff] [blame^] | 93 | enet_setup_pars(); |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 94 | |
| 95 | /* Disable Watchdog */ |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 96 | writew(0x3333, &sc520_mmcr->wdtmrctl); |
| 97 | writew(0xcccc, &sc520_mmcr->wdtmrctl); |
| 98 | writew(0x0000, &sc520_mmcr->wdtmrctl); |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 99 | |
| 100 | /* Chip Select Configuration */ |
Graeme Russ | 420c7c0 | 2011-02-12 15:11:45 +1100 | [diff] [blame] | 101 | writew(CONFIG_SYS_SC520_BOOTCS_CTRL, &sc520_mmcr->bootcsctl); |
| 102 | writew(CONFIG_SYS_SC520_ROMCS1_CTRL, &sc520_mmcr->romcs1ctl); |
| 103 | writew(CONFIG_SYS_SC520_ROMCS2_CTRL, &sc520_mmcr->romcs2ctl); |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 104 | |
Graeme Russ | 420c7c0 | 2011-02-12 15:11:45 +1100 | [diff] [blame] | 105 | writeb(CONFIG_SYS_SC520_ADDDECCTL, &sc520_mmcr->adddecctl); |
| 106 | writeb(CONFIG_SYS_SC520_UART1CTL, &sc520_mmcr->uart1ctl); |
| 107 | writeb(CONFIG_SYS_SC520_UART2CTL, &sc520_mmcr->uart2ctl); |
Graeme Russ | 870847f | 2011-02-12 15:11:38 +1100 | [diff] [blame] | 108 | |
Graeme Russ | 420c7c0 | 2011-02-12 15:11:45 +1100 | [diff] [blame] | 109 | writeb(CONFIG_SYS_SC520_SYSARBCTL, &sc520_mmcr->sysarbctl); |
| 110 | writew(CONFIG_SYS_SC520_SYSARBMENB, &sc520_mmcr->sysarbmenb); |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 111 | |
Graeme Russ | 870847f | 2011-02-12 15:11:38 +1100 | [diff] [blame] | 112 | /* enable posted-writes */ |
Graeme Russ | 420c7c0 | 2011-02-12 15:11:45 +1100 | [diff] [blame] | 113 | writeb(CONFIG_SYS_SC520_HBCTL, &sc520_mmcr->hbctl); |
Graeme Russ | 870847f | 2011-02-12 15:11:38 +1100 | [diff] [blame] | 114 | |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
Graeme Russ | c083e4b | 2011-02-12 15:11:47 +1100 | [diff] [blame^] | 118 | static void enet_setup_pars(void) |
| 119 | { |
| 120 | /* |
| 121 | * PARs 11 and 12 are 2MB SRAM @ 0x19000000 |
| 122 | * |
| 123 | * These are setup now because older version of U-Boot have them |
| 124 | * mapped to a different PAR which gets clobbered which prevents |
| 125 | * using SRAM for warm-booting a new image |
| 126 | */ |
| 127 | writel(CONFIG_SYS_SC520_SRAM1_PAR, &sc520_mmcr->par[11]); |
| 128 | writel(CONFIG_SYS_SC520_SRAM2_PAR, &sc520_mmcr->par[12]); |
| 129 | |
| 130 | /* PARs 0 and 1 are Compact Flash slots (4kB each) */ |
| 131 | writel(CONFIG_SYS_SC520_CF1_PAR, &sc520_mmcr->par[0]); |
| 132 | writel(CONFIG_SYS_SC520_CF2_PAR, &sc520_mmcr->par[1]); |
| 133 | |
| 134 | /* PAR 2 is used for Cache-As-RAM */ |
| 135 | |
| 136 | /* |
| 137 | * PARs 5 through 8 are additional NS16550 UARTS |
| 138 | * 8 bytes each @ 0x013f8, 0x012f8, 0x011f8 and 0x010f8 |
| 139 | */ |
| 140 | writel(CONFIG_SYS_SC520_UARTA_PAR, &sc520_mmcr->par[5]); |
| 141 | writel(CONFIG_SYS_SC520_UARTB_PAR, &sc520_mmcr->par[6]); |
| 142 | writel(CONFIG_SYS_SC520_UARTC_PAR, &sc520_mmcr->par[7]); |
| 143 | writel(CONFIG_SYS_SC520_UARTD_PAR, &sc520_mmcr->par[8]); |
| 144 | |
| 145 | /* PARs 9 and 10 are 32MB StrataFlash @ 0x10000000 */ |
| 146 | writel(CONFIG_SYS_SC520_SF1_PAR, &sc520_mmcr->par[9]); |
| 147 | writel(CONFIG_SYS_SC520_SF2_PAR, &sc520_mmcr->par[10]); |
| 148 | |
| 149 | /* PAR 13 is 4kB DPRAM @ 0x18100000 (implemented in FPGA) */ |
| 150 | writel(CONFIG_SYS_SC520_DPRAM_PAR, &sc520_mmcr->par[13]); |
| 151 | |
| 152 | /* |
| 153 | * PAR 14 is Low Level I/O (LEDs, Hex Switches etc) |
| 154 | * Already configured in board_init16 (eNET_start16.S) |
| 155 | * |
| 156 | * PAR 15 is Boot ROM |
| 157 | * Already configured in board_init16 (eNET_start16.S) |
| 158 | */ |
| 159 | } |
| 160 | |
| 161 | |
Graeme Russ | 1c409bc | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 162 | int board_early_init_r(void) |
| 163 | { |
| 164 | /* CPU Speed to 100MHz */ |
| 165 | gd->cpu_clk = 100000000; |
| 166 | |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 167 | /* Crystal is 33.000MHz */ |
| 168 | gd->bus_clk = 33000000; |
| 169 | |
| 170 | return 0; |
| 171 | } |
| 172 | |
| 173 | int dram_init(void) |
| 174 | { |
| 175 | init_sc520_dram(); |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | void show_boot_progress(int val) |
| 180 | { |
| 181 | uchar led_mask; |
| 182 | |
| 183 | led_mask = 0x00; |
| 184 | |
| 185 | if (val < 0) |
| 186 | led_mask |= LED_ERR_BITMASK; |
| 187 | |
| 188 | led_mask |= (uchar)(val & 0x001f); |
| 189 | outb(led_mask, LED_LATCH_ADDRESS); |
| 190 | } |
| 191 | |
| 192 | |
| 193 | int last_stage_init(void) |
| 194 | { |
| 195 | int minor; |
| 196 | int major; |
| 197 | |
| 198 | major = minor = 0; |
| 199 | |
Graeme Russ | 880c59e | 2010-04-24 00:05:58 +1000 | [diff] [blame] | 200 | outb(0x00, LED_LATCH_ADDRESS); |
| 201 | |
| 202 | register_timer_isr (enet_timer_isr); |
| 203 | |
Graeme Russ | c620c01 | 2008-12-07 10:28:57 +1100 | [diff] [blame] | 204 | printf("Serck Controls eNET\n"); |
| 205 | |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | ulong board_flash_get_legacy (ulong base, int banknum, flash_info_t * info) |
| 210 | { |
| 211 | if (banknum == 0) { /* non-CFI boot flash */ |
| 212 | info->portwidth = FLASH_CFI_8BIT; |
| 213 | info->chipwidth = FLASH_CFI_BY8; |
| 214 | info->interface = FLASH_CFI_X8; |
| 215 | return 1; |
| 216 | } else |
| 217 | return 0; |
| 218 | } |
Graeme Russ | 8fd8056 | 2010-04-24 00:05:55 +1000 | [diff] [blame] | 219 | |
| 220 | int board_eth_init(bd_t *bis) |
| 221 | { |
| 222 | return pci_eth_init(bis); |
| 223 | } |
Graeme Russ | 4a4c31a | 2010-04-24 00:05:56 +1000 | [diff] [blame] | 224 | |
| 225 | void setup_pcat_compatibility() |
| 226 | { |
| 227 | /* disable global interrupt mode */ |
| 228 | writeb(0x40, &sc520_mmcr->picicr); |
| 229 | |
| 230 | /* set all irqs to edge */ |
| 231 | writeb(0x00, &sc520_mmcr->pic_mode[0]); |
| 232 | writeb(0x00, &sc520_mmcr->pic_mode[1]); |
| 233 | writeb(0x00, &sc520_mmcr->pic_mode[2]); |
| 234 | |
| 235 | /* |
| 236 | * active low polarity on PIC interrupt pins, |
| 237 | * active high polarity on all other irq pins |
| 238 | */ |
| 239 | writew(0x0000,&sc520_mmcr->intpinpol); |
| 240 | |
Graeme Russ | d881ea5 | 2011-02-12 15:11:41 +1100 | [diff] [blame] | 241 | /* |
| 242 | * PIT 0 -> IRQ0 |
| 243 | * RTC -> IRQ8 |
| 244 | * FP error -> IRQ13 |
| 245 | * UART1 -> IRQ4 |
| 246 | * UART2 -> IRQ3 |
| 247 | */ |
Graeme Russ | 4a4c31a | 2010-04-24 00:05:56 +1000 | [diff] [blame] | 248 | writeb(SC520_IRQ0, &sc520_mmcr->pit_int_map[0]); |
| 249 | writeb(SC520_IRQ8, &sc520_mmcr->rtcmap); |
| 250 | writeb(SC520_IRQ13, &sc520_mmcr->ferrmap); |
Graeme Russ | d881ea5 | 2011-02-12 15:11:41 +1100 | [diff] [blame] | 251 | writeb(SC520_IRQ4, &sc520_mmcr->uart_int_map[0]); |
| 252 | writeb(SC520_IRQ3, &sc520_mmcr->uart_int_map[1]); |
Graeme Russ | 4a4c31a | 2010-04-24 00:05:56 +1000 | [diff] [blame] | 253 | |
| 254 | /* Disable all other interrupt sources */ |
| 255 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[0]); |
| 256 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[1]); |
| 257 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->gp_tmr_int_map[2]); |
| 258 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pit_int_map[1]); |
| 259 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->pit_int_map[2]); |
Graeme Russ | 4a4c31a | 2010-04-24 00:05:56 +1000 | [diff] [blame] | 260 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->ssimap); |
| 261 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->wdtmap); |
| 262 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->wpvmap); |
| 263 | writeb(SC520_IRQ_DISABLED, &sc520_mmcr->icemap); |
| 264 | } |
Graeme Russ | 880c59e | 2010-04-24 00:05:58 +1000 | [diff] [blame] | 265 | |
| 266 | void enet_timer_isr(void) |
| 267 | { |
| 268 | static long enet_ticks = 0; |
| 269 | |
| 270 | enet_ticks++; |
| 271 | |
| 272 | /* Toggle Watchdog every 100ms */ |
| 273 | if ((enet_ticks % 100) == 0) |
| 274 | hw_watchdog_reset(); |
| 275 | |
| 276 | /* Toggle Run LED every 500ms */ |
| 277 | if ((enet_ticks % 500) == 0) |
| 278 | enet_toggle_run_led(); |
| 279 | } |
| 280 | |
| 281 | void hw_watchdog_reset(void) |
| 282 | { |
| 283 | /* Watchdog Reset must be atomic */ |
| 284 | long flag = disable_interrupts(); |
| 285 | |
| 286 | if (sc520_mmcr->piodata15_0 & WATCHDOG_PIO_BIT) |
| 287 | sc520_mmcr->pioclr15_0 = WATCHDOG_PIO_BIT; |
| 288 | else |
| 289 | sc520_mmcr->pioset15_0 = WATCHDOG_PIO_BIT; |
| 290 | |
| 291 | if (flag) |
| 292 | enable_interrupts(); |
| 293 | } |
| 294 | |
| 295 | void enet_toggle_run_led(void) |
| 296 | { |
| 297 | unsigned char leds_state= inb(LED_LATCH_ADDRESS); |
| 298 | if (leds_state & LED_RUN_BITMASK) |
| 299 | outb(leds_state &~ LED_RUN_BITMASK, LED_LATCH_ADDRESS); |
| 300 | else |
| 301 | outb(leds_state | LED_RUN_BITMASK, LED_LATCH_ADDRESS); |
| 302 | } |