blob: a8bc3b309c3cd581ecd5be38b14b4636205ad4b7 [file] [log] [blame]
wdenk138ff602004-12-16 15:52:40 +00001/*
Detlev Zundel7b5611c2009-03-30 00:31:34 +02002 * (C) Copyright 2008-2009
3 * Andreas Pfefferle, DENX Software Engineering, ap@denx.de.
4 *
5 * (C) Copyright 2009
6 * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
wdenk138ff602004-12-16 15:52:40 +00007 *
8 * (C) Copyright 2004
9 * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
10 *
11 * (C) Copyright 2004
12 * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
13 *
Detlev Zundel7b5611c2009-03-30 00:31:34 +020014 * (C) Copyright 2003-2004
15 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
16 *
wdenk138ff602004-12-16 15:52:40 +000017 * See file CREDITS for list of people who contributed to this
18 * project.
19 *
20 * This program is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU General Public License as
22 * published by the Free Software Foundation; either version 2 of
23 * the License, or (at your option) any later version.
24 *
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
29 *
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
33 * MA 02111-1307 USA
34 */
35
Detlev Zundele979e852009-03-30 00:31:35 +020036#include <asm/io.h>
wdenk138ff602004-12-16 15:52:40 +000037#include <common.h>
38#include <mpc5xxx.h>
39#include <pci.h>
40
Marian Balakowicz5fb6d712007-11-15 13:29:55 +010041#if defined(CONFIG_DDR_MT46V16M16)
wdenk138ff602004-12-16 15:52:40 +000042#include "mt46v16m16-75.h"
Marian Balakowicz5fb6d712007-11-15 13:29:55 +010043#elif defined(CONFIG_SDR_MT48LC16M16A2)
wdenk138ff602004-12-16 15:52:40 +000044#include "mt48lc16m16a2-75.h"
Marian Balakowicz5fb6d712007-11-15 13:29:55 +010045#elif defined(CONFIG_DDR_MT46V32M16)
46#include "mt46v32m16.h"
47#elif defined(CONFIG_DDR_HYB25D512160BF)
48#include "hyb25d512160bf.h"
49#elif defined(CONFIG_DDR_K4H511638C)
50#include "k4h511638c.h"
51#else
52#error "INKA4x0 SDRAM: invalid chip type specified!"
wdenk138ff602004-12-16 15:52:40 +000053#endif
54
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020055#ifndef CONFIG_SYS_RAMBOOT
wdenk138ff602004-12-16 15:52:40 +000056static void sdram_start (int hi_addr)
57{
58 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
59
60 /* unlock mode register */
wdenkf4733a02005-03-06 01:21:30 +000061 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
wdenk138ff602004-12-16 15:52:40 +000062 __asm__ volatile ("sync");
63
64 /* precharge all banks */
wdenkf4733a02005-03-06 01:21:30 +000065 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
wdenk138ff602004-12-16 15:52:40 +000066 __asm__ volatile ("sync");
67
68#if SDRAM_DDR
69 /* set mode register: extended mode */
70 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
71 __asm__ volatile ("sync");
72
73 /* set mode register: reset DLL */
74 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
75 __asm__ volatile ("sync");
76#endif
77
78 /* precharge all banks */
wdenkf4733a02005-03-06 01:21:30 +000079 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
wdenk138ff602004-12-16 15:52:40 +000080 __asm__ volatile ("sync");
81
82 /* auto refresh */
wdenkf4733a02005-03-06 01:21:30 +000083 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
wdenk138ff602004-12-16 15:52:40 +000084 __asm__ volatile ("sync");
85
86 /* set mode register */
87 *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
88 __asm__ volatile ("sync");
89
90 /* normal operation */
91 *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
92 __asm__ volatile ("sync");
93}
94#endif
95
96/*
97 * ATTENTION: Although partially referenced initdram does NOT make real use
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020098 * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
wdenk138ff602004-12-16 15:52:40 +000099 * is something else than 0x00000000.
100 */
101
Becky Bruce9973e3c2008-06-09 16:03:40 -0500102phys_size_t initdram (int board_type)
wdenk138ff602004-12-16 15:52:40 +0000103{
104 ulong dramsize = 0;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200105#ifndef CONFIG_SYS_RAMBOOT
Marian Balakowiczf23cb342007-11-15 13:24:43 +0100106 long test1, test2;
wdenk138ff602004-12-16 15:52:40 +0000107
108 /* setup SDRAM chip selects */
109 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
110 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
111 __asm__ volatile ("sync");
112
113 /* setup config registers */
114 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
115 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
116 __asm__ volatile ("sync");
117
118#if SDRAM_DDR
119 /* set tap delay */
120 *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
121 __asm__ volatile ("sync");
122#endif
123
124 /* find RAM size using SDRAM CS0 only */
125 sdram_start(0);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200126 test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
wdenk138ff602004-12-16 15:52:40 +0000127 sdram_start(1);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200128 test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
wdenk138ff602004-12-16 15:52:40 +0000129 if (test1 > test2) {
130 sdram_start(0);
131 dramsize = test1;
132 } else {
133 dramsize = test2;
134 }
135
136 /* memory smaller than 1MB is impossible */
137 if (dramsize < (1 << 20)) {
138 dramsize = 0;
139 }
140
141 /* set SDRAM CS0 size according to the amount of RAM found */
142 if (dramsize > 0) {
143 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
144 __builtin_ffs(dramsize >> 20) - 1;
145 } else {
146 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
147 }
148
149 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200150#else /* CONFIG_SYS_RAMBOOT */
wdenk138ff602004-12-16 15:52:40 +0000151
152 /* retrieve size of memory connected to SDRAM CS0 */
153 dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
154 if (dramsize >= 0x13) {
155 dramsize = (1 << (dramsize - 0x13)) << 20;
156 } else {
157 dramsize = 0;
158 }
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200159#endif /* CONFIG_SYS_RAMBOOT */
wdenk138ff602004-12-16 15:52:40 +0000160
wdenk138ff602004-12-16 15:52:40 +0000161 return dramsize;
162}
163
164int checkboard (void)
165{
wdenk08f27272004-12-19 21:39:27 +0000166 puts ("Board: INKA 4X0\n");
wdenk138ff602004-12-16 15:52:40 +0000167 return 0;
168}
169
170void flash_preinit(void)
171{
172 /*
173 * Now, when we are in RAM, enable flash write
174 * access for detection process.
175 * Note that CS_BOOT cannot be cleared when
176 * executing in flash.
177 */
178 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
179}
wdenk436be292005-01-31 22:09:11 +0000180
Detlev Zundel7b5611c2009-03-30 00:31:34 +0200181int misc_init_r (void) {
182 extern int inkadiag_init_r (void);
183
184 /*
185 * The command table used for the subcommands of inkadiag
186 * needs to be relocated manually.
187 */
188 return inkadiag_init_r();
189}
190
wdenk151ab832005-02-24 22:44:16 +0000191int misc_init_f (void)
192{
Detlev Zundele979e852009-03-30 00:31:35 +0200193 struct mpc5xxx_gpio *gpio = (struct mpc5xxx_gpio *)MPC5XXX_GPIO;
194 struct mpc5xxx_wu_gpio *wu_gpio = (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO;
Marian Balakowiczf23cb342007-11-15 13:24:43 +0100195 char tmp[10];
wdenka0bdf492005-03-14 13:14:58 +0000196 int i, br;
197
198 i = getenv_r("brightness", tmp, sizeof(tmp));
199 br = (i > 0)
200 ? (int) simple_strtoul (tmp, NULL, 10)
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200201 : CONFIG_SYS_BRIGHTNESS;
wdenka0bdf492005-03-14 13:14:58 +0000202 if (br > 255)
203 br = 255;
204
wdenkf4733a02005-03-06 01:21:30 +0000205 /* Initialize GPIO output pins.
206 */
wdenk342717f2005-06-27 13:30:03 +0000207 /* Configure GPT as GPIO output (and set them as they control low-active LEDs */
wdenkf4733a02005-03-06 01:21:30 +0000208 *(vu_long *)MPC5XXX_GPT0_ENABLE =
209 *(vu_long *)MPC5XXX_GPT1_ENABLE =
210 *(vu_long *)MPC5XXX_GPT2_ENABLE =
211 *(vu_long *)MPC5XXX_GPT3_ENABLE =
212 *(vu_long *)MPC5XXX_GPT4_ENABLE =
wdenk342717f2005-06-27 13:30:03 +0000213 *(vu_long *)MPC5XXX_GPT5_ENABLE = 0x34;
wdenkf4733a02005-03-06 01:21:30 +0000214
wdenka0bdf492005-03-14 13:14:58 +0000215 /* Configure GPT7 as PWM timer, 1kHz, no ints. */
216 *(vu_long *)MPC5XXX_GPT7_ENABLE = 0;/* Disable */
217 *(vu_long *)MPC5XXX_GPT7_COUNTER = 0x020000fe;
218 *(vu_long *)MPC5XXX_GPT7_PWMCFG = (br << 16);
219 *(vu_long *)MPC5XXX_GPT7_ENABLE = 0x3;/* Enable PWM mode and start */
wdenkf4733a02005-03-06 01:21:30 +0000220
221 /* Configure PSC3_6,7 as GPIO output */
222 *(vu_long *)MPC5XXX_GPIO_ENABLE |= 0x00003000;
223 *(vu_long *)MPC5XXX_GPIO_DIR |= 0x00003000;
224
225 /* Configure PSC3_8 as GPIO output, no interrupt */
226 *(vu_long *)MPC5XXX_GPIO_SI_ENABLE |= 0x04000000;
227 *(vu_long *)MPC5XXX_GPIO_SI_DIR |= 0x04000000;
228 *(vu_long *)MPC5XXX_GPIO_SI_IEN &= ~0x04000000;
229
230 /* Configure PSC3_9 and GPIO_WKUP6,7 as GPIO output */
231 *(vu_long *)MPC5XXX_WU_GPIO_ENABLE |= 0xc4000000;
232 *(vu_long *)MPC5XXX_WU_GPIO_DIR |= 0xc4000000;
233
wdenk342717f2005-06-27 13:30:03 +0000234 /* Set LR mirror bit because it is low-active */
Bartlomiej Siekadae80f32006-11-01 01:38:16 +0100235 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_WKUP_7;
wdenk151ab832005-02-24 22:44:16 +0000236 /*
237 * Reset Coral-P graphics controller
238 */
wdenkf4733a02005-03-06 01:21:30 +0000239 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC3_9;
240 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC3_9;
Bartlomiej Siekadae80f32006-11-01 01:38:16 +0100241 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC3_9;
Detlev Zundele979e852009-03-30 00:31:35 +0200242
243 /*
244 * Configure three wire serial interface to RTC (PSC1_4,
245 * PSC2_4, PSC3_4, PSC3_5)
246 */
247 setbits_8(&wu_gpio->enable, MPC5XXX_GPIO_WKUP_PSC1_4 |
248 MPC5XXX_GPIO_WKUP_PSC2_4);
249 setbits_8(&wu_gpio->ddr, MPC5XXX_GPIO_WKUP_PSC1_4 |
250 MPC5XXX_GPIO_WKUP_PSC2_4);
251 clrbits_8(&wu_gpio->dvo, MPC5XXX_GPIO_WKUP_PSC1_4);
252 clrbits_8(&gpio->sint_inten, MPC5XXX_GPIO_SINT_PSC3_4 |
253 MPC5XXX_GPIO_SINT_PSC3_5);
254 setbits_8(&gpio->sint_gpioe, MPC5XXX_GPIO_SINT_PSC3_4 |
255 MPC5XXX_GPIO_SINT_PSC3_5);
256 setbits_8(&gpio->sint_ddr, MPC5XXX_GPIO_SINT_PSC3_5);
257 clrbits_8(&gpio->sint_dvo, MPC5XXX_GPIO_SINT_PSC3_5);
258
wdenkf4733a02005-03-06 01:21:30 +0000259 return 0;
wdenk151ab832005-02-24 22:44:16 +0000260}
261
wdenkf4733a02005-03-06 01:21:30 +0000262#ifdef CONFIG_PCI
wdenk436be292005-01-31 22:09:11 +0000263static struct pci_controller hose;
264
265extern void pci_mpc5xxx_init(struct pci_controller *);
266
267void pci_init_board(void)
268{
wdenkf4733a02005-03-06 01:21:30 +0000269 pci_mpc5xxx_init(&hose);
wdenk436be292005-01-31 22:09:11 +0000270}
271#endif
wdenkb05dcb52005-03-04 11:27:31 +0000272
Jon Loeliger77a31852007-07-10 10:39:10 -0500273#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
wdenkb05dcb52005-03-04 11:27:31 +0000274
wdenkb05dcb52005-03-04 11:27:31 +0000275void init_ide_reset (void)
276{
277 debug ("init_ide_reset\n");
278
wdenkf4733a02005-03-06 01:21:30 +0000279 /* Configure PSC1_4 as GPIO output for ATA reset */
wdenkb05dcb52005-03-04 11:27:31 +0000280 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
281 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
282 /* Deassert reset */
Bartlomiej Siekadae80f32006-11-01 01:38:16 +0100283 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
wdenkb05dcb52005-03-04 11:27:31 +0000284}
285
286void ide_set_reset (int idereset)
287{
288 debug ("ide_reset(%d)\n", idereset);
289
290 if (idereset) {
Bartlomiej Siekadae80f32006-11-01 01:38:16 +0100291 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
wdenkb05dcb52005-03-04 11:27:31 +0000292 /* Make a delay. MPC5200 spec says 25 usec min */
293 udelay(500000);
294 } else {
Bartlomiej Siekadae80f32006-11-01 01:38:16 +0100295 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
wdenkb05dcb52005-03-04 11:27:31 +0000296 }
297}
Jon Loeliger77a31852007-07-10 10:39:10 -0500298#endif