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