blob: 8eaf7cbde3071036a063f68758f2b508173b36ae [file] [log] [blame]
wdenk78e3ab32003-12-28 11:44:59 +00001/*
2 * (C) Copyright 2003
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4 *
5 * (C) Copyright 2003
6 * Reinhard Meyer, EMK Elektronik GmbH, r.meyer@emk-elektronik.de
7 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02008 * SPDX-License-Identifier: GPL-2.0+
wdenk78e3ab32003-12-28 11:44:59 +00009 */
10
11#include <common.h>
12#include <mpc5xxx.h>
13#include <pci.h>
14
15/*****************************************************************************
16 * initialize SDRAM/DDRAM controller.
17 * TBD: get data from I2C EEPROM
18 *****************************************************************************/
Becky Brucebd99ae72008-06-09 16:03:40 -050019phys_size_t initdram (int board_type)
wdenk78e3ab32003-12-28 11:44:59 +000020{
21 ulong dramsize = 0;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020022#ifndef CONFIG_SYS_RAMBOOT
wdenk1ebf41e2004-01-02 14:00:00 +000023#if 0
wdenk78e3ab32003-12-28 11:44:59 +000024 ulong t;
25 ulong tap_del;
wdenk1ebf41e2004-01-02 14:00:00 +000026#endif
wdenk78e3ab32003-12-28 11:44:59 +000027
28 #define MODE_EN 0x80000000
29 #define SOFT_PRE 2
30 #define SOFT_REF 4
31
32 /* configure SDRAM start/end */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020033 *(vu_long *)MPC5XXX_SDRAM_CS0CFG = (CONFIG_SYS_SDRAM_BASE & 0xFFF00000) | CONFIG_SYS_DRAM_RAM_SIZE;
wdenk78e3ab32003-12-28 11:44:59 +000034 *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x80000000; /* disabled */
35
36 /* setup config registers */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020037 *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = CONFIG_SYS_DRAM_CONFIG1;
38 *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = CONFIG_SYS_DRAM_CONFIG2;
wdenk78e3ab32003-12-28 11:44:59 +000039
40 /* unlock mode register */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020041 *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN;
wdenk78e3ab32003-12-28 11:44:59 +000042 /* precharge all banks */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020043 *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_PRE;
44#ifdef CONFIG_SYS_DRAM_DDR
wdenk78e3ab32003-12-28 11:44:59 +000045 /* set extended mode register */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020046 *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_EMODE;
wdenk78e3ab32003-12-28 11:44:59 +000047#endif
48 /* set mode register */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020049 *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_MODE | 0x0400;
wdenk78e3ab32003-12-28 11:44:59 +000050 /* precharge all banks */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020051 *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_PRE;
wdenk78e3ab32003-12-28 11:44:59 +000052 /* auto refresh */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020053 *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL | MODE_EN | SOFT_REF;
wdenk78e3ab32003-12-28 11:44:59 +000054 /* set mode register */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020055 *(vu_short *)MPC5XXX_SDRAM_MODE = CONFIG_SYS_DRAM_MODE;
wdenk78e3ab32003-12-28 11:44:59 +000056 /* normal operation */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020057 *(vu_long *)MPC5XXX_SDRAM_CTRL = CONFIG_SYS_DRAM_CONTROL;
wdenk78e3ab32003-12-28 11:44:59 +000058 /* write default TAP delay */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020059 *(vu_long *)MPC5XXX_CDM_PORCFG = CONFIG_SYS_DRAM_TAP_DEL << 24;
wdenk78e3ab32003-12-28 11:44:59 +000060
61#if 0
wdenk1ebf41e2004-01-02 14:00:00 +000062 for (tap_del = 0; tap_del < 32; tap_del++)
63 {
wdenk78e3ab32003-12-28 11:44:59 +000064 *(vu_long *)MPC5XXX_CDM_PORCFG = tap_del << 24;
65
66 printf ("\nTAP Delay:%x Filling DRAM...", *(vu_long *)MPC5XXX_CDM_PORCFG);
67 for (t = 0; t < 0x04000000; t+=4)
68 *(vu_long *) t = t;
69 printf ("Checking DRAM...\n");
wdenk1ebf41e2004-01-02 14:00:00 +000070 for (t = 0; t < 0x04000000; t+=4)
71 {
wdenk78e3ab32003-12-28 11:44:59 +000072 ulong rval = *(vu_long *) t;
wdenk1ebf41e2004-01-02 14:00:00 +000073 if (rval != t)
74 {
wdenk78e3ab32003-12-28 11:44:59 +000075 printf ("mismatch at %x: ", t);
76 printf (" 1.read %x", rval);
77 printf (" 2.read %x", *(vu_long *) t);
78 printf (" 3.read %x", *(vu_long *) t);
79 break;
80 }
81 }
82 }
83#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020084#endif /* CONFIG_SYS_RAMBOOT */
wdenk78e3ab32003-12-28 11:44:59 +000085
86 dramsize = ((1 << (*(vu_long *)MPC5XXX_SDRAM_CS0CFG - 0x13)) << 20);
87
88 /* return total ram size */
89 return dramsize;
90}
91
92/*****************************************************************************
93 * print board identification
94 *****************************************************************************/
95int checkboard (void)
96{
97#if defined (CONFIG_EVAL5200)
98 puts ("Board: EMK TOP5200 on EVAL5200\n");
99#else
wdenk369d43d2004-03-14 14:09:05 +0000100#if defined (CONFIG_LITE5200)
101 puts ("Board: LITE5200\n");
102#else
wdenk78e3ab32003-12-28 11:44:59 +0000103#if defined (CONFIG_MINI5200)
104 puts ("Board: EMK TOP5200 on MINI5200\n");
105#else
106 puts ("Board: EMK TOP5200\n");
107#endif
108#endif
wdenk369d43d2004-03-14 14:09:05 +0000109#endif
wdenk78e3ab32003-12-28 11:44:59 +0000110 return 0;
111}
112
113/*****************************************************************************
114 * prepare for FLASH detection
115 *****************************************************************************/
116void flash_preinit(void)
117{
118 /*
119 * Now, when we are in RAM, enable flash write
120 * access for detection process.
121 * Note that CS_BOOT cannot be cleared when
122 * executing in flash.
123 */
124 *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
125}
126
127/*****************************************************************************
128 * finalize FLASH setup
129 *****************************************************************************/
130void flash_afterinit(uint bank, ulong start, ulong size)
131{
132 if (bank == 0) { /* adjust mapping */
133 *(vu_long *)MPC5XXX_BOOTCS_START =
134 *(vu_long *)MPC5XXX_CS0_START = START_REG(start);
135 *(vu_long *)MPC5XXX_BOOTCS_STOP =
136 *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(start, size);
137 }
138}
139
140/*****************************************************************************
141 * otherinits after RAM is there and we are relocated to RAM
142 * note: though this is an int function, nobody cares for the result!
143 *****************************************************************************/
144int misc_init_r (void)
145{
wdenk369d43d2004-03-14 14:09:05 +0000146#if !defined (CONFIG_LITE5200)
wdenk78e3ab32003-12-28 11:44:59 +0000147 /* read 'factory' part of EEPROM */
wdenke97d3d92004-02-23 22:22:28 +0000148 extern void read_factory_r (void);
149 read_factory_r ();
wdenk369d43d2004-03-14 14:09:05 +0000150#endif
wdenk78e3ab32003-12-28 11:44:59 +0000151 return (0);
152}
153
154/*****************************************************************************
155 * initialize the PCI system
156 *****************************************************************************/
157#ifdef CONFIG_PCI
158static struct pci_controller hose;
159
160extern void pci_mpc5xxx_init(struct pci_controller *);
161
162void pci_init_board(void)
163{
164 pci_mpc5xxx_init(&hose);
165}
166#endif
wdenk369d43d2004-03-14 14:09:05 +0000167
168/*****************************************************************************
wdenk19c8fb72004-04-18 22:26:17 +0000169 * provide the IDE Reset Function
wdenk369d43d2004-03-14 14:09:05 +0000170 *****************************************************************************/
Jon Loeliger13f75992007-07-10 10:39:10 -0500171#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
wdenk19c8fb72004-04-18 22:26:17 +0000172
wdenk19c8fb72004-04-18 22:26:17 +0000173void init_ide_reset (void)
174{
175 debug ("init_ide_reset\n");
176
Wolfgang Denk87b3d4b2006-11-30 18:02:20 +0100177 /* Configure PSC1_4 as GPIO output for ATA reset */
wdenk19c8fb72004-04-18 22:26:17 +0000178 *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
179 *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
180}
181
wdenk369d43d2004-03-14 14:09:05 +0000182void ide_set_reset (int idereset)
183{
wdenk19c8fb72004-04-18 22:26:17 +0000184 debug ("ide_reset(%d)\n", idereset);
185
wdenk369d43d2004-03-14 14:09:05 +0000186 if (idereset) {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100187 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
wdenk369d43d2004-03-14 14:09:05 +0000188 } else {
Bartlomiej Sieka79eecbfb2006-11-01 01:38:16 +0100189 *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
wdenk369d43d2004-03-14 14:09:05 +0000190 }
wdenk369d43d2004-03-14 14:09:05 +0000191}
Jon Loeliger13f75992007-07-10 10:39:10 -0500192#endif