blob: 7acd471d9631f95ee6c6cbca8246a8d5ae87ff9f [file] [log] [blame]
wdenk591dda52002-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
wdenk591dda52002-11-18 00:14:45 +000027#include <common.h>
wdenk591dda52002-11-18 00:14:45 +000028#include <asm/io.h>
wdenk591dda52002-11-18 00:14:45 +000029#include <asm/ic/sc520.h>
30
Wolfgang Denk6405a152006-03-31 18:32:53 +020031DECLARE_GLOBAL_DATA_PTR;
32
wdenk57b2d802003-06-27 21:31:46 +000033/*
34 * utility functions for boards based on the AMD sc520
35 *
wdenk591dda52002-11-18 00:14:45 +000036 * void init_sc520(void)
37 * unsigned long init_sc520_dram(void)
wdenk591dda52002-11-18 00:14:45 +000038 */
39
Graeme Russ1d977dc2009-08-23 12:59:56 +100040volatile sc520_mmcr_t *sc520_mmcr = (sc520_mmcr_t *)0xfffef000;
wdenk591dda52002-11-18 00:14:45 +000041
42void init_sc520(void)
43{
Graeme Russ3e6ec382010-10-07 20:03:21 +110044 /*
45 * Set the UARTxCTL register at it's slower,
wdenk57b2d802003-06-27 21:31:46 +000046 * baud clock giving us a 1.8432 MHz reference
wdenk591dda52002-11-18 00:14:45 +000047 */
Graeme Russ0c5ced72010-04-24 00:05:37 +100048 writeb(0x07, &sc520_mmcr->uart1ctl);
49 writeb(0x07, &sc520_mmcr->uart2ctl);
wdenk57b2d802003-06-27 21:31:46 +000050
wdenk591dda52002-11-18 00:14:45 +000051 /* first set the timer pin mapping */
Graeme Russ0c5ced72010-04-24 00:05:37 +100052 writeb(0x72, &sc520_mmcr->clksel); /* no clock frequency selected, use 1.1892MHz */
wdenk57b2d802003-06-27 21:31:46 +000053
Graeme Russ3e6ec382010-10-07 20:03:21 +110054 /* enable PCI bus arbiter (concurrent mode) */
55 writeb(0x02, &sc520_mmcr->sysarbctl);
wdenk57b2d802003-06-27 21:31:46 +000056
Graeme Russ3e6ec382010-10-07 20:03:21 +110057 /* enable external grants */
58 writeb(0x1f, &sc520_mmcr->sysarbmenb);
59
60 /* enable posted-writes */
61 writeb(0x04, &sc520_mmcr->hbctl);
wdenk591dda52002-11-18 00:14:45 +000062
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020063 if (CONFIG_SYS_SC520_HIGH_SPEED) {
Graeme Russ3e6ec382010-10-07 20:03:21 +110064 /* set it to 133 MHz and write back */
65 writeb(0x02, &sc520_mmcr->cpuctl);
wdenk591dda52002-11-18 00:14:45 +000066 gd->cpu_clk = 133000000;
67 printf("## CPU Speed set to 133MHz\n");
68 } else {
Graeme Russ3e6ec382010-10-07 20:03:21 +110069 /* set it to 100 MHz and write back */
70 writeb(0x01, &sc520_mmcr->cpuctl);
wdenk591dda52002-11-18 00:14:45 +000071 printf("## CPU Speed set to 100MHz\n");
72 gd->cpu_clk = 100000000;
73 }
wdenk57b2d802003-06-27 21:31:46 +000074
wdenk591dda52002-11-18 00:14:45 +000075
76 /* wait at least one millisecond */
Graeme Russ3e6ec382010-10-07 20:03:21 +110077 asm("movl $0x2000, %%ecx\n"
Graeme Russde7f9382009-08-23 12:59:46 +100078 "0: pushl %%ecx\n"
wdenk591dda52002-11-18 00:14:45 +000079 "popl %%ecx\n"
Graeme Russde7f9382009-08-23 12:59:46 +100080 "loop 0b\n": : : "ecx");
wdenk591dda52002-11-18 00:14:45 +000081
82 /* turn on the SDRAM write buffer */
Graeme Russ0c5ced72010-04-24 00:05:37 +100083 writeb(0x11, &sc520_mmcr->dbctl);
wdenk591dda52002-11-18 00:14:45 +000084
85 /* turn on the cache and disable write through */
86 asm("movl %%cr0, %%eax\n"
87 "andl $0x9fffffff, %%eax\n"
88 "movl %%eax, %%cr0\n" : : : "eax");
89}
90
91unsigned long init_sc520_dram(void)
92{
wdenk591dda52002-11-18 00:14:45 +000093 bd_t *bd = gd->bd;
wdenk57b2d802003-06-27 21:31:46 +000094
wdenk591dda52002-11-18 00:14:45 +000095 u32 dram_present=0;
96 u32 dram_ctrl;
Graeme Russ0c5ced72010-04-24 00:05:37 +100097
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020098#ifdef CONFIG_SYS_SDRAM_DRCTMCTL
Wolfgang Denk8ceef302006-08-14 23:23:06 +020099 /* these memory control registers are set up in the assember part,
100 * in sc520_asm.S, during 'mem_init'. If we muck with them here,
101 * after we are running a stack in RAM, we have troubles. Besides,
Wolfgang Denkdd314d12006-08-27 18:10:01 +0200102 * these refresh and delay values are better ? simply specified
Wolfgang Denk8ceef302006-08-14 23:23:06 +0200103 * outright in the include/configs/{cfg} file since the HW designer
104 * simply dictates it.
105 */
106#else
Graeme Russ0c5ced72010-04-24 00:05:37 +1000107 u8 tmp;
108 u8 val;
wdenk57b2d802003-06-27 21:31:46 +0000109
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200110 int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY;
111 int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE;
112 int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY;
wdenk57b2d802003-06-27 21:31:46 +0000113
wdenk591dda52002-11-18 00:14:45 +0000114 /* set SDRAM speed here */
wdenk57b2d802003-06-27 21:31:46 +0000115
Graeme Russ3e6ec382010-10-07 20:03:21 +1100116 refresh_rate /= 78;
117 if (refresh_rate <= 1) {
118 val = 0; /* 7.8us */
119 } else if (refresh_rate == 2) {
120 val = 1; /* 15.6us */
121 } else if (refresh_rate == 3 || refresh_rate == 4) {
122 val = 2; /* 31.2us */
wdenk591dda52002-11-18 00:14:45 +0000123 } else {
Graeme Russ3e6ec382010-10-07 20:03:21 +1100124 val = 3; /* 62.4us */
wdenk591dda52002-11-18 00:14:45 +0000125 }
Wolfgang Denk8ceef302006-08-14 23:23:06 +0200126
Graeme Russ0c5ced72010-04-24 00:05:37 +1000127 tmp = (readb(&sc520_mmcr->drcctl) & 0xcf) | (val<<4);
128 writeb(tmp, &sc520_mmcr->drcctl);
wdenk57b2d802003-06-27 21:31:46 +0000129
Graeme Russ0c5ced72010-04-24 00:05:37 +1000130 val = readb(&sc520_mmcr->drctmctl) & 0xf0;
wdenk57b2d802003-06-27 21:31:46 +0000131
132 if (cas_precharge_delay==3) {
Graeme Russ3e6ec382010-10-07 20:03:21 +1100133 val |= 0x04; /* 3T */
wdenk57b2d802003-06-27 21:31:46 +0000134 } else if (cas_precharge_delay==4) {
Graeme Russ3e6ec382010-10-07 20:03:21 +1100135 val |= 0x08; /* 4T */
wdenk57b2d802003-06-27 21:31:46 +0000136 } else if (cas_precharge_delay>4) {
wdenk591dda52002-11-18 00:14:45 +0000137 val |= 0x0c;
wdenk57b2d802003-06-27 21:31:46 +0000138 }
139
wdenk591dda52002-11-18 00:14:45 +0000140 if (ras_cas_delay > 3) {
wdenk57b2d802003-06-27 21:31:46 +0000141 val |= 2;
wdenk591dda52002-11-18 00:14:45 +0000142 } else {
wdenk57b2d802003-06-27 21:31:46 +0000143 val |= 1;
wdenk591dda52002-11-18 00:14:45 +0000144 }
Graeme Russ0c5ced72010-04-24 00:05:37 +1000145 writeb(val, &c520_mmcr->drctmctl);
Wolfgang Denk8ceef302006-08-14 23:23:06 +0200146#endif
wdenk591dda52002-11-18 00:14:45 +0000147
Graeme Russ3e6ec382010-10-07 20:03:21 +1100148 /*
149 * We read-back the configuration of the dram
150 * controller that the assembly code wrote
151 */
Graeme Russ0c5ced72010-04-24 00:05:37 +1000152 dram_ctrl = readl(&sc520_mmcr->drcbendadr);
wdenk57b2d802003-06-27 21:31:46 +0000153
wdenk591dda52002-11-18 00:14:45 +0000154 bd->bi_dram[0].start = 0;
155 if (dram_ctrl & 0x80) {
156 /* bank 0 enabled */
157 dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
wdenk57b2d802003-06-27 21:31:46 +0000158 bd->bi_dram[0].size = bd->bi_dram[1].start;
wdenk591dda52002-11-18 00:14:45 +0000159 } else {
160 bd->bi_dram[0].size = 0;
161 bd->bi_dram[1].start = bd->bi_dram[0].start;
162 }
wdenk57b2d802003-06-27 21:31:46 +0000163
wdenk591dda52002-11-18 00:14:45 +0000164 if (dram_ctrl & 0x8000) {
165 /* bank 1 enabled */
166 dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
wdenk57b2d802003-06-27 21:31:46 +0000167 bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
wdenk591dda52002-11-18 00:14:45 +0000168 } else {
169 bd->bi_dram[1].size = 0;
170 bd->bi_dram[2].start = bd->bi_dram[1].start;
171 }
wdenk57b2d802003-06-27 21:31:46 +0000172
wdenk591dda52002-11-18 00:14:45 +0000173 if (dram_ctrl & 0x800000) {
174 /* bank 2 enabled */
175 dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
wdenk57b2d802003-06-27 21:31:46 +0000176 bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
wdenk591dda52002-11-18 00:14:45 +0000177 } else {
178 bd->bi_dram[2].size = 0;
179 bd->bi_dram[3].start = bd->bi_dram[2].start;
wdenk57b2d802003-06-27 21:31:46 +0000180 }
181
wdenk591dda52002-11-18 00:14:45 +0000182 if (dram_ctrl & 0x80000000) {
183 /* bank 3 enabled */
184 dram_present = (dram_ctrl & 0x7f000000) >> 2;
185 bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
186 } else {
187 bd->bi_dram[3].size = 0;
188 }
wdenk591dda52002-11-18 00:14:45 +0000189 gd->ram_size = dram_present;
wdenk57b2d802003-06-27 21:31:46 +0000190
wdenk591dda52002-11-18 00:14:45 +0000191 return dram_present;
192}
193
Graeme Russ27a2bf42009-02-24 21:12:20 +1100194#ifdef CONFIG_SYS_SC520_RESET
Graeme Russ382827c2008-12-07 10:29:03 +1100195void reset_cpu(ulong addr)
196{
197 printf("Resetting using SC520 MMCR\n");
198 /* Write a '1' to the SYS_RST of the RESCFG MMCR */
Graeme Russ0c5ced72010-04-24 00:05:37 +1000199 writeb(0x01, &sc520_mmcr->rescfg);
Graeme Russ382827c2008-12-07 10:29:03 +1100200
201 /* NOTREACHED */
202}
203#endif