blob: b99408cc999ce9eb0e072770122abf4e0d3a9fad [file] [log] [blame]
wdenk2262cfe2002-11-18 00:14:45 +00001/*
2 * (C) Copyright 2002
Graeme Russ0ea76e92011-02-12 15:11:35 +11003 * Daniel Engstr�m, Omicron Ceti AB <daniel@omicron.se>.
wdenk2262cfe2002-11-18 00:14:45 +00004 *
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>
Graeme Russ0c24c9c2011-02-12 15:11:32 +110029#include <asm/processor-flags.h>
wdenk2262cfe2002-11-18 00:14:45 +000030#include <asm/ic/sc520.h>
31
Wolfgang Denkd87080b2006-03-31 18:32:53 +020032DECLARE_GLOBAL_DATA_PTR;
33
wdenk8bde7f72003-06-27 21:31:46 +000034/*
35 * utility functions for boards based on the AMD sc520
36 *
wdenk2262cfe2002-11-18 00:14:45 +000037 * void init_sc520(void)
38 * unsigned long init_sc520_dram(void)
wdenk2262cfe2002-11-18 00:14:45 +000039 */
40
Graeme Russed7a1b62009-08-23 12:59:56 +100041volatile sc520_mmcr_t *sc520_mmcr = (sc520_mmcr_t *)0xfffef000;
wdenk2262cfe2002-11-18 00:14:45 +000042
Graeme Russ0ea76e92011-02-12 15:11:35 +110043int cpu_init_f(void)
wdenk2262cfe2002-11-18 00:14:45 +000044{
Graeme Russ8ffb2e82010-10-07 20:03:21 +110045 /*
46 * Set the UARTxCTL register at it's slower,
wdenk8bde7f72003-06-27 21:31:46 +000047 * baud clock giving us a 1.8432 MHz reference
wdenk2262cfe2002-11-18 00:14:45 +000048 */
Graeme Russ64a0a492010-04-24 00:05:37 +100049 writeb(0x07, &sc520_mmcr->uart1ctl);
50 writeb(0x07, &sc520_mmcr->uart2ctl);
wdenk8bde7f72003-06-27 21:31:46 +000051
wdenk2262cfe2002-11-18 00:14:45 +000052 /* first set the timer pin mapping */
Graeme Russ64a0a492010-04-24 00:05:37 +100053 writeb(0x72, &sc520_mmcr->clksel); /* no clock frequency selected, use 1.1892MHz */
wdenk8bde7f72003-06-27 21:31:46 +000054
Graeme Russ8ffb2e82010-10-07 20:03:21 +110055 /* enable PCI bus arbiter (concurrent mode) */
56 writeb(0x02, &sc520_mmcr->sysarbctl);
wdenk8bde7f72003-06-27 21:31:46 +000057
Graeme Russ8ffb2e82010-10-07 20:03:21 +110058 /* enable external grants */
59 writeb(0x1f, &sc520_mmcr->sysarbmenb);
60
61 /* enable posted-writes */
62 writeb(0x04, &sc520_mmcr->hbctl);
wdenk2262cfe2002-11-18 00:14:45 +000063
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020064 if (CONFIG_SYS_SC520_HIGH_SPEED) {
Graeme Russ8ffb2e82010-10-07 20:03:21 +110065 /* set it to 133 MHz and write back */
66 writeb(0x02, &sc520_mmcr->cpuctl);
wdenk2262cfe2002-11-18 00:14:45 +000067 gd->cpu_clk = 133000000;
68 printf("## CPU Speed set to 133MHz\n");
69 } else {
Graeme Russ8ffb2e82010-10-07 20:03:21 +110070 /* set it to 100 MHz and write back */
71 writeb(0x01, &sc520_mmcr->cpuctl);
wdenk2262cfe2002-11-18 00:14:45 +000072 printf("## CPU Speed set to 100MHz\n");
73 gd->cpu_clk = 100000000;
74 }
wdenk8bde7f72003-06-27 21:31:46 +000075
wdenk2262cfe2002-11-18 00:14:45 +000076
77 /* wait at least one millisecond */
Graeme Russ8ffb2e82010-10-07 20:03:21 +110078 asm("movl $0x2000, %%ecx\n"
Graeme Russcfb3a732009-08-23 12:59:46 +100079 "0: pushl %%ecx\n"
wdenk2262cfe2002-11-18 00:14:45 +000080 "popl %%ecx\n"
Graeme Russcfb3a732009-08-23 12:59:46 +100081 "loop 0b\n": : : "ecx");
wdenk2262cfe2002-11-18 00:14:45 +000082
83 /* turn on the SDRAM write buffer */
Graeme Russ64a0a492010-04-24 00:05:37 +100084 writeb(0x11, &sc520_mmcr->dbctl);
wdenk2262cfe2002-11-18 00:14:45 +000085
Graeme Russ0ea76e92011-02-12 15:11:35 +110086 return x86_cpu_init_f();
wdenk2262cfe2002-11-18 00:14:45 +000087}
88
89unsigned long init_sc520_dram(void)
90{
wdenk2262cfe2002-11-18 00:14:45 +000091 bd_t *bd = gd->bd;
wdenk8bde7f72003-06-27 21:31:46 +000092
wdenk2262cfe2002-11-18 00:14:45 +000093 u32 dram_present=0;
94 u32 dram_ctrl;
Graeme Russ64a0a492010-04-24 00:05:37 +100095
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020096#ifdef CONFIG_SYS_SDRAM_DRCTMCTL
Wolfgang Denk94568b62006-08-14 23:23:06 +020097 /* these memory control registers are set up in the assember part,
98 * in sc520_asm.S, during 'mem_init'. If we muck with them here,
99 * after we are running a stack in RAM, we have troubles. Besides,
Wolfgang Denk16850912006-08-27 18:10:01 +0200100 * these refresh and delay values are better ? simply specified
Wolfgang Denk94568b62006-08-14 23:23:06 +0200101 * outright in the include/configs/{cfg} file since the HW designer
102 * simply dictates it.
103 */
104#else
Graeme Russ64a0a492010-04-24 00:05:37 +1000105 u8 tmp;
106 u8 val;
wdenk8bde7f72003-06-27 21:31:46 +0000107
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200108 int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY;
109 int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE;
110 int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY;
wdenk8bde7f72003-06-27 21:31:46 +0000111
wdenk2262cfe2002-11-18 00:14:45 +0000112 /* set SDRAM speed here */
wdenk8bde7f72003-06-27 21:31:46 +0000113
Graeme Russ8ffb2e82010-10-07 20:03:21 +1100114 refresh_rate /= 78;
115 if (refresh_rate <= 1) {
116 val = 0; /* 7.8us */
117 } else if (refresh_rate == 2) {
118 val = 1; /* 15.6us */
119 } else if (refresh_rate == 3 || refresh_rate == 4) {
120 val = 2; /* 31.2us */
wdenk2262cfe2002-11-18 00:14:45 +0000121 } else {
Graeme Russ8ffb2e82010-10-07 20:03:21 +1100122 val = 3; /* 62.4us */
wdenk2262cfe2002-11-18 00:14:45 +0000123 }
Wolfgang Denk94568b62006-08-14 23:23:06 +0200124
Graeme Russ64a0a492010-04-24 00:05:37 +1000125 tmp = (readb(&sc520_mmcr->drcctl) & 0xcf) | (val<<4);
126 writeb(tmp, &sc520_mmcr->drcctl);
wdenk8bde7f72003-06-27 21:31:46 +0000127
Graeme Russ64a0a492010-04-24 00:05:37 +1000128 val = readb(&sc520_mmcr->drctmctl) & 0xf0;
wdenk8bde7f72003-06-27 21:31:46 +0000129
130 if (cas_precharge_delay==3) {
Graeme Russ8ffb2e82010-10-07 20:03:21 +1100131 val |= 0x04; /* 3T */
wdenk8bde7f72003-06-27 21:31:46 +0000132 } else if (cas_precharge_delay==4) {
Graeme Russ8ffb2e82010-10-07 20:03:21 +1100133 val |= 0x08; /* 4T */
wdenk8bde7f72003-06-27 21:31:46 +0000134 } else if (cas_precharge_delay>4) {
wdenk2262cfe2002-11-18 00:14:45 +0000135 val |= 0x0c;
wdenk8bde7f72003-06-27 21:31:46 +0000136 }
137
wdenk2262cfe2002-11-18 00:14:45 +0000138 if (ras_cas_delay > 3) {
wdenk8bde7f72003-06-27 21:31:46 +0000139 val |= 2;
wdenk2262cfe2002-11-18 00:14:45 +0000140 } else {
wdenk8bde7f72003-06-27 21:31:46 +0000141 val |= 1;
wdenk2262cfe2002-11-18 00:14:45 +0000142 }
Graeme Russ64a0a492010-04-24 00:05:37 +1000143 writeb(val, &c520_mmcr->drctmctl);
Wolfgang Denk94568b62006-08-14 23:23:06 +0200144#endif
wdenk2262cfe2002-11-18 00:14:45 +0000145
Graeme Russ8ffb2e82010-10-07 20:03:21 +1100146 /*
147 * We read-back the configuration of the dram
148 * controller that the assembly code wrote
149 */
Graeme Russ64a0a492010-04-24 00:05:37 +1000150 dram_ctrl = readl(&sc520_mmcr->drcbendadr);
wdenk8bde7f72003-06-27 21:31:46 +0000151
wdenk2262cfe2002-11-18 00:14:45 +0000152 bd->bi_dram[0].start = 0;
153 if (dram_ctrl & 0x80) {
154 /* bank 0 enabled */
155 dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
wdenk8bde7f72003-06-27 21:31:46 +0000156 bd->bi_dram[0].size = bd->bi_dram[1].start;
wdenk2262cfe2002-11-18 00:14:45 +0000157 } else {
158 bd->bi_dram[0].size = 0;
159 bd->bi_dram[1].start = bd->bi_dram[0].start;
160 }
wdenk8bde7f72003-06-27 21:31:46 +0000161
wdenk2262cfe2002-11-18 00:14:45 +0000162 if (dram_ctrl & 0x8000) {
163 /* bank 1 enabled */
164 dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
wdenk8bde7f72003-06-27 21:31:46 +0000165 bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
wdenk2262cfe2002-11-18 00:14:45 +0000166 } else {
167 bd->bi_dram[1].size = 0;
168 bd->bi_dram[2].start = bd->bi_dram[1].start;
169 }
wdenk8bde7f72003-06-27 21:31:46 +0000170
wdenk2262cfe2002-11-18 00:14:45 +0000171 if (dram_ctrl & 0x800000) {
172 /* bank 2 enabled */
173 dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
wdenk8bde7f72003-06-27 21:31:46 +0000174 bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
wdenk2262cfe2002-11-18 00:14:45 +0000175 } else {
176 bd->bi_dram[2].size = 0;
177 bd->bi_dram[3].start = bd->bi_dram[2].start;
wdenk8bde7f72003-06-27 21:31:46 +0000178 }
179
wdenk2262cfe2002-11-18 00:14:45 +0000180 if (dram_ctrl & 0x80000000) {
181 /* bank 3 enabled */
182 dram_present = (dram_ctrl & 0x7f000000) >> 2;
183 bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
184 } else {
185 bd->bi_dram[3].size = 0;
186 }
wdenk2262cfe2002-11-18 00:14:45 +0000187 gd->ram_size = dram_present;
wdenk8bde7f72003-06-27 21:31:46 +0000188
wdenk2262cfe2002-11-18 00:14:45 +0000189 return dram_present;
190}
191
Graeme Russ6d83e3a2009-02-24 21:12:20 +1100192#ifdef CONFIG_SYS_SC520_RESET
Graeme Russead056b2008-12-07 10:29:03 +1100193void reset_cpu(ulong addr)
194{
195 printf("Resetting using SC520 MMCR\n");
196 /* Write a '1' to the SYS_RST of the RESCFG MMCR */
Graeme Russ64a0a492010-04-24 00:05:37 +1000197 writeb(0x01, &sc520_mmcr->rescfg);
Graeme Russead056b2008-12-07 10:29:03 +1100198
199 /* NOTREACHED */
200}
201#endif