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> |
| 35 | #include <environment.h> |
| 36 | #include <fdt_support.h> |
| 37 | #include <asm/io.h> |
| 38 | #include "fpga.h" |
| 39 | #include "mvbc_p.h" |
| 40 | |
| 41 | #define SDRAM_MODE 0x00CD0000 |
| 42 | #define SDRAM_CONTROL 0x504F0000 |
| 43 | #define SDRAM_CONFIG1 0xD2322800 |
| 44 | #define SDRAM_CONFIG2 0x8AD70000 |
| 45 | |
| 46 | DECLARE_GLOBAL_DATA_PTR; |
| 47 | |
| 48 | static void sdram_start (int hi_addr) |
| 49 | { |
| 50 | long hi_bit = hi_addr ? 0x01000000 : 0; |
| 51 | |
| 52 | /* unlock mode register */ |
| 53 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000000 | hi_bit); |
| 54 | |
| 55 | /* precharge all banks */ |
| 56 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit); |
| 57 | |
| 58 | /* precharge all banks */ |
| 59 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000002 | hi_bit); |
| 60 | |
| 61 | /* auto refresh */ |
| 62 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | 0x80000004 | hi_bit); |
| 63 | |
| 64 | /* set mode register */ |
| 65 | out_be32((u32*)MPC5XXX_SDRAM_MODE, SDRAM_MODE); |
| 66 | |
| 67 | /* normal operation */ |
| 68 | out_be32((u32*)MPC5XXX_SDRAM_CTRL, SDRAM_CONTROL | hi_bit); |
| 69 | } |
| 70 | |
| 71 | phys_addr_t initdram (int board_type) |
| 72 | { |
| 73 | ulong dramsize = 0; |
| 74 | ulong test1, |
| 75 | test2; |
| 76 | |
| 77 | /* setup SDRAM chip selects */ |
| 78 | out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x0000001e); |
| 79 | |
| 80 | /* setup config registers */ |
| 81 | out_be32((u32*)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1); |
| 82 | out_be32((u32*)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2); |
| 83 | |
| 84 | /* find RAM size using SDRAM CS0 only */ |
| 85 | sdram_start(0); |
| 86 | test1 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000); |
| 87 | sdram_start(1); |
| 88 | test2 = get_ram_size((long *)CFG_SDRAM_BASE, 0x80000000); |
| 89 | if (test1 > test2) { |
| 90 | sdram_start(0); |
| 91 | dramsize = test1; |
| 92 | } else |
| 93 | dramsize = test2; |
| 94 | |
| 95 | if (dramsize < (1 << 20)) |
| 96 | dramsize = 0; |
| 97 | |
| 98 | if (dramsize > 0) |
| 99 | out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0x13 + |
| 100 | __builtin_ffs(dramsize >> 20) - 1); |
| 101 | else |
| 102 | out_be32((u32*)MPC5XXX_SDRAM_CS0CFG, 0); |
| 103 | |
| 104 | return dramsize; |
| 105 | } |
| 106 | |
| 107 | void mvbc_init_gpio(void) |
| 108 | { |
| 109 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 110 | |
| 111 | printf("Ports : 0x%08x\n", gpio->port_config); |
| 112 | printf("PORCFG: 0x%08x\n", *(vu_long*)MPC5XXX_CDM_PORCFG); |
| 113 | |
| 114 | out_be32(&gpio->simple_ddr, SIMPLE_DDR); |
| 115 | out_be32(&gpio->simple_dvo, SIMPLE_DVO); |
| 116 | out_be32(&gpio->simple_ode, SIMPLE_ODE); |
| 117 | out_be32(&gpio->simple_gpioe, SIMPLE_GPIOEN); |
| 118 | |
| 119 | out_be32((u32*)&gpio->sint_ode, SINT_ODE); |
| 120 | out_be32((u32*)&gpio->sint_ddr, SINT_DDR); |
| 121 | out_be32((u32*)&gpio->sint_dvo, SINT_DVO); |
| 122 | out_be32((u32*)&gpio->sint_inten, SINT_INTEN); |
| 123 | out_be32((u32*)&gpio->sint_itype, SINT_ITYPE); |
| 124 | out_be32((u32*)&gpio->sint_gpioe, SINT_GPIOEN); |
| 125 | |
| 126 | out_8((u8*)MPC5XXX_WU_GPIO_ODE, WKUP_ODE); |
| 127 | out_8((u8*)MPC5XXX_WU_GPIO_DIR, WKUP_DIR); |
| 128 | out_8((u8*)MPC5XXX_WU_GPIO_DATA_O, WKUP_DO); |
| 129 | out_8((u8*)MPC5XXX_WU_GPIO_ENABLE, WKUP_EN); |
| 130 | |
| 131 | printf("simple_gpioe: 0x%08x\n", gpio->simple_gpioe); |
| 132 | printf("sint_gpioe : 0x%08x\n", gpio->sint_gpioe); |
| 133 | } |
| 134 | |
| 135 | void reset_environment(void) |
| 136 | { |
| 137 | char *s, sernr[64]; |
| 138 | |
| 139 | printf("\n*** RESET ENVIRONMENT ***\n"); |
| 140 | memset(sernr, 0, sizeof(sernr)); |
| 141 | s = getenv("serial#"); |
| 142 | if (s) { |
| 143 | printf("found serial# : %s\n", s); |
| 144 | strncpy(sernr, s, 64); |
| 145 | } |
| 146 | gd->env_valid = 0; |
| 147 | env_relocate(); |
| 148 | if (s) |
| 149 | setenv("serial#", sernr); |
| 150 | } |
| 151 | |
| 152 | int misc_init_r(void) |
| 153 | { |
| 154 | char *s = getenv("reset_env"); |
| 155 | |
| 156 | if (!s) { |
| 157 | if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6) |
| 158 | return 0; |
| 159 | udelay(50000); |
| 160 | if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6) |
| 161 | return 0; |
| 162 | udelay(50000); |
| 163 | if (in_8((u8*)MPC5XXX_WU_GPIO_DATA_I) & MPC5XXX_GPIO_WKUP_6) |
| 164 | return 0; |
| 165 | } |
| 166 | printf(" === FACTORY RESET ===\n"); |
| 167 | reset_environment(); |
| 168 | saveenv(); |
| 169 | |
| 170 | return -1; |
| 171 | } |
| 172 | |
| 173 | int checkboard(void) |
| 174 | { |
| 175 | mvbc_init_gpio(); |
| 176 | printf("Board: Matrix Vision mvBlueCOUGAR-P\n"); |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
| 181 | void flash_preinit(void) |
| 182 | { |
| 183 | /* |
| 184 | * Now, when we are in RAM, enable flash write |
| 185 | * access for detection process. |
| 186 | * Note that CS_BOOT cannot be cleared when |
| 187 | * executing in flash. |
| 188 | */ |
| 189 | clrbits_be32((u32*)MPC5XXX_BOOTCS_CFG, 0x1); |
| 190 | } |
| 191 | |
| 192 | void flash_afterinit(ulong size) |
| 193 | { |
| 194 | out_be32((u32*)MPC5XXX_BOOTCS_START, START_REG(CFG_BOOTCS_START | |
| 195 | size)); |
| 196 | out_be32((u32*)MPC5XXX_CS0_START, START_REG(CFG_BOOTCS_START | |
| 197 | size)); |
| 198 | out_be32((u32*)MPC5XXX_BOOTCS_STOP, STOP_REG(CFG_BOOTCS_START | size, |
| 199 | size)); |
| 200 | out_be32((u32*)MPC5XXX_CS0_STOP, STOP_REG(CFG_BOOTCS_START | size, |
| 201 | size)); |
| 202 | } |
| 203 | |
| 204 | void pci_mvbc_fixup_irq(struct pci_controller *hose, pci_dev_t dev) |
| 205 | { |
| 206 | unsigned char line = 0xff; |
| 207 | u32 base; |
| 208 | |
| 209 | if (PCI_BUS(dev) == 0) { |
| 210 | switch (PCI_DEV (dev)) { |
| 211 | case 0xa: /* FPGA */ |
| 212 | line = 3; |
| 213 | pci_hose_read_config_dword(hose, dev, PCI_BASE_ADDRESS_0, &base); |
| 214 | printf("found FPA - enable arbitration\n"); |
| 215 | writel(0x03, (u32*)(base + 0x80c0)); |
| 216 | writel(0xf0, (u32*)(base + 0x8080)); |
| 217 | break; |
| 218 | case 0xb: /* LAN */ |
| 219 | line = 2; |
| 220 | break; |
| 221 | case 0x1a: |
| 222 | break; |
| 223 | default: |
| 224 | printf ("***pci_scan: illegal dev = 0x%08x\n", PCI_DEV (dev)); |
| 225 | break; |
| 226 | } |
| 227 | pci_hose_write_config_byte(hose, dev, PCI_INTERRUPT_LINE, line); |
| 228 | } |
| 229 | } |
| 230 | |
| 231 | struct pci_controller hose = { |
| 232 | fixup_irq:pci_mvbc_fixup_irq |
| 233 | }; |
| 234 | |
| 235 | int mvbc_p_load_fpga(void) |
| 236 | { |
| 237 | size_t data_size = 0; |
| 238 | void *fpga_data = NULL; |
| 239 | char *datastr = getenv("fpgadata"); |
| 240 | char *sizestr = getenv("fpgadatasize"); |
| 241 | |
| 242 | if (datastr) |
| 243 | fpga_data = (void *)simple_strtoul(datastr, NULL, 16); |
| 244 | if (sizestr) |
| 245 | data_size = (size_t)simple_strtoul(sizestr, NULL, 16); |
| 246 | |
| 247 | return fpga_load(0, fpga_data, data_size); |
| 248 | } |
| 249 | |
| 250 | extern void pci_mpc5xxx_init(struct pci_controller *); |
| 251 | |
| 252 | void pci_init_board(void) |
| 253 | { |
| 254 | char *s; |
| 255 | int load_fpga = 1; |
| 256 | |
| 257 | mvbc_p_init_fpga(); |
| 258 | s = getenv("skip_fpga"); |
| 259 | if (s) { |
| 260 | printf("found 'skip_fpga' -> FPGA _not_ loaded !\n"); |
| 261 | load_fpga = 0; |
| 262 | } |
| 263 | if (load_fpga) { |
| 264 | printf("loading FPGA ... "); |
| 265 | mvbc_p_load_fpga(); |
| 266 | printf("done\n"); |
| 267 | } |
| 268 | pci_mpc5xxx_init(&hose); |
| 269 | } |
| 270 | |
| 271 | u8 *dhcp_vendorex_prep(u8 *e) |
| 272 | { |
| 273 | char *ptr; |
| 274 | |
| 275 | /* DHCP vendor-class-identifier = 60 */ |
| 276 | if ((ptr = getenv("dhcp_vendor-class-identifier"))) { |
| 277 | *e++ = 60; |
| 278 | *e++ = strlen(ptr); |
| 279 | while (*ptr) |
| 280 | *e++ = *ptr++; |
| 281 | } |
| 282 | /* DHCP_CLIENT_IDENTIFIER = 61 */ |
| 283 | if ((ptr = getenv("dhcp_client_id"))) { |
| 284 | *e++ = 61; |
| 285 | *e++ = strlen(ptr); |
| 286 | while (*ptr) |
| 287 | *e++ = *ptr++; |
| 288 | } |
| 289 | |
| 290 | return e; |
| 291 | } |
| 292 | |
| 293 | u8 *dhcp_vendorex_proc (u8 *popt) |
| 294 | { |
| 295 | return NULL; |
| 296 | } |
| 297 | |
| 298 | void show_boot_progress(int val) |
| 299 | { |
| 300 | struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio*)MPC5XXX_GPIO; |
| 301 | |
| 302 | switch(val) { |
| 303 | case 0: /* FPGA ok */ |
| 304 | setbits_be32(&gpio->simple_dvo, 0x80); |
| 305 | break; |
| 306 | case 1: |
| 307 | setbits_be32(&gpio->simple_dvo, 0x40); |
| 308 | break; |
| 309 | case 12: |
| 310 | setbits_be32(&gpio->simple_dvo, 0x20); |
| 311 | break; |
| 312 | case 15: |
| 313 | setbits_be32(&gpio->simple_dvo, 0x10); |
| 314 | break; |
| 315 | default: |
| 316 | break; |
| 317 | } |
| 318 | |
| 319 | } |
| 320 | |
| 321 | void ft_board_setup(void *blob, bd_t *bd) |
| 322 | { |
| 323 | ft_cpu_setup(blob, bd); |
| 324 | fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize); |
| 325 | } |