Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2000-2004 |
| 3 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 4 | * |
| 5 | * Modified by, Yuli Barcohen, Arabella Software Ltd., yuli@arabellasw.com |
| 6 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <config.h> |
| 11 | #include <common.h> |
| 12 | #include <mpc8xx.h> |
| 13 | #include "pld.h" |
Markus Klotzbuecher | d28707d | 2007-01-09 14:57:10 +0100 | [diff] [blame] | 14 | #include "hpi.h" |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 15 | |
| 16 | #define _NOT_USED_ 0xFFFFFFFF |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 17 | |
| 18 | static long int dram_size (long int, long int *, long int); |
| 19 | |
| 20 | const uint sdram_table[] = { |
| 21 | /* |
| 22 | * Single Read. (Offset 0 in UPMB RAM) |
| 23 | */ |
| 24 | 0x1F07FC04, 0xEEAEFC04, 0x11ADFC04, 0xEFBBBC00, |
| 25 | 0x1FF77C47, /* last */ |
| 26 | /* |
| 27 | * SDRAM Initialization (offset 5 in UPMB RAM) |
| 28 | * |
| 29 | * This is no UPM entry point. The following definition uses |
| 30 | * the remaining space to establish an initialization |
| 31 | * sequence, which is executed by a RUN command. |
| 32 | * |
| 33 | */ |
| 34 | 0x1FF77C34, 0xEFEABC34, 0x1FB57C35, /* last */ |
| 35 | /* |
| 36 | * Burst Read. (Offset 8 in UPMB RAM) |
| 37 | */ |
| 38 | 0x1F07FC04, 0xEEAEFC04, 0x10ADFC04, 0xF0AFFC00, |
| 39 | 0xF0AFFC00, 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C47, /* last */ |
| 40 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 41 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 42 | /* |
| 43 | * Single Write. (Offset 18 in UPMB RAM) |
| 44 | */ |
| 45 | 0x1F07FC04, 0xEEAEBC00, 0x01B93C04, 0x1FF77C47, /* last */ |
| 46 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 47 | /* |
| 48 | * Burst Write. (Offset 20 in UPMB RAM) |
| 49 | */ |
| 50 | 0x1F07FC04, 0xEEAEBC00, 0x10AD7C00, 0xF0AFFC00, |
| 51 | 0xF0AFFC00, 0xE1BBBC04, 0x1FF77C47, /* last */ |
| 52 | _NOT_USED_, |
| 53 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 54 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 55 | /* |
| 56 | * Refresh (Offset 30 in UPMB RAM) |
| 57 | */ |
| 58 | 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04, |
| 59 | 0xFFFFFC84, 0xFFFFFC07, /* last */ |
| 60 | _NOT_USED_, _NOT_USED_, |
| 61 | _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 62 | /* |
| 63 | * Exception. (Offset 3c in UPMB RAM) |
| 64 | */ |
| 65 | 0x7FFFFC07, /* last */ |
| 66 | _NOT_USED_, _NOT_USED_, _NOT_USED_, |
| 67 | }; |
| 68 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 69 | phys_size_t initdram (int board_type) |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 70 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 71 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 72 | volatile memctl8xx_t *memctl = &immr->im_memctl; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 73 | /* volatile spc1920_pld_t *pld = (spc1920_pld_t *) CONFIG_SYS_SPC1920_PLD_BASE; */ |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 74 | |
| 75 | long int size_b0; |
| 76 | long int size8, size9; |
| 77 | int i; |
| 78 | |
| 79 | /* |
| 80 | * Configure UPMB for SDRAM |
| 81 | */ |
| 82 | upmconfig (UPMB, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint)); |
| 83 | |
| 84 | udelay(100); |
| 85 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 86 | memctl->memc_mptpr = CONFIG_SYS_MPTPR; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 87 | |
| 88 | /* burst length=4, burst type=sequential, CAS latency=2 */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 89 | memctl->memc_mar = CONFIG_SYS_MAR; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * Map controller bank 1 to the SDRAM bank at preliminary address. |
| 93 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 94 | memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM; |
| 95 | memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 96 | |
| 97 | /* initialize memory address register */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 98 | memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL; /* refresh not enabled yet */ |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 99 | |
| 100 | /* mode initialization (offset 5) */ |
| 101 | udelay (200); /* 0x80006105 */ |
| 102 | memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS1 | MCR_MLCF (1) | MCR_MAD (0x05); |
| 103 | |
| 104 | /* run 2 refresh sequence with 4-beat refresh burst (offset 0x30) */ |
| 105 | udelay (1); /* 0x80006130 */ |
| 106 | memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS1 | MCR_MLCF (1) | MCR_MAD (0x30); |
| 107 | udelay (1); /* 0x80006130 */ |
| 108 | memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS1 | MCR_MLCF (1) | MCR_MAD (0x30); |
| 109 | udelay (1); /* 0x80006106 */ |
| 110 | memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS1 | MCR_MLCF (1) | MCR_MAD (0x06); |
| 111 | |
| 112 | memctl->memc_mbmr |= MBMR_PTBE; /* refresh enabled */ |
| 113 | |
| 114 | udelay (200); |
| 115 | |
| 116 | /* Need at least 10 DRAM accesses to stabilize */ |
| 117 | for (i = 0; i < 10; ++i) { |
| 118 | volatile unsigned long *addr = |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 119 | (volatile unsigned long *) CONFIG_SYS_SDRAM_BASE; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 120 | unsigned long val; |
| 121 | |
| 122 | val = *(addr + i); |
| 123 | *(addr + i) = val; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Check Bank 0 Memory Size for re-configuration |
| 128 | * |
| 129 | * try 8 column mode |
| 130 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 131 | size8 = dram_size (CONFIG_SYS_MBMR_8COL, (long *)CONFIG_SYS_SDRAM_BASE, SDRAM_MAX_SIZE); |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 132 | |
| 133 | udelay (1000); |
| 134 | |
| 135 | /* |
| 136 | * try 9 column mode |
| 137 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 138 | size9 = dram_size (CONFIG_SYS_MBMR_9COL, (long *)CONFIG_SYS_SDRAM_BASE, SDRAM_MAX_SIZE); |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 139 | |
| 140 | if (size8 < size9) { /* leave configuration at 9 columns */ |
| 141 | size_b0 = size9; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 142 | memctl->memc_mbmr = CONFIG_SYS_MBMR_9COL | MBMR_PTBE; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 143 | udelay (500); |
| 144 | } else { /* back to 8 columns */ |
| 145 | size_b0 = size8; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 146 | memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL | MBMR_PTBE; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 147 | udelay (500); |
| 148 | } |
| 149 | |
| 150 | /* |
| 151 | * Final mapping: |
| 152 | */ |
| 153 | |
| 154 | memctl->memc_or1 = ((-size_b0) & 0xFFFF0000) | |
| 155 | OR_CSNT_SAM | OR_G5LS | SDRAM_TIMING; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 156 | memctl->memc_br1 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMB | BR_V; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 157 | udelay (1000); |
| 158 | |
Markus Klotzbuecher | d28707d | 2007-01-09 14:57:10 +0100 | [diff] [blame] | 159 | /* initalize the DSP Host Port Interface */ |
| 160 | hpi_init(); |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 161 | |
Markus Klotzbuecher | 67fea02 | 2007-01-09 16:02:48 +0100 | [diff] [blame] | 162 | /* FRAM Setup */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 163 | memctl->memc_or4 = CONFIG_SYS_OR4; |
| 164 | memctl->memc_br4 = CONFIG_SYS_BR4; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 165 | udelay(1000); |
| 166 | |
| 167 | return (size_b0); |
| 168 | } |
| 169 | |
| 170 | /* |
| 171 | * Check memory range for valid RAM. A simple memory test determines |
| 172 | * the actually available RAM size between addresses `base' and |
| 173 | * `base + maxsize'. Some (not all) hardware errors are detected: |
| 174 | * - short between address lines |
| 175 | * - short between data lines |
| 176 | */ |
| 177 | static long int dram_size (long int mbmr_value, long int *base, |
| 178 | long int maxsize) |
| 179 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 180 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 181 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
| 182 | |
| 183 | memctl->memc_mbmr = mbmr_value; |
| 184 | |
| 185 | return (get_ram_size (base, maxsize)); |
| 186 | } |
| 187 | |
| 188 | |
| 189 | /************* other stuff ******************/ |
| 190 | |
| 191 | |
| 192 | int board_early_init_f(void) |
| 193 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 194 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 195 | |
Markus Klotzbuecher | e4c2d37 | 2007-01-09 14:57:12 +0100 | [diff] [blame] | 196 | /* Set Go/NoGo led (PA15) to color red */ |
| 197 | immap->im_ioport.iop_papar &= ~0x1; |
| 198 | immap->im_ioport.iop_paodr &= ~0x1; |
| 199 | immap->im_ioport.iop_padir |= 0x1; |
| 200 | immap->im_ioport.iop_padat |= 0x1; |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 201 | |
Markus Klotzbuecher | e4c2d37 | 2007-01-09 14:57:12 +0100 | [diff] [blame] | 202 | #if 0 |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 203 | /* Turn on LED PD9 */ |
| 204 | immap->im_ioport.iop_pdpar &= ~(0x0040); |
| 205 | immap->im_ioport.iop_pddir |= 0x0040; |
| 206 | immap->im_ioport.iop_pddat |= 0x0040; |
Markus Klotzbuecher | e4c2d37 | 2007-01-09 14:57:12 +0100 | [diff] [blame] | 207 | #endif |
| 208 | |
Markus Klotzbuecher | 5921e53 | 2007-01-09 14:57:13 +0100 | [diff] [blame] | 209 | /* |
| 210 | * Enable console on SMC1. This requires turning on |
| 211 | * the com2_en signal and SMC1_DISABLE |
| 212 | */ |
| 213 | |
| 214 | /* SMC1_DISABLE: PB17 */ |
| 215 | immap->im_cpm.cp_pbodr &= ~0x4000; |
| 216 | immap->im_cpm.cp_pbpar &= ~0x4000; |
| 217 | immap->im_cpm.cp_pbdir |= 0x4000; |
| 218 | immap->im_cpm.cp_pbdat &= ~0x4000; |
| 219 | |
| 220 | /* COM2_EN: PD10 */ |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 221 | immap->im_ioport.iop_pdpar &= ~0x0020; |
| 222 | immap->im_ioport.iop_pddir &= ~0x4000; |
| 223 | immap->im_ioport.iop_pddir |= 0x0020; |
| 224 | immap->im_ioport.iop_pddat |= 0x0020; |
| 225 | |
| 226 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 227 | #ifdef CONFIG_SYS_SMC1_PLD_CLK4 /* SMC1 uses CLK4 from PLD */ |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 228 | immap->im_cpm.cp_simode |= 0x7000; |
| 229 | immap->im_cpm.cp_simode &= ~(0x8000); |
| 230 | #endif |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
Markus Klotzbuecher | d28707d | 2007-01-09 14:57:10 +0100 | [diff] [blame] | 235 | int last_stage_init(void) |
| 236 | { |
| 237 | #ifdef CONFIG_SPC1920_HPI_TEST |
| 238 | printf("CMB1920 Host Port Interface Test: %s\n", |
| 239 | hpi_test() ? "Failed!" : "OK"); |
| 240 | #endif |
| 241 | return 0; |
| 242 | } |
Markus Klotzbuecher | b02d017 | 2006-07-12 08:48:24 +0200 | [diff] [blame] | 243 | |
| 244 | int checkboard (void) |
| 245 | { |
| 246 | puts("Board: SPC1920\n"); |
| 247 | return 0; |
| 248 | } |