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