Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * (C) Copyright 2004 |
| 6 | * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com. |
| 7 | * |
| 8 | * (C) Copyright 2005-2007 |
| 9 | * Andre Schwarz, Matrix Vision GmbH, andre.schwarz@matrix-vision.de |
| 10 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame^] | 11 | * SPDX-License-Identifier: GPL-2.0+ |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 12 | */ |
| 13 | |
| 14 | #include <common.h> |
| 15 | #include <mpc5xxx.h> |
| 16 | #include <malloc.h> |
| 17 | #include <pci.h> |
| 18 | #include <i2c.h> |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 19 | #include <fpga.h> |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 20 | #include <environment.h> |
| 21 | #include <fdt_support.h> |
Ben Warren | cba8851 | 2008-08-31 10:39:12 -0700 | [diff] [blame] | 22 | #include <netdev.h> |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 23 | #include <asm/io.h> |
| 24 | #include "fpga.h" |
| 25 | #include "mvbc_p.h" |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 26 | #include "../common/mv_common.h" |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 27 | |
| 28 | #define SDRAM_MODE 0x00CD0000 |
| 29 | #define SDRAM_CONTROL 0x504F0000 |
| 30 | #define SDRAM_CONFIG1 0xD2322800 |
| 31 | #define SDRAM_CONFIG2 0x8AD70000 |
| 32 | |
| 33 | DECLARE_GLOBAL_DATA_PTR; |
| 34 | |
| 35 | static void sdram_start (int hi_addr) |
| 36 | { |
| 37 | long hi_bit = hi_addr ? 0x01000000 : 0; |
| 38 | |
| 39 | /* unlock mode register */ |
| 40 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000000 | hi_bit); |
| 41 | |
| 42 | /* precharge all banks */ |
| 43 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit); |
| 44 | |
| 45 | /* precharge all banks */ |
| 46 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit); |
| 47 | |
| 48 | /* auto refresh */ |
| 49 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000004 | hi_bit); |
| 50 | |
| 51 | /* set mode register */ |
| 52 | out_be32((u32*)MPC5XXX_SDRAM_MODE, SDRAM_MODE); |
| 53 | |
| 54 | /* normal operation */ |
| 55 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | hi_bit); |
| 56 | } |
| 57 | |
| 58 | phys_addr_t initdram (int board_type) |
| 59 | { |
| 60 | ulong dramsize = 0; |
| 61 | ulong test1, |
| 62 | test2; |
| 63 | |
| 64 | /* setup SDRAM chip selects */ |
| 65 | out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x0000001e); |
| 66 | |
| 67 | /* setup config registers */ |
| 68 | out_be32((u32*)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1); |
| 69 | out_be32((u32*)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2); |
| 70 | |
| 71 | /* find RAM size using SDRAM CS0 only */ |
| 72 | sdram_start(0); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 74 | sdram_start(1); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 75 | test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 76 | if (test1 > test2) { |
| 77 | sdram_start(0); |
| 78 | dramsize = test1; |
| 79 | } else |
| 80 | dramsize = test2; |
| 81 | |
| 82 | if (dramsize < (1 << 20)) |
| 83 | dramsize = 0; |
| 84 | |
| 85 | if (dramsize > 0) |
| 86 | out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x13 + |
| 87 | __builtin_ffs(dramsize >> 20) - 1); |
| 88 | else |
| 89 | out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0); |
| 90 | |
| 91 | return dramsize; |
| 92 | } |
| 93 | |
| 94 | void mvbc_init_gpio(void) |
| 95 | { |
| 96 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 97 | |
| 98 | printf("Ports : 0x%08x\n", gpio->port_config); |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 99 | printf("PORCFG: 0x%08lx\n", *(vu_long*)MPC5XXX_CDM_PORCFG); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 100 | |
| 101 | out_be32(&gpio->simple_ddr, SIMPLE_DDR); |
| 102 | out_be32(&gpio->simple_dvo, SIMPLE_DVO); |
| 103 | out_be32(&gpio->simple_ode, SIMPLE_ODE); |
| 104 | out_be32(&gpio->simple_gpioe, SIMPLE_GPIOEN); |
| 105 | |
Andre Schwarz | f6f431d | 2008-08-18 12:02:51 +0200 | [diff] [blame] | 106 | out_8(&gpio->sint_ode, SINT_ODE); |
| 107 | out_8(&gpio->sint_ddr, SINT_DDR); |
| 108 | out_8(&gpio->sint_dvo, SINT_DVO); |
| 109 | out_8(&gpio->sint_inten, SINT_INTEN); |
| 110 | out_be16(&gpio->sint_itype, SINT_ITYPE); |
| 111 | out_8(&gpio->sint_gpioe, SINT_GPIOEN); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 112 | |
| 113 | out_8((u8*)MPC5XXX_WU_GPIO_ODE, WKUP_ODE); |
| 114 | out_8((u8*)MPC5XXX_WU_GPIO_DIR, WKUP_DIR); |
| 115 | out_8((u8*)MPC5XXX_WU_GPIO_DATA_O, WKUP_DO); |
| 116 | out_8((u8*)MPC5XXX_WU_GPIO_ENABLE, WKUP_EN); |
| 117 | |
| 118 | printf("simple_gpioe: 0x%08x\n", gpio->simple_gpioe); |
| 119 | printf("sint_gpioe : 0x%08x\n", gpio->sint_gpioe); |
| 120 | } |
| 121 | |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 122 | int misc_init_r(void) |
| 123 | { |
| 124 | char *s = getenv("reset_env"); |
| 125 | |
| 126 | if (!s) { |
| 127 | if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6) |
| 128 | return 0; |
| 129 | udelay(50000); |
| 130 | if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6) |
| 131 | return 0; |
| 132 | udelay(50000); |
| 133 | if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6) |
| 134 | return 0; |
| 135 | } |
| 136 | printf(" === FACTORY RESET ===\n"); |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 137 | mv_reset_environment(); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 138 | saveenv(); |
| 139 | |
| 140 | return -1; |
| 141 | } |
| 142 | |
| 143 | int checkboard(void) |
| 144 | { |
| 145 | mvbc_init_gpio(); |
| 146 | printf("Board: Matrix Vision mvBlueCOUGAR-P\n"); |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | void flash_preinit(void) |
| 152 | { |
| 153 | /* |
| 154 | * Now, when we are in RAM, enable flash write |
| 155 | * access for detection process. |
| 156 | * Note that CS_BOOT cannot be cleared when |
| 157 | * executing in flash. |
| 158 | */ |
| 159 | clrbits_be32((u32*)MPC5XXX_BOOTCS_CFG, 0x1); |
| 160 | } |
| 161 | |
| 162 | void flash_afterinit(ulong size) |
| 163 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 164 | out_be32((u32*)MPC5XXX_BOOTCS_START, START_REG(CONFIG_SYS_BOOTCS_START | |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 165 | size)); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 166 | out_be32((u32*)MPC5XXX_CS0_START, START_REG(CONFIG_SYS_BOOTCS_START | |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 167 | size)); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 168 | out_be32((u32*)MPC5XXX_BOOTCS_STOP, STOP_REG(CONFIG_SYS_BOOTCS_START | size, |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 169 | size)); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 170 | out_be32((u32*)MPC5XXX_CS0_STOP, STOP_REG(CONFIG_SYS_BOOTCS_START | size, |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 171 | size)); |
| 172 | } |
| 173 | |
| 174 | void pci_mvbc_fixup_irq(struct pci_controller *hose, pci_dev_t dev) |
| 175 | { |
| 176 | unsigned char line = 0xff; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 177 | char *s = getenv("pci_latency"); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 178 | u32 base; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 179 | u8 val = 0; |
| 180 | |
| 181 | if (s) |
| 182 | val = simple_strtoul(s, NULL, 16); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 183 | |
| 184 | if (PCI_BUS(dev) == 0) { |
| 185 | switch (PCI_DEV (dev)) { |
| 186 | case 0xa: /* FPGA */ |
| 187 | line = 3; |
| 188 | pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &base); |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 189 | printf("found FPGA - enable arbitration\n"); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 190 | writel(0x03, (u32*)(base + 0x80c0)); |
| 191 | writel(0xf0, (u32*)(base + 0x8080)); |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 192 | if (val) |
| 193 | pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, val); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 194 | break; |
| 195 | case 0xb: /* LAN */ |
| 196 | line = 2; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 197 | if (val) |
| 198 | pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, val); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 199 | break; |
| 200 | case 0x1a: |
| 201 | break; |
| 202 | default: |
| 203 | printf ("***pci_scan: illegal dev = 0x%08x\n", PCI_DEV (dev)); |
| 204 | break; |
| 205 | } |
| 206 | pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, line); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | struct pci_controller hose = { |
| 211 | fixup_irq:pci_mvbc_fixup_irq |
| 212 | }; |
| 213 | |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 214 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 215 | |
| 216 | void pci_init_board(void) |
| 217 | { |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 218 | mvbc_p_init_fpga(); |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 219 | mv_load_fpga(); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 220 | pci_mpc5xxx_init(&hose); |
| 221 | } |
| 222 | |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 223 | void show_boot_progress(int val) |
| 224 | { |
| 225 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 226 | |
| 227 | switch(val) { |
Simon Glass | 53624e0 | 2012-01-14 15:24:47 +0000 | [diff] [blame] | 228 | case BOOTSTAGE_ID_START: /* FPGA ok */ |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 229 | setbits_be32(&gpio->simple_dvo, LED_G0); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 230 | break; |
Simon Glass | 964d1d4 | 2012-01-14 15:24:52 +0000 | [diff] [blame] | 231 | case BOOTSTAGE_ID_NET_ETH_INIT: |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 232 | setbits_be32(&gpio->simple_dvo, LED_G1); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 233 | break; |
Simon Glass | 3038f80 | 2011-12-10 11:07:57 +0000 | [diff] [blame] | 234 | case BOOTSTAGE_ID_COPY_RAMDISK: |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 235 | setbits_be32(&gpio->simple_dvo, LED_Y); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 236 | break; |
Simon Glass | 2939564 | 2011-12-10 11:07:54 +0000 | [diff] [blame] | 237 | case BOOTSTAGE_ID_RUN_OS: |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 238 | setbits_be32(&gpio->simple_dvo, LED_R); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 239 | break; |
| 240 | default: |
| 241 | break; |
| 242 | } |
| 243 | |
| 244 | } |
| 245 | |
| 246 | void ft_board_setup(void *blob, bd_t *bd) |
| 247 | { |
| 248 | ft_cpu_setup(blob, bd); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 249 | } |
Ben Warren | cba8851 | 2008-08-31 10:39:12 -0700 | [diff] [blame] | 250 | |
| 251 | int board_eth_init(bd_t *bis) |
| 252 | { |
Ben Warren | 050019d | 2008-08-31 10:44:19 -0700 | [diff] [blame] | 253 | cpu_eth_init(bis); /* Built in FEC comes first */ |
| 254 | return pci_eth_init(bis); |
Ben Warren | cba8851 | 2008-08-31 10:39:12 -0700 | [diff] [blame] | 255 | } |