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