wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 2 | * (C) Copyright 2002-2004 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 3 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 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 | #include <common.h> |
| 25 | #include <ppc4xx.h> |
| 26 | #include <asm/processor.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | #ifdef CONFIG_SDRAM_BANK0 |
| 30 | |
| 31 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 32 | #define mtsdram0(reg, data) mtdcr(memcfga,reg);mtdcr(memcfgd,data) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 33 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 34 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 35 | struct sdram_conf_s { |
| 36 | unsigned long size; |
| 37 | unsigned long reg; |
| 38 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 39 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 40 | typedef struct sdram_conf_s sdram_conf_t; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 41 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 42 | sdram_conf_t mb0cf[] = { |
| 43 | {(128 << 20), 0x000A4001}, /* (0-128MB) Address Mode 3, 13x10(4) */ |
| 44 | {(64 << 20), 0x00084001}, /* (0-64MB) Address Mode 3, 13x9(4) */ |
| 45 | {(32 << 20), 0x00062001}, /* (0-32MB) Address Mode 2, 12x9(4) */ |
| 46 | {(16 << 20), 0x00046001}, /* (0-16MB) Address Mode 4, 12x8(4) */ |
| 47 | {(4 << 20), 0x00008001}, /* (0-4MB) Address Mode 5, 11x8(2) */ |
| 48 | }; |
| 49 | #define N_MB0CF (sizeof(mb0cf) / sizeof(mb0cf[0])) |
| 50 | |
| 51 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 52 | void sdram_init(void) |
| 53 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 54 | ulong sdtr1; |
| 55 | ulong rtr; |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 56 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 57 | |
| 58 | /* |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 59 | * Support for 100MHz and 133MHz SDRAM |
| 60 | */ |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 61 | if (get_bus_freq(0) > 100000000) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 62 | /* |
| 63 | * 133 MHz SDRAM |
| 64 | */ |
| 65 | sdtr1 = 0x01074015; |
| 66 | rtr = 0x07f00000; |
| 67 | } else { |
| 68 | /* |
| 69 | * default: 100 MHz SDRAM |
| 70 | */ |
| 71 | sdtr1 = 0x0086400d; |
| 72 | rtr = 0x05f00000; |
| 73 | } |
| 74 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 75 | for (i=0; i<N_MB0CF; i++) { |
stroese | 51c57b9 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 76 | /* |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 77 | * Disable memory controller. |
stroese | 51c57b9 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 78 | */ |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 79 | mtsdram0(mem_mcopt1, 0x00000000); |
wdenk | 41e2e05 | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 80 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 81 | /* |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 82 | * Set MB0CF for bank 0. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 83 | */ |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 84 | mtsdram0(mem_mb0cf, mb0cf[i].reg); |
| 85 | mtsdram0(mem_sdtr1, sdtr1); |
| 86 | mtsdram0(mem_rtr, rtr); |
wdenk | 41e2e05 | 2003-02-11 01:49:43 +0000 | [diff] [blame] | 87 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 88 | udelay(200); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 89 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 90 | /* |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 91 | * Set memory controller options reg, MCOPT1. |
| 92 | * Set DC_EN to '1' and BRD_PRF to '01' for 16 byte PLB Burst |
| 93 | * read/prefetch. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 94 | */ |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 95 | mtsdram0(mem_mcopt1, 0x80800000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 96 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 97 | udelay(10000); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 98 | |
stroese | 55ca749 | 2004-07-15 14:41:13 +0000 | [diff] [blame] | 99 | if (get_ram_size(0, mb0cf[i].size) == mb0cf[i].size) { |
| 100 | /* |
| 101 | * OK, size detected -> all done |
| 102 | */ |
| 103 | return; |
| 104 | } |
stroese | 51c57b9 | 2003-02-10 16:26:37 +0000 | [diff] [blame] | 105 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | #endif /* CONFIG_SDRAM_BANK0 */ |