3 * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
24 /* stuff specific for the sc520,
25 * but idependent of implementation */
29 #include <asm/processor-flags.h>
30 #include <asm/ic/sc520.h>
32 DECLARE_GLOBAL_DATA_PTR;
35 * utility functions for boards based on the AMD sc520
37 * void init_sc520(void)
38 * unsigned long init_sc520_dram(void)
41 volatile sc520_mmcr_t *sc520_mmcr = (sc520_mmcr_t *)0xfffef000;
45 const u32 nw_cd_rst = ~(X86_CR0_NW | X86_CR0_CD);
48 * Set the UARTxCTL register at it's slower,
49 * baud clock giving us a 1.8432 MHz reference
51 writeb(0x07, &sc520_mmcr->uart1ctl);
52 writeb(0x07, &sc520_mmcr->uart2ctl);
54 /* first set the timer pin mapping */
55 writeb(0x72, &sc520_mmcr->clksel); /* no clock frequency selected, use 1.1892MHz */
57 /* enable PCI bus arbiter (concurrent mode) */
58 writeb(0x02, &sc520_mmcr->sysarbctl);
60 /* enable external grants */
61 writeb(0x1f, &sc520_mmcr->sysarbmenb);
63 /* enable posted-writes */
64 writeb(0x04, &sc520_mmcr->hbctl);
66 if (CONFIG_SYS_SC520_HIGH_SPEED) {
67 /* set it to 133 MHz and write back */
68 writeb(0x02, &sc520_mmcr->cpuctl);
69 gd->cpu_clk = 133000000;
70 printf("## CPU Speed set to 133MHz\n");
72 /* set it to 100 MHz and write back */
73 writeb(0x01, &sc520_mmcr->cpuctl);
74 printf("## CPU Speed set to 100MHz\n");
75 gd->cpu_clk = 100000000;
79 /* wait at least one millisecond */
80 asm("movl $0x2000, %%ecx\n"
83 "loop 0b\n": : : "ecx");
85 /* turn on the SDRAM write buffer */
86 writeb(0x11, &sc520_mmcr->dbctl);
88 /* turn on the cache and disable write through */
89 asm("movl %%cr0, %%eax\n"
91 "movl %%eax, %%cr0\n" : : "i" (nw_cd_rst) : "eax");
94 unsigned long init_sc520_dram(void)
101 #ifdef CONFIG_SYS_SDRAM_DRCTMCTL
102 /* these memory control registers are set up in the assember part,
103 * in sc520_asm.S, during 'mem_init'. If we muck with them here,
104 * after we are running a stack in RAM, we have troubles. Besides,
105 * these refresh and delay values are better ? simply specified
106 * outright in the include/configs/{cfg} file since the HW designer
107 * simply dictates it.
113 int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY;
114 int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE;
115 int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY;
117 /* set SDRAM speed here */
120 if (refresh_rate <= 1) {
122 } else if (refresh_rate == 2) {
123 val = 1; /* 15.6us */
124 } else if (refresh_rate == 3 || refresh_rate == 4) {
125 val = 2; /* 31.2us */
127 val = 3; /* 62.4us */
130 tmp = (readb(&sc520_mmcr->drcctl) & 0xcf) | (val<<4);
131 writeb(tmp, &sc520_mmcr->drcctl);
133 val = readb(&sc520_mmcr->drctmctl) & 0xf0;
135 if (cas_precharge_delay==3) {
136 val |= 0x04; /* 3T */
137 } else if (cas_precharge_delay==4) {
138 val |= 0x08; /* 4T */
139 } else if (cas_precharge_delay>4) {
143 if (ras_cas_delay > 3) {
148 writeb(val, &c520_mmcr->drctmctl);
152 * We read-back the configuration of the dram
153 * controller that the assembly code wrote
155 dram_ctrl = readl(&sc520_mmcr->drcbendadr);
157 bd->bi_dram[0].start = 0;
158 if (dram_ctrl & 0x80) {
160 dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
161 bd->bi_dram[0].size = bd->bi_dram[1].start;
163 bd->bi_dram[0].size = 0;
164 bd->bi_dram[1].start = bd->bi_dram[0].start;
167 if (dram_ctrl & 0x8000) {
169 dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
170 bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
172 bd->bi_dram[1].size = 0;
173 bd->bi_dram[2].start = bd->bi_dram[1].start;
176 if (dram_ctrl & 0x800000) {
178 dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
179 bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
181 bd->bi_dram[2].size = 0;
182 bd->bi_dram[3].start = bd->bi_dram[2].start;
185 if (dram_ctrl & 0x80000000) {
187 dram_present = (dram_ctrl & 0x7f000000) >> 2;
188 bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
190 bd->bi_dram[3].size = 0;
192 gd->ram_size = dram_present;
197 #ifdef CONFIG_SYS_SC520_RESET
198 void reset_cpu(ulong addr)
200 printf("Resetting using SC520 MMCR\n");
201 /* Write a '1' to the SYS_RST of the RESCFG MMCR */
202 writeb(0x01, &sc520_mmcr->rescfg);