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 | * |
| 11 | * See file CREDITS for list of people who contributed to this |
| 12 | * project. |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License as |
| 16 | * published by the Free Software Foundation; either version 2 of |
| 17 | * the License, or (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 27 | * MA 02111-1307 USA |
| 28 | */ |
| 29 | |
| 30 | #include <common.h> |
| 31 | #include <mpc5xxx.h> |
| 32 | #include <malloc.h> |
| 33 | #include <pci.h> |
| 34 | #include <i2c.h> |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 35 | #include <fpga.h> |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 36 | #include <environment.h> |
| 37 | #include <fdt_support.h> |
Ben Warren | cba8851 | 2008-08-31 10:39:12 -0700 | [diff] [blame] | 38 | #include <netdev.h> |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 39 | #include <asm/io.h> |
| 40 | #include "fpga.h" |
| 41 | #include "mvbc_p.h" |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 42 | #include "../common/mv_common.h" |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 43 | |
| 44 | #define SDRAM_MODE 0x00CD0000 |
| 45 | #define SDRAM_CONTROL 0x504F0000 |
| 46 | #define SDRAM_CONFIG1 0xD2322800 |
| 47 | #define SDRAM_CONFIG2 0x8AD70000 |
| 48 | |
| 49 | DECLARE_GLOBAL_DATA_PTR; |
| 50 | |
| 51 | static void sdram_start (int hi_addr) |
| 52 | { |
| 53 | long hi_bit = hi_addr ? 0x01000000 : 0; |
| 54 | |
| 55 | /* unlock mode register */ |
| 56 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000000 | hi_bit); |
| 57 | |
| 58 | /* precharge all banks */ |
| 59 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit); |
| 60 | |
| 61 | /* precharge all banks */ |
| 62 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit); |
| 63 | |
| 64 | /* auto refresh */ |
| 65 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000004 | hi_bit); |
| 66 | |
| 67 | /* set mode register */ |
| 68 | out_be32((u32*)MPC5XXX_SDRAM_MODE, SDRAM_MODE); |
| 69 | |
| 70 | /* normal operation */ |
| 71 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | hi_bit); |
| 72 | } |
| 73 | |
| 74 | phys_addr_t initdram (int board_type) |
| 75 | { |
| 76 | ulong dramsize = 0; |
| 77 | ulong test1, |
| 78 | test2; |
| 79 | |
| 80 | /* setup SDRAM chip selects */ |
| 81 | out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x0000001e); |
| 82 | |
| 83 | /* setup config registers */ |
| 84 | out_be32((u32*)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1); |
| 85 | out_be32((u32*)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2); |
| 86 | |
| 87 | /* find RAM size using SDRAM CS0 only */ |
| 88 | sdram_start(0); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 89 | test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 90 | sdram_start(1); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 91 | test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x80000000); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 92 | if (test1 > test2) { |
| 93 | sdram_start(0); |
| 94 | dramsize = test1; |
| 95 | } else |
| 96 | dramsize = test2; |
| 97 | |
| 98 | if (dramsize < (1 << 20)) |
| 99 | dramsize = 0; |
| 100 | |
| 101 | if (dramsize > 0) |
| 102 | out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x13 + |
| 103 | __builtin_ffs(dramsize >> 20) - 1); |
| 104 | else |
| 105 | out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0); |
| 106 | |
| 107 | return dramsize; |
| 108 | } |
| 109 | |
| 110 | void mvbc_init_gpio(void) |
| 111 | { |
| 112 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 113 | |
| 114 | printf("Ports : 0x%08x\n", gpio->port_config); |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 115 | printf("PORCFG: 0x%08lx\n", *(vu_long*)MPC5XXX_CDM_PORCFG); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 116 | |
| 117 | out_be32(&gpio->simple_ddr, SIMPLE_DDR); |
| 118 | out_be32(&gpio->simple_dvo, SIMPLE_DVO); |
| 119 | out_be32(&gpio->simple_ode, SIMPLE_ODE); |
| 120 | out_be32(&gpio->simple_gpioe, SIMPLE_GPIOEN); |
| 121 | |
Andre Schwarz | f6f431d | 2008-08-18 12:02:51 +0200 | [diff] [blame] | 122 | out_8(&gpio->sint_ode, SINT_ODE); |
| 123 | out_8(&gpio->sint_ddr, SINT_DDR); |
| 124 | out_8(&gpio->sint_dvo, SINT_DVO); |
| 125 | out_8(&gpio->sint_inten, SINT_INTEN); |
| 126 | out_be16(&gpio->sint_itype, SINT_ITYPE); |
| 127 | out_8(&gpio->sint_gpioe, SINT_GPIOEN); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 128 | |
| 129 | out_8((u8*)MPC5XXX_WU_GPIO_ODE, WKUP_ODE); |
| 130 | out_8((u8*)MPC5XXX_WU_GPIO_DIR, WKUP_DIR); |
| 131 | out_8((u8*)MPC5XXX_WU_GPIO_DATA_O, WKUP_DO); |
| 132 | out_8((u8*)MPC5XXX_WU_GPIO_ENABLE, WKUP_EN); |
| 133 | |
| 134 | printf("simple_gpioe: 0x%08x\n", gpio->simple_gpioe); |
| 135 | printf("sint_gpioe : 0x%08x\n", gpio->sint_gpioe); |
| 136 | } |
| 137 | |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 138 | int misc_init_r(void) |
| 139 | { |
| 140 | char *s = getenv("reset_env"); |
| 141 | |
| 142 | if (!s) { |
| 143 | if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6) |
| 144 | return 0; |
| 145 | udelay(50000); |
| 146 | if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6) |
| 147 | return 0; |
| 148 | udelay(50000); |
| 149 | if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6) |
| 150 | return 0; |
| 151 | } |
| 152 | printf(" === FACTORY RESET ===\n"); |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 153 | mv_reset_environment(); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 154 | saveenv(); |
| 155 | |
| 156 | return -1; |
| 157 | } |
| 158 | |
| 159 | int checkboard(void) |
| 160 | { |
| 161 | mvbc_init_gpio(); |
| 162 | printf("Board: Matrix Vision mvBlueCOUGAR-P\n"); |
| 163 | |
| 164 | return 0; |
| 165 | } |
| 166 | |
| 167 | void flash_preinit(void) |
| 168 | { |
| 169 | /* |
| 170 | * Now, when we are in RAM, enable flash write |
| 171 | * access for detection process. |
| 172 | * Note that CS_BOOT cannot be cleared when |
| 173 | * executing in flash. |
| 174 | */ |
| 175 | clrbits_be32((u32*)MPC5XXX_BOOTCS_CFG, 0x1); |
| 176 | } |
| 177 | |
| 178 | void flash_afterinit(ulong size) |
| 179 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 180 | out_be32((u32*)MPC5XXX_BOOTCS_START, START_REG(CONFIG_SYS_BOOTCS_START | |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 181 | size)); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 182 | out_be32((u32*)MPC5XXX_CS0_START, START_REG(CONFIG_SYS_BOOTCS_START | |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 183 | size)); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 184 | 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] | 185 | size)); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 186 | 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] | 187 | size)); |
| 188 | } |
| 189 | |
| 190 | void pci_mvbc_fixup_irq(struct pci_controller *hose, pci_dev_t dev) |
| 191 | { |
| 192 | unsigned char line = 0xff; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 193 | char *s = getenv("pci_latency"); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 194 | u32 base; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 195 | u8 val = 0; |
| 196 | |
| 197 | if (s) |
| 198 | val = simple_strtoul(s, NULL, 16); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 199 | |
| 200 | if (PCI_BUS(dev) == 0) { |
| 201 | switch (PCI_DEV (dev)) { |
| 202 | case 0xa: /* FPGA */ |
| 203 | line = 3; |
| 204 | pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &base); |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 205 | printf("found FPGA - enable arbitration\n"); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 206 | writel(0x03, (u32*)(base + 0x80c0)); |
| 207 | writel(0xf0, (u32*)(base + 0x8080)); |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 208 | if (val) |
| 209 | pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, val); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 210 | break; |
| 211 | case 0xb: /* LAN */ |
| 212 | line = 2; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 213 | if (val) |
| 214 | pci_hose_write_config_byte(hose, dev, PCI_LATENCY_TIMER, val); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 215 | break; |
| 216 | case 0x1a: |
| 217 | break; |
| 218 | default: |
| 219 | printf ("***pci_scan: illegal dev = 0x%08x\n", PCI_DEV (dev)); |
| 220 | break; |
| 221 | } |
| 222 | pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, line); |
| 223 | } |
| 224 | } |
| 225 | |
| 226 | struct pci_controller hose = { |
| 227 | fixup_irq:pci_mvbc_fixup_irq |
| 228 | }; |
| 229 | |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 230 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 231 | |
| 232 | void pci_init_board(void) |
| 233 | { |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 234 | mvbc_p_init_fpga(); |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 235 | mv_load_fpga(); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 236 | pci_mpc5xxx_init(&hose); |
| 237 | } |
| 238 | |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 239 | void show_boot_progress(int val) |
| 240 | { |
| 241 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 242 | |
| 243 | switch(val) { |
Simon Glass | 53624e0 | 2012-01-14 15:24:47 +0000 | [diff] [blame] | 244 | case BOOTSTAGE_ID_START: /* FPGA ok */ |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 245 | setbits_be32(&gpio->simple_dvo, LED_G0); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 246 | break; |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 247 | case 65: |
| 248 | setbits_be32(&gpio->simple_dvo, LED_G1); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 249 | break; |
Simon Glass | 3038f80 | 2011-12-10 11:07:57 +0000 | [diff] [blame^] | 250 | case BOOTSTAGE_ID_COPY_RAMDISK: |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 251 | setbits_be32(&gpio->simple_dvo, LED_Y); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 252 | break; |
Simon Glass | 2939564 | 2011-12-10 11:07:54 +0000 | [diff] [blame] | 253 | case BOOTSTAGE_ID_RUN_OS: |
André Schwarz | a8e1d95 | 2009-08-27 14:48:35 +0200 | [diff] [blame] | 254 | setbits_be32(&gpio->simple_dvo, LED_R); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 255 | break; |
| 256 | default: |
| 257 | break; |
| 258 | } |
| 259 | |
| 260 | } |
| 261 | |
| 262 | void ft_board_setup(void *blob, bd_t *bd) |
| 263 | { |
| 264 | ft_cpu_setup(blob, bd); |
Andre Schwarz | 2a29329 | 2008-07-09 18:30:44 +0200 | [diff] [blame] | 265 | } |
Ben Warren | cba8851 | 2008-08-31 10:39:12 -0700 | [diff] [blame] | 266 | |
| 267 | int board_eth_init(bd_t *bis) |
| 268 | { |
Ben Warren | 050019d | 2008-08-31 10:44:19 -0700 | [diff] [blame] | 269 | cpu_eth_init(bis); /* Built in FEC comes first */ |
| 270 | return pci_eth_init(bis); |
Ben Warren | cba8851 | 2008-08-31 10:39:12 -0700 | [diff] [blame] | 271 | } |