blob: 76de6bee41a6c13852ce0d58ecf54d5775c20ede [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 Russc2cbbaf2011-02-12 15:11:36 +110041sc520_mmcr_t *sc520_mmcr = (sc520_mmcr_t *)SC520_MMCR_BASE;
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{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020045 if (CONFIG_SYS_SC520_HIGH_SPEED) {
Graeme Russ8ffb2e82010-10-07 20:03:21 +110046 /* set it to 133 MHz and write back */
47 writeb(0x02, &sc520_mmcr->cpuctl);
wdenk2262cfe2002-11-18 00:14:45 +000048 gd->cpu_clk = 133000000;
wdenk2262cfe2002-11-18 00:14:45 +000049 } else {
Graeme Russ8ffb2e82010-10-07 20:03:21 +110050 /* set it to 100 MHz and write back */
51 writeb(0x01, &sc520_mmcr->cpuctl);
wdenk2262cfe2002-11-18 00:14:45 +000052 gd->cpu_clk = 100000000;
53 }
wdenk8bde7f72003-06-27 21:31:46 +000054
wdenk2262cfe2002-11-18 00:14:45 +000055
56 /* wait at least one millisecond */
Graeme Russ8ffb2e82010-10-07 20:03:21 +110057 asm("movl $0x2000, %%ecx\n"
Graeme Russcfb3a732009-08-23 12:59:46 +100058 "0: pushl %%ecx\n"
wdenk2262cfe2002-11-18 00:14:45 +000059 "popl %%ecx\n"
Graeme Russcfb3a732009-08-23 12:59:46 +100060 "loop 0b\n": : : "ecx");
wdenk2262cfe2002-11-18 00:14:45 +000061
62 /* turn on the SDRAM write buffer */
Graeme Russ64a0a492010-04-24 00:05:37 +100063 writeb(0x11, &sc520_mmcr->dbctl);
wdenk2262cfe2002-11-18 00:14:45 +000064
Graeme Russ0ea76e92011-02-12 15:11:35 +110065 return x86_cpu_init_f();
wdenk2262cfe2002-11-18 00:14:45 +000066}
67
68unsigned long init_sc520_dram(void)
69{
wdenk2262cfe2002-11-18 00:14:45 +000070 bd_t *bd = gd->bd;
wdenk8bde7f72003-06-27 21:31:46 +000071
wdenk2262cfe2002-11-18 00:14:45 +000072 u32 dram_present=0;
73 u32 dram_ctrl;
Graeme Russ64a0a492010-04-24 00:05:37 +100074
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020075#ifdef CONFIG_SYS_SDRAM_DRCTMCTL
Wolfgang Denk94568b62006-08-14 23:23:06 +020076 /* these memory control registers are set up in the assember part,
77 * in sc520_asm.S, during 'mem_init'. If we muck with them here,
78 * after we are running a stack in RAM, we have troubles. Besides,
Wolfgang Denk16850912006-08-27 18:10:01 +020079 * these refresh and delay values are better ? simply specified
Wolfgang Denk94568b62006-08-14 23:23:06 +020080 * outright in the include/configs/{cfg} file since the HW designer
81 * simply dictates it.
82 */
83#else
Graeme Russ64a0a492010-04-24 00:05:37 +100084 u8 tmp;
85 u8 val;
wdenk8bde7f72003-06-27 21:31:46 +000086
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020087 int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY;
88 int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE;
89 int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY;
wdenk8bde7f72003-06-27 21:31:46 +000090
wdenk2262cfe2002-11-18 00:14:45 +000091 /* set SDRAM speed here */
wdenk8bde7f72003-06-27 21:31:46 +000092
Graeme Russ8ffb2e82010-10-07 20:03:21 +110093 refresh_rate /= 78;
94 if (refresh_rate <= 1) {
95 val = 0; /* 7.8us */
96 } else if (refresh_rate == 2) {
97 val = 1; /* 15.6us */
98 } else if (refresh_rate == 3 || refresh_rate == 4) {
99 val = 2; /* 31.2us */
wdenk2262cfe2002-11-18 00:14:45 +0000100 } else {
Graeme Russ8ffb2e82010-10-07 20:03:21 +1100101 val = 3; /* 62.4us */
wdenk2262cfe2002-11-18 00:14:45 +0000102 }
Wolfgang Denk94568b62006-08-14 23:23:06 +0200103
Graeme Russ64a0a492010-04-24 00:05:37 +1000104 tmp = (readb(&sc520_mmcr->drcctl) & 0xcf) | (val<<4);
105 writeb(tmp, &sc520_mmcr->drcctl);
wdenk8bde7f72003-06-27 21:31:46 +0000106
Graeme Russ64a0a492010-04-24 00:05:37 +1000107 val = readb(&sc520_mmcr->drctmctl) & 0xf0;
wdenk8bde7f72003-06-27 21:31:46 +0000108
109 if (cas_precharge_delay==3) {
Graeme Russ8ffb2e82010-10-07 20:03:21 +1100110 val |= 0x04; /* 3T */
wdenk8bde7f72003-06-27 21:31:46 +0000111 } else if (cas_precharge_delay==4) {
Graeme Russ8ffb2e82010-10-07 20:03:21 +1100112 val |= 0x08; /* 4T */
wdenk8bde7f72003-06-27 21:31:46 +0000113 } else if (cas_precharge_delay>4) {
wdenk2262cfe2002-11-18 00:14:45 +0000114 val |= 0x0c;
wdenk8bde7f72003-06-27 21:31:46 +0000115 }
116
wdenk2262cfe2002-11-18 00:14:45 +0000117 if (ras_cas_delay > 3) {
wdenk8bde7f72003-06-27 21:31:46 +0000118 val |= 2;
wdenk2262cfe2002-11-18 00:14:45 +0000119 } else {
wdenk8bde7f72003-06-27 21:31:46 +0000120 val |= 1;
wdenk2262cfe2002-11-18 00:14:45 +0000121 }
Graeme Russ64a0a492010-04-24 00:05:37 +1000122 writeb(val, &c520_mmcr->drctmctl);
Wolfgang Denk94568b62006-08-14 23:23:06 +0200123#endif
wdenk2262cfe2002-11-18 00:14:45 +0000124
Graeme Russ8ffb2e82010-10-07 20:03:21 +1100125 /*
126 * We read-back the configuration of the dram
127 * controller that the assembly code wrote
128 */
Graeme Russ64a0a492010-04-24 00:05:37 +1000129 dram_ctrl = readl(&sc520_mmcr->drcbendadr);
wdenk8bde7f72003-06-27 21:31:46 +0000130
wdenk2262cfe2002-11-18 00:14:45 +0000131 bd->bi_dram[0].start = 0;
132 if (dram_ctrl & 0x80) {
133 /* bank 0 enabled */
134 dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22;
wdenk8bde7f72003-06-27 21:31:46 +0000135 bd->bi_dram[0].size = bd->bi_dram[1].start;
wdenk2262cfe2002-11-18 00:14:45 +0000136 } else {
137 bd->bi_dram[0].size = 0;
138 bd->bi_dram[1].start = bd->bi_dram[0].start;
139 }
wdenk8bde7f72003-06-27 21:31:46 +0000140
wdenk2262cfe2002-11-18 00:14:45 +0000141 if (dram_ctrl & 0x8000) {
142 /* bank 1 enabled */
143 dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14;
wdenk8bde7f72003-06-27 21:31:46 +0000144 bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start;
wdenk2262cfe2002-11-18 00:14:45 +0000145 } else {
146 bd->bi_dram[1].size = 0;
147 bd->bi_dram[2].start = bd->bi_dram[1].start;
148 }
wdenk8bde7f72003-06-27 21:31:46 +0000149
wdenk2262cfe2002-11-18 00:14:45 +0000150 if (dram_ctrl & 0x800000) {
151 /* bank 2 enabled */
152 dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6;
wdenk8bde7f72003-06-27 21:31:46 +0000153 bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start;
wdenk2262cfe2002-11-18 00:14:45 +0000154 } else {
155 bd->bi_dram[2].size = 0;
156 bd->bi_dram[3].start = bd->bi_dram[2].start;
wdenk8bde7f72003-06-27 21:31:46 +0000157 }
158
wdenk2262cfe2002-11-18 00:14:45 +0000159 if (dram_ctrl & 0x80000000) {
160 /* bank 3 enabled */
161 dram_present = (dram_ctrl & 0x7f000000) >> 2;
162 bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start;
163 } else {
164 bd->bi_dram[3].size = 0;
165 }
wdenk2262cfe2002-11-18 00:14:45 +0000166 gd->ram_size = dram_present;
wdenk8bde7f72003-06-27 21:31:46 +0000167
wdenk2262cfe2002-11-18 00:14:45 +0000168 return dram_present;
169}
170
Graeme Russ6d83e3a2009-02-24 21:12:20 +1100171#ifdef CONFIG_SYS_SC520_RESET
Graeme Russead056b2008-12-07 10:29:03 +1100172void reset_cpu(ulong addr)
173{
174 printf("Resetting using SC520 MMCR\n");
175 /* Write a '1' to the SYS_RST of the RESCFG MMCR */
Graeme Russ64a0a492010-04-24 00:05:37 +1000176 writeb(0x01, &sc520_mmcr->rescfg);
Graeme Russead056b2008-12-07 10:29:03 +1100177
178 /* NOTREACHED */
179}
180#endif