wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
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> |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 29 | #include <asm/ic/sc520.h> |
| 30 | |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 31 | DECLARE_GLOBAL_DATA_PTR; |
| 32 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 33 | /* |
| 34 | * utility functions for boards based on the AMD sc520 |
| 35 | * |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 36 | * void init_sc520(void) |
| 37 | * unsigned long init_sc520_dram(void) |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 38 | */ |
| 39 | |
Graeme Russ | ed7a1b6 | 2009-08-23 12:59:56 +1000 | [diff] [blame] | 40 | volatile sc520_mmcr_t *sc520_mmcr = (sc520_mmcr_t *)0xfffef000; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 41 | |
| 42 | void init_sc520(void) |
| 43 | { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 44 | /* Set the UARTxCTL register at it's slower, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 45 | * baud clock giving us a 1.8432 MHz reference |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 46 | */ |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 47 | writeb(0x07, &sc520_mmcr->uart1ctl); |
| 48 | writeb(0x07, &sc520_mmcr->uart2ctl); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 49 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 50 | /* first set the timer pin mapping */ |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 51 | writeb(0x72, &sc520_mmcr->clksel); /* no clock frequency selected, use 1.1892MHz */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 52 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 53 | /* enable PCI bus arbitrer */ |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 54 | writeb(0x02, &sc520_mmcr->sysarbctl); /* enable concurrent mode */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 55 | |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 56 | writeb(0x1f, &sc520_mmcr->sysarbmenb); /* enable external grants */ |
| 57 | writeb(0x04, &sc520_mmcr->hbctl); /* enable posted-writes */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 58 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 59 | if (CONFIG_SYS_SC520_HIGH_SPEED) { |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 60 | writeb(0x02, &sc520_mmcr->cpuctl); /* set it to 133 MHz and write back */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 61 | gd->cpu_clk = 133000000; |
| 62 | printf("## CPU Speed set to 133MHz\n"); |
| 63 | } else { |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 64 | writeb(0x01, &sc520_mmcr->cpuctl); /* set it to 100 MHz and write back */ |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 65 | printf("## CPU Speed set to 100MHz\n"); |
| 66 | gd->cpu_clk = 100000000; |
| 67 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 68 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 69 | |
| 70 | /* wait at least one millisecond */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 71 | asm("movl $0x2000,%%ecx\n" |
Graeme Russ | cfb3a73 | 2009-08-23 12:59:46 +1000 | [diff] [blame] | 72 | "0: pushl %%ecx\n" |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 73 | "popl %%ecx\n" |
Graeme Russ | cfb3a73 | 2009-08-23 12:59:46 +1000 | [diff] [blame] | 74 | "loop 0b\n": : : "ecx"); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 75 | |
| 76 | /* turn on the SDRAM write buffer */ |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 77 | writeb(0x11, &sc520_mmcr->dbctl); |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 78 | |
| 79 | /* turn on the cache and disable write through */ |
| 80 | asm("movl %%cr0, %%eax\n" |
| 81 | "andl $0x9fffffff, %%eax\n" |
| 82 | "movl %%eax, %%cr0\n" : : : "eax"); |
| 83 | } |
| 84 | |
| 85 | unsigned long init_sc520_dram(void) |
| 86 | { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 87 | bd_t *bd = gd->bd; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 88 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 89 | u32 dram_present=0; |
| 90 | u32 dram_ctrl; |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 91 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 92 | #ifdef CONFIG_SYS_SDRAM_DRCTMCTL |
Wolfgang Denk | 94568b6 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 93 | /* these memory control registers are set up in the assember part, |
| 94 | * in sc520_asm.S, during 'mem_init'. If we muck with them here, |
| 95 | * after we are running a stack in RAM, we have troubles. Besides, |
Wolfgang Denk | 1685091 | 2006-08-27 18:10:01 +0200 | [diff] [blame] | 96 | * these refresh and delay values are better ? simply specified |
Wolfgang Denk | 94568b6 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 97 | * outright in the include/configs/{cfg} file since the HW designer |
| 98 | * simply dictates it. |
| 99 | */ |
| 100 | #else |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 101 | u8 tmp; |
| 102 | u8 val; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 103 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 104 | int cas_precharge_delay = CONFIG_SYS_SDRAM_PRECHARGE_DELAY; |
| 105 | int refresh_rate = CONFIG_SYS_SDRAM_REFRESH_RATE; |
| 106 | int ras_cas_delay = CONFIG_SYS_SDRAM_RAS_CAS_DELAY; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 107 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 108 | /* set SDRAM speed here */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 109 | |
| 110 | refresh_rate/=78; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 111 | if (refresh_rate<=1) { |
| 112 | val = 0; /* 7.8us */ |
| 113 | } else if (refresh_rate==2) { |
| 114 | val = 1; /* 15.6us */ |
| 115 | } else if (refresh_rate==3 || refresh_rate==4) { |
| 116 | val = 2; /* 31.2us */ |
| 117 | } else { |
| 118 | val = 3; /* 62.4us */ |
| 119 | } |
Wolfgang Denk | 94568b6 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 120 | |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 121 | tmp = (readb(&sc520_mmcr->drcctl) & 0xcf) | (val<<4); |
| 122 | writeb(tmp, &sc520_mmcr->drcctl); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 123 | |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 124 | val = readb(&sc520_mmcr->drctmctl) & 0xf0; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 125 | |
| 126 | if (cas_precharge_delay==3) { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 127 | val |= 0x04; /* 3T */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 128 | } else if (cas_precharge_delay==4) { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 129 | val |= 0x08; /* 4T */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 130 | } else if (cas_precharge_delay>4) { |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 131 | val |= 0x0c; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 132 | } |
| 133 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 134 | if (ras_cas_delay > 3) { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | val |= 2; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 136 | } else { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 137 | val |= 1; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 138 | } |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 139 | writeb(val, &c520_mmcr->drctmctl); |
Wolfgang Denk | 94568b6 | 2006-08-14 23:23:06 +0200 | [diff] [blame] | 140 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 141 | |
| 142 | /* We read-back the configuration of the dram |
| 143 | * controller that the assembly code wrote */ |
Graeme Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 144 | dram_ctrl = readl(&sc520_mmcr->drcbendadr); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 145 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 146 | bd->bi_dram[0].start = 0; |
| 147 | if (dram_ctrl & 0x80) { |
| 148 | /* bank 0 enabled */ |
| 149 | dram_present = bd->bi_dram[1].start = (dram_ctrl & 0x7f) << 22; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 150 | bd->bi_dram[0].size = bd->bi_dram[1].start; |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 151 | |
| 152 | } else { |
| 153 | bd->bi_dram[0].size = 0; |
| 154 | bd->bi_dram[1].start = bd->bi_dram[0].start; |
| 155 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 156 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 157 | if (dram_ctrl & 0x8000) { |
| 158 | /* bank 1 enabled */ |
| 159 | dram_present = bd->bi_dram[2].start = (dram_ctrl & 0x7f00) << 14; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 160 | 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] | 161 | } else { |
| 162 | bd->bi_dram[1].size = 0; |
| 163 | bd->bi_dram[2].start = bd->bi_dram[1].start; |
| 164 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 165 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 166 | if (dram_ctrl & 0x800000) { |
| 167 | /* bank 2 enabled */ |
| 168 | dram_present = bd->bi_dram[3].start = (dram_ctrl & 0x7f0000) << 6; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 169 | 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] | 170 | } else { |
| 171 | bd->bi_dram[2].size = 0; |
| 172 | bd->bi_dram[3].start = bd->bi_dram[2].start; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 173 | } |
| 174 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 175 | if (dram_ctrl & 0x80000000) { |
| 176 | /* bank 3 enabled */ |
| 177 | dram_present = (dram_ctrl & 0x7f000000) >> 2; |
| 178 | bd->bi_dram[3].size = dram_present - bd->bi_dram[3].start; |
| 179 | } else { |
| 180 | bd->bi_dram[3].size = 0; |
| 181 | } |
| 182 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 183 | |
| 184 | #if 0 |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 185 | printf("Configured %d bytes of dram\n", dram_present); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 186 | #endif |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 187 | gd->ram_size = dram_present; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 188 | |
wdenk | 2262cfe | 2002-11-18 00:14:45 +0000 | [diff] [blame] | 189 | return dram_present; |
| 190 | } |
| 191 | |
Graeme Russ | 6d83e3a | 2009-02-24 21:12:20 +1100 | [diff] [blame] | 192 | #ifdef CONFIG_SYS_SC520_RESET |
Graeme Russ | ead056b | 2008-12-07 10:29:03 +1100 | [diff] [blame] | 193 | void 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 Russ | 64a0a49 | 2010-04-24 00:05:37 +1000 | [diff] [blame^] | 197 | writeb(0x01, &sc520_mmcr->rescfg); |
Graeme Russ | ead056b | 2008-12-07 10:29:03 +1100 | [diff] [blame] | 198 | |
| 199 | /* NOTREACHED */ |
| 200 | } |
| 201 | #endif |