Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 1 | /* |
| 2 | *(C) Copyright 2005-2008 Netstal Maschinen AG |
| 3 | * Niklaus Giger (Niklaus.Giger@netstal.com) |
| 4 | * |
| 5 | * This source code is free software; you can redistribute it |
| 6 | * and/or modify it in source code form under the terms of the GNU |
| 7 | * General Public License as published by the Free Software |
| 8 | * Foundation; either version 2 of the License, or (at your option) |
| 9 | * any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA |
| 19 | */ |
| 20 | |
| 21 | #include <common.h> |
Stefan Roese | b36df56 | 2010-09-09 19:18:00 +0200 | [diff] [blame] | 22 | #include <asm/ppc4xx.h> |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 23 | #include <asm/processor.h> |
| 24 | #include "nm.h" |
| 25 | |
| 26 | #if defined(DEBUG) |
| 27 | void show_sdram_registers(void) |
| 28 | { |
| 29 | u32 value; |
| 30 | |
| 31 | printf("SDRAM Controller Registers --\n"); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 32 | mfsdram(SDRAM0_CFG, value); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 33 | printf(" SDRAM0_CFG : 0x%08x\n", value); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 34 | mfsdram(SDRAM0_STATUS, value); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 35 | printf(" SDRAM0_STATUS: 0x%08x\n", value); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 36 | mfsdram(SDRAM0_B0CR, value); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 37 | printf(" SDRAM0_B0CR : 0x%08x\n", value); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 38 | mfsdram(SDRAM0_B1CR, value); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 39 | printf(" SDRAM0_B1CR : 0x%08x\n", value); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 40 | mfsdram(SDRAM0_TR, value); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 41 | printf(" SDRAM0_TR : 0x%08x\n", value); |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 42 | mfsdram(SDRAM0_RTR, value); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 43 | printf(" SDRAM0_RTR : 0x%08x\n", value); |
| 44 | } |
| 45 | #endif |
| 46 | |
Niklaus Giger | 7497312 | 2008-02-05 11:31:28 +0100 | [diff] [blame] | 47 | long int init_ppc405_sdram(unsigned int dram_size) |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 48 | { |
| 49 | #ifdef DEBUG |
| 50 | printf(__FUNCTION__); |
| 51 | #endif |
| 52 | /* disable memory controller */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 53 | mtsdram(SDRAM0_CFG, 0x00000000); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 54 | |
| 55 | udelay (500); |
| 56 | |
| 57 | /* Clear SDRAM0_BESR0 (Bus Error Syndrome Register) */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 58 | mtsdram(SDRAM0_BESR0, 0xffffffff); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 59 | |
| 60 | /* Clear SDRAM0_BESR1 (Bus Error Syndrome Register) */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 61 | mtsdram(SDRAM0_BESR1, 0xffffffff); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 62 | |
| 63 | /* Clear SDRAM0_ECCCFG (disable ECC) */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 64 | mtsdram(SDRAM0_ECCCFG, 0x00000000); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 65 | |
| 66 | /* Clear SDRAM0_ECCESR (ECC Error Syndrome Register) */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 67 | mtsdram(SDRAM0_ECCESR, 0xffffffff); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 68 | |
| 69 | /* Timing register: CASL=2, PTA=2, CTP=2, LDF=1, RFTA=5, RCD=2 |
| 70 | */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 71 | mtsdram(SDRAM0_TR, 0x008a4015); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 72 | |
| 73 | /* Memory Bank 0 Config == BA=0x00000000, SZ=64M, AM=3, BE=1 |
| 74 | * and refresh timer |
| 75 | */ |
| 76 | switch (dram_size >> 20) { |
| 77 | case 32: |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 78 | mtsdram(SDRAM0_B0CR, 0x00062001); |
| 79 | mtsdram(SDRAM0_RTR, 0x07F00000); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 80 | break; |
| 81 | case 64: |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 82 | mtsdram(SDRAM0_B0CR, 0x00084001); |
| 83 | mtsdram(SDRAM0_RTR, 0x04100000); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 84 | break; |
| 85 | case 128: |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 86 | mtsdram(SDRAM0_B0CR, 0x000A4001); |
| 87 | mtsdram(SDRAM0_RTR, 0x04100000); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 88 | break; |
| 89 | default: |
| 90 | printf("Invalid memory size of %d MB given\n", dram_size >> 20); |
| 91 | } |
| 92 | |
| 93 | /* Power management idle timer set to the default. */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 94 | mtsdram(SDRAM0_PMIT, 0x07c00000); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 95 | |
| 96 | udelay (500); |
| 97 | |
| 98 | /* Enable banks (DCE=1, BPRF=1, ECCDD=1, EMDUL=1) TODO */ |
Stefan Roese | 95b602b | 2009-09-24 13:59:57 +0200 | [diff] [blame] | 99 | mtsdram(SDRAM0_CFG, 0x90800000); |
Niklaus Giger | 69b0634 | 2008-01-17 12:53:56 +0100 | [diff] [blame] | 100 | |
| 101 | #ifdef DEBUG |
| 102 | printf("%s: done\n", __FUNCTION__); |
| 103 | #endif |
| 104 | return dram_size; |
| 105 | } |