blob: 4b566a75ccd8ca037e0ee8d2a0f47c031c78ebe9 [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
2 * (C) Copyright 2002
3 * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24/* stuff specific for the sc520,
25 * but idependent of implementation */
26
wdenk2262cfe2002-11-18 00:14:45 +000027#include <common.h>
wdenk2262cfe2002-11-18 00:14:45 +000028#include <asm/io.h>
wdenk2262cfe2002-11-18 00:14:45 +000029#include <asm/ic/sc520.h>
30
Wolfgang Denkd87080b2006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
wdenk8bde7f72003-06-27 21:31:46 +000033/*
34 * utility functions for boards based on the AMD sc520
35 *
wdenk2262cfe2002-11-18 00:14:45 +000036 * void init_sc520(void)
37 * unsigned long init_sc520_dram(void)
wdenk2262cfe2002-11-18 00:14:45 +000038 */
39
Graeme Russed7a1b62009-08-23 12:59:56 +100040volatile sc520_mmcr_t *sc520_mmcr = (sc520_mmcr_t *)0xfffef000;
wdenk2262cfe2002-11-18 00:14:45 +000041
42void init_sc520(void)
43{
wdenk2262cfe2002-11-18 00:14:45 +000044 /* Set the UARTxCTL register at it's slower,
wdenk8bde7f72003-06-27 21:31:46 +000045 * baud clock giving us a 1.8432 MHz reference
wdenk2262cfe2002-11-18 00:14:45 +000046 */
Graeme Russed7a1b62009-08-23 12:59:56 +100047 sc520_mmcr->uart1ctl = 0x07;
48 sc520_mmcr->uart2ctl = 0x07;
wdenk8bde7f72003-06-27 21:31:46 +000049
wdenk2262cfe2002-11-18 00:14:45 +000050 /* first set the timer pin mapping */
Graeme Russed7a1b62009-08-23 12:59:56 +100051 sc520_mmcr->clksel = 0x72; /* no clock frequency selected, use 1.1892MHz */
wdenk8bde7f72003-06-27 21:31:46 +000052
wdenk2262cfe2002-11-18 00:14:45 +000053 /* enable PCI bus arbitrer */
Graeme Russed7a1b62009-08-23 12:59:56 +100054 sc520_mmcr->sysarbctl = 0x02; /* enable concurrent mode */
wdenk8bde7f72003-06-27 21:31:46 +000055
Graeme Russed7a1b62009-08-23 12:59:56 +100056 sc520_mmcr->sysarbmenb = 0x1f; /* enable external grants */
57 sc520_mmcr->hbctl = 0x04; /* enable posted-writes */
wdenk2262cfe2002-11-18 00:14:45 +000058
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020059 if (CONFIG_SYS_SC520_HIGH_SPEED) {
Graeme Russed7a1b62009-08-23 12:59:56 +100060 sc520_mmcr->cpuctl = 0x02; /* set it to 133 MHz and write back */
wdenk2262cfe2002-11-18 00:14:45 +000061 gd->cpu_clk = 133000000;
62 printf("## CPU Speed set to 133MHz\n");
63 } else {
Graeme Russed7a1b62009-08-23 12:59:56 +100064 sc520_mmcr->cpuctl = 0x01; /* set it to 100 MHz and write back */
wdenk2262cfe2002-11-18 00:14:45 +000065 printf("## CPU Speed set to 100MHz\n");
66 gd->cpu_clk = 100000000;
67 }
wdenk8bde7f72003-06-27 21:31:46 +000068
wdenk2262cfe2002-11-18 00:14:45 +000069
70 /* wait at least one millisecond */
wdenk8bde7f72003-06-27 21:31:46 +000071 asm("movl $0x2000,%%ecx\n"
Graeme Russcfb3a732009-08-23 12:59:46 +100072 "0: pushl %%ecx\n"
wdenk2262cfe2002-11-18 00:14:45 +000073 "popl %%ecx\n"
Graeme Russcfb3a732009-08-23 12:59:46 +100074 "loop 0b\n": : : "ecx");
wdenk2262cfe2002-11-18 00:14:45 +000075
76 /* turn on the SDRAM write buffer */
Graeme Russed7a1b62009-08-23 12:59:56 +100077 sc520_mmcr->dbctl = 0x11;
wdenk2262cfe2002-11-18 00:14:45 +000078
79 /* turn on the cache and disable write through */
80 asm("movl %%cr0, %%eax\n"
81 "andl $0x9fffffff, %%eax\n"
82 "movl %%eax, %%cr0\n" : : : "eax");
83}
84
85unsigned long init_sc520_dram(void)
86{
wdenk2262cfe2002-11-18 00:14:45 +000087 bd_t *bd = gd->bd;
wdenk8bde7f72003-06-27 21:31:46 +000088
wdenk2262cfe2002-11-18 00:14:45 +000089 u32 dram_present=0;
90 u32 dram_ctrl;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020091#ifdef CONFIG_SYS_SDRAM_DRCTMCTL
Wolfgang Denk94568b62006-08-14 23:23:06 +020092 /* these memory control registers are set up in the assember part,
93 * in sc520_asm.S, during 'mem_init'. If we muck with them here,
94 * after we are running a stack in RAM, we have troubles. Besides,
Wolfgang Denk16850912006-08-27 18:10:01 +020095 * these refresh and delay values are better ? simply specified
Wolfgang Denk94568b62006-08-14 23:23:06 +020096 * outright in the include/configs/{cfg} file since the HW designer
97 * simply dictates it.
98 */
99#else
wdenk2262cfe2002-11-18 00:14:45 +0000100 int val;
wdenk8bde7f72003-06-27 21:31:46 +0000101
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200102 int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY;
103 int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE;
104 int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY;
wdenk8bde7f72003-06-27 21:31:46 +0000105
wdenk2262cfe2002-11-18 00:14:45 +0000106 /* set SDRAM speed here */
wdenk8bde7f72003-06-27 21:31:46 +0000107
108 refresh_rate/=78;
wdenk2262cfe2002-11-18 00:14:45 +0000109 if (refresh_rate<=1) {
110 val = 0; /* 7.8us */
111 } else if (refresh_rate==2) {
112 val = 1; /* 15.6us */
113 } else if (refresh_rate==3 || refresh_rate==4) {
114 val = 2; /* 31.2us */
115 } else {
116 val = 3; /* 62.4us */
117 }
Wolfgang Denk94568b62006-08-14 23:23:06 +0200118
Graeme Russed7a1b62009-08-23 12:59:56 +1000119 sc520_mmcr->drcctl = (sc520_mmcr->drcctl & 0xcf) | (val<<4);
wdenk8bde7f72003-06-27 21:31:46 +0000120
Graeme Russed7a1b62009-08-23 12:59:56 +1000121 val = sc520_mmcr->drctmctl & 0xf0;
wdenk8bde7f72003-06-27 21:31:46 +0000122
123 if (cas_precharge_delay==3) {
wdenk2262cfe2002-11-18 00:14:45 +0000124 val |= 0x04; /* 3T */
wdenk8bde7f72003-06-27 21:31:46 +0000125 } else if (cas_precharge_delay==4) {
wdenk2262cfe2002-11-18 00:14:45 +0000126 val |= 0x08; /* 4T */
wdenk8bde7f72003-06-27 21:31:46 +0000127 } else if (cas_precharge_delay>4) {
wdenk2262cfe2002-11-18 00:14:45 +0000128 val |= 0x0c;
wdenk8bde7f72003-06-27 21:31:46 +0000129 }
130
wdenk2262cfe2002-11-18 00:14:45 +0000131 if (ras_cas_delay > 3) {
wdenk8bde7f72003-06-27 21:31:46 +0000132 val |= 2;
wdenk2262cfe2002-11-18 00:14:45 +0000133 } else {
wdenk8bde7f72003-06-27 21:31:46 +0000134 val |= 1;
wdenk2262cfe2002-11-18 00:14:45 +0000135 }
Graeme Russed7a1b62009-08-23 12:59:56 +1000136 sc520_mmcr->drctmctl = val;
Wolfgang Denk94568b62006-08-14 23:23:06 +0200137#endif
wdenk2262cfe2002-11-18 00:14:45 +0000138
139 /* We read-back the configuration of the dram
140 * controller that the assembly code wrote */
Graeme Russed7a1b62009-08-23 12:59:56 +1000141 dram_ctrl = sc520_mmcr->drcbendadr;
wdenk8bde7f72003-06-27 21:31:46 +0000142
wdenk2262cfe2002-11-18 00:14:45 +0000143 bd->bi_dram[0].start = 0;
144 if (dram_ctrl & 0x80) {
145 /* bank 0 enabled */
146 dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
wdenk8bde7f72003-06-27 21:31:46 +0000147 bd->bi_dram[0].size = bd->bi_dram[1].start;
wdenk2262cfe2002-11-18 00:14:45 +0000148
149 } else {
150 bd->bi_dram[0].size = 0;
151 bd->bi_dram[1].start = bd->bi_dram[0].start;
152 }
wdenk8bde7f72003-06-27 21:31:46 +0000153
wdenk2262cfe2002-11-18 00:14:45 +0000154 if (dram_ctrl & 0x8000) {
155 /* bank 1 enabled */
156 dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
wdenk8bde7f72003-06-27 21:31:46 +0000157 bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
wdenk2262cfe2002-11-18 00:14:45 +0000158 } else {
159 bd->bi_dram[1].size = 0;
160 bd->bi_dram[2].start = bd->bi_dram[1].start;
161 }
wdenk8bde7f72003-06-27 21:31:46 +0000162
wdenk2262cfe2002-11-18 00:14:45 +0000163 if (dram_ctrl & 0x800000) {
164 /* bank 2 enabled */
165 dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
wdenk8bde7f72003-06-27 21:31:46 +0000166 bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
wdenk2262cfe2002-11-18 00:14:45 +0000167 } else {
168 bd->bi_dram[2].size = 0;
169 bd->bi_dram[3].start = bd->bi_dram[2].start;
wdenk8bde7f72003-06-27 21:31:46 +0000170 }
171
wdenk2262cfe2002-11-18 00:14:45 +0000172 if (dram_ctrl & 0x80000000) {
173 /* bank 3 enabled */
174 dram_present = (dram_ctrl & 0x7f000000) >> 2;
175 bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
176 } else {
177 bd->bi_dram[3].size = 0;
178 }
179
wdenk8bde7f72003-06-27 21:31:46 +0000180
181#if 0
wdenk2262cfe2002-11-18 00:14:45 +0000182 printf("Configured %d bytes of dram\n", dram_present);
wdenk8bde7f72003-06-27 21:31:46 +0000183#endif
wdenk2262cfe2002-11-18 00:14:45 +0000184 gd->ram_size = dram_present;
wdenk8bde7f72003-06-27 21:31:46 +0000185
wdenk2262cfe2002-11-18 00:14:45 +0000186 return dram_present;
187}
188
Graeme Russ6d83e3a2009-02-24 21:12:20 +1100189#ifdef CONFIG_SYS_SC520_RESET
Graeme Russead056b2008-12-07 10:29:03 +1100190void reset_cpu(ulong addr)
191{
192 printf("Resetting using SC520 MMCR\n");
193 /* Write a '1' to the SYS_RST of the RESCFG MMCR */
Graeme Russed7a1b62009-08-23 12:59:56 +1000194 sc520_mmcr->rescfg = 0x01;
Graeme Russead056b2008-12-07 10:29:03 +1100195
196 /* NOTREACHED */
197}
198#endif