blob: ce515d834c6dfc2c324f373c12af8bd024591fe2 [file] [log] [blame]
Jon Smirlc9969942009-06-14 18:21:28 -04001/*
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 2006
9 * Eric Schumann, Phytec Messtechnik GmbH
10 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020011 * SPDX-License-Identifier: GPL-2.0+
Jon Smirlc9969942009-06-14 18:21:28 -040012 */
13
14#include <common.h>
15#include <mpc5xxx.h>
16#include <pci.h>
Peter Tyser61f2b382010-04-12 22:28:07 -050017#include <asm/io.h>
Jon Smirlc9969942009-06-14 18:21:28 -040018
19#include "mt46v32m16-75.h"
20
21#ifndef CONFIG_SYS_RAMBOOT
22static void sdram_start(int hi_addr)
23{
24 volatile struct mpc5xxx_cdm *cdm =
25 (struct mpc5xxx_cdm *)MPC5XXX_CDM;
26 volatile struct mpc5xxx_sdram *sdram =
27 (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
28
29 long hi_addr_bit = hi_addr ? 0x01000000 : 0;
30
31 /* unlock mode register */
32 out_be32 (&sdram->ctrl,
33 (SDRAM_CONTROL | 0x80000000 | hi_addr_bit));
34
35 /* precharge all banks */
36 out_be32 (&sdram->ctrl,
37 (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
38
39#ifdef SDRAM_DDR
40 /* set mode register: extended mode */
41 out_be32 (&sdram->mode, (SDRAM_EMODE));
42
43 /* set mode register: reset DLL */
44 out_be32 (&sdram->mode,
45 (SDRAM_MODE | 0x04000000));
46#endif
47
48 /* precharge all banks */
49 out_be32 (&sdram->ctrl,
50 (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
51
52 /* auto refresh */
53 out_be32 (&sdram->ctrl,
54 (SDRAM_CONTROL | 0x80000004 | hi_addr_bit));
55
56 /* set mode register */
57 out_be32 (&sdram->mode, (SDRAM_MODE));
58
59 /* normal operation */
60 out_be32 (&sdram->ctrl,
61 (SDRAM_CONTROL | hi_addr_bit));
62
63 /* set CDM clock enable register, set MPC5200B SDRAM bus */
64 /* to reduced driver strength */
65 out_be32 (&cdm->clock_enable, (0x00CFFFFF));
66}
67#endif
68
69/*
70 * ATTENTION: Although partially referenced initdram does NOT make
71 * real use of CONFIG_SYS_SDRAM_BASE. The code does not
72 * work if CONFIG_SYS_SDRAM_BASE
73 * is something else than 0x00000000.
74 */
75
76phys_size_t initdram(int board_type)
77{
78 volatile struct mpc5xxx_mmap_ctl *mm =
79 (struct mpc5xxx_mmap_ctl *)CONFIG_SYS_MBAR;
80 volatile struct mpc5xxx_cdm *cdm =
81 (struct mpc5xxx_cdm *)MPC5XXX_CDM;
82 volatile struct mpc5xxx_sdram *sdram =
83 (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
84 ulong dramsize = 0;
85 ulong dramsize2 = 0;
86#ifndef CONFIG_SYS_RAMBOOT
87 ulong test1, test2;
88
89 /* setup SDRAM chip selects */
90 /* 256MB at 0x0 */
91 out_be32 (&mm->sdram0, 0x0000001b);
92 /* disabled */
93 out_be32 (&mm->sdram1, 0x10000000);
94
95 /* setup config registers */
96 out_be32 (&sdram->config1, SDRAM_CONFIG1);
97 out_be32 (&sdram->config2, SDRAM_CONFIG2);
98
99#if defined(SDRAM_DDR) && defined(SDRAM_TAPDELAY)
100 /* set tap delay */
101 out_be32 (&cdm->porcfg, SDRAM_TAPDELAY);
102#endif
103
104 /* find RAM size using SDRAM CS0 only */
105 sdram_start(0);
106 test1 = get_ram_size((long *) CONFIG_SYS_SDRAM_BASE, 0x10000000);
107 sdram_start(1);
108 test2 = get_ram_size((long *) CONFIG_SYS_SDRAM_BASE, 0x10000000);
109 if (test1 > test2) {
110 sdram_start(0);
111 dramsize = test1;
112 } else
113 dramsize = test2;
114
115 /* memory smaller than 1MB is impossible */
116 if (dramsize < (1 << 20))
117 dramsize = 0;
118
119 /* set SDRAM CS0 size according to the amount of RAM found */
120 if (dramsize > 0) {
121 out_be32 (&mm->sdram0,
122 (0x13 + __builtin_ffs(dramsize >> 20) - 1));
123 } else {
124 /* disabled */
125 out_be32 (&mm->sdram0, 0);
126 }
127
128#else /* CONFIG_SYS_RAMBOOT */
129
130 /* retrieve size of memory connected to SDRAM CS0 */
131 dramsize = in_be32(&mm->sdram0) & 0xFF;
132 if (dramsize >= 0x13)
133 dramsize = (1 << (dramsize - 0x13)) << 20;
134 else
135 dramsize = 0;
136
137 /* retrieve size of memory connected to SDRAM CS1 */
138 dramsize2 = in_be32(&mm->sdram1) & 0xFF;
139 if (dramsize2 >= 0x13)
140 dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
141 else
142 dramsize2 = 0;
143
144#endif /* CONFIG_SYS_RAMBOOT */
145
146 return dramsize + dramsize2;
147}
148
149int checkboard(void)
150{
151 puts("Board: phyCORE-MPC5200B-tiny\n");
152 return 0;
153}
154
155#ifdef CONFIG_PCI
156static struct pci_controller hose;
157
158extern void pci_mpc5xxx_init(struct pci_controller *);
159
160void pci_init_board(void)
161{
162 pci_mpc5xxx_init(&hose);
163}
164#endif
165
166#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
167void ft_board_setup(void *blob, bd_t * bd)
168{
169 ft_cpu_setup(blob, bd);
170}
171#endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */
172
173#if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
174
175#define GPIO_PSC2_4 0x02000000UL
176
177void init_ide_reset(void)
178{
179 volatile struct mpc5xxx_wu_gpio *wu_gpio =
180 (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO;
181 debug("init_ide_reset\n");
182
183 /* Configure PSC2_4 as GPIO output for ATA reset */
184 setbits_be32(&wu_gpio->enable, GPIO_PSC2_4);
185 setbits_be32(&wu_gpio->ddr, GPIO_PSC2_4);
186 /* Deassert reset */
187 setbits_be32(&wu_gpio->dvo, GPIO_PSC2_4);
188}
189
190void ide_set_reset(int idereset)
191{
192 volatile struct mpc5xxx_wu_gpio *wu_gpio =
193 (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO;
194 debug("ide_reset(%d)\n", idereset);
195
196 if (idereset) {
197 clrbits_be32(&wu_gpio->dvo, GPIO_PSC2_4);
198 /* Make a delay. MPC5200 spec says 25 usec min */
199 udelay(500000);
200 } else
201 setbits_be32(&wu_gpio->dvo, GPIO_PSC2_4);
202}
203#endif /* defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET) */