wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
Graeme Russ | 0ea76e9 | 2011-02-12 15:11:35 +1100 | [diff] [blame] | 3 | * Daniel Engstr�m, Omicron Ceti AB <daniel@omicron.se>. |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 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 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 27 | #include <common.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 28 | #include <asm/io.h> |
Graeme Russ | 0c24c9c | 2011-02-12 15:11:32 +1100 | [diff] [blame] | 29 | #include <asm/processor-flags.h> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 30 | #include <asm/ic/sc520.h> |
| 31 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 32 | DECLARE_GLOBAL_DATA_PTR; |
| 33 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 34 | /* |
| 35 | * utility functions for boards based on the AMD sc520 |
| 36 | * |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 37 | * void init_sc520(void) |
| 38 | * unsigned long init_sc520_dram(void) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 39 | */ |
| 40 | |
Graeme Russ | c2cbbaf | 2011-02-12 15:11:36 +1100 | [diff] [blame] | 41 | sc520_mmcr_t *sc520_mmcr = (sc520_mmcr_t *)SC520_MMCR_BASE; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 42 | |
Graeme Russ | 0ea76e9 | 2011-02-12 15:11:35 +1100 | [diff] [blame] | 43 | int cpu_init_f(void) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 44 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 45 | if (CONFIG_SYS_SC520_HIGH_SPEED) { |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 46 | /* set it to 133 MHz and write back */ |
| 47 | writeb(0x02, &sc520_mmcr->cpuctl); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 48 | gd->cpu_clk = 133000000; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 49 | } else { |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 50 | /* set it to 100 MHz and write back */ |
| 51 | writeb(0x01, &sc520_mmcr->cpuctl); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 52 | gd->cpu_clk = 100000000; |
| 53 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 54 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 55 | |
| 56 | /* wait at least one millisecond */ |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 57 | asm("movl $0x2000, %%ecx\n" |
Graeme Russ | cfb3a73 | 2009-08-23 12:59:46 +1000 | [diff] [blame] | 58 | "0: pushl %%ecx\n" |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 59 | "popl %%ecx\n" |
Graeme Russ | cfb3a73 | 2009-08-23 12:59:46 +1000 | [diff] [blame] | 60 | "loop 0b\n": : : "ecx"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 61 | |
| 62 | /* turn on the SDRAM write buffer */ |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 63 | writeb(0x11, &sc520_mmcr->dbctl); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 64 | |
Graeme Russ | 0ea76e9 | 2011-02-12 15:11:35 +1100 | [diff] [blame] | 65 | return x86_cpu_init_f(); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | unsigned long init_sc520_dram(void) |
| 69 | { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 70 | bd_t *bd = gd->bd; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 71 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 72 | u32 dram_present=0; |
| 73 | u32 dram_ctrl; |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 74 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 75 | #ifdef CONFIG_SYS_SDRAM_DRCTMCTL |
Wolfgang Denk | 94568b6 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 76 | /* 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 Denk | 1685091 | 2006-08-27 18:10:01 +0200 | [diff] [blame] | 79 | * these refresh and delay values are better ? simply specified |
Wolfgang Denk | 94568b6 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 80 | * outright in the include/configs/{cfg} file since the HW designer |
| 81 | * simply dictates it. |
| 82 | */ |
| 83 | #else |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 84 | u8 tmp; |
| 85 | u8 val; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 87 | 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; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 90 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 91 | /* set SDRAM speed here */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 92 | |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 93 | 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 */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 100 | } else { |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 101 | val = 3; /* 62.4us */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 102 | } |
Wolfgang Denk | 94568b6 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 103 | |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 104 | tmp = (readb(&sc520_mmcr->drcctl) & 0xcf) | (val<<4); |
| 105 | writeb(tmp, &sc520_mmcr->drcctl); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 106 | |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 107 | val = readb(&sc520_mmcr->drctmctl) & 0xf0; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 108 | |
| 109 | if (cas_precharge_delay==3) { |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 110 | val |= 0x04; /* 3T */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 111 | } else if (cas_precharge_delay==4) { |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 112 | val |= 0x08; /* 4T */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 113 | } else if (cas_precharge_delay>4) { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 114 | val |= 0x0c; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 115 | } |
| 116 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 117 | if (ras_cas_delay > 3) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 118 | val |= 2; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 119 | } else { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 120 | val |= 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 121 | } |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 122 | writeb(val, &c520_mmcr->drctmctl); |
Wolfgang Denk | 94568b6 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 123 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 124 | |
Graeme Russ | 8ffb2e8 | 2010-10-07 20:03:21 +1100 | [diff] [blame] | 125 | /* |
| 126 | * We read-back the configuration of the dram |
| 127 | * controller that the assembly code wrote |
| 128 | */ |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 129 | dram_ctrl = readl(&sc520_mmcr->drcbendadr); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 130 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 131 | 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; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | bd->bi_dram[0].size = bd->bi_dram[1].start; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 136 | } else { |
| 137 | bd->bi_dram[0].size = 0; |
| 138 | bd->bi_dram[1].start = bd->bi_dram[0].start; |
| 139 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 140 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 141 | if (dram_ctrl & 0x8000) { |
| 142 | /* bank 1 enabled */ |
| 143 | dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 144 | bd->bi_dram[1].size = bd->bi_dram[2].start - bd->bi_dram[1].start; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 145 | } else { |
| 146 | bd->bi_dram[1].size = 0; |
| 147 | bd->bi_dram[2].start = bd->bi_dram[1].start; |
| 148 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 149 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 150 | if (dram_ctrl & 0x800000) { |
| 151 | /* bank 2 enabled */ |
| 152 | dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 153 | bd->bi_dram[2].size = bd->bi_dram[3].start - bd->bi_dram[2].start; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 154 | } else { |
| 155 | bd->bi_dram[2].size = 0; |
| 156 | bd->bi_dram[3].start = bd->bi_dram[2].start; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 157 | } |
| 158 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 159 | 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 | } |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 166 | gd->ram_size = dram_present; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 167 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 168 | return dram_present; |
| 169 | } |
| 170 | |
Graeme Russ | 6d83e3a | 2009-02-24 21:12:20 +1100 | [diff] [blame] | 171 | #ifdef CONFIG_SYS_SC520_RESET |
Graeme Russ | ead056b | 2008-12-07 10:29:03 +1100 | [diff] [blame] | 172 | void 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 Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame] | 176 | writeb(0x01, &sc520_mmcr->rescfg); |
Graeme Russ | ead056b | 2008-12-07 10:29:03 +1100 | [diff] [blame] | 177 | |
| 178 | /* NOTREACHED */ |
| 179 | } |
| 180 | #endif |