blob: 1775433f0d0f3896ee42a05b1d4fd364980fc107 [file] [log] [blame]
Markus Klotzbuecher8f824852006-07-12 08:48:24 +02001/*
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 Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Markus Klotzbuecher8f824852006-07-12 08:48:24 +02008 */
9
10#include <config.h>
11#include <common.h>
12#include <mpc8xx.h>
13#include "pld.h"
Markus Klotzbuecher0dda6452007-01-09 14:57:10 +010014#include "hpi.h"
Markus Klotzbuecher8f824852006-07-12 08:48:24 +020015
16#define _NOT_USED_ 0xFFFFFFFF
Markus Klotzbuecher8f824852006-07-12 08:48:24 +020017
18static long int dram_size (long int, long int *, long int);
19
20const 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 Brucebd99ae72008-06-09 16:03:40 -050069phys_size_t initdram (int board_type)
Markus Klotzbuecher8f824852006-07-12 08:48:24 +020070{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020071 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +020072 volatile memctl8xx_t *memctl = &immr->im_memctl;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020073 /* volatile spc1920_pld_t *pld = (spc1920_pld_t *) CONFIG_SYS_SPC1920_PLD_BASE; */
Markus Klotzbuecher8f824852006-07-12 08:48:24 +020074
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-VILLARD03836942008-10-16 15:01:15 +020086 memctl->memc_mptpr = CONFIG_SYS_MPTPR;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +020087
88 /* burst length=4, burst type=sequential, CAS latency=2 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020089 memctl->memc_mar = CONFIG_SYS_MAR;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +020090
91 /*
92 * Map controller bank 1 to the SDRAM bank at preliminary address.
93 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020094 memctl->memc_or1 = CONFIG_SYS_OR1_PRELIM;
95 memctl->memc_br1 = CONFIG_SYS_BR1_PRELIM;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +020096
97 /* initialize memory address register */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098 memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL; /* refresh not enabled yet */
Markus Klotzbuecher8f824852006-07-12 08:48:24 +020099
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-VILLARD03836942008-10-16 15:01:15 +0200119 (volatile unsigned long *) CONFIG_SYS_SDRAM_BASE;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200120 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-VILLARD03836942008-10-16 15:01:15 +0200131 size8 = dram_size (CONFIG_SYS_MBMR_8COL, (long *)CONFIG_SYS_SDRAM_BASE, SDRAM_MAX_SIZE);
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200132
133 udelay (1000);
134
135 /*
136 * try 9 column mode
137 */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200138 size9 = dram_size (CONFIG_SYS_MBMR_9COL, (long *)CONFIG_SYS_SDRAM_BASE, SDRAM_MAX_SIZE);
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200139
140 if (size8 < size9) { /* leave configuration at 9 columns */
141 size_b0 = size9;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200142 memctl->memc_mbmr = CONFIG_SYS_MBMR_9COL | MBMR_PTBE;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200143 udelay (500);
144 } else { /* back to 8 columns */
145 size_b0 = size8;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200146 memctl->memc_mbmr = CONFIG_SYS_MBMR_8COL | MBMR_PTBE;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200147 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-VILLARD03836942008-10-16 15:01:15 +0200156 memctl->memc_br1 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMB | BR_V;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200157 udelay (1000);
158
Markus Klotzbuecher0dda6452007-01-09 14:57:10 +0100159 /* initalize the DSP Host Port Interface */
160 hpi_init();
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200161
Markus Klotzbuecher79bac7a2007-01-09 16:02:48 +0100162 /* FRAM Setup */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200163 memctl->memc_or4 = CONFIG_SYS_OR4;
164 memctl->memc_br4 = CONFIG_SYS_BR4;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200165 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 */
177static long int dram_size (long int mbmr_value, long int *base,
178 long int maxsize)
179{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200180 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200181 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
192int board_early_init_f(void)
193{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200194 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200195
Markus Klotzbuecher2c0fbbd2007-01-09 14:57:12 +0100196 /* 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 Klotzbuecher8f824852006-07-12 08:48:24 +0200201
Markus Klotzbuecher2c0fbbd2007-01-09 14:57:12 +0100202#if 0
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200203 /* 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 Klotzbuecher2c0fbbd2007-01-09 14:57:12 +0100207#endif
208
Markus Klotzbuecher63ee6fe2007-01-09 14:57:13 +0100209 /*
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 Klotzbuecher8f824852006-07-12 08:48:24 +0200221 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-VILLARD03836942008-10-16 15:01:15 +0200227#ifdef CONFIG_SYS_SMC1_PLD_CLK4 /* SMC1 uses CLK4 from PLD */
Markus Klotzbuecher8f824852006-07-12 08:48:24 +0200228 immap->im_cpm.cp_simode |= 0x7000;
229 immap->im_cpm.cp_simode &= ~(0x8000);
230#endif
231
232 return 0;
233}
234
Markus Klotzbuecher0dda6452007-01-09 14:57:10 +0100235int 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 Klotzbuecher8f824852006-07-12 08:48:24 +0200243
244int checkboard (void)
245{
246 puts("Board: SPC1920\n");
247 return 0;
248}